fixed UI bug + make rounding a consistent behaviour

had accidentally deleted some patches somehow
This commit is contained in:
Az committed 2026-11-15 02:39:27 -05:00
1 parent 9fbbfde047
commit 6e91781e4c
10 files changed
+93 -24

No files matched your search

@@ -156,7 +156,7 @@ public class ModdedNumberOptionAttribute(
var value = opt.Value;
if (ValueType == typeof(int))
return (int)MathF.Round(value);
return (int)MathF.Round(value, MidpointRounding.AwayFromZero);
return value;
}
@@ -172,6 +172,6 @@ public class ModdedNumberOptionAttribute(
/// <inheritdoc />
int ITypedOption<int>.GetValueUnboxed()
{
return (int)MathF.Round(GetValueUnboxed());
return (int)MathF.Round(GetValueUnboxed(), MidpointRounding.AwayFromZero);
}
}
@@ -158,7 +158,7 @@ public class ModdedNumberOptionListAttribute(
var value = opt.Value;
if (ValueType == typeof(int))
return (int)MathF.Round(value);
return (int)MathF.Round(value, MidpointRounding.AwayFromZero);
return value;
}
@@ -174,6 +174,6 @@ public class ModdedNumberOptionListAttribute(
/// <inheritdoc />
int ITypedOptionList<int>.GetValueUnboxed(int idx)
{
return (int)MathF.Round(GetValueUnboxed(idx));
return (int)MathF.Round(GetValueUnboxed(idx), MidpointRounding.AwayFromZero);
}
}
@@ -47,6 +47,7 @@ public abstract class ModdedBaseStringOption<T>(string groupPrefix, string title
data.Type = global::OptionTypes.String;
data.Values = StringNameValues;
data.Index = defaultIndex;
data.OptionName = Int32OptionNames.Invalid;
Data = data;
}
@@ -54,6 +54,11 @@ public class ModdedNumberOption : ModdedOption<float>
/// </summary>
public bool ShiftIncrement { get; }
/// <summary>
/// Gets a value indicating whether the option is an int option.
/// </summary>
public bool IsInt { get; }
/// <summary>
/// Gets a value indicating whether zero is infinity.
/// </summary>
@@ -98,27 +103,45 @@ public class ModdedNumberOption : ModdedOption<float>
ZeroWordValue = zeroBehavior;
ShiftIncrement = halfIncrements;
NegativeWordValue = negativeBehavior;
FormatString = formatString ??
(defaultValue.IsInteger() &&
Increment.IsInteger() &&
Value.IsInteger() &&
Min.IsInteger() &&
Max.IsInteger() ? "0" : "0.0");
IsInt = defaultValue.IsInteger() &&
Increment.IsInteger() &&
Value.IsInteger() &&
Min.IsInteger() &&
Max.IsInteger();
FormatString = formatString ?? (IsInt ? "0" : "0.0");
Value = Mathf.Clamp(defaultValue, min, max);
var data = ScriptableObject.CreateInstance<FloatGameSetting>();
data.Type = global::OptionTypes.Float;
data.Title = StringName;
data.Value = Value;
data.Increment = Increment;
data.ValidRange = new FloatRange(Min, Max);
data.FormatString = FormatString;
data.ZeroIsInfinity = ZeroInfinity;
data.SuffixType = (NumberSuffixes)SuffixType;
data.OptionName = FloatOptionNames.Invalid;
if (IsInt)
{
var data = ScriptableObject.CreateInstance<IntGameSetting>();
data.Type = global::OptionTypes.Int;
data.Title = StringName;
data.Value = (int)Value;
data.Increment = (int)Increment;
data.ValidRange = new IntRange((int)Min, (int)Max);
data.FormatString = FormatString;
data.ZeroIsInfinity = ZeroInfinity;
data.SuffixType = (NumberSuffixes)SuffixType;
data.OptionName = Int32OptionNames.Invalid;
Data = data;
Data = data;
}
else
{
var data = ScriptableObject.CreateInstance<FloatGameSetting>();
data.Type = global::OptionTypes.Float;
data.Title = StringName;
data.Value = Value;
data.Increment = Increment;
data.ValidRange = new FloatRange(Min, Max);
data.FormatString = FormatString;
data.ZeroIsInfinity = ZeroInfinity;
data.SuffixType = (NumberSuffixes)SuffixType;
data.OptionName = FloatOptionNames.Invalid;
Data = data;
}
}
/// <summary>
@@ -225,6 +248,7 @@ public class ModdedNumberOption : ModdedOption<float>
numberOption.FormatString = FormatString;
numberOption.ZeroIsInfinity = ZeroInfinity;
numberOption.SuffixType = (NumberSuffixes)SuffixType;
numberOption.intOptionName = Int32OptionNames.Invalid;
numberOption.floatOptionName = FloatOptionNames.Invalid;
numberOption.OnValueChanged = (Action<OptionBehaviour>)ValueChanged;
@@ -46,6 +46,7 @@ public class ModdedPlayerOption : ModdedOption<int>
var data = ScriptableObject.CreateInstance<PlayerSelectionGameSetting>();
data.Title = StringName;
data.Type = global::OptionTypes.Player;
data.OptionName = Int32OptionNames.Invalid;
Data = data;
}
@@ -40,6 +40,7 @@ public class ModdedToggleOption : ModdedOption<bool>
var data = ScriptableObject.CreateInstance<CheckboxGameSetting>();
data.Title = StringName;
data.Type = global::OptionTypes.Checkbox;
data.OptionName = BoolOptionNames.Invalid;
Data = data;
}
+1 -1
View File
@@ -51,7 +51,7 @@ public abstract class TimedModifier : BaseModifier
/// <returns>A string with the time remaining.</returns>
public override string GetDescription()
{
return $"Remaining Time: {MathF.Round(Duration - TimeRemaining, 0)}s/{Duration}s";
return $"Remaining Time: {MathF.Round(Duration - TimeRemaining, 0, MidpointRounding.AwayFromZero)}s/{Duration}s";
}
/// <summary>
+42
View File
@@ -1,6 +1,7 @@
using HarmonyLib;
using MiraAPI.GameOptions;
using MiraAPI.Roles;
using MiraAPI.Translation;
using MiraAPI.Utilities;
using UnityEngine;
@@ -184,5 +185,46 @@ public static class OptionsPatches
[HarmonyPatch(typeof(StringOption), nameof(StringOption.UpdateValue))]
[HarmonyPatch(typeof(NumberOption), nameof(NumberOption.UpdateValue))]
[HarmonyPatch(typeof(PlayerOption), nameof(PlayerOption.UpdateValue))]
[HarmonyPatch(typeof(ToggleOption), nameof(ToggleOption.UpdateValue))]
public static bool UpdateValuePrefix(OptionBehaviour __instance) => !__instance.IsCustom();
[HarmonyPrefix]
[HarmonyPatch(typeof(StringOption), nameof(StringOption.Initialize))]
public static bool StringInit(StringOption __instance)
{
if (!__instance.IsCustom())
{
return true;
}
__instance.TitleText.text = TranslationController.Instance.GetString(__instance.Title).Translate();
__instance.ValueText.text = TranslationController.Instance.GetString(__instance.Values[__instance.Value]);
return false;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(ToggleOption), nameof(ToggleOption.Initialize))]
public static bool ToggleInit(ToggleOption __instance)
{
if (!__instance.IsCustom())
{
return true;
}
__instance.TitleText.text = TranslationController.Instance.GetString(__instance.Title).Translate();
return false;
}
[HarmonyPrefix]
[HarmonyPatch(typeof(NumberOption), nameof(NumberOption.Initialize))]
public static bool NumberInit(NumberOption __instance)
{
if (!__instance.IsCustom())
{
return true;
}
__instance.TitleText.text = TranslationController.Instance.GetString(__instance.Title).Translate();
return false;
}
}
+1 -1
View File
@@ -18,7 +18,7 @@ public static class ColorExtensions
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static byte ToByte(this float @float)
{
return (byte)MathF.Round(@float * 255f);
return (byte)MathF.Round(@float * 255f, MidpointRounding.AwayFromZero);
}
/// <summary>
+1 -1
View File
@@ -204,7 +204,7 @@ public static class Extensions
/// <returns><see langword="true"/> if the <see langword="float"/> is an integer, <see langword="false"/> otherwise.</returns>
public static bool IsInteger(this float number)
{
return Mathf.Approximately(number, MathF.Round(number));
return Mathf.Approximately(number, MathF.Round(number, MidpointRounding.AwayFromZero));
}
/// <summary>