Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
UIWorldSelect.cs
Go to the documentation of this file.
1using System;
3using System.Linq;
9using Terraria.ID;
10using Terraria.IO;
12using Terraria.UI;
14
16
17public class UIWorldSelect : UIState
18{
20
22
24
26
28
30
32
34
35 private bool skipDraw;
36
37 public override void OnInitialize()
38 {
40 uIElement.Width.Set(0f, 0.8f);
41 uIElement.MaxWidth.Set(650f, 0f);
42 uIElement.Top.Set(220f, 0f);
43 uIElement.Height.Set(-220f, 1f);
44 uIElement.HAlign = 0.5f;
45 UIPanel uIPanel = new UIPanel();
46 uIPanel.Width.Set(0f, 1f);
47 uIPanel.Height.Set(-110f, 1f);
48 uIPanel.BackgroundColor = new Color(33, 43, 79) * 0.8f;
49 uIElement.Append(uIPanel);
51 _worldList = new UIList();
52 _worldList.Width.Set(0f, 1f);
53 _worldList.Height.Set(0f, 1f);
54 _worldList.ListPadding = 5f;
55 uIPanel.Append(_worldList);
56 _scrollbar = new UIScrollbar();
57 _scrollbar.SetView(100f, 1000f);
58 _scrollbar.Height.Set(0f, 1f);
59 _scrollbar.HAlign = 1f;
62 uITextPanel.HAlign = 0.5f;
63 uITextPanel.Top.Set(-40f, 0f);
64 uITextPanel.SetPadding(15f);
65 uITextPanel.BackgroundColor = new Color(73, 94, 171);
66 uIElement.Append(uITextPanel);
68 uITextPanel2.Width.Set(-10f, 0.5f);
69 uITextPanel2.Height.Set(50f, 0f);
70 uITextPanel2.VAlign = 1f;
71 uITextPanel2.HAlign = 0f;
72 uITextPanel2.Top.Set(-45f, 0f);
73 uITextPanel2.OnMouseOver += FadedMouseOver;
74 uITextPanel2.OnMouseOut += FadedMouseOut;
75 uITextPanel2.OnLeftClick += GoBackClick;
76 uIElement.Append(uITextPanel2);
79 uITextPanel3.CopyStyle(uITextPanel2);
80 uITextPanel3.HAlign = 1f;
81 uITextPanel3.OnMouseOver += FadedMouseOver;
82 uITextPanel3.OnMouseOut += FadedMouseOut;
83 uITextPanel3.OnLeftClick += NewWorldClick;
84 uIElement.Append(uITextPanel3);
87 }
88
89 public override void Recalculate()
90 {
91 if (_scrollbar != null)
92 {
94 {
97 _worldList.Width.Set(0f, 1f);
98 }
100 {
103 _worldList.Width.Set(-25f, 1f);
104 }
105 }
106 base.Recalculate();
107 }
108
110 {
112 Main.newWorldName = Lang.gen[57].Value + " " + (Main.WorldList.Count + 1);
113 Main.menuMode = 888;
114 Main.MenuUI.SetState(new UIWorldCreation());
115 }
116
118 {
120 Main.menuMode = ((!Main.menuMultiplayer) ? 1 : 12);
121 }
122
124 {
126 ((UIPanel)evt.Target).BackgroundColor = new Color(73, 94, 171);
127 ((UIPanel)evt.Target).BorderColor = Colors.FancyUIFatButtonMouseOver;
128 }
129
131 {
132 ((UIPanel)evt.Target).BackgroundColor = new Color(63, 82, 151) * 0.7f;
133 ((UIPanel)evt.Target).BorderColor = Color.Black;
134 }
135
136 public override void OnActivate()
137 {
141 {
142 UILinkPointNavigator.ChangePoint(3000 + ((_worldList.Count == 0) ? 1 : 2));
143 }
144 }
145
146 private void UpdateWorldsList()
147 {
150 .ThenBy((WorldFileData x) => x.GetFileName());
151 int num = 0;
153 {
155 }
156 }
157
159 {
160 bool num = Main.ActivePlayerFileData.Player.difficulty == 3;
161 bool flag = file.GameMode == 3;
162 return num == flag;
163 }
164
165 public override void Draw(SpriteBatch spriteBatch)
166 {
167 if (skipDraw)
168 {
169 skipDraw = false;
170 return;
171 }
173 {
174 skipDraw = true;
175 Main.MenuUI.Draw(spriteBatch, new GameTime());
176 }
177 base.Draw(spriteBatch);
178 SetupGamepadPoints(spriteBatch);
179 }
180
181 private bool UpdateFavoritesCache()
182 {
185 {
186 if (x.IsFavorite && !y.IsFavorite)
187 {
188 return -1;
189 }
190 if (!x.IsFavorite && y.IsFavorite)
191 {
192 return 1;
193 }
194 if (x.Name == null)
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 (WorldFileData 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 = 2;
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 }
257 foreach (SnapPoint item in snapPoints.Where((SnapPoint a) => a.Name == "Play"))
258 {
259 array[item.Id, 0] = item;
260 }
261 foreach (SnapPoint item2 in snapPoints.Where((SnapPoint a) => a.Name == "Favorite"))
262 {
263 array[item2.Id, 1] = item2;
264 }
265 foreach (SnapPoint item3 in snapPoints.Where((SnapPoint a) => a.Name == "Cloud"))
266 {
267 array[item3.Id, 2] = item3;
268 }
269 foreach (SnapPoint item4 in snapPoints.Where((SnapPoint a) => a.Name == "Seed"))
270 {
271 array[item4.Id, 3] = item4;
272 }
273 foreach (SnapPoint item5 in snapPoints.Where((SnapPoint a) => a.Name == "Rename"))
274 {
275 array[item5.Id, 4] = item5;
276 }
277 foreach (SnapPoint item6 in snapPoints.Where((SnapPoint a) => a.Name == "Delete"))
278 {
279 array[item6.Id, 5] = item6;
280 }
281 num2 = num + 2;
282 int[] array2 = new int[_worldList.Count];
283 for (int j = 0; j < array2.Length; j++)
284 {
285 array2[j] = -1;
286 }
287 for (int k = 0; k < array.GetLength(1); k++)
288 {
289 int num4 = -1;
290 for (int l = 0; l < array.GetLength(0); l++)
291 {
292 if (array[l, k] != null)
293 {
295 uILinkPoint.Unlink();
297 if (num4 != -1)
298 {
299 uILinkPoint.Up = num4;
301 }
302 if (array2[l] != -1)
303 {
304 uILinkPoint.Left = array2[l];
306 }
307 uILinkPoint.Down = num;
308 if (k == 0)
309 {
311 }
312 num4 = num2;
313 array2[l] = num2;
314 UILinkPointNavigator.Shortcuts.FANCYUI_HIGHEST_INDEX = num2;
315 num2++;
316 }
317 }
318 }
320 {
322 }
323 }
324}
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)
override void Draw(SpriteBatch spriteBatch)
UITextPanel< LocalizedText > _newPanel
void GoBackClick(UIMouseEvent evt, UIElement listeningElement)
void NewWorldClick(UIMouseEvent evt, UIElement listeningElement)
void SetupGamepadPoints(SpriteBatch spriteBatch)
void FadedMouseOut(UIMouseEvent evt, UIElement listeningElement)
UITextPanel< LocalizedText > _workshopPanel
UITextPanel< LocalizedText > _backPanel
void FadedMouseOver(UIMouseEvent evt, UIElement listeningElement)
List< Tuple< string, bool > > favoritesCache
static readonly Color FancyUIFatButtonMouseOver
Definition Colors.cs:91
string GetFileName(bool includeExtension=true)
Definition FileData.cs:43
static LocalizedText[] gen
Definition Lang.cs:22
static LocalizedText GetText(string key)
Definition Language.cs:10
static List< WorldFileData > WorldList
Definition Main.cs:1944
static void LoadWorlds()
Definition Main.cs:3642
static UserInterface MenuUI
Definition Main.cs:381
static float UIScale
Definition Main.cs:2624
static bool menuMultiplayer
Definition Main.cs:2091
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)