Skip to content

Commit

Permalink
move wml [inspect] impl to lua (and lua_gui2 namespace)
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeck88 committed Dec 24, 2014
1 parent ca58a71 commit 9922b98
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 7 deletions.
4 changes: 4 additions & 0 deletions data/lua/wml-tags.lua
Expand Up @@ -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
Expand Down
7 changes: 0 additions & 7 deletions src/game_events/action_wml.cpp
Expand Up @@ -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"
Expand Down Expand Up @@ -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");
Expand Down
9 changes: 9 additions & 0 deletions src/scripting/game_lua_kernel.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions src/scripting/game_lua_kernel.hpp
Expand Up @@ -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*);
Expand Down
8 changes: 8 additions & 0 deletions src/scripting/lua_gui2.cpp
Expand Up @@ -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
Expand Down Expand Up @@ -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
2 changes: 2 additions & 0 deletions src/scripting/lua_gui2.hpp
Expand Up @@ -18,6 +18,7 @@
struct lua_State;
class CVideo;
class lua_kernel_base;
class vconfig;

namespace lua_gui2 {

Expand All @@ -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

Expand Down

0 comments on commit 9922b98

Please sign in to comment.