mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-11-19 13:17:10 +00:00
Merge branch 'dev' into no-boxing
This commit is contained in:
11 files changed
+138
-145
No files matched your search
@@ -105,6 +105,12 @@ dotnet_diagnostic.S1244.severity = none
|
||||
# S2325: Methods and properties that don't access instance data should be static
|
||||
dotnet_diagnostic.S2325.severity = none
|
||||
|
||||
# CA1710: Identifiers should have correct suffix
|
||||
dotnet_diagnostic.CA1710.severity = silent
|
||||
|
||||
# CA1010: Generic interface should also be implemented
|
||||
dotnet_diagnostic.CA1010.severity = silent
|
||||
|
||||
# IDE0005: Using directive is unnecessary.
|
||||
dotnet_diagnostic.IDE0005.severity = warning
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ public class ModdedEnumOptionListAttribute(string? title, Type enumType, string
|
||||
{
|
||||
}
|
||||
|
||||
internal override IModdedOptionList CreateOptionList(IList list, PropertyInfo property, AbstractOptionGroup group)
|
||||
internal override IBaseModdedOptionList CreateOptionList(IList list, PropertyInfo property, AbstractOptionGroup group)
|
||||
{
|
||||
var optList = new ModdedOptionList<ModdedEnumOption>(
|
||||
list.Count, idx => new(group.GroupPrefix, GetFormattedTitle(idx, property), (int)(list[idx] ?? 0), enumType, idPrefix, values));
|
||||
@@ -59,14 +59,14 @@ public class ModdedEnumOptionListAttribute(string? title, Type enumType, string
|
||||
/// <inheritdoc />
|
||||
public override void SetValue(int idx, object value)
|
||||
{
|
||||
var opt = HolderOptionList?[idx] as ModdedEnumOption;
|
||||
var opt = HolderOptionList?.ElementAt(idx) as ModdedEnumOption;
|
||||
opt?.SetValue((int)value);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override object GetValue(int idx)
|
||||
{
|
||||
return HolderOptionList?[idx] is ModdedEnumOption opt
|
||||
return HolderOptionList?.ElementAt(idx) is ModdedEnumOption opt
|
||||
? Enum.ToObject(enumType, opt.Value)
|
||||
: throw new InvalidOperationException($"HolderOption for option \"{Titles[idx]}\" is not a ModdedEnumOption with enum type {enumType.FullName}");
|
||||
}
|
||||
@@ -104,7 +104,7 @@ public class ModdedEnumOptionListAttribute<T>(string? title, string idPrefix, st
|
||||
{
|
||||
}
|
||||
|
||||
internal override IModdedOptionList CreateOptionList(IList list, PropertyInfo property, AbstractOptionGroup group)
|
||||
internal override IBaseModdedOptionList CreateOptionList(IList list, PropertyInfo property, AbstractOptionGroup group)
|
||||
{
|
||||
var optList = new ModdedOptionList<ModdedEnumOption<T>>(
|
||||
list.Count, idx => new(group.GroupPrefix, GetFormattedTitle(idx, property), (T)(list[idx] ?? 0), idPrefix, values));
|
||||
@@ -120,7 +120,7 @@ public class ModdedEnumOptionListAttribute<T>(string? title, string idPrefix, st
|
||||
/// <inheritdoc />
|
||||
public void SetValueUnboxed(int idx, T value)
|
||||
{
|
||||
(HolderOptionList?[idx] as ModdedEnumOption<T>)?.SetValue(value);
|
||||
(HolderOptionList?.ElementAt(idx) as ModdedEnumOption<T>)?.SetValue(value);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -132,7 +132,7 @@ public class ModdedEnumOptionListAttribute<T>(string? title, string idPrefix, st
|
||||
/// <inheritdoc />
|
||||
public T GetValueUnboxed(int idx)
|
||||
{
|
||||
return HolderOptionList?[idx] is ModdedEnumOption<T> opt
|
||||
return HolderOptionList?.ElementAt(idx) is ModdedEnumOption<T> opt
|
||||
? opt.Value
|
||||
: throw new InvalidOperationException($"HolderOption for option \"{Titles[idx]}\" is not a ModdedEnumOption<{typeof(T).FullName}>");
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ public class ModdedNumberOptionListAttribute(
|
||||
{
|
||||
}
|
||||
|
||||
internal override IModdedOptionList CreateOptionList(IList list, PropertyInfo property, AbstractOptionGroup group)
|
||||
internal override IBaseModdedOptionList CreateOptionList(IList list, PropertyInfo property, AbstractOptionGroup group)
|
||||
{
|
||||
return new ModdedOptionList<ModdedNumberOption>(list.Count, idx =>
|
||||
{
|
||||
@@ -126,7 +126,7 @@ public class ModdedNumberOptionListAttribute(
|
||||
/// <inheritdoc />
|
||||
public override void SetValue(int idx, object value)
|
||||
{
|
||||
if (HolderOptionList?[idx] is not ModdedNumberOption opt)
|
||||
if (HolderOptionList?.ElementAt(idx) is not ModdedNumberOption opt)
|
||||
return;
|
||||
|
||||
var final = value switch
|
||||
@@ -140,19 +140,19 @@ public class ModdedNumberOptionListAttribute(
|
||||
/// <inheritdoc />
|
||||
public void SetValueUnboxed(int idx, float value)
|
||||
{
|
||||
(HolderOptionList?[idx] as ModdedNumberOption)?.SetValue(value);
|
||||
(HolderOptionList?.ElementAt(idx) as ModdedNumberOption)?.SetValue(value);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
void ITypedOptionList<int>.SetValueUnboxed(int idx, int value)
|
||||
{
|
||||
(HolderOptionList?[idx] as ModdedNumberOption)?.SetValue(value);
|
||||
(HolderOptionList?.ElementAt(idx) as ModdedNumberOption)?.SetValue(value);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override object GetValue(int idx)
|
||||
{
|
||||
if (HolderOptionList?[idx] is not ModdedNumberOption opt)
|
||||
if (HolderOptionList?.ElementAt(idx) is not ModdedNumberOption opt)
|
||||
throw new InvalidOperationException($"HolderOption for option \"{Titles[idx]}\" is not a ModdedNumberOption");
|
||||
|
||||
var value = opt.Value;
|
||||
@@ -166,7 +166,7 @@ public class ModdedNumberOptionListAttribute(
|
||||
/// <inheritdoc />
|
||||
public float GetValueUnboxed(int idx)
|
||||
{
|
||||
return HolderOptionList?[idx] is ModdedNumberOption opt
|
||||
return HolderOptionList?.ElementAt(idx) is ModdedNumberOption opt
|
||||
? opt.Value
|
||||
: throw new InvalidOperationException($"HolderOption for option \"{Titles[idx]}\" is not a ModdedNumberOption");
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace MiraAPI.GameOptions.Attributes;
|
||||
[SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1401:Fields should be private", Justification = "Read above.")]
|
||||
public abstract class ModdedOptionListAttribute(string? title = null) : PropertyOptionAttribute
|
||||
{
|
||||
internal IModdedOptionList? HolderOptionList;
|
||||
internal IBaseModdedOptionList? HolderOptionList;
|
||||
internal IList? Value;
|
||||
internal Type ValueType;
|
||||
internal string[] Titles;
|
||||
@@ -73,7 +73,7 @@ public abstract class ModdedOptionListAttribute(string? title = null) : Property
|
||||
/// <returns>The value of the option as an object.</returns>
|
||||
public abstract object GetValue(int idx);
|
||||
|
||||
internal abstract IModdedOptionList? CreateOptionList(IList list, PropertyInfo property, AbstractOptionGroup group);
|
||||
internal abstract IBaseModdedOptionList? CreateOptionList(IList list, PropertyInfo property, AbstractOptionGroup group);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="Title"/> formatted with the option's index.
|
||||
|
||||
@@ -23,7 +23,7 @@ public class ModdedPlayerOptionListAttribute(string? title, bool allowNone = tru
|
||||
{
|
||||
}
|
||||
|
||||
internal override IModdedOptionList CreateOptionList(IList list, PropertyInfo property, AbstractOptionGroup group)
|
||||
internal override IBaseModdedOptionList CreateOptionList(IList list, PropertyInfo property, AbstractOptionGroup group)
|
||||
{
|
||||
return new ModdedOptionList<ModdedPlayerOption>(list.Count, idx => new(GetFormattedTitle(idx, property), allowNone));
|
||||
}
|
||||
@@ -31,7 +31,7 @@ public class ModdedPlayerOptionListAttribute(string? title, bool allowNone = tru
|
||||
/// <inheritdoc />
|
||||
public override void SetValue(int idx, object value)
|
||||
{
|
||||
if (HolderOptionList?[idx] is not ModdedPlayerOption opt)
|
||||
if (HolderOptionList?.ElementAt(idx) is not ModdedPlayerOption opt)
|
||||
return;
|
||||
|
||||
var final = value switch
|
||||
@@ -52,7 +52,7 @@ public class ModdedPlayerOptionListAttribute(string? title, bool allowNone = tru
|
||||
if (!value && !allowNone)
|
||||
throw new ArgumentException("Cannot assign null to a ModdedPlayerOption that does not allow none as an option.");
|
||||
|
||||
if (HolderOptionList?[idx] is ModdedPlayerOption opt)
|
||||
if (HolderOptionList?.ElementAt(idx) is ModdedPlayerOption opt)
|
||||
opt.SetValue(value ? opt.Values.IndexOf(value!) : -1);
|
||||
}
|
||||
|
||||
@@ -62,13 +62,13 @@ public class ModdedPlayerOptionListAttribute(string? title, bool allowNone = tru
|
||||
if (value == -1 && !allowNone)
|
||||
throw new ArgumentException("Cannot assign -1 to a ModdedPlayerOption that does not allow none as an option.");
|
||||
|
||||
(HolderOptionList?[idx] as ModdedPlayerOption)?.SetValue(value);
|
||||
(HolderOptionList?.ElementAt(idx) as ModdedPlayerOption)?.SetValue(value);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override object GetValue(int idx)
|
||||
{
|
||||
if (HolderOptionList?[idx] is not ModdedPlayerOption opt)
|
||||
if (HolderOptionList?.ElementAt(idx) is not ModdedPlayerOption opt)
|
||||
throw new InvalidOperationException($"HolderOption for option \"{Titles[idx]}\" is not a ModdedPlayerOption");
|
||||
|
||||
if (ValueType == typeof(int))
|
||||
@@ -80,7 +80,7 @@ public class ModdedPlayerOptionListAttribute(string? title, bool allowNone = tru
|
||||
/// <inheritdoc />
|
||||
public NetworkedPlayerInfo? GetValueUnboxed(int idx)
|
||||
{
|
||||
return HolderOptionList?[idx] is ModdedPlayerOption opt
|
||||
return HolderOptionList?.ElementAt(idx) is ModdedPlayerOption opt
|
||||
? opt.GetPlayerValue()
|
||||
: throw new InvalidOperationException($"HolderOption for option \"{Titles[idx]}\" is not a ModdedPlayerOption");
|
||||
}
|
||||
@@ -88,7 +88,7 @@ public class ModdedPlayerOptionListAttribute(string? title, bool allowNone = tru
|
||||
/// <inheritdoc />
|
||||
int ITypedOptionList<int>.GetValueUnboxed(int idx)
|
||||
{
|
||||
return HolderOptionList?[idx] is ModdedPlayerOption opt
|
||||
return HolderOptionList?.ElementAt(idx) is ModdedPlayerOption opt
|
||||
? opt.Value
|
||||
: throw new InvalidOperationException($"HolderOption for option \"{Titles[idx]}\" is not a ModdedPlayerOption");
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ public class ModdedStringOptionListAttribute(string? title, string[] values)
|
||||
{
|
||||
}
|
||||
|
||||
internal override IModdedOptionList CreateOptionList(IList list, PropertyInfo property, AbstractOptionGroup group)
|
||||
internal override IBaseModdedOptionList CreateOptionList(IList list, PropertyInfo property, AbstractOptionGroup group)
|
||||
{
|
||||
return new ModdedOptionList<ModdedStringOption>(list.Count, idx => new ModdedStringOption(group.GroupPrefix, GetFormattedTitle(idx, property), (string)(list[idx] ?? string.Empty), values));
|
||||
}
|
||||
@@ -37,7 +37,7 @@ public class ModdedStringOptionListAttribute(string? title, string[] values)
|
||||
/// <inheritdoc />
|
||||
public void SetValueUnboxed(int idx, string value)
|
||||
{
|
||||
(HolderOptionList?[idx] as ModdedStringOption)?.SetValue(value);
|
||||
(HolderOptionList?.ElementAt(idx) as ModdedStringOption)?.SetValue(value);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -49,7 +49,7 @@ public class ModdedStringOptionListAttribute(string? title, string[] values)
|
||||
/// <inheritdoc />
|
||||
public string GetValueUnboxed(int idx)
|
||||
{
|
||||
return HolderOptionList?[idx] is ModdedStringOption opt
|
||||
return HolderOptionList?.ElementAt(idx) is ModdedStringOption opt
|
||||
? opt.Value
|
||||
: throw new InvalidOperationException($"HolderOption for option \"{Titles[idx]}\" is not a ModdedStringOption");
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ public class ModdedToggleOptionListAttribute(string? title, string on, string of
|
||||
{
|
||||
}
|
||||
|
||||
internal override IModdedOptionList CreateOptionList(IList list, PropertyInfo property, AbstractOptionGroup group)
|
||||
internal override IBaseModdedOptionList CreateOptionList(IList list, PropertyInfo property, AbstractOptionGroup group)
|
||||
{
|
||||
var optList = new ModdedOptionList<ModdedToggleOption>(
|
||||
list.Count, idx => new(group.GroupPrefix, GetFormattedTitle(idx, property), (bool)(list[idx] ?? false), on, off));
|
||||
@@ -59,7 +59,7 @@ public class ModdedToggleOptionListAttribute(string? title, string on, string of
|
||||
/// <inheritdoc />
|
||||
public void SetValueUnboxed(int idx, bool value)
|
||||
{
|
||||
(HolderOptionList?[idx] as ModdedToggleOption)?.SetValue(value);
|
||||
(HolderOptionList?.ElementAt(idx) as ModdedToggleOption)?.SetValue(value);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -71,7 +71,7 @@ public class ModdedToggleOptionListAttribute(string? title, string on, string of
|
||||
/// <inheritdoc />
|
||||
public bool GetValueUnboxed(int idx)
|
||||
{
|
||||
return HolderOptionList?[idx] is ModdedToggleOption opt
|
||||
return HolderOptionList?.ElementAt(idx) is ModdedToggleOption opt
|
||||
? opt.Value
|
||||
: throw new InvalidOperationException($"Holder option \"{Titles[idx]}\" is not a ModdedToggleOption.");
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using BepInEx.Configuration;
|
||||
using MiraAPI.Networking;
|
||||
@@ -149,9 +150,11 @@ public interface IModdedOption
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Interface for list of modded options.
|
||||
/// Base interface for list of modded options.
|
||||
/// <para/>
|
||||
/// Do not implement directly, implement <see cref="IModdedOptionList"/> or <see cref="IModdedOptionList{T}"/> instead.
|
||||
/// </summary>
|
||||
public interface IModdedOptionList : IReadOnlyList<IModdedOption>
|
||||
public interface IBaseModdedOptionList : IEnumerable
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the function to name the keys of the individual options in the configuration file.
|
||||
@@ -159,18 +162,34 @@ public interface IModdedOptionList : IReadOnlyList<IModdedOption>
|
||||
/// Return <see langword="null"/> to use the default of the property's name with its index appended.
|
||||
/// </summary>
|
||||
Func<int, string>? ConfigName { get; init; }
|
||||
|
||||
/// <inheritdoc cref="IReadOnlyCollection{T}.Count"/>
|
||||
int Count { get; }
|
||||
|
||||
/// <inheritdoc cref="System.Linq.Enumerable.ElementAt{TSource}(IEnumerable{TSource}, int)"/>
|
||||
IModdedOption ElementAt(int index);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Interface for list of modded options.
|
||||
/// </summary>
|
||||
public interface IModdedOptionList : IBaseModdedOptionList, IReadOnlyList<IModdedOption>
|
||||
{
|
||||
IModdedOption IBaseModdedOptionList.ElementAt(int index)
|
||||
{
|
||||
return this[index];
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Interface for list of <typeparamref name="T"/> options.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of <see cref="IModdedOption"/>.</typeparam>
|
||||
public interface IModdedOptionList<out T> : IModdedOptionList
|
||||
public interface IModdedOptionList<out T> : IBaseModdedOptionList, IReadOnlyList<T>
|
||||
where T : IModdedOption
|
||||
{
|
||||
/// <inheritdoc cref="IReadOnlyList{T}.this[int]"/>
|
||||
new T this[int index] { get; }
|
||||
|
||||
/// <inheritdoc cref="IEnumerable{T}.GetEnumerator"/>
|
||||
new IEnumerator<T> GetEnumerator();
|
||||
IModdedOption IBaseModdedOptionList.ElementAt(int index)
|
||||
{
|
||||
return this[index];
|
||||
}
|
||||
}
|
||||
@@ -38,7 +38,7 @@ public static class ModdedOptionsManager
|
||||
private static readonly Dictionary<RuntimeTypeHandle, HarmonyMethod> ConcretisedSetters = [];
|
||||
|
||||
private static readonly Type OptionType = typeof(IModdedOption);
|
||||
private static readonly Type OptionListType = typeof(IModdedOptionList);
|
||||
private static readonly Type OptionListType = typeof(IBaseModdedOptionList);
|
||||
|
||||
internal static readonly Dictionary<Type, List<AbstractOptionGroup>> GameModeOptionGroups = [];
|
||||
internal static readonly Dictionary<uint, IModdedOption> ModdedOptions = [];
|
||||
@@ -151,7 +151,7 @@ public static class ModdedOptionsManager
|
||||
|
||||
foreach (var field in type.GetFields(MiraPluginManager.DeclaredInstanceMembers)
|
||||
.Where(f => !MiraPluginManager.IsAutoPropertyBackingField(f)
|
||||
&& (f.FieldType.IsAssignableTo(typeof(IModdedOption)) || f.FieldType.IsAssignableTo(typeof(IModdedOptionList)))))
|
||||
&& (f.FieldType.IsAssignableTo(typeof(IModdedOption)) || f.FieldType.IsAssignableTo(typeof(IBaseModdedOptionList)))))
|
||||
{
|
||||
Error($"{field.Name} is a field, not a property. Use properties for options.");
|
||||
}
|
||||
@@ -256,7 +256,7 @@ public static class ModdedOptionsManager
|
||||
MiraPluginInfo pluginInfo,
|
||||
AbstractOptionGroup group)
|
||||
{
|
||||
if (property.GetValue(group) is not IModdedOptionList optionList)
|
||||
if (property.GetValue(group) is not IBaseModdedOptionList optionList)
|
||||
{
|
||||
Error($"Failed to get option list for {property.Name}");
|
||||
return;
|
||||
@@ -266,7 +266,7 @@ public static class ModdedOptionsManager
|
||||
|
||||
for (var i = 0; i < optionList.Count; i++)
|
||||
{
|
||||
RegisterOption(type, optionList[i], group, configName(i), pluginInfo);
|
||||
RegisterOption(type, optionList.ElementAt(i), group, configName(i), pluginInfo);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -345,7 +345,7 @@ public static class ModdedOptionsManager
|
||||
|
||||
for (var i = 0; i < optionList.Count; i++)
|
||||
{
|
||||
var option = optionList[i];
|
||||
var option = optionList.ElementAt(i);
|
||||
|
||||
if (visibilityFactory != null)
|
||||
option.Visible = visibilityFactory(i) as Func<bool> ?? DelegateUtilities.AlwaysTrue;
|
||||
|
||||
@@ -51,9 +51,6 @@ public class ModdedOptionList<T> : IModdedOptionList<T>
|
||||
/// <returns>option of type <typeparamref name="T"/>.</returns>
|
||||
public T this[int idx] => Options[idx];
|
||||
|
||||
/// <inheritdoc cref="IReadOnlyList{T}.this"/>
|
||||
IModdedOption IReadOnlyList<IModdedOption>.this[int index] => this[index];
|
||||
|
||||
/// <inheritdoc cref="IEnumerable{T}.GetEnumerator"/>
|
||||
public IEnumerator<T> GetEnumerator()
|
||||
{
|
||||
@@ -65,10 +62,4 @@ public class ModdedOptionList<T> : IModdedOptionList<T>
|
||||
{
|
||||
return Options.GetEnumerator();
|
||||
}
|
||||
|
||||
/// <inheritdoc cref="IEnumerable{T}.GetEnumerator"/>
|
||||
IEnumerator<IModdedOption> IEnumerable<IModdedOption>.GetEnumerator()
|
||||
{
|
||||
return ((IEnumerable<IModdedOption>)Options).GetEnumerator();
|
||||
}
|
||||
}
|
||||
@@ -88,6 +88,8 @@ public static class RoleGuidePatches
|
||||
|
||||
private static bool IsModifiersTabActive => ActiveGuideTabIndex == ModifiersTabIndex;
|
||||
|
||||
private static readonly PropertyInfo? CaretYOffset = typeof(TextBoxTMP).GetProperty("caretYOffset", BindingFlags.Instance | BindingFlags.Public);
|
||||
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPriority(Priority.First)]
|
||||
[HarmonyPatch(typeof(MatchInfoGuide), nameof(MatchInfoGuide.CreateNormalModeSettings))]
|
||||
@@ -214,16 +216,6 @@ public static class RoleGuidePatches
|
||||
Coroutines.Start(CoPreload(__instance));
|
||||
}
|
||||
|
||||
public static void TriggerPreload(MatchInfoGuide instance)
|
||||
{
|
||||
if (!instance || _populate != null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Coroutines.Start(CoPreload(instance));
|
||||
}
|
||||
|
||||
private static IEnumerator CoPreload(MatchInfoGuide instance)
|
||||
{
|
||||
while (instance && (!HudManager.InstanceExists || !GameManager.Instance))
|
||||
@@ -765,8 +757,7 @@ public static class RoleGuidePatches
|
||||
modifier.ModifierCategoryTitle,
|
||||
modifier.ParentMod.MiraPlugin.GetAbbreviatedModName(),
|
||||
null,
|
||||
modifier,
|
||||
modifier.TypeId));
|
||||
modifier));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -802,8 +793,7 @@ public static class RoleGuidePatches
|
||||
roleBehaviour.GetCategoryTitle(),
|
||||
modId,
|
||||
roleBehaviour,
|
||||
null,
|
||||
(uint)roleBehaviour.Role));
|
||||
null));
|
||||
}
|
||||
|
||||
_roleEntriesMode = activeModeType;
|
||||
@@ -834,16 +824,14 @@ public static class RoleGuidePatches
|
||||
|
||||
private static float GetCaretYOffset(TextBoxTMP box)
|
||||
{
|
||||
if (CaretYOffset == null)
|
||||
{
|
||||
return 0f;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var prop = typeof(TextBoxTMP).GetProperty("caretYOffset", BindingFlags.Instance | BindingFlags.Public);
|
||||
|
||||
if (prop == null)
|
||||
{
|
||||
return 0f;
|
||||
}
|
||||
|
||||
return Convert.ToSingle(prop.GetValue(box), CultureInfo.InvariantCulture);
|
||||
return Convert.ToSingle(CaretYOffset.GetValue(box), CultureInfo.InvariantCulture);
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -960,14 +948,13 @@ public static class RoleGuidePatches
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class DetailedPanel(string title, string category, string modId, RoleBehaviour? role, GameModifier? modifier, uint typeId)
|
||||
private sealed class DetailedPanel(string title, string category, string modId, RoleBehaviour? role, GameModifier? modifier)
|
||||
{
|
||||
public string Title => title;
|
||||
public string Category => category;
|
||||
public string ModId => modId;
|
||||
public RoleBehaviour? Role => role;
|
||||
public GameModifier? Modifier => modifier;
|
||||
public uint TypeId => typeId;
|
||||
public MatchInfoRolePanel? Panel { get; set; }
|
||||
public int Amount { get; set; }
|
||||
public int Chance { get; set; }
|
||||
@@ -1004,12 +991,12 @@ public static class RoleGuidePatches
|
||||
|
||||
private static void UpdateSpinner()
|
||||
{
|
||||
if (_loadingSpinner != null)
|
||||
{
|
||||
_loadingSpinner.gameObject.SetActive(
|
||||
_loading && ActiveGuideTabIndex is RolesTabIndex or ModifiersTabIndex &&
|
||||
!(_wikiScroller && _wikiScroller.gameObject.activeSelf));
|
||||
}
|
||||
if (_loadingSpinner == null)
|
||||
return;
|
||||
|
||||
_loadingSpinner.gameObject.SetActive(
|
||||
_loading && ActiveGuideTabIndex is RolesTabIndex or ModifiersTabIndex &&
|
||||
!(_wikiScroller && _wikiScroller.gameObject.activeSelf));
|
||||
}
|
||||
|
||||
private static float GetGridScrollBounds(int count)
|
||||
@@ -1074,14 +1061,16 @@ public static class RoleGuidePatches
|
||||
foreach (var item in collection)
|
||||
{
|
||||
action(item);
|
||||
if (timer.ElapsedMilliseconds > budget)
|
||||
if (timer.ElapsedMilliseconds <= budget)
|
||||
{
|
||||
timer.Restart();
|
||||
yield return null;
|
||||
if (!_guide)
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
timer.Restart();
|
||||
yield return null;
|
||||
if (!_guide)
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1188,15 +1177,17 @@ public static class RoleGuidePatches
|
||||
{
|
||||
ComputeCounts(entry);
|
||||
entry.Visible = entry.CanShow && MatchesSearch(entry, searchText);
|
||||
if (entry.Panel)
|
||||
if (!entry.Panel)
|
||||
{
|
||||
dynamic entryType = entry.Modifier != null ? entry.Modifier : entry.Role!;
|
||||
var text = GetPanelCountText(entryType, entry.Amount, entry.Chance, entry.ModId);
|
||||
SetPanelCount(entry.Panel!, text);
|
||||
if (!entry.Visible && entry.Panel!.gameObject.activeSelf)
|
||||
{
|
||||
entry.Panel.gameObject.SetActive(false);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
dynamic entryType = entry.Modifier != null ? entry.Modifier : entry.Role!;
|
||||
var text = GetPanelCountText(entryType, entry.Amount, entry.Chance, entry.ModId);
|
||||
SetPanelCount(entry.Panel!, text);
|
||||
if (!entry.Visible && entry.Panel!.gameObject.activeSelf)
|
||||
{
|
||||
entry.Panel.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1244,7 +1235,6 @@ public static class RoleGuidePatches
|
||||
var activeModifiers = GetActiveModifiers();
|
||||
var comparisons = activeModifiers.Select(x => x.TypeId).ToList();
|
||||
comparisons.AddRange(GetActiveRoles().Select(x => (uint)x.Role));
|
||||
|
||||
return comparisons;
|
||||
}
|
||||
|
||||
@@ -1450,26 +1440,20 @@ public static class RoleGuidePatches
|
||||
{
|
||||
if (hover)
|
||||
{
|
||||
switch (value)
|
||||
return value switch
|
||||
{
|
||||
case SortingFilter.AllRoles:
|
||||
return MiraAssets.VisibleAllHoverSprite;
|
||||
case SortingFilter.DisabledOnly:
|
||||
return MiraAssets.VisibleOffHoverSprite;
|
||||
default:
|
||||
return MiraAssets.VisibleOnHoverSprite;
|
||||
}
|
||||
SortingFilter.AllRoles => MiraAssets.VisibleAllHoverSprite,
|
||||
SortingFilter.DisabledOnly => MiraAssets.VisibleOffHoverSprite,
|
||||
_ => MiraAssets.VisibleOnHoverSprite,
|
||||
};
|
||||
}
|
||||
|
||||
switch (value)
|
||||
return value switch
|
||||
{
|
||||
case SortingFilter.AllRoles:
|
||||
return MiraAssets.VisibleAllIdleSprite;
|
||||
case SortingFilter.DisabledOnly:
|
||||
return MiraAssets.VisibleOffIdleSprite;
|
||||
default:
|
||||
return MiraAssets.VisibleOnIdleSprite;
|
||||
}
|
||||
SortingFilter.AllRoles => MiraAssets.VisibleAllIdleSprite,
|
||||
SortingFilter.DisabledOnly => MiraAssets.VisibleOffIdleSprite,
|
||||
_ => MiraAssets.VisibleOnIdleSprite,
|
||||
};
|
||||
}
|
||||
|
||||
public static void SwitchMethod()
|
||||
@@ -1535,26 +1519,20 @@ public static class RoleGuidePatches
|
||||
{
|
||||
if (hover)
|
||||
{
|
||||
switch (value)
|
||||
return value switch
|
||||
{
|
||||
case SortingGroups.Faction:
|
||||
return MiraAssets.GroupFactionHoverSprite;
|
||||
case SortingGroups.AmountChance:
|
||||
return MiraAssets.GroupCountHoverSprite;
|
||||
default:
|
||||
return MiraAssets.GroupNoneHoverSprite;
|
||||
}
|
||||
SortingGroups.Faction => MiraAssets.GroupFactionHoverSprite,
|
||||
SortingGroups.AmountChance => MiraAssets.GroupCountHoverSprite,
|
||||
_ => MiraAssets.GroupNoneHoverSprite,
|
||||
};
|
||||
}
|
||||
|
||||
switch (value)
|
||||
return value switch
|
||||
{
|
||||
case SortingGroups.Faction:
|
||||
return MiraAssets.GroupFactionIdleSprite;
|
||||
case SortingGroups.AmountChance:
|
||||
return MiraAssets.GroupCountIdleSprite;
|
||||
default:
|
||||
return MiraAssets.GroupNoneIdleSprite;
|
||||
}
|
||||
SortingGroups.Faction => MiraAssets.GroupFactionIdleSprite,
|
||||
SortingGroups.AmountChance => MiraAssets.GroupCountIdleSprite,
|
||||
_ => MiraAssets.GroupNoneIdleSprite,
|
||||
};
|
||||
}
|
||||
|
||||
private static void CopyTextLayout(TextMeshPro source, TextMeshPro target)
|
||||
@@ -1597,7 +1575,7 @@ public static class RoleGuidePatches
|
||||
passiveButton.ClickSound = HudManager.Instance.MapButton.ClickSound;
|
||||
passiveButton.OnMouseOver = new UnityEvent();
|
||||
passiveButton.OnMouseOver.AddListener(
|
||||
(UnityAction)(() => { panel.roleIcon.color = new Color32(255, 255, 255, 150); }));
|
||||
(UnityAction)(() => panel.roleIcon.color = new Color32(255, 255, 255, 150)));
|
||||
passiveButton.OnMouseOut = new UnityEvent();
|
||||
passiveButton.OnMouseOut.AddListener((UnityAction)(() => { panel.roleIcon.color = Color.white; }));
|
||||
|
||||
@@ -1724,12 +1702,10 @@ public static class RoleGuidePatches
|
||||
var roles = GetActiveRoles().Shuffle().ToList();
|
||||
foreach (var role in roles)
|
||||
{
|
||||
if (role.RoleIconSolid == null)
|
||||
if (role.RoleIconSolid != null)
|
||||
{
|
||||
continue;
|
||||
return role.RoleIconSolid;
|
||||
}
|
||||
|
||||
return role.RoleIconSolid;
|
||||
}
|
||||
|
||||
return GetRandomFactionIcon();
|
||||
@@ -1920,7 +1896,7 @@ public static class RoleGuidePatches
|
||||
modId);
|
||||
}
|
||||
|
||||
private static string GetPanelCountText(BaseModifier modifier, int amount, int chance, string modId)
|
||||
private static string GetPanelCountText(GameModifier modifier, int amount, int chance, string modId)
|
||||
{
|
||||
return modifier.GetAmountText(amount, chance, modId);
|
||||
}
|
||||
@@ -2054,12 +2030,10 @@ public static class RoleGuidePatches
|
||||
|
||||
private static void EnterSettingsTab()
|
||||
{
|
||||
if (!_uiInitialized)
|
||||
if (_uiInitialized)
|
||||
{
|
||||
return;
|
||||
RefreshSettingsTab(true);
|
||||
}
|
||||
|
||||
RefreshSettingsTab(true);
|
||||
}
|
||||
|
||||
private static void LeaveSettingsTab()
|
||||
@@ -2285,16 +2259,19 @@ public static class RoleGuidePatches
|
||||
|
||||
private static void UpdateSettingsTitle()
|
||||
{
|
||||
if (_titleText && IsSettingsTabActive)
|
||||
if (!_titleText || !IsSettingsTabActive)
|
||||
{
|
||||
_titleText.text = GetSettingsTitle();
|
||||
if (_titleIcon)
|
||||
{
|
||||
_titleIcon.sprite = GetSettingsIcon();
|
||||
|
||||
_titleIcon.SetSizeLimit(0.55f);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
_titleText.text = GetSettingsTitle();
|
||||
if (!_titleIcon)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_titleIcon.sprite = GetSettingsIcon();
|
||||
_titleIcon.SetSizeLimit(0.55f);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in new issue
Block a user