Menu* load_game_menu = 0;
Menu* save_game_menu = 0;
Menu* contrib_menu = 0;
+Menu* contrib_subset_menu = 0;
Menu* current_menu = 0;
/* 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;
}
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 */
delete pmenu_item;
}
+void
+Menu::clear()
+{
+ item.clear();
+}
+
/* Process actions done on the menu */
void
Menu::action()
int effect_offset = 0;
{
int effect_time = 0;
+
if(effect.check())
effect_time = effect.get_left() / 4;
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
~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 ();
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;
#endif /*SUPERTUX_MENU_H*/
/* Local Variables: */
-/* mode:c++ */
+/* mode: c++ */
/* End */
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);
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);
April 11, 2000 - March 15, 2004
*/
+#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void display_credits();
+std::vector<st_subset> 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: */
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;
{
#if 0
case 0:
+ string_list_type level_subsets;
+ level_subsets = dsubdirs("/levels", "info");
+
// Quick Play
// FIXME: obsolete
done = 0;
break;
case 1:
// Contrib Menu
+ update_contrib_menu();
break;
case 3:
done = true;
}
else if(current_menu == contrib_menu)
{
-
+ check_contrib_menu();
+ }
+ else if (current_menu == contrib_subset_menu)
+ {
+ check_contrib_subset_menu();
}
mouse_cursor->draw();
texture_free(&bkg_title);
texture_free(&logo);
- string_list_free(&level_subsets);
-
+
/* Return to main! */
return done;
}