mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-10-19 15:51:48 +00:00
MiraNumberSuffixes, and checkmark fix
This commit is contained in:
1 parent
9fb25542e7
commit
05fdf5313d
9 files changed
+86
-29
No files matched your search
@@ -1,5 +1,6 @@
|
||||
using MiraAPI.GameOptions;
|
||||
using MiraAPI.GameOptions.Attributes;
|
||||
using MiraAPI.Utilities;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI.Example.Options;
|
||||
@@ -15,7 +16,7 @@ public class ExampleOptions : AbstractOptionGroup
|
||||
[ModdedToggleOption("Toggle Opt 2")]
|
||||
public bool ToggleOpt2 { get; set; } = true;
|
||||
|
||||
[ModdedNumberOption("Number Opt", min: 0, max: 10)]
|
||||
[ModdedNumberOption("Number Opt", min: 0, max: 10, suffixType: MiraNumberSuffixes.Percent)]
|
||||
public float NumberOpt { get; set; } = 4f;
|
||||
|
||||
[ModdedStringOption("String Opt", ["Hello", "Hey", "Bye"])]
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using MiraAPI.GameOptions.OptionTypes;
|
||||
using MiraAPI.Utilities;
|
||||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
@@ -9,7 +10,7 @@ public class ModdedNumberOptionAttribute(
|
||||
float min,
|
||||
float max,
|
||||
float increment = 1,
|
||||
NumberSuffixes suffixType = NumberSuffixes.None,
|
||||
MiraNumberSuffixes suffixType = MiraNumberSuffixes.None,
|
||||
bool zeroInfinity = false,
|
||||
Type roleType = null)
|
||||
: ModdedOptionAttribute(title, roleType)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using System;
|
||||
using AmongUs.GameOptions;
|
||||
using AmongUs.GameOptions;
|
||||
using MiraAPI.Networking;
|
||||
using MiraAPI.Utilities;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
@@ -9,17 +9,17 @@ namespace MiraAPI.GameOptions.OptionTypes;
|
||||
|
||||
public class ModdedNumberOption : ModdedOption<float>
|
||||
{
|
||||
public float Min { get;}
|
||||
|
||||
public float Min { get; }
|
||||
|
||||
public float Max { get; }
|
||||
|
||||
|
||||
public float Increment { get; }
|
||||
|
||||
public NumberSuffixes SuffixType { get; }
|
||||
|
||||
|
||||
public MiraNumberSuffixes SuffixType { get; }
|
||||
|
||||
public bool ZeroInfinity { get; }
|
||||
|
||||
public ModdedNumberOption(string title, float defaultValue, float min, float max, float increment, NumberSuffixes suffixType, bool zeroInfinity=false, Type roleType=null) : base(title, defaultValue, roleType)
|
||||
|
||||
public ModdedNumberOption(string title, float defaultValue, float min, float max, float increment, MiraNumberSuffixes suffixType, bool zeroInfinity = false, Type roleType = null) : base(title, defaultValue, roleType)
|
||||
{
|
||||
Min = min;
|
||||
Max = max;
|
||||
@@ -28,18 +28,18 @@ public class ModdedNumberOption : ModdedOption<float>
|
||||
ZeroInfinity = zeroInfinity;
|
||||
|
||||
Value = Mathf.Clamp(defaultValue, min, max);
|
||||
|
||||
|
||||
Data = ScriptableObject.CreateInstance<FloatGameSetting>();
|
||||
|
||||
|
||||
var data = (FloatGameSetting)Data;
|
||||
data.Type = global::OptionTypes.Float;
|
||||
data.Title = StringName;
|
||||
data.Value = Value;
|
||||
data.Increment = Increment;
|
||||
data.ValidRange = new FloatRange(Min, Max);
|
||||
data.FormatString = Increment % 1 == 0 && Value % 1 == 0 && Min % 1 == 0 && Max % 1 == 0 ? "0" : "0.0";
|
||||
data.FormatString = Increment % 1 == 0 && Value % 1 == 0 && Min % 1 == 0 && Max % 1 == 0 ? "0" : "0.0";
|
||||
data.ZeroIsInfinity = ZeroInfinity;
|
||||
data.SuffixType = SuffixType;
|
||||
data.SuffixType = (NumberSuffixes)SuffixType;
|
||||
data.OptionName = FloatOptionNames.Invalid;
|
||||
}
|
||||
|
||||
@@ -49,17 +49,17 @@ public class ModdedNumberOption : ModdedOption<float>
|
||||
|
||||
numberOption.SetUpFromData(Data, 20);
|
||||
numberOption.OnValueChanged = (Il2CppSystem.Action<OptionBehaviour>)ValueChanged;
|
||||
|
||||
|
||||
numberOption.Title = StringName;
|
||||
numberOption.Value = Value;
|
||||
numberOption.Increment = Increment;
|
||||
numberOption.ValidRange = new FloatRange(Min, Max);
|
||||
numberOption.FormatString = ((FloatGameSetting)Data).FormatString;
|
||||
numberOption.ZeroIsInfinity = ZeroInfinity;
|
||||
numberOption.SuffixType = SuffixType;
|
||||
numberOption.SuffixType = (NumberSuffixes)SuffixType;
|
||||
numberOption.floatOptionName = FloatOptionNames.Invalid;
|
||||
|
||||
|
||||
|
||||
|
||||
OptionBehaviour = numberOption;
|
||||
|
||||
return numberOption;
|
||||
|
||||
@@ -3,7 +3,6 @@ using MiraAPI.Utilities;
|
||||
using MiraAPI.Utilities.Assets;
|
||||
using Reactor.Localization.Utilities;
|
||||
using Reactor.Utilities.Extensions;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
@@ -102,7 +101,7 @@ public static class GameOptionsMenuPatch
|
||||
|
||||
var options = group.Options.Select(opt => opt.CreateOption(__instance.checkboxOrigin,
|
||||
__instance.numberOptionOrigin, __instance.stringOptionOrigin, __instance.settingsContainer));
|
||||
|
||||
|
||||
foreach (var newOpt in options)
|
||||
{
|
||||
newOpt.SetClickMask(__instance.ButtonClickMask);
|
||||
@@ -137,10 +136,10 @@ public static class GameOptionsMenuPatch
|
||||
if (newOpt is ToggleOption toggle)
|
||||
{
|
||||
toggle.CheckMark.sprite = MiraAssets.Checkmark.LoadAsset();
|
||||
|
||||
toggle.CheckMark.color = group.GroupColor != Color.clear ? group.GroupColor : MiraAssets.AcceptedTeal;
|
||||
var rend = toggle.CheckMark.transform.parent.FindChild("ActiveSprite").GetComponent<SpriteRenderer>();
|
||||
rend.sprite = MiraAssets.CheckmarkBox.LoadAsset();
|
||||
rend.color = group.GroupColor;
|
||||
rend.color = group.GroupColor != Color.clear ? group.GroupColor : MiraAssets.AcceptedTeal;
|
||||
}
|
||||
|
||||
__instance.Children.Add(newOpt);
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
using HarmonyLib;
|
||||
using MiraAPI.Utilities;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI.Patches.Options;
|
||||
[HarmonyPatch]
|
||||
public class SettingPatches
|
||||
{
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(FloatGameSetting), nameof(FloatGameSetting.GetValueString))]
|
||||
public static bool ValueStringPatch(FloatGameSetting __instance, ref string __result, [HarmonyArgument(0)] float value)
|
||||
{
|
||||
string result = string.Empty;
|
||||
MiraNumberSuffixes suffix = (MiraNumberSuffixes)__instance.SuffixType;
|
||||
|
||||
if (__instance.ZeroIsInfinity && Mathf.Abs(value) < 0.0001f)
|
||||
{
|
||||
result = "<b>∞</b>";
|
||||
}
|
||||
else if (suffix == MiraNumberSuffixes.None)
|
||||
{
|
||||
result = value.ToString(__instance.FormatString);
|
||||
}
|
||||
else if (suffix == MiraNumberSuffixes.Multiplier)
|
||||
{
|
||||
result = value.ToString(__instance.FormatString) + "x";
|
||||
}
|
||||
else if (suffix == MiraNumberSuffixes.Percent)
|
||||
{
|
||||
result = value.ToString(__instance.FormatString) + "%";
|
||||
}
|
||||
else
|
||||
{
|
||||
result = DestroyableSingleton<TranslationController>.Instance.GetString(StringNames.GameSecondsAbbrev, (Il2CppSystem.Object[])(
|
||||
[
|
||||
value.ToString(__instance.FormatString)
|
||||
]));
|
||||
}
|
||||
__result = result;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 370 B After Width: | Height: | Size: 1.0 KiB |
@@ -1,4 +1,6 @@
|
||||
namespace MiraAPI.Utilities.Assets;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI.Utilities.Assets;
|
||||
|
||||
public static class MiraAssets
|
||||
{
|
||||
@@ -9,4 +11,7 @@ public static class MiraAssets
|
||||
public static readonly LoadableResourceAsset Cog = new("MiraAPI.Resources.Cog.png");
|
||||
public static readonly LoadableResourceAsset Checkmark = new("MiraAPI.Resources.Checkmark.png");
|
||||
public static readonly LoadableResourceAsset CheckmarkBox = new("MiraAPI.Resources.CheckMarkBox.png");
|
||||
|
||||
|
||||
public static readonly Color32 AcceptedTeal = new Color32(43, 233, 198, 255);
|
||||
}
|
||||
@@ -46,13 +46,14 @@ TextAlignmentOptions textAlignment = TextAlignmentOptions.Center)
|
||||
return Object.FindObjectsOfType<DeadBody>().FirstOrDefault(body => body.ParentId == id);
|
||||
}
|
||||
|
||||
public static string GetSuffix(NumberSuffixes suffix)
|
||||
public static string GetSuffix(MiraNumberSuffixes suffix)
|
||||
{
|
||||
return suffix switch
|
||||
{
|
||||
NumberSuffixes.None => string.Empty,
|
||||
NumberSuffixes.Multiplier => "x",
|
||||
NumberSuffixes.Seconds => "s",
|
||||
MiraNumberSuffixes.None => string.Empty,
|
||||
MiraNumberSuffixes.Multiplier => "x",
|
||||
MiraNumberSuffixes.Seconds => "s",
|
||||
MiraNumberSuffixes.Percent => "%",
|
||||
_ => string.Empty
|
||||
};
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace MiraAPI.Utilities;
|
||||
public enum MiraNumberSuffixes
|
||||
{
|
||||
None,
|
||||
Multiplier,
|
||||
Seconds,
|
||||
Percent
|
||||
}
|
||||
Reference in new issue
Block a user