serverbrowsermenunew.c 21 KB

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