diff --git a/UI/ControlMappingScreen.cpp b/UI/ControlMappingScreen.cpp index a9230e99abb1..a4ec6e6657e3 100644 --- a/UI/ControlMappingScreen.cpp +++ b/UI/ControlMappingScreen.cpp @@ -36,6 +36,7 @@ #include "Common/StringUtils.h" #include "Common/System/Display.h" #include "Common/System/System.h" +#include "Common/TimeUtil.h" #include "Core/KeyMap.h" #include "Core/Host.h" #include "Core/HLE/sceCtrl.h" @@ -326,7 +327,7 @@ void KeyMappingNewKeyDialog::CreatePopupContents(UI::ViewGroup *parent) { } bool KeyMappingNewKeyDialog::key(const KeyInput &key) { - if (mapped_) + if (mapped_ || time_now_d() < delayUntil_) return false; if (key.flags & KEY_DOWN) { if (key.keyCode == NKCODE_EXT_MOUSEBUTTON_1) { @@ -342,6 +343,10 @@ bool KeyMappingNewKeyDialog::key(const KeyInput &key) { return true; } +void KeyMappingNewKeyDialog::SetDelay(float t) { + delayUntil_ = time_now_d() + t; +} + void KeyMappingNewMouseKeyDialog::CreatePopupContents(UI::ViewGroup *parent) { using namespace UI; @@ -392,7 +397,7 @@ static bool IgnoreAxisForMapping(int axis) { bool KeyMappingNewKeyDialog::axis(const AxisInput &axis) { - if (mapped_) + if (mapped_ || time_now_d() < delayUntil_) return false; if (IgnoreAxisForMapping(axis.axisId)) return false; @@ -1144,14 +1149,14 @@ void VisualMappingScreen::resized() { UI::EventReturn VisualMappingScreen::OnMapButton(UI::EventParams &e) { nextKey_ = e.a; - MapNext(); + MapNext(false); return UI::EVENT_DONE; } UI::EventReturn VisualMappingScreen::OnBindAll(UI::EventParams &e) { bindAll_ = 0; nextKey_ = bindAllOrder[bindAll_]; - MapNext(); + MapNext(false); return UI::EVENT_DONE; } @@ -1184,7 +1189,7 @@ void VisualMappingScreen::HandleKeyMapping(KeyDef key) { void VisualMappingScreen::dialogFinished(const Screen *dialog, DialogResult result) { if (result == DR_YES && nextKey_ != 0) { - MapNext(); + MapNext(true); } else { // This means they canceled. if (nextKey_ != 0) @@ -1195,7 +1200,7 @@ void VisualMappingScreen::dialogFinished(const Screen *dialog, DialogResult resu } } -void VisualMappingScreen::MapNext() { +void VisualMappingScreen::MapNext(bool successive) { auto km = GetI18NCategory("KeyMapping"); if (nextKey_ == VIRTKEY_AXIS_Y_MIN || nextKey_ == VIRTKEY_AXIS_X_MIN || nextKey_ == VIRTKEY_AXIS_X_MAX) { @@ -1207,5 +1212,6 @@ void VisualMappingScreen::MapNext() { Bounds bounds = screenManager()->getUIContext()->GetLayoutBounds(); dialog->SetPopupOffset(psp_->GetPopupOffset() * bounds.h); + dialog->SetDelay(successive ? 0.5f : 0.1f); screenManager()->push(dialog); } diff --git a/UI/ControlMappingScreen.h b/UI/ControlMappingScreen.h index 393fb1f18c03..add89bfdfa26 100644 --- a/UI/ControlMappingScreen.h +++ b/UI/ControlMappingScreen.h @@ -57,13 +57,15 @@ class ControlMappingScreen : public UIDialogScreenWithBackground { class KeyMappingNewKeyDialog : public PopupScreen { public: explicit KeyMappingNewKeyDialog(int btn, bool replace, std::function callback, std::shared_ptr i18n) - : PopupScreen(i18n->T("Map Key"), "Cancel", ""), callback_(callback), mapped_(false) { + : PopupScreen(i18n->T("Map Key"), "Cancel", ""), callback_(callback) { pspBtn_ = btn; } virtual bool key(const KeyInput &key) override; virtual bool axis(const AxisInput &axis) override; + void SetDelay(float t); + protected: void CreatePopupContents(UI::ViewGroup *parent) override; @@ -74,7 +76,8 @@ class KeyMappingNewKeyDialog : public PopupScreen { private: int pspBtn_; std::function callback_; - bool mapped_; // Prevent double registrations + bool mapped_ = false; // Prevent double registrations + double delayUntil_ = 0.0f; }; class KeyMappingNewMouseKeyDialog : public PopupScreen { @@ -178,7 +181,7 @@ class VisualMappingScreen : public UIDialogScreenWithBackground { UI::EventReturn OnMapButton(UI::EventParams &e); UI::EventReturn OnBindAll(UI::EventParams &e); void HandleKeyMapping(KeyDef key); - void MapNext(); + void MapNext(bool successive); MockPSP *psp_ = nullptr; int nextKey_ = 0;