From a00085c8846cd85e7c4fd004b32753a367ac684a Mon Sep 17 00:00:00 2001 From: Ingo Ruhnke Date: Wed, 24 Mar 2004 13:52:34 +0000 Subject: [PATCH] - turned menu into a class, still a lot of public variables around and menu_item isn't a class either, but its a start SVN-Revision: 330 --- src/gameloop.cpp | 22 ++-- src/high_scores.cpp | 14 +-- src/leveleditor.cpp | 251 +++++++++++++++++++++++----------------------- src/menu.cpp | 284 +++++++++++++++++++++++++++------------------------- src/menu.h | 56 +++++++---- src/setup.cpp | 150 ++++++++++++++------------- src/setup.h | 2 +- src/texture.cpp | 1 + src/timer.cpp | 11 +- src/title.cpp | 14 +-- 10 files changed, 417 insertions(+), 388 deletions(-) diff --git a/src/gameloop.cpp b/src/gameloop.cpp index 084be64a1..357b1ff89 100644 --- a/src/gameloop.cpp +++ b/src/gameloop.cpp @@ -12,6 +12,7 @@ #include #include +#include #include #include #include @@ -145,13 +146,13 @@ void game_event(void) quit = 1; else if(show_menu) { - menu_set_current(&game_menu); + Menu::set_current(game_menu); show_menu = 0; st_pause_ticks_stop(); } else { - menu_set_current(&game_menu); + Menu::set_current(game_menu); show_menu = 1; st_pause_ticks_start(); } @@ -492,7 +493,7 @@ void game_draw(void) { for (x = 0; x < 21; ++x) { - drawshape(x * 32 - ((int)scroll_x % 32), y * 32, + drawshape(32*x - fmodf(scroll_x, 32), y * 32, current_level.tiles[(int)y][(int)x + (int)(scroll_x / 32)]); } } @@ -678,18 +679,18 @@ int gameloop(const char * subset, int levelnb, int mode) if(show_menu) { - if(current_menu == &game_menu) + if(current_menu == game_menu) { - switch (menu_check(&game_menu)) + switch (game_menu->check()) { case 2: st_pause_ticks_stop(); break; case 3: - update_load_save_game_menu(&save_game_menu, false); + update_load_save_game_menu(save_game_menu, false); break; case 4: - update_load_save_game_menu(&load_game_menu, true); + update_load_save_game_menu(load_game_menu, true); break; case 7: st_pause_ticks_stop(); @@ -697,15 +698,15 @@ int gameloop(const char * subset, int levelnb, int mode) break; } } - else if(current_menu == &options_menu) + else if(current_menu == options_menu) { process_options_menu(); } - else if(current_menu == &save_game_menu ) + else if(current_menu == save_game_menu ) { process_save_load_game_menu(true); } - else if(current_menu == &load_game_menu ) + else if(current_menu == load_game_menu ) { process_save_load_game_menu(false); } @@ -1785,6 +1786,5 @@ void slotinfo(char **pinfo, int slot) *pinfo = (char*) malloc(sizeof(char) * (strlen(tmp)+1)); strcpy(*pinfo,tmp); - } diff --git a/src/high_scores.cpp b/src/high_scores.cpp index 0fc59ddad..d2e71020c 100644 --- a/src/high_scores.cpp +++ b/src/high_scores.cpp @@ -123,12 +123,12 @@ void save_hs(int score) hs_score = score; menu_reset(); - menu_set_current(&highscore_menu); + Menu::set_current(highscore_menu); - if(!highscore_menu.item[0].input) - highscore_menu.item[0].input = (char*) malloc(strlen(hs_name) + 1); + if(!highscore_menu->item[0].input) + highscore_menu->item[0].input = (char*) malloc(strlen(hs_name) + 1); - strcpy(highscore_menu.item[0].input,hs_name); + strcpy(highscore_menu->item[0].input,hs_name); /* ask for player's name */ show_menu = 1; @@ -148,11 +148,11 @@ void save_hs(int score) if(event.type == SDL_KEYDOWN) menu_event(&event.key.keysym); - switch (menu_check(&highscore_menu)) + switch (highscore_menu->check()) { case 0: - if(highscore_menu.item[0].input != NULL) - strcpy(hs_name, highscore_menu.item[0].input); + if(highscore_menu->item[0].input != NULL) + strcpy(hs_name, highscore_menu->item[0].input); break; } diff --git a/src/leveleditor.cpp b/src/leveleditor.cpp index 3cc6cc777..6bfaa37ac 100644 --- a/src/leveleditor.cpp +++ b/src/leveleditor.cpp @@ -108,11 +108,11 @@ static button_type le_fgd_bt; static button_panel_type le_bkgd_panel; static button_panel_type le_fgd_panel; static button_panel_type le_bad_panel; -static menu_type leveleditor_menu; -static menu_type subset_load_menu; -static menu_type subset_new_menu; -static menu_type subset_settings_menu; -static menu_type level_settings_menu; +static Menu* leveleditor_menu; +static Menu* subset_load_menu; +static Menu* subset_new_menu; +static Menu* subset_settings_menu; +static Menu* level_settings_menu; static square selection; static int le_selection_mode; @@ -187,9 +187,9 @@ int leveleditor(int levelnb) if(show_menu) { menu_process_current(); - if(current_menu == &leveleditor_menu) + if(current_menu == leveleditor_menu) { - switch (menu_check(&leveleditor_menu)) + switch (leveleditor_menu->check()) { case 2: show_menu = false; @@ -202,22 +202,22 @@ int leveleditor(int levelnb) break; } } - else if(current_menu == &level_settings_menu) + else if(current_menu == level_settings_menu) { - switch (menu_check(&level_settings_menu)) + switch (level_settings_menu->check()) { case 13: apply_level_settings_menu(); - menu_set_current(&leveleditor_menu); + Menu::set_current(leveleditor_menu); break; default: show_menu = true; break; } } - else if(current_menu == &subset_load_menu) + else if(current_menu == subset_load_menu) { - switch (i = menu_check(&subset_load_menu)) + switch (i = subset_load_menu->check()) { case 0: break; @@ -225,7 +225,7 @@ int leveleditor(int levelnb) if(i != -1) { le_level_subset.load(level_subsets.item[i-2]); - leveleditor_menu.item[3].kind = MN_GOTO; + leveleditor_menu->item[3].kind = MN_GOTO; le_level = 1; arrays_init(); loadshared(); @@ -244,20 +244,20 @@ int leveleditor(int levelnb) break; } } - else if(current_menu == &subset_new_menu) + else if(current_menu == subset_new_menu) { - if(subset_new_menu.item[2].input[0] == '\0') - subset_new_menu.item[3].kind = MN_DEACTIVE; + if(subset_new_menu->item[2].input[0] == '\0') + subset_new_menu->item[3].kind = MN_DEACTIVE; else { - subset_new_menu.item[3].kind = MN_ACTION; + subset_new_menu->item[3].kind = MN_ACTION; - switch (i = menu_check(&subset_new_menu)) + switch (i = subset_new_menu->check()) { case 3: - st_subset::create(subset_new_menu.item[2].input); - le_level_subset.load(subset_new_menu.item[2].input); - leveleditor_menu.item[3].kind = MN_GOTO; + st_subset::create(subset_new_menu->item[2].input); + le_level_subset.load(subset_new_menu->item[2].input); + leveleditor_menu->item[3].kind = MN_GOTO; le_level = 1; arrays_init(); loadshared(); @@ -271,20 +271,20 @@ int leveleditor(int levelnb) le_set_defaults(); level_load_gfx(le_current_level); le_activate_bad_guys(); - menu_item_change_input(&subset_new_menu.item[2],""); + menu_item_change_input(&subset_new_menu->item[2],""); show_menu = true; break; } } } - else if(current_menu == &subset_settings_menu) + else if(current_menu == subset_settings_menu) { - if(le_level_subset.title.compare(subset_settings_menu.item[2].input) == 0 && le_level_subset.description.compare(subset_settings_menu.item[3].input) == 0 ) - subset_settings_menu.item[5].kind = MN_DEACTIVE; + if(le_level_subset.title.compare(subset_settings_menu->item[2].input) == 0 && le_level_subset.description.compare(subset_settings_menu->item[3].input) == 0 ) + subset_settings_menu->item[5].kind = MN_DEACTIVE; else - subset_settings_menu.item[5].kind = MN_ACTION; + subset_settings_menu->item[5].kind = MN_ACTION; - switch (i = menu_check(&subset_settings_menu)) + switch (i = subset_settings_menu->check()) { case 5: save_subset_settings_menu(); @@ -488,64 +488,66 @@ int le_init() button_panel_additem(&le_bad_panel,button_create(filename, "Bad Guy",(SDLKey)((int)key+i),0,0),i); } - menu_init(&leveleditor_menu); - menu_additem(&leveleditor_menu, MN_LABEL,"Level Editor Menu",0,0); - menu_additem(&leveleditor_menu, MN_HL,"",0,0); - menu_additem(&leveleditor_menu, MN_ACTION,"Return To Level Editor",0,0); - menu_additem(&leveleditor_menu, MN_DEACTIVE,"Level Subset Settings",0,&subset_settings_menu); - menu_additem(&leveleditor_menu, MN_GOTO,"Load Level Subset",0,&subset_load_menu); - menu_additem(&leveleditor_menu, MN_GOTO,"New Level Subset",0,&subset_new_menu); - menu_additem(&leveleditor_menu, MN_HL,"",0,0); - menu_additem(&leveleditor_menu, MN_ACTION,"Quit Level Editor",0,0); + leveleditor_menu = new Menu(); + subset_load_menu = new Menu(); + subset_new_menu = new Menu(); + subset_settings_menu = new Menu(); + level_settings_menu = new Menu(); + + leveleditor_menu->additem(MN_LABEL,"Level Editor Menu",0,0); + leveleditor_menu->additem(MN_HL,"",0,0); + leveleditor_menu->additem(MN_ACTION,"Return To Level Editor",0,0); + leveleditor_menu->additem(MN_DEACTIVE,"Level Subset Settings",0,subset_settings_menu); + leveleditor_menu->additem(MN_GOTO,"Load Level Subset",0,subset_load_menu); + leveleditor_menu->additem(MN_GOTO,"New Level Subset",0,subset_new_menu); + leveleditor_menu->additem(MN_HL,"",0,0); + leveleditor_menu->additem(MN_ACTION,"Quit Level Editor",0,0); menu_reset(); - menu_set_current(&leveleditor_menu); + Menu::set_current(leveleditor_menu); show_menu = true; - menu_init(&subset_load_menu); - menu_additem(&subset_load_menu,MN_LABEL,"Load Level Subset",0,0); - menu_additem(&subset_load_menu,MN_HL,"",0,0); + subset_load_menu->additem(MN_LABEL, "Load Level Subset", 0, 0); + subset_load_menu->additem(MN_HL, "", 0, 0); + for(i = 0; i < level_subsets.num_items; ++i) { - menu_additem(&subset_load_menu,MN_ACTION,level_subsets.item[i],0,0); + subset_load_menu->additem(MN_ACTION,level_subsets.item[i],0,0); } - menu_additem(&subset_load_menu,MN_HL,"",0,0); - menu_additem(&subset_load_menu,MN_BACK,"Back",0,0); - - menu_init(&subset_new_menu); - menu_additem(&subset_new_menu,MN_LABEL,"New Level Subset",0,0); - menu_additem(&subset_new_menu,MN_HL,"",0,0); - menu_additem(&subset_new_menu,MN_TEXTFIELD,"Enter Name",0,0); - menu_additem(&subset_new_menu,MN_ACTION,"Create",0,0); - menu_additem(&subset_new_menu,MN_HL,"",0,0); - menu_additem(&subset_new_menu,MN_BACK,"Back",0,0); - - menu_init(&subset_settings_menu); - menu_additem(&subset_settings_menu,MN_LABEL,"Level Subset Settings",0,0); - menu_additem(&subset_settings_menu,MN_HL,"",0,0); - menu_additem(&subset_settings_menu,MN_TEXTFIELD,"Title",0,0); - menu_additem(&subset_settings_menu,MN_TEXTFIELD,"Description",0,0); - menu_additem(&subset_settings_menu,MN_HL,"",0,0); - menu_additem(&subset_settings_menu,MN_ACTION,"Save Changes",0,0); - menu_additem(&subset_settings_menu,MN_HL,"",0,0); - menu_additem(&subset_settings_menu,MN_BACK,"Back",0,0); - - menu_init(&level_settings_menu); - level_settings_menu.arrange_left = true; - menu_additem(&level_settings_menu,MN_LABEL,"Level Settings",0,0); - menu_additem(&level_settings_menu,MN_HL,"",0,0); - menu_additem(&level_settings_menu,MN_TEXTFIELD,"Name ",0,0); - menu_additem(&level_settings_menu,MN_STRINGSELECT,"Theme ",0,0); - menu_additem(&level_settings_menu,MN_STRINGSELECT,"Song ",0,0); - menu_additem(&level_settings_menu,MN_STRINGSELECT,"Bg-Image",0,0); - menu_additem(&level_settings_menu,MN_NUMFIELD,"Length ",0,0); - menu_additem(&level_settings_menu,MN_NUMFIELD,"Time ",0,0); - menu_additem(&level_settings_menu,MN_NUMFIELD,"Gravity",0,0); - menu_additem(&level_settings_menu,MN_NUMFIELD,"Red ",0,0); - menu_additem(&level_settings_menu,MN_NUMFIELD,"Green ",0,0); - menu_additem(&level_settings_menu,MN_NUMFIELD,"Blue ",0,0); - menu_additem(&level_settings_menu,MN_HL,"",0,0); - menu_additem(&level_settings_menu,MN_ACTION,"Apply Changes",0,0); + subset_load_menu->additem(MN_HL,"",0,0); + subset_load_menu->additem(MN_BACK,"Back",0,0); + + subset_new_menu->additem(MN_LABEL,"New Level Subset",0,0); + subset_new_menu->additem(MN_HL,"",0,0); + subset_new_menu->additem(MN_TEXTFIELD,"Enter Name",0,0); + subset_new_menu->additem(MN_ACTION,"Create",0,0); + subset_new_menu->additem(MN_HL,"",0,0); + subset_new_menu->additem(MN_BACK,"Back",0,0); + + subset_settings_menu->additem(MN_LABEL,"Level Subset Settings",0,0); + subset_settings_menu->additem(MN_HL,"",0,0); + subset_settings_menu->additem(MN_TEXTFIELD,"Title",0,0); + subset_settings_menu->additem(MN_TEXTFIELD,"Description",0,0); + subset_settings_menu->additem(MN_HL,"",0,0); + subset_settings_menu->additem(MN_ACTION,"Save Changes",0,0); + subset_settings_menu->additem(MN_HL,"",0,0); + subset_settings_menu->additem(MN_BACK,"Back",0,0); + + level_settings_menu->arrange_left = true; + level_settings_menu->additem(MN_LABEL,"Level Settings",0,0); + level_settings_menu->additem(MN_HL,"",0,0); + level_settings_menu->additem(MN_TEXTFIELD,"Name ",0,0); + level_settings_menu->additem(MN_STRINGSELECT,"Theme ",0,0); + level_settings_menu->additem(MN_STRINGSELECT,"Song ",0,0); + level_settings_menu->additem(MN_STRINGSELECT,"Bg-Image",0,0); + level_settings_menu->additem(MN_NUMFIELD,"Length ",0,0); + level_settings_menu->additem(MN_NUMFIELD,"Time ",0,0); + level_settings_menu->additem(MN_NUMFIELD,"Gravity",0,0); + level_settings_menu->additem(MN_NUMFIELD,"Red ",0,0); + level_settings_menu->additem(MN_NUMFIELD,"Green ",0,0); + level_settings_menu->additem(MN_NUMFIELD,"Blue ",0,0); + level_settings_menu->additem(MN_HL,"",0,0); + level_settings_menu->additem(MN_ACTION,"Apply Changes",0,0); SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); @@ -557,37 +559,37 @@ void update_level_settings_menu() char str[80]; int i; - menu_item_change_input(&level_settings_menu.item[2], le_current_level->name.c_str()); + menu_item_change_input(&level_settings_menu->item[2], le_current_level->name.c_str()); sprintf(str,"%d",le_current_level->width); - string_list_copy(level_settings_menu.item[3].list, dsubdirs("images/themes", "solid0.png")); - string_list_copy(level_settings_menu.item[4].list, dfiles("music/",NULL, "-fast")); - string_list_copy(level_settings_menu.item[5].list, dfiles("images/background",NULL, NULL)); - string_list_add_item(level_settings_menu.item[5].list,""); - if((i = string_list_find(level_settings_menu.item[3].list,le_current_level->theme.c_str())) != -1) - level_settings_menu.item[3].list->active_item = i; - if((i = string_list_find(level_settings_menu.item[4].list,le_current_level->song_title.c_str())) != -1) - level_settings_menu.item[4].list->active_item = i; - if((i = string_list_find(level_settings_menu.item[5].list,le_current_level->bkgd_image.c_str())) != -1) - level_settings_menu.item[5].list->active_item = i; - - menu_item_change_input(&level_settings_menu.item[6], str); + string_list_copy(level_settings_menu->item[3].list, dsubdirs("images/themes", "solid0.png")); + string_list_copy(level_settings_menu->item[4].list, dfiles("music/",NULL, "-fast")); + string_list_copy(level_settings_menu->item[5].list, dfiles("images/background",NULL, NULL)); + string_list_add_item(level_settings_menu->item[5].list,""); + if((i = string_list_find(level_settings_menu->item[3].list,le_current_level->theme.c_str())) != -1) + level_settings_menu->item[3].list->active_item = i; + if((i = string_list_find(level_settings_menu->item[4].list,le_current_level->song_title.c_str())) != -1) + level_settings_menu->item[4].list->active_item = i; + if((i = string_list_find(level_settings_menu->item[5].list,le_current_level->bkgd_image.c_str())) != -1) + level_settings_menu->item[5].list->active_item = i; + + menu_item_change_input(&level_settings_menu->item[6], str); sprintf(str,"%d",le_current_level->time_left); - menu_item_change_input(&level_settings_menu.item[7], str); + menu_item_change_input(&level_settings_menu->item[7], str); sprintf(str,"%2.0f",le_current_level->gravity); - menu_item_change_input(&level_settings_menu.item[8], str); + menu_item_change_input(&level_settings_menu->item[8], str); sprintf(str,"%d",le_current_level->bkgd_red); - menu_item_change_input(&level_settings_menu.item[9], str); + menu_item_change_input(&level_settings_menu->item[9], str); sprintf(str,"%d",le_current_level->bkgd_green); - menu_item_change_input(&level_settings_menu.item[10], str); + menu_item_change_input(&level_settings_menu->item[10], str); sprintf(str,"%d",le_current_level->bkgd_blue); - menu_item_change_input(&level_settings_menu.item[11], str); + menu_item_change_input(&level_settings_menu->item[11], str); } void update_subset_settings_menu() { - menu_item_change_input(&subset_settings_menu.item[2], le_level_subset.title.c_str()); - menu_item_change_input(&subset_settings_menu.item[3], le_level_subset.description.c_str()); + menu_item_change_input(&subset_settings_menu->item[2], le_level_subset.title.c_str()); + menu_item_change_input(&subset_settings_menu->item[3], le_level_subset.description.c_str()); } void apply_level_settings_menu() @@ -595,17 +597,17 @@ void apply_level_settings_menu() int i,y,j; i = false; - le_current_level->name = level_settings_menu.item[2].input; + le_current_level->name = level_settings_menu->item[2].input; - if(le_current_level->bkgd_image.compare(string_list_active(level_settings_menu.item[5].list)) != 0) + if(le_current_level->bkgd_image.compare(string_list_active(level_settings_menu->item[5].list)) != 0) { - le_current_level->bkgd_image = string_list_active(level_settings_menu.item[5].list); + le_current_level->bkgd_image = string_list_active(level_settings_menu->item[5].list); i = true; } - if(le_current_level->theme.compare(string_list_active(level_settings_menu.item[3].list)) != 0) + if(le_current_level->theme.compare(string_list_active(level_settings_menu->item[3].list)) != 0) { - le_current_level->theme = string_list_active(level_settings_menu.item[3].list); + le_current_level->theme = string_list_active(level_settings_menu->item[3].list); le_update_buttons(le_current_level->theme.c_str()); i = true; } @@ -616,10 +618,10 @@ void apply_level_settings_menu() level_load_gfx(le_current_level); } - le_current_level->song_title = string_list_active(level_settings_menu.item[4].list); + le_current_level->song_title = string_list_active(level_settings_menu->item[4].list); i = le_current_level->width; - le_current_level->width = atoi(level_settings_menu.item[6].input); + le_current_level->width = atoi(level_settings_menu->item[6].input); if(le_current_level->width < i) { if(le_current_level->width < 21) @@ -640,17 +642,17 @@ void apply_level_settings_menu() le_current_level->tiles[y][le_current_level->width] = (unsigned int) '\0'; } } - le_current_level->time_left = atoi(level_settings_menu.item[7].input); - le_current_level->gravity = atof(level_settings_menu.item[8].input); - le_current_level->bkgd_red = atoi(level_settings_menu.item[9].input); - le_current_level->bkgd_green = atoi(level_settings_menu.item[10].input); - le_current_level->bkgd_blue = atoi(level_settings_menu.item[11].input); + le_current_level->time_left = atoi(level_settings_menu->item[7].input); + le_current_level->gravity = atof(level_settings_menu->item[8].input); + le_current_level->bkgd_red = atoi(level_settings_menu->item[9].input); + le_current_level->bkgd_green = atoi(level_settings_menu->item[10].input); + le_current_level->bkgd_blue = atoi(level_settings_menu->item[11].input); } void save_subset_settings_menu() { - le_level_subset.title = subset_settings_menu.item[2].input; - le_level_subset.description = subset_settings_menu.item[3].input; + le_level_subset.title = subset_settings_menu->item[2].input; + le_level_subset.description = subset_settings_menu->item[3].input; le_level_subset.save(); } @@ -688,11 +690,11 @@ void le_quit(void) SDL_EnableKeyRepeat(0, 0); // disables key repeating texture_free(&le_selection); - menu_free(&leveleditor_menu); - menu_free(&subset_load_menu); - menu_free(&subset_new_menu); - menu_free(&subset_settings_menu); - menu_free(&level_settings_menu); + delete leveleditor_menu; + delete subset_load_menu; + delete subset_new_menu; + delete subset_settings_menu; + delete level_settings_menu; button_panel_free(&le_bkgd_panel); button_panel_free(&le_fgd_panel); button_panel_free(&le_bad_panel); @@ -836,7 +838,8 @@ void le_drawlevel() for (y = 0; y < 15; ++y) for (x = 0; x < 20; ++x) { - drawshape(x * 32 - ((int)pos_x % 32), y * 32, le_current_level->tiles[y][x + (int)(pos_x / 32)]); + drawshape(x * 32 - ((int)pos_x % 32), y * 32, + le_current_level->tiles[y][x + (int)(pos_x / 32)]); /* draw whats inside stuff when cursor is selecting those */ /* (draw them all the time - is this the right behaviour?) */ @@ -902,7 +905,7 @@ void le_checkevents() if(key == SDLK_ESCAPE) { show_menu = false; - menu_set_current(&leveleditor_menu); + Menu::set_current(leveleditor_menu); } break; } @@ -1138,12 +1141,12 @@ void le_checkevents() if(show_menu == false) { update_level_settings_menu(); - menu_set_current(&level_settings_menu); + Menu::set_current(level_settings_menu); show_menu = true; } else { - menu_set_current(&leveleditor_menu); + Menu::set_current(leveleditor_menu); show_menu = false; } } @@ -1229,12 +1232,12 @@ void le_checkevents() if(show_menu == false) { update_level_settings_menu(); - menu_set_current(&level_settings_menu); + Menu::set_current(level_settings_menu); show_menu = true; } else { - menu_set_current(&leveleditor_menu); + Menu::set_current(leveleditor_menu); show_menu = false; } } @@ -1395,7 +1398,7 @@ void le_testlevel() { level_save(le_current_level,"test",le_level); gameloop("test",le_level, ST_GL_TEST); - menu_set_current(&leveleditor_menu); + Menu::set_current(leveleditor_menu); arrays_init(); level_load_gfx(le_current_level); loadshared(); diff --git a/src/menu.cpp b/src/menu.cpp index 27182469b..9b9aec62d 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -36,27 +36,35 @@ bool show_menu; bool menu_change; texture_type checkbox, checkbox_checked, back, arrow_left, arrow_right; -menu_type main_menu, game_menu, options_menu, highscore_menu, load_game_menu, save_game_menu; -menu_type* current_menu, * last_menu; +Menu* main_menu = 0; +Menu* game_menu = 0; +Menu* options_menu = 0; +Menu* highscore_menu = 0; +Menu* load_game_menu = 0; +Menu* save_game_menu = 0; + +Menu* current_menu = 0; +Menu* last_menu = 0; /* input implementation variables */ int delete_character; char mn_input_char; /* Set the current menu */ -void menu_set_current(menu_type* pmenu) +void +Menu::set_current(Menu* pmenu) { if(pmenu != current_menu) { - menu_change = true; - last_menu = current_menu; + menu_change = true; + last_menu = current_menu; current_menu = pmenu; timer_start(&pmenu->effect, 500); } } /* Return a pointer to a new menu item */ -menu_item_type* menu_item_create(MenuItemKind kind, char *text, int init_toggle, void* target_menu) +menu_item_type* menu_item_create(MenuItemKind kind, char *text, int init_toggle, Menu* target_menu) { menu_item_type *pnew_item = (menu_item_type*) malloc(sizeof(menu_item_type)); pnew_item->kind = kind; @@ -99,118 +107,133 @@ void menu_item_change_input(menu_item_type* pmenu_item,const char *text) } /* Free a menu and all its items */ -void menu_free(menu_type* pmenu) +Menu::~Menu() { - int i; - if(pmenu->num_items != 0 && pmenu->item != NULL) + if(num_items != 0 && item != NULL) { - for(i = 0; i < pmenu->num_items; ++i) + for(int i = 0; i < num_items; ++i) { - free(pmenu->item[i].text); - free(pmenu->item[i].input); - string_list_free(pmenu->item[i].list); + free(item[i].text); + free(item[i].input); + string_list_free(item[i].list); } - free(pmenu->item); + free(item); } } -/* Initialize a menu */ -void menu_init(menu_type* pmenu) +Menu::Menu() +{ + pos_x = screen->w/2; + pos_y = screen->h/2; + arrange_left = 0; + num_items = 0; + active_item = 0; + item = NULL; + timer_init(&effect,false); +} + +menu_item_type* +Menu::additem(MenuItemKind kind, char *text, int toggle, Menu* menu) { - pmenu->x = screen->w/2; - pmenu->y = screen->h/2; - pmenu->arrange_left = 0; - pmenu->num_items = 0; - pmenu->active_item = 0; - pmenu->item = NULL; - timer_init(&pmenu->effect,false); + additem(menu_item_create(kind, text, toggle, menu)); } /* Add an item to a menu */ -void menu_additem(menu_type* pmenu, menu_item_type* pmenu_item) +void +Menu::additem(menu_item_type* pmenu_item) { - ++pmenu->num_items; - pmenu->item = (menu_item_type*)realloc(pmenu->item, sizeof(menu_item_type) * pmenu->num_items); - memcpy(&pmenu->item[pmenu->num_items-1],pmenu_item,sizeof(menu_item_type)); + ++num_items; + item = (menu_item_type*)realloc(item, sizeof(menu_item_type) * num_items); + memcpy(&item[num_items-1],pmenu_item,sizeof(menu_item_type)); free(pmenu_item); } /* Process actions done on the menu */ -void menu_action(menu_type* pmenu) +void +Menu::action() { - menu_item_type& item = pmenu->item[pmenu->active_item]; - - if(pmenu->num_items != 0 && pmenu->item != NULL) + if(num_items != 0 && item != NULL) { switch(menuaction) { case MENU_ACTION_UP: - if(pmenu->active_item > 0) - --pmenu->active_item; + if (active_item > 0) + --active_item; else - pmenu->active_item = pmenu->num_items-1; + active_item = num_items-1; break; case MENU_ACTION_DOWN: - if(pmenu->active_item < pmenu->num_items-1) - ++pmenu->active_item; + if(active_item < num_items-1) + ++active_item; else - pmenu->active_item = 0; + active_item = 0; break; case MENU_ACTION_LEFT: - if(item.kind == MN_STRINGSELECT - && item.list->num_items != 0) + if(item[active_item].kind == MN_STRINGSELECT + && item[active_item].list->num_items != 0) { - if(item.list->active_item > 0) - --item.list->active_item; + if(item[active_item].list->active_item > 0) + --item[active_item].list->active_item; else - item.list->active_item = item.list->num_items-1; + item[active_item].list->active_item = item[active_item].list->num_items-1; } break; case MENU_ACTION_RIGHT: - if(item.kind == MN_STRINGSELECT - && item.list->num_items != 0) + if(item[active_item].kind == MN_STRINGSELECT + && item[active_item].list->num_items != 0) { - if(item.list->active_item < item.list->num_items-1) - ++item.list->active_item; + if(item[active_item].list->active_item < item[active_item].list->num_items-1) + ++item[active_item].list->active_item; else - item.list->active_item = 0; + item[active_item].list->active_item = 0; } break; case MENU_ACTION_HIT: - if(item.kind == MN_GOTO - && item.target_menu != NULL) - menu_set_current((menu_type*)item.target_menu); - - else if(item.kind == MN_TOGGLE) - { - item.toggled = !item.toggled; - menu_change = true; - } - else if(item.kind == MN_ACTION || item.kind == MN_TEXTFIELD || item.kind == MN_NUMFIELD) - { - item.toggled = true; - } - else if(item.kind == MN_BACK) - { - if(last_menu != NULL) - menu_set_current(last_menu); - } + { + switch (item[active_item].kind) + { + case MN_GOTO: + if (item[active_item].target_menu != NULL) + Menu::set_current(item[active_item].target_menu); + else + puts("NULLL"); + break; + + case MN_TOGGLE: + item[active_item].toggled = !item[active_item].toggled; + menu_change = true; + break; + + case MN_ACTION: + case MN_TEXTFIELD: + case MN_NUMFIELD: + item[active_item].toggled = true; + break; + + case MN_BACK: + if(last_menu != NULL) + Menu::set_current(last_menu); + break; + default: + break; + } + } break; case MENU_ACTION_REMOVE: - if(item.kind == MN_TEXTFIELD - || item.kind == MN_NUMFIELD) + if(item[active_item].kind == MN_TEXTFIELD + || item[active_item].kind == MN_NUMFIELD) { - if(item.input != NULL) + if(item[active_item].input != NULL) { - int i = strlen(item.input); + int i = strlen(item[active_item].input); while(delete_character > 0) /* remove charactes */ { - item.input[i-1] = '\0'; + item[active_item].input[i-1] = '\0'; delete_character--; } } @@ -218,21 +241,21 @@ void menu_action(menu_type* pmenu) break; case MENU_ACTION_INPUT: - if(item.kind == MN_TEXTFIELD - || (item.kind == MN_NUMFIELD && mn_input_char >= '0' && mn_input_char <= '9')) + if(item[active_item].kind == MN_TEXTFIELD + || (item[active_item].kind == MN_NUMFIELD && mn_input_char >= '0' && mn_input_char <= '9')) { - if(item.input != NULL) + if(item[active_item].input != NULL) { - int i = strlen(item.input); - item.input = (char*) realloc(item.input,sizeof(char)*(i + 2)); - item.input[i] = mn_input_char; - item.input[i+1] = '\0'; + int i = strlen(item[active_item].input); + item[active_item].input = (char*) realloc(item[active_item].input,sizeof(char)*(i + 2)); + item[active_item].input[i] = mn_input_char; + item[active_item].input[i+1] = '\0'; } else { - item.input = (char*) malloc(2*sizeof(char)); - item.input[0] = mn_input_char; - item.input[1] = '\0'; + item[active_item].input = (char*) malloc(2*sizeof(char)); + item[active_item].input[0] = mn_input_char; + item[active_item].input[1] = '\0'; } } break; @@ -242,7 +265,7 @@ void menu_action(menu_type* pmenu) } } - menu_item_type& new_item = pmenu->item[pmenu->active_item]; + menu_item_type& new_item = item[active_item]; if(new_item.kind == MN_DEACTIVE || new_item.kind == MN_LABEL || new_item.kind == MN_HL) @@ -251,27 +274,26 @@ void menu_action(menu_type* pmenu) if(menuaction != MENU_ACTION_UP && menuaction != MENU_ACTION_DOWN) menuaction = MENU_ACTION_DOWN; - if(pmenu->num_items > 1) - menu_action(pmenu); + if(num_items > 1) + action(); } } /* Check, if the value of the active menu item has changed. */ -int menu_check(menu_type* pmenu) +int +Menu::check() { - menu_item_type& item = pmenu->item[pmenu->active_item]; - - if(pmenu->num_items != 0 && pmenu->item != NULL) + if(num_items != 0 && item != NULL) { - if((item.kind == MN_ACTION || item.kind == MN_TEXTFIELD || item.kind == MN_NUMFIELD) && item.toggled == true) + if((item[active_item].kind == MN_ACTION || item[active_item].kind == MN_TEXTFIELD || item[active_item].kind == MN_NUMFIELD) && item[active_item].toggled == true) { - item.toggled = false; + item[active_item].toggled = false; show_menu = 0; - return pmenu->active_item; + return active_item; } - else if(item.kind == MN_TOGGLE || item.kind == MN_GOTO) + else if(item[active_item].kind == MN_TOGGLE || item[active_item].kind == MN_GOTO) { - return pmenu->active_item; + return active_item; } else return -1; @@ -280,36 +302,36 @@ int menu_check(menu_type* pmenu) return -1; } -void menu_draw_item(menu_type* pmenu, - int index, // Position of the current item in the menu - int menu_width, - int menu_height) +void +Menu::draw_item(int index, // Position of the current item in the menu + int menu_width, + int menu_height) { int font_width = 16; - const menu_item_type& pitem = pmenu->item[index]; + const menu_item_type& pitem = item[index]; int effect_offset = 0; { int effect_time = 0; - if(timer_check(&pmenu->effect)) - effect_time = timer_get_left(&pmenu->effect) / 4; + if(timer_check(&effect)) + effect_time = timer_get_left(&effect) / 4; effect_offset = (index % 2) ? effect_time : -effect_time; } - int x_pos = pmenu->x; - int y_pos = pmenu->y + 24*index - menu_height/2 + 12 + effect_offset; + int x_pos = pos_x; + int y_pos = pos_y + 24*index - menu_height/2 + 12 + effect_offset; int shadow_size = 2; int text_width = strlen(pitem.text) * font_width; int input_width = strlen(pitem.input) * font_width; int list_width = strlen(string_list_active(pitem.list)) * font_width; text_type* text_font = &white_text; - if(pmenu->arrange_left == true) + if(arrange_left == true) x_pos += 24 - menu_width/2 + (text_width + input_width + list_width)/2; - if(index == pmenu->active_item) + if(index == active_item) { shadow_size = 3; text_font = &blue_text; @@ -327,7 +349,7 @@ void menu_draw_item(menu_type* pmenu, case MN_HL: { - int x = pmenu->x - menu_width/2; + int x = pos_x - menu_width/2; int y = y_pos - 12 - effect_offset; /* Draw a horizontal line with a little 3d effect */ fillrect(x, y + 6, @@ -426,7 +448,8 @@ void menu_draw_item(menu_type* pmenu, } /* Draw the current menu. */ -void menu_draw(menu_type* pmenu) +void +Menu::draw() { int menu_height; int menu_width; @@ -434,28 +457,28 @@ void menu_draw(menu_type* pmenu) /* The width of the menu has to be more than the width of the text with the most characters */ menu_width = 0; - for(int i = 0; i < pmenu->num_items; ++i) + for(int i = 0; i < num_items; ++i) { - int w = strlen(pmenu->item[i].text) + (pmenu->item[i].input ? strlen(pmenu->item[i].input) + 1 : 0) + strlen(string_list_active(pmenu->item[i].list)); + int w = strlen(item[i].text) + (item[i].input ? strlen(item[i].input) + 1 : 0) + strlen(string_list_active(item[i].list)); if( w > menu_width ) { menu_width = w; - if( pmenu->item[i].kind == MN_TOGGLE) + if( item[i].kind == MN_TOGGLE) menu_width += 2; } } menu_width = menu_width * 16 + 48; - menu_height = (pmenu->num_items) * 24; + menu_height = (num_items) * 24; /* Draw a transparent background */ - fillrect(pmenu->x - menu_width/2, - pmenu->y - 24*pmenu->num_items/2, + fillrect(pos_x - menu_width/2, + pos_y - 24*num_items/2, menu_width,menu_height,150,150,150,100); - for(int i = 0; i < pmenu->num_items; ++i) + for(int i = 0; i < num_items; ++i) { - menu_draw_item(pmenu, i, menu_width, menu_height); + draw_item(i, menu_width, menu_height); } } @@ -480,8 +503,8 @@ void menu_process_current(void) if(current_menu != NULL) { - menu_action(current_menu); - menu_draw(current_menu); + current_menu->action(); + current_menu->draw(); } menuaction = MENU_ACTION_NONE; @@ -527,12 +550,12 @@ void menu_event(SDL_keysym* keysym) break; case SDLK_SPACE: if(current_menu->item[current_menu->active_item].kind == MN_TEXTFIELD) - { - menuaction = MENU_ACTION_INPUT; - menu_change = true; - mn_input_char = ' '; - break; - } + { + menuaction = MENU_ACTION_INPUT; + menu_change = true; + mn_input_char = ' '; + break; + } case SDLK_RETURN: /* Menu Hit */ menuaction = MENU_ACTION_HIT; menu_change = true; @@ -560,21 +583,14 @@ void menu_event(SDL_keysym* keysym) /* FIXME: NO JOYSTICK SUPPORT */ /*#ifdef JOY_YES - else if (event.type == SDL_JOYBUTTONDOWN) - { - Joystick button: Continue: + else if (event.type == SDL_JOYBUTTONDOWN) + { + Joystick button: Continue: - done = 1; - } - #endif*/ + done = 1; + } + #endif*/ } -menu_item_type* -menu_additem(menu_type* pmenu, MenuItemKind kind, char *text, int init_toggle, void* target_menu) -{ - menu_item_type* item = menu_item_create(kind, text, init_toggle, target_menu); - menu_additem(pmenu, item); - return item; -} // EOF // diff --git a/src/menu.h b/src/menu.h index fc991a4c6..1a3669136 100644 --- a/src/menu.h +++ b/src/menu.h @@ -32,6 +32,8 @@ enum MenuItemKind { MN_HL /* horizontal line */ }; +class Menu; + struct menu_item_type { MenuItemKind kind; @@ -39,34 +41,41 @@ struct menu_item_type char *text; char *input; string_list_type* list; - void* target_menu; + Menu* target_menu; }; -menu_item_type* menu_item_create(MenuItemKind kind, char *text, int init_toggle, void* target_menu); +menu_item_type* menu_item_create(MenuItemKind kind, char *text, int init_toggle, Menu* target_menu); void menu_item_change_text (menu_item_type* pmenu_item, const char *text); void menu_item_change_input(menu_item_type* pmenu_item, const char *text); -struct menu_type +class Menu { - // center of the menu on the screen - int x; - int y; - +private: + // position of the menu (ie. center of the menu, not top/left) + int pos_x; + int pos_y; + int num_items; - int active_item; + +public: + timer_type effect; int arrange_left; + int active_item; menu_item_type *item; - timer_type effect; + + static void set_current(Menu* pmenu); + + Menu(); + ~Menu(); + + void additem(menu_item_type* pmenu_item); + void additem(MenuItemKind kind, char *text, int init_toggle, Menu* target_menu); + void action (); + int check (); + void draw (); + void draw_item(int index, int menu_width, int menu_height); }; -void menu_init (menu_type* pmenu); -void menu_free (menu_type* pmenu); -void menu_additem(menu_type* pmenu, menu_item_type* pmenu_item); -menu_item_type* menu_additem(menu_type* pmenu, MenuItemKind kind, char *text, int init_toggle, void* target_menu); -void menu_action (menu_type* pmenu); -int menu_check (menu_type* pmenu); -void menu_draw (menu_type* pmenu); -void menu_set_current(menu_type* pmenu); /* Action done on the menu */ enum MenuAction { @@ -86,8 +95,14 @@ extern bool show_menu; extern bool menu_change; extern texture_type checkbox, checkbox_checked, back, arrow_left, arrow_right; -extern menu_type main_menu, game_menu, options_menu, highscore_menu, load_game_menu, save_game_menu; -extern menu_type* current_menu, * last_menu; +extern Menu* main_menu; +extern Menu* game_menu; +extern Menu* options_menu; +extern Menu* highscore_menu; +extern Menu* load_game_menu; +extern Menu* save_game_menu; +extern Menu* current_menu; +extern Menu* last_menu; /* input implementation variables */ extern int delete_character; @@ -104,3 +119,6 @@ void menu_event(SDL_keysym* keysym); #endif /*SUPERTUX_MENU_H*/ +/* Local Variables: */ +/* mode:c++ */ +/* End */ diff --git a/src/setup.cpp b/src/setup.cpp index 54f1c7659..d1ccad6d6 100644 --- a/src/setup.cpp +++ b/src/setup.cpp @@ -319,77 +319,75 @@ void st_directory_setup(void) /* Create and setup menus. */ void st_menu(void) { - menu_init(&main_menu); - menu_additem(&main_menu, MN_LABEL,"Main Menu",0,0); - menu_additem(&main_menu, MN_HL,"",0,0); - menu_additem(&main_menu, MN_ACTION,"Start Game",0,0); - menu_additem(&main_menu, MN_GOTO,"Load Game",0,&load_game_menu); - menu_additem(&main_menu, MN_GOTO,"Options",0,&options_menu); - menu_additem(&main_menu, MN_ACTION,"Level editor",0,0); - menu_additem(&main_menu, MN_ACTION,"Credits",0,0); - menu_additem(&main_menu, MN_HL,"",0,0); - menu_additem(&main_menu, MN_ACTION,"Quit",0,0); - - menu_init(&options_menu); - menu_additem(&options_menu, MN_LABEL,"Options",0,0); - menu_additem(&options_menu, MN_HL,"",0,0); - menu_additem(&options_menu, MN_TOGGLE,"Fullscreen",use_fullscreen,0); + main_menu = new Menu(); + options_menu = new Menu(); + load_game_menu = new Menu(); + save_game_menu = new Menu(); + game_menu = new Menu(); + highscore_menu = new Menu(); + + main_menu->additem(MN_LABEL,"Main Menu",0,0); + main_menu->additem(MN_HL,"",0,0); + main_menu->additem(MN_ACTION,"Start Game",0,0); + main_menu->additem(MN_GOTO,"Load Game",0,load_game_menu); + main_menu->additem(MN_GOTO,"Options",0,options_menu); + main_menu->additem(MN_ACTION,"Level editor",0,0); + main_menu->additem(MN_ACTION,"Credits",0,0); + main_menu->additem(MN_HL,"",0,0); + main_menu->additem(MN_ACTION,"Quit",0,0); + + options_menu->additem(MN_LABEL,"Options",0,0); + options_menu->additem(MN_HL,"",0,0); + options_menu->additem(MN_TOGGLE,"Fullscreen",use_fullscreen,0); if(audio_device) { - menu_additem(&options_menu, MN_TOGGLE,"Sound ",use_sound,0); - menu_additem(&options_menu, MN_TOGGLE,"Music ",use_music,0); + options_menu->additem(MN_TOGGLE,"Sound ",use_sound,0); + options_menu->additem(MN_TOGGLE,"Music ",use_music,0); } else { - menu_additem(&options_menu, MN_DEACTIVE,"Sound ",use_sound,0); - menu_additem(&options_menu, MN_DEACTIVE,"Music ",use_music,0); + options_menu->additem(MN_DEACTIVE,"Sound ",use_sound,0); + options_menu->additem(MN_DEACTIVE,"Music ",use_music,0); } - menu_additem(&options_menu, MN_TOGGLE,"Show FPS ",show_fps,0); - menu_additem(&options_menu, MN_HL,"",0,0); - menu_additem(&options_menu, MN_BACK,"Back",0,0); - - menu_init(&load_game_menu); - menu_additem(&load_game_menu, MN_LABEL,"Load Game",0,0); - menu_additem(&load_game_menu, MN_HL,"",0,0); - menu_additem(&load_game_menu, MN_DEACTIVE,"Slot 1",0,0); - menu_additem(&load_game_menu, MN_DEACTIVE,"Slot 2",0,0); - menu_additem(&load_game_menu, MN_DEACTIVE,"Slot 3",0,0); - menu_additem(&load_game_menu, MN_DEACTIVE,"Slot 4",0,0); - menu_additem(&load_game_menu, MN_DEACTIVE,"Slot 5",0,0); - menu_additem(&load_game_menu, MN_HL,"",0,0); - menu_additem(&load_game_menu, MN_BACK,"Back",0,0); - - menu_init(&save_game_menu); - menu_additem(&save_game_menu, MN_LABEL,"Save Game",0,0); - menu_additem(&save_game_menu, MN_HL,"",0,0); - menu_additem(&save_game_menu, MN_DEACTIVE,"Slot 1",0,0); - menu_additem(&save_game_menu, MN_DEACTIVE,"Slot 2",0,0); - menu_additem(&save_game_menu, MN_DEACTIVE,"Slot 3",0,0); - menu_additem(&save_game_menu, MN_DEACTIVE,"Slot 4",0,0); - menu_additem(&save_game_menu, MN_DEACTIVE,"Slot 5",0,0); - menu_additem(&save_game_menu, MN_HL,"",0,0); - menu_additem(&save_game_menu, MN_BACK,"Back",0,0); - - menu_init(&game_menu); - menu_additem(&game_menu, MN_LABEL,"InGame Menu",0,0); - menu_additem(&game_menu, MN_HL,"",0,0); - menu_additem(&game_menu, MN_ACTION,"Return To Game",0,0); - menu_additem(&game_menu, MN_GOTO,"Save Game",0,&save_game_menu); - menu_additem(&game_menu, MN_GOTO,"Load Game",0,&load_game_menu); - menu_additem(&game_menu, MN_GOTO,"Options",0,&options_menu); - menu_additem(&game_menu, MN_HL,"",0,0); - menu_additem(&game_menu, MN_ACTION,"Quit Game",0,0); - - menu_init(&highscore_menu); - menu_additem(&highscore_menu, MN_TEXTFIELD,"Enter your name:",0,0); - + options_menu->additem(MN_TOGGLE,"Show FPS ",show_fps,0); + options_menu->additem(MN_HL,"",0,0); + options_menu->additem(MN_BACK,"Back",0,0); + + load_game_menu->additem(MN_LABEL,"Load Game",0,0); + load_game_menu->additem(MN_HL,"",0,0); + load_game_menu->additem(MN_DEACTIVE,"Slot 1",0,0); + load_game_menu->additem(MN_DEACTIVE,"Slot 2",0,0); + load_game_menu->additem(MN_DEACTIVE,"Slot 3",0,0); + load_game_menu->additem(MN_DEACTIVE,"Slot 4",0,0); + load_game_menu->additem(MN_DEACTIVE,"Slot 5",0,0); + load_game_menu->additem(MN_HL,"",0,0); + load_game_menu->additem(MN_BACK,"Back",0,0); + + save_game_menu->additem(MN_LABEL,"Save Game",0,0); + save_game_menu->additem(MN_HL,"",0,0); + save_game_menu->additem(MN_DEACTIVE,"Slot 1",0,0); + save_game_menu->additem(MN_DEACTIVE,"Slot 2",0,0); + save_game_menu->additem(MN_DEACTIVE,"Slot 3",0,0); + save_game_menu->additem(MN_DEACTIVE,"Slot 4",0,0); + save_game_menu->additem(MN_DEACTIVE,"Slot 5",0,0); + save_game_menu->additem(MN_HL,"",0,0); + save_game_menu->additem(MN_BACK,"Back",0,0); + + game_menu->additem(MN_LABEL,"InGame Menu",0,0); + game_menu->additem(MN_HL,"",0,0); + game_menu->additem(MN_ACTION,"Return To Game",0,0); + game_menu->additem(MN_GOTO,"Save Game",0,save_game_menu); + game_menu->additem(MN_GOTO,"Load Game",0,load_game_menu); + game_menu->additem(MN_GOTO,"Options",0,options_menu); + game_menu->additem(MN_HL,"",0,0); + game_menu->additem(MN_ACTION,"Quit Game",0,0); + + highscore_menu->additem(MN_TEXTFIELD,"Enter your name:",0,0); } -void update_load_save_game_menu(menu_type* pmenu, int load) +void update_load_save_game_menu(Menu* pmenu, int load) { - int i; - - for(i = 2; i < 7; ++i) + for(int i = 2; i < 7; ++i) { char *tmp; slotinfo(&tmp,i-1); @@ -405,7 +403,7 @@ void update_load_save_game_menu(menu_type* pmenu, int load) void process_save_load_game_menu(int save) { int slot; - switch (slot = menu_check(save ? &save_game_menu : &load_game_menu)) + switch (slot = (save ? save_game_menu->check() : load_game_menu->check())) { default: if(slot != -1) @@ -420,7 +418,7 @@ void process_save_load_game_menu(int save) { gameloop("default",slot - 1,ST_GL_LOAD_GAME); show_menu = true; - menu_set_current(&main_menu); + Menu::set_current(main_menu); } else loadgame(slot - 1); @@ -434,21 +432,21 @@ void process_save_load_game_menu(int save) /* Handle changes made to global settings in the options menu. */ void process_options_menu(void) { - switch (menu_check(&options_menu)) + switch (options_menu->check()) { case 2: - if(use_fullscreen != options_menu.item[2].toggled) + if(use_fullscreen != options_menu->item[2].toggled) { use_fullscreen = !use_fullscreen; st_video_setup(); } break; case 3: - if(use_sound != options_menu.item[3].toggled) + if(use_sound != options_menu->item[3].toggled) use_sound = !use_sound; break; case 4: - if(use_music != options_menu.item[4].toggled) + if(use_music != options_menu->item[4].toggled) { if(use_music == true) { @@ -469,7 +467,7 @@ void process_options_menu(void) } break; case 5: - if(show_fps != options_menu.item[5].toggled) + if(show_fps != options_menu->item[5].toggled) show_fps = !show_fps; break; } @@ -530,14 +528,12 @@ void st_general_free(void) texture_free(&arrow_right); /* Free menus */ - - menu_free(&main_menu); - menu_free(&game_menu); - menu_free(&options_menu); - menu_free(&highscore_menu); - menu_free(&save_game_menu); - menu_free(&load_game_menu); - + delete main_menu; + delete game_menu; + delete options_menu; + delete highscore_menu; + delete save_game_menu; + delete load_game_menu; } void st_video_setup(void) diff --git a/src/setup.h b/src/setup.h index 35a8b6b55..3686d3fe5 100644 --- a/src/setup.h +++ b/src/setup.h @@ -35,7 +35,7 @@ void st_menu(void); void st_abort(const std::string& reason, const std::string& details); void process_options_menu(void); void process_save_load_game_menu(int save); -void update_load_save_game_menu(menu_type* pmenu, int load); +void update_load_save_game_menu(Menu* pmenu, int load); void parseargs(int argc, char * argv[]); #endif /*SUPERTUX_SETUP_H*/ diff --git a/src/texture.cpp b/src/texture.cpp index bd0031e20..1b420ad40 100644 --- a/src/texture.cpp +++ b/src/texture.cpp @@ -74,6 +74,7 @@ void texture_load_part_gl(texture_type* ptexture, const std::string& file, int x static int power_of_two(int input) { int value = 1; + int a; while ( value < input ) { value <<= 1; diff --git a/src/timer.cpp b/src/timer.cpp index 89525ad28..a31e93f18 100644 --- a/src/timer.cpp +++ b/src/timer.cpp @@ -43,14 +43,9 @@ void st_pause_ticks_stop(void) void timer_init(timer_type* ptimer, bool st_ticks) { - ptimer->period = 0; - ptimer->time = 0; - - if(st_ticks) - ptimer->get_ticks = st_get_ticks; - else - ptimer->get_ticks = SDL_GetTicks; - + ptimer->period = 0; + ptimer->time = 0; + ptimer->get_ticks = st_ticks ? st_get_ticks : SDL_GetTicks; } void timer_start(timer_type* ptimer, unsigned int period) diff --git a/src/title.cpp b/src/title.cpp index e2799565e..73aa9d9b8 100644 --- a/src/title.cpp +++ b/src/title.cpp @@ -73,7 +73,7 @@ int title(void) /* Reset menu variables */ menu_reset(); - menu_set_current(&main_menu); + Menu::set_current(main_menu); clearscreen(0, 0, 0); updatescreen(); @@ -151,9 +151,9 @@ int title(void) if(show_menu && !quit) menu_process_current(); - if(current_menu == &main_menu) + if(current_menu == main_menu) { - switch (menu_check(&main_menu)) + switch (main_menu->check()) { case 2: done = 0; @@ -229,7 +229,7 @@ int title(void) } break; case 3: - update_load_save_game_menu(&load_game_menu, true); + update_load_save_game_menu(load_game_menu, true); break; case 5: done = 1; @@ -243,11 +243,11 @@ int title(void) break; } } - else if(current_menu == &options_menu) + else if(current_menu == options_menu) { process_options_menu(); } - else if(current_menu == &load_game_menu) + else if(current_menu == load_game_menu) { process_save_load_game_menu(false); } @@ -405,5 +405,5 @@ void display_credits() SDL_EnableKeyRepeat(0, 0); // disables key repeating show_menu = 1; - menu_set_current(&main_menu); + Menu::set_current(main_menu); } -- 2.11.0