diff --git a/UI/ControlMappingScreen.cpp b/UI/ControlMappingScreen.cpp index 278ef7d80051..ebc924604ed7 100644 --- a/UI/ControlMappingScreen.cpp +++ b/UI/ControlMappingScreen.cpp @@ -999,6 +999,7 @@ class MockPSP : public UI::AnchorLayout { 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); } -UI::EventReturn VisualMappingScreen::OnMapButton(UI::EventParams &e) { - auto km = GetI18NCategory("KeyMapping"); +void VisualMappingScreen::resized() { + RecreateViews(); +} +UI::EventReturn VisualMappingScreen::OnMapButton(UI::EventParams &e) { 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 dc0aa61b0252..d95818a3cb26 100644 --- a/UI/ControlMappingScreen.h +++ b/UI/ControlMappingScreen.h @@ -170,11 +170,13 @@ class VisualMappingScreen : public UIDialogScreenWithBackground { 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;