mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-10-19 15:51:48 +00:00
Fix errors
This commit is contained in:
1 parent
dccd06eac3
commit
5049d16ac9
9 files changed
+136
-4
No files matched your search
@@ -92,6 +92,11 @@ public interface IModdedOption
|
|||||||
/// <param name="saveDefault">Indicates whether to save the default value instead of the current value.</param>
|
/// <param name="saveDefault">Indicates whether to save the default value instead of the current value.</param>
|
||||||
void SaveToPreset(ConfigFile presetConfig, bool saveDefault = false);
|
void SaveToPreset(ConfigFile presetConfig, bool saveDefault = false);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Changes the scales and positions of the option if it's attached to the game options menu.
|
||||||
|
/// </summary>
|
||||||
|
void ChangeGameSetting();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Binds the option to a configuration file.
|
/// Binds the option to a configuration file.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -71,7 +71,12 @@ public class ModdedMultiSelectOption<T> : ModdedOption<T> where T : struct, Enum
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override OptionBehaviour CreateOption(ToggleOption toggleOpt, NumberOption numberOpt, StringOption stringOpt, Transform container)
|
public override OptionBehaviour CreateOption(
|
||||||
|
ToggleOption toggleOpt,
|
||||||
|
NumberOption numberOpt,
|
||||||
|
StringOption stringOpt,
|
||||||
|
PlayerOption playerOpt,
|
||||||
|
Transform container)
|
||||||
{
|
{
|
||||||
var stringOption = Object.Instantiate(stringOpt, container);
|
var stringOption = Object.Instantiate(stringOpt, container);
|
||||||
|
|
||||||
|
|||||||
@@ -181,6 +181,23 @@ public abstract class ModdedOption<T> : IModdedOption
|
|||||||
PlayerOption playerOpt,
|
PlayerOption playerOpt,
|
||||||
Transform container);
|
Transform container);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Visually adjust the game option as needed.
|
||||||
|
/// </summary>
|
||||||
|
public abstract void ChangeGameSetting();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Binds the option to the configuration file of the parent mod, if available.
|
||||||
|
/// </summary>
|
||||||
|
public virtual void BindConfig()
|
||||||
|
{
|
||||||
|
var entry = ParentMod?.GetConfigFile().Bind(ConfigDefinition, DefaultValue);
|
||||||
|
if (entry != null)
|
||||||
|
{
|
||||||
|
Value = entry.Value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Implicitly converts the option to type of <typeparamref name="T"/>.
|
/// Implicitly converts the option to type of <typeparamref name="T"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -28,6 +28,27 @@ public class ModdedPlayerOption : ModdedOption<int>
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public bool AllowNone { get; set; }
|
public bool AllowNone { get; set; }
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override void ChangeGameSetting()
|
||||||
|
{
|
||||||
|
var numberOption = OptionBehaviour as PlayerOption;
|
||||||
|
|
||||||
|
numberOption!.PlusBtn.transform.localPosition += new Vector3(0.6f, 0f, 0f);
|
||||||
|
numberOption.MinusBtn.transform.localPosition += new Vector3(1.5f, 0f, 0f);
|
||||||
|
|
||||||
|
var background = numberOption.transform.GetChild(0);
|
||||||
|
background.localPosition += new Vector3(-0.8f, 0f, 0f);
|
||||||
|
background.localScale += new Vector3(1f, 0f, 0f);
|
||||||
|
|
||||||
|
var title = numberOption.TitleText;
|
||||||
|
title.transform.localPosition = new(-2.0466f, 0f, -2.9968f);
|
||||||
|
title.GetComponent<RectTransform>().sizeDelta = new(5.8f, 0.458f);
|
||||||
|
|
||||||
|
var valueBox = numberOption.transform.GetChild(5);
|
||||||
|
valueBox.localPosition += new Vector3(1.05f, 0f, 0f);
|
||||||
|
valueBox.localScale += new Vector3(0.2f, 0f, 0f);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes a new instance of the <see cref="ModdedPlayerOption"/> class.
|
/// Initializes a new instance of the <see cref="ModdedPlayerOption"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
global using static Reactor.Utilities.Logger<MiraAPI.MiraApiPlugin>;
|
global using static Reactor.Utilities.Logger<MiraAPI.MiraApiPlugin>;
|
||||||
using BepInEx;
|
using BepInEx;
|
||||||
|
using BepInEx.Configuration;
|
||||||
using BepInEx.Unity.IL2CPP;
|
using BepInEx.Unity.IL2CPP;
|
||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
using MiraAPI.PluginLoading;
|
using MiraAPI.PluginLoading;
|
||||||
@@ -31,6 +32,7 @@ public partial class MiraApiPlugin : BasePlugin
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static Color DefaultHeaderColor { get; } = new Color32(77, 77, 77, 255);
|
public static Color DefaultHeaderColor { get; } = new Color32(77, 77, 77, 255);
|
||||||
|
|
||||||
|
internal static ConfigEntry<string>? DistanceSuffix { get; private set; }
|
||||||
private static MiraPluginManager? PluginManager { get; set; }
|
private static MiraPluginManager? PluginManager { get; set; }
|
||||||
internal Harmony Harmony { get; } = new(Id);
|
internal Harmony Harmony { get; } = new(Id);
|
||||||
|
|
||||||
@@ -41,6 +43,8 @@ public partial class MiraApiPlugin : BasePlugin
|
|||||||
|
|
||||||
ReactorCredits.Register("Mira API", Version, true, ReactorCredits.AlwaysShow);
|
ReactorCredits.Register("Mira API", Version, true, ReactorCredits.AlwaysShow);
|
||||||
|
|
||||||
|
DistanceSuffix = Config.Bind("Display", "Distance", "unit(s)", "Dictates how a distance is shown in numeric option displays");
|
||||||
|
|
||||||
PluginManager = new MiraPluginManager();
|
PluginManager = new MiraPluginManager();
|
||||||
PluginManager.Initialize();
|
PluginManager.Initialize();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -284,7 +284,8 @@ internal static class GameOptionsMenuPatch
|
|||||||
menu.playerOptionOrigin,
|
menu.playerOptionOrigin,
|
||||||
menu.settingsContainer));
|
menu.settingsContainer));
|
||||||
|
|
||||||
group.Options.ForEach(x => x.ChangeGameSetting());
|
// TODO: Reimplement this without breaking the menu.
|
||||||
|
// group.Options.ForEach(x => x.ChangeGameSetting());
|
||||||
|
|
||||||
foreach (var newOpt in options)
|
foreach (var newOpt in options)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -439,7 +439,6 @@ public static class RoleSettingMenuPatches
|
|||||||
__instance.AdvancedRolesSettings.transform);
|
__instance.AdvancedRolesSettings.transform);
|
||||||
|
|
||||||
newOpt.SetClickMask(__instance.ButtonClickMask);
|
newOpt.SetClickMask(__instance.ButtonClickMask);
|
||||||
option.ChangeRoleSetting();
|
|
||||||
|
|
||||||
SpriteRenderer[] componentsInChildren = newOpt.GetComponentsInChildren<SpriteRenderer>(true);
|
SpriteRenderer[] componentsInChildren = newOpt.GetComponentsInChildren<SpriteRenderer>(true);
|
||||||
foreach (var renderer in componentsInChildren)
|
foreach (var renderer in componentsInChildren)
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System.Collections;
|
using System;
|
||||||
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@@ -12,6 +13,7 @@ using TMPro;
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using MethodBase = System.Reflection.MethodBase;
|
using MethodBase = System.Reflection.MethodBase;
|
||||||
using Object = UnityEngine.Object;
|
using Object = UnityEngine.Object;
|
||||||
|
using Random = UnityEngine.Random;
|
||||||
|
|
||||||
namespace MiraAPI.Utilities;
|
namespace MiraAPI.Utilities;
|
||||||
|
|
||||||
@@ -522,6 +524,79 @@ public static class Helpers
|
|||||||
(Il2CppSystem.Object[])[value.ToString(formatString, CultureInfo.InvariantCulture)]),
|
(Il2CppSystem.Object[])[value.ToString(formatString, CultureInfo.InvariantCulture)]),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Shorthand for <see cref="string.Split(char, StringSplitOptions)"/> that removes empty entries and trims leading and ending spaces.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="value">The string to split.</param>
|
||||||
|
/// <param name="separator">The separator.</param>
|
||||||
|
/// <returns>An array of substrings.</returns>
|
||||||
|
public static string[] TrueSplit(this string value, char separator) => value.Split(separator, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Joins a collection of items that are separated by a character.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="separator">The separator.</param>
|
||||||
|
/// <param name="items">The collection of items to string together.</param>
|
||||||
|
/// <typeparam name="T">The type of the items.</typeparam>
|
||||||
|
/// <returns>A string formed by concatenating the ToString results of each item, each separated by a separator.</returns>
|
||||||
|
public static string Join<T>(char separator, IEnumerable<T> items) => Join(separator.ToString(), items);
|
||||||
|
|
||||||
|
/// <inheritdoc cref="Join{T}(char, IEnumerable{T})"/>
|
||||||
|
public static string Join<T>(string separator, IEnumerable<T> items)
|
||||||
|
{
|
||||||
|
if (!items.Any())
|
||||||
|
return string.Empty;
|
||||||
|
|
||||||
|
var result = string.Empty;
|
||||||
|
items.Do(x => result += $"{separator}{x}");
|
||||||
|
return result[separator.Length..];
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Shorthand helper for overriding the on click listeners for PassiveButton.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="passive">The PassiveButton being modified.</param>
|
||||||
|
/// <param name="action">The action that's replacing the original listeners.</param>
|
||||||
|
public static void OverrideOnClickListeners(this PassiveButton passive, Action action)
|
||||||
|
{
|
||||||
|
if (!passive)
|
||||||
|
return;
|
||||||
|
|
||||||
|
passive.OnClick?.RemoveAllListeners();
|
||||||
|
passive.OnClick = new();
|
||||||
|
passive.OnClick.AddListener(action);
|
||||||
|
passive.enabled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Shorthand helper for overriding the on mouse over listeners for PassiveButton.
|
||||||
|
/// </summary>
|
||||||
|
/// <inheritdoc cref="OverrideOnClickListeners"/>
|
||||||
|
public static void OverrideOnMouseOverListeners(this PassiveButton passive, Action action)
|
||||||
|
{
|
||||||
|
if (!passive)
|
||||||
|
return;
|
||||||
|
|
||||||
|
passive.OnMouseOver?.RemoveAllListeners();
|
||||||
|
passive.OnMouseOver = new();
|
||||||
|
passive.OnMouseOver.AddListener(action);
|
||||||
|
passive.enabled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Shorthand helper for overriding the on mouse out listeners for PassiveButton.
|
||||||
|
/// </summary>
|
||||||
|
/// <inheritdoc cref="OverrideOnClickListeners"/>
|
||||||
|
public static void OverrideOnMouseOutListeners(this PassiveButton passive, Action action)
|
||||||
|
{
|
||||||
|
if (!passive)
|
||||||
|
return;
|
||||||
|
|
||||||
|
passive.OnMouseOut?.RemoveAllListeners();
|
||||||
|
passive.OnMouseOut = new();
|
||||||
|
passive.OnMouseOut.AddListener(action);
|
||||||
|
passive.enabled = true;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns the string of a role.
|
/// Returns the string of a role.
|
||||||
|
|||||||
@@ -24,4 +24,9 @@ public enum MiraNumberSuffixes
|
|||||||
/// Percentage suffix (%).
|
/// Percentage suffix (%).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Percent,
|
Percent,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Display in units.
|
||||||
|
/// </summary>
|
||||||
|
Distance,
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user