Skip to content

Commit

Permalink
Merge pull request #19165 from hrydgard/ui-crash-fixes
Browse files Browse the repository at this point in the history
UI crash fix in control mapping screen
  • Loading branch information
hrydgard authored May 21, 2024
2 parents aecc77f + 58f7e19 commit 076194e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 18 deletions.
4 changes: 3 additions & 1 deletion Common/UI/ViewGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1194,8 +1194,10 @@ void CollapsibleSection::Update() {
}

void CollapsibleSection::UpdateVisibility() {
const bool open = *open_;
// Skipping over the header, we start from 1, not 0.
for (size_t i = 1; i < views_.size(); i++) {
views_[i]->SetVisibility(*open_ ? V_VISIBLE : V_GONE);
views_[i]->SetVisibility(open ? V_VISIBLE : V_GONE);
}
}

Expand Down
7 changes: 5 additions & 2 deletions Common/UI/ViewGroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -332,10 +332,13 @@ class CollapsibleSection : public LinearLayout {
void Update() override;

void SetOpen(bool open) {
_dbg_assert_(open_);
*open_ = open;
UpdateVisibility();
}
void SetOpenPtr(bool *open) {
_dbg_assert_(header_);
_dbg_assert_(open);
header_->SetOpenPtr(open);
open_ = open;
UpdateVisibility();
Expand All @@ -344,8 +347,8 @@ class CollapsibleSection : public LinearLayout {
private:
void UpdateVisibility();
bool localOpen_ = true;
bool *open_;
CollapsibleHeader *header_;
bool *open_ = nullptr;
CollapsibleHeader *header_ = nullptr;
};

} // namespace UI
32 changes: 17 additions & 15 deletions UI/ControlMappingScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,20 @@ UI::EventReturn SingleControlMapper::OnDelete(UI::EventParams &params) {
return UI::EVENT_DONE;
}


struct BindingCategory {
const char *catName;
int firstKey;
};

// Category name, first input from psp_button_names.
static const BindingCategory cats[] = {
{"Standard PSP controls", CTRL_UP},
{"Control modifiers", VIRTKEY_ANALOG_ROTATE_CW},
{"Emulator controls", VIRTKEY_FASTFORWARD},
{"Extended PSP controls", VIRTKEY_AXIS_RIGHT_Y_MAX},
};

void ControlMappingScreen::CreateViews() {
using namespace UI;
mappers_.clear();
Expand Down Expand Up @@ -279,25 +293,12 @@ void ControlMappingScreen::CreateViews() {
size_t numMappableKeys = 0;
const KeyMap::KeyMap_IntStrPair *mappableKeys = KeyMap::GetMappableKeys(&numMappableKeys);

struct Cat {
const char *catName;
int firstKey;
bool *open;
};
// Category name, first input from psp_button_names.
static const Cat cats[] = {
{"Standard PSP controls", CTRL_UP, &categoryToggles_[0]},
{"Control modifiers", VIRTKEY_ANALOG_ROTATE_CW, &categoryToggles_[1]},
{"Emulator controls", VIRTKEY_FASTFORWARD, &categoryToggles_[2]},
{"Extended PSP controls", VIRTKEY_AXIS_RIGHT_Y_MAX, &categoryToggles_[3]},
};

int curCat = -1;
CollapsibleSection *curSection = nullptr;
for (size_t i = 0; i < numMappableKeys; i++) {
if (curCat < (int)ARRAY_SIZE(cats) && mappableKeys[i].key == cats[curCat + 1].firstKey) {
if (curCat >= 0) {
curSection->SetOpenPtr(cats[curCat].open);
curSection->SetOpenPtr(&categoryToggles_[curCat]);
}
curCat++;
curSection = rightColumn->Add(new CollapsibleSection(km->T(cats[curCat].catName)));
Expand All @@ -310,8 +311,9 @@ void ControlMappingScreen::CreateViews() {
mappers_.push_back(mapper);
}
if (curCat >= 0 && curSection) {
curSection->SetOpenPtr(cats[curCat].open);
curSection->SetOpenPtr(&categoryToggles_[curCat]);
}
_dbg_assert_(curCat == ARRAY_SIZE(cats) - 1);

keyMapGeneration_ = KeyMap::g_controllerMapGeneration;
}
Expand Down

0 comments on commit 076194e

Please sign in to comment.