Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/main/java/com/cleanroommc/modularui/ModularUIConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import com.gtnewhorizon.gtnhlib.config.Config;


@Config(modid = ModularUI.ID)
public class ModularUIConfig {

Expand All @@ -28,6 +27,12 @@ public class ModularUIConfig {
@Config.Comment("If true and not specified otherwise, screens will try to use the 'vanilla_dark' theme.")
public static boolean useDarkThemeByDefault = false;

@Config.Comment("Debug text color. Prefix Hex values with a #. Common colors can be referred by their name.")
public static String debugTextColor = "#FFAAAAAA";

@Config.Comment("Debug outline color. Prefix Hex values with a #. Common colors can be referred by their name.")
public static String debugOutlineColor = "#DCB42873";

@Config.RequiresMcRestart
@Config.Comment("Enables a test block, test item with a test gui and opening a gui by right clicking a diamond.")
public static boolean enableTestGuis = ModularUI.isDevEnv;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.StatCollector;
import net.minecraftforge.client.event.GuiOpenEvent;
import net.minecraftforge.client.event.GuiScreenEvent;
import cpw.mods.fml.common.eventhandler.EventPriority;
Expand Down Expand Up @@ -78,6 +79,8 @@
public class ClientScreenHandler {

private static final GuiContext defaultContext = new GuiContext();
private static final int DEFAULT_DEBUG_TEXT_COLOR = 0xFFAAAAAA;
private static final int DEFAULT_DEBUG_OUTLINE_COLOR = 0xDCB42873;

private static ModularScreen currentScreen = null;
private static Character lastChar = null;
Expand Down Expand Up @@ -584,8 +587,8 @@ public static void drawDebugScreen(@Nullable ModularScreen muiScreen, @Nullable
ModularGuiContext context = muiScreen.getContext();
int mouseX = context.getAbsMouseX(), mouseY = context.getAbsMouseY();
int screenH = muiScreen.getScreenArea().height;
int outlineColor = DebugOptions.INSTANCE.outlineColor.getIntValue();//Color.argb(180, 40, 115, 220);
int textColor = DebugOptions.INSTANCE.textColor.getIntValue();//Color.argb(180, 40, 115, 220);
int outlineColor = Color.parseString(ModularUIConfig.debugOutlineColor, DEFAULT_DEBUG_OUTLINE_COLOR, true);
int textColor = Color.parseString(ModularUIConfig.debugTextColor, DEFAULT_DEBUG_TEXT_COLOR, true);
float scale = DebugOptions.INSTANCE.scale.getFloatValue();
int shift = (int) (11 * scale + 0.5f);
int lineY = screenH - shift - 2;
Expand All @@ -594,9 +597,11 @@ public static void drawDebugScreen(@Nullable ModularScreen muiScreen, @Nullable
muiScreen.getContext().getRecipeViewerSettings().isEnabled(muiScreen)) {
lineY -= 20;
}
GuiDraw.drawText("Mouse Pos: " + mouseX + ", " + mouseY, 5, lineY, scale, outlineColor, true);
GuiDraw.drawText(StatCollector.translateToLocalFormatted("modularui2.debug.mouse_pos", mouseX, mouseY),
5, lineY, scale, textColor, true);
lineY -= shift;
GuiDraw.drawText("FPS: " + fpsCounter.getFps(), 5, lineY, scale, outlineColor, true);
GuiDraw.drawText(StatCollector.translateToLocalFormatted("modularui2.debug.fps", fpsCounter.getFps()),
5, lineY, scale, textColor, true);
lineY -= shift;

LocatedWidget locatedHovered = muiScreen.getPanelManager().getTopWidgetLocated(true);
Expand All @@ -608,10 +613,11 @@ public static void drawDebugScreen(@Nullable ModularScreen muiScreen, @Nullable
} else {
theme = context.getTheme();
}
GuiDraw.drawText("Theme ID: " + theme.getId(), 5, lineY, scale, outlineColor, true);
GuiDraw.drawText(StatCollector.translateToLocalFormatted("modularui2.debug.theme_id", theme.getId()),
5, lineY, scale, textColor, true);

if (locatedHovered != null && (showHovered || showParent)) {
drawSegmentLine(lineY -= 4, scale, outlineColor);
drawSegmentLine(lineY -= 4, scale, textColor);
lineY -= 10;

IWidget hovered = locatedHovered.getElement();
Expand All @@ -626,66 +632,108 @@ public static void drawDebugScreen(@Nullable ModularScreen muiScreen, @Nullable
GuiDraw.drawBorderOutsideXYWH(0, 0, area.width, area.height, scale, outlineColor);
}
if (hovered.hasParent() && showParent && DebugOptions.INSTANCE.showParentOutline.getBoolValue()) {
GuiDraw.drawBorderOutsideXYWH(-area.rx, -area.ry, parent.getArea().width, parent.getArea().height, scale, Color.withAlpha(outlineColor, 0.3f));
GuiDraw.drawBorderOutsideXYWH(
-area.rx,
-area.ry,
parent.getArea().width,
parent.getArea().height,
scale,
Color.withAlpha(outlineColor, 0.3f));
}
GlStateManager.popMatrix();
locatedHovered.unapplyMatrix(context);
if (showHovered) {
if (DebugOptions.INSTANCE.showWidgetTheme.getBoolValue()) {
GuiDraw.drawText("Widget Theme: " + hovered.getWidgetTheme(muiScreen.getCurrentTheme()).getKey().getFullName(), 5, lineY, scale, textColor, true);
GuiDraw.drawText(
StatCollector.translateToLocalFormatted(
"modularui2.debug.widget_theme",
hovered.getWidgetTheme(muiScreen.getCurrentTheme()).getKey().getFullName()),
5, lineY, scale, textColor, true);
lineY -= shift;
}
if (DebugOptions.INSTANCE.showSize.getBoolValue()) {
GuiDraw.drawText("Size: " + area.width + ", " + area.height, 5, lineY, scale, textColor, true);
GuiDraw.drawText(StatCollector.translateToLocalFormatted("modularui2.debug.size", area.width, area.height),
5, lineY, scale, textColor, true);
lineY -= shift;
}
if (DebugOptions.INSTANCE.showPos.getBoolValue()) {
GuiDraw.drawText("Pos: " + area.x + ", " + area.y + " Rel: " + area.rx + ", " + area.ry, 5, lineY, scale, textColor, true);
GuiDraw.drawText(
StatCollector.translateToLocalFormatted(
"modularui2.debug.pos_rel",
area.x,
area.y,
area.rx,
area.ry),
5, lineY, scale, textColor, true);
lineY -= shift;
}
GuiDraw.drawText("Widget: " + hovered, 5, lineY, scale, textColor, true);
GuiDraw.drawText(StatCollector.translateToLocalFormatted("modularui2.debug.widget", hovered),
5, lineY, scale, textColor, true);
}
if (hovered.hasParent() && showParent) {
if (showHovered) {
drawSegmentLine(lineY -= 4, scale, textColor);
lineY -= 10;
}
if (DebugOptions.INSTANCE.showParentWidgetTheme.getBoolValue()) {
GuiDraw.drawText("Widget Theme: " + parent.getWidgetTheme(muiScreen.getCurrentTheme()).getKey().getFullName(), 5, lineY, scale, textColor, true);
GuiDraw.drawText(
StatCollector.translateToLocalFormatted(
"modularui2.debug.widget_theme",
parent.getWidgetTheme(muiScreen.getCurrentTheme()).getKey().getFullName()),
5, lineY, scale, textColor, true);
lineY -= shift;
}
area = parent.getArea();
if (DebugOptions.INSTANCE.showParentSize.getBoolValue()) {
GuiDraw.drawText("Parent size: " + area.width + ", " + area.height, 5, lineY, scale, textColor, true);
GuiDraw.drawText(
StatCollector.translateToLocalFormatted("modularui2.debug.parent_size", area.width, area.height),
5, lineY, scale, textColor, true);
lineY -= shift;
}
if (DebugOptions.INSTANCE.showParentPos.getBoolValue()) {
GuiDraw.drawText("Parent pos: " + area.x + ", " + area.y + " Rel: " + area.rx + ", " + area.ry, 5, lineY, scale, textColor, true);
GuiDraw.drawText(
StatCollector.translateToLocalFormatted(
"modularui2.debug.parent_pos_rel",
area.x,
area.y,
area.rx,
area.ry),
5, lineY, scale, textColor, true);
lineY -= shift;
}
GuiDraw.drawText("Parent: " + parent, 5, lineY, scale, outlineColor, true);
GuiDraw.drawText(StatCollector.translateToLocalFormatted("modularui2.debug.parent", parent),
5, lineY, scale, textColor, true);
}
if (showHovered && DebugOptions.INSTANCE.showExtra.getBoolValue()) {
if (hovered instanceof ItemSlot slotWidget) {
drawSegmentLine(lineY -= 4, scale, textColor);
lineY -= 10;
ModularSlot slot = slotWidget.getSlot();
GuiDraw.drawText("Slot Index: " + slot.getSlotIndex(), 5, lineY, scale, textColor, true);
GuiDraw.drawText(StatCollector.translateToLocalFormatted("modularui2.debug.slot_index", slot.getSlotIndex()),
5, lineY, scale, textColor, true);
lineY -= shift;
GuiDraw.drawText("Slot Number: " + slot.slotNumber, 5, lineY, scale, textColor, true);
GuiDraw.drawText(StatCollector.translateToLocalFormatted("modularui2.debug.slot_number", slot.slotNumber),
5, lineY, scale, textColor, true);
lineY -= shift;
if (slotWidget.isSynced()) {
SlotGroup slotGroup = slot.getSlotGroup();
boolean allowShiftTransfer = slotGroup != null && slotGroup.allowShiftTransfer();
GuiDraw.drawText("Shift-Click Priority: " + (allowShiftTransfer ? slotGroup.getShiftClickPriority() : "DISABLED"), 5, lineY, scale, textColor, true);
GuiDraw.drawText(
StatCollector.translateToLocalFormatted(
"modularui2.debug.shift_click_priority",
allowShiftTransfer
? slotGroup.getShiftClickPriority()
: StatCollector.translateToLocal("modularui2.debug.disabled")),
5, lineY, scale, textColor, true);
}
} else if (hovered instanceof RichTextWidget richTextWidget) {
drawSegmentLine(lineY -= 4, scale, outlineColor);
drawSegmentLine(lineY -= 4, scale, textColor);
lineY -= 10;
locatedHovered.applyMatrix(context);
Object hoveredElement = richTextWidget.getHoveredElement();
locatedHovered.unapplyMatrix(context);
GuiDraw.drawText("Hovered: " + hoveredElement, 5, lineY, scale, textColor, true);
GuiDraw.drawText(StatCollector.translateToLocalFormatted("modularui2.debug.hovered", hoveredElement),
5, lineY, scale, textColor, true);
}
}
}
Expand Down
97 changes: 64 additions & 33 deletions src/main/java/com/cleanroommc/modularui/utils/Color.java
Original file line number Diff line number Diff line change
Expand Up @@ -884,48 +884,79 @@ public static String componentToFullHexString(int component) {
return s;
}

/**
* Parses a ARGB color of a json element.
*
* @param jsonElement json element
* @return ARGB color
* @throws JsonParseException if color could not be parsed
*/
public static int ofJson(JsonElement jsonElement) {
if (jsonElement.isJsonPrimitive()) {
String colorString = jsonElement.getAsString();
if (colorString.isEmpty()) return WHITE.main;
char c = colorString.charAt(0);
// a normal int string
if (Character.isDigit(c) || c == '-' || c == '#') {
public static int parseString(String colorString) {
return parseString(colorString, WHITE.main, false);
}

/**
* Parses a color ARGB int from a string.
* The string can be a number in decimal (no prefix), hexadecimal (0x, 0X or # prefix) or octal (0 prefix).
* Otherwise, it can be a name from a {@link ColorShade} instance. The default instances can be found at the bottom
* of this class. These names can be suffixed with colon and a negative number for darker colors or positive number for brighter colors.
* The number is an index to an array with predefined shades. 0 is the main color. If no color for a name is found, the fallback value
* is returned. The shade index is clamped to valid values.
* <p>
* Example: "deep_purple:-3" returns 0xFF4527A0
* </p>
* As a special case "invisible" returns 0x00FFFFFF.
*
* @param colorString a string which can be a number or a color name
* @param fallback the returned color value when the string is invalid
* @return the parsed color ARGB.
*/
public static int parseString(String colorString, int fallback, boolean silent) {
if (colorString.isEmpty()) return fallback;
char c = colorString.charAt(0);
// a normal int string
if (Character.isDigit(c) || c == '-' || c == '#') {
try {
int color = (int) (long) Long.decode(colorString); // bruh
if (color != 0 && getAlpha(color) == 0) {
return withAlpha(color, 255);
}
return color;
} catch (NumberFormatException e) {
if (!silent) ModularUI.LOGGER.error("Error parsing color ARGB int from string '{}'", colorString);
return fallback;
}
}

if ("invisible".equals(jsonElement.getAsString())) {
return withAlpha(WHITE.main, 0);
}
int i = colorString.indexOf(':');
int index = 0;
if (i > 0) {
try {
index = Integer.parseInt(colorString.substring(i + 1));
} catch (NumberFormatException e) {
ModularUI.LOGGER.error("[THEME] If the color is a word, then after the : must come a negative or positive integer, but got '{}'", colorString.substring(i + 1));
if ("invisible".equals(colorString)) {
return withAlpha(WHITE.main, 0);
}
int i = colorString.indexOf(':');
int index = 0;
if (i > 0) {
try {
index = Integer.parseInt(colorString.substring(i + 1));
} catch (NumberFormatException e) {
if (!silent) {
ModularUI.LOGGER.error("Error parsing color from string '{}': If the color is a word, then after the : " +
"must come a negative or positive integer, but got '{}'", colorString, colorString.substring(i + 1));
}
colorString = colorString.substring(0, i);
}
ColorShade colorShade = ColorShade.getFromName(colorString);
if (colorShade != null) {
if (index == 0) return colorShade.main;
if (index > 0) return colorShade.brighterSafe(index - 1);
else return colorShade.darkerSafe(-index - 1);
}
ModularUI.LOGGER.error("[THEME] No color shade for name '{}' was found", colorString);
return WHITE.main;
colorString = colorString.substring(0, i);
}
ColorShade colorShade = ColorShade.getFromName(colorString);
if (colorShade != null) {
if (index == 0) return colorShade.main;
if (index > 0) return colorShade.brighterSafe(index - 1);
else return colorShade.darkerSafe(-index - 1);
}
if (!silent) ModularUI.LOGGER.error("Error parsing color: No color shade for name '{}' was found", colorString);
return fallback;
}

/**
* Parses a ARGB color of a json element.
*
* @param jsonElement json element
* @return ARGB color
* @throws JsonParseException if color could not be parsed
*/
public static int ofJson(JsonElement jsonElement) {
if (jsonElement.isJsonPrimitive()) {
return parseString(jsonElement.getAsString());
}
if (jsonElement.isJsonObject()) {
JsonObject json = jsonElement.getAsJsonObject();
Expand Down
17 changes: 17 additions & 0 deletions src/main/resources/assets/modularui2/lang/en_US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,20 @@ modularui2.item.phantom.control=§7Scroll wheel up increases amount, down decrea
modularui2.fluid.click_to_fill=§bLeft §7Click with a Fluid Container to §bfill §7the tank (Shift-click for a full stack).
modularui2.fluid.click_combined=§cRight §7or §bLeft §7Click with a Fluid Container to §cempty §7or §bfill §7the tank (Shift-click for a full stack).
modularui2.fluid.click_to_empty=§cRight §7Click with a Fluid Container to §cempty §7the tank (Shift-click for a full stack).

# Debug Screen
modularui2.debug.mouse_pos=§7Mouse Pos: §3%d§7, §3%d
modularui2.debug.fps=§7FPS: §3%d
modularui2.debug.theme_id=§7Theme ID: §6%s
modularui2.debug.widget_theme=§7Widget Theme: §6%s
modularui2.debug.size=§7Size: §3%d§7, §3%d
modularui2.debug.pos_rel=§7Post: §3%d§7, §3%d§7 Rel: §3%d§7, §3%d
modularui2.debug.widget=§7Widget: §6%s
modularui2.debug.parent_size=§7Parent size: §3%d§7, §3%d
modularui2.debug.parent_pos_rel=§7Parent pos: §3%d§7, §3%d§7 Rel: §3%d§7, §3%d
modularui2.debug.parent=§7Parent: §6%s
modularui2.debug.slot_index=§7Slot Index: §3%d
modularui2.debug.slot_number=§7Slot Number: §3%d
modularui2.debug.shift_click_priority=§7Shift-Click Priority: §3%d
modularui2.debug.disabled=§cDISABLED
modularui2.debug.hovered=§7Hovered: §6%s
Loading