mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-10-19 15:51:48 +00:00
New events and more flexibility
This commit is contained in:
1 parent
a65de5a938
commit
22718a708c
10 files changed
+151
-30
No files matched your search
@@ -0,0 +1,28 @@
|
||||
namespace MiraAPI.Events.Vanilla.Meeting;
|
||||
|
||||
/// <summary>
|
||||
/// The event that is invoked when a player is ejected.
|
||||
/// </summary>
|
||||
public class EjectionEvent : MiraCancelableEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the player that is being ejected.
|
||||
/// </summary>
|
||||
public PlayerControl? Player { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the instance of the ExileController.
|
||||
/// </summary>
|
||||
public ExileController ExileController { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="EjectionEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="player">The player who is being ejected.</param>
|
||||
/// <param name="controller">The exile controller.</param>
|
||||
public EjectionEvent(PlayerControl player, ExileController controller)
|
||||
{
|
||||
Player = player;
|
||||
ExileController = controller;
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
namespace MiraAPI.Events.Vanilla;
|
||||
namespace MiraAPI.Events.Vanilla.Meeting;
|
||||
|
||||
/// <summary>
|
||||
/// The event that is invoked when a meeting is called
|
||||
/// The event that is invoked when a meeting is called.
|
||||
/// </summary>
|
||||
public class StartMeetingEvent : MiraCancelableEvent
|
||||
{
|
||||
@@ -0,0 +1,21 @@
|
||||
namespace MiraAPI.Events.Vanilla.Meeting;
|
||||
|
||||
/// <summary>
|
||||
/// The event that is invoked when the intro cutscene is shown. Non cancellable.
|
||||
/// </summary>
|
||||
public class IntroBeginEvent : MiraEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the instance of the IntroCutscene.
|
||||
/// </summary>
|
||||
public IntroCutscene IntroCutscene { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="IntroBeginEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="controller">The exile controller.</param>
|
||||
public IntroBeginEvent(IntroCutscene introCutscene)
|
||||
{
|
||||
IntroCutscene = introCutscene;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,8 @@
|
||||
using System;
|
||||
using MiraAPI.Events;
|
||||
using MiraAPI.Events;
|
||||
using MiraAPI.Events.Mira;
|
||||
using MiraAPI.Patches;
|
||||
using MiraAPI.Utilities.Assets;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.UI;
|
||||
@@ -47,7 +48,7 @@ public abstract class CustomActionButton
|
||||
/// <summary>
|
||||
/// Gets the location of the button on the screen.
|
||||
/// </summary>
|
||||
public virtual ButtonLocation Location => ButtonLocation.BottomLeft;
|
||||
public virtual ButtonLocation Location { get; private set; } = ButtonLocation.BottomLeft;
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the button has an effect ability.
|
||||
@@ -79,7 +80,11 @@ public abstract class CustomActionButton
|
||||
/// </summary>
|
||||
protected ActionButton? Button { get; private set; }
|
||||
|
||||
internal void CreateButton(Transform parent)
|
||||
/// <summary>
|
||||
/// The method used to create the button.
|
||||
/// </summary>
|
||||
/// <param name="parent">The parent of the button.</param>
|
||||
public virtual void CreateButton(Transform parent)
|
||||
{
|
||||
if (Button)
|
||||
{
|
||||
@@ -142,10 +147,49 @@ public abstract class CustomActionButton
|
||||
}));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Allows you to change the button's location.
|
||||
/// </summary>
|
||||
/// <param name="location">The new location.</param>
|
||||
/// <param name="moveButton">Whether the button's position should change ingame.</param>
|
||||
public virtual void SetButtonLocation(ButtonLocation location, bool moveButton = true)
|
||||
{
|
||||
if (HudManager.Instance == null || Button == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this.Location = location;
|
||||
|
||||
if (!moveButton) return;
|
||||
|
||||
if (HudManagerPatches._bottomLeft == null || HudManagerPatches._bottomRight == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
switch (location)
|
||||
{
|
||||
case ButtonLocation.BottomLeft:
|
||||
var gridArrange = HudManagerPatches._bottomLeft.GetComponent<GridArrange>();
|
||||
var aspectPosition = HudManagerPatches._bottomLeft.GetComponent<AspectPosition>();
|
||||
|
||||
Button.transform.SetParent(HudManagerPatches._bottomLeft.transform);
|
||||
|
||||
gridArrange.Start();
|
||||
gridArrange.ArrangeChilds();
|
||||
aspectPosition.AdjustPosition();
|
||||
break;
|
||||
case ButtonLocation.BottomRight:
|
||||
Button.transform.SetParent(HudManagerPatches._bottomRight);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A utility function to reset the cooldown and/or effect of the button.
|
||||
/// </summary>
|
||||
public void ResetCooldownAndOrEffect()
|
||||
public virtual void ResetCooldownAndOrEffect()
|
||||
{
|
||||
Timer = Cooldown;
|
||||
if (EffectActive)
|
||||
@@ -160,7 +204,7 @@ public abstract class CustomActionButton
|
||||
/// A utility function to override the sprite of the button.
|
||||
/// </summary>
|
||||
/// <param name="sprite">The new sprite to override with.</param>
|
||||
public void OverrideSprite(Sprite sprite)
|
||||
public virtual void OverrideSprite(Sprite sprite)
|
||||
{
|
||||
if (Button != null)
|
||||
{
|
||||
@@ -172,7 +216,7 @@ public abstract class CustomActionButton
|
||||
/// A utility function to override the name of the button.
|
||||
/// </summary>
|
||||
/// <param name="name">The new name to override with.</param>
|
||||
public void OverrideName(string name)
|
||||
public virtual void OverrideName(string name)
|
||||
{
|
||||
Button?.OverrideText(name);
|
||||
}
|
||||
@@ -181,7 +225,7 @@ public abstract class CustomActionButton
|
||||
/// Set the button's timer.
|
||||
/// </summary>
|
||||
/// <param name="time">The time you want to set to.</param>
|
||||
public void SetTimer(float time)
|
||||
public virtual void SetTimer(float time)
|
||||
{
|
||||
Timer = Mathf.Clamp(time, -1, float.MaxValue);
|
||||
}
|
||||
@@ -190,7 +234,7 @@ public abstract class CustomActionButton
|
||||
/// Increase the button's timer.
|
||||
/// </summary>
|
||||
/// <param name="amount">The amount you want to increase by.</param>
|
||||
public void IncreaseTimer(float amount)
|
||||
public virtual void IncreaseTimer(float amount)
|
||||
{
|
||||
SetTimer(Timer + amount);
|
||||
}
|
||||
@@ -199,7 +243,7 @@ public abstract class CustomActionButton
|
||||
/// Decrease the button's timer.
|
||||
/// </summary>
|
||||
/// <param name="amount">The amount you want to decrease by.</param>
|
||||
public void DecreaseTimer(float amount)
|
||||
public virtual void DecreaseTimer(float amount)
|
||||
{
|
||||
SetTimer(Timer - amount);
|
||||
}
|
||||
@@ -208,7 +252,7 @@ public abstract class CustomActionButton
|
||||
/// Set the amount of uses this button has left.
|
||||
/// </summary>
|
||||
/// <param name="amount">The amount you want to set to.</param>
|
||||
public void SetUses(int amount)
|
||||
public virtual void SetUses(int amount)
|
||||
{
|
||||
UsesLeft = Mathf.Clamp(amount, 0, int.MaxValue);
|
||||
Button?.SetUsesRemaining(UsesLeft);
|
||||
@@ -218,7 +262,7 @@ public abstract class CustomActionButton
|
||||
/// Increase the amount of uses this button has left.
|
||||
/// </summary>
|
||||
/// <param name="amount">The amount you want to increase by. Default: 1.</param>
|
||||
public void IncreaseUses(int amount = 1)
|
||||
public virtual void IncreaseUses(int amount = 1)
|
||||
{
|
||||
SetUses(UsesLeft + amount);
|
||||
}
|
||||
@@ -227,7 +271,7 @@ public abstract class CustomActionButton
|
||||
/// Decrease the amount of uses this button has left.
|
||||
/// </summary>
|
||||
/// <param name="amount">The amount you want to decrease by. Default: 1.</param>
|
||||
public void DecreaseUses(int amount = 1)
|
||||
public virtual void DecreaseUses(int amount = 1)
|
||||
{
|
||||
SetUses(UsesLeft - amount);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using MiraAPI.Events.Mira;
|
||||
using MiraAPI.Events.Mira;
|
||||
using MiraAPI.PluginLoading;
|
||||
using Reactor.Utilities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
|
||||
namespace MiraAPI.Hud;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using HarmonyLib;
|
||||
using MiraAPI.Events;
|
||||
using MiraAPI.Events.Vanilla;
|
||||
using MiraAPI.Events.Vanilla.Meeting;
|
||||
using MiraAPI.Utilities;
|
||||
|
||||
namespace MiraAPI.Patches.Events;
|
||||
|
||||
@@ -13,7 +13,9 @@ namespace MiraAPI.Patches;
|
||||
public static class HudManagerPatches
|
||||
{
|
||||
// Custom buttons parent.
|
||||
private static GameObject? _bottomLeft;
|
||||
internal static GameObject? _bottomLeft;
|
||||
internal static Transform? _bottomRight;
|
||||
internal static Transform? _buttons;
|
||||
|
||||
/*
|
||||
/// <summary>
|
||||
@@ -34,12 +36,19 @@ public static class HudManagerPatches
|
||||
[HarmonyPatch(nameof(HudManager.Start))]
|
||||
public static void StartPostfix(HudManager __instance)
|
||||
{
|
||||
var buttons = __instance.transform.Find("Buttons");
|
||||
var bottomRight = buttons.Find("BottomRight");
|
||||
if (_buttons == null)
|
||||
{
|
||||
_buttons = __instance.transform.Find("Buttons");
|
||||
}
|
||||
|
||||
if (_bottomRight == null)
|
||||
{
|
||||
_bottomRight = _buttons.Find("BottomRight");
|
||||
}
|
||||
|
||||
if (_bottomLeft == null)
|
||||
{
|
||||
_bottomLeft = Object.Instantiate(bottomRight.gameObject, buttons);
|
||||
_bottomLeft = Object.Instantiate(_bottomRight.gameObject, _buttons);
|
||||
}
|
||||
|
||||
foreach (var t in _bottomLeft.GetComponentsInChildren<ActionButton>(true))
|
||||
@@ -59,7 +68,7 @@ public static class HudManagerPatches
|
||||
var location = button.Location switch
|
||||
{
|
||||
ButtonLocation.BottomLeft => _bottomLeft.transform,
|
||||
ButtonLocation.BottomRight => bottomRight,
|
||||
ButtonLocation.BottomRight => _bottomRight,
|
||||
_ => null,
|
||||
};
|
||||
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using HarmonyLib;
|
||||
using MiraAPI.Events;
|
||||
using MiraAPI.Events.Vanilla.Meeting;
|
||||
using MiraAPI.Roles;
|
||||
using MiraAPI.Utilities;
|
||||
using UnityEngine;
|
||||
@@ -20,6 +22,14 @@ public static class IntroCutscenePatches
|
||||
}
|
||||
}*/
|
||||
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(nameof(IntroCutscene.CoBegin))]
|
||||
public static void IntroBeginPatch(IntroCutscene __instance)
|
||||
{
|
||||
var @event = new IntroBeginEvent(__instance);
|
||||
MiraEventManager.InvokeEvent(@event);
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(nameof(IntroCutscene.BeginCrewmate))]
|
||||
public static bool BeginCrewmatePatch(IntroCutscene __instance)
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
using HarmonyLib;
|
||||
using MiraAPI.Events;
|
||||
using MiraAPI.Events.Vanilla.Meeting;
|
||||
using MiraAPI.Roles;
|
||||
|
||||
namespace MiraAPI.Patches.Roles;
|
||||
@@ -13,6 +15,13 @@ public static class EjectionPatches
|
||||
[HarmonyPatch(nameof(ExileController.Begin))]
|
||||
public static void BeginPostfix(ExileController __instance)
|
||||
{
|
||||
var @event = new EjectionEvent(__instance.initData.networkedPlayer.Object, __instance);
|
||||
MiraEventManager.InvokeEvent(@event);
|
||||
|
||||
if (@event.IsCancelled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (!__instance.initData.networkedPlayer || !__instance.initData.networkedPlayer.Role ||
|
||||
__instance.initData.networkedPlayer.Role is not ICustomRole role)
|
||||
{
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
using MiraAPI.Modifiers;
|
||||
using MiraAPI.PluginLoading;
|
||||
using MiraAPI.Utilities;
|
||||
using System.Text;
|
||||
using Reactor.Utilities;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI.Roles;
|
||||
@@ -63,7 +63,7 @@ public interface ICustomRole
|
||||
/// Gets the role chance option.
|
||||
/// </summary>
|
||||
/// <returns>The role chance option.</returns>
|
||||
public int? GetChance()
|
||||
public virtual int? GetChance()
|
||||
{
|
||||
if (!Configuration.CanModifyChance)
|
||||
{
|
||||
@@ -82,7 +82,7 @@ public interface ICustomRole
|
||||
/// Gets the role count option.
|
||||
/// </summary>
|
||||
/// <returns>The role count option.</returns>
|
||||
public int? GetCount()
|
||||
public virtual int? GetCount()
|
||||
{
|
||||
if (ParentMod.PluginConfig.TryGetEntry(NumConfigDefinition, out ConfigEntry<int> entry))
|
||||
{
|
||||
@@ -96,7 +96,7 @@ public interface ICustomRole
|
||||
/// Sets the role chance option.
|
||||
/// </summary>
|
||||
/// <param name="chance">The chance between 0 and 100.</param>
|
||||
public void SetChance(int chance)
|
||||
public virtual void SetChance(int chance)
|
||||
{
|
||||
if (!Configuration.CanModifyChance)
|
||||
{
|
||||
@@ -117,7 +117,7 @@ public interface ICustomRole
|
||||
/// Sets the role count option.
|
||||
/// </summary>
|
||||
/// <param name="count">The amount of this role between zero and its MaxRoleCount in the Configuration.</param>
|
||||
public void SetCount(int count)
|
||||
public virtual void SetCount(int count)
|
||||
{
|
||||
if (ParentMod.PluginConfig.TryGetEntry(NumConfigDefinition, out ConfigEntry<int> entry))
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user