Skip to content

Commit

Permalink
UI theme cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
serenibyss committed Dec 17, 2023
1 parent 510be94 commit 5e73960
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 23 deletions.
7 changes: 6 additions & 1 deletion src/main/java/gregtech/api/mui/GTGuiTextures.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import com.cleanroommc.modularui.drawable.UITexture;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;

/**
* GT MUI textures.<br>
Expand Down Expand Up @@ -454,7 +455,11 @@ private static UITexture progressBar(String path, int width, int height, boolean
}

// todo steam logos? multi indicator blinking logos?
public static UITexture getLogo() {
public static @NotNull UITexture getLogo(GTGuiTheme theme) {
if (theme != null) {
UITexture logo = theme.getLogo();
if (logo != null) return logo;
}
return GTValues.XMAS.get() ? GREGTECH_LOGO_XMAS : GREGTECH_LOGO;
}
}
110 changes: 91 additions & 19 deletions src/main/java/gregtech/api/mui/GTGuiTheme.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

import com.cleanroommc.modularui.api.ITheme;
import com.cleanroommc.modularui.api.IThemeApi;
import com.cleanroommc.modularui.drawable.UITexture;
import com.cleanroommc.modularui.screen.Tooltip;
import com.cleanroommc.modularui.theme.ReloadThemeEvent;
import com.cleanroommc.modularui.utils.JsonBuilder;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Supplier;

public class GTGuiTheme {

Expand All @@ -24,7 +28,7 @@ public class GTGuiTheme {
.fluidSlot(GTGuiTextures.IDs.STANDARD_FLUID_SLOT)
.color(ConfigHolder.client.defaultUIColor)
.button(GTGuiTextures.IDs.STANDARD_BUTTON)
.toggleButton(GTGuiTextures.IDs.STANDARD_BUTTON,
.simpleToggleButton(GTGuiTextures.IDs.STANDARD_BUTTON,
GTGuiTextures.IDs.STANDARD_SLOT,
ConfigHolder.client.defaultUIColor)
.build();
Expand All @@ -51,6 +55,8 @@ public class GTGuiTheme {
private final List<Consumer<JsonBuilder>> elementBuilder;
private final JsonBuilder jsonBuilder;

private Supplier<UITexture> logo;

private GTGuiTheme(String themeId) {
this.themeId = themeId;
this.jsonBuilder = new JsonBuilder();
Expand All @@ -62,6 +68,15 @@ public String getId() {
return themeId;
}

public ITheme getMuiTheme() {
return IThemeApi.get().getTheme(themeId);
}

public @Nullable UITexture getLogo() {
if (logo == null) return null;
return logo.get();
}

private void register() {
buildJson();
IThemeApi.get().registerTheme(themeId, jsonBuilder);
Expand Down Expand Up @@ -278,33 +293,90 @@ public Builder textField(int textColor, int markedColor) {
return this;
}

public Builder toggleButton(String toggleButtonId, String selectedBackgroundId) {
return toggleButton(toggleButtonId, selectedBackgroundId, 0xFFFFFFFF, true);
}

public Builder toggleButton(String toggleButtonId, String selectedBackgroundId, int selectedColor) {
return toggleButton(toggleButtonId, selectedBackgroundId, 0xFFFFFFFF, true, null, selectedColor);
}

public Builder toggleButton(String toggleButtonId, String selectedBackgroundId, int textColor,
boolean textShadow) {
return toggleButton(toggleButtonId, selectedBackgroundId, textColor, textShadow, null, 0xFFBBBBBB);
/**
* Set the theme options for a ToggleButton widget.
*
* @param backgroundId The main background for the unpressed button
* @param hoverBackgroundId The on-hover background for the unpressed button
* @param selectedBackgroundId The main background for the pressed button
* @param selectedHoverBackgroundId The on-hover background for the pressed button
* @param selectedColor The color to apply to the pressed button
*/
public Builder toggleButton(String backgroundId, String hoverBackgroundId,
String selectedBackgroundId, String selectedHoverBackgroundId, int selectedColor) {
return toggleButton(
backgroundId, hoverBackgroundId,
selectedBackgroundId, selectedHoverBackgroundId,
selectedColor, 0xFFBBBBBB, false);
}

public Builder toggleButton(String toggleButtonId, String selectedBackgroundId, int textColor,
boolean textShadow, String selectedHoverBackgroundId, int selectedColor) {
/**
* Set the theme options for a ToggleButton widget.
*
* @param backgroundId The main background for the unpressed button
* @param hoverBackgroundId The on-hover background for the unpressed button
* @param selectedBackgroundId The main background for the pressed button
* @param selectedHoverBackgroundId The on-hover background for the pressed button
* @param selectedColor The color to apply to the pressed button
* @param textColor The color for text overlaid on this button
* @param textShadow Whether to apply text shadow to text overlaid on this button
*/
public Builder toggleButton(String backgroundId, String hoverBackgroundId,
String selectedBackgroundId, String selectedHoverBackgroundId,
int selectedColor, int textColor, boolean textShadow) {
theme.elementBuilder.add(b -> b
.add("toggleButton", new JsonBuilder()
.add("background", new JsonBuilder()
.add("type", "texture")
.add("id", toggleButtonId))
.add("textColor", textColor)
.add("textShadow", textShadow)
.add("id", backgroundId))
.add("hoverBackground", new JsonBuilder()
.add("type", "texture")
.add("id", hoverBackgroundId))
.add("selectedBackground", new JsonBuilder()
.add("type", "texture")
.add("id", selectedBackgroundId))
.add("selectedHoverBackground", selectedHoverBackgroundId)
.add("selectedColor", selectedColor)));
.add("selectedHoverBackground", new JsonBuilder()
.add("type", "texture")
.add("id", selectedHoverBackgroundId))
.add("selectedColor", selectedColor)
.add("textColor", textColor)
.add("textShadow", textShadow)));
return this;
}

/**
* Simple toggle button configuration for when you want a button with no texture changes on hover.
*
* @param backgroundId The unselected background texture
* @param selectedBackgroundId The selected background texture
* @param selectedColor The background color when the button is selected
*/
public Builder simpleToggleButton(String backgroundId, String selectedBackgroundId, int selectedColor) {
return simpleToggleButton(backgroundId, selectedBackgroundId, selectedColor, 0xFFBBBBBB, false);
}

/**
* Simple toggle button configuration for when you want a button with no texture changes on hover.
*
* @param backgroundId The unselected background texture
* @param selectedBackgroundId The selected background texture
* @param selectedColor The background color when the button is selected
* @param textColor The color for text overlaid on this button
* @param textShadow Whether to apply text shadow to text overlaid on this button
*/
public Builder simpleToggleButton(String backgroundId, String selectedBackgroundId, int selectedColor,
int textColor, boolean textShadow) {
return toggleButton(
backgroundId, backgroundId,
selectedBackgroundId, selectedBackgroundId,
selectedColor, textColor, textShadow);
}

/**
* Set a logo supplier for this theme.
*/
public Builder logo(Supplier<UITexture> logo) {
theme.logo = logo;
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,13 +305,12 @@ public ModularPanel buildUI(PosGuiData guiData, GuiSyncManager guiSyncManager) {
.child(new Column()
.pos(backgroundWidth - 7 - 18, backgroundHeight - 18 * 4 - 7 - 5)
.width(18).height(18 * 4 + 5)
.child(GTGuiTextures.getLogo().asWidget().size(17).top(18 * 3 + 5))
.child(GTGuiTextures.getLogo(getUITheme()).asWidget().size(17).top(18 * 3 + 5))
.child(new ToggleButton()
.top(18 * 2)
.value(new BoolValue.Dynamic(workingStateValue::getBoolValue,
workingStateValue::setBoolValue))
.overlay(GTGuiTextures.BUTTON_ITEM_OUTPUT)
.disableHoverBackground()
.tooltipBuilder(t -> t.setAutoUpdate(true)
.addLine(workingStateValue.getBoolValue() ?
IKey.lang("gregtech.gui.item_auto_output.tooltip.enabled") :
Expand All @@ -321,7 +320,6 @@ public ModularPanel buildUI(PosGuiData guiData, GuiSyncManager guiSyncManager) {
.value(new BoolValue.Dynamic(collapseStateValue::getBoolValue,
collapseStateValue::setBoolValue))
.overlay(GTGuiTextures.BUTTON_AUTO_COLLAPSE)
.disableHoverBackground()
.tooltipBuilder(t -> t.setAutoUpdate(true)
.addLine(collapseStateValue.getBoolValue() ?
IKey.lang("gregtech.gui.item_auto_collapse.tooltip.enabled") :
Expand Down

0 comments on commit 5e73960

Please sign in to comment.