From 1550c48187b7f7ca46eb4c81b2ceaec88180fde5 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Mon, 3 Aug 2020 11:39:04 +0200 Subject: [PATCH] Improved the input configuration logic. Also added a command line option to force the input configuration even if a es_input.cfg file exists. --- INSTALL.md | 2 ++ es-app/src/emulationstation.6.gz | Bin 1081 -> 1107 bytes es-app/src/guis/GuiMenu.cpp | 2 +- es-app/src/main.cpp | 27 ++++++++++++------- es-app/src/views/ViewController.cpp | 3 +++ es-core/src/guis/GuiDetectDevice.cpp | 39 +++++++++++++++++++++------ es-core/src/guis/GuiDetectDevice.h | 4 ++- 7 files changed, 58 insertions(+), 19 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index 4d4370002..0f804bfaa 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -575,6 +575,7 @@ You can use `--help` or `-h` to view a list of command line options, as shown he --force-kid Force the UI mode to Kid --force-kiosk Force the UI mode to Kiosk --force-disable-filters Force the UI to ignore applied filters in gamelist +--force-input-config Force configuration of input device --home [path] Directory to use as home path --version, -v Displays version information --help, -h Summon a sentient, angry tuba @@ -599,6 +600,7 @@ You can use `--help` or `-h` to view a list of command line options, as shown he --force-kid Force the UI mode to Kid --force-kiosk Force the UI mode to Kiosk --force-disable-filters Force the UI to ignore applied filters in gamelist +--force-input-config Force configuration of input device --home [path] Directory to use as home path --version, -v Displays version information --help, -h Summon a sentient, angry tuba diff --git a/es-app/src/emulationstation.6.gz b/es-app/src/emulationstation.6.gz index 46527c69245aebc12ad3dee851a3e9e808da138c..808912ffdb629ace1d7a73650d3626c5c9fd40ed 100644 GIT binary patch literal 1107 zcmV-Z1g!fXiwFq!(Y+-b1Z*FsRVRUJ4ZZ0+eg;i~D;zkhu?q4zG%W+aL zNqXu@r>YV;NP`*z!lczH&WE+VwzpaDy88m5zy4;{Bms`J9}wQzdFJ(***NXNcn){- z70l-2>Gd~Q-Aog>p59J=0+>43Fbfq|+%U%r$hJ^(*?=>5`z-pE(pI=DQ)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2-Km0aZQh5$>8 ze1ves2*h4?+V-8)-0TD=^FI&YP#Z4JC{U|7(YP>mE;T9wci-aQu}f^9>MlhIU`#~@ zH{lCjlp)G{xZGIm81^r8QiXvOL*F~6(^C7B{P@|zKOB{{X z;$|Z)baIqJpNo>=q|@p!`jw-aJ)$@4ZgA%0KjJ=`vq$)2HJ;OqA!Vt7^Bikc60hBk zH4QR0igO#K!jlp6padC{C2gWN?e6;rtaS+ zT>;S76)NArJV^d7Tw*9~jiWf#TB9^}`f;9JB8nAhufqfMrn%)#_F!hpzgt>qePiWDYNY)k_Qxm+ zJANqzd^L65YU%gTf0p6J9?)hcFly@e6_%`j`m}X66ug&Cr!bzSi(W(&0B(vFH^|{h zq$hC8qzcqx{xf{3yl>p+;cz28N@JYrp%V1)QlR1KLyT)=_)GLJj;HomdpushGui(new GuiMsgBox(window, getHelpStyle(), "ARE YOU SURE YOU WANT TO CONFIGURE INPUT?", "YES", [window] { - window->pushGui(new GuiDetectDevice(window, false, nullptr)); + window->pushGui(new GuiDetectDevice(window, false, false, nullptr)); }, "NO", nullptr) ); } diff --git a/es-app/src/main.cpp b/es-app/src/main.cpp index 51797005d..a8b1a921f 100644 --- a/es-app/src/main.cpp +++ b/es-app/src/main.cpp @@ -51,6 +51,8 @@ #include #include +bool forceInputConfig = false; + #ifdef _WIN64 enum eConsoleType { NO_CONSOLE, @@ -283,6 +285,9 @@ bool parseArgs(int argc, char* argv[]) else if (strcmp(argv[i], "--force-disable-filters") == 0) { Settings::getInstance()->setBool("ForceDisableFilters", true); } + else if (strcmp(argv[i], "--force-input-config") == 0) { + forceInputConfig = true; + } else if (strcmp(argv[i], "--version") == 0 || strcmp(argv[i], "-v") == 0) { std::cout << "EmulationStation Desktop Edition v" << PROGRAM_VERSION_STRING << "\n"; @@ -314,6 +319,7 @@ bool parseArgs(int argc, char* argv[]) " --force-kid Force the UI mode to Kid\n" " --force-kiosk Force the UI mode to Kiosk\n" " --force-disable-filters Force the UI to ignore applied filters in gamelist\n" +" --force-input-config Force configuration of input device\n" " --home [path] Directory to use as home path\n" " --version, -v Display version information\n" " --help, -h Summon a sentient, angry tuba\n"; @@ -519,21 +525,24 @@ int main(int argc, char* argv[]) if (splashScreen && splashScreenProgress) window.renderLoadingScreen("Done."); - // Choose which GUI to open depending on if an input configuration already exists. + // Choose which GUI to open depending on if an input configuration already exists and + // whether the flag to force the input configuration was passed from the command line. if (errorMsg == "") { - if (Utils::FileSystem::exists(InputManager::getConfigPath()) && + if (!forceInputConfig && Utils::FileSystem::exists(InputManager::getConfigPath()) && InputManager::getInstance()->getNumConfiguredDevices() > 0) { ViewController::get()->goToStart(); } - else { - // Always reset ShowDefaultKeyboardWarning to true if the es_input.cfg - // file is missing. - Settings::getInstance()->setBool("ShowDefaultKeyboardWarning", true); - Settings::getInstance()->saveFile(); - - window.pushGui(new GuiDetectDevice(&window, true, [] { + else if (forceInputConfig) { + window.pushGui(new GuiDetectDevice(&window, true, true, [] { ViewController::get()->goToStart(); })); } + else { + if (InputManager::getInstance()->getNumJoysticks() > 0) + window.pushGui(new GuiDetectDevice(&window, true, false, [] { + ViewController::get()->goToStart(); })); + else + ViewController::get()->goToStart(); + } } // Check if the media directory exists, and if not, log a warning. diff --git a/es-app/src/views/ViewController.cpp b/es-app/src/views/ViewController.cpp index 1fdef57d1..e1d14a470 100644 --- a/es-app/src/views/ViewController.cpp +++ b/es-app/src/views/ViewController.cpp @@ -66,6 +66,9 @@ void ViewController::goToStart() // configuration has been performed. if (InputManager::getInstance()-> getInputConfigByDevice(DEVICE_KEYBOARD)->getDefaultConfigFlag()) { + + LOG(LogInfo) << "Applying default keyboard mappings."; + if (Settings::getInstance()->getBool("ShowDefaultKeyboardWarning")) { std::string message = "NO KEYBOARD CONFIGURATION COULD BE\n" "FOUND IN ES_INPUT.CFG, SO APPLYING THE\n" diff --git a/es-core/src/guis/GuiDetectDevice.cpp b/es-core/src/guis/GuiDetectDevice.cpp index adefabb41..4b8d24dbd 100644 --- a/es-core/src/guis/GuiDetectDevice.cpp +++ b/es-core/src/guis/GuiDetectDevice.cpp @@ -19,9 +19,11 @@ GuiDetectDevice::GuiDetectDevice( Window* window, bool firstRun, + bool forcedConfig, const std::function& doneCallback) : GuiComponent(window), mFirstRun(firstRun), + mForcedConfig(forcedConfig), mBackground(window, ":/graphics/frame.png"), mGrid(window, Vector2i(1, 5)) { @@ -50,12 +52,21 @@ GuiDetectDevice::GuiDetectDevice( mGrid.setEntry(mDeviceInfo, Vector2i(0, 1), false, true); // Message. - mMsg1 = std::make_shared(mWindow, - "HOLD A BUTTON ON YOUR DEVICE OR KEYBOARD TO CONFIGURE IT.", - Font::get(FONT_SIZE_SMALL), 0x777777FF, ALIGN_CENTER); + if (numDevices > 0) { + mMsg1 = std::make_shared(mWindow, + "HOLD A BUTTON ON YOUR GAMEPAD OR KEYBOARD TO CONFIGURE IT.", + Font::get(FONT_SIZE_SMALL), 0x777777FF, ALIGN_CENTER); + } + else { + mMsg1 = std::make_shared(mWindow, + "HOLD A BUTTON ON YOUR KEYBOARD TO CONFIGURE IT.", + Font::get(FONT_SIZE_SMALL), 0x777777FF, ALIGN_CENTER); + } + mGrid.setEntry(mMsg1, Vector2i(0, 2), false, true); - const char* msg2str = firstRun ? "PRESS F4 TO QUIT AT ANY TIME." : "PRESS ESC TO CANCEL."; + const char* msg2str = firstRun ? + "PRESS ESC TO SKIP (OR F4 TO QUIT AT ANY TIME)." : "PRESS ESC TO CANCEL."; mMsg2 = std::make_shared(mWindow, msg2str, Font::get(FONT_SIZE_SMALL), 0x777777FF, ALIGN_CENTER); mGrid.setEntry(mMsg2, Vector2i(0, 3), false, true); @@ -91,9 +102,19 @@ bool GuiDetectDevice::input(InputConfig* config, Input input) input.value && input.id == SDLK_ESCAPE) { // Cancel the configuration. PowerSaver::resume(); - delete this; + delete this; // Delete GUI element. return true; } + // First run, but the user chooses to skip the configuration. This will default to the + // built-in keyboard mappings. + else if (mFirstRun && input.device == DEVICE_KEYBOARD && input.type == TYPE_KEY && + input.value && input.id == SDLK_ESCAPE) { + if (mDoneCallback) + mDoneCallback(); + PowerSaver::resume(); + delete this; // Delete GUI element. + return true; + } if (input.type == TYPE_BUTTON || input.type == TYPE_KEY ||input.type == TYPE_CEC_BUTTON) { if (input.value && mHoldingConfig == nullptr) { @@ -114,9 +135,11 @@ bool GuiDetectDevice::input(InputConfig* config, Input input) void GuiDetectDevice::update(int deltaTime) { if (mHoldingConfig) { - // If ES starts and if a known device is connected after startup - // skip controller configuration. - if (mFirstRun && Utils::FileSystem::exists(InputManager::getConfigPath()) && + // If ES starts and if a known device is connected after startup skip controller + // configuration unless the flag to force the configuration was passed on the + // command line. + if (!mForcedConfig && mFirstRun && + Utils::FileSystem::exists(InputManager::getConfigPath()) && InputManager::getInstance()->getNumConfiguredDevices() > 0) { if (mDoneCallback) mDoneCallback(); diff --git a/es-core/src/guis/GuiDetectDevice.h b/es-core/src/guis/GuiDetectDevice.h index f0bc9651e..273339907 100644 --- a/es-core/src/guis/GuiDetectDevice.h +++ b/es-core/src/guis/GuiDetectDevice.h @@ -17,7 +17,8 @@ class TextComponent; class GuiDetectDevice : public GuiComponent { public: - GuiDetectDevice(Window* window, bool firstRun, const std::function& doneCallback); + GuiDetectDevice(Window* window, bool firstRun, bool forcedConfig, + const std::function& doneCallback); bool input(InputConfig* config, Input input) override; void update(int deltaTime) override; @@ -25,6 +26,7 @@ public: private: bool mFirstRun; + bool mForcedConfig; InputConfig* mHoldingConfig; int mHoldTime;