diff options
author | isXander <xandersmith2008@gmail.com> | 2022-12-11 18:27:11 +0000 |
---|---|---|
committer | isXander <xandersmith2008@gmail.com> | 2022-12-11 18:27:11 +0000 |
commit | b890c2f0eec3627e552f1c6cfc846c8a55663243 (patch) | |
tree | 7eefefe1b74cdf4f120a89a6b78efe5a810722f3 /src/client/java | |
parent | c1afd0716e34f042d3c8a0df5211a5e3f2dec801 (diff) | |
download | YetAnotherConfigLib-b890c2f0eec3627e552f1c6cfc846c8a55663243.tar.gz YetAnotherConfigLib-b890c2f0eec3627e552f1c6cfc846c8a55663243.tar.bz2 YetAnotherConfigLib-b890c2f0eec3627e552f1c6cfc846c8a55663243.zip |
close #21
Diffstat (limited to 'src/client/java')
-rw-r--r-- | src/client/java/dev/isxander/yacl/gui/CategoryListWidget.java | 5 | ||||
-rw-r--r-- | src/client/java/dev/isxander/yacl/gui/YACLScreen.java | 5 | ||||
-rw-r--r-- | src/client/java/dev/isxander/yacl/gui/controllers/ControllerWidget.java | 5 | ||||
-rw-r--r-- | src/client/java/dev/isxander/yacl/gui/controllers/string/StringControllerElement.java | 6 | ||||
-rw-r--r-- | src/client/java/dev/isxander/yacl/gui/utils/GuiUtils.java (renamed from src/client/java/dev/isxander/yacl/gui/utils/RenderUtils.java) | 15 |
5 files changed, 19 insertions, 17 deletions
diff --git a/src/client/java/dev/isxander/yacl/gui/CategoryListWidget.java b/src/client/java/dev/isxander/yacl/gui/CategoryListWidget.java index 974dc2c..e97f46c 100644 --- a/src/client/java/dev/isxander/yacl/gui/CategoryListWidget.java +++ b/src/client/java/dev/isxander/yacl/gui/CategoryListWidget.java @@ -3,11 +3,10 @@ package dev.isxander.yacl.gui; import com.google.common.collect.ImmutableList; import com.mojang.blaze3d.systems.RenderSystem; import dev.isxander.yacl.api.ConfigCategory; -import dev.isxander.yacl.gui.utils.RenderUtils; +import dev.isxander.yacl.gui.utils.GuiUtils; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.Element; import net.minecraft.client.gui.Selectable; -import net.minecraft.client.gui.widget.ElementListWidget; import net.minecraft.client.util.math.MatrixStack; import java.util.List; @@ -28,7 +27,7 @@ public class CategoryListWidget extends ElementListWidgetExt<CategoryListWidget. @Override public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) { - RenderUtils.enableScissor(0, 0, width, height); + GuiUtils.enableScissor(0, 0, width, height); super.render(matrices, mouseX, mouseY, delta); RenderSystem.disableScissor(); } diff --git a/src/client/java/dev/isxander/yacl/gui/YACLScreen.java b/src/client/java/dev/isxander/yacl/gui/YACLScreen.java index 1fbc769..a1dc08e 100644 --- a/src/client/java/dev/isxander/yacl/gui/YACLScreen.java +++ b/src/client/java/dev/isxander/yacl/gui/YACLScreen.java @@ -5,6 +5,7 @@ import dev.isxander.yacl.api.*; import dev.isxander.yacl.api.utils.Dimension; import dev.isxander.yacl.api.utils.MutableDimension; import dev.isxander.yacl.api.utils.OptionUtils; +import dev.isxander.yacl.gui.utils.GuiUtils; import net.minecraft.client.font.MultilineText; import net.minecraft.client.font.TextRenderer; import net.minecraft.client.gui.DrawableHelper; @@ -161,9 +162,9 @@ public class YACLScreen extends Screen { boolean pendingChanges = pendingChanges(); undoButton.active = pendingChanges; - finishedSaveButton.setMessage(pendingChanges ? Text.translatable("yacl.gui.save") : ScreenTexts.DONE); + finishedSaveButton.setMessage(pendingChanges ? Text.translatable("yacl.gui.save") : GuiUtils.translatableFallback("yacl.gui.done", ScreenTexts.DONE)); finishedSaveButton.setTooltip(pendingChanges ? Text.translatable("yacl.gui.save.tooltip") : Text.translatable("yacl.gui.finished.tooltip")); - cancelResetButton.setMessage(pendingChanges ? ScreenTexts.CANCEL : Text.translatable("controls.reset")); + cancelResetButton.setMessage(pendingChanges ? GuiUtils.translatableFallback("yacl.gui.cancel", ScreenTexts.CANCEL) : Text.translatable("controls.reset")); cancelResetButton.setTooltip(pendingChanges ? Text.translatable("yacl.gui.cancel.tooltip") : Text.translatable("yacl.gui.reset.tooltip")); } diff --git a/src/client/java/dev/isxander/yacl/gui/controllers/ControllerWidget.java b/src/client/java/dev/isxander/yacl/gui/controllers/ControllerWidget.java index 9a16d22..0f49d3d 100644 --- a/src/client/java/dev/isxander/yacl/gui/controllers/ControllerWidget.java +++ b/src/client/java/dev/isxander/yacl/gui/controllers/ControllerWidget.java @@ -4,8 +4,7 @@ import dev.isxander.yacl.api.Controller; import dev.isxander.yacl.api.utils.Dimension; import dev.isxander.yacl.gui.AbstractWidget; import dev.isxander.yacl.gui.YACLScreen; -import dev.isxander.yacl.gui.utils.RenderUtils; -import dev.isxander.yacl.impl.utils.YACLConstants; +import dev.isxander.yacl.gui.utils.GuiUtils; import net.minecraft.client.font.MultilineText; import net.minecraft.client.gui.DrawableHelper; import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder; @@ -39,7 +38,7 @@ public abstract class ControllerWidget<T extends Controller<?>> extends Abstract hovered = isMouseOver(mouseX, mouseY); Text name = control.option().changed() ? modifiedOptionName : control.option().name(); - Text shortenedName = Text.literal(RenderUtils.shortenString(name.getString(), textRenderer, getDimension().width() - getControlWidth() - getXPadding() - 7, "...")).fillStyle(name.getStyle()); + Text shortenedName = Text.literal(GuiUtils.shortenString(name.getString(), textRenderer, getDimension().width() - getControlWidth() - getXPadding() - 7, "...")).fillStyle(name.getStyle()); drawButtonRect(matrices, getDimension().x(), getDimension().y(), getDimension().xLimit(), getDimension().yLimit(), isHovered(), isAvailable()); matrices.push(); diff --git a/src/client/java/dev/isxander/yacl/gui/controllers/string/StringControllerElement.java b/src/client/java/dev/isxander/yacl/gui/controllers/string/StringControllerElement.java index f536334..ef70341 100644 --- a/src/client/java/dev/isxander/yacl/gui/controllers/string/StringControllerElement.java +++ b/src/client/java/dev/isxander/yacl/gui/controllers/string/StringControllerElement.java @@ -4,7 +4,7 @@ import com.mojang.blaze3d.systems.RenderSystem; import dev.isxander.yacl.api.utils.Dimension; import dev.isxander.yacl.gui.YACLScreen; import dev.isxander.yacl.gui.controllers.ControllerWidget; -import dev.isxander.yacl.gui.utils.RenderUtils; +import dev.isxander.yacl.gui.utils.GuiUtils; import net.minecraft.client.gui.DrawableHelper; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.util.InputUtil; @@ -49,12 +49,12 @@ public class StringControllerElement extends ControllerWidget<IStringController< @Override protected void drawValueText(MatrixStack matrices, int mouseX, int mouseY, float delta) { Text valueText = getValueText(); - if (!isHovered()) valueText = Text.literal(RenderUtils.shortenString(valueText.getString(), textRenderer, getDimension().width() / 2, "...")).setStyle(valueText.getStyle()); + if (!isHovered()) valueText = Text.literal(GuiUtils.shortenString(valueText.getString(), textRenderer, getDimension().width() / 2, "...")).setStyle(valueText.getStyle()); matrices.push(); int textX = getDimension().xLimit() - textRenderer.getWidth(valueText) + renderOffset - getXPadding(); matrices.translate(textX, getTextY(), 0); - RenderUtils.enableScissor(inputFieldBounds.x(), inputFieldBounds.y(), inputFieldBounds.width() + 1, inputFieldBounds.height() + 2); + GuiUtils.enableScissor(inputFieldBounds.x(), inputFieldBounds.y(), inputFieldBounds.width() + 1, inputFieldBounds.height() + 2); textRenderer.drawWithShadow(matrices, valueText, 0, 0, getValueColor()); matrices.pop(); diff --git a/src/client/java/dev/isxander/yacl/gui/utils/RenderUtils.java b/src/client/java/dev/isxander/yacl/gui/utils/GuiUtils.java index 222517b..670bd12 100644 --- a/src/client/java/dev/isxander/yacl/gui/utils/RenderUtils.java +++ b/src/client/java/dev/isxander/yacl/gui/utils/GuiUtils.java @@ -3,15 +3,18 @@ package dev.isxander.yacl.gui.utils; import com.mojang.blaze3d.systems.RenderSystem; import net.minecraft.client.MinecraftClient; import net.minecraft.client.font.TextRenderer; -import net.minecraft.client.util.TextCollector; import net.minecraft.client.util.Window; -import net.minecraft.text.*; +import net.minecraft.text.MutableText; +import net.minecraft.text.Text; +import net.minecraft.util.Language; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; +public class GuiUtils { + public static MutableText translatableFallback(String key, Text fallback) { + if (Language.getInstance().hasTranslation(key)) + return Text.translatable(key); + return fallback.copy(); + } -public class RenderUtils { public static void enableScissor(int x, int y, int width, int height) { Window window = MinecraftClient.getInstance().getWindow(); double d = window.getScaleFactor(); |