serverbrowsermenunew.c 21 KB

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