diff --git a/src/main/java/org/saturnclient/ui2/RenderScope.java b/src/main/java/org/saturnclient/ui2/RenderScope.java index b197f85..fecac10 100644 --- a/src/main/java/org/saturnclient/ui2/RenderScope.java +++ b/src/main/java/org/saturnclient/ui2/RenderScope.java @@ -80,17 +80,19 @@ public class RenderScope { } public void drawText(String text, int x, int y, boolean bold, int color) { - color = getColor(color); - - Identifier font = bold ? Fonts.INTER_BOLD : Fonts.INTER; - - matrices.push(); - matrices.translate(x, y, 0); - matrices.scale(1.0f, 1.0f, 1.0f); - TextRenderer textRenderer = SaturnClient.client.textRenderer; - textRenderer.draw(Fonts.setFont(text, font), 0, 7, color, false, this.matrices.peek().getPositionMatrix(), - this.vertexConsumers, TextLayerType.NORMAL, 0, 15728880); - matrices.pop(); + int i = 0; + for (String line : text.split("\n")) { + color = getColor(color); + Identifier font = bold ? Fonts.INTER_BOLD : Fonts.INTER; + matrices.push(); + matrices.translate(x, y + (i * Fonts.getHeight()), 0); + matrices.scale(1.0f, 1.0f, 1.0f); + TextRenderer textRenderer = SaturnClient.client.textRenderer; + textRenderer.draw(Fonts.setFont(line, font), 0, 7, color, false, this.matrices.peek().getPositionMatrix(), + this.vertexConsumers, TextLayerType.NORMAL, 0, 15728880); + matrices.pop(); + i++; + } } public void drawRoundedCorner(int width, int height, int radius, int color) { diff --git a/src/main/java/org/saturnclient/ui2/components/SaturnModule.java b/src/main/java/org/saturnclient/ui2/components/SaturnModule.java index 99f69ef..a24325e 100644 --- a/src/main/java/org/saturnclient/ui2/components/SaturnModule.java +++ b/src/main/java/org/saturnclient/ui2/components/SaturnModule.java @@ -5,6 +5,7 @@ import org.saturnclient.saturnclient.SaturnClient; import org.saturnclient.saturnclient.config.Property; import org.saturnclient.saturnclient.config.ThemeManager; import org.saturnclient.saturnclient.menus.ConfigEditor; +import org.saturnclient.ui.Textures; import org.saturnclient.ui2.Element; import org.saturnclient.ui2.RenderContext; import org.saturnclient.ui2.RenderScope; @@ -14,28 +15,33 @@ import org.saturnclient.ui2.resources.Fonts; import net.minecraft.client.render.RenderLayer; public class SaturnModule extends Element { - private static ThemeManager theme = new ThemeManager("SaturnModule", "enabled", "hovering", "toggle-hovering"); + private static ThemeManager theme = new ThemeManager("SaturnModule", "enabled", "hovering"); private static Property bgColor = theme.property("bg-color", new Property(-16777216)); private static Property fgColor = theme.property("fg-color", new Property(-1)); - private static Property iconColor = theme.property("icon-color", new Property(-1)); - private static Property toggleFg = theme.property("toggle-fg", new Property(-1)); - private static Property toggleBg = theme.property("toggle-bg", new Property(-16777216)); + private static Property iconBgColor = theme.property("icon-bg-color", new Property(-16777216)); + private static Property iconColor = theme.property("icon-fg-color", new Property(-1)); - private static Property cornerRadius = theme.property("corner-radius", new Property(25)); - private static Property toggleBold = theme.property("toggle-bold", new Property(false)); - private static Property nameBold = theme.property("name-bold", new Property(false)); + private static Property cornerRadius = theme.property("corner-radius", new Property(10)); + private static Property padding = theme.property("padding", new Property(10)); + private static Property iconMargin = theme.property("icon-margin", new Property(10)); + private static Property iconPadding = theme.property("icon-padding", new Property(4)); + + private static ThemeManager settingsTheme = new ThemeManager("SaturnModule$Settings", "hovering"); + private static Property settingsBg = settingsTheme.property("bg-color", new Property(-16777216)); + private static Property settingsFg = settingsTheme.property("fg-color", new Property(-1)); + private static Property settingsRadius = settingsTheme.property("corner-radius", new Property(10)); static { - theme.propertyStateDefault("enabled", "toggle-bg", -7643914); + theme.propertyStateDefault("enabled", "icon-bg-color", -7643914); theme.propertyStateDefault("hovering", "fg-color", -7643914); - theme.propertyStateDefault("hovering", "icon-color", -7643914); + settingsTheme.propertyStateDefault("hovering", "bg-color", -7643914); } private Module mod; public SaturnModule(Module mod) { this.mod = mod; - this.width = 140; + this.width = 180; this.height = 140; } @@ -45,39 +51,76 @@ public class SaturnModule extends Element { if (mod.isEnabled()) { theme.setState("enabled"); - } else { - theme.setState(null); } - if (ctx.isHovering(0, (height-30), width, 30)) { - theme.applyState("toggle-hovering"); + if (ctx.isHovering(0, (height-40), width, 30)) { + settingsTheme.setState("hovering"); } else if (ctx.isHovering()) { theme.applyState("hovering"); } - renderScope.enableScissor(0, 0, width + 10, height - 30); renderScope.drawRoundedRectangle(0, 0, width, height, cornerRadius.value, bgColor.value); - renderScope.disableScissor(); - renderScope.drawTexture(mod.getIconTexture(), (width - 20) / 2, (height - 65) / 2, 0, 0, 20, 20, iconColor.value); + renderScope.matrices.push(); - renderScope.drawText(mod.getName(), Fonts.centerX(width, mod.getName(), focused), Fonts.centerY(height), nameBold.value, fgColor.value); + renderScope.matrices.translate(padding.value, padding.value, 0); - renderScope.enableScissor(0, height - 30, width + 10, height); - renderScope.drawRoundedRectangle(0, 0, width, height, cornerRadius.value, toggleBg.value); - renderScope.disableScissor(); + renderScope.drawRoundedRectangle(0, 0, 20, 20, 10, iconBgColor.value); + renderScope.drawTexture(mod.getIconTexture(), iconPadding.value, iconPadding.value, 0, 0, 20 - (iconPadding.value * 2), 20 - (iconPadding.value * 2), iconColor.value); + renderScope.drawText(mod.getName(), 20 + iconMargin.value, (22 - Fonts.getHeight()) / 2, false, fgColor.value); + renderScope.matrices.push(); + renderScope.matrices.translate(20 + iconMargin.value, ((22 - Fonts.getHeight()) / 2) + Fonts.getHeight(), 0); - String t = mod.isEnabled() ? "Enabled" : "Disabled"; + renderScope.matrices.scale(0.5f, 0.5f, 1); + renderScope.drawText(formatText(mod.getDescription(), (int) ((width - iconMargin.value) * 1.5f)), 0, 0, false, -20); + renderScope.matrices.pop(); - renderScope.drawText(t, Fonts.centerX(width, t, toggleBold.value), height - 30 + Fonts.centerY(30), toggleBold.value, toggleFg.value); + renderScope.matrices.pop(); + + // Settings button + renderScope.matrices.push(); + renderScope.matrices.translate(padding.value, height - 30 - padding.value, 0); + + int w = width - (padding.value * 2); + + renderScope.drawRoundedRectangle(0, 0, w, 30, settingsRadius.value, settingsBg.value); + renderScope.drawTexture(Textures.SETTINGS, ((w - Fonts.getWidth("Settings", false)) / 2) - 20, (16) / 2, 0, 0, 15, 15, settingsFg.value); + renderScope.drawText("Settings", Fonts.centerX(w, "Settings", false), Fonts.centerY(32), false, settingsFg.value); + renderScope.matrices.pop(); + + theme.setState(null); + settingsTheme.setState(null); } @Override public void click(int mouseX, int mouseY) { - if (Utils.isHovering(mouseX, mouseY - (height-30), width, 30, scale)) { - mod.setEnabled(!mod.isEnabled()); - } else { + if (Utils.isHovering(mouseX, mouseY - (height-40), width, 30, scale)) { SaturnClient.client.setScreen(new ConfigEditor(mod.getConfig())); + } else { + mod.setEnabled(!mod.isEnabled()); } } + + public static String formatText(String text, int width) { + StringBuilder formatted = new StringBuilder(); + StringBuilder currentLine = new StringBuilder(); + + for (char c : text.toCharArray()) { + currentLine.append(c); + if (Fonts.getWidth(currentLine.toString(), false) > width) { + // Line is too wide; backtrack the last character + currentLine.deleteCharAt(currentLine.length() - 1); + formatted.append(currentLine).append('\n'); + currentLine.setLength(0); // clear currentLine + currentLine.append(c); // start new line with the character that overflowed + } + } + + // Append any remaining characters in the currentLine + if (currentLine.length() > 0) { + formatted.append(currentLine); + } + + return formatted.toString(); + } } diff --git a/src/main/java/org/saturnclient/ui2/screens/ModMenu.java b/src/main/java/org/saturnclient/ui2/screens/ModMenu.java index 5c7fc6c..50bee87 100644 --- a/src/main/java/org/saturnclient/ui2/screens/ModMenu.java +++ b/src/main/java/org/saturnclient/ui2/screens/ModMenu.java @@ -30,7 +30,7 @@ public class ModMenu extends SaturnScreen { int col = 0; for (Module mod : ModManager.MODS) { - scroll.draw(new SaturnModule(mod).position((140 + gap.value) * col, (140 + gap.value) * row)); + scroll.draw(new SaturnModule(mod).position((180 + gap.value) * col, (140 + gap.value) * row)); if (col == 2) { col = 0; @@ -40,7 +40,7 @@ public class ModMenu extends SaturnScreen { } } - int scrollWidth = 420 + (gap.value * 2) + (padding.value * 2); + int scrollWidth = 540 + (gap.value * 2) + (padding.value * 2); draw(scroll.dimensions(scrollWidth, 350).center(width, height));