mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-10-20 01:46:15 +00:00
Add proper support for modded roles in wiki
This commit is contained in:
1 parent
aa4dd24ac3
commit
a3668b3150
2 files changed
+70
No files matched your search
@@ -1,9 +1,11 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using HarmonyLib;
|
||||
using MiraAPI.Hud;
|
||||
using MiraAPI.Keybinds;
|
||||
using MiraAPI.LocalSettings;
|
||||
using MiraAPI.Roles;
|
||||
using MiraAPI.Utilities;
|
||||
using Reactor.Utilities;
|
||||
using Reactor.Utilities.Extensions;
|
||||
@@ -215,6 +217,33 @@ public static class HudManagerPatches
|
||||
__instance.SetActiveTab(0);
|
||||
return false;
|
||||
}
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPriority(Priority.First)]
|
||||
[HarmonyPatch(typeof(MatchInfoRolePanel), nameof(MatchInfoRolePanel.SetPanel))]
|
||||
public static bool SetPanel(MatchInfoRolePanel __instance, RoleBehaviour role, int numPerGame, int chancePerGame)
|
||||
{
|
||||
if (role is ICustomRole customRole)
|
||||
{
|
||||
__instance.roleName.text = customRole.RoleName;
|
||||
__instance.roleDescription.text = customRole.RoleDescription;
|
||||
__instance.roleIcon.sprite = customRole.Configuration.Icon?.LoadAsset();
|
||||
}
|
||||
else
|
||||
{
|
||||
__instance.roleName.text = role.NiceName;
|
||||
__instance.roleDescription.text = role.BlurbMed;
|
||||
__instance.roleIcon.sprite = role.RoleIconColor;
|
||||
}
|
||||
|
||||
__instance.roleIcon.SetSizeLimit(0.13f);
|
||||
__instance.roleCount.text = string.Format(CultureInfo.InvariantCulture, "{0} at {1}%", numPerGame.ToString(CultureInfo.InvariantCulture), chancePerGame);
|
||||
__instance.roleIcon.material.SetInt(PlayerMaterial.MaskLayer, 50);
|
||||
__instance.roleName.fontMaterial.SetFloat(__instance.STENCIL_NAME, 50f);
|
||||
__instance.roleDescription.fontMaterial.SetFloat(__instance.STENCIL_NAME, 50f);
|
||||
__instance.roleCount.fontMaterial.SetFloat(__instance.STENCIL_NAME, 50f);
|
||||
__instance.roleIcon.transform.localScale = new Vector3(4f, 4f, 1f);
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create custom buttons and arrange them on the hud.
|
||||
|
||||
@@ -378,6 +378,47 @@ public static class Extensions
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resizes a <see cref="SpriteRenderer"/> appropriate to the maximum pixel size without messing up ratios.
|
||||
/// </summary>
|
||||
/// <param name="sprite">The <see cref="SpriteRenderer"/> to adjust.</param>
|
||||
/// <param name="pixelSize">The scale for the sprite to be adjusted to.</param>
|
||||
public static void SetSizeLimit(this SpriteRenderer sprite, float pixelSize)
|
||||
{
|
||||
sprite.drawMode = SpriteDrawMode.Sliced;
|
||||
if (!sprite.sprite)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
float spriteWidth = sprite.sprite.rect.width;
|
||||
float spriteHeight = sprite.sprite.rect.height;
|
||||
|
||||
if (spriteWidth < spriteHeight)
|
||||
{
|
||||
sprite.size = new Vector2(pixelSize * spriteWidth / spriteHeight, pixelSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
sprite.size = new Vector2(pixelSize, pixelSize * spriteHeight / spriteWidth);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resizes a <see cref="SpriteRenderer"/> appropriate to the maximum pixel size without messing up ratios.
|
||||
/// </summary>
|
||||
/// <param name="spriteObj">The <see cref="GameObject"/> to adjust.</param>
|
||||
/// <param name="pixelSize">The scale for the sprite to be adjusted to.</param>
|
||||
public static void SetSizeLimit(this GameObject spriteObj, float pixelSize)
|
||||
{
|
||||
if (!spriteObj.TryGetComponent<SpriteRenderer>(out var sprite))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
sprite.SetSizeLimit(pixelSize);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a cache of <see cref="PlayerControl"/>'s <see cref="PlayerVoteData"/> to improve performance.
|
||||
/// </summary>
|
||||
|
||||
Reference in new issue
Block a user