Skip to content

Commit

Permalink
UI: Try to keep button visible while mapping.
Browse files Browse the repository at this point in the history
  • Loading branch information
unknownbrackets committed Aug 28, 2021
1 parent efeca78 commit 4f681f2
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 13 deletions.
47 changes: 34 additions & 13 deletions UI/ControlMappingScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -999,6 +999,7 @@ class MockPSP : public UI::AnchorLayout {

MockPSP(UI::LayoutParams *layoutParams = nullptr);
void SelectButton(int btn);
float GetPopupOffset();

UI::Event ButtonClick;

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

Expand All @@ -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);
}
2 changes: 2 additions & 0 deletions UI/ControlMappingScreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 4f681f2

Please sign in to comment.