rnd-20040411-1-src
[rocksndiamonds.git] / src / events.c
index facafec6be76761e2afcf20dd9e7656d550fefda..abf5711fdf6f3da311d21917a0ca721898801b0e 100644 (file)
@@ -85,7 +85,7 @@ void EventLoop(void)
     {
       Event event;
 
-      if (NextValidEvent(&event))
+      while (NextValidEvent(&event))
       {
        switch(event.type)
        {
@@ -112,7 +112,7 @@ void EventLoop(void)
     else
     {
       /* when playing, display a special mouse pointer inside the playfield */
-      if (game_status == GAME_MODE_PLAYING)
+      if (game_status == GAME_MODE_PLAYING && !tape.pausing)
       {
        if (!playfield_cursor_set && cursor_inside_playfield &&
            DelayReached(&playfield_cursor_delay, 1000))
@@ -411,36 +411,8 @@ void HandleButton(int mx, int my, int button)
 
     case GAME_MODE_PLAYING:
 #ifdef DEBUG
-      if (button == MB_RELEASED)
-      {
-       if (IN_GFX_SCREEN(mx, my))
-       {
-         int sx = (mx - SX) / TILEX;
-         int sy = (my - SY) / TILEY;
-         int x = LEVELX(sx);
-         int y = LEVELY(sy);
-
-         printf("INFO: SCREEN(%d, %d), LEVEL(%d, %d)\n", sx, sy, x, y);
-
-         if (!IN_LEV_FIELD(x, y))
-           break;
-
-         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]);
-         printf("      MovPos[%d][%d] == %d\n", x,y, MovPos[x][y]);
-         printf("      MovDir[%d][%d] == %d\n", x,y, MovDir[x][y]);
-         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");
-       }
-      }
+      if (button == MB_PRESSED && !motion_status && IN_GFX_SCREEN(mx, my))
+       DumpTile(LEVELX((mx - SX) / TILEX), LEVELY((my - SY) / TILEY));
 #endif
       break;
 
@@ -462,7 +434,7 @@ static boolean is_string_suffix(char *string, char *suffix)
 
 #define MAX_CHEAT_INPUT_LEN    32
 
-static void HandleKeysCheating(Key key)
+static void HandleKeysSpecial(Key key)
 {
   static char cheat_input[2 * MAX_CHEAT_INPUT_LEN + 1] = "";
   char letter = getCharFromKey(key);
@@ -487,23 +459,68 @@ static void HandleKeysCheating(Key key)
   printf("::: '%s' [%d]\n", cheat_input, cheat_input_len);
 #endif
 
-#if 1
-  if (is_string_suffix(cheat_input, ":insert solution tape"))
-    InsertSolutionTape();
-#else
-  if (is_string_suffix(cheat_input, ":ist"))
-    InsertSolutionTape();
-#endif
-
+  if (game_status == GAME_MODE_MAIN)
+  {
+    if (is_string_suffix(cheat_input, ":insert-solution-tape") ||
+       is_string_suffix(cheat_input, ":ist"))
+    {
+      InsertSolutionTape();
+    }
+    else if (is_string_suffix(cheat_input, ":reload-graphics") ||
+            is_string_suffix(cheat_input, ":rg"))
+    {
+      ReloadCustomArtwork(1 << ARTWORK_TYPE_GRAPHICS);
+      DrawMainMenu();
+    }
+    else if (is_string_suffix(cheat_input, ":reload-sounds") ||
+            is_string_suffix(cheat_input, ":rs"))
+    {
+      ReloadCustomArtwork(1 << ARTWORK_TYPE_SOUNDS);
+      DrawMainMenu();
+    }
+    else if (is_string_suffix(cheat_input, ":reload-music") ||
+            is_string_suffix(cheat_input, ":rm"))
+    {
+      ReloadCustomArtwork(1 << ARTWORK_TYPE_MUSIC);
+      DrawMainMenu();
+    }
+    else if (is_string_suffix(cheat_input, ":reload-artwork") ||
+            is_string_suffix(cheat_input, ":ra"))
+    {
+      ReloadCustomArtwork(1 << ARTWORK_TYPE_GRAPHICS |
+                         1 << ARTWORK_TYPE_SOUNDS |
+                         1 << ARTWORK_TYPE_MUSIC);
+      DrawMainMenu();
+    }
+    else if (is_string_suffix(cheat_input, ":dump-level") ||
+            is_string_suffix(cheat_input, ":dl"))
+    {
+      DumpLevel(&level);
+    }
+    else if (is_string_suffix(cheat_input, ":dump-tape") ||
+            is_string_suffix(cheat_input, ":dt"))
+    {
+      DumpTape(&tape);
+    }
+  }
+  else if (game_status == GAME_MODE_PLAYING)
+  {
 #ifdef DEBUG
-  else if (is_string_suffix(cheat_input, ":dump tape"))
-    DumpTape(&tape);
-  else 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;
+    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;
 #endif
+  }
+  else if (game_status == GAME_MODE_EDITOR)
+  {
+    if (is_string_suffix(cheat_input, ":dump-brush") ||
+       is_string_suffix(cheat_input, ":DB"))
+    {
+      DumpBrush();
+    }
+  }
 }
 
 void HandleKey(Key key, int key_status)
@@ -614,16 +631,35 @@ void HandleKey(Key key, int key_status)
   if (key_status == KEY_RELEASED)
     return;
 
-  if ((key == KSYM_Return || key == setup.shortcut.toggle_pause) &&
-      game_status == GAME_MODE_PLAYING && AllPlayersGone)
+  if (game_status == GAME_MODE_PLAYING && AllPlayersGone &&
+      (key == KSYM_Return || key == setup.shortcut.toggle_pause))
   {
     CloseDoor(DOOR_CLOSE_1);
     game_status = GAME_MODE_MAIN;
     DrawMainMenu();
+
+    return;
+  }
+
+  if (game_status == GAME_MODE_MAIN && key == setup.shortcut.toggle_pause)
+  {
+    if (setup.autorecord)
+      TapeStartRecording();
+
+#if defined(PLATFORM_UNIX)
+    if (options.network)
+      SendToServer_StartPlaying();
+    else
+#endif
+    {
+      game_status = GAME_MODE_PLAYING;
+      StopAnimation();
+      InitGame();
+    }
+
     return;
   }
 
-  /* special key shortcuts */
   if (game_status == GAME_MODE_MAIN || game_status == GAME_MODE_PLAYING)
   {
     if (key == setup.shortcut.save_game)
@@ -632,10 +668,10 @@ void HandleKey(Key key, int key_status)
       TapeQuickLoad();
     else if (key == setup.shortcut.toggle_pause)
       TapeTogglePause(TAPE_TOGGLE_MANUAL);
-
-    HandleKeysCheating(key);
   }
 
+  HandleKeysSpecial(key);
+
   if (HandleGadgetsKeyInput(key))
   {
     if (key != KSYM_Escape)    /* always allow ESC key to be handled */