File size: 17,874 Bytes
24b81cb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
const int MAX_FAVORITES = 25;

#ifdef PLATFORM_CONSOLE
const int SERVER_BROWSER_PAGE_SIZE = 22;
#else
const int SERVER_BROWSER_PAGE_SIZE = 5;
#endif

class ServerBrowserMenuNew extends UIScriptedMenu
{
	protected Widget				m_Play;
	protected Widget				m_Back;
	protected Widget				m_CustomizeCharacter;
	protected TextWidget			m_PlayerName;
	
	protected TabberUI				m_Tabber;
	protected ref ServerBrowserTab	m_OfficialTab;
	protected ref ServerBrowserTab	m_CommunityTab;
	protected ref ServerBrowserTab  m_FavoritesTab;
	protected ref ServerBrowserTab	m_LANTab;
	
	protected TabType				m_IsRefreshing = TabType.NONE;
	protected ref TStringArray		m_Favorites;
	protected ServerBrowserEntry	m_SelectedServer;
	
	override Widget Init()
	{
		#ifdef PLATFORM_CONSOLE
		layoutRoot 		= GetGame().GetWorkspace().CreateWidgets("gui/layouts/new_ui/server_browser/xbox/server_browser.layout");
		m_FavoritesTab  = new ServerBrowserFavoritesTabConsolePages(layoutRoot.FindAnyWidget("Tab_0"), this, TabType.FAVORITE);
		m_OfficialTab	= new ServerBrowserTabConsolePages(layoutRoot.FindAnyWidget("Tab_1"), this, TabType.OFFICIAL);
		m_CommunityTab	= new ServerBrowserTabConsolePages(layoutRoot.FindAnyWidget("Tab_2"), this, TabType.COMMUNITY);
		#else
		layoutRoot 		= GetGame().GetWorkspace().CreateWidgets("gui/layouts/new_ui/server_browser/pc/server_browser.layout");
		m_FavoritesTab  = new ServerBrowserFavoritesTabPc(layoutRoot.FindAnyWidget("Tab_0"), this, TabType.FAVORITE);
		m_OfficialTab	= new ServerBrowserTabPc(layoutRoot.FindAnyWidget("Tab_1"), this, TabType.OFFICIAL);
		m_CommunityTab	= new ServerBrowserTabPc(layoutRoot.FindAnyWidget("Tab_2"), this, TabType.COMMUNITY);
		m_LANTab		= new ServerBrowserTabPc(layoutRoot.FindAnyWidget("Tab_3"), this, TabType.LAN);
		#endif
		
		layoutRoot.FindAnyWidget("Tabber").GetScript(m_Tabber);
		
		m_Play					= layoutRoot.FindAnyWidget("play");
		m_Back					= layoutRoot.FindAnyWidget("back_button");
		m_CustomizeCharacter	= layoutRoot.FindAnyWidget("customize_character");
		m_PlayerName			= TextWidget.Cast(layoutRoot.FindAnyWidget("character_name_text"));
		m_Favorites 			= new TStringArray;
		
		#ifndef PLATFORM_CONSOLE
		layoutRoot.FindAnyWidget("customize_character").Show(false);
		layoutRoot.FindAnyWidget("character").Show(false);
		#endif
		
		Refresh();
		
		string version;
		GetGame().GetVersion(version);
		
		#ifdef PLATFORM_CONSOLE
		version = "#main_menu_version" + " " + version + " (" + g_Game.GetDatabaseID() + ")";
		if (GetGame().GetInput().IsEnabledMouseAndKeyboard())
		{
			layoutRoot.FindAnyWidget("play_panel_root").Show(true);
			layoutRoot.FindAnyWidget("MouseAndKeyboardWarning").Show(true);
			layoutRoot.FindAnyWidget("toolbar_bg").Show(false);
		}
		#else
		version = "#main_menu_version" + " " + version;
		#endif
		
		OnlineServices.m_ServersAsyncInvoker.Insert(OnLoadServersAsync);
		OnlineServices.m_ServerModLoadAsyncInvoker.Insert(OnLoadServerModsAsync);
		LoadFavoriteServers();
		
		m_Tabber.m_OnTabSwitch.Insert(OnTabSwitch);
		
		m_FavoritesTab.RefreshList();

		#ifdef PLATFORM_CONSOLE
		UpdateControlsElements();
		//Sort init
		TextWidget sort_text = TextWidget.Cast(layoutRoot.FindAnyWidget("SortText"));
		sort_text.SetText("#str_serverbrowserroot_toolbar_bg_consoletoolbar_sort_sorttext0");
		#endif
		
		PPERequesterBank.GetRequester(PPERequester_ServerBrowserBlur).Start(new Param1<float>(0.5));
		
		GetGame().GetMission().GetOnInputPresetChanged().Insert(OnInputPresetChanged);
		GetGame().GetMission().GetOnInputDeviceChanged().Insert(OnInputDeviceChanged);
		OnInputDeviceChanged(GetGame().GetInput().GetCurrentInputDevice());

		return layoutRoot;
	}
	
	void ~ServerBrowserMenuNew()
	{
		#ifdef PLATFORM_CONSOLE
		SaveFavoriteServersConsoles();
		#endif

		OnlineServices.m_ServersAsyncInvoker.Remove(OnLoadServersAsync);
		OnlineServices.m_ServerModLoadAsyncInvoker.Remove(OnLoadServerModsAsync);
		m_Tabber.m_OnTabSwitch.Remove(OnTabSwitch);
		PPERequesterBank.GetRequester(PPERequester_ServerBrowserBlur).Stop();
	}
	
	TStringArray GetFavoritedServerIds()
	{
		return m_Favorites;
	}
	
	protected void OnInputPresetChanged()
	{
		#ifdef PLATFORM_CONSOLE
		UpdateControlsElements();
		#endif
	}

	protected void OnInputDeviceChanged(EInputDeviceType pInputDeviceType)
	{
		switch (pInputDeviceType)
		{
		case EInputDeviceType.CONTROLLER:
			#ifdef PLATFORM_CONSOLE
			UpdateControlsElements();
			layoutRoot.FindAnyWidget("toolbar_bg").Show(true);
			layoutRoot.FindAnyWidget("ConsoleControls").Show(true);
			#endif
		break;

		default:
			#ifdef PLATFORM_CONSOLE
			if (GetGame().GetInput().IsEnabledMouseAndKeyboardEvenOnServer())
			{
				layoutRoot.FindAnyWidget("toolbar_bg").Show(false);
				layoutRoot.FindAnyWidget("ConsoleControls").Show(false);
			}
			#endif
		break;
		}
	}
	
	override bool OnClick(Widget w, int x, int y, int button)
	{
		if (button == MouseState.LEFT)
		{
			if (w == m_Play)
			{
				Play();
				return true;
			}
			else if (w == m_Back)
			{
				Back();
				return true;
			}
			else if (w == m_CustomizeCharacter)
			{
				CustomizeCharacter();
				return true;
			}
		}
		return false;
	}
	
	override bool OnMouseEnter(Widget w, int x, int y)
	{
		if (IsFocusable(w))
		{
			ColorHighlight(w);
			return true;
		}
		return false;
	}
	
	override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
	{
		if (IsFocusable(w))
		{
			ColorNormal(w);
			return true;
		}
		return false;
	}
	
	void SetServersLoadingTab(TabType refreshing)
	{
		m_IsRefreshing = refreshing;
		
		OnlineServices.m_ServersAsyncInvoker.Remove(OnLoadServersAsync);
		OnlineServices.m_ServersAsyncInvoker.Insert(OnLoadServersAsync, EScriptInvokerInsertFlags.NONE);
	}

	TabType GetServersLoadingTab()
	{
		return m_IsRefreshing;
	}
	
	void AddFavoritesToFilter(GetServersInput input)
	{
		foreach (string id : m_Favorites)
		{
			array<string> output = new array<string>;
			id.Split(":", output);
			if (output.Count() == 2)
			{
				string ip = output[0];
				int port = output[1].ToInt();
				input.AddFavourite(ip, port);
			}
		}
	}

	bool IsFavorited(string server_id)
	{
		int index = -1;
		if (m_Favorites)
		{
			index = m_Favorites.Find(server_id);		
		}
		return (index >= 0);
	}
	
	// Returns whether server was favorited or not
	bool SetFavoriteConsoles(string ipAddress, int port, bool favorite)
	{
		if (favorite && m_Favorites.Count() >= MAX_FAVORITES)
		{
			g_Game.GetUIManager().ShowDialog("#layout_notification_info_warning", "#STR_MaxFavouriteReached", 0, DBT_OK, DBB_YES, DMT_EXCLAMATION, this);
			return false;
		}

		AddFavorite(ipAddress, port, favorite);
		SaveFavoriteServersConsoles();
		
		return favorite;
	}
	
	void AddFavorite(string ipAddress, int port, bool favorite)
	{
		string serverId = ipAddress + ":" + port;
		bool isFavorited = IsFavorited(serverId);
		
		if (favorite && !isFavorited)
		{
			m_Favorites.Insert(serverId);
		}
		else if (isFavorited)
		{
			m_Favorites.RemoveItem(serverId);
			m_OfficialTab.Unfavorite(serverId);
			m_CommunityTab.Unfavorite(serverId);
			m_FavoritesTab.Unfavorite(serverId);
#ifndef PLATFORM_CONSOLE
			m_LANTab.Unfavorite(serverId);
#endif
		}
	}
	
	void Back()
	{
		GetGame().GetUIManager().Back();
	}
	
	void ShowYButton(bool show)
	{
		RichTextWidget yIcon = RichTextWidget.Cast(layoutRoot.FindAnyWidget("ResetIcon"));
		TextWidget yText = TextWidget.Cast(layoutRoot.FindAnyWidget("ResetText"));
		
		if (yIcon)
		{
			yIcon.Show(show);
		}
		
		if (yText)
		{
			yText.Show(show);
		}
	}
	
	void ShowAButton(bool show)
	{
		RichTextWidget aIcon = RichTextWidget.Cast(layoutRoot.FindAnyWidget("ConnectIcon"));
		TextWidget aText = TextWidget.Cast(layoutRoot.FindAnyWidget("ConnectText"));
		
		if (aIcon)
		{
			aIcon.Show(show);
		}
		
		if (aText)
		{
			aText.Show(show);
		}
				
	}
	
	void FilterFocus(bool focus)
	{
		#ifdef PLATFORM_CONSOLE
		TextWidget con_text = TextWidget.Cast(layoutRoot.FindAnyWidget("ConnectText"));
		TextWidget ref_text = TextWidget.Cast(layoutRoot.FindAnyWidget("RefreshText"));
		TextWidget res_text = TextWidget.Cast(layoutRoot.FindAnyWidget("ResetText"));
		
		if (focus)
		{
			con_text.SetText("#dialog_change");
			ref_text.SetText("#server_browser_menu_refresh");
			res_text.SetText("#server_browser_menu_reset_filters");
		
			con_text.Update();
			ref_text.Update();
			res_text.Update();
		}
		#endif
	}
	
	void BackButtonFocus()
	{
		SetFocus(m_Back);
	}

	void ServerListFocus(bool focus, bool favorite)
	{
		#ifdef PLATFORM_CONSOLE
		TextWidget con_text = TextWidget.Cast(layoutRoot.FindAnyWidget("ConnectText"));
		TextWidget ref_text = TextWidget.Cast(layoutRoot.FindAnyWidget("RefreshText"));
		TextWidget res_text = TextWidget.Cast(layoutRoot.FindAnyWidget("ResetText"));
		
		if (focus)
		{			
			con_text.SetText("#server_browser_menu_connect");
			
			float x, y;
			res_text.GetSize(x, y);
			if (favorite)
			{
				res_text.SetText("#server_browser_menu_unfavorite");
			}
			else
			{
				res_text.SetText("#server_browser_menu_favorite");
			}
			con_text.Update();
			res_text.Update();
		}
		#endif
	}
	
	override bool OnFocus(Widget w, int x, int y)
	{
		if (IsFocusable(w))
		{
			ColorHighlight(w);
			return true;
		}
		return false;
	}
	
	override bool OnFocusLost(Widget w, int x, int y)
	{
		if (IsFocusable(w))
		{
			ColorNormal(w);
			return true;
		}
		return false;
	}
	
	override void Refresh()
	{
		string name;
		
		#ifdef PLATFORM_CONSOLE
			if (GetGame().GetUserManager() && GetGame().GetUserManager().GetSelectedUser())
			{
				name = GetGame().GetUserManager().GetSelectedUser().GetName();
				if (name.LengthUtf8() > 18)
				{
					name = name.SubstringUtf8(0, 18);
					name += "...";
				}
			}
		#else
			g_Game.GetPlayerNameShort(14, name);
		#endif
		
		if (m_PlayerName)
			m_PlayerName.SetText(name);
		
		string version;
		GetGame().GetVersion(version);
		#ifdef PLATFORM_CONSOLE
			version = "#main_menu_version" + " " + version + " (" + g_Game.GetDatabaseID() + ")";
		#else
			version = "#main_menu_version" + " " + version;
		#endif
	}
	
	override void Update(float timeslice)
	{
		if (!GetGame().GetUIManager().IsDialogVisible() && !GetDayZGame().IsConnecting())
		{
			if (GetUApi().GetInputByID(UAUITabLeft).LocalPress())
			{
				m_Tabber.PreviousTab();
			}
			
			if (GetUApi().GetInputByID(UAUITabRight).LocalPress())
			{
				m_Tabber.NextTab();
			}
			
			if (GetUApi().GetInputByID(UAUINextDown).LocalPress())
			{
				GetSelectedTab().PressSholderLeft();
			}
			
			if (GetUApi().GetInputByID(UAUINextUp).LocalPress())
			{
				GetSelectedTab().PressSholderRight();
			}
			
			if (GetUApi().GetInputByID(UAUISelect).LocalPress())
			{
				GetSelectedTab().PressA();
			}
			
			if (GetUApi().GetInputByID(UAUICtrlX).LocalPress())
			{
				GetSelectedTab().PressX();
			}
			
			if (GetUApi().GetInputByID(UAUICtrlY).LocalPress())
			{
				GetSelectedTab().PressY();
			}
			
			if (GetUApi().GetInputByID(UAUILeft).LocalPress())
			{
				GetSelectedTab().Left();
			}
			
			// LEFT HOLD
			if (GetUApi().GetInputByID(UAUILeft).LocalHold())
			{
				GetSelectedTab().LeftHold();
			}
			
			// LEFT RELEASE
			if (GetUApi().GetInputByID(UAUILeft).LocalRelease())
			{
				GetSelectedTab().LeftRelease();
			}
			
			if (GetUApi().GetInputByID(UAUIRight).LocalPress())
			{
				GetSelectedTab().Right();
			}
			
			// RIGHT HOLD
			if (GetUApi().GetInputByID(UAUIRight).LocalHold())
			{
				GetSelectedTab().RightHold();
			}
			
			// RIGHT RELEASE
			if (GetUApi().GetInputByID(UAUIRight).LocalRelease())
			{
				GetSelectedTab().RightRelease();
			}
			
			if (GetUApi().GetInputByID(UAUIUp).LocalPress())
			{
				GetSelectedTab().Up();
			}
			
			if (GetUApi().GetInputByID(UAUIDown).LocalPress())
			{
				GetSelectedTab().Down();
			}
	
			if (GetUApi().GetInputByID(UAUIBack).LocalPress())
			{
				Back();
			}
		}
		
		super.Update(timeslice);
	}
	
	bool IsFocusable(Widget w)
	{
		if (w)
		{
			return (w == m_Play || w == m_CustomizeCharacter || w == m_Back);
		}
		return false;
	}
	
	void LoadFavoriteServers()
	{		
		m_Favorites = new TStringArray;
		
#ifdef PLATFORM_WINDOWS
		OnlineServices.GetFavoriteServers(m_Favorites);
#else
		GetGame().GetProfileStringList("SB_Favorites", m_Favorites);
		
		// ignore any ids that do not follow correct IP:PORT format
		for (int i = 0; i < m_Favorites.Count(); ++i)
		{
			string id = m_Favorites[i];
			array<string> output = new array<string>;
						
			id.Split(":", output);
			if (output.Count() != 2)
			{
				m_Favorites.Remove(i);
				--i;
			}
		}
		
		// only handle MAX_FAVORITES on consoles
		if (m_Favorites.Count() > MAX_FAVORITES)
		{
			// favorites are ordered by when they were favorited
			// so keep most recent favorites and ignore oldest favorites
			m_Favorites.Invert();
			m_Favorites.Resize(MAX_FAVORITES);
			m_Favorites.Invert();
		}
#endif
	}
	
	void SaveFavoriteServersConsoles()
	{
		GetGame().SetProfileStringList("SB_Favorites", m_Favorites);
		GetGame().SaveProfile();
		
	}
	
	void SelectServer(ServerBrowserEntry server)
	{
	
		if (m_SelectedServer)
		{
			m_SelectedServer.Deselect();						
		}
				
		m_SelectedServer = server;
		
#ifdef PLATFORM_CONSOLE
		// disable CONNECT button if server is offline
		RichTextWidget aButton = RichTextWidget.Cast(layoutRoot.FindAnyWidget("ConnectIcon"));
		TextWidget connectText = TextWidget.Cast(layoutRoot.FindAnyWidget("ConnectText"));
		
		aButton.Show(server.IsOnline());
		connectText.Show(server.IsOnline());
#endif
	}
	
	void Connect(ServerBrowserEntry server)
	{
		SelectServer(server);
#ifdef PLATFORM_CONSOLE
		SaveFavoriteServersConsoles();
#endif
		Play();
	}
	
	void Play()
	{
		if (m_SelectedServer)
		{
			string mapNM = m_SelectedServer.GetMapToRun();
			if (!g_Game.VerifyWorldOwnership(mapNM))
			{
				GetGame().GetUIManager().ShowDialog("#server_browser_connect_label", "#mod_detail_info_warning", 232, DBT_OK, DBB_NONE, DMT_INFO, GetGame().GetUIManager().GetMenu());
				g_Game.GoBuyWorldDLC(mapNM);
				return;
			}
			
			string ip = m_SelectedServer.GetIP();
			int port = m_SelectedServer.GetPort();
			g_Game.ConnectFromServerBrowser(ip, port, "");
		}
	}
	
	void CustomizeCharacter()
	{
		PPERequesterBank.GetRequester(PPERequester_ServerBrowserBlur).Stop();
		EnterScriptedMenu(MENU_CHARACTER);
	}
	
	void NextCharacter()
	{
		
	}
	
	void PreviousCharacter()
	{
		
	}
	
	ServerBrowserTab GetSelectedTab()
	{
		switch (m_Tabber.GetSelectedIndex())
		{
			case 0:
			{
				return m_FavoritesTab;
			}
			case 1:
			{
				return m_OfficialTab;
			}
			case 2:
			{
				return m_CommunityTab;
			}
			case 3:
			{
				return m_LANTab;
			}
		}
		return null;
	}
	
	void OnTabSwitch()
	{
		LoadFavoriteServers();
		SetServersLoadingTab(TabType.NONE);
		
		if (GetSelectedTab().IsNotInitialized())
		{
			GetSelectedTab().RefreshList();
		}
		
		GetSelectedTab().Focus();
	}
	
	void OnLoadServerModsAsync(GetServerModListResult result_list)
	{
		if (GetSelectedTab())
		{
			GetSelectedTab().OnLoadServerModsAsync(result_list.m_Id, result_list.m_Mods);
		}
	}
	
	void OnLoadServersAsync(GetServersResult result_list, EBiosError error, string response)
	{		
		#ifdef PLATFORM_WINDOWS
			#ifdef PLATFORM_CONSOLE
				GetSelectedTab().OnLoadServersAsyncConsole(result_list, error, response);
			#else
				GetSelectedTab().OnLoadServersAsyncPC(result_list, error, response);
			#endif
		#else
			GetSelectedTab().OnLoadServersAsyncConsole(result_list, error, response);
		#endif
	}
	
	//Coloring functions (Until WidgetStyles are useful)
	void ColorHighlight(Widget w)
	{
		if (!w)
			return;
		
		int color_pnl = ARGB(255, 0, 0, 0);
		int color_lbl = ARGB(255, 255, 0, 0);
		
		#ifdef PLATFORM_CONSOLE
			color_pnl = ARGB(255, 200, 0, 0);
			color_lbl = ARGB(255, 255, 255, 255);
		#endif
		
		ButtonSetColor(w, color_pnl);
		ButtonSetTextColor(w, color_lbl);
	}
	
	void ColorNormal(Widget w)
	{
		if (!w)
			return;
		
		int color_pnl = ARGB(0, 0, 0, 0);
		int color_lbl = ARGB(255, 255, 255, 255);
		
		ButtonSetColor(w, color_pnl);
		ButtonSetTextColor(w, color_lbl);
	}
	
	void ButtonSetText(Widget w, string text)
	{
		if (!w)
			return;
				
		TextWidget label = TextWidget.Cast(w.FindWidget(w.GetName() + "_label"));
		
		if (label)
		{
			label.SetText(text);
		}
		
	}
	
	void ButtonSetColor(Widget w, int color)
	{
		if (!w)
			return;
		
		Widget panel = w.FindWidget(w.GetName() + "_panel");
		
		if (panel)
		{
			panel.SetColor(color);
		}
	}
	
	void ButtonSetTextColor(Widget w, int color)
	{
		if (!w)
			return;

		TextWidget label	= TextWidget.Cast(w.FindAnyWidget(w.GetName() + "_label"));
		TextWidget text		= TextWidget.Cast(w.FindAnyWidget(w.GetName() + "_text"));
		TextWidget text2	= TextWidget.Cast(w.FindAnyWidget(w.GetName() + "_text_1"));
				
		if (label)
		{
			label.SetColor(color);
		}
		
		if (text)
		{
			text.SetColor(color);
		}
		
		if (text2)
		{
			text2.SetColor(color);
		}
	}

	protected void UpdateControlsElements()
	{
		RichTextWidget toolbar_a = RichTextWidget.Cast(layoutRoot.FindAnyWidget("ConnectIcon"));
		RichTextWidget toolbar_b = RichTextWidget.Cast(layoutRoot.FindAnyWidget("BackIcon"));
		RichTextWidget toolbar_x = RichTextWidget.Cast(layoutRoot.FindAnyWidget("RefreshIcon"));
		RichTextWidget toolbar_y = RichTextWidget.Cast(layoutRoot.FindAnyWidget("ResetIcon"));
		toolbar_a.SetText(InputUtils.GetRichtextButtonIconFromInputAction("UAUISelect", "", EUAINPUT_DEVICE_CONTROLLER, InputUtils.ICON_SCALE_TOOLBAR));
		toolbar_b.SetText(InputUtils.GetRichtextButtonIconFromInputAction("UAUIBack", "", EUAINPUT_DEVICE_CONTROLLER, InputUtils.ICON_SCALE_TOOLBAR));
		toolbar_x.SetText(InputUtils.GetRichtextButtonIconFromInputAction("UAUICtrlX", "", EUAINPUT_DEVICE_CONTROLLER, InputUtils.ICON_SCALE_TOOLBAR));
		toolbar_y.SetText(InputUtils.GetRichtextButtonIconFromInputAction("UAUICtrlY", "", EUAINPUT_DEVICE_CONTROLLER, InputUtils.ICON_SCALE_TOOLBAR));
	}
}