Diffstat (limited to 'noncore/games/sfcave-sdl/menu.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/games/sfcave-sdl/menu.cpp | 41 |
1 files changed, 32 insertions, 9 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 | |||
@@ -5,13 +5,13 @@ | |||
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 | } |
@@ -112,19 +112,21 @@ Menu :: Menu( SFCave *p ) | |||
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 ); |
@@ -133,12 +135,35 @@ Menu :: Menu( SFCave *p ) | |||
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 ); |
138 | 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 ); | ||
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 | ||
@@ -212,13 +237,12 @@ void Menu :: draw( SDL_Surface *screen ) | |||
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 ); |
@@ -273,50 +297,49 @@ int Menu :: handleKeys( SDL_KeyboardEvent &key ) | |||
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 | } | 325 | } |
301 | // else | 326 | |
302 | { | ||
303 | return id; | 327 | return id; |
304 | } | ||
305 | 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; |