00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef MENU_H
00011 #define MENU_H
00012
00013
00014 #include <string>
00015 #include <vector>
00016
00017 class CMenuItem;
00018 class CEnumMenuItem;
00019 class CTextMenuItem;
00020
00021
00022 enum
00023 {
00024
00025
00026
00027 MENU_UNKNOWN,
00028 MENU_SURRENDER,
00029 MENU_SINGLE_PLAYER,
00030 MENU_EASY,
00031 MENU_MEDIUM,
00032 MENU_HARD,
00033 MENU_MULTI_PLAYER,
00034 MENU_MULTI_PLAYER_START,
00035 MENU_NUM_PLAYERS,
00036 MENU_TEAM_MODE,
00037 MENU_TEAM_SIZE,
00038 MENU_TEAM_MULTISELECT,
00039 MENU_NETWORK_GAME,
00040 MENU_SERVER,
00041 MENU_HOSTNAME,
00042 MENU_NICK,
00043 MENU_CONNECT,
00044 MENU_MORTALNET,
00045 MENU_CANCEL,
00046 MENU_OPTIONS,
00047 MENU_GAME_SPEED,
00048 MENU_GAME_TIME,
00049 MENU_TOTAL_HIT_POINTS,
00050 MENU_SOUND,
00051 MENU_CHANNELS,
00052
00053 MENU_MIXING_RATE,
00054 MENU_BITS,
00055 MENU_MUSIC_VOLUME,
00056 MENU_SOUND_VOLUME,
00057 MENU_SOUND_OK,
00058 MENU_FULLSCREEN,
00059 MENU_KEYS_RIGHT,
00060 MENU_KEYS_LEFT,
00061 MENU_OPTIONS_OK,
00062 MENU_LANGUAGE,
00063 MENU_INFO,
00064 MENU_QUIT,
00065 };
00066
00067
00068
00084 class CMenu
00085 {
00086 public:
00087 CMenu( const char* a_pcTitle );
00088 virtual ~CMenu();
00089
00090 virtual CMenuItem* AddMenuItem( const char* a_pcUtf8Text, SDLKey a_tShortcut = SDLK_UNKNOWN, int a_iCode = 0 );
00091 virtual CEnumMenuItem* AddEnumMenuItem( const char* a_pcUtf8Text, int a_iInitialValue,
00092 const char** a_ppcNames, const int* a_piValues, int a_iCode = 0 );
00093 virtual CTextMenuItem* AddTextMenuItem( const char* a_pcTitle, const char* a_pcValue, int a_iCode = 0 );
00094 virtual CMenuItem* AddMenuItem( CMenuItem* a_poItem );
00095 virtual void AddOkCancel( int a_iOkCode = 0 );
00096 virtual CMenuItem* GetMenuItem( int a_iCode ) const;
00097
00098 virtual void ItemActivated( int a_iItemCode, CMenuItem* a_poMenuItem );
00099 virtual void ItemChanged( int a_iItemCode, int a_iValue, CMenuItem* a_poMenuItem );
00100 virtual int Run();
00101
00102 virtual void Draw();
00103 virtual void Clear();
00104 virtual void EnterName( const char* a_pcTitle, std::string& a_rsTarget, CTextMenuItem* a_poMenuItem, int a_iMaxlen );
00105
00106 protected:
00107
00108 virtual void FocusNext();
00109 virtual void FocusPrev();
00110 virtual void InvokeSubmenu( CMenu* a_poSubmenu );
00111
00112 typedef std::vector<CMenuItem*> CItemList;
00113 typedef CItemList::iterator CItemIterator;
00114
00115
00116 std::string m_sTitle;
00117 CItemList m_oItems;
00118 int m_iCurrentItem;
00119 int m_iReturnCode;
00120 bool m_bDone;
00121 };
00122
00123
00130 class CMenuItem
00131 {
00132 public:
00133 CMenuItem( CMenu* a_poMenu, const char* a_pcUtf8Text, int a_iCode = -1 );
00134 virtual ~CMenuItem();
00135
00136 virtual void Draw();
00137 virtual void Clear();
00138 virtual void Activate();
00139 virtual void Increment() {};
00140 virtual void Decrement() {};
00141
00142 virtual void SetText( const char* a_pcUtf8Text, bool a_bCenter );
00143 virtual void SetPosition( const SDL_Rect& a_roPosition );
00144 virtual void SetActive( bool a_bActive );
00145 virtual void SetEnabled( bool a_bEnabled );
00146
00147 virtual bool GetEnabled() const { return m_bEnabled; }
00148 virtual int GetCode() const { return m_iCode; }
00149
00150 protected:
00151 CMenu* m_poMenu;
00152
00153
00154 std::string m_sUtf8Text;
00155 SDL_Rect m_oPosition;
00156 bool m_bCenter;
00157 Uint32 m_iHighColor;
00158 Uint32 m_iLowColor;
00159 Uint32 m_iInactiveColor;
00160 Uint32 m_iBackgroundColor;
00161
00162
00163 int m_iCode;
00164 bool m_bActive;
00165 bool m_bEnabled;
00166 };
00167
00168
00178 class CEnumMenuItem: public CMenuItem
00179 {
00180 public:
00181 CEnumMenuItem( CMenu* a_poMenu, int a_iInitialValue, const char* a_pcUtf8Text, int a_iCode = -1 );
00182 virtual ~CEnumMenuItem();
00183
00184 int GetCurrentValue();
00185 const char* GetCurrentText();
00186 virtual void Draw();
00187 virtual void Increment();
00188 virtual void Decrement();
00189
00190 virtual void SetEnumValues( const char ** a_ppcNames, const int * a_piValues );
00191 virtual void SetMaxValue( int a_iMaxValue );
00192
00193 protected:
00194 int m_iValue;
00195 int m_iMax;
00196 std::string m_sUtf8Title;
00197 const char** m_ppcNames;
00198 const int* m_piValues;
00199 };
00200
00201
00210 class CTextMenuItem: public CMenuItem
00211 {
00212 public:
00213 CTextMenuItem( CMenu* a_poMenu, const char* a_pcInitialValue, const char* a_pcUtf8Title, int a_iCode );
00214 virtual ~CTextMenuItem();
00215
00216 virtual void Draw();
00217 virtual void SetValue( const char* a_pcValue );
00218
00219 protected:
00220 std::string m_sTitle;
00221 std::string m_sValue;
00222 };
00223
00224
00225
00232 class CNetworkMenu: public CMenu
00233 {
00234 public:
00235 CNetworkMenu();
00236 virtual ~CNetworkMenu();
00237
00238 void Connect();
00239
00240 void ItemActivated( int a_iItemCode, CMenuItem* a_poMenuItem );
00241 void ItemChanged( int a_iItemCode, int a_iValue, CMenuItem* a_poMenuItem );
00242
00243 protected:
00244 bool m_bOK;
00245 bool m_bServer;
00246 std::string m_sHostname;
00247 std::string m_sNick;
00248
00249 CTextMenuItem* m_poServerMenuItem;
00250 CTextMenuItem* m_poNickMenuItem;
00251 };
00252
00253
00254
00255
00256 void DoMenu();
00257 void DoMenu( CMenu& a_roMenu );
00258
00259 #endif