rnd-20060804-1-src
[rocksndiamonds.git] / src / events.c
index f478a86bee482edd481952a5cee3325d92fcb776..6b501408b892bec896f7de108d3e11d9a8805d2e 100644 (file)
@@ -171,7 +171,9 @@ void EventLoop(void)
        has its own synchronization and is CPU friendly, too */
 
     if (game_status == GAME_MODE_PLAYING)
+    {
       HandleGameActions();
+    }
     else
     {
       SyncDisplay();
@@ -313,6 +315,11 @@ void HandleExposeEvent(ExposeEvent *event)
 
 void HandleButtonEvent(ButtonEvent *event)
 {
+#if 0
+  printf("::: BUTTON EVENT: button %d %s\n", event->button,
+        event->type == EVENT_BUTTONPRESS ? "pressed" : "released");
+#endif
+
   motion_status = FALSE;
 
   if (event->type == EVENT_BUTTONPRESS)
@@ -320,7 +327,7 @@ void HandleButtonEvent(ButtonEvent *event)
   else
     button_status = MB_RELEASED;
 
-  HandleButton(event->x, event->y, button_status);
+  HandleButton(event->x, event->y, button_status, event->button);
 }
 
 void HandleMotionEvent(MotionEvent *event)
@@ -333,7 +340,7 @@ void HandleMotionEvent(MotionEvent *event)
 
   motion_status = TRUE;
 
-  HandleButton(event->x, event->y, button_status);
+  HandleButton(event->x, event->y, button_status, button_status);
 }
 
 void HandleKeyEvent(KeyEvent *event)
@@ -343,6 +350,11 @@ void HandleKeyEvent(KeyEvent *event)
   Key key = GetEventKey(event, with_modifiers);
   Key keymod = (with_modifiers ? GetEventKey(event, FALSE) : key);
 
+#if 0
+  printf("::: KEY EVENT: %d %s\n", GetEventKey(event, TRUE),
+        event->type == EVENT_KEYPRESS ? "pressed" : "released");
+#endif
+
   HandleKeyModState(keymod, key_status);
   HandleKey(key, key_status);
 }
@@ -394,7 +406,7 @@ void HandleClientMessageEvent(ClientMessageEvent *event)
     CloseAllAndExit(0);
 }
 
-void HandleButton(int mx, int my, int button)
+void HandleButton(int mx, int my, int button, int button_nr)
 {
   static int old_mx = 0, old_my = 0;
 
@@ -416,10 +428,18 @@ void HandleButton(int mx, int my, int button)
     mx = my = -32;     /* force mouse event to be outside screen tiles */
   }
 
-  switch(game_status)
+  /* do not use scroll wheel button events for anything other than gadgets */
+  if (IS_WHEEL_BUTTON(button_nr))
+    return;
+
+  switch (game_status)
   {
+    case GAME_MODE_TITLE:
+      HandleTitleScreen(mx, my, 0, 0, button);
+      break;
+
     case GAME_MODE_MAIN:
-      HandleMainMenu(mx,my, 0,0, button);
+      HandleMainMenu(mx, my, 0, 0, button);
       break;
 
     case GAME_MODE_PSEUDO_TYPENAME:
@@ -427,11 +447,11 @@ void HandleButton(int mx, int my, int button)
       break;
 
     case GAME_MODE_LEVELS:
-      HandleChooseLevel(mx,my, 0,0, button);
+      HandleChooseLevel(mx, my, 0, 0, button);
       break;
 
     case GAME_MODE_SCORES:
-      HandleHallOfFame(0,0, 0,0, button);
+      HandleHallOfFame(0, 0, 0, 0, button);
       break;
 
     case GAME_MODE_EDITOR:
@@ -439,11 +459,11 @@ void HandleButton(int mx, int my, int button)
       break;
 
     case GAME_MODE_INFO:
-      HandleInfoScreen(mx,my, 0,0, button);
+      HandleInfoScreen(mx, my, 0, 0, button);
       break;
 
     case GAME_MODE_SETUP:
-      HandleSetupScreen(mx,my, 0,0, button);
+      HandleSetupScreen(mx, my, 0, 0, button);
       break;
 
     case GAME_MODE_PLAYING:
@@ -466,7 +486,7 @@ static boolean is_string_suffix(char *string, char *suffix)
   if (suffix_len > string_len)
     return FALSE;
 
-  return (strcmp(&string[string_len - suffix_len], suffix) == 0);
+  return (strEqual(&string[string_len - suffix_len], suffix));
 }
 
 #define MAX_CHEAT_INPUT_LEN    32
@@ -544,10 +564,7 @@ static void HandleKeysSpecial(Key key)
   {
 #ifdef DEBUG
     if (is_string_suffix(cheat_input, ".q"))
-      for (i = 0; i < MAX_INVENTORY_SIZE; i++)
-       if (local_player->inventory_size < MAX_INVENTORY_SIZE)
-         local_player->inventory_element[local_player->inventory_size++] =
-           EL_DYNAMITE;
+      DEBUG_SetMaximumDynamite();
 #endif
   }
   else if (game_status == GAME_MODE_EDITOR)
@@ -698,14 +715,28 @@ void HandleKey(Key key, int key_status)
       TapeTogglePause(TAPE_TOGGLE_MANUAL);
   }
 
-  if (game_status == GAME_MODE_PLAYING)
+  if (game_status == GAME_MODE_PLAYING && !network_playing)
   {
-    if (key == KSYM_5)
-      game.centered_player_nr_next = -1;
+    int centered_player_nr_next = -999;
+
+    if (key == setup.shortcut.focus_player_all)
+      centered_player_nr_next = -1;
     else
       for (i = 0; i < MAX_PLAYERS; i++)
-       if (key == KSYM_1 + i)
-         game.centered_player_nr_next = i;
+       if (key == setup.shortcut.focus_player[i])
+         centered_player_nr_next = i;
+
+    if (centered_player_nr_next != -999)
+    {
+      game.centered_player_nr_next = centered_player_nr_next;
+      game.set_centered_player = TRUE;
+
+      if (tape.recording)
+      {
+       tape.centered_player_nr_next = game.centered_player_nr_next;
+       tape.set_centered_player = TRUE;
+      }
+    }
   }
 
   HandleKeysSpecial(key);
@@ -722,6 +753,7 @@ void HandleKey(Key key, int key_status)
       HandleTypeName(0, key);
       break;
 
+    case GAME_MODE_TITLE:
     case GAME_MODE_MAIN:
     case GAME_MODE_LEVELS:
     case GAME_MODE_SETUP:
@@ -735,7 +767,9 @@ void HandleKey(Key key, int key_status)
        case KSYM_space:
 #endif
        case KSYM_Return:
-         if (game_status == GAME_MODE_MAIN)
+         if (game_status == GAME_MODE_TITLE)
+           HandleTitleScreen(0,0, 0,0, MB_MENU_CHOICE);
+         else if (game_status == GAME_MODE_MAIN)
            HandleMainMenu(0,0, 0,0, MB_MENU_CHOICE);
           else if (game_status == GAME_MODE_LEVELS)
             HandleChooseLevel(0,0, 0,0, MB_MENU_CHOICE);
@@ -746,7 +780,9 @@ void HandleKey(Key key, int key_status)
          break;
 
        case KSYM_Escape:
-          if (game_status == GAME_MODE_LEVELS)
+         if (game_status == GAME_MODE_TITLE)
+           HandleTitleScreen(0,0, 0,0, MB_MENU_LEAVE);
+          else if (game_status == GAME_MODE_LEVELS)
             HandleChooseLevel(0,0, 0,0, MB_MENU_LEAVE);
          else if (game_status == GAME_MODE_SETUP)
            HandleSetupScreen(0,0, 0,0, MB_MENU_LEAVE);
@@ -925,7 +961,8 @@ void HandleNoEvent()
 {
   if (button_status && game_status != GAME_MODE_PLAYING)
   {
-    HandleButton(0, 0, -button_status);
+    HandleButton(0, 0, -button_status, button_status);
+
     return;
   }
 
@@ -979,6 +1016,7 @@ void HandleJoystick()
 
   switch(game_status)
   {
+    case GAME_MODE_TITLE:
     case GAME_MODE_MAIN:
     case GAME_MODE_LEVELS:
     case GAME_MODE_SETUP:
@@ -990,7 +1028,9 @@ void HandleJoystick()
          !DelayReached(&joystickmove_delay, GADGET_FRAME_DELAY))
        newbutton = dx = dy = 0;
 
-      if (game_status == GAME_MODE_MAIN)
+      if (game_status == GAME_MODE_TITLE)
+       HandleTitleScreen(0,0,dx,dy,newbutton ? MB_MENU_CHOICE : MB_MENU_MARK);
+      else if (game_status == GAME_MODE_MAIN)
        HandleMainMenu(0,0,dx,dy,newbutton ? MB_MENU_CHOICE : MB_MENU_MARK);
       else if (game_status == GAME_MODE_LEVELS)
         HandleChooseLevel(0,0,dx,dy,newbutton ? MB_MENU_CHOICE : MB_MENU_MARK);