serverbrowsermenunew.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895
  1. const int MAX_FAVORITES = 25;
  2. #ifdef PLATFORM_CONSOLE
  3. const int SERVER_BROWSER_PAGE_SIZE = 22;
  4. #else
  5. const int SERVER_BROWSER_PAGE_SIZE = 5;
  6. #endif
  7. class ServerBrowserMenuNew extends UIScriptedMenu
  8. {
  9. protected Widget m_Play;
  10. protected TextWidget m_PlayButtonLabel;
  11. protected TextWidget m_OpenStoreButtonLabel;
  12. protected Widget m_Back;
  13. protected Widget m_CustomizeCharacter;
  14. protected TextWidget m_PlayerName;
  15. protected TabberUI m_Tabber;
  16. protected ref ServerBrowserTab m_OfficialTab;
  17. protected ref ServerBrowserTab m_CommunityTab;
  18. protected ref ServerBrowserTab m_FavoritesTab;
  19. protected ref ServerBrowserTab m_LANTab;
  20. protected TabType m_IsRefreshing = TabType.NONE;
  21. protected ref TStringArray m_Favorites;
  22. protected ServerBrowserEntry m_SelectedServer;
  23. override Widget Init()
  24. {
  25. #ifdef PLATFORM_CONSOLE
  26. layoutRoot = GetGame().GetWorkspace().CreateWidgets("gui/layouts/new_ui/server_browser/xbox/server_browser.layout");
  27. m_FavoritesTab = new ServerBrowserFavoritesTabConsolePages(layoutRoot.FindAnyWidget("Tab_0"), this, TabType.FAVORITE);
  28. m_OfficialTab = new ServerBrowserTabConsolePages(layoutRoot.FindAnyWidget("Tab_1"), this, TabType.OFFICIAL);
  29. m_CommunityTab = new ServerBrowserTabConsolePages(layoutRoot.FindAnyWidget("Tab_2"), this, TabType.COMMUNITY);
  30. #else
  31. layoutRoot = GetGame().GetWorkspace().CreateWidgets("gui/layouts/new_ui/server_browser/pc/server_browser.layout");
  32. m_FavoritesTab = new ServerBrowserFavoritesTabPc(layoutRoot.FindAnyWidget("Tab_0"), this, TabType.FAVORITE);
  33. m_OfficialTab = new ServerBrowserTabPc(layoutRoot.FindAnyWidget("Tab_1"), this, TabType.OFFICIAL);
  34. m_CommunityTab = new ServerBrowserTabPc(layoutRoot.FindAnyWidget("Tab_2"), this, TabType.COMMUNITY);
  35. m_LANTab = new ServerBrowserTabPc(layoutRoot.FindAnyWidget("Tab_3"), this, TabType.LAN);
  36. #endif
  37. layoutRoot.FindAnyWidget("Tabber").GetScript(m_Tabber);
  38. m_Play = layoutRoot.FindAnyWidget("play");
  39. m_PlayButtonLabel = TextWidget.Cast(m_Play.FindAnyWidget("play_label"));
  40. m_OpenStoreButtonLabel = TextWidget.Cast(m_Play.FindAnyWidget("open_store_label"));
  41. m_Back = layoutRoot.FindAnyWidget("back_button");
  42. m_CustomizeCharacter = layoutRoot.FindAnyWidget("customize_character");
  43. m_PlayerName = TextWidget.Cast(layoutRoot.FindAnyWidget("character_name_text"));
  44. m_Favorites = new TStringArray;
  45. #ifndef PLATFORM_CONSOLE
  46. layoutRoot.FindAnyWidget("customize_character").Show(false);
  47. layoutRoot.FindAnyWidget("character").Show(false);
  48. #endif
  49. Refresh();
  50. string version;
  51. GetGame().GetVersion(version);
  52. #ifdef PLATFORM_CONSOLE
  53. version = "#main_menu_version" + " " + version + " (" + g_Game.GetDatabaseID() + ")";
  54. if (GetGame().GetInput().IsEnabledMouseAndKeyboard())
  55. {
  56. layoutRoot.FindAnyWidget("toolbar_bg").Show(false);
  57. }
  58. RichTextWidget playPanelBack = RichTextWidget.Cast(layoutRoot.FindAnyWidget("BackIcon0"));
  59. playPanelBack.SetText(InputUtils.GetRichtextButtonIconFromInputAction("UAUIBack", "", EUAINPUT_DEVICE_CONTROLLER, InputUtils.ICON_SCALE_NORMAL));
  60. RichTextWidget playPanelPlay = RichTextWidget.Cast(layoutRoot.FindAnyWidget("PlayIcon0"));
  61. playPanelPlay.SetText(InputUtils.GetRichtextButtonIconFromInputAction("UAUISelect", "", EUAINPUT_DEVICE_CONTROLLER, InputUtils.ICON_SCALE_NORMAL));
  62. #else
  63. version = "#main_menu_version" + " " + version;
  64. #endif
  65. OnlineServices.m_ServersAsyncInvoker.Insert(OnLoadServersAsync);
  66. OnlineServices.m_ServerModLoadAsyncInvoker.Insert(OnLoadServerModsAsync);
  67. LoadFavoriteServers();
  68. m_Tabber.m_OnTabSwitch.Insert(OnTabSwitch);
  69. m_FavoritesTab.RefreshList();
  70. #ifdef PLATFORM_CONSOLE
  71. UpdateControlsElements();
  72. //Sort init
  73. TextWidget sort_text = TextWidget.Cast(layoutRoot.FindAnyWidget("SortText"));
  74. sort_text.SetText("#str_serverbrowserroot_toolbar_bg_consoletoolbar_sort_sorttext0");
  75. #endif
  76. PPERequesterBank.GetRequester(PPERequester_ServerBrowserBlur).Start(new Param1<float>(0.5));
  77. GetGame().GetMission().GetOnInputPresetChanged().Insert(OnInputPresetChanged);
  78. GetGame().GetMission().GetOnInputDeviceChanged().Insert(OnInputDeviceChanged);
  79. OnInputDeviceChanged(GetGame().GetInput().GetCurrentInputDevice());
  80. return layoutRoot;
  81. }
  82. void ~ServerBrowserMenuNew()
  83. {
  84. #ifdef PLATFORM_CONSOLE
  85. SaveFavoriteServersConsoles();
  86. #endif
  87. OnlineServices.m_ServersAsyncInvoker.Remove(OnLoadServersAsync);
  88. OnlineServices.m_ServerModLoadAsyncInvoker.Remove(OnLoadServerModsAsync);
  89. m_Tabber.m_OnTabSwitch.Remove(OnTabSwitch);
  90. PPERequesterBank.GetRequester(PPERequester_ServerBrowserBlur).Stop();
  91. }
  92. TStringArray GetFavoritedServerIds()
  93. {
  94. return m_Favorites;
  95. }
  96. protected void OnInputPresetChanged()
  97. {
  98. #ifdef PLATFORM_CONSOLE
  99. UpdateControlsElements();
  100. #endif
  101. }
  102. protected void OnInputDeviceChanged(EInputDeviceType pInputDeviceType)
  103. {
  104. switch (pInputDeviceType)
  105. {
  106. case EInputDeviceType.CONTROLLER:
  107. #ifdef PLATFORM_CONSOLE
  108. UpdateControlsElements();
  109. layoutRoot.FindAnyWidget("toolbar_bg").Show(true);
  110. layoutRoot.FindAnyWidget("ConsoleControls").Show(true);
  111. layoutRoot.FindAnyWidget("PlayIcon0").Show(false);
  112. layoutRoot.FindAnyWidget("BackIcon0").Show(false);
  113. #endif
  114. break;
  115. default:
  116. #ifdef PLATFORM_CONSOLE
  117. if (GetGame().GetInput().IsEnabledMouseAndKeyboardEvenOnServer())
  118. {
  119. layoutRoot.FindAnyWidget("toolbar_bg").Show(false);
  120. layoutRoot.FindAnyWidget("ConsoleControls").Show(false);
  121. layoutRoot.FindAnyWidget("PlayIcon0").Show(true);
  122. layoutRoot.FindAnyWidget("BackIcon0").Show(true);
  123. }
  124. #endif
  125. break;
  126. }
  127. }
  128. override bool OnClick(Widget w, int x, int y, int button)
  129. {
  130. if (button == MouseState.LEFT)
  131. {
  132. if (w == m_Play)
  133. {
  134. Play();
  135. return true;
  136. }
  137. else if (w == m_Back)
  138. {
  139. Back();
  140. return true;
  141. }
  142. else if (w == m_CustomizeCharacter)
  143. {
  144. CustomizeCharacter();
  145. return true;
  146. }
  147. }
  148. return false;
  149. }
  150. override bool OnMouseEnter(Widget w, int x, int y)
  151. {
  152. if (IsFocusable(w))
  153. {
  154. ColorHighlight(w);
  155. return true;
  156. }
  157. return false;
  158. }
  159. override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
  160. {
  161. if (IsFocusable(w))
  162. {
  163. ColorNormal(w);
  164. return true;
  165. }
  166. return false;
  167. }
  168. void SetServersLoadingTab(TabType refreshing)
  169. {
  170. m_IsRefreshing = refreshing;
  171. OnlineServices.m_ServersAsyncInvoker.Remove(OnLoadServersAsync);
  172. OnlineServices.m_ServersAsyncInvoker.Insert(OnLoadServersAsync, EScriptInvokerInsertFlags.NONE);
  173. }
  174. TabType GetServersLoadingTab()
  175. {
  176. return m_IsRefreshing;
  177. }
  178. void AddFavoritesToFilter(GetServersInput input)
  179. {
  180. foreach (string id : m_Favorites)
  181. {
  182. array<string> output = new array<string>;
  183. id.Split(":", output);
  184. if (output.Count() == 2)
  185. {
  186. string ip = output[0];
  187. int port = output[1].ToInt();
  188. input.AddFavourite(ip, port);
  189. }
  190. }
  191. }
  192. bool IsFavorited(string server_id)
  193. {
  194. int index = -1;
  195. if (m_Favorites)
  196. {
  197. index = m_Favorites.Find(server_id);
  198. }
  199. return (index >= 0);
  200. }
  201. // Returns whether server was favorited or not
  202. bool SetFavoriteConsoles(string ipAddress, int port, bool favorite)
  203. {
  204. if (favorite && m_Favorites.Count() >= MAX_FAVORITES)
  205. {
  206. g_Game.GetUIManager().ShowDialog("#layout_notification_info_warning", "#STR_MaxFavouriteReached", 0, DBT_OK, DBB_YES, DMT_EXCLAMATION, this);
  207. return false;
  208. }
  209. AddFavorite(ipAddress, port, favorite);
  210. SaveFavoriteServersConsoles();
  211. return favorite;
  212. }
  213. void AddFavorite(string ipAddress, int port, bool favorite)
  214. {
  215. string serverId = ipAddress + ":" + port;
  216. bool isFavorited = IsFavorited(serverId);
  217. if (favorite && !isFavorited)
  218. {
  219. m_Favorites.Insert(serverId);
  220. }
  221. else if (isFavorited)
  222. {
  223. m_Favorites.RemoveItem(serverId);
  224. m_OfficialTab.Unfavorite(serverId);
  225. m_CommunityTab.Unfavorite(serverId);
  226. m_FavoritesTab.Unfavorite(serverId);
  227. #ifndef PLATFORM_CONSOLE
  228. m_LANTab.Unfavorite(serverId);
  229. #endif
  230. }
  231. }
  232. void Back()
  233. {
  234. GetGame().GetUIManager().Back();
  235. }
  236. void ShowYButton(bool show)
  237. {
  238. RichTextWidget yIcon = RichTextWidget.Cast(layoutRoot.FindAnyWidget("ResetIcon"));
  239. TextWidget yText = TextWidget.Cast(layoutRoot.FindAnyWidget("ResetText"));
  240. if (yIcon)
  241. {
  242. yIcon.Show(show);
  243. }
  244. if (yText)
  245. {
  246. yText.Show(show);
  247. }
  248. }
  249. void UpdateYButtonLabel(string text)
  250. {
  251. TextWidget yText = TextWidget.Cast(layoutRoot.FindAnyWidget("ResetText"));
  252. if (yText)
  253. {
  254. yText.SetText(text);
  255. yText.Update();
  256. }
  257. }
  258. void ShowAButton(bool show)
  259. {
  260. RichTextWidget aIcon = RichTextWidget.Cast(layoutRoot.FindAnyWidget("ConnectIcon"));
  261. TextWidget aText = TextWidget.Cast(layoutRoot.FindAnyWidget("ConnectText"));
  262. if (aIcon)
  263. {
  264. aIcon.Show(show);
  265. }
  266. if (aText)
  267. {
  268. aText.Show(show);
  269. }
  270. }
  271. void UpdateAButtonLabel(string text)
  272. {
  273. TextWidget aText = TextWidget.Cast(layoutRoot.FindAnyWidget("ConnectText"));
  274. if (aText)
  275. {
  276. aText.SetText(text);
  277. aText.Update();
  278. }
  279. }
  280. void UpdateXButtonLabel(string text)
  281. {
  282. TextWidget xText = TextWidget.Cast(layoutRoot.FindAnyWidget("RefreshText"));
  283. if (xText)
  284. {
  285. xText.SetText(text);
  286. xText.Update();
  287. }
  288. }
  289. void ShowThumbRButton(bool show)
  290. {
  291. RichTextWidget trIcon = RichTextWidget.Cast(layoutRoot.FindAnyWidget("SwitchIcon"));
  292. TextWidget trText = TextWidget.Cast(layoutRoot.FindAnyWidget("SwitchText"));
  293. if (trIcon)
  294. {
  295. trIcon.Show(show);
  296. }
  297. if (trText)
  298. {
  299. trText.Show(show);
  300. }
  301. }
  302. void UpdateThumbRButtonLabel(string text)
  303. {
  304. TextWidget trText = TextWidget.Cast(layoutRoot.FindAnyWidget("SwitchText"));
  305. if (trText)
  306. {
  307. trText.SetText(text);
  308. trText.Update();
  309. }
  310. }
  311. void FilterFocus(bool focus)
  312. {
  313. #ifdef PLATFORM_CONSOLE
  314. if (focus)
  315. {
  316. ShowThumbRButton(false);
  317. string aButtonLabel;
  318. if (GetServersLoadingTab() == TabType.FAVORITE)
  319. {
  320. #ifdef PLATFORM_PS4
  321. aButtonLabel = "#ps4_ingame_menu_select";
  322. #else
  323. aButtonLabel = "#layout_xbox_ingame_menu_select";
  324. #endif
  325. }
  326. else
  327. {
  328. aButtonLabel = "#dialog_change";
  329. }
  330. UpdateAButtonLabel(aButtonLabel);
  331. UpdateXButtonLabel("#server_browser_menu_refresh");
  332. UpdateYButtonLabel("#server_details_header");
  333. }
  334. #endif
  335. }
  336. void DetailsFocus(bool focus)
  337. {
  338. #ifdef PLATFORM_CONSOLE
  339. if (focus)
  340. {
  341. ShowThumbRButton(false);
  342. UpdateYButtonLabel("#STR_server_browser_tab_root_details_show_server_filters");
  343. string aButtonLabel;
  344. #ifdef PLATFORM_PS4
  345. aButtonLabel = "#ps4_ingame_menu_select";
  346. #else
  347. aButtonLabel = "#layout_xbox_ingame_menu_select";
  348. #endif
  349. UpdateAButtonLabel(aButtonLabel);
  350. }
  351. #endif
  352. }
  353. void BackButtonFocus()
  354. {
  355. SetFocus(m_Back);
  356. }
  357. void ServerListFocus(bool focus, bool favorite)
  358. {
  359. #ifdef PLATFORM_CONSOLE
  360. if (focus)
  361. {
  362. UpdateAButtonLabel("#server_browser_menu_connect");
  363. string trText;
  364. if (favorite)
  365. {
  366. trText = "#server_browser_menu_unfavorite";
  367. }
  368. else
  369. {
  370. trText = "#server_browser_menu_favorite";
  371. }
  372. UpdateThumbRButtonLabel(trText);
  373. }
  374. #endif
  375. }
  376. override bool OnFocus(Widget w, int x, int y)
  377. {
  378. if (IsFocusable(w))
  379. {
  380. ColorHighlight(w);
  381. return true;
  382. }
  383. return false;
  384. }
  385. override bool OnFocusLost(Widget w, int x, int y)
  386. {
  387. if (IsFocusable(w))
  388. {
  389. ColorNormal(w);
  390. return true;
  391. }
  392. return false;
  393. }
  394. override void Refresh()
  395. {
  396. string name;
  397. #ifdef PLATFORM_CONSOLE
  398. if (GetGame().GetUserManager() && GetGame().GetUserManager().GetSelectedUser())
  399. {
  400. name = GetGame().GetUserManager().GetSelectedUser().GetName();
  401. if (name.LengthUtf8() > 18)
  402. {
  403. name = name.SubstringUtf8(0, 18);
  404. name += "...";
  405. }
  406. }
  407. #else
  408. g_Game.GetPlayerNameShort(14, name);
  409. #endif
  410. if (m_PlayerName)
  411. m_PlayerName.SetText(name);
  412. string version;
  413. GetGame().GetVersion(version);
  414. #ifdef PLATFORM_CONSOLE
  415. version = "#main_menu_version" + " " + version + " (" + g_Game.GetDatabaseID() + ")";
  416. #else
  417. version = "#main_menu_version" + " " + version;
  418. #endif
  419. }
  420. override void Update(float timeslice)
  421. {
  422. if (!GetGame().GetUIManager().IsDialogVisible() && !GetDayZGame().IsConnecting())
  423. {
  424. if (GetUApi().GetInputByID(UAUIThumbRight).LocalPress())
  425. {
  426. GetSelectedTab().PressThumbRight();
  427. }
  428. if (GetUApi().GetInputByID(UAUITabLeft).LocalPress())
  429. {
  430. m_Tabber.PreviousTab();
  431. }
  432. if (GetUApi().GetInputByID(UAUITabRight).LocalPress())
  433. {
  434. m_Tabber.NextTab();
  435. }
  436. if (GetUApi().GetInputByID(UAUINextDown).LocalPress())
  437. {
  438. GetSelectedTab().PressSholderLeft();
  439. }
  440. if (GetUApi().GetInputByID(UAUINextUp).LocalPress())
  441. {
  442. GetSelectedTab().PressSholderRight();
  443. }
  444. if (GetUApi().GetInputByID(UAUISelect).LocalPress())
  445. {
  446. GetSelectedTab().PressA();
  447. }
  448. if (GetUApi().GetInputByID(UAUICtrlX).LocalPress())
  449. {
  450. GetSelectedTab().PressX();
  451. }
  452. if (GetUApi().GetInputByID(UAUICtrlY).LocalPress())
  453. {
  454. GetSelectedTab().PressY();
  455. }
  456. if (GetUApi().GetInputByID(UAUILeft).LocalPress())
  457. {
  458. GetSelectedTab().Left();
  459. }
  460. // LEFT HOLD
  461. if (GetUApi().GetInputByID(UAUILeft).LocalHold())
  462. {
  463. GetSelectedTab().LeftHold();
  464. }
  465. // LEFT RELEASE
  466. if (GetUApi().GetInputByID(UAUILeft).LocalRelease())
  467. {
  468. GetSelectedTab().LeftRelease();
  469. }
  470. if (GetUApi().GetInputByID(UAUIRight).LocalPress())
  471. {
  472. GetSelectedTab().Right();
  473. }
  474. // RIGHT HOLD
  475. if (GetUApi().GetInputByID(UAUIRight).LocalHold())
  476. {
  477. GetSelectedTab().RightHold();
  478. }
  479. // RIGHT RELEASE
  480. if (GetUApi().GetInputByID(UAUIRight).LocalRelease())
  481. {
  482. GetSelectedTab().RightRelease();
  483. }
  484. if (GetUApi().GetInputByID(UAUIUp).LocalPress())
  485. {
  486. GetSelectedTab().Up();
  487. }
  488. if (GetUApi().GetInputByID(UAUIDown).LocalPress())
  489. {
  490. GetSelectedTab().Down();
  491. }
  492. if (GetUApi().GetInputByID(UAUIBack).LocalPress())
  493. {
  494. Back();
  495. }
  496. }
  497. super.Update(timeslice);
  498. }
  499. bool IsFocusable(Widget w)
  500. {
  501. if (w)
  502. {
  503. return (w == m_Play || w == m_CustomizeCharacter || w == m_Back);
  504. }
  505. return false;
  506. }
  507. void LoadFavoriteServers()
  508. {
  509. m_Favorites = new TStringArray;
  510. #ifdef PLATFORM_WINDOWS
  511. OnlineServices.GetFavoriteServers(m_Favorites);
  512. #else
  513. GetGame().GetProfileStringList("SB_Favorites", m_Favorites);
  514. // ignore any ids that do not follow correct IP:PORT format
  515. for (int i = 0; i < m_Favorites.Count(); ++i)
  516. {
  517. string id = m_Favorites[i];
  518. array<string> output = new array<string>;
  519. id.Split(":", output);
  520. if (output.Count() != 2)
  521. {
  522. m_Favorites.Remove(i);
  523. --i;
  524. }
  525. }
  526. // only handle MAX_FAVORITES on consoles
  527. if (m_Favorites.Count() > MAX_FAVORITES)
  528. {
  529. // favorites are ordered by when they were favorited
  530. // so keep most recent favorites and ignore oldest favorites
  531. m_Favorites.Invert();
  532. m_Favorites.Resize(MAX_FAVORITES);
  533. m_Favorites.Invert();
  534. }
  535. #endif
  536. }
  537. void SaveFavoriteServersConsoles()
  538. {
  539. GetGame().SetProfileStringList("SB_Favorites", m_Favorites);
  540. GetGame().SaveProfile();
  541. }
  542. void SelectServer(ServerBrowserEntry server)
  543. {
  544. if (m_SelectedServer)
  545. {
  546. m_SelectedServer.Deselect();
  547. }
  548. m_SelectedServer = server;
  549. string mapNM = m_SelectedServer.GetMapToRun();
  550. if (!g_Game.VerifyWorldOwnership(mapNM))
  551. {
  552. m_PlayButtonLabel.Show(false);
  553. m_OpenStoreButtonLabel.Show(true);
  554. }
  555. else
  556. {
  557. m_PlayButtonLabel.Show(true);
  558. m_OpenStoreButtonLabel.Show(false);
  559. }
  560. }
  561. void DeselectCurrentServer()
  562. {
  563. if (m_SelectedServer)
  564. m_SelectedServer.Deselect();
  565. m_SelectedServer = null;
  566. }
  567. void Connect(ServerBrowserEntry server)
  568. {
  569. SelectServer(server);
  570. #ifdef PLATFORM_CONSOLE
  571. SaveFavoriteServersConsoles();
  572. #endif
  573. Play();
  574. }
  575. void Play()
  576. {
  577. if (m_SelectedServer)
  578. {
  579. string mapNM = m_SelectedServer.GetMapToRun();
  580. if (!g_Game.VerifyWorldOwnership(mapNM))
  581. {
  582. /*JsonDataDLCList data = DlcDataLoader.GetData();
  583. foreach (JsonDataDLCInfo dlcInfo : data.DLCs)
  584. {
  585. // fetch mod info
  586. // if server runs this dlcInfo && !info.GetIsOwned()
  587. //info.GoToStore();
  588. }*/
  589. GetGame().GetUIManager().ShowDialog("#server_browser_connect_label", "#mod_detail_info_warning", 232, DBT_OK, DBB_NONE, DMT_INFO, GetGame().GetUIManager().GetMenu());
  590. g_Game.GoBuyWorldDLC(mapNM);
  591. return;
  592. }
  593. string ip = m_SelectedServer.GetIP();
  594. int port = m_SelectedServer.GetPort();
  595. int steamQueryPort = m_SelectedServer.GetSteamQueryPort();
  596. g_Game.ConnectFromServerBrowserEx(ip, port, steamQueryPort, "");
  597. }
  598. }
  599. void CustomizeCharacter()
  600. {
  601. PPERequesterBank.GetRequester(PPERequester_ServerBrowserBlur).Stop();
  602. EnterScriptedMenu(MENU_CHARACTER);
  603. }
  604. // Unused?!
  605. void NextCharacter()
  606. {
  607. }
  608. // Unused?!
  609. void PreviousCharacter()
  610. {
  611. }
  612. ServerBrowserTab GetSelectedTab()
  613. {
  614. switch (m_Tabber.GetSelectedIndex())
  615. {
  616. case 0:
  617. {
  618. return m_FavoritesTab;
  619. }
  620. case 1:
  621. {
  622. return m_OfficialTab;
  623. }
  624. case 2:
  625. {
  626. return m_CommunityTab;
  627. }
  628. case 3:
  629. {
  630. return m_LANTab;
  631. }
  632. }
  633. return null;
  634. }
  635. void OnTabSwitch()
  636. {
  637. #ifdef PLATFORM_CONSOLE
  638. ShowThumbRButton(false);
  639. #endif
  640. LoadFavoriteServers();
  641. SetServersLoadingTab(TabType.NONE);
  642. if (GetSelectedTab().IsNotInitialized())
  643. {
  644. GetSelectedTab().RefreshList();
  645. }
  646. GetSelectedTab().Focus();
  647. #ifdef PLATFORM_CONSOLE
  648. UpdateControlsElements();
  649. if (GetSelectedTab().GetTabType() != TabType.FAVORITE)
  650. {
  651. ShowYButton(true);
  652. }
  653. else
  654. {
  655. ShowYButton(false);
  656. }
  657. #endif
  658. }
  659. void OnLoadServerModsAsync(GetServerModListResult result_list)
  660. {
  661. if (GetSelectedTab())
  662. {
  663. GetSelectedTab().OnLoadServerModsAsync(result_list.m_Id, result_list.m_Mods);
  664. }
  665. }
  666. void OnLoadServersAsync(GetServersResult result_list, EBiosError error, string response)
  667. {
  668. #ifdef PLATFORM_WINDOWS
  669. #ifdef PLATFORM_CONSOLE
  670. GetSelectedTab().OnLoadServersAsyncConsole(result_list, error, response);
  671. #else
  672. GetSelectedTab().OnLoadServersAsyncPC(result_list, error, response);
  673. #endif
  674. #else
  675. GetSelectedTab().OnLoadServersAsyncConsole(result_list, error, response);
  676. #endif
  677. }
  678. //Coloring functions (Until WidgetStyles are useful)
  679. void ColorHighlight(Widget w)
  680. {
  681. if (!w)
  682. return;
  683. int color_pnl = ARGB(255, 0, 0, 0);
  684. int color_lbl = ARGB(255, 255, 0, 0);
  685. #ifdef PLATFORM_CONSOLE
  686. color_pnl = ARGB(255, 200, 0, 0);
  687. color_lbl = ARGB(255, 255, 255, 255);
  688. #endif
  689. ButtonSetColor(w, color_pnl);
  690. ButtonSetTextColor(w, color_lbl);
  691. }
  692. void ColorNormal(Widget w)
  693. {
  694. if (!w)
  695. return;
  696. int color_pnl = ARGB(0, 0, 0, 0);
  697. int color_lbl = ARGB(255, 255, 255, 255);
  698. ButtonSetColor(w, color_pnl);
  699. ButtonSetTextColor(w, color_lbl);
  700. }
  701. void ButtonSetText(Widget w, string text)
  702. {
  703. if (!w)
  704. return;
  705. TextWidget label = TextWidget.Cast(w.FindWidget(w.GetName() + "_label"));
  706. if (label)
  707. {
  708. label.SetText(text);
  709. }
  710. }
  711. void ButtonSetColor(Widget w, int color)
  712. {
  713. if (!w)
  714. return;
  715. Widget panel = w.FindWidget(w.GetName() + "_panel");
  716. if (panel)
  717. {
  718. panel.SetColor(color);
  719. }
  720. }
  721. void ButtonSetTextColor(Widget w, int color)
  722. {
  723. if (!w)
  724. return;
  725. TextWidget label = TextWidget.Cast(w.FindAnyWidget(w.GetName() + "_label"));
  726. TextWidget text = TextWidget.Cast(w.FindAnyWidget(w.GetName() + "_text"));
  727. TextWidget text2 = TextWidget.Cast(w.FindAnyWidget(w.GetName() + "_text_1"));
  728. if (label)
  729. {
  730. label.SetColor(color);
  731. }
  732. if (text)
  733. {
  734. text.SetColor(color);
  735. }
  736. if (text2)
  737. {
  738. text2.SetColor(color);
  739. }
  740. }
  741. protected void UpdateControlsElements()
  742. {
  743. RichTextWidget toolbar_a = RichTextWidget.Cast(layoutRoot.FindAnyWidget("ConnectIcon"));
  744. RichTextWidget toolbar_b = RichTextWidget.Cast(layoutRoot.FindAnyWidget("BackIcon"));
  745. RichTextWidget toolbar_x = RichTextWidget.Cast(layoutRoot.FindAnyWidget("RefreshIcon"));
  746. RichTextWidget toolbar_y = RichTextWidget.Cast(layoutRoot.FindAnyWidget("ResetIcon"));
  747. RichTextWidget toolbar_tr = RichTextWidget.Cast(layoutRoot.FindAnyWidget("SwitchIcon"));
  748. toolbar_a.SetText(InputUtils.GetRichtextButtonIconFromInputAction("UAUISelect", "", EUAINPUT_DEVICE_CONTROLLER, InputUtils.ICON_SCALE_TOOLBAR));
  749. toolbar_b.SetText(InputUtils.GetRichtextButtonIconFromInputAction("UAUIBack", "", EUAINPUT_DEVICE_CONTROLLER, InputUtils.ICON_SCALE_TOOLBAR));
  750. toolbar_x.SetText(InputUtils.GetRichtextButtonIconFromInputAction("UAUICtrlX", "", EUAINPUT_DEVICE_CONTROLLER, InputUtils.ICON_SCALE_TOOLBAR));
  751. toolbar_y.SetText(InputUtils.GetRichtextButtonIconFromInputAction("UAUICtrlY", "", EUAINPUT_DEVICE_CONTROLLER, InputUtils.ICON_SCALE_TOOLBAR));
  752. toolbar_tr.SetText(InputUtils.GetRichtextButtonIconFromInputAction("UAUIThumbRight", "", EUAINPUT_DEVICE_CONTROLLER, InputUtils.ICON_SCALE_TOOLBAR));
  753. }
  754. override void OnHide()
  755. {
  756. super.OnHide();
  757. PPERequesterBank.GetRequester(PPERequester_ServerBrowserBlur).Stop();
  758. }
  759. }