X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fmenu.h;h=e8baf7018bd4a46903f95e7e47fd844950d17e09;hb=9e082fc66762cb43a25955a971082a0a5aab0840;hp=92a801a15e687b794926e2c1a51df366c6cdd091;hpb=05a38383bb378e05aadad886e87f0fe64fdc6ba0;p=supertux.git diff --git a/src/menu.h b/src/menu.h index 92a801a15..e8baf7018 100644 --- a/src/menu.h +++ b/src/menu.h @@ -14,47 +14,132 @@ #define SUPERTUX_MENU_H #include +#include +#include "texture.h" +#include "timer.h" +#include "type.h" +#include "mousecursor.h" -/* (global) menu variables */ -int menuaction; -int menuitem; -int menumenu; -int show_menu; -int menu_change; +/* Kinds of menu items */ +enum MenuItemKind { + MN_ACTION, + MN_GOTO, + MN_TOGGLE, + MN_BACK, + MN_DEACTIVE, + MN_TEXTFIELD, + MN_NUMFIELD, + MN_CONTROLFIELD, + MN_STRINGSELECT, + MN_LABEL, + MN_HL, /* horizontal line */ +}; -#define MENU_MAIN_ITEM_MAX 3 -#define MENU_GAME_ITEM_MAX 4 -#define MENU_OPTIONS_ITEM_MAX 3 -#define MENU_LEVELEDITOR_ITEM_MAX 4 +class Menu; -/* Action done on the menu */ -enum { - MN_UP, - MN_DOWN, - MN_HIT +class MenuItem +{ +public: + MenuItemKind kind; + int toggled; + char *text; + char *input; + string_list_type* list; + Menu* target_menu; + + void change_text (const char *text); + void change_input(const char *text); + + static MenuItem* create(MenuItemKind kind, const char *text, int init_toggle, Menu* target_menu); +}; + +class Menu +{ +private: + // position of the menu (ie. center of the menu, not top/left) + int pos_x; + int pos_y; + + Menu* last_menu; + int width(); + int height(); + +public: + Timer effect; + int arrange_left; + int active_item; + std::vector item; + + static void set_current(Menu* pmenu); + + Menu(); + ~Menu(); + + void additem(MenuItem* pmenu_item); + 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 (); + void draw (); + void draw_item(int index, int menu_width, int menu_height); + void set_pos(int x, int y, float rw = 0, float rh = 0); + + /* Check for a menu event */ + void event(SDL_Event& event); }; -/* Menus */ -enum { - MENU_MAIN, - MENU_GAME, - MENU_OPTIONS, - MENU_LEVELEDITOR, - MENU_HIGHSCORE + +/* Action done on the menu */ +enum MenuAction { + MENU_ACTION_NONE = -1, + MENU_ACTION_UP, + MENU_ACTION_DOWN, + MENU_ACTION_LEFT, + MENU_ACTION_RIGHT, + MENU_ACTION_HIT, + MENU_ACTION_INPUT, + MENU_ACTION_REMOVE }; +/* (global) menu variables */ +extern MenuAction menuaction; +extern bool show_menu; +extern bool menu_change; + +extern Surface* checkbox; +extern Surface* checkbox_checked; +extern Surface* back; +extern Surface* arrow_left; +extern Surface* arrow_right; + +extern Menu* contrib_menu; +extern Menu* contrib_subset_menu; +extern Menu* main_menu; +extern Menu* game_menu; +extern Menu* worldmap_menu; +extern Menu* options_menu; +extern Menu* options_controls_menu; +extern Menu* highscore_menu; +extern Menu* load_game_menu; +extern Menu* save_game_menu; +extern Menu* current_menu; + /* input implementation variables */ -int delete_character; -char input_string[62]; +extern int delete_character; +extern char mn_input_char; -/* Initialize the menu variables */ -void initmenu(void); +/* Reset the global menu variables */ +void menu_reset(void); /* "Calculate" and draw the menu */ -int drawmenu(void); - -/* Check for a menu event */ -void menu_event(SDL_keysym* keysym); +void menu_process_current(void); #endif /*SUPERTUX_MENU_H*/ +/* Local Variables: */ +/* mode: c++ */ +/* End: */