Game.UI.Menu.AutomaticSettings
Assembly:
Namespace: Game.UI.Menu
Type: static class
Base: System.Object
Summary:
AutomaticSettings is a reflection-driven helper used by the Options/Settings UI to automatically build settings pages for Setting-derived objects. It inspects a Setting instance's public properties and the various SettingsUI* attributes (e.g., SettingsUIDropdownAttribute, SettingsUISliderAttribute, SettingsUIButtonAttribute, SettingsUISectionAttribute, etc.) to produce a structured SettingPageData containing tabs, sections and IWidget-backed option entries. It also contains helpers to build concrete widget instances (ToggleField, DropdownField
Fields
-
private static readonly MethodInfo s_CustomDropdownMethodInfo
Holds a MethodInfo reference to the generic factory method AddCustomDropdownPropertyGeneric. Used to create custom dropdown widgets via reflection for arbitrary IJsonWritable/IJsonReadable value types. -
private static readonly MethodInfo s_EnumSetterMethodInfo
Holds a MethodInfo reference to the generic enum setter wrapper GetSetterActionGeneric. Used to wrap typed enum Action setter delegates into a common Action form required by Enum UI fields. -
private static readonly Dictionary<string, ButtonRow> s_ButtonGroups
Internal cache/dictionary that groups Button instances into ButtonRow widgets (so multiple [UIButton]-annotated properties with the same group produce a single ButtonRow). Cleared when building a page.
Properties
- (No public properties on AutomaticSettings itself)
The class exposes nested types (SettingPageData, SettingTabData, SettingItemData, IProxyProperty, ProxyProperty, ManualProperty, DropdownItemsAccessor) that have their own properties; see nested type descriptions below.
Constructors
static AutomaticSettings()
Static constructor. Initializes reflection MethodInfo references (s_CustomDropdownMethodInfo and s_EnumSetterMethodInfo) and the s_ButtonGroups dictionary. Ensures reflection helpers are ready before any other static methods run.
Methods
Note: The class exposes many public static methods used by the options system; below are the most important ones and a brief description of their behavior.
-
public static SettingPageData FillSettingsPage(Setting setting, string id, bool addPrefix)
Scans the provided Setting instance's public properties and attributes, constructs and returns a SettingPageData describing tabs, sections and items for the UI. Respects attributes for tab/group ordering, page-level warnings, button grouping, and show-group-name settings. Returns null if setting is null. -
public static void FillSettingsPage(SettingPageData pageData, Setting setting)
Fills an existing SettingPageData instance using reflection over the Setting instance. Called internally by the above overload (and can be used directly to fill an already-created page data). -
public static bool TryGetAction<T>(Setting setting, Type type, string name, out Func<T> action)
Reflection helper that tries to find a static or instance (when type is instance-of setting) method or property named name that returns T and takes no parameters. Produces a delegate Func. -
public static WidgetType GetWidgetType(IProxyProperty property)
Given a property (IProxyProperty), decides the widget type (WidgetType enum) the UI should use based on property type (bool, int, float, string, LocalizedString, ProxyBinding, enum, custom) and presence of SettingsUI* attributes (SettingsUIButtonAttribute, SettingsUIDropdownAttribute, SettingsUISliderAttribute, SettingsUITextInputAttribute, etc.). Returns WidgetType.None if no supported widget exists. -
public static LocalizedString GetConfirmationMessage(SettingItemData itemData)
Builds the confirmation LocalizedString for a SettingsUIButton with confirmation, using SettingsUIConfirmationAttribute values or falling back to a generated Options.WARNING[...] id. -
Button/group helper:
-
private static bool GetButtonsGroup(string groupName, out ButtonRow buttons, Button item)
Adds item to ButtonRow for groupName or creates a new ButtonRow if needed. Used to combine multiple button properties into a single UI row. -
Platform / visibility checks:
private static bool IsHidden(IProxyProperty property)
Checks SettingsUIHiddenAttribute.private static bool IsSupportedOnPlatform(IProxyProperty property)
Uses SettingsUIPlatformAttribute to determine platform availability.-
private static bool IsDeveloperOnly(IProxyProperty property)
Skips developer-only properties unless GameManager.instance.configuration.developerMode == true. -
Sectioning:
-
private static Dictionary<string, SectionInfo> GetSections(IProxyProperty property)
Reads SettingsUISectionAttribute(s) on a property (or on the declaring type) and returns mapping tab -> SectionInfo (tab name, simpleGroup, advancedGroup). Falls back to a default "General" tab. -
Dropdown and enum helpers:
private static DropdownItemsAccessor<DropdownItem<T>[]> GetDropdownItemAccessor<T>(IProxyProperty property, Setting setting)
If SettingsUIDropdownAttribute points to an items-getter, wraps that getter into a DropdownItemsAccessor.private static DelegateAccessor<EnumMember[]> GetEnumMemberAccessor(IProxyProperty property, Setting setting, string prefix)
Either uses a SettingsUIDropdownAttribute-provided items getter (returning EnumMember[]) or builds EnumMember[] via GetEnumValues.-
public static EnumMember[] GetEnumValues(Type enumType, string prefix)
Builds EnumMember entries (value + localized id string) for all enum values except those annotated with SettingsUIHiddenAttribute. Supports all common enum underlying integer types. -
Enum value conversion / setters:
private static Func<ulong> GetEnumGetter(SettingItemData itemData)
Returns a conversion function that reads the enum and returns its underlying unsigned (ulong) numeric representation.private static Action<ulong> GetEnumSetter(SettingItemData itemData)
Returns an Actionthat converts and sets the enum value on the underlying property (handles all common underlying integer types). private static Action<ulong> GetEnumCustomSetterAction(SettingItemData itemData)
If a custom typed setter delegate was provided, returns an Actionadapter that forwards to it (handles Action , Action , and basic numeric typed actions). -
private static Action<ulong> GetSetterActionGeneric<T>(SettingItemData itemData) where T : Enum
Generic helper that wraps Actioninto Action using Enum.ToObject for the underlying type T. -
Widget factory methods (create concrete IWidget instances from SettingItemData):
public static IWidget AddBoolButtonWithConfirmationProperty(SettingItemData itemData)
Creates ButtonWithConfirmation or groups it into ButtonRow.public static IWidget AddBoolToggleProperty(SettingItemData itemData)
Creates ToggleField for bool read/write properties; uses DelegateAccessorto read/write and calls setting.ApplyAndSave() after changes. public static IWidget AddBoolButtonProperty(SettingItemData itemData)
Creates Button or groups into ButtonRow for write-only bools or button style properties.public static IWidget AddIntDropdownProperty(SettingItemData itemData)
Creates DropdownFieldusing itemsAccessor from SettingsUIDropdownAttribute. public static IWidget AddIntSliderProperty(SettingItemData itemData)
Creates IntSliderField using SettingsUISliderAttribute parameters; supports scalarMultiplier and custom formatting.public static IWidget AddFloatSliderProperty(SettingItemData itemData)
Creates FloatSliderField using SettingsUISliderAttribute parameters; supports custom formatting.public static IWidget AddStringTextInputProperty(SettingItemData itemData)
Creates StringInputField for text input.public static IWidget AddStringDropdownProperty(SettingItemData itemData)
Creates DropdownField. public static IWidget AddStringFieldProperty(SettingItemData itemData)
Creates LocalizedValueField read-only string display.public static IWidget AddLocalizedStringFieldProperty(SettingItemData itemData)
Creates LocalizedValueField for LocalizedString read-only properties.public static IWidget AddEnumDropdownProperty(SettingItemData itemData)
Creates DropdownFieldfor enums when a dropdown attribute is used. public static IWidget AddEnumSimpleProperty(SettingItemData itemData)
Creates EnumField (numeric-backed) using GetEnumGetter/GetEnumSetter and EnumMember items.public static IWidget AddKeyBindingProperty(SettingItemData itemData)
Creates InputBindingField and uses InputManager to watch/update bindings. Uses actionVersion to reflect input changes.public static IWidget AddDirectoryPickerBindingProperty(SettingItemData itemData)
Creates DirectoryPickerField; uses OptionsUISystem.OpenDirectoryBrowser to allow picking folder and store choice.public static IWidget AddCustomDropdownProperty(SettingItemData itemData)
For properties annotated with SettingsUIDropdownAttribute whose type implements IJsonWritable & IJsonReadable and is value-type-or-has-parameterless-constructor, invokes AddCustomDropdownPropertyGenericthrough reflection. -
public static IWidget AddCustomDropdownPropertyGeneric<T>(SettingItemData itemData) where T : IJsonWritable, IJsonReadable, new()
Creates DropdownFieldwith ValueWriter and ValueReader (JSON read/write) and appropriate accessor and items accessor. -
Page warnings / groups:
private static bool IsShowGroupName(Setting setting, out bool showAll, out ReadOnlyCollection<string> groups)
Reads SettingsUIShowGroupNameAttribute on the setting type to determine whether group names should be shown and which groups.private static Func<bool> GetWarningGetter(Setting setting)
Reads SettingsUIPageWarningAttribute to get a page-level warning check delegate.private static Dictionary<string, Func<bool>> GetTabWarningGetters(Setting setting)
Reads SettingsUITabWarningAttribute attributes to get tab-level warning predicates.
(This file contains many more small helpers and overloads — the above list summarizes the primary, public and commonly-used internal helpers.)
Nested types (brief)
-
enum WidgetType
Describes the kind of widget to generate for a property: None, BoolButton, BoolButtonWithConfirmation, BoolToggle, IntDropdown, IntSlider, FloatSlider, StringDropdown, StringField, StringTextInput, LocalizedStringField, AdvancedEnumDropdown, EnumDropdown, KeyBinding, DirectoryPicker, MultilineText, CustomDropdown. -
class SettingPageData
Represents a page: id, prefix setting, tab/group ordering, a collection of SettingTabData, showGroupName controls, warningGetter and tabWarningGetters. Has BuildPage() to produce an OptionsUISystem.Page. -
class SettingTabData
Represents a tab within a page. Holds a list of SettingItemData, can build an OptionsUISystem.Section via BuildTab. -
class SettingItemData
Represents a single setting/property to be shown: stores widgetType, Setting reference, IProxyProperty, prefix, path, localized displayName/description (and dynamic delegates), disable/hide actions, value version action, setterAction, isAdvanced, and lazy-creates the IWidget for the item via GetWidget(). -
interface IProxyProperty
Abstraction over a reflected property: canRead/canWrite, name, propertyType, declaringType, GetValue/SetValue and attribute helpers. Used so code can operate uniformly on PropertyInfo-backed or manually-created properties. -
class ProxyProperty : IProxyProperty
Adapter for System.Reflection.PropertyInfo. -
class ManualProperty : IProxyProperty
A manually-created property description with getter/setter delegates and attribute list; useful for dynamically synthesized items. -
class DropdownItemsAccessor
: ITypedValueAccessor , IValueAccessor
Wraps a Funcgetter to satisfy dropdown item accessors. Throws if setter is attempted (readonly).
Usage Example
// Example: build an options page for a Setting-derived instance and register it with the options system.
Setting mySetting = MyModSettings.instance; // any Setting-derived instance
var pageData = AutomaticSettings.FillSettingsPage(mySetting, "MyMod.Options", addPrefix: true);
if (pageData != null)
{
// Build an OptionsUISystem.Page that the Options UI can show
var page = pageData.BuildPage();
// Example: register or open the page via OptionsUISystem (pseudo-code, actual registration depends on the game UI entry points)
World.DefaultGameObjectInjectionWorld?.GetOrCreateSystemManaged<OptionsUISystem>().RegisterPage(page);
}
Additional notes:
- The automatic generation relies heavily on a set of SettingsUI* attributes placed on properties (or declaring types) to control layout, grouping, dropdown sources, sliders bounds, button grouping, visibility, platform support, developer-only exposure, warnings and custom setter/dynamic display text.
- When a widget writes a value, Setting.ApplyAndSave() is called after setter invocation to persist and apply the change.
- Custom dropdowns require the property type to implement both IJsonWritable and IJsonReadable and either be a value type or have a parameterless constructor; the items getter must return DropdownItem