Пример #1
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());
  }
}
Пример #2
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();
  }
}
Пример #3
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();
    }
  }
}
Пример #4
0
/**
 * @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();
  }
}
Пример #5
0
/**
 * @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;
      }
    }
  }
}
Пример #6
0
/**
 * @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));
    }
  }
}
Пример #7
0
/**
 * @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;
    }
  }
}
Пример #8
0
/**
* @brief Calls an input callback method of the object on top of the stack.
* @param event The input event to forward.
* @return \c true if the event was handled and should stop being propagated.
*/
bool LuaContext::on_input(InputEvent& event) 
{
  // Call the Lua function(s) corresponding to this input event.
  bool handled = false;
  if (event.is_keyboard_event()) 
  {
    // Keyboard.
    if (event.is_keyboard_key_pressed()) 
	{
      handled = on_key_pressed(event) || handled;/*
      if (event.is_character_pressed()) 
	  {
        handled = on_character_pressed(event) || handled;
      }*/
    }
    /*
	else if (event.is_keyboard_key_released()) 
	{
      handled = on_key_released(event) || handled;
    }
	*/
  }
  //TODO Change this to mouse input events 
  /*
  else if (event.is_joypad_event()) 
  {
    // Joypad.
    if (event.is_joypad_button_pressed()) {
      handled = on_joypad_button_pressed(event) || handled;
    }
    else if (event.is_joypad_button_released()) {
      handled = on_joypad_button_released(event) || handled;
    }
    else if (event.is_joypad_axis_moved()) {
      handled = on_joypad_axis_moved(event) || handled;
    }
    else if (event.is_joypad_hat_moved()) {
      handled = on_joypad_hat_moved(event) || handled;
    }
  }*/

  return handled;
}
Пример #9
0
/**
 * \brief This function is called when there is an input event.
 *
 * It handles the events common to all screens:
 * closing the window, pressing F5 or a debug key.
 * The notify_input() method of the current screen
 * is then called.
 */
void MainLoop::notify_input(const InputEvent& event) {

  if (event.is_window_closing()) {
    exiting = true;
  }
  else if (event.is_keyboard_key_pressed()) {
    // A key was pressed.
#if defined(PANDORA)
    // TODO make a clean flag
    if (event.get_keyboard_key() == InputEvent::KEY_ESCAPE) {
      exiting = true;
    }
#endif
  }

  // Send the event to Lua and to the current screen.
  bool handled = lua_context->notify_input(event);
  if (!handled && game != NULL) {
    game->notify_input(event);
  }
}
Пример #10
0
/**
 * @brief This function is called when there is an input event.
 *
 * It handles the events common to all screens:
 * closing the window, pressing F5 or a debug key.
 * The notify_event() method of the current screen
 * is then called.
 */
void Solarus::notify_event(InputEvent& event) {

  // handle the common events
  InputEvent::KeyboardKey key = event.get_keyboard_key();

  if (event.is_window_closing()) {
    exiting = true;
  }
  else if (event.is_keyboard_key_pressed()) {
    // a key is pressed
    if (key == InputEvent::KEY_F5) {
      // F5: change the video mode
      VideoManager::get_instance()->switch_video_mode();
    }
    else if (key == InputEvent::KEY_RETURN
        && (event.is_alt_down() || event.is_control_down())) {
      // Alt + Return or Ctrl + Return: switch fullscreen
      VideoManager::get_instance()->switch_fullscreen();
    }
    else if (key == InputEvent::KEY_F4 && event.is_alt_down()) {
      // Alt + F4: quit the program
      exiting = true;
    }
#if defined(PANDORA)
    else if (key == InputEvent::KEY_ESCAPE) {
      exiting = true;
    }
#endif
    else {
      debug_keys->key_pressed(key);
    }
  }
  else if (event.is_keyboard_key_released()) {
    // a key is released
    debug_keys->key_released(key);
  }

  // send the event to the current screen
  current_screen->notify_event(event);
}
Пример #11
0
void GameControls::notify_input(InputEvent &event) {
	if(event.is_keyboard_key_pressed())
		key_pressed(event.get_keyboard_key());
	else if(event.is_keyboard_key_released())
		key_released(event.get_keyboard_key());
}