Skip to content

Commit

Permalink
Fixed all the GUI errors
Browse files Browse the repository at this point in the history
  • Loading branch information
maghedo243 committed Jan 4, 2024
1 parent 6e300a5 commit cc6724b
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 74 deletions.
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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);

Expand All @@ -49,7 +48,6 @@ public void render(DrawContext context, int mouseX, int mouseY, float delta) {
@Override
public void tick() {
super.tick();
commandField.tick();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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 -> {
Expand All @@ -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);
Expand All @@ -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) {
Expand Down Expand Up @@ -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()) {
Expand All @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {

Expand All @@ -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);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand All @@ -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);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
// }
// }



Expand Down Expand Up @@ -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);
Expand All @@ -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){
Expand Down
Original file line number Diff line number Diff line change
@@ -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<MacroEntry>{

Expand All @@ -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();
}


Expand All @@ -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) {
Expand Down Expand Up @@ -95,7 +93,7 @@ private void onPressed() {
}

public Text getNarration() {
return new TranslatableTextContent("narrator.select");
return Text.translatable("narrator.select");
}


Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -19,7 +18,7 @@ public class MacroListWidget extends AlwaysSelectedEntryListWidget<MacroEntry> {


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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -26,6 +25,7 @@

import static tools.redstone.redstonetools.RedstoneToolsClient.INJECTOR;


public abstract class ItemBindMixin {

@Mixin(ItemStack.class)
Expand All @@ -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<TypedActionResult<ItemStack>> cir) {
public void checkCommandNBT(World world, PlayerEntity user, Hand hand, CallbackInfoReturnable<TypedActionResult<ItemStack>> cir) {
if (tryToExecuteNBTCommand(hand, world)) {
cir.setReturnValue(TypedActionResult.pass((ItemStack) ((Object) this)));
}
Expand All @@ -50,33 +49,31 @@ public void checkCommandNBT(ItemUsageContext context, CallbackInfoReturnable<Act
}

private boolean tryToExecuteNBTCommand(Hand hand, World world) {
if (hand == Hand.OFF_HAND || world.isClient)
return false;
if (hand == Hand.OFF_HAND || world.isClient) return false;
NbtCompound nbt = getNbt();
if (nbt == null || !nbt.contains("command"))
return false;
if (nbt == null || !nbt.contains("command")) return false;
NbtString command = (NbtString) nbt.get("command");
MinecraftClient.getInstance().player.networkHandler.sendChatCommand(command.asString());
MinecraftClient.getInstance().getNetworkHandler().sendChatMessage(command.asString());

return true;
}
}


@Mixin(ClientPlayNetworkHandler.class)
private abstract static class NetworkHandlerMixin {
private abstract static class PlayerMixin {

@Inject(method = "sendChatCommand", at = @At("HEAD"), cancellable = true)
@Inject(method = "sendChatMessage", at = @At("HEAD"), cancellable = true)
public void injectCommand(String message, CallbackInfo ci) {
if (!ItemBindFeature.waitingForCommand)
return;
if (!message.startsWith("/") || !ItemBindFeature.waitingForCommand) return;

Feedback addCommandFeedback = ItemBindFeature.addCommand(message);
if (addCommandFeedback != null) {
INJECTOR.getInstance(FeedbackSender.class).sendFeedback(((Entity) ((Object) this)).getCommandSource(),
addCommandFeedback);
INJECTOR.getInstance(FeedbackSender.class).sendFeedback(((Entity) ((Object)this)).getCommandSource(),addCommandFeedback);
ci.cancel();
}
}
}


}
Loading

0 comments on commit cc6724b

Please sign in to comment.