From 37f21296c62e9c4d23d72a45ebfe0f4c5cdc9ce5 Mon Sep 17 00:00:00 2001 From: Cedric Date: Thu, 28 Sep 2023 15:09:11 +0200 Subject: [PATCH] applied I18Wrapper --- guilib | 2 +- .../com/troblecodings/signals/SEProperty.java | 5 +- .../signals/guis/ContainerSignalBox.java | 6 +- .../signals/guis/GuiPlacementtool.java | 6 +- .../signals/guis/GuiSignalBox.java | 179 ++++++++++-------- .../signals/guis/GuiSignalController.java | 8 +- .../signals/guis/NamableGui.java | 8 +- .../troblecodings/signals/guis/SidePanel.java | 175 +++++++++-------- .../signals/items/Placementtool.java | 6 +- 9 files changed, 209 insertions(+), 186 deletions(-) diff --git a/guilib b/guilib index 8a523546b..950afe764 160000 --- a/guilib +++ b/guilib @@ -1 +1 @@ -Subproject commit 8a523546b6bbb323008deca8d24f22a247430fe3 +Subproject commit 950afe764ed8d53fa995e1ad5c2ef27c444c37fa diff --git a/src/main/java/com/troblecodings/signals/SEProperty.java b/src/main/java/com/troblecodings/signals/SEProperty.java index 26de7d36b..db2dea4d2 100644 --- a/src/main/java/com/troblecodings/signals/SEProperty.java +++ b/src/main/java/com/troblecodings/signals/SEProperty.java @@ -7,12 +7,12 @@ import java.util.function.Predicate; import com.google.common.collect.ImmutableList; +import com.troblecodings.core.I18Wrapper; import com.troblecodings.core.NBTWrapper; import com.troblecodings.guilib.ecs.interfaces.IIntegerable; import com.troblecodings.signals.core.JsonEnum; import com.troblecodings.signals.enums.ChangeableStage; -import net.minecraft.client.resources.language.I18n; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.client.model.data.IModelData; @@ -141,7 +141,8 @@ public SEAutoNameProp(final String name, final JsonEnum parent, final String def @OnlyIn(Dist.CLIENT) @Override public String getNamedObj(final int obj) { - return I18n.get("property." + this.getName() + ".name") + ": " + getObjFromID(obj); + return I18Wrapper.format("property." + this.getName() + ".name") + ": " + + getObjFromID(obj); } } } \ No newline at end of file diff --git a/src/main/java/com/troblecodings/signals/guis/ContainerSignalBox.java b/src/main/java/com/troblecodings/signals/guis/ContainerSignalBox.java index 071fa493d..bbdd3a926 100644 --- a/src/main/java/com/troblecodings/signals/guis/ContainerSignalBox.java +++ b/src/main/java/com/troblecodings/signals/guis/ContainerSignalBox.java @@ -8,6 +8,7 @@ import java.util.function.Consumer; import java.util.stream.Collectors; +import com.troblecodings.core.I18Wrapper; import com.troblecodings.core.ReadBuffer; import com.troblecodings.core.WriteBuffer; import com.troblecodings.guilib.ecs.ContainerBase; @@ -29,7 +30,6 @@ import com.troblecodings.signals.signalbox.entrys.PathEntryType; import com.troblecodings.signals.signalbox.entrys.PathOptionEntry; -import net.minecraft.client.resources.language.I18n; import net.minecraft.core.BlockPos; import net.minecraft.world.entity.player.Player; import net.minecraft.world.level.block.Rotation; @@ -119,11 +119,11 @@ public void deserializeClient(final ReadBuffer buffer) { break; } case NO_PW_FOUND: { - infoUpdates.accept(I18n.get("error.nopathfound")); + infoUpdates.accept(I18Wrapper.format("error.nopathfound")); break; } case NO_OUTPUT_UPDATE: { - infoUpdates.accept(I18n.get("error.nooutputupdate")); + infoUpdates.accept(I18Wrapper.format("error.nooutputupdate")); break; } case OUTPUT_UPDATE: { diff --git a/src/main/java/com/troblecodings/signals/guis/GuiPlacementtool.java b/src/main/java/com/troblecodings/signals/guis/GuiPlacementtool.java index 00b8b99ee..cab4234d0 100644 --- a/src/main/java/com/troblecodings/signals/guis/GuiPlacementtool.java +++ b/src/main/java/com/troblecodings/signals/guis/GuiPlacementtool.java @@ -5,6 +5,7 @@ import java.util.function.IntConsumer; import com.mojang.blaze3d.vertex.PoseStack; +import com.troblecodings.core.I18Wrapper; import com.troblecodings.core.NBTWrapper; import com.troblecodings.core.WriteBuffer; import com.troblecodings.guilib.ecs.GuiBase; @@ -24,7 +25,6 @@ import com.troblecodings.signals.enums.ChangeableStage; import com.troblecodings.signals.items.Placementtool; -import net.minecraft.client.resources.language.I18n; import net.minecraft.network.chat.Component; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.ItemStack; @@ -101,7 +101,7 @@ private void initInternal() { lowerEntity.setInheritHeight(true); lowerEntity.setInheritWidth(true); - final UILabel titlelabel = new UILabel(I18n.get("property.signal.name")); + final UILabel titlelabel = new UILabel(I18Wrapper.format("property.signal.name")); titlelabel.setCenterX(false); final UIEntity titel = new UIEntity(); @@ -150,7 +150,7 @@ public void updateFromContainer() { textfield.setInheritWidth(true); if (currentSelectedBlock.canHaveCustomname(new HashMap<>())) { final UITextInput name = new UITextInput(container.signalName); - textfield.add(new UIToolTip(I18n.get("property.customname.desc"))); + textfield.add(new UIToolTip(I18Wrapper.format("property.customname.desc"))); name.setOnTextUpdate(this::sendName); textfield.add(name); list.add(textfield); diff --git a/src/main/java/com/troblecodings/signals/guis/GuiSignalBox.java b/src/main/java/com/troblecodings/signals/guis/GuiSignalBox.java index d1c32bcb1..7c940e735 100644 --- a/src/main/java/com/troblecodings/signals/guis/GuiSignalBox.java +++ b/src/main/java/com/troblecodings/signals/guis/GuiSignalBox.java @@ -11,11 +11,12 @@ import java.util.function.BiConsumer; import java.util.stream.Collectors; +import com.troblecodings.core.I18Wrapper; +import com.troblecodings.core.WriteBuffer; import com.troblecodings.guilib.ecs.DrawUtil.BoolIntegerables; import com.troblecodings.guilib.ecs.DrawUtil.DisableIntegerable; import com.troblecodings.guilib.ecs.DrawUtil.EnumIntegerable; import com.troblecodings.guilib.ecs.DrawUtil.SizeIntegerables; -import com.troblecodings.core.WriteBuffer; import com.troblecodings.guilib.ecs.GuiBase; import com.troblecodings.guilib.ecs.GuiElements; import com.troblecodings.guilib.ecs.GuiInfo; @@ -57,7 +58,6 @@ import com.troblecodings.signals.signalbox.entrys.PathOptionEntry; import net.minecraft.client.Minecraft; -import net.minecraft.client.resources.language.I18n; import net.minecraft.core.BlockPos; import net.minecraft.world.level.block.Rotation; @@ -179,17 +179,15 @@ public static String getSignalInfo(final BlockPos signalPos, final LinkType type final Minecraft mc = Minecraft.getInstance(); final String customName = ClientNameHandler .getClientName(new NameStateInfo(mc.level, signalPos)); - return String.format("%s (x=%d, y=%d. z=%d)", - customName == null - ? (type.equals(LinkType.SIGNAL) ? "" : I18n.get("type." + type.name())) - : customName, - signalPos.getX(), signalPos.getY(), signalPos.getZ()); + return String.format("%s (x=%d, y=%d. z=%d)", customName == null + ? (type.equals(LinkType.SIGNAL) ? "" : I18Wrapper.format("type." + type.name())) + : customName, signalPos.getX(), signalPos.getY(), signalPos.getZ()); } private void setupModeSettings(final UIEntity parent, final EnumGuiMode mode, final Rotation rotation, final SignalBoxNode node, final PathOptionEntry option) { - final String modeName = I18n.get("property." + mode.name()); - final String rotationName = I18n.get("property." + rotation.name() + ".rotation"); + final String modeName = I18Wrapper.format("property." + mode.name()); + final String rotationName = I18Wrapper.format("property." + rotation.name() + ".rotation"); final UIEntity entity = new UIEntity(); entity.setInheritWidth(true); entity.setHeight(20); @@ -210,8 +208,8 @@ private void setupModeSettings(final UIEntity parent, final EnumGuiMode mode, final UIEntity stateEntity = new UIEntity(); stateEntity.setInheritWidth(true); stateEntity.setHeight(15); - final String pathUsageName = I18n.get("property.status") + ": "; - final String pathUsage = I18n.get("property." + path); + final String pathUsageName = I18Wrapper.format("property.status") + ": "; + final String pathUsage = I18Wrapper.format("property." + path); stateEntity.add(new UILabel(pathUsageName + pathUsage)); parent.add(stateEntity); @@ -243,74 +241,88 @@ private void setupModeSettings(final UIEntity parent, final EnumGuiMode mode, break; } } - final UILabel currentStatus = new UILabel(I18n.get("info.usage.status") + " : " - + I18n.get("info.usage.status.free")); + final UILabel currentStatus = new UILabel(I18Wrapper.format("info.usage.status") + + " : " + I18Wrapper.format("info.usage.status.free")); currentStatus.setTextColor(new UIEntity().getBasicTextColor()); final UIEntity statusEntity = new UIEntity(); statusEntity.setInheritWidth(true); statusEntity.setHeight(20); statusEntity.add(new UIScale(1.1f, 1.1f, 1)); statusEntity.add(currentStatus); - parent.add(GuiElements.createButton(I18n.get("info.usage.manuel"), e1 -> { - final Optional usage = option - .getEntry(PathEntryType.PATHUSAGE); - final UIEntity info = new UIEntity(); - info.setInherits(true); - info.add(new UIBox(UIBox.VBOX, 5)); - info.add(new UIColor(BACKGROUND_COLOR)); - info.add(new UIClickable(_u -> pop(), 1)); - info.add(statusEntity); - final UIEntity textureEntity = new UIEntity(); - textureEntity.setHeight(40); - textureEntity.setWidth(40); - textureEntity.setX(120); - textureEntity.add(new UIToolTip(I18n.get("info.usage.rs.desc"))); - if (canBeManuelChanged.get()) { - if (node.containsManuellOutput(modeSet)) { - textureEntity.add(new UITexture(SidePanel.REDSTONE_ON)); - } else { - textureEntity.add(new UITexture(SidePanel.REDSTONE_OFF)); - } - } else { - if (usage.isPresent() && !usage.get().equals(EnumPathUsage.FREE)) { - textureEntity.add(new UITexture(SidePanel.REDSTONE_ON_BLOCKED)); - } else { - textureEntity.add(new UITexture(SidePanel.REDSTONE_OFF_BLOCKED)); - } - } - info.add(textureEntity); - final UILabel outputStatus = new UILabel( - ((usage.isPresent() && !usage.get().equals(EnumPathUsage.FREE)) - || node.containsManuellOutput(modeSet)) - ? I18n.get("info.usage.rs.true") - : I18n.get("info.usage.rs.false")); - outputStatus.setCenterY(false); - outputStatus.setTextColor(new UIEntity().getBasicTextColor()); - final UIEntity outputEntity = new UIEntity(); - outputEntity.setInheritWidth(true); - outputEntity.setHeight(20); - outputEntity.add(outputStatus); - info.add(outputEntity); - if (canBeManuelChanged.get()) { - info.add(GuiElements.createButton(I18n.get("info.usage.change"), i -> { - final boolean turnOff = node.containsManuellOutput(modeSet); - textureEntity.clear(); - textureEntity.add(new UIToolTip(I18n.get("info.usage.rs.desc"))); - if (turnOff) { - changeRedstoneOutput(node.getPoint(), modeSet, false); - outputStatus.setText(I18n.get("info.usage.rs.false")); - textureEntity.add(new UITexture(SidePanel.REDSTONE_OFF)); + parent.add( + GuiElements.createButton(I18Wrapper.format("info.usage.manuel"), e1 -> { + final Optional usage = option + .getEntry(PathEntryType.PATHUSAGE); + final UIEntity info = new UIEntity(); + info.setInherits(true); + info.add(new UIBox(UIBox.VBOX, 5)); + info.add(new UIColor(BACKGROUND_COLOR)); + info.add(new UIClickable(_u -> pop(), 1)); + info.add(statusEntity); + final UIEntity textureEntity = new UIEntity(); + textureEntity.setHeight(40); + textureEntity.setWidth(40); + textureEntity.setX(120); + textureEntity.add( + new UIToolTip(I18Wrapper.format("info.usage.rs.desc"))); + if (canBeManuelChanged.get()) { + if (node.containsManuellOutput(modeSet)) { + textureEntity.add(new UITexture(SidePanel.REDSTONE_ON)); + } else { + textureEntity.add(new UITexture(SidePanel.REDSTONE_OFF)); + } } else { - changeRedstoneOutput(node.getPoint(), modeSet, true); - outputStatus.setText(I18n.get("info.usage.rs.true")); - textureEntity.add(new UITexture(SidePanel.REDSTONE_ON)); + if (usage.isPresent() + && !usage.get().equals(EnumPathUsage.FREE)) { + textureEntity + .add(new UITexture(SidePanel.REDSTONE_ON_BLOCKED)); + } else { + textureEntity + .add(new UITexture(SidePanel.REDSTONE_OFF_BLOCKED)); + } } + info.add(textureEntity); + final UILabel outputStatus = new UILabel(((usage.isPresent() + && !usage.get().equals(EnumPathUsage.FREE)) + || node.containsManuellOutput(modeSet)) + ? I18Wrapper.format("info.usage.rs.true") + : I18Wrapper.format("info.usage.rs.false")); + outputStatus.setCenterY(false); + outputStatus.setTextColor(new UIEntity().getBasicTextColor()); + final UIEntity outputEntity = new UIEntity(); + outputEntity.setInheritWidth(true); + outputEntity.setHeight(20); + outputEntity.add(outputStatus); + info.add(outputEntity); + if (canBeManuelChanged.get()) { + info.add(GuiElements.createButton( + I18Wrapper.format("info.usage.change"), i -> { + final boolean turnOff = node + .containsManuellOutput(modeSet); + textureEntity.clear(); + textureEntity.add(new UIToolTip( + I18Wrapper.format("info.usage.rs.desc"))); + if (turnOff) { + changeRedstoneOutput(node.getPoint(), modeSet, + false); + outputStatus.setText(I18Wrapper + .format("info.usage.rs.false")); + textureEntity.add( + new UITexture(SidePanel.REDSTONE_OFF)); + } else { + changeRedstoneOutput(node.getPoint(), modeSet, + true); + outputStatus.setText(I18Wrapper + .format("info.usage.rs.true")); + textureEntity.add( + new UITexture(SidePanel.REDSTONE_ON)); + } + })); + } + final UIEntity screen = GuiElements.createScreen(e -> e.add(info)); + push(screen); })); - } - final UIEntity screen = GuiElements.createScreen(e -> e.add(info)); - push(screen); - })); - parent.add(new UIToolTip(I18n.get("info.usage.manuel.desc"))); + parent.add(new UIToolTip(I18Wrapper.format("info.usage.manuel.desc"))); } selectLink(parent, node, option, entrySet, LinkType.INPUT, PathEntryType.BLOCKING, mode, rotation, ".blocking"); @@ -326,7 +338,7 @@ private void setupModeSettings(final UIEntity parent, final EnumGuiMode mode, }, option.getEntry(PathEntryType.ZS2).orElse((byte) 0)); parent.add(zs2Entity); - parent.add(GuiElements.createButton(I18n.get("button.reset"), e -> { + parent.add(GuiElements.createButton(I18Wrapper.format("button.reset"), e -> { reset(); initializeFieldUsage(mainButton); resetPathwayOnServer(node); @@ -352,12 +364,13 @@ private void setupModeSettings(final UIEntity parent, final EnumGuiMode mode, } case RS: { if (option.containsEntry(PathEntryType.SIGNAL)) - parent.add(GuiElements.createButton(I18n.get("btn.subsidiary"), e -> { + parent.add(GuiElements.createButton(I18Wrapper.format("btn.subsidiary"), e -> { final UIBox hbox = new UIBox(UIBox.VBOX, 1); final UIEntity list = new UIEntity(); list.setInherits(true); list.add(hbox); - list.add(GuiElements.createButton(I18n.get("btn.return"), a -> pop())); + list.add(GuiElements.createButton(I18Wrapper.format("btn.return"), + a -> pop())); final BlockPos pos = option.getEntry(PathEntryType.SIGNAL).get(); final List subsidiaries = container.possibleSubsidiaries .getOrDefault(pos, SubsidiaryState.ALL_STATES); @@ -585,7 +598,7 @@ private void initializePageSettings(final UIEntity entity, icon.add(new UITexture(UISignalBoxTile.ICON, 0.2 * id, 0.5, 0.2 * id + 0.2, 1)); icon.setHeight(20); icon.setWidth(20); - icon.add(new UIToolTip(I18n.get("type." + t.name()))); + icon.add(new UIToolTip(I18Wrapper.format("type." + t.name()))); layout.add(icon); layout.add(GuiElements.createButton(name)); @@ -624,13 +637,13 @@ private void initializeFieldEdit(final UIEntity entity) { final UIBox hbox = new UIBox(UIBox.VBOX, 3); selectionEntity.add(hbox); final UIEntity question = new UIEntity(); - final UILabel label = new UILabel(I18n.get("sb.editmode")); + final UILabel label = new UILabel(I18Wrapper.format("sb.editmode")); label.setTextColor(0xFFFFFFFF); question.setScaleX(1.1f); question.setScaleY(1.1f); question.add(label); question.setInherits(true); - final UILabel info = new UILabel(I18n.get("sb.allreset")); + final UILabel info = new UILabel(I18Wrapper.format("sb.allreset")); info.setTextColor(0xFFFFFFFF); final UIEntity infoEntity = new UIEntity(); infoEntity.add(info); @@ -638,7 +651,7 @@ private void initializeFieldEdit(final UIEntity entity) { selectionEntity.add(question); selectionEntity.add(infoEntity); final UIEntity buttons = new UIEntity(); - final UIEntity buttonYes = GuiElements.createButton(I18n.get("btn.yes"), e -> { + final UIEntity buttonYes = GuiElements.createButton(I18Wrapper.format("btn.yes"), e -> { pop(); reset(); final UIMenu menu = new UIMenu(); @@ -653,7 +666,7 @@ private void initializeFieldEdit(final UIEntity entity) { helpPage.updateNextNode(menu.getSelection(), menu.getRotation()); this.lastTile = null; }); - final UIEntity buttonNo = GuiElements.createButton(I18n.get("btn.no"), e -> { + final UIEntity buttonNo = GuiElements.createButton(I18Wrapper.format("btn.no"), e -> { pop(); }); buttons.setInherits(true); @@ -743,7 +756,7 @@ private void initializeFieldTemplate(final BiConsumer } private void initializeBasicUI() { - final String name = I18n.get("tile.signalbox.name"); + final String name = I18Wrapper.format("tile.signalbox.name"); final UILabel titlelabel = new UILabel(name); titlelabel.setCenterX(false); @@ -760,10 +773,12 @@ private void initializeBasicUI() { header.add(new UIBox(UIBox.HBOX, 4)); header.add(titel); header.add(GuiElements.createSpacerH(40)); + header.add(GuiElements.createButton(I18Wrapper.format("btn.settings"), + this::initializePageSettings)); header.add( - GuiElements.createButton(I18n.get("btn.settings"), this::initializePageSettings)); - header.add(GuiElements.createButton(I18n.get("btn.edit"), this::initializeFieldEdit)); - mainButton = GuiElements.createButton(I18n.get("btn.main"), this::initializeFieldUsage); + GuiElements.createButton(I18Wrapper.format("btn.edit"), this::initializeFieldEdit)); + mainButton = GuiElements.createButton(I18Wrapper.format("btn.main"), + this::initializeFieldUsage); header.add(mainButton); header.add(GuiElements.createSpacerH(5)); resetSelection(mainButton); diff --git a/src/main/java/com/troblecodings/signals/guis/GuiSignalController.java b/src/main/java/com/troblecodings/signals/guis/GuiSignalController.java index 329851892..dc48f6782 100644 --- a/src/main/java/com/troblecodings/signals/guis/GuiSignalController.java +++ b/src/main/java/com/troblecodings/signals/guis/GuiSignalController.java @@ -5,10 +5,11 @@ import java.util.List; import java.util.Map; +import com.troblecodings.core.I18Wrapper; +import com.troblecodings.core.WriteBuffer; import com.troblecodings.guilib.ecs.DrawUtil.DisableIntegerable; import com.troblecodings.guilib.ecs.DrawUtil.EnumIntegerable; import com.troblecodings.guilib.ecs.DrawUtil.SizeIntegerables; -import com.troblecodings.core.WriteBuffer; import com.troblecodings.guilib.ecs.GuiBase; import com.troblecodings.guilib.ecs.GuiElements; import com.troblecodings.guilib.ecs.GuiInfo; @@ -37,7 +38,6 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.block.model.BakedQuad; -import net.minecraft.client.resources.language.I18n; import net.minecraft.client.resources.model.BakedModel; import net.minecraft.core.Direction; import net.minecraft.world.entity.player.Player; @@ -228,7 +228,7 @@ private void addRSInputMode() { SizeIntegerables.of("profile", 32, in -> String.valueOf(in))); lowerEntity.add(GuiElements.createEnumElement(profile, e -> sendRSInputProfileToServer(e), controller.linkedRSInputProfile)); - lowerEntity.add(GuiElements.createButton(I18n.get("gui.unlink"), e -> { + lowerEntity.add(GuiElements.createButton(I18Wrapper.format("gui.unlink"), e -> { unlinkInputPos(); label.setText("Linked To: not linked"); })); @@ -244,7 +244,7 @@ private void initInternal() { } lowerEntity.setInherits(true); - final String name = I18n.get("tile." + signal.delegate.name().getPath() + ".name") + final String name = I18Wrapper.format("tile." + signal.delegate.name().getPath() + ".name") + "; Name: " + ClientNameHandler.getClientName(new NameStateInfo(mc.level, controller.getPos())); diff --git a/src/main/java/com/troblecodings/signals/guis/NamableGui.java b/src/main/java/com/troblecodings/signals/guis/NamableGui.java index f262dbd13..8b7da55d5 100644 --- a/src/main/java/com/troblecodings/signals/guis/NamableGui.java +++ b/src/main/java/com/troblecodings/signals/guis/NamableGui.java @@ -1,5 +1,6 @@ package com.troblecodings.signals.guis; +import com.troblecodings.core.I18Wrapper; import com.troblecodings.core.WriteBuffer; import com.troblecodings.guilib.ecs.GuiBase; import com.troblecodings.guilib.ecs.GuiElements; @@ -15,7 +16,6 @@ import com.troblecodings.signals.init.OSBlocks; import com.troblecodings.signals.tileentitys.RedstoneIOTileEntity; -import net.minecraft.client.resources.language.I18n; import net.minecraft.world.entity.player.Player; public class NamableGui extends GuiBase { @@ -62,10 +62,10 @@ private void initOwn() { final UITextInput input = new UITextInput(container.tile.getNameWrapper()); textfield.add(input); - textfield.add(new UIToolTip(I18n.get("property.customname.desc"))); + textfield.add(new UIToolTip(I18Wrapper.format("property.customname.desc"))); hbox.add(textfield); - final UIEntity apply = GuiElements.createButton(I18n.get("btn.apply"), + final UIEntity apply = GuiElements.createButton(I18Wrapper.format("btn.apply"), _u -> this.updateText(input.getText())); apply.setInheritWidth(false); apply.setWidth(60); @@ -74,7 +74,7 @@ private void initOwn() { if (!(container.tile instanceof RedstoneIOTileEntity)) { return; } - inner.add(GuiElements.createLabel(I18n.get("label.linkedto"))); + inner.add(GuiElements.createLabel(I18Wrapper.format("label.linkedto"))); final UIEntity list = new UIEntity(); list.setInheritHeight(true); list.setInheritWidth(true); diff --git a/src/main/java/com/troblecodings/signals/guis/SidePanel.java b/src/main/java/com/troblecodings/signals/guis/SidePanel.java index bd5c5565e..f3fe6b546 100644 --- a/src/main/java/com/troblecodings/signals/guis/SidePanel.java +++ b/src/main/java/com/troblecodings/signals/guis/SidePanel.java @@ -8,6 +8,7 @@ import java.util.function.BiConsumer; import java.util.stream.Collectors; +import com.troblecodings.core.I18Wrapper; import com.troblecodings.guilib.ecs.DrawUtil.BoolIntegerables; import com.troblecodings.guilib.ecs.DrawUtil.SizeIntegerables; import com.troblecodings.guilib.ecs.GuiElements; @@ -42,7 +43,6 @@ import com.troblecodings.signals.signalbox.entrys.PathOptionEntry; import net.minecraft.client.Minecraft; -import net.minecraft.client.resources.language.I18n; import net.minecraft.core.BlockPos; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.block.Rotation; @@ -84,7 +84,7 @@ public SidePanel(final UIEntity lowerEntity, final GuiSignalBox gui) { final UIRotate rotate = new UIRotate(); rotate.setRotateZ((float) Math.PI / 2.0f); label.add(rotate); - final UILabel labelComponent = new UILabel(I18n.get("info.infolabel")); + final UILabel labelComponent = new UILabel(I18Wrapper.format("info.infolabel")); labelComponent.setTextColor(new UIEntity().getBasicTextColor()); label.add(labelComponent); label.setX(2); @@ -117,7 +117,7 @@ public SidePanel(final UIEntity lowerEntity, final GuiSignalBox gui) { public void addHelpPageToPlane() { if (showHelpPage) { - helpPageButton.setText(I18n.get("info.info") + " >"); + helpPageButton.setText(I18Wrapper.format("info.info") + " >"); spacerEntity.setWidth(80); helpPage.clearChildren(); helpPage.add(infoEntity); @@ -153,7 +153,7 @@ public void add(final UIEntity entity) { public void updateNextNode(final int selection, final int rotation) { infoEntity.clearChildren(); infoEntity.add(GuiElements.createSpacerV(2)); - infoEntity.add(GuiElements.createLabel(I18n.get("info.nextelement"), + infoEntity.add(GuiElements.createLabel(I18Wrapper.format("info.nextelement"), new UIEntity().getBasicTextColor(), 0.8f)); final UIEntity preview = new UIEntity(); @@ -174,17 +174,20 @@ public void updateNextNode(final int selection, final int rotation) { infoEntity.add(preview); infoEntity.add(GuiElements.createSpacerV(5)); - infoEntity.add(GuiElements.createLabel("[R] = " + I18n.get("info.editor.key.r"), - new UIEntity().getInfoTextColor(), 0.5f)); - infoEntity.add(GuiElements.createLabel("[LMB] = " + I18n.get("info.editor.key.lmb"), - new UIEntity().getInfoTextColor(), 0.5f)); - infoEntity.add(GuiElements.createLabel("[RMB] = " + I18n.get("info.editor.key.rmb"), + infoEntity.add(GuiElements.createLabel("[R] = " + I18Wrapper.format("info.editor.key.r"), new UIEntity().getInfoTextColor(), 0.5f)); + infoEntity + .add(GuiElements.createLabel("[LMB] = " + I18Wrapper.format("info.editor.key.lmb"), + new UIEntity().getInfoTextColor(), 0.5f)); + infoEntity + .add(GuiElements.createLabel("[RMB] = " + I18Wrapper.format("info.editor.key.rmb"), + new UIEntity().getInfoTextColor(), 0.5f)); infoEntity.add(GuiElements.createSpacerV(5)); - infoEntity.add(GuiElements.createLabel(I18n.get("info.description"), + infoEntity.add(GuiElements.createLabel(I18Wrapper.format("info.description"), new UIEntity().getBasicTextColor(), 0.8f)); - infoEntity.add(GuiElements.createLabel(I18n.get("info." + modes.toString().toLowerCase()), - new UIEntity().getInfoTextColor(), 0.5f)); + infoEntity.add( + GuiElements.createLabel(I18Wrapper.format("info." + modes.toString().toLowerCase()), + new UIEntity().getInfoTextColor(), 0.5f)); addHelpPageToPlane(); } @@ -207,17 +210,17 @@ public void helpUsageMode(final Map subsidiaries, final UIScrollBox helpScrollbox = new UIScrollBox(UIBox.VBOX, 2); - helpList.add(GuiElements.createLabel(I18n.get("info.keys"), + helpList.add(GuiElements.createLabel(I18Wrapper.format("info.keys"), new UIEntity().getBasicTextColor(), 0.8f)); - helpList.add(GuiElements.createLabel("[LMB] = " + I18n.get("info.usage.key.lmb"), + helpList.add(GuiElements.createLabel("[LMB] = " + I18Wrapper.format("info.usage.key.lmb"), new UIEntity().getInfoTextColor(), 0.5f)); - helpList.add(GuiElements.createLabel("[RMB] = " + I18n.get("info.usage.key.rmb"), + helpList.add(GuiElements.createLabel("[RMB] = " + I18Wrapper.format("info.usage.key.rmb"), new UIEntity().getInfoTextColor(), 0.5f)); final Minecraft mc = Minecraft.getInstance(); if (!allNodes.isEmpty()) { - final UIEntity manuelButton = GuiElements.createButton(I18n.get("info.usage.manuel"), - e -> { + final UIEntity manuelButton = GuiElements + .createButton(I18Wrapper.format("info.usage.manuel"), e -> { final UIEntity screen = GuiElements.createScreen(searchPanel -> { final UIEntity searchBar = new UIEntity(); searchBar.setInheritWidth(true); @@ -245,8 +248,8 @@ public void helpUsageMode(final Map subsidiaries, allNodes.forEach(currentNode -> { final UILabel currentStatus = new UILabel( - I18n.get("info.usage.status") + " : " - + I18n.get("info.usage.status.free")); + I18Wrapper.format("info.usage.status") + " : " + + I18Wrapper.format("info.usage.status.free")); currentStatus.setTextColor(new UIEntity().getBasicTextColor()); final UIEntity statusEntity = new UIEntity(); statusEntity.setInheritWidth(true); @@ -259,8 +262,9 @@ public void helpUsageMode(final Map subsidiaries, .getEntry(PathEntryType.PATHUSAGE); if (pathUsage.isPresent() && !pathUsage.get().equals(EnumPathUsage.FREE)) { - currentStatus.setText(I18n.get("info.usage.status") + " : " - + I18n.get("info.usage.status.blocked")); + currentStatus.setText(I18Wrapper.format("info.usage.status") + + " : " + + I18Wrapper.format("info.usage.status.blocked")); canBeManuelChanged.set(false); } if (!entry.containsEntry(PathEntryType.OUTPUT)) @@ -281,8 +285,8 @@ public void helpUsageMode(final Map subsidiaries, textureEntity.setHeight(40); textureEntity.setWidth(40); textureEntity.setX(120); - textureEntity - .add(new UIToolTip(I18n.get("info.usage.rs.desc"))); + textureEntity.add(new UIToolTip( + I18Wrapper.format("info.usage.rs.desc"))); if (canBeManuelChanged.get()) { if (currentNode.containsManuellOutput(mode)) { textureEntity.add(new UITexture(REDSTONE_ON)); @@ -304,8 +308,8 @@ public void helpUsageMode(final Map subsidiaries, .isPresent() && !pathUsage.get().equals(EnumPathUsage.FREE)) || currentNode.containsManuellOutput(mode)) - ? I18n.get("info.usage.rs.true") - : I18n.get("info.usage.rs.false")); + ? I18Wrapper.format("info.usage.rs.true") + : I18Wrapper.format("info.usage.rs.false")); outputStatus.setCenterY(false); outputStatus .setTextColor(new UIEntity().getBasicTextColor()); @@ -319,26 +323,26 @@ public void helpUsageMode(final Map subsidiaries, .createScreen(entity -> entity.add(info))); return; } - info.add(GuiElements - .createButton(I18n.get("info.usage.change"), i -> { + info.add(GuiElements.createButton( + I18Wrapper.format("info.usage.change"), i -> { final boolean turnOff = currentNode .containsManuellOutput(mode); textureEntity.clear(); - textureEntity.add(new UIToolTip( - I18n.get("info.usage.rs.desc"))); + textureEntity.add(new UIToolTip(I18Wrapper + .format("info.usage.rs.desc"))); if (turnOff) { gui.changeRedstoneOutput( currentNode.getPoint(), mode, false); - outputStatus.setText( - I18n.get("info.usage.rs.false")); + outputStatus.setText(I18Wrapper + .format("info.usage.rs.false")); textureEntity .add(new UITexture(REDSTONE_OFF)); } else { gui.changeRedstoneOutput( currentNode.getPoint(), mode, true); - outputStatus.setText( - I18n.get("info.usage.rs.true")); + outputStatus.setText(I18Wrapper + .format("info.usage.rs.true")); textureEntity .add(new UITexture(REDSTONE_ON)); } @@ -380,54 +384,56 @@ public void helpUsageMode(final Map subsidiaries, manuelButton.setScaleY(0.8f); manuelButton.setX(5); helpList.add(manuelButton); - manuelButton.add(new UIToolTip(I18n.get("info.usage.manuel.desc"))); + manuelButton.add(new UIToolTip(I18Wrapper.format("info.usage.manuel.desc"))); } if (node != null) { final Map modes = node.getModes(); final List guiModes = modes.keySet().stream().map(mode -> mode.mode) .collect(Collectors.toList()); - helpList.add(GuiElements.createLabel(I18n.get("info.usage.node"), + helpList.add(GuiElements.createLabel(I18Wrapper.format("info.usage.node"), new UIEntity().getBasicTextColor(), 0.8f)); - final UIEntity reset = GuiElements.createButton(I18n.get("button.reset"), e -> { - final UIEntity screen = GuiElements.createScreen(selectionEntity -> { - final UIBox hbox = new UIBox(UIBox.VBOX, 3); - selectionEntity.add(hbox); - final UIEntity question = new UIEntity(); - final UILabel label = new UILabel(I18n.get("sb.resetpage")); - label.setTextColor(0xFFFFFFFF); - question.setScaleX(1.1f); - question.setScaleY(1.1f); - question.add(label); - question.setInherits(true); - final UILabel info = new UILabel(I18n.get("sb.pathwayreset")); - info.setTextColor(0xFFFFFFFF); - final UIEntity infoEntity = new UIEntity(); - infoEntity.add(info); - infoEntity.setInherits(true); - selectionEntity.add(question); - selectionEntity.add(infoEntity); - final UIEntity buttons = new UIEntity(); - final UIEntity buttonYes = GuiElements.createButton(I18n.get("btn.yes"), e1 -> { - gui.pop(); - gui.resetPathwayOnServer(node); + final UIEntity reset = GuiElements.createButton(I18Wrapper.format("button.reset"), + e -> { + final UIEntity screen = GuiElements.createScreen(selectionEntity -> { + final UIBox hbox = new UIBox(UIBox.VBOX, 3); + selectionEntity.add(hbox); + final UIEntity question = new UIEntity(); + final UILabel label = new UILabel(I18Wrapper.format("sb.resetpage")); + label.setTextColor(0xFFFFFFFF); + question.setScaleX(1.1f); + question.setScaleY(1.1f); + question.add(label); + question.setInherits(true); + final UILabel info = new UILabel(I18Wrapper.format("sb.pathwayreset")); + info.setTextColor(0xFFFFFFFF); + final UIEntity infoEntity = new UIEntity(); + infoEntity.add(info); + infoEntity.setInherits(true); + selectionEntity.add(question); + selectionEntity.add(infoEntity); + final UIEntity buttons = new UIEntity(); + final UIEntity buttonYes = GuiElements + .createButton(I18Wrapper.format("btn.yes"), e1 -> { + gui.pop(); + gui.resetPathwayOnServer(node); + }); + final UIEntity buttonNo = GuiElements + .createButton(I18Wrapper.format("btn.no"), e2 -> gui.pop()); + buttons.setInherits(true); + final UIBox vbox = new UIBox(UIBox.HBOX, 1); + buttons.add(vbox); + buttons.add(buttonYes); + buttons.add(buttonNo); + selectionEntity.add(buttons); + }); + gui.push(screen); }); - final UIEntity buttonNo = GuiElements.createButton(I18n.get("btn.no"), - e2 -> gui.pop()); - buttons.setInherits(true); - final UIBox vbox = new UIBox(UIBox.HBOX, 1); - buttons.add(vbox); - buttons.add(buttonYes); - buttons.add(buttonNo); - selectionEntity.add(buttons); - }); - gui.push(screen); - }); reset.setScaleX(0.8f); reset.setScaleY(0.8f); reset.setX(5); helpList.add(reset); - reset.add(new UIToolTip(I18n.get("button.reset.desc"))); + reset.add(new UIToolTip(I18Wrapper.format("button.reset.desc"))); if (guiModes.contains(EnumGuiMode.HP)) { final UIEntity entity = GuiElements .createBoolElement(BoolIntegerables.of("auto_pathway"), e -> { @@ -451,13 +457,13 @@ public void helpUsageMode(final Map subsidiaries, (signalName.isEmpty() ? "Rotaion: " + mode.rotation.toString() : signalName) + " - " + mode.mode.toString(), new UIEntity().getBasicTextColor(), 0.8f)); - final UIEntity entity = GuiElements.createButton(I18n.get("btn.subsidiary"), - e -> { + final UIEntity entity = GuiElements + .createButton(I18Wrapper.format("btn.subsidiary"), e -> { final UIBox hbox = new UIBox(UIBox.VBOX, 1); final UIEntity list = new UIEntity(); list.setInherits(true); list.add(hbox); - list.add(GuiElements.createButton(I18n.get("btn.return"), + list.add(GuiElements.createButton(I18Wrapper.format("btn.return"), a -> gui.pop())); final List possibleSubsidiaires = possibleSubsidiaries .getOrDefault(signalPos, SubsidiaryState.ALL_STATES); @@ -498,22 +504,23 @@ public void helpUsageMode(final Map subsidiaries, entity.setScaleY(0.8f); entity.setX(5); helpList.add(entity); - entity.add(new UIToolTip(I18n.get("btn.subsidiary.desc"))); + entity.add(new UIToolTip(I18Wrapper.format("btn.subsidiary.desc"))); } } - final UIEntity edit = GuiElements.createButton(I18n.get("info.usage.edit"), e -> { - helpUsageMode(subsidiaries, null, allNodes, possibleSubsidiaries); - gui.initializePageTileConfig(node); - }); + final UIEntity edit = GuiElements.createButton(I18Wrapper.format("info.usage.edit"), + e -> { + helpUsageMode(subsidiaries, null, allNodes, possibleSubsidiaries); + gui.initializePageTileConfig(node); + }); edit.setScaleX(0.8f); edit.setScaleY(0.8f); edit.setX(5); helpList.add(edit); - edit.add(new UIToolTip(I18n.get("info.usage.edit.desc"))); + edit.add(new UIToolTip(I18Wrapper.format("info.usage.edit.desc"))); } if (!subsidiaries.isEmpty()) { - helpList.add(GuiElements.createLabel(I18n.get("info.usage.subsidiary"), + helpList.add(GuiElements.createLabel(I18Wrapper.format("info.usage.subsidiary"), new UIEntity().getBasicTextColor(), 0.8f)); subsidiaries.forEach((pos, holder) -> { final String name = ClientNameHandler @@ -530,7 +537,7 @@ public void helpUsageMode(final Map subsidiaries, question.setScaleY(1.1f); question.add(label); question.setInherits(true); - final UILabel info = new UILabel(I18n.get("sb.disablesubsidiary")); + final UILabel info = new UILabel(I18Wrapper.format("sb.disablesubsidiary")); info.setTextColor(0xFFFFFFFF); final UIEntity infoEntity = new UIEntity(); infoEntity.add(info); @@ -538,13 +545,13 @@ public void helpUsageMode(final Map subsidiaries, selectionEntity.add(question); selectionEntity.add(infoEntity); final UIEntity buttons = new UIEntity(); - final UIEntity buttonYes = GuiElements.createButton(I18n.get("btn.yes"), - e1 -> { + final UIEntity buttonYes = GuiElements + .createButton(I18Wrapper.format("btn.yes"), e1 -> { gui.pop(); disableSubsidiary.accept(pos, holder); }); - final UIEntity buttonNo = GuiElements.createButton(I18n.get("btn.no"), - e2 -> gui.pop()); + final UIEntity buttonNo = GuiElements + .createButton(I18Wrapper.format("btn.no"), e2 -> gui.pop()); buttons.setInherits(true); final UIBox vbox = new UIBox(UIBox.HBOX, 1); buttons.add(vbox); diff --git a/src/main/java/com/troblecodings/signals/items/Placementtool.java b/src/main/java/com/troblecodings/signals/items/Placementtool.java index c88b7068c..46614296e 100644 --- a/src/main/java/com/troblecodings/signals/items/Placementtool.java +++ b/src/main/java/com/troblecodings/signals/items/Placementtool.java @@ -5,6 +5,7 @@ import java.util.List; import java.util.Map; +import com.troblecodings.core.I18Wrapper; import com.troblecodings.core.MessageWrapper; import com.troblecodings.core.NBTWrapper; import com.troblecodings.guilib.ecs.interfaces.IIntegerable; @@ -21,7 +22,6 @@ import com.troblecodings.signals.init.OSBlocks; import com.troblecodings.signals.init.OSTabs; -import net.minecraft.client.resources.language.I18n; import net.minecraft.core.BlockPos; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; @@ -50,8 +50,8 @@ public Placementtool() { @OnlyIn(Dist.CLIENT) @Override public String getNamedObj(final int obj) { - return I18n.get("property." + this.getName() + ".name") + ": " - + I18n.get(this.getObjFromID(obj).toString()); + return I18Wrapper.format("property." + this.getName() + ".name") + ": " + + I18Wrapper.format(this.getObjFromID(obj).toString()); } @Override