Diffstat (limited to 'noncore/games/sfcave-sdl/menu.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/games/sfcave-sdl/menu.cpp | 43 |
1 files changed, 33 insertions, 10 deletions
diff --git a/noncore/games/sfcave-sdl/menu.cpp b/noncore/games/sfcave-sdl/menu.cpp index 0a7366f..a4a4216 100644 --- a/noncore/games/sfcave-sdl/menu.cpp +++ b/noncore/games/sfcave-sdl/menu.cpp | |||
@@ -1,23 +1,23 @@ | |||
1 | #include <SDL_image.h> | 1 | #include <SDL_image.h> |
2 | #include "SDL_rotozoom.h" | 2 | #include "SDL_rotozoom.h" |
3 | 3 | ||
4 | #include "constants.h" | 4 | #include "constants.h" |
5 | #include "sfcave.h" | 5 | #include "sfcave.h" |
6 | #include "game.h" | 6 | #include "game.h" |
7 | #include "menu.h" | 7 | #include "menu.h" |
8 | #include "font.h" | 8 | #include "font.h" |
9 | #include "starfield.h" | 9 | #include "starfield.h" |
10 | 10 | ||
11 | MenuOption :: MenuOption( QString text, int id ) | 11 | MenuOption :: MenuOption( string text, int id ) |
12 | { | 12 | { |
13 | menuText = text; | 13 | menuText = text; |
14 | menuId = id; | 14 | menuId = id; |
15 | nextMenu = 0; | 15 | nextMenu = 0; |
16 | highlighted = false; | 16 | highlighted = false; |
17 | } | 17 | } |
18 | 18 | ||
19 | MenuOption :: ~MenuOption() | 19 | MenuOption :: ~MenuOption() |
20 | { | 20 | { |
21 | } | 21 | } |
22 | 22 | ||
23 | 23 | ||
@@ -106,44 +106,69 @@ Menu :: Menu( SFCave *p ) | |||
106 | Menu *gameType = new Menu( options ); | 106 | Menu *gameType = new Menu( options ); |
107 | item = gameType->addMenuOption( "SFCave", MENU_GAME_SFCAVE ); | 107 | item = gameType->addMenuOption( "SFCave", MENU_GAME_SFCAVE ); |
108 | item->setNextMenu( options ); | 108 | item->setNextMenu( options ); |
109 | item = gameType->addMenuOption( "Gates", MENU_GAME_GATES ); | 109 | item = gameType->addMenuOption( "Gates", MENU_GAME_GATES ); |
110 | item->setNextMenu( options ); | 110 | item->setNextMenu( options ); |
111 | item = gameType->addMenuOption( "Fly", MENU_GAME_FLY ); | 111 | item = gameType->addMenuOption( "Fly", MENU_GAME_FLY ); |
112 | item->setNextMenu( options ); | 112 | item->setNextMenu( options ); |
113 | item = gameType->addMenuOption( "Back", MENU_BACK ); | 113 | item = gameType->addMenuOption( "Back", MENU_BACK ); |
114 | item->setNextMenu( options ); | 114 | item->setNextMenu( options ); |
115 | typeMenu->setNextMenu( gameType ); | 115 | typeMenu->setNextMenu( gameType ); |
116 | 116 | ||
117 | // Game Difficulty menu | 117 | // Game Difficulty menu |
118 | MenuOption *customMenu = 0; | ||
118 | Menu *gameDifficulty = new Menu( options ); | 119 | Menu *gameDifficulty = new Menu( options ); |
119 | item = gameDifficulty->addMenuOption( "Easy", MENU_DIFFICULTY_EASY ); | 120 | item = gameDifficulty->addMenuOption( "Easy", MENU_DIFFICULTY_EASY ); |
120 | item->setNextMenu( options, false ); | 121 | item->setNextMenu( options, false ); |
121 | item = gameDifficulty->addMenuOption( "Normal", MENU_DIFFICULTY_NORMAL ); | 122 | item = gameDifficulty->addMenuOption( "Normal", MENU_DIFFICULTY_NORMAL ); |
122 | item->setNextMenu( options, false ); | 123 | item->setNextMenu( options, false ); |
123 | item = gameDifficulty->addMenuOption( "Hard", MENU_DIFFICULTY_HARD ); | 124 | item = gameDifficulty->addMenuOption( "Hard", MENU_DIFFICULTY_HARD ); |
124 | item->setNextMenu( options, false ); | 125 | item->setNextMenu( options, false ); |
126 | customMenu = gameDifficulty->addMenuOption( "Custom", MENU_DIFFICULTY_CUSTOM ); | ||
125 | item = gameDifficulty->addMenuOption( "Back", MENU_BACK ); | 127 | item = gameDifficulty->addMenuOption( "Back", MENU_BACK ); |
126 | item->setNextMenu( options, false ); | 128 | item->setNextMenu( options, false ); |
127 | difficultyMenu->setNextMenu( gameDifficulty ); | 129 | difficultyMenu->setNextMenu( gameDifficulty ); |
128 | 130 | ||
129 | // Sounds Menu | 131 | // Sounds Menu |
130 | Menu *sounds = new Menu( options ); | 132 | Menu *sounds = new Menu( options ); |
131 | sounds->addMenuOption( "Sound On", MENU_SOUND_ON ); | 133 | sounds->addMenuOption( "Sound On", MENU_SOUND_ON ); |
132 | sounds->addMenuOption( "Sound Off", MENU_SOUND_OFF ); | 134 | sounds->addMenuOption( "Sound Off", MENU_SOUND_OFF ); |
133 | sounds->addMenuOption( "Music On", MENU_MUSIC_ON ); | 135 | sounds->addMenuOption( "Music On", MENU_MUSIC_ON ); |
134 | sounds->addMenuOption( "Music Off", MENU_MUSIC_OFF ); | 136 | sounds->addMenuOption( "Music Off", MENU_MUSIC_OFF ); |
135 | item = sounds->addMenuOption( "Back", MENU_BACK ); | 137 | item = sounds->addMenuOption( "Back", MENU_BACK ); |
136 | item->setNextMenu( options, false ); | 138 | item->setNextMenu( options, false ); |
137 | soundsMenu->setNextMenu( sounds ); | 139 | soundsMenu->setNextMenu( sounds ); |
140 | |||
141 | // Custom Menu | ||
142 | Menu *custom = new Menu( gameDifficulty ); | ||
143 | Menu *updown = new Menu( custom ); | ||
144 | item = custom->addMenuOption( "Thrust", MENU_CUSTOM_THRUST ); | ||
145 | item->setNextMenu( updown ); | ||
146 | item = custom->addMenuOption( "Gravity", MENU_CUSTOM_GRAVITY ); | ||
147 | item->setNextMenu( updown ); | ||
148 | item = custom->addMenuOption( "Max Speed Up", MENU_CUSTOM_MAXSPEEDUP ); | ||
149 | item->setNextMenu( updown ); | ||
150 | item = custom->addMenuOption( "Max Speed Down", MENU_CUSTOM_MAXSPEEDDOWN ); | ||
151 | item->setNextMenu( updown ); | ||
152 | item = custom->addMenuOption( "Back", MENU_BACK ); | ||
153 | item->setNextMenu( gameDifficulty, false ); | ||
154 | customMenu->setNextMenu( custom ); | ||
155 | |||
156 | // Up down menu | ||
157 | item = updown->addMenuOption( "Increase", MENU_CUSTOM_INCREASE ); | ||
158 | item = updown->addMenuOption( "Decrease", MENU_CUSTOM_DECREASE ); | ||
159 | item = updown->addMenuOption( "Save", MENU_CUSTOM_SAVE ); | ||
160 | item->setNextMenu( custom, false ); | ||
161 | item = updown->addMenuOption( "Cancel", MENU_CUSTOM_CANCEL ); | ||
162 | item->setNextMenu( custom, false ); | ||
138 | 163 | ||
139 | // Set static variables for menu selection up | 164 | // Set static variables for menu selection up |
140 | mainMenu = this; | 165 | mainMenu = this; |
141 | currentMenuOption = 0; | 166 | currentMenuOption = 0; |
142 | 167 | ||
143 | resetToTopMenu(); | 168 | resetToTopMenu(); |
144 | 169 | ||
145 | angle = 0; | 170 | angle = 0; |
146 | 171 | ||
147 | stars = new StarField; | 172 | stars = new StarField; |
148 | } | 173 | } |
149 | 174 | ||
@@ -206,25 +231,24 @@ void Menu :: draw( SDL_Surface *screen ) | |||
206 | list<MenuOption *>::iterator it; | 231 | list<MenuOption *>::iterator it; |
207 | for ( it = currentMenu->listItems.begin(); it != currentMenu->listItems.end() ; ++it ) | 232 | for ( it = currentMenu->listItems.begin(); it != currentMenu->listItems.end() ; ++it ) |
208 | { | 233 | { |
209 | y += (*it)->draw( screen, y ) + 2; | 234 | y += (*it)->draw( screen, y ) + 2; |
210 | } | 235 | } |
211 | } | 236 | } |
212 | 237 | ||
213 | int Menu :: handleKeys( SDL_KeyboardEvent &key ) | 238 | int Menu :: handleKeys( SDL_KeyboardEvent &key ) |
214 | { | 239 | { |
215 | if ( key.type != SDL_KEYDOWN ) | 240 | if ( key.type != SDL_KEYDOWN ) |
216 | return -1; | 241 | return -1; |
217 | 242 | ||
218 | statusText = ""; | ||
219 | switch( key.keysym.sym ) | 243 | switch( key.keysym.sym ) |
220 | { | 244 | { |
221 | case SDLK_DOWN: | 245 | case SDLK_DOWN: |
222 | { | 246 | { |
223 | // Move to next menu item | 247 | // Move to next menu item |
224 | currentMenu->currentMenuOption->highlight( false ); | 248 | currentMenu->currentMenuOption->highlight( false ); |
225 | 249 | ||
226 | list<MenuOption *>::iterator it; | 250 | list<MenuOption *>::iterator it; |
227 | for ( it = currentMenu->listItems.begin(); it != currentMenu->listItems.end() ; ++it ) | 251 | for ( it = currentMenu->listItems.begin(); it != currentMenu->listItems.end() ; ++it ) |
228 | { | 252 | { |
229 | if ( (*it) == currentMenu->currentMenuOption ) | 253 | if ( (*it) == currentMenu->currentMenuOption ) |
230 | { | 254 | { |
@@ -267,62 +291,61 @@ int Menu :: handleKeys( SDL_KeyboardEvent &key ) | |||
267 | if ( reachedBeginning ) | 291 | if ( reachedBeginning ) |
268 | currentMenu->currentMenuOption = currentMenu->listItems.back(); | 292 | currentMenu->currentMenuOption = currentMenu->listItems.back(); |
269 | else | 293 | else |
270 | currentMenu->currentMenuOption = *it; | 294 | currentMenu->currentMenuOption = *it; |
271 | 295 | ||
272 | currentMenu->currentMenuOption->highlight( true ); | 296 | currentMenu->currentMenuOption->highlight( true ); |
273 | 297 | ||
274 | break; | 298 | break; |
275 | } | 299 | } |
276 | case SDLK_LEFT: | 300 | case SDLK_LEFT: |
277 | if ( currentMenu->parentMenu != 0 ) | 301 | if ( currentMenu->parentMenu != 0 ) |
278 | { | 302 | { |
303 | statusText = ""; | ||
279 | currentMenu = currentMenu->parentMenu; | 304 | currentMenu = currentMenu->parentMenu; |
280 | printf( "HERE\n" ); | ||
281 | 305 | ||
282 | return -1; | 306 | return -1; |
283 | } | 307 | } |
284 | break; | 308 | break; |
285 | 309 | ||
286 | case SDLK_RETURN: | 310 | case SDLK_RETURN: |
287 | case SDLK_SPACE: | 311 | case SDLK_SPACE: |
288 | { | 312 | { |
313 | statusText = ""; | ||
289 | // select menu item | 314 | // select menu item |
290 | int id = currentMenu->currentMenuOption->getMenuId(); | 315 | int id = currentMenu->currentMenuOption->getMenuId(); |
291 | // // if the current item has a child menu then move to that menu | 316 | |
317 | // if the current item has a child menu then move to that menu | ||
292 | Menu *next = currentMenu->currentMenuOption->getNextMenu(); | 318 | Menu *next = currentMenu->currentMenuOption->getNextMenu(); |
293 | if ( next != 0 ) | 319 | if ( next != 0 ) |
294 | { | 320 | { |
295 | bool down = currentMenu->currentMenuOption->isDownMenuTree(); | 321 | bool down = currentMenu->currentMenuOption->isDownMenuTree(); |
296 | currentMenu = next; | 322 | currentMenu = next; |
297 | if ( down ) | 323 | if ( down ) |
298 | initCurrentMenu(); | 324 | initCurrentMenu(); |
299 | // return -1; | ||
300 | } | ||
301 | // else | ||
302 | { | ||
303 | return id; | ||
304 | } | 325 | } |
305 | 326 | ||
327 | return id; | ||
328 | |||
306 | break; | 329 | break; |
307 | } | 330 | } |
308 | 331 | ||
309 | default: | 332 | default: |
310 | break; | 333 | break; |
311 | } | 334 | } |
312 | 335 | ||
313 | return -1; | 336 | return -1; |
314 | } | 337 | } |
315 | 338 | ||
316 | MenuOption *Menu :: addMenuOption( QString text, int id ) | 339 | MenuOption *Menu :: addMenuOption( string text, int id ) |
317 | { | 340 | { |
318 | MenuOption *item = new MenuOption( text, id ); | 341 | MenuOption *item = new MenuOption( text, id ); |
319 | 342 | ||
320 | listItems.push_back( item ); | 343 | listItems.push_back( item ); |
321 | 344 | ||
322 | return item; | 345 | return item; |
323 | } | 346 | } |
324 | 347 | ||
325 | void Menu :: resetToTopMenu() | 348 | void Menu :: resetToTopMenu() |
326 | { | 349 | { |
327 | currentMenu = mainMenu; | 350 | currentMenu = mainMenu; |
328 | initCurrentMenu(); | 351 | initCurrentMenu(); |