Skip to content

Options Menu

Dan edited this page Jan 31, 2024 · 3 revisions

Implementing the GooeeSettings Class in Cities Skylines 2 Modding

Overview

The GooeeSettings class is an integral part of the Gooee UI framework, designed to facilitate the creation of in-game options menus in Cities Skylines 2 mods. This documentation provides a step-by-step guide on implementing the GooeeSettings class along with XML markup to create a customized settings interface for your mod.

Note

These settings automatically get saved into the games storage.

Step 1: Creating the Settings Class

Begin by extending the GooeeSettings class. This custom class will hold the settings for your mod. Below is an example implementation:

public class ExampleSettings : GooeeSettings
{
    [SettingsUIHidden]
    protected override string UIResource => "MyAssembly.Resources.settings.xml";

    public bool Test { get; set; }
    public bool AVal { get; set; }
    public bool BVal { get; set; }
    public bool CVal { get; set; }

    public ExampleSettings()
    {
    }

    public override void SetDefaults()
    {
        Test = true;
    }
}

Step 2: Defining the XML Markup

The XML file is crucial as it defines the UI layout for your settings. Each setting in the C# model corresponds to an element in the XML. Here's an example markup:

<?xml version="1.0" encoding="utf-8" ?>
<settings>
    <group title="General">
        <description>VersionNumber</description>
        <field title="Test">
            <checkbox isChecked="Test" />
            <button>ShowChangeLog</button>
        </field>
    </group>
    <group title="Another">
        <field title="AVal">
            <checkbox isChecked="AVal" />
        </field>
    </group>
    <tab title="Misc">
        <group title="Two">
            <field title="BVal">
                <checkbox isChecked="BVal" />
            </field>
        </group>
        <group title="Five">
            <field title="CVal">
                <checkbox isChecked="CVal" />
            </field>
        </group>
    </tab>
</settings>

Step 3: Understanding the XML Structure

  • <settings>: The root element.
  • <group>: Defines a group of settings.
  • <tab>: Organizes groups into tabs.
  • <field>: Represents an individual setting.
  • <checkbox>: A checkbox element, isChecked binds to a boolean property in the C# model.
  • <button>: A button element, can trigger actions or events.

Step 4: Binding C# Properties to XML

Ensure that the properties in your C# class match the isChecked attributes in the XML. For example, the Test property in the C# class corresponds to the <checkbox isChecked="Test" /> element in the XML.

Step 6: Editing plugin definition

You need to also edit your plugin definition to include IGooeeSettings and the new Settings property:

[ControllerTypes(typeof(ExampleController))]
[GooeeSettingsMenu(typeof(ExampleSettings))]
public class ExamplePlugin : IGooeePluginWithControllers, IGooeeSettings
{
    public string Name => "Example";
    public string ScriptResource => "MyAssembly.Resources.ui.js";

    public IController[] Controllers { get; set; }
    public GooeeSettings Settings { get; set; }
}

Step 5: Testing and Debugging

As this is an experimental feature, thorough testing is crucial. Check the integration of the settings within the game and ensure that the UI behaves as expected. Report any bugs or issues for further development and refinement.

Notes

  • The XML file must be correctly referenced in the UIResource property and MUST be an embedded resource in your assembly.
  • Ensure that the XML structure correctly represents the intended layout and functionality of your settings menu.
  • This framework is in the experimental phase; some features might not be fully implemented.

Conclusion

By following these steps, you can effectively implement the GooeeSettings class in your Cities Skylines 2 mod. This will enable you to create a dynamic and user-friendly settings interface, enhancing the overall experience of your mod. Keep an eye on updates and community feedback for continuous improvement of the framework.

Clone this wiki locally