optionselectorbase.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. class OptionSelectorBase extends ScriptedWidgetEventHandler
  2. {
  3. protected int m_SelectorType = 0;
  4. protected Widget m_Parent;
  5. protected Widget m_Root;
  6. protected bool m_Enabled;
  7. protected ScriptedWidgetEventHandler m_ParentClass;
  8. ref ScriptInvoker m_OptionFocused = new ScriptInvoker;
  9. ref ScriptInvoker m_OptionUnfocused = new ScriptInvoker;
  10. ref ScriptInvoker m_AttemptOptionChange = new ScriptInvoker;
  11. ref ScriptInvoker m_OptionChanged = new ScriptInvoker;
  12. void ~OptionSelectorBase()
  13. {
  14. delete m_Root;
  15. }
  16. Widget GetParent()
  17. {
  18. return m_Parent;
  19. }
  20. bool IsFocusable(Widget w)
  21. {
  22. if (w)
  23. {
  24. return w == m_Parent;
  25. }
  26. return false;
  27. }
  28. override bool OnMouseEnter(Widget w, int x, int y)
  29. {
  30. if (!IsFocusable(w))
  31. return true;
  32. if (m_ParentClass)
  33. {
  34. m_ParentClass.OnFocus(m_Root.GetParent(), -1, m_SelectorType);
  35. #ifndef PLATFORM_CONSOLE
  36. m_ParentClass.OnMouseEnter(m_Root.GetParent().GetParent(), x, y);
  37. #endif
  38. }
  39. UIScriptedMenu menu = GetGame().GetUIManager().GetMenu();
  40. if (menu && menu.IsInherited(CharacterCreationMenu))
  41. {
  42. menu.OnFocus(m_Root.GetParent(), -1, m_SelectorType);
  43. menu.OnMouseEnter(m_Root.GetParent().GetParent(), x, y);
  44. }
  45. #ifndef PLATFORM_CONSOLE
  46. ColorHighlight(w);
  47. #else
  48. ColorHighlightConsole(w);
  49. if (m_ParentClass)
  50. {
  51. m_ParentClass.OnFocus(m_Root.GetParent(), -1, m_SelectorType);
  52. }
  53. #endif
  54. return true;
  55. }
  56. override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
  57. {
  58. #ifdef PLATFORM_CONSOLE
  59. if (IsFocusable(enterW))
  60. return true;
  61. #endif
  62. if (m_ParentClass)
  63. {
  64. m_ParentClass.OnFocus(null, x, y);
  65. #ifndef PLATFORM_CONSOLE
  66. m_ParentClass.OnMouseLeave(m_Root.GetParent().GetParent(), enterW, x, y);
  67. #endif
  68. }
  69. UIScriptedMenu menu = GetGame().GetUIManager().GetMenu();
  70. if (menu && menu.IsInherited(CharacterCreationMenu))
  71. {
  72. menu.OnFocus(null, x, y);
  73. menu.OnMouseLeave(m_Root.GetParent().GetParent(), enterW, x, y);
  74. }
  75. #ifndef PLATFORM_CONSOLE
  76. ColorNormal(w);
  77. #else
  78. ColorNormalConsole(w);
  79. if (m_ParentClass)
  80. {
  81. m_ParentClass.OnFocusLost(w, x, y);
  82. }
  83. #endif
  84. return true;
  85. }
  86. override bool OnFocus(Widget w, int x, int y)
  87. {
  88. if (IsFocusable(w))
  89. {
  90. ColorHighlightConsole(w);
  91. if (m_ParentClass)
  92. {
  93. m_ParentClass.OnFocus(m_Root.GetParent(), -1, m_SelectorType);
  94. }
  95. return true;
  96. }
  97. return false;
  98. }
  99. override bool OnFocusLost(Widget w, int x, int y)
  100. {
  101. ColorNormalConsole(w);
  102. if (m_ParentClass)
  103. {
  104. m_ParentClass.OnFocusLost(w, x, y);
  105. }
  106. return true;
  107. }
  108. void Focus()
  109. {
  110. #ifndef PLATFORM_CONSOLE
  111. SetFocus(m_Root);
  112. #else
  113. SetFocus(m_Parent);
  114. #endif
  115. }
  116. void Enable()
  117. {
  118. m_Enabled = true;
  119. m_Parent.ClearFlags(WidgetFlags.IGNOREPOINTER);
  120. #ifdef PLATFORM_CONSOLE
  121. ColorNormalConsole(m_Parent);
  122. #else
  123. ColorNormal(m_Parent);
  124. #endif
  125. }
  126. void Disable()
  127. {
  128. m_Enabled = false;
  129. m_Parent.SetFlags(WidgetFlags.IGNOREPOINTER);
  130. #ifdef PLATFORM_CONSOLE
  131. ColorDisabledConsole(m_Parent);
  132. #else
  133. ColorDisabled(m_Parent);
  134. #endif
  135. }
  136. void ColorHighlight(Widget w)
  137. {
  138. if (!w)
  139. return;
  140. ButtonSetColor(w, ARGB(255, 255, 0, 0));
  141. }
  142. void ColorNormal(Widget w)
  143. {
  144. if (!w)
  145. return;
  146. int color_pnl = ARGB(255, 255, 255, 255);
  147. int color_lbl = ARGB(255, 255, 255, 255);
  148. ButtonSetColor(w, color_pnl);
  149. Widget title_label = w.FindAnyWidget(w.GetName() + "_label");
  150. Widget option_label = w.FindAnyWidget("option_label");
  151. if (title_label)
  152. {
  153. title_label.SetColor(color_lbl);
  154. }
  155. if (option_label)
  156. {
  157. option_label.SetColor(color_lbl);
  158. }
  159. }
  160. void ColorDisabled(Widget w)
  161. {
  162. if (!w)
  163. return;
  164. int color_pnl = ARGB(0, 0, 0, 0);
  165. int color_lbl = ARGB(120, 255, 255, 255);
  166. ButtonSetColor(w, color_pnl);
  167. Widget title_label = w.FindAnyWidget(w.GetName() + "_label");
  168. Widget option_label = w.FindAnyWidget("option_label");
  169. if (title_label)
  170. {
  171. title_label.SetColor(color_lbl);
  172. }
  173. if (option_label)
  174. {
  175. option_label.SetColor(color_lbl);
  176. }
  177. }
  178. void ButtonSetColor(Widget w, int color)
  179. {
  180. Widget option = w.FindAnyWidget(w.GetName() + "_image");
  181. if (option)
  182. {
  183. option.SetColor(color);
  184. }
  185. }
  186. void ColorHighlightConsole(Widget w)
  187. {
  188. if (!w)
  189. return;
  190. int color_pnl = ARGB(255, 200, 0, 0);
  191. int color_lbl = ARGB(255, 255, 255, 255);
  192. ButtonSetColorConsole(w, color_pnl);
  193. ButtonSetAlphaAnimConsole(null);
  194. ButtonSetTextColorConsole(w, color_lbl);
  195. }
  196. void ColorNormalConsole(Widget w)
  197. {
  198. if (!w)
  199. return;
  200. int color_pnl = ARGB(0, 0, 0, 0);
  201. int color_lbl = ARGB(255, 255, 255, 255);
  202. ButtonSetColorConsole(w, color_pnl);
  203. ButtonSetAlphaAnimConsole(null);
  204. ButtonSetTextColorConsole(w, color_lbl);
  205. }
  206. void ColorDisabledConsole(Widget w)
  207. {
  208. if (!w)
  209. return;
  210. int color_pnl = ARGB(0, 0, 0, 0);
  211. int color_lbl = ARGB(120, 255, 255, 255);
  212. ButtonSetColorConsole(w, color_pnl);
  213. ButtonSetAlphaAnimConsole(null);
  214. ButtonSetTextColorConsole(w, color_lbl);
  215. }
  216. void ButtonSetColorConsole(Widget w, int color)
  217. {
  218. w.SetColor(color);
  219. }
  220. void ButtonSetAlphaAnimConsole(Widget w)
  221. {
  222. if (!w)
  223. return;
  224. Widget panel = w.FindAnyWidget(w.GetName() + "_panel");
  225. if (panel)
  226. {
  227. //m_Root.SetWidgetAnimAlpha(panel);
  228. }
  229. }
  230. void ButtonSetTextColorConsole(Widget w, int color)
  231. {
  232. if (!w)
  233. return;
  234. TextWidget label = TextWidget.Cast(w.FindAnyWidget(w.GetName() + "_label"));
  235. TextWidget text = TextWidget.Cast(w.FindAnyWidget(w.GetName() + "_text"));
  236. TextWidget text2 = TextWidget.Cast(w.FindAnyWidget(w.GetName() + "_text_1"));
  237. if (label)
  238. {
  239. label.SetColor(color);
  240. }
  241. if (text)
  242. {
  243. text.SetColor(color);
  244. }
  245. if (text2)
  246. {
  247. text2.SetColor(color);
  248. }
  249. }
  250. }