1 /***************************************************************************
2                           menu.h  -  description
3                              -------------------
4     begin                : Sun Aug 3 2003
5     copyright            : (C) 2003 by upi
6     email                : upi@apocalypse.rulez.org
7  ***************************************************************************/
8 
9 
10 #ifndef MENU_H
11 #define MENU_H
12 
13 
14 #include <string>
15 #include <vector>
16 
17 class MenuItem;
18 class EnumMenuItem;
19 class TextMenuItem;
20 
21 
22 enum
23 {
24 /* Master menu structure:
25 MAIN MENU
26 */
27 MENU_UNKNOWN,
28 	MENU_SURRENDER,
29 	MENU_SINGLE_PLAYER,
30 		MENU_EASY,
31 		MENU_MEDIUM,
32 		MENU_HARD,
33 	MENU_MULTI_PLAYER,
34 		MENU_MULTI_PLAYER_START,
35 		MENU_NUM_PLAYERS,		// 2-4
36 		MENU_TEAM_MODE,			// 1 vs 1, good vs evil, evil vs good, custom
37 		MENU_TEAM_SIZE,			// 2-10
38 		MENU_TEAM_MULTISELECT,	// yes / no
39 	MENU_NETWORK_GAME,
40 		MENU_SERVER,
41 		MENU_HOSTNAME,
42 		MENU_NICK,
43 		MENU_CONNECT,
44 		MENU_MORTALNET,
45 		MENU_CANCEL,
46 	MENU_OPTIONS,
47 		MENU_GAME_SPEED,
48 		MENU_GAME_TIME,			//	( :30 - 5:00 )
49 		MENU_TOTAL_HIT_POINTS,	// ( 25 - 1000 )
50 		MENU_SOUND,
51 			MENU_CHANNELS,		// MONO / STEREO
52 
53 			MENU_MIXING_RATE,	// 11kHz / 22kHz / 44.1 kHz
54 			MENU_BITS,			// 8 bit / 16 bit
55 			MENU_MUSIC_VOLUME,	// (0% - 100%)
56 			MENU_SOUND_VOLUME,	// (0% - 100%)
57 			MENU_SOUND_OK,
58 		MENU_FULLSCREEN,
59 		MENU_KEYS_RIGHT,
60 		MENU_KEYS_LEFT,
61 		MENU_OPTIONS_OK,
62 	MENU_LANGUAGE,
63 	MENU_INFO,
64 	MENU_QUIT,					// (confirm)
65 };
66 
67 
68 class Menu
69 {
70 
71 
72 public:
73 	Menu( const char* a_pcTitle );
74 	virtual ~Menu();
75 
76 	virtual MenuItem*		AddMenuItem( const char* a_pcUtf8Text, SDLKey a_tShortcut = SDLK_UNKNOWN, int a_iCode = 0 );
77 	virtual EnumMenuItem*	AddEnumMenuItem( const char* a_pcUtf8Text, int a_iInitialValue,
78 								const char** a_ppcNames, const int* a_piValues, int a_iCode = 0 );
79 	virtual TextMenuItem*	AddTextMenuItem( const char* a_pcTitle, const char* a_pcValue, int a_iCode = 0 );
80 	virtual MenuItem*		AddMenuItem( MenuItem* a_poItem );
81 	virtual void			AddOkCancel( int a_iOkCode = 0 );
82 	virtual MenuItem*		GetMenuItem( int a_iCode ) const;
83 
84 	virtual void			ItemActivated( int a_iItemCode, MenuItem* a_poMenuItem );
85 	virtual void			ItemChanged( int a_iItemCode, int a_iValue, MenuItem* a_poMenuItem );
86 	virtual int				Run();
87 
88 	virtual void			Draw();
89 	virtual void			Clear();
90 	virtual void			EnterName( const char* a_pcTitle, std::string& a_rsTarget, TextMenuItem* a_poMenuItem, int a_iMaxlen );
91 
92 protected:
93 
94 	virtual void			FocusNext();
95 	virtual void			FocusPrev();
96 	virtual void			InvokeSubmenu( Menu* a_poSubmenu );
97 
98 	typedef std::vector<MenuItem*> ItemList;
99 	typedef ItemList::iterator ItemIterator;
100 
101 
102 	std::string				m_sTitle;
103 	ItemList				m_oItems;
104 	int						m_iCurrentItem;
105 	int						m_iReturnCode;
106 	bool					m_bDone;
107 };
108 
109 
110 
111 class MenuItem
112 {
113 public:
114 	MenuItem( Menu* a_poMenu, const char* a_pcUtf8Text, int a_iCode = -1 );
115 	virtual ~MenuItem();
116 
117 	virtual void Draw();
118 	virtual void Clear();
119 	virtual void Activate();
Increment()120 	virtual void Increment() {};
Decrement()121 	virtual void Decrement() {};
122 
123 	virtual void SetText( const char* a_pcUtf8Text, bool a_bCenter );
124 	virtual void SetPosition( const SDL_Rect& a_roPosition );
125 	virtual void SetActive( bool a_bActive );
126 	virtual void SetEnabled( bool a_bEnabled );
127 
GetEnabled()128 	virtual bool GetEnabled() const { return m_bEnabled; }
GetCode()129 	virtual int  GetCode() const { return m_iCode; }
130 
131 protected:
132 	Menu*			m_poMenu;
133 
134 	// appearance
135 	std::string		m_sUtf8Text;
136 	SDL_Rect		m_oPosition;
137 	bool			m_bCenter;
138 	Uint32			m_iHighColor;
139 	Uint32			m_iLowColor;
140 	Uint32			m_iInactiveColor;
141 	Uint32			m_iBackgroundColor;
142 
143 	// data content
144 	int				m_iCode;
145 	bool			m_bActive;
146 	bool			m_bEnabled;
147 };
148 
149 
150 
151 class EnumMenuItem: public MenuItem
152 {
153 public:
154 	EnumMenuItem(  Menu* a_poMenu, int a_iInitialValue, const char* a_pcUtf8Text, int a_iCode = -1 );
155 	virtual ~EnumMenuItem();
156 
157 	int GetCurrentValue();
158 	const char* GetCurrentText();
159 	virtual void Draw();
160 	virtual void Increment();
161 	virtual void Decrement();
162 
163 	virtual void SetEnumValues( const char ** a_ppcNames, const int * a_piValues );
164 	virtual void SetMaxValue( int a_iMaxValue );
165 
166 protected:
167 	int				m_iValue;
168 	int				m_iMax;
169 	std::string		m_sUtf8Title;
170 	const char**	m_ppcNames;
171 	const int*		m_piValues;
172 };
173 
174 
175 
176 class TextMenuItem: public MenuItem
177 {
178 public:
179 	TextMenuItem( Menu* a_poMenu, const char* a_pcInitialValue, const char* a_pcUtf8Title, int a_iCode );
180 	virtual ~TextMenuItem();
181 
182 	virtual void Draw();
183 	virtual void SetValue( const char* a_pcValue );
184 
185 protected:
186 	std::string		m_sTitle;
187 	std::string		m_sValue;
188 };
189 
190 
191 
192 
193 class CNetworkMenu: public Menu
194 {
195 public:
196 	CNetworkMenu();
197 	virtual ~CNetworkMenu();
198 
199 	void Connect();
200 
201 	void ItemActivated( int a_iItemCode, MenuItem* a_poMenuItem );
202 	void ItemChanged( int a_iItemCode, int a_iValue, MenuItem* a_poMenuItem );
203 
204 protected:
205 	bool			m_bOK;
206 	bool			m_bServer;
207 	std::string		m_sHostname;
208 	std::string		m_sNick;
209 
210 	TextMenuItem*	m_poServerMenuItem;
211 	TextMenuItem*	m_poNickMenuItem;
212 };
213 
214 
215 
216 
217 void DoMenu();
218 void DoMenu( Menu& a_roMenu );
219 
220 #endif
221