Scroll kept its position as an int, so wheel and trackpad deltas were truncated: small ones were lost in one direction and a wheel notch moved one unit. It now keeps a fractional position, scrolls 24 units a notch, sizes and places its thumb consistently, and the thumb can be dragged or the track clicked. PanelScreen's scrollWidth and scrollContentWidth keep every scrolling list clear of the bar. Sliders read a float step from its text, so 0.1 no longer shows 17 decimals, and show at most three; number boxes show at most three too. Co-Authored-By: Claude Opus 5.5 <[email protected]>
98 lines
3.7 KiB
Java
98 lines
3.7 KiB
Java
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 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), scrollContentWidth(listWidth),
|
|
0);
|
|
draw(scroll.dimensions(scrollWidth(listWidth), 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();
|
|
}
|
|
}
|