Game.Settings.SettingsUIHideByConditionAttribute
Assembly:
Game (assembly containing Game.Settings)
Namespace:
Game.Settings
Type:
class
Base:
System.Attribute
Summary:
Attribute used to mark a settings UI class or individual property to be hidden based on a runtime condition. The attribute stores a Type that contains the check method and the name of the method to call. The condition result can be inverted by setting invert = true. The attribute itself only stores the metadata; the UI/system responsible for rendering settings must reflect over this attribute and invoke the specified method to decide whether to hide the target. The attribute is allowed on classes and properties and is inheritable (AttributeUsage: AttributeTargets.Class | AttributeTargets.Property, Inherited = true).
Fields
-
public readonly System.Type checkType
Type that contains the condition method. Typically this is a static helper or manager type that exposes a boolean method the UI code can call. -
public readonly string checkMethod
The name of the method on checkType to invoke. The method should return a bool indicating visibility (true = visible, false = hidden) unlessinvert
semantics are applied by the consumer. -
public readonly bool invert
If true, the boolean result of the check method should be inverted (i.e., hide when the method returns true). Default is false.
Properties
- This attribute exposes no properties. All configuration is via the readonly fields set by its constructors.
Constructors
-
public SettingsUIHideByConditionAttribute(System.Type checkType, string checkMethod)
Creates the attribute with the provided type and method name.invert
defaults to false. -
public SettingsUIHideByConditionAttribute(System.Type checkType, string checkMethod, bool invert)
Creates the attribute and sets whether the check result should be inverted.
Methods
- This attribute does not declare any methods beyond what it inherits from System.Attribute. The runtime UI code that enforces hiding must reflectively locate and invoke the specified method on the provided type.
Usage Example
// Example condition provider
public static class SettingsConditions
{
// Should be public and accessible to the UI reflection code.
public static bool IsAdvancedMode() => GameManager.Options.AdvancedModeEnabled;
}
// Hide an entire settings class when advanced mode is disabled
[SettingsUIHideByCondition(typeof(SettingsConditions), nameof(SettingsConditions.IsAdvancedMode))]
public class AdvancedFeatureSettings
{
// All settings here would be hidden unless IsAdvancedMode() returns true.
}
// Hide a single property, inverting the check so the property is shown when the method is false
public class GeneralSettings
{
[SettingsUIHideByCondition(typeof(SettingsConditions), nameof(SettingsConditions.IsAdvancedMode), invert: true)]
public bool SimpleOption { get; set; }
}
Notes:
- The attribute only stores the metadata. A UI renderer or settings system must reflect on the attribute, call the target method (commonly a public static bool with no parameters) and apply the invert
flag when deciding to hide/show the element.
- Ensure the check method is accessible (visibility and static vs instance semantics) to whatever reflection/invocation code is used by your mod or the game's UI system.