From 5f70f3c5eb8261811250e788b2934adfcdc56bd8 Mon Sep 17 00:00:00 2001 From: Ranzu <66495944+Ranzuu@users.noreply.github.com> Date: Mon, 20 Apr 2026 20:47:55 +0200 Subject: [PATCH 01/10] Localize Debug Overlay --- .../modularui/screen/ClientScreenHandler.java | 78 +++++++++++++++---- .../assets/modularui2/lang/en_US.lang | 17 ++++ 2 files changed, 79 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/cleanroommc/modularui/screen/ClientScreenHandler.java b/src/main/java/com/cleanroommc/modularui/screen/ClientScreenHandler.java index dc786b3f0..61c159d3a 100644 --- a/src/main/java/com/cleanroommc/modularui/screen/ClientScreenHandler.java +++ b/src/main/java/com/cleanroommc/modularui/screen/ClientScreenHandler.java @@ -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; @@ -594,9 +595,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, outlineColor, 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, outlineColor, true); lineY -= shift; LocatedWidget locatedHovered = muiScreen.getPanelManager().getTopWidgetLocated(true); @@ -608,7 +611,8 @@ 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, outlineColor, true); if (locatedHovered != null && (showHovered || showParent)) { drawSegmentLine(lineY -= 4, scale, outlineColor); @@ -626,24 +630,43 @@ 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) { @@ -651,33 +674,55 @@ public static void drawDebugScreen(@Nullable ModularScreen muiScreen, @Nullable 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, outlineColor, 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); @@ -685,7 +730,8 @@ public static void drawDebugScreen(@Nullable ModularScreen muiScreen, @Nullable 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); } } } diff --git a/src/main/resources/assets/modularui2/lang/en_US.lang b/src/main/resources/assets/modularui2/lang/en_US.lang index e0efb54dd..310428367 100644 --- a/src/main/resources/assets/modularui2/lang/en_US.lang +++ b/src/main/resources/assets/modularui2/lang/en_US.lang @@ -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=Mouse Pos: %d, %d +modularui2.debug.fps=FPS: %d +modularui2.debug.theme_id=Theme ID: %s +modularui2.debug.widget_theme=Widget Theme: %s +modularui2.debug.size=Size: %s, %s +modularui2.debug.pos_rel=Post: %d, %d Rel: %d, %d +modularui2.debug.widget=Widget: %s +modularui2.debug.parent_size=Parent size: %s, %s +modularui2.debug.parent_pos_rel=Parent pos: %d, %d Rel: %d, %d +modularui2.debug.parent=Parent: %s +modularui2.debug.slot_index=Slot Index: %d +modularui2.debug.slot_number=Slot Number: %d +modularui2.debug.shift_click_priority=Shift-Click Priority: %s +modularui2.debug.disabled=DISABLED +modularui2.debug.hovered=Hovered: %s \ No newline at end of file From 15049c01ef5dcb8c27e0a5bd49073b8c6938a835 Mon Sep 17 00:00:00 2001 From: Ranzu <66495944+Ranzuu@users.noreply.github.com> Date: Mon, 20 Apr 2026 22:43:25 +0200 Subject: [PATCH 02/10] DebugColorconfig --- .../modularui/ModularUIConfig.java | 16 +- .../modularui/overlay/DebugOptions.java | 3 +- .../modularui/overlay/DebugOverlay.java | 27 +- .../modularui/screen/ClientScreenHandler.java | 352 +++++++++++++++--- 4 files changed, 335 insertions(+), 63 deletions(-) diff --git a/src/main/java/com/cleanroommc/modularui/ModularUIConfig.java b/src/main/java/com/cleanroommc/modularui/ModularUIConfig.java index ab517381b..dbe583727 100644 --- a/src/main/java/com/cleanroommc/modularui/ModularUIConfig.java +++ b/src/main/java/com/cleanroommc/modularui/ModularUIConfig.java @@ -4,7 +4,6 @@ import com.gtnewhorizon.gtnhlib.config.Config; - @Config(modid = ModularUI.ID) public class ModularUIConfig { @@ -28,6 +27,21 @@ 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 for literal text segments.") + public static String debugTextColorHex = "#B4AAAAAA"; + + @Config.Comment("Debug text color for numeric placeholders like %d.") + public static String debugNumericValueColorHex = "#B400AAAA"; + + @Config.Comment("Debug text color for string placeholders like %s.") + public static String debugStringValueColorHex = "#DCFFAA00"; + + @Config.Comment("Debug text color for non-numeric and non-string placeholders.") + public static String debugOtherValueColorHex = "#DCAAAAAA"; + + @Config.Comment("Debug outline color.") + public static String debugOutlineColorHex = "#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; diff --git a/src/main/java/com/cleanroommc/modularui/overlay/DebugOptions.java b/src/main/java/com/cleanroommc/modularui/overlay/DebugOptions.java index 926511077..c7767db06 100644 --- a/src/main/java/com/cleanroommc/modularui/overlay/DebugOptions.java +++ b/src/main/java/com/cleanroommc/modularui/overlay/DebugOptions.java @@ -8,6 +8,7 @@ public class DebugOptions { public static final DebugOptions INSTANCE = new DebugOptions(); + public static final int DEFAULT_DEBUG_COLOR = Color.argb(180, 40, 115, 220); public BoolValue showHovered = new BoolValue(true); public BoolValue showPos = new BoolValue(true); @@ -22,7 +23,7 @@ public class DebugOptions { public BoolValue showParentWidgetTheme = new BoolValue(false); public BoolValue showParentOutline = new BoolValue(true); - public IntValue textColor = new IntValue(Color.argb(180, 40, 115, 220)); + public IntValue textColor = new IntValue(DEFAULT_DEBUG_COLOR); public IntValue outlineColor = new IntValue(textColor.getIntValue()); public IntValue cursorColor = new IntValue(Color.withAlpha(Color.GREEN.main, 0.8f)); public FloatValue scale = new FloatValue(0.8f); diff --git a/src/main/java/com/cleanroommc/modularui/overlay/DebugOverlay.java b/src/main/java/com/cleanroommc/modularui/overlay/DebugOverlay.java index 8425fb1e0..0b91d9cab 100644 --- a/src/main/java/com/cleanroommc/modularui/overlay/DebugOverlay.java +++ b/src/main/java/com/cleanroommc/modularui/overlay/DebugOverlay.java @@ -1,6 +1,7 @@ package com.cleanroommc.modularui.overlay; import com.cleanroommc.modularui.ModularUI; +import com.cleanroommc.modularui.ModularUIConfig; import com.cleanroommc.modularui.api.IMuiScreen; import com.cleanroommc.modularui.api.drawable.IIcon; import com.cleanroommc.modularui.api.drawable.IKey; @@ -43,7 +44,9 @@ public DebugOverlay(IMuiScreen screen) { .bottom(0) .height(12) .width(160) - .background(new Rectangle().color(Color.withAlpha(DebugOptions.INSTANCE.outlineColor.getIntValue(), 0.4f)).cornerRadius(4)) + .background(new Rectangle() + .color(Color.withAlpha(getDebugOutlineColor(), 0.4f)) + .cornerRadius(4)) .disableHoverBackground() .overlay(IKey.str("Debug Options")) .openUp() @@ -125,4 +128,26 @@ private boolean logWidgetTrees(int b) { } return true; } + + private static int getDebugOutlineColor() { + return parseDebugHexColor(ModularUIConfig.debugOutlineColorHex, DebugOptions.DEFAULT_DEBUG_COLOR); + } + + private static int parseDebugHexColor(String input, int fallbackColor) { + if (input == null) return fallbackColor; + String hex = input.trim(); + if (hex.startsWith("#")) hex = hex.substring(1); + if (hex.length() == 10) { + hex = hex.substring(2); + } + if (hex.length() == 6) { + hex = "FF" + hex; + } + if (hex.length() != 8) return fallbackColor; + try { + return (int) Long.parseLong(hex, 16); + } catch (NumberFormatException ignored) { + return fallbackColor; + } + } } diff --git a/src/main/java/com/cleanroommc/modularui/screen/ClientScreenHandler.java b/src/main/java/com/cleanroommc/modularui/screen/ClientScreenHandler.java index 61c159d3a..c869dc470 100644 --- a/src/main/java/com/cleanroommc/modularui/screen/ClientScreenHandler.java +++ b/src/main/java/com/cleanroommc/modularui/screen/ClientScreenHandler.java @@ -72,6 +72,7 @@ import java.io.IOException; import java.util.Collections; import java.util.List; +import java.util.Locale; import java.util.function.Predicate; @ApiStatus.Internal @@ -585,8 +586,12 @@ 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 defaultDebugTextColor = DebugOptions.DEFAULT_DEBUG_COLOR; + int outlineColor = parseDebugHexColor(ModularUIConfig.debugOutlineColorHex, defaultDebugTextColor); + int localizedTextColor = parseDebugHexColor(ModularUIConfig.debugTextColorHex, defaultDebugTextColor); + int localizedNumberColor = parseDebugHexColor(ModularUIConfig.debugNumericValueColorHex, defaultDebugTextColor); + int localizedStringColor = parseDebugHexColor(ModularUIConfig.debugStringValueColorHex, defaultDebugTextColor); + int localizedOtherValueColor = parseDebugHexColor(ModularUIConfig.debugOtherValueColorHex, defaultDebugTextColor); float scale = DebugOptions.INSTANCE.scale.getFloatValue(); int shift = (int) (11 * scale + 0.5f); int lineY = screenH - shift - 2; @@ -595,11 +600,30 @@ public static void drawDebugScreen(@Nullable ModularScreen muiScreen, @Nullable muiScreen.getContext().getRecipeViewerSettings().isEnabled(muiScreen)) { lineY -= 20; } - GuiDraw.drawText(StatCollector.translateToLocalFormatted("modularui2.debug.mouse_pos", mouseX, mouseY), - 5, lineY, scale, outlineColor, true); + drawLocalizedDebugText( + "modularui2.debug.mouse_pos", + 5, + lineY, + scale, + true, + localizedTextColor, + localizedNumberColor, + localizedStringColor, + localizedOtherValueColor, + mouseX, + mouseY); lineY -= shift; - GuiDraw.drawText(StatCollector.translateToLocalFormatted("modularui2.debug.fps", fpsCounter.getFps()), - 5, lineY, scale, outlineColor, true); + drawLocalizedDebugText( + "modularui2.debug.fps", + 5, + lineY, + scale, + true, + localizedTextColor, + localizedNumberColor, + localizedStringColor, + localizedOtherValueColor, + fpsCounter.getFps()); lineY -= shift; LocatedWidget locatedHovered = muiScreen.getPanelManager().getTopWidgetLocated(true); @@ -611,11 +635,20 @@ public static void drawDebugScreen(@Nullable ModularScreen muiScreen, @Nullable } else { theme = context.getTheme(); } - GuiDraw.drawText(StatCollector.translateToLocalFormatted("modularui2.debug.theme_id", theme.getId()), - 5, lineY, scale, outlineColor, true); + drawLocalizedDebugText( + "modularui2.debug.theme_id", + 5, + lineY, + scale, + true, + localizedTextColor, + localizedNumberColor, + localizedStringColor, + localizedOtherValueColor, + theme.getId()); if (locatedHovered != null && (showHovered || showParent)) { - drawSegmentLine(lineY -= 4, scale, outlineColor); + drawSegmentLine(lineY -= 4, scale, localizedTextColor); lineY -= 10; IWidget hovered = locatedHovered.getElement(); @@ -642,96 +675,190 @@ public static void drawDebugScreen(@Nullable ModularScreen muiScreen, @Nullable locatedHovered.unapplyMatrix(context); if (showHovered) { if (DebugOptions.INSTANCE.showWidgetTheme.getBoolValue()) { - GuiDraw.drawText( - StatCollector.translateToLocalFormatted( - "modularui2.debug.widget_theme", - hovered.getWidgetTheme(muiScreen.getCurrentTheme()).getKey().getFullName()), - 5, lineY, scale, textColor, true); + drawLocalizedDebugText( + "modularui2.debug.widget_theme", + 5, + lineY, + scale, + true, + localizedTextColor, + localizedNumberColor, + localizedStringColor, + localizedOtherValueColor, + hovered.getWidgetTheme(muiScreen.getCurrentTheme()).getKey().getFullName()); lineY -= shift; } if (DebugOptions.INSTANCE.showSize.getBoolValue()) { - GuiDraw.drawText(StatCollector.translateToLocalFormatted("modularui2.debug.size", area.width, area.height), - 5, lineY, scale, textColor, true); + drawLocalizedDebugText( + "modularui2.debug.size", + 5, + lineY, + scale, + true, + localizedTextColor, + localizedNumberColor, + localizedStringColor, + localizedOtherValueColor, + area.width, + area.height); lineY -= shift; } if (DebugOptions.INSTANCE.showPos.getBoolValue()) { - GuiDraw.drawText( - StatCollector.translateToLocalFormatted( - "modularui2.debug.pos_rel", - area.x, - area.y, - area.rx, - area.ry), - 5, lineY, scale, textColor, true); + drawLocalizedDebugText( + "modularui2.debug.pos_rel", + 5, + lineY, + scale, + true, + localizedTextColor, + localizedNumberColor, + localizedStringColor, + localizedOtherValueColor, + area.x, + area.y, + area.rx, + area.ry); lineY -= shift; } - GuiDraw.drawText(StatCollector.translateToLocalFormatted("modularui2.debug.widget", hovered), - 5, lineY, scale, textColor, true); + drawLocalizedDebugText( + "modularui2.debug.widget", + 5, + lineY, + scale, + true, + localizedTextColor, + localizedNumberColor, + localizedStringColor, + localizedOtherValueColor, + hovered); } if (hovered.hasParent() && showParent) { if (showHovered) { - drawSegmentLine(lineY -= 4, scale, textColor); + drawSegmentLine(lineY -= 4, scale, localizedTextColor); lineY -= 10; } if (DebugOptions.INSTANCE.showParentWidgetTheme.getBoolValue()) { - GuiDraw.drawText( - StatCollector.translateToLocalFormatted( - "modularui2.debug.widget_theme", - parent.getWidgetTheme(muiScreen.getCurrentTheme()).getKey().getFullName()), - 5, lineY, scale, textColor, true); + drawLocalizedDebugText( + "modularui2.debug.widget_theme", + 5, + lineY, + scale, + true, + localizedTextColor, + localizedNumberColor, + localizedStringColor, + localizedOtherValueColor, + parent.getWidgetTheme(muiScreen.getCurrentTheme()).getKey().getFullName()); lineY -= shift; } area = parent.getArea(); if (DebugOptions.INSTANCE.showParentSize.getBoolValue()) { - GuiDraw.drawText( - StatCollector.translateToLocalFormatted("modularui2.debug.parent_size", area.width, area.height), - 5, lineY, scale, textColor, true); + drawLocalizedDebugText( + "modularui2.debug.parent_size", + 5, + lineY, + scale, + true, + localizedTextColor, + localizedNumberColor, + localizedStringColor, + localizedOtherValueColor, + area.width, + area.height); lineY -= shift; } if (DebugOptions.INSTANCE.showParentPos.getBoolValue()) { - GuiDraw.drawText( - StatCollector.translateToLocalFormatted( - "modularui2.debug.parent_pos_rel", - area.x, - area.y, - area.rx, - area.ry), - 5, lineY, scale, textColor, true); + drawLocalizedDebugText( + "modularui2.debug.parent_pos_rel", + 5, + lineY, + scale, + true, + localizedTextColor, + localizedNumberColor, + localizedStringColor, + localizedOtherValueColor, + area.x, + area.y, + area.rx, + area.ry); lineY -= shift; } - GuiDraw.drawText(StatCollector.translateToLocalFormatted("modularui2.debug.parent", parent), - 5, lineY, scale, outlineColor, true); + drawLocalizedDebugText( + "modularui2.debug.parent", + 5, + lineY, + scale, + true, + localizedTextColor, + localizedNumberColor, + localizedStringColor, + localizedOtherValueColor, + parent); } if (showHovered && DebugOptions.INSTANCE.showExtra.getBoolValue()) { if (hovered instanceof ItemSlot slotWidget) { - drawSegmentLine(lineY -= 4, scale, textColor); + drawSegmentLine(lineY -= 4, scale, localizedTextColor); lineY -= 10; ModularSlot slot = slotWidget.getSlot(); - GuiDraw.drawText(StatCollector.translateToLocalFormatted("modularui2.debug.slot_index", slot.getSlotIndex()), - 5, lineY, scale, textColor, true); + drawLocalizedDebugText( + "modularui2.debug.slot_index", + 5, + lineY, + scale, + true, + localizedTextColor, + localizedNumberColor, + localizedStringColor, + localizedOtherValueColor, + slot.getSlotIndex()); lineY -= shift; - GuiDraw.drawText(StatCollector.translateToLocalFormatted("modularui2.debug.slot_number", slot.slotNumber), - 5, lineY, scale, textColor, true); + drawLocalizedDebugText( + "modularui2.debug.slot_number", + 5, + lineY, + scale, + true, + localizedTextColor, + localizedNumberColor, + localizedStringColor, + localizedOtherValueColor, + slot.slotNumber); lineY -= shift; if (slotWidget.isSynced()) { SlotGroup slotGroup = slot.getSlotGroup(); boolean allowShiftTransfer = slotGroup != null && slotGroup.allowShiftTransfer(); - GuiDraw.drawText( - StatCollector.translateToLocalFormatted( - "modularui2.debug.shift_click_priority", - allowShiftTransfer - ? slotGroup.getShiftClickPriority() - : StatCollector.translateToLocal("modularui2.debug.disabled")), - 5, lineY, scale, textColor, true); + drawLocalizedDebugText( + "modularui2.debug.shift_click_priority", + 5, + lineY, + scale, + true, + localizedTextColor, + localizedNumberColor, + localizedStringColor, + localizedOtherValueColor, + allowShiftTransfer + ? slotGroup.getShiftClickPriority() + : StatCollector.translateToLocal("modularui2.debug.disabled")); } } else if (hovered instanceof RichTextWidget richTextWidget) { - drawSegmentLine(lineY -= 4, scale, outlineColor); + drawSegmentLine(lineY -= 4, scale, localizedTextColor); lineY -= 10; locatedHovered.applyMatrix(context); Object hoveredElement = richTextWidget.getHoveredElement(); locatedHovered.unapplyMatrix(context); - GuiDraw.drawText(StatCollector.translateToLocalFormatted("modularui2.debug.hovered", hoveredElement), - 5, lineY, scale, textColor, true); + drawLocalizedDebugText( + "modularui2.debug.hovered", + 5, + lineY, + scale, + true, + localizedTextColor, + localizedNumberColor, + localizedStringColor, + localizedOtherValueColor, + hoveredElement); } } } @@ -744,6 +871,111 @@ private static void drawSegmentLine(int y, float scale, int color) { GuiDraw.drawRect(5, y, 140 * scale, 1 * scale, color); } + private static void drawLocalizedDebugText(String key, + float x, + float y, + float scale, + boolean shadow, + int textColor, + int numericValueColor, + int stringValueColor, + int otherValueColor, + Object... args) { + String template = StatCollector.translateToLocal(key); + if (template == null || template.isEmpty()) { + GuiDraw.drawText(StatCollector.translateToLocalFormatted(key, args), x, y, scale, textColor, shadow); + return; + } + float xOffset = 0f; + int start = 0; + int argIndex = 0; + int i = 0; + while (i < template.length()) { + char current = template.charAt(i); + if (current != '%') { + i++; + continue; + } + if (i + 1 < template.length() && template.charAt(i + 1) == '%') { + if (start < i) { + String literal = template.substring(start, i); + xOffset += drawDebugTextSegment(literal, x + xOffset, y, scale, textColor, shadow); + } + xOffset += drawDebugTextSegment("%", x + xOffset, y, scale, textColor, shadow); + i += 2; + start = i; + continue; + } + int specEnd = i + 1; + while (specEnd < template.length() && !Character.isLetter(template.charAt(specEnd))) { + specEnd++; + } + if (specEnd >= template.length()) { + break; + } + if (start < i) { + String literal = template.substring(start, i); + xOffset += drawDebugTextSegment(literal, x + xOffset, y, scale, textColor, shadow); + } + String placeholder = template.substring(i, specEnd + 1); + char conversion = Character.toLowerCase(template.charAt(specEnd)); + Object value = argIndex < args.length ? args[argIndex++] : placeholder; + String rendered; + try { + rendered = String.format(Locale.ROOT, placeholder, value); + } catch (Exception ignored) { + rendered = String.valueOf(value); + } + int valueColor; + if (isNumericConversion(conversion) || (conversion == 's' && value instanceof Number)) { + valueColor = numericValueColor; + } else if (conversion == 's') { + valueColor = stringValueColor; + } else { + valueColor = otherValueColor; + } + xOffset += drawDebugTextSegment(rendered, x + xOffset, y, scale, valueColor, shadow); + i = specEnd + 1; + start = i; + } + if (start < template.length()) { + String trailing = template.substring(start); + drawDebugTextSegment(trailing, x + xOffset, y, scale, textColor, shadow); + } + } + + private static float drawDebugTextSegment(String text, float x, float y, float scale, int color, boolean shadow) { + if (text.isEmpty()) return 0f; + GuiDraw.drawText(text, x, y, scale, color, shadow); + FontRenderer fontRenderer = Minecraft.getMinecraft().fontRenderer; + return fontRenderer.getStringWidth(text) * scale; + } + + private static boolean isNumericConversion(char conversion) { + return switch (conversion) { + case 'd', 'o', 'x', 'e', 'f', 'g', 'a' -> true; + default -> false; + }; + } + + private static int parseDebugHexColor(String input, int fallbackColor) { + if (input == null) return fallbackColor; + String hex = input.trim(); + if (hex.startsWith("#")) hex = hex.substring(1); + if (hex.length() == 10) { + hex = hex.substring(2); + } + if (hex.length() == 6) { + hex = "FF" + hex; + } + if (hex.length() != 8) return fallbackColor; + try { + return (int) Long.parseLong(hex, 16); + } catch (NumberFormatException ignored) { + return fallbackColor; + } + } + public static void updateGuiArea(GuiContainer container, Rectangle area) { GuiContainerAccessor acc = (GuiContainerAccessor) container; acc.setGuiLeft(area.x); From ed22b38889f3c87d38ece230a4167cbb62cc1e6f Mon Sep 17 00:00:00 2001 From: Ranzu <66495944+Ranzuu@users.noreply.github.com> Date: Mon, 20 Apr 2026 22:58:51 +0200 Subject: [PATCH 03/10] Revert "DebugColorconfig" This reverts commit 15049c01ef5dcb8c27e0a5bd49073b8c6938a835. --- .../modularui/ModularUIConfig.java | 16 +- .../modularui/overlay/DebugOptions.java | 3 +- .../modularui/overlay/DebugOverlay.java | 27 +- .../modularui/screen/ClientScreenHandler.java | 352 +++--------------- 4 files changed, 63 insertions(+), 335 deletions(-) diff --git a/src/main/java/com/cleanroommc/modularui/ModularUIConfig.java b/src/main/java/com/cleanroommc/modularui/ModularUIConfig.java index dbe583727..ab517381b 100644 --- a/src/main/java/com/cleanroommc/modularui/ModularUIConfig.java +++ b/src/main/java/com/cleanroommc/modularui/ModularUIConfig.java @@ -4,6 +4,7 @@ import com.gtnewhorizon.gtnhlib.config.Config; + @Config(modid = ModularUI.ID) public class ModularUIConfig { @@ -27,21 +28,6 @@ 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 for literal text segments.") - public static String debugTextColorHex = "#B4AAAAAA"; - - @Config.Comment("Debug text color for numeric placeholders like %d.") - public static String debugNumericValueColorHex = "#B400AAAA"; - - @Config.Comment("Debug text color for string placeholders like %s.") - public static String debugStringValueColorHex = "#DCFFAA00"; - - @Config.Comment("Debug text color for non-numeric and non-string placeholders.") - public static String debugOtherValueColorHex = "#DCAAAAAA"; - - @Config.Comment("Debug outline color.") - public static String debugOutlineColorHex = "#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; diff --git a/src/main/java/com/cleanroommc/modularui/overlay/DebugOptions.java b/src/main/java/com/cleanroommc/modularui/overlay/DebugOptions.java index c7767db06..926511077 100644 --- a/src/main/java/com/cleanroommc/modularui/overlay/DebugOptions.java +++ b/src/main/java/com/cleanroommc/modularui/overlay/DebugOptions.java @@ -8,7 +8,6 @@ public class DebugOptions { public static final DebugOptions INSTANCE = new DebugOptions(); - public static final int DEFAULT_DEBUG_COLOR = Color.argb(180, 40, 115, 220); public BoolValue showHovered = new BoolValue(true); public BoolValue showPos = new BoolValue(true); @@ -23,7 +22,7 @@ public class DebugOptions { public BoolValue showParentWidgetTheme = new BoolValue(false); public BoolValue showParentOutline = new BoolValue(true); - public IntValue textColor = new IntValue(DEFAULT_DEBUG_COLOR); + public IntValue textColor = new IntValue(Color.argb(180, 40, 115, 220)); public IntValue outlineColor = new IntValue(textColor.getIntValue()); public IntValue cursorColor = new IntValue(Color.withAlpha(Color.GREEN.main, 0.8f)); public FloatValue scale = new FloatValue(0.8f); diff --git a/src/main/java/com/cleanroommc/modularui/overlay/DebugOverlay.java b/src/main/java/com/cleanroommc/modularui/overlay/DebugOverlay.java index 0b91d9cab..8425fb1e0 100644 --- a/src/main/java/com/cleanroommc/modularui/overlay/DebugOverlay.java +++ b/src/main/java/com/cleanroommc/modularui/overlay/DebugOverlay.java @@ -1,7 +1,6 @@ package com.cleanroommc.modularui.overlay; import com.cleanroommc.modularui.ModularUI; -import com.cleanroommc.modularui.ModularUIConfig; import com.cleanroommc.modularui.api.IMuiScreen; import com.cleanroommc.modularui.api.drawable.IIcon; import com.cleanroommc.modularui.api.drawable.IKey; @@ -44,9 +43,7 @@ public DebugOverlay(IMuiScreen screen) { .bottom(0) .height(12) .width(160) - .background(new Rectangle() - .color(Color.withAlpha(getDebugOutlineColor(), 0.4f)) - .cornerRadius(4)) + .background(new Rectangle().color(Color.withAlpha(DebugOptions.INSTANCE.outlineColor.getIntValue(), 0.4f)).cornerRadius(4)) .disableHoverBackground() .overlay(IKey.str("Debug Options")) .openUp() @@ -128,26 +125,4 @@ private boolean logWidgetTrees(int b) { } return true; } - - private static int getDebugOutlineColor() { - return parseDebugHexColor(ModularUIConfig.debugOutlineColorHex, DebugOptions.DEFAULT_DEBUG_COLOR); - } - - private static int parseDebugHexColor(String input, int fallbackColor) { - if (input == null) return fallbackColor; - String hex = input.trim(); - if (hex.startsWith("#")) hex = hex.substring(1); - if (hex.length() == 10) { - hex = hex.substring(2); - } - if (hex.length() == 6) { - hex = "FF" + hex; - } - if (hex.length() != 8) return fallbackColor; - try { - return (int) Long.parseLong(hex, 16); - } catch (NumberFormatException ignored) { - return fallbackColor; - } - } } diff --git a/src/main/java/com/cleanroommc/modularui/screen/ClientScreenHandler.java b/src/main/java/com/cleanroommc/modularui/screen/ClientScreenHandler.java index c869dc470..61c159d3a 100644 --- a/src/main/java/com/cleanroommc/modularui/screen/ClientScreenHandler.java +++ b/src/main/java/com/cleanroommc/modularui/screen/ClientScreenHandler.java @@ -72,7 +72,6 @@ import java.io.IOException; import java.util.Collections; import java.util.List; -import java.util.Locale; import java.util.function.Predicate; @ApiStatus.Internal @@ -586,12 +585,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 defaultDebugTextColor = DebugOptions.DEFAULT_DEBUG_COLOR; - int outlineColor = parseDebugHexColor(ModularUIConfig.debugOutlineColorHex, defaultDebugTextColor); - int localizedTextColor = parseDebugHexColor(ModularUIConfig.debugTextColorHex, defaultDebugTextColor); - int localizedNumberColor = parseDebugHexColor(ModularUIConfig.debugNumericValueColorHex, defaultDebugTextColor); - int localizedStringColor = parseDebugHexColor(ModularUIConfig.debugStringValueColorHex, defaultDebugTextColor); - int localizedOtherValueColor = parseDebugHexColor(ModularUIConfig.debugOtherValueColorHex, defaultDebugTextColor); + int outlineColor = DebugOptions.INSTANCE.outlineColor.getIntValue();//Color.argb(180, 40, 115, 220); + int textColor = DebugOptions.INSTANCE.textColor.getIntValue();//Color.argb(180, 40, 115, 220); float scale = DebugOptions.INSTANCE.scale.getFloatValue(); int shift = (int) (11 * scale + 0.5f); int lineY = screenH - shift - 2; @@ -600,30 +595,11 @@ public static void drawDebugScreen(@Nullable ModularScreen muiScreen, @Nullable muiScreen.getContext().getRecipeViewerSettings().isEnabled(muiScreen)) { lineY -= 20; } - drawLocalizedDebugText( - "modularui2.debug.mouse_pos", - 5, - lineY, - scale, - true, - localizedTextColor, - localizedNumberColor, - localizedStringColor, - localizedOtherValueColor, - mouseX, - mouseY); + GuiDraw.drawText(StatCollector.translateToLocalFormatted("modularui2.debug.mouse_pos", mouseX, mouseY), + 5, lineY, scale, outlineColor, true); lineY -= shift; - drawLocalizedDebugText( - "modularui2.debug.fps", - 5, - lineY, - scale, - true, - localizedTextColor, - localizedNumberColor, - localizedStringColor, - localizedOtherValueColor, - fpsCounter.getFps()); + GuiDraw.drawText(StatCollector.translateToLocalFormatted("modularui2.debug.fps", fpsCounter.getFps()), + 5, lineY, scale, outlineColor, true); lineY -= shift; LocatedWidget locatedHovered = muiScreen.getPanelManager().getTopWidgetLocated(true); @@ -635,20 +611,11 @@ public static void drawDebugScreen(@Nullable ModularScreen muiScreen, @Nullable } else { theme = context.getTheme(); } - drawLocalizedDebugText( - "modularui2.debug.theme_id", - 5, - lineY, - scale, - true, - localizedTextColor, - localizedNumberColor, - localizedStringColor, - localizedOtherValueColor, - theme.getId()); + GuiDraw.drawText(StatCollector.translateToLocalFormatted("modularui2.debug.theme_id", theme.getId()), + 5, lineY, scale, outlineColor, true); if (locatedHovered != null && (showHovered || showParent)) { - drawSegmentLine(lineY -= 4, scale, localizedTextColor); + drawSegmentLine(lineY -= 4, scale, outlineColor); lineY -= 10; IWidget hovered = locatedHovered.getElement(); @@ -675,190 +642,96 @@ public static void drawDebugScreen(@Nullable ModularScreen muiScreen, @Nullable locatedHovered.unapplyMatrix(context); if (showHovered) { if (DebugOptions.INSTANCE.showWidgetTheme.getBoolValue()) { - drawLocalizedDebugText( - "modularui2.debug.widget_theme", - 5, - lineY, - scale, - true, - localizedTextColor, - localizedNumberColor, - localizedStringColor, - localizedOtherValueColor, - hovered.getWidgetTheme(muiScreen.getCurrentTheme()).getKey().getFullName()); + 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()) { - drawLocalizedDebugText( - "modularui2.debug.size", - 5, - lineY, - scale, - true, - localizedTextColor, - localizedNumberColor, - localizedStringColor, - localizedOtherValueColor, - area.width, - area.height); + GuiDraw.drawText(StatCollector.translateToLocalFormatted("modularui2.debug.size", area.width, area.height), + 5, lineY, scale, textColor, true); lineY -= shift; } if (DebugOptions.INSTANCE.showPos.getBoolValue()) { - drawLocalizedDebugText( - "modularui2.debug.pos_rel", - 5, - lineY, - scale, - true, - localizedTextColor, - localizedNumberColor, - localizedStringColor, - localizedOtherValueColor, - area.x, - area.y, - area.rx, - area.ry); + GuiDraw.drawText( + StatCollector.translateToLocalFormatted( + "modularui2.debug.pos_rel", + area.x, + area.y, + area.rx, + area.ry), + 5, lineY, scale, textColor, true); lineY -= shift; } - drawLocalizedDebugText( - "modularui2.debug.widget", - 5, - lineY, - scale, - true, - localizedTextColor, - localizedNumberColor, - localizedStringColor, - localizedOtherValueColor, - hovered); + GuiDraw.drawText(StatCollector.translateToLocalFormatted("modularui2.debug.widget", hovered), + 5, lineY, scale, textColor, true); } if (hovered.hasParent() && showParent) { if (showHovered) { - drawSegmentLine(lineY -= 4, scale, localizedTextColor); + drawSegmentLine(lineY -= 4, scale, textColor); lineY -= 10; } if (DebugOptions.INSTANCE.showParentWidgetTheme.getBoolValue()) { - drawLocalizedDebugText( - "modularui2.debug.widget_theme", - 5, - lineY, - scale, - true, - localizedTextColor, - localizedNumberColor, - localizedStringColor, - localizedOtherValueColor, - parent.getWidgetTheme(muiScreen.getCurrentTheme()).getKey().getFullName()); + 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()) { - drawLocalizedDebugText( - "modularui2.debug.parent_size", - 5, - lineY, - scale, - true, - localizedTextColor, - localizedNumberColor, - localizedStringColor, - localizedOtherValueColor, - area.width, - area.height); + GuiDraw.drawText( + StatCollector.translateToLocalFormatted("modularui2.debug.parent_size", area.width, area.height), + 5, lineY, scale, textColor, true); lineY -= shift; } if (DebugOptions.INSTANCE.showParentPos.getBoolValue()) { - drawLocalizedDebugText( - "modularui2.debug.parent_pos_rel", - 5, - lineY, - scale, - true, - localizedTextColor, - localizedNumberColor, - localizedStringColor, - localizedOtherValueColor, - area.x, - area.y, - area.rx, - area.ry); + GuiDraw.drawText( + StatCollector.translateToLocalFormatted( + "modularui2.debug.parent_pos_rel", + area.x, + area.y, + area.rx, + area.ry), + 5, lineY, scale, textColor, true); lineY -= shift; } - drawLocalizedDebugText( - "modularui2.debug.parent", - 5, - lineY, - scale, - true, - localizedTextColor, - localizedNumberColor, - localizedStringColor, - localizedOtherValueColor, - parent); + GuiDraw.drawText(StatCollector.translateToLocalFormatted("modularui2.debug.parent", parent), + 5, lineY, scale, outlineColor, true); } if (showHovered && DebugOptions.INSTANCE.showExtra.getBoolValue()) { if (hovered instanceof ItemSlot slotWidget) { - drawSegmentLine(lineY -= 4, scale, localizedTextColor); + drawSegmentLine(lineY -= 4, scale, textColor); lineY -= 10; ModularSlot slot = slotWidget.getSlot(); - drawLocalizedDebugText( - "modularui2.debug.slot_index", - 5, - lineY, - scale, - true, - localizedTextColor, - localizedNumberColor, - localizedStringColor, - localizedOtherValueColor, - slot.getSlotIndex()); + GuiDraw.drawText(StatCollector.translateToLocalFormatted("modularui2.debug.slot_index", slot.getSlotIndex()), + 5, lineY, scale, textColor, true); lineY -= shift; - drawLocalizedDebugText( - "modularui2.debug.slot_number", - 5, - lineY, - scale, - true, - localizedTextColor, - localizedNumberColor, - localizedStringColor, - localizedOtherValueColor, - slot.slotNumber); + 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(); - drawLocalizedDebugText( - "modularui2.debug.shift_click_priority", - 5, - lineY, - scale, - true, - localizedTextColor, - localizedNumberColor, - localizedStringColor, - localizedOtherValueColor, - allowShiftTransfer - ? slotGroup.getShiftClickPriority() - : StatCollector.translateToLocal("modularui2.debug.disabled")); + 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, localizedTextColor); + drawSegmentLine(lineY -= 4, scale, outlineColor); lineY -= 10; locatedHovered.applyMatrix(context); Object hoveredElement = richTextWidget.getHoveredElement(); locatedHovered.unapplyMatrix(context); - drawLocalizedDebugText( - "modularui2.debug.hovered", - 5, - lineY, - scale, - true, - localizedTextColor, - localizedNumberColor, - localizedStringColor, - localizedOtherValueColor, - hoveredElement); + GuiDraw.drawText(StatCollector.translateToLocalFormatted("modularui2.debug.hovered", hoveredElement), + 5, lineY, scale, textColor, true); } } } @@ -871,111 +744,6 @@ private static void drawSegmentLine(int y, float scale, int color) { GuiDraw.drawRect(5, y, 140 * scale, 1 * scale, color); } - private static void drawLocalizedDebugText(String key, - float x, - float y, - float scale, - boolean shadow, - int textColor, - int numericValueColor, - int stringValueColor, - int otherValueColor, - Object... args) { - String template = StatCollector.translateToLocal(key); - if (template == null || template.isEmpty()) { - GuiDraw.drawText(StatCollector.translateToLocalFormatted(key, args), x, y, scale, textColor, shadow); - return; - } - float xOffset = 0f; - int start = 0; - int argIndex = 0; - int i = 0; - while (i < template.length()) { - char current = template.charAt(i); - if (current != '%') { - i++; - continue; - } - if (i + 1 < template.length() && template.charAt(i + 1) == '%') { - if (start < i) { - String literal = template.substring(start, i); - xOffset += drawDebugTextSegment(literal, x + xOffset, y, scale, textColor, shadow); - } - xOffset += drawDebugTextSegment("%", x + xOffset, y, scale, textColor, shadow); - i += 2; - start = i; - continue; - } - int specEnd = i + 1; - while (specEnd < template.length() && !Character.isLetter(template.charAt(specEnd))) { - specEnd++; - } - if (specEnd >= template.length()) { - break; - } - if (start < i) { - String literal = template.substring(start, i); - xOffset += drawDebugTextSegment(literal, x + xOffset, y, scale, textColor, shadow); - } - String placeholder = template.substring(i, specEnd + 1); - char conversion = Character.toLowerCase(template.charAt(specEnd)); - Object value = argIndex < args.length ? args[argIndex++] : placeholder; - String rendered; - try { - rendered = String.format(Locale.ROOT, placeholder, value); - } catch (Exception ignored) { - rendered = String.valueOf(value); - } - int valueColor; - if (isNumericConversion(conversion) || (conversion == 's' && value instanceof Number)) { - valueColor = numericValueColor; - } else if (conversion == 's') { - valueColor = stringValueColor; - } else { - valueColor = otherValueColor; - } - xOffset += drawDebugTextSegment(rendered, x + xOffset, y, scale, valueColor, shadow); - i = specEnd + 1; - start = i; - } - if (start < template.length()) { - String trailing = template.substring(start); - drawDebugTextSegment(trailing, x + xOffset, y, scale, textColor, shadow); - } - } - - private static float drawDebugTextSegment(String text, float x, float y, float scale, int color, boolean shadow) { - if (text.isEmpty()) return 0f; - GuiDraw.drawText(text, x, y, scale, color, shadow); - FontRenderer fontRenderer = Minecraft.getMinecraft().fontRenderer; - return fontRenderer.getStringWidth(text) * scale; - } - - private static boolean isNumericConversion(char conversion) { - return switch (conversion) { - case 'd', 'o', 'x', 'e', 'f', 'g', 'a' -> true; - default -> false; - }; - } - - private static int parseDebugHexColor(String input, int fallbackColor) { - if (input == null) return fallbackColor; - String hex = input.trim(); - if (hex.startsWith("#")) hex = hex.substring(1); - if (hex.length() == 10) { - hex = hex.substring(2); - } - if (hex.length() == 6) { - hex = "FF" + hex; - } - if (hex.length() != 8) return fallbackColor; - try { - return (int) Long.parseLong(hex, 16); - } catch (NumberFormatException ignored) { - return fallbackColor; - } - } - public static void updateGuiArea(GuiContainer container, Rectangle area) { GuiContainerAccessor acc = (GuiContainerAccessor) container; acc.setGuiLeft(area.x); From f2e009809bec149dfada09831e11ad110640a799 Mon Sep 17 00:00:00 2001 From: Ranzu <66495944+Ranzuu@users.noreply.github.com> Date: Mon, 20 Apr 2026 23:43:13 +0200 Subject: [PATCH 04/10] Revert DebugColorconfig and add two config colors --- .../java/com/cleanroommc/modularui/ModularUIConfig.java | 6 ++++++ .../cleanroommc/modularui/screen/ClientScreenHandler.java | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/cleanroommc/modularui/ModularUIConfig.java b/src/main/java/com/cleanroommc/modularui/ModularUIConfig.java index ab517381b..2c55312b4 100644 --- a/src/main/java/com/cleanroommc/modularui/ModularUIConfig.java +++ b/src/main/java/com/cleanroommc/modularui/ModularUIConfig.java @@ -28,6 +28,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 (ARGB).") + public static int debugTextColor = 0xDCB42873; + + @Config.Comment("Debug outline color (ARGB).") + public static int debugOutlineColor = 0xDCB42873; + @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; diff --git a/src/main/java/com/cleanroommc/modularui/screen/ClientScreenHandler.java b/src/main/java/com/cleanroommc/modularui/screen/ClientScreenHandler.java index 61c159d3a..67a54428a 100644 --- a/src/main/java/com/cleanroommc/modularui/screen/ClientScreenHandler.java +++ b/src/main/java/com/cleanroommc/modularui/screen/ClientScreenHandler.java @@ -585,8 +585,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 = ModularUIConfig.debugOutlineColor; + int textColor = ModularUIConfig.debugTextColor; float scale = DebugOptions.INSTANCE.scale.getFloatValue(); int shift = (int) (11 * scale + 0.5f); int lineY = screenH - shift - 2; From 04767158f1457d124b2a29c23dd81b868ff9aa31 Mon Sep 17 00:00:00 2001 From: Ranzu <66495944+Ranzuu@users.noreply.github.com> Date: Mon, 20 Apr 2026 23:43:15 +0200 Subject: [PATCH 05/10] COLORS --- .../java/com/cleanroommc/modularui/ModularUIConfig.java | 8 ++++---- .../cleanroommc/modularui/screen/ClientScreenHandler.java | 7 +++++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/cleanroommc/modularui/ModularUIConfig.java b/src/main/java/com/cleanroommc/modularui/ModularUIConfig.java index 2c55312b4..04f7a7d02 100644 --- a/src/main/java/com/cleanroommc/modularui/ModularUIConfig.java +++ b/src/main/java/com/cleanroommc/modularui/ModularUIConfig.java @@ -28,11 +28,11 @@ 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 (ARGB).") - public static int debugTextColor = 0xDCB42873; + @Config.Comment("Debug text color.") + public static String debugTextColor = "0xDCB42873"; - @Config.Comment("Debug outline color (ARGB).") - public static int debugOutlineColor = 0xDCB42873; + @Config.Comment("Debug outline color.") + public static String debugOutlineColor = "0xDCB42873"; @Config.RequiresMcRestart @Config.Comment("Enables a test block, test item with a test gui and opening a gui by right clicking a diamond.") diff --git a/src/main/java/com/cleanroommc/modularui/screen/ClientScreenHandler.java b/src/main/java/com/cleanroommc/modularui/screen/ClientScreenHandler.java index 67a54428a..48a05480d 100644 --- a/src/main/java/com/cleanroommc/modularui/screen/ClientScreenHandler.java +++ b/src/main/java/com/cleanroommc/modularui/screen/ClientScreenHandler.java @@ -60,6 +60,7 @@ import codechicken.nei.LayoutManager; import codechicken.nei.guihook.GuiContainerManager; import codechicken.nei.guihook.IContainerDrawHandler; +import com.google.gson.JsonPrimitive; import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; @@ -79,6 +80,8 @@ public class ClientScreenHandler { private static final GuiContext defaultContext = new GuiContext(); + private static final int DEFAULT_DEBUG_TEXT_COLOR = 0xDCB42873; + private static final int DEFAULT_DEBUG_OUTLINE_COLOR = 0xDCB42873; private static ModularScreen currentScreen = null; private static Character lastChar = null; @@ -585,8 +588,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 = ModularUIConfig.debugOutlineColor; - int textColor = ModularUIConfig.debugTextColor; + int outlineColor = parseDebugColor(ModularUIConfig.debugOutlineColor, DEFAULT_DEBUG_OUTLINE_COLOR); + int textColor = parseDebugColor(ModularUIConfig.debugTextColor, DEFAULT_DEBUG_TEXT_COLOR); float scale = DebugOptions.INSTANCE.scale.getFloatValue(); int shift = (int) (11 * scale + 0.5f); int lineY = screenH - shift - 2; From cb350186aa573d794264ba6f0d253f4f54ff0ac9 Mon Sep 17 00:00:00 2001 From: Ranzu <66495944+Ranzuu@users.noreply.github.com> Date: Mon, 20 Apr 2026 23:46:33 +0200 Subject: [PATCH 06/10] parseDebugColor --- .../cleanroommc/modularui/screen/ClientScreenHandler.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/com/cleanroommc/modularui/screen/ClientScreenHandler.java b/src/main/java/com/cleanroommc/modularui/screen/ClientScreenHandler.java index 48a05480d..564143f62 100644 --- a/src/main/java/com/cleanroommc/modularui/screen/ClientScreenHandler.java +++ b/src/main/java/com/cleanroommc/modularui/screen/ClientScreenHandler.java @@ -747,6 +747,12 @@ private static void drawSegmentLine(int y, float scale, int color) { GuiDraw.drawRect(5, y, 140 * scale, 1 * scale, color); } + private static int parseDebugColor(String color, int fallback) { + String parsed = color == null ? "" : color.trim(); + if (parsed.isEmpty()) return fallback; + return Color.ofJson(new JsonPrimitive(parsed)); + } + public static void updateGuiArea(GuiContainer container, Rectangle area) { GuiContainerAccessor acc = (GuiContainerAccessor) container; acc.setGuiLeft(area.x); From d1a44f9023c53b3ba1c99a1dfc27a4eb35cdcffe Mon Sep 17 00:00:00 2001 From: Ranzu <66495944+Ranzuu@users.noreply.github.com> Date: Mon, 20 Apr 2026 23:52:50 +0200 Subject: [PATCH 07/10] Argb Config --- src/main/java/com/cleanroommc/modularui/ModularUIConfig.java | 4 ++-- .../com/cleanroommc/modularui/screen/ClientScreenHandler.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/cleanroommc/modularui/ModularUIConfig.java b/src/main/java/com/cleanroommc/modularui/ModularUIConfig.java index 04f7a7d02..661468602 100644 --- a/src/main/java/com/cleanroommc/modularui/ModularUIConfig.java +++ b/src/main/java/com/cleanroommc/modularui/ModularUIConfig.java @@ -29,10 +29,10 @@ public class ModularUIConfig { public static boolean useDarkThemeByDefault = false; @Config.Comment("Debug text color.") - public static String debugTextColor = "0xDCB42873"; + public static String debugTextColor = "DCB42873"; @Config.Comment("Debug outline color.") - public static String debugOutlineColor = "0xDCB42873"; + 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.") diff --git a/src/main/java/com/cleanroommc/modularui/screen/ClientScreenHandler.java b/src/main/java/com/cleanroommc/modularui/screen/ClientScreenHandler.java index 564143f62..a1a876aef 100644 --- a/src/main/java/com/cleanroommc/modularui/screen/ClientScreenHandler.java +++ b/src/main/java/com/cleanroommc/modularui/screen/ClientScreenHandler.java @@ -60,7 +60,6 @@ import codechicken.nei.LayoutManager; import codechicken.nei.guihook.GuiContainerManager; import codechicken.nei.guihook.IContainerDrawHandler; -import com.google.gson.JsonPrimitive; import it.unimi.dsi.fastutil.objects.ObjectArrayList; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.Nullable; @@ -750,7 +749,8 @@ private static void drawSegmentLine(int y, float scale, int color) { private static int parseDebugColor(String color, int fallback) { String parsed = color == null ? "" : color.trim(); if (parsed.isEmpty()) return fallback; - return Color.ofJson(new JsonPrimitive(parsed)); + if (!parsed.matches("(?i)[0-9a-f]{8}")) return fallback; + return (int) Long.parseLong(parsed, 16); } public static void updateGuiArea(GuiContainer container, Rectangle area) { From bbf09d3d8a630876300b598f2d65768c529c5765 Mon Sep 17 00:00:00 2001 From: Ranzu <66495944+Ranzuu@users.noreply.github.com> Date: Tue, 21 Apr 2026 13:18:22 +0200 Subject: [PATCH 08/10] fix --- .../modularui/screen/ClientScreenHandler.java | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/cleanroommc/modularui/screen/ClientScreenHandler.java b/src/main/java/com/cleanroommc/modularui/screen/ClientScreenHandler.java index a1a876aef..72db8e2e8 100644 --- a/src/main/java/com/cleanroommc/modularui/screen/ClientScreenHandler.java +++ b/src/main/java/com/cleanroommc/modularui/screen/ClientScreenHandler.java @@ -598,10 +598,10 @@ public static void drawDebugScreen(@Nullable ModularScreen muiScreen, @Nullable lineY -= 20; } GuiDraw.drawText(StatCollector.translateToLocalFormatted("modularui2.debug.mouse_pos", mouseX, mouseY), - 5, lineY, scale, outlineColor, true); + 5, lineY, scale, textColor, true); lineY -= shift; GuiDraw.drawText(StatCollector.translateToLocalFormatted("modularui2.debug.fps", fpsCounter.getFps()), - 5, lineY, scale, outlineColor, true); + 5, lineY, scale, textColor, true); lineY -= shift; LocatedWidget locatedHovered = muiScreen.getPanelManager().getTopWidgetLocated(true); @@ -614,10 +614,10 @@ public static void drawDebugScreen(@Nullable ModularScreen muiScreen, @Nullable theme = context.getTheme(); } GuiDraw.drawText(StatCollector.translateToLocalFormatted("modularui2.debug.theme_id", theme.getId()), - 5, lineY, scale, outlineColor, true); + 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(); @@ -702,7 +702,7 @@ public static void drawDebugScreen(@Nullable ModularScreen muiScreen, @Nullable lineY -= shift; } GuiDraw.drawText(StatCollector.translateToLocalFormatted("modularui2.debug.parent", parent), - 5, lineY, scale, outlineColor, true); + 5, lineY, scale, textColor, true); } if (showHovered && DebugOptions.INSTANCE.showExtra.getBoolValue()) { if (hovered instanceof ItemSlot slotWidget) { @@ -748,9 +748,8 @@ private static void drawSegmentLine(int y, float scale, int color) { private static int parseDebugColor(String color, int fallback) { String parsed = color == null ? "" : color.trim(); - if (parsed.isEmpty()) return fallback; - if (!parsed.matches("(?i)[0-9a-f]{8}")) return fallback; - return (int) Long.parseLong(parsed, 16); + if (!parsed.matches("(?i)^[0-9a-f]{8}$")) return fallback; + return (int) Long.parseLong(parsed, 16); } public static void updateGuiArea(GuiContainer container, Rectangle area) { From b70cc6343dcf02eebb047a92f694bf830eaf038f Mon Sep 17 00:00:00 2001 From: Ranzu <66495944+Ranzuu@users.noreply.github.com> Date: Tue, 21 Apr 2026 14:07:43 +0200 Subject: [PATCH 09/10] debug default colors --- .../modularui/ModularUIConfig.java | 2 +- .../assets/modularui2/lang/en_US.lang | 30 +++++++++---------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/cleanroommc/modularui/ModularUIConfig.java b/src/main/java/com/cleanroommc/modularui/ModularUIConfig.java index 661468602..90d13d07a 100644 --- a/src/main/java/com/cleanroommc/modularui/ModularUIConfig.java +++ b/src/main/java/com/cleanroommc/modularui/ModularUIConfig.java @@ -29,7 +29,7 @@ public class ModularUIConfig { public static boolean useDarkThemeByDefault = false; @Config.Comment("Debug text color.") - public static String debugTextColor = "DCB42873"; + public static String debugTextColor = "FFAAAAAA"; @Config.Comment("Debug outline color.") public static String debugOutlineColor = "DCB42873"; diff --git a/src/main/resources/assets/modularui2/lang/en_US.lang b/src/main/resources/assets/modularui2/lang/en_US.lang index 310428367..02b46ca2d 100644 --- a/src/main/resources/assets/modularui2/lang/en_US.lang +++ b/src/main/resources/assets/modularui2/lang/en_US.lang @@ -22,18 +22,18 @@ modularui2.fluid.click_combined=§cRight §7or §bLeft §7Click with a Fluid Con 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=Mouse Pos: %d, %d -modularui2.debug.fps=FPS: %d -modularui2.debug.theme_id=Theme ID: %s -modularui2.debug.widget_theme=Widget Theme: %s -modularui2.debug.size=Size: %s, %s -modularui2.debug.pos_rel=Post: %d, %d Rel: %d, %d -modularui2.debug.widget=Widget: %s -modularui2.debug.parent_size=Parent size: %s, %s -modularui2.debug.parent_pos_rel=Parent pos: %d, %d Rel: %d, %d -modularui2.debug.parent=Parent: %s -modularui2.debug.slot_index=Slot Index: %d -modularui2.debug.slot_number=Slot Number: %d -modularui2.debug.shift_click_priority=Shift-Click Priority: %s -modularui2.debug.disabled=DISABLED -modularui2.debug.hovered=Hovered: %s \ No newline at end of file +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 \ No newline at end of file From 21818345eaa11a7ebe5d1b3fdd57def6c607ea2d Mon Sep 17 00:00:00 2001 From: brachy84 Date: Fri, 24 Apr 2026 14:05:51 +0200 Subject: [PATCH 10/10] better color parsing --- .../modularui/ModularUIConfig.java | 9 +- .../modularui/screen/ClientScreenHandler.java | 14 +-- .../cleanroommc/modularui/utils/Color.java | 97 ++++++++++++------- 3 files changed, 72 insertions(+), 48 deletions(-) diff --git a/src/main/java/com/cleanroommc/modularui/ModularUIConfig.java b/src/main/java/com/cleanroommc/modularui/ModularUIConfig.java index 90d13d07a..4c6bea4b8 100644 --- a/src/main/java/com/cleanroommc/modularui/ModularUIConfig.java +++ b/src/main/java/com/cleanroommc/modularui/ModularUIConfig.java @@ -4,7 +4,6 @@ import com.gtnewhorizon.gtnhlib.config.Config; - @Config(modid = ModularUI.ID) public class ModularUIConfig { @@ -28,11 +27,11 @@ 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.") - public static String debugTextColor = "FFAAAAAA"; + @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.") - public static String debugOutlineColor = "DCB42873"; + @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.") diff --git a/src/main/java/com/cleanroommc/modularui/screen/ClientScreenHandler.java b/src/main/java/com/cleanroommc/modularui/screen/ClientScreenHandler.java index 72db8e2e8..937e2bbdb 100644 --- a/src/main/java/com/cleanroommc/modularui/screen/ClientScreenHandler.java +++ b/src/main/java/com/cleanroommc/modularui/screen/ClientScreenHandler.java @@ -79,7 +79,7 @@ public class ClientScreenHandler { private static final GuiContext defaultContext = new GuiContext(); - private static final int DEFAULT_DEBUG_TEXT_COLOR = 0xDCB42873; + private static final int DEFAULT_DEBUG_TEXT_COLOR = 0xFFAAAAAA; private static final int DEFAULT_DEBUG_OUTLINE_COLOR = 0xDCB42873; private static ModularScreen currentScreen = null; @@ -587,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 = parseDebugColor(ModularUIConfig.debugOutlineColor, DEFAULT_DEBUG_OUTLINE_COLOR); - int textColor = parseDebugColor(ModularUIConfig.debugTextColor, DEFAULT_DEBUG_TEXT_COLOR); + 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; @@ -727,7 +727,7 @@ public static void drawDebugScreen(@Nullable ModularScreen muiScreen, @Nullable 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(); @@ -746,12 +746,6 @@ private static void drawSegmentLine(int y, float scale, int color) { GuiDraw.drawRect(5, y, 140 * scale, 1 * scale, color); } - private static int parseDebugColor(String color, int fallback) { - String parsed = color == null ? "" : color.trim(); - if (!parsed.matches("(?i)^[0-9a-f]{8}$")) return fallback; - return (int) Long.parseLong(parsed, 16); - } - public static void updateGuiArea(GuiContainer container, Rectangle area) { GuiContainerAccessor acc = (GuiContainerAccessor) container; acc.setGuiLeft(area.x); diff --git a/src/main/java/com/cleanroommc/modularui/utils/Color.java b/src/main/java/com/cleanroommc/modularui/utils/Color.java index a6c0c78f0..5ebd0adb1 100644 --- a/src/main/java/com/cleanroommc/modularui/utils/Color.java +++ b/src/main/java/com/cleanroommc/modularui/utils/Color.java @@ -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. + *

+ * Example: "deep_purple:-3" returns 0xFF4527A0 + *

+ * 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();