Exemple #1
0
/**
 * @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();
    }
  }
}
Exemple #2
0
/**
 * \brief This function is called by the game when a low-level event occurs.
 * \param event An input event.
 */
void GameCommands::notify_input(const InputEvent& event) {

  // If no game command is being customized, we look for a binding
  // for this input event and we ignore the event if no binding is found.
  // If a command is being customized, we consider instead this event as
  // the new binding for this game command.

  if (event.is_keyboard_key_pressed()) {
    keyboard_key_pressed(event.get_keyboard_key());
  }
  else if (event.is_keyboard_key_released()) {
    keyboard_key_released(event.get_keyboard_key());
  }
  else if (event.is_joypad_button_pressed()) {
    joypad_button_pressed(event.get_joypad_button());
  }
  else if (event.is_joypad_button_released()) {
    joypad_button_released(event.get_joypad_button());
  }
  else if (event.is_joypad_axis_moved()) {
    joypad_axis_moved(event.get_joypad_axis(), event.get_joypad_axis_state());
  }
  else if (event.is_joypad_hat_moved()) {
    joypad_hat_moved(event.get_joypad_hat(), event.get_joypad_hat_direction());
  }
}
/**
 * @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));
    }
  }
}
Exemple #5
0
/**
 * @brief This function is called by the main loop when there is an input event.
 * @param event the event to handle
 */
void TitleScreen::notify_event(InputEvent &event) {

  static const InputEvent::KeyboardKey keys[] = { InputEvent::KEY_SPACE, InputEvent::KEY_RETURN, InputEvent::KEY_NONE };

  if (event.is_keyboard_key_pressed(InputEvent::KEY_ESCAPE)) {
    solarus.set_exiting();
  }
  else if (current_phase == PHASE_TITLE
      && (event.is_joypad_button_pressed() || event.is_keyboard_key_pressed(keys))
      && counter >= 1
      && !transition_out->is_started()
      && !transition_out->is_finished()) {

    transition_out->start();
  }
}
/**
 * @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;
    }
  }
}