Skip to content

Commit

Permalink
Merge branch 'master' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
ang-xd committed Aug 28, 2024
2 parents 7cb103f + 19c7e38 commit 9fc5044
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 13 deletions.
2 changes: 1 addition & 1 deletion MiraAPI.Example/Buttons/Teleporter/TeleportButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ protected override void FixedUpdate(PlayerControl playerControl)
if (Input.GetKey(KeyCode.Mouse0))
{
playerControl.NetTransform.RpcSnapTo(Camera.main.ScreenToWorldPoint(Input.mousePosition));
ResetCooldown();
ResetCooldownAndOrEffect();
}
}

Expand Down
5 changes: 5 additions & 0 deletions MiraAPI/GameOptions/ModdedOptionsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ internal static void HandleSyncOptions(NetData[] data)
plugin.PluginConfig.Save();
plugin.PluginConfig.SaveOnConfigSet = true;
}

if (LobbyInfoPane.Instance)
{
LobbyInfoPane.Instance.RefreshPane();
}
}


Expand Down
20 changes: 9 additions & 11 deletions MiraAPI/Hud/CustomActionButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ internal void CreateButton(Transform parent)
}

/// <summary>
/// A utility function to reset the cooldown of the button.
/// A utility function to reset the cooldown and/or effect of the button.
/// </summary>
public void ResetCooldown()
public void ResetCooldownAndOrEffect()
{
Timer = Cooldown;
if (EffectActive)
Expand Down Expand Up @@ -136,13 +136,13 @@ public void OverrideName(string name)
}

/// <summary>
/// A utility function that runs with the local PlayerControl's FixedUpdate.
/// A utility function that runs with the local PlayerControl's FixedUpdate if the button is enabled.
/// </summary>
/// <param name="playerControl">the local PlayerControl</param>
protected virtual void FixedUpdate(PlayerControl playerControl) { }

/// <summary>
/// Runs when the button is clicked.
/// Callback method for the button click event.
/// </summary>
protected abstract void OnClick();

Expand All @@ -154,7 +154,8 @@ protected virtual void FixedUpdate(PlayerControl playerControl) { }
public abstract bool Enabled(RoleBehaviour? role);

/// <summary>
/// Given that there is an effect, this method that runs when the effect ends.
/// Given that there is an effect, this method runs when the effect ends.
/// <br /> <br /> THIS IS A CALLBACK METHOD! Use <see cref="ResetCooldownAndOrEffect" /> if you want to end the effect.
/// </summary>
public virtual void OnEffectEnd() { }

Expand Down Expand Up @@ -270,18 +271,15 @@ public abstract class CustomActionButton<T> : CustomActionButton where T : MonoB
/// <summary>
/// Determines if the target object is valid.
/// </summary>
public virtual bool IsTargetValid(T target)
public virtual bool IsTargetValid(T? target)
{
return target;
}

/// <summary>
/// The method used to get the target object.
/// </summary>
public virtual T? GetTarget()
{
return PlayerControl.LocalPlayer.GetNearestObjectOfType<T>(Distance, ColliderTag, IsTargetValid);
}
public abstract T? GetTarget();

/// <summary>
/// Sets the outline of the target object.
Expand All @@ -298,7 +296,7 @@ public override bool CanUse()
SetOutline(false);
}

Target = newTarget;
Target = IsTargetValid(newTarget) ? newTarget : null;
SetOutline(true);

return base.CanUse() && Target;
Expand Down
2 changes: 1 addition & 1 deletion MiraAPI/Patches/MeetingHudPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public static void VotingCompletePostfix()
{
foreach (var customActionButton in CustomButtonManager.CustomButtons)
{
customActionButton.ResetCooldown();
customActionButton.ResetCooldownAndOrEffect();
}
}
}
9 changes: 9 additions & 0 deletions MiraAPI/Patches/Options/RoleSettingMenuPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,20 @@ private static void ChangeTab(RoleBehaviour role, RolesSettingsMenu __instance)
__instance.roleScreenshot.drawMode = SpriteDrawMode.Sliced;
__instance.roleHeaderSprite.color = customRole.RoleColor;
__instance.roleHeaderText.color = customRole.RoleColor.GetAlternateColor();

var bg = __instance.AdvancedRolesSettings.transform.Find("Background");
bg.localPosition = new Vector3(1.4041f, -7.08f, 0);
bg.GetComponent<SpriteRenderer>().size = new Vector2(89.4628f, 100);

CreateAdvancedSettings(__instance, role);

foreach (var optionBehaviour in __instance.advancedSettingChildren)
{
if (optionBehaviour.IsCustom())
{
continue;
}

optionBehaviour.OnValueChanged = new Action<OptionBehaviour>(__instance.ValueChanged);
if (AmongUsClient.Instance && !AmongUsClient.Instance.AmHost)
{
Expand Down
5 changes: 5 additions & 0 deletions MiraAPI/Roles/CustomRoleManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,5 +221,10 @@ internal static void HandleSyncRoleOptions(NetData[] data)
plugin.PluginConfig.Save();
plugin.PluginConfig.SaveOnConfigSet = oldConfigSetting[plugin];
}

if (LobbyInfoPane.Instance)
{
LobbyInfoPane.Instance.RefreshPane();
}
}
}
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ Roles are very simple in Mira API. There are 3 things you need to do to create a
2. Implement the `ICustomRole` interface from Mira API.
3. Add the `[RegisterCustomRole]` attribute to the class.

**Disclaimer: Make sure your plugin class has the following attribute `[ReactorModFlags(ModFlags.RequireOnAllClients)]` or else your roles will not register correctly.**

Note: For step 1, if you are making neutral roles, choose either `CrewmateRole` or `ImpostorRole` as the base depending on if it can kill or not!

Mira API handles everything else, from adding the proper options to the settings menu, to managing the role assignment at the start of the game. There are no extra steps on the developer's part.
Expand Down

0 comments on commit 9fc5044

Please sign in to comment.