From cc6724b4e2d96b47e7987ba40f65d38b82159bb1 Mon Sep 17 00:00:00 2001 From: Quie_ Date: Wed, 3 Jan 2024 22:55:57 -0800 Subject: [PATCH] Fixed all the GUI errors --- .../macros/gui/screen/CommandEditScreen.java | 8 +++--- .../macros/gui/screen/MacroEditScreen.java | 26 +++++++++---------- .../macros/gui/screen/MacroSelectScreen.java | 20 +++++++------- .../macros/gui/widget/IconButtonWidget.java | 9 +++---- .../widget/commandlist/CommandListWidget.java | 21 ++++++++------- .../gui/widget/macrolist/MacroEntry.java | 22 +++++++--------- .../gui/widget/macrolist/MacroListWidget.java | 7 +++-- .../mixin/features/ItemBindMixin.java | 25 ++++++++---------- .../mixin/macros/AddMacroButtonMixin.java | 5 ++-- 9 files changed, 69 insertions(+), 74 deletions(-) diff --git a/src/main/java/tools/redstone/redstonetools/macros/gui/screen/CommandEditScreen.java b/src/main/java/tools/redstone/redstonetools/macros/gui/screen/CommandEditScreen.java index 90125762..5031ce25 100644 --- a/src/main/java/tools/redstone/redstonetools/macros/gui/screen/CommandEditScreen.java +++ b/src/main/java/tools/redstone/redstonetools/macros/gui/screen/CommandEditScreen.java @@ -1,15 +1,14 @@ package tools.redstone.redstonetools.macros.gui.screen; -import net.minecraft.client.gui.DrawContext; -import tools.redstone.redstonetools.macros.gui.MacroCommandSuggestor; import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.screen.option.GameOptionsScreen; import net.minecraft.client.gui.widget.TextFieldWidget; import net.minecraft.client.option.GameOptions; import net.minecraft.client.util.InputUtil; -import net.minecraft.client.util.math.MatrixStack; import net.minecraft.text.Text; +import tools.redstone.redstonetools.macros.gui.MacroCommandSuggestor; public class CommandEditScreen extends GameOptionsScreen { @@ -32,7 +31,7 @@ public CommandEditScreen(Screen parent, GameOptions gameOptions, TextFieldWidget public void render(DrawContext context, int mouseX, int mouseY, float delta) { parent.render(context, mouseX, mouseY, delta); - this.fillGradient(context, 0, 0, this.width, this.height, -1072689136, -804253680); + //this.fillGradient(context, 0, 0, this.width, this.height, -1072689136, -804253680); commandField.render(context, mouseX, mouseY, delta); @@ -49,7 +48,6 @@ public void render(DrawContext context, int mouseX, int mouseY, float delta) { @Override public void tick() { super.tick(); - commandField.tick(); } @Override diff --git a/src/main/java/tools/redstone/redstonetools/macros/gui/screen/MacroEditScreen.java b/src/main/java/tools/redstone/redstonetools/macros/gui/screen/MacroEditScreen.java index 0cdbb8cb..20682157 100644 --- a/src/main/java/tools/redstone/redstonetools/macros/gui/screen/MacroEditScreen.java +++ b/src/main/java/tools/redstone/redstonetools/macros/gui/screen/MacroEditScreen.java @@ -59,7 +59,7 @@ public void init() { nameField = new TextFieldWidget(this.textRenderer, this.width / 2 - 100, 22, 200, 20, Text.of("")); nameField.setText(macro.name.trim()); - doneButton = this.addDrawableChild(new ButtonWidget(this.width / 2 - 100, this.height / 4 + 144 + 5, 98, 20, Text.of("Done"), (button) -> { + doneButton = this.addDrawableChild(ButtonWidget.builder(Text.of("Done"), (button) -> { String name = nameField.getText().trim(); if (name.isEmpty()) return; @@ -71,7 +71,7 @@ public void init() { INJECTOR.getInstance(MacroManager.class).saveChanges(); client.setScreen(parent); - })); + }).dimensions(this.width / 2 - 100, this.height / 4 + 144 + 5, 98, 20).build()); doneButton.active = canClickDone(); nameField.setChangedListener(s -> { @@ -81,19 +81,19 @@ public void init() { addSelectableChild(nameField); - this.addDrawableChild(new ButtonWidget(this.width / 2 + 2, this.height / 4 + 144 + 5, 98, 20, ScreenTexts.CANCEL, (button) -> { + this.addDrawableChild(ButtonWidget.builder(ScreenTexts.CANCEL, (button) -> { close(); - })); + }).dimensions(this.width / 2 + 2, this.height / 4 + 144 + 5, 98, 20).build()); Key keyCode = macro.getKey(); Text text = keyCode.getLocalizedText(); if (keyCode == InputUtil.UNKNOWN_KEY) text = Text.of(""); if ( KeyBindingUtils.isKeyAlreadyBound(keyCode) ) { text = Text.literal(text.getString()).formatted(Formatting.RED); } - keyBindButton = new ButtonWidget(this.width / 2 + 26, 55, 75, 20, text, (button) -> { + keyBindButton = ButtonWidget.builder(text, (button) -> { detectingKeycodeKey = true; keyBindButton.setMessage((Text.literal("> ")).append(keyBindButton.getMessage().copy().formatted(Formatting.YELLOW)).append(" <").formatted(Formatting.YELLOW)); - }); + }).dimensions(this.width / 2 + 26, 55, 75, 20).build(); if (detectingKeycodeKey) keyBindButton.onPress(); this.addDrawableChild(keyBindButton); @@ -106,8 +106,8 @@ public void init() { scrollAmount = commandList.getScrollAmount(); } - commandList = new CommandListWidget(client, this, widgetWidth, height, 85, this.height / 4 + 144 + 5 - 10, 24); - commandList.setLeftPos(width / 2 - widgetWidth / 2); + commandList = new CommandListWidget(client, this, widgetWidth, height, 85, 24); + //commandList.setLeftPos(width / 2 - widgetWidth / 2); if (entries != null) { @@ -139,13 +139,13 @@ public void render(DrawContext context, int mouseX, int mouseY, float delta) { mouseY = -1; } - this.renderBackgroundTexture(0); + this.renderBackgroundTexture(context); commandList.render(context, mouseX, mouseY, delta); super.render(context, mouseX, mouseY, delta); - drawCenteredTextWithShadow(context, this.textRenderer, this.title, this.width / 2, 8, 16777215); + context.drawCenteredTextWithShadow(this.textRenderer, this.title, this.width / 2, 8, 16777215); - drawCenteredTextWithShadow(context, this.textRenderer, "Key Bind", width / 2 - (99 - textRenderer.getWidth("Key Bind") / 2), 55 + textRenderer.fontHeight / 2, 16777215); + context.drawCenteredTextWithShadow(this.textRenderer, "Key Bind", width / 2 - (99 - textRenderer.getWidth("Key Bind") / 2), 55 + textRenderer.fontHeight / 2, 16777215); nameField.render(context, mouseX, mouseY, delta); if (nameField.getText().isEmpty() && !nameField.isFocused()) { @@ -157,8 +157,8 @@ public void render(DrawContext context, int mouseX, int mouseY, float delta) { @Override public void tick() { - nameField.tick(); - commandList.tick(); + //nameField.tick(); + //commandList.tick(); super.tick(); } diff --git a/src/main/java/tools/redstone/redstonetools/macros/gui/screen/MacroSelectScreen.java b/src/main/java/tools/redstone/redstonetools/macros/gui/screen/MacroSelectScreen.java index ce7e9382..4275c7f1 100644 --- a/src/main/java/tools/redstone/redstonetools/macros/gui/screen/MacroSelectScreen.java +++ b/src/main/java/tools/redstone/redstonetools/macros/gui/screen/MacroSelectScreen.java @@ -1,15 +1,14 @@ package tools.redstone.redstonetools.macros.gui.screen; import net.minecraft.client.gui.DrawContext; -import tools.redstone.redstonetools.macros.gui.widget.macrolist.MacroEntry; -import tools.redstone.redstonetools.macros.gui.widget.macrolist.MacroListWidget; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.screen.option.GameOptionsScreen; import net.minecraft.client.gui.widget.ButtonWidget; import net.minecraft.client.option.GameOptions; -import net.minecraft.client.util.math.MatrixStack; import net.minecraft.screen.ScreenTexts; import net.minecraft.text.Text; +import tools.redstone.redstonetools.macros.gui.widget.macrolist.MacroEntry; +import tools.redstone.redstonetools.macros.gui.widget.macrolist.MacroListWidget; public class MacroSelectScreen extends GameOptionsScreen { @@ -27,20 +26,23 @@ public void init() { this.macroList = new MacroListWidget(this,client); this.addSelectableChild(this.macroList); - this.addDrawableChild(new ButtonWidget(this.width / 2 +1, this.height - 29, 150, 20, Text.of("Create New..."), (button) -> { + ButtonWidget buttonWidget = ButtonWidget.builder(Text.of("Create New..."), (button) -> { this.client.setScreen(new MacroEditScreen(this,gameOptions,Text.of("New Macro"), macroList)); - })); + }).dimensions(this.width / 2 +1, this.height - 29, 150, 20).build(); + this.addDrawableChild(buttonWidget); - this.addDrawableChild(new ButtonWidget(this.width / 2 - 151, this.height - 29, 150, 20, ScreenTexts.DONE, (button) -> { + buttonWidget = ButtonWidget.builder(ScreenTexts.DONE, (button) -> { this.client.setScreen(this.parent); - })); + }).dimensions(this.width / 2 - 151, this.height - 29, 150, 20).build(); + + this.addDrawableChild(buttonWidget); } public void render(DrawContext context, int mouseX, int mouseY, float delta) { - this.renderBackgroundTexture(0); + this.renderBackgroundTexture(context); macroList.render(context, mouseX, mouseY, delta); - drawCenteredTextWithShadow(context, this.textRenderer, this.title, this.width / 2, 8, 16777215); + context.drawCenteredTextWithShadow(this.textRenderer, this.title, this.width / 2, 8, 16777215); super.render(context, mouseX, mouseY, delta); } diff --git a/src/main/java/tools/redstone/redstonetools/macros/gui/widget/IconButtonWidget.java b/src/main/java/tools/redstone/redstonetools/macros/gui/widget/IconButtonWidget.java index af56ea36..db1038aa 100644 --- a/src/main/java/tools/redstone/redstonetools/macros/gui/widget/IconButtonWidget.java +++ b/src/main/java/tools/redstone/redstonetools/macros/gui/widget/IconButtonWidget.java @@ -4,7 +4,6 @@ import com.mojang.blaze3d.systems.RenderSystem; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.widget.ButtonWidget; -import net.minecraft.client.util.math.MatrixStack; import net.minecraft.text.Text; import net.minecraft.util.Identifier; @@ -14,13 +13,13 @@ public class IconButtonWidget extends ButtonWidget { public static Identifier PENCIL_ICON = new Identifier("redstonetools","gui/pencil.png"); private final Identifier texture; - public IconButtonWidget(Identifier texture ,int x, int y, int width, int height, Text message, PressAction onPress) { - super(x, y, width, height, message, onPress); + public IconButtonWidget(Identifier texture ,int x, int y, int width, int height, Text message, PressAction onPress, NarrationSupplier narrationSupplier) { + super(x, y, width, height, message, onPress, narrationSupplier); this.texture = texture; } public void renderButton(DrawContext context, int mouseX, int mouseY, float delta) { - super.renderButton(context, mouseX, mouseY, delta); + super.renderWidget(context, mouseX, mouseY, delta); RenderSystem.setShaderTexture(0, texture); @@ -30,7 +29,7 @@ public void renderButton(DrawContext context, int mouseX, int mouseY, float delt RenderSystem.enableBlend(); RenderSystem.defaultBlendFunc(); RenderSystem.blendFunc(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE_MINUS_SRC_ALPHA); - drawTexture(context, this.getX(), this.getY(), 0,0, 20, this.height, 20, 20); + context.drawGuiTexture(this.texture,this.getX(), this.getY(), 0,0, 20, this.height, 20, 20); } } diff --git a/src/main/java/tools/redstone/redstonetools/macros/gui/widget/commandlist/CommandListWidget.java b/src/main/java/tools/redstone/redstonetools/macros/gui/widget/commandlist/CommandListWidget.java index e855aa4f..c5e1b05a 100644 --- a/src/main/java/tools/redstone/redstonetools/macros/gui/widget/commandlist/CommandListWidget.java +++ b/src/main/java/tools/redstone/redstonetools/macros/gui/widget/commandlist/CommandListWidget.java @@ -24,11 +24,11 @@ public CommandListWidget(MinecraftClient client, MacroEditScreen parent, int wid addEntry(new CommandEntryPlaceHolder(client,this,"")); } - public void tick() { - for (CommandEntry entry : children()) { - entry.tick(); - } - } +// public void tick() { +// for (CommandEntry entry : children()) { +// entry.tick(); +// } +// } @@ -148,9 +148,10 @@ public CommandEntry(MinecraftClient client, CommandListWidget owner, String text command.setMaxLength(255); command.setText(text); - deleteButton = new IconButtonWidget(IconButtonWidget.CROSS_ICON,0, 0, 20, 20, Text.of(""), (button) -> { + + deleteButton = IconButtonWidget.builder(Text.of(""), (button) -> { this.owner.removeCommand(this); - }); + }).dimensions(0, 0, 20, 20).build(); MacroCommandSuggestor commandMacroCommandSuggestor = new MacroCommandSuggestor(client, owner.getParent(), command,client.textRenderer,true,false, 0,0,0); commandMacroCommandSuggestor.setWindowActive(false); @@ -176,9 +177,9 @@ public void render(DrawContext context, int index, int y, int x, int entryWidth, } } - public void tick() { - command.tick(); - } +// public void tick() { +// command.tick(); +// } private boolean edit = false; public void setFocused(boolean focused){ diff --git a/src/main/java/tools/redstone/redstonetools/macros/gui/widget/macrolist/MacroEntry.java b/src/main/java/tools/redstone/redstonetools/macros/gui/widget/macrolist/MacroEntry.java index 8426057e..d59750b4 100644 --- a/src/main/java/tools/redstone/redstonetools/macros/gui/widget/macrolist/MacroEntry.java +++ b/src/main/java/tools/redstone/redstonetools/macros/gui/widget/macrolist/MacroEntry.java @@ -1,15 +1,13 @@ package tools.redstone.redstonetools.macros.gui.widget.macrolist; import net.minecraft.client.gui.DrawContext; -import tools.redstone.redstonetools.macros.Macro; -import tools.redstone.redstonetools.macros.gui.widget.IconButtonWidget; import net.minecraft.client.gui.screen.ConfirmScreen; import net.minecraft.client.gui.widget.*; import net.minecraft.client.sound.PositionedSoundInstance; -import net.minecraft.client.util.math.MatrixStack; import net.minecraft.sound.SoundEvents; import net.minecraft.text.Text; -import net.minecraft.text.TranslatableTextContent; +import tools.redstone.redstonetools.macros.Macro; +import tools.redstone.redstonetools.macros.gui.widget.IconButtonWidget; public class MacroEntry extends AlwaysSelectedEntryListWidget.Entry{ @@ -25,13 +23,14 @@ public MacroEntry(Macro macro, MacroListWidget owner) { this.macro = macro; this.owner = owner; - buttonWidget = new CheckboxWidget(0, 0, 20, 20, null, macro.enabled, false); - deleteButton = new IconButtonWidget(IconButtonWidget.CROSS_ICON,0, 0, 20, 20 ,Text.of(""), (button) -> { + buttonWidget = CheckboxWidget.builder(null, null).build(); + buttonWidget.setDimensionsAndPosition(20,20,0,0); + deleteButton = IconButtonWidget.builder(Text.of(""), (button) -> { deleteIfConfirmed(); - }); - editButton = new IconButtonWidget(IconButtonWidget.PENCIL_ICON,0, 0, 20, 20, Text.of(""), (button) -> { + }).dimensions(0, 0, 20, 20).build(); + editButton = IconButtonWidget.builder(Text.of(""), (button) -> { owner.parent.openEditScreen(this); - }); + }).dimensions(0, 0, 20, 20).build(); } @@ -50,8 +49,7 @@ public void render(DrawContext context, int index, int y, int x, int entryWidth, text += "..."; } - - owner.client.textRenderer.drawWithShadow(context, text, x, y+3,macro.enabled?16777215:8355711, true); + context.drawTextWithShadow(owner.client.textRenderer,text,x,y+3,macro.enabled?16777215:8355711); } private void renderWidget(PressableWidget widget, DrawContext context, int mouseX, int mouseY, float tickDelta, int x, int y) { @@ -95,7 +93,7 @@ private void onPressed() { } public Text getNarration() { - return new TranslatableTextContent("narrator.select"); + return Text.translatable("narrator.select"); } diff --git a/src/main/java/tools/redstone/redstonetools/macros/gui/widget/macrolist/MacroListWidget.java b/src/main/java/tools/redstone/redstonetools/macros/gui/widget/macrolist/MacroListWidget.java index 73743d7a..477f2873 100644 --- a/src/main/java/tools/redstone/redstonetools/macros/gui/widget/macrolist/MacroListWidget.java +++ b/src/main/java/tools/redstone/redstonetools/macros/gui/widget/macrolist/MacroListWidget.java @@ -1,12 +1,11 @@ package tools.redstone.redstonetools.macros.gui.widget.macrolist; +import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.DrawContext; +import net.minecraft.client.gui.widget.AlwaysSelectedEntryListWidget; import tools.redstone.redstonetools.macros.Macro; import tools.redstone.redstonetools.macros.MacroManager; import tools.redstone.redstonetools.macros.gui.screen.MacroSelectScreen; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.widget.AlwaysSelectedEntryListWidget; -import net.minecraft.client.util.math.MatrixStack; import static tools.redstone.redstonetools.RedstoneToolsClient.INJECTOR; @@ -19,7 +18,7 @@ public class MacroListWidget extends AlwaysSelectedEntryListWidget { public MacroListWidget(MacroSelectScreen parent, MinecraftClient client) { - super(client, parent.width, parent.height, 20, parent.height - 42, 20); + super(client, parent.width, parent.height, 20, 20); this.parent = parent; this.client = client; diff --git a/src/main/java/tools/redstone/redstonetools/mixin/features/ItemBindMixin.java b/src/main/java/tools/redstone/redstonetools/mixin/features/ItemBindMixin.java index ce3c181a..085a813c 100644 --- a/src/main/java/tools/redstone/redstonetools/mixin/features/ItemBindMixin.java +++ b/src/main/java/tools/redstone/redstonetools/mixin/features/ItemBindMixin.java @@ -2,7 +2,6 @@ import net.minecraft.client.MinecraftClient; import net.minecraft.client.network.ClientPlayNetworkHandler; -import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.entity.Entity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; @@ -26,6 +25,7 @@ import static tools.redstone.redstonetools.RedstoneToolsClient.INJECTOR; + public abstract class ItemBindMixin { @Mixin(ItemStack.class) @@ -35,8 +35,7 @@ private abstract static class ItemStackMixin { public abstract @Nullable NbtCompound getNbt(); @Inject(method = "use", at = @At("HEAD"), cancellable = true) - public void checkCommandNBT(World world, PlayerEntity user, Hand hand, - CallbackInfoReturnable> cir) { + public void checkCommandNBT(World world, PlayerEntity user, Hand hand, CallbackInfoReturnable> cir) { if (tryToExecuteNBTCommand(hand, world)) { cir.setReturnValue(TypedActionResult.pass((ItemStack) ((Object) this))); } @@ -50,33 +49,31 @@ public void checkCommandNBT(ItemUsageContext context, CallbackInfoReturnable { + ButtonWidget buttonWidget = ButtonWidget.builder(Text.of("Macros..."), (button) -> { this.client.setScreen(new MacroSelectScreen(this,super.gameOptions,Text.of("Macros"))); - })); + }).dimensions(this.width / 2 + 5, this.height / 6 + 36, 150, 20).build(); + this.addDrawableChild(buttonWidget); } }