- fixed an ugly hack I was using before for the JS config menu
authorRyan Flegel <rflegel@gmail.com>
Fri, 14 May 2004 02:44:34 +0000 (02:44 +0000)
committerRyan Flegel <rflegel@gmail.com>
Fri, 14 May 2004 02:44:34 +0000 (02:44 +0000)
SVN-Revision: 1169

src/menu.cpp
src/menu.h
src/setup.cpp

index afd02e6..8b16164 100644 (file)
@@ -240,67 +240,65 @@ std::string MenuItem::get_input_with_symbol(bool active_item)
   return string;
 }
 
-/* Set ControlField a key */
+/* Set ControlField for keyboard key */
 void Menu::get_controlfield_key_into_input(MenuItem *item)
 {
-  if (this == options_joystick_menu)
+  switch(*item->int_p)
   {
-    std::ostringstream oss;
-    oss << "Button " << *item->int_p;
-    item->change_input(oss.str().c_str());
-  }
-
-  else if (this == options_keys_menu)
-  {
-    switch(*item->int_p)
+  case SDLK_UP:
+    item->change_input("Up cursor");
+    break;
+  case SDLK_DOWN:
+    item->change_input("Down cursor");
+    break;
+  case SDLK_LEFT:
+    item->change_input("Left cursor");
+    break;
+  case SDLK_RIGHT:
+    item->change_input("Right cursor");
+    break;
+  case SDLK_RETURN:
+    item->change_input("Return");
+    break;
+  case SDLK_SPACE:
+    item->change_input("Space");
+    break;
+  case SDLK_RSHIFT:
+    item->change_input("Right Shift");
+    break;
+  case SDLK_LSHIFT:
+    item->change_input("Left Shift");
+    break;
+  case SDLK_RCTRL:
+    item->change_input("Right Control");
+    break;
+  case SDLK_LCTRL:
+    item->change_input("Left Control");
+    break;
+  case SDLK_RALT:
+    item->change_input("Right Alt");
+    break;
+  case SDLK_LALT:
+    item->change_input("Left Alt");
+    break;
+  default:
     {
-    case SDLK_UP:
-      item->change_input("Up cursor");
-      break;
-    case SDLK_DOWN:
-      item->change_input("Down cursor");
-      break;
-    case SDLK_LEFT:
-      item->change_input("Left cursor");
-      break;
-    case SDLK_RIGHT:
-      item->change_input("Right cursor");
-      break;
-    case SDLK_RETURN:
-      item->change_input("Return");
-      break;
-    case SDLK_SPACE:
-      item->change_input("Space");
-      break;
-    case SDLK_RSHIFT:
-      item->change_input("Right Shift");
-      break;
-    case SDLK_LSHIFT:
-      item->change_input("Left Shift");
-      break;
-    case SDLK_RCTRL:
-      item->change_input("Right Control");
-      break;
-    case SDLK_LCTRL:
-      item->change_input("Left Control");
-      break;
-    case SDLK_RALT:
-      item->change_input("Right Alt");
-      break;
-    case SDLK_LALT:
-      item->change_input("Left Alt");
-      break;
-    default:
-      {
-        char tmp[64];
-        snprintf(tmp, 64, "%d", *item->int_p);
-        item->change_input(tmp);
-      }
-      break;
+      char tmp[64];
+      snprintf(tmp, 64, "%d", *item->int_p);
+      item->change_input(tmp);
     }
+    break;
   }
 }
 
+/* Set ControlField for joystick button */
+void Menu::get_controlfield_js_into_input(MenuItem *item)
+{
+  std::ostringstream oss;
+  oss << "Button " << *item->int_p;
+  item->change_input(oss.str().c_str());
+}
+
 /* Free a menu and all its items */
 Menu::~Menu()
 {
@@ -572,7 +570,8 @@ Menu::draw_item(int index, // Position of the current item in the menu
     }
   case MN_TEXTFIELD:
   case MN_NUMFIELD:
-  case MN_CONTROLFIELD:
+  case MN_CONTROLFIELD_KB:
+  case MN_CONTROLFIELD_JS:
     {
       int input_pos = input_width/2;
       int text_pos  = (text_width + font_width)/2;
@@ -584,8 +583,10 @@ Menu::draw_item(int index, // Position of the current item in the menu
                input_width + font_width, 18,
                0,0,0,128);
 
-      if(pitem.kind == MN_CONTROLFIELD)
+      if(pitem.kind == MN_CONTROLFIELD_KB)
         get_controlfield_key_into_input(&pitem);
+      else if (pitem.kind == MN_CONTROLFIELD_JS)
+        get_controlfield_js_into_input(&pitem);
 
       if(pitem.kind == MN_TEXTFIELD || pitem.kind == MN_NUMFIELD)
       {
@@ -756,7 +757,7 @@ Menu::event(SDL_Event& event)
       /* An International Character. */
     }
 
-    if(item[active_item].kind == MN_CONTROLFIELD && this == options_keys_menu)
+    if(item[active_item].kind == MN_CONTROLFIELD_KB)
     {
       if(key == SDLK_ESCAPE)
       {
@@ -824,7 +825,7 @@ Menu::event(SDL_Event& event)
     }
     break;
   case  SDL_JOYBUTTONDOWN:
-    if (item[active_item].kind == MN_CONTROLFIELD && this == options_joystick_menu)
+    if (item[active_item].kind == MN_CONTROLFIELD_JS)
     {
       *item[active_item].int_p = key;
       menuaction = MENU_ACTION_DOWN;
index 41d6dd7..fa1ddf5 100644 (file)
@@ -104,7 +104,8 @@ enum MenuItemKind {
   MN_DEACTIVE,
   MN_TEXTFIELD,
   MN_NUMFIELD,
-  MN_CONTROLFIELD,
+  MN_CONTROLFIELD_KB,
+  MN_CONTROLFIELD_JS,
   MN_STRINGSELECT,
   MN_LABEL,
   MN_HL, /* horizontal line */
@@ -209,6 +210,7 @@ public:
   bool isToggled(int id);
 
   void Menu::get_controlfield_key_into_input(MenuItem *item);
+  void Menu::get_controlfield_js_into_input(MenuItem *item);
 
   void draw   ();
   void draw_item(int index, int menu_width, int menu_height);
index 6476053..af5a964 100644 (file)
@@ -420,11 +420,11 @@ void st_menu(void)
   
   options_keys_menu->additem(MN_LABEL,"Key Setup",0,0);
   options_keys_menu->additem(MN_HL,"",0,0);
-  options_keys_menu->additem(MN_CONTROLFIELD,"Left move", 0,0, 0,&keymap.left);
-  options_keys_menu->additem(MN_CONTROLFIELD,"Right move", 0,0, 0,&keymap.right);
-  options_keys_menu->additem(MN_CONTROLFIELD,"Jump", 0,0, 0,&keymap.jump);
-  options_keys_menu->additem(MN_CONTROLFIELD,"Duck", 0,0, 0,&keymap.duck);
-  options_keys_menu->additem(MN_CONTROLFIELD,"Power/Run", 0,0, 0,&keymap.fire);
+  options_keys_menu->additem(MN_CONTROLFIELD_KB,"Left move", 0,0, 0,&keymap.left);
+  options_keys_menu->additem(MN_CONTROLFIELD_KB,"Right move", 0,0, 0,&keymap.right);
+  options_keys_menu->additem(MN_CONTROLFIELD_KB,"Jump", 0,0, 0,&keymap.jump);
+  options_keys_menu->additem(MN_CONTROLFIELD_KB,"Duck", 0,0, 0,&keymap.duck);
+  options_keys_menu->additem(MN_CONTROLFIELD_KB,"Power/Run", 0,0, 0,&keymap.fire);
   options_keys_menu->additem(MN_HL,"",0,0);
   options_keys_menu->additem(MN_BACK,"Back",0,0);
 
@@ -432,12 +432,12 @@ void st_menu(void)
     {
     options_joystick_menu->additem(MN_LABEL,"Joystick Setup",0,0);
     options_joystick_menu->additem(MN_HL,"",0,0);
-    //options_joystick_menu->additem(MN_CONTROLFIELD,"X axis", 0,0, 0,&joystick_keymap.x_axis);
-    //options_joystick_menu->additem(MN_CONTROLFIELD,"Y axis", 0,0, 0,&joystick_keymap.y_axis);
-    options_joystick_menu->additem(MN_CONTROLFIELD,"A button", 0,0, 0,&joystick_keymap.a_button);
-    options_joystick_menu->additem(MN_CONTROLFIELD,"B button", 0,0, 0,&joystick_keymap.b_button);
-    //options_joystick_menu->additem(MN_CONTROLFIELD,"Start", 0,0, 0,&joystick_keymap.start_button);
-    //options_joystick_menu->additem(MN_CONTROLFIELD,"DeadZone", 0,0, 0,&joystick_keymap.dead_zone);
+    //options_joystick_menu->additem(MN_CONTROLFIELD_JS,"X axis", 0,0, 0,&joystick_keymap.x_axis);
+    //options_joystick_menu->additem(MN_CONTROLFIELD_JS,"Y axis", 0,0, 0,&joystick_keymap.y_axis);
+    options_joystick_menu->additem(MN_CONTROLFIELD_JS,"A button", 0,0, 0,&joystick_keymap.a_button);
+    options_joystick_menu->additem(MN_CONTROLFIELD_JS,"B button", 0,0, 0,&joystick_keymap.b_button);
+    //options_joystick_menu->additem(MN_CONTROLFIELD_JS,"Start", 0,0, 0,&joystick_keymap.start_button);
+    //options_joystick_menu->additem(MN_CONTROLFIELD_JS,"DeadZone", 0,0, 0,&joystick_keymap.dead_zone);
     options_joystick_menu->additem(MN_HL,"",0,0);
     options_joystick_menu->additem(MN_BACK,"Back",0,0);
     }