From 15a1eb7886875c728dbc860e46e04e814725b967 Mon Sep 17 00:00:00 2001 From: Fallen_Breath Date: Sat, 12 Feb 2022 15:46:43 +0800 Subject: [PATCH] Fixed `applyTweakerMoreOptionLabelGlobally` does not work with options with custom translation key now it works correctly with MasaGadget --- .../gui/TweakerMoreOptionLabel.java | 30 +++++++++---------- .../mixins/core/gui/WidgetLabelMixin.java | 4 +-- .../core/gui/WidgetListConfigOptionMixin.java | 11 ++++--- 3 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/main/java/me/fallenbreath/tweakermore/gui/TweakerMoreOptionLabel.java b/src/main/java/me/fallenbreath/tweakermore/gui/TweakerMoreOptionLabel.java index 72b3710e..eaa77c8b 100644 --- a/src/main/java/me/fallenbreath/tweakermore/gui/TweakerMoreOptionLabel.java +++ b/src/main/java/me/fallenbreath/tweakermore/gui/TweakerMoreOptionLabel.java @@ -1,9 +1,7 @@ package me.fallenbreath.tweakermore.gui; import fi.dy.masa.malilib.gui.widgets.WidgetLabel; -import me.fallenbreath.tweakermore.util.StringUtil; -import java.util.Arrays; import java.util.function.Function; /** @@ -13,33 +11,33 @@ public class TweakerMoreOptionLabel extends WidgetLabel { public static final double TRANSLATION_SCALE = 0.65; - private final String[] originalTexts; - private final boolean showOriginalTexts; + private final String[] originalLines; + private final boolean showOriginalLines; - public TweakerMoreOptionLabel(int x, int y, int width, int height, int textColor, String[] lines, Function lineModifier) + public TweakerMoreOptionLabel(int x, int y, int width, int height, int textColor, String[] displayLines, String[] originalLines, Function lineModifier) { - super(x, y, width, height, textColor, lines); - this.originalTexts = Arrays.stream(lines).map(StringUtil::removeTweakerMoreNameSpacePrefix).toArray(String[]::new); - boolean showOriginalNames = false; - for (int i = 0; i < this.originalTexts.length; i++) + super(x, y, width, height, textColor, displayLines); + this.originalLines = originalLines; + boolean showOriginalLines = false; + for (int i = 0; i < this.originalLines.length; i++) { String linesToDisplay = this.labels.get(i); - if (!this.originalTexts[i].equals(linesToDisplay)) + if (!this.originalLines[i].equals(linesToDisplay)) { - showOriginalNames = true; + showOriginalLines = true; } this.labels.set(i, lineModifier.apply(linesToDisplay)); } - this.showOriginalTexts = showOriginalNames; + this.showOriginalLines = showOriginalLines; } - public String[] getOriginalTexts() + public String[] getOriginalLines() { - return this.originalTexts; + return this.originalLines; } - public boolean shouldShowOriginalTexts() + public boolean shouldShowOriginalLines() { - return this.showOriginalTexts; + return this.showOriginalLines; } } diff --git a/src/main/java/me/fallenbreath/tweakermore/mixins/core/gui/WidgetLabelMixin.java b/src/main/java/me/fallenbreath/tweakermore/mixins/core/gui/WidgetLabelMixin.java index f8991801..57cad7fe 100644 --- a/src/main/java/me/fallenbreath/tweakermore/mixins/core/gui/WidgetLabelMixin.java +++ b/src/main/java/me/fallenbreath/tweakermore/mixins/core/gui/WidgetLabelMixin.java @@ -32,7 +32,7 @@ public WidgetLabelMixin(int x, int y, int width, int height) private boolean shouldUseTranslatedOptionLabelLogic() { WidgetLabel self = (WidgetLabel)(Object)this; - return self instanceof TweakerMoreOptionLabel && ((TweakerMoreOptionLabel)self).shouldShowOriginalTexts(); + return self instanceof TweakerMoreOptionLabel && ((TweakerMoreOptionLabel)self).shouldShowOriginalLines(); } @ModifyVariable( @@ -71,7 +71,7 @@ private void translatedOptionLabelRenderTranslation(int mouseX, int mouseY, bool { int color = darkerColor(this.textColor); double scale = TweakerMoreOptionLabel.TRANSLATION_SCALE; - String originText = ((TweakerMoreOptionLabel)(Object)this).getOriginalTexts()[i]; + String originText = ((TweakerMoreOptionLabel)(Object)this).getOriginalLines()[i]; int x = this.x + (this.centered ? this.width / 2 : 0); int y = (int)(yTextStart + (this.labels.size() + i * scale + 0.2) * fontHeight); diff --git a/src/main/java/me/fallenbreath/tweakermore/mixins/core/gui/WidgetListConfigOptionMixin.java b/src/main/java/me/fallenbreath/tweakermore/mixins/core/gui/WidgetListConfigOptionMixin.java index 438cc958..00265caa 100644 --- a/src/main/java/me/fallenbreath/tweakermore/mixins/core/gui/WidgetListConfigOptionMixin.java +++ b/src/main/java/me/fallenbreath/tweakermore/mixins/core/gui/WidgetListConfigOptionMixin.java @@ -27,7 +27,6 @@ import java.util.Objects; import java.util.function.Function; -import java.util.stream.IntStream; @Mixin(WidgetConfigOption.class) public abstract class WidgetListConfigOptionMixin extends WidgetConfigOptionBase @@ -108,21 +107,25 @@ private void useMyBetterOptionLabelForTweakerMore(Args args, int x_, int y_, flo int height = args.get(3); int textColor = args.get(4); String[] lines = args.get(5); + if (lines.length != 1) + { + return; + } args.set(5, null); // cancel original call Function modifier = s -> s; if (isTweakerMoreConfigGui()) { - IntStream.range(0, lines.length).forEach(i -> lines[i] = StringUtil.TWEAKERMORE_NAMESPACE_PREFIX + lines[i]); + lines[0] = StringUtil.TWEAKERMORE_NAMESPACE_PREFIX + lines[0]; if (!TweakerMoreConfigs.getOptionFromConfig(config).map(TweakerMoreOption::isEnabled).orElse(true)) { modifier = s -> GuiBase.TXT_DARK_RED + s + GuiBase.TXT_RST; } } - TweakerMoreOptionLabel label = new TweakerMoreOptionLabel(x, y, width, height, textColor, lines, modifier); + TweakerMoreOptionLabel label = new TweakerMoreOptionLabel(x, y, width, height, textColor, lines, new String[]{config.getName()}, modifier); this.addWidget(label); - this.showOriginalTextsThisTime = label.shouldShowOriginalTexts(); + this.showOriginalTextsThisTime = label.shouldShowOriginalLines(); } else {