Files
MiraAPI/MiraAPI/GameOptions/AbstractOptionGroup.cs
T
2026-10-17 15:52:53 -04:00

211 lines
7.0 KiB
C#

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Il2CppInterop.Runtime.Attributes;
using MiraAPI.Modifiers;
using MiraAPI.Roles;
using MiraAPI.Utilities;
using MiraAPI.Utilities.Assets;
using UnityEngine;
namespace MiraAPI.GameOptions;
/// <summary>
/// Base class for option groups. An option group is a collection of options that are displayed together in the options menu.
/// </summary>
public abstract class AbstractOptionGroup
{
internal List<IModdedOption> Options { get; } = [];
/// <summary>
/// Gets a list of the options which are a part of this group.
/// </summary>
public ReadOnlyCollection<IModdedOption> Children => new(Options);
/// <summary>
/// Gets the name of the group. Visible in options menu.
/// </summary>
public abstract string GroupName { get; }
/// <summary>
/// Gets the sprite of the group that is displayed in the match info guide.
/// </summary>
[HideFromIl2Cpp]
public virtual LoadableAsset<Sprite> Sprite => MiraAssets.IconSettings;
/// <summary>
/// Gets the Optionable type of the group.
/// </summary>
public virtual Type? OptionableType => null;
/// <summary>
/// Gets a value indicating whether the group should be shown in the modifiers menu.
/// </summary>
// Completed: make this not a boolean
[Obsolete("Use ParentMenu instead.", true)]
[SuppressMessage("Info Code Smell", "S1133:Deprecated code should be removed", Justification = "Retained.")]
public virtual bool ShowInModifiersMenu => false;
/// <summary>
/// Gets a value indicating which menu the group is in.
/// </summary>
public virtual MenuCategory ParentMenu => MenuCategory.Game;
/// <summary>
/// Gets the function that determines whether the group should be visible or not.
/// </summary>
public virtual Func<bool> GroupVisible => DelegateUtilities.AlwaysTrue;
/// <summary>
/// Gets a value indicating whether this group's options are shown in the Match Info Guide.
/// </summary>
public virtual bool ShowInMatchInfoGuide => ParentMenu is MenuCategory.Game;
/// <summary>
/// Gets the name title of the group when it is in the match info guide.
/// </summary>
public virtual string RoleGuideTitle => GroupName;
/// <summary>
/// Gets the key used to combine this group with other option groups on one Match Info Guide page.
/// Groups are combined only with groups from the same plugin that use the same non-empty key.
/// </summary>
public virtual string? MatchInfoGuidePageKey => null;
/// <summary>
/// Gets the title of the Match Info Guide page. For groups sharing a page key, the first
/// group in menu order supplies the page title.
/// </summary>
public virtual string MatchInfoGuidePageTitle => RoleGuideTitle;
/// <summary>
/// Gets the ordering priority of this Match Info Guide page. Lower values appear first
/// among pages with the same menu category and group priority. Groups sharing a page key
/// use the lowest page-order value among those groups.
/// </summary>
public virtual int MatchInfoGuidePageOrder => int.MaxValue;
/// <summary>
/// Gets the number of columns used to lay out options on this Match Info Guide page.
/// For a combined page, groups are placed into these columns. Values are limited to 1-6;
/// for groups sharing a page key, the first group in menu order supplies this value.
/// </summary>
public virtual int MatchInfoGuidePageColumns => 2;
/// <summary>
/// Gets the group <see cref="Color"/>. This is used to color the group in the options menu.
/// </summary>
public virtual Color GroupColor => MiraApiPlugin.DefaultHeaderColor;
/// <summary>
/// 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 <see langword="uint"/> value.
/// </summary>
public virtual uint GroupPriority => uint.MaxValue;
/// <summary>
/// Gets the default notification settings for the group.
/// </summary>
public virtual OptionNotifConfiguration Configuration => new(new Color(0.7333f, 0.7333f, 0.7333f, 1));
internal bool AllOptionsHidden { get; set; }
internal CategoryHeaderMasked? Header { get; set; }
internal bool Ready { get; set; }
}
/// <summary>
/// Base class for option groups. An option group is a collection of options that are displayed together in the options menu.
/// </summary>
/// <typeparam name="T">The type of the optionable that this group contains.</typeparam>
public abstract class AbstractOptionGroup<T> : AbstractOptionGroup
where T : IOptionable
{
/// <inheritdoc />
public override Type OptionableType => typeof(T);
/// <inheritdoc />
public override MenuCategory ParentMenu
{
get
{
var type = typeof(T);
if (typeof(BaseModifier).IsAssignableFrom(type))
{
return MenuCategory.Modifiers;
}
else if (typeof(RoleBehaviour).IsAssignableFrom(type))
{
return MenuCategory.Roles;
}
return MenuCategory.Game;
}
}
}
/// <summary>
/// Base class for option groups. An option group is a collection of options that are displayed together in the options menu.
/// </summary>
/// <typeparam name="T">The custom role that the group is for.</typeparam>
public abstract class AbstractRoleOptionGroup<T> : AbstractOptionGroup<T>
where T : ICustomRole
{
/// <inheritdoc />
public override Type OptionableType => typeof(T);
/// <inheritdoc />
public override MenuCategory ParentMenu => MenuCategory.Roles;
/// <inheritdoc />
public override OptionNotifConfiguration Configuration
{
get
{
var role = CustomRoleManager.CustomMiraRoles.FirstOrDefault(x => x.GetType() == OptionableType);
return role == null
? new(new Color(0.7333f, 0.7333f, 0.7333f, 1))
: new(role.RoleColor, role.Configuration.IconTmp);
}
}
}
/// <summary>
/// Menu categories for option groups.
/// </summary>
public enum MenuCategory
{
/// <summary>
/// Placeholder for indexing purposes. Options don't exist in the preset tab.
/// </summary>
Preset,
/// <summary>
/// Determines the option group is in the game settings tab.
/// </summary>
Game,
/// <summary>
/// Determines the option group is in the role settings tab.
/// </summary>
Roles,
/// <summary>
/// Determines the option group is in the modifier settings tab.
/// </summary>
Modifiers,
/// <summary>
/// Determines the option group is in the first custom settings tab.
/// </summary>
CustomOne,
/// <summary>
/// Determines the option group is in the second custom settings tab.
/// </summary>
CustomTwo,
}