Skip to content

Commit b9fb922

Browse files
committed
improve key util methods some more
fix comp keys losing formatting actually draw the formatted keys
1 parent 91c6b61 commit b9fb922

File tree

4 files changed

+35
-19
lines changed

4 files changed

+35
-19
lines changed

src/main/java/gregtech/api/mui/widget/GregtechDisplayScreen.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public void draw(ModularGuiContext context, WidgetTheme widgetTheme) {
9595
for (var key : syncHandler.builtKeys) {
9696
if (key == null) continue;
9797
textRenderer.setPos(x, y);
98-
textRenderer.draw(key.get());
98+
textRenderer.draw(key.getFormatted());
9999
y += 12;
100100
}
101101
}

src/main/java/gregtech/api/util/KeyUtil.java

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.cleanroommc.modularui.api.drawable.IKey;
66
import org.apache.commons.lang3.ArrayUtils;
77

8+
import java.util.Arrays;
89
import java.util.function.LongSupplier;
910
import java.util.function.Supplier;
1011

@@ -23,7 +24,7 @@ public static IKey string(String s) {
2324
}
2425

2526
public static IKey string(Supplier<String> s) {
26-
return string(TextFormatting.RESET, s);
27+
return IKey.dynamic(s);
2728
}
2829

2930
public static IKey string(TextFormatting formatting, String string) {
@@ -36,31 +37,29 @@ public static IKey string(TextFormatting formatting, Supplier<String> stringSupp
3637
}
3738

3839
public static IKey string(Supplier<TextFormatting> formatting, String s) {
39-
return IKey.dynamic(() -> formatting.get() + s);
40+
return IKey.dynamic(() -> IKey.str(s).format(formatting.get()).getFormatted());
4041
}
4142

4243
public static IKey string(Supplier<TextFormatting> formatting, Supplier<String> stringSupplier) {
43-
return IKey.dynamic(() -> formatting.get() + stringSupplier.get());
44+
return IKey.dynamic(() -> IKey.str(stringSupplier.get()).format(formatting.get()).getFormatted());
4445
}
4546

4647
public static IKey lang(String lang, Object... args) {
47-
return lang(TextFormatting.RESET, lang, args);
48+
return IKey.lang(lang, args);
4849
}
4950

5051
public static IKey lang(TextFormatting formatting, String lang, Object... args) {
51-
return IKey.lang(lang, args).format(formatting);
52+
return IKey.lang(lang, checkFormatting(formatting, args)).format(formatting);
5253
}
5354

5455
public static IKey lang(TextFormatting formatting, String lang, Supplier<?>... argSuppliers) {
55-
if (ArrayUtils.isEmpty(argSuppliers)) return colored(formatting, IKey.lang(lang));
56+
if (ArrayUtils.isEmpty(argSuppliers)) return IKey.lang(lang).format(formatting);
5657
if (argSuppliers.length == 1)
57-
return string(formatting, () -> IKey.lang(lang, fixArg(formatting, argSuppliers[0].get())).get());
58-
final Object[] fixedArgs = new Object[argSuppliers.length];
58+
return IKey.dynamic(() -> IKey.lang(lang, fixArg(formatting, argSuppliers[0].get())).format(formatting).getFormatted());
59+
final Object[] args = new Object[argSuppliers.length];
5960
return IKey.dynamic(() -> {
60-
for (int i = 0; i < fixedArgs.length; i++) {
61-
fixedArgs[i] = fixArg(formatting, argSuppliers[i].get());
62-
}
63-
return formatting + IKey.lang(lang, fixedArgs).get();
61+
Arrays.setAll(args, value -> fixArg(formatting, argSuppliers[value].get()));
62+
return IKey.lang(lang, args).format(formatting).getFormatted();
6463
});
6564
}
6665

@@ -97,16 +96,13 @@ private static IKey wrap(TextFormatting formatting) {
9796
}
9897

9998
private static Object[] checkFormatting(TextFormatting formatting, Object[] args) {
100-
Object[] fixedArgs = new Object[args.length];
101-
for (int i = 0; i < args.length; i++) {
102-
fixedArgs[i] = fixArg(formatting, args[i]);
103-
}
104-
return fixedArgs;
99+
Arrays.setAll(args, value -> fixArg(formatting, args[value]));
100+
return args;
105101
}
106102

107103
private static Object fixArg(TextFormatting formatting, Object arg) {
108104
if (arg instanceof IKey key) {
109-
if (hasFormatting(key.get()))
105+
if (hasFormatting(key.getFormatted()))
110106
return IKey.comp(key, wrap(formatting));
111107
} else if (arg instanceof String s) {
112108
if (hasFormatting(s))
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package gregtech.mixins.mui2;
2+
3+
import com.cleanroommc.modularui.api.drawable.IKey;
4+
import com.cleanroommc.modularui.drawable.text.BaseKey;
5+
6+
import com.cleanroommc.modularui.drawable.text.CompoundKey;
7+
8+
import org.spongepowered.asm.mixin.Mixin;
9+
import org.spongepowered.asm.mixin.injection.At;
10+
import org.spongepowered.asm.mixin.injection.Redirect;
11+
12+
@Mixin(value = CompoundKey.class, remap = false)
13+
public abstract class KeyCompMixin extends BaseKey {
14+
15+
@Redirect(method = "get", at = @At(value = "INVOKE", target = "Lcom/cleanroommc/modularui/api/drawable/IKey;get()Ljava/lang/String;"))
16+
public String formatTheKeys(IKey key) {
17+
return key.getFormatted();
18+
}
19+
}

src/main/resources/mixins.gregtech.mui2.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
},
1010
"mixins": [
1111
"ItemSlotSHMixin",
12+
"KeyCompMixin",
1213
"PanelSyncHandlerMixin",
1314
"PanelSyncManagerMixin",
1415
"StyledTextMixin",

0 commit comments

Comments
 (0)