Skip to content

Commit

Permalink
malilib plz stop applying unwanted redundant translation for option c…
Browse files Browse the repository at this point in the history
…omment hover string
  • Loading branch information
Fallen-Breath committed Jun 19, 2024
1 parent 8f16aa8 commit a0e6a6d
Show file tree
Hide file tree
Showing 4 changed files with 157 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.
*/

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<Boolean> dontTranslate = ThreadLocal.withInitial(() -> false);
}
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.
*/

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<GuiConfigsBase.ConfigOptionWrapper>
{
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();
}
}
}
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.
*/

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<String> 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);
}
}
2 changes: 2 additions & 0 deletions src/main/resources/tweakermore.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit a0e6a6d

Please sign in to comment.