Mario Editor: add keyboard control to menu
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
zv0n 2022-07-22 13:26:23 +02:00
parent ab6dcccbac
commit fffa56706d

View File

@ -29,15 +29,24 @@ void resumeMainMenuCallback(void * /*UNUSED*/, Button * /*UNUSED*/) {
resumeMainMenu(); resumeMainMenu();
} }
void __updateSelectedButton_MainMenu(uint64_t new_index) {
if (new_index != __cur_button_index_main_menu &&
new_index != (uint64_t)-1) {
__buttons_main_menu[new_index]->setHighlight();
if (__cur_button_index_main_menu != (uint64_t)-1) {
__buttons_main_menu[__cur_button_index_main_menu]
->unsetHighlight();
}
__cur_button_index_main_menu = new_index;
}
}
void resetGlobals() { void resetGlobals() {
__update_scenes_main_menu = false; __update_scenes_main_menu = false;
__quit_scenes_main_menu = false; __quit_scenes_main_menu = false;
__cur_button_index_main_menu = -1;
__cur_button_index_main_menu_down = -1; __cur_button_index_main_menu_down = -1;
__mouse_main_menu->setPos(0, 0); __mouse_main_menu->setPos(0, 0);
for (auto &button : __buttons_main_menu) {
button->unsetHighlight();
}
} }
void handleKeyUpMainMenu(SDL_Keycode key, SDLPP::Scene & /*UNUSED*/) { void handleKeyUpMainMenu(SDL_Keycode key, SDLPP::Scene & /*UNUSED*/) {
@ -45,6 +54,28 @@ void handleKeyUpMainMenu(SDL_Keycode key, SDLPP::Scene & /*UNUSED*/) {
case SDLK_ESCAPE: case SDLK_ESCAPE:
resumeMainMenu(); resumeMainMenu();
break; break;
case SDLK_DOWN:
case SDLK_s:
if(__cur_button_index_main_menu == __buttons_main_menu.size() - 1) {
__updateSelectedButton_MainMenu(0);
} else {
__updateSelectedButton_MainMenu(__cur_button_index_main_menu + 1);
}
break;
case SDLK_UP:
case SDLK_w:
if(__cur_button_index_main_menu == 0) {
__updateSelectedButton_MainMenu(__buttons_main_menu.size() - 1);
} else {
__updateSelectedButton_MainMenu(__cur_button_index_main_menu - 1);
}
break;
case SDLK_RETURN:
if(__cur_button_index_main_menu >= 0 && __cur_button_index_main_menu < __buttons_main_menu.size()) {
__buttons_main_menu[__cur_button_index_main_menu]
->performFunction();
}
break;
default: default:
break; break;
} }
@ -139,15 +170,7 @@ void getMousePositionFlagsMainMenu(SDLPP::Scene &scene) {
MouseVisitor visitor; MouseVisitor visitor;
scene.visitCollisions(*mouse, visitor); scene.visitCollisions(*mouse, visitor);
if (visitor.getCurButton() != __cur_button_index_main_menu) { __updateSelectedButton_MainMenu(visitor.getCurButton());
if (__cur_button_index_main_menu != (uint64_t)-1) {
__buttons_main_menu[__cur_button_index_main_menu]->unsetHighlight();
}
if (visitor.getCurButton() != (uint64_t)-1) {
__buttons_main_menu[visitor.getCurButton()]->setHighlight();
}
}
__cur_button_index_main_menu = visitor.getCurButton();
} }
void pollEventsMainMenu(std::shared_ptr<SDLPP::Scene> &scene) { void pollEventsMainMenu(std::shared_ptr<SDLPP::Scene> &scene) {
@ -193,5 +216,6 @@ createEditorMainMenuScene(std::shared_ptr<SDLPP::Renderer> &renderer) {
ret.additionalRender = additionalRenderMainMenu; ret.additionalRender = additionalRenderMainMenu;
ret.doInput = pollEventsMainMenu; ret.doInput = pollEventsMainMenu;
__update_scenes_main_menu = true; __update_scenes_main_menu = true;
__updateSelectedButton_MainMenu(0);
return ret; return ret;
} }