Limitated the number of bullets to be shot at the same time.
[supertux.git] / src / menu.cpp
index 14834c1..079e85d 100644 (file)
@@ -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;
@@ -461,6 +464,32 @@ Menu::draw_item(int index, // Position of the current item in the menu
                               A_HMIDDLE, A_VMIDDLE, shadow_size);
         break;
       }
+//    case MN_CONTROLFIELD:
+//      {
+        /* display key */  // FIXME: the key number is not that obvious to the user :P
+/*        char str[12];
+        sprintf(str, "%i", *pitem.int_p);
+        input_width = strlen(str) * font_width;
+
+        int input_pos = input_width/2;
+        int text_pos  = (text_width + font_width)/2;
+
+        fillrect(x_pos - input_pos + text_pos - 1, y_pos - 10,
+                 input_width + font_width + 2, 20,
+                 255,255,255,255);
+        fillrect(x_pos - input_pos + text_pos, y_pos - 9,
+                 input_width + font_width, 18,
+                 0,0,0,128);
+
+        gold_text->draw_align(str,
+                              x_pos + text_pos, y_pos,
+                              A_HMIDDLE, A_VMIDDLE, 2);
+
+        text_font->draw_align(pitem.text,
+                              x_pos - (input_width + font_width)/2, y_pos,
+                              A_HMIDDLE, A_VMIDDLE, shadow_size);
+        break;
+      }*/
     case MN_STRINGSELECT:
       {
         int list_pos_2 = list_width + font_width;
@@ -588,6 +617,60 @@ Menu::event(SDL_Event& event)
           /* An International Character. */
         }
 
+      if(item[active_item].kind == MN_CONTROLFIELD)
+        {
+        *item[active_item].int_p = event.key.keysym.unicode;
+        if(ch[0] != '\0')
+          strcpy(item[active_item].input, ch);
+        else
+          switch(key)
+           {
+           case SDLK_UP:
+             strcpy(item[active_item].input, "Up cursor");
+             break;
+           case SDLK_DOWN:
+             strcpy(item[active_item].input, "Down cursor");
+             break;
+           case SDLK_LEFT:
+             strcpy(item[active_item].input, "Left cursor");
+             break;
+           case SDLK_RIGHT:
+             strcpy(item[active_item].input, "Right cursor");
+             break;
+           case SDLK_RETURN:
+             strcpy(item[active_item].input, "Return");
+             break;
+           case SDLK_SPACE:
+             strcpy(item[active_item].input, "Space");
+             break;
+           case SDLK_RSHIFT:
+             strcpy(item[active_item].input, "Right Shift");
+             break;
+           case SDLK_LSHIFT:
+             strcpy(item[active_item].input, "Left Shift");
+             break;
+           case SDLK_RCTRL:
+             strcpy(item[active_item].input, "Right Control");
+             break;
+           case SDLK_LCTRL:
+             strcpy(item[active_item].input, "Left Control");
+             break;
+           case SDLK_RALT:
+             strcpy(item[active_item].input, "Right Alt");
+             break;
+           case SDLK_LALT:
+             strcpy(item[active_item].input, "Left Alt");
+             break;
+           default:
+             strcpy(item[active_item].input, "?");
+             break;
+           }
+        
+        menuaction = MENU_ACTION_DOWN;
+        return;
+        }
+
+
       switch(key)
         {
         case SDLK_UP:          /* Menu Up */