1 // 2 // Cross-platform free Puyo-Puyo clone. 3 // Copyright (C) 2006, 2007 Emma's Software 4 // 5 // This program is free software; you can redistribute it and/or modify 6 // it under the terms of the GNU General Public License as published by 7 // the Free Software Foundation; either version 2 of the License, or 8 // (at your option) any later version. 9 // 10 // This program is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU General Public License for more details. 14 // 15 // You should have received a copy of the GNU General Public License 16 // along with this program; if not, write to the Free Software 17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 18 // 19 #if !defined (AMOEBAX_OPTIONS_MENU_STATE_H) 20 #define AMOEBAX_OPTIONS_MENU_STATE_H 21 22 #include "IState.h" 23 #include "IPlayer.h" 24 #include "Options.h" 25 #include "System.h" 26 27 namespace Amoebax 28 { 29 /// 30 /// \class OptionsMenuState. 31 /// \brief The options menu state. 32 /// 33 class OptionsMenuState: public IState 34 { 35 public: 36 OptionsMenuState (void); 37 virtual ~OptionsMenuState (void); 38 39 virtual void joyMotion (uint8_t joystick, uint8_t axis, 40 int16_t value); 41 virtual void joyDown (uint8_t joystick, uint8_t button); 42 virtual void joyUp (uint8_t joystick, uint8_t button); 43 #if !defined (IS_GP2X_HOST) 44 virtual void keyDown (uint32_t key); 45 virtual void keyUp (uint32_t key); 46 #endif // !IS_GP2X_HOST 47 virtual void redrawBackground (SDL_Rect *region, SDL_Surface *screen); 48 virtual void render (SDL_Surface *screen); 49 virtual void update (uint32_t elapsedTime); 50 virtual void videoModeChanged (void); 51 52 private: 53 /// 54 /// \class IOption 55 /// \brief A single menu option interface. 56 /// 57 class IOption 58 { 59 public: 60 /// 61 /// \brief Default constructor. 62 /// 63 /// \param title The option's title. 64 /// IOption(const std::string & title)65 IOption (const std::string &title): m_Title (title) { } 66 67 /// 68 /// \brief Destructor. 69 /// ~IOption(void)70 inline virtual ~IOption (void) { } 71 72 73 /// 74 /// \brief Makes the option to apply its value. 75 /// apply(void)76 virtual void apply (void) { } 77 78 /// 79 /// \brief Gets the title of the option. 80 /// 81 /// \return The option's title. 82 /// getTitle(void)83 inline const std::string &getTitle (void) { return m_Title; } 84 85 /// 86 /// \brief Actives the option. 87 /// 88 /// This is called when the option is currently 89 /// selected and the user presses the action button. 90 /// 91 /// The options that should be activated when the 92 /// action button is pressed must inherit this member 93 /// and perform its action here. 94 /// operator()95 virtual void operator() (void) { } 96 97 /// 98 /// \brief Tells if the option is selectable or not. 99 /// 100 /// \return \a true if the user can select this option, 101 /// \a false otherwise. 102 /// isSelectable(void)103 virtual bool isSelectable (void) const { return true; } 104 105 /// 106 /// \brief Selects the next option's value. 107 /// 108 /// This is called when the user pressed the 109 /// right direction button. 110 /// 111 /// The options that have multiple values should 112 /// change to the next logical value here. 113 /// next(void)114 virtual void next (void) { } 115 116 /// 117 /// \brief Selects the previous option's value. 118 /// 119 /// This is called when the user pressed the 120 /// left direction button. 121 /// 122 /// The options that have multiple values should 123 /// change the the previous logical value here. 124 /// previous(void)125 virtual void previous (void) { } 126 127 /// 128 /// \brief Renders the option and its values. 129 /// 130 /// The options that have multiple value must render 131 /// its own title plus the currently selected values 132 /// centered on the screen. 133 /// The remaining options must only to render their 134 /// only title centered on the screen. 135 /// 136 /// \param y The vertical screen position to draw the 137 /// option to. 138 /// \param font The font to use to render the title and 139 /// the value, if any. 140 /// \param screen The SDL surface to render the option to. 141 /// 142 virtual void render (uint16_t y, Font *font, SDL_Surface *screen) = 0; 143 144 private: 145 /// Option's title. 146 std::string m_Title; 147 }; 148 149 /// 150 /// \class ApplyOption. 151 /// \brief Applies all options' changes. 152 /// 153 class ApplyOption: public IOption 154 { 155 public: 156 /// 157 /// \brief Default constructor. 158 /// 159 /// \param title The option's title. 160 /// \param options The list of options to apply. 161 /// ApplyOption(const std::string & title,const std::vector<IOption * > & options)162 ApplyOption (const std::string &title, 163 const std::vector<IOption *> &options): 164 IOption (title), 165 m_Options (options) 166 { 167 } 168 virtual void operator() (void); 169 virtual void render (uint16_t y, Font *font, SDL_Surface *screen); 170 171 private: 172 /// The list of options to apply when activated. 173 const std::vector<IOption *> &m_Options; 174 }; 175 176 /// 177 /// \class BackOption. 178 /// \brief Back menu option. 179 /// 180 class BackOption: public IOption 181 { 182 public: 183 /// 184 /// \brief Default constructor. 185 /// 186 /// \param title The option's title. 187 /// BackOption(const std::string & title)188 BackOption (const std::string &title): IOption (title) { } 189 virtual void operator() (void); 190 virtual void render (uint16_t y, Font *font, SDL_Surface *screen); 191 }; 192 193 /// 194 /// \class ChangeControlKeysOption. 195 /// \brief Change Control Keys menu option. 196 /// 197 class ChangeControlKeysOption: public IOption 198 { 199 public: 200 /// 201 /// \brief Default constructor. 202 /// 203 /// \param title The option's title. 204 /// \param leftControls The left player's controls. 205 /// \param rightControls The right player's controls. 206 /// ChangeControlKeysOption(const std::string & title,Options::PlayerControls & leftControls,Options::PlayerControls & rightControls)207 ChangeControlKeysOption (const std::string &title, 208 Options::PlayerControls &leftControls, 209 Options::PlayerControls &rightControls): 210 IOption (title), 211 m_LeftControls (leftControls), 212 m_RightControls (rightControls) 213 { 214 } 215 216 virtual void operator() (void); 217 virtual void render (uint16_t y, Font *font, SDL_Surface *screen); 218 219 private: 220 /// The controls for the left player. 221 Options::PlayerControls &m_LeftControls; 222 /// The controls for the right player. 223 Options::PlayerControls &m_RightControls; 224 }; 225 226 /// 227 /// \class PlayerControlsOption. 228 /// \brief Player Controls menu option. 229 /// 230 class PlayerControlsOption: public IOption 231 { 232 public: 233 /// 234 /// <\brief Default constructor. 235 /// 236 /// \param title The option's title. 237 /// \param side The player's side. 238 /// \param controls The player's controls to modify 239 /// PlayerControlsOption(const std::string & title,IPlayer::PlayerSide side,Options::PlayerControls & controls)240 PlayerControlsOption (const std::string &title, 241 IPlayer::PlayerSide side, 242 Options::PlayerControls &controls): 243 IOption (title), 244 m_Controls (controls), 245 m_Side (side) 246 { 247 } 248 249 virtual void apply (void); 250 virtual void next (void); 251 virtual void previous (void); 252 virtual void render (uint16_t y, Font *font, SDL_Surface *screen); 253 254 private: 255 /// The player controls. 256 Options::PlayerControls &m_Controls; 257 /// The player side. 258 IPlayer::PlayerSide m_Side; 259 260 }; 261 262 /// 263 /// \class ScreenModeOption. 264 /// \brief Screen Mode menu option. 265 /// 266 class ScreenModeOption: public IOption 267 { 268 public: 269 /// 270 /// \brief Default constructor. 271 /// 272 /// \param title The option's title. 273 /// ScreenModeOption(const std::string & title)274 ScreenModeOption (const std::string &title): 275 IOption (title), 276 m_FullScreen (System::getInstance().isFullScreen()) 277 { } 278 virtual void apply (void); 279 virtual void next (void); 280 virtual void previous (void); 281 virtual void render (uint16_t y, Font *font, SDL_Surface *screen); 282 283 private: 284 /// Tells if the current selected mode if full screen. 285 bool m_FullScreen; 286 }; 287 288 /// 289 /// \class ScreenResolutionOption. 290 /// \brief Screen Resolution menu option. 291 /// 292 class ScreenResolutionOption: public IOption 293 { 294 public: 295 /// 296 /// \brief Default constructor. 297 /// 298 /// \param title The option's title. 299 /// 300 ScreenResolutionOption (const std::string &title); 301 virtual void apply (void); 302 virtual void next (void); 303 virtual void previous (void); 304 virtual void render (uint16_t y, Font *font, SDL_Surface *screen); 305 306 private: 307 /// The currently selected screen resolution. 308 std::vector<std::pair<uint16_t, uint16_t> >::iterator m_CurrentMode; 309 /// The list of available screen resolutions. 310 std::vector<std::pair<uint16_t, uint16_t> > m_Modes; 311 }; 312 313 /// 314 /// \class SpaceOption. 315 /// \brief Just a blank option to separate the back option. 316 /// 317 class SpaceOption: public IOption 318 { 319 public: 320 /// 321 /// \brief Default constructor. 322 /// SpaceOption(void)323 SpaceOption (void): 324 IOption ("") 325 { } 326 isSelectable(void)327 virtual bool isSelectable (void) const { return false; } render(uint16_t y,Font * font,SDL_Surface * screen)328 virtual void render (uint16_t y, Font *font, SDL_Surface *screen) { } 329 }; 330 331 /// 332 /// \class VolumeOption. 333 /// \brief Volume menu option. 334 /// 335 class VolumeOption: public IOption 336 { 337 public: 338 /// 339 /// \brief Default constructor. 340 /// 341 /// \param title The options' title. 342 /// VolumeOption(const std::string & title)343 VolumeOption (const std::string &title): IOption (title) { } 344 virtual void next (void); 345 virtual void previous (void); 346 virtual void render (uint16_t y, Font *font, SDL_Surface *screen); 347 }; 348 349 /// 350 /// \brief Copy constructor. 351 /// 352 /// \note This constructor is left unimplemented because we 353 /// don't want copies of OptionsMenuState objects. Don't use it. 354 /// 355 OptionsMenuState (const OptionsMenuState &); 356 357 /// 358 /// \brief Assigment operator. 359 /// 360 /// \note This operator is left unimplemented because we don't 361 /// want copied of OptionsMenuState objects. Don't use it. 362 /// 363 OptionsMenuState &operator= (const OptionsMenuState &); 364 365 void activateMenuOption (void); 366 void loadGraphicResources (void); 367 void selectBackOption (void); 368 void selectNextMenuOption (void); 369 void selectPreviousMenuOption (void); 370 371 /// Menu's background. 372 std::auto_ptr<Surface> m_Background; 373 /// Menu's font. 374 std::auto_ptr<Font> m_Font; 375 /// Menu's font selected. 376 std::auto_ptr<Font> m_FontSelected; 377 /// The left player's controls. 378 Options::PlayerControls m_LeftControls; 379 /// Menu Options. 380 std::vector<IOption *> m_MenuOptions; 381 /// The right player's controls. 382 Options::PlayerControls m_RightControls; 383 /// Current selected option. 384 std::vector<IOption *>::iterator m_SelectedOption; 385 386 }; 387 } 388 389 #endif // !AMOEABX_OPTIONS_MENU_STATE_H 390