mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-10-20 01:46:15 +00:00
fix oversights + errors
This commit is contained in:
10 files changed
+60
-41
No files matched your search
@@ -21,7 +21,7 @@ public record struct CmykColor(float c, float m, float y, float k, float a = 1f)
|
||||
/// Implicitly converts a <see cref="CmykColor"/> to a Unity <see cref="Color"/>.
|
||||
/// </summary>
|
||||
/// <param name="c">The color being converted.</param>
|
||||
public static implicit operator Color(in CmykColor c)
|
||||
public static implicit operator Color(CmykColor c)
|
||||
{
|
||||
return ToColor(c);
|
||||
}
|
||||
@@ -30,7 +30,7 @@ public record struct CmykColor(float c, float m, float y, float k, float a = 1f)
|
||||
/// Implicitly converts a Unity <see cref="Color"/> to a <see cref="CmykColor"/>.
|
||||
/// </summary>
|
||||
/// <param name="c">The color being converted.</param>
|
||||
public static implicit operator CmykColor(in Color c)
|
||||
public static implicit operator CmykColor(Color c)
|
||||
{
|
||||
return FromColor(c);
|
||||
}
|
||||
@@ -40,7 +40,7 @@ public record struct CmykColor(float c, float m, float y, float k, float a = 1f)
|
||||
/// </summary>
|
||||
/// <param name="cmyk">The CMYK color to convert.</param>
|
||||
/// <returns>A Unity <see cref="Color"/> representing the same visual color.</returns>
|
||||
public static Color ToColor(in CmykColor cmyk)
|
||||
public static Color ToColor(CmykColor cmyk)
|
||||
{
|
||||
var r = (1f - cmyk.c) * (1f - cmyk.k);
|
||||
var g = (1f - cmyk.m) * (1f - cmyk.k);
|
||||
@@ -54,7 +54,7 @@ public record struct CmykColor(float c, float m, float y, float k, float a = 1f)
|
||||
/// </summary>
|
||||
/// <param name="color">The Unity Color to convert.</param>
|
||||
/// <returns>A <see cref="CmykColor"/> representing the same visual color.</returns>
|
||||
public static CmykColor FromColor(in Color color)
|
||||
public static CmykColor FromColor(Color color)
|
||||
{
|
||||
var r = color.r;
|
||||
var g = color.g;
|
||||
@@ -81,7 +81,7 @@ public record struct CmykColor(float c, float m, float y, float k, float a = 1f)
|
||||
/// <param name="b">The ending color.</param>
|
||||
/// <param name="t">The interpolation value between the two colors, clamped to a 0 to 1 range.</param>
|
||||
/// <returns>The interpolated <see cref="CmykColor"/>.</returns>
|
||||
public static CmykColor Lerp(in CmykColor a, in CmykColor b, float t)
|
||||
public static CmykColor Lerp(CmykColor a, CmykColor b, float t)
|
||||
{
|
||||
return LerpUnclamped(a, b, MathUtilities.Clamp01(t));
|
||||
}
|
||||
@@ -93,7 +93,7 @@ public record struct CmykColor(float c, float m, float y, float k, float a = 1f)
|
||||
/// <param name="b">The ending color.</param>
|
||||
/// <param name="t">The interpolation value between the two colors.</param>
|
||||
/// <returns>The interpolated <see cref="CmykColor"/>.</returns>
|
||||
public static CmykColor LerpUnclamped(in CmykColor a, in CmykColor b, float t)
|
||||
public static CmykColor LerpUnclamped(CmykColor a, CmykColor b, float t)
|
||||
{
|
||||
return new CmykColor(
|
||||
MathUtilities.LerpUnclamped(a.c, b.c, t),
|
||||
|
||||
@@ -20,7 +20,7 @@ public record struct HsbColor(float h, float s, float b, float a = 1f)
|
||||
/// Implicitly converts an <see cref="HsbColor"/> to a Unity <see cref="Color"/>.
|
||||
/// </summary>
|
||||
/// <param name="c">The color being converted.</param>
|
||||
public static implicit operator Color(in HsbColor c)
|
||||
public static implicit operator Color(HsbColor c)
|
||||
{
|
||||
return ToColor(c);
|
||||
}
|
||||
@@ -29,7 +29,7 @@ public record struct HsbColor(float h, float s, float b, float a = 1f)
|
||||
/// Implicitly converts a Unity <see cref="Color"/> to an <see cref="HsbColor"/>.
|
||||
/// </summary>
|
||||
/// <param name="c">The color being converted.</param>
|
||||
public static implicit operator HsbColor(in Color c)
|
||||
public static implicit operator HsbColor(Color c)
|
||||
{
|
||||
return FromColor(c);
|
||||
}
|
||||
@@ -39,7 +39,7 @@ public record struct HsbColor(float h, float s, float b, float a = 1f)
|
||||
/// </summary>
|
||||
/// <param name="hsb">The HSB color to convert.</param>
|
||||
/// <returns>A Unity <see cref="Color"/> representing the same visual color.</returns>
|
||||
public static Color ToColor(in HsbColor hsb)
|
||||
public static Color ToColor(HsbColor hsb)
|
||||
{
|
||||
if (hsb.s <= float.Epsilon)
|
||||
return new Color(MathUtilities.Clamp01(hsb.b), MathUtilities.Clamp01(hsb.b), MathUtilities.Clamp01(hsb.b), hsb.a);
|
||||
@@ -72,7 +72,7 @@ public record struct HsbColor(float h, float s, float b, float a = 1f)
|
||||
/// </summary>
|
||||
/// <param name="color">The Unity Color to convert.</param>
|
||||
/// <returns>An <see cref="HsbColor"/> representing the same visual color.</returns>
|
||||
public static HsbColor FromColor(in Color color)
|
||||
public static HsbColor FromColor(Color color)
|
||||
{
|
||||
var max = MathF.Max(color.r, MathF.Max(color.g, color.b));
|
||||
var min = MathF.Min(color.r, MathF.Min(color.g, color.b));
|
||||
@@ -108,7 +108,7 @@ public record struct HsbColor(float h, float s, float b, float a = 1f)
|
||||
/// <param name="b">The ending color.</param>
|
||||
/// <param name="t">The interpolation value between the two colors, clamped to a 0 to 1 range.</param>
|
||||
/// <returns>The interpolated <see cref="HsbColor"/>.</returns>
|
||||
public static HsbColor Lerp(in HsbColor a, in HsbColor b, float t)
|
||||
public static HsbColor Lerp(HsbColor a, HsbColor b, float t)
|
||||
{
|
||||
return LerpUnclamped(a, b, MathUtilities.Clamp01(t));
|
||||
}
|
||||
@@ -120,7 +120,7 @@ public record struct HsbColor(float h, float s, float b, float a = 1f)
|
||||
/// <param name="b">The ending color.</param>
|
||||
/// <param name="t">The interpolation value between the two colors.</param>
|
||||
/// <returns>The interpolated <see cref="HsbColor"/>.</returns>
|
||||
public static HsbColor LerpUnclamped(in HsbColor a, in HsbColor b, float t)
|
||||
public static HsbColor LerpUnclamped(HsbColor a, HsbColor b, float t)
|
||||
{
|
||||
var hueDifference = MathUtilities.Repeat(b.h - a.h, 1f);
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ public record struct HslColor(float h, float s, float l, float a = 1f)
|
||||
/// Implicitly converts an <see cref="HslColor"/> to a Unity <see cref="Color"/>.
|
||||
/// </summary>
|
||||
/// <param name="c">The color being converted.</param>
|
||||
public static implicit operator Color(in HslColor c)
|
||||
public static implicit operator Color(HslColor c)
|
||||
{
|
||||
return ToColor(c);
|
||||
}
|
||||
@@ -29,7 +29,7 @@ public record struct HslColor(float h, float s, float l, float a = 1f)
|
||||
/// Implicitly converts a Unity <see cref="Color"/> to an <see cref="HslColor"/>.
|
||||
/// </summary>
|
||||
/// <param name="c">The color being converted.</param>
|
||||
public static implicit operator HslColor(in Color c)
|
||||
public static implicit operator HslColor(Color c)
|
||||
{
|
||||
return FromColor(c);
|
||||
}
|
||||
@@ -39,7 +39,7 @@ public record struct HslColor(float h, float s, float l, float a = 1f)
|
||||
/// </summary>
|
||||
/// <param name="hsl">The HSL color to convert.</param>
|
||||
/// <returns>A Unity <see cref="Color"/> representing the same visual color.</returns>
|
||||
public static Color ToColor(in HslColor hsl)
|
||||
public static Color ToColor(HslColor hsl)
|
||||
{
|
||||
if (hsl.s <= float.Epsilon)
|
||||
return new Color(MathUtilities.Clamp01(hsl.l), MathUtilities.Clamp01(hsl.l), MathUtilities.Clamp01(hsl.l), hsl.a);
|
||||
@@ -68,7 +68,7 @@ public record struct HslColor(float h, float s, float l, float a = 1f)
|
||||
/// </summary>
|
||||
/// <param name="color">The Unity Color to convert.</param>
|
||||
/// <returns>An <see cref="HslColor"/> representing the same visual color.</returns>
|
||||
public static HslColor FromColor(in Color color)
|
||||
public static HslColor FromColor(Color color)
|
||||
{
|
||||
var max = MathF.Max(color.r, MathF.Max(color.g, color.b));
|
||||
var min = MathF.Min(color.r, MathF.Min(color.g, color.b));
|
||||
@@ -104,7 +104,7 @@ public record struct HslColor(float h, float s, float l, float a = 1f)
|
||||
/// <param name="b">The ending color.</param>
|
||||
/// <param name="t">The interpolation value between the two colors, clamped to a 0 to 1 range.</param>
|
||||
/// <returns>The interpolated <see cref="HslColor"/>.</returns>
|
||||
public static HslColor Lerp(in HslColor a, in HslColor b, float t)
|
||||
public static HslColor Lerp(HslColor a, HslColor b, float t)
|
||||
{
|
||||
return LerpUnclamped(a, b, MathUtilities.Clamp01(t));
|
||||
}
|
||||
@@ -116,7 +116,7 @@ public record struct HslColor(float h, float s, float l, float a = 1f)
|
||||
/// <param name="b">The ending color.</param>
|
||||
/// <param name="t">The interpolation value between the two colors.</param>
|
||||
/// <returns>The interpolated <see cref="HslColor"/>.</returns>
|
||||
public static HslColor LerpUnclamped(in HslColor a, in HslColor b, float t)
|
||||
public static HslColor LerpUnclamped(HslColor a, HslColor b, float t)
|
||||
{
|
||||
var hueDifference = MathUtilities.Repeat(b.h - a.h, 1f);
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ public static class PaletteManager
|
||||
Palette.TextColors = Palette.TextColors.ToArray().AddRangeToArray(colors);
|
||||
Palette.TextOutlineColors = Palette.TextOutlineColors.ToArray().AddRangeToArray(shadowColors);
|
||||
|
||||
for (var i = 0; i < originalLength + CustomColors.Count; i++)
|
||||
for (var i = 0; i < CustomColors.Count; i++)
|
||||
ColorIdToColorMap[i + originalLength] = CustomColors[i];
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ public static class PaletteManager
|
||||
return !ColorIdToColorMap.TryGetValue(colorId, out var custom)
|
||||
? Palette.PlayerColors[colorId]
|
||||
: (custom is VariableColor variable
|
||||
? variable.EvaluateMainColor()
|
||||
? variable.EvaluateMainColor(Time.time)
|
||||
: custom.InternalMainColor);
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ public static class PaletteManager
|
||||
return !ColorIdToColorMap.TryGetValue(colorId, out var custom)
|
||||
? Palette.ShadowColors[colorId]
|
||||
: (custom is VariableColor variable
|
||||
? variable.EvaluateShadowColor()
|
||||
? variable.EvaluateShadowColor(Time.time)
|
||||
: custom.InternalShadowColor);
|
||||
}
|
||||
}
|
||||
@@ -48,22 +48,24 @@ public sealed class VariableColor(StringNames name, Func<float, Color> mainEvalu
|
||||
/// <summary>
|
||||
/// Evaluates the dynamic main color based on the current in-game time.
|
||||
/// </summary>
|
||||
/// <param name="time">The time to evaluate the color against.</param>
|
||||
/// <returns>The dynamically evaluated color, or the static <see cref="CustomColor.MainColor"/> if static variant colors are enabled in the user's settings.</returns>
|
||||
public Color EvaluateMainColor()
|
||||
public Color EvaluateMainColor(float time)
|
||||
{
|
||||
return LocalSettingsTabSingleton<MiraApiSettings>.Instance.EnableVariableColors.Value
|
||||
? MainEvaluator(Time.time)
|
||||
? MainEvaluator(time)
|
||||
: InternalMainColor;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Evaluates the dynamic shadow color based on the current in-game time.
|
||||
/// </summary>
|
||||
/// <param name="time">The time to evaluate the color against.</param>
|
||||
/// <returns>The dynamically evaluated color, or the static <see cref="CustomColor.ShadowColor"/> if static variant colors are enabled in the user's settings.</returns>
|
||||
public Color EvaluateShadowColor()
|
||||
public Color EvaluateShadowColor(float time)
|
||||
{
|
||||
return LocalSettingsTabSingleton<MiraApiSettings>.Instance.EnableVariableColors.Value
|
||||
? ShadowEvaluator(Time.time)
|
||||
? ShadowEvaluator(time)
|
||||
: InternalShadowColor;
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ using System.Diagnostics.CodeAnalysis;
|
||||
using Il2CppInterop.Runtime.Attributes;
|
||||
using MiraAPI.Colors;
|
||||
using MiraAPI.Utilities;
|
||||
using Reactor.Utilities.Attributes;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI;
|
||||
@@ -9,6 +10,7 @@ namespace MiraAPI;
|
||||
/// <summary>
|
||||
/// A mono script that adjusts the material colors of a <see cref="SpriteRenderer"/> component that it's attached to based on the provided variable color.
|
||||
/// </summary>
|
||||
[RegisterInIl2Cpp]
|
||||
[SuppressMessage("Style", "IDE0051:Remove unused private members", Justification = "Unity methods.")]
|
||||
[SuppressMessage("Design", "CA1051:Do not declare visible instance fields", Justification = "Unity fields.")]
|
||||
[SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1401:Fields should be private", Justification = "Read above.")]
|
||||
@@ -34,6 +36,7 @@ public sealed class VariableColorBehaviour : MonoBehaviour
|
||||
{
|
||||
rend = GetComponent<SpriteRenderer>();
|
||||
material = rend.material;
|
||||
material.SetColor(ShaderID.VisorColor, VisorColor);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
@@ -41,8 +44,8 @@ public sealed class VariableColorBehaviour : MonoBehaviour
|
||||
if (!rend || color == null)
|
||||
return;
|
||||
|
||||
material.SetColor(ShaderID.BodyColor, color.EvaluateMainColor());
|
||||
material.SetColor(ShaderID.BackColor, color.EvaluateShadowColor());
|
||||
material.SetColor(ShaderID.VisorColor, VisorColor);
|
||||
var time = Time.time;
|
||||
material.SetColor(ShaderID.BodyColor, color.EvaluateMainColor(time));
|
||||
material.SetColor(ShaderID.BackColor, color.EvaluateShadowColor(time));
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using MiraAPI.Patches.Stubs;
|
||||
using MiraAPI.Translation;
|
||||
using MiraAPI.Utilities;
|
||||
using MiraAPI.Utilities.Assets;
|
||||
using Reactor.Utilities;
|
||||
using Reactor.Utilities.Extensions;
|
||||
@@ -248,8 +249,7 @@ public abstract class CustomPaginableMenu : CustomPhoneMenu<CustomPaginableMenu.
|
||||
|
||||
var wikiClickSound = HudManager.Instance?.MapButton?.ClickSound;
|
||||
|
||||
var searchFocusButton = searchTextbox.gameObject.GetComponent<PassiveButton>()
|
||||
?? searchTextbox.gameObject.AddComponent<PassiveButton>();
|
||||
var searchFocusButton = searchTextbox.gameObject.GetOrAddComponent<PassiveButton>();
|
||||
if (wikiClickSound != null)
|
||||
{
|
||||
searchFocusButton.ClickSound = wikiClickSound;
|
||||
|
||||
@@ -3,6 +3,8 @@ using System.Text.RegularExpressions;
|
||||
using AmongUs.Data;
|
||||
using HarmonyLib;
|
||||
using MiraAPI.Colors;
|
||||
using MiraAPI.Utilities;
|
||||
using Reactor.Utilities.Extensions;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI.Patches.Hud;
|
||||
@@ -13,18 +15,17 @@ internal static class SetPlayerMaterialPatch
|
||||
[HarmonyPatch(nameof(PlayerMaterial.SetColors), typeof(int), typeof(Renderer))]
|
||||
public static bool Prefix(int colorId, Renderer rend)
|
||||
{
|
||||
var r = rend.gameObject.GetComponent<VariableColorBehaviour>()
|
||||
?? rend.gameObject.AddComponent<VariableColorBehaviour>();
|
||||
r.SetColor(PaletteManager.IsVariable(colorId) ? (VariableColor)PaletteManager.ColorIdToColorMap[colorId] : null);
|
||||
rend.gameObject.GetOrAddComponent<VariableColorBehaviour>().SetColor(
|
||||
PaletteManager.ColorIdToColorMap.TryGetValue(colorId, out var color) && color is VariableColor variable
|
||||
? variable
|
||||
: null);
|
||||
return !PaletteManager.IsVariable(colorId);
|
||||
}
|
||||
|
||||
[HarmonyPatch(nameof(PlayerMaterial.SetColors), typeof(Color), typeof(Renderer))]
|
||||
public static void Prefix(Renderer rend)
|
||||
{
|
||||
var r = rend.gameObject.GetComponent<VariableColorBehaviour>()
|
||||
?? rend.gameObject.AddComponent<VariableColorBehaviour>();
|
||||
r.SetColor(null);
|
||||
rend.gameObject.GetOrAddComponent<VariableColorBehaviour>().SetColor(null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +49,7 @@ internal static class ChatNotifRainbowPatch
|
||||
if (!__instance.gameObject.active || !PaletteManager.IsVariable(__instance.player.cosmetics.ColorId))
|
||||
return;
|
||||
|
||||
var str = ColorUtility.ToHtmlStringRGB(PaletteManager.GetMainColor(__instance.player.cosmetics.ColorId));
|
||||
var str = PaletteManager.GetMainColor(__instance.player.cosmetics.ColorId).ToHtmlStringRGBA();
|
||||
__instance.playerNameText.text = "<color=#" + str + ">" + __instance.playerNameText.text.WithoutRichText();
|
||||
}
|
||||
|
||||
@@ -71,9 +72,9 @@ internal static class RainbowLobbyInfoPanePatch
|
||||
}
|
||||
|
||||
var host = GameData.Instance.GetHost();
|
||||
var text = ColorUtility.ToHtmlStringRGB(PaletteManager.GetMainColor(__instance.player.cosmetics.ColorId));
|
||||
__instance.hostLabel.text =
|
||||
TranslationController.Instance.GetString(StringNames.HostNounLabel);
|
||||
var text = PaletteManager.GetMainColor(__instance.player.cosmetics.ColorId).ToHtmlStringRGBA();
|
||||
__instance.hostLabel.text = TranslationController.Instance.GetString(StringNames.HostNounLabel);
|
||||
|
||||
if (__instance.ShouldBoldenHostLabel(DataManager.Settings.Language.CurrentLanguage))
|
||||
{
|
||||
__instance.hostLabel.text = __instance.hostLabel.text.Insert(0, "<b>");
|
||||
|
||||
@@ -404,7 +404,7 @@ public sealed class MiraPluginManager
|
||||
|
||||
foreach (var property in type.GetProperties())
|
||||
{
|
||||
if (property.PropertyType.IsAssignableTo(typeof(CustomColor)))
|
||||
if (!property.PropertyType.IsAssignableTo(typeof(CustomColor)))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -871,4 +871,17 @@ public static class Extensions
|
||||
userData.joystickMaps[0].actionElementMaps.Add(map);
|
||||
return action;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a component that is attached to the provided <see cref="GameObject"/>, attaching and returning the component if it wasn't found.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The component type.</typeparam>
|
||||
/// <param name="go">The <see cref="GameObject"/> to get the component from.</param>
|
||||
/// <returns>The component.</returns>
|
||||
public static T GetOrAddComponent<T>(this GameObject go)
|
||||
where T : Component
|
||||
{
|
||||
var comp = go.GetComponent<T>();
|
||||
return comp ? comp : go.AddComponent<T>();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user