/** * @brief This function is called by the main loop when there is an input event. * @param event the event to handle */ void LanguageScreen::notify_event(InputEvent &event) { static const InputEvent::KeyboardKey validation_keys[] = { InputEvent::KEY_SPACE, InputEvent::KEY_RETURN, InputEvent::KEY_NONE }; if (transition == NULL) { if (event.is_direction_pressed()) { int direction = event.get_direction(); if (direction == 2) { // up set_cursor_position((cursor_position - 1 + nb_languages) % nb_languages); Sound::play("cursor"); } else if (direction == 6) { // down set_cursor_position((cursor_position + 1) % nb_languages); Sound::play("cursor"); } } else if (event.is_keyboard_key_pressed(validation_keys) || event.is_joypad_button_pressed()) { FileTools::set_language(language_codes[cursor_position]); transition = Transition::create(Transition::FADE, Transition::OUT); transition->start(); } } }
/** * @brief Handles an input event in this phase. * @param event the event */ void SelectionMenuConfirmErase::notify_event(InputEvent &event) { if (event.is_keyboard_key_pressed(validation_keys)) { // to erase a savegame file we don't allow joypad buttons int cursor_position = menu->get_cursor_position(); if (cursor_position == 5) { // the user chose "Yes" menu->play_erase_sound(); delete_save_file(save_number_to_erase); menu->set_next_phase(new SelectionMenuSelectFile(menu, save_number_to_erase + 1)); } else if (cursor_position == 4) { // the user chose "No" menu->play_ok_sound(); menu->set_next_phase(new SelectionMenuSelectFile(menu, 4)); } } if (event.is_direction_pressed() && event.get_direction() % 4 == 0) { // right or left menu->move_cursor_left_or_right(); } }
/** * @brief Handles an input event in this phase. * @param event the event */ void SelectionMenuSelectFile::notify_event(InputEvent &event) { if (!menu->has_transition()) { if (event.is_keyboard_key_pressed(validation_keys) || event.is_joypad_button_pressed()) { menu->play_ok_sound(); int cursor_position = menu->get_cursor_position(); if (cursor_position == 5) { // the user chose "Options" menu->set_next_phase(new SelectionMenuOptions(menu)); } else if (cursor_position == 4) { // the user chose "Erase" menu->set_next_phase(new SelectionMenuEraseFile(menu)); } else { // the user chose a save Savegame **savegames = menu->get_savegames(); if (savegames[cursor_position - 1]->is_empty()) { // the savegame doesn't exist: ask the name menu->set_next_phase(new SelectionMenuChooseName(menu)); } else { // the savegame exists: choose the mode and then start the game menu->set_next_phase(new SelectionMenuChooseMode(menu)); } } } if (event.is_direction_pressed()) { switch (event.get_direction()) { case 6: // down menu->move_cursor_down(); break; case 2: // up menu->move_cursor_up(); break; case 0: // right case 4: // left menu->move_cursor_left_or_right(); break; default: break; } } } }
/** * @brief Handles an input event in this phase. * @param event the event */ void SelectionMenuOptions::notify_event(InputEvent &event) { if (event.is_direction_pressed()) { int direction = event.get_direction(); if (!modifying) { if (direction == 2) { // up move_cursor_up(); } else if (direction == 6) { // down move_cursor_down(); } } else { if (direction == 0) { // right set_option_next_value(); } else if (direction == 4) { // left set_option_previous_value(); } } } else if (event.is_keyboard_key_pressed(validation_keys) || event.is_joypad_button_pressed()) { if (cursor_position < nb_options) { // set an option if (!modifying) { menu->play_ok_sound(); left_arrow_sprite->restart_animation(); right_arrow_sprite->restart_animation(); label_texts[cursor_position]->set_text_color(Color::get_white()); value_texts[cursor_position]->set_text_color(Color::get_yellow()); menu->set_title_text("selection_menu.phase.options.changing"); modifying = true; } else { menu->play_letter_sound(); label_texts[cursor_position]->set_text_color(Color::get_yellow()); value_texts[cursor_position]->set_text_color(Color::get_white()); menu->set_title_text("selection_menu.phase.options"); modifying = false; } } else if (cursor_position == nb_options) { // back menu->play_ok_sound(); menu->set_next_phase(new SelectionMenuSelectFile(menu, 5)); } } }
/** * @brief Handles an event in this phase. * @param event the event */ void SelectionMenuEraseFile::notify_event(InputEvent &event) { if (event.is_keyboard_key_pressed(validation_keys) || event.is_joypad_button_pressed()) { int cursor_position = menu->get_cursor_position(); if (cursor_position == 5) { // the user chose "Quit" menu->set_exiting(); } else if (cursor_position == 4) { // the user chose "Cancel" menu->play_ok_sound(); menu->set_next_phase(new SelectionMenuSelectFile(menu, 4)); } else { int save_number_to_erase = cursor_position - 1; if (menu->get_savegame(save_number_to_erase)->is_empty()) { // the savegame doesn't exist: error sound menu->play_error_sound(); } else { // the savegame exists: confirm deleting it menu->play_ok_sound(); menu->set_next_phase(new SelectionMenuConfirmErase(menu, save_number_to_erase)); } } } if (event.is_direction_pressed()) { switch (event.get_direction()) { case 6: // down menu->move_cursor_down(); break; case 2: // up menu->move_cursor_up(); break; default: break; } } }