move clear_menu_item to lua implementation

This commit is contained in:
Chris Beck 2014-12-23 22:23:22 -05:00
parent 41e54fd009
commit 09ce8b5774
4 changed files with 20 additions and 13 deletions

View file

@ -1322,6 +1322,10 @@ function wml_actions.disallow_end_turn(cfg)
wesnoth.allow_end_turn(false)
end
function wml_actions.clear_menu_item(cfg)
wesnoth.clear_menu_item(cfg.id)
end
function wml_actions.set_menu_item(cfg)
wesnoth.set_menu_item(cfg.id, cfg)
end

View file

@ -555,19 +555,6 @@ WML_HANDLER_FUNCTION(clear_global_variable,/**/,pcfg)
verify_and_clear_global_variable(pcfg);
}
WML_HANDLER_FUNCTION(clear_menu_item, /*event_info*/, cfg)
{
const std::string ids = cfg["id"].str();
BOOST_FOREACH(const std::string& id, utils::split(ids, ',', utils::STRIP_SPACES)) {
if(id.empty()) {
WRN_NG << "[clear_menu_item] has been given an empty id=, ignoring" << std::endl;
continue;
}
resources::gamedata->get_wml_menu_items().erase(id);
}
}
WML_HANDLER_FUNCTION(color_adjust, /*event_info*/, cfg)
{
game_display &screen = *resources::screen;

View file

@ -783,6 +783,20 @@ int game_lua_kernel::intf_set_menu_item(lua_State *L)
return 0;
}
int game_lua_kernel::intf_clear_menu_item(lua_State *L)
{
std::string ids(luaL_checkstring(L, 1));
BOOST_FOREACH(const std::string& id, utils::split(ids, ',', utils::STRIP_SPACES)) {
if(id.empty()) {
WRN_LUA << "[clear_menu_item] has been given an empty id=, ignoring" << std::endl;
continue;
}
gamedata().get_wml_menu_items().erase(id);
}
return 0;
}
int game_lua_kernel::intf_shroud_op(lua_State *L, bool place_shroud)
{
vconfig cfg = luaW_checkvconfig(L, 1);
@ -3069,6 +3083,7 @@ game_lua_kernel::game_lua_kernel(const config &cfg, CVideo * video, game_state &
{ "add_tile_overlay", boost::bind(&game_lua_kernel::intf_add_tile_overlay, this, _1) },
{ "allow_end_turn", boost::bind(&game_lua_kernel::intf_allow_end_turn, this, _1) },
{ "allow_undo", boost::bind(&game_lua_kernel::intf_allow_undo, this, _1) },
{ "clear_menu_item", boost::bind(&game_lua_kernel::intf_clear_menu_item, this, _1) },
{ "clear_messages", boost::bind(&game_lua_kernel::intf_clear_messages, this, _1) },
{ "delay", boost::bind(&game_lua_kernel::intf_delay, this, _1) },
{ "extract_unit", boost::bind(&game_lua_kernel::intf_extract_unit, this, _1) },

View file

@ -107,6 +107,7 @@ class game_lua_kernel : public lua_kernel_base
int intf_extract_unit(lua_State *L);
int intf_find_vacant_tile(lua_State *L);
int intf_float_label(lua_State *L);
int intf_clear_menu_item(lua_State *L);
int intf_set_menu_item(lua_State *L);
int intf_shroud_op(lua_State *L, bool place_shroud);
int intf_simulate_combat(lua_State *L);