added selecting new level set if dropped as zip file into window
[rocksndiamonds.git] / src / events.c
index 8c8ae5a910f25ee6fb41a11d0661dad4bd062e0a..05d4b351e8b868b9307917dc4fcba7483fd0b3eb 100644 (file)
@@ -268,8 +268,12 @@ void HandleOtherEvents(Event *event)
       HandleJoystickEvent(event);
       break;
 
-    case SDL_SYSWMEVENT:
-      HandleWindowManagerEvent(event);
+    case SDL_DROPFILE:
+      HandleDropFileEvent(event);
+      break;
+
+    case SDL_DROPTEXT:
+      HandleDropTextEvent(event);
       break;
 
     default:
@@ -1522,9 +1526,63 @@ void HandleClientMessageEvent(ClientMessageEvent *event)
     CloseAllAndExit(0);
 }
 
-void HandleWindowManagerEvent(Event *event)
+static void HandleDropFileEventExt(char *filename)
 {
-  SDLHandleWindowManagerEvent(event);
+  Error(ERR_DEBUG, "DROP FILE EVENT: '%s'", filename);
+
+  // check and extract dropped zip files into correct user data directory
+  if (strSuffixLower(filename, ".zip"))
+  {
+    int tree_type = GetZipFileTreeType(filename);
+    char *directory = TREE_USERDIR(tree_type);
+
+    if (directory == NULL)
+    {
+      Error(ERR_WARN, "zip file '%s' has invalid content!", filename);
+
+      return;
+    }
+
+    char *top_dir = ExtractZipFileIntoDirectory(filename, directory, tree_type);
+
+    if (top_dir != NULL)
+    {
+      AddUserTreeSetToTreeInfo(top_dir, tree_type);
+
+      // when adding new level set, select it as the new current level set
+      if (tree_type == TREE_TYPE_LEVEL_DIR)
+      {
+       // change current level set to newly added level set from zip file
+       leveldir_current = getTreeInfoFromIdentifier(leveldir_first, top_dir);
+
+       // change current level number to first level of newly added level set
+       level_nr = leveldir_current->first_level;
+
+       // when in main menu, redraw screen to reflect changed level set
+       if (game_status == GAME_MODE_MAIN)
+         DrawMainMenu();
+      }
+    }
+  }
+}
+
+static void HandleDropTextEventExt(char *text)
+{
+  Error(ERR_DEBUG, "DROP TEXT EVENT: '%s'", text);
+}
+
+void HandleDropFileEvent(Event *event)
+{
+  HandleDropFileEventExt(event->drop.file);
+
+  SDL_free(event->drop.file);
+}
+
+void HandleDropTextEvent(Event *event)
+{
+  HandleDropTextEventExt(event->drop.file);
+
+  SDL_free(event->drop.file);
 }
 
 void HandleButton(int mx, int my, int button, int button_nr)
@@ -1849,9 +1907,9 @@ boolean HandleKeysDebug(Key key, int key_status)
       return TRUE;
     }
   }
+#endif
 
   return FALSE;
-#endif
 }
 
 void HandleKey(Key key, int key_status)
@@ -2360,6 +2418,16 @@ void HandleJoystick(void)
     return;
   }
 
+  if (newbutton && (game_status == GAME_MODE_PSEUDO_TYPENAME ||
+                   anyTextGadgetActive()))
+  {
+    // leave name input in main menu or text input gadget
+    HandleKey(KSYM_Escape, KEY_PRESSED);
+    HandleKey(KSYM_Escape, KEY_RELEASED);
+
+    return;
+  }
+
   if (level.game_engine_type == GAME_ENGINE_TYPE_MM)
   {
     if (game_status == GAME_MODE_PLAYING)