mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-10-20 01:46:15 +00:00
WIP Left side Modifiers HUD option
This commit is contained in:
1 parent
c89e5938cc
commit
2ee8730ba4
5 files changed
+74
-19
No files matched your search
@@ -0,0 +1,23 @@
|
||||
using BepInEx;
|
||||
using BepInEx.Configuration;
|
||||
using BepInEx.Unity.IL2CPP;
|
||||
using HarmonyLib;
|
||||
using MiraAPI.PluginLoading;
|
||||
using Reactor;
|
||||
using Reactor.Networking;
|
||||
using Reactor.Networking.Attributes;
|
||||
using Reactor.Utilities;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI;
|
||||
|
||||
/// <summary>
|
||||
/// Mira API Config File Handler
|
||||
/// </summary>
|
||||
public class MiraApiConfig(ConfigFile config)
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets whether the modifiers hud should be on the left side of the screen (under roles/task tab). Recommended for streamers.
|
||||
/// </summary>
|
||||
public ConfigEntry<bool> ModifiersHudLeftSide { get; private set; } = config.Bind("Displays", "Show Modifiers HUD on Left Side", false);
|
||||
}
|
||||
@@ -30,6 +30,10 @@ public partial class MiraApiPlugin : BasePlugin
|
||||
/// </summary>
|
||||
public static Color DefaultHeaderColor { get; } = new Color32(77, 77, 77, 255);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Mira Api Config Handler.
|
||||
/// </summary>
|
||||
public MiraApiConfig? MiraConfig { get; private set; }
|
||||
private static MiraPluginManager? PluginManager { get; set; }
|
||||
internal Harmony Harmony { get; } = new(Id);
|
||||
|
||||
@@ -40,6 +44,7 @@ public partial class MiraApiPlugin : BasePlugin
|
||||
|
||||
ReactorCredits.Register("Mira API", Version, true, ReactorCredits.AlwaysShow);
|
||||
|
||||
MiraConfig = new MiraApiConfig(Config);
|
||||
PluginManager = new MiraPluginManager();
|
||||
PluginManager.Initialize();
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ using System.Linq;
|
||||
using Il2CppInterop.Runtime.Attributes;
|
||||
using MiraAPI.Modifiers.ModifierDisplay;
|
||||
using MiraAPI.Modifiers.Types;
|
||||
using MiraAPI.Patches.Roles;
|
||||
using Reactor.Utilities;
|
||||
using Reactor.Utilities.Attributes;
|
||||
using UnityEngine;
|
||||
@@ -126,7 +127,18 @@ public class ModifierComponent(IntPtr cppPtr) : MonoBehaviour(cppPtr)
|
||||
|
||||
if (_player.AmOwner && ModifierDisplay && HudManager.InstanceExists)
|
||||
{
|
||||
ModifierDisplay!.gameObject.SetActive(MeetingHud.Instance || HudManager.Instance.TaskPanel.isActiveAndEnabled);
|
||||
var taskPanelOpen = HudManager.Instance.TaskPanel.open;
|
||||
var roleTabOpen = HudManagerPatches.RoleTab != null && HudManagerPatches.RoleTab.open;
|
||||
var leftSideHud = PluginSingleton<MiraApiPlugin>.Instance.MiraConfig!.ModifiersHudLeftSide.Value;
|
||||
|
||||
if (leftSideHud && (taskPanelOpen || roleTabOpen))
|
||||
{
|
||||
ModifierDisplay!.gameObject.SetActive(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
ModifierDisplay!.gameObject.SetActive(MeetingHud.Instance || HudManager.Instance.TaskPanel.isActiveAndEnabled);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using HarmonyLib;
|
||||
using Il2CppInterop.Runtime.Attributes;
|
||||
using MiraAPI.Patches.Roles;
|
||||
using MiraAPI.Utilities.Assets;
|
||||
using Reactor.Utilities;
|
||||
using Reactor.Utilities.Attributes;
|
||||
using Reactor.Utilities.Extensions;
|
||||
using TMPro;
|
||||
@@ -94,6 +97,16 @@ public class ModifierDisplayComponent(nint cppPtr) : MonoBehaviour(cppPtr)
|
||||
|
||||
IsOpen = false;
|
||||
_children.gameObject.SetActive(false);
|
||||
|
||||
if (PluginSingleton<MiraApiPlugin>.Instance.MiraConfig!.ModifiersHudLeftSide.Value)
|
||||
{
|
||||
var aspect = GetComponent<AspectPosition>();
|
||||
_toggleButton.transform.localPosition = new Vector3(-1f, 2.7f, 0f);
|
||||
_children.transform.localPosition = new Vector3(-0.2f, -0.05f, 0f);
|
||||
aspect.Alignment = AspectPosition.EdgeAlignments.LeftTop;
|
||||
aspect.DistanceFromEdge = new Vector3(1.8f, 2.55f, -20f);
|
||||
aspect.AdjustPosition();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -109,7 +122,16 @@ public class ModifierDisplayComponent(nint cppPtr) : MonoBehaviour(cppPtr)
|
||||
/// </summary>
|
||||
public void ToggleTab()
|
||||
{
|
||||
IsOpen = !IsOpen;
|
||||
SetOpened(!IsOpen);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Use this to set the visibility of the modifiers tab.
|
||||
/// </summary>
|
||||
/// <param name="val">Whether it should be visible or not.</param>
|
||||
public void SetOpened(bool val)
|
||||
{
|
||||
IsOpen = val;
|
||||
_children.gameObject.SetActive(IsOpen);
|
||||
RefreshModifiers();
|
||||
}
|
||||
@@ -118,7 +140,6 @@ public class ModifierDisplayComponent(nint cppPtr) : MonoBehaviour(cppPtr)
|
||||
{
|
||||
_modifiers.Remove(component.Modifier!);
|
||||
component.gameObject.DestroyImmediate();
|
||||
|
||||
RefreshModifiers();
|
||||
}
|
||||
|
||||
@@ -194,13 +215,7 @@ public class ModifierDisplayComponent(nint cppPtr) : MonoBehaviour(cppPtr)
|
||||
|
||||
_toggleBtnText.text = $"Modifiers ({filteredModifiers.Count})";
|
||||
|
||||
if (filteredModifiers.Count == 0)
|
||||
{
|
||||
_toggleButton.gameObject.SetActive(false);
|
||||
return;
|
||||
}
|
||||
|
||||
_toggleButton.gameObject.SetActive(true);
|
||||
_toggleButton.gameObject.SetActive(filteredModifiers.Count != 0);
|
||||
|
||||
foreach (var mod in modifiersToAdd)
|
||||
{
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace MiraAPI.Patches.Roles;
|
||||
public static class HudManagerPatches
|
||||
{
|
||||
// Custom role tab.
|
||||
private static TaskPanelBehaviour? _roleTab;
|
||||
public static TaskPanelBehaviour? RoleTab;
|
||||
|
||||
/// <summary>
|
||||
/// Fixes Kill Button not showing for Neutral killing role.
|
||||
@@ -38,9 +38,9 @@ public static class HudManagerPatches
|
||||
__instance.SabotageButton.gameObject.SetActive(isActive && customRole.Configuration.CanUseSabotage);
|
||||
}
|
||||
|
||||
if (_roleTab)
|
||||
if (RoleTab)
|
||||
{
|
||||
_roleTab?.gameObject.SetActive(isActive);
|
||||
RoleTab?.gameObject.SetActive(isActive);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,16 +62,16 @@ public static class HudManagerPatches
|
||||
|
||||
if (role is ICustomRole { Configuration.RoleHintType: RoleHintType.RoleTab } customRole)
|
||||
{
|
||||
if (_roleTab == null)
|
||||
if (RoleTab == null)
|
||||
{
|
||||
_roleTab = CustomRoleManager.CreateRoleTab(customRole);
|
||||
RoleTab = CustomRoleManager.CreateRoleTab(customRole);
|
||||
}
|
||||
|
||||
CustomRoleManager.UpdateRoleTab(_roleTab, customRole);
|
||||
CustomRoleManager.UpdateRoleTab(RoleTab, customRole);
|
||||
}
|
||||
else if (_roleTab)
|
||||
else if (RoleTab)
|
||||
{
|
||||
_roleTab?.gameObject.Destroy();
|
||||
RoleTab?.gameObject.Destroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user