optionsmenu.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867
  1. class OptionsMenu extends UIScriptedMenu
  2. {
  3. const int MODAL_ID_DEFAULT = 100;
  4. const int DIALOG_TAB_OFFSET = 1400;
  5. protected TabberUI m_Tabber;
  6. protected ref OptionsMenuGame m_GameTab;
  7. protected ref OptionsMenuSounds m_SoundsTab;
  8. protected ref OptionsMenuVideo m_VideoTab;
  9. protected ref OptionsMenuControls m_ControlsTab;
  10. protected ref GameOptions m_Options;
  11. protected ButtonWidget m_Apply;
  12. protected ButtonWidget m_Back;
  13. protected ButtonWidget m_Reset; //undo
  14. protected ButtonWidget m_Defaults; //defaults
  15. protected Widget m_Details;
  16. protected TextWidget m_Version;
  17. protected int m_ActiveTabIdx = 0;
  18. protected bool m_ModalLock;
  19. protected bool m_CanApplyOrReset;
  20. protected bool m_CanToggle;
  21. void OptionsMenu()
  22. {
  23. }
  24. override Widget Init()
  25. {
  26. m_Options = new GameOptions();
  27. #ifdef PLATFORM_XBOX
  28. layoutRoot = GetGame().GetWorkspace().CreateWidgets("gui/layouts/new_ui/options/xbox/options_menu.layout", null);
  29. #else
  30. #ifdef PLATFORM_PS4
  31. layoutRoot = GetGame().GetWorkspace().CreateWidgets("gui/layouts/new_ui/options/ps/options_menu.layout", null);
  32. #else
  33. #ifdef PLATFORM_WINDOWS
  34. layoutRoot = GetGame().GetWorkspace().CreateWidgets("gui/layouts/new_ui/options/pc/options_menu.layout", null);
  35. #endif
  36. #endif
  37. #endif
  38. layoutRoot.FindAnyWidget("Tabber").GetScript(m_Tabber);
  39. m_Details = layoutRoot.FindAnyWidget("settings_details");
  40. m_Version = TextWidget.Cast(layoutRoot.FindAnyWidget("version"));
  41. m_GameTab = new OptionsMenuGame(layoutRoot.FindAnyWidget("Tab_0"), m_Details, m_Options, this);
  42. m_SoundsTab = new OptionsMenuSounds(layoutRoot.FindAnyWidget("Tab_1"), m_Details, m_Options, this);
  43. #ifdef PLATFORM_XBOX
  44. m_ControlsTab = new OptionsMenuControls(layoutRoot.FindAnyWidget("Tab_2"), m_Details, m_Options, this);
  45. #else
  46. m_VideoTab = new OptionsMenuVideo(layoutRoot.FindAnyWidget("Tab_2"), m_Details, m_Options, this);
  47. m_ControlsTab = new OptionsMenuControls(layoutRoot.FindAnyWidget("Tab_3"), m_Details, m_Options, this);
  48. #endif
  49. m_Apply = ButtonWidget.Cast(layoutRoot.FindAnyWidget("apply"));
  50. m_Back = ButtonWidget.Cast(layoutRoot.FindAnyWidget("back"));
  51. m_Reset = ButtonWidget.Cast(layoutRoot.FindAnyWidget("reset"));
  52. m_Defaults = ButtonWidget.Cast(layoutRoot.FindAnyWidget("defaults"));
  53. m_ModalLock = false;
  54. m_CanApplyOrReset = false;
  55. m_CanToggle = false;
  56. string version;
  57. GetGame().GetVersion(version);
  58. #ifdef PLATFORM_CONSOLE
  59. version = "#main_menu_version" + " " + version + " (" + g_Game.GetDatabaseID() + ")";
  60. #else
  61. version = "#main_menu_version" + " " + version;
  62. #endif
  63. m_Version.SetText(version);
  64. #ifdef PLATFORM_WINDOWS
  65. SetFocus(layoutRoot);
  66. #else
  67. ToggleFocus();
  68. #endif
  69. m_Tabber.m_OnTabSwitch.Insert(OnTabSwitch);
  70. m_Tabber.m_OnAttemptTabSwitch.Insert(OnAttemptTabSwitch);
  71. GetGame().GetMission().GetOnInputPresetChanged().Insert(OnInputPresetChanged);
  72. GetGame().GetMission().GetOnInputDeviceChanged().Insert(OnInputDeviceChanged);
  73. OnChanged();
  74. return layoutRoot;
  75. }
  76. void ~OptionsMenu()
  77. {
  78. }
  79. protected void OnInputPresetChanged()
  80. {
  81. #ifdef PLATFORM_CONSOLE
  82. UpdateControlsElementVisibility();
  83. #endif
  84. }
  85. protected void OnInputDeviceChanged(EInputDeviceType pInputDeviceType)
  86. {
  87. #ifdef PLATFORM_CONSOLE
  88. bool mk = GetGame().GetInput().IsEnabledMouseAndKeyboard();
  89. bool mkServer = GetGame().GetInput().IsEnabledMouseAndKeyboardEvenOnServer();
  90. switch (pInputDeviceType)
  91. {
  92. case EInputDeviceType.CONTROLLER:
  93. if (mk && mkServer)
  94. {
  95. GetGame().GetUIManager().ShowUICursor(false);
  96. }
  97. break;
  98. default:
  99. if (mk && mkServer)
  100. {
  101. GetGame().GetUIManager().ShowUICursor(true);
  102. }
  103. break;
  104. }
  105. UpdateControlsElementVisibility();
  106. #endif
  107. }
  108. override bool OnClick(Widget w, int x, int y, int button)
  109. {
  110. if (button == MouseState.LEFT)
  111. {
  112. switch (w)
  113. {
  114. case m_Apply:
  115. {
  116. Apply();
  117. return true;
  118. }
  119. case m_Back:
  120. {
  121. Back();
  122. return true;
  123. }
  124. case m_Reset:
  125. {
  126. ResetCurrentTab();
  127. return true;
  128. }
  129. case m_Defaults:
  130. {
  131. //SetToDefaults();
  132. PerformSetToDefaults();
  133. return true;
  134. }
  135. }
  136. }
  137. return false;
  138. }
  139. void OnTabSwitch(int tab)
  140. {
  141. switch (tab)
  142. {
  143. case 0:
  144. {
  145. m_GameTab.Focus();
  146. break;
  147. }
  148. case 1:
  149. {
  150. m_SoundsTab.Focus();
  151. break;
  152. }
  153. case 2:
  154. {
  155. #ifdef PLATFORM_XBOX
  156. m_ControlsTab.Focus();
  157. #else
  158. m_VideoTab.Focus();
  159. #endif
  160. break;
  161. }
  162. case 3:
  163. {
  164. #ifndef PLATFORM_XBOX
  165. m_ControlsTab.Focus();
  166. #endif
  167. break;
  168. }
  169. }
  170. m_ActiveTabIdx = tab;
  171. }
  172. void Apply()
  173. {
  174. if (m_ControlsTab.IsChanged())
  175. m_ControlsTab.Apply();
  176. if (m_SoundsTab.IsChanged())
  177. m_SoundsTab.Apply();
  178. if (m_GameTab.IsChanged())
  179. m_GameTab.Apply();
  180. if (m_Options.IsChanged() || m_GameTab.IsChanged())
  181. {
  182. m_Options.Test();
  183. m_Options.Apply();
  184. }
  185. // save input configuration
  186. GetUApi().Export();
  187. if (GetGame().GetInput().IsEnabledMouseAndKeyboard()) //useless on consoles
  188. {
  189. m_Apply.SetFlags(WidgetFlags.IGNOREPOINTER);
  190. ColorDisable(m_Apply);
  191. m_Reset.SetFlags(WidgetFlags.IGNOREPOINTER);
  192. ColorDisable(m_Reset);
  193. }
  194. m_CanApplyOrReset = false;
  195. #ifdef PLATFORM_CONSOLE
  196. UpdateControlsElements();
  197. UpdateControlsElementVisibility();
  198. IngameHud hud;
  199. if (GetGame().GetMission() && Class.CastTo(hud,GetGame().GetMission().GetHud()))
  200. {
  201. hud.ShowQuickBar(GetGame().GetInput().IsEnabledMouseAndKeyboardEvenOnServer());
  202. }
  203. #endif
  204. if (m_Options.NeedRestart())
  205. g_Game.GetUIManager().ShowDialog("#main_menu_configure", "#menu_restart_needed", 117, DBT_YESNO, DBB_YES, DMT_QUESTION, this);
  206. }
  207. void Back()
  208. {
  209. if (!g_Game.GetUIManager().IsDialogVisible() && !g_Game.GetUIManager().IsModalVisible())
  210. {
  211. if (IsAnyTabChanged())
  212. {
  213. g_Game.GetUIManager().ShowDialog("#main_menu_configure", "#main_menu_configure_desc", 1337, DBT_YESNO, DBB_YES, DMT_QUESTION, this);
  214. #ifdef PLATFORM_CONSOLE
  215. UpdateControlsElements();
  216. #endif
  217. }
  218. else
  219. {
  220. m_Options.Revert();
  221. GetGame().EndOptionsVideo();
  222. GetGame().GetUIManager().Back();
  223. }
  224. }
  225. }
  226. void OnAttemptTabSwitch(int source, int target)
  227. {
  228. bool changed = IsAnyTabChanged();
  229. if (changed)
  230. {
  231. if (!g_Game.GetUIManager().IsDialogVisible() && !g_Game.GetUIManager().IsModalVisible())
  232. {
  233. int id = target + DIALOG_TAB_OFFSET;
  234. g_Game.GetUIManager().ShowDialog("#main_menu_configure", "#main_menu_configure_desc", id, DBT_YESNO, DBB_YES, DMT_QUESTION, this);
  235. #ifdef PLATFORM_CONSOLE
  236. UpdateControlsElements();
  237. #endif
  238. }
  239. }
  240. else
  241. {
  242. ResetCurrentTab();
  243. }
  244. m_Tabber.SetCanSwitch(!changed);
  245. }
  246. bool IsAnyTabChanged()
  247. {
  248. bool changed = (m_Options.IsChanged() || m_GameTab.IsChanged() || m_SoundsTab.IsChanged() || m_ControlsTab.IsChanged());
  249. #ifndef PLATFORM_XBOX
  250. changed |= m_VideoTab.IsChanged();
  251. #endif
  252. return changed;
  253. }
  254. void OnChanged()
  255. {
  256. bool changed = IsAnyTabChanged();
  257. if (GetGame().GetInput().IsEnabledMouseAndKeyboard())
  258. {
  259. if (changed)
  260. {
  261. m_Reset.ClearFlags(WidgetFlags.IGNOREPOINTER);
  262. ColorNormal(m_Reset);
  263. m_Apply.ClearFlags(WidgetFlags.IGNOREPOINTER);
  264. ColorNormal(m_Apply);
  265. }
  266. else
  267. {
  268. m_Apply.SetFlags(WidgetFlags.IGNOREPOINTER);
  269. ColorDisable(m_Apply);
  270. m_Reset.SetFlags(WidgetFlags.IGNOREPOINTER);
  271. ColorDisable(m_Reset);
  272. }
  273. }
  274. m_CanApplyOrReset = changed;
  275. #ifdef PLATFORM_CONSOLE
  276. UpdateControlsElements();
  277. UpdateControlsElementVisibility();
  278. #endif
  279. m_Tabber.AlignTabbers();
  280. }
  281. //resets it all
  282. void Reset()
  283. {
  284. m_Options.Revert();
  285. m_GameTab.Revert();
  286. m_SoundsTab.Revert();
  287. m_ControlsTab.Revert();
  288. #ifndef PLATFORM_XBOX
  289. m_VideoTab.Revert();
  290. #endif
  291. if (m_Options.IsChanged())
  292. m_Options.Revert();
  293. if (GetGame().GetInput().IsEnabledMouseAndKeyboard())
  294. {
  295. m_Apply.SetFlags(WidgetFlags.IGNOREPOINTER);
  296. ColorDisable(m_Apply);
  297. m_Reset.SetFlags(WidgetFlags.IGNOREPOINTER);
  298. ColorDisable(m_Reset);
  299. }
  300. m_CanApplyOrReset = false;
  301. #ifdef PLATFORM_CONSOLE
  302. UpdateControlsElements();
  303. UpdateControlsElementVisibility();
  304. #endif
  305. }
  306. void ResetCurrentTab()
  307. {
  308. if (m_Options.IsChanged())
  309. {
  310. m_Options.Revert();
  311. }
  312. switch (m_ActiveTabIdx)
  313. {
  314. case 0:
  315. {
  316. m_GameTab.Revert();
  317. break;
  318. }
  319. case 1:
  320. {
  321. m_SoundsTab.Revert();
  322. break;
  323. }
  324. case 2:
  325. {
  326. #ifdef PLATFORM_XBOX
  327. m_ControlsTab.Revert();
  328. #else
  329. m_VideoTab.Revert();
  330. #endif
  331. break;
  332. }
  333. case 3:
  334. {
  335. #ifndef PLATFORM_XBOX
  336. m_ControlsTab.Revert();
  337. #endif
  338. break;
  339. }
  340. }
  341. if (m_Options.IsChanged())
  342. {
  343. m_Options.Revert();
  344. }
  345. if (GetGame().GetInput().IsEnabledMouseAndKeyboard())
  346. {
  347. m_Apply.SetFlags(WidgetFlags.IGNOREPOINTER);
  348. ColorDisable(m_Apply);
  349. m_Reset.SetFlags(WidgetFlags.IGNOREPOINTER);
  350. ColorDisable(m_Reset);
  351. }
  352. m_CanApplyOrReset = false;
  353. #ifdef PLATFORM_CONSOLE
  354. UpdateControlsElements();
  355. UpdateControlsElementVisibility();
  356. #endif
  357. m_Tabber.AlignTabbers();
  358. }
  359. void SetToDefaults()
  360. {
  361. if (!g_Game.GetUIManager().IsDialogVisible() && !g_Game.GetUIManager().IsModalVisible())
  362. {
  363. g_Game.GetUIManager().ShowDialog("#menu_default_cap", "TODO - reset options to default", MODAL_ID_DEFAULT, DBT_YESNO, DBB_YES, DMT_QUESTION, this);
  364. }
  365. }
  366. void PerformSetToDefaults()
  367. {
  368. switch (m_ActiveTabIdx)
  369. {
  370. case 0:
  371. m_GameTab.SetToDefaults();
  372. break;
  373. case 1:
  374. m_SoundsTab.SetToDefaults();
  375. break;
  376. case 2:
  377. #ifdef PLATFORM_XBOX
  378. m_ControlsTab.SetToDefaults();
  379. #else
  380. m_VideoTab.SetToDefaults();
  381. #endif
  382. break;
  383. case 3:
  384. #ifndef PLATFORM_XBOX
  385. m_ControlsTab.SetToDefaults();
  386. #endif
  387. break;
  388. }
  389. if (GetGame().GetInput().IsEnabledMouseAndKeyboard())
  390. {
  391. m_Reset.ClearFlags(WidgetFlags.IGNOREPOINTER);
  392. ColorNormal(m_Reset);
  393. m_Apply.ClearFlags(WidgetFlags.IGNOREPOINTER);
  394. ColorNormal(m_Apply);
  395. }
  396. m_CanApplyOrReset = true;
  397. #ifdef PLATFORM_CONSOLE
  398. UpdateControlsElements();
  399. UpdateControlsElementVisibility();
  400. #endif
  401. }
  402. void SliderFocus()
  403. {
  404. #ifdef PLATFORM_CONSOLE
  405. m_CanToggle = false;
  406. UpdateControlsElements();
  407. #endif
  408. }
  409. void ToggleFocus()
  410. {
  411. #ifdef PLATFORM_CONSOLE
  412. m_CanToggle = true;
  413. UpdateControlsElements();
  414. #endif
  415. }
  416. //! Controls visibility and sometimes even state of specific, dependent options across sub-menus
  417. void ToggleDependentOptions(int mode, bool state)
  418. {
  419. m_GameTab.ToggleDependentOptions(mode,state);
  420. m_SoundsTab.ToggleDependentOptions(mode,state);
  421. m_ControlsTab.ToggleDependentOptions(mode,state);
  422. #ifndef PLATFORM_XBOX
  423. m_VideoTab.ToggleDependentOptions(mode,state);
  424. #endif
  425. }
  426. void ReloadOptions()
  427. {
  428. m_Options = new GameOptions();
  429. if (m_GameTab)
  430. m_GameTab.SetOptions(m_Options);
  431. if (m_SoundsTab)
  432. m_SoundsTab.SetOptions(m_Options);
  433. if (m_ControlsTab)
  434. m_ControlsTab.SetOptions(m_Options);
  435. #ifndef PLATFORM_XBOX
  436. if (m_VideoTab)
  437. m_VideoTab.SetOptions(m_Options);
  438. #endif
  439. }
  440. void ReloadVideoOptions()
  441. {
  442. #ifndef PLATFORM_XBOX
  443. if (m_VideoTab)
  444. m_VideoTab.SetOptions(m_Options);
  445. #endif
  446. }
  447. override bool OnModalResult(Widget w, int x, int y, int code, int result)
  448. {
  449. bool ret = false;
  450. if (code == 1337)
  451. {
  452. if (result == 2)
  453. {
  454. m_Options.Revert();
  455. GetGame().EndOptionsVideo();
  456. GetGame().GetUIManager().Back();
  457. }
  458. ret = true;
  459. }
  460. else if (code == 117)
  461. {
  462. g_Game.RequestRestart(IDC_MAIN_QUIT);
  463. }
  464. else if (code == MODAL_ID_DEFAULT)
  465. {
  466. if (result == 2)
  467. {
  468. PerformSetToDefaults();
  469. }
  470. }
  471. else if (code >= DIALOG_TAB_OFFSET)
  472. {
  473. if (result == 2)
  474. {
  475. int id = code - DIALOG_TAB_OFFSET;
  476. //m_Options.Revert();
  477. ResetCurrentTab();
  478. m_Tabber.PerformSwitchTab(id);
  479. }
  480. ret = true;
  481. }
  482. m_ModalLock = ret; //prevents dialog being shown on the next update
  483. return ret;
  484. }
  485. override bool OnMouseEnter(Widget w, int x, int y)
  486. {
  487. if (w && IsFocusable(w))
  488. {
  489. ColorHighlight(w);
  490. return true;
  491. }
  492. return false;
  493. }
  494. override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
  495. {
  496. if (w && IsFocusable(w))
  497. {
  498. ColorNormal(w);
  499. return true;
  500. }
  501. return false;
  502. }
  503. override bool OnFocus(Widget w, int x, int y)
  504. {
  505. if (w && IsFocusable(w))
  506. {
  507. ColorHighlight(w);
  508. return true;
  509. }
  510. else if (y == 1)
  511. {
  512. SliderFocus();
  513. }
  514. else
  515. {
  516. ToggleFocus();
  517. }
  518. return false;
  519. }
  520. override bool OnFocusLost(Widget w, int x, int y)
  521. {
  522. if (w && IsFocusable(w))
  523. {
  524. ColorNormal(w);
  525. return true;
  526. }
  527. return false;
  528. }
  529. bool IsFocusable(Widget w)
  530. {
  531. if (w)
  532. {
  533. return (w == m_Apply || w == m_Back || w == m_Reset || w == m_Defaults);
  534. }
  535. return false;
  536. }
  537. override void Refresh()
  538. {
  539. string version;
  540. GetGame().GetVersion(version);
  541. #ifdef PLATFORM_CONSOLE
  542. version = "#main_menu_version" + " " + version + " (" + g_Game.GetDatabaseID() + ")";
  543. #else
  544. version = "#main_menu_version" + " " + version;
  545. #endif
  546. m_Version.SetText(version);
  547. #ifdef PLATFORM_CONSOLE
  548. OnInputDeviceChanged(GetGame().GetInput().GetCurrentInputDevice());
  549. UpdateControlsElementVisibility();
  550. #endif
  551. }
  552. override void OnShow()
  553. {
  554. super.OnShow();
  555. m_GameTab.Focus();
  556. Refresh();
  557. }
  558. override void Update(float timeslice)
  559. {
  560. super.Update(timeslice);
  561. if (m_ModalLock)
  562. {
  563. m_ModalLock = false;
  564. #ifdef PLATFORM_CONSOLE
  565. UpdateControlsElements();
  566. #endif
  567. return;
  568. }
  569. if (g_Game.GetUIManager().IsDialogVisible())
  570. {
  571. return;
  572. }
  573. if (GetUApi().GetInputByID(UAUITabLeft).LocalPress())
  574. {
  575. m_Tabber.PreviousTab();
  576. }
  577. else if (GetUApi().GetInputByID(UAUITabRight).LocalPress())
  578. {
  579. m_Tabber.NextTab();
  580. }
  581. else if (GetUApi().GetInputByID(UAUICtrlX).LocalPress())
  582. {
  583. if (m_CanApplyOrReset)
  584. {
  585. Apply();
  586. }
  587. }
  588. else if (GetUApi().GetInputByID(UAUICredits).LocalPress())
  589. {
  590. if (m_CanApplyOrReset)
  591. {
  592. ResetCurrentTab();
  593. }
  594. }
  595. else if (GetUApi().GetInputByID(UAUICtrlY).LocalPress())
  596. {
  597. PerformSetToDefaults();
  598. }
  599. else if (GetUApi().GetInputByID(UAUIBack).LocalPress())
  600. {
  601. Back();
  602. }
  603. }
  604. //Coloring functions (Until WidgetStyles are useful)
  605. void ColorHighlight(Widget w)
  606. {
  607. if ((w.GetFlags() & WidgetFlags.IGNOREPOINTER) == WidgetFlags.IGNOREPOINTER)
  608. {
  609. return;
  610. }
  611. if (w.IsInherited(ButtonWidget))
  612. {
  613. ButtonWidget button = ButtonWidget.Cast(w);
  614. button.SetTextColor(ARGB(255, 200, 0, 0));
  615. }
  616. w.SetColor(ARGB(255, 0, 0, 0));
  617. TextWidget text1 = TextWidget.Cast(w.FindAnyWidget(w.GetName() + "_text"));
  618. TextWidget text2 = TextWidget.Cast(w.FindAnyWidget(w.GetName() + "_label"));
  619. TextWidget text3 = TextWidget.Cast(w.FindAnyWidget(w.GetName() + "_text_1"));
  620. ImageWidget image = ImageWidget.Cast(w.FindAnyWidget(w.GetName() + "_image"));
  621. Widget option = Widget.Cast(w.FindAnyWidget(w.GetName() + "_option_wrapper"));
  622. Widget option_label = w.FindAnyWidget("option_label");
  623. if (text1)
  624. {
  625. text1.SetColor(ARGB(255, 255, 0, 0));
  626. }
  627. if (text2)
  628. {
  629. text2.SetColor(ARGB(255, 255, 0, 0));
  630. }
  631. if (text3)
  632. {
  633. text3.SetColor(ARGB(255, 255, 0, 0));
  634. w.SetAlpha(1);
  635. }
  636. if (image)
  637. {
  638. image.SetColor(ARGB(255, 200, 0, 0));
  639. }
  640. if (option)
  641. {
  642. option.SetColor(ARGB(255, 255, 0, 0));
  643. }
  644. if (option_label)
  645. {
  646. option_label.SetColor(ARGB(255, 255, 0, 0));
  647. }
  648. }
  649. void ColorNormal(Widget w)
  650. {
  651. if ((w.GetFlags() & WidgetFlags.IGNOREPOINTER) == WidgetFlags.IGNOREPOINTER)
  652. {
  653. return;
  654. }
  655. if (w.IsInherited(ButtonWidget))
  656. {
  657. ButtonWidget button = ButtonWidget.Cast(w);
  658. button.SetTextColor(ARGB(255, 255, 255, 255));
  659. }
  660. TextWidget text1 = TextWidget.Cast(w.FindAnyWidget(w.GetName() + "_text"));
  661. TextWidget text2 = TextWidget.Cast(w.FindAnyWidget(w.GetName() + "_text_1"));
  662. TextWidget text3 = TextWidget.Cast(w.FindAnyWidget(w.GetName() + "_label"));
  663. ImageWidget image = ImageWidget.Cast(w.FindAnyWidget(w.GetName() + "_image"));
  664. Widget option = w.FindAnyWidget(w.GetName() + "_option_wrapper");
  665. Widget option_label = w.FindAnyWidget("option_label");
  666. if (text1)
  667. {
  668. text1.SetColor(ARGB(255, 255, 255, 255));
  669. }
  670. if (text2)
  671. {
  672. text2.SetColor(ARGB(255, 255, 255, 255));
  673. }
  674. if (text3)
  675. {
  676. text3.SetColor(ARGB(255, 255, 255, 255));
  677. w.SetAlpha(0);
  678. }
  679. if (image)
  680. {
  681. image.SetColor(ARGB(255, 255, 255, 255));
  682. }
  683. if (option)
  684. {
  685. option.SetColor(ARGB(150, 255, 255, 255));
  686. }
  687. if (option_label)
  688. {
  689. option_label.SetColor(ARGB(255, 255, 255, 255));
  690. }
  691. }
  692. void ColorDisable(Widget w)
  693. {
  694. #ifdef PLATFORM_WINDOWS
  695. SetFocus(null);
  696. #endif
  697. if (w)
  698. {
  699. ButtonWidget button = ButtonWidget.Cast(w);
  700. if (button)
  701. {
  702. button.SetTextColor(ColorManager.COLOR_DISABLED_TEXT);
  703. }
  704. }
  705. }
  706. protected void UpdateControlsElements()
  707. {
  708. #ifdef PLATFORM_CONSOLE
  709. RichTextWidget toolbar_text = RichTextWidget.Cast(layoutRoot.FindAnyWidget("ContextToolbarText"));
  710. string text = "";
  711. if (g_Game.GetUIManager().IsDialogVisible() || g_Game.GetUIManager().IsDialogQueued())
  712. {
  713. text += string.Format(" %1",InputUtils.GetRichtextButtonIconFromInputAction("UAUISelect", "#dialog_confirm", EUAINPUT_DEVICE_CONTROLLER, InputUtils.ICON_SCALE_TOOLBAR));
  714. }
  715. else
  716. {
  717. if (m_CanToggle)
  718. {
  719. text += string.Format(" %1",InputUtils.GetRichtextButtonIconFromInputAction("UAUISelect", "#dialog_change", EUAINPUT_DEVICE_CONTROLLER, InputUtils.ICON_SCALE_TOOLBAR));
  720. }
  721. if (m_CanApplyOrReset)
  722. {
  723. text += string.Format(" %1",InputUtils.GetRichtextButtonIconFromInputAction("UAUICtrlX", "#STR_settings_menu_root_toolbar_bg_ConsoleToolbar_Apply_ApplyText0", EUAINPUT_DEVICE_CONTROLLER, InputUtils.ICON_SCALE_TOOLBAR));
  724. }
  725. text += string.Format(" %1",InputUtils.GetRichtextButtonIconFromInputAction("UAUICtrlY", "#menu_default", EUAINPUT_DEVICE_CONTROLLER, InputUtils.ICON_SCALE_TOOLBAR));
  726. if (m_CanApplyOrReset)
  727. {
  728. text += string.Format(" %1",InputUtils.GetRichtextButtonIconFromInputAction("UAUICredits", "#menu_undo", EUAINPUT_DEVICE_CONTROLLER, InputUtils.ICON_SCALE_TOOLBAR));
  729. }
  730. }
  731. text += string.Format(" %1",InputUtils.GetRichtextButtonIconFromInputAction("UAUIBack", "#STR_settings_menu_root_toolbar_bg_ConsoleToolbar_Back_BackText0", EUAINPUT_DEVICE_CONTROLLER, InputUtils.ICON_SCALE_TOOLBAR));
  732. toolbar_text.SetText(text);
  733. RichTextWidget toolbar_b2 = RichTextWidget.Cast(layoutRoot.FindAnyWidget("BackIcon0"));
  734. RichTextWidget toolbar_x2 = RichTextWidget.Cast(layoutRoot.FindAnyWidget("ApplyIcon0"));
  735. RichTextWidget toolbar_y2 = RichTextWidget.Cast(layoutRoot.FindAnyWidget("ResetIcon0"));
  736. RichTextWidget toolbar_def2 = RichTextWidget.Cast(layoutRoot.FindAnyWidget("DefaultIcon0"));
  737. toolbar_b2.SetText(InputUtils.GetRichtextButtonIconFromInputAction("UAUIBack", "", EUAINPUT_DEVICE_CONTROLLER));
  738. toolbar_x2.SetText(InputUtils.GetRichtextButtonIconFromInputAction("UAUICtrlX", "", EUAINPUT_DEVICE_CONTROLLER));
  739. toolbar_y2.SetText(InputUtils.GetRichtextButtonIconFromInputAction("UAUICredits", "", EUAINPUT_DEVICE_CONTROLLER));
  740. toolbar_def2.SetText(InputUtils.GetRichtextButtonIconFromInputAction("UAUICtrlY", "", EUAINPUT_DEVICE_CONTROLLER));
  741. #endif
  742. }
  743. protected void UpdateControlsElementVisibility()
  744. {
  745. bool toolbarShow = false;
  746. #ifdef PLATFORM_CONSOLE
  747. toolbarShow = !GetGame().GetInput().IsEnabledMouseAndKeyboardEvenOnServer() || GetGame().GetInput().GetCurrentInputDevice() == EInputDeviceType.CONTROLLER;
  748. #endif
  749. layoutRoot.FindAnyWidget("toolbar_bg").Show(toolbarShow);
  750. layoutRoot.FindAnyWidget("play_panel_root").Show(!toolbarShow);
  751. }
  752. }