diff --git a/Common/UI/UIScreen.cpp b/Common/UI/UIScreen.cpp index 3a852dc2ee..33b49683a4 100644 --- a/Common/UI/UIScreen.cpp +++ b/Common/UI/UIScreen.cpp @@ -296,6 +296,10 @@ void PopupScreen::SetPopupOrigin(const UI::View *view) { popupOrigin_ = view->GetBounds().Center(); } +void PopupScreen::SetPopupOffset(float y) { + offsetY_ = y; +} + void PopupScreen::TriggerFinish(DialogResult result) { if (CanComplete(result)) { finishFrame_ = frames_; @@ -320,7 +324,7 @@ void PopupScreen::CreateViews() { float yres = screenManager()->getUIContext()->GetBounds().h; box_ = new LinearLayout(ORIENT_VERTICAL, - new AnchorLayoutParams(PopupWidth(), FillVertical() ? yres - 30 : WRAP_CONTENT, dc.GetBounds().centerX(), dc.GetBounds().centerY(), NONE, NONE, true)); + new AnchorLayoutParams(PopupWidth(), FillVertical() ? yres - 30 : WRAP_CONTENT, dc.GetBounds().centerX(), dc.GetBounds().centerY() + offsetY_, NONE, NONE, true)); root_->Add(box_); box_->SetBG(dc.theme->popupStyle.background); diff --git a/Common/UI/UIScreen.h b/Common/UI/UIScreen.h index 3e1fa8fdc9..9541309523 100644 --- a/Common/UI/UIScreen.h +++ b/Common/UI/UIScreen.h @@ -81,6 +81,7 @@ public: virtual void TriggerFinish(DialogResult result) override; void SetPopupOrigin(const UI::View *view); + void SetPopupOffset(float y); protected: virtual bool FillVertical() const { return false; } @@ -109,6 +110,7 @@ private: DialogResult finishResult_; bool hasPopupOrigin_ = false; Point popupOrigin_; + float offsetY_ = 0.0f; }; class ListPopupScreen : public PopupScreen { diff --git a/UI/ControlMappingScreen.cpp b/UI/ControlMappingScreen.cpp index 278ef7d800..ebc924604e 100644 --- a/UI/ControlMappingScreen.cpp +++ b/UI/ControlMappingScreen.cpp @@ -999,6 +999,7 @@ public: MockPSP(UI::LayoutParams *layoutParams = nullptr); void SelectButton(int btn); + float GetPopupOffset(); UI::Event ButtonClick; @@ -1044,6 +1045,18 @@ void MockPSP::SelectButton(int btn) { selectedButton_ = btn; } +float MockPSP::GetPopupOffset() { + MockButton *view = buttons_[selectedButton_]; + if (!view) + return 0.0f; + + float ypos = view->GetBounds().centerY(); + if (ypos > bounds_.centerY()) { + return -0.25f; + } + return 0.25f; +} + UI::AnchorLayoutParams *MockPSP::LayoutAt(float l, float t, float r, float b) { return new UI::AnchorLayoutParams(l * SCALE, t * SCALE, r * SCALE, b * SCALE); } @@ -1112,24 +1125,20 @@ void VisualMappingScreen::CreateViews() { root_->Add(rightColumn); } +void VisualMappingScreen::resized() { + RecreateViews(); +} + UI::EventReturn VisualMappingScreen::OnMapButton(UI::EventParams &e) { - auto km = GetI18NCategory("KeyMapping"); - nextKey_ = e.a; - psp_->SelectButton(nextKey_); - - screenManager()->push(new KeyMappingNewKeyDialog(nextKey_, true, std::bind(&VisualMappingScreen::HandleKeyMapping, this, std::placeholders::_1), km)); + MapNext(); return UI::EVENT_DONE; } UI::EventReturn VisualMappingScreen::OnBindAll(UI::EventParams &e) { - auto km = GetI18NCategory("KeyMapping"); - bindAll_ = 0; nextKey_ = bindAllOrder[bindAll_]; - psp_->SelectButton(nextKey_); - - screenManager()->push(new KeyMappingNewKeyDialog(nextKey_, true, std::bind(&VisualMappingScreen::HandleKeyMapping, this, std::placeholders::_1), km)); + MapNext(); return UI::EVENT_DONE; } @@ -1156,14 +1165,26 @@ void VisualMappingScreen::HandleKeyMapping(KeyDef key) { } void VisualMappingScreen::dialogFinished(const Screen *dialog, DialogResult result) { - auto km = GetI18NCategory("KeyMapping"); - if (result == DR_YES && nextKey_ != 0) { - screenManager()->push(new KeyMappingNewKeyDialog(nextKey_, true, std::bind(&VisualMappingScreen::HandleKeyMapping, this, std::placeholders::_1), km)); + MapNext(); } else { nextKey_ = 0; bindAll_ = -1; psp_->SelectButton(0); } +} +void VisualMappingScreen::MapNext() { + auto km = GetI18NCategory("KeyMapping"); + + if (nextKey_ == VIRTKEY_AXIS_Y_MIN || nextKey_ == VIRTKEY_AXIS_X_MIN || nextKey_ == VIRTKEY_AXIS_X_MAX) { + psp_->SelectButton(VIRTKEY_AXIS_Y_MAX); + } else { + psp_->SelectButton(nextKey_); + } + auto dialog = new KeyMappingNewKeyDialog(nextKey_, true, std::bind(&VisualMappingScreen::HandleKeyMapping, this, std::placeholders::_1), km); + + Bounds bounds = screenManager()->getUIContext()->GetLayoutBounds(); + dialog->SetPopupOffset(psp_->GetPopupOffset() * bounds.h); + screenManager()->push(dialog); } diff --git a/UI/ControlMappingScreen.h b/UI/ControlMappingScreen.h index dc0aa61b02..d95818a3cb 100644 --- a/UI/ControlMappingScreen.h +++ b/UI/ControlMappingScreen.h @@ -170,11 +170,13 @@ protected: void CreateViews() override; void dialogFinished(const Screen *dialog, DialogResult result) override; + void resized() override; private: UI::EventReturn OnMapButton(UI::EventParams &e); UI::EventReturn OnBindAll(UI::EventParams &e); void HandleKeyMapping(KeyDef key); + void MapNext(); MockPSP *psp_ = nullptr; int nextKey_ = 0;