Add categories for control bindings

This commit is contained in:
Henrik Rydgård
2023-12-20 16:20:26 +01:00
parent 2d4e59eb62
commit 9cb3d03098
7 changed files with 70 additions and 14 deletions
+28 -1
View File
@@ -275,13 +275,40 @@ void ControlMappingScreen::CreateViews() {
root_->Add(rightScroll_);
std::vector<KeyMap::KeyMap_IntStrPair> mappableKeys = KeyMap::GetMappableKeys();
struct Cat {
const char *catName;
int firstKey;
bool openByDefault;
};
// Category name, first input from psp_button_names.
static const Cat cats[] = {
{"Standard PSP controls", CTRL_UP, true},
{"Control modifiers", VIRTKEY_ANALOG_ROTATE_CW, true},
{"Emulator controls", VIRTKEY_FASTFORWARD, true},
{"Extended PSP controls", VIRTKEY_AXIS_RIGHT_Y_MAX, false},
};
int curCat = -1;
CollapsibleSection *curSection = nullptr;
for (size_t i = 0; i < mappableKeys.size(); i++) {
SingleControlMapper *mapper = rightColumn->Add(
if (curCat < (int)ARRAY_SIZE(cats) && mappableKeys[i].key == cats[curCat + 1].firstKey) {
if (curCat >= 0 && !cats[curCat].openByDefault) {
curSection->SetOpen(false);
}
curCat++;
curSection = rightColumn->Add(new CollapsibleSection(km->T(cats[curCat].catName)));
curSection->SetSpacing(6.0f);
}
SingleControlMapper *mapper = curSection->Add(
new SingleControlMapper(mappableKeys[i].key, mappableKeys[i].name, screenManager(),
new LinearLayoutParams(FILL_PARENT, WRAP_CONTENT)));
mapper->SetTag(StringFromFormat("KeyMap%s", mappableKeys[i].name));
mappers_.push_back(mapper);
}
if (curCat >= 0 && curSection && !cats[curCat].openByDefault) {
curSection->SetOpen(false);
}
keyMapGeneration_ = KeyMap::g_controllerMapGeneration;
}