Merge pull request #14988 from unknownbrackets/ui-ctrl-delay

UI: Delay between successive mapping in controls
This commit is contained in:
Henrik Rydgård 2021-10-08 06:39:56 +02:00 committed by GitHub
commit a968728ada
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 9 deletions

View File

@ -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);
}

View File

@ -57,13 +57,15 @@ private:
class KeyMappingNewKeyDialog : public PopupScreen {
public:
explicit KeyMappingNewKeyDialog(int btn, bool replace, std::function<void(KeyDef)> callback, std::shared_ptr<I18NCategory> 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 @@ protected:
private:
int pspBtn_;
std::function<void(KeyDef)> callback_;
bool mapped_; // Prevent double registrations
bool mapped_ = false; // Prevent double registrations
double delayUntil_ = 0.0f;
};
class KeyMappingNewMouseKeyDialog : public PopupScreen {
@ -178,7 +181,7 @@ private:
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;