This repository was archived by the owner on Jan 24, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathReMenuCategory.cs
240 lines (206 loc) · 8.52 KB
/
ReMenuCategory.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
using System;
using ReMod.Core.VRChat;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using VRC.UI.Elements;
using Object = UnityEngine.Object;
namespace ReMod.Core.UI.QuickMenu
{
public class ReMenuHeader : UiElement
{
private static GameObject _headerPrefab;
private static GameObject HeaderPrefab
{
get
{
if (_headerPrefab == null)
{
_headerPrefab = QuickMenuEx.Instance.field_Public_Transform_0
.Find("Window/QMParent/Menu_Dashboard/ScrollRect").GetComponent<ScrollRect>().content
.Find("Header_QuickActions").gameObject;
}
return _headerPrefab;
}
}
protected TextMeshProUGUI TextComponent;
public string Title
{
get => TextComponent.text;
set => TextComponent.text = value;
}
public ReMenuHeader(string title, Transform parent) : base(HeaderPrefab, (parent == null ? HeaderPrefab.transform.parent : parent), $"Header_{title}")
{
TextComponent = GameObject.GetComponentInChildren<TextMeshProUGUI>();
TextComponent.text = title;
TextComponent.richText = true;
TextComponent.transform.parent.GetComponent<HorizontalLayoutGroup>().childControlWidth = true;
}
public ReMenuHeader(Transform transform) : base(transform)
{
TextComponent = GameObject.GetComponentInChildren<TextMeshProUGUI>();
}
protected ReMenuHeader(GameObject original, Transform parent, Vector3 pos, string name, bool defaultState = true) : base(original, parent, pos, name, defaultState) { }
protected ReMenuHeader(GameObject original, Transform parent, string name, bool defaultState = true) : base(original, parent, name, defaultState) { }
}
public class ReMenuHeaderCollapsible : ReMenuHeader
{
private static GameObject _headerPrefab;
private static GameObject HeaderPrefab
{
get
{
if (_headerPrefab == null)
{
_headerPrefab = QuickMenuEx.Instance.field_Public_Transform_0
.Find("Window/QMParent/Menu_Settings/Panel_QM_ScrollRect").GetComponent<ScrollRect>().content
.Find("QM_Foldout_UI_Elements").gameObject;
}
return _headerPrefab;
}
}
public Action<bool> OnToggle;
public ReMenuHeaderCollapsible(string title, Transform parent) : base(HeaderPrefab, (parent == null ? HeaderPrefab.transform.parent : parent), $"Header_{title}")
{
TextComponent = GameObject.GetComponentInChildren<TextMeshProUGUI>();
TextComponent.text = title;
TextComponent.richText = true;
var foldout = GameObject.GetComponent<QMFoldout>();
foldout.field_Private_String_0 = $"UI.ReMod.{GetCleanName(title)}";
foldout.field_Private_Action_1_Boolean_0 = new Action<bool>(b => OnToggle?.Invoke(b));
}
public ReMenuHeaderCollapsible(Transform transform) : base(transform)
{
TextComponent = GameObject.GetComponentInChildren<TextMeshProUGUI>();
}
}
public class ReMenuButtonContainer : UiElement
{
private static GameObject _containerPrefab;
private static GameObject ContainerPrefab
{
get
{
if (_containerPrefab == null)
{
_containerPrefab = QuickMenuEx.Instance.field_Public_Transform_0
.Find("Window/QMParent/Menu_Dashboard/ScrollRect").GetComponent<ScrollRect>().content
.Find("Buttons_QuickActions").gameObject;
}
return _containerPrefab;
}
}
public ReMenuButtonContainer(string name, Transform parent = null) : base(ContainerPrefab, parent == null ? ContainerPrefab.transform.parent : parent, $"Buttons_{name}")
{
foreach (var obj in RectTransform)
{
var control = obj.Cast<Transform>();
if (control == null)
{
continue;
}
Object.Destroy(control.gameObject);
}
var gridLayout = GameObject.GetComponent<GridLayoutGroup>();
gridLayout.childAlignment = TextAnchor.UpperLeft;
gridLayout.padding.top = 8;
gridLayout.padding.left = 64;
}
public ReMenuButtonContainer(Transform transform) : base(transform)
{
}
}
public class ReMenuCategory : IButtonPage
{
public readonly ReMenuHeader Header;
private readonly ReMenuButtonContainer _buttonContainer;
public string Title
{
get => Header.Title;
set => Header.Title = value;
}
public bool Active
{
get => _buttonContainer.GameObject.activeInHierarchy;
set
{
Header.Active = value;
_buttonContainer.Active = value;
}
}
public ReMenuCategory(string title, Transform parent = null, bool collapsible = true)
{
if (collapsible)
{
var header = new ReMenuHeaderCollapsible(title, parent);
header.OnToggle += b => _buttonContainer!.GameObject.SetActive(b);
Header = header;
}
else
{
var header = new ReMenuHeader(title, parent);
Header = header;
}
_buttonContainer = new ReMenuButtonContainer(title, parent);
}
public ReMenuCategory(ReMenuHeader headerElement, ReMenuButtonContainer container)
{
Header = headerElement;
_buttonContainer = container;
}
public ReMenuButton AddButton(string text, string tooltip, Action onClick, Sprite sprite = null)
{
var button = new ReMenuButton(text, tooltip, onClick, _buttonContainer.RectTransform, sprite);
return button;
}
public ReMenuButton AddSpacer(Sprite sprite = null) {
var spacer = new ReMenuButton(string.Empty, string.Empty, null, _buttonContainer.RectTransform, sprite);
spacer.GameObject.name = "Button_Spacer";
spacer.Background.gameObject.SetActive(false);
return spacer;
}
public ReMenuToggle AddToggle(string text, string tooltip, Action<bool> onToggle, bool defaultValue = false)
{
var toggle = new ReMenuToggle(text, tooltip, onToggle, _buttonContainer.RectTransform, defaultValue);
return toggle;
}
public ReMenuToggle AddToggle(string text, string tooltip, ConfigValue<bool> configValue)
{
var toggle = new ReMenuToggle(text, tooltip, configValue.SetValue, _buttonContainer.RectTransform, configValue);
return toggle;
}
public ReMenuPage AddMenuPage(string text, string tooltip = "", Sprite sprite = null)
{
var existingPage = GetMenuPage(text);
if (existingPage != null)
{
return existingPage;
}
var menu = new ReMenuPage(text);
AddButton(text, string.IsNullOrEmpty(tooltip) ? $"Open the {text} menu" : tooltip, menu.Open, sprite);
return menu;
}
public ReCategoryPage AddCategoryPage(string text, string tooltip = "", Sprite sprite = null)
{
var existingPage = GetCategoryPage(text);
if (existingPage != null)
{
return existingPage;
}
var menu = new ReCategoryPage(text);
AddButton(text, string.IsNullOrEmpty(tooltip) ? $"Open the {text} menu" : tooltip, menu.Open, sprite);
return menu;
}
public RectTransform RectTransform => _buttonContainer.RectTransform;
public ReMenuPage GetMenuPage(string name)
{
var transform = QuickMenuEx.MenuParent.Find(UiElement.GetCleanName($"Menu_{name}"));
return transform == null ? null : new ReMenuPage(transform);
}
public ReCategoryPage GetCategoryPage(string name)
{
var transform = QuickMenuEx.MenuParent.Find(UiElement.GetCleanName($"Menu_{name}"));
return transform == null ? null : new ReCategoryPage(transform);
}
}
}