Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
UIVirtualKeyboard.cs
Go to the documentation of this file.
1using System;
8using Terraria.ID;
10using Terraria.UI;
12
14
16{
17 public delegate void KeyboardSubmitEvent(string text);
18
19 public enum KeyState
20 {
21 Default,
22 Symbol,
23 Shift
24 }
25
27
28 private static string _cancelCacheSign = "";
29
30 private static string _cancelCacheChest = "";
31
32 private const string DEFAULT_KEYS = "1234567890qwertyuiopasdfghjkl'zxcvbnm,.?";
33
34 private const string SHIFT_KEYS = "1234567890QWERTYUIOPASDFGHJKL'ZXCVBNM,.?";
35
36 private const string SYMBOL_KEYS = "1234567890!@#$%^&*()-_+=/\\{}[]<>;:\"`|~£¥";
37
38 private const float KEY_SPACING = 4f;
39
40 private const float KEY_WIDTH = 48f;
41
42 private const float KEY_HEIGHT = 37f;
43
45
47
49
51
53
55
56 private UIText _label;
57
59
61
63
65
67
68 private Color _internalBorderColor = new Color(89, 116, 213);
69
71
73
75
77
79
80 private bool _allowEmpty;
81
83
84 private KeyboardSubmitEvent _submitAction;
85
86 private Action _cancelAction;
87
88 private int _lastOffsetDown;
89
90 public static int OffsetDown;
91
92 public static bool ShouldHideText;
93
94 private int _keyboardContext;
95
96 private bool _edittingSign;
97
98 private bool _edittingChest;
99
100 private float _textBoxHeight;
101
102 private float _labelHeight;
103
104 public Func<string, bool> CustomTextValidationForUpdate;
105
106 public Func<string, bool> CustomTextValidationForSubmit;
107
108 public Func<bool> CustomEscapeAttempt;
109
110 private bool _canSubmit;
111
112 public string Text
113 {
114 get
115 {
116 return _textBox.Text;
117 }
118 set
119 {
121 ValidateText();
122 }
123 }
124
125 public bool HideContents
126 {
127 get
128 {
129 return _textBox.HideContents;
130 }
131 set
132 {
133 _textBox.HideContents = value;
134 }
135 }
136
137 public static bool CanSubmit
138 {
139 get
140 {
141 if (_currentInstance != null)
142 {
143 return _currentInstance._canSubmit;
144 }
145 return false;
146 }
147 }
148
149 public static int KeyboardContext
150 {
151 get
152 {
153 if (_currentInstance == null)
154 {
155 return -1;
156 }
157 return _currentInstance._keyboardContext;
158 }
159 }
160
161 public UIVirtualKeyboard(string labelText, string startingText, KeyboardSubmitEvent submitAction, Action cancelAction, int inputMode = 0, bool allowEmpty = false)
162 {
163 _keyboardContext = inputMode;
164 _allowEmpty = allowEmpty;
165 OffsetDown = 0;
166 ShouldHideText = false;
167 _lastOffsetDown = 0;
170 _currentInstance = this;
171 _submitAction = submitAction;
172 _cancelAction = cancelAction;
173 _textureShift = Main.Assets.Request<Texture2D>("Images/UI/VK_Shift", (AssetRequestMode)1);
174 _textureBackspace = Main.Assets.Request<Texture2D>("Images/UI/VK_Backspace", (AssetRequestMode)1);
175 Top.Pixels = _lastOffsetDown;
176 float num = 0.5f;
177 float num2 = -20f;
178 float num3 = -5000 * _edittingSign.ToInt();
179 num2 = 270f;
180 num = 0f;
181 float num4 = 516f;
182 UIElement uIElement = new UIElement();
183 uIElement.Width.Pixels = num4 + 8f + 16f;
184 uIElement.Top.Precent = num;
185 uIElement.Top.Pixels = num2;
186 uIElement.Height.Pixels = 266f;
187 uIElement.HAlign = 0.5f;
188 uIElement.SetPadding(0f);
189 outerLayer1 = uIElement;
190 UIElement uIElement2 = new UIElement();
191 uIElement2.Width.Pixels = num4 + 8f + 16f;
192 uIElement2.Top.Precent = num;
193 uIElement2.Top.Pixels = num2;
194 uIElement2.Height.Pixels = 266f;
195 uIElement2.HAlign = 0.5f;
196 uIElement2.SetPadding(0f);
197 outerLayer2 = uIElement2;
198 UIPanel uIPanel = new UIPanel
199 {
200 Width =
201 {
202 Precent = 1f
203 },
204 Height =
205 {
206 Pixels = 225f
207 },
208 BackgroundColor = new Color(23, 33, 69) * 0.7f
209 };
210 uIElement.Append(uIPanel);
211 float num5 = -50f;
212 _textBox = new UITextBox("", 0.78f, large: true);
213 _textBox.BackgroundColor = Color.Transparent;
214 _textBox.BorderColor = Color.Transparent;
215 _textBox.HAlign = 0.5f;
216 _textBox.Width.Pixels = num4;
217 _textBox.Top.Pixels = num5 + num2 - 10f + num3;
218 _textBox.Top.Precent = num;
219 _textBox.Height.Pixels = 37f;
221 for (int i = 0; i < 10; i++)
222 {
223 for (int j = 0; j < 4; j++)
224 {
225 int index = j * 10 + i;
226 UITextPanel<object> uITextPanel = CreateKeyboardButton("1234567890qwertyuiopasdfghjkl'zxcvbnm,.?"[index].ToString(), i, j);
227 uITextPanel.OnLeftClick += TypeText;
228 uIPanel.Append(uITextPanel);
229 }
230 }
231 _shiftButton = CreateKeyboardButton("", 0, 4, 1, style: false);
232 _shiftButton.PaddingLeft = 0f;
233 _shiftButton.PaddingRight = 0f;
234 _shiftButton.PaddingBottom = (_shiftButton.PaddingTop = 0f);
235 _shiftButton.BackgroundColor = new Color(63, 82, 151) * 0.7f;
236 _shiftButton.BorderColor = _internalBorderColor * 0.7f;
237 _shiftButton.OnMouseOver += delegate
238 {
239 _shiftButton.BorderColor = _internalBorderColorSelected;
240 if (_keyState != KeyState.Shift)
241 {
242 _shiftButton.BackgroundColor = new Color(73, 94, 171);
243 }
244 };
245 _shiftButton.OnMouseOut += delegate
246 {
247 _shiftButton.BorderColor = _internalBorderColor * 0.7f;
248 if (_keyState != KeyState.Shift)
249 {
250 _shiftButton.BackgroundColor = new Color(63, 82, 151) * 0.7f;
251 }
252 };
253 _shiftButton.OnLeftClick += delegate
254 {
256 SetKeyState((_keyState != KeyState.Shift) ? KeyState.Shift : KeyState.Default);
257 };
258 UIImage element = new UIImage(_textureShift)
259 {
260 HAlign = 0.5f,
261 VAlign = 0.5f,
262 ImageScale = 0.85f
263 };
264 _shiftButton.Append(element);
265 uIPanel.Append(_shiftButton);
266 _symbolButton = CreateKeyboardButton("@%", 1, 4, 1, style: false);
267 _symbolButton.PaddingLeft = 0f;
268 _symbolButton.PaddingRight = 0f;
269 _symbolButton.BackgroundColor = new Color(63, 82, 151) * 0.7f;
270 _symbolButton.BorderColor = _internalBorderColor * 0.7f;
271 _symbolButton.OnMouseOver += delegate
272 {
273 _symbolButton.BorderColor = _internalBorderColorSelected;
274 if (_keyState != KeyState.Symbol)
275 {
276 _symbolButton.BackgroundColor = new Color(73, 94, 171);
277 }
278 };
279 _symbolButton.OnMouseOut += delegate
280 {
281 _symbolButton.BorderColor = _internalBorderColor * 0.7f;
282 if (_keyState != KeyState.Symbol)
283 {
284 _symbolButton.BackgroundColor = new Color(63, 82, 151) * 0.7f;
285 }
286 };
287 _symbolButton.OnLeftClick += delegate
288 {
290 SetKeyState((_keyState != KeyState.Symbol) ? KeyState.Symbol : KeyState.Default);
291 };
292 uIPanel.Append(_symbolButton);
293 BuildSpaceBarArea(uIPanel);
294 _submitButton = new UITextPanel<LocalizedText>((_edittingSign || _edittingChest) ? Language.GetText("UI.Save") : Language.GetText("UI.Submit"), 0.4f, large: true);
295 _submitButton.Height.Pixels = 37f;
296 _submitButton.Width.Precent = 0.4f;
297 _submitButton.HAlign = 1f;
298 _submitButton.VAlign = 1f;
299 _submitButton.PaddingLeft = 0f;
300 _submitButton.PaddingRight = 0f;
301 ValidateText();
302 _submitButton.OnMouseOver += FadedMouseOver;
303 _submitButton.OnMouseOut += FadedMouseOut;
304 _submitButton.OnMouseOver += delegate
305 {
306 ValidateText();
307 };
308 _submitButton.OnMouseOut += delegate
309 {
310 ValidateText();
311 };
312 _submitButton.OnLeftClick += delegate
313 {
314 Submit();
315 };
316 uIElement.Append(_submitButton);
317 _cancelButton = new UITextPanel<LocalizedText>(Language.GetText("UI.Cancel"), 0.4f, large: true);
318 StyleKey(_cancelButton, external: true);
319 _cancelButton.Height.Pixels = 37f;
320 _cancelButton.Width.Precent = 0.4f;
321 _cancelButton.VAlign = 1f;
322 _cancelButton.OnLeftClick += delegate
323 {
326 };
327 _cancelButton.OnMouseOver += FadedMouseOver;
328 _cancelButton.OnMouseOut += FadedMouseOut;
329 uIElement.Append(_cancelButton);
330 _submitButton2 = new UITextPanel<LocalizedText>((_edittingSign || _edittingChest) ? Language.GetText("UI.Save") : Language.GetText("UI.Submit"), 0.72f, large: true);
331 _submitButton2.TextColor = Color.Silver;
332 _submitButton2.DrawPanel = false;
333 _submitButton2.Height.Pixels = 60f;
334 _submitButton2.Width.Precent = 0.4f;
335 _submitButton2.HAlign = 0.5f;
336 _submitButton2.VAlign = 0f;
337 _submitButton2.OnMouseOver += delegate(UIMouseEvent a, UIElement b)
338 {
339 ((UITextPanel<LocalizedText>)b).TextScale = 0.85f;
340 ((UITextPanel<LocalizedText>)b).TextColor = Color.White;
341 };
342 _submitButton2.OnMouseOut += delegate(UIMouseEvent a, UIElement b)
343 {
344 ((UITextPanel<LocalizedText>)b).TextScale = 0.72f;
345 ((UITextPanel<LocalizedText>)b).TextColor = Color.Silver;
346 };
347 _submitButton2.Top.Pixels = 50f;
348 _submitButton2.PaddingLeft = 0f;
349 _submitButton2.PaddingRight = 0f;
350 ValidateText();
351 _submitButton2.OnMouseOver += delegate
352 {
353 ValidateText();
354 };
355 _submitButton2.OnMouseOut += delegate
356 {
357 ValidateText();
358 };
359 _submitButton2.OnMouseOver += FadedMouseOver;
360 _submitButton2.OnMouseOut += FadedMouseOut;
361 _submitButton2.OnLeftClick += delegate
362 {
364 {
366 _submitAction(Text.Trim());
367 }
368 };
370 _cancelButton2 = new UITextPanel<LocalizedText>(Language.GetText("UI.Cancel"), 0.72f, large: true);
371 _cancelButton2.TextColor = Color.Silver;
372 _cancelButton2.DrawPanel = false;
373 _cancelButton2.OnMouseOver += delegate(UIMouseEvent a, UIElement b)
374 {
375 ((UITextPanel<LocalizedText>)b).TextScale = 0.85f;
376 ((UITextPanel<LocalizedText>)b).TextColor = Color.White;
377 };
378 _cancelButton2.OnMouseOut += delegate(UIMouseEvent a, UIElement b)
379 {
380 ((UITextPanel<LocalizedText>)b).TextScale = 0.72f;
381 ((UITextPanel<LocalizedText>)b).TextColor = Color.Silver;
382 };
383 _cancelButton2.Height.Pixels = 60f;
384 _cancelButton2.Width.Precent = 0.4f;
385 _cancelButton2.Top.Pixels = 114f;
386 _cancelButton2.VAlign = 0f;
387 _cancelButton2.HAlign = 0.5f;
388 _cancelButton2.OnLeftClick += delegate
389 {
392 };
394 UITextPanel<object> uITextPanel2 = CreateKeyboardButton("", 8, 4, 2);
395 uITextPanel2.OnLeftClick += delegate
396 {
399 ValidateText();
400 };
401 uITextPanel2.PaddingLeft = 0f;
402 uITextPanel2.PaddingRight = 0f;
403 uITextPanel2.PaddingBottom = (uITextPanel2.PaddingTop = 0f);
404 uITextPanel2.Append(new UIImage(_textureBackspace)
405 {
406 HAlign = 0.5f,
407 VAlign = 0.5f,
408 ImageScale = 0.92f
409 });
410 uIPanel.Append(uITextPanel2);
411 UIText uIText = new UIText(labelText, 0.75f, large: true)
412 {
413 HAlign = 0.5f,
414 Width =
415 {
416 Pixels = num4
417 },
418 Top =
419 {
420 Pixels = num5 - 37f - 4f + num2 + num3,
421 Precent = num
422 },
423 Height =
424 {
425 Pixels = 37f
426 }
427 };
428 Append(uIText);
429 _label = uIText;
430 Append(uIElement);
431 int textMaxLength = (_edittingSign ? 1200 : 20);
432 _textBox.SetTextMaxLength(textMaxLength);
433 Text = startingText;
434 if (Text.Length == 0)
435 {
436 SetKeyState(KeyState.Shift);
437 }
438 ShouldHideText = true;
439 OffsetDown = 9999;
441 }
442
443 public void SetMaxInputLength(int length)
444 {
446 }
447
448 private void BuildSpaceBarArea(UIPanel mainPanel)
449 {
450 Action createTheseTwo = delegate
451 {
452 bool flag = CanRestore();
453 int x = (flag ? 4 : 5);
454 bool edittingSign = _edittingSign;
455 int num = ((flag && edittingSign) ? 2 : 3);
456 UITextPanel<object> uITextPanel = CreateKeyboardButton(Language.GetText("UI.SpaceButton"), 2, 4, (_edittingSign || (_edittingChest && flag)) ? num : 6);
457 uITextPanel.OnLeftClick += delegate
458 {
459 PressSpace();
460 };
461 mainPanel.Append(uITextPanel);
462 _spacebarButton = uITextPanel;
463 if (edittingSign)
464 {
465 UITextPanel<object> uITextPanel2 = CreateKeyboardButton(Language.GetText("UI.EnterButton"), x, 4, num);
466 uITextPanel2.OnLeftClick += delegate
467 {
469 _textBox.Write("\n");
470 ValidateText();
471 };
472 mainPanel.Append(uITextPanel2);
473 _enterButton = uITextPanel2;
474 }
475 };
476 createTheseTwo();
477 if (CanRestore())
478 {
479 UITextPanel<object> restoreBar = CreateKeyboardButton(Language.GetText("UI.RestoreButton"), 6, 4, 2);
480 restoreBar.OnLeftClick += delegate
481 {
484 ValidateText();
485 restoreBar.Remove();
486 _enterButton.Remove();
487 _spacebarButton.Remove();
488 createTheseTwo();
489 };
490 mainPanel.Append(restoreBar);
491 _restoreButton = restoreBar;
492 }
493 }
494
495 private void PressSpace()
496 {
497 string text = " ";
499 {
501 return;
502 }
505 ValidateText();
506 }
507
508 private bool CanRestore()
509 {
510 if (_edittingSign)
511 {
512 return _cancelCacheSign.Length > 0;
513 }
514 if (_edittingChest)
515 {
516 return _cancelCacheChest.Length > 0;
517 }
518 return false;
519 }
520
521 private void TypeText(UIMouseEvent evt, UIElement listeningElement)
522 {
523 string text = ((UITextPanel<object>)listeningElement).Text;
525 {
527 return;
528 }
530 bool num = Text.Length == 0;
532 ValidateText();
533 if (num && Text.Length > 0 && _keyState == KeyState.Shift)
534 {
535 SetKeyState(KeyState.Default);
536 }
537 }
538
539 public void SetKeyState(KeyState keyState)
540 {
541 UITextPanel<object> uITextPanel = null;
542 switch (_keyState)
543 {
544 case KeyState.Shift:
545 uITextPanel = _shiftButton;
546 break;
547 case KeyState.Symbol:
548 uITextPanel = _symbolButton;
549 break;
550 }
551 if (uITextPanel != null)
552 {
553 if (uITextPanel.IsMouseHovering)
554 {
555 uITextPanel.BackgroundColor = new Color(73, 94, 171);
556 }
557 else
558 {
559 uITextPanel.BackgroundColor = new Color(63, 82, 151) * 0.7f;
560 }
561 }
562 string text = null;
563 UITextPanel<object> uITextPanel2 = null;
564 switch (keyState)
565 {
566 case KeyState.Default:
567 text = "1234567890qwertyuiopasdfghjkl'zxcvbnm,.?";
568 break;
569 case KeyState.Shift:
570 text = "1234567890QWERTYUIOPASDFGHJKL'ZXCVBNM,.?";
571 uITextPanel2 = _shiftButton;
572 break;
573 case KeyState.Symbol:
574 text = "1234567890!@#$%^&*()-_+=/\\{}[]<>;:\"`|~£¥";
575 uITextPanel2 = _symbolButton;
576 break;
577 }
578 for (int i = 0; i < text.Length; i++)
579 {
580 _keyList[i].SetText(text[i].ToString());
581 }
582 _keyState = keyState;
583 if (uITextPanel2 != null)
584 {
585 uITextPanel2.BackgroundColor = new Color(93, 114, 191);
586 }
587 }
588
589 private void ValidateText()
590 {
592 {
593 _canSubmit = true;
594 _submitButton.TextColor = Color.White;
595 if (_submitButton.IsMouseHovering)
596 {
597 _submitButton.BackgroundColor = new Color(73, 94, 171);
598 }
599 else
600 {
601 _submitButton.BackgroundColor = new Color(63, 82, 151) * 0.7f;
602 }
603 }
604 else
605 {
606 _canSubmit = false;
607 _submitButton.TextColor = Color.Gray;
608 if (_submitButton.IsMouseHovering)
609 {
610 _submitButton.BackgroundColor = new Color(180, 60, 60) * 0.85f;
611 }
612 else
613 {
614 _submitButton.BackgroundColor = new Color(150, 40, 40) * 0.85f;
615 }
616 }
617 }
618
619 private bool TextIsValidForSubmit()
620 {
622 {
624 }
625 if (Text.Trim().Length <= 0 && !_edittingSign && !_edittingChest)
626 {
627 return _allowEmpty;
628 }
629 return true;
630 }
631
632 private void StyleKey<T>(UITextPanel<T> button, bool external = false)
633 {
634 button.PaddingLeft = 0f;
635 button.PaddingRight = 0f;
636 button.BackgroundColor = new Color(63, 82, 151) * 0.7f;
637 if (!external)
638 {
639 button.BorderColor = _internalBorderColor * 0.7f;
640 }
641 button.OnMouseOver += delegate(UIMouseEvent evt, UIElement listeningElement)
642 {
643 ((UITextPanel<T>)listeningElement).BackgroundColor = new Color(73, 94, 171) * 0.85f;
644 if (!external)
645 {
646 ((UITextPanel<T>)listeningElement).BorderColor = _internalBorderColorSelected * 0.85f;
647 }
648 };
649 button.OnMouseOut += delegate(UIMouseEvent evt, UIElement listeningElement)
650 {
651 ((UITextPanel<T>)listeningElement).BackgroundColor = new Color(63, 82, 151) * 0.7f;
652 if (!external)
653 {
654 ((UITextPanel<T>)listeningElement).BorderColor = _internalBorderColor * 0.7f;
655 }
656 };
657 }
658
659 private UITextPanel<object> CreateKeyboardButton(object text, int x, int y, int width = 1, bool style = true)
660 {
661 float num = 516f;
662 UITextPanel<object> uITextPanel = new UITextPanel<object>(text, 0.4f, large: true);
663 uITextPanel.Width.Pixels = 48f * (float)width + 4f * (float)(width - 1);
664 uITextPanel.Height.Pixels = 37f;
665 uITextPanel.Left.Precent = 0.5f;
666 uITextPanel.Left.Pixels = 52f * (float)x - num * 0.5f;
667 uITextPanel.Top.Pixels = 41f * (float)y;
668 if (style)
669 {
670 StyleKey(uITextPanel);
671 }
672 for (int i = 0; i < width; i++)
673 {
674 _keyList[y * 10 + x + i] = uITextPanel;
675 }
676 return uITextPanel;
677 }
678
679 private bool ShouldShowKeyboard()
680 {
682 }
683
684 protected override void DrawSelf(SpriteBatch spriteBatch)
685 {
686 if (Main.gameMenu)
687 {
688 if (ShouldShowKeyboard())
689 {
691 if (!Elements.Contains(outerLayer1))
692 {
694 }
697 Recalculate();
699 if (_labelHeight != 0f)
700 {
701 _textBox.Top.Pixels = _textBoxHeight;
702 _label.Top.Pixels = _labelHeight;
706 UserInterface.ActiveInstance.ResetLasts();
707 }
708 }
709 else
710 {
712 if (!Elements.Contains(outerLayer2))
713 {
715 }
718 Recalculate();
720 if (_textBoxHeight == 0f)
721 {
722 _textBoxHeight = _textBox.Top.Pixels;
724 _textBox.Top.Pixels += 50f;
725 _label.Top.Pixels += 50f;
728 UserInterface.ActiveInstance.ResetLasts();
729 }
730 }
731 }
733 {
735 return;
736 }
738 {
740 return;
741 }
742 base.DrawSelf(spriteBatch);
744 OffsetDown = 0;
745 ShouldHideText = false;
746 SetupGamepadPoints(spriteBatch);
747 PlayerInput.WritingText = true;
748 Main.instance.HandleIME();
749 Vector2 position = new Vector2(Main.screenWidth / 2, _textBox.GetDimensions().ToRectangle().Bottom + 32);
750 Main.instance.DrawWindowsIMEPanel(position, 0.5f);
751 string text = Main.GetInputText(Text, _edittingSign);
753 {
754 text += "\n";
755 }
756 else
757 {
759 {
762 return;
763 }
765 {
766 Submit();
767 }
768 else if (_edittingChest && Main.player[Main.myPlayer].chest < 0)
769 {
771 }
773 {
774 return;
775 }
776 }
778 {
779 if (text != Text)
780 {
782 {
783 Text = text;
784 }
785 else
786 {
788 }
789 }
790 if (_edittingSign)
791 {
793 }
794 if (_edittingChest)
795 {
797 }
798 }
799 byte b = (byte)((255 + Main.tileColor.R * 2) / 3);
800 Color value = new Color(b, b, b, 255);
801 _textBox.TextColor = Color.Lerp(Color.White, value, 0.2f);
802 _label.TextColor = Color.Lerp(Color.White, value, 0.2f);
803 position = new Vector2(Main.screenWidth / 2, _textBox.GetDimensions().ToRectangle().Bottom + 32);
804 Main.instance.DrawWindowsIMEPanel(position, 0.5f);
805 }
806
807 private bool TryEscapingMenu()
808 {
809 if (CustomEscapeAttempt != null)
810 {
811 return CustomEscapeAttempt();
812 }
813 if (_edittingSign)
814 {
816 }
817 if (_edittingChest)
818 {
820 }
821 if (Main.gameMenu && _cancelAction != null)
822 {
823 Cancel();
824 }
825 else
826 {
828 }
829 return true;
830 }
831
832 private void UpdateOffsetDown()
833 {
834 _textBox.HideSelf = ShouldHideText;
835 int num = OffsetDown - _lastOffsetDown;
836 int num2 = num;
837 if (Math.Abs(num) < 10)
838 {
839 num2 = num;
840 }
841 _lastOffsetDown += num2;
842 if (num2 != 0)
843 {
844 Top.Pixels += num2;
845 Recalculate();
846 }
847 }
848
849 public override void OnActivate()
850 {
852 {
854 }
855 }
856
857 public override void OnDeactivate()
858 {
859 base.OnDeactivate();
860 PlayerInput.WritingText = false;
861 UILinkPointNavigator.Shortcuts.FANCYUI_SPECIAL_INSTRUCTIONS = 0;
862 }
863
864 private void SetupGamepadPoints(SpriteBatch spriteBatch)
865 {
866 UILinkPointNavigator.Shortcuts.BackButtonCommand = 6;
867 UILinkPointNavigator.Shortcuts.FANCYUI_SPECIAL_INSTRUCTIONS = 1;
868 int num = 3002;
869 int num2 = num;
870 int num3 = 5;
871 int num4 = 10;
872 int num5 = num4 * num3 - 1;
873 int num6 = num4 * (num3 - 1);
874 UILinkPointNavigator.SetPosition(3000, _cancelButton.GetDimensions().Center());
875 UILinkPoint uILinkPoint = UILinkPointNavigator.Points[3000];
876 uILinkPoint.Unlink();
877 uILinkPoint.Right = 3001;
878 uILinkPoint.Up = num + num6;
879 UILinkPointNavigator.SetPosition(3001, _submitButton.GetDimensions().Center());
880 uILinkPoint = UILinkPointNavigator.Points[3001];
881 uILinkPoint.Unlink();
882 uILinkPoint.Left = 3000;
883 uILinkPoint.Up = num + num5;
884 for (int i = 0; i < num3; i++)
885 {
886 for (int j = 0; j < num4; j++)
887 {
888 int num7 = i * num4 + j;
889 num2 = num + num7;
890 if (_keyList[num7] != null)
891 {
893 uILinkPoint = UILinkPointNavigator.Points[num2];
894 uILinkPoint.Unlink();
895 int num8 = j - 1;
896 while (num8 >= 0 && _keyList[i * num4 + num8] == _keyList[num7])
897 {
898 num8--;
899 }
900 if (num8 != -1)
901 {
902 uILinkPoint.Left = i * num4 + num8 + num;
903 }
904 else
905 {
906 uILinkPoint.Left = i * num4 + (num4 - 1) + num;
907 }
908 int k;
909 for (k = j + 1; k <= num4 - 1 && _keyList[i * num4 + k] == _keyList[num7]; k++)
910 {
911 }
912 if (k != num4 && _keyList[num7] != _keyList[k])
913 {
914 uILinkPoint.Right = i * num4 + k + num;
915 }
916 else
917 {
918 uILinkPoint.Right = i * num4 + num;
919 }
920 if (i != 0)
921 {
922 uILinkPoint.Up = num2 - num4;
923 }
924 if (i != num3 - 1)
925 {
926 uILinkPoint.Down = num2 + num4;
927 }
928 else
929 {
930 uILinkPoint.Down = ((j < num3) ? 3000 : 3001);
931 }
932 }
933 }
934 }
935 }
936
937 public static void CycleSymbols()
938 {
939 if (_currentInstance != null)
940 {
941 switch (_currentInstance._keyState)
942 {
943 case KeyState.Default:
944 _currentInstance.SetKeyState(KeyState.Shift);
945 break;
946 case KeyState.Shift:
947 _currentInstance.SetKeyState(KeyState.Symbol);
948 break;
949 case KeyState.Symbol:
950 _currentInstance.SetKeyState(KeyState.Default);
951 break;
952 }
953 }
954 }
955
956 public static void BackSpace()
957 {
958 if (_currentInstance != null)
959 {
961 _currentInstance._textBox.Backspace();
962 _currentInstance.ValidateText();
963 }
964 }
965
966 public static void Submit()
967 {
968 if (_currentInstance != null)
969 {
970 _currentInstance.InternalSubmit();
971 }
972 }
973
974 private void InternalSubmit()
975 {
976 string text = Text.Trim();
978 {
981 }
982 }
983
984 public static void Cancel()
985 {
986 if (_currentInstance != null)
987 {
989 _currentInstance._cancelAction();
990 }
991 }
992
993 public static void Write(string text)
994 {
995 if (_currentInstance != null)
996 {
998 bool num = _currentInstance.Text.Length == 0;
999 _currentInstance._textBox.Write(text);
1000 _currentInstance.ValidateText();
1001 if (num && _currentInstance.Text.Length > 0 && _currentInstance._keyState == KeyState.Shift)
1002 {
1003 _currentInstance.SetKeyState(KeyState.Default);
1004 }
1005 }
1006 }
1007
1008 public static void CursorLeft()
1009 {
1010 if (_currentInstance != null)
1011 {
1013 _currentInstance._textBox.CursorLeft();
1014 }
1015 }
1016
1017 public static void CursorRight()
1018 {
1019 if (_currentInstance != null)
1020 {
1022 _currentInstance._textBox.CursorRight();
1023 }
1024 }
1025
1026 public static bool CanDisplay(int keyboardContext)
1027 {
1028 if (keyboardContext == 1)
1029 {
1030 return Main.screenHeight > 700;
1031 }
1032 return true;
1033 }
1034
1035 public static void CacheCanceledInput(int cacheMode)
1036 {
1037 if (cacheMode == 1)
1038 {
1040 }
1041 }
1042
1043 private void RestoreCanceledInput(int cacheMode)
1044 {
1045 if (cacheMode == 1)
1046 {
1047 Main.npcChatText = _cancelCacheSign;
1048 Text = Main.npcChatText;
1049 _cancelCacheSign = "";
1050 }
1051 }
1052
1053 private void CopyTextToSign()
1054 {
1055 if (_edittingSign)
1056 {
1057 int sign = Main.player[Main.myPlayer].sign;
1058 if (sign >= 0 && Main.sign[sign] != null)
1059 {
1060 Main.npcChatText = Text;
1061 }
1062 }
1063 }
1064
1065 private void CopyTextToChest()
1066 {
1067 if (_edittingChest)
1068 {
1069 Main.npcChatText = Text;
1070 }
1071 }
1072
1073 private void FadedMouseOver(UIMouseEvent evt, UIElement listeningElement)
1074 {
1076 ((UIPanel)evt.Target).BackgroundColor = new Color(73, 94, 171);
1077 ((UIPanel)evt.Target).BorderColor = Colors.FancyUIFatButtonMouseOver;
1078 }
1079
1080 private void FadedMouseOut(UIMouseEvent evt, UIElement listeningElement)
1081 {
1082 ((UIPanel)evt.Target).BackgroundColor = new Color(63, 82, 151) * 0.7f;
1083 ((UIPanel)evt.Target).BorderColor = Color.Black;
1084 }
1085}
static double Abs(double value)
static void PlaySound(int type, Vector2 position, int style=1)
override void SetText(string text, float textScale, bool large)
Definition UITextBox.cs:31
UIVirtualKeyboard(string labelText, string startingText, KeyboardSubmitEvent submitAction, Action cancelAction, int inputMode=0, bool allowEmpty=false)
void StyleKey< T >(UITextPanel< T > button, bool external=false)
void FadedMouseOver(UIMouseEvent evt, UIElement listeningElement)
void FadedMouseOut(UIMouseEvent evt, UIElement listeningElement)
override void DrawSelf(SpriteBatch spriteBatch)
delegate void KeyboardSubmitEvent(string text)
void TypeText(UIMouseEvent evt, UIElement listeningElement)
UITextPanel< object > CreateKeyboardButton(object text, int x, int y, int width=1, bool style=true)
static readonly Color FancyUIFatButtonMouseOver
Definition Colors.cs:91
static LocalizedText GetText(string key)
Definition Language.cs:10
static string GetInputText(string oldString, bool allowMultiLine=false)
Definition Main.cs:18593
static bool inputTextEscape
Definition Main.cs:1747
static string npcChatText
Definition Main.cs:1825
static void InputTextSignCancel()
Definition Main.cs:18428
static int myPlayer
Definition Main.cs:1801
static bool editSign
Definition Main.cs:1815
static Microsoft.Xna.Framework.Color tileColor
Definition Main.cs:1270
static Main instance
Definition Main.cs:283
static Microsoft.Xna.Framework.Color OurFavoriteColor
Definition Main.cs:902
static bool editChest
Definition Main.cs:1817
static int screenWidth
Definition Main.cs:1719
static IAssetRepository Assets
Definition Main.cs:209
static bool gameMenu
Definition Main.cs:1926
static bool inputTextEnter
Definition Main.cs:1745
static Sign[] sign
Definition Main.cs:1701
static Player[] player
Definition Main.cs:1803
static void RenameChestCancel()
Definition ChestUI.cs:933
static void RenameChestSubmit(Player player)
Definition ChestUI.cs:910
static Dictionary< int, UILinkPoint > Points
static void SetPosition(int ID, Vector2 Position)
static bool CanShowVirtualKeyboard(int context)
StyleDimension Height
Definition UIElement.cs:29
void Append(UIElement element)
Definition UIElement.cs:166
virtual void RecalculateChildren()
Definition UIElement.cs:369
StyleDimension Width
Definition UIElement.cs:27
virtual void Recalculate()
Definition UIElement.cs:281
CalculatedStyle GetDimensions()
Definition UIElement.cs:382
void SetPadding(float pixels)
Definition UIElement.cs:361
StyleDimension Top
Definition UIElement.cs:23
readonly UIElement Target
Definition UIEvent.cs:5
static UserInterface ActiveInstance
static Color Transparent
Definition Color.cs:76
static Color Lerp(Color value1, Color value2, float amount)
Definition Color.cs:491