optionselectoreditbox.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. class OptionSelectorEditbox extends OptionSelectorBase
  2. {
  3. protected EditBoxWidget m_EditBox;
  4. void OptionSelectorEditbox(Widget parent, string value, ScriptedWidgetEventHandler parent_menu, bool disabled)
  5. {
  6. m_Root = GetGame().GetWorkspace().CreateWidgets("gui/layouts/new_ui/option_editbox.layout", parent);
  7. #ifdef PLATFORM_CONSOLE
  8. m_Parent = parent.GetParent().GetParent();
  9. #else
  10. #ifdef PLATFORM_WINDOWS
  11. m_Parent = parent.GetParent();
  12. #endif
  13. #endif
  14. m_SelectorType = 1;
  15. m_ParentClass = parent_menu;
  16. m_EditBox = EditBoxWidget.Cast(m_Root.FindAnyWidget("option_value"));
  17. SetValue(value);
  18. Enable();
  19. m_Parent.SetHandler(this);
  20. }
  21. void ~OptionSelectorEditbox()
  22. {
  23. delete m_Root;
  24. }
  25. override void Enable()
  26. {
  27. super.Enable();
  28. m_EditBox.ClearFlags(WidgetFlags.IGNOREPOINTER);
  29. }
  30. override void Disable()
  31. {
  32. super.Disable();
  33. m_EditBox.SetFlags(WidgetFlags.IGNOREPOINTER);
  34. }
  35. override bool OnMouseEnter(Widget w, int x, int y)
  36. {
  37. if (!IsFocusable(w))
  38. return true;
  39. if (m_ParentClass)
  40. {
  41. m_ParentClass.OnFocus(m_Root.GetParent(), -1, m_SelectorType);
  42. m_ParentClass.OnMouseEnter(m_Root.GetParent().GetParent(), x, y);
  43. }
  44. UIScriptedMenu menu = GetGame().GetUIManager().GetMenu();
  45. if (menu && menu.IsInherited(CharacterCreationMenu))
  46. {
  47. menu.OnFocus(m_Root.GetParent(), -1, m_SelectorType);
  48. menu.OnMouseEnter(m_Root.GetParent().GetParent(), x, y);
  49. }
  50. ColorHighlight(w);
  51. return true;
  52. }
  53. override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
  54. {
  55. if (IsFocusable(enterW))
  56. return true;
  57. if (m_ParentClass)
  58. {
  59. m_ParentClass.OnFocus(null, x, y);
  60. m_ParentClass.OnMouseLeave(m_Root.GetParent().GetParent(), enterW, x, y);
  61. }
  62. UIScriptedMenu menu = GetGame().GetUIManager().GetMenu();
  63. if (menu && menu.IsInherited(CharacterCreationMenu))
  64. {
  65. menu.OnFocus(null, x, y);
  66. menu.OnMouseLeave(m_Root.GetParent().GetParent(), enterW, x, y);
  67. }
  68. ColorNormal(w);
  69. return true;
  70. }
  71. override bool OnChange(Widget w, int x, int y, bool finished)
  72. {
  73. if (w == m_EditBox)
  74. {
  75. m_OptionChanged.Invoke(GetValue());
  76. return true;
  77. }
  78. return false;
  79. }
  80. override bool IsFocusable(Widget w)
  81. {
  82. if (w)
  83. {
  84. return (w == m_Parent || w == m_EditBox);
  85. }
  86. return false;
  87. }
  88. override bool OnFocus(Widget w, int x, int y)
  89. {
  90. if (GetFocus() != m_EditBox)
  91. {
  92. SetFocus(m_EditBox);
  93. m_Parent.Enable(false);
  94. }
  95. return super.OnFocus(m_Parent, x, y);
  96. }
  97. override bool OnFocusLost(Widget w, int x, int y)
  98. {
  99. if (w == m_EditBox)
  100. {
  101. m_Parent.Enable(true);
  102. return super.OnFocusLost(m_Parent, x, y);
  103. }
  104. return false;
  105. }
  106. void SetValue(string value, bool update = true)
  107. {
  108. m_EditBox.SetText(value);
  109. if (update)
  110. m_OptionChanged.Invoke(GetValue());
  111. }
  112. string GetValue()
  113. {
  114. return m_EditBox.GetText();
  115. }
  116. override void ColorHighlight(Widget w)
  117. {
  118. if (!w)
  119. return;
  120. if (m_EditBox)
  121. {
  122. SetFocus(m_EditBox);
  123. m_EditBox.SetColor(ARGB(255, 200, 0, 0));
  124. }
  125. super.ColorHighlight(w);
  126. }
  127. override void ColorNormal(Widget w)
  128. {
  129. if (!w)
  130. return;
  131. if (m_EditBox)
  132. {
  133. m_EditBox.SetColor(ARGB(140, 255, 255, 255));
  134. }
  135. super.ColorNormal(w);
  136. }
  137. }