diff --git a/common/src/main/java/muramasa/antimatter/gui/ButtonOverlay.java b/common/src/main/java/muramasa/antimatter/gui/ButtonOverlay.java index 9635fc58f..171d7acd0 100644 --- a/common/src/main/java/muramasa/antimatter/gui/ButtonOverlay.java +++ b/common/src/main/java/muramasa/antimatter/gui/ButtonOverlay.java @@ -7,10 +7,9 @@ public class ButtonOverlay implements IAntimatterObject { public static ButtonOverlay STOP = new ButtonOverlay(Ref.ID,"stop",16, 16); - public static ButtonOverlay TORCH_OFF = new ButtonOverlay(Ref.ID,"torch_off",16, 16) - .setTextureOverride(new ResourceLocation("textures/block/redstone_torch_off.png")); + public static ButtonOverlay TORCH_OFF = new ButtonOverlay(Ref.ID,"torch_off",16, 16); public static ButtonOverlay TORCH_ON = new ButtonOverlay(Ref.ID,"torch_on",16, 16) - .setTextureOverride(new ResourceLocation("textures/block/redstone_torch.png")); + .setTextureOverride(new ResourceLocation("textures/item/redstone_torch.png")); public static ButtonOverlay REDSTONE = new ButtonOverlay(Ref.ID, "redstone", 16, 16) .setTextureOverride(new ResourceLocation("textures/item/redstone.png")); public static ButtonOverlay EXPORT = new ButtonOverlay(Ref.ID,"export",16, 16); diff --git a/common/src/main/java/muramasa/antimatter/gui/GuiInstance.java b/common/src/main/java/muramasa/antimatter/gui/GuiInstance.java index a92ac9a72..6943396c0 100644 --- a/common/src/main/java/muramasa/antimatter/gui/GuiInstance.java +++ b/common/src/main/java/muramasa/antimatter/gui/GuiInstance.java @@ -200,8 +200,8 @@ public GuiInstance addSwitchButton(int x, int y, int w, int h, ButtonOverlay bod return this; } - public GuiInstance addSwitchButton(int x, int y, int w, int h, ButtonOverlay bodyOff, ButtonOverlay bodyOn, Predicate syncFunction, String tooltipKey) { - addWidget(SwitchButtonWidget.build(bodyOff, bodyOn, syncFunction, GuiEvents.EXTRA_BUTTON, buttonCounter++, tooltipKey).setSize(x, y, w, h)); + public GuiInstance addSwitchButton(int x, int y, int w, int h, ButtonOverlay bodyOff, ButtonOverlay bodyOn, Predicate syncFunction, Function tooltipKeyFunction) { + addWidget(SwitchButtonWidget.build(bodyOff, bodyOn, syncFunction, GuiEvents.EXTRA_BUTTON, buttonCounter++, tooltipKeyFunction).setSize(x, y, w, h)); return this; } @@ -210,7 +210,7 @@ public GuiInstance addCycleButton(int x, int y, int w, int h, ToIntFunction syncFunction, String tooltipKey, ButtonOverlay... buttons) { + public GuiInstance addCycleButton(int x, int y, int w, int h, ToIntFunction syncFunction, IntFunction tooltipKey, ButtonOverlay... buttons) { addWidget(CycleButtonWidget.build(syncFunction, GuiEvents.EXTRA_BUTTON, buttonCounter++, tooltipKey, buttons).setSize(x, y, w, h)); return this; } diff --git a/common/src/main/java/muramasa/antimatter/gui/widget/ButtonWidget.java b/common/src/main/java/muramasa/antimatter/gui/widget/ButtonWidget.java index 2a865abee..95f7ecf47 100644 --- a/common/src/main/java/muramasa/antimatter/gui/widget/ButtonWidget.java +++ b/common/src/main/java/muramasa/antimatter/gui/widget/ButtonWidget.java @@ -83,11 +83,15 @@ protected void clientClick() { @Override public void mouseOver(PoseStack stack, double mouseX, double mouseY, float partialTicks) { super.mouseOver(stack, mouseX, mouseY, partialTicks); - if (tooltipKey != null){ - renderTooltip(stack,new TranslatableComponent(tooltipKey), mouseX, mouseY); + if (getTooltipKey() != null){ + renderTooltip(stack,new TranslatableComponent(getTooltipKey()), mouseX, mouseY); } } + protected String getTooltipKey(){ + return tooltipKey; + } + @Override public void render(PoseStack matrixStack, double mouseX, double mouseY, float partialTicks) { Minecraft minecraft = Minecraft.getInstance(); diff --git a/common/src/main/java/muramasa/antimatter/gui/widget/CycleButtonWidget.java b/common/src/main/java/muramasa/antimatter/gui/widget/CycleButtonWidget.java index 7ea105f83..7b3f75787 100644 --- a/common/src/main/java/muramasa/antimatter/gui/widget/CycleButtonWidget.java +++ b/common/src/main/java/muramasa/antimatter/gui/widget/CycleButtonWidget.java @@ -15,6 +15,7 @@ public class CycleButtonWidget extends ButtonWidget{ final ButtonOverlay[] buttons; final ToIntFunction syncFunction; + protected IntFunction tooltipKeyFunction; int state = 0; public CycleButtonWidget(GuiInstance instance, IGuiElement parent, @Nullable Consumer onPress, ToIntFunction syncFunction, ButtonOverlay... buttons) { super(instance, parent, buttons[0], onPress); @@ -32,11 +33,21 @@ protected ButtonOverlay getBody() { return buttons[state]; } + @Override + protected String getTooltipKey() { + return tooltipKeyFunction.apply(state); + } + + public CycleButtonWidget setTooltipKeyFunction(IntFunction tooltipKeyFunction) { + this.tooltipKeyFunction = tooltipKeyFunction; + return this; + } + public static WidgetSupplier build(ToIntFunction syncFunction, IGuiEvent.IGuiEventFactory ev, int id, ButtonOverlay... buttons) { return builder(((a, b) -> new CycleButtonWidget(a, b, but -> but.gui.sendPacket(but.gui.handler.createGuiPacket(new GuiEvents.GuiEvent(ev, Screen.hasShiftDown() ? 1 : 0, id))), syncFunction, buttons))); } - public static WidgetSupplier build(ToIntFunction syncFunction, IGuiEvent.IGuiEventFactory ev, int id, String tooltipKey, ButtonOverlay... buttons) { + public static WidgetSupplier build(ToIntFunction syncFunction, IGuiEvent.IGuiEventFactory ev, int id, IntFunction tooltipKey, ButtonOverlay... buttons) { return builder(((a, b) -> new CycleButtonWidget(a, b, but -> but.gui.sendPacket(but.gui.handler.createGuiPacket(new GuiEvents.GuiEvent(ev, Screen.hasShiftDown() ? 1 : 0, id))), syncFunction, buttons).setTooltipKey(tooltipKey))); } } diff --git a/common/src/main/java/muramasa/antimatter/gui/widget/SwitchButtonWidget.java b/common/src/main/java/muramasa/antimatter/gui/widget/SwitchButtonWidget.java index a46a219c7..9c5b0f767 100644 --- a/common/src/main/java/muramasa/antimatter/gui/widget/SwitchButtonWidget.java +++ b/common/src/main/java/muramasa/antimatter/gui/widget/SwitchButtonWidget.java @@ -12,12 +12,14 @@ import org.jetbrains.annotations.Nullable; import java.util.function.Consumer; +import java.util.function.Function; import java.util.function.Predicate; public class SwitchButtonWidget extends ButtonWidget{ final ButtonOverlay bodyOff; final ButtonOverlay bodyOn; final Predicate syncFunction; + protected Function tooltipKeyFunction; boolean on = false; public SwitchButtonWidget(GuiInstance instance, IGuiElement parent, @NotNull ButtonOverlay bodyOff, @NotNull ButtonOverlay bodyOn, @Nullable Consumer onPress, Predicate syncFunction) { super(instance, parent, bodyOff, onPress); @@ -36,11 +38,21 @@ protected ButtonOverlay getBody() { return on ? bodyOn : bodyOff; } + @Override + protected String getTooltipKey() { + return tooltipKeyFunction.apply(on); + } + + public SwitchButtonWidget setTooltipKeyFunction(Function tooltipKeyFunction) { + this.tooltipKeyFunction = tooltipKeyFunction; + return this; + } + public static WidgetSupplier build(ButtonOverlay bodyOff, ButtonOverlay bodyOn, Predicate syncFunction, IGuiEvent.IGuiEventFactory ev, int id) { return builder(((a, b) -> new SwitchButtonWidget(a, b, bodyOff, bodyOn, but -> but.gui.sendPacket(but.gui.handler.createGuiPacket(new GuiEvents.GuiEvent(ev, Screen.hasShiftDown() ? 1 : 0, id))), syncFunction))); } - public static WidgetSupplier build(ButtonOverlay bodyOff, ButtonOverlay bodyOn, Predicate syncFunction, IGuiEvent.IGuiEventFactory ev, int id, String tooltipKey) { - return builder(((a, b) -> new SwitchButtonWidget(a, b, bodyOff, bodyOn, but -> but.gui.sendPacket(but.gui.handler.createGuiPacket(new GuiEvents.GuiEvent(ev, Screen.hasShiftDown() ? 1 : 0, id))), syncFunction).setTooltipKey(tooltipKey))); + public static WidgetSupplier build(ButtonOverlay bodyOff, ButtonOverlay bodyOn, Predicate syncFunction, IGuiEvent.IGuiEventFactory ev, int id, Function tooltipKeyFunction) { + return builder(((a, b) -> new SwitchButtonWidget(a, b, bodyOff, bodyOn, but -> but.gui.sendPacket(but.gui.handler.createGuiPacket(new GuiEvents.GuiEvent(ev, Screen.hasShiftDown() ? 1 : 0, id))), syncFunction).setTooltipKeyFunction(tooltipKeyFunction))); } } diff --git a/common/src/main/resources/assets/antimatter/textures/gui/button/torch_off.png b/common/src/main/resources/assets/antimatter/textures/gui/button/torch_off.png new file mode 100644 index 000000000..df609e184 Binary files /dev/null and b/common/src/main/resources/assets/antimatter/textures/gui/button/torch_off.png differ