X-Git-Url: https://git.artsoft.org/?p=rocksndiamonds.git;a=blobdiff_plain;f=src%2Fevents.c;h=05d4b351e8b868b9307917dc4fcba7483fd0b3eb;hp=7e1f293f9b067cf5792ac4385f1e24a708a3e8b4;hb=be5bf9c7912238465ec23cec535277ebc1a4a21b;hpb=d3e24bbfb70edb9a805806345eede28c7129baf8 diff --git a/src/events.c b/src/events.c index 7e1f293f..05d4b351 100644 --- a/src/events.c +++ b/src/events.c @@ -39,6 +39,8 @@ static int cursor_mode_last = CURSOR_DEFAULT; static unsigned int special_cursor_delay = 0; static unsigned int special_cursor_delay_value = 1000; +static boolean virtual_button_pressed = FALSE; + // forward declarations for internal use static void HandleNoEvent(void); @@ -266,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: @@ -722,6 +728,8 @@ static void HandleFingerEvent_VirtualButtons(FingerEvent *event) "KEY_PRESSED"); int i; + virtual_button_pressed = (key_status == KEY_PRESSED && key != KSYM_UNDEFINED); + // for any touch input event, enable overlay buttons (if activated) SetOverlayEnabled(TRUE); @@ -1452,9 +1460,15 @@ void HandleKeyEvent(KeyEvent *event) // always map the "back" button to the "escape" key on Android devices key = KSYM_Escape; } + else if (key == KSYM_Menu) + { + // the "menu" button can be used to toggle displaying virtual buttons + if (key_status == KEY_PRESSED) + SetOverlayEnabled(!GetOverlayEnabled()); + } else { - // for any key event other than "back" button, disable overlay buttons + // for any other "real" key event, disable virtual buttons SetOverlayEnabled(FALSE); } #endif @@ -1512,9 +1526,63 @@ void HandleClientMessageEvent(ClientMessageEvent *event) CloseAllAndExit(0); } -void HandleWindowManagerEvent(Event *event) +static void HandleDropFileEventExt(char *filename) +{ + 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) { - SDLHandleWindowManagerEvent(event); + 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) @@ -1539,10 +1607,13 @@ void HandleButton(int mx, int my, int button, int button_nr) #if defined(PLATFORM_ANDROID) // when playing, only handle gadgets when using "follow finger" controls // or when using touch controls in combination with the MM game engine + // or when using gadgets that do not overlap with virtual buttons handle_gadgets = (game_status != GAME_MODE_PLAYING || level.game_engine_type == GAME_ENGINE_TYPE_MM || - strEqual(setup.touch.control_type, TOUCH_CONTROL_FOLLOW_FINGER)); + strEqual(setup.touch.control_type, TOUCH_CONTROL_FOLLOW_FINGER) || + (strEqual(setup.touch.control_type, TOUCH_CONTROL_VIRTUAL_BUTTONS) && + !virtual_button_pressed)); #endif if (HandleGlobalAnimClicks(mx, my, button)) @@ -1778,11 +1849,14 @@ static void HandleKeysSpecial(Key key) } } -void HandleKeysDebug(Key key) +boolean HandleKeysDebug(Key key, int key_status) { #ifdef DEBUG int i; + if (key_status != KEY_PRESSED) + return FALSE; + if (game_status == GAME_MODE_PLAYING || !setup.debug.frame_delay_game_only) { boolean mod_key_pressed = ((GetKeyModState() & KMOD_Valid) != KMOD_None); @@ -1809,7 +1883,7 @@ void HandleKeysDebug(Key key) else Error(ERR_DEBUG, "frame delay == 0 ms (maximum speed)"); - break; + return TRUE; } } } @@ -1822,14 +1896,20 @@ void HandleKeysDebug(Key key) Error(ERR_DEBUG, "debug mode %s", (options.debug ? "enabled" : "disabled")); + + return TRUE; } else if (key == KSYM_v) { Error(ERR_DEBUG, "currently using game engine version %d", game.engine_version); + + return TRUE; } } #endif + + return FALSE; } void HandleKey(Key key, int key_status) @@ -1856,6 +1936,9 @@ void HandleKey(Key key, int key_status) int joy = 0; int i; + if (HandleKeysDebug(key, key_status)) + return; // do not handle already processed keys again + // map special keys (media keys / remote control buttons) to default keys if (key == KSYM_PlayPause) key = KSYM_space; @@ -2081,10 +2164,7 @@ void HandleKey(Key key, int key_status) HandleKeysSpecial(key); if (HandleGadgetsKeyInput(key)) - { - if (key != KSYM_Escape) // always allow ESC key to be handled - key = KSYM_UNDEFINED; - } + return; // do not handle already processed keys again switch (game_status) { @@ -2201,8 +2281,6 @@ void HandleKey(Key key, int key_status) return; } } - - HandleKeysDebug(key); } void HandleNoEvent(void) @@ -2340,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)