mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-10-19 15:51:48 +00:00
fixing HUD buttons not working oops
This commit is contained in:
1 parent
b1cbd9dd0f
commit
fc4baf0316
7 files changed
+75
-40
No files matched your search
@@ -127,12 +127,11 @@ public abstract class CustomActionButton
|
||||
{
|
||||
Timer -= Time.deltaTime;
|
||||
}
|
||||
else
|
||||
else if (HasEffect && EffectActive)
|
||||
{
|
||||
if (HasEffect && EffectActive)
|
||||
{
|
||||
EffectEndHandler();
|
||||
}
|
||||
EffectActive = false;
|
||||
Timer = Cooldown;
|
||||
OnEffectEnd();
|
||||
}
|
||||
|
||||
if (CanUse())
|
||||
@@ -143,15 +142,9 @@ public abstract class CustomActionButton
|
||||
{
|
||||
Button.SetDisabled();
|
||||
}
|
||||
|
||||
Button.SetCoolDown(Timer, EffectActive ? EffectDuration : Cooldown);
|
||||
|
||||
FixedUpdate(playerControl);
|
||||
}
|
||||
|
||||
private void EffectEndHandler()
|
||||
{
|
||||
EffectActive = false;
|
||||
Timer = Cooldown;
|
||||
OnEffectEnd();
|
||||
}
|
||||
}
|
||||
@@ -4,21 +4,5 @@ using System.Reflection;
|
||||
|
||||
namespace MiraAPI.Hud;
|
||||
|
||||
public class RegisterButtonAttribute : Attribute
|
||||
{
|
||||
private static readonly HashSet<Assembly> RegisteredAssemblies = [];
|
||||
|
||||
public static void Register(Assembly assembly)
|
||||
{
|
||||
if (!RegisteredAssemblies.Add(assembly)) return;
|
||||
|
||||
foreach (var type in assembly.GetTypes())
|
||||
{
|
||||
var attribute = type.GetCustomAttribute<RegisterButtonAttribute>();
|
||||
if (attribute != null)
|
||||
{
|
||||
CustomButtonManager.RegisterButton(type);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
[AttributeUsage(AttributeTargets.Class)]
|
||||
public class RegisterButtonAttribute : Attribute;
|
||||
@@ -0,0 +1,18 @@
|
||||
using HarmonyLib;
|
||||
using MiraAPI.Hud;
|
||||
|
||||
namespace MiraAPI.Patches;
|
||||
|
||||
[HarmonyPatch(typeof(MeetingHud))]
|
||||
public static class MeetingHudPatches
|
||||
{
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(nameof(MeetingHud.VotingComplete))]
|
||||
public static void VotingCompletePostfix()
|
||||
{
|
||||
foreach (var customActionButton in CustomButtonManager.CustomButtons)
|
||||
{
|
||||
customActionButton.ResetCooldown();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using HarmonyLib;
|
||||
using MiraAPI.Hud;
|
||||
|
||||
namespace MiraAPI.Patches;
|
||||
|
||||
[HarmonyPatch(typeof(PlayerControl))]
|
||||
public static class PlayerControlPatches
|
||||
{
|
||||
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(nameof(PlayerControl.FixedUpdate))]
|
||||
public static void PlayerControlFixedUpdatePostfix(PlayerControl __instance)
|
||||
{
|
||||
if (!__instance.AmOwner) return;
|
||||
|
||||
foreach (var button in CustomButtonManager.CustomButtons)
|
||||
{
|
||||
if (!button.Enabled(__instance.Data.Role))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
button.FixedUpdateHandler(__instance);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -9,6 +9,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using MiraAPI.Hud;
|
||||
|
||||
namespace MiraAPI.PluginLoading;
|
||||
|
||||
@@ -36,6 +37,7 @@ public class MiraPluginManager
|
||||
RegisterRoleAttribute(assembly, info);
|
||||
RegisterOptionsGroups(assembly, info);
|
||||
RegisterOptionsAttributes(assembly, info);
|
||||
RegisterButtonAttribute(assembly);
|
||||
|
||||
RegisteredPlugins.Add(assembly, info);
|
||||
|
||||
@@ -48,7 +50,6 @@ public class MiraPluginManager
|
||||
return RegisteredPlugins.Values.First(plugin => plugin.PluginId == guid);
|
||||
}
|
||||
|
||||
|
||||
private static void RegisterOptionsAttributes(Assembly assembly, MiraPluginInfo pluginInfo)
|
||||
{
|
||||
foreach (var type in assembly.GetTypes())
|
||||
@@ -102,4 +103,16 @@ public class MiraPluginManager
|
||||
pluginInfo.CustomRoles.Add((ushort)role.Role, role);
|
||||
}
|
||||
}
|
||||
|
||||
private static void RegisterButtonAttribute(Assembly assembly)
|
||||
{
|
||||
foreach (var type in assembly.GetTypes())
|
||||
{
|
||||
var attribute = type.GetCustomAttribute<RegisterButtonAttribute>();
|
||||
if (attribute != null)
|
||||
{
|
||||
CustomButtonManager.RegisterButton(type);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace MiraAPI.Utilities.Assets
|
||||
{
|
||||
public class LoadableResourceAsset(string name, string resourcesFolder) : LoadableAsset<Sprite>
|
||||
public class LoadableResourceAsset(string path) : LoadableAsset<Sprite>
|
||||
{
|
||||
public override Sprite LoadAsset()
|
||||
{
|
||||
@@ -13,11 +13,11 @@ namespace MiraAPI.Utilities.Assets
|
||||
|
||||
try
|
||||
{
|
||||
return _loadedAsset = SpriteTools.LoadSpriteFromPath(resourcesFolder + name);
|
||||
return _loadedAsset = SpriteTools.LoadSpriteFromPath(path);
|
||||
}
|
||||
catch
|
||||
{
|
||||
Debug.LogError($"Not loading, invalid asset: {name}");
|
||||
Debug.LogError($"Not loading, invalid asset: {path}");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,12 +2,12 @@
|
||||
{
|
||||
public static class MiraAssets
|
||||
{
|
||||
public static readonly LoadableResourceAsset Empty = new("", "");
|
||||
public static readonly LoadableResourceAsset Empty = new("");
|
||||
|
||||
public static readonly LoadableResourceAsset NextButton = new("NextButton.png", "MiraAPI.Resources.");
|
||||
public static readonly LoadableResourceAsset NextButtonActive = new("NextButtonActive.png", "MiraAPI.Resources.");
|
||||
public static readonly LoadableResourceAsset Cog = new("Cog.png", "MiraAPI.Resources.");
|
||||
public static readonly LoadableResourceAsset CogActive = new("CogActive.png", "MiraAPI.Resources.");
|
||||
public static readonly LoadableResourceAsset Banner = new("FortniteBanner.jpeg", "MiraAPI.Resources.");
|
||||
public static readonly LoadableResourceAsset NextButton = new("MiraAPI.Resources.NextButton.png");
|
||||
public static readonly LoadableResourceAsset NextButtonActive = new("MiraAPI.Resources.NextButtonActive.png");
|
||||
public static readonly LoadableResourceAsset Cog = new("MiraAPI.Resources.Cog.png");
|
||||
public static readonly LoadableResourceAsset CogActive = new("MiraAPI.Resources.CogActive.png");
|
||||
public static readonly LoadableResourceAsset Banner = new("MiraAPI.Resources.FortniteBanner.jpeg");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user