fixed ignoring mouse actions with MM engine using virtual buttons
[rocksndiamonds.git] / src / events.c
index dd3e88af8721f49039488aba261eb8bc3f51c9ea..8e368b613686a1331f71d396dd47c0daaef87e62 100644 (file)
@@ -1370,6 +1370,8 @@ static void HandleButtonOrFinger(int mx, int my, int button)
       HandleButtonOrFinger_WipeGestures_MM(mx, my, button);
     else if (strEqual(setup.touch.control_type, TOUCH_CONTROL_FOLLOW_FINGER))
       HandleButtonOrFinger_FollowFinger_MM(mx, my, button);
+    else if (strEqual(setup.touch.control_type, TOUCH_CONTROL_VIRTUAL_BUTTONS))
+      SetPlayerMouseAction(mx, my, button);    /* special case */
   }
   else
   {
@@ -1554,16 +1556,16 @@ void HandleButton(int mx, int my, int button, int button_nr)
      strEqual(setup.touch.control_type, TOUCH_CONTROL_FOLLOW_FINGER));
 #endif
 
-  if (handle_gadgets && HandleGadgets(mx, my, button))
+  if (HandleGlobalAnimClicks(mx, my, button))
   {
     /* do not handle this button event anymore */
-    mx = my = -32;     /* force mouse event to be outside screen tiles */
+    return;            /* force mouse event not to be handled at all */
   }
 
-  if (HandleGlobalAnimClicks(mx, my, button))
+  if (handle_gadgets && HandleGadgets(mx, my, button))
   {
     /* do not handle this button event anymore */
-    return;            /* force mouse event not to be handled at all */
+    mx = my = -32;     /* force mouse event to be outside screen tiles */
   }
 
   if (button_hold && game_status == GAME_MODE_PLAYING && tape.pausing)
@@ -1675,6 +1677,11 @@ static void HandleKeysSpecial(Key key)
     {
       InsertSolutionTape();
     }
+    else if (is_string_suffix(cheat_input, ":play-solution-tape") ||
+            is_string_suffix(cheat_input, ":pst"))
+    {
+      PlaySolutionTape();
+    }
     else if (is_string_suffix(cheat_input, ":reload-graphics") ||
             is_string_suffix(cheat_input, ":rg"))
     {
@@ -1755,6 +1762,15 @@ static void HandleKeysSpecial(Key key)
       DumpBrush_Small();
     }
   }
+
+  /* special key shortcuts for all game modes */
+  if (is_string_suffix(cheat_input, ":dump-event-actions") ||
+      is_string_suffix(cheat_input, ":dea") ||
+      is_string_suffix(cheat_input, ":DEA"))
+  {
+    DumpGadgetIdentifiers();
+    DumpScreenIdentifiers();
+  }
 }
 
 void HandleKeysDebug(Key key)
@@ -2017,7 +2033,7 @@ void HandleKey(Key key, int key_status)
   if (game_status == GAME_MODE_MAIN &&
       (key == setup.shortcut.toggle_pause || key == KSYM_space))
   {
-    StartGameActions(options.network, setup.autorecord, level.random_seed);
+    StartGameActions(network.enabled, setup.autorecord, level.random_seed);
 
     return;
   }
@@ -2208,10 +2224,8 @@ void HandleEventActions()
     HandleJoystick();
   }
 
-#if defined(NETWORK_AVALIABLE)
-  if (options.network)
+  if (network.enabled)
     HandleNetworking();
-#endif
 
   switch (game_status)
   {
@@ -2418,24 +2432,38 @@ void HandleJoystick()
 void HandleSpecialGameControllerButtons(Event *event)
 {
 #if defined(TARGET_SDL2)
+  int key_status;
+  Key key;
+
   switch (event->type)
   {
     case SDL_CONTROLLERBUTTONDOWN:
-      if (event->cbutton.button == SDL_CONTROLLER_BUTTON_START)
-       HandleKey(KSYM_space, KEY_PRESSED);
-      else if (event->cbutton.button == SDL_CONTROLLER_BUTTON_BACK)
-       HandleKey(KSYM_Escape, KEY_PRESSED);
-
+      key_status = KEY_PRESSED;
       break;
 
     case SDL_CONTROLLERBUTTONUP:
-      if (event->cbutton.button == SDL_CONTROLLER_BUTTON_START)
-       HandleKey(KSYM_space, KEY_RELEASED);
-      else if (event->cbutton.button == SDL_CONTROLLER_BUTTON_BACK)
-       HandleKey(KSYM_Escape, KEY_RELEASED);
+      key_status = KEY_RELEASED;
+      break;
 
+    default:
+      return;
+  }
+
+  switch (event->cbutton.button)
+  {
+    case SDL_CONTROLLER_BUTTON_START:
+      key = KSYM_space;
+      break;
+
+    case SDL_CONTROLLER_BUTTON_BACK:
+      key = KSYM_Escape;
       break;
+
+    default:
+      return;
   }
+
+  HandleKey(key, key_status);
 #endif
 }
 
@@ -2468,3 +2496,18 @@ void HandleSpecialGameControllerKeys(Key key, int key_status)
 #endif
 #endif
 }
+
+boolean DoKeysymAction(int keysym)
+{
+  if (keysym < 0)
+  {
+    Key key = (Key)(-keysym);
+
+    HandleKey(key, KEY_PRESSED);
+    HandleKey(key, KEY_RELEASED);
+
+    return TRUE;
+  }
+
+  return FALSE;
+}