Skip to content

1) Quick intro to ModSettings

Aaron C Robinson edited this page Nov 5, 2017 · 1 revision

RimWorld provides some functionality for each mod to collect settings from users. The two main objects we are exposed to achieve this are Mod and ModSettings.Mod provides an interface for where to display the window to the user (in the settings). ModSettings provides an object that can be utilized to track any settings/data you collect for a mod. A good example of this can be seen here in SeasonsalWeather which has two bools for tracking if the user wishes certain disasters to occur.

Let's look at the ModSettings:

public class SeasonalWeatherSettings : ModSettings
{
    public bool enableEarthquakes = true;
    public bool enableWildfires = true;

    public override void ExposeData()
    {
        base.ExposeData();
        Scribe_Values.Look(ref this.enableEarthquakes, "enableEarthquakes", true);
        Scribe_Values.Look(ref this.enableWildfires, "enableWildfires", true);
    }
}

Here we have the two bools and so that we can save this data, we have the ExposeData implemented.

Here is the base of the Mod:

class SeasonalWeatherMod : Mod
{
    public static SeasonalWeatherSettings settings;

    public SeasonalWeatherMod(ModContentPack content) : base(content)
    {
        settings = GetSettings<SeasonalWeatherSettings>();
    }

    public override string SettingsCategory() => "SeasonalWeatherSettingsCategoryLabel".Translate();

    public override void DoSettingsWindowContents(Rect inRect)
    {
        ...
    }
}

Settings now exposes our ModSettings as a public static giving use full use of it throughout the codebase and these settings are fetched when the mod is initialized. SettingsCategory allows us to set what our mod shows up as in the settings UI and the bulk of the UI for custom settings goes into DoSettingsWindowContents which is discussed in other sections.

Clone this wiki locally