Improved the input configuration logic.

Also added a command line option to force the input configuration even if a es_input.cfg file exists.
This commit is contained in:
Leon Styhre 2020-08-03 11:39:04 +02:00
parent d4907f69a7
commit 1550c48187
7 changed files with 58 additions and 19 deletions

View file

@ -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-kid Force the UI mode to Kid
--force-kiosk Force the UI mode to Kiosk --force-kiosk Force the UI mode to Kiosk
--force-disable-filters Force the UI to ignore applied filters in gamelist --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 --home [path] Directory to use as home path
--version, -v Displays version information --version, -v Displays version information
--help, -h Summon a sentient, angry tuba --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-kid Force the UI mode to Kid
--force-kiosk Force the UI mode to Kiosk --force-kiosk Force the UI mode to Kiosk
--force-disable-filters Force the UI to ignore applied filters in gamelist --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 --home [path] Directory to use as home path
--version, -v Displays version information --version, -v Displays version information
--help, -h Summon a sentient, angry tuba --help, -h Summon a sentient, angry tuba

Binary file not shown.

View file

@ -705,7 +705,7 @@ void GuiMenu::openConfigInput()
Window* window = mWindow; Window* window = mWindow;
window->pushGui(new GuiMsgBox(window, getHelpStyle(), window->pushGui(new GuiMsgBox(window, getHelpStyle(),
"ARE YOU SURE YOU WANT TO CONFIGURE INPUT?", "YES", [window] { "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) }, "NO", nullptr)
); );
} }

View file

@ -51,6 +51,8 @@
#include <iostream> #include <iostream>
#include <time.h> #include <time.h>
bool forceInputConfig = false;
#ifdef _WIN64 #ifdef _WIN64
enum eConsoleType { enum eConsoleType {
NO_CONSOLE, NO_CONSOLE,
@ -283,6 +285,9 @@ bool parseArgs(int argc, char* argv[])
else if (strcmp(argv[i], "--force-disable-filters") == 0) { else if (strcmp(argv[i], "--force-disable-filters") == 0) {
Settings::getInstance()->setBool("ForceDisableFilters", true); 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) { else if (strcmp(argv[i], "--version") == 0 || strcmp(argv[i], "-v") == 0) {
std::cout << std::cout <<
"EmulationStation Desktop Edition v" << PROGRAM_VERSION_STRING << "\n"; "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-kid Force the UI mode to Kid\n"
" --force-kiosk Force the UI mode to Kiosk\n" " --force-kiosk Force the UI mode to Kiosk\n"
" --force-disable-filters Force the UI to ignore applied filters in gamelist\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" " --home [path] Directory to use as home path\n"
" --version, -v Display version information\n" " --version, -v Display version information\n"
" --help, -h Summon a sentient, angry tuba\n"; " --help, -h Summon a sentient, angry tuba\n";
@ -519,21 +525,24 @@ int main(int argc, char* argv[])
if (splashScreen && splashScreenProgress) if (splashScreen && splashScreenProgress)
window.renderLoadingScreen("Done."); 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 (errorMsg == "") {
if (Utils::FileSystem::exists(InputManager::getConfigPath()) && if (!forceInputConfig && Utils::FileSystem::exists(InputManager::getConfigPath()) &&
InputManager::getInstance()->getNumConfiguredDevices() > 0) { InputManager::getInstance()->getNumConfiguredDevices() > 0) {
ViewController::get()->goToStart(); ViewController::get()->goToStart();
} }
else { else if (forceInputConfig) {
// Always reset ShowDefaultKeyboardWarning to true if the es_input.cfg window.pushGui(new GuiDetectDevice(&window, true, true, [] {
// file is missing.
Settings::getInstance()->setBool("ShowDefaultKeyboardWarning", true);
Settings::getInstance()->saveFile();
window.pushGui(new GuiDetectDevice(&window, true, [] {
ViewController::get()->goToStart(); })); 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. // Check if the media directory exists, and if not, log a warning.

View file

@ -66,6 +66,9 @@ void ViewController::goToStart()
// configuration has been performed. // configuration has been performed.
if (InputManager::getInstance()-> if (InputManager::getInstance()->
getInputConfigByDevice(DEVICE_KEYBOARD)->getDefaultConfigFlag()) { getInputConfigByDevice(DEVICE_KEYBOARD)->getDefaultConfigFlag()) {
LOG(LogInfo) << "Applying default keyboard mappings.";
if (Settings::getInstance()->getBool("ShowDefaultKeyboardWarning")) { if (Settings::getInstance()->getBool("ShowDefaultKeyboardWarning")) {
std::string message = "NO KEYBOARD CONFIGURATION COULD BE\n" std::string message = "NO KEYBOARD CONFIGURATION COULD BE\n"
"FOUND IN ES_INPUT.CFG, SO APPLYING THE\n" "FOUND IN ES_INPUT.CFG, SO APPLYING THE\n"

View file

@ -19,9 +19,11 @@
GuiDetectDevice::GuiDetectDevice( GuiDetectDevice::GuiDetectDevice(
Window* window, Window* window,
bool firstRun, bool firstRun,
bool forcedConfig,
const std::function<void()>& doneCallback) const std::function<void()>& doneCallback)
: GuiComponent(window), : GuiComponent(window),
mFirstRun(firstRun), mFirstRun(firstRun),
mForcedConfig(forcedConfig),
mBackground(window, ":/graphics/frame.png"), mBackground(window, ":/graphics/frame.png"),
mGrid(window, Vector2i(1, 5)) mGrid(window, Vector2i(1, 5))
{ {
@ -50,12 +52,21 @@ GuiDetectDevice::GuiDetectDevice(
mGrid.setEntry(mDeviceInfo, Vector2i(0, 1), false, true); mGrid.setEntry(mDeviceInfo, Vector2i(0, 1), false, true);
// Message. // Message.
mMsg1 = std::make_shared<TextComponent>(mWindow, if (numDevices > 0) {
"HOLD A BUTTON ON YOUR DEVICE OR KEYBOARD TO CONFIGURE IT.", mMsg1 = std::make_shared<TextComponent>(mWindow,
Font::get(FONT_SIZE_SMALL), 0x777777FF, ALIGN_CENTER); "HOLD A BUTTON ON YOUR GAMEPAD OR KEYBOARD TO CONFIGURE IT.",
Font::get(FONT_SIZE_SMALL), 0x777777FF, ALIGN_CENTER);
}
else {
mMsg1 = std::make_shared<TextComponent>(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); 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<TextComponent>(mWindow, msg2str, mMsg2 = std::make_shared<TextComponent>(mWindow, msg2str,
Font::get(FONT_SIZE_SMALL), 0x777777FF, ALIGN_CENTER); Font::get(FONT_SIZE_SMALL), 0x777777FF, ALIGN_CENTER);
mGrid.setEntry(mMsg2, Vector2i(0, 3), false, true); 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) { input.value && input.id == SDLK_ESCAPE) {
// Cancel the configuration. // Cancel the configuration.
PowerSaver::resume(); PowerSaver::resume();
delete this; delete this; // Delete GUI element.
return true; 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.type == TYPE_BUTTON || input.type == TYPE_KEY ||input.type == TYPE_CEC_BUTTON) {
if (input.value && mHoldingConfig == nullptr) { if (input.value && mHoldingConfig == nullptr) {
@ -114,9 +135,11 @@ bool GuiDetectDevice::input(InputConfig* config, Input input)
void GuiDetectDevice::update(int deltaTime) void GuiDetectDevice::update(int deltaTime)
{ {
if (mHoldingConfig) { if (mHoldingConfig) {
// If ES starts and if a known device is connected after startup // If ES starts and if a known device is connected after startup skip controller
// skip controller configuration. // configuration unless the flag to force the configuration was passed on the
if (mFirstRun && Utils::FileSystem::exists(InputManager::getConfigPath()) && // command line.
if (!mForcedConfig && mFirstRun &&
Utils::FileSystem::exists(InputManager::getConfigPath()) &&
InputManager::getInstance()->getNumConfiguredDevices() > 0) { InputManager::getInstance()->getNumConfiguredDevices() > 0) {
if (mDoneCallback) if (mDoneCallback)
mDoneCallback(); mDoneCallback();

View file

@ -17,7 +17,8 @@ class TextComponent;
class GuiDetectDevice : public GuiComponent class GuiDetectDevice : public GuiComponent
{ {
public: public:
GuiDetectDevice(Window* window, bool firstRun, const std::function<void()>& doneCallback); GuiDetectDevice(Window* window, bool firstRun, bool forcedConfig,
const std::function<void()>& doneCallback);
bool input(InputConfig* config, Input input) override; bool input(InputConfig* config, Input input) override;
void update(int deltaTime) override; void update(int deltaTime) override;
@ -25,6 +26,7 @@ public:
private: private:
bool mFirstRun; bool mFirstRun;
bool mForcedConfig;
InputConfig* mHoldingConfig; InputConfig* mHoldingConfig;
int mHoldTime; int mHoldTime;