From 2f57e3f69d5e3ea5e8420951609e1256b3f2bb73 Mon Sep 17 00:00:00 2001 From: cpasjuste Date: Wed, 26 Apr 2017 14:55:46 +0200 Subject: [PATCH] PFBA: add option to configure menu(s) button(s) PFBA: minor cleanup/changes --- pfba/deps/libcross2d/src/sdl2/sdl2_input.cpp | 4 +- pfba/deps/libcross2d/src/sfml/sfml_input.cpp | 59 +++++++++++--------- pfba/deps/libcross2d/src/skeleton/input.h | 12 ++-- pfba/gui/config.cpp | 20 ++++++- pfba/gui/config.h | 40 +++++++++---- pfba/gui/gui.cpp | 17 +++--- pfba/gui/option.cpp | 6 +- pfba/gui/option.h | 5 +- pfba/run.cpp | 18 +++--- 9 files changed, 112 insertions(+), 69 deletions(-) diff --git a/pfba/deps/libcross2d/src/sdl2/sdl2_input.cpp b/pfba/deps/libcross2d/src/sdl2/sdl2_input.cpp index 3f98ba1..632a6ab 100644 --- a/pfba/deps/libcross2d/src/sdl2/sdl2_input.cpp +++ b/pfba/deps/libcross2d/src/sdl2/sdl2_input.cpp @@ -16,7 +16,9 @@ static int key_id[KEY_COUNT]{ Input::Key::KEY_FIRE3, Input::Key::KEY_FIRE4, Input::Key::KEY_FIRE5, - Input::Key::KEY_FIRE6 + Input::Key::KEY_FIRE6, + Input::Key::KEY_MENU1, + Input::Key::KEY_MENU2 }; SDL2Input::SDL2Input() { diff --git a/pfba/deps/libcross2d/src/sfml/sfml_input.cpp b/pfba/deps/libcross2d/src/sfml/sfml_input.cpp index 94caa1d..786cbf0 100644 --- a/pfba/deps/libcross2d/src/sfml/sfml_input.cpp +++ b/pfba/deps/libcross2d/src/sfml/sfml_input.cpp @@ -18,7 +18,9 @@ static int key_id[KEY_COUNT]{ Input::Key::KEY_FIRE3, Input::Key::KEY_FIRE4, Input::Key::KEY_FIRE5, - Input::Key::KEY_FIRE6 + Input::Key::KEY_FIRE6, + Input::Key::KEY_MENU1, + Input::Key::KEY_MENU2 }; SFMLInput::SFMLInput(SFMLRenderer *rdr) { @@ -95,14 +97,13 @@ Input::Player *SFMLInput::Update(int rotate) { return players; } - /* if (event.type == sf::Event::KeyPressed) { printf("%i\n", (int) event.key.code); } if (event.type == sf::Event::JoystickButtonPressed) { printf("%i\n", (int) event.joystickButton.button); } - */ + } for (int i = 0; i < PLAYER_COUNT; i++) { @@ -134,30 +135,34 @@ void SFMLInput::process_axis(Input::Player &player, int rotate) { } // X AXIS - if (sf::Joystick::hasAxis(player.id, sf::Joystick::X)) { - int x = (int) sf::Joystick::getAxisPosition(player.id, sf::Joystick::X) * 320; + if (sf::Joystick::hasAxis((unsigned int) player.id, sf::Joystick::X)) { + int x = (int) sf::Joystick::getAxisPosition((unsigned int) player.id, sf::Joystick::X) * 320; if (x > player.dead_zone) { - player.lx.value = x; - player.state |= (rotate == 1) ? Input::Key::KEY_DOWN : (rotate == 3) ? Input::Key::KEY_UP : Input::Key::KEY_RIGHT; + player.lx.value = (short) x; + player.state |= (rotate == 1) ? Input::Key::KEY_DOWN : (rotate == 3) ? Input::Key::KEY_UP + : Input::Key::KEY_RIGHT; } else if (x < -player.dead_zone) { - player.lx.value = x; - player.state |= (rotate == 1) ? Input::Key::KEY_UP : (rotate == 3) ? Input::Key::KEY_DOWN : Input::Key::KEY_LEFT; + player.lx.value = (short) x; + player.state |= (rotate == 1) ? Input::Key::KEY_UP : (rotate == 3) ? Input::Key::KEY_DOWN + : Input::Key::KEY_LEFT; } else { player.lx.value = 0; } } // Y AXIS - if (sf::Joystick::hasAxis(player.id, sf::Joystick::Y)) { - int y = (int) sf::Joystick::getAxisPosition(player.id, sf::Joystick::Y) * 320; + if (sf::Joystick::hasAxis((unsigned int) player.id, sf::Joystick::Y)) { + int y = (int) sf::Joystick::getAxisPosition((unsigned int) player.id, sf::Joystick::Y) * 320; if (y > player.dead_zone) { - player.ly.value = y; - player.state |= (rotate == 1) ? Input::Key::KEY_LEFT : (rotate == 3) ? Input::Key::KEY_RIGHT : Input::Key::KEY_DOWN; + player.ly.value = (short) y; + player.state |= (rotate == 1) ? Input::Key::KEY_LEFT : (rotate == 3) ? Input::Key::KEY_RIGHT + : Input::Key::KEY_DOWN; } else if (y < -player.dead_zone) { - player.state |= (rotate == 1) ? Input::Key::KEY_RIGHT : (rotate == 3) ? Input::Key::KEY_LEFT : Input::Key::KEY_UP; - player.ly.value = y; + player.state |= (rotate == 1) ? Input::Key::KEY_RIGHT : (rotate == 3) ? Input::Key::KEY_LEFT + : Input::Key::KEY_UP; + player.ly.value = (short) y; } else { - player.ly.value = 0; + player.ly.value = 0;/**/ } } } @@ -169,22 +174,26 @@ void SFMLInput::process_hat(Input::Player &player, int rotate) { } // X AXIS - if (sf::Joystick::hasAxis(player.id, sf::Joystick::PovX)) { - int x = (int) sf::Joystick::getAxisPosition(player.id, sf::Joystick::PovX) * 320; + if (sf::Joystick::hasAxis((unsigned int) player.id, sf::Joystick::PovX)) { + int x = (int) sf::Joystick::getAxisPosition((unsigned int) player.id, sf::Joystick::PovX) * 320; if (x > player.dead_zone) { - player.state |= (rotate == 1) ? Input::Key::KEY_DOWN : (rotate == 3) ? Input::Key::KEY_UP : Input::Key::KEY_RIGHT; + player.state |= (rotate == 1) ? Input::Key::KEY_DOWN : (rotate == 3) ? Input::Key::KEY_UP + : Input::Key::KEY_RIGHT; } else if (x < -player.dead_zone) { - player.state |= (rotate == 1) ? Input::Key::KEY_UP : (rotate == 3) ? Input::Key::KEY_DOWN : Input::Key::KEY_LEFT; + player.state |= (rotate == 1) ? Input::Key::KEY_UP : (rotate == 3) ? Input::Key::KEY_DOWN + : Input::Key::KEY_LEFT; } } // Y AXIS - if (sf::Joystick::hasAxis(player.id, sf::Joystick::PovY)) { - int y = (int) sf::Joystick::getAxisPosition(player.id, sf::Joystick::PovY) * 320; + if (sf::Joystick::hasAxis((unsigned int) player.id, sf::Joystick::PovY)) { + int y = (int) sf::Joystick::getAxisPosition((unsigned int) player.id, sf::Joystick::PovY) * 320; if (y > player.dead_zone) { - player.state |= (rotate == 1) ? Input::Key::KEY_LEFT : (rotate == 3) ? Input::Key::KEY_RIGHT : Input::Key::KEY_DOWN; + player.state |= (rotate == 1) ? Input::Key::KEY_LEFT : (rotate == 3) ? Input::Key::KEY_RIGHT + : Input::Key::KEY_DOWN; } else if (y < -player.dead_zone) { - player.state |= (rotate == 1) ? Input::Key::KEY_RIGHT : (rotate == 3) ? Input::Key::KEY_LEFT : Input::Key::KEY_UP; + player.state |= (rotate == 1) ? Input::Key::KEY_RIGHT : (rotate == 3) ? Input::Key::KEY_LEFT + : Input::Key::KEY_UP; } } @@ -202,7 +211,7 @@ void SFMLInput::process_buttons(Input::Player &player, int rotate) { if (mapping < 0) mapping = 0; - if (sf::Joystick::isButtonPressed(player.id, mapping)) { + if (sf::Joystick::isButtonPressed((unsigned int) player.id, (unsigned int) mapping)) { if (rotate && key_id[i] == Input::Key::KEY_UP) { if (rotate == 1) { player.state |= Input::Key::KEY_RIGHT; diff --git a/pfba/deps/libcross2d/src/skeleton/input.h b/pfba/deps/libcross2d/src/skeleton/input.h index 2928189..8cc3d87 100644 --- a/pfba/deps/libcross2d/src/skeleton/input.h +++ b/pfba/deps/libcross2d/src/skeleton/input.h @@ -9,11 +9,11 @@ #include #define PLAYER_COUNT 4 -#define KEY_COUNT 12 +#define KEY_COUNT 14 -#define EV_RESIZE 0x1000 -#define EV_QUIT 0x2000 -#define EV_REFRESH 0x4000 +#define EV_RESIZE 0x4000 +#define EV_QUIT 0x8000 +#define EV_REFRESH 0x10000 class Input { @@ -31,7 +31,9 @@ class Input { KEY_FIRE3 = 0x0100, KEY_FIRE4 = 0x0200, KEY_FIRE5 = 0x0400, - KEY_FIRE6 = 0x0800 + KEY_FIRE6 = 0x0800, + KEY_MENU1 = 0x1000, + KEY_MENU2 = 0x2000, }; struct Axis { diff --git a/pfba/gui/config.cpp b/pfba/gui/config.cpp index 987e070..51856c5 100644 --- a/pfba/gui/config.cpp +++ b/pfba/gui/config.cpp @@ -81,11 +81,11 @@ Config::Config(const std::string &cfgPath, Renderer *renderer) { // default rom config options_gui.push_back(Option("EMULATION", {"EMULATION"}, 0, Option::Index::MENU_ROM_OPTIONS, Option::Type::MENU)); - options_gui.push_back(Option("SCALING", {"NONE", "2X", "FIT", "FIT 4:3", "FULL"}, 3, Option::Index::ROM_SCALING)); + options_gui.push_back(Option("SCALING", {"NONE", "2X", "FIT", "FIT 4:3", "FULL"}, 2, Option::Index::ROM_SCALING)); options_gui.push_back( - Option("FILTER", {"POINT", "LINEAR"}, 1, Option::Index::ROM_FILTER)); + Option("FILTER", {"POINT", "LINEAR"}, 0, Option::Index::ROM_FILTER)); options_gui.push_back( - Option("SHADER", renderer->shaders->GetNames(), 2, Option::Index::ROM_SHADER)); + Option("SHADER", renderer->shaders->GetNames(), 0, Option::Index::ROM_SHADER)); options_gui.push_back( Option("ROTATION", {"OFF", "ON", "OFF+FLIP", "OFF+CAB MODE"}, 0, Option::Index::ROM_ROTATION)); options_gui.push_back(Option("SHOW_FPS", {"NO", "YES"}, 0, Option::Index::ROM_SHOW_FPS)); @@ -119,6 +119,10 @@ Config::Config(const std::string &cfgPath, Renderer *renderer) { Option("JOY_COIN1", {"6"}, KEY_JOY_COIN1_DEFAULT, Option::Index::JOY_COIN1, Option::Type::INPUT)); options_gui.push_back( Option("JOY_START1", {"7"}, KEY_JOY_START1_DEFAULT, Option::Index::JOY_START1, Option::Type::INPUT)); + options_gui.push_back( + Option("JOY_MENU1", {"6"}, KEY_JOY_MENU1_DEFAULT, Option::Index::JOY_MENU1, Option::Type::INPUT)); + options_gui.push_back( + Option("JOY_MENU2", {"7"}, KEY_JOY_MENU2_DEFAULT, Option::Index::JOY_MENU2, Option::Type::INPUT)); // TODO: add gui option for axis in option menu options_gui.push_back( Option("JOY_AXIS_LX", {"0"}, KEY_JOY_AXIS_LX, Option::Index::JOY_AXIS_LX, Option::Type::HIDDEN)); @@ -148,6 +152,8 @@ Config::Config(const std::string &cfgPath, Renderer *renderer) { options_gui.push_back(Option("KEY_FIRE6", {"81"}, 81, Option::Index::KEY_FIRE6, Option::Type::INPUT)); // KP_6 options_gui.push_back(Option("KEY_COIN1", {"36"}, 36, Option::Index::KEY_COIN1, Option::Type::INPUT)); // ESCAPE options_gui.push_back(Option("KEY_START1", {"58"}, 58, Option::Index::KEY_START1, Option::Type::INPUT));// ENTER + options_gui.push_back(Option("KEY_MENU1", {"58"}, 58, Option::Index::KEY_MENU1, Option::Type::INPUT)); + options_gui.push_back(Option("KEY_MENU2", {"36"}, 36, Option::Index::KEY_MENU2, Option::Type::INPUT)); #endif // @@ -367,6 +373,8 @@ int *Config::GetGuiPlayerInputKeys(int player) { keyboard_keys[9] = GetGuiValue(Option::Index::KEY_FIRE4); keyboard_keys[10] = GetGuiValue(Option::Index::KEY_FIRE5); keyboard_keys[11] = GetGuiValue(Option::Index::KEY_FIRE6); + keyboard_keys[12] = GetGuiValue(Option::Index::KEY_MENU1); + keyboard_keys[13] = GetGuiValue(Option::Index::KEY_MENU2); #endif return keyboard_keys; @@ -387,6 +395,8 @@ int *Config::GetGuiPlayerInputButtons(int player) { joystick_keys[9] = GetGuiValue(Option::Index::JOY_FIRE4); joystick_keys[10] = GetGuiValue(Option::Index::JOY_FIRE5); joystick_keys[11] = GetGuiValue(Option::Index::JOY_FIRE6); + joystick_keys[12] = GetGuiValue(Option::Index::JOY_MENU1); + joystick_keys[13] = GetGuiValue(Option::Index::JOY_MENU2); return joystick_keys; } @@ -407,6 +417,8 @@ int *Config::GetRomPlayerInputKeys(int player) { keyboard_keys[9] = GetRomValue(Option::Index::KEY_FIRE4); keyboard_keys[10] = GetRomValue(Option::Index::KEY_FIRE5); keyboard_keys[11] = GetRomValue(Option::Index::KEY_FIRE6); + keyboard_keys[12] = GetRomValue(Option::Index::KEY_MENU1); + keyboard_keys[13] = GetRomValue(Option::Index::KEY_MENU2); #endif return keyboard_keys; @@ -427,6 +439,8 @@ int *Config::GetRomPlayerInputButtons(int player) { joystick_keys[9] = GetRomValue(Option::Index::JOY_FIRE4); joystick_keys[10] = GetRomValue(Option::Index::JOY_FIRE5); joystick_keys[11] = GetRomValue(Option::Index::JOY_FIRE6); + joystick_keys[12] = GetRomValue(Option::Index::JOY_MENU1); + joystick_keys[13] = GetRomValue(Option::Index::JOY_MENU2); return joystick_keys; } diff --git a/pfba/gui/config.h b/pfba/gui/config.h index a4f402d..2d9136a 100644 --- a/pfba/gui/config.h +++ b/pfba/gui/config.h @@ -8,6 +8,7 @@ #include "libconfig.h" #include "gui.h" + class Gui; #include "option.h" @@ -25,10 +26,12 @@ class Gui; #define KEY_JOY_FIRE6_DEFAULT 5 #define KEY_JOY_COIN1_DEFAULT 10 #define KEY_JOY_START1_DEFAULT 11 -#define KEY_JOY_AXIS_LX 0 -#define KEY_JOY_AXIS_LY 1 -#define KEY_JOY_AXIS_RX 2 -#define KEY_JOY_AXIS_RY 3 +#define KEY_JOY_MENU1_DEFAULT 11 +#define KEY_JOY_MENU2_DEFAULT 10 +#define KEY_JOY_AXIS_LX 0 +#define KEY_JOY_AXIS_LY 1 +#define KEY_JOY_AXIS_RX 2 +#define KEY_JOY_AXIS_RY 3 #elif __3DS__ #define KEY_JOY_UP_DEFAULT 6 #define KEY_JOY_DOWN_DEFAULT 7 @@ -42,10 +45,12 @@ class Gui; #define KEY_JOY_FIRE6_DEFAULT 8 #define KEY_JOY_COIN1_DEFAULT 2 #define KEY_JOY_START1_DEFAULT 3 -#define KEY_JOY_AXIS_LX 0 -#define KEY_JOY_AXIS_LY 0 -#define KEY_JOY_AXIS_RX 0 -#define KEY_JOY_AXIS_RY 0 +#define KEY_JOY_MENU1_DEFAULT 3 +#define KEY_JOY_MENU2_DEFAULT 2 +#define KEY_JOY_AXIS_LX 0 +#define KEY_JOY_AXIS_LY 0 +#define KEY_JOY_AXIS_RX 0 +#define KEY_JOY_AXIS_RY 0 #else #define KEY_JOY_UP_DEFAULT -1 // use hat #define KEY_JOY_DOWN_DEFAULT -1 // use hat @@ -59,10 +64,12 @@ class Gui; #define KEY_JOY_FIRE6_DEFAULT 5 #define KEY_JOY_COIN1_DEFAULT 6 #define KEY_JOY_START1_DEFAULT 7 -#define KEY_JOY_AXIS_LX 0 -#define KEY_JOY_AXIS_LY 1 -#define KEY_JOY_AXIS_RX 4 -#define KEY_JOY_AXIS_RY 5 +#define KEY_JOY_MENU1_DEFAULT 7 +#define KEY_JOY_MENU2_DEFAULT 6 +#define KEY_JOY_AXIS_LX 0 +#define KEY_JOY_AXIS_LY 1 +#define KEY_JOY_AXIS_RX 4 +#define KEY_JOY_AXIS_RY 5 #endif class Config { @@ -70,26 +77,35 @@ class Config { public: Config(const std::string &cfgPath, Renderer *renderer); + ~Config() {}; void Load(RomList::Rom *rom = NULL); + void Save(RomList::Rom *rom = NULL); int GetGuiValue(int id); + int GetRomValue(int id); const char *GetRomPath(int n); + std::vector GetRomPaths(); std::vector