mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-10-20 01:46:15 +00:00
final addressables
This commit is contained in:
1 parent
23c0397afe
commit
71b537dba9
9 files changed
+380
-28
No files matched your search
@@ -4,7 +4,10 @@ using MiraAPI.Events.Vanilla.Gameplay;
|
|||||||
using MiraAPI.Events.Vanilla.Map;
|
using MiraAPI.Events.Vanilla.Map;
|
||||||
using MiraAPI.Events.Vanilla.Player;
|
using MiraAPI.Events.Vanilla.Player;
|
||||||
using MiraAPI.Example.Buttons.Freezer;
|
using MiraAPI.Example.Buttons.Freezer;
|
||||||
|
using MiraAPI.Utilities.Assets;
|
||||||
using Reactor.Utilities;
|
using Reactor.Utilities;
|
||||||
|
using TMPro;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
namespace MiraAPI.Example;
|
namespace MiraAPI.Example;
|
||||||
|
|
||||||
@@ -16,6 +19,8 @@ public static class ExampleEventHandlers
|
|||||||
MiraEventManager.RegisterEventHandler<BeforeMurderEvent>(@event =>
|
MiraEventManager.RegisterEventHandler<BeforeMurderEvent>(@event =>
|
||||||
{
|
{
|
||||||
Logger<ExamplePlugin>.Info($"{@event.Source.Data.PlayerName} is about to kill {@event.Target.Data.PlayerName}");
|
Logger<ExamplePlugin>.Info($"{@event.Source.Data.PlayerName} is about to kill {@event.Target.Data.PlayerName}");
|
||||||
|
var asset = new LoadableAddressableAsset<GameObject>("Assets/Prefabs/SomeText.prefab");
|
||||||
|
Logger<ExamplePlugin>.Info($"{asset.LoadAsset().GetComponent<TextMeshPro>().text}");
|
||||||
});
|
});
|
||||||
|
|
||||||
MiraEventManager.RegisterEventHandler<AfterMurderEvent>(@event =>
|
MiraEventManager.RegisterEventHandler<AfterMurderEvent>(@event =>
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ using Reactor.Networking;
|
|||||||
using Reactor.Networking.Attributes;
|
using Reactor.Networking.Attributes;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
namespace MiraAPI.Example;
|
namespace MiraAPI.Example;
|
||||||
|
|
||||||
@@ -28,7 +29,9 @@ public partial class ExamplePlugin : BasePlugin, IMiraPlugin
|
|||||||
Harmony.PatchAll();
|
Harmony.PatchAll();
|
||||||
|
|
||||||
var path = Path.GetDirectoryName(Assembly.GetAssembly(typeof(ExamplePlugin))!.Location) + "\\touhats.catalog";
|
var path = Path.GetDirectoryName(Assembly.GetAssembly(typeof(ExamplePlugin))!.Location) + "\\touhats.catalog";
|
||||||
AddressablesLoader.RegisterToLoad(path);
|
AddressablesLoader.RegisterCatalog(path);
|
||||||
AddressablesLoader.RegisterHats("touhats");
|
AddressablesLoader.RegisterHats("touhats");
|
||||||
|
|
||||||
|
AddressablesLoader.RegisterCatalog("https://raw.githubusercontent.com/MyDragonBreath/MyDragonBreath/refs/heads/main/DONTUSEGITHUBASACDN/catalog.json");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -54,8 +54,10 @@ public static class HatsTabPatches
|
|||||||
{
|
{
|
||||||
hatIndex = (hatIndex + 4) / 5 * 5; // yes it looks redundant, but consider hatindex = 0, symbolically it would be 4, the computer calculates 0.
|
hatIndex = (hatIndex + 4) / 5 * 5; // yes it looks redundant, but consider hatindex = 0, symbolically it would be 4, the computer calculates 0.
|
||||||
var text = Object.Instantiate(groupNameText, __instance.scroller.Inner);
|
var text = Object.Instantiate(groupNameText, __instance.scroller.Inner);
|
||||||
|
text.enabled = true;
|
||||||
text.gameObject.transform.localScale = Vector3.one;
|
text.gameObject.transform.localScale = Vector3.one;
|
||||||
text.GetComponent<TextTranslatorTMP>().Destroy();
|
text.GetComponent<TextTranslatorTMP>().Destroy();
|
||||||
|
text.EnableStencilMasking();
|
||||||
text.text = $"{groupName}";
|
text.text = $"{groupName}";
|
||||||
text.alignment = TextAlignmentOptions.Center;
|
text.alignment = TextAlignmentOptions.Center;
|
||||||
text.fontSize = 3f;
|
text.fontSize = 3f;
|
||||||
@@ -87,7 +89,10 @@ public static class HatsTabPatches
|
|||||||
colorChip.Button.OnMouseOver.AddListener((Action)(() => __instance.SelectHat(hat)));
|
colorChip.Button.OnMouseOver.AddListener((Action)(() => __instance.SelectHat(hat)));
|
||||||
colorChip.Button.OnMouseOut.AddListener((Action)(() => __instance.SelectHat(HatManager.Instance.GetHatById(DataManager.Player.Customization.Hat))));
|
colorChip.Button.OnMouseOut.AddListener((Action)(() => __instance.SelectHat(HatManager.Instance.GetHatById(DataManager.Player.Customization.Hat))));
|
||||||
colorChip.Inner.SetHat(hat, __instance.HasLocalPlayer() ? PlayerControl.LocalPlayer.Data.DefaultOutfit.ColorId : DataManager.Player.Customization.Color);
|
colorChip.Inner.SetHat(hat, __instance.HasLocalPlayer() ? PlayerControl.LocalPlayer.Data.DefaultOutfit.ColorId : DataManager.Player.Customization.Color);
|
||||||
colorChip.Inner.transform.GetChild(0).GetComponent<SpriteRenderer>().maskInteraction = SpriteMaskInteraction.VisibleInsideMask;
|
colorChip.Button.ClickMask = __instance.scroller.Hitbox;
|
||||||
|
colorChip.SelectionHighlight.gameObject.SetActive(false);
|
||||||
|
__instance.UpdateMaterials(colorChip.Inner.FrontLayer, hat);
|
||||||
|
colorChip.Inner.SetMaskType(PlayerMaterial.MaskType.SimpleUI);
|
||||||
colorChip.transform.localPosition = new Vector3(position.x, position.y, -1f);
|
colorChip.transform.localPosition = new Vector3(position.x, position.y, -1f);
|
||||||
colorChip.Inner.transform.localPosition = hat.ChipOffset + new Vector2(0f, -0.3f);
|
colorChip.Inner.transform.localPosition = hat.ChipOffset + new Vector2(0f, -0.3f);
|
||||||
colorChip.Tag = hat;
|
colorChip.Tag = hat;
|
||||||
|
|||||||
@@ -1,17 +1,17 @@
|
|||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
using MiraAPI.Utilities.Assets;
|
using MiraAPI.Utilities.Assets;
|
||||||
using Reactor.Utilities;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace MiraAPI.Patches.Menu;
|
namespace MiraAPI.Patches.Menu;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// General MainMenuManage patches.
|
||||||
|
/// </summary>
|
||||||
[HarmonyPatch(typeof(MainMenuManager))]
|
[HarmonyPatch(typeof(MainMenuManager))]
|
||||||
public static class MainMenuManagerPatches
|
public static class MainMenuManagerPatches
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A postifix on Awake to load all the addressables registered.
|
||||||
|
/// </summary>
|
||||||
[HarmonyPatch(nameof(MainMenuManager.Awake))]
|
[HarmonyPatch(nameof(MainMenuManager.Awake))]
|
||||||
[HarmonyPostfix]
|
[HarmonyPostfix]
|
||||||
public static void AwakePostfix()
|
public static void AwakePostfix()
|
||||||
|
|||||||
@@ -0,0 +1,102 @@
|
|||||||
|
using AmongUs.Data;
|
||||||
|
using HarmonyLib;
|
||||||
|
using Innersloth.Assets;
|
||||||
|
using MiraAPI.Utilities;
|
||||||
|
using Reactor.Utilities.Extensions;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using TMPro;
|
||||||
|
using UnityEngine;
|
||||||
|
using Object = UnityEngine.Object;
|
||||||
|
|
||||||
|
namespace MiraAPI.Patches.Menu;
|
||||||
|
|
||||||
|
[HarmonyPatch(typeof(NameplatesTab))]
|
||||||
|
public static class NameplatesTabPatches
|
||||||
|
{
|
||||||
|
private static readonly SortedList<string, List<NamePlateData>> SortedNameplates = new(new ControllableComparer<string>(["vanilla"], [], StringComparer.InvariantCulture));
|
||||||
|
|
||||||
|
internal static void AddRange(IEnumerable<(string Key, NamePlateData Visor)> data)
|
||||||
|
{
|
||||||
|
foreach (var item in data)
|
||||||
|
{
|
||||||
|
if (!SortedNameplates.ContainsKey(item.Key)) SortedNameplates.Add(item.Key, []);
|
||||||
|
SortedNameplates[item.Key].Add(item.Visor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HarmonyPatch(nameof(NameplatesTab.OnEnable))]
|
||||||
|
[HarmonyPrefix]
|
||||||
|
public static bool OnEnablePrefix(NameplatesTab __instance)
|
||||||
|
{
|
||||||
|
__instance.plateId = HatManager.Instance.GetNamePlateById(DataManager.Player.Customization.namePlate).ProdId;
|
||||||
|
|
||||||
|
if (!SortedNameplates.ContainsKey("Vanilla")) AddRange(DestroyableSingleton<HatManager>.Instance.GetUnlockedNamePlates().Select(x => ("Vanilla", x)));
|
||||||
|
GenerateHats(__instance);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void GenerateHats(NameplatesTab __instance)
|
||||||
|
{
|
||||||
|
foreach (ColorChip instanceColorChip in __instance.ColorChips) instanceColorChip.gameObject.Destroy();
|
||||||
|
__instance.ColorChips.Clear();
|
||||||
|
__instance.scroller.Inner.GetComponentsInChildren<TextMeshPro>().Do(x => x.gameObject.Destroy());
|
||||||
|
|
||||||
|
var groupNameText = __instance.GetComponentInChildren<TextMeshPro>(false);
|
||||||
|
|
||||||
|
int hatIndex = 0;
|
||||||
|
|
||||||
|
foreach ((string groupName, List<NamePlateData> visors) in SortedNameplates)
|
||||||
|
{
|
||||||
|
hatIndex = (hatIndex + 1) / 2 * 2; // yes it looks redundant, but consider hatindex = 0, symbolically it would be 4, the computer calculates 0.
|
||||||
|
var text = Object.Instantiate(groupNameText, __instance.scroller.Inner);
|
||||||
|
text.enabled = true;
|
||||||
|
text.gameObject.transform.localScale = Vector3.one;
|
||||||
|
text.GetComponent<TextTranslatorTMP>().Destroy();
|
||||||
|
text.EnableStencilMasking();
|
||||||
|
text.text = $"{groupName}";
|
||||||
|
text.alignment = TextAlignmentOptions.Center;
|
||||||
|
text.fontSize = 3f;
|
||||||
|
text.fontSizeMax = 3f;
|
||||||
|
text.fontSizeMin = 0f;
|
||||||
|
float xLerp = __instance.XRange.Lerp(0.5f);
|
||||||
|
float yLerp = __instance.YStart - hatIndex / __instance.NumPerRow * __instance.YOffset;
|
||||||
|
text.transform.localPosition = new Vector3(xLerp, yLerp, -1f);
|
||||||
|
|
||||||
|
hatIndex += 2;
|
||||||
|
foreach (var visor in visors.OrderBy(HatManager.Instance.allNamePlates.IndexOf))
|
||||||
|
{
|
||||||
|
float hatXposition = __instance.XRange.Lerp(hatIndex % __instance.NumPerRow / (__instance.NumPerRow - 1f));
|
||||||
|
float hatYposition = __instance.YStart - hatIndex / __instance.NumPerRow * __instance.YOffset;
|
||||||
|
GenerateColorChip(__instance, new Vector2(hatXposition, hatYposition), visor);
|
||||||
|
hatIndex += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
__instance.scroller.ContentYBounds.max = -(__instance.YStart - (hatIndex + 1) / __instance.NumPerRow * __instance.YOffset) - 3f;
|
||||||
|
__instance.currentNameplateIsEquipped = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void GenerateColorChip(NameplatesTab __instance, Vector2 position, NamePlateData namePlate)
|
||||||
|
{
|
||||||
|
var colorChip = Object.Instantiate(__instance.ColorTabPrefab, __instance.scroller.Inner);
|
||||||
|
colorChip.gameObject.name = namePlate.ProductId;
|
||||||
|
colorChip.Button.OnClick.AddListener((Action)(() => __instance.ClickEquip()));
|
||||||
|
colorChip.Button.OnMouseOver.AddListener((Action)(() => __instance.SelectNameplate(namePlate)));
|
||||||
|
colorChip.Button.OnMouseOut.AddListener((Action)(() => __instance.SelectNameplate(HatManager.Instance.GetNamePlateById(DataManager.Player.Customization.NamePlate))));
|
||||||
|
colorChip.Button.ClickMask = __instance.scroller.Hitbox;
|
||||||
|
colorChip.ProductId = namePlate.ProdId;
|
||||||
|
|
||||||
|
var x = (NamePlateViewData viewdata) =>
|
||||||
|
{
|
||||||
|
colorChip.transform.GetChild(1).GetComponent<SpriteRenderer>().sprite = viewdata?.Image;
|
||||||
|
//(colorChip as NameplateChip).image.sprite = viewdata?.Image;
|
||||||
|
};
|
||||||
|
__instance.StartCoroutine(AddressableAssetExtensions.CoLoadAssetAsync<NamePlateViewData>(__instance, namePlate.GetAssetReference(), x));
|
||||||
|
colorChip.transform.localPosition = new Vector3(position.x, position.y, -1f);
|
||||||
|
colorChip.Tag = namePlate;
|
||||||
|
__instance.ColorChips.Add(colorChip);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,101 @@
|
|||||||
|
using AmongUs.Data;
|
||||||
|
using HarmonyLib;
|
||||||
|
using MiraAPI.Utilities;
|
||||||
|
using Reactor.Utilities.Extensions;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Collections.Immutable;
|
||||||
|
using System.Linq;
|
||||||
|
using TMPro;
|
||||||
|
using UnityEngine;
|
||||||
|
using Object = UnityEngine.Object;
|
||||||
|
|
||||||
|
namespace MiraAPI.Patches.Menu;
|
||||||
|
|
||||||
|
[HarmonyPatch(typeof(SkinsTab))]
|
||||||
|
public static class SkinsTabPatches
|
||||||
|
{
|
||||||
|
private static SortedList<string, List<SkinData>> sortedSkins = [];
|
||||||
|
|
||||||
|
[HarmonyPatch(nameof(SkinsTab.OnEnable))]
|
||||||
|
[HarmonyPrefix]
|
||||||
|
public static bool OnEnablePrefix(SkinsTab __instance)
|
||||||
|
{
|
||||||
|
__instance.skinId = HatManager.Instance.GetSkinById(DataManager.Player.Customization.Skin).ProdId;
|
||||||
|
var allSkins = HatManager.Instance.GetUnlockedSkins().ToImmutableList();
|
||||||
|
|
||||||
|
if (sortedSkins.Count == 0)
|
||||||
|
{
|
||||||
|
var comparer = new ControllableComparer<string>(["vanilla"], [], StringComparer.InvariantCulture);
|
||||||
|
sortedSkins = new SortedList<string, List<SkinData>>(comparer);
|
||||||
|
foreach (var skin in allSkins)
|
||||||
|
{
|
||||||
|
if (!sortedSkins.ContainsKey(skin.StoreName)) sortedSkins[skin.StoreName] = [];
|
||||||
|
sortedSkins[skin.StoreName].Add(skin);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
GenerateHats(__instance);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void GenerateHats(SkinsTab __instance)
|
||||||
|
{
|
||||||
|
foreach (ColorChip instanceColorChip in __instance.ColorChips) instanceColorChip.gameObject.Destroy();
|
||||||
|
__instance.ColorChips.Clear();
|
||||||
|
__instance.scroller.Inner.GetComponentsInChildren<TextMeshPro>().Do(x => x.gameObject.Destroy());
|
||||||
|
|
||||||
|
var groupNameText = __instance.GetComponentInChildren<TextMeshPro>(false);
|
||||||
|
|
||||||
|
int hatIndex = 0;
|
||||||
|
|
||||||
|
foreach ((string groupName, List<SkinData> skins) in sortedSkins)
|
||||||
|
{
|
||||||
|
hatIndex = (hatIndex + 4) / 5 * 5; // yes it looks redundant, but consider hatindex = 0, symbolically it would be 4, the computer calculates 0.
|
||||||
|
var text = Object.Instantiate(groupNameText, __instance.scroller.Inner);
|
||||||
|
text.enabled = true;
|
||||||
|
text.gameObject.transform.localScale = Vector3.one;
|
||||||
|
text.GetComponent<TextTranslatorTMP>().Destroy();
|
||||||
|
text.EnableStencilMasking();
|
||||||
|
text.text = $"{groupName}";
|
||||||
|
text.alignment = TextAlignmentOptions.Center;
|
||||||
|
text.fontSize = 3f;
|
||||||
|
text.fontSizeMax = 3f;
|
||||||
|
text.fontSizeMin = 0f;
|
||||||
|
float xLerp = __instance.XRange.Lerp(0.5f);
|
||||||
|
float yLerp = __instance.YStart - hatIndex / __instance.NumPerRow * __instance.YOffset;
|
||||||
|
text.transform.localPosition = new Vector3(xLerp, yLerp, -1f);
|
||||||
|
|
||||||
|
hatIndex += 5;
|
||||||
|
foreach (var skin in skins.OrderBy(HatManager.Instance.allSkins.IndexOf))
|
||||||
|
{
|
||||||
|
float hatXposition = __instance.XRange.Lerp(hatIndex % __instance.NumPerRow / (__instance.NumPerRow - 1f));
|
||||||
|
float hatYposition = __instance.YStart - hatIndex / __instance.NumPerRow * __instance.YOffset;
|
||||||
|
GenerateColorChip(__instance, new Vector2(hatXposition, hatYposition), skin);
|
||||||
|
hatIndex += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
__instance.scroller.ContentYBounds.max = -(__instance.YStart - (hatIndex + 1) / __instance.NumPerRow * __instance.YOffset) - 3f;
|
||||||
|
__instance.currentSkinIsEquipped = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void GenerateColorChip(SkinsTab __instance, Vector2 position, SkinData skin)
|
||||||
|
{
|
||||||
|
var colorChip = Object.Instantiate(__instance.ColorTabPrefab, __instance.scroller.Inner);
|
||||||
|
colorChip.gameObject.name = skin.ProductId;
|
||||||
|
colorChip.Button.OnClick.AddListener((Action)(() => __instance.ClickEquip()));
|
||||||
|
colorChip.Button.OnMouseOver.AddListener((Action)(() => __instance.SelectSkin(skin)));
|
||||||
|
colorChip.Button.OnMouseOut.AddListener((Action)(() => __instance.SelectSkin(HatManager.Instance.GetSkinById(DataManager.Player.Customization.Skin))));
|
||||||
|
colorChip.Button.ClickMask = __instance.scroller.Hitbox;
|
||||||
|
colorChip.ProductId = skin.ProductId;
|
||||||
|
colorChip.SelectionHighlight.gameObject.SetActive(false);
|
||||||
|
__instance.UpdateMaterials(colorChip.Inner.FrontLayer, skin);
|
||||||
|
skin.SetPreview(colorChip.Inner.FrontLayer, __instance.HasLocalPlayer() ? PlayerControl.LocalPlayer.Data.DefaultOutfit.ColorId : DataManager.Player.Customization.Color);
|
||||||
|
colorChip.transform.localPosition = new Vector3(position.x, position.y, -1f);
|
||||||
|
colorChip.Inner.transform.localPosition = skin.ChipOffset + new Vector2(0f, -0.3f);
|
||||||
|
colorChip.Tag = skin;
|
||||||
|
__instance.ColorChips.Add(colorChip);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,98 @@
|
|||||||
|
using AmongUs.Data;
|
||||||
|
using HarmonyLib;
|
||||||
|
using MiraAPI.Utilities;
|
||||||
|
using Reactor.Utilities.Extensions;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using TMPro;
|
||||||
|
using UnityEngine;
|
||||||
|
using Object = UnityEngine.Object;
|
||||||
|
|
||||||
|
namespace MiraAPI.Patches.Menu;
|
||||||
|
|
||||||
|
[HarmonyPatch(typeof(VisorsTab))]
|
||||||
|
public static class VisorsTabPatches
|
||||||
|
{
|
||||||
|
private static readonly SortedList<string, List<VisorData>> SortedVisors = new(new ControllableComparer<string>(["vanilla"], [], StringComparer.InvariantCulture));
|
||||||
|
|
||||||
|
internal static void AddRange(IEnumerable<(string Key, VisorData Visor)> data)
|
||||||
|
{
|
||||||
|
foreach (var item in data)
|
||||||
|
{
|
||||||
|
if (!SortedVisors.ContainsKey(item.Key)) SortedVisors.Add(item.Key, []);
|
||||||
|
SortedVisors[item.Key].Add(item.Visor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[HarmonyPatch(nameof(VisorsTab.OnEnable))]
|
||||||
|
[HarmonyPrefix]
|
||||||
|
public static bool OnEnablePrefix(VisorsTab __instance)
|
||||||
|
{
|
||||||
|
__instance.visorId = HatManager.Instance.GetVisorById(DataManager.Player.Customization.Visor).ProdId;
|
||||||
|
|
||||||
|
if (!SortedVisors.ContainsKey("Vanilla")) AddRange(DestroyableSingleton<HatManager>.Instance.GetUnlockedVisors().Select(x => ("Vanilla", x)));
|
||||||
|
GenerateHats(__instance);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void GenerateHats(VisorsTab __instance)
|
||||||
|
{
|
||||||
|
foreach (ColorChip instanceColorChip in __instance.ColorChips) instanceColorChip.gameObject.Destroy();
|
||||||
|
__instance.ColorChips.Clear();
|
||||||
|
__instance.scroller.Inner.GetComponentsInChildren<TextMeshPro>().Do(x => x.gameObject.Destroy());
|
||||||
|
|
||||||
|
var groupNameText = __instance.GetComponentInChildren<TextMeshPro>(false);
|
||||||
|
|
||||||
|
int hatIndex = 0;
|
||||||
|
|
||||||
|
foreach ((string groupName, List<VisorData> visors) in SortedVisors)
|
||||||
|
{
|
||||||
|
hatIndex = (hatIndex + 4) / 5 * 5; // yes it looks redundant, but consider hatindex = 0, symbolically it would be 4, the computer calculates 0.
|
||||||
|
var text = Object.Instantiate(groupNameText, __instance.scroller.Inner);
|
||||||
|
text.enabled = true;
|
||||||
|
text.gameObject.transform.localScale = Vector3.one;
|
||||||
|
text.GetComponent<TextTranslatorTMP>().Destroy();
|
||||||
|
text.EnableStencilMasking();
|
||||||
|
text.text = $"{groupName}";
|
||||||
|
text.alignment = TextAlignmentOptions.Center;
|
||||||
|
text.fontSize = 3f;
|
||||||
|
text.fontSizeMax = 3f;
|
||||||
|
text.fontSizeMin = 0f;
|
||||||
|
float xLerp = __instance.XRange.Lerp(0.5f);
|
||||||
|
float yLerp = __instance.YStart - hatIndex / __instance.NumPerRow * __instance.YOffset;
|
||||||
|
text.transform.localPosition = new Vector3(xLerp, yLerp, -1f);
|
||||||
|
|
||||||
|
hatIndex += 5;
|
||||||
|
foreach (var visor in visors.OrderBy(HatManager.Instance.allVisors.IndexOf))
|
||||||
|
{
|
||||||
|
float hatXposition = __instance.XRange.Lerp(hatIndex % __instance.NumPerRow / (__instance.NumPerRow - 1f));
|
||||||
|
float hatYposition = __instance.YStart - hatIndex / __instance.NumPerRow * __instance.YOffset;
|
||||||
|
GenerateColorChip(__instance, new Vector2(hatXposition, hatYposition), visor);
|
||||||
|
hatIndex += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
__instance.scroller.ContentYBounds.max = -(__instance.YStart - (hatIndex + 1) / __instance.NumPerRow * __instance.YOffset) - 3f;
|
||||||
|
__instance.currentVisorIsEquipped = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void GenerateColorChip(VisorsTab __instance, Vector2 position, VisorData visor)
|
||||||
|
{
|
||||||
|
var colorChip = Object.Instantiate(__instance.ColorTabPrefab, __instance.scroller.Inner);
|
||||||
|
colorChip.gameObject.name = visor.ProductId;
|
||||||
|
colorChip.Button.OnClick.AddListener((Action)(() => __instance.ClickEquip()));
|
||||||
|
colorChip.Button.OnMouseOver.AddListener((Action)(() => __instance.SelectVisor(visor)));
|
||||||
|
colorChip.Button.OnMouseOut.AddListener((Action)(() => __instance.SelectVisor(HatManager.Instance.GetVisorById(DataManager.Player.Customization.Visor))));
|
||||||
|
colorChip.Button.ClickMask = __instance.scroller.Hitbox;
|
||||||
|
colorChip.ProductId = visor.ProductId;
|
||||||
|
colorChip.SelectionHighlight.gameObject.SetActive(false);
|
||||||
|
__instance.UpdateMaterials(colorChip.Inner.FrontLayer, visor);
|
||||||
|
visor.SetPreview(colorChip.Inner.FrontLayer, __instance.HasLocalPlayer() ? PlayerControl.LocalPlayer.Data.DefaultOutfit.ColorId : DataManager.Player.Customization.Color);
|
||||||
|
colorChip.transform.localPosition = new Vector3(position.x, position.y, -1f);
|
||||||
|
colorChip.Inner.transform.localPosition = visor.ChipOffset + new Vector2(0f, -0.3f);
|
||||||
|
colorChip.Tag = visor;
|
||||||
|
__instance.ColorChips.Add(colorChip);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,12 +1,9 @@
|
|||||||
using BepInEx.Unity.IL2CPP.Utils;
|
using Il2CppInterop.Runtime.Attributes;
|
||||||
using Il2CppInterop.Runtime.Attributes;
|
using MiraAPI.Patches.Menu;
|
||||||
using Reactor.Utilities;
|
using Reactor.Utilities;
|
||||||
using Reactor.Utilities.Attributes;
|
|
||||||
using System;
|
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using UnityEngine;
|
|
||||||
using UnityEngine.AddressableAssets;
|
using UnityEngine.AddressableAssets;
|
||||||
using UnityEngine.ResourceManagement.AsyncOperations;
|
using UnityEngine.ResourceManagement.AsyncOperations;
|
||||||
|
|
||||||
@@ -15,14 +12,14 @@ namespace MiraAPI.Utilities.Assets;
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The component for loading Addressables, and cosmetics.
|
/// The component for loading Addressables, and cosmetics.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class AddressablesLoader
|
public static class AddressablesLoader
|
||||||
{
|
{
|
||||||
private static readonly List<(string Location, string ProviderSuffix)> CatalogLocations = [];
|
private static readonly List<(string Location, string ProviderSuffix)> CatalogLocations = [];
|
||||||
private static readonly List<string> LoadedLocations = [];
|
private static readonly List<string> LoadedLocations = [];
|
||||||
|
|
||||||
private static readonly List<string> RegisteredHatKeys = [];
|
private static readonly List<string> RegisteredHatKeys = [];
|
||||||
private static readonly List<string> RegisteredVisorKeys = [];
|
private static readonly List<(string, string)> RegisteredVisorKeys = [];
|
||||||
private static readonly List<string> RegisteredNameplateKeys = [];
|
private static readonly List<(string, string)> RegisteredNameplateKeys = [];
|
||||||
private static readonly List<string> RegisteredSkinKeys = [];
|
private static readonly List<string> RegisteredSkinKeys = [];
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -30,29 +27,47 @@ public class AddressablesLoader
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="location">The location, remote or otherwise, of the addressables.</param>
|
/// <param name="location">The location, remote or otherwise, of the addressables.</param>
|
||||||
/// <param name="providerSuffix">The suffix of the provider for an addressables package.</param>
|
/// <param name="providerSuffix">The suffix of the provider for an addressables package.</param>
|
||||||
public static void RegisterToLoad(string location, string providerSuffix = "")
|
public static void RegisterCatalog(string location, string providerSuffix = "")
|
||||||
{
|
{
|
||||||
CatalogLocations.Add((location, providerSuffix));
|
CatalogLocations.Add((location, providerSuffix));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Registers a specific addressables key as only containing <see cref="HatData"/>'s to load.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="addressables_key">The key/label/group for a List <see cref="HatData"/>.</param>
|
||||||
public static void RegisterHats(string addressables_key)
|
public static void RegisterHats(string addressables_key)
|
||||||
{
|
{
|
||||||
RegisteredHatKeys.Add(addressables_key);
|
RegisteredHatKeys.Add(addressables_key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Registers a specific addressables key as only containing <see cref="SkinData"/>'s to load.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="addressables_key">The key/label/group for a List <see cref="SkinData"/>.</param>
|
||||||
public static void RegisterSkins(string addressables_key)
|
public static void RegisterSkins(string addressables_key)
|
||||||
{
|
{
|
||||||
RegisteredSkinKeys.Add(addressables_key);
|
RegisteredSkinKeys.Add(addressables_key);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void RegisterNameplates(string addressables_key)
|
/// <summary>
|
||||||
|
/// Registers a specific addressables key as only containing <see cref="NamePlateData"/>'s to load.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="addressables_key">The key/label/group for a List <see cref="NamePlateData"/>.</param>
|
||||||
|
/// /// <param name="group_title">The title of the group for visors.</param>
|
||||||
|
public static void RegisterNameplates(string addressables_key, string group_title)
|
||||||
{
|
{
|
||||||
RegisteredNameplateKeys.Add(addressables_key);
|
RegisteredNameplateKeys.Add((addressables_key, group_title));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void RegisterVisors(string addressables_key)
|
/// <summary>
|
||||||
|
/// Registers a specific addressables key as only containing <see cref="VisorData"/>'s to load.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="addressables_key">The key/label/group for a List <see cref="VisorData"/>.</param>
|
||||||
|
/// <param name="group_title">The title of the group for visors.</param>
|
||||||
|
public static void RegisterVisors(string addressables_key, string group_title)
|
||||||
{
|
{
|
||||||
RegisteredVisorKeys.Add(addressables_key);
|
RegisteredVisorKeys.Add((addressables_key, group_title));
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static void LoadAll()
|
internal static void LoadAll()
|
||||||
@@ -89,8 +104,8 @@ public class AddressablesLoader
|
|||||||
|
|
||||||
var hatBehaviours = DiscoverData<HatData>(RegisteredHatKeys);
|
var hatBehaviours = DiscoverData<HatData>(RegisteredHatKeys);
|
||||||
var skinBehaviours = DiscoverData<SkinData>(RegisteredSkinKeys);
|
var skinBehaviours = DiscoverData<SkinData>(RegisteredSkinKeys);
|
||||||
var namePlateBehaviours = DiscoverData<NamePlateData>(RegisteredNameplateKeys);
|
var namePlateBehaviours = DiscoverAndReportData<NamePlateData>(RegisteredNameplateKeys);
|
||||||
var visorBehaviours = DiscoverData<VisorData>(RegisteredVisorKeys);
|
var visorBehaviours = DiscoverAndReportData<VisorData>(RegisteredVisorKeys);
|
||||||
|
|
||||||
var hatData = new List<HatData>();
|
var hatData = new List<HatData>();
|
||||||
hatData.AddRange(DestroyableSingleton<HatManager>.Instance.allHats);
|
hatData.AddRange(DestroyableSingleton<HatManager>.Instance.allHats);
|
||||||
@@ -99,15 +114,18 @@ public class AddressablesLoader
|
|||||||
|
|
||||||
var skinData = new List<SkinData>();
|
var skinData = new List<SkinData>();
|
||||||
skinData.AddRange(DestroyableSingleton<HatManager>.Instance.allSkins);
|
skinData.AddRange(DestroyableSingleton<HatManager>.Instance.allSkins);
|
||||||
|
skinData.ForEach(x => x.StoreName = "Vanilla");
|
||||||
DestroyableSingleton<HatManager>.Instance.allSkins = PrepareArray(skinData, skinBehaviours);
|
DestroyableSingleton<HatManager>.Instance.allSkins = PrepareArray(skinData, skinBehaviours);
|
||||||
|
|
||||||
var visorData = new List<VisorData>();
|
var visorData = new List<VisorData>();
|
||||||
visorData.AddRange(DestroyableSingleton<HatManager>.Instance.allVisors);
|
visorData.AddRange(DestroyableSingleton<HatManager>.Instance.allVisors);
|
||||||
DestroyableSingleton<HatManager>.Instance.allVisors = PrepareArray(visorData, visorBehaviours);
|
VisorsTabPatches.AddRange(visorBehaviours);
|
||||||
|
DestroyableSingleton<HatManager>.Instance.allVisors = PrepareArray(visorData, visorBehaviours.Select(x=>x.Data).ToList());
|
||||||
|
|
||||||
var namePlateData = new List<NamePlateData>();
|
var namePlateData = new List<NamePlateData>();
|
||||||
namePlateData.AddRange(DestroyableSingleton<HatManager>.Instance.allNamePlates);
|
namePlateData.AddRange(DestroyableSingleton<HatManager>.Instance.allNamePlates);
|
||||||
DestroyableSingleton<HatManager>.Instance.allNamePlates = PrepareArray(namePlateData, namePlateBehaviours);
|
NameplatesTabPatches.AddRange(namePlateBehaviours);
|
||||||
|
DestroyableSingleton<HatManager>.Instance.allNamePlates = PrepareArray(namePlateData, namePlateBehaviours.Select(x => x.Data).ToList());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static T[] PrepareArray<T>(List<T> data, List<T> behaviours) where T : CosmeticData
|
private static T[] PrepareArray<T>(List<T> data, List<T> behaviours) where T : CosmeticData
|
||||||
@@ -141,4 +159,25 @@ public class AddressablesLoader
|
|||||||
}
|
}
|
||||||
return behaviours;
|
return behaviours;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static List<(string Category, T Data)> DiscoverAndReportData<T>(List<(string Tag, string Category)> tags)
|
||||||
|
{
|
||||||
|
var behaviours = new List<(string, T)>();
|
||||||
|
|
||||||
|
foreach (var tag in tags)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var all_locations = Addressables.LoadResourceLocationsAsync(tag.Tag).WaitForCompletion();
|
||||||
|
var assets = Addressables.LoadAssetsAsync<T>(all_locations, null, false).WaitForCompletion();
|
||||||
|
var array = new Il2CppSystem.Collections.Generic.List<T>(assets.Pointer);
|
||||||
|
behaviours.AddRange(array.ToArray().Select(x => (tag.Category, x)));
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
Logger<MiraApiPlugin>.Error($"Failed to find tag {tag}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return behaviours;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,8 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace MiraAPI.Utilities;
|
namespace MiraAPI.Utilities;
|
||||||
|
|
||||||
@@ -18,7 +16,8 @@ internal sealed class ControllableComparer<T> : IComparer<T> where T : IComparab
|
|||||||
_fallbackComparer = fallbackComparer;
|
_fallbackComparer = fallbackComparer;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Compare(T x, T y)
|
/// <inheritdoc/>
|
||||||
|
public int Compare(T? x, T? y)
|
||||||
{
|
{
|
||||||
if ((_forcedToBottom.Contains(x) && _forcedToBottom.Contains(y)) || (_forcedToTop.Contains(x) && _forcedToTop.Contains(y)))
|
if ((_forcedToBottom.Contains(x) && _forcedToBottom.Contains(y)) || (_forcedToTop.Contains(x) && _forcedToTop.Contains(y)))
|
||||||
return _fallbackComparer.Compare(x, y);
|
return _fallbackComparer.Compare(x, y);
|
||||||
|
|||||||
Reference in new issue
Block a user