55import static gregtech .common .gui .modularui .widget .SteamGaugeWidget .GAUGE_NEEDLE_WIDTH ;
66import static gregtech .common .gui .modularui .widget .SteamGaugeWidget .GAUGE_SIZE ;
77
8+ import java .lang .reflect .Constructor ;
9+ import java .lang .reflect .InvocationTargetException ;
10+
811import com .cleanroommc .modularui .api .IThemeApi ;
9- import com .cleanroommc .modularui .api .drawable .IDrawable ;
1012import com .cleanroommc .modularui .drawable .DrawableStack ;
1113import com .cleanroommc .modularui .drawable .GuiTextures ;
1214import com .cleanroommc .modularui .drawable .Rectangle ;
15+ import com .cleanroommc .modularui .theme .SelectableTheme ;
1316import com .cleanroommc .modularui .theme .SlotTheme ;
1417import com .cleanroommc .modularui .theme .WidgetTheme ;
1518import com .cleanroommc .modularui .theme .WidgetThemeKey ;
1619import com .cleanroommc .modularui .theme .WidgetThemeParser ;
1720import com .cleanroommc .modularui .utils .Color ;
18- import com .cleanroommc .modularui .utils .JsonHelper ;
1921import com .cleanroommc .modularui .widget .Widget ;
22+ import com .google .gson .JsonObject ;
2023
2124import gregtech .common .modularui2 .theme .ProgressbarWidgetTheme ;
2225
@@ -122,7 +125,7 @@ public final class GTWidgetThemes {
122125 .defaultTheme (
123126 new WidgetTheme (GAUGE_NEEDLE_WIDTH , GAUGE_NEEDLE_HEIGHT , null , Color .BROWN .main , 0xFF404040 , false , 0 ))
124127 .defaultHoverTheme (null )
125- .parser (noInheritanceParser ())
128+ .parser (noInheritanceParser (WidgetTheme . class ))
126129 .register ();
127130
128131 public static WidgetThemeKey <WidgetTheme > BUTTON_COVER_TAB_ENABLED = registerThemedButton ("buttonCoverTabEnabled" );
@@ -135,6 +138,41 @@ public final class GTWidgetThemes {
135138 .defaultHoverTheme (null )
136139 .register ();
137140
141+ public static WidgetThemeKey <SelectableTheme > TOGGLE_BUTTON_DISABLED = themeApi
142+ .widgetThemeKeyBuilder ("toggleButtonDisabled" , SelectableTheme .class )
143+ .defaultTheme (
144+ new SelectableTheme (
145+ 18 ,
146+ 18 ,
147+ GTGuiTextures .TOGGLE_BUTTON_STANDARD_DISABLED .getSubArea (0 , 0 , 1 , 0.5f ),
148+ Color .argb (1f , 1f , 1f , 0.5f ),
149+ 0xFAFAFA ,
150+ false ,
151+ 0 ,
152+ GTGuiTextures .TOGGLE_BUTTON_STANDARD_DISABLED .getSubArea (0 , 0.5f , 1 , 1 ),
153+ Color .argb (1f , 1f , 1f , 0.5f ),
154+ 0xFAFAFA ,
155+ false ,
156+ 0 ))
157+ .defaultHoverTheme (null )
158+ .parser (noInheritanceParser (SelectableTheme .class ))
159+ .register ();
160+
161+ public static WidgetThemeKey <WidgetTheme > BUTTON_DISABLED = themeApi
162+ .widgetThemeKeyBuilder ("buttonDisabled" , WidgetTheme .class )
163+ .defaultTheme (
164+ new WidgetTheme (
165+ 18 ,
166+ 18 ,
167+ GTGuiTextures .BUTTON_STANDARD_DISABLED ,
168+ Color .argb (1f , 1f , 1f , 0.5f ),
169+ 0xFAFAFA ,
170+ false ,
171+ 0 ))
172+ .defaultHoverTheme (null )
173+ .parser (noInheritanceParser (WidgetTheme .class ))
174+ .register ();
175+
138176 public static WidgetThemeKey <WidgetTheme > PICTURE_CANISTER = registerThemedTexture ("pictureCanister" );
139177 public static WidgetThemeKey <WidgetTheme > PICTURE_LOGO = registerThemedTexture ("pictureLogo" );
140178 public static WidgetThemeKey <WidgetTheme > PICTURE_ERROR = registerThemedTexture ("pictureError" );
@@ -151,7 +189,7 @@ public final class GTWidgetThemes {
151189 false ,
152190 0 ))
153191 .defaultHoverTheme (null )
154- .parser (noInheritanceParser ())
192+ .parser (noInheritanceParser (WidgetTheme . class ))
155193 .register ();
156194
157195 public static WidgetThemeKey <WidgetTheme > TESLA_TOWER_CHART_SPECIAL = themeApi
@@ -168,7 +206,7 @@ public final class GTWidgetThemes {
168206 false ,
169207 0 ))
170208 .defaultHoverTheme (null )
171- .parser (noInheritanceParser ())
209+ .parser (noInheritanceParser (WidgetTheme . class ))
172210 .register ();
173211
174212 private static WidgetThemeKey <WidgetTheme > registerThemedTexture (String textureThemeId ) {
@@ -200,20 +238,22 @@ private static WidgetThemeKey<WidgetTheme> registerThemedButton(String textureTh
200238 }
201239
202240 // Needed because by default it will inherit the global color
203- private static WidgetThemeParser <WidgetTheme > noInheritanceParser () {
204- return (parent , json , fallback ) -> {
205- int defaultWidth = JsonHelper .getInt (json , parent .getDefaultWidth (), "w" , "width" );
206- int defaultHeight = JsonHelper .getInt (json , parent .getDefaultHeight (), "h" , "height" );
207- IDrawable background = JsonHelper
208- .deserialize (json , IDrawable .class , parent .getBackground (), IThemeApi .BACKGROUND , "bg" );
209- int color = JsonHelper .getColorWithFallback (json , null , parent .getColor (), IThemeApi .COLOR );
210- int textColor = JsonHelper .getColorWithFallback (json , null , parent .getTextColor (), IThemeApi .TEXT_COLOR );
211- textColor = textColor == 0 ? color : textColor ;
212- boolean textShadow = JsonHelper
213- .getBoolWithFallback (json , null , parent .getTextShadow (), IThemeApi .TEXT_SHADOW );
214- int iconColor = JsonHelper .getColorWithFallback (json , null , parent .getIconColor (), IThemeApi .ICON_COLOR );
215- iconColor = iconColor == 0 ? color : iconColor ;
216- return new WidgetTheme (defaultWidth , defaultHeight , background , color , textColor , textShadow , iconColor );
217- };
241+ private static <T extends WidgetTheme > WidgetThemeParser <T > noInheritanceParser (Class <T > type ) {
242+ try {
243+ Constructor <T > ctor = type .getConstructor (type , JsonObject .class , JsonObject .class );
244+ return (parent , json , _ ) -> {
245+ try {
246+ return ctor .newInstance (parent , json , null );
247+ } catch (InstantiationException | IllegalAccessException | InvocationTargetException e ) {
248+ throw new RuntimeException ("Failed to instantiate widget theme of type " + type .getSimpleName (), e );
249+ }
250+ };
251+ } catch (NoSuchMethodException e ) {
252+ throw new RuntimeException (
253+ String .format (
254+ "No constructor with signature '%s(%s parent, JsonObject json, JsonObject fallback)' found" ,
255+ type .getSimpleName (),
256+ type .getSimpleName ()));
257+ }
218258 }
219259}
0 commit comments