Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI crash fix in control mapping screen #19165

Merged
merged 3 commits into from
May 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading