diff --git a/src/main/java/me/fallenbreath/tweakermore/gui/WidgetHoverInfoNoTranslateHelper.java b/src/main/java/me/fallenbreath/tweakermore/gui/WidgetHoverInfoNoTranslateHelper.java new file mode 100644 index 00000000..9446effd --- /dev/null +++ b/src/main/java/me/fallenbreath/tweakermore/gui/WidgetHoverInfoNoTranslateHelper.java @@ -0,0 +1,30 @@ +/* + * This file is part of the TweakerMore project, licensed under the + * GNU Lesser General Public License v3.0 + * + * Copyright (C) 2024 Fallen_Breath and contributors + * + * TweakerMore is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * TweakerMore is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with TweakerMore. If not, see . + */ + +package me.fallenbreath.tweakermore.gui; + +/** + * Redundant {@link fi.dy.masa.malilib.util.StringUtils#translate} calls might mess up strings with "%" inside, + * creating unexpected strings like "Format error: ", which is bad + */ +public class WidgetHoverInfoNoTranslateHelper +{ + public static final ThreadLocal dontTranslate = ThreadLocal.withInitial(() -> false); +} diff --git a/src/main/java/me/fallenbreath/tweakermore/mixins/core/gui/panel/noDoubleCommentTranslate/WidgetConfigOptionMixin.java b/src/main/java/me/fallenbreath/tweakermore/mixins/core/gui/panel/noDoubleCommentTranslate/WidgetConfigOptionMixin.java new file mode 100644 index 00000000..e80d3e36 --- /dev/null +++ b/src/main/java/me/fallenbreath/tweakermore/mixins/core/gui/panel/noDoubleCommentTranslate/WidgetConfigOptionMixin.java @@ -0,0 +1,68 @@ +/* + * This file is part of the TweakerMore project, licensed under the + * GNU Lesser General Public License v3.0 + * + * Copyright (C) 2024 Fallen_Breath and contributors + * + * TweakerMore is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * TweakerMore is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with TweakerMore. If not, see . + */ + +package me.fallenbreath.tweakermore.mixins.core.gui.panel.noDoubleCommentTranslate; + +import fi.dy.masa.malilib.gui.GuiConfigsBase; +import fi.dy.masa.malilib.gui.widgets.WidgetConfigOption; +import fi.dy.masa.malilib.gui.widgets.WidgetConfigOptionBase; +import fi.dy.masa.malilib.gui.widgets.WidgetListConfigOptions; +import fi.dy.masa.malilib.gui.widgets.WidgetListConfigOptionsBase; +import me.fallenbreath.tweakermore.gui.TweakerMoreConfigGui; +import me.fallenbreath.tweakermore.gui.WidgetHoverInfoNoTranslateHelper; +import me.fallenbreath.tweakermore.mixins.core.gui.access.WidgetListConfigOptionsAccessor; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(WidgetConfigOption.class) +public abstract class WidgetConfigOptionMixin extends WidgetConfigOptionBase +{ + public WidgetConfigOptionMixin(int x, int y, int width, int height, WidgetListConfigOptionsBase parent, GuiConfigsBase.ConfigOptionWrapper entry, int listIndex) + { + super(x, y, width, height, parent, entry, listIndex); + } + + @Unique + private boolean isTweakerMoreConfigGui() + { + return this.parent instanceof WidgetListConfigOptions && ((WidgetListConfigOptionsAccessor)this.parent).getParent() instanceof TweakerMoreConfigGui; + } + + @Inject(method = "addConfigComment", at = @At("HEAD"), remap = false) + private void doNotTranslateTheCommentAgainPlease_set(CallbackInfo ci) + { + if (isTweakerMoreConfigGui()) + { + WidgetHoverInfoNoTranslateHelper.dontTranslate.set(true); + } + } + + @Inject(method = "addConfigComment", at = @At("TAIL"), remap = false) + private void doNotTranslateTheCommentAgainPlease_unset(CallbackInfo ci) + { + if (isTweakerMoreConfigGui()) + { + WidgetHoverInfoNoTranslateHelper.dontTranslate.remove(); + } + } +} diff --git a/src/main/java/me/fallenbreath/tweakermore/mixins/core/gui/panel/noDoubleCommentTranslate/WidgetHoverInfoMixin.java b/src/main/java/me/fallenbreath/tweakermore/mixins/core/gui/panel/noDoubleCommentTranslate/WidgetHoverInfoMixin.java new file mode 100644 index 00000000..2bb2dd13 --- /dev/null +++ b/src/main/java/me/fallenbreath/tweakermore/mixins/core/gui/panel/noDoubleCommentTranslate/WidgetHoverInfoMixin.java @@ -0,0 +1,57 @@ +/* + * This file is part of the TweakerMore project, licensed under the + * GNU Lesser General Public License v3.0 + * + * Copyright (C) 2024 Fallen_Breath and contributors + * + * TweakerMore is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * TweakerMore is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with TweakerMore. If not, see . + */ + +package me.fallenbreath.tweakermore.mixins.core.gui.panel.noDoubleCommentTranslate; + +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; +import fi.dy.masa.malilib.gui.widgets.WidgetHoverInfo; +import me.fallenbreath.tweakermore.gui.WidgetHoverInfoNoTranslateHelper; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; + +@Mixin(WidgetHoverInfo.class) +public abstract class WidgetHoverInfoMixin +{ + @WrapOperation( + method = { + "setInfoLines", + "addLines" + }, + at = @At( + value = "INVOKE", + target = "Lfi/dy/masa/malilib/util/StringUtils;translate(Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;", + remap = false + ), + remap = false + ) + private String dontTranslateIfTheFlagIsSet(String translationKey, Object[] args, Operation original) + { + if (WidgetHoverInfoNoTranslateHelper.dontTranslate.get()) + { + if (args.length > 0) + { + throw new RuntimeException("dontTranslate is set to true, but args is still provided"); + } + return translationKey; + } + return original.call(translationKey, args); + } +} diff --git a/src/main/resources/tweakermore.mixins.json b/src/main/resources/tweakermore.mixins.json index 0caede36..04439e74 100644 --- a/src/main/resources/tweakermore.mixins.json +++ b/src/main/resources/tweakermore.mixins.json @@ -16,6 +16,8 @@ "core.gui.panel.dropDownListRedraw.WidgetListBaseMixin", "core.gui.panel.labelWithOriginalText.WidgetListConfigOptionMixin", "core.gui.panel.labelWithOriginalText.WidgetListConfigOptionsMixin", + "core.gui.panel.noDoubleCommentTranslate.WidgetConfigOptionMixin", + "core.gui.panel.noDoubleCommentTranslate.WidgetHoverInfoMixin", "core.gui.panel.ocd.WidgetListConfigOptionMixin", "core.gui.panel.searchBar.WidgetListConfigOptionsMixin", "core.gui.panel.widthTweak.WidgetListConfigOptionsMixin",