mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-10-20 01:46:15 +00:00
WIP Colors & Config button fix
This commit is contained in:
1 parent
2fb9d426c7
commit
4db75aa4a9
9 files changed
+110
-30
No files matched your search
@@ -10,8 +10,8 @@ public class CustomRole : ImpostorRole, ICustomRole
|
||||
public string RoleName => "fortnite killer";
|
||||
public string RoleLongDescription => "ok so your objective is to eliminate everyone with your fortnite tactical shotgun, good luck";
|
||||
public string RoleDescription => RoleLongDescription;
|
||||
public Color RoleColor => Palette.Orange;
|
||||
public Color RoleColor => Palette.Black;
|
||||
public ModdedRoleTeams Team => ModdedRoleTeams.Impostor;
|
||||
public LoadableAsset<Sprite> OptionsScreenshot => MiraAssets.Banner;
|
||||
|
||||
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
using System;
|
||||
using MiraAPI.Networking;
|
||||
using MiraAPI.Networking;
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace MiraAPI.GameOptions.OptionTypes;
|
||||
|
||||
public class ModdedToggleOption : ModdedOption<bool>
|
||||
{
|
||||
public ModdedToggleOption(string title, bool defaultValue, Type roleType=null) : base(title, defaultValue, roleType)
|
||||
public ModdedToggleOption(string title, bool defaultValue, Type roleType = null) : base(title, defaultValue, roleType)
|
||||
{
|
||||
Data = ScriptableObject.CreateInstance<CheckboxGameSetting>();
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ public static class GameOptionsMenuPatch
|
||||
if (group.GroupColor != Color.clear)
|
||||
{
|
||||
categoryHeaderMasked.Background.color = group.GroupColor;
|
||||
categoryHeaderMasked.Title.color = group.GroupColor.DarkenColor();
|
||||
categoryHeaderMasked.Title.color = group.GroupColor.GetAlternateColor();
|
||||
}
|
||||
categoryHeaderMasked.transform.localScale = Vector3.one * 0.63f;
|
||||
categoryHeaderMasked.transform.localPosition = new Vector3(-0.903f, num, -2f);
|
||||
@@ -58,7 +58,12 @@ public static class GameOptionsMenuPatch
|
||||
{
|
||||
if (group.GroupColor != Color.clear)
|
||||
{
|
||||
componentsInChildren[i].color = group.GroupColor;
|
||||
componentsInChildren[i].color = group.GroupColor.GetAlternateColor();
|
||||
if (componentsInChildren[i].transform.parent.TryGetComponent<GameOptionButton>(out var btn))
|
||||
{
|
||||
btn.interactableColor = group.GroupColor.GetAlternateColor();
|
||||
btn.interactableHoveredColor = Color.white;
|
||||
}
|
||||
}
|
||||
|
||||
componentsInChildren[i].material.SetInt(PlayerMaterial.MaskLayer, 20);
|
||||
@@ -68,7 +73,7 @@ public static class GameOptionsMenuPatch
|
||||
{
|
||||
if (group.GroupColor != Color.clear)
|
||||
{
|
||||
textMeshPro.color = group.GroupColor.DarkenColor();
|
||||
textMeshPro.color = group.GroupColor;
|
||||
}
|
||||
|
||||
textMeshPro.fontMaterial.SetFloat(ShaderID.StencilComp, 3f);
|
||||
|
||||
@@ -131,7 +131,7 @@ public static class RoleSettingMenuPatches
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(nameof(RolesSettingsMenu.OpenChancesTab))]
|
||||
public static void OpenChancesTabPostfix(RolesSettingsMenu __instance)
|
||||
@@ -139,7 +139,7 @@ public static class RoleSettingMenuPatches
|
||||
__instance.scrollBar.CalculateAndSetYBounds(__instance.roleChances.Count + 5, 1f, 6f, 0.43f);
|
||||
__instance.scrollBar.ScrollToTop();
|
||||
}
|
||||
|
||||
|
||||
private static void ValueChanged(OptionBehaviour obj)
|
||||
{
|
||||
var roleSetting = obj.Cast<RoleOptionSetting>();
|
||||
@@ -225,7 +225,7 @@ public static class RoleSettingMenuPatches
|
||||
__instance.roleScreenshot.sprite = Sprite.Create(customRole.OptionsScreenshot.LoadAsset().texture, new Rect(0, 0, 370, 230), Vector2.one / 2, 100);
|
||||
__instance.roleScreenshot.drawMode = SpriteDrawMode.Sliced;
|
||||
__instance.roleHeaderSprite.color = customRole.RoleColor;
|
||||
__instance.roleHeaderText.color = customRole.RoleColor.DarkenColor();
|
||||
__instance.roleHeaderText.color = customRole.RoleColor.GetAlternateColor();
|
||||
|
||||
CreateAdvancedSettings(__instance, role);
|
||||
|
||||
@@ -249,12 +249,14 @@ public static class RoleSettingMenuPatches
|
||||
roleOptionSetting.transform.localPosition = new Vector3(-0.15f, yPos, -2f);
|
||||
roleOptionSetting.SetRole(GameOptionsManager.Instance.CurrentGameOptions.RoleOptions, role, 20);
|
||||
roleOptionSetting.labelSprite.color = customRole.RoleColor;
|
||||
roleOptionSetting.titleText.color = customRole.RoleColor.DarkenColor();
|
||||
roleOptionSetting.OnValueChanged = new Action<OptionBehaviour>(ValueChanged);
|
||||
roleOptionSetting.titleText.horizontalAlignment = HorizontalAlignmentOptions.Left;
|
||||
roleOptionSetting.SetClickMask(__instance.ButtonClickMask);
|
||||
__instance.roleChances.Add(roleOptionSetting);
|
||||
|
||||
roleOptionSetting.titleText.transform.localPosition = new Vector3(-0.5376f, -0.2923f, 0f);
|
||||
roleOptionSetting.titleText.color = customRole.RoleColor.GetAlternateColor();
|
||||
roleOptionSetting.titleText.horizontalAlignment = HorizontalAlignmentOptions.Left;
|
||||
|
||||
PassiveButton newButton = Object.Instantiate(roleOptionSetting.buttons[0], roleOptionSetting.transform);
|
||||
newButton.name = "ConfigButton";
|
||||
newButton.transform.localPosition = new Vector3(0.4473f, -0.3f, -2f);
|
||||
@@ -263,12 +265,11 @@ public static class RoleSettingMenuPatches
|
||||
|
||||
SpriteRenderer btnRend = newButton.transform.FindChild("ButtonSprite").GetComponent<SpriteRenderer>();
|
||||
btnRend.sprite = MiraAssets.Cog.LoadAsset();
|
||||
btnRend.color = customRole.RoleColor.DarkenColor();
|
||||
|
||||
PassiveButton passiveButton = newButton.GetComponent<PassiveButton>();
|
||||
GameOptionButton passiveButton = newButton.GetComponent<GameOptionButton>();
|
||||
passiveButton.OnClick = new ButtonClickedEvent();
|
||||
passiveButton.disabledTextColor = customRole.RoleColor.DarkenColor();
|
||||
passiveButton.selectedTextColor = customRole.RoleColor.DarkenColor().DarkenColor();
|
||||
passiveButton.interactableColor = btnRend.color = customRole.RoleColor.GetAlternateColor();
|
||||
passiveButton.interactableHoveredColor = Color.white;
|
||||
|
||||
passiveButton.OnClick.AddListener((UnityAction)(() =>
|
||||
{
|
||||
|
||||
@@ -6,12 +6,12 @@ namespace MiraAPI.Patches.Roles;
|
||||
[HarmonyPatch(typeof(ExileController))]
|
||||
public static class EjectionPatches
|
||||
{
|
||||
|
||||
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(nameof(ExileController.Begin))]
|
||||
public static void Begin(ExileController __instance)
|
||||
{
|
||||
if (!__instance.initData.networkedPlayer.Role || __instance.initData.networkedPlayer.Role is not ICustomRole role)
|
||||
if (!__instance.initData.networkedPlayer || !__instance.initData.networkedPlayer.Role || __instance.initData.networkedPlayer.Role is not ICustomRole role)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -20,7 +20,7 @@ public static class EjectionPatches
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
__instance.completeString = role.GetCustomEjectionMessage(__instance.initData.networkedPlayer);
|
||||
}
|
||||
}
|
||||
@@ -3,25 +3,27 @@ using BepInEx.Unity.IL2CPP;
|
||||
using Il2CppInterop.Runtime.Injection;
|
||||
using MiraAPI.GameOptions;
|
||||
using MiraAPI.GameOptions.Attributes;
|
||||
using MiraAPI.Hud;
|
||||
using MiraAPI.Roles;
|
||||
using MiraAPI.Utilities.Colors;
|
||||
using Reactor.Utilities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using MiraAPI.Hud;
|
||||
|
||||
namespace MiraAPI.PluginLoading;
|
||||
|
||||
internal class MiraPluginManager
|
||||
{
|
||||
public readonly Dictionary<Assembly, MiraPluginInfo> RegisteredPlugins = [];
|
||||
|
||||
|
||||
private static MiraPluginManager _instance;
|
||||
|
||||
public static MiraPluginManager Instance {
|
||||
|
||||
public static MiraPluginManager Instance
|
||||
{
|
||||
get => _instance ??= new MiraPluginManager();
|
||||
private set => _instance = value;
|
||||
private set => _instance = value;
|
||||
}
|
||||
|
||||
internal void Initialize()
|
||||
@@ -38,10 +40,12 @@ internal class MiraPluginManager
|
||||
var info = new MiraPluginInfo(id, plugin as IMiraPlugin, IL2CPPChainloader.Instance.Plugins[id]);
|
||||
|
||||
RegisterAllOptions(assembly, info);
|
||||
|
||||
|
||||
RegisterRoleAttribute(assembly, info);
|
||||
RegisterButtonAttribute(assembly);
|
||||
|
||||
RegisterAllColors(assembly);
|
||||
|
||||
RegisteredPlugins.Add(assembly, info);
|
||||
|
||||
Logger<MiraApiPlugin>.Info($"Registering mod {id} with Mira API.");
|
||||
@@ -56,14 +60,14 @@ internal class MiraPluginManager
|
||||
private static void RegisterAllOptions(Assembly assembly, MiraPluginInfo pluginInfo)
|
||||
{
|
||||
var filteredTypes = assembly.GetTypes().Where(type => type.IsAssignableTo(typeof(AbstractOptionGroup)));
|
||||
|
||||
|
||||
foreach (var type in filteredTypes)
|
||||
{
|
||||
if (!ModdedOptionsManager.RegisterGroup(type, pluginInfo))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
foreach (var property in type.GetProperties())
|
||||
{
|
||||
if (property.PropertyType.IsAssignableTo(typeof(IModdedOption)))
|
||||
@@ -71,7 +75,7 @@ internal class MiraPluginManager
|
||||
ModdedOptionsManager.RegisterPropertyOption(type, property, pluginInfo);
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
var attribute = property.GetCustomAttribute<ModdedOptionAttribute>();
|
||||
if (attribute == null)
|
||||
{
|
||||
@@ -109,12 +113,31 @@ internal class MiraPluginManager
|
||||
{
|
||||
Logger<MiraApiPlugin>.Error($"{k}: {v}");
|
||||
}
|
||||
|
||||
|
||||
Logger<MiraApiPlugin>.Error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void RegisterAllColors(Assembly assembly)
|
||||
{
|
||||
foreach (var type in assembly.GetTypes())
|
||||
{
|
||||
foreach (FieldInfo field in type.GetFields())
|
||||
{
|
||||
foreach (var attribute in field.GetCustomAttributes())
|
||||
{
|
||||
if (attribute.GetType().BaseType == typeof(RegisterColorAttribute))
|
||||
{
|
||||
/* Palette.PlayerColors = Palette.PlayerColors.ToArray().AddToArray();
|
||||
Palette.ShadowColors = Palette.ShadowColors.ToArray().AddToArray();
|
||||
Palette.ColorNames = Palette.ColorNames.ToArray().AddToArray();*/
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void RegisterButtonAttribute(Assembly assembly)
|
||||
{
|
||||
foreach (var type in assembly.GetTypes())
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI.Utilities;
|
||||
public class CustomColor
|
||||
{
|
||||
public CustomColor(Color32 mainColor, StringNames name)
|
||||
{
|
||||
MainColor = mainColor;
|
||||
ShadowColor = GetShadowColor(mainColor, 60);
|
||||
Name = name;
|
||||
}
|
||||
|
||||
public CustomColor(Color32 mainColor, Color32 shadowColor, StringNames name)
|
||||
{
|
||||
MainColor = mainColor;
|
||||
ShadowColor = shadowColor;
|
||||
Name = name;
|
||||
}
|
||||
|
||||
public Color32 MainColor { get; }
|
||||
public Color32 ShadowColor { get; }
|
||||
public StringNames Name { get; }
|
||||
|
||||
public static Color32 GetShadowColor(Color32 c, byte darknessAmount)
|
||||
{
|
||||
return
|
||||
new Color32((byte)Mathf.Clamp(c.r - darknessAmount, 0, 255), (byte)Mathf.Clamp(c.g - darknessAmount, 0, 255),
|
||||
(byte)Mathf.Clamp(c.b - darknessAmount, 0, 255), byte.MaxValue);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
using System;
|
||||
|
||||
namespace MiraAPI.Utilities.Colors;
|
||||
|
||||
[AttributeUsage(AttributeTargets.Field)]
|
||||
public class RegisterColorAttribute : Attribute;
|
||||
@@ -17,6 +17,21 @@ public static class Extensions
|
||||
{
|
||||
return new Color(color.r - 0.3f, color.g - 0.3f, color.b - 0.3f);
|
||||
}
|
||||
public static Color GetAlternateColor(this Color color)
|
||||
{
|
||||
return color.IsColorDark() ? LightenColor(color) : DarkenColor(color);
|
||||
}
|
||||
|
||||
public static Color LightenColor(this Color color)
|
||||
{
|
||||
return new Color(color.r + 0.3f, color.g + 0.3f, color.b + 0.3f);
|
||||
}
|
||||
|
||||
public static bool IsColorDark(this Color color)
|
||||
{
|
||||
return color.r < 0.5f && color.g < 0.5f && color.b < 0.5f;
|
||||
}
|
||||
|
||||
public static void UpdateBodies(this PlayerControl playerControl, Color outlineColor, ref DeadBody target)
|
||||
{
|
||||
foreach (var body in Object.FindObjectsOfType<DeadBody>())
|
||||
|
||||
Reference in new issue
Block a user