/** * @brief Calls the on_command_released() method of a Lua game. * @param game A game. * @param command The command released. * @return \c true if the event was handled and should stop being propagated. */ bool LuaContext::game_on_command_released(Game& game, GameCommands::Command command) { bool handled = false; push_game(l, game.get_savegame()); handled = on_command_released(command); if (!handled) { handled = menus_on_command_released(-1, command); } lua_pop(l, 1); return handled; }
/** * \brief Calls the on_command_released() method of a Lua game if it exists. * * Also notifies the menus of the game if the game itself does not handle the * event. * * \param game A game. * \param command The command released. * \return \c true if the event was handled and should stop being propagated. */ bool LuaContext::game_on_command_released(Game& game, GameCommands::Command command) { if (!game.get_savegame().is_known_to_lua()) { return false; } bool handled = false; push_game(l, game.get_savegame()); if (userdata_has_field(game.get_savegame(), "on_command_released")) { handled = on_command_released(command); } if (!handled) { handled = menus_on_command_released(-1, command); } lua_pop(l, 1); return handled; }
/** * \brief Calls the on_command_released() method of a Lua menu. * \param menu_ref A reference to the menu object. * \param command The game command just released. * \return \c true if the event was handled and should stop being propagated. */ bool LuaContext::menu_on_command_released( const ScopedLuaRef& menu_ref, GameCommand command ) { push_ref(l, menu_ref); // Send the event to children menus first. bool handled = menus_on_command_released(-1, command); if (!handled) { // Sent the event to this menu. handled = on_command_released(command); } lua_pop(l, 1); return handled; }