From 9922b98fa30072b93ed9501acdbcadcbdb30cfdd Mon Sep 17 00:00:00 2001 From: Chris Beck Date: Wed, 24 Dec 2014 05:00:44 -0500 Subject: [PATCH] move wml [inspect] impl to lua (and lua_gui2 namespace) --- data/lua/wml-tags.lua | 4 ++++ src/game_events/action_wml.cpp | 7 ------- src/scripting/game_lua_kernel.cpp | 9 +++++++++ src/scripting/game_lua_kernel.hpp | 1 + src/scripting/lua_gui2.cpp | 8 ++++++++ src/scripting/lua_gui2.hpp | 2 ++ 6 files changed, 24 insertions(+), 7 deletions(-) diff --git a/data/lua/wml-tags.lua b/data/lua/wml-tags.lua index ece1f3a013e1..fee5656e7269 100644 --- a/data/lua/wml-tags.lua +++ b/data/lua/wml-tags.lua @@ -1372,6 +1372,10 @@ function wml_actions.event(cfg) end end +function wml_actions.inspect(cfg) + wesnoth.gamestate_inspector(cfg) +end + function wml_actions.label(cfg) wesnoth.label(cfg) end diff --git a/src/game_events/action_wml.cpp b/src/game_events/action_wml.cpp index cca5ec38b374..45881fd8ee15 100644 --- a/src/game_events/action_wml.cpp +++ b/src/game_events/action_wml.cpp @@ -36,7 +36,6 @@ #include "game_errors.hpp" #include "game_preferences.hpp" #include "gettext.hpp" -#include "gui/dialogs/gamestate_inspector.hpp" #include "gui/dialogs/transient_message.hpp" #include "gui/dialogs/wml_message.hpp" #include "gui/widgets/window.hpp" @@ -734,12 +733,6 @@ WML_HANDLER_FUNCTION(heal_unit, event_info, cfg) } } -WML_HANDLER_FUNCTION(inspect, /*event_info*/, cfg) -{ - gui2::tgamestate_inspector inspect_dialog(cfg); - inspect_dialog.show(resources::screen->video()); -} - WML_HANDLER_FUNCTION(kill, event_info, cfg) { bool secondary_unit = cfg.has_child("secondary_unit"); diff --git a/src/scripting/game_lua_kernel.cpp b/src/scripting/game_lua_kernel.cpp index 10b55b459ecf..7373be45afcf 100644 --- a/src/scripting/game_lua_kernel.cpp +++ b/src/scripting/game_lua_kernel.cpp @@ -74,6 +74,7 @@ #include "scripting/lua_api.hpp" // for luaW_toboolean, etc #include "scripting/lua_common.hpp" #include "scripting/lua_cpp_function.hpp" +#include "scripting/lua_gui2.hpp" // for show_gamestate_inspector #include "scripting/lua_types.hpp" // for getunitKey, dlgclbkKey, etc #include "sdl/utils.hpp" // for surface #include "side_filter.hpp" // for side_filter @@ -490,6 +491,14 @@ static int impl_unit_variables_set(lua_State *L) return 0; } +int game_lua_kernel::intf_gamestate_inspector(lua_State *L) +{ + if (game_display_) { + return lua_gui2::show_gamestate_inspector(game_display_->video(), luaW_checkvconfig(L, 1)); + } + return 0; +} + /** * Gets the unit at the given location or with the given id. * - Arg 1: integer. diff --git a/src/scripting/game_lua_kernel.hpp b/src/scripting/game_lua_kernel.hpp index f00fc9f13215..23d5eb09eafb 100644 --- a/src/scripting/game_lua_kernel.hpp +++ b/src/scripting/game_lua_kernel.hpp @@ -74,6 +74,7 @@ class game_lua_kernel : public lua_kernel_base int intf_allow_undo(lua_State *); int intf_add_time_area(lua_State *); int intf_remove_time_area(lua_State *); + int intf_gamestate_inspector(lua_State *); int intf_get_unit(lua_State *); int intf_get_units(lua_State *); int intf_get_displayed_unit(lua_State*); diff --git a/src/scripting/lua_gui2.cpp b/src/scripting/lua_gui2.cpp index 5923b9ee9a5e..5744f2c73c5c 100644 --- a/src/scripting/lua_gui2.cpp +++ b/src/scripting/lua_gui2.cpp @@ -16,6 +16,7 @@ #include "gui/auxiliary/canvas.hpp" // for tcanvas #include "gui/auxiliary/window_builder.hpp" // for twindow_builder, etc +#include "gui/dialogs/gamestate_inspector.hpp" #include "gui/dialogs/lua_interpreter.hpp" #include "gui/widgets/clickable.hpp" // for tclickable_ #include "gui/widgets/control.hpp" // for tcontrol @@ -445,4 +446,11 @@ int show_lua_console(lua_State * /*L*/, CVideo & video, lua_kernel_base * lk) return 0; } +int show_gamestate_inspector(CVideo & video, const vconfig & cfg) +{ + gui2::tgamestate_inspector inspect_dialog(cfg); + inspect_dialog.show(video); + return 0; +} + } // end namespace lua_gui2 diff --git a/src/scripting/lua_gui2.hpp b/src/scripting/lua_gui2.hpp index 751fe6314cc7..946937209411 100644 --- a/src/scripting/lua_gui2.hpp +++ b/src/scripting/lua_gui2.hpp @@ -18,6 +18,7 @@ struct lua_State; class CVideo; class lua_kernel_base; +class vconfig; namespace lua_gui2 { @@ -29,6 +30,7 @@ int intf_set_dialog_canvas(lua_State *L); int intf_set_dialog_active(lua_State *L); int show_dialog(lua_State *L, CVideo & video); int show_lua_console(lua_State*L, CVideo & video, lua_kernel_base * lk); +int show_gamestate_inspector(CVideo & video, const vconfig & cfg); } // end namespace lua_gui2