From: Ricardo Cruz Date: Wed, 21 Apr 2004 15:15:28 +0000 (+0000) Subject: Finally, made keys configurable via the menu!! ;) X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=734dad6deb86707d985d2af76b5b09db7a14d259;p=supertux.git Finally, made keys configurable via the menu!! ;) Next step is to save them to config file and to make joystick also configurable. SVN-Revision: 611 --- diff --git a/src/menu.cpp b/src/menu.cpp index 14834c1b8..53a339833 100644 --- a/src/menu.cpp +++ b/src/menu.cpp @@ -97,7 +97,7 @@ Menu::set_current(Menu* menu) /* Return a pointer to a new menu item */ MenuItem* -MenuItem::create(MenuItemKind kind_, const char *text_, int init_toggle_, Menu* target_menu_) +MenuItem::create(MenuItemKind kind_, const char *text_, int init_toggle_, Menu* target_menu_, int* int_p_) { MenuItem *pnew_item = new MenuItem; @@ -121,6 +121,9 @@ MenuItem::create(MenuItemKind kind_, const char *text_, int init_toggle_, Menu* } else pnew_item->list = NULL; + + pnew_item->int_p = int_p_; + return pnew_item; } @@ -183,12 +186,12 @@ void Menu::set_pos(int x, int y, float rw, float rh) } void -Menu::additem(MenuItemKind kind_, const std::string& text_, int toggle_, Menu* menu_) +Menu::additem(MenuItemKind kind_, const std::string& text_, int toggle_, Menu* menu_, int* int_p) { if(kind_ == MN_BACK) has_backitem = true; - additem(MenuItem::create(kind_, text_.c_str(), toggle_, menu_)); + additem(MenuItem::create(kind_, text_.c_str(), toggle_, menu_, int_p)); } /* Add an item to a menu */ @@ -272,10 +275,11 @@ Menu::action() case MN_ACTION: case MN_TEXTFIELD: case MN_NUMFIELD: - case MN_CONTROLFIELD: Menu::set_current(0); item[active_item].toggled = true; break; + case MN_CONTROLFIELD: + break; case MN_BACK: Menu::pop_current(); @@ -321,7 +325,6 @@ Menu::action() item[active_item].input[1] = '\0'; } } - break; case MENU_ACTION_NONE: break; @@ -588,6 +591,14 @@ Menu::event(SDL_Event& event) /* An International Character. */ } + if(item[active_item].kind == MN_CONTROLFIELD) + { + *item[active_item].int_p = event.key.keysym.unicode; + menuaction = MENU_ACTION_DOWN; + return; + } + + switch(key) { case SDLK_UP: /* Menu Up */ diff --git a/src/menu.h b/src/menu.h index 56e1a360f..8342a465a 100644 --- a/src/menu.h +++ b/src/menu.h @@ -51,13 +51,14 @@ public: int toggled; char *text; char *input; + int *int_p; // used for setting keys (can be used for more stuff...) 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); + static MenuItem* create(MenuItemKind kind, const char *text, int init_toggle, Menu* target_menu, int* int_p); }; class Menu @@ -115,7 +116,7 @@ public: ~Menu(); void additem(MenuItem* pmenu_item); - void additem(MenuItemKind kind, const std::string& text, int init_toggle, Menu* target_menu); + void additem(MenuItemKind kind, const std::string& text, int init_toggle, Menu* target_menu, int *int_p = NULL); void action (); diff --git a/src/player.h b/src/player.h index 0632c6cd4..b0edbd23c 100644 --- a/src/player.h +++ b/src/player.h @@ -58,6 +58,8 @@ public: PlayerKeymap(); }; +extern PlayerKeymap keymap; + struct player_input_type { int right; diff --git a/src/setup.cpp b/src/setup.cpp index ab73581ab..3cf3a9186 100644 --- a/src/setup.cpp +++ b/src/setup.cpp @@ -50,6 +50,8 @@ #include "scene.h" #include "worldmap.h" +#include "player.h" + #ifdef WIN32 #define mkdir(dir, mode) mkdir(dir) // on win32 we typically don't want LFS paths @@ -405,7 +407,11 @@ void st_menu(void) options_controls_menu->additem(MN_LABEL,"Controls",0,0); options_controls_menu->additem(MN_HL,"",0,0); - //FIXME:options_controls_menu->additem(MN_CONTROLFIELD,"Move Right", tux.keymap.right,0); + options_controls_menu->additem(MN_CONTROLFIELD,"Right move", 0,0, &keymap.right); + options_controls_menu->additem(MN_CONTROLFIELD,"Left move", 0,0, &keymap.left); + options_controls_menu->additem(MN_CONTROLFIELD,"Jump", 0,0, &keymap.jump); + options_controls_menu->additem(MN_CONTROLFIELD,"Duck", 0,0, &keymap.duck); + options_controls_menu->additem(MN_CONTROLFIELD,"Power", 0,0, &keymap.fire); options_controls_menu->additem(MN_HL,"",0,0); options_controls_menu->additem(MN_BACK,"Back",0,0);