Mario Editor: add keyboard control to menu
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
ab6dcccbac
commit
fffa56706d
@ -29,15 +29,24 @@ void resumeMainMenuCallback(void * /*UNUSED*/, Button * /*UNUSED*/) {
|
||||
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() {
|
||||
__update_scenes_main_menu = false;
|
||||
__quit_scenes_main_menu = false;
|
||||
__cur_button_index_main_menu = -1;
|
||||
__cur_button_index_main_menu_down = -1;
|
||||
__mouse_main_menu->setPos(0, 0);
|
||||
for (auto &button : __buttons_main_menu) {
|
||||
button->unsetHighlight();
|
||||
}
|
||||
}
|
||||
|
||||
void handleKeyUpMainMenu(SDL_Keycode key, SDLPP::Scene & /*UNUSED*/) {
|
||||
@ -45,6 +54,28 @@ void handleKeyUpMainMenu(SDL_Keycode key, SDLPP::Scene & /*UNUSED*/) {
|
||||
case SDLK_ESCAPE:
|
||||
resumeMainMenu();
|
||||
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:
|
||||
break;
|
||||
}
|
||||
@ -139,15 +170,7 @@ void getMousePositionFlagsMainMenu(SDLPP::Scene &scene) {
|
||||
|
||||
MouseVisitor visitor;
|
||||
scene.visitCollisions(*mouse, visitor);
|
||||
if (visitor.getCurButton() != __cur_button_index_main_menu) {
|
||||
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();
|
||||
__updateSelectedButton_MainMenu(visitor.getCurButton());
|
||||
}
|
||||
|
||||
void pollEventsMainMenu(std::shared_ptr<SDLPP::Scene> &scene) {
|
||||
@ -193,5 +216,6 @@ createEditorMainMenuScene(std::shared_ptr<SDLPP::Renderer> &renderer) {
|
||||
ret.additionalRender = additionalRenderMainMenu;
|
||||
ret.doInput = pollEventsMainMenu;
|
||||
__update_scenes_main_menu = true;
|
||||
__updateSelectedButton_MainMenu(0);
|
||||
return ret;
|
||||
}
|
Loading…
Reference in New Issue
Block a user