Settings
Context menu
When a player right-clicks your module in the HUD editor, a context menu opens. Extend it by overriding getContextMenuSettings().
The six setting types
All six live in com.eymistaken.simplecps.api. Their constructors are on the HudModuleSetting reference.
BooleanSetting | An [ON] or [OFF] toggle. |
|---|---|
ColorSetting | A color swatch that opens the color picker. |
TextSetting | Shows the current value and opens an inline text field. |
CycleSetting | Steps through a fixed list of options on each click. |
ActionSetting | A plain button with no value. Since 1.2.5 it can tint its label, to mark a row that opens something rather than changing a value. |
SliderSetting | A draggable integer slider with a live value and a Reset button. Takes a minimum, a maximum and a default. |
All six in one menu
import com.eymistaken.simplecps.api.*;
import java.util.Arrays;
import java.util.List;
// Inside your MyCustomModule class:
@Override
public List<HudModuleSetting> getContextMenuSettings() {
List<HudModuleSetting> settings = new java.util.ArrayList<>(super.getContextMenuSettings());
// Toggle, shown as [ON] or [OFF]
settings.add(new BooleanSetting("Enable My Module",
() -> MyAddonConfig.enabled,
val -> { MyAddonConfig.enabled = val; MyAddonConfig.save(); }
));
// Color, opens the color picker on click
settings.add(new ColorSetting("Text Color",
() -> MyAddonConfig.textColor,
color -> { MyAddonConfig.textColor = color; MyAddonConfig.save(); }
));
// Text, opens an inline field on click
settings.add(new TextSetting("Suffix Text",
() -> MyAddonConfig.suffix,
val -> { MyAddonConfig.suffix = val; MyAddonConfig.save(); }
));
// Cycle, clicks through the options
settings.add(new CycleSetting("Display Mode",
Arrays.asList("Compact", "Full", "Minimal"),
() -> MyAddonConfig.displayModeIndex,
idx -> { MyAddonConfig.displayModeIndex = idx; MyAddonConfig.save(); }
));
// Action, a plain button with no value
settings.add(new ActionSetting("Reset My Settings", () -> {
MyAddonConfig.resetVisuals();
MyAddonConfig.save();
}));
// Slider, an integer range with a Reset button
settings.add(new SliderSetting("Scale %",
50, 300, 100,
() -> MyAddonConfig.scale,
val -> { MyAddonConfig.scale = val; MyAddonConfig.save(); }
));
return settings;
}Keep the super call. Calling super.getContextMenuSettings() and copying it into a new ArrayList keeps the default Reset Settings row at the top of the menu. Leave it out only to replace that row on purpose. Reset Position is there either way: the editor adds it, not getContextMenuSettings().
What Reset Settings does
Override resetVisualDefaults() to define it for your module. Reset visual and behavioral fields, and leave the enabled state and the offsets to the player. If your module treats scale as a visual preference it is safe to reset it here, as the built-in modules do.
@Override
public void resetVisualDefaults() {
MyAddonConfig.textColor = 0xFFFFFF;
MyAddonConfig.suffix = "";
MyAddonConfig.displayModeIndex = 0;
MyAddonConfig.scale = 100;
MyAddonConfig.save();
}**Never reset enabled, the anchor or the offsets here.** Position belongs to Reset Position, and whether the module is on is always the player's choice.