Skip to content

Commit 6e32345

Browse files
TheYoingLadDream-MasterRanzuu
authored
[MUI2] Added Disabled Button Themes (#7048)
Co-authored-by: Martin Robertz <dream-master@gmx.net> Co-authored-by: Ranzu <66495944+Ranzuu@users.noreply.github.com>
1 parent 295e8fe commit 6e32345

18 files changed

Lines changed: 284 additions & 303 deletions

File tree

src/main/java/gregtech/api/modularui2/GTGuiTextures.java

Lines changed: 59 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -498,22 +498,27 @@ public static void init() {}
498498
.build();
499499

500500
public static final UITexture OVERLAY_BUTTON_VOID_EXCESS_NONE = UITexture.builder()
501+
.nonOpaque()
501502
.canApplyTheme()
502503
.location(GregTech.ID, "gui/overlay_button/void_excess_none")
503504
.build();
504505
public static final UITexture OVERLAY_BUTTON_VOID_EXCESS_ITEM = UITexture.builder()
506+
.nonOpaque()
505507
.canApplyTheme()
506508
.location(GregTech.ID, "gui/overlay_button/void_excess_item")
507509
.build();
508510
public static final UITexture OVERLAY_BUTTON_VOID_EXCESS_FLUID = UITexture.builder()
511+
.nonOpaque()
509512
.canApplyTheme()
510513
.location(GregTech.ID, "gui/overlay_button/void_excess_fluid")
511514
.build();
512515
public static final UITexture OVERLAY_BUTTON_VOID_EXCESS_ALL = UITexture.builder()
516+
.nonOpaque()
513517
.canApplyTheme()
514518
.location(GregTech.ID, "gui/overlay_button/void_excess_all")
515519
.build();
516520
public static final UITexture OVERLAY_BUTTON_AUTOOUTPUT_FLUID = UITexture.builder()
521+
.nonOpaque()
517522
.canApplyTheme()
518523
.fullImage()
519524
.location(GregTech.ID, "gui/overlay_button/autooutput_fluid")
@@ -538,42 +543,42 @@ public static void init() {}
538543
.fullImage()
539544
.location(GregTech.ID, "gui/overlay_button/tank_void_all")
540545
.build();
541-
public static final UITexture OVERLAY_BUTTON_INPUT_SEPARATION_ON = fullImage(
542-
GregTech.ID,
543-
"gui/overlay_button/input_separation_on");
544-
public static final UITexture OVERLAY_BUTTON_INPUT_SEPARATION_ON_DISABLED = fullImage(
545-
GregTech.ID,
546-
"gui/overlay_button/input_separation_on_disabled");
547-
public static final UITexture OVERLAY_BUTTON_INPUT_SEPARATION_OFF = fullImage(
548-
GregTech.ID,
549-
"gui/overlay_button/input_separation_off");
550-
public static final UITexture OVERLAY_BUTTON_INPUT_SEPARATION_OFF_DISABLED = fullImage(
551-
GregTech.ID,
552-
"gui/overlay_button/input_separation_off_disabled");
553-
public static final UITexture OVERLAY_BUTTON_RECIPE_UNLOCKED = fullImage(
554-
GregTech.ID,
555-
"gui/overlay_button/recipe_unlocked");
556-
public static final UITexture OVERLAY_BUTTON_RECIPE_UNLOCKED_DISABLED = fullImage(
557-
GregTech.ID,
558-
"gui/overlay_button/recipe_unlocked_disabled");
559-
public static final UITexture OVERLAY_BUTTON_RECIPE_LOCKED = fullImage(
560-
GregTech.ID,
561-
"gui/overlay_button/recipe_locked");
562-
public static final UITexture OVERLAY_BUTTON_RECIPE_LOCKED_DISABLED = fullImage(
563-
GregTech.ID,
564-
"gui/overlay_button/recipe_locked_disabled");
565-
public static final UITexture OVERLAY_BUTTON_BATCH_MODE_ON = fullImage(
566-
GregTech.ID,
567-
"gui/overlay_button/batch_mode_on");
568-
public static final UITexture OVERLAY_BUTTON_BATCH_MODE_ON_DISABLED = fullImage(
569-
GregTech.ID,
570-
"gui/overlay_button/batch_mode_on_disabled");
571-
public static final UITexture OVERLAY_BUTTON_BATCH_MODE_OFF = fullImage(
572-
GregTech.ID,
573-
"gui/overlay_button/batch_mode_off");
574-
public static final UITexture OVERLAY_BUTTON_BATCH_MODE_OFF_DISABLED = fullImage(
575-
GregTech.ID,
576-
"gui/overlay_button/batch_mode_off_disabled");
546+
public static final UITexture OVERLAY_BUTTON_INPUT_SEPARATION_ON = UITexture.builder()
547+
.nonOpaque()
548+
.canApplyTheme()
549+
.fullImage()
550+
.location(GregTech.ID, "gui/overlay_button/input_separation_on")
551+
.build();
552+
public static final UITexture OVERLAY_BUTTON_INPUT_SEPARATION_OFF = UITexture.builder()
553+
.nonOpaque()
554+
.canApplyTheme()
555+
.fullImage()
556+
.location(GregTech.ID, "gui/overlay_button/input_separation_off")
557+
.build();
558+
public static final UITexture OVERLAY_BUTTON_RECIPE_UNLOCKED = UITexture.builder()
559+
.nonOpaque()
560+
.canApplyTheme()
561+
.fullImage()
562+
.location(GregTech.ID, "gui/overlay_button/recipe_unlocked")
563+
.build();
564+
public static final UITexture OVERLAY_BUTTON_RECIPE_LOCKED = UITexture.builder()
565+
.nonOpaque()
566+
.canApplyTheme()
567+
.fullImage()
568+
.location(GregTech.ID, "gui/overlay_button/recipe_locked")
569+
.build();
570+
public static final UITexture OVERLAY_BUTTON_BATCH_MODE_ON = UITexture.builder()
571+
.nonOpaque()
572+
.canApplyTheme()
573+
.fullImage()
574+
.location(GregTech.ID, "gui/overlay_button/batch_mode_on")
575+
.build();
576+
public static final UITexture OVERLAY_BUTTON_BATCH_MODE_OFF = UITexture.builder()
577+
.nonOpaque()
578+
.canApplyTheme()
579+
.fullImage()
580+
.location(GregTech.ID, "gui/overlay_button/batch_mode_off")
581+
.build();
577582
public static final UITexture OVERLAY_BUTTON_STRUCTURE_UPDATE = fullImage(
578583
GregTech.ID,
579584
"gui/overlay_button/structure_update");
@@ -1358,6 +1363,12 @@ public static void init() {}
13581363
.adaptable(1)
13591364
.canApplyTheme()
13601365
.build();
1366+
public static final UITexture TOGGLE_BUTTON_STANDARD_DISABLED = UITexture.builder()
1367+
.location(GregTech.ID, "gui/button/standard_toggle_disabled")
1368+
.imageSize(18, 18)
1369+
.adaptable(1)
1370+
.canApplyTheme()
1371+
.build();
13611372
public static final SteamTexture BUTTON_STEAM_PRESSED = SteamTexture.builder()
13621373
.location("gui/button/%s_pressed")
13631374
.imageSize(18, 18)
@@ -1571,7 +1582,12 @@ public static void init() {}
15711582
.build())
15721583
.toArray(UITexture[]::new);
15731584

1574-
public static final UITexture TT_BUTTON_CELESTIAL_32x32 = UITexture.fullImage(MODID, "gui/button/celestial");
1585+
public static final UITexture TT_BUTTON_CELESTIAL_32x32 = UITexture.builder()
1586+
.location(MODID, "gui/button/celestial")
1587+
.fullImage()
1588+
.canApplyTheme()
1589+
.name(GTTextureIds.BUTTON_GORGE)
1590+
.build();
15751591

15761592
public static final UITexture OVERLAY_BUTTON_POWER_PASS_ON = UITexture
15771593
.fullImage(MODID, "gui/overlay_button/power_pass_on");
@@ -1587,8 +1603,12 @@ public static void init() {}
15871603
.fullImage("goodgenerator", "gui/overlay_button/assembler_mode");
15881604
public static final UITexture OVERLAY_BUTTON_PRECISE_MODE = UITexture
15891605
.fullImage("goodgenerator", "gui/overlay_button/precise_mode");
1590-
public static final UITexture OVERLAY_BUTTON_AUTOOUTPUT_ITEM = UITexture
1591-
.fullImage(GregTech.ID, "gui/overlay_button/autooutput_item");
1606+
public static final UITexture OVERLAY_BUTTON_AUTOOUTPUT_ITEM = UITexture.builder()
1607+
.nonOpaque()
1608+
.canApplyTheme()
1609+
.fullImage()
1610+
.location(GregTech.ID, "gui/overlay_button/autooutput_item")
1611+
.build();
15921612
public static final UITexture OVERLAY_BUTTON_AUTOPULL_ME = UITexture
15931613
.fullImage(GregTech.ID, "gui/overlay_button/auto_pull_me");
15941614
public static final UITexture OVERLAY_BUTTON_AUTOPULL_ME_DISABLED = UITexture

src/main/java/gregtech/api/modularui2/GTGuiTheme.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,7 @@ public Builder progressbar(String textureThemeId, String emptyTextureId, String
545545

546546
/**
547547
* A shorthand for applying a Dye to every (non-text) part of the UI theme
548-
*
548+
*
549549
* @param dye - dye to apply
550550
* @return this
551551
*/

src/main/java/gregtech/api/modularui2/GTGuiThemes.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,11 @@ public static void init() {
236236
.themedTexture(GTWidgetThemes.PICTURE_LOGO.getFullName(), GTTextureIds.PICTURE_TECTECH_LOGO)
237237
.themedTexture(GTWidgetThemes.BACKGROUND_TERMINAL.getFullName(), GTTextureIds.BACKGROUND_TERMINAL_TECTECH)
238238
.build();
239+
public static final GTGuiTheme GORGE = GTGuiTheme.builder("gorge")
240+
.parent(TECTECH_STANDARD)
241+
.button(GTTextureIds.BUTTON_GORGE)
242+
.simpleToggleButton(GTTextureIds.BUTTON_GORGE, GTTextureIds.BUTTON_GORGE, Dyes.MACHINE_METAL.toInt())
243+
.build();
239244
public static final GTGuiTheme EXOFOUNDRY = GTGuiTheme.builder("exofoundry")
240245
.parent(STANDARD)
241246
.panel(GTTextureIds.BACKGROUND_FOUNDRY)

src/main/java/gregtech/api/modularui2/GTTextureIds.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ public final class GTTextureIds {
7474
public static final String BUTTON_STEAM_PRESSED = "gregtech:button_%s_pressed";
7575
public static final String BUTTON_FOUNDRY_PRESSED = "gregtech:button_foundry_pressed";
7676
public static final String BUTTON_NANOCHIP_PRESSED = "gregtech:button_nanochip_pressed";
77+
public static final String BUTTON_GORGE = "gregtech:button_gorge";
7778

7879
public static final String BUTTON_COVER_TAB_NORMAL_STANDARD = "gregtech:button_cover_tab_normal_standard";
7980
public static final String BUTTON_COVER_TAB_NORMAL_STEAM = "gregtech:button_cover_tab_normal_%s";

src/main/java/gregtech/api/modularui2/GTWidgetThemes.java

Lines changed: 60 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,21 @@
55
import static gregtech.common.gui.modularui.widget.SteamGaugeWidget.GAUGE_NEEDLE_WIDTH;
66
import static gregtech.common.gui.modularui.widget.SteamGaugeWidget.GAUGE_SIZE;
77

8+
import java.lang.reflect.Constructor;
9+
import java.lang.reflect.InvocationTargetException;
10+
811
import com.cleanroommc.modularui.api.IThemeApi;
9-
import com.cleanroommc.modularui.api.drawable.IDrawable;
1012
import com.cleanroommc.modularui.drawable.DrawableStack;
1113
import com.cleanroommc.modularui.drawable.GuiTextures;
1214
import com.cleanroommc.modularui.drawable.Rectangle;
15+
import com.cleanroommc.modularui.theme.SelectableTheme;
1316
import com.cleanroommc.modularui.theme.SlotTheme;
1417
import com.cleanroommc.modularui.theme.WidgetTheme;
1518
import com.cleanroommc.modularui.theme.WidgetThemeKey;
1619
import com.cleanroommc.modularui.theme.WidgetThemeParser;
1720
import com.cleanroommc.modularui.utils.Color;
18-
import com.cleanroommc.modularui.utils.JsonHelper;
1921
import com.cleanroommc.modularui.widget.Widget;
22+
import com.google.gson.JsonObject;
2023

2124
import 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

Comments
 (0)