Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
UIResourcePackSelectionMenu.cs
Go to the documentation of this file.
2using System.Linq;
8using Terraria.ID;
10using Terraria.IO;
12using Terraria.UI;
14
16
18{
20
22
24
26
28
30
32
33 private const string _snapCategory_ToggleFromOffToOn = "ToggleToOn";
34
35 private const string _snapCategory_ToggleFromOnToOff = "ToggleToOff";
36
37 private const string _snapCategory_InfoWhenOff = "InfoOff";
38
39 private const string _snapCategory_InfoWhenOn = "InfoOn";
40
41 private const string _snapCategory_OffsetOrderUp = "OrderUp";
42
43 private const string _snapCategory_OffsetOrderDown = "OrderDown";
44
45 private const string _snapPointName_goBack = "GoBack";
46
47 private const string _snapPointName_openFolder = "OpenFolder";
48
50
59
60 private void PopulatePackList()
61 {
67 int num = 0;
68 foreach (ResourcePack item in disabledPacks)
69 {
71 {
73 };
75 uIElement.OnUpdate += EnablePackUpdate;
76 uIElement.SetSnapPoint("ToggleToOn", num);
77 uIResourcePack.ContentPanel.Append(uIElement);
79 uIElement.OnUpdate += SeeInfoUpdate;
80 uIElement.SetSnapPoint("InfoOff", num);
81 uIResourcePack.ContentPanel.Append(uIElement);
83 num++;
84 }
85 num = 0;
87 {
89 {
91 };
92 if (item2.IsEnabled)
93 {
95 uIElement2.Left = new StyleDimension(0f, 0f);
96 uIElement2.Width = new StyleDimension(0f, 0.5f);
97 uIElement2.OnUpdate += DisablePackUpdate;
98 uIElement2.SetSnapPoint("ToggleToOff", num);
99 uIResourcePack2.ContentPanel.Append(uIElement2);
101 uIElement2.OnUpdate += SeeInfoUpdate;
102 uIElement2.Left = new StyleDimension(0f, 0.5f);
103 uIElement2.Width = new StyleDimension(0f, 1f / 6f);
104 uIElement2.SetSnapPoint("InfoOn", num);
105 uIResourcePack2.ContentPanel.Append(uIElement2);
107 uIElement2.Left = new StyleDimension(0f, 2f / 3f);
108 uIElement2.Width = new StyleDimension(0f, 1f / 6f);
109 uIElement2.SetSnapPoint("OrderUp", num);
110 uIResourcePack2.ContentPanel.Append(uIElement2);
112 uIElement2.Left = new StyleDimension(0f, 0.8333334f);
113 uIElement2.Width = new StyleDimension(0f, 1f / 6f);
114 uIElement2.SetSnapPoint("OrderDown", num);
115 uIResourcePack2.ContentPanel.Append(uIElement2);
116 }
118 num++;
119 }
120 UpdateTitles();
121 }
122
124 {
125 GroupOptionButton<bool> groupOptionButton = new GroupOptionButton<bool>(option: true, null, null, Color.White, null, 0.8f)
126 {
129 Height = StyleDimension.Fill
130 };
131 bool num = (offset == -1 && resourcePack.SortingOrder == 0) | (offset == 1 && resourcePack.SortingOrder == _packsList.EnabledPacks.Count() - 1);
133 groupOptionButton.SetColorsBasedOnSelectionState(lightCyan, lightCyan, 0.7f, 0.7f);
134 groupOptionButton.ShowHighlightWhenSelected = false;
135 groupOptionButton.SetPadding(0f);
136 Asset<Texture2D> obj = Main.Assets.Request<Texture2D>("Images/UI/TexturePackButtons", (AssetRequestMode)1);
137 UIImageFramed element = new UIImageFramed(obj, obj.Frame(2, 2, (offset == 1) ? 1 : 0))
138 {
139 HAlign = 0.5f,
140 VAlign = 0.5f,
142 };
143 groupOptionButton.Append(element);
144 groupOptionButton.OnMouseOver += delegate
145 {
147 };
148 int offsetLocalForLambda = offset;
149 if (num)
150 {
151 groupOptionButton.OnLeftClick += delegate
152 {
154 };
155 }
156 else
157 {
158 groupOptionButton.OnLeftClick += delegate
159 {
163 Main.instance.ResetAllContentBasedRenderTargets();
164 };
165 }
166 if (offset == 1)
167 {
168 groupOptionButton.OnUpdate += OffsetFrontwardUpdate;
169 }
170 else
171 {
172 groupOptionButton.OnUpdate += OffsetBackwardUpdate;
173 }
174 return groupOptionButton;
175 }
176
178 {
179 Language.GetText(resourcePack.IsEnabled ? "GameUI.Enabled" : "GameUI.Disabled");
180 GroupOptionButton<bool> groupOptionButton = new GroupOptionButton<bool>(option: true, null, null, Color.White, null, 0.8f);
181 groupOptionButton.Left = StyleDimension.FromPercent(0.5f);
182 groupOptionButton.Width = StyleDimension.FromPixelsAndPercent(0f, 0.5f);
183 groupOptionButton.Height = StyleDimension.Fill;
184 groupOptionButton.SetColorsBasedOnSelectionState(Color.LightGreen, Color.PaleVioletRed, 0.7f, 0.7f);
185 groupOptionButton.SetCurrentOption(resourcePack.IsEnabled);
186 groupOptionButton.ShowHighlightWhenSelected = false;
187 groupOptionButton.SetPadding(0f);
188 Asset<Texture2D> obj = Main.Assets.Request<Texture2D>("Images/UI/TexturePackButtons", (AssetRequestMode)1);
189 UIImageFramed element = new UIImageFramed(obj, obj.Frame(2, 2, (!resourcePack.IsEnabled) ? 1 : 0, 1))
190 {
191 HAlign = 0.5f,
192 VAlign = 0.5f,
194 };
195 groupOptionButton.Append(element);
196 groupOptionButton.OnMouseOver += delegate
197 {
199 };
200 groupOptionButton.OnLeftClick += delegate
201 {
203 resourcePack.IsEnabled = !resourcePack.IsEnabled;
206 Main.instance.ResetAllContentBasedRenderTargets();
207 };
208 return groupOptionButton;
209 }
210
212 {
213 if (!resourcePack.IsEnabled)
214 {
215 return;
216 }
217 int num = -1;
219 {
220 if (num < enabledPack.SortingOrder && enabledPack != resourcePack)
221 {
222 num = enabledPack.SortingOrder;
223 }
224 }
225 resourcePack.SortingOrder = num + 1;
226 }
227
229 {
230 if (resourcePack.IsEnabled)
231 {
233 int num = list.IndexOf(resourcePack);
234 int num2 = Utils.Clamp(num + offset, 0, list.Count - 1);
235 if (num2 != num)
236 {
237 int sortingOrder = list[num].SortingOrder;
238 list[num].SortingOrder = list[num2].SortingOrder;
239 list[num2].SortingOrder = sortingOrder;
240 }
241 }
242 }
243
245 {
247 uIResourcePackInfoButton.Width = StyleDimension.FromPixelsAndPercent(0f, 0.5f);
248 uIResourcePackInfoButton.Height = StyleDimension.Fill;
249 uIResourcePackInfoButton.ResourcePack = resourcePack;
250 uIResourcePackInfoButton.SetPadding(0f);
251 UIImage element = new UIImage(Main.Assets.Request<Texture2D>("Images/UI/CharCreation/CharInfo", (AssetRequestMode)1))
252 {
253 HAlign = 0.5f,
254 VAlign = 0.5f,
256 };
257 uIResourcePackInfoButton.Append(element);
258 uIResourcePackInfoButton.OnMouseOver += delegate
259 {
261 };
262 uIResourcePackInfoButton.OnLeftClick += Click_Info;
264 }
265
274
279
281 {
283 int num = 0;
284 foreach (ResourcePack item in orderedEnumerable)
285 {
286 item.SortingOrder = num++;
287 }
288 }
289
290 private void BuildPage()
291 {
294 uIElement.Width.Set(0f, 0.8f);
295 uIElement.MaxWidth.Set(800f, 0f);
296 uIElement.MinWidth.Set(600f, 0f);
297 uIElement.Top.Set(240f, 0f);
298 uIElement.Height.Set(-240f, 1f);
299 uIElement.HAlign = 0.5f;
302 {
304 Height = new StyleDimension(-110f, 1f),
305 BackgroundColor = new Color(33, 43, 79) * 0.8f,
306 PaddingRight = 0f,
307 PaddingLeft = 0f
308 };
309 uIElement.Append(uIPanel);
310 int num = 35;
311 int num2 = num;
312 int num3 = 30;
314 {
317 VAlign = 1f
318 };
319 uIElement2.SetPadding(0f);
320 uIPanel.Append(uIElement2);
322 {
323 Width = new StyleDimension(-20f, 0.5f),
324 Height = new StyleDimension(0f, 1f),
325 Left = new StyleDimension(10f, 0f)
326 };
327 uIElement3.SetPadding(0f);
328 uIElement2.Append(uIElement3);
330 {
331 Width = new StyleDimension(-20f, 0.5f),
332 Height = new StyleDimension(0f, 1f),
333 Left = new StyleDimension(-10f, 0f),
334 HAlign = 1f
335 };
336 uIElement4.SetPadding(0f);
337 uIElement2.Append(uIElement4);
338 UIList uIList = new UIList
339 {
340 Width = new StyleDimension(-25f, 1f),
341 Height = new StyleDimension(0f, 1f),
342 ListPadding = 5f,
343 HAlign = 1f
344 };
345 uIElement3.Append(uIList);
347 UIList uIList2 = new UIList
348 {
349 Width = new StyleDimension(-25f, 1f),
350 Height = new StyleDimension(0f, 1f),
351 ListPadding = 5f,
352 HAlign = 0f,
353 Left = new StyleDimension(0f, 0f)
354 };
355 uIElement4.Append(uIList2);
357 uIPanel.Append(_titleAvailable = new UIText(Language.GetText("UI.AvailableResourcePacksTitle"))
358 {
359 HAlign = 0f,
360 Left = new StyleDimension(25f, 0f),
361 Width = new StyleDimension(-25f, 0.5f),
362 VAlign = 0f,
363 Top = new StyleDimension(10f, 0f)
364 });
365 uIPanel.Append(_titleEnabled = new UIText(Language.GetText("UI.EnabledResourcePacksTitle"))
366 {
367 HAlign = 1f,
368 Left = new StyleDimension(-25f, 0f),
369 Width = new StyleDimension(-25f, 0.5f),
370 VAlign = 0f,
371 Top = new StyleDimension(10f, 0f)
372 });
374 {
375 HAlign = 0.5f,
376 VAlign = 0f,
377 Top = new StyleDimension(-44f, 0f),
378 BackgroundColor = new Color(73, 94, 171)
379 };
380 uITextPanel.SetPadding(13f);
381 uIElement.Append(uITextPanel);
383 {
384 Height = new StyleDimension(0f, 1f),
385 HAlign = 0f,
386 Left = new StyleDimension(0f, 0f)
387 };
388 uIElement3.Append(uIScrollbar);
391 {
392 Height = new StyleDimension(-12f, 1f),
393 HAlign = 0.5f,
394 VAlign = 1f,
395 Color = new Color(89, 116, 213, 255) * 0.9f
396 };
397 uIPanel.Append(element);
399 {
400 Width = new StyleDimension(-num2, 0.5f),
401 VAlign = 0f,
402 HAlign = 0f,
403 Color = new Color(89, 116, 213, 255) * 0.9f,
404 Top = new StyleDimension(num3, 0f),
405 Left = new StyleDimension(num, 0f)
406 };
408 {
409 Width = new StyleDimension(-num2, 0.5f),
410 VAlign = 0f,
411 HAlign = 1f,
412 Color = new Color(89, 116, 213, 255) * 0.9f,
413 Top = new StyleDimension(num3, 0f),
414 Left = new StyleDimension(-num, 0f)
415 };
417 {
418 Height = new StyleDimension(0f, 1f),
419 HAlign = 1f
420 };
421 uIElement4.Append(uIScrollbar2);
424 }
425
426 private void UpdateTitles()
427 {
428 _titleAvailable.SetText(Language.GetText("UI.AvailableResourcePacksTitle").FormatWith(new
429 {
430 Amount = _availablePacksList.Count
431 }));
432 _titleEnabled.SetText(Language.GetText("UI.EnabledResourcePacksTitle").FormatWith(new
433 {
434 Amount = _enabledPacksList.Count
435 }));
436 }
437
439 {
441 {
442 Width = new StyleDimension(-8f, 0.5f),
443 Height = new StyleDimension(50f, 0f),
444 VAlign = 1f,
445 HAlign = 0f,
446 Top = new StyleDimension(-45f, 0f)
447 };
448 uITextPanel.OnMouseOver += FadedMouseOver;
449 uITextPanel.OnMouseOut += FadedMouseOut;
450 uITextPanel.OnLeftClick += GoBackClick;
451 uITextPanel.SetSnapPoint("GoBack", 0);
454 {
455 Width = new StyleDimension(-8f, 0.5f),
456 Height = new StyleDimension(50f, 0f),
457 VAlign = 1f,
458 HAlign = 1f,
459 Top = new StyleDimension(-45f, 0f)
460 };
461 uITextPanel2.OnMouseOver += FadedMouseOver;
462 uITextPanel2.OnMouseOut += FadedMouseOut;
463 uITextPanel2.OnLeftClick += OpenFoldersClick;
464 uITextPanel2.SetSnapPoint("OpenFolder", 0);
466 }
467
474
479
481 {
485 if (_uiStateToGoBackTo != null)
486 {
488 return;
489 }
490 Main.menuMode = 0;
492 }
493
495 {
497 ((UIPanel)evt.Target).BackgroundColor = new Color(73, 94, 171);
498 ((UIPanel)evt.Target).BorderColor = Colors.FancyUIFatButtonMouseOver;
499 }
500
502 {
503 ((UIPanel)evt.Target).BackgroundColor = new Color(63, 82, 151) * 0.8f;
504 ((UIPanel)evt.Target).BorderColor = Color.Black;
505 }
506
508 {
509 DisplayMouseTextIfHovered(affectedElement, "UI.OffsetTexturePackPriorityDown");
510 }
511
513 {
514 DisplayMouseTextIfHovered(affectedElement, "UI.OffsetTexturePackPriorityUp");
515 }
516
518 {
519 DisplayMouseTextIfHovered(affectedElement, "UI.EnableTexturePack");
520 }
521
523 {
524 DisplayMouseTextIfHovered(affectedElement, "UI.DisableTexturePack");
525 }
526
528 {
529 DisplayMouseTextIfHovered(affectedElement, "UI.SeeTexturePackInfo");
530 }
531
533 {
534 if (affectedElement.IsMouseHovering)
535 {
536 string textValue = Language.GetTextValue(textKey);
537 Main.instance.MouseText(textValue, 0, 0);
538 }
539 }
540
541 public override void Draw(SpriteBatch spriteBatch)
542 {
543 base.Draw(spriteBatch);
544 SetupGamepadPoints(spriteBatch);
545 }
546
547 private void SetupGamepadPoints(SpriteBatch spriteBatch)
548 {
549 UILinkPointNavigator.Shortcuts.BackButtonCommand = 7;
550 int num = 3000;
551 int currentID = num;
565 for (int i = 0; i < snapPoints.Count; i++)
566 {
568 string name = snapPoint.Name;
569 if (!(name == "GoBack"))
570 {
571 if (name == "OpenFolder")
572 {
574 }
575 }
576 else
577 {
579 }
580 }
594 }
595}
static void PlaySound(int type, Vector2 position, int style=1)
void UseResourcePacks(ResourcePackList resourcePacks)
virtual void Add(UIElement item)
Definition UIList.cs:82
override List< SnapPoint > GetSnapPoints()
Definition UIList.cs:165
void SetScrollbar(UIScrollbar scrollbar)
Definition UIList.cs:141
void GoBackClick(UIMouseEvent evt, UIElement listeningElement)
void Click_Info(UIMouseEvent evt, UIElement listeningElement)
static void FadedMouseOut(UIMouseEvent evt, UIElement listeningElement)
void OffsetResourcePackPriority(ResourcePack resourcePack, int offset)
static void DisplayMouseTextIfHovered(UIElement affectedElement, string textKey)
void OpenFoldersClick(UIMouseEvent evt, UIElement listeningElement)
UIResourcePackSelectionMenu(UIState uiStateToGoBackTo, AssetSourceController sourceController, ResourcePackList currentResourcePackList)
static void FadedMouseOver(UIMouseEvent evt, UIElement listeningElement)
UIElement CreateOffsetButton(ResourcePack resourcePack, int offset)
static readonly Color FancyUIFatButtonMouseOver
Definition Colors.cs:91
IEnumerable< ResourcePack > DisabledPacks
IEnumerable< ResourcePack > EnabledPacks
static void GetResourcePacksFolderPathAndConfirmItExists(out JArray resourcePackJson, out string resourcePackFolder)
static LocalizedText GetText(string key)
Definition Language.cs:10
static string GetTextValue(string key)
Definition Language.cs:15
static UserInterface MenuUI
Definition Main.cs:381
static Main instance
Definition Main.cs:283
static IAssetRepository Assets
Definition Main.cs:209
static bool SaveSettings()
Definition Main.cs:3806
StyleDimension Height
Definition UIElement.cs:29
void Append(UIElement element)
Definition UIElement.cs:166
StyleDimension Left
Definition UIElement.cs:25
StyleDimension Width
Definition UIElement.cs:27
virtual List< SnapPoint > GetSnapPoints()
Definition UIElement.cs:267
StyleDimension Top
Definition UIElement.cs:23
static void OpenFolder(string folderPath)
Definition Utils.cs:772
static Color PaleVioletRed
Definition Color.cs:288
void LinkVerticalStrips(UILinkPoint[] stripOnLeft, UILinkPoint[] stripOnRight, int leftStripStartOffset)
void CullPointsOutOfElementArea(SpriteBatch spriteBatch, List< SnapPoint > pointsAtMiddle, UIElement container)
void PairLeftRight(UILinkPoint leftSide, UILinkPoint rightSide)
void LinkVerticalStripBottomSideToSingle(UILinkPoint[] strip, UILinkPoint theSingle)
UILinkPoint MakeLinkPointFromSnapPoint(int id, SnapPoint snap)
UILinkPoint[] GetVerticalStripFromCategoryName(ref int currentID, List< SnapPoint > pts, string categoryName)
void MoveToVisuallyClosestPoint(List< UILinkPoint > lostrefpoints)
static StyleDimension Fill
static StyleDimension FromPercent(float percent)
static StyleDimension FromPixelsAndPercent(float pixels, float percent)