From 9b210ec4be976001e4efdce29c291d093eb3344b Mon Sep 17 00:00:00 2001 From: Keelhauled Date: Sun, 21 Mar 2021 15:55:02 +0200 Subject: [PATCH] Stop using Lazy, it blows --- src/ClothingStateMenuX.Koikatu/Game.cs | 22 --------- src/ClothingStateMenuX.Koikatu/UI.cs | 65 +++++++++++++++++--------- 2 files changed, 44 insertions(+), 43 deletions(-) delete mode 100644 src/ClothingStateMenuX.Koikatu/Game.cs diff --git a/src/ClothingStateMenuX.Koikatu/Game.cs b/src/ClothingStateMenuX.Koikatu/Game.cs deleted file mode 100644 index 0609535..0000000 --- a/src/ClothingStateMenuX.Koikatu/Game.cs +++ /dev/null @@ -1,22 +0,0 @@ -using ChaCustom; -using HarmonyLib; -using KeelPlugins.Utils; -using TMPro; -using UnityEngine; - -namespace ClothingStateMenuX.Koikatu -{ - internal static class Game - { - public static Lazy Character = new Lazy(() => GameObject.FindObjectOfType()); - public static Lazy OutfitDropDown = new Lazy(() => Traverse.Create(Singleton.Instance).Field("ddCoordinate").GetValue()); - public static Lazy Sidebar = new Lazy(() => GameObject.Find("CustomScene/CustomRoot/FrontUIGroup/CvsDraw/Top")); - public static Lazy AccessoryToggles = new Lazy(() => Sidebar.Value.transform.Find("tglAcsGrp").gameObject); - public static Lazy ClothingStateToggles = new Lazy(() => Sidebar.Value.transform.Find("rbClothesState").gameObject); - public static Lazy TitleTextTemplate = new Lazy(() => Sidebar.Value.transform.Find("txtClothesState").gameObject); - public static Lazy NormalTextTemplate = new Lazy(() => Sidebar.Value.transform.Find("rbClothesState/imgRbCol00/textRbSelect").gameObject); - public static Lazy ButtonTemplate = new Lazy(() => Sidebar.Value.transform.Find("btnLightingInitialize/btnSelect").gameObject); - public static Lazy ButtonContainerTemplate = new Lazy(() => Sidebar.Value.transform.Find("btnLightingInitialize").gameObject); - public static Lazy SeparatorTemplate = new Lazy(() => Sidebar.Value.transform.Find("Separate").gameObject); - } -} diff --git a/src/ClothingStateMenuX.Koikatu/UI.cs b/src/ClothingStateMenuX.Koikatu/UI.cs index e2c6f29..7daa42c 100644 --- a/src/ClothingStateMenuX.Koikatu/UI.cs +++ b/src/ClothingStateMenuX.Koikatu/UI.cs @@ -1,4 +1,6 @@ using System.Collections.Generic; +using ChaCustom; +using HarmonyLib; using TMPro; using UILib; using UnityEngine; @@ -9,14 +11,35 @@ namespace ClothingStateMenuX.Koikatu { public static class UI { - private static string ID = "(CSMX)"; + private const string ID = "(CSMX)"; + private static ChaControl character; + private static TMP_Dropdown outfitDropDown; + private static GameObject sidebar; + //private static GameObject accessoryToggles; + private static GameObject clothingStateToggles; + private static GameObject titleTextTemplate; + private static GameObject normalTextTemplate; + private static GameObject buttonTemplate; + private static GameObject buttonContainerTemplate; + private static GameObject separatorTemplate; public static void CreateUI() { + character = GameObject.FindObjectOfType(); + outfitDropDown = Traverse.Create(Singleton.Instance).Field("ddCoordinate").GetValue(); + sidebar = GameObject.Find("CustomScene/CustomRoot/FrontUIGroup/CvsDraw/Top"); + //accessoryToggles = sidebar.transform.Find("tglAcsGrp").gameObject; + clothingStateToggles = sidebar.transform.Find("rbClothesState").gameObject; + titleTextTemplate = sidebar.transform.Find("txtClothesState").gameObject; + normalTextTemplate = sidebar.transform.Find("rbClothesState/imgRbCol00/textRbSelect").gameObject; + buttonTemplate = sidebar.transform.Find("btnLightingInitialize/btnSelect").gameObject; + buttonContainerTemplate = sidebar.transform.Find("btnLightingInitialize").gameObject; + separatorTemplate = sidebar.transform.Find("Separate").gameObject; + CreateTitle("Clothing Sets", 0); CreateClothingSets(1); CreateSeparator(2); - CreateClothingOptions(Game.ClothingStateToggles.Value.transform.GetSiblingIndex() + 1); + CreateClothingOptions(clothingStateToggles.transform.GetSiblingIndex() + 1); } public static void CreateClothingSets(int index) @@ -25,13 +48,13 @@ public static void CreateClothingSets(int index) var buttons = new List { - CreateButton("1", 14, () => Game.OutfitDropDown.Value.value = 0, container.transform), - CreateButton("2", 14, () => Game.OutfitDropDown.Value.value = 1, container.transform), - CreateButton("3", 14, () => Game.OutfitDropDown.Value.value = 2, container.transform), - CreateButton("4", 14, () => Game.OutfitDropDown.Value.value = 3, container.transform), - CreateButton("5", 14, () => Game.OutfitDropDown.Value.value = 4, container.transform), - CreateButton("6", 14, () => Game.OutfitDropDown.Value.value = 5, container.transform), - CreateButton("7", 14, () => Game.OutfitDropDown.Value.value = 6, container.transform), + CreateButton("1", 14, () => outfitDropDown.value = 0, container.transform), + CreateButton("2", 14, () => outfitDropDown.value = 1, container.transform), + CreateButton("3", 14, () => outfitDropDown.value = 2, container.transform), + CreateButton("4", 14, () => outfitDropDown.value = 3, container.transform), + CreateButton("5", 14, () => outfitDropDown.value = 4, container.transform), + CreateButton("6", 14, () => outfitDropDown.value = 5, container.transform), + CreateButton("7", 14, () => outfitDropDown.value = 6, container.transform), }; var pos = 0.03f; @@ -40,9 +63,9 @@ public static void CreateClothingSets(int index) foreach(var button in buttons) button.transform.SetRect(pos, 0f, pos += step, 1f); - buttons[Game.OutfitDropDown.Value.value].GetComponent