From 76c9ddc17543f92af9ffb71571cfb927053334c4 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 28 Jan 2023 17:41:43 -0800 Subject: [PATCH 1/2] UI: Label visual PSP buttons on focus. For clarity on what button they are and that they are focused. --- UI/ControlMappingScreen.cpp | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/UI/ControlMappingScreen.cpp b/UI/ControlMappingScreen.cpp index 3b2d4d16f1..ef2de5b486 100644 --- a/UI/ControlMappingScreen.cpp +++ b/UI/ControlMappingScreen.cpp @@ -1032,6 +1032,8 @@ public: void FocusButton(int btn); float GetPopupOffset(); + bool SubviewFocused(View *view) override; + UI::Event ButtonClick; private: @@ -1042,6 +1044,7 @@ private: UI::EventReturn OnSelectButton(UI::EventParams &e); std::unordered_map buttons_; + UI::TextView *labelView_ = nullptr; int selectedButton_ = 0; }; @@ -1070,6 +1073,10 @@ MockPSP::MockPSP(UI::LayoutParams *layoutParams) : AnchorLayout(layoutParams) { AddButton(CTRL_CIRCLE, ImageID("I_CIRCLE"), ImageID("I_ROUND_LINE"), 0.0f, LayoutSize(23.0f, 23.0f, 446.0f, 74.0f))->SetScale(0.7f); AddButton(CTRL_CROSS, ImageID("I_CROSS"), ImageID("I_ROUND_LINE"), 0.0f, LayoutSize(23.0f, 23.0f, 419.0f, 102.0f))->SetScale(0.7f); AddButton(CTRL_SQUARE, ImageID("I_SQUARE"), ImageID("I_ROUND_LINE"), 0.0f, LayoutSize(23.0f, 23.0f, 392.0f, 74.0f))->SetScale(0.7f); + + labelView_ = Add(new UI::TextView("")); + labelView_->SetShadow(true); + labelView_->SetVisibility(UI::V_GONE); } void MockPSP::SelectButton(int btn) { @@ -1077,9 +1084,25 @@ void MockPSP::SelectButton(int btn) { } void MockPSP::FocusButton(int btn) { - MockButton *view = buttons_[selectedButton_]; - if (view) + MockButton *view = buttons_[btn]; + if (view) { view->SetFocus(); + } else { + labelView_->SetVisibility(UI::V_GONE); + } +} + +bool MockPSP::SubviewFocused(View *view) { + for (auto it : buttons_) { + if (view == it.second) { + labelView_->SetVisibility(UI::V_VISIBLE); + labelView_->SetText(KeyMap::GetPspButtonName(it.first)); + + const Bounds &pos = view->GetBounds().Offset(-GetBounds().x, -GetBounds().y); + labelView_->ReplaceLayoutParams(new UI::AnchorLayoutParams(pos.centerX(), pos.y2() + 5, UI::NONE, UI::NONE)); + } + } + return AnchorLayout::SubviewFocused(view); } float MockPSP::GetPopupOffset() { From 4cb37d43912fba6f482637f9246dace0837d19ec Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 28 Jan 2023 17:42:23 -0800 Subject: [PATCH 2/2] UI: Highlight buttons on press in visual PSP map. --- UI/ControlMappingScreen.cpp | 62 +++++++++++++++++++++++++++++++++++++ UI/ControlMappingScreen.h | 3 ++ 2 files changed, 65 insertions(+) diff --git a/UI/ControlMappingScreen.cpp b/UI/ControlMappingScreen.cpp index ef2de5b486..db5926de42 100644 --- a/UI/ControlMappingScreen.cpp +++ b/UI/ControlMappingScreen.cpp @@ -970,6 +970,12 @@ public: if (img_.isValid()) { scales[0] *= scaleX_; scales[1] *= scaleY_; + if (timeLastPressed_ >= 0.0) { + double sincePress = time_now_d() - timeLastPressed_; + if (sincePress < 1.0) { + c = colorBlend(c, dc.theme->itemDownStyle.background.color, (float)sincePress); + } + } dc.Draw()->DrawImageRotatedStretch(img_, bounds_.Offset(offsetX_, offsetY_), scales, angle_, c); } } @@ -1010,6 +1016,10 @@ public: return button_; } + void NotifyPressed() { + timeLastPressed_ = time_now_d(); + } + private: int button_; ImageID img_; @@ -1021,6 +1031,7 @@ private: float offsetY_ = 0.0f; bool flipHBG_ = false; int *selectedButton_ = nullptr; + double timeLastPressed_ = -1.0; }; class MockPSP : public UI::AnchorLayout { @@ -1030,6 +1041,7 @@ public: MockPSP(UI::LayoutParams *layoutParams = nullptr); void SelectButton(int btn); void FocusButton(int btn); + void NotifyPressed(int btn); float GetPopupOffset(); bool SubviewFocused(View *view) override; @@ -1092,6 +1104,12 @@ void MockPSP::FocusButton(int btn) { } } +void MockPSP::NotifyPressed(int btn) { + MockButton *view = buttons_[btn]; + if (view) + view->NotifyPressed(); +} + bool MockPSP::SubviewFocused(View *view) { for (auto it : buttons_) { if (view == it.second) { @@ -1185,6 +1203,50 @@ void VisualMappingScreen::CreateViews() { root_->Add(rightColumn); } +bool VisualMappingScreen::key(const KeyInput &key) { + if (key.flags & KEY_DOWN) { + std::vector pspKeys; + KeyMap::KeyToPspButton(key.deviceId, key.keyCode, &pspKeys); + for (int pspKey : pspKeys) { + switch (pspKey) { + case VIRTKEY_AXIS_X_MIN: + case VIRTKEY_AXIS_Y_MIN: + case VIRTKEY_AXIS_X_MAX: + case VIRTKEY_AXIS_Y_MAX: + psp_->NotifyPressed(VIRTKEY_AXIS_Y_MAX); + break; + default: + psp_->NotifyPressed(pspKey); + break; + } + } + } + return UIDialogScreenWithGameBackground::key(key); +} + +void VisualMappingScreen::axis(const AxisInput &axis) { + std::vector results; + if (axis.value >= g_Config.fAnalogDeadzone * 0.7f) + KeyMap::AxisToPspButton(axis.deviceId, axis.axisId, 1, &results); + if (axis.value <= g_Config.fAnalogDeadzone * -0.7f) + KeyMap::AxisToPspButton(axis.deviceId, axis.axisId, -1, &results); + + for (int result : results) { + switch (result) { + case VIRTKEY_AXIS_X_MIN: + case VIRTKEY_AXIS_Y_MIN: + case VIRTKEY_AXIS_X_MAX: + case VIRTKEY_AXIS_Y_MAX: + psp_->NotifyPressed(VIRTKEY_AXIS_Y_MAX); + break; + default: + psp_->NotifyPressed(result); + break; + } + } + UIDialogScreenWithGameBackground::axis(axis); +} + void VisualMappingScreen::resized() { UIDialogScreenWithGameBackground::resized(); RecreateViews(); diff --git a/UI/ControlMappingScreen.h b/UI/ControlMappingScreen.h index a54a53afe3..569ea9721c 100644 --- a/UI/ControlMappingScreen.h +++ b/UI/ControlMappingScreen.h @@ -177,6 +177,9 @@ public: const char *tag() const override { return "VisualMapping"; } + bool key(const KeyInput &key) override; + void axis(const AxisInput &axis) override; + protected: void CreateViews() override;