using GadgetCore.API; using GadgetCore.API.ConfigMenu; using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Text; using UnityEngine; using UnityEngine.UI; namespace QuickStack { public class GadgetConfigDropdownComponent : GadgetConfigComponent { public string Value { get; protected set; } public string[] Values { get; protected set; } public readonly string DefaultValue; private readonly Action ValueSetter; private RectTransform[] Entries; public GadgetConfigDropdownComponent(BasicGadgetConfigMenu configMenu, string name, string value, string[] values, Action valueSetter, float height = 0.1f) : base(configMenu, name, height) { Value = value; Values = values; ValueSetter = valueSetter; } private T GetFromStatic(string classString, string paramString) { var type = Type.GetType("GadgetCore" + "." + classString + ", GadgetCore"); var property = type.GetProperty(paramString, BindingFlags.Public | BindingFlags.Static); MethodInfo strGetter = property.GetGetMethod(); return (T)strGetter.Invoke(null, null); } public override void Build(RectTransform parent) { var ModConfigMenuText = GetFromStatic("SceneInjector", "ModConfigMenuText"); var BoxSprite = GetFromStatic("SceneInjector", "BoxSprite"); var textureMenuTile = GadgetCoreAPI.LoadTexture2D("menuTile.png"); var MenuTile = Sprite.Create(textureMenuTile, BoxSprite.rect, BoxSprite.pivot, BoxSprite.pixelsPerUnit, default, default, BoxSprite.border); if (!string.IsNullOrEmpty(Name)) { StringBuilder nameString = new StringBuilder(); int spacesAdded = 0; foreach (char c in Name) { if (nameString.Length > 0 && char.IsUpper(c) && !char.IsUpper(Name[nameString.Length - spacesAdded - 1]) && (Name.Length == 1 || !char.IsUpper(Name[nameString.Length - spacesAdded - 2]) || (Name.Length > 2 && !char.IsUpper(Name[nameString.Length - spacesAdded - 3])))) { spacesAdded++; nameString.Append(' '); } nameString.Append(nameString.Length > 0 ? c : char.ToUpper(c)); } Text label = new GameObject("Label", typeof(RectTransform), typeof(CanvasRenderer), typeof(Text)).GetComponent(); label.rectTransform.SetParent(parent); label.rectTransform.anchorMin = new Vector2(0f, 0f); label.rectTransform.anchorMax = new Vector2(0.25f, 1f); label.rectTransform.offsetMin = new Vector2(0, 0); label.rectTransform.offsetMax = new Vector2(-10, 0); label.text = nameString + ":"; label.font = ModConfigMenuText.GetComponent().font; label.fontSize = 12; label.horizontalOverflow = HorizontalWrapMode.Wrap; label.alignment = TextAnchor.MiddleLeft; } RectTransform button = new GameObject("Button", typeof(RectTransform), typeof(Button), typeof(CanvasRenderer), typeof(Image)).GetComponent(); button.SetParent(parent); button.anchorMin = new Vector2(0.25f, 0f); button.anchorMax = new Vector2(0.75f, 1f); button.offsetMin = new Vector2(10, 0); button.offsetMax = new Vector2(-10, 0); button.GetComponent().sprite = BoxSprite; button.GetComponent().type = Image.Type.Sliced; button.GetComponent().fillCenter = true; button.GetComponent