Ejemplo n.º 1
0
/**
 * \brief Notifies Lua that an input event has just occurred.
 *
 * The appropriate callback in sol.main is triggered if it exists.
 *
 * \param event The input event to handle.
 * \return \c true if the event was handled and should stop being propagated.
 */
bool LuaContext::main_on_input(const InputEvent& event) {

  bool handled = false;
  push_main(l);
  handled = on_input(event);
  if (!handled) {
    handled = menus_on_input(-1, event);
  }
  lua_pop(l, 1);
  return handled;
}
Ejemplo n.º 2
0
/**
 * @brief Notifies a Lua game that an input event has just occurred.
 *
 * The appropriate callback in the game is triggered if it exists.
 *
 * @param game A game.
 * @param event The input event to handle.
 * @return \c true if the event was handled and should stop being propagated.
 */
bool LuaContext::game_on_input(Game& game, InputEvent& event) {

  bool handled = false;
  push_game(l, game.get_savegame());
  handled = on_input(event);
  if (!handled) {
    handled = menus_on_input(-1, event);
  }
  lua_pop(l, 1);
  return handled;
}
Ejemplo n.º 3
0
/**
 * \brief Notifies a Lua game that an input event has just occurred.
 *
 * The appropriate callback in the game is triggered if it exists.
 * Also notifies the menus of the game if the game itself does not handle the
 * event.
 *
 * \param game A game.
 * \param event The input event to handle.
 * \return \c true if the event was handled and should stop being propagated.
 */
bool LuaContext::game_on_input(Game& game, const InputEvent& event) {

  if (!game.get_savegame().is_known_to_lua()) {
    return false;
  }

  bool handled = false;
  push_game(l, game.get_savegame());
  if (game.get_savegame().is_with_lua_table()) {
    handled = on_input(event);
  }
  if (!handled) {
    handled = menus_on_input(-1, event);
  }
  lua_pop(l, 1);
  return handled;
}
Ejemplo n.º 4
0
/**
 * \brief Calls an input callback method of a Lua menu.
 * \param menu_ref A reference to the menu object.
 * \param event The input event to forward.
 * \return \c true if the event was handled and should stop being propagated.
 */
bool LuaContext::menu_on_input(
    const ScopedLuaRef& menu_ref,
    const InputEvent& event
) {
  // Get the Lua menu.
  push_ref(l, menu_ref);

  // Send the event to children menus first.
  bool handled = menus_on_input(-1, event);

  if (!handled) {
    // Sent the event to this menu.
    handled = on_input(event);
  }

  // Remove the menu from the stack.
  lua_pop(l, 1);

  return handled;
}