Redesign mod settings
A mod's settings button now opens ModSettings: a header with the mod's icon, name, version, tags and description, a Reset button and an on/off switch, then its properties as rows, with nested namespaces as titled sections and a live preview card beside them for HUD mods. PanelScreen holds the sidebar-and-panel frame that the mod menu, mod settings and config editor share. PropertyList lays out any config as rows. The inputs share one field look: Toggle is a switch, Select steps with arrows, and the number, keybinding and color inputs are boxes. The color picker opens to the left and closes on outside clicks. Every property type now implements reset(), which was a no-op, and ModLayout keeps its settings in order instead of Map.of's. ConfigEditor moves onto the same frame and rows and drops its HUD preview, which added a new element every frame. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -0,0 +1,97 @@
|
||||
package org.saturnclient.ui.screens;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.saturnclient.common.provider.Providers;
|
||||
import org.saturnclient.config.property.Property;
|
||||
import org.saturnclient.mod.HudMod;
|
||||
import org.saturnclient.mod.Mod;
|
||||
import org.saturnclient.ui.PanelScreen;
|
||||
import org.saturnclient.ui.components.HudPreviewCard;
|
||||
import org.saturnclient.ui.components.ModHeader;
|
||||
import org.saturnclient.ui.components.PropertyList;
|
||||
import org.saturnclient.ui.components.Sidebar;
|
||||
import org.saturnclient.ui.elements.ActionButton;
|
||||
import org.saturnclient.ui.elements.Divider;
|
||||
import org.saturnclient.ui.elements.Scroll;
|
||||
import org.saturnclient.ui.elements.SwitchButton;
|
||||
import org.saturnclient.ui.resources.Textures;
|
||||
|
||||
/**
|
||||
* One mod's settings: a header with the mod's details and its on/off switch,
|
||||
* the rest of its properties below, and a live preview for HUD mods.
|
||||
*/
|
||||
public class ModSettings extends PanelScreen {
|
||||
/**
|
||||
* Every mod's first property. It's shown as the header's switch, so the list
|
||||
* leaves it out.
|
||||
*/
|
||||
private static final String ENABLED = "Enabled";
|
||||
|
||||
private static final int HEADER_Y = 40;
|
||||
private static final int PREVIEW_WIDTH = 280;
|
||||
private static final int PREVIEW_MAX_HEIGHT = 220;
|
||||
private static final int COLUMN_GAP = 22;
|
||||
private static final int SCROLLBAR_SPACE = 14;
|
||||
|
||||
private final Mod mod;
|
||||
|
||||
public ModSettings(Mod mod) {
|
||||
super(mod.getName() + " Settings", Sidebar.MODS);
|
||||
this.mod = mod;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void panel() {
|
||||
draw(new ActionButton(Textures.ICON_CHEVRON_LEFT, "Mods", false,
|
||||
() -> Providers.saturn.getClient().setScreen(new ModMenu()))
|
||||
.position(contentX - 12, contentY - 4));
|
||||
|
||||
// Header: the mod's details, then Reset and the on/off switch on the right
|
||||
int headerY = contentY + HEADER_Y;
|
||||
|
||||
SwitchButton enabled = new SwitchButton("Enabled", "Disabled", mod::isEnabled,
|
||||
() -> mod.setEnabled(!mod.isEnabled()));
|
||||
int buttonY = headerY + (ModHeader.HEIGHT - enabled.height) / 2;
|
||||
draw(enabled.position(contentX + contentWidth - enabled.width, buttonY));
|
||||
|
||||
ActionButton reset = new ActionButton(Textures.ICON_RESET, "Reset", true, this::reset);
|
||||
draw(reset.position(enabled.x - 10 - reset.width, buttonY));
|
||||
|
||||
draw(new ModHeader(mod, reset.x - 16 - contentX).position(contentX, headerY));
|
||||
|
||||
int dividerY = headerY + ModHeader.HEIGHT + 16;
|
||||
draw(new Divider(contentWidth).position(contentX, dividerY));
|
||||
|
||||
// Body: the properties, with a preview beside them for HUD mods
|
||||
int bodyY = dividerY + 1;
|
||||
int bodyHeight = contentY + contentHeight - bodyY;
|
||||
int listWidth = contentWidth;
|
||||
|
||||
if (mod instanceof HudMod hudMod) {
|
||||
listWidth -= PREVIEW_WIDTH + COLUMN_GAP;
|
||||
draw(new HudPreviewCard(hudMod)
|
||||
.dimensions(PREVIEW_WIDTH, Math.min(PREVIEW_MAX_HEIGHT, bodyHeight - 16))
|
||||
.position(contentX + contentWidth - PREVIEW_WIDTH, bodyY + 16));
|
||||
}
|
||||
|
||||
Scroll scroll = new Scroll(0).noBackground();
|
||||
PropertyList.draw(scroll, mod.getConfig().getProperties(), Set.of(ENABLED), listWidth, 0);
|
||||
draw(scroll.dimensions(listWidth + SCROLLBAR_SPACE, bodyHeight).position(contentX, bodyY));
|
||||
}
|
||||
|
||||
/**
|
||||
* Puts every setting except the on/off switch back to its default, then
|
||||
* rebuilds the screen so the inputs show the new values.
|
||||
*/
|
||||
private void reset() {
|
||||
for (Map.Entry<String, Property> entry : mod.getConfig().getProperties().entrySet()) {
|
||||
if (!entry.getKey().equals(ENABLED)) {
|
||||
entry.getValue().reset();
|
||||
}
|
||||
}
|
||||
|
||||
init();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user