From 4e33a1ef078a018d0bc78faaf813fc6ce89f99c2 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 28 Aug 2021 14:37:53 -0700 Subject: [PATCH] UI: Allow rebinding the analog from PSP view. --- UI/ControlMappingScreen.cpp | 33 +++++++++++++++++++++++++++------ UI/ControlMappingScreen.h | 5 +++++ 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/UI/ControlMappingScreen.cpp b/UI/ControlMappingScreen.cpp index 993c26874d..2806f45892 100644 --- a/UI/ControlMappingScreen.cpp +++ b/UI/ControlMappingScreen.cpp @@ -1068,13 +1068,34 @@ void VisualMappingScreen::CreateViews() { UI::EventReturn VisualMappingScreen::OnMapButton(UI::EventParams &e) { auto km = GetI18NCategory("KeyMapping"); + nextKey_ = e.a; if (e.a == 0) { - // TODO - } else { - auto callback = [=](KeyDef key) { - KeyMap::SetKeyMapping(e.a, key, false); - }; - screenManager()->push(new KeyMappingNewKeyDialog(e.a, true, callback, km)); + nextKey_ = VIRTKEY_AXIS_Y_MAX; } + screenManager()->push(new KeyMappingNewKeyDialog(nextKey_, true, std::bind(&VisualMappingScreen::HandleKeyMapping, this, std::placeholders::_1), km)); return UI::EVENT_DONE; } + +void VisualMappingScreen::HandleKeyMapping(KeyDef key) { + KeyMap::SetKeyMapping(nextKey_, key, false); + + // For analog, we do each direction in a row. + if (nextKey_ == VIRTKEY_AXIS_Y_MAX) + nextKey_ = VIRTKEY_AXIS_Y_MIN; + else if (nextKey_ == VIRTKEY_AXIS_Y_MIN) + nextKey_ = VIRTKEY_AXIS_X_MIN; + else if (nextKey_ == VIRTKEY_AXIS_X_MIN) + nextKey_ = VIRTKEY_AXIS_X_MAX; + else + nextKey_ = 0; +} + +void VisualMappingScreen::dialogFinished(const Screen *dialog, DialogResult result) { + auto km = GetI18NCategory("KeyMapping"); + + if (result == DR_OK && nextKey_ != 0) { + screenManager()->push(new KeyMappingNewKeyDialog(nextKey_, true, std::bind(&VisualMappingScreen::HandleKeyMapping, this, std::placeholders::_1), km)); + } else { + nextKey_ = 0; + } +} diff --git a/UI/ControlMappingScreen.h b/UI/ControlMappingScreen.h index a3e17e2387..521aa84081 100644 --- a/UI/ControlMappingScreen.h +++ b/UI/ControlMappingScreen.h @@ -167,6 +167,11 @@ public: protected: void CreateViews() override; + void dialogFinished(const Screen *dialog, DialogResult result) override; + private: UI::EventReturn OnMapButton(UI::EventParams &e); + void HandleKeyMapping(KeyDef key); + + int nextKey_ = 0; };