Skip to content

Commit

Permalink
fix text input width
Browse files Browse the repository at this point in the history
  • Loading branch information
ImToggle committed Jan 28, 2024
1 parent 3122cdc commit 12f14ac
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 21 deletions.
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 @@ -118,9 +118,8 @@ private void onDrawScreen(int mouseX, int mouseY, float partialTicks, CallbackIn
@ModifyArg(method = "drawScreen", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiChat;drawRect(IIIII)V"), index = 2)
private int modifyRight(int right) {
ChattingConfig config = ChattingConfig.INSTANCE;
int stringWidth = fontRendererObj.getStringWidth(ChatHooks.INSTANCE.getInput());
ChatHooks.INSTANCE.setInputRight(config.getCompactInputBox() ? Math.max((int) config.getChatWindow().getWidth(), stringWidth + 2 + (inputField.getText().length() < 100 ? 8 : 2)) + 2 : right);
return ChatHooks.INSTANCE.getInputRight();
ChatHooks.INSTANCE.setInputBoxRight(config.getCompactInputBox() ? Math.max((int) config.getChatWindow().getWidth() + 2, ChatHooks.INSTANCE.getInputRight() + (inputField.getText().length() < 100 ? 8 : 2)) : right);
return ChatHooks.INSTANCE.getInputBoxRight();
}

@ModifyArg(method = "drawScreen", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiChat;drawRect(IIIII)V"), index = 4)
Expand Down
20 changes: 4 additions & 16 deletions src/main/java/org/polyfrost/chatting/mixin/GuiTextFieldMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,14 @@
import org.polyfrost.chatting.chat.ChatHooks;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyArgs;
import org.spongepowered.asm.mixin.injection.ModifyVariable;
import org.spongepowered.asm.mixin.injection.invoke.arg.Args;

@Mixin(GuiTextField.class)
public abstract class GuiTextFieldMixin {

@ModifyVariable(method = "drawTextBox", at = @At("STORE"), ordinal = 0)
private String reset(String string) {
if (string.isEmpty() && ChatHooks.INSTANCE.checkField(this)) ChatHooks.INSTANCE.setInput("");
return string;
}

@ModifyArgs(method = "drawTextBox", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/FontRenderer;drawStringWithShadow(Ljava/lang/String;FFI)I", ordinal = 0))
private void captureString(Args args) {
if (ChatHooks.INSTANCE.checkField(this)) ChatHooks.INSTANCE.setInput(args.get(0));
}

@ModifyArgs(method = "drawTextBox", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/FontRenderer;drawStringWithShadow(Ljava/lang/String;FFI)I", ordinal = 1))
private void captureString2(Args args) {
if (ChatHooks.INSTANCE.checkField(this)) ChatHooks.INSTANCE.setInput(args.get(0));
@ModifyVariable(method = "drawTextBox", at = @At(value = "STORE"), ordinal = 6)
private int getRight(int right) {
if (ChatHooks.INSTANCE.checkField(this)) ChatHooks.INSTANCE.setInputRight(right);
return right;
}
}
2 changes: 1 addition & 1 deletion src/main/kotlin/org/polyfrost/chatting/chat/ChatHooks.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ object ChatHooks {

var commandDraft = ""

var input = ""
var inputBoxRight = 0

var inputRight = 0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ open class CleanButton(
}

open fun setPositionY() {
yPosition = UResolution.scaledHeight - 27 + if (ChattingConfig.compactInputBox && xPosition - ChatHooks.inputRight >= 1) 13 else 0
yPosition = UResolution.scaledHeight - 27 + if (ChattingConfig.compactInputBox && xPosition - ChatHooks.inputBoxRight >= 1) 13 else 0
}

override fun mousePressed(mc: Minecraft, mouseX: Int, mouseY: Int): Boolean {
Expand Down

0 comments on commit 12f14ac

Please sign in to comment.