Skip to content

Commit

Permalink
fixed trch off button texture, added better tooltip system for switch…
Browse files Browse the repository at this point in the history
… and cycle buttons
  • Loading branch information
Trinsdar committed Sep 14, 2023
1 parent 9ed4523 commit 9413718
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions common/src/main/java/muramasa/antimatter/gui/GuiInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<IGuiHandler> 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<IGuiHandler> syncFunction, Function<Boolean, String> tooltipKeyFunction) {
addWidget(SwitchButtonWidget.build(bodyOff, bodyOn, syncFunction, GuiEvents.EXTRA_BUTTON, buttonCounter++, tooltipKeyFunction).setSize(x, y, w, h));
return this;
}

Expand All @@ -210,7 +210,7 @@ public GuiInstance addCycleButton(int x, int y, int w, int h, ToIntFunction<IGui
return this;
}

public GuiInstance addCycleButton(int x, int y, int w, int h, ToIntFunction<IGuiHandler> syncFunction, String tooltipKey, ButtonOverlay... buttons) {
public GuiInstance addCycleButton(int x, int y, int w, int h, ToIntFunction<IGuiHandler> syncFunction, IntFunction<String> tooltipKey, ButtonOverlay... buttons) {
addWidget(CycleButtonWidget.build(syncFunction, GuiEvents.EXTRA_BUTTON, buttonCounter++, tooltipKey, buttons).setSize(x, y, w, h));
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
public class CycleButtonWidget extends ButtonWidget{
final ButtonOverlay[] buttons;
final ToIntFunction<IGuiHandler> syncFunction;
protected IntFunction<String> tooltipKeyFunction;
int state = 0;
public CycleButtonWidget(GuiInstance instance, IGuiElement parent, @Nullable Consumer<ButtonWidget> onPress, ToIntFunction<IGuiHandler> syncFunction, ButtonOverlay... buttons) {
super(instance, parent, buttons[0], onPress);
Expand All @@ -32,11 +33,21 @@ protected ButtonOverlay getBody() {
return buttons[state];
}

@Override
protected String getTooltipKey() {
return tooltipKeyFunction.apply(state);
}

public CycleButtonWidget setTooltipKeyFunction(IntFunction<String> tooltipKeyFunction) {
this.tooltipKeyFunction = tooltipKeyFunction;
return this;
}

public static WidgetSupplier build(ToIntFunction<IGuiHandler> 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<IGuiHandler> syncFunction, IGuiEvent.IGuiEventFactory ev, int id, String tooltipKey, ButtonOverlay... buttons) {
public static WidgetSupplier build(ToIntFunction<IGuiHandler> syncFunction, IGuiEvent.IGuiEventFactory ev, int id, IntFunction<String> 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)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<IGuiHandler> syncFunction;
protected Function<Boolean, String> tooltipKeyFunction;
boolean on = false;
public SwitchButtonWidget(GuiInstance instance, IGuiElement parent, @NotNull ButtonOverlay bodyOff, @NotNull ButtonOverlay bodyOn, @Nullable Consumer<ButtonWidget> onPress, Predicate<IGuiHandler> syncFunction) {
super(instance, parent, bodyOff, onPress);
Expand All @@ -36,11 +38,21 @@ protected ButtonOverlay getBody() {
return on ? bodyOn : bodyOff;
}

@Override
protected String getTooltipKey() {
return tooltipKeyFunction.apply(on);
}

public SwitchButtonWidget setTooltipKeyFunction(Function<Boolean, String> tooltipKeyFunction) {
this.tooltipKeyFunction = tooltipKeyFunction;
return this;
}

public static WidgetSupplier build(ButtonOverlay bodyOff, ButtonOverlay bodyOn, Predicate<IGuiHandler> 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<IGuiHandler> 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<IGuiHandler> syncFunction, IGuiEvent.IGuiEventFactory ev, int id, Function<Boolean, String> 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)));
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 9413718

Please sign in to comment.