diff --git a/resources/easyrpg-player.6.adoc b/resources/easyrpg-player.6.adoc index 36793227ad..95496f724b 100644 --- a/resources/easyrpg-player.6.adoc +++ b/resources/easyrpg-player.6.adoc @@ -48,6 +48,9 @@ for some additional binary patches. *--show-fps*:: Enable frames per second counter. +*--enable-mouse*:: + Use mouse click for decision and scroll wheel for lists. + *--hide-title*:: Hide the title background image and center the command menu. diff --git a/resources/unix/bash-completion/easyrpg-player b/resources/unix/bash-completion/easyrpg-player index 484344308f..debc95c608 100644 --- a/resources/unix/bash-completion/easyrpg-player +++ b/resources/unix/bash-completion/easyrpg-player @@ -1,5 +1,5 @@ # bash completion script for easyrpg-player -# (c) carstene1ns 2016 +# (c) carstene1ns 2016-2017 # available under the MIT license _easyrpg-player () @@ -13,13 +13,12 @@ _easyrpg-player () prev=${COMP_WORDS[COMP_CWORD-1]} # all possible options - ouropts='--battle-test --disable-audio --disable-rtp --encoding --engine \ - --fullscreen --show-fps --hide-title --load-game-id --new-game \ - --project-path --record-input --replay-input --seed --start-map-id \ - --start-position --save-path --start-party --test-play --window -v \ - --version -h --help' - rpgrtopts='BattleTest battletest HideTitle hidetitle TestPlay testplay \ - Window window' + ouropts='--battle-test --disable-audio --disable-rtp --enable-mouse --encoding \ + --engine --fullscreen -h --help --hide-title --load-game-id --new-game \ + --project-path --record-input --replay-input --save-path --seed --show-fps \ + --start-map-id --start-party --start-position --test-play --window -v \ + --version' + rpgrtopts='BattleTest battletest HideTitle hidetitle TestPlay testplay Window window' engines='rpg2k rpg2kv150 rpg2k3 rpg2k3v105 rpg2k3e' # first list all special cases @@ -52,8 +51,7 @@ _easyrpg-player () return ;; # argument required but no completions available - --@(battle-test|encoding|seed|start-position|start-party)| \ - BattleTest|battletest) + --@(battle-test|encoding|seed|start-position|start-party)|BattleTest|battletest) return ;; # these have no argument and shall be used exclusively diff --git a/src/input_buttons.h b/src/input_buttons.h index 05b800fd54..2da9dcd47a 100644 --- a/src/input_buttons.h +++ b/src/input_buttons.h @@ -55,9 +55,11 @@ namespace Input { TOGGLE_FPS, TAKE_SCREENSHOT, SHOW_LOG, + RESET, PAGE_UP, PAGE_DOWN, - RESET, + SCROLL_UP, + SCROLL_DOWN, BUTTON_COUNT }; diff --git a/src/input_buttons_desktop.cpp b/src/input_buttons_desktop.cpp index e7f1d5bfab..4840ecb251 100644 --- a/src/input_buttons_desktop.cpp +++ b/src/input_buttons_desktop.cpp @@ -85,6 +85,8 @@ void Input::InitButtons() { buttons[DECISION].push_back(Keys::MOUSE_LEFT); buttons[CANCEL].push_back(Keys::MOUSE_RIGHT); buttons[SHIFT].push_back(Keys::MOUSE_MIDDLE); + buttons[SCROLL_UP].push_back(Keys::MOUSE_SCROLLUP); + buttons[SCROLL_DOWN].push_back(Keys::MOUSE_SCROLLDOWN); #endif #if defined(USE_JOYSTICK) && defined(SUPPORT_JOYSTICK) diff --git a/src/keys.h b/src/keys.h index 44513d0f4f..7a2c9553f8 100644 --- a/src/keys.h +++ b/src/keys.h @@ -134,6 +134,8 @@ namespace Input { MOUSE_MIDDLE, MOUSE_XBUTTON1, MOUSE_XBUTTON2, + MOUSE_SCROLLUP, + MOUSE_SCROLLDOWN, #endif #if defined(USE_JOYSTICK) && defined(SUPPORT_JOYSTICK) diff --git a/src/options.h b/src/options.h index 23cea7f20e..cb13a53d2f 100644 --- a/src/options.h +++ b/src/options.h @@ -86,7 +86,7 @@ #endif #define USE_KEYBOARD -//#define USE_MOUSE +#define USE_MOUSE #define USE_JOYSTICK #define USE_JOYSTICK_HAT #define USE_JOYSTICK_AXIS diff --git a/src/player.cpp b/src/player.cpp index 7dc281b200..932af858a6 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -90,6 +90,7 @@ namespace Player { int start_map_id; bool no_rtp_flag; bool no_audio_flag; + bool mouse_flag; std::string encoding; std::string escape_symbol; int engine; @@ -418,6 +419,7 @@ void Player::ParseCommandLine(int argc, char *argv[]) { start_map_id = -1; no_rtp_flag = false; no_audio_flag = false; + mouse_flag = false; std::vector args; @@ -445,6 +447,9 @@ void Player::ParseCommandLine(int argc, char *argv[]) { else if (*it == "--show-fps") { fps_flag = true; } + else if (*it == "--enable-mouse") { + mouse_flag = true; + } else if (*it == "testplay" || *it == "--test-play") { debug_flag = true; } @@ -926,6 +931,7 @@ R"(EasyRPG Player - An open source interpreter for RPG Maker 2000/2003 games. rpg2k3e - RPG Maker 2003 (English release) engine --fullscreen Start in fullscreen mode. --show-fps Enable frames per second counter. + --enable-mouse Use mouse click for decision and scroll wheel for lists --hide-title Hide the title background image and center the command menu. --load-game-id N Skip the title scene and load SaveN.lsd diff --git a/src/player.h b/src/player.h index 6616112f13..cf8de02235 100644 --- a/src/player.h +++ b/src/player.h @@ -184,6 +184,9 @@ namespace Player { /** FPS flag, if true will display frames per second counter. */ extern bool fps_flag; + /** Mouse flag, if true enables mouse click and scroll wheel */ + extern bool mouse_flag; + /** Battle Test flag, if true will run battle test. */ extern bool battle_test_flag; diff --git a/src/scene_file.cpp b/src/scene_file.cpp index 3d1615afe1..a82d7a6e08 100644 --- a/src/scene_file.cpp +++ b/src/scene_file.cpp @@ -141,16 +141,18 @@ void Scene_File::Update() { unsigned int old_index = index; unsigned int max_index = file_windows.size() - 1; - if (Input::IsRepeated(Input::DOWN)) { - if (Input::IsTriggered(Input::DOWN) || index < max_index) { + if (Input::IsRepeated(Input::DOWN) || Input::IsTriggered(Input::SCROLL_DOWN)) { + if (Input::IsTriggered(Input::DOWN) || Input::IsTriggered(Input::SCROLL_DOWN) + || index < max_index) { Game_System::SePlay(Game_System::GetSystemSE(Game_System::SFX_Cursor)); index = (index + 1) % file_windows.size(); } //top_index = std::max(top_index, index - 3 + 1); } - if (Input::IsRepeated(Input::UP)) { - if (Input::IsTriggered(Input::UP) || index >= 1) { + if (Input::IsRepeated(Input::UP) || Input::IsTriggered(Input::SCROLL_UP)) { + if (Input::IsTriggered(Input::UP) || Input::IsTriggered(Input::SCROLL_UP) + || index >= 1) { Game_System::SePlay(Game_System::GetSystemSE(Game_System::SFX_Cursor)); index = (index + max_index) % file_windows.size(); } diff --git a/src/sdl_ui.cpp b/src/sdl_ui.cpp index 338db75408..24b35aaf36 100644 --- a/src/sdl_ui.cpp +++ b/src/sdl_ui.cpp @@ -555,6 +555,12 @@ void SdlUi::ToggleZoom() { void SdlUi::ProcessEvents() { SDL_Event evnt; + // Reset Mouse scroll + if (Player::mouse_flag) { + keys[Input::Keys::MOUSE_SCROLLUP] = false; + keys[Input::Keys::MOUSE_SCROLLDOWN] = false; + } + // Poll SDL events and process them while (SDL_PollEvent(&evnt)) { ProcessEvent(evnt); @@ -642,6 +648,12 @@ void SdlUi::ProcessEvent(SDL_Event &evnt) { ProcessMouseMotionEvent(evnt); return; +#if SDL_MAJOR_VERSION>1 + case SDL_MOUSEWHEEL: + ProcessMouseWheelEvent(evnt); + return; +#endif + case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: ProcessMouseButtonEvent(evnt); @@ -681,11 +693,13 @@ void SdlUi::ProcessActiveEvent(SDL_Event &evnt) { state = evnt.window.event; #endif + if ( #if SDL_MAJOR_VERSION==1 - if (state == SDL_APPINPUTFOCUS && !evnt.active.gain) { + (state == SDL_APPINPUTFOCUS && !evnt.active.gain) #else - if (state == SDL_WINDOWEVENT_FOCUS_LOST) { + state == SDL_WINDOWEVENT_FOCUS_LOST #endif + ) { Player::Pause(); @@ -792,16 +806,50 @@ void SdlUi::ProcessKeyUpEvent(SDL_Event &evnt) { #endif } -void SdlUi::ProcessMouseMotionEvent(SDL_Event& /* evnt */) { +void SdlUi::ProcessMouseMotionEvent(SDL_Event& evnt) { #if defined(USE_MOUSE) && defined(SUPPORT_MOUSE) mouse_focus = true; mouse_x = evnt.motion.x; mouse_y = evnt.motion.y; +#else + /* unused */ + (void) evnt; +#endif +} + +#if SDL_MAJOR_VERSION>1 +void SdlUi::ProcessMouseWheelEvent(SDL_Event& evnt) { +#if defined(USE_MOUSE) && defined(SUPPORT_MOUSE) + if (!Player::mouse_flag) + return; + + // Ignore Finger (touch) events here + if (evnt.wheel.which == SDL_TOUCH_MOUSEID) + return; + + int amount = evnt.wheel.y; + // translate direction + if (evnt.wheel.direction == SDL_MOUSEWHEEL_FLIPPED) + amount *= -1; + + keys[Input::Keys::MOUSE_SCROLLUP] = amount > 0; + keys[Input::Keys::MOUSE_SCROLLDOWN] = amount < 0; +#else + /* unused */ + (void) evnt; #endif } +#endif -void SdlUi::ProcessMouseButtonEvent(SDL_Event& /* evnt */) { +void SdlUi::ProcessMouseButtonEvent(SDL_Event& evnt) { #if defined(USE_MOUSE) && defined(SUPPORT_MOUSE) + if (!Player::mouse_flag) + return; + + // Ignore Finger (touch) events here + if (evnt.button.which == SDL_TOUCH_MOUSEID) + return; + switch (evnt.button.button) { case SDL_BUTTON_LEFT: keys[Input::Keys::MOUSE_LEFT] = evnt.button.state == SDL_PRESSED; @@ -813,6 +861,9 @@ void SdlUi::ProcessMouseButtonEvent(SDL_Event& /* evnt */) { keys[Input::Keys::MOUSE_RIGHT] = evnt.button.state == SDL_PRESSED; break; } +#else + /* unused */ + (void) evnt; #endif } diff --git a/src/sdl_ui.h b/src/sdl_ui.h index 0b7b9a9058..febe364304 100644 --- a/src/sdl_ui.h +++ b/src/sdl_ui.h @@ -111,6 +111,8 @@ class SdlUi : public BaseUi { void ProcessJoystickHatEvent(SDL_Event &evnt); void ProcessJoystickAxisEvent(SDL_Event &evnt); #if SDL_MAJOR_VERSION>1 + void ProcessMouseWheelEvent(SDL_Event &evnt); + void ProcessFingerDownEvent(SDL_Event & evnt); void ProcessFingerUpEvent(SDL_Event & evnt); void ProcessFingerEvent(SDL_Event & evnt, bool finger_down); diff --git a/src/window_battlecommand.cpp b/src/window_battlecommand.cpp index 5c0e186294..7edfbaa86f 100644 --- a/src/window_battlecommand.cpp +++ b/src/window_battlecommand.cpp @@ -61,12 +61,12 @@ void Window_BattleCommand::Update() { size_t num_commands = commands.size(); int old_index = index; if (active && num_commands > 0 && index >= 0) { - if (Input::IsRepeated(Input::DOWN)) { + if (Input::IsRepeated(Input::DOWN) || Input::IsTriggered(Input::SCROLL_DOWN)) { Game_System::SePlay(Game_System::GetSystemSE(Game_System::SFX_Cursor)); index++; } - if (Input::IsRepeated(Input::UP)) { + if (Input::IsRepeated(Input::UP) || Input::IsTriggered(Input::SCROLL_UP)) { Game_System::SePlay(Game_System::GetSystemSE(Game_System::SFX_Cursor)); index--; } diff --git a/src/window_battleoption.cpp b/src/window_battleoption.cpp index b3102d86d9..329afef889 100644 --- a/src/window_battleoption.cpp +++ b/src/window_battleoption.cpp @@ -59,12 +59,12 @@ void Window_BattleOption::Update() { int num_commands = commands.size(); if (active && num_commands > 0 && index >= 0) { - if (Input::IsRepeated(Input::DOWN)) { + if (Input::IsRepeated(Input::DOWN) || Input::IsTriggered(Input::SCROLL_DOWN)) { Game_System::SePlay(Game_System::GetSystemSE(Game_System::SFX_Cursor)); index++; } - if (Input::IsRepeated(Input::UP)) { + if (Input::IsRepeated(Input::UP) || Input::IsTriggered(Input::SCROLL_UP)) { Game_System::SePlay(Game_System::GetSystemSE(Game_System::SFX_Cursor)); index--; } diff --git a/src/window_battlestatus.cpp b/src/window_battlestatus.cpp index 64cfea654a..2fbdfc350c 100644 --- a/src/window_battlestatus.cpp +++ b/src/window_battlestatus.cpp @@ -242,7 +242,7 @@ void Window_BattleStatus::Update() { } if (active && index >= 0) { - if (Input::IsRepeated(Input::DOWN)) { + if (Input::IsRepeated(Input::DOWN) || Input::IsTriggered(Input::SCROLL_DOWN)) { Game_System::SePlay(Game_System::GetSystemSE(Game_System::SFX_Cursor)); for (int i = 1; i < item_max; i++) { int new_index = (index + i) % item_max; @@ -252,7 +252,7 @@ void Window_BattleStatus::Update() { } } } - if (Input::IsRepeated(Input::UP)) { + if (Input::IsRepeated(Input::UP) || Input::IsTriggered(Input::SCROLL_UP)) { Game_System::SePlay(Game_System::GetSystemSE(Game_System::SFX_Cursor)); for (int i = item_max - 1; i > 0; i--) { int new_index = (index + i) % item_max; diff --git a/src/window_selectable.cpp b/src/window_selectable.cpp index 23832935a9..c9fe7ace51 100644 --- a/src/window_selectable.cpp +++ b/src/window_selectable.cpp @@ -124,14 +124,16 @@ void Window_Selectable::UpdateCursorRect() { void Window_Selectable::Update() { Window_Base::Update(); if (active && item_max > 0 && index >= 0) { - if (Input::IsRepeated(Input::DOWN)) { - if ((column_max == 1 && Input::IsTriggered(Input::DOWN)) || index < item_max - column_max) { + if (Input::IsRepeated(Input::DOWN) || Input::IsTriggered(Input::SCROLL_DOWN)) { + if (index < item_max - column_max || (column_max == 1 && + (Input::IsTriggered(Input::DOWN) || Input::IsTriggered(Input::SCROLL_DOWN)))) { Game_System::SePlay(Game_System::GetSystemSE(Game_System::SFX_Cursor)); index = (index + column_max) % item_max; } } - if (Input::IsRepeated(Input::UP)) { - if ((column_max == 1 && Input::IsTriggered(Input::UP)) || index >= column_max) { + if (Input::IsRepeated(Input::UP) || Input::IsTriggered(Input::SCROLL_UP)) { + if (index >= column_max || (column_max == 1 && + (Input::IsTriggered(Input::UP) || Input::IsTriggered(Input::SCROLL_UP)))) { Game_System::SePlay(Game_System::GetSystemSE(Game_System::SFX_Cursor)); index = (index - column_max + item_max) % item_max; } diff --git a/src/window_shop.cpp b/src/window_shop.cpp index a8cc41eb5f..2ec9665a93 100644 --- a/src/window_shop.cpp +++ b/src/window_shop.cpp @@ -157,7 +157,7 @@ void Window_Shop::Update() { switch (mode) { case Scene_Shop::BuySellLeave: case Scene_Shop::BuySellLeave2: - if (Input::IsRepeated(Input::DOWN)) { + if (Input::IsRepeated(Input::DOWN) || Input::IsTriggered(Input::SCROLL_DOWN)) { if (index < leave_index) { index++; } @@ -166,7 +166,7 @@ void Window_Shop::Update() { } Game_System::SePlay(Game_System::GetSystemSE(Game_System::SFX_Cursor)); } - if (Input::IsRepeated(Input::UP)) { + if (Input::IsRepeated(Input::UP) || Input::IsTriggered(Input::SCROLL_UP)) { if (index > 1) { index--; } diff --git a/src/window_shopnumber.cpp b/src/window_shopnumber.cpp index 1c0282976a..f45a15d96b 100644 --- a/src/window_shopnumber.cpp +++ b/src/window_shopnumber.cpp @@ -68,9 +68,11 @@ void Window_ShopNumber::Update() { number++; } else if (Input::IsRepeated(Input::LEFT) && number > 1) { number--; - } else if (Input::IsRepeated(Input::UP) && number < item_max) { + } else if ((Input::IsRepeated(Input::UP) || Input::IsTriggered(Input::SCROLL_UP)) + && number < item_max) { number = min(number + 10, item_max); - } else if (Input::IsRepeated(Input::DOWN) && number > 1) { + } else if ((Input::IsRepeated(Input::DOWN) || Input::IsTriggered(Input::SCROLL_DOWN)) + && number > 1) { number = max(number - 10, 1); }