File size: 17,999 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
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
class ServerBrowserEntry extends ScriptedWidgetEventHandler
{
	protected Widget					m_Root;
	protected Widget					m_Favorite;
	protected Widget					m_Expand;
	
	//Basic info
	protected TextWidget				m_ServerName;
	protected TextWidget				m_ServerPopulation;
	protected TextWidget				m_ServerSlots;
	protected TextWidget				m_ServerPing;
	protected ImageWidget				m_ServerTime;
	protected ImageWidget				m_ServerLock;
	protected ImageWidget				m_ServerModIcon;
	protected ImageWidget				m_ServerMaKIcon;
	
	//Detailed info
	protected TextWidget				m_ServerShard;
	protected TextWidget				m_ServerCharacterAlive;
	protected TextWidget				m_ServerFriends;
	protected TextWidget				m_ServerMode;
	protected TextWidget				m_ServerBattleye;
	protected TextWidget				m_ServerIP;
	protected TextWidget				m_ServerAcceleration;
	protected TextWidget				m_ServerMap;
	protected TextWidget				m_ServerMods;
	protected ButtonWidget				m_ServerModsExpand;
	protected ref array<string>			m_Mods;
	
	protected bool						m_IsExpanded;
	protected bool						m_IsFavorited;
	protected bool						m_IsOnline;
	
	protected ref GetServersResultRow	m_ServerData;
	protected int						m_Index;
	protected ServerBrowserTab			m_Tab;
	protected bool						m_Selected;
	protected bool						m_FirstExpand = true;
	
	void ServerBrowserEntry( Widget parent, int index, ServerBrowserTab tab )
	{		
		#ifdef PLATFORM_CONSOLE
			m_Root				= GetGame().GetWorkspace().CreateWidgets( "gui/layouts/new_ui/server_browser/xbox/server_browser_list_entry.layout", parent );
		#else
			m_Root				= GetGame().GetWorkspace().CreateWidgets( "gui/layouts/new_ui/server_browser/pc/server_browser_list_entry_pages.layout", parent );
		#endif
		
		m_Root.Enable( true );
		m_Favorite				= m_Root.FindAnyWidget( "favorite_button" );
		m_Expand				= m_Root.FindAnyWidget( "expand_button" );
		m_ServerName			= TextWidget.Cast( m_Root.FindAnyWidget( "server_name" ) );
		m_ServerPopulation		= TextWidget.Cast( m_Root.FindAnyWidget( "server_population" ) );
		m_ServerSlots			= TextWidget.Cast( m_Root.FindAnyWidget( "server_slots" ) );
		m_ServerPing			= TextWidget.Cast( m_Root.FindAnyWidget( "server_ping" ) );
		m_ServerTime			= ImageWidget.Cast( m_Root.FindAnyWidget( "server_time" ) );
		m_ServerLock			= ImageWidget.Cast( m_Root.FindAnyWidget( "lock_icon" ) );
		m_ServerModIcon			= ImageWidget.Cast( m_Root.FindAnyWidget( "modded_icon" ) );
		m_ServerMaKIcon			= ImageWidget.Cast( m_Root.FindAnyWidget( "mandk_icon" ) );
		
		m_ServerShard			= TextWidget.Cast( m_Root.FindAnyWidget( "shard_text" ) );
		m_ServerCharacterAlive	= TextWidget.Cast( m_Root.FindAnyWidget( "character_alive_text" ) );
		m_ServerFriends			= TextWidget.Cast( m_Root.FindAnyWidget( "steam_friends_text" ) );
		m_ServerMode			= TextWidget.Cast( m_Root.FindAnyWidget( "mode_text" ) );
		m_ServerBattleye		= TextWidget.Cast( m_Root.FindAnyWidget( "battlleye_text" ) );
		m_ServerIP				= TextWidget.Cast( m_Root.FindAnyWidget( "ip_text" ) );
		m_ServerAcceleration	= TextWidget.Cast( m_Root.FindAnyWidget( "server_acceleration_text" ) );
		m_ServerMap				= TextWidget.Cast( m_Root.FindAnyWidget( "map_text" ) );
		m_ServerMods			= TextWidget.Cast( m_Root.FindAnyWidget( "mods_text" ) );
		m_ServerModsExpand		= ButtonWidget.Cast( m_Root.FindAnyWidget( "mods_expand" ) );
		
		m_Root.FindAnyWidget( "basic_info" ).Show( true );
		m_Root.FindAnyWidget( "favorite_image" ).Update();
		m_Root.FindAnyWidget( "unfavorite_image" ).Update();
		
		m_Index					= index;
		m_Tab					= tab;
		m_IsOnline              = true;
		
		m_ServerTime.LoadImageFile( 0, "set:dayz_gui image:icon_sun" );
		m_ServerTime.LoadImageFile( 1, "set:dayz_gui image:icon_sun_accel" );
		m_ServerTime.LoadImageFile( 2, "set:dayz_gui image:icon_moon" );
		m_ServerTime.LoadImageFile( 3, "set:dayz_gui image:icon_moon_accel" );
		
		m_Root.SetHandler( this );
	}
	
	void ~ServerBrowserEntry()
	{
		delete m_Root;
	}
	
	Widget GetRoot()
	{
		return m_Root;
	}
	
	void Show(bool show)
	{
		m_Root.Show( show );
	}
	
	override bool OnClick( Widget w, int x, int y, int button )
	{
		if (!IsOnline())
		{
			return false;
		}
		
		#ifdef PLATFORM_CONSOLE
		if ( w == m_Root	)
		{
			m_Tab.Connect( this );
			return true;
		}
		#endif

		if ( w == m_ServerModsExpand )
		{
			string mods_text;
			if ( m_Mods && m_Mods.Count() > 0 )
			{
				mods_text = m_Mods[0];
				for ( int i = 1; i < m_Mods.Count(); i++ )
				{
					mods_text += "\n" + m_Mods[i];
				}
			}

			GetGame().GetUIManager().ShowDialog( "#main_menu_mods", mods_text, 0, 0, 0, 0, GetGame().GetUIManager().GetMenu() );
		}

		return false;
	}
	
	override bool OnDoubleClick( Widget w, int x, int y, int button )
	{
		if (!IsOnline())
		{
			return false;
		}
		
		if ( button == MouseState.LEFT )
		{
			if ( w == m_Root )
			{
				m_Tab.Connect( this );
				return true;
			}
		}

		return false;
	}
	
	override bool OnMouseButtonUp( Widget w, int x, int y, int button )
	{
		if ( button == MouseState.LEFT )
		{
			if ( w == m_Favorite )
			{
				ToggleFavorite();
				return true;
			}
			else if ( w == m_Expand )
			{
				ToggleExpand();
				return true;
			}
			else if ( w == m_Root )
			{
				Darken(w, x, y);
				Select();
				SetFocus( m_Root );
				return true;
			}
		}
		return false;
	}
	
	override bool OnMouseEnter( Widget w, int x, int y )
	{
		if ( IsFocusable( w ) )
		{
			Preview( w, x, y );
			return true;
		}

		return false;
	}
	
	override bool OnMouseLeave( Widget w, Widget enterW, int x, int y )
	{
		if ( IsFocusable( w ) && !IsFocusable( enterW ) )
		{
			Lighten( w, enterW, x, y );
			return true;
		}

		return false;
	}
	
	void Focus()
	{
		SetFocus( m_Root );
	}
	
	void ServerListFocus( bool focus )
	{
		m_Tab.ServerListFocus( focus, m_IsFavorited );
	}
	
	override bool OnFocus( Widget w, int x, int y )
	{
		if ( !m_Selected )
		{
			if ( IsFocusable( w ) )
				Darken( w, x, y );

			#ifdef PLATFORM_CONSOLE
			if ( w == m_Root )
			{
				Select();
				ServerListFocus( true );
			}
			#endif

			return true;
		}
		return false;
	}
	
	override bool OnFocusLost( Widget w, int x, int y )
	{
		#ifdef PLATFORM_CONSOLE

		if ( w == m_Root )
		{
			Deselect();
			ServerListFocus( false );
		}
		#endif
		
		if ( IsFocusable( w ) )
		{
			Lighten( w, null, x, y );
		}
		
		return true;
		return false;
	}
	
	bool IsOnline()
	{
		return m_IsOnline;
	}
	
	bool IsFocusable( Widget w )
	{
		if ( w )
			return ( w == m_Root || w == m_Favorite || w == m_Expand || w == m_ServerModsExpand );

		return false;
	}
	
	void FillInfo( GetServersResultRow server_info )
	{	
		m_ServerData = server_info;
		m_FirstExpand = true;
		
#ifndef PLATFORM_CONSOLE
		m_Root.FindAnyWidget( "detailed_info" ).Show( server_info.m_IsExpanded );
#endif
		
		SetName( server_info.m_Name );
		SetPasswordLocked( server_info.m_IsPasswordProtected );
		SetPopulationEx( server_info );
		SetSlots( server_info.m_MaxPlayers );
		SetPing( server_info.m_Ping );
		SetTime( server_info.m_TimeOfDay, server_info.m_EnvironmentTimeMul );
		SetFavorite( server_info.m_Favorite );
		SetModded( server_info.m_Modded );
		SetMapName( server_info.m_MapNameToRun );
		
		#ifdef PLATFORM_CONSOLE
		SetMouseAndKeyboard( server_info.m_MouseAndKeyboardEnabled );
		#endif
		
#ifdef PLATFORM_WINDOWS
#ifndef PLATFORM_CONSOLE
		SetExpand( server_info.m_IsExpanded );
		
		int pp = 0; // private
		if ( server_info.m_ShardId.Length() == 3 && server_info.m_ShardId.ToInt() < 200 )
		{
			pp = 1;	// official
		}
		
		SetShard( pp );
		SetCharacterAlive( server_info.m_CharactersAlive );
		SetFriends( server_info.m_SteamFriends );
		SetMode( server_info.m_Disable3rdPerson );
		SetBattleye( server_info.m_AntiCheat );
		SetIP( server_info.m_Id );
		SetAcceleration( server_info.m_EnvironmentTimeMul );
		SetServerMapName();
#endif
#endif
	}
	
	void UpdateEntry()
	{
		if (m_ServerData.m_IsSelected)
		{
			Darken(m_Root, 0, 0);
			Select();
			SetFocus( m_Root );
		}
		else
		{
			Lighten(m_Root, null, 0, 0);
		}
	}
	
	void SetName( string name )
	{
		m_ServerName.SetText( name );
	}
	
	void SetPasswordLocked( bool locked )
	{
		m_ServerLock.Show( locked );
	}
	
	// DEPRECATED
	void SetPopulation( int population, int slots )
	{
		int color = ARGBF(1, 1, 1, 1);
		string pop_text = population.ToString() + "/" + slots.ToString();
		
		if ( slots > 0 )
		{
			float pop_percentage = population / slots;

			if (pop_percentage >= 1)
				color	= ARGBF( 1, 1, 0, 0 );
			else if ( pop_percentage >= 0.8 )
				color	= ARGBF( 1, 1, 0.5, 0 );
		}

		m_ServerPopulation.SetText(pop_text);
		m_ServerPopulation.SetColor(color);
		m_ServerPopulation.SetBold(true);
		m_ServerPopulation.SetOutline(1);
		
	}
	
	private void SetPopulationEx(GetServersResultRow serverInfo)
	{		
		string popText = "";
		int population = serverInfo.m_CurrentNumberPlayers;
		int maxPlayers = serverInfo.m_MaxPlayers;
		int playersInQueue = serverInfo.m_PlayersInQueue;
		
		if (IsOnline())
		{
			// sometimes servers report a queue size even though server isn't full,
			// in which case we ignore queue size
			if (playersInQueue > 0 && population == maxPlayers)
			{
				popText = population.ToString() + "+" + playersInQueue.ToString() + "/" + maxPlayers.ToString();
			}
			else
			{
				popText = population.ToString() + "/" + maxPlayers.ToString();
			}
		}
		
		else
		{
			popText = "-";
		}

		m_ServerPopulation.SetText(popText);
	}
	
	void SetSlots( int slots )
	{
		if (IsOnline())
		{
			m_ServerSlots.SetText( slots.ToString() );
		}
		else
		{
			m_ServerSlots.SetText("-");
		}
	}
	
	void SetPing( int ping )
	{
		int color;
		string displayValue;
		
		if ( ping < 50 )
			color	= ARGBF( 1, 0, 1, 0 );
		else if( ping < 100 )
			color	= ARGBF( 1, 0.8, 0.8, 0 );
		else if( ping < 200 )
			color	= ARGBF( 1, 1, 0.5, 0 );
		else
			color	= ARGBF( 1, 1, 0, 0 );
		
		if (IsOnline())
		{
			displayValue = ping.ToString();
		}
		
		else
		{
			displayValue = "-";
		}
		
		m_ServerPing.SetColor( color );
		m_ServerPing.SetText( displayValue );
	}
	
	void SetTime( string time, float multiplier )
	{
		if ( time != "" )
		{
			TStringArray arr	= new TStringArray;
			
			time.Split( ":", arr );
			
			if ( arr.Count() == 2 )
			{
				int hour		= arr.Get( 0 ).ToInt();
				int minute		= arr.Get( 1 ).ToInt();
				
				if ( hour >= 19 || hour <= 5 )	//Night
				{
					if ( multiplier > 1 )
						m_ServerTime.SetImage( 3 );
					else
						m_ServerTime.SetImage( 2 );
				}
				else							//Day
				{
					if ( multiplier > 1 )
						m_ServerTime.SetImage( 1 );
					else
						m_ServerTime.SetImage( 0 );
				}
			}
		}
	}
	
	void SetShard( int shard )
	{
		string text;
		switch ( shard )
		{
			case 0:
			{
				text = "#server_browser_entry_private";
				break;
			}
			case 1:
			{
				text = "#server_browser_entry_official";
				break;
			}
		}
		m_ServerShard.SetText( text );
	}
	
	void SetMapName( string mapName )
	{
		RefreshDLCIcon();
	}
	
	void RefreshDLCIcon()
	{
		if ( m_ServerData.m_IsDLC )
		{
			bool own = GetGame().VerifyWorldOwnership( GetMapToRun() );
			m_ServerModIcon.Show( true );
			m_ServerModIcon.FindWidget( "Owned" ).Show( own );
			m_ServerModIcon.FindWidget( "Unowned" ).Show( !own );
		}
		else
		{
			m_ServerModIcon.FindWidget( "Owned" ).Show( false );
			m_ServerModIcon.FindWidget( "Unowned" ).Show( false );
		}
	}
	
	void SetCharacterAlive( string char_alive )
	{
		if ( char_alive == "")
			m_ServerCharacterAlive.SetText( "#STR_server_browser_char_not_alive" );
		else
			m_ServerCharacterAlive.SetText( char_alive );
	}
	
	void SetFriends( string friends_text )
	{
		m_ServerFriends.SetText( friends_text );
	}
	
	void SetMode( int mode )
	{
		string text;
		switch ( mode )
		{
			case 0:
			{
				text = "#server_browser_entry_person_both";
				break;
			}
			case 1:
			{
				text = "#server_browser_entry_person_first";
				break;
			}
		}
		m_ServerMode.SetText( text );
	}
	
	void SetBattleye( bool battleye )
	{
		if ( battleye )
		{
			m_ServerBattleye.SetText( "#server_browser_entry_enabled" );
			m_ServerBattleye.SetColor( ARGBF( 1, 0, 1, 0 ) );
		}
		else
		{
			m_ServerBattleye.SetText( "#server_browser_entry_disabled" );
			m_ServerBattleye.SetColor( ARGBF( 1, 1, 0, 0 ) );
		}
	}
	
	void SetIP( string ip )
	{
		m_ServerIP.SetText( ip );
	}
	
	string GetIP()
	{
		return m_ServerData.GetIP();
	}
	
	int GetPort()
	{
		return m_ServerData.m_HostPort;
	}
	
	string GetServerID()
	{
		return m_ServerData.m_Id;
	}
	
	string GetMapToRun()
	{
		return m_ServerData.m_MapNameToRun;
	}
	
	string GetMapName()
	{
		string map_name = m_ServerData.m_MapNameToRun;
		map_name.ToLower();

		if ( map_name == "enoch" )
			return "Livonia";
		if ( map_name == "chernarusplus" )
			return "Chernarus";

		return m_ServerData.m_MapNameToRun;
	}
	
	void SetFavorite( bool favorite )
	{
		m_IsFavorited = favorite;
		m_Root.FindAnyWidget( "favorite_image" ).Show( favorite );
		m_Root.FindAnyWidget( "unfavorite_image" ).Show( !favorite );		
	}
	
	void SetAcceleration( float mult )
	{
		if ( mult > 1 )
		{
			m_ServerAcceleration.Show( true );
			m_ServerAcceleration.SetText( mult.ToString() + "x" );
		}
		else
		{
			m_ServerAcceleration.Show( false );
		}
	}
	
	void SetModded( bool is_modded )
	{
		m_ServerModIcon.Show( is_modded );
	}

	void SetServerMapName()
	{
		m_ServerMap.SetText( GetMapName()  );
	}
		
	void SetMods( array<string> mods )
	{
		m_Mods = mods;

		//string mods_text = "#STR_USRACT_MAP" + ": " + GetMapName() + " | ";
		if ( mods && mods.Count() > 0 )
		{
			string mods_text = mods[0];
			for ( int i = 1; i < mods.Count(); i++ )
				mods_text += ", " + mods[i];
	
			m_ServerMods.SetText( mods_text );
		}

		#ifdef PLATFORM_WINDOWS
			m_ServerModsExpand.Show( ( mods && mods.Count() > 0 ) );
		#endif
	}
	
	void SetMouseAndKeyboard( bool is_mkenabled )
	{
		m_ServerMaKIcon.Show( is_mkenabled );
	}
	
	void SetIsOnline(bool isOnline)
	{
		m_IsOnline = isOnline;
	}
	
	bool ToggleFavorite()
	{
		m_IsFavorited = !m_IsFavorited;
		string ip = m_ServerData.GetIP();
#ifdef PLATFORM_WINDOWS	
		//Save Data PC
		m_Tab.GetRootMenu().AddFavorite(ip, m_ServerData.m_SteamQueryPort, m_IsFavorited);
	
	#ifdef PLATFORM_CONSOLE
		OnlineServices.SetServerFavorited(ip, 0, m_ServerData.m_SteamQueryPort, m_IsFavorited);
	#else
		OnlineServices.SetServerFavorited(ip, m_ServerData.m_HostPort, m_ServerData.m_SteamQueryPort, m_IsFavorited);
	#endif
#else
		//Save Data Console		
		m_IsFavorited = m_Tab.GetRootMenu().SetFavoriteConsoles(ip, m_ServerData.m_HostPort, m_IsFavorited);
#endif
		
		m_Root.FindAnyWidget( "unfavorite_image" ).Show( !m_IsFavorited );
		m_Root.FindAnyWidget( "favorite_image" ).Show( m_IsFavorited );
		
		return m_IsFavorited;
	}
	
	bool ToggleExpand()
	{
		return SetExpand(!m_IsExpanded);
	}
	
	bool SetExpand(bool expand)
	{
		m_IsExpanded = expand;
		m_Root.FindAnyWidget( "collapse_image" ).Show( m_IsExpanded );
		m_Root.FindAnyWidget( "expand_image" ).Show( !m_IsExpanded );
		m_Root.FindAnyWidget( "detailed_info" ).Show( m_IsExpanded );
		
		if ( m_ServerData )
		{
			m_ServerData.m_IsExpanded = m_IsExpanded;
		}
		
		if ( expand && m_FirstExpand )
		{
			if ( m_ServerData.m_Modded )
				OnlineServices.GetServerModList( m_ServerData.m_Id );
/*
			else
				m_ServerMods.SetText( "#STR_USRACT_MAP" + ": " + GetMapName() );
*/

			m_FirstExpand = false;
		}
		
		return m_IsExpanded;
	}
	
	void Select( bool notify = true )
	{
		if ( !m_Selected )
		{
			if ( notify )
			{
				m_Tab.SelectServer( this );
			}
			
			m_ServerData.m_IsSelected = true;
			
			m_Selected = true;
			#ifdef PLATFROM_XBOX
				m_Root.SetColor( ARGB( 1, 50, 50, 50 ) );
			#endif
		}
	}
	
	void Deselect()
	{
		if ( m_Selected )
		{
			m_ServerData.m_IsSelected = false;		
			m_Selected = false;
			
			Lighten( m_Root, null, 0, 0 );
		}
	}
	
	void UpdateColors()
	{
		float alpha = 1;
		int maxPlayers = m_ServerData.m_MaxPlayers;
		int whiteColor = ARGBF(1, 1, 1, 1);
		int populationColor = whiteColor;
		int populationOutline = 1;
		
		if (IsOnline())
		{	
			if ( maxPlayers > 0 )
			{
				int population = m_ServerData.m_CurrentNumberPlayers;
				float pop_percentage = population / maxPlayers;
	
				if (pop_percentage >= 1)
				{
					populationColor	= ARGBF( 1, 1, 0, 0 );
				}
				else if ( pop_percentage >= 0.8 )
				{
					populationColor	= ARGBF( 1, 1, 0.5, 0 );
				}
			}
		}
		
		else
		{
			alpha = 0.5;
			populationOutline = 0;
						
			m_ServerPing.SetColor(whiteColor);
		}
		
		m_ServerTime.Show(IsOnline());
		m_ServerName.SetColor(whiteColor);
		m_ServerName.SetAlpha(alpha);
		m_ServerPopulation.SetBold(IsOnline());
		m_ServerPopulation.SetColor(populationColor);
		m_ServerPopulation.SetOutline(populationOutline);
		m_ServerPopulation.SetAlpha(alpha);
		m_ServerSlots.SetAlpha(alpha);
		m_ServerPing.SetAlpha(alpha);
		m_Root.SetAlpha(alpha);
		
#ifndef PLATFORM_CONSOLE
		m_Expand.Show(IsOnline());
#endif
	}
	
	//Coloring functions (Until WidgetStyles are useful)
	void Preview( Widget w, int x, int y )
	{		
		if ( m_Selected )
			return;
		
		if ( w == m_Root || w == m_Favorite || w == m_Expand )
		{
			m_Root.SetColor( ARGB( 255, 0, 0, 0) );
			m_Root.SetAlpha( 1 );
			UpdateColors();
			
			m_ServerName.SetColor( ARGB( 255, 255, 0, 0 ) );
			if (!IsOnline())
			{
				m_ServerName.SetAlpha(0.5);
			}
		}
	}
	
	//Coloring functions (Until WidgetStyles are useful)
	void Darken( Widget w, int x, int y )
	{
		if ( m_Selected )
			return;
		
		if ( w == m_Root || w == m_Favorite || w == m_Expand )
		{
			m_Root.SetColor( ARGB( 255, 200, 0, 0) );
			SetPopulationEx(m_ServerData);
			UpdateColors();
		}
	}
	
	void Lighten( Widget w, Widget enterW, int x, int y )
	{
		float alpha = 0.3;
		
		if ( GetFocus() == w || m_Selected )
		{
			return;
		}
		
		if ( w == m_Root && ( ( m_Favorite && enterW == m_Favorite ) || ( m_Expand && enterW == m_Expand ) ) )
		{
			return;
		}

		m_Root.SetColor( ARGB( 255, 0, 0, 0) );			
		SetPopulationEx(m_ServerData);
		UpdateColors();
		
		if ( m_Index % 2 )
		{
			alpha = 0;
		}
		
		m_Root.SetAlpha( alpha );
	}
}