Mod Options Panel

From Cities: Skylines Wiki
Jump to navigation Jump to search

It is possible to add options in the Options panel for use in your own mods. The options panel should be used for custom settings for your mod. To enable your mod to be displayed in the Options panel, you need to implement the method OnSettingsUI() in your IUserMod class already describing your mod. (See below)

public class MyMod : IUserMod {
    public string Name { get { return "MyMod"; } }
    public string Description { get { return "My very own mod"; } }

    public void OnSettingsUI(UIHelperBase helper) {
        // Render UI elements using the UIHelperBase (see below)
    }
}

API Reference[edit]

UIHelperBase AddGroup(string text);
object AddButton(string text, OnButtonClicked eventCallback);
object AddSpace(int height);
object AddCheckbox(string text, bool defaultValue, OnCheckChanged eventCallback);
object AddSlider(string text, float min, float max, float step, float defaultValue, OnValueChanged eventCallback);
object AddDropdown(string text, string[] options, int defaultSelection, OnDropdownSelectionChanged eventCallback);
object AddTextfield(string text, string defaultContent, OnTextChanged eventChangedCallback, OnTextSubmitted eventSubmittedCallback = null);

Example[edit]

using ICities;
using UnityEngine;

public class MyMod : IUserMod {
    public string Name { get { return "MyMod"; } }
    public string Description { get { return "My very own mod"; } }

    public void OnSettingsUI(UIHelperBase helper) {
        UIHelperBase group = helper.AddGroup("My Own Group");
        group.AddCheckbox("My Checkbox", false, (isChecked) => Debug.Log(isChecked));
        group.AddSlider("My Slider", 0, 1, 0.01f, 0.5f, (value) => Debug.Log(value));
        group.AddDropdown("My Dropdown", new string[] { "First Entry", "Second Entry", "Third Entry" }, -1, (index) => Debug.Log(index));
        group.AddSpace(250);
        group.AddButton("My Button", () => { Debug.Log("Button clicked!"); });
        group.AddTextfield("My Textfield", "Default value", (value) => Debug.Log("text changed: " + value), (value) => Debug.Log("text submitted: " + value));
    }
}

See also[edit]