|
| 1 | +using KiraiMod.Core.UI.Elements; |
| 2 | +using KiraiMod.Core.UI.SideUI.Wrappers; |
| 3 | +using System; |
| 4 | +using System.Collections.Generic; |
| 5 | +using UnityEngine; |
| 6 | +using UnityEngine.UI; |
| 7 | + |
| 8 | +namespace KiraiMod.Core.UI.SideUI |
| 9 | +{ |
| 10 | + public class SideUI : AbstractUI |
| 11 | + { |
| 12 | + public static Lazy<SideUI> _globalContext = new(() => |
| 13 | + { |
| 14 | + SideUI ui = new(); |
| 15 | + Controller.Initialize(ui); |
| 16 | + return ui; |
| 17 | + }); |
| 18 | + |
| 19 | + public static SideUI GlobalContext |
| 20 | + { |
| 21 | + get => _globalContext.Value; |
| 22 | + } |
| 23 | + |
| 24 | + public List<BaseWrapper> Wrappers = new(); |
| 25 | + |
| 26 | + public SideUI Parent; |
| 27 | + public GameObject Sidebar; |
| 28 | + public RectTransform rect; |
| 29 | + |
| 30 | + public SideUI(string ID) : base(ID, null) { } |
| 31 | + private SideUI() : base("global.SideUI", "SideUI") |
| 32 | + { |
| 33 | + Sidebar = ElementFactory.CreateSide(Name, UIManager.ScreenUI.transform.parent); |
| 34 | + |
| 35 | + rect = Sidebar.transform.Cast<RectTransform>(); |
| 36 | + rect.sizeDelta = new(200, 0); |
| 37 | + rect.anchorMin = new(0, 1); |
| 38 | + rect.anchorMax = new(0, 1); |
| 39 | + rect.position = new(101, 1337.5f); |
| 40 | + } |
| 41 | + |
| 42 | + public void IncreaseSize() |
| 43 | + { |
| 44 | + rect.sizeDelta = rect.sizeDelta.AddY(25); |
| 45 | + rect.position = rect.position.AddY(-12.5f); |
| 46 | + } |
| 47 | + |
| 48 | + protected override BaseElement AddElement(BaseElement element) |
| 49 | + { |
| 50 | + Image image; |
| 51 | + Text text; |
| 52 | + BaseWrapper container; |
| 53 | + |
| 54 | + switch (element) |
| 55 | + { |
| 56 | + case BoundElement<bool> elemBool: |
| 57 | + (image, text) = ElementFactory.CreateElement(Sidebar, elemBool.Name); |
| 58 | + container = new ToggleWrapper(image, elemBool, text); |
| 59 | + break; |
| 60 | + |
| 61 | + case BoundElement<SideUI> elemMenu: |
| 62 | + if (elemMenu.Bound._value is null) return null; |
| 63 | + |
| 64 | + (image, text) = ElementFactory.CreateElement(Sidebar, $"< {elemMenu.Name} >"); |
| 65 | + |
| 66 | + SideUI ui = elemMenu.Bound._value; |
| 67 | + ui.Sidebar = ElementFactory.CreateSide(elemMenu.Name, Sidebar.transform); |
| 68 | + ui.Parent = this; |
| 69 | + ui.rect = ui.Sidebar.transform.Cast<RectTransform>(); |
| 70 | + ui.rect.sizeDelta = new(200, 0); |
| 71 | + ui.rect.localPosition = new(201, 87.5f); |
| 72 | + ui.Sidebar.active = false; |
| 73 | + |
| 74 | + container = new SideUIWrapper(image, elemMenu, text); |
| 75 | + break; |
| 76 | + |
| 77 | + default: |
| 78 | + return null; |
| 79 | + } |
| 80 | + |
| 81 | + IncreaseSize(); |
| 82 | + |
| 83 | + Wrappers.Add(container); |
| 84 | + if (Wrappers.Count == 1) |
| 85 | + Controller.Redraw(); |
| 86 | + |
| 87 | + return element; |
| 88 | + } |
| 89 | + |
| 90 | + public override bool RemoveElement(BaseElement element) |
| 91 | + { |
| 92 | + throw new NotImplementedException(); |
| 93 | + } |
| 94 | + |
| 95 | + public override bool RemoveElement(string element) |
| 96 | + { |
| 97 | + throw new NotImplementedException(); |
| 98 | + } |
| 99 | + } |
| 100 | +} |
0 commit comments