diff --git a/src/main/java/mcjty/xnet/apiimpl/energy/EnergyConnectorSettings.java b/src/main/java/mcjty/xnet/apiimpl/energy/EnergyConnectorSettings.java index 47a603a0..68c8c59b 100644 --- a/src/main/java/mcjty/xnet/apiimpl/energy/EnergyConnectorSettings.java +++ b/src/main/java/mcjty/xnet/apiimpl/energy/EnergyConnectorSettings.java @@ -94,7 +94,7 @@ public void createGui(IEditorGui gui) { colorsGui(gui); redstoneGui(gui); gui.nl(); - ((ConnectorEditorPanel) gui).translatableChoices(TAG_MODE, energyMode, InsExtMode.values());// TODO: 09.03.2024 remove ConnectorEditorPanel cast after rftoolbase update + gui.translatableChoices(TAG_MODE, energyMode, InsExtMode.values()); gui.nl() .label(PRIORITY_LABEL.i18n()).integer(TAG_PRIORITY, PRIORITY_TOOLTIP.i18n(), priority, 30).nl() diff --git a/src/main/java/mcjty/xnet/apiimpl/enums/InsExtMode.java b/src/main/java/mcjty/xnet/apiimpl/enums/InsExtMode.java index 26e581c5..8399b855 100644 --- a/src/main/java/mcjty/xnet/apiimpl/enums/InsExtMode.java +++ b/src/main/java/mcjty/xnet/apiimpl/enums/InsExtMode.java @@ -1,8 +1,8 @@ package mcjty.xnet.apiimpl.enums; import mcjty.lib.varia.ComponentFactory; +import mcjty.lib.gui.ITranslatableEnum; import mcjty.xnet.utils.I18nUtils; -import mcjty.xnet.utils.ITranslatableEnum; public enum InsExtMode implements ITranslatableEnum { INS("xnet.enum.insextmode.ins"), diff --git a/src/main/java/mcjty/xnet/apiimpl/items/enums/ExtractMode.java b/src/main/java/mcjty/xnet/apiimpl/items/enums/ExtractMode.java index 8dbafdfa..5c1c6004 100644 --- a/src/main/java/mcjty/xnet/apiimpl/items/enums/ExtractMode.java +++ b/src/main/java/mcjty/xnet/apiimpl/items/enums/ExtractMode.java @@ -1,8 +1,8 @@ package mcjty.xnet.apiimpl.items.enums; import mcjty.lib.varia.ComponentFactory; +import mcjty.lib.gui.ITranslatableEnum; import mcjty.xnet.utils.I18nUtils; -import mcjty.xnet.utils.ITranslatableEnum; public enum ExtractMode implements ITranslatableEnum { FIRST("xnet.enum.items.extractmode.first"), diff --git a/src/main/java/mcjty/xnet/apiimpl/items/enums/StackMode.java b/src/main/java/mcjty/xnet/apiimpl/items/enums/StackMode.java index 2944b02e..b784b01b 100644 --- a/src/main/java/mcjty/xnet/apiimpl/items/enums/StackMode.java +++ b/src/main/java/mcjty/xnet/apiimpl/items/enums/StackMode.java @@ -1,8 +1,8 @@ package mcjty.xnet.apiimpl.items.enums; import mcjty.lib.varia.ComponentFactory; +import mcjty.lib.gui.ITranslatableEnum; import mcjty.xnet.utils.I18nUtils; -import mcjty.xnet.utils.ITranslatableEnum; public enum StackMode implements ITranslatableEnum { SINGLE("xnet.enum.items.stackmode.single"), diff --git a/src/main/java/mcjty/xnet/apiimpl/logic/LogicConnectorSettings.java b/src/main/java/mcjty/xnet/apiimpl/logic/LogicConnectorSettings.java index 0974a66e..f1d8b1bc 100644 --- a/src/main/java/mcjty/xnet/apiimpl/logic/LogicConnectorSettings.java +++ b/src/main/java/mcjty/xnet/apiimpl/logic/LogicConnectorSettings.java @@ -131,15 +131,13 @@ public void createGui(IEditorGui gui) { sideGui(gui); colorsGui(gui); redstoneGui(gui); - gui.nl(); - ((ConnectorEditorPanel)gui).translatableChoices(TAG_MODE, logicMode, LogicMode.values());// TODO: 09.03.2024 remove ConnectorEditorPanel cast after rftoolbase update - gui.nl(); + gui.nl().translatableChoices(TAG_MODE, logicMode, LogicMode.values()).nl(); if (logicMode == LogicMode.SENSOR) { for (RSSensor sensor : sensors) { sensor.createGui(gui); } } else { - output.createGui((ConnectorEditorPanel) gui); // TODO: 06.03.2024 remove ConnectorEditorPanel cast after rftoolbase update + output.createGui(gui); } } diff --git a/src/main/java/mcjty/xnet/apiimpl/logic/RSOutput.java b/src/main/java/mcjty/xnet/apiimpl/logic/RSOutput.java index 3bc01db2..bcbf6b9f 100644 --- a/src/main/java/mcjty/xnet/apiimpl/logic/RSOutput.java +++ b/src/main/java/mcjty/xnet/apiimpl/logic/RSOutput.java @@ -1,8 +1,8 @@ package mcjty.xnet.apiimpl.logic; import mcjty.rftoolsbase.api.xnet.channels.Color; +import mcjty.rftoolsbase.api.xnet.gui.IEditorGui; import mcjty.xnet.apiimpl.logic.enums.LogicFilter; -import mcjty.xnet.modules.controller.client.ConnectorEditorPanel; import mcjty.xnet.utils.CastTools; import net.minecraft.nbt.CompoundTag; @@ -135,7 +135,7 @@ public void setRedstoneOut(int redstoneOut) { this.redstoneOut = redstoneOut; } - public void createGui(ConnectorEditorPanel gui) {// TODO: 09.03.2024 remove ConnectorEditorPanel cast after rftoolbase update + public void createGui(IEditorGui gui) { if (gui.isAdvanced()) { gui.translatableChoices(TAG_RS_FILTER, logicFilter, LogicFilter.values()); switch (logicFilter) { diff --git a/src/main/java/mcjty/xnet/apiimpl/logic/RSSensor.java b/src/main/java/mcjty/xnet/apiimpl/logic/RSSensor.java index 566fd80a..5a59916b 100644 --- a/src/main/java/mcjty/xnet/apiimpl/logic/RSSensor.java +++ b/src/main/java/mcjty/xnet/apiimpl/logic/RSSensor.java @@ -112,7 +112,7 @@ public boolean isEnabled(String tag) { } public void createGui(IEditorGui gui) { - ((AbstractEditorPanel)gui).translatableChoices(TAG_MODE + index, sensorMode, SensorMode.values()); + gui.translatableChoices(TAG_MODE + index, sensorMode, SensorMode.values()); gui .choices(TAG_OP + index, LOGIC_SENSOR_OPERATOR_TOOLTIP.i18n(), operator, Operator.values()) .integer(TAG_AMOUNT + index, LOGIC_SENSOR_AMOUNT_TOOLTIP.i18n(), amount, 46) diff --git a/src/main/java/mcjty/xnet/apiimpl/logic/enums/LogicFilter.java b/src/main/java/mcjty/xnet/apiimpl/logic/enums/LogicFilter.java index 2d56e899..b581efef 100644 --- a/src/main/java/mcjty/xnet/apiimpl/logic/enums/LogicFilter.java +++ b/src/main/java/mcjty/xnet/apiimpl/logic/enums/LogicFilter.java @@ -1,7 +1,7 @@ package mcjty.xnet.apiimpl.logic.enums; +import mcjty.lib.gui.ITranslatableEnum; import mcjty.xnet.utils.I18nUtils; -import mcjty.xnet.utils.ITranslatableEnum; import org.apache.commons.lang3.StringUtils; public enum LogicFilter implements ITranslatableEnum { diff --git a/src/main/java/mcjty/xnet/apiimpl/logic/enums/LogicMode.java b/src/main/java/mcjty/xnet/apiimpl/logic/enums/LogicMode.java index ddacc86c..96abb21b 100644 --- a/src/main/java/mcjty/xnet/apiimpl/logic/enums/LogicMode.java +++ b/src/main/java/mcjty/xnet/apiimpl/logic/enums/LogicMode.java @@ -2,8 +2,8 @@ import mcjty.lib.varia.ComponentFactory; +import mcjty.lib.gui.ITranslatableEnum; import mcjty.xnet.utils.I18nUtils; -import mcjty.xnet.utils.ITranslatableEnum; public enum LogicMode implements ITranslatableEnum { diff --git a/src/main/java/mcjty/xnet/apiimpl/logic/enums/SensorMode.java b/src/main/java/mcjty/xnet/apiimpl/logic/enums/SensorMode.java index 9259d06c..9bf21dd4 100644 --- a/src/main/java/mcjty/xnet/apiimpl/logic/enums/SensorMode.java +++ b/src/main/java/mcjty/xnet/apiimpl/logic/enums/SensorMode.java @@ -1,8 +1,8 @@ package mcjty.xnet.apiimpl.logic.enums; import mcjty.lib.varia.ComponentFactory; +import mcjty.lib.gui.ITranslatableEnum; import mcjty.xnet.utils.I18nUtils; -import mcjty.xnet.utils.ITranslatableEnum; public enum SensorMode implements ITranslatableEnum { OFF("xnet.enum.logic.sensormode.off"), diff --git a/src/main/java/mcjty/xnet/modules/facade/blocks/FacadeBlockItem.java b/src/main/java/mcjty/xnet/modules/facade/blocks/FacadeBlockItem.java index 5a7dd003..c41305fa 100644 --- a/src/main/java/mcjty/xnet/modules/facade/blocks/FacadeBlockItem.java +++ b/src/main/java/mcjty/xnet/modules/facade/blocks/FacadeBlockItem.java @@ -86,7 +86,7 @@ private static void userSetMimicBlock(@Nonnull ItemStack item, BlockState mimicB setMimicBlock(item, mimicBlock); if (world.isClientSide) { player.displayClientMessage(ComponentFactory.literal( - String.format(FACADE_CURRENT_MIMIC_FORMATTED.i18n(), mimicBlock.getBlock().getDescriptionId())), + FACADE_CURRENT_MIMIC_FORMATTED.i18n(mimicBlock.getBlock().getDescriptionId())), false ); } diff --git a/src/main/java/mcjty/xnet/utils/ChoiceEvent.java b/src/main/java/mcjty/xnet/utils/ChoiceEvent.java deleted file mode 100644 index 24138020..00000000 --- a/src/main/java/mcjty/xnet/utils/ChoiceEvent.java +++ /dev/null @@ -1,5 +0,0 @@ -package mcjty.xnet.utils; - -public interface ChoiceEvent { - void choiceChanged(T newChoice); -} diff --git a/src/main/java/mcjty/xnet/utils/EnumChoiceLabel.java b/src/main/java/mcjty/xnet/utils/EnumChoiceLabel.java deleted file mode 100644 index 7c31d184..00000000 --- a/src/main/java/mcjty/xnet/utils/EnumChoiceLabel.java +++ /dev/null @@ -1,203 +0,0 @@ -package mcjty.xnet.utils; - -import com.mojang.blaze3d.vertex.PoseStack; -import mcjty.lib.base.StyleConfig; -import mcjty.lib.client.RenderHelper; -import mcjty.lib.gui.GuiParser; -import mcjty.lib.gui.Window; -import mcjty.lib.gui.widgets.AbstractLabel; -import mcjty.lib.gui.widgets.Widget; -import mcjty.lib.typed.Key; -import mcjty.lib.typed.Type; -import mcjty.lib.typed.TypedMap; -import mcjty.lib.varia.SafeClientTools; -import net.minecraft.client.gui.screens.Screen; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.stream.Collectors; - -public class EnumChoiceLabel extends AbstractLabel { - - public static final String TYPE_ENUM_CHOICE_LABEL = "enumchoicelabel"; - public static final Key PARAM_CHOICE = new Key<>("choice", Type.INTEGER); - public static final Key PARAM_CHOICE_IDX = new Key<>("choiceIdx", Type.INTEGER); - - private Integer choiceIndex = null; - private ITranslatableEnum[] enumChoices = null; - private final Map, List> tooltipMap = new HashMap<>(); - private List>> choiceEvents = null; - - public EnumChoiceLabel() { - text(""); - } - - private void setCurrentChoice(ITranslatableEnum enumChoice) { - this.choiceIndex = enumChoice.ordinal(); - } - - public EnumChoiceLabel choices(ITranslatableEnum[] choices) { - enumChoices = choices; - if (choiceIndex == null) { - choiceIndex = choices[0].ordinal(); - text(choices[0].getI18n()); - fireChoiceEvents(choices[0]); - } - if (tooltipMap.isEmpty()) { - for (ITranslatableEnum choice : choices) { - setChoiceTooltip(choice); - } - } - - return this; - } - - public EnumChoiceLabel setChoiceTooltip(ITranslatableEnum choice) { - tooltipMap.put(choice, Arrays.asList(choice.getI18nSplitedTooltip())); - return this; - } - - public EnumChoiceLabel choice(ITranslatableEnum choice) { - if (Objects.equals(choiceIndex, choice.ordinal())) { - return this; - } - choiceIndex = choice.ordinal(); - text(choice.getI18n()); - return this; - } - - @Override - public List getTooltips() { - List tooltips = tooltipMap.get(enumChoices[choiceIndex]); - if (tooltips == null) { - return super.getTooltips(); - } else { - return tooltips; - } - } - - @Override - public void draw(Screen gui, PoseStack matrixStack, int x, int y) { - if (!visible) { - return; - } - int xx = x + bounds.x; - int yy = y + bounds.y; - - if (isEnabled()) { - if (isHovering()) { - drawStyledBoxHovering(window, matrixStack, xx, yy, xx + bounds.width - 1, yy + bounds.height - 1); - } else { - drawStyledBoxNormal(window, matrixStack, xx, yy, xx + bounds.width - 1, yy + bounds.height - 1); - } - RenderHelper.drawLeftTriangle(matrixStack, xx + bounds.width - 10, yy + bounds.height / 2, StyleConfig.colorCycleButtonTriangleNormal); - RenderHelper.drawRightTriangle(matrixStack, xx + bounds.width - 4, yy + bounds.height / 2, StyleConfig.colorCycleButtonTriangleNormal); - } else { - drawStyledBoxDisabled(window, matrixStack, xx, yy, xx + bounds.width - 1, yy + bounds.height - 1); - RenderHelper.drawLeftTriangle(matrixStack, xx + bounds.width - 10, yy + bounds.height / 2, StyleConfig.colorCycleButtonTriangleDisabled); - RenderHelper.drawRightTriangle(matrixStack, xx + bounds.width - 4, yy + bounds.height / 2, StyleConfig.colorCycleButtonTriangleDisabled); - } - - super.drawOffset(gui, matrixStack, x, y, -3, 1); - } - - @Override - public Widget mouseClick(double x, double y, int button) { - if (isEnabledAndVisible()) { - if (enumChoices.length == 0) { - return null; - } - if (button == 1 || SafeClientTools.isSneaking()) { - choiceIndex--; - if (choiceIndex < 0) { - choiceIndex = enumChoices.length - 1; - } - } else { - choiceIndex++; - if (choiceIndex >= enumChoices.length) { - choiceIndex = 0; - } - } - - text(enumChoices[choiceIndex].getI18n()); - fireChoiceEvents(enumChoices[choiceIndex]); - } - return null; - } - - public EnumChoiceLabel event(ChoiceEvent> event) { - if (choiceEvents == null) { - choiceEvents = new ArrayList<>(); - } - choiceEvents.add(event); - return this; - } - - public void removeChoiceEvent(ChoiceEvent> event) { - if (choiceEvents != null) { - choiceEvents.remove(event); - } - } - - private void fireChoiceEvents(ITranslatableEnum choice) { - - fireChannelEvents(TypedMap.builder() - .put(Window.PARAM_ID, "choice") - .put(PARAM_CHOICE, choice.ordinal()) - .put(PARAM_CHOICE_IDX, choice.ordinal()) - .build()); - - if (choiceEvents != null) { - for (ChoiceEvent> event : choiceEvents) { - event.choiceChanged(choice); - } - } - } - - @Override - public void readFromGuiCommand(GuiParser.GuiCommand command) { - System.out.println("readFromGuiCommand"); - super.readFromGuiCommand(command); - command.findCommand("choices").ifPresent(cmd -> { - cmd.commands().forEach(choiceCmd -> { - Integer enumIndex = choiceCmd.getOptionalPar(0, 0); - -// Arrays.fill(enumChoices, choice); - choiceCmd.findCommand("tooltips") - .ifPresent(tooltipsCmd -> tooltipMap.put(enumChoices[enumIndex], tooltipsCmd.parameters() - .map(Object::toString) - .collect(Collectors.toList()))); - }); - }); - } - - @Override - public void fillGuiCommand(GuiParser.GuiCommand command) { - System.out.println("fillGuiCommand"); - super.fillGuiCommand(command); - command.removeParameter(1); // We don't need the name as set by the label - GuiParser.GuiCommand choicesCmd = new GuiParser.GuiCommand("choices"); - for (ITranslatableEnum s : enumChoices) { - GuiParser.GuiCommand choiceCmd = new GuiParser.GuiCommand("choice").parameter(s.ordinal()); - choicesCmd.command(choiceCmd); - List tooltips = tooltipMap.get(s); - if (tooltips != null && !tooltips.isEmpty()) { - GuiParser.GuiCommand tooltipsCmd = new GuiParser.GuiCommand("tooltips"); - choiceCmd.command(tooltipsCmd); - for (String tt : tooltips) { - tooltipsCmd.parameter(tt); - } - } - } - command.command(choicesCmd); - } - - @Override - public GuiParser.GuiCommand createGuiCommand() { - return new GuiParser.GuiCommand(TYPE_ENUM_CHOICE_LABEL); - } -} diff --git a/src/main/java/mcjty/xnet/utils/ITranslatableEnum.java b/src/main/java/mcjty/xnet/utils/ITranslatableEnum.java deleted file mode 100644 index 813f9879..00000000 --- a/src/main/java/mcjty/xnet/utils/ITranslatableEnum.java +++ /dev/null @@ -1,11 +0,0 @@ -package mcjty.xnet.utils; - -public interface ITranslatableEnum> { - - String name(); - int ordinal(); - String toString(); - - String getI18n(); - String[] getI18nSplitedTooltip(); -}