Config: Implement "isMovementAllowed" callback

This commit is contained in:
Maschell 2022-09-23 21:39:02 +02:00
parent e7eeb10873
commit 4a2f60592e

View File

@ -160,6 +160,8 @@ void ConfigUtils::displayMenu() {
KPADStatus kpad_data{}; KPADStatus kpad_data{};
KPADError kpad_error; KPADError kpad_error;
bool isItemMovementAllowed = true;
while (true) { while (true) {
buttonsTriggered = 0; buttonsTriggered = 0;
buttonsReleased = 0; buttonsReleased = 0;
@ -400,27 +402,29 @@ void ConfigUtils::displayMenu() {
const std::vector<WUPSConfigItem *> config_items = currentCategory->getItems(); const std::vector<WUPSConfigItem *> config_items = currentCategory->getItems();
if (buttonsTriggered & VPAD_BUTTON_DOWN) { if (isItemMovementAllowed) {
if (selectedBtn < config_items.size() - 1) { if (buttonsTriggered & VPAD_BUTTON_DOWN) {
selectedBtn++; if (selectedBtn < config_items.size() - 1) {
selectedBtn++;
redraw = true;
}
} else if (buttonsTriggered & VPAD_BUTTON_UP) {
if (selectedBtn > 0) {
selectedBtn--;
redraw = true;
}
} else if (buttonsTriggered & VPAD_BUTTON_B) {
currentCategory = nullptr;
selectedBtn = 0;
start = 0;
end = MAX_BUTTONS_ON_SCREEN;
auto catSize = currentConfig->config->getCategories().size();
if (catSize < MAX_BUTTONS_ON_SCREEN) {
end = catSize;
}
redraw = true; redraw = true;
continue;
} }
} else if (buttonsTriggered & VPAD_BUTTON_UP) {
if (selectedBtn > 0) {
selectedBtn--;
redraw = true;
}
} else if (buttonsTriggered & VPAD_BUTTON_B) {
currentCategory = nullptr;
selectedBtn = 0;
start = 0;
end = MAX_BUTTONS_ON_SCREEN;
auto catSize = currentConfig->config->getCategories().size();
if (catSize < MAX_BUTTONS_ON_SCREEN) {
end = catSize;
}
redraw = true;
continue;
} }
WUPSConfigButtons pressedButtons = WUPS_CONFIG_BUTTON_NONE; WUPSConfigButtons pressedButtons = WUPS_CONFIG_BUTTON_NONE;
@ -464,6 +468,18 @@ void ConfigUtils::displayMenu() {
pressedButtons |= WUPS_CONFIG_BUTTON_MINUS; pressedButtons |= WUPS_CONFIG_BUTTON_MINUS;
} }
if (!isItemMovementAllowed) {
if (buttonsTriggered & VPAD_BUTTON_B) {
pressedButtons |= WUPS_CONFIG_BUTTON_B;
}
if (buttonsTriggered & VPAD_BUTTON_UP) {
pressedButtons |= WUPS_CONFIG_BUTTON_UP;
}
if (buttonsTriggered & VPAD_BUTTON_DOWN) {
pressedButtons |= WUPS_CONFIG_BUTTON_UP;
}
}
if (pressedButtons != WUPS_CONFIG_BUTTON_NONE) { if (pressedButtons != WUPS_CONFIG_BUTTON_NONE) {
redraw = true; redraw = true;
} }
@ -536,6 +552,8 @@ void ConfigUtils::displayMenu() {
DrawUtils::endDraw(); DrawUtils::endDraw();
redraw = pressedButtons != WUPS_CONFIG_BUTTON_NONE; redraw = pressedButtons != WUPS_CONFIG_BUTTON_NONE;
isItemMovementAllowed = config_items[selectedBtn]->isMovementAllowed();
} }
} }