mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-10-20 01:46:15 +00:00
Update conflict system
This commit is contained in:
1 parent
355eef509b
commit
01fa1f0915
2 files changed
+36
-11
No files matched your search
@@ -0,0 +1,36 @@
|
||||
using HarmonyLib;
|
||||
using MiraAPI.Keybinds;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI.Patches;
|
||||
|
||||
/// <summary>
|
||||
/// Checks keybind conflicts in the lobby and disables secondary ones.
|
||||
/// </summary>
|
||||
[HarmonyPatch(typeof(GameStartManager))]
|
||||
public static class GameStartManagerPatch
|
||||
{
|
||||
public static bool conflictShown = false;
|
||||
|
||||
[HarmonyPatch(nameof(GameStartManager.Start))]
|
||||
[HarmonyPostfix]
|
||||
public static void StartPostfix(GameStartManager __instance)
|
||||
{
|
||||
if (conflictShown) return;
|
||||
|
||||
var conflicts = KeybindManager.GetConflicts();
|
||||
if (conflicts.Count == 0) return;
|
||||
|
||||
conflictShown = true;
|
||||
|
||||
var message = "The following keybinds are disabled due to conflicts:\n\n";
|
||||
|
||||
foreach (var (a, b) in conflicts)
|
||||
{
|
||||
message += $"• <color=#FF5555>{b.Description}</color> (conflicts with {a.Description})\n";
|
||||
b.Handler = null;
|
||||
}
|
||||
|
||||
HudManager.Instance.ShowPopUp(message.TrimEnd());
|
||||
}
|
||||
}
|
||||
@@ -141,17 +141,6 @@ public sealed class MiraPluginManager
|
||||
|
||||
Logger<MiraApiPlugin>.Info($"Registered keybind for button '{button.GetType().Name}' with default key {button.Defaultkeybind}.");
|
||||
}
|
||||
|
||||
var conflicts = KeybindManager.GetConflicts();
|
||||
foreach (var (a, b) in conflicts)
|
||||
{
|
||||
Logger<MiraApiPlugin>.Warning($"Keybind conflict detected: {a.Id} and {b.Id} share {a.Key}");
|
||||
|
||||
var newKey = Helpers.FindAvailableKey(a.Key);
|
||||
b.Key = newKey;
|
||||
|
||||
Logger<MiraApiPlugin>.Info($"Resolved conflict: '{b.Id}' reassigned to {newKey}.");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user