Skip to content
This repository has been archived by the owner on Oct 21, 2022. It is now read-only.

ModSettings

dani0105 edited this page Apr 13, 2022 · 2 revisions

ModSettings

Description

This class handles the Keybinding buttons in the settings menu. You can also load your configuration and store it.

This class can only be used in or after the load() method in your mod.

Events

There are not events for this class.

Properties

Name Description
main Main instance of ModSettings. Use this to load settings or add the Keybidings buttons.
TextPrefab This prefab is used to add text in the settings menu
SpacePrefab This prefab is used to add space in the settings menu
KeybindingPrefab This prefab is used to add keybinding buttons in the settings menu
KeybindingsHolder This transforms keep all keybiding buttons.

Public Methods

void addKeybinding( KeybindingsPC.Key key, KeybindingsPC.Key defaultKey, string name, SFSSettings modSettings);

This method adds simple hotkey buttons in the settings menu

  ModSettings.main.addKeybinding( MyLoadedSettings.My_Key, MyDefaultSettings.My_Key, "My_Key", MyLoadedSettings);

void addKeybinding( KeybindingsPC.Key[] key, KeybindingsPC.Key[] defaultKey, string name, SFSSettings modSettings);

This method adds multiple hotkey buttons in the settings menu

  ModSettings.main.addKeybinding( MyLoadedSettings.My_Key, MyDefaultSettings.My_Key, "My_Key", MyLoadedSettings);

static void addText( string text);

This method add text in the settings menu

  ModSettings.main.addText("My Text");

void resetKeybindings();

This function resets all mod keybindings

  ModSettings.main.resetKeybindings();

T loadSettings<T>( I_key key, Action action);

This method loads the mod's keybindings.

  MySettings currentSettings = ModSettings.main.loadSettings<MySettings>(MyMod);

Implementation Example

// My Main mod class
public class MyMod: SFSMod
{
  public static MyMod main;
  // My current mod settings.
  public MySettings mySettings;

  //                 ModID, Mod Name, Author, Mod Loader, Mod Version
  public MyMod() : base("myID","My Mod", "Me", "1.3.x", "v1.0.0")
  {
    main = this;
  }

  public override void load()
  {
    // Add Mod Name in settigs menu
    ModSettings.main.addText(this.Name);
    MySettings defaultKeys = new MySettings();
    this.mySettings = ModSettings.main.loadSettings<MySettings>(this); // load my settings
    ModSettings.main.addKeybinding(this.mySettings.MyKey, defaultKeys.MyKey, "My_key", this.mySettings);
  }
}

// My Settings class
public class MySettings : SFSSettings
{
  // key definition
  public KeybindingsPC.Key MyKey = KeyCode.T;

  public string getModId()
  {
      return MyMod.main.ModId;
  }
}