split HudManager patches

This commit is contained in:
XtraCube committed 2024-09-01 16:14:30 -04:00
1 parent d1c469746e
commit f17089f435
2 files changed
+75 -67

No files matched your search

+1 -67
View File
@@ -17,62 +17,6 @@ public static class HudManagerPatches
// Custom buttons parent.
private static GameObject? _bottomLeft;
// Custom role tab.
private static TaskPanelBehaviour? _roleTab;
/// <summary>
/// Update custom role tab and custom role hud elements.
/// </summary>
/// <param name="__instance">The HudManager instance.</param>
[HarmonyPostfix]
[HarmonyPatch(nameof(HudManager.Update))]
public static void UpdatePostfix(HudManager __instance)
{
var local = PlayerControl.LocalPlayer;
if (AmongUsClient.Instance.GameState != InnerNetClient.GameStates.Started && !ShipStatus.Instance)
{
return;
}
// CustomGameModeManager.ActiveMode?.HudUpdate(__instance);
switch (local?.Data?.Role)
{
case null:
return;
case ICustomRole customRole:
{
customRole.HudUpdate(__instance);
if (customRole.RoleHintType != RoleHintType.RoleTab)
{
_roleTab?.gameObject.Destroy();
return;
}
if (_roleTab == null)
{
_roleTab = CustomRoleManager.CreateRoleTab(customRole);
}
else
{
CustomRoleManager.UpdateRoleTab(_roleTab, customRole);
}
break;
}
default:
if (_roleTab != null)
{
_roleTab.gameObject.Destroy();
}
break;
}
}
/*
/// <summary>
/// Trigger hudstart on current custom gamemode
@@ -136,7 +80,7 @@ public static class HudManagerPatches
}
/// <summary>
/// Set the custom role tab and custom buttons active when the hud is active.
/// Set the custom buttons active when the hud is active.
/// </summary>
/// <param name="__instance">HudManager instance.</param>
/// <param name="localPlayer">The local PlayerControl.</param>
@@ -151,19 +95,9 @@ public static class HudManagerPatches
return;
}
if (_roleTab)
{
_roleTab?.gameObject.SetActive(isActive);
}
foreach (var button in CustomButtonManager.CustomButtons)
{
button.SetActive(isActive, role);
}
if (role is ICustomRole customRole)
{
__instance.ImpostorVentButton.gameObject.SetActive(isActive && customRole.CanUseVent);
}
}
}
@@ -0,0 +1,74 @@
using HarmonyLib;
using InnerNet;
using MiraAPI.Roles;
using Reactor.Utilities.Extensions;
namespace MiraAPI.Patches.Roles;
/// <summary>
/// HudManager patches for roles.
/// </summary>
[HarmonyPatch(typeof(HudManager))]
public static class HudManagerPatches
{
// Custom role tab.
private static TaskPanelBehaviour? _roleTab;
/// <summary>
/// Fixes Kill Button not showing for Neutral killing role.
/// </summary>
[HarmonyPostfix]
[HarmonyPatch(nameof(HudManager.SetHudActive), typeof(PlayerControl), typeof(RoleBehaviour), typeof(bool))]
public static void SetHudActivePostfix(
HudManager __instance,
PlayerControl localPlayer,
RoleBehaviour role,
bool isActive)
{
var flag = localPlayer.Data != null && localPlayer.Data.IsDead;
if (role is ICustomRole)
{
__instance.KillButton.ToggleVisible(isActive && role.CanUseKillButton && !flag);
__instance.ImpostorVentButton.ToggleVisible(isActive && role.CanVent && !flag);
}
if (_roleTab)
{
_roleTab?.gameObject.SetActive(isActive);
}
}
/// <summary>
/// Update custom role tab and custom role hud elements.
/// </summary>
[HarmonyPostfix]
[HarmonyPatch(nameof(HudManager.Update))]
public static void UpdatePostfix(HudManager __instance)
{
var local = PlayerControl.LocalPlayer;
if (AmongUsClient.Instance.GameState != InnerNetClient.GameStates.Started && !ShipStatus.Instance)
{
return;
}
var role = local?.Data?.Role;
if (role is ICustomRole { RoleHintType: RoleHintType.RoleTab } customRole)
{
customRole.HudUpdate(__instance);
if (_roleTab == null)
{
_roleTab = CustomRoleManager.CreateRoleTab(customRole);
}
CustomRoleManager.UpdateRoleTab(_roleTab, customRole);
}
else if (_roleTab)
{
_roleTab?.gameObject.Destroy();
}
}
}