rnd-20031202-1-src
[rocksndiamonds.git] / src / events.c
index 61bdf6be9698da0b6186dac9c857380da87e4f21..ffd028953a4a7073ca1729af01a631f96e42081c 100644 (file)
@@ -79,7 +79,7 @@ static boolean NextValidEvent(Event *event)
 
 void EventLoop(void)
 {
-  while(1)
+  while (1)
   {
     if (PendingEvent())                /* got event */
     {
@@ -219,7 +219,7 @@ void ClearPlayerAction()
 
   /* simulate key release events for still pressed keys */
   key_joystick_mapping = 0;
-  for (i=0; i<MAX_PLAYERS; i++)
+  for (i = 0; i < MAX_PLAYERS; i++)
     stored_player[i].action = 0;
 }
 
@@ -229,7 +229,7 @@ void SleepWhileUnmapped()
 
   KeyboardAutoRepeatOn();
 
-  while(window_unmapped)
+  while (window_unmapped)
   {
     Event event;
 
@@ -374,7 +374,11 @@ void HandleButton(int mx, int my, int button)
     old_my = my;
   }
 
-  HandleGadgets(mx, my, button);
+  if (HandleGadgets(mx, my, button))
+  {
+    /* do not handle this button event anymore */
+    mx = my = -32;     /* force mouse event to be outside screen tiles */
+  }
 
   switch(game_status)
   {
@@ -398,7 +402,7 @@ void HandleButton(int mx, int my, int button)
       break;
 
     case GAME_MODE_INFO:
-      HandleHelpScreen(button);
+      HandleInfoScreen(mx,my, 0,0, button);
       break;
 
     case GAME_MODE_SETUP:
@@ -409,11 +413,10 @@ void HandleButton(int mx, int my, int button)
 #ifdef DEBUG
       if (button == MB_RELEASED)
       {
-       int sx = (mx - SX) / TILEX;
-       int sy = (my - SY) / TILEY;
-
-       if (IN_VIS_FIELD(sx,sy))
+       if (IN_GFX_SCREEN(mx, my))
        {
+         int sx = (mx - SX) / TILEX;
+         int sy = (my - SY) / TILEY;
          int x = LEVELX(sx);
          int y = LEVELY(sy);
 
@@ -422,7 +425,9 @@ void HandleButton(int mx, int my, int button)
          if (!IN_LEV_FIELD(x, y))
            break;
 
-         printf("      Feld[%d][%d] == %d\n", x,y, Feld[x][y]);
+         printf("      Feld[%d][%d] == %d ('%s')\n", x,y, Feld[x][y],
+                element_info[Feld[x][y]].token_name);
+         printf("      Back[%d][%d] == %d\n", x,y, Back[x][y]);
          printf("      Store[%d][%d] == %d\n", x,y, Store[x][y]);
          printf("      Store2[%d][%d] == %d\n", x,y, Store2[x][y]);
          printf("      StorePlayer[%d][%d] == %d\n", x,y, StorePlayer[x][y]);
@@ -431,6 +436,8 @@ void HandleButton(int mx, int my, int button)
          printf("      MovDelay[%d][%d] == %d\n", x,y, MovDelay[x][y]);
          printf("      ChangeDelay[%d][%d] == %d\n", x,y, ChangeDelay[x][y]);
          printf("      GfxElement[%d][%d] == %d\n", x,y, GfxElement[x][y]);
+         printf("      GfxAction[%d][%d] == %d\n", x,y, GfxAction[x][y]);
+         printf("      GfxFrame[%d][%d] == %d\n", x,y, GfxFrame[x][y]);
          printf("\n");
        }
       }
@@ -469,7 +476,7 @@ void HandleKey(Key key, int key_status)
     static boolean bomb_placed[MAX_PLAYERS] = { FALSE,FALSE,FALSE,FALSE };
     int pnr;
 
-    for (pnr=0; pnr<MAX_PLAYERS; pnr++)
+    for (pnr = 0; pnr < MAX_PLAYERS; pnr++)
     {
       int i;
       byte key_action = 0;
@@ -479,7 +486,7 @@ void HandleKey(Key key, int key_status)
 
       custom_key = setup.input[pnr].key;
 
-      for (i=0; i<6; i++)
+      for (i = 0; i < 6; i++)
        if (key == *key_info[i].key_custom)
          key_action |= key_info[i].action;
 
@@ -529,7 +536,7 @@ void HandleKey(Key key, int key_status)
   {
     int i;
 
-    for (i=0; i<6; i++)
+    for (i = 0; i < 6; i++)
       if (key == key_info[i].key_default)
        joy |= key_info[i].action;
   }
@@ -559,19 +566,6 @@ void HandleKey(Key key, int key_status)
     return;
   }
 
-  /* allow quick escape to the main menu with the Escape key */
-  if (key == KSYM_Escape &&
-      game_status != GAME_MODE_MAIN &&
-      game_status != GAME_MODE_PLAYING &&
-      game_status != GAME_MODE_EDITOR &&
-      game_status != GAME_MODE_LEVELS &&
-      game_status != GAME_MODE_SETUP)
-  {
-    game_status = GAME_MODE_MAIN;
-    DrawMainMenu();
-    return;
-  }
-
   /* special key shortcuts */
   if (game_status == GAME_MODE_MAIN || game_status == GAME_MODE_PLAYING)
   {
@@ -583,17 +577,11 @@ void HandleKey(Key key, int key_status)
       TapeTogglePause(TAPE_TOGGLE_MANUAL);
   }
 
-#if 0
-#ifndef DEBUG
-
-  if (game_status == GAME_MODE_PLAYING && (tape.playing || tape.pausing))
-    return;
-
-#endif
-#endif
-
-
-  HandleGadgetsKeyInput(key);
+  if (HandleGadgetsKeyInput(key))
+  {
+    if (key != KSYM_Escape)    /* always allow ESC key to be handled */
+      key = KSYM_UNDEFINED;
+  }
 
   switch(game_status)
   {
@@ -604,6 +592,7 @@ void HandleKey(Key key, int key_status)
     case GAME_MODE_MAIN:
     case GAME_MODE_LEVELS:
     case GAME_MODE_SETUP:
+    case GAME_MODE_INFO:
       switch(key)
       {
        case KSYM_Return:
@@ -613,6 +602,8 @@ void HandleKey(Key key, int key_status)
             HandleChooseLevel(0,0, 0,0, MB_MENU_CHOICE);
          else if (game_status == GAME_MODE_SETUP)
            HandleSetupScreen(0,0, 0,0, MB_MENU_CHOICE);
+         else if (game_status == GAME_MODE_INFO)
+           HandleInfoScreen(0,0, 0,0, MB_MENU_CHOICE);
          break;
 
        case KSYM_Escape:
@@ -620,6 +611,8 @@ void HandleKey(Key key, int key_status)
             HandleChooseLevel(0,0, 0,0, MB_MENU_LEAVE);
          else if (game_status == GAME_MODE_SETUP)
            HandleSetupScreen(0,0, 0,0, MB_MENU_LEAVE);
+         else if (game_status == GAME_MODE_INFO)
+           HandleInfoScreen(0,0, 0,0, MB_MENU_LEAVE);
          break;
 
         case KSYM_Page_Up:
@@ -627,6 +620,8 @@ void HandleKey(Key key, int key_status)
             HandleChooseLevel(0,0, 0, -1 * SCROLL_PAGE, MB_MENU_MARK);
          else if (game_status == GAME_MODE_SETUP)
            HandleSetupScreen(0,0, 0, -1 * SCROLL_PAGE, MB_MENU_MARK);
+         else if (game_status == GAME_MODE_INFO)
+           HandleInfoScreen(0,0, 0, -1 * SCROLL_PAGE, MB_MENU_MARK);
          break;
 
         case KSYM_Page_Down:
@@ -634,6 +629,8 @@ void HandleKey(Key key, int key_status)
             HandleChooseLevel(0,0, 0, +1 * SCROLL_PAGE, MB_MENU_MARK);
          else if (game_status == GAME_MODE_SETUP)
            HandleSetupScreen(0,0, 0, +1 * SCROLL_PAGE, MB_MENU_MARK);
+         else if (game_status == GAME_MODE_INFO)
+           HandleInfoScreen(0,0, 0, +1 * SCROLL_PAGE, MB_MENU_MARK);
          break;
 
 #ifdef DEBUG
@@ -647,17 +644,13 @@ void HandleKey(Key key, int key_status)
       }
       break;
 
-    case GAME_MODE_INFO:
-      HandleHelpScreen(MB_RELEASED);
-      break;
-
     case GAME_MODE_SCORES:
       switch(key)
       {
        case KSYM_Return:
+       case KSYM_Escape:
          game_status = GAME_MODE_MAIN;
          DrawMainMenu();
-         BackToFront();
          break;
 
         case KSYM_Page_Up:
@@ -791,9 +784,16 @@ void HandleKey(Key key, int key_status)
 
        case KSYM_Q:
        case KSYM_q:
-         local_player->dynamite = 1000;
-         break;
+         {
+           int i;
 
+           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;
+         }
+
+         break;
 
 
 #if 0
@@ -802,7 +802,7 @@ void HandleKey(Key key, int key_status)
          {
            int i;
 
-           for(i=0; i<MAX_PLAYERS; i++)
+           for (i = 0; i < MAX_PLAYERS; i++)
            {
              printf("Player %d:\n", i);
              printf("  jx == %d, jy == %d\n",
@@ -823,7 +823,13 @@ void HandleKey(Key key, int key_status)
       break;
     }
     default:
-      break;
+      if (key == KSYM_Escape)
+      {
+       game_status = GAME_MODE_MAIN;
+       DrawMainMenu();
+
+       return;
+      }
   }
 }
 
@@ -848,7 +854,7 @@ static int HandleJoystickForAllPlayers()
   int i;
   int result = 0;
 
-  for (i=0; i<MAX_PLAYERS; i++)
+  for (i = 0; i < MAX_PLAYERS; i++)
   {
     byte joy_action = 0;
 
@@ -888,6 +894,7 @@ void HandleJoystick()
     case GAME_MODE_MAIN:
     case GAME_MODE_LEVELS:
     case GAME_MODE_SETUP:
+    case GAME_MODE_INFO:
     {
       static unsigned long joystickmove_delay = 0;
 
@@ -901,6 +908,8 @@ void HandleJoystick()
         HandleChooseLevel(0,0,dx,dy,newbutton ? MB_MENU_CHOICE : MB_MENU_MARK);
       else if (game_status == GAME_MODE_SETUP)
        HandleSetupScreen(0,0,dx,dy,newbutton ? MB_MENU_CHOICE : MB_MENU_MARK);
+      else if (game_status == GAME_MODE_INFO)
+       HandleInfoScreen(0,0,dx,dy,newbutton ? MB_MENU_CHOICE : MB_MENU_MARK);
       break;
     }
 
@@ -908,10 +917,6 @@ void HandleJoystick()
       HandleHallOfFame(0,0, dx,dy, !newbutton);
       break;
 
-    case GAME_MODE_INFO:
-      HandleHelpScreen(!newbutton);
-      break;
-
     case GAME_MODE_EDITOR:
       HandleLevelEditorIdle();
       break;