mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-10-20 01:46:15 +00:00
fix warnings
This commit is contained in:
1 parent
669c541279
commit
0d2a9d9700
8 files changed
+34
-129
No files matched your search
@@ -1,114 +0,0 @@
|
|||||||
using System;
|
|
||||||
using MiraAPI.Utilities.Assets;
|
|
||||||
using Reactor.Utilities.Attributes;
|
|
||||||
using UnityEngine;
|
|
||||||
using UnityEngine.Events;
|
|
||||||
using UnityEngine.UI;
|
|
||||||
|
|
||||||
namespace MiraAPI.Hud;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Simple input box for user input.
|
|
||||||
/// </summary>
|
|
||||||
[RegisterInIl2Cpp]
|
|
||||||
public class InputBox : MonoBehaviour
|
|
||||||
{
|
|
||||||
public InputField inputField = null!;
|
|
||||||
|
|
||||||
public void CreateDialog(string title, string placeholder, string submitText, Action<string> onSubmit)
|
|
||||||
{
|
|
||||||
var canvasObj = new GameObject("DialogCanvas");
|
|
||||||
canvasObj.transform.SetParent(transform);
|
|
||||||
canvasObj.layer = LayerMask.NameToLayer("UI");
|
|
||||||
|
|
||||||
var canvas = canvasObj.AddComponent<Canvas>();
|
|
||||||
canvas.renderMode = RenderMode.ScreenSpaceOverlay;
|
|
||||||
canvas.overrideSorting = true;
|
|
||||||
canvas.sortingOrder = 1000; // Ensure the canvas is on top of other UI elements
|
|
||||||
|
|
||||||
canvasObj.AddComponent<CanvasScaler>().uiScaleMode = CanvasScaler.ScaleMode.ScaleWithScreenSize;
|
|
||||||
canvasObj.AddComponent<GraphicRaycaster>();
|
|
||||||
|
|
||||||
var panelObj = new GameObject("DialogPanel");
|
|
||||||
panelObj.transform.SetParent(canvasObj.transform);
|
|
||||||
var panelRect = panelObj.AddComponent<RectTransform>();
|
|
||||||
var img = panelObj.AddComponent<Image>();
|
|
||||||
|
|
||||||
img.color = new Color(1, 1, 1, 0.9f);
|
|
||||||
img.raycastTarget = true;
|
|
||||||
img.sprite = MiraAssets.RoundedBox.LoadAsset();
|
|
||||||
img.type = Image.Type.Sliced;
|
|
||||||
|
|
||||||
panelRect.sizeDelta = new Vector2(300, 200);
|
|
||||||
panelRect.anchoredPosition = Vector2.zero;
|
|
||||||
|
|
||||||
var titleText = CreateText(panelObj, title);
|
|
||||||
titleText.alignment = TextAnchor.MiddleCenter;
|
|
||||||
titleText.fontSize = 26;
|
|
||||||
titleText.fontStyle = FontStyle.Bold;
|
|
||||||
titleText.color = Color.white;
|
|
||||||
|
|
||||||
var titleRect = titleText.GetComponent<RectTransform>();
|
|
||||||
titleRect.sizeDelta = new Vector2(280, 50);
|
|
||||||
titleRect.anchoredPosition = new Vector2(0, 70);
|
|
||||||
|
|
||||||
var inputObj = new GameObject("InputField");
|
|
||||||
inputObj.transform.SetParent(panelObj.transform);
|
|
||||||
var inputRect = inputObj.AddComponent<RectTransform>();
|
|
||||||
inputRect.sizeDelta = new Vector2(220, 40);
|
|
||||||
inputRect.anchoredPosition = new Vector2(0, 20);
|
|
||||||
|
|
||||||
var inputBg = inputObj.AddComponent<Image>();
|
|
||||||
inputBg.color = new Color(1, 1, 1, 0.8f);
|
|
||||||
|
|
||||||
inputField = inputObj.AddComponent<InputField>();
|
|
||||||
inputField.textComponent = CreateText(inputObj, string.Empty, 18, Color.black);
|
|
||||||
inputField.placeholder = CreateText(inputObj, placeholder, 18, new Color(0.5f, 0.5f, 0.5f));
|
|
||||||
|
|
||||||
var buttonObj = new GameObject("SubmitButton");
|
|
||||||
buttonObj.transform.SetParent(panelObj.transform);
|
|
||||||
var button = buttonObj.AddComponent<Button>();
|
|
||||||
var buttonRect = buttonObj.AddComponent<RectTransform>();
|
|
||||||
buttonRect.sizeDelta = new Vector2(150, 50);
|
|
||||||
buttonRect.anchoredPosition = new Vector2(0, -50);
|
|
||||||
|
|
||||||
var buttonImg = buttonObj.AddComponent<Image>();
|
|
||||||
buttonImg.color = new Color(1f, 1f, 1f, 1f);
|
|
||||||
buttonImg.sprite = MiraAssets.RoundedBox.LoadAsset();
|
|
||||||
buttonImg.type = Image.Type.Sliced;
|
|
||||||
|
|
||||||
var buttonText = CreateText(buttonObj, submitText, 20, Color.white);
|
|
||||||
buttonText.alignment = TextAnchor.MiddleCenter;
|
|
||||||
|
|
||||||
var colors = button.colors;
|
|
||||||
colors.highlightedColor = Color.green;
|
|
||||||
colors.pressedColor = MiraAssets.AcceptedTeal;
|
|
||||||
button.colors = colors;
|
|
||||||
|
|
||||||
button.onClick.AddListener((UnityAction)(() =>
|
|
||||||
{
|
|
||||||
onSubmit(inputField.text);
|
|
||||||
DestroyImmediate(canvasObj);
|
|
||||||
}));
|
|
||||||
|
|
||||||
inputField.ActivateInputField();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Text CreateText(GameObject parent, string textContent = "", int fontSize = 20, Color? textColor = null, Font? font = null)
|
|
||||||
{
|
|
||||||
var textObj = new GameObject("Text");
|
|
||||||
textObj.transform.SetParent(parent.transform);
|
|
||||||
|
|
||||||
var text = textObj.AddComponent<Text>();
|
|
||||||
text.font = font ?? Resources.GetBuiltinResource<Font>("Arial.ttf");
|
|
||||||
text.text = textContent;
|
|
||||||
text.color = textColor ?? Color.white;
|
|
||||||
text.fontSize = fontSize;
|
|
||||||
text.alignment = TextAnchor.MiddleCenter;
|
|
||||||
|
|
||||||
var rect = textObj.GetComponent<RectTransform>();
|
|
||||||
rect.sizeDelta = new Vector2(200, 40);
|
|
||||||
rect.anchoredPosition = Vector2.zero;
|
|
||||||
return text;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -16,6 +16,11 @@ namespace MiraAPI.Modifiers;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static class ModifierManager
|
public static class ModifierManager
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets a value indicating whether modifiers should be assigned to players.
|
||||||
|
/// </summary>
|
||||||
|
public static bool MiraAssignsModifiers { get; set; } = true;
|
||||||
|
|
||||||
private static readonly Dictionary<uint, Type> IdToTypeModifierMap = [];
|
private static readonly Dictionary<uint, Type> IdToTypeModifierMap = [];
|
||||||
private static readonly Dictionary<Type, uint> TypeToIdModifierMap = [];
|
private static readonly Dictionary<Type, uint> TypeToIdModifierMap = [];
|
||||||
private static readonly Dictionary<int, List<uint>> PrioritiesToIdsMap = [];
|
private static readonly Dictionary<int, List<uint>> PrioritiesToIdsMap = [];
|
||||||
@@ -98,7 +103,11 @@ public static class ModifierManager
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static void AssignModifiers(List<PlayerControl> plrs)
|
/// <summary>
|
||||||
|
/// Assigns modifiers to players. ONLY CALL THIS METHOD IF YOU KNOW WHAT YOU ARE DOING.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="plrs">The players to assign modifiers to.</param>
|
||||||
|
public static void AssignModifiers(List<PlayerControl> plrs)
|
||||||
{
|
{
|
||||||
var rand = new Random();
|
var rand = new Random();
|
||||||
|
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ internal static class GamePresetsTabPatches
|
|||||||
|
|
||||||
var prefab = GameSettingMenu.Instance.GameSettingsButton;
|
var prefab = GameSettingMenu.Instance.GameSettingsButton;
|
||||||
|
|
||||||
foreach (var preset in MiraPluginManager.Instance.RegisteredPlugins.SelectMany(x => x.Presets))
|
foreach (var preset in MiraPluginManager.Instance.RegisteredPlugins.SelectMany(x => x.InternalPresets))
|
||||||
{
|
{
|
||||||
var button = Object.Instantiate(prefab, _presetHolder.transform);
|
var button = Object.Instantiate(prefab, _presetHolder.transform);
|
||||||
button.buttonText.text = preset.Name;
|
button.buttonText.text = preset.Name;
|
||||||
@@ -112,7 +112,7 @@ internal static class GamePresetsTabPatches
|
|||||||
|
|
||||||
foreach (var mod in MiraPluginManager.Instance.RegisteredPlugins)
|
foreach (var mod in MiraPluginManager.Instance.RegisteredPlugins)
|
||||||
{
|
{
|
||||||
foreach (var button in mod.Presets.Select(x => x.PresetButton))
|
foreach (var button in mod.InternalPresets.Select(x => x.PresetButton))
|
||||||
{
|
{
|
||||||
if (button != null)
|
if (button != null)
|
||||||
{
|
{
|
||||||
@@ -154,7 +154,7 @@ internal static class GamePresetsTabPatches
|
|||||||
|
|
||||||
foreach (var mod in MiraPluginManager.Instance.RegisteredPlugins)
|
foreach (var mod in MiraPluginManager.Instance.RegisteredPlugins)
|
||||||
{
|
{
|
||||||
foreach (var button in mod.Presets.Select(x => x.PresetButton))
|
foreach (var button in mod.InternalPresets.Select(x => x.PresetButton))
|
||||||
{
|
{
|
||||||
if (button != null)
|
if (button != null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -495,7 +495,6 @@ internal static class GameSettingMenuPatches
|
|||||||
.ForEach(header => header.gameObject.DestroyImmediate());
|
.ForEach(header => header.gameObject.DestroyImmediate());
|
||||||
|
|
||||||
gameOptMenu.Initialize();
|
gameOptMenu.Initialize();
|
||||||
|
|
||||||
var positions = modifiers ? ModifiersPositions : OptionsPositions;
|
var positions = modifiers ? ModifiersPositions : OptionsPositions;
|
||||||
if (positions.TryGetValue(SelectedModIdx, out var pos))
|
if (positions.TryGetValue(SelectedModIdx, out var pos))
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ public static class RoleManagerPatches
|
|||||||
[HarmonyPatch(nameof(RoleManager.SelectRoles))]
|
[HarmonyPatch(nameof(RoleManager.SelectRoles))]
|
||||||
public static void ModifierSelectionPatches(RoleManager __instance)
|
public static void ModifierSelectionPatches(RoleManager __instance)
|
||||||
{
|
{
|
||||||
if (!AmongUsClient.Instance.AmHost)
|
if (!AmongUsClient.Instance.AmHost || !ModifierManager.MiraAssignsModifiers)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -91,6 +91,6 @@ public static class PresetManager
|
|||||||
|
|
||||||
plugin.InternalPresets.Add(new OptionPreset(presetName, plugin, presetConfig));
|
plugin.InternalPresets.Add(new OptionPreset(presetName, plugin, presetConfig));
|
||||||
}
|
}
|
||||||
plugin.Presets = [.. plugin.InternalPresets];
|
plugin.Presets = [..plugin.InternalPresets];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -9,16 +9,21 @@ using TMPro;
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.Events;
|
using UnityEngine.Events;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
|
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
|
||||||
|
|
||||||
[RegisterInIl2Cpp]
|
[RegisterInIl2Cpp]
|
||||||
public class SavePresetPopup(nint ptr) : Minigame(ptr)
|
#pragma warning disable S3903
|
||||||
|
#pragma warning disable CA1050
|
||||||
|
public class SavePresetPopup(nint cppPtr) : Minigame(cppPtr)
|
||||||
|
#pragma warning restore CA1050
|
||||||
|
#pragma warning restore S3903
|
||||||
{
|
{
|
||||||
private PassiveButton saveButton;
|
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable.
|
||||||
private PassiveButton closeButton;
|
|
||||||
private TextMeshPro textBoxText;
|
private TextMeshPro textBoxText;
|
||||||
private TextBoxTMP textBox;
|
private TextBoxTMP textBox;
|
||||||
|
|
||||||
private Action<string> onSave;
|
private Action<string> onSave;
|
||||||
|
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable.
|
||||||
|
|
||||||
// Cleanup holder object
|
// Cleanup holder object
|
||||||
public void OnDestroy()
|
public void OnDestroy()
|
||||||
@@ -28,13 +33,14 @@ public class SavePresetPopup(nint ptr) : Minigame(ptr)
|
|||||||
|
|
||||||
public override void Close()
|
public override void Close()
|
||||||
{
|
{
|
||||||
|
// no-op
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Awake()
|
private void Awake()
|
||||||
{
|
{
|
||||||
var textboxHolder = transform.GetChild(1).GetChild(1);
|
var textboxHolder = transform.GetChild(1).GetChild(1);
|
||||||
saveButton = transform.FindChild("SaveButton").GetComponent<PassiveButton>();
|
var saveButton = transform.FindChild("SaveButton").GetComponent<PassiveButton>();
|
||||||
closeButton = transform.FindChild("CloseButton").GetComponent<PassiveButton>();
|
var closeButton = transform.FindChild("CloseButton").GetComponent<PassiveButton>();
|
||||||
textBox = textboxHolder.GetChild(0).GetComponent<TextBoxTMP>();
|
textBox = textboxHolder.GetChild(0).GetComponent<TextBoxTMP>();
|
||||||
textBoxText = textBox.transform.GetChild(0).GetComponent<TextMeshPro>();
|
textBoxText = textBox.transform.GetChild(0).GetComponent<TextMeshPro>();
|
||||||
|
|
||||||
@@ -64,7 +70,11 @@ public class SavePresetPopup(nint ptr) : Minigame(ptr)
|
|||||||
|
|
||||||
foreach (var tmp in gameObject.GetComponentsInChildren<TextMeshPro>())
|
foreach (var tmp in gameObject.GetComponentsInChildren<TextMeshPro>())
|
||||||
{
|
{
|
||||||
if (tmp.gameObject.transform.parent.name == "Textbox") continue;
|
if (tmp.gameObject.transform.parent.name == "Textbox")
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
var text = tmp.text;
|
var text = tmp.text;
|
||||||
tmp.text = $"<font=\"LiberationSans SDF\" material=\"LiberationSans SDF RadialMenu Material\">{text}</font>";
|
tmp.text = $"<font=\"LiberationSans SDF\" material=\"LiberationSans SDF RadialMenu Material\">{text}</font>";
|
||||||
}
|
}
|
||||||
@@ -78,9 +88,9 @@ public class SavePresetPopup(nint ptr) : Minigame(ptr)
|
|||||||
transform =
|
transform =
|
||||||
{
|
{
|
||||||
parent = Camera.main!.transform,
|
parent = Camera.main!.transform,
|
||||||
|
localPosition = new Vector3(0, -1f, -500),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
holder.transform.localPosition = new Vector3(0, -1f, -500);
|
|
||||||
|
|
||||||
var gameObject = Instantiate(MiraAssets.PresetSavePopup.LoadAsset(), holder.transform);
|
var gameObject = Instantiate(MiraAssets.PresetSavePopup.LoadAsset(), holder.transform);
|
||||||
var popup = gameObject.GetComponent<SavePresetPopup>();
|
var popup = gameObject.GetComponent<SavePresetPopup>();
|
||||||
@@ -89,3 +99,4 @@ public class SavePresetPopup(nint ptr) : Minigame(ptr)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -84,7 +84,7 @@ public static class Extensions
|
|||||||
analytics.MinigameClosed(data, taskType, realtimeSinceStartup, isComplete);
|
analytics.MinigameClosed(data, taskType, realtimeSinceStartup, isComplete);
|
||||||
self.StartCoroutine(self.CoDestroySelf());
|
self.StartCoroutine(self.CoDestroySelf());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sets the cooldown of a button with a formatted string.
|
/// Sets the cooldown of a button with a formatted string.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
Reference in new issue
Block a user