From f83dce99ef5ec69527ee5e2263a70c86517afca6 Mon Sep 17 00:00:00 2001 From: XtraCube <72575280+XtraCube@users.noreply.github.com> Date: Tue, 3 Sep 2024 20:59:26 -0400 Subject: [PATCH] add group priorities for ordering groups --- MiraAPI.Example/Options/ExampleOptions2.cs | 2 ++ MiraAPI/GameOptions/AbstractOptionGroup.cs | 6 ++++++ MiraAPI/PluginLoading/MiraPluginManager.cs | 2 ++ 3 files changed, 10 insertions(+) diff --git a/MiraAPI.Example/Options/ExampleOptions2.cs b/MiraAPI.Example/Options/ExampleOptions2.cs index c521ea8..56dd209 100644 --- a/MiraAPI.Example/Options/ExampleOptions2.cs +++ b/MiraAPI.Example/Options/ExampleOptions2.cs @@ -8,6 +8,8 @@ public class ExampleOptions2 : AbstractOptionGroup { public override string GroupName => "Example Options 2"; + public override uint GroupPriority => 0; // This group will be displayed first. The default value is uint.MaxValue. + public ModdedToggleOption ToggleOpt1 { get; } = new("Toggle Option 1", false); public ModdedToggleOption ToggleOpt2 { get; } = new("Toggle Option 2", false) diff --git a/MiraAPI/GameOptions/AbstractOptionGroup.cs b/MiraAPI/GameOptions/AbstractOptionGroup.cs index aeae257..418f25b 100644 --- a/MiraAPI/GameOptions/AbstractOptionGroup.cs +++ b/MiraAPI/GameOptions/AbstractOptionGroup.cs @@ -26,6 +26,12 @@ public abstract class AbstractOptionGroup /// public virtual Color GroupColor => Color.clear; + /// + /// Gets the group priority. This is used to determine the order in which groups are displayed in the options menu. + /// Zero is the highest priority, and the default value is the max uint value. + /// + public virtual uint GroupPriority => uint.MaxValue; + /// /// Gets the role the group is associated with. This is used for the advanced role options menu. /// diff --git a/MiraAPI/PluginLoading/MiraPluginManager.cs b/MiraAPI/PluginLoading/MiraPluginManager.cs index 423cb09..2a735b8 100644 --- a/MiraAPI/PluginLoading/MiraPluginManager.cs +++ b/MiraAPI/PluginLoading/MiraPluginManager.cs @@ -83,6 +83,8 @@ private static void RegisterAllOptions(Assembly assembly, MiraPluginInfo pluginI ModdedOptionsManager.RegisterAttributeOption(type, attribute, property, pluginInfo); } } + + pluginInfo.OptionGroups.Sort((x, y) => x.GroupPriority.CompareTo(y.GroupPriority)); } private static void RegisterRoleAttribute(Assembly assembly, MiraPluginInfo pluginInfo)