Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
UICharacterSelect.cs
Go to the documentation of this file.
1using System;
3using System.Linq;
9using Terraria.ID;
10using Terraria.IO;
12using Terraria.UI;
14
16
18{
20
22
24
26
28
30
32
33 private bool skipDraw;
34
35 public override void OnInitialize()
36 {
38 uIElement.Width.Set(0f, 0.8f);
39 uIElement.MaxWidth.Set(650f, 0f);
40 uIElement.Top.Set(220f, 0f);
41 uIElement.Height.Set(-220f, 1f);
42 uIElement.HAlign = 0.5f;
43 UIPanel uIPanel = new UIPanel();
44 uIPanel.Width.Set(0f, 1f);
45 uIPanel.Height.Set(-110f, 1f);
46 uIPanel.BackgroundColor = new Color(33, 43, 79) * 0.8f;
48 uIElement.Append(uIPanel);
49 _playerList = new UIList();
50 _playerList.Width.Set(0f, 1f);
51 _playerList.Height.Set(0f, 1f);
52 _playerList.ListPadding = 5f;
53 uIPanel.Append(_playerList);
54 _scrollbar = new UIScrollbar();
55 _scrollbar.SetView(100f, 1000f);
56 _scrollbar.Height.Set(0f, 1f);
57 _scrollbar.HAlign = 1f;
60 uITextPanel.HAlign = 0.5f;
61 uITextPanel.Top.Set(-40f, 0f);
62 uITextPanel.SetPadding(15f);
63 uITextPanel.BackgroundColor = new Color(73, 94, 171);
64 uIElement.Append(uITextPanel);
66 uITextPanel2.Width.Set(-10f, 0.5f);
67 uITextPanel2.Height.Set(50f, 0f);
68 uITextPanel2.VAlign = 1f;
69 uITextPanel2.Top.Set(-45f, 0f);
70 uITextPanel2.OnMouseOver += FadedMouseOver;
71 uITextPanel2.OnMouseOut += FadedMouseOut;
72 uITextPanel2.OnLeftClick += GoBackClick;
73 uITextPanel2.SetSnapPoint("Back", 0);
74 uIElement.Append(uITextPanel2);
77 uITextPanel3.CopyStyle(uITextPanel2);
78 uITextPanel3.HAlign = 1f;
79 uITextPanel3.OnMouseOver += FadedMouseOver;
80 uITextPanel3.OnMouseOut += FadedMouseOut;
81 uITextPanel3.OnLeftClick += NewCharacterClick;
82 uIElement.Append(uITextPanel3);
83 uITextPanel2.SetSnapPoint("New", 0);
86 }
87
88 public override void Recalculate()
89 {
90 if (_scrollbar != null)
91 {
93 {
96 _playerList.Width.Set(0f, 1f);
97 }
99 {
102 _playerList.Width.Set(-25f, 1f);
103 }
104 }
105 base.Recalculate();
106 }
107
109 {
111 Main.PendingPlayer = new Player();
112 Main.menuMode = 888;
114 }
115
117 {
119 Main.menuMode = 0;
120 }
121
123 {
125 ((UIPanel)evt.Target).BackgroundColor = new Color(73, 94, 171);
126 ((UIPanel)evt.Target).BorderColor = Colors.FancyUIFatButtonMouseOver;
127 }
128
130 {
131 ((UIPanel)evt.Target).BackgroundColor = new Color(63, 82, 151) * 0.7f;
132 ((UIPanel)evt.Target).BorderColor = Color.Black;
133 }
134
135 public override void OnActivate()
136 {
138 Main.ActivePlayerFileData = new PlayerFileData();
141 {
142 UILinkPointNavigator.ChangePoint(3000 + ((_playerList.Count == 0) ? 1 : 2));
143 }
144 }
145
146 private void UpdatePlayersList()
147 {
151 {
152 if (x.IsFavorite && !y.IsFavorite)
153 {
154 return -1;
155 }
156 if (!x.IsFavorite && y.IsFavorite)
157 {
158 return 1;
159 }
160 return (x.Name.CompareTo(y.Name) != 0) ? x.Name.CompareTo(y.Name) : x.GetFileName().CompareTo(y.GetFileName());
161 });
162 int num = 0;
163 foreach (PlayerFileData item in list)
164 {
166 }
167 }
168
169 public override void Draw(SpriteBatch spriteBatch)
170 {
171 if (skipDraw)
172 {
173 skipDraw = false;
174 return;
175 }
177 {
178 skipDraw = true;
179 Main.MenuUI.Draw(spriteBatch, new GameTime());
180 }
181 base.Draw(spriteBatch);
182 SetupGamepadPoints(spriteBatch);
183 }
184
185 private bool UpdateFavoritesCache()
186 {
189 {
190 if (x.IsFavorite && !y.IsFavorite)
191 {
192 return -1;
193 }
194 if (!x.IsFavorite && y.IsFavorite)
195 {
196 return 1;
197 }
198 return (x.Name.CompareTo(y.Name) != 0) ? x.Name.CompareTo(y.Name) : x.GetFileName().CompareTo(y.GetFileName());
199 });
200 bool flag = false;
201 if (!flag && list.Count != favoritesCache.Count)
202 {
203 flag = true;
204 }
205 if (!flag)
206 {
207 for (int i = 0; i < favoritesCache.Count; i++)
208 {
210 if (!(list[i].Name == tuple.Item1) || list[i].IsFavorite != tuple.Item2)
211 {
212 flag = true;
213 break;
214 }
215 }
216 }
217 if (flag)
218 {
220 foreach (PlayerFileData item in list)
221 {
222 favoritesCache.Add(Tuple.Create(item.Name, item.IsFavorite));
223 }
225 }
226 return flag;
227 }
228
229 private void SetupGamepadPoints(SpriteBatch spriteBatch)
230 {
231 UILinkPointNavigator.Shortcuts.BackButtonCommand = 1;
232 int num = 3000;
233 UILinkPointNavigator.SetPosition(num, _backPanel.GetInnerDimensions().ToRectangle().Center.ToVector2());
234 UILinkPointNavigator.SetPosition(num + 1, _newPanel.GetInnerDimensions().ToRectangle().Center.ToVector2());
235 int num2 = num;
237 uILinkPoint.Unlink();
238 uILinkPoint.Right = num2 + 1;
239 num2 = num + 1;
241 uILinkPoint.Unlink();
242 uILinkPoint.Left = num2 - 1;
243 float num3 = 1f / Main.UIScale;
246 Vector2 maximum = clippingRectangle.BottomRight() * num3;
248 for (int i = 0; i < snapPoints.Count; i++)
249 {
250 if (!snapPoints[i].Position.Between(minimum, maximum))
251 {
253 i--;
254 }
255 }
256 int num4 = 5;
258 foreach (SnapPoint item in snapPoints.Where((SnapPoint a) => a.Name == "Play"))
259 {
260 array[item.Id, 0] = item;
261 }
262 foreach (SnapPoint item2 in snapPoints.Where((SnapPoint a) => a.Name == "Favorite"))
263 {
264 array[item2.Id, 1] = item2;
265 }
266 foreach (SnapPoint item3 in snapPoints.Where((SnapPoint a) => a.Name == "Cloud"))
267 {
268 array[item3.Id, 2] = item3;
269 }
270 foreach (SnapPoint item4 in snapPoints.Where((SnapPoint a) => a.Name == "Rename"))
271 {
272 array[item4.Id, 3] = item4;
273 }
274 foreach (SnapPoint item5 in snapPoints.Where((SnapPoint a) => a.Name == "Delete"))
275 {
276 array[item5.Id, 4] = item5;
277 }
278 num2 = num + 2;
279 int[] array2 = new int[_playerList.Count];
280 for (int j = 0; j < array2.Length; j++)
281 {
282 array2[j] = -1;
283 }
284 for (int k = 0; k < num4; k++)
285 {
286 int num5 = -1;
287 for (int l = 0; l < array.GetLength(0); l++)
288 {
289 if (array[l, k] != null)
290 {
292 uILinkPoint.Unlink();
294 if (num5 != -1)
295 {
296 uILinkPoint.Up = num5;
298 }
299 if (array2[l] != -1)
300 {
301 uILinkPoint.Left = array2[l];
303 }
304 uILinkPoint.Down = num;
305 if (k == 0)
306 {
308 }
309 num5 = num2;
310 array2[l] = num2;
311 UILinkPointNavigator.Shortcuts.FANCYUI_HIGHEST_INDEX = num2;
312 num2++;
313 }
314 }
315 }
317 {
319 }
320 }
321}
bool ICollection< KeyValuePair< TKey, TValue > >. Remove(KeyValuePair< TKey, TValue > keyValuePair)
static void PlaySound(int type, Vector2 position, int style=1)
virtual void Add(UIElement item)
Definition UIList.cs:82
void SetScrollbar(UIScrollbar scrollbar)
Definition UIList.cs:141
void SetView(float viewSize, float maxViewSize)
void GoBackClick(UIMouseEvent evt, UIElement listeningElement)
void FadedMouseOut(UIMouseEvent evt, UIElement listeningElement)
override void Draw(SpriteBatch spriteBatch)
void FadedMouseOver(UIMouseEvent evt, UIElement listeningElement)
void NewCharacterClick(UIMouseEvent evt, UIElement listeningElement)
static readonly Color FancyUIFatButtonMouseOver
Definition Colors.cs:91
string GetFileName(bool includeExtension=true)
Definition FileData.cs:43
static LocalizedText GetText(string key)
Definition Language.cs:10
static UserInterface MenuUI
Definition Main.cs:381
static void LoadPlayers()
Definition Main.cs:3718
static float UIScale
Definition Main.cs:2624
static List< PlayerFileData > PlayerList
Definition Main.cs:1938
static Player PendingPlayer
Definition Main.cs:1942
static Dictionary< int, UILinkPoint > Points
static void SetPosition(int ID, Vector2 Position)
StyleDimension Height
Definition UIElement.cs:29
void Append(UIElement element)
Definition UIElement.cs:166
StyleDimension Width
Definition UIElement.cs:27
void RemoveChild(UIElement child)
Definition UIElement.cs:182
virtual List< SnapPoint > GetSnapPoints()
Definition UIElement.cs:267
Rectangle GetClippingRectangle(SpriteBatch spriteBatch)
Definition UIElement.cs:246
void Set(float pixels, float precent)