Skip to content

Commit

Permalink
Revert "maybe a better way to cancel rectangle"
Browse files Browse the repository at this point in the history
This reverts commit 32a58c3.
  • Loading branch information
ImToggle committed Aug 4, 2024
1 parent 32a58c3 commit e8a26dd
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 79 deletions.
1 change: 0 additions & 1 deletion src/main/java/org/polyfrost/chatting/hook/ChatHook.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@
public class ChatHook {
public static ChatLine currentLine = null;
public static boolean lineVisible = false;
public static boolean cancelRect = false;
}
5 changes: 2 additions & 3 deletions src/main/java/org/polyfrost/chatting/mixin/GuiChatMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,11 @@ private void onDrawScreen(int mouseX, int mouseY, float partialTicks, CallbackIn
return hook.chatting$isHovering() && x > right * scale && x < (right + 9 * hud.getScale()) * scale;
}

@Inject(method = "drawScreen", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiChat;drawRect(IIIII)V"))
private void drawBG(int mouseX, int mouseY, float partialTicks, CallbackInfo ci) {
@Redirect(method = "drawScreen", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiChat;drawRect(IIIII)V"))
private void cancelBG(int left, int top, int right, int bottom, int color) {
ChattingConfig config = ChattingConfig.INSTANCE;
ChatHooks.INSTANCE.setInputBoxRight(config.getChatInput().getCompactInputBox() ? Math.max((int) config.getChatWindow().getWidth() + 2, ChatHooks.INSTANCE.getInputRight() + (inputField.getText().length() < ModCompatHooks.getChatInputLimit() ? 8 : 2)) : width - 2);
config.getChatInput().drawBG();
ChatHook.cancelRect = true;
}

@Inject(method = "mouseClicked", at = @At("HEAD"))
Expand Down
21 changes: 0 additions & 21 deletions src/main/java/org/polyfrost/chatting/mixin/GuiMixin.java

This file was deleted.

68 changes: 40 additions & 28 deletions src/main/java/org/polyfrost/chatting/mixin/GuiNewChatMixin.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.polyfrost.chatting.mixin;

import cc.polyfrost.oneconfig.config.core.OneColor;
import cc.polyfrost.oneconfig.libs.universal.UResolution;
import cc.polyfrost.oneconfig.utils.Notifications;
import cc.polyfrost.oneconfig.utils.color.ColorUtils;
import net.minecraft.util.IChatComponent;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.GL11;
Expand Down Expand Up @@ -162,7 +162,7 @@ private void disableScissor(int updateCounter, CallbackInfo ci) {

@ModifyArgs(method = "drawChat", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiNewChat;drawRect(IIIII)V", ordinal = 0))
private void captureDrawRect(Args args, int updateCounter) {
ChatHook.cancelRect = true;
args.set(4, ColorUtils.getColor(0, 0, 0, 0));
if (mc.currentScreen instanceof GuiChat) {
int left = args.get(0);
int top = args.get(1);
Expand All @@ -174,7 +174,6 @@ private void captureDrawRect(Args args, int updateCounter) {
}
if (chatting$isHovered(left, top, right - left, 9) || chatting$isHovered(right + 1, top, 9, 9) || chatting$isHovered(right + 11, top, 9, 9)) {
args.set(4, chatting$config().getHoveredChatBackgroundColor().getRGB());
ChatHook.cancelRect = false;
}
}
}
Expand Down Expand Up @@ -320,44 +319,57 @@ private void chatScale(CallbackInfoReturnable<Float> cir) {
GlStateManager.translate(chatting$config().getChatWindow().getPaddingX() * chatting$config().getChatWindow().getScale(), 0f, 0f);
}
if (chatting$config().getChatCopy()) {
chatting$drawButton(chatting$COPY, posLeft, top, posRight);
mc.getTextureManager().bindTexture(chatting$COPY);
chatting$right = right;
boolean hovered = chatting$isHovered(posLeft, top, posRight - posLeft, 9);
OneColor color = hovered ? chatting$config().getChatButtonHoveredBackgroundColor() : chatting$config().getChatButtonBackgroundColor();
drawRect(posLeft, top, posRight, top + 9, color.getRGB());
color = hovered ? chatting$config().getChatButtonHoveredColor() : chatting$config().getChatButtonColor();
GlStateManager.pushMatrix();
GlStateManager.enableAlpha();
GlStateManager.enableBlend();
GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
if (chatting$config().getButtonShadow()) {
GlStateManager.color(0f, 0f, 0f, color.getAlpha() / 255f);
drawModalRectWithCustomSizedTexture(posLeft + 1, top + 1, 0f, 0f, 9, 9, 9, 9);
}
GlStateManager.color(color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f, color.getAlpha() / 255f);
drawModalRectWithCustomSizedTexture(posLeft, top, 0f, 0f, 9, 9, 9, 9);
GlStateManager.disableAlpha();
GlStateManager.disableBlend();
GlStateManager.popMatrix();
posLeft += 10;
posRight += 10;
}
if (chatting$config().getChatDelete()) {
chatting$drawButton(chatting$DELETE, posLeft, top, posRight);
mc.getTextureManager().bindTexture(chatting$DELETE);
boolean hovered = chatting$isHovered(posLeft, top, posRight - posLeft, 9);
OneColor color = hovered ? chatting$config().getChatButtonHoveredBackgroundColor() : chatting$config().getChatButtonBackgroundColor();
drawRect(posLeft, top, posRight, top + 9, color.getRGB());
color = hovered ? chatting$config().getChatButtonHoveredColor() : chatting$config().getChatButtonColor();
GlStateManager.pushMatrix();
GlStateManager.enableAlpha();
GlStateManager.enableBlend();
GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
if (chatting$config().getButtonShadow()) {
GlStateManager.color(0f, 0f, 0f, color.getAlpha() / 255f);
drawModalRectWithCustomSizedTexture(posLeft + 1, top + 1, 0f, 0f, 9, 9, 9, 9);
}
GlStateManager.color(color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f, color.getAlpha() / 255f);
drawModalRectWithCustomSizedTexture(posLeft, top, 0f, 0f, 9, 9, 9, 9);
GlStateManager.disableAlpha();
GlStateManager.disableBlend();
GlStateManager.popMatrix();
}
GlStateManager.disableLighting();
GlStateManager.popMatrix();
}

@Unique
private void chatting$drawButton(ResourceLocation location, int left, int top, int right) {
mc.getTextureManager().bindTexture(chatting$DELETE);
boolean hovered = chatting$isHovered(left, top, 9, 9);
OneColor color = hovered ? chatting$config().getChatButtonHoveredBackgroundColor() : chatting$config().getChatButtonBackgroundColor();
drawRect(left, top, right, top + 9, color.getRGB());
color = hovered ? chatting$config().getChatButtonHoveredColor() : chatting$config().getChatButtonColor();
GlStateManager.pushMatrix();
GlStateManager.enableAlpha();
GlStateManager.enableBlend();
GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
if (chatting$config().getButtonShadow()) {
GlStateManager.color(0f, 0f, 0f, color.getAlpha() / 255f);
drawModalRectWithCustomSizedTexture(left + 1, top + 1, 0f, 0f, 9, 9, 9, 9);
}
GlStateManager.color(color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f, color.getAlpha() / 255f);
drawModalRectWithCustomSizedTexture(left, top, 0f, 0f, 9, 9, 9, 9);
GlStateManager.disableAlpha();
GlStateManager.disableBlend();
GlStateManager.popMatrix();
}

@Override
public ChatLine chatting$getHoveredLine(int mouseY) {
if (this.getChatOpen()) {
ScaledResolution scaledresolution = new ScaledResolution(this.mc);
float i = (float) UResolution.getScaleFactor();
int i = scaledresolution.getScaleFactor();
ChatWindow hud = chatting$config().getChatWindow();
float f = hud.getScale();
int k = (int) (mouseY / i - (scaledresolution.getScaledHeight() - hud.position.getBottomY() + hud.getPaddingY() * hud.getScale()) + ModCompatHooks.getYOffset());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

import cc.polyfrost.oneconfig.hud.Position;
import cc.polyfrost.oneconfig.internal.hud.HudCore;
import cc.polyfrost.oneconfig.libs.universal.UResolution;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.ChatLine;
import net.minecraft.client.gui.GuiNewChat;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.util.MathHelper;
import org.polyfrost.chatting.chat.ChatWindow;
import org.polyfrost.chatting.config.ChattingConfig;
Expand Down Expand Up @@ -37,6 +38,16 @@ private int width(int value) {
return MathHelper.ceiling_float_int((float)this.getChatWidth());
}

@ModifyConstant(method = "drawChat", constant = @Constant(intValue = 9, ordinal = 0))
private int chatMode(int constant) {
return constant;
}

@Redirect(method = "drawChat", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiNewChat;getChatScale()F"))
private float scale(GuiNewChat instance) {
return ChattingConfig.INSTANCE.getChatWindow().getScale();
}

@Inject(method = "drawChat", at = @At(value = "HEAD"), cancellable = true)
private void exampleChat(int updateCounter, CallbackInfo ci) {
if (HudCore.editing) ci.cancel();
Expand All @@ -51,8 +62,9 @@ private int mouseX(int constant) {

@ModifyConstant(method = "getChatComponent", constant = @Constant(intValue = 27))
private int mouseY(int constant) {
int height = new ScaledResolution(Minecraft.getMinecraft()).getScaledHeight();
ChatWindow hud = ChattingConfig.INSTANCE.getChatWindow();
return UResolution.getScaledHeight() - (int) (hud.position.getBottomY() - hud.getPaddingY() * hud.getScale() + ModCompatHooks.getChatPosition());
return height - (int) (hud.position.getBottomY() - hud.getPaddingY() * hud.getScale() + ModCompatHooks.getChatPosition());
}

@ModifyVariable(method = "getChatComponent", at = @At("STORE"), ordinal = 0)
Expand All @@ -66,6 +78,11 @@ private int offset(int value) {
return ((ChatLineHook) chatting$currentLine).chatting$hasDetected() || ChattingConfig.INSTANCE.getOffsetNonPlayerMessages() ? ModCompatHooks.getChatHeadOffset() : 0;
}

@Redirect(method = "getChatComponent", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiNewChat;getChatScale()F", ordinal = 0))
private float getScale(GuiNewChat instance) {
return ChattingConfig.INSTANCE.getChatWindow().getScale();
}

@ModifyArg(method = "getChatComponent", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/MathHelper;floor_float(F)I", ordinal = 2))
private float width(float value) {
ChatWindow hud = ChattingConfig.INSTANCE.getChatWindow();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiNewChat;
import org.polyfrost.chatting.config.ChattingConfig;
import org.polyfrost.chatting.hook.ChatHook;
import org.polyfrost.chatting.utils.EaseOutQuad;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
Expand Down Expand Up @@ -44,14 +43,18 @@ private int redirectPos(GuiNewChat instance) {
return ChattingConfig.INSTANCE.getSmoothScrolling() ? (int) chatting$scrollingAnimation.get() : scrollPos;
}

@Inject(method = "drawChat", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiNewChat;drawRect(IIIII)V", ordinal = 1))
private void redirectScrollBar(int updateCounter, CallbackInfo ci) {
if (ChattingConfig.INSTANCE.getRemoveScrollBar()) ChatHook.cancelRect = true;
@Redirect(method = "drawChat", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiNewChat;drawRect(IIIII)V", ordinal = 1))
private void redirectScrollBar(int left, int top, int right, int bottom, int color) {
if (!ChattingConfig.INSTANCE.getRemoveScrollBar()) {
drawRect(left, top, right, bottom, color);
}
}

@Inject(method = "drawChat", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiNewChat;drawRect(IIIII)V", ordinal = 2))
private void redirectScrollBar2(int updateCounter, CallbackInfo ci) {
if (ChattingConfig.INSTANCE.getRemoveScrollBar()) ChatHook.cancelRect = true;
@Redirect(method = "drawChat", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiNewChat;drawRect(IIIII)V", ordinal = 2))
private void redirectScrollBar2(int left, int top, int right, int bottom, int color) {
if (!ChattingConfig.INSTANCE.getRemoveScrollBar()) {
drawRect(left, top, right, bottom, color);
}
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.polyfrost.chatting.mixin;

import org.polyfrost.chatting.Chatting;
import org.polyfrost.chatting.chat.ChatSearchingManager;
import org.polyfrost.chatting.chat.ChatTabs;
import org.polyfrost.chatting.config.ChattingConfig;
Expand Down
25 changes: 9 additions & 16 deletions src/main/java/org/polyfrost/chatting/mixin/GuiUtilsMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,22 @@
import net.minecraft.client.gui.FontRenderer;
import net.minecraftforge.fml.client.config.GuiUtils;
import org.polyfrost.chatting.config.ChattingConfig;
import org.polyfrost.chatting.hook.ChatHook;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.util.List;

@Mixin(value = GuiUtils.class, remap = false)
public class GuiUtilsMixin {
@Shadow
public static void drawGradientRect(int zLevel, int left, int top, int right, int bottom, int startColor, int endColor) {
}

@Inject(method = "drawHoveringText", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/fml/client/config/GuiUtils;drawGradientRect(IIIIIII)V"))
private static void redirectBackground(List<String> textLines, int mouseX, int mouseY, int screenWidth, int screenHeight, int maxTextWidth, FontRenderer font, CallbackInfo ci) {
if (ChattingConfig.INSTANCE.getRemoveTooltipBackground()) ChatHook.cancelRect = true;
@Redirect(method = "drawHoveringText", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/fml/client/config/GuiUtils;drawGradientRect(IIIIIII)V"))
private static void redirectBackground(int zLevel, int left, int top, int right, int bottom, int startColor, int endColor) {
if (!ChattingConfig.INSTANCE.getRemoveTooltipBackground()) {
drawGradientRect(zLevel, left, top, right, bottom, startColor, endColor);
}
}

@Redirect(method = "drawHoveringText", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/FontRenderer;drawStringWithShadow(Ljava/lang/String;FFI)I"))
Expand All @@ -32,12 +33,4 @@ private static int redirectText(FontRenderer instance, String text, float x, flo
return instance.drawStringWithShadow(text, x, y, color);
}
}

@Inject(method = "drawGradientRect", at = @At("HEAD"), cancellable = true)
private static void cancelRect(int zLevel, int left, int top, int right, int bottom, int startColor, int endColor, CallbackInfo ci) {
if (ChatHook.cancelRect) {
ChatHook.cancelRect = false;
ci.cancel();
}
}
}
1 change: 0 additions & 1 deletion src/main/resources/mixins.chatting.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"GuiContainerCreativeMixin",
"GuiIngameForgeAccessor",
"GuiIngameForgeMixin",
"GuiMixin",
"GuiNewChatAccessor",
"GuiNewChatMixin",
"GuiNewChatMixin_ChatHeight",
Expand Down

0 comments on commit e8a26dd

Please sign in to comment.