Table of Contents

Class MenuAttribute

Namespace
Nautilus.Options.Attributes
Assembly
Nautilus.dll
Attribute used to signify a ModOptions menu should be automatically generated from a ConfigFile, as well as specifying options for handling the ConfigFile and ModOptions menu.
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false)]
public sealed class MenuAttribute : Attribute, _Attribute
Inheritance
MenuAttribute
Implements
Inherited Members
Extension Methods

Examples

using Nautilus.Json;
using Nautilus.Options;
using QModManager.Utility;
using UnityEngine;

[Menu("Nautilus Example Mod")]
public class Config : ConfigFile
{
    [Choice("My index-based choice", "Choice 1", "Choice 2", "Choice 3", Tooltip = "A simple tooltip")]
    [OnChange(nameof(MyGenericValueChangedEvent))]
    public int ChoiceIndex;

    [Choice("My enum-based choice"), OnChange(nameof(MyGenericValueChangedEvent))]
    public CustomChoice ChoiceEnum;

    [Keybind("My keybind"), OnChange(nameof(MyGenericValueChangedEvent))]
    public KeyCode KeybindKey;

    [Slider("My slider", 0, 50, DefaultValue = 25, Format = "{0:F2}"), OnChange(nameof(MyGenericValueChangedEvent))]
    public float SliderValue;

    [Toggle("My checkbox"), OnChange(nameof(MyCheckboxToggleEvent)), OnChange(nameof(MyGenericValueChangedEvent))]
    public bool ToggleValue;

    [Button("My button")]
    public void MyButtonClickEvent(ButtonClickedEventArgs e)
    {
        Logger.Log(Logger.Level.Info, "Button was clicked!");
        Logger.Log(Logger.Level.Info, $"{e.Id}");
    }

    public void MyCheckboxToggleEvent(ToggleChangedEventArgs e)
    {
        Logger.Log(Logger.Level.Info, "Checkbox value was changed!");
        Logger.Log(Logger.Level.Info, $"{e.Value}");
    }

    private void MyGenericValueChangedEvent(ModOptionEventArgs e)
    {
        Logger.Log(Logger.Level.Info, "Generic value changed!");
        Logger.Log(Logger.Level.Info, $"{e.Id}: {e.GetType()}");

        switch (e)
        {
            case KeybindChangedEventArgs keybindChangedEventArgs:
                Logger.Log(Logger.Level.Info, keybindChangedEventArgs.KeyName);
                break;
            case ChoiceChangedEventArgs choiceChangedEventArgs:
                Logger.Log(Logger.Level.Info, choiceChangedEventArgs.Value);
                break;
            case SliderChangedEventArgs sliderChangedEventArgs:
                Logger.Log(Logger.Level.Info, sliderChangedEventArgs.Value.ToString());
                break;
            case ToggleChangedEventArgs toggleChangedEventArgs:
                Logger.Log(Logger.Level.Info, toggleChangedEventArgs.Value.ToString());
                break;
        }
     }
}

Constructors

MenuAttribute(string)

Signifies a ModOptions menu should be automatically generated from a ConfigFile.
public MenuAttribute(string name)

Parameters

name string
The display name for the generated options menu.

Properties

LoadOn

The events after which the config file will be loaded from disk automatically. Defaults to MenuRegistered.
public MenuAttribute.LoadEvents LoadOn { get; set; }

Property Value

MenuAttribute.LoadEvents
See Also

MemberProcessing

How members of the ConfigFile will be processed. Defaults to Explicit, so that only public decorated members will be processed.
public MenuAttribute.Members MemberProcessing { get; set; }

Property Value

MenuAttribute.Members
See Also

Name

The display name for the generated options menu.
public string Name { get; }

Property Value

string

SaveOn

The events after which the config file will be saved to disk automatically. Defaults to ChangeValue.
public MenuAttribute.SaveEvents SaveOn { get; set; }

Property Value

MenuAttribute.SaveEvents
See Also

See Also