From 35c470be75fe9c80ae2f54ec8fe1b062f4df76b1 Mon Sep 17 00:00:00 2001 From: Ingo Ruhnke Date: Sun, 11 Apr 2004 20:28:11 +0000 Subject: [PATCH] - added contrib menu generator SVN-Revision: 491 --- src/menu.cpp | 14 ++++++-- src/menu.h | 10 ++++-- src/setup.cpp | 9 +---- src/title.cpp | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 4 files changed, 118 insertions(+), 21 deletions(-) diff --git a/src/menu.cpp b/src/menu.cpp index c70b69955..7d59a9053 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -44,6 +44,7 @@ Menu* highscore_menu = 0; Menu* load_game_menu = 0; Menu* save_game_menu = 0; Menu* contrib_menu = 0; +Menu* contrib_subset_menu = 0; Menu* current_menu = 0; @@ -70,7 +71,7 @@ Menu::set_current(Menu* pmenu) /* Return a pointer to a new menu item */ MenuItem* -MenuItem::create(MenuItemKind kind_, char *text_, int init_toggle_, Menu* target_menu_) +MenuItem::create(MenuItemKind kind_, const char *text_, int init_toggle_, Menu* target_menu_) { MenuItem *pnew_item = new MenuItem; @@ -151,9 +152,9 @@ void Menu::set_pos(int x, int y, float rw, float rh) } void -Menu::additem(MenuItemKind kind_, char *text_, int toggle_, Menu* menu_) +Menu::additem(MenuItemKind kind_, const std::string& text_, int toggle_, Menu* menu_) { - additem(MenuItem::create(kind_, text_, toggle_, menu_)); + additem(MenuItem::create(kind_, text_.c_str(), toggle_, menu_)); } /* Add an item to a menu */ @@ -164,6 +165,12 @@ Menu::additem(MenuItem* pmenu_item) delete pmenu_item; } +void +Menu::clear() +{ + item.clear(); +} + /* Process actions done on the menu */ void Menu::action() @@ -333,6 +340,7 @@ Menu::draw_item(int index, // Position of the current item in the menu int effect_offset = 0; { int effect_time = 0; + if(effect.check()) effect_time = effect.get_left() / 4; diff --git a/src/menu.h b/src/menu.h index cfecbee4d..58e09e95a 100644 --- a/src/menu.h +++ b/src/menu.h @@ -50,7 +50,7 @@ public: void change_text (const char *text); void change_input(const char *text); - static MenuItem* create(MenuItemKind kind, char *text, int init_toggle, Menu* target_menu); + static MenuItem* create(MenuItemKind kind, const char *text, int init_toggle, Menu* target_menu); }; class Menu @@ -76,8 +76,11 @@ public: ~Menu(); void additem(MenuItem* pmenu_item); - void additem(MenuItemKind kind, char *text, int init_toggle, Menu* target_menu); + void additem(MenuItemKind kind, const std::string& text, int init_toggle, Menu* target_menu); void action (); + + /** Remove all entries from the menu */ + void clear(); /** Check, if the value of the active menu item has changed. */ int check (); @@ -114,6 +117,7 @@ extern texture_type arrow_left; extern texture_type arrow_right; extern Menu* contrib_menu; +extern Menu* contrib_subset_menu; extern Menu* main_menu; extern Menu* game_menu; extern Menu* options_menu; @@ -136,5 +140,5 @@ void menu_process_current(void); #endif /*SUPERTUX_MENU_H*/ /* Local Variables: */ -/* mode:c++ */ +/* mode: c++ */ /* End */ diff --git a/src/setup.cpp b/src/setup.cpp index 589d129e8..9865bfa5a 100644 --- a/src/setup.cpp +++ b/src/setup.cpp @@ -360,6 +360,7 @@ void st_menu(void) game_menu = new Menu(); highscore_menu = new Menu(); contrib_menu = new Menu(); + contrib_subset_menu = new Menu(); main_menu->set_pos(screen->w/2, 335); main_menu->additem(MN_GOTO, "Start Game",0,load_game_menu); @@ -369,14 +370,6 @@ void st_menu(void) main_menu->additem(MN_ACTION,"Credits",0,0); main_menu->additem(MN_ACTION,"Quit",0,0); - contrib_menu->additem(MN_LABEL,"Contrib Levels",0,0); - contrib_menu->additem(MN_HL,"",0,0); - contrib_menu->additem(MN_ACTION, "Some Levelset", 0, 0); - contrib_menu->additem(MN_ACTION, "Someother Levelset", 0, 0); - contrib_menu->additem(MN_ACTION, "Yet another Levelset", 0, 0); - contrib_menu->additem(MN_HL,"",0,0); - contrib_menu->additem(MN_BACK,"Back",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); diff --git a/src/title.cpp b/src/title.cpp index 10b7c4c3a..60eaa4ef1 100644 --- a/src/title.cpp +++ b/src/title.cpp @@ -10,6 +10,7 @@ April 11, 2000 - March 15, 2004 */ +#include #include #include #include @@ -56,6 +57,94 @@ static unsigned int update_time; void display_credits(); +std::vector contrib_subsets; +std::string current_contrib_subset; + +void update_contrib_menu() +{ + // FIXME: Hack to update only once + static bool up_to_date = false; + + if (!up_to_date) + { + string_list_type level_subsets = dsubdirs("/levels", "info"); + + contrib_menu->clear(); + contrib_menu->additem(MN_LABEL,"Contrib Levels",0,0); + contrib_menu->additem(MN_HL,"",0,0); + + for (int i = 0; i < level_subsets.num_items; ++i) + { + st_subset subset; + subset.load(level_subsets.item[0]); + contrib_menu->additem(MN_GOTO, subset.title.c_str(), 0, contrib_subset_menu); + contrib_subsets.push_back(subset); + } + + contrib_menu->additem(MN_HL,"",0,0); + contrib_menu->additem(MN_BACK,"Back",0,0); + + string_list_free(&level_subsets); + up_to_date = true; + } +} + +void check_contrib_menu() +{ + static int current_subset = -1; + + int index = contrib_menu->check(); + if (index != -1) + { + index -= 2; // FIXME: Hack + if (index >= 0 && index <= int(contrib_subsets.size())) + { + if (current_subset != index) + { + current_subset = index; + // FIXME: This shouln't be busy looping + st_subset& subset = contrib_subsets[index]; + + current_contrib_subset = subset.name; + + std::cout << "Updating the contrib subset menu..." << subset.levels << std::endl; + + contrib_subset_menu->clear(); + + contrib_subset_menu->additem(MN_LABEL, subset.title, 0,0); + contrib_subset_menu->additem(MN_HL,"",0,0); + for (int i = 1; i <= subset.levels; ++i) + { + Level level; + level.load(subset.name, i); + contrib_subset_menu->additem(MN_ACTION, level.name, 0, 0); + } + contrib_subset_menu->additem(MN_HL,"",0,0); + contrib_subset_menu->additem(MN_BACK, "Back", 0, 0); + } + } + else + { + // Back button + } + } +} + +void check_contrib_subset_menu() +{ + int index = contrib_subset_menu->check(); + if (index != -1) + { + index -= 1; // FIXME: Hack + std::cout << "Sarting level: " << index << std::endl; + GameSession session(current_contrib_subset, index, ST_GL_PLAY); + session.run(); + menu_reset(); + Menu::set_current(main_menu); + show_menu = 1; + } +} + void draw_background() { /* Draw the title background: */ @@ -129,16 +218,12 @@ void draw_demo(GameSession* session, double frame_ratio) walking = false; tux->draw(); - - /* DEMO end */ } /* --- TITLE SCREEN --- */ bool title(void) { - string_list_type level_subsets; st_subset subset; - level_subsets = dsubdirs("/levels", "info"); random_timer.init(true); walking = true; @@ -241,6 +326,9 @@ bool title(void) { #if 0 case 0: + string_list_type level_subsets; + level_subsets = dsubdirs("/levels", "info"); + // Quick Play // FIXME: obsolete done = 0; @@ -324,6 +412,7 @@ bool title(void) break; case 1: // Contrib Menu + update_contrib_menu(); break; case 3: done = true; @@ -357,7 +446,11 @@ bool title(void) } else if(current_menu == contrib_menu) { - + check_contrib_menu(); + } + else if (current_menu == contrib_subset_menu) + { + check_contrib_subset_menu(); } mouse_cursor->draw(); @@ -377,8 +470,7 @@ bool title(void) texture_free(&bkg_title); texture_free(&logo); - string_list_free(&level_subsets); - + /* Return to main! */ return done; } -- 2.11.0