11package gregtech .mixins .mui2 ;
22
3- import com .cleanroommc .modularui .api .ITheme ;
3+ import gregtech .api .mui .UnboxFix ;
4+
45import com .cleanroommc .modularui .api .drawable .IKey ;
56import com .cleanroommc .modularui .drawable .text .AnimatedText ;
67import com .cleanroommc .modularui .drawable .text .StyledText ;
8+ import com .cleanroommc .modularui .theme .WidgetTheme ;
79import com .cleanroommc .modularui .utils .Alignment ;
810import com .cleanroommc .modularui .widgets .TextWidget ;
11+ import com .llamalad7 .mixinextras .sugar .Local ;
912import org .spongepowered .asm .mixin .Final ;
1013import org .spongepowered .asm .mixin .Mixin ;
1114import org .spongepowered .asm .mixin .Overwrite ;
1215import 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}
0 commit comments