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 entry : mod.getConfig().getProperties().entrySet()) { if (!entry.getKey().equals(ENABLED)) { entry.getValue().reset(); } } init(); } }