This commit is contained in:
2026-02-21 18:40:14 +01:00
parent 5b37131bfd
commit aab4f02dc0
@@ -1,9 +1,8 @@
package org.saturnclient.ui2.components; package org.saturnclient.ui2.components;
import org.saturnclient.saturnclient.SaturnClient; import org.saturnclient.saturnclient.SaturnClient;
import org.saturnclient.saturnclient.config.Property;
import org.saturnclient.saturnclient.config.SaturnClientConfig; import org.saturnclient.saturnclient.config.SaturnClientConfig;
import org.saturnclient.saturnclient.config.ThemeManager; import org.saturnclient.saturnclient.config.Theme;
import org.saturnclient.ui2.resources.Textures; import org.saturnclient.ui2.resources.Textures;
import org.saturnclient.ui2.Element; import org.saturnclient.ui2.Element;
import org.saturnclient.ui2.ElementContext; import org.saturnclient.ui2.ElementContext;
@@ -18,19 +17,6 @@ import net.minecraft.client.render.RenderLayer;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
public class Sidebar extends Element { public class Sidebar extends Element {
private static ThemeManager theme = new ThemeManager("SideBar", "hovering");
private static Property<Integer> bgColor = theme.property("bg-color", Property.color(0x90000000));
private static Property<Integer> iconFg = theme.property("icon-fg", Property.color(0xFFFFFFFF));
private static Property<Integer> iconBg = theme.property("icon-bg", Property.color(0x00000000));
private static Property<Integer> cornerRadius = theme.property("corner-radius", Property.integer(10));
private static Property<Integer> iconRadius = theme.property("icon-radius", Property.integer(10));
private static Property<Integer> padding = theme.property("padding", Property.integer(10));
static {
theme.propertyStateDefault("hovering", "icon-bg", -7643914);
}
public static class SidebarComponent { public static class SidebarComponent {
Runnable onClick; Runnable onClick;
boolean end; boolean end;
@@ -45,7 +31,7 @@ public class Sidebar extends Element {
Runnable onClose; Runnable onClose;
SidebarComponent[] components = { SidebarComponent[] components = {
new Sidebar.SidebarComponent(Textures.MODS_TAB, () -> { new Sidebar.SidebarComponent(Textures.MODS_TAB, () -> {
SaturnClient.client.setScreen(new ModMenu()); SaturnClient.client.setScreen(new ModMenu());
}, false), }, false),
new Sidebar.SidebarComponent(Textures.SETTINGS, () -> { new Sidebar.SidebarComponent(Textures.SETTINGS, () -> {
@@ -79,36 +65,33 @@ public class Sidebar extends Element {
int bottomRow = 0; int bottomRow = 0;
int gap = 5; // 5px gap between icons int gap = 5; // 5px gap between icons
int sp = 30 - padding.value + gap; int padding = 10;
int s = 30 - (padding.value * 2); int sp = 30 - padding + gap;
int s2 = s + padding.value; int s = 30 - (padding * 2);
int s2 = s + padding;
renderScope.setRenderLayer(RenderLayer::getGuiTextured); renderScope.setRenderLayer(RenderLayer::getGuiTextured);
renderScope.drawRoundedRectangle(0, 0, width, height, cornerRadius.value, bgColor.value); renderScope.drawRoundedRectangle(0, 0, width, height, Theme.BG_RADIUS.value, Theme.BACKGROUND.value);
int i = 0; int i = 0;
for (SidebarComponent component : components) { for (SidebarComponent component : components) {
if (component.end) { if (component.end) {
int y = (height - (sp * bottomRow)) - (s * 2); int y = (height - (sp * bottomRow)) - (s * 2);
if (ctx.isHovering(0, y - (padding.value / 2), s2, s2) || active == i) { if (ctx.isHovering(0, y - (padding / 2), s2, s2) || active == i) {
theme.setState("hovering");
} else {
theme.setState(null);
} }
renderScope.drawRoundedRectangle(padding.value / 2, y - (padding.value / 2), s + padding.value, s + padding.value, iconRadius.value, iconBg.value); renderScope.drawRoundedRectangle(padding / 2, y - (padding / 2), s + padding,
renderScope.drawTexture(component.sprite, padding.value, y, 0, 0, s, s, iconFg.value); s + padding, Theme.WIDGET_RADIUS.value, Theme.PRIMARY.value);
renderScope.drawTexture(component.sprite, padding, y, 0, 0, s, s, Theme.PRIMARY_FG.value);
bottomRow += 1; bottomRow += 1;
} else { } else {
int y = padding.value + (sp * topRow); int y = padding + (sp * topRow);
if (ctx.isHovering(0, y - (padding.value / 2), s2, s2) || active == i) { if (ctx.isHovering(0, y - (padding / 2), s2, s2) || active == i) {
theme.setState("hovering");
} else {
theme.setState(null);
} }
renderScope.drawRoundedRectangle(padding.value / 2, y - (padding.value / 2), s + padding.value, s + padding.value, iconRadius.value, iconBg.value); renderScope.drawRoundedRectangle(padding / 2, y - (padding / 2), s + padding,
renderScope.drawTexture(component.sprite, padding.value, y, 0, 0, s, s, iconFg.value); s + padding, Theme.WIDGET_RADIUS.value, Theme.PRIMARY.value);
renderScope.drawTexture(component.sprite, padding, y, 0, 0, s, s, Theme.PRIMARY_FG.value);
topRow += 1; topRow += 1;
} }
@@ -122,21 +105,22 @@ public class Sidebar extends Element {
int bottomRow = 0; int bottomRow = 0;
int gap = 5; // same 5px gap here int gap = 5; // same 5px gap here
int sp = 30 - padding.value + gap; int padding = 10;
int s = 30 - (padding.value * 2); int sp = 30 - padding + gap;
int s2 = s + padding.value; int s = 30 - (padding * 2);
int s2 = s + padding;
for (SidebarComponent component : components) { for (SidebarComponent component : components) {
if (component.end) { if (component.end) {
int y = (height - (sp * bottomRow)) - (s * 2); int y = (height - (sp * bottomRow)) - (s * 2);
if (Utils.isHovering(mouseX - (padding.value / 2), mouseY - (y - (padding.value / 2)), s2, s2, scale)) { if (Utils.isHovering(mouseX - (padding / 2), mouseY - (y - (padding / 2)), s2, s2, scale)) {
component.onClick.run(); component.onClick.run();
break; break;
} }
bottomRow += 1; bottomRow += 1;
} else { } else {
int y = padding.value + (sp * topRow); int y = padding + (sp * topRow);
if (Utils.isHovering(mouseX - (padding.value / 2), mouseY - (y - (padding.value / 2)), s2, s2, scale)) { if (Utils.isHovering(mouseX - (padding / 2), mouseY - (y - (padding / 2)), s2, s2, scale)) {
component.onClick.run(); component.onClick.run();
break; break;
} }