Skip to content

Commit d9df0bb

Browse files
committed
Use constants for certain true false displays
1 parent 26c2e68 commit d9df0bb

File tree

8 files changed

+30
-14
lines changed

8 files changed

+30
-14
lines changed

src/main/java/mekanism/client/gui/GuiDimensionalStabilizer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ public void updateTooltip(int mouseX, int mouseY) {
108108
addRenderableWidget(new TooltipColorButton(this, 63 + 10 * shiftedX, 19 + 10 * shiftedZ, 10, EnumColor.DARK_BLUE,
109109
() -> tile.isChunkLoadingAt(shiftedX, shiftedZ),
110110
(element, mouseX, mouseY) -> PacketUtils.sendToServer(new PacketGuiInteract(GuiInteraction.TOGGLE_CHUNKLOAD, tile, packetTarget)),
111-
MekanismLang.STABILIZER_TOGGLE_LOADING.translate(OnOff.of(true, true), EnumColor.INDIGO, chunkX, EnumColor.INDIGO, chunkZ),
112-
MekanismLang.STABILIZER_TOGGLE_LOADING.translate(OnOff.of(false, true), EnumColor.INDIGO, chunkX, EnumColor.INDIGO, chunkZ)
111+
MekanismLang.STABILIZER_TOGGLE_LOADING.translate(OnOff.ON_COLORED, EnumColor.INDIGO, chunkX, EnumColor.INDIGO, chunkZ),
112+
MekanismLang.STABILIZER_TOGGLE_LOADING.translate(OnOff.OFF_COLORED, EnumColor.INDIGO, chunkX, EnumColor.INDIGO, chunkZ)
113113
));
114114
}
115115
}

src/main/java/mekanism/client/gui/GuiSecurityDesk.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ protected void addGuiElements() {
120120
PacketUtils.sendToServer(new PacketGuiInteract(GuiInteraction.OVERRIDE_BUTTON, desk.tile));
121121
desk.updateButtons();
122122
return true;
123-
}, MekanismLang.SECURITY_OVERRIDE.translate(OnOff.of(true)), MekanismLang.SECURITY_OVERRIDE.translate(OnOff.of(false))));
123+
}, MekanismLang.SECURITY_OVERRIDE.translate(OnOff.ON), MekanismLang.SECURITY_OVERRIDE.translate(OnOff.OFF)));
124124
updateButtons();
125125
}
126126

src/main/java/mekanism/client/gui/element/tab/GuiVisualsTab.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717

1818
public class GuiVisualsTab extends GuiInsetElement<IHasVisualization> {
1919

20-
private static final Component ON = MekanismLang.VISUALS.translate(OnOff.of(true));
21-
private static final Component OFF = MekanismLang.VISUALS.translate(OnOff.of(false));
20+
private static final Component ON = MekanismLang.VISUALS.translate(OnOff.ON);
21+
private static final Component OFF = MekanismLang.VISUALS.translate(OnOff.OFF);
2222
private static final Component TOO_BIG = MekanismLang.VISUALS_TOO_BIG.translateColored(EnumColor.RED);
2323
private static final Tooltip VISUALS_ON = Tooltip.create(ON);
2424
private static final Tooltip VISUALS_OFF = Tooltip.create(OFF);

src/main/java/mekanism/client/gui/element/window/filter/miner/GuiMinerFilterHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ default void addMinerDefaults(IGuiWrapper gui, int slotOffset, UnaryOperator<Gui
3737
MinerFilter<?> filter = getFilter();
3838
filter.requiresReplacement = !filter.requiresReplacement;
3939
return true;
40-
}, MekanismLang.MINER_REQUIRE_REPLACE.translate(YesNo.of(true)), MekanismLang.MINER_REQUIRE_REPLACE.translate(YesNo.of(false))));
40+
}, MekanismLang.MINER_REQUIRE_REPLACE.translate(YesNo.YES), MekanismLang.MINER_REQUIRE_REPLACE.translate(YesNo.NO)));
4141
}
4242

4343
@Override

src/main/java/mekanism/client/gui/element/window/filter/transporter/GuiSorterFilterHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ default void renderSorterForeground(GuiGraphics guiGraphics) {
8484
drawString(guiGraphics, MekanismLang.MIN.translate(""), relativeX + 148, relativeY + 32, titleTextColor());
8585
drawString(guiGraphics, MekanismLang.MAX.translate(""), relativeX + 148, relativeY + 44, titleTextColor());
8686
if (isSingleItem() && filter.sizeMode) {
87-
drawString(guiGraphics, MekanismLang.SORTER_FILTER_SIZE_MODE.translateColored(EnumColor.RED, OnOff.of(true)), relativeX + 161, relativeY + 58, titleTextColor());
87+
drawString(guiGraphics, MekanismLang.SORTER_FILTER_SIZE_MODE.translateColored(EnumColor.RED, OnOff.ON), relativeX + 161, relativeY + 58, titleTextColor());
8888
} else {
8989
drawString(guiGraphics, OnOff.of(filter.sizeMode).getTextComponent(), relativeX + 161, relativeY + 58, titleTextColor());
9090
}

src/main/java/mekanism/client/gui/machine/GuiDigitalMinerConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ protected void addGuiElements() {
101101
});
102102
addRenderableWidget(new TooltipToggleButton(this, 35, 137, 14, 16, getButtonLocation("exclamation"), tile::getInverseRequiresReplacement,
103103
(element, mouseX, mouseY) -> PacketUtils.sendToServer(new PacketGuiInteract(GuiInteraction.INVERSE_REQUIRES_REPLACEMENT_BUTTON, ((GuiDigitalMinerConfig) element.gui()).tile)),
104-
MekanismLang.MINER_REQUIRE_REPLACE_INVERSE.translate(YesNo.of(true)), MekanismLang.MINER_REQUIRE_REPLACE_INVERSE.translate(false)));
104+
MekanismLang.MINER_REQUIRE_REPLACE_INVERSE.translate(YesNo.YES), MekanismLang.MINER_REQUIRE_REPLACE_INVERSE.translate(YesNo.NO)));
105105
radiusField = addRenderableWidget(new GuiTextField(this, 13, 45, 38, 11));
106106
radiusField.setMaxLength(Integer.toString(MekanismConfig.general.minerMaxRadius.get()).length());
107107
radiusField.setInputValidator(InputValidator.DIGIT);

src/main/java/mekanism/client/gui/machine/GuiFormulaicAssemblicator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ protected void addGuiElements() {
6767
.setTooltip(MekanismLang.ENCODE_FORMULA);
6868
stockControlButton = addRenderableWidget(new TooltipToggleButton(this, 26, 75, 16, getButtonLocation("stock_control"), tile::getStockControl,
6969
(element, mouseX, mouseY) -> PacketUtils.sendToServer(new PacketGuiInteract(GuiInteraction.STOCK_CONTROL_BUTTON, ((GuiFormulaicAssemblicator) element.gui()).tile)),
70-
MekanismLang.STOCK_CONTROL.translate(OnOff.of(true)), MekanismLang.STOCK_CONTROL.translate(OnOff.of(false))));
70+
MekanismLang.STOCK_CONTROL.translate(OnOff.ON), MekanismLang.STOCK_CONTROL.translate(OnOff.OFF)));
7171
fillEmptyButton = addRenderableWidget(new ToggleButton(this, 44, 75, 16, 16, getButtonLocation("empty"),
7272
getButtonLocation("fill"), () -> tile.formula == null, (element, mouseX, mouseY) -> {
7373
TileEntityFormulaicAssemblicator tile = ((GuiFormulaicAssemblicator) element.gui()).tile;
@@ -82,7 +82,7 @@ protected void addGuiElements() {
8282
.setTooltip(MekanismLang.CRAFT_AVAILABLE);
8383
autoModeButton = addRenderableWidget(new TooltipToggleButton(this, 107, 75, 16, getButtonLocation("auto_toggle"), tile::getAutoMode,
8484
(element, mouseX, mouseY) -> PacketUtils.sendToServer(new PacketGuiInteract(GuiInteraction.NEXT_MODE, ((GuiFormulaicAssemblicator) element.gui()).tile)),
85-
MekanismLang.AUTO_MODE.translate(OnOff.of(true)), MekanismLang.AUTO_MODE.translate(OnOff.of(false))));
85+
MekanismLang.AUTO_MODE.translate(OnOff.ON), MekanismLang.AUTO_MODE.translate(OnOff.OFF)));
8686
updateEnabledButtons();
8787
}
8888

src/main/java/mekanism/common/util/text/BooleanStateDisplay.java

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,28 @@ public Component getTextComponent() {
3232

3333
public static class YesNo extends BooleanStateDisplay {
3434

35+
public static final YesNo YES = new YesNo(true, false);
36+
public static final YesNo NO = new YesNo(false, false);
37+
public static final YesNo YES_COLORED = new YesNo(true, true);
38+
public static final YesNo NO_COLORED = new YesNo(false, true);
39+
3540
private YesNo(boolean value, boolean colored) {
3641
super(value, colored);
3742
}
3843

3944
public static YesNo of(boolean value) {
40-
return of(value, false);
45+
return value ? YES : NO;
4146
}
4247

4348
public static YesNo hasInventory(ItemStack stack) {
4449
return of(ContainerType.ITEM.getAttachmentContainersIfPresent(stack).stream().anyMatch(slot -> !slot.isEmpty()), true);
4550
}
4651

4752
public static YesNo of(boolean value, boolean colored) {
48-
return new YesNo(value, colored);
53+
if (colored) {
54+
return value ? YES_COLORED : NO_COLORED;
55+
}
56+
return of(value);
4957
}
5058

5159
@Override
@@ -56,6 +64,11 @@ protected ILangEntry getLangEntry() {
5664

5765
public static class OnOff extends BooleanStateDisplay {
5866

67+
public static final OnOff ON = new OnOff(true, false, false);
68+
public static final OnOff OFF = new OnOff(false, false, false);
69+
public static final OnOff ON_COLORED = new OnOff(true, true, false);
70+
public static final OnOff OFF_COLORED = new OnOff(false, true, false);
71+
5972
private final boolean caps;
6073

6174
private OnOff(boolean value, boolean colored, boolean caps) {
@@ -64,11 +77,14 @@ private OnOff(boolean value, boolean colored, boolean caps) {
6477
}
6578

6679
public static OnOff of(boolean value) {
67-
return of(value, false);
80+
return value ? ON : OFF;
6881
}
6982

7083
public static OnOff of(boolean value, boolean colored) {
71-
return new OnOff(value, colored, false);
84+
if (colored) {
85+
return value ? ON_COLORED : OFF_COLORED;
86+
}
87+
return of(value);
7288
}
7389

7490
public static OnOff caps(boolean value, boolean colored) {

0 commit comments

Comments
 (0)