Skip to content

Commit d619740

Browse files
committed
properly fix unboxing issue
1 parent 48341a7 commit d619740

File tree

3 files changed

+94
-16
lines changed

3 files changed

+94
-16
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package gregtech.api.mui;
2+
3+
public interface UnboxFix {
4+
5+
void gregTech$useDefaultTextColor(boolean b);
6+
7+
void gregTech$useDefaultShadow(boolean b);
8+
}

src/main/java/gregtech/mixins/mui2/StyledTextMixin.java

Lines changed: 46 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
11
package gregtech.mixins.mui2;
22

3-
import com.cleanroommc.modularui.api.ITheme;
3+
import gregtech.api.mui.UnboxFix;
4+
45
import com.cleanroommc.modularui.api.drawable.IKey;
56
import com.cleanroommc.modularui.drawable.text.AnimatedText;
67
import com.cleanroommc.modularui.drawable.text.StyledText;
8+
import com.cleanroommc.modularui.theme.WidgetTheme;
79
import com.cleanroommc.modularui.utils.Alignment;
810
import com.cleanroommc.modularui.widgets.TextWidget;
11+
import com.llamalad7.mixinextras.sugar.Local;
912
import org.spongepowered.asm.mixin.Final;
1013
import org.spongepowered.asm.mixin.Mixin;
1114
import org.spongepowered.asm.mixin.Overwrite;
1215
import org.spongepowered.asm.mixin.Shadow;
16+
import org.spongepowered.asm.mixin.Unique;
17+
import org.spongepowered.asm.mixin.injection.At;
18+
import org.spongepowered.asm.mixin.injection.ModifyArg;
1319

1420
@Mixin(value = StyledText.class, remap = false)
15-
public class StyledTextMixin {
21+
public abstract class StyledTextMixin implements UnboxFix {
1622

1723
@Shadow
1824
@Final
@@ -30,6 +36,22 @@ public class StyledTextMixin {
3036
@Shadow
3137
private Boolean shadow;
3238

39+
@Unique
40+
private boolean gregTech$defaultTextColor = true;
41+
42+
@Unique
43+
private boolean gregTech$defaultShadow = true;
44+
45+
@Override
46+
public void gregTech$useDefaultTextColor(boolean b) {
47+
gregTech$defaultTextColor = b;
48+
}
49+
50+
@Override
51+
public void gregTech$useDefaultShadow(boolean b) {
52+
gregTech$defaultShadow = b;
53+
}
54+
3355
/**
3456
* @author GTCEu - Ghzdude
3557
* @reason Implement <a href="https://github.com/CleanroomMC/ModularUI/pull/86">MUI2 PR#86</a>
@@ -40,12 +62,11 @@ public TextWidget asWidget() {
4062
.alignment(this.alignment)
4163
.scale(this.scale);
4264

43-
var theme = ITheme.getDefault().getTextFieldTheme();
44-
int color = this.color == null ? theme.getColor() : this.color;
45-
boolean shadow = this.shadow == null ? theme.getTextShadow() : this.shadow;
65+
((UnboxFix) text).gregTech$useDefaultTextColor(this.color == null);
66+
((UnboxFix) text).gregTech$useDefaultShadow(this.shadow == null);
4667

47-
return text.color(color)
48-
.shadow(shadow);
68+
return text.color(color == null ? 0 : color)
69+
.shadow(shadow != null && shadow);
4970
}
5071

5172
/**
@@ -58,11 +79,24 @@ public AnimatedText withAnimation() {
5879
.alignment(this.alignment)
5980
.scale(this.scale);
6081

61-
var theme = ITheme.getDefault().getTextFieldTheme();
62-
int color = this.color == null ? theme.getColor() : this.color;
63-
boolean shadow = this.shadow == null ? theme.getTextShadow() : this.shadow;
82+
((UnboxFix) text).gregTech$useDefaultTextColor(this.color == null);
83+
((UnboxFix) text).gregTech$useDefaultShadow(this.shadow == null);
84+
85+
return text.color(color == null ? 0 : color)
86+
.shadow(shadow != null && shadow);
87+
}
88+
89+
@ModifyArg(method = "draw",
90+
at = @At(value = "INVOKE",
91+
target = "Lcom/cleanroommc/modularui/drawable/text/TextRenderer;setColor(I)V"))
92+
public int fixColor(int color, @Local(argsOnly = true) WidgetTheme theme) {
93+
return gregTech$defaultTextColor ? theme.getTextColor() : color;
94+
}
6495

65-
return text.color(color)
66-
.shadow(shadow);
96+
@ModifyArg(method = "draw",
97+
at = @At(value = "INVOKE",
98+
target = "Lcom/cleanroommc/modularui/drawable/text/TextRenderer;setShadow(Z)V"))
99+
public boolean fixShadow(boolean shadow, @Local(argsOnly = true) WidgetTheme theme) {
100+
return gregTech$defaultShadow ? theme.getTextShadow() : shadow;
67101
}
68102
}
Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,57 @@
11
package gregtech.mixins.mui2;
22

3+
import gregtech.api.mui.UnboxFix;
4+
5+
import com.cleanroommc.modularui.theme.WidgetTheme;
36
import com.cleanroommc.modularui.widget.Widget;
47
import com.cleanroommc.modularui.widgets.TextWidget;
58
import com.llamalad7.mixinextras.injector.ModifyReturnValue;
9+
import com.llamalad7.mixinextras.sugar.Local;
610
import org.spongepowered.asm.mixin.Mixin;
11+
import org.spongepowered.asm.mixin.Unique;
712
import org.spongepowered.asm.mixin.injection.At;
13+
import org.spongepowered.asm.mixin.injection.ModifyArg;
814

915
@Mixin(value = TextWidget.class, remap = false)
10-
public abstract class TextWidgetMixin extends Widget<TextWidget> {
16+
public abstract class TextWidgetMixin extends Widget<TextWidget> implements UnboxFix {
1117

12-
@ModifyReturnValue(method = { "getDefaultHeight", "getDefaultWidth" }, at = @At("TAIL"))
13-
public int clamp(int r) {
14-
return Math.max(1, r);
18+
@Unique
19+
private boolean gregTech$defaultTextColor = true;
20+
21+
@Unique
22+
private boolean gregTech$defaultShadow = true;
23+
24+
@Override
25+
public void gregTech$useDefaultTextColor(boolean b) {
26+
gregTech$defaultTextColor = b;
27+
}
28+
29+
@Override
30+
public void gregTech$useDefaultShadow(boolean b) {
31+
gregTech$defaultShadow = b;
1532
}
1633

1734
@Override
1835
public boolean canHover() {
1936
return hasTooltip();
2037
}
38+
39+
@ModifyReturnValue(method = { "getDefaultHeight", "getDefaultWidth" }, at = @At("TAIL"))
40+
public int clamp(int r) {
41+
return Math.max(1, r);
42+
}
43+
44+
@ModifyArg(method = "draw",
45+
at = @At(value = "INVOKE",
46+
target = "Lcom/cleanroommc/modularui/drawable/text/TextRenderer;setColor(I)V"))
47+
public int fixColor(int color, @Local(argsOnly = true) WidgetTheme theme) {
48+
return gregTech$defaultTextColor ? theme.getTextColor() : color;
49+
}
50+
51+
@ModifyArg(method = "draw",
52+
at = @At(value = "INVOKE",
53+
target = "Lcom/cleanroommc/modularui/drawable/text/TextRenderer;setShadow(Z)V"))
54+
public boolean fixShadow(boolean shadow, @Local(argsOnly = true) WidgetTheme theme) {
55+
return gregTech$defaultShadow ? theme.getTextShadow() : shadow;
56+
}
2157
}

0 commit comments

Comments
 (0)