mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-10-11 13:36:24 +02:00
UI: Try to keep button visible while mapping.
This commit is contained in:
1 parent
efeca78c1a
commit
f7b92ebb29
4 files changed
+43
-14
No files matched your search
@@ -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);
|
||||
|
||||
@@ -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 {
|
||||
|
||||
+34
-13
@@ -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);
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user