summaryrefslogtreecommitdiff
path: root/src/game/client/components/menus.h
blob: 5ab6ea302d73b50e086eb43768250d06bc41298c (plain)
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
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
/* If you are missing that file, acquire a complete release at teeworlds.com.                */
#ifndef GAME_CLIENT_COMPONENTS_MENUS_H
#define GAME_CLIENT_COMPONENTS_MENUS_H

#include <base/vmath.h>
#include <base/tl/sorted_array.h>

#include <engine/graphics.h>
#include <engine/demo.h>
#include <engine/contacts.h>
#include <engine/serverbrowser.h>
#include <engine/config.h>

#include <game/voting.h>
#include <game/client/component.h>
#include <game/client/localization.h>
#include <game/client/ui.h>

#include "skins.h"


// component to fetch keypresses, override all other input
class CMenusKeyBinder : public CComponent
{
public:
	bool m_TakeKey;
	bool m_GotKey;
	int m_Modifier;
	IInput::CEvent m_Key;
	CMenusKeyBinder();
	virtual bool OnInput(IInput::CEvent Event);
};

class CMenus : public CComponent
{
public:
	class CUIElementBase
	{
	protected:
		static CRenderTools *m_pRenderTools;
		static CUI *m_pUI;
		static IInput *m_pInput;
		static IClient *m_pClient;
		static CConfig *m_pConfig;

	public:
		static void Init(CMenus *pMenus) { m_pRenderTools = pMenus->RenderTools(); m_pUI = pMenus->UI(); m_pInput = pMenus->Input(); m_pClient = pMenus->Client(); m_pConfig = pMenus->Config(); }
	};

	class CButtonContainer : public CUIElementBase
	{
		bool m_CleanBackground;
		float m_FadeStartTime;
	public:
		CButtonContainer(bool CleanBackground = false) : m_FadeStartTime(0.0f) { m_CleanBackground = CleanBackground; }
		float GetFade(bool Checked = false, float Seconds = 0.6f);
		bool IsCleanBackground() const { return m_CleanBackground; }
	};

private:
	typedef float (CMenus::*FDropdownCallback)(CUIRect View);

	bool DoButton_SpriteID(CButtonContainer *pBC, int ImageID, int SpriteID, bool Checked, const CUIRect *pRect, int Corners = CUIRect::CORNER_ALL, float Rounding = 5.0f, bool Fade = true);
	bool DoButton_Toggle(const void *pID, bool Checked, const CUIRect *pRect, bool Active);
	bool DoButton_Menu(CButtonContainer *pBC, const char *pText, bool Checked, const CUIRect *pRect, const char *pImageName = 0, int Corners = CUIRect::CORNER_ALL, float Rounding = 5.0f, float FontFactor = 0.0f, vec4 ColorHot = vec4(1.0f, 1.0f, 1.0f, 0.75f), bool TextFade = true);
	bool DoButton_MenuTabTop(CButtonContainer *pBC, const char *pText, bool Checked, const CUIRect *pRect, float Alpha = 1.0f, float FontAlpha = 1.0f, int Corners = CUIRect::CORNER_ALL, float Rounding = 5.0f, float FontFactor = 0.0f);

	bool DoButton_CheckBox(const void *pID, const char *pText, bool Checked, const CUIRect *pRect, bool Locked = false);

	void DoIcon(int ImageId, int SpriteId, const CUIRect *pRect, const vec4 *pColor = 0);
	bool DoButton_GridHeader(const void *pID, const char *pText, bool Checked, int Align, const CUIRect *pRect, int Corners = CUIRect::CORNER_ALL);

	float DoIndependentDropdownMenu(void *pID, const CUIRect *pRect, const char *pStr, float HeaderHeight, FDropdownCallback pfnCallback, bool *pActive);
	void DoInfoBox(const CUIRect *pRect, const char *pLable, const char *pValue);

	void DoJoystickBar(const CUIRect *pRect, float Current, float Tolerance, bool Active);
	void DoButton_KeySelect(CButtonContainer *pBC, const char *pText, const CUIRect *pRect);
	int DoKeyReader(CButtonContainer *pPC, const CUIRect *pRect, int Key, int Modifier, int *pNewModifier);

	// Scroll region : found in menus_scrollregion.cpp
	struct CScrollRegionParams
	{
		float m_ScrollbarWidth;
		float m_ScrollbarMargin;
		float m_SliderMinHeight;
		float m_ScrollUnit;
		vec4 m_ClipBgColor;
		vec4 m_ScrollbarBgColor;
		vec4 m_RailBgColor;
		vec4 m_SliderColor;
		vec4 m_SliderColorHover;
		vec4 m_SliderColorGrabbed;
		int m_Flags;

		enum {
			FLAG_CONTENT_STATIC_WIDTH = 0x1
		};

		CScrollRegionParams()
		{
			m_ScrollbarWidth = 20;
			m_ScrollbarMargin = 5;
			m_SliderMinHeight = 25;
			m_ScrollUnit = 10;
			m_ClipBgColor = vec4(0.0f, 0.0f, 0.0f, 0.25f);
			m_ScrollbarBgColor = vec4(0.0f, 0.0f, 0.0f, 0.25f);
			m_RailBgColor = vec4(1.0f, 1.0f, 1.0f, 0.25f);
			m_SliderColor = vec4(0.8f, 0.8f, 0.8f, 1.0f);
			m_SliderColorHover = vec4(1.0f, 1.0f, 1.0f, 1.0f);
			m_SliderColorGrabbed = vec4(0.9f, 0.9f, 0.9f, 1.0f);
			m_Flags = 0;
		}
	};

	/*
	Usage:
		-- Initialization --
		static CScrollRegion s_ScrollRegion;
		vec2 ScrollOffset(0, 0);
		s_ScrollRegion.Begin(&ScrollRegionRect, &ScrollOffset);
		Content = ScrollRegionRect;
		Content.y += ScrollOffset.y;

		-- "Register" your content rects --
		CUIRect Rect;
		Content.HSplitTop(SomeValue, &Rect, &Content);
		s_ScrollRegion.AddRect(Rect);

		-- [Optional] Knowing if a rect is clipped --
		s_ScrollRegion.IsRectClipped(Rect);

		-- [Optional] Scroll to a rect (to the last added rect)--
		...
		s_ScrollRegion.AddRect(Rect);
		s_ScrollRegion.ScrollHere(Option);

		-- End --
		s_ScrollRegion.End();
	*/
	// Instances of CScrollRegion must be static, as member addresses are used as UI item IDs
	class CScrollRegion : private CUIElementBase
	{
	private:
		float m_ScrollY;
		float m_ContentH;
		float m_RequestScrollY; // [0, ContentHeight]

		float m_AnimTime;
		float m_AnimInitScrollY;
		float m_AnimTargetScrollY;

		CUIRect m_ClipRect;
		CUIRect m_RailRect;
		CUIRect m_LastAddedRect; // saved for ScrollHere()
		vec2 m_SliderGrabPos; // where did user grab the slider
		vec2 m_ContentScrollOff;
		CScrollRegionParams m_Params;

	public:
		enum {
			SCROLLHERE_KEEP_IN_VIEW=0,
			SCROLLHERE_TOP,
			SCROLLHERE_BOTTOM,
		};

		CScrollRegion();
		void Begin(CUIRect* pClipRect, vec2* pOutOffset, CScrollRegionParams* pParams = 0);
		void End();
		void AddRect(CUIRect Rect);
		void ScrollHere(int Option = CScrollRegion::SCROLLHERE_KEEP_IN_VIEW);
		bool IsRectClipped(const CUIRect& Rect) const;
		bool IsScrollbarShown() const;
		bool IsAnimating() const;
	};

	// Listbox : found in menus_listbox.cpp
	struct CListboxItem
	{
		bool m_Visible;
		bool m_Selected;
		bool m_Disabled;
		CUIRect m_Rect;
	};

	// Instances of CListBox must be static, as member addresses are used as UI item IDs
	class CListBox : private CUIElementBase
	{
	private:
		CUIRect m_ListBoxView;
		float m_ListBoxRowHeight;
		int m_ListBoxItemIndex;
		int m_ListBoxSelectedIndex;
		int m_ListBoxNewSelected;
		int m_ListBoxNewSelOffset;
		int m_ListBoxUpdateScroll;
		int m_ListBoxDoneEvents;
		int m_ListBoxNumItems;
		int m_ListBoxItemsPerRow;
		bool m_ListBoxItemActivated;
		const char *m_pBottomText;
		float m_FooterHeight;
		CScrollRegion m_ScrollRegion;
		vec2 m_ScrollOffset;
		CLineInput m_FilterInput;
		char m_aFilterString[64];
		int m_BackgroundCorners;

	protected:
		CListboxItem DoNextRow();

	public:
		CListBox();

		void DoBegin(const CUIRect *pRect);
		void DoHeader(const CUIRect *pRect, const char *pTitle, float HeaderHeight = 20.0f, float Spacing = 2.0f);
		void DoSpacing(float Spacing = 20.0f);
		bool DoFilter(float FilterHeight = 20.0f, float Spacing = 2.0f);
		void DoFooter(const char *pBottomText, float FooterHeight = 20.0f); // call before DoStart to create a footer
		void DoStart(float RowHeight, int NumItems, int ItemsPerRow, int RowsPerScroll, int SelectedIndex,
					const CUIRect *pRect = 0, bool Background = true, bool *pActive = 0, int BackgroundCorners = CUIRect::CORNER_ALL);
		CListboxItem DoNextItem(const void *pID, bool Selected = false, bool *pActive = 0);
		CListboxItem DoSubheader();
		int DoEnd();
		bool FilterMatches(const char *pNeedle) const;
		bool WasItemActivated() const { return m_ListBoxItemActivated; }
		float GetScrollBarWidth() const { return m_ScrollRegion.IsScrollbarShown() ? 20 : 0; } // defined in menus_scrollregion.cpp
	};


	enum
	{
		POPUP_NONE=0,
		POPUP_MESSAGE, // generic message popup (one button)
		POPUP_CONFIRM, // generic confirmation popup (two buttons)
		POPUP_FIRST_LAUNCH,
		POPUP_CONNECTING,
		POPUP_LOADING_DEMO,
		POPUP_LANGUAGE,
		POPUP_COUNTRY,
		POPUP_RENAME_DEMO,
		POPUP_SAVE_SKIN,
		POPUP_PASSWORD,
		POPUP_QUIT,
	};

	enum
	{
		PAGE_NEWS=0,
		PAGE_GAME,
		PAGE_PLAYERS,
		PAGE_SERVER_INFO,
		PAGE_CALLVOTE,
		PAGE_INTERNET,
		PAGE_LAN,
		PAGE_DEMOS,
		PAGE_SETTINGS,
		PAGE_SYSTEM,
		PAGE_START,

		SETTINGS_GENERAL=0,
		SETTINGS_PLAYER,
		SETTINGS_TBD, // TODO: replace this removed tee page
		SETTINGS_CONTROLS,
		SETTINGS_GRAPHICS,
		SETTINGS_SOUND,

		ACTLB_NONE=0,
		ACTLB_LANG,
		ACTLB_THEME,
	};

	int m_GamePage;
	int m_Popup;
	int m_ActivePage;
	int m_MenuPage;
	int m_MenuPageOld;
	bool m_MenuActive;
	vec2 m_MousePos;
	vec2 m_PrevMousePos;
	int m_ActiveListBox;
	int m_PopupCountrySelection;
	bool m_SkinModified;
	bool m_KeyReaderWasActive;
	bool m_KeyReaderIsActive;

	// generic popups
	typedef void (CMenus::*FPopupButtonCallback)();
	void DefaultButtonCallback() { /* do nothing */ };
	enum
	{
		BUTTON_CONFIRM = 0, // confirm / yes / close / ok
		BUTTON_CANCEL, // cancel / no
		NUM_BUTTONS
	};
	char m_aPopupTitle[128];
	char m_aPopupMessage[256];
	struct
	{
		char m_aLabel[64];
		int m_NextPopup;
		FPopupButtonCallback m_pfnCallback;
	} m_aPopupButtons[NUM_BUTTONS];

	void PopupMessage(const char *pTitle, const char *pMessage,
		const char *pButtonLabel, int NextPopup = POPUP_NONE, FPopupButtonCallback pfnButtonCallback = &CMenus::DefaultButtonCallback);
	void PopupConfirm(const char *pTitle, const char *pMessage,
		const char *pConfirmButtonLabel, const char *pCancelButtonLabel,
		FPopupButtonCallback pfnConfirmButtonCallback = &CMenus::DefaultButtonCallback, int ConfirmNextPopup = POPUP_NONE,
		FPopupButtonCallback pfnCancelButtonCallback = &CMenus::DefaultButtonCallback, int CancelNextPopup = POPUP_NONE);
	void PopupCountry(int Selection, FPopupButtonCallback pfnOkButtonCallback = &CMenus::DefaultButtonCallback);

	// images
	struct CMenuImage
	{
		char m_aName[64];
		IGraphics::CTextureHandle m_OrgTexture;
		IGraphics::CTextureHandle m_GreyTexture;
	};
	array<CMenuImage> m_lMenuImages;

	static int MenuImageScan(const char *pName, int IsDir, int DirType, void *pUser);

	const CMenuImage *FindMenuImage(const char* pName);

	// themes
	class CTheme
	{
	public:
		CTheme() {}
		CTheme(const char *n, bool HasDay, bool HasNight) : m_Name(n), m_HasDay(HasDay), m_HasNight(HasNight) {}

		string m_Name;
		bool m_HasDay;
		bool m_HasNight;
		IGraphics::CTextureHandle m_IconTexture;
		bool operator<(const CTheme &Other) const { return m_Name < Other.m_Name; }
	};
	sorted_array<CTheme> m_lThemes;

	static int ThemeScan(const char *pName, int IsDir, int DirType, void *pUser);
	static int ThemeIconScan(const char *pName, int IsDir, int DirType, void *pUser);

	// gametype icons
	class CGameIcon
	{
	public:
		enum
		{
			GAMEICON_SIZE=64,
			GAMEICON_OLDHEIGHT=192,
		};
		CGameIcon() {}
		CGameIcon(const char *pName) : m_Name(pName) {}

		string m_Name;
		IGraphics::CTextureHandle m_IconTexture;
	};
	array<CGameIcon> m_lGameIcons;
	IGraphics::CTextureHandle m_GameIconDefault;
	void DoGameIcon(const char *pName, const CUIRect *pRect);
	static int GameIconScan(const char *pName, int IsDir, int DirType, void *pUser);

	int64 m_LastInput;

	static float ms_FontmodHeight;

	// for settings
	bool m_NeedRestartPlayer;
	bool m_NeedRestartGraphics;
	bool m_NeedRestartSound;
	int m_TeePartSelected;
	char m_aSaveSkinName[MAX_SKIN_ARRAY_SIZE];

	bool m_RefreshSkinSelector;
	const CSkins::CSkin *m_pSelectedSkin;

	// for map download popup
	int64 m_DownloadLastCheckTime;
	int m_DownloadLastCheckSize;
	float m_DownloadSpeed;

	// for demo loading popup
	char m_aDemoLoadingFile[IO_MAX_PATH_LENGTH];
	int m_DemoLoadingStorageType;
	bool m_DemoLoadingPopupRendered;

	// for password popup
	char m_aPasswordPopupServerAddress[256];

	// for call vote
	int m_CallvoteSelectedOption;
	int m_CallvoteSelectedPlayer;
	char m_aFilterString[VOTE_REASON_LENGTH];
	char m_aCallvoteReason[VOTE_REASON_LENGTH];

	// demo
	enum
	{
		SORT_DEMONAME=0,
		SORT_LENGTH,
		SORT_DATE,
	};

	struct CDemoItem
	{
		char m_aFilename[128];
		char m_aName[128];
		bool m_IsDir;
		int m_StorageType;
		time_t m_Date;

		bool m_InfosLoaded;
		bool m_Valid;
		CDemoHeader m_Info;

		int GetMarkerCount() const
		{
			if(!m_Valid || !m_InfosLoaded)
				return -1;
			return bytes_be_to_uint(m_Info.m_aNumTimelineMarkers);
		}

		int Length() const
		{
			return bytes_be_to_uint(m_Info.m_aLength);
		}

		bool operator<(const CDemoItem &Other) const
		{
			return !str_comp(m_aFilename, "..") ? true
				: !str_comp(Other.m_aFilename, "..") ? false
				: m_IsDir && !Other.m_IsDir ? true
				: !m_IsDir && Other.m_IsDir ? false
				: str_comp_filenames(m_aFilename, Other.m_aFilename) < 0;
		}
	};

	class CDemoComparator
	{
		int m_Type;
		int m_Order;

	public:
		CDemoComparator(int Type, int Order)
		{
			m_Type = Type;
			m_Order = Order;
		}

		bool operator()(const CDemoItem &Self, const CDemoItem &Other)
		{
			if(!str_comp(Self.m_aFilename, ".."))
				return true;
			if(!str_comp(Other.m_aFilename, ".."))
				return false;
			if(Self.m_IsDir && !Other.m_IsDir)
				return true;
			if(!Self.m_IsDir && Other.m_IsDir)
				return false;

			const CDemoItem &Left = m_Order ? Other : Self;
			const CDemoItem &Right = m_Order ? Self : Other;

			if(m_Type == SORT_DEMONAME)
				return str_comp_nocase(Left.m_aFilename, Right.m_aFilename) < 0;
			else if(m_Type == SORT_LENGTH)
				return Left.Length() < Right.Length();
			else if(m_Type == SORT_DATE)
				return Left.m_Date < Right.m_Date;
			return false;
		}
	};

	sorted_array<CDemoItem> m_lDemos;
	char m_aCurrentDemoFolder[IO_MAX_PATH_LENGTH];
	char m_aCurrentDemoFile[IO_MAX_PATH_LENGTH];
	int m_DemolistSelectedIndex;
	bool m_DemolistSelectedIsDir;
	int m_DemolistStorageType;
	int64 m_SeekBarActivatedTime;
	bool m_SeekBarActive;

	void DemolistOnUpdate(bool Reset);
	void DemolistPopulate();
	static int DemolistFetchCallback(const CFsFileInfo* pFileInfo, int IsDir, int StorageType, void *pUser);

	// friends
	class CFriendItem
	{
	public:
		const CServerInfo *m_pServerInfo;
		char m_aName[MAX_NAME_ARRAY_SIZE];
		char m_aClan[MAX_CLAN_ARRAY_SIZE];
		int m_FriendState;
		bool m_IsPlayer;

		CFriendItem()
		{
			m_pServerInfo = 0;
		}

		bool operator<(const CFriendItem &Other) const
		{
			if(m_aName[0] && !Other.m_aName[0])
				return true;
			if(!m_aName[0] && Other.m_aName[0])
				return false;
			int Result = str_comp_nocase(m_aName, Other.m_aName);
			return Result < 0 || (Result == 0 && str_comp_nocase(m_aClan, Other.m_aClan) < 0);
		}
	};

	enum
	{
		FRIEND_PLAYER_ON = 0,
		FRIEND_CLAN_ON,
		FRIEND_OFF,
		NUM_FRIEND_TYPES
	};
	sorted_array<CFriendItem> m_lFriendList[NUM_FRIEND_TYPES];
	const CFriendItem *m_pDeleteFriend;

	void FriendlistOnUpdate();


	// server browser
	class CBrowserFilter
	{
		bool m_Extended;
		int m_Custom;
		char m_aName[64];
		int m_Filter;
		IServerBrowser *m_pServerBrowser;

		static CServerFilterInfo ms_FilterStandard;
		static CServerFilterInfo ms_FilterFavorites;
		static CServerFilterInfo ms_FilterAll;

	public:
		enum
		{
			FILTER_CUSTOM=0,
			FILTER_ALL,
			FILTER_STANDARD,
			FILTER_FAVORITES,
		};

		CButtonContainer m_DeleteButtonContainer;
		CButtonContainer m_UpButtonContainer;
		CButtonContainer m_DownButtonContainer;

		CBrowserFilter() {}
		CBrowserFilter(int Custom, const char* pName, IServerBrowser *pServerBrowser);
		void Switch();
		bool Extended() const;
		int Custom() const;
		int Filter() const;
		const char* Name() const;

		void SetFilterNum(int Num);

		int NumSortedServers() const;
		int NumPlayers() const;
		const CServerInfo* SortedGet(int Index) const;
		const void* ID(int Index) const;

		void Reset();
		void GetFilter(CServerFilterInfo *pFilterInfo) const;
		void SetFilter(const CServerFilterInfo *pFilterInfo);
	};

	array<CBrowserFilter> m_lFilters;

	int m_RemoveFilterIndex;

	void LoadFilters();
	void SaveFilters();
	void RemoveFilter(int FilterIndex);
	void Move(bool Up, int Filter);
	void InitDefaultFilters();

	struct CColumn
	{
		int m_ID;
		int m_Sort;
		CLocConstString m_Caption;
		int m_Direction;
		float m_Width;
		int m_Flags;
		CUIRect m_Rect;
		CUIRect m_Spacer;
		int m_Align;
	};

	enum
	{
		COL_BROWSER_FLAG = 0,
		COL_BROWSER_NAME,
		COL_BROWSER_GAMETYPE,
		COL_BROWSER_MAP,
		COL_BROWSER_PLAYERS,
		COL_BROWSER_PING,
		NUM_BROWSER_COLS,

		COL_DEMO_NAME = 0,
		COL_DEMO_LENGTH,
		COL_DEMO_DATE,
		NUM_DEMO_COLS,

		SIDEBAR_TAB_INFO = 0,
		SIDEBAR_TAB_FILTER,
		SIDEBAR_TAB_FRIEND,
		NUM_SIDEBAR_TABS,

		ADDR_SELECTION_CHANGE = 1, // select the server based on server address input
		ADDR_SELECTION_RESET_SERVER_IF_NOT_FOUND = 2, // clear selection if ADDR_SELECTION_CHANGE did not match any server
		ADDR_SELECTION_REVEAL = 4, // scroll to the selected server
		ADDR_SELECTION_UPDATE_ADDRESS = 8, // update address input to the selected server's address
	};
	int m_SidebarTab;
	bool m_SidebarActive;
	bool m_ShowServerDetails;
	int m_LastBrowserType; // -1 if not initialized
	int m_aSelectedFilters[IServerBrowser::NUM_TYPES]; // -1 if none selected, -2 if not initialized
	int m_aSelectedServers[IServerBrowser::NUM_TYPES]; // -1 if none selected
	int m_AddressSelection;
	static CColumn ms_aBrowserCols[NUM_BROWSER_COLS];
	static CColumn ms_aDemoCols[NUM_DEMO_COLS];

	CBrowserFilter *GetSelectedBrowserFilter()
	{
		const int Tab = ServerBrowser()->GetType();
		if(m_aSelectedFilters[Tab] < 0 || m_aSelectedFilters[Tab] >= m_lFilters.size())
			return 0;
		return &m_lFilters[m_aSelectedFilters[Tab]];
	}

	const CServerInfo *GetSelectedServerInfo()
	{
		CBrowserFilter *pSelectedFilter = GetSelectedBrowserFilter();
		if(!pSelectedFilter)
			return 0;
		const int Tab = ServerBrowser()->GetType();
		if(m_aSelectedServers[Tab] < 0 || m_aSelectedServers[Tab] >= pSelectedFilter->NumSortedServers())
			return 0;
		return pSelectedFilter->SortedGet(m_aSelectedServers[Tab]);
	}

	void UpdateServerBrowserAddress();
	const char *GetServerBrowserAddress();
	void SetServerBrowserAddress(const char *pAddress);
	void ServerBrowserFilterOnUpdate();
	void ServerBrowserSortingOnUpdate();


	// video settings
	bool m_CheckVideoSettings;
	enum
	{
		MAX_RESOLUTIONS=256,
	};
	CVideoMode m_aModes[MAX_RESOLUTIONS];
	int m_NumModes;
	struct CVideoFormat
	{
		int m_WidthValue;
		int m_HeightValue;
	};
	sorted_array<CVideoMode> m_lRecommendedVideoModes;
	sorted_array<CVideoMode> m_lOtherVideoModes;
	void UpdatedFilteredVideoModes();
	void UpdateVideoModeSettings();

	// found in menus.cpp
	void RenderMenu(CUIRect Screen);
	void RenderMenubar(CUIRect r);
	void RenderNews(CUIRect MainView);
	void RenderBackButton(CUIRect MainView);
	static void ConchainUpdateMusicState(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
	void UpdateMusicState();

	// found in menus_demo.cpp
	bool FetchHeader(CDemoItem *pItem);
	void RenderDemoPlayer(CUIRect Screen);
	void RenderDemoList(CUIRect MainView);
	float RenderDemoDetails(CUIRect View);
	void PopupConfirmDeleteDemo();

	// found in menus_start.cpp
	void RenderStartMenu(CUIRect MainView);
	void RenderLogo(CUIRect MainView);

	// found in menus_ingame.cpp
	void RenderGame(CUIRect MainView);
	void RenderPlayers(CUIRect MainView);
	void RenderServerInfo(CUIRect MainView);
	void HandleCallvote(int Page, bool Force);
	void RenderServerControl(CUIRect MainView);
	void RenderServerControlKick(CUIRect MainView, bool FilterSpectators);
	bool RenderServerControlServer(CUIRect MainView);

	// found in menus_browser.cpp
	void RenderServerbrowserServerList(CUIRect View);
	void RenderServerbrowserSidebar(CUIRect View);
	void RenderServerbrowserFriendTab(CUIRect View);
	void PopupConfirmRemoveFriend();
	void RenderServerbrowserFilterTab(CUIRect View);
	void RenderServerbrowserInfoTab(CUIRect View);
	void RenderServerbrowserFriendList(CUIRect View);
	void RenderDetailInfo(CUIRect View, const CServerInfo *pInfo, const vec4 &TextColor, const vec4 &TextOutlineColor);
	void RenderDetailScoreboard(CUIRect View, const CServerInfo *pInfo, int RowCount, const vec4 &TextColor, const vec4 &TextOutlineColor);
	void RenderServerbrowserServerDetail(CUIRect View, const CServerInfo *pInfo);
	void RenderServerbrowserBottomBox(CUIRect View);
	void RenderFilterHeader(CUIRect View, int FilterIndex);
	void PopupConfirmRemoveFilter();
	void PopupConfirmCountryFilter();
	int DoBrowserEntry(const void *pID, CUIRect View, const CServerInfo *pEntry, const CBrowserFilter *pFilter, bool Selected, bool ShowServerInfo, CScrollRegion *pScroll = 0);
	void RenderServerbrowser(CUIRect MainView);
	static void ConchainConnect(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
	static void ConchainFriendlistUpdate(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
	static void ConchainServerbrowserUpdate(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
	static void ConchainServerbrowserSortingUpdate(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
	void DoFriendListEntry(CUIRect *pView, CFriendItem *pFriend, const void *pID, const CContactInfo *pFriendInfo, const CServerInfo *pServerInfo, bool Checked, bool Clan = false);
	void UpdateFriendCounter(const CServerInfo *pEntry);
	void UpdateFriends();

	// found in menus_settings.cpp
	void RenderLanguageSelection(CUIRect MainView, bool Header=true);
	void RenderThemeSelection(CUIRect MainView, bool Header=true);
	void RenderHSLPicker(CUIRect Picker);
	void RenderSkinSelection(CUIRect MainView);
	void RenderSkinPartSelection(CUIRect MainView);
	void RenderSkinPartPalette(CUIRect MainView);
	void RenderSettingsGeneral(CUIRect MainView);
	void RenderSettingsPlayer(CUIRect MainView);
	// void RenderSettingsTBD(CUIRect MainView); // TODO: change removed tee page to something else
	void RenderSettingsTeeBasic(CUIRect MainView);
	void RenderSettingsTeeCustom(CUIRect MainView);
	void PopupConfirmDeleteSkin();
	void RenderSettingsControls(CUIRect MainView);
	void RenderSettingsGraphics(CUIRect MainView);
	void RenderSettingsSound(CUIRect MainView);
	void RenderSettings(CUIRect MainView);
	void ResetSettingsGeneral();
	void ResetSettingsControls();
	void ResetSettingsGraphics();
	void ResetSettingsSound();
	void PopupConfirmPlayerCountry();

	bool DoResolutionList(CUIRect* pRect, CListBox* pListBox,
						  const sorted_array<CVideoMode>& lModes);

	// found in menus_callback.cpp
	float RenderSettingsControlsMouse(CUIRect View);
	float RenderSettingsControlsJoystick(CUIRect View);
	float RenderSettingsControlsMovement(CUIRect View);
	float RenderSettingsControlsWeapon(CUIRect View);
	float RenderSettingsControlsVoting(CUIRect View);
	float RenderSettingsControlsChat(CUIRect View);
	float RenderSettingsControlsScoreboard(CUIRect View);
	float RenderSettingsControlsStats(CUIRect View);
	float RenderSettingsControlsMisc(CUIRect View);
	void DoSettingsControlsButtons(int Start, int Stop, CUIRect View, float ButtonHeight, float Spacing);

	void DoJoystickAxisPicker(CUIRect View);

	void SetActive(bool Active);

	// loading
	int m_LoadCurrent;
	int m_LoadTotal;

	void SetMenuPage(int NewPage);

	bool CheckHotKey(int Key) const;

	void RenderBackground(float Time);
	void RenderBackgroundShadow(const CUIRect *pRect, bool TopToBottom, float Rounding = 5.0f);
public:
	void InitLoading(int TotalWorkAmount);
	void RenderLoading(int WorkedAmount = 0);
	bool IsBackgroundNeeded() const;

	struct CSwitchTeamInfo
	{
		char m_aNotification[128];
		bool m_AllowSpec;
		int m_TimeLeft;
	};
	void GetSwitchTeamInfo(CSwitchTeamInfo *pInfo);

	CMenusKeyBinder m_Binder;

	CMenus();

	bool IsActive() const { return m_MenuActive; }

	virtual int GetInitAmount() const;
	virtual void OnInit();

	virtual void OnConsoleInit();
	virtual void OnShutdown();
	virtual void OnStateChange(int NewState, int OldState);
	virtual void OnReset();
	virtual void OnRender();
	virtual bool OnInput(IInput::CEvent Event);
	virtual bool OnCursorMove(float x, float y, int CursorType);

	static void Con_Play(IConsole::IResult *pResult, void *pUserData);
};
#endif