Elin Decompiled Documentation EA 23.102 Nightly
Loading...
Searching...
No Matches
WidgetRoster.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using Newtonsoft.Json;
4using UnityEngine;
5using UnityEngine.UI;
6
7public class WidgetRoster : Widget
8{
9 public class Extra
10 {
11 [JsonProperty]
12 public int width = 40;
13
14 [JsonProperty]
15 public int margin;
16
17 [JsonProperty]
18 public bool vertical;
19
20 [JsonProperty]
21 public bool pc;
22
23 [JsonProperty]
24 public bool portrait;
25
26 [JsonProperty]
27 public bool reverse;
28
29 [JsonProperty]
30 public bool onlyName;
31
32 [JsonProperty]
33 public bool showHP;
34 }
35
36 public static WidgetRoster Instance;
37
38 public GridLayoutGroup layout;
39
41
42 public RawImage imageGrid;
43
44 public Dictionary<Chara, ButtonRoster> buttons = new Dictionary<Chara, ButtonRoster>();
45
47
49
50 public bool showName;
51
52 public bool dirty;
53
54 public int maxWidth;
55
56 public Extra extra => base.config.extra as Extra;
57
58 public override bool AlwaysBottom => true;
59
60 public override Type SetSiblingAfter => typeof(WidgetBottomBar);
61
62 public override object CreateExtra()
63 {
64 return new Extra();
65 }
66
67 public override void OnActivate()
68 {
69 if (Mathf.Abs(extra.margin) > 100)
70 {
71 extra.margin = 0;
72 extra.width = 40;
73 extra.portrait = false;
74 extra.onlyName = true;
75 }
76 Instance = this;
77 mold = layout.CreateMold<ButtonRoster>();
78 Build();
79 }
80
81 private void OnEnable()
82 {
83 InvokeRepeating("Refresh", 0.2f, 0.2f);
84 }
85
86 private void OnDisable()
87 {
88 CancelInvoke();
89 }
90
91 public void OnMoveZone()
92 {
93 Build();
94 }
95
96 public void Build()
97 {
98 buttons.Clear();
99 layout.DestroyChildren();
100 layout.constraint = (extra.vertical ? GridLayoutGroup.Constraint.FixedColumnCount : GridLayoutGroup.Constraint.FixedRowCount);
101 layout.startCorner = (extra.reverse ? GridLayoutGroup.Corner.LowerRight : GridLayoutGroup.Corner.UpperLeft);
102 layout.cellSize = new Vector2(extra.width * 4 / 5, extra.onlyName ? 32 : extra.width);
103 layout.spacing = new Vector2(extra.margin, extra.margin);
104 foreach (Chara member in EMono.pc.party.members)
105 {
106 if (member != EMono.pc || extra.pc)
107 {
108 Add(member);
109 }
110 }
111 if (buttons.Count == 0)
112 {
113 Add(EMono.pc);
114 }
115 layout.RebuildLayout();
116 this.RebuildLayout();
119 }
120
121 public static void SetDirty()
122 {
123 if ((bool)Instance)
124 {
125 Instance.dirty = true;
126 }
127 }
128
129 public void Refresh()
130 {
131 if (dirty)
132 {
133 Build();
134 }
135 foreach (ButtonRoster value in buttons.Values)
136 {
137 value.Refresh();
138 }
139 dirty = false;
140 }
141
142 public void Add(Chara c)
143 {
144 ButtonRoster buttonRoster = Util.Instantiate(mold, layout);
145 buttonRoster.SetChara(c);
146 buttons.Add(c, buttonRoster);
147 }
148
149 public void Remove(Chara c)
150 {
151 UnityEngine.Object.DestroyImmediate(buttons[c].gameObject);
152 buttons.Remove(c);
153 }
154
155 public void OnAddMember(Chara c)
156 {
157 if (!buttons.ContainsKey(c))
158 {
159 Add(c);
160 }
161 }
162
163 public void OnRemoveMember(Chara c)
164 {
165 if (buttons.ContainsKey(c))
166 {
167 Remove(c);
168 }
169 }
170
171 public override void OnSetContextMenu(UIContextMenu m)
172 {
173 ButtonRoster b = InputModuleEX.GetComponentOf<ButtonRoster>();
174 int index;
175 if ((bool)b)
176 {
177 index = EMono.pc.party.members.IndexOf(b.chara);
178 int count = EMono.pc.party.members.Count;
179 if (index >= 1 && index < count - 1)
180 {
181 m.AddButton("next", delegate
182 {
183 Move(1);
184 });
185 }
186 if (index >= 2)
187 {
188 m.AddButton("prev", delegate
189 {
190 Move(-1);
191 });
192 }
193 }
194 UIContextMenu uIContextMenu = m.AddChild("setting");
195 uIContextMenu.AddSlider("width", (float a) => a.ToString() ?? "", extra.width, delegate(float a)
196 {
197 extra.width = (int)a;
198 Build();
199 }, 30f, 160f, isInt: true);
200 uIContextMenu.AddSlider("margin", (float a) => a.ToString() ?? "", extra.margin, delegate(float a)
201 {
202 extra.margin = (int)a;
203 Build();
204 }, -50f, 50f, isInt: true);
205 uIContextMenu.AddToggle("roster_pc", extra.pc, delegate(bool a)
206 {
207 extra.pc = a;
208 Build();
209 });
210 uIContextMenu.AddToggle("vertical", extra.vertical, delegate(bool a)
211 {
212 extra.vertical = a;
213 Build();
214 });
215 uIContextMenu.AddToggle("roster_portrait", extra.portrait, delegate(bool a)
216 {
217 extra.portrait = a;
218 Build();
219 });
220 uIContextMenu.AddToggle("roster_onlyname", extra.onlyName, delegate(bool a)
221 {
222 extra.onlyName = a;
223 Build();
224 });
225 uIContextMenu.AddToggle("reverseOrder", extra.reverse, delegate(bool a)
226 {
227 extra.reverse = a;
228 Build();
229 });
230 m.AddChild("style").AddSlider("toggleButtonBG", (float a) => a.ToString() ?? "", base.config.skin.button, delegate(float a)
231 {
232 base.config.skin.button = (int)a;
233 ApplySkin();
234 }, 0f, base.config.skin.Skin.buttons.Count - 1, isInt: true);
236 void Move(int mod)
237 {
238 EMono.pc.party.Replace(b.chara, index + mod);
239 Build();
240 }
241 }
242}
void Refresh()
Definition: ButtonRoster.cs:35
void SetChara(Chara c)
Definition: ButtonRoster.cs:23
Definition: Chara.cs:10
Party party
Definition: Chara.cs:43
Definition: EMono.cs:4
static Chara pc
Definition: EMono.cs:13
void Replace(Chara c, int index)
Definition: Party.cs:103
List< Chara > members
Definition: Party.cs:18
UIContextMenuItem AddToggle(string idLang="", bool isOn=false, UnityAction< bool > action=null)
UIContextMenuItem AddSlider(string text, Func< float, string > textFunc, float value, Action< float > action, float min=0f, float max=1f, bool isInt=false, bool hideOther=true, bool useInput=false)
void AddButton(Func< string > funcText, UnityAction action=null)
UIContextMenu AddChild(string idLang, TextAnchor anchor)
static void SetDirty()
static WidgetRoster Instance
Definition: WidgetRoster.cs:36
void Build()
Definition: WidgetRoster.cs:96
void OnMoveZone()
Definition: WidgetRoster.cs:91
Dictionary< Chara, ButtonRoster > buttons
Definition: WidgetRoster.cs:44
UIButton moldDropperLeft
Definition: WidgetRoster.cs:46
RawImage imageGrid
Definition: WidgetRoster.cs:42
override bool AlwaysBottom
Definition: WidgetRoster.cs:58
UIButton moldDropperRight
Definition: WidgetRoster.cs:48
void OnDisable()
Definition: WidgetRoster.cs:86
GridLayoutGroup layout
Definition: WidgetRoster.cs:38
override Type SetSiblingAfter
Definition: WidgetRoster.cs:60
void Add(Chara c)
ButtonRoster mold
Definition: WidgetRoster.cs:40
void OnAddMember(Chara c)
override void OnSetContextMenu(UIContextMenu m)
override void OnActivate()
Definition: WidgetRoster.cs:67
void OnEnable()
Definition: WidgetRoster.cs:81
void OnRemoveMember(Chara c)
void Remove(Chara c)
void Refresh()
override object CreateExtra()
Definition: WidgetRoster.cs:62
Definition: Widget.cs:7
virtual void ApplySkin()
Definition: Widget.cs:556
void SetBaseContextMenu(UIContextMenu m)
Definition: Widget.cs:608
virtual void OnChangeResolution()
Definition: Widget.cs:457
void ClampToScreen()
Definition: Widget.cs:437