Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
UILinkPointNavigator.cs
Go to the documentation of this file.
1using System;
3using System.Linq;
9
10namespace Terraria.UI.Gamepad;
11
13{
14 public static class Shortcuts
15 {
16 public static int NPCS_IconsPerColumn = 100;
17
18 public static int NPCS_IconsTotal = 0;
19
20 public static int NPCS_LastHovered = -2;
21
22 public static bool NPCS_IconsDisplay = false;
23
24 public static int CRAFT_IconsPerRow = 100;
25
26 public static int CRAFT_IconsPerColumn = 100;
27
28 public static int CRAFT_CurrentIngredientsCount = 0;
29
30 public static int CRAFT_CurrentRecipeBig = 0;
31
32 public static int CRAFT_CurrentRecipeSmall = 0;
33
34 public static bool NPCCHAT_ButtonsLeft = false;
35
36 public static bool NPCCHAT_ButtonsMiddle = false;
37
38 public static bool NPCCHAT_ButtonsRight = false;
39
40 public static bool NPCCHAT_ButtonsRight2 = false;
41
42 public static int INGAMEOPTIONS_BUTTONS_LEFT = 0;
43
44 public static int INGAMEOPTIONS_BUTTONS_RIGHT = 0;
45
47
49
50 public static int BackButtonCommand;
51
52 public static bool BackButtonInUse = false;
53
54 public static bool BackButtonLock;
55
56 public static int FANCYUI_HIGHEST_INDEX = 1;
57
58 public static int FANCYUI_SPECIAL_INSTRUCTIONS = 0;
59
60 public static int INFOACCCOUNT = 0;
61
62 public static int BUILDERACCCOUNT = 0;
63
64 public static int BUFFS_PER_COLUMN = 0;
65
66 public static int BUFFS_DRAWN = 0;
67
68 public static int INV_MOVE_OPTION_CD = 0;
69 }
70
72
74
75 public static int CurrentPage = 1000;
76
77 public static int OldPage = 1000;
78
79 private static int XCooldown;
80
81 private static int YCooldown;
82
83 private static Vector2 LastInput;
84
85 private static int PageLeftCD;
86
87 private static int PageRightCD;
88
89 public static bool InUse;
90
91 public static int OverridePoint = -1;
92
93 private static int? _suggestedPointID;
94
95 private static int? _preSuggestionPoint;
96
97 public static int CurrentPoint => Pages[CurrentPage].CurrentPoint;
98
99 public static bool Available
100 {
101 get
102 {
103 if (!Main.playerInventory && !Main.ingameOptionsWindow && Main.player[Main.myPlayer].talkNPC == -1 && Main.player[Main.myPlayer].sign == -1 && !Main.mapFullscreen && !Main.clothesWindow && !Main.MenuUI.IsVisible)
104 {
105 return Main.InGameUI.IsVisible;
106 }
107 return true;
108 }
109 }
110
111 public static void SuggestUsage(int PointID)
112 {
113 if (Points.ContainsKey(PointID))
114 {
116 }
117 }
118
119 public static void ConsumeSuggestion()
120 {
121 if (_suggestedPointID.HasValue)
122 {
123 int value = _suggestedPointID.Value;
125 CurrentPage = Points[value].Page;
128 PlayerInput.Triggers.Current.UsedMovementKey = true;
129 }
130 }
131
132 public static void ClearSuggestion()
133 {
134 _suggestedPointID = null;
135 }
136
137 public static void GoToDefaultPage(int specialFlag = 0)
138 {
139 TileEntity tileEntity = Main.LocalPlayer.tileEntityAnchor.GetTileEntity();
140 if (Main.MenuUI.IsVisible)
141 {
142 CurrentPage = 1004;
143 }
144 else if (Main.InGameUI.IsVisible || specialFlag == 1)
145 {
146 CurrentPage = 1004;
147 }
148 else if (Main.gameMenu)
149 {
150 CurrentPage = 1000;
151 }
152 else if (Main.ingameOptionsWindow)
153 {
154 CurrentPage = 1001;
155 }
156 else if (Main.CreativeMenu.Enabled)
157 {
158 CurrentPage = 1005;
159 }
160 else if (Main.hairWindow)
161 {
162 CurrentPage = 12;
163 }
164 else if (Main.clothesWindow)
165 {
166 CurrentPage = 15;
167 }
168 else if (Main.npcShop != 0)
169 {
170 CurrentPage = 13;
171 }
172 else if (Main.InGuideCraftMenu)
173 {
174 CurrentPage = 0;
175 }
176 else if (Main.InReforgeMenu)
177 {
178 CurrentPage = 0;
179 }
180 else if (Main.player[Main.myPlayer].chest != -1)
181 {
182 CurrentPage = 4;
183 }
184 else if (tileEntity is TEDisplayDoll)
185 {
186 CurrentPage = 20;
187 }
188 else if (tileEntity is TEHatRack)
189 {
190 CurrentPage = 21;
191 }
192 else if (Main.player[Main.myPlayer].talkNPC != -1 || Main.player[Main.myPlayer].sign != -1)
193 {
194 CurrentPage = 1003;
195 }
196 else
197 {
198 CurrentPage = 0;
199 }
200 }
201
202 public static void Update()
203 {
204 bool inUse = InUse;
205 InUse = false;
206 bool flag = true;
207 if (flag)
208 {
210 if ((uint)currentInputMode <= 2u && !Main.gameMenu)
211 {
212 flag = false;
213 }
214 }
215 if (flag && PlayerInput.NavigatorRebindingLock > 0)
216 {
217 flag = false;
218 }
219 if (flag && !Main.gameMenu && !PlayerInput.UsingGamepadUI)
220 {
221 flag = false;
222 }
223 if (flag && !Main.gameMenu && PlayerInput.InBuildingMode)
224 {
225 flag = false;
226 }
227 if (flag && !Main.gameMenu && !Available)
228 {
229 flag = false;
230 }
231 bool flag2 = false;
232 if (!Pages.TryGetValue(CurrentPage, out var value))
233 {
234 flag2 = true;
235 }
236 else if (!value.IsValid())
237 {
238 flag2 = true;
239 }
240 if (flag2)
241 {
244 flag = false;
245 }
246 if (inUse != flag)
247 {
248 if (!flag)
249 {
250 value.Leave();
253 }
254 else
255 {
259 value.Enter();
260 }
261 if (flag)
262 {
264 {
265 Main.player[Main.myPlayer].releaseInventory = false;
266 }
267 Main.player[Main.myPlayer].releaseUseTile = false;
268 PlayerInput.LockGamepadTileUseButton = true;
269 }
270 if (!Main.gameMenu)
271 {
272 if (flag)
273 {
275 }
276 else
277 {
279 }
280 }
281 }
283 if (!flag)
284 {
285 return;
286 }
287 InUse = true;
288 OverridePoint = -1;
289 if (PageLeftCD > 0)
290 {
291 PageLeftCD--;
292 }
293 if (PageRightCD > 0)
294 {
295 PageRightCD--;
296 }
297 Vector2 navigatorDirections = PlayerInput.Triggers.Current.GetNavigatorDirections();
298 bool num = PlayerInput.Triggers.Current.HotbarMinus && !PlayerInput.Triggers.Current.HotbarPlus;
299 bool flag3 = PlayerInput.Triggers.Current.HotbarPlus && !PlayerInput.Triggers.Current.HotbarMinus;
300 if (!num)
301 {
302 PageLeftCD = 0;
303 }
304 if (!flag3)
305 {
306 PageRightCD = 0;
307 }
308 bool num2 = num && PageLeftCD == 0;
309 flag3 = flag3 && PageRightCD == 0;
311 {
312 XCooldown = 0;
313 }
315 {
316 YCooldown = 0;
317 }
318 if (XCooldown > 0)
319 {
320 XCooldown--;
321 }
322 if (YCooldown > 0)
323 {
324 YCooldown--;
325 }
327 if (num2)
328 {
329 PageLeftCD = 16;
330 }
331 if (flag3)
332 {
333 PageRightCD = 16;
334 }
335 Pages[CurrentPage].Update();
336 int num3 = 10;
338 {
339 num3 = PlayerInput.CurrentProfile.InventoryMoveCD;
340 }
341 if (navigatorDirections.X == -1f && XCooldown == 0)
342 {
343 XCooldown = num3;
344 Pages[CurrentPage].TravelLeft();
345 }
346 if (navigatorDirections.X == 1f && XCooldown == 0)
347 {
348 XCooldown = num3;
349 Pages[CurrentPage].TravelRight();
350 }
351 if (navigatorDirections.Y == -1f && YCooldown == 0)
352 {
353 YCooldown = num3;
354 Pages[CurrentPage].TravelUp();
355 }
356 if (navigatorDirections.Y == 1f && YCooldown == 0)
357 {
358 YCooldown = num3;
359 Pages[CurrentPage].TravelDown();
360 }
362 if (num2)
363 {
364 Pages[CurrentPage].SwapPageLeft();
365 }
366 if (flag3)
367 {
368 Pages[CurrentPage].SwapPageRight();
369 }
370 if (PlayerInput.Triggers.Current.UsedMovementKey)
371 {
372 Vector2 position = Points[CurrentPoint].Position;
374 float amount = 0.3f;
376 {
377 amount = 1f;
378 }
379 Vector2 vector = Vector2.Lerp(value2, position, amount);
380 if (Main.gameMenu)
381 {
382 if (Math.Abs(vector.X - position.X) <= 5f)
383 {
384 vector.X = position.X;
385 }
386 if (Math.Abs(vector.Y - position.Y) <= 5f)
387 {
388 vector.Y = position.Y;
389 }
390 }
391 PlayerInput.MouseX = (int)vector.X;
392 PlayerInput.MouseY = (int)vector.Y;
393 }
395 }
396
397 public static void ResetFlagsEnd()
398 {
399 Shortcuts.OPTIONS_BUTTON_SPECIALFEATURE = 0;
400 Shortcuts.BackButtonLock = false;
401 Shortcuts.BackButtonCommand = 0;
402 }
403
404 public static string GetInstructions()
405 {
408 if (_suggestedPointID.HasValue)
409 {
414 uILinkPage.CurrentPoint = _suggestedPointID.Value;
415 }
416 string text = uILinkPage.SpecialInteractions();
417 if ((PlayerInput.SettingsForUI.CurrentCursorMode == CursorMode.Gamepad && PlayerInput.Triggers.Current.UsedMovementKey && InUse) || _suggestedPointID.HasValue)
418 {
419 string text2 = uILinkPoint.SpecialInteractions();
420 if (!string.IsNullOrEmpty(text2))
421 {
422 if (string.IsNullOrEmpty(text))
423 {
424 return text2;
425 }
426 text = text + " " + text2;
427 }
428 }
430 return text;
431 }
432
433 public static void SwapToSuggestion()
434 {
436 }
437
438 public static void ConsumeSuggestionSwap()
439 {
440 if (_preSuggestionPoint.HasValue)
441 {
442 int value = _preSuggestionPoint.Value;
443 CurrentPage = Points[value].Page;
444 Pages[CurrentPage].CurrentPoint = value;
445 }
446 _preSuggestionPoint = null;
447 }
448
449 public static void ForceMovementCooldown(int time)
450 {
451 LastInput = PlayerInput.Triggers.Current.GetNavigatorDirections();
452 XCooldown = time;
453 YCooldown = time;
454 }
455
456 public static void SetPosition(int ID, Vector2 Position)
457 {
458 Points[ID].Position = Position * Main.UIScale;
459 }
460
461 public static void RegisterPage(UILinkPage page, int ID, bool automatedDefault = true)
462 {
464 {
465 page.DefaultPoint = page.LinkMap.Keys.First();
466 }
467 page.CurrentPoint = page.DefaultPoint;
468 page.ID = ID;
469 Pages.Add(page.ID, page);
470 foreach (KeyValuePair<int, UILinkPoint> item in page.LinkMap)
471 {
472 item.Value.SetPage(ID);
473 Points.Add(item.Key, item.Value);
474 }
475 }
476
477 public static void ChangePage(int PageID)
478 {
479 if (Pages.ContainsKey(PageID) && Pages[PageID].CanEnter())
480 {
484 }
485 }
486
487 public static void ChangePoint(int PointID)
488 {
489 if (Points.ContainsKey(PointID))
490 {
491 CurrentPage = Points[PointID].Page;
494 }
495 }
496
497 public static void ProcessChanges()
498 {
500 if (OldPage != CurrentPage)
501 {
502 value.Leave();
503 if (!Pages.TryGetValue(CurrentPage, out value))
504 {
507 OverridePoint = -1;
508 }
509 value.CurrentPoint = value.DefaultPoint;
510 value.Enter();
511 value.Update();
513 }
514 if (OverridePoint != -1 && value.LinkMap.ContainsKey(OverridePoint))
515 {
516 value.CurrentPoint = OverridePoint;
517 }
518 }
519}
static double Abs(double value)
static byte Max(byte val1, byte val2)
Definition Math.cs:738
static void PlaySound(int type, Vector2 position, int style=1)
static TriggersPack Triggers
static bool PreventCursorModeSwappingToGamepad
static InputMode CurrentInputMode
static PlayerInputProfile CurrentProfile
static bool ingameOptionsWindow
Definition Main.cs:704
static UserInterface InGameUI
Definition Main.cs:383
static UserInterface MenuUI
Definition Main.cs:381
static int myPlayer
Definition Main.cs:1801
static bool inFancyUI
Definition Main.cs:706
static CreativeUI CreativeMenu
Definition Main.cs:369
static float UIScale
Definition Main.cs:2624
static bool clothesWindow
Definition Main.cs:702
static bool InReforgeMenu
Definition Main.cs:1908
static int npcShop
Definition Main.cs:2833
static bool InGuideCraftMenu
Definition Main.cs:1906
static bool playerInventory
Definition Main.cs:1759
static bool gameMenu
Definition Main.cs:1926
static Player LocalPlayer
Definition Main.cs:2829
static bool mapFullscreen
Definition Main.cs:932
static Player[] player
Definition Main.cs:1803
static bool hairWindow
Definition Main.cs:700
static void GoToDefaultPage(int specialFlag=0)
static Dictionary< int, UILinkPoint > Points
static void SetPosition(int ID, Vector2 Position)
static void RegisterPage(UILinkPage page, int ID, bool automatedDefault=true)
static Dictionary< int, UILinkPage > Pages
static Vector2 Lerp(Vector2 value1, Vector2 value2, float amount)
Definition Vector2.cs:227