mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-10-20 01:46:15 +00:00
Sync local settings branch with dev
This commit is contained in:
15 files changed
+132
-27
No files matched your search
@@ -17,10 +17,8 @@ public class FreezeButton : CustomActionButton<PlayerControl>
|
||||
|
||||
public override float Cooldown => OptionGroupSingleton<FreezerRoleSettings>.Instance.FreezeDuration;
|
||||
|
||||
public override int MaxUses => (int)OptionGroupSingleton<FreezerRoleSettings>.Instance.FreezeUses;
|
||||
|
||||
public override LoadableAsset<Sprite> Sprite => ExampleAssets.ExampleButton;
|
||||
public override KeyboardKeyCode Defaultkeybind => KeyboardKeyCode.T;
|
||||
public override KeyboardKeyCode? DefaultKeybind => KeyboardKeyCode.T;
|
||||
public override ModifierKey Modifier1 => ModifierKey.Control;
|
||||
|
||||
protected override void OnClick()
|
||||
|
||||
@@ -16,7 +16,7 @@ public class MeetingButton : CustomActionButton
|
||||
public override int MaxUses => 3;
|
||||
|
||||
public override LoadableAsset<Sprite> Sprite => ExampleAssets.ExampleButton;
|
||||
public override KeyboardKeyCode Defaultkeybind => KeyboardKeyCode.P;
|
||||
public override KeyboardKeyCode? DefaultKeybind => KeyboardKeyCode.P;
|
||||
public override ModifierKey Modifier1 => ModifierKey.Control;
|
||||
public override ModifierKey Modifier2 => ModifierKey.Shift;
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ public class NeutralKillerButton : CustomActionButton
|
||||
public override string Name => "Win Game";
|
||||
public override float Cooldown => 0f;
|
||||
public override LoadableAsset<Sprite> Sprite => ExampleAssets.ExampleButton;
|
||||
public override KeyboardKeyCode Defaultkeybind => KeyboardKeyCode.K;
|
||||
public override KeyboardKeyCode? DefaultKeybind => KeyboardKeyCode.K;
|
||||
protected override void OnClick()
|
||||
{
|
||||
CustomGameOver.Trigger<NeutralKillerGameOver>([PlayerControl.LocalPlayer.Data]);
|
||||
|
||||
@@ -22,7 +22,7 @@ public class TeleportButton : CustomActionButton
|
||||
public override LoadableAsset<Sprite> Sprite => ExampleAssets.TeleportButton;
|
||||
public override Color TextOutlineColor => new Color32(221, 176, 152, 255);
|
||||
public static bool IsZoom { get; private set; }
|
||||
public override KeyboardKeyCode Defaultkeybind => KeyboardKeyCode.M;
|
||||
public override KeyboardKeyCode? DefaultKeybind => KeyboardKeyCode.M;
|
||||
public override bool Enabled(RoleBehaviour? role)
|
||||
{
|
||||
return role is TeleporterRole;
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
namespace MiraAPI.Events.Vanilla.Gameplay;
|
||||
|
||||
/// <summary>
|
||||
/// The event that is invoked when the player's role is shown on the intro cutscene. Non cancelable.
|
||||
/// </summary>
|
||||
public class IntroRoleRevealEvent : MiraEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the instance of the IntroCutscene.
|
||||
/// </summary>
|
||||
public IntroCutscene IntroCutscene { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="IntroRoleRevealEvent"/> class.
|
||||
/// </summary>
|
||||
/// <param name="introCutscene">The intro cutscene.</param>
|
||||
public IntroRoleRevealEvent(IntroCutscene introCutscene)
|
||||
{
|
||||
IntroCutscene = introCutscene;
|
||||
}
|
||||
}
|
||||
@@ -57,23 +57,23 @@ public abstract class CustomActionButton
|
||||
public virtual int MaxUses => 0;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the current key binding for this button.
|
||||
/// Gets the current key binding for this button. If null, no keybind will be added.
|
||||
/// </summary>
|
||||
public abstract KeyboardKeyCode Defaultkeybind { get; }
|
||||
public virtual KeyboardKeyCode? DefaultKeybind { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The first optional modifier key (e.g., Control, Shift, Alt) that must be held with the main key to activate the button.
|
||||
/// Gets the first optional modifier key (e.g., Control, Shift, Alt) that must be held with the main key to activate the button.
|
||||
/// </summary>
|
||||
public virtual ModifierKey Modifier1 => ModifierKey.None;
|
||||
|
||||
/// <summary>
|
||||
/// The second optional modifier key.
|
||||
/// Gets the second optional modifier key.
|
||||
/// Set to <see cref="ModifierKey.None"/> if unused.
|
||||
/// </summary>
|
||||
public virtual ModifierKey Modifier2 => ModifierKey.None;
|
||||
|
||||
/// <summary>
|
||||
/// The third optional modifier key.
|
||||
/// Gets the third optional modifier key.
|
||||
/// Set to <see cref="ModifierKey.None"/> if unused.
|
||||
/// </summary>
|
||||
public virtual ModifierKey Modifier3 => ModifierKey.None;
|
||||
@@ -126,7 +126,17 @@ public abstract class CustomActionButton
|
||||
/// <summary>
|
||||
/// Gets the gameObject used for the keybind icon.
|
||||
/// </summary>
|
||||
public GameObject KeybindIcon { get; set; }
|
||||
public GameObject? KeybindIcon { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the keybind entry for the button.
|
||||
/// </summary>
|
||||
private KeybindManager.KeybindEntry? KeybindEntry { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the keybind icon text.
|
||||
/// </summary>
|
||||
private TextMeshPro? KeybindText { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The method used to create the button.
|
||||
@@ -200,12 +210,18 @@ public abstract class CustomActionButton
|
||||
}
|
||||
}));
|
||||
|
||||
KeybindIcon = Object.Instantiate(Button.usesRemainingSprite.gameObject, Button.transform);
|
||||
KeybindIcon.GetComponent<SpriteRenderer>().sprite = MiraAssets.KeybindButton.LoadAsset();
|
||||
KeybindIcon.transform.GetChild(0).GetComponent<TextMeshPro>().text =
|
||||
KeybindManager.GetEntries().First(x => x.Id == $"{Name}_Keybind").Key.ToString();
|
||||
KeybindIcon.name = "KeybindIcon";
|
||||
KeybindIcon.transform.localPosition = new(0.341f, 0.374f, -0.1f);
|
||||
if (DefaultKeybind != KeyboardKeyCode.None)
|
||||
{
|
||||
KeybindEntry = KeybindManager.GetEntries().First(x => x.Id == $"{Name}_Keybind");
|
||||
KeybindIcon =
|
||||
Helpers.CreateKeybindIcon(
|
||||
Button.gameObject,
|
||||
KeybindEntry.Key,
|
||||
new Vector3(MaxUses <= 0 ? -0.4f : 0.4f, 0.45f, -9f)
|
||||
);
|
||||
KeybindText = KeybindIcon.transform.GetChild(0).GetComponent<TextMeshPro>();
|
||||
Button.usesRemainingSprite.transform.localPosition = new(-0.341f, 0.45f, -0.1f);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -464,6 +480,11 @@ public abstract class CustomActionButton
|
||||
/// <param name="playerControl">The local PlayerControl.</param>
|
||||
public virtual void FixedUpdateHandler(PlayerControl playerControl)
|
||||
{
|
||||
if (KeybindText != null && KeybindEntry != null)
|
||||
{
|
||||
KeybindText.text = KeybindEntry.Key.ToString();
|
||||
}
|
||||
|
||||
if (Timer >= 0)
|
||||
{
|
||||
if (!TimerPaused)
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.Collections.ObjectModel;
|
||||
using System.Reflection;
|
||||
using MiraAPI.Events.Mira;
|
||||
using MiraAPI.PluginLoading;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI.Hud;
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ public static class ModifierExtensions
|
||||
/// </summary>
|
||||
/// <param name="target">The player to remove the modifier from.</param>
|
||||
/// <param name="uniqueId">The unique ID of the modifier.</param>
|
||||
[MethodRpc((uint)MiraRpc.RemoveModifier, SendImmediately = true)]
|
||||
[MethodRpc((uint)MiraRpc.RemoveModifier)]
|
||||
public static void RpcRemoveModifier(this PlayerControl target, Guid uniqueId)
|
||||
{
|
||||
target.RemoveModifier(uniqueId);
|
||||
|
||||
@@ -29,7 +29,7 @@ public static class CustomMurderRpc
|
||||
/// <param name="teleportMurderer">Should the killer be snapped to the dead player.</param>
|
||||
/// <param name="showKillAnim">Should the kill animation be shown.</param>
|
||||
/// <param name="playKillSound">Should the kill sound be played.</param>
|
||||
[MethodRpc((uint)MiraRpc.CustomMurder, LocalHandling = RpcLocalHandling.Before, SendImmediately = true)]
|
||||
[MethodRpc((uint)MiraRpc.CustomMurder, LocalHandling = RpcLocalHandling.Before)]
|
||||
public static void RpcCustomMurder(
|
||||
this PlayerControl source,
|
||||
PlayerControl target,
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using HarmonyLib;
|
||||
using MiraAPI.Hud;
|
||||
using MiraAPI.Keybinds;
|
||||
using MiraAPI.Utilities;
|
||||
using Reactor.Utilities;
|
||||
using Reactor.Utilities.Extensions;
|
||||
using Rewired;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
@@ -22,6 +25,8 @@ public static class HudManagerPatches
|
||||
public static Transform? BottomRight { get; private set; }
|
||||
public static Transform? Buttons { get; private set; }
|
||||
|
||||
private static Dictionary<TextMeshPro, int> VanillaKeybindIcons = new();
|
||||
|
||||
/*
|
||||
/// <summary>
|
||||
/// Trigger hudstart on current custom gamemode
|
||||
@@ -96,6 +101,26 @@ public static class HudManagerPatches
|
||||
gridArrange.ArrangeChilds();
|
||||
|
||||
aspectPosition.AdjustPosition();
|
||||
|
||||
var keybindIconPos = new Vector3(-0.4f, 0.4f, -9f);
|
||||
var vanillaButtons = new Dictionary<GameObject, int>
|
||||
{
|
||||
{ __instance.KillButton.gameObject, 8 },
|
||||
{ __instance.UseButton.gameObject, 6 },
|
||||
{ __instance.ReportButton.gameObject, 7 },
|
||||
{ __instance.ImpostorVentButton.gameObject, 50 },
|
||||
{ __instance.SabotageButton.gameObject, 4 },
|
||||
};
|
||||
|
||||
foreach (var kvp in vanillaButtons)
|
||||
{
|
||||
var buttonObj = kvp.Key;
|
||||
var actionId = kvp.Value;
|
||||
|
||||
var key = Helpers.GetKeybindByActionId(actionId);
|
||||
var icon = Helpers.CreateKeybindIcon(buttonObj, key, keybindIconPos);
|
||||
VanillaKeybindIcons.Add(icon.transform.GetChild(0).GetComponent<TextMeshPro>(), actionId);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -132,8 +157,10 @@ public static class HudManagerPatches
|
||||
[HarmonyPostfix]
|
||||
public static void StartPostfix()
|
||||
{
|
||||
if (AmongUsClient.Instance.GameState != InnerNet.InnerNetClient.GameStates.Started) return;
|
||||
if (PlayerControl.LocalPlayer.Data.IsDead) return;
|
||||
foreach (var btnIcon in VanillaKeybindIcons)
|
||||
{
|
||||
btnIcon.Key.text = Helpers.GetKeybindByActionId(btnIcon.Value).ToString();
|
||||
}
|
||||
|
||||
foreach (var entry in KeybindManager.GetEntries())
|
||||
{
|
||||
|
||||
@@ -29,6 +29,16 @@ public static class IntroCutscenePatches
|
||||
MiraEventManager.InvokeEvent(@event);
|
||||
}
|
||||
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(typeof(IntroCutscene._ShowRole_d__41), nameof(IntroCutscene._ShowRole_d__41.MoveNext))]
|
||||
[HarmonyPriority(Priority.Last)]
|
||||
public static void ShowRolePatch(IntroCutscene._ShowRole_d__41 __instance)
|
||||
{
|
||||
var realInstance = __instance.__4__this;
|
||||
var @event = new IntroRoleRevealEvent(realInstance);
|
||||
MiraEventManager.InvokeEvent(@event);
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(nameof(IntroCutscene.BeginImpostor))]
|
||||
[HarmonyPatch(nameof(IntroCutscene.BeginCrewmate))]
|
||||
|
||||
@@ -18,6 +18,7 @@ using MiraAPI.Roles;
|
||||
using MiraAPI.Utilities;
|
||||
using Reactor.Networking;
|
||||
using Reactor.Utilities;
|
||||
using Rewired;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI.PluginLoading;
|
||||
@@ -137,9 +138,13 @@ public sealed class MiraPluginManager
|
||||
|
||||
foreach (var button in CustomButtonManager.Buttons)
|
||||
{
|
||||
KeybindManager.Register($"{button.Name}_Keybind", $"Keybind for {button.Name}", button.Defaultkeybind, button.ClickHandler, modifier1: button.Modifier1, modifier2: button.Modifier2, modifier3: button.Modifier3);
|
||||
if (button.DefaultKeybind == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
KeybindManager.Register($"{button.Name}_Keybind", $"Keybind for {button.Name}", (KeyboardKeyCode)button.DefaultKeybind, button.ClickHandler, modifier1: button.Modifier1, modifier2: button.Modifier2, modifier3: button.Modifier3);
|
||||
|
||||
Logger<MiraApiPlugin>.Info($"Registered keybind for button '{button.GetType().Name}' with default key {button.Defaultkeybind}.");
|
||||
Logger<MiraApiPlugin>.Info($"Registered keybind for button '{button.GetType().Name}' with default key {(KeyboardKeyCode)button.DefaultKeybind}.");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ public static class Extensions
|
||||
/// <param name="timer">The current timer value.</param>
|
||||
/// <param name="maxTimer">The maximum timer value.</param>
|
||||
/// <param name="format">The format string to use for the timer text.</param>
|
||||
public static void SetCooldownFormat(this ActionButton button, float timer, float maxTimer, string format = "0")
|
||||
public static void SetCooldownFormat(this ActionButton? button, float timer, float maxTimer, string format = "0")
|
||||
{
|
||||
var num = Mathf.Clamp(timer / maxTimer, 0f, 1f);
|
||||
button.isCoolingDown = num > 0f;
|
||||
|
||||
@@ -5,6 +5,7 @@ using System.Globalization;
|
||||
using System.Linq;
|
||||
using Il2CppSystem.IO;
|
||||
using MiraAPI.Keybinds;
|
||||
using MiraAPI.Utilities.Assets;
|
||||
using Rewired;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
@@ -25,6 +26,27 @@ public static class Helpers
|
||||
{
|
||||
return [.. GameData.Instance.AllPlayers.ToArray().Where(x => !x.IsDead && !x.Disconnected && x.Object).Select(x => x.Object)];
|
||||
}
|
||||
internal static GameObject CreateKeybindIcon(GameObject button, KeyboardKeyCode keyCode, Vector3 localPos)
|
||||
{
|
||||
var keybindIcon = Object.Instantiate(HudManager.Instance.AbilityButton.usesRemainingSprite.gameObject, button.transform);
|
||||
keybindIcon.GetComponent<SpriteRenderer>().sprite = MiraAssets.KeybindButton.LoadAsset();
|
||||
keybindIcon.transform.GetChild(0).GetComponent<TextMeshPro>().text = keyCode.ToString();
|
||||
keybindIcon.name = "KeybindIcon";
|
||||
keybindIcon.transform.localPosition = localPos;
|
||||
return keybindIcon;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the keybind for an action with ReInput.
|
||||
/// </summary>
|
||||
/// <param name="actionId">The action ID.</param>
|
||||
/// <returns>The keyboard key code.</returns>
|
||||
public static KeyboardKeyCode GetKeybindByActionId(int actionId)
|
||||
{
|
||||
var player = ReInput.players.GetPlayer(0);
|
||||
return player.controllers.maps.GetFirstElementMapWithAction(ControllerType.Keyboard, actionId, false)
|
||||
.keyboardKeyCode;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether a given probability check succeeds.
|
||||
|
||||
@@ -71,7 +71,7 @@ public static class VotingUtils
|
||||
/// <param name="source">The player who is sending the RPC. Should be the host.</param>
|
||||
/// <param name="voterId">The player who voted.</param>
|
||||
/// <param name="votedFor">The player who the voter voted for.</param>
|
||||
[MethodRpc((uint)MiraRpc.RemoveVote, SendImmediately = true)]
|
||||
[MethodRpc((uint)MiraRpc.RemoveVote)]
|
||||
public static void RpcRemoveVote(PlayerControl source, byte voterId, byte votedFor)
|
||||
{
|
||||
if (!source.IsHost()) return;
|
||||
@@ -107,7 +107,7 @@ public static class VotingUtils
|
||||
/// <param name="source">The player who sent this RPC.</param>
|
||||
/// <param name="srcPlayerId">The id of the player who casted the vote.</param>
|
||||
/// <param name="suspectPlayerId">The voted player's id.</param>
|
||||
[MethodRpc((uint)MiraRpc.CastVote, SendImmediately = true)]
|
||||
[MethodRpc((uint)MiraRpc.CastVote)]
|
||||
public static void RpcCastVote(PlayerControl source, byte srcPlayerId, byte suspectPlayerId)
|
||||
{
|
||||
CustomCastVote(srcPlayerId, suspectPlayerId);
|
||||
|
||||
Reference in new issue
Block a user