[Mod Util] Add Support for Save Storage Settings

Started by Kiame, June 29, 2017, 02:50:53 PM

Previous topic - Next topic


These are instructions for others who want to add support for Save Storage Settings to their mods. Specifically "Save Settings" and "Load Settings" buttons (gizmos) to save ThingFilters to a file.

The dll can be downloaded from here: https://github.com/KiameV/rimworld-SaveStorageSettings/releases/download/1.0util/SaveStorageSettingsUtil.zip

To integrate this mod:

  • Load the mod to which this will be added and in Visual Studio
  • Right click on the project's "References" and select "Add Reference..."
  • In the new window select "Browse" on the right and then "Browse..." button on the lower right and navigate to where the extracted SaveStorageSettingsUtil.dll is located. Verify the dll is checked and press "Ok"
  • Expand "References" and right click on "SaveStorageSettingsUtil" and select "Properties"
  • In the Properties window verify "Copy Local" is set to "True"
  • Open the .cs file for the object that extends Build_Storage and override the method GetGizmos with the following:

public override IEnumerable<Gizmo> GetGizmos()
      IEnumerable<Gizmo> enumerables = base.GetGizmos();

      return SaveStorageSettingsUtil.SaveStorageSettingsGizmoUtil.AddSaveLoadGizmos(
              enumerables, // The parent's returned gizmos
              "Custom_Mod",  // The location where saved settings will be located, specifically SaveStorageSettings/Custom_Mod in this case
              this.settings.filter); // The ThingFilters to save

Some additional notes:

  • The second argument is either a string or SaveTypeEnum. SaveTypeEnum has two values, Outfit_Manager and Zone_Stockpile.
    If the desire is to allow the user to save/load Outfits (for Outfit_Manager) or Storage (for Stockpiles) this Enum can be used. If the desire is to have a separate set of filters for the mod then use the string argument - preferably make the string the name of the mod if the mod's name is unique.

How it works
SaveStorageSettingsUtil will check the first time AddSaveLoadGizmos is called to see if the mod SaveStorageSettings. If the mod is installed (load order does not matter in game) the Save and Load gizmos will be added. If the mod is not installed, the buttons will not be added with nothing added to the logs.

SaveStorageSettingsUtil does have another public method Exists which returns True if the mod SaveStorageSettings is loaded in game. This may be helpful for Mod Settings maybe? I just thought i'd leave it public in case anyone could think of a reason it would be useful.