generated from Fallen-Breath/fabric-mod-template
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
malilib plz stop applying unwanted redundant translation for option c…
…omment hover string
- Loading branch information
1 parent
8f16aa8
commit a0e6a6d
Showing
4 changed files
with
157 additions
and
0 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
src/main/java/me/fallenbreath/tweakermore/gui/WidgetHoverInfoNoTranslateHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
68 changes: 68 additions & 0 deletions
68
...h/tweakermore/mixins/core/gui/panel/noDoubleCommentTranslate/WidgetConfigOptionMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
...eath/tweakermore/mixins/core/gui/panel/noDoubleCommentTranslate/WidgetHoverInfoMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters