new 'inspect' debug command, new [inspect] debug tag,

...new gamestate inspector dialog (prototype)
This commit is contained in:
Iurii Chernyi 2009-09-05 11:02:23 +00:00
parent a1fd0454ff
commit 2bac79fad0
15 changed files with 539 additions and 0 deletions

View file

@ -8,6 +8,9 @@ Version 1.7.5+svn:
* Added a couple of missing frames for the Inferno Drake
* Language and i18n:
* Updated translations: Estonian, Spanish.
* User interface:
* new gamestate inspector debug dialog (via 'inspect' command
and '[inspect]' tag)
* WML engine:
* Fix silent=yes for objectives
* Miscellaneous and bugfixes:

View file

@ -0,0 +1,256 @@
#textdomain wesnoth-lib
###
### Definition of the window to control gamestate inspector.
###
[window]
id = "gamestate_inspector"
description = "Gamestate inspector dialog."
[resolution]
definition = "default"
automatic_placement = "true"
vertical_placement = "top"
horizontal_placement = "left"
[linked_group]
id = "name"
fixed_width = "true"
[/linked_group]
[grid]
[row] #header
grow_factor = 0
[column]
grow_factor = 7
border = "all"
border_size = 5
horizontal_alignment = "left"
[label]
definition = "title"
label = _ "Gamestate Inspector"
[/label]
[/column]
[column]
grow_factor = 0
[spacer]
definition = "default"
[/spacer]
[/column]
[/row]
[row] #menu
grow_factor = 0
[column]
grow_factor = 7
border = "all"
border_size = 5
horizontal_alignment = "left"
[label]
id="inspector_name"
definition = "default"
label= ""
[/label]
[/column]
[column]
grow_factor = 0
border = "all"
border_size = 5
horizontal_alignment = "left"
[spacer]
definition = "default"
[/spacer]
[/column]
[/row]
[row] #stack-title
grow_factor = 4
[column]
grow_factor = 7
[grid]
[row]
[column]
grow_factor = 3
border = "all"
border_size = 5
horizontal_alignment = "left"
[label]
definition = "default"
label= _ "Content"
[/label]
[/column]
[column]
grow_factor = 4
border = "all"
border_size = 5
horizontal_alignment = "left"
[label]
definition = "default"
label= _ "Inspection window"
[/label]
[/column]
[/row]
[row]
[column]
grow_factor = 3
border = "all"
border_size = 5
vertical_alignment = "top"
horizontal_alignment = "left"
[listbox]
id = "stuff_list"
definition = "default"
[header]
[row]
[column]
grow_factor = 1
horizontal_grow = "true"
border = "all"
border_size = 5
[label]
id = "name"
definition = "default"
linked_group = "name"
label = _ "Variable"
[/label]
[/column]
[/row]
[/header]
[list_definition]
[row]
[column]
vertical_grow = "true"
horizontal_grow = "true"
[toggle_panel]
definition = "default"
[grid]
[row]
[column]
grow_factor = 1
horizontal_grow = "true"
border = "all"
border_size = 5
[label]
id = "name"
definition = "default"
linked_group = "name"
[/label]
[/column]
[/row]
[/grid]
[/toggle_panel]
[/column]
[/row]
[/list_definition]
[/listbox]
[/column]
[column]
grow_factor = 4
border = "all"
border_size = 5
vertical_alignment = "top"
horizontal_alignment = "left"
[scroll_label]
id = "inspect"
definition = "default"
[/scroll_label]
[/column]
[/row]
[/grid]
[/column]
[column]
grow_factor = 0
horizontal_alignment="center"
vertical_alignment = "top"
[grid]
[row]
[column]
[label]
definition = "default"
label = _ "Actions"
[/label]
[/column]
[/row]
# [row]
# [column]
# [button]
# grow_factor = 0
# horizontal_alignment="center"
# vertical_alignment = "top"
# id = "add_variable"
# definition = "default"
# label = _ "Add variable"
# [/button]
# [/column]
# [/row]
# [row]
# [column]
# [button]
# grow_factor = 0
# horizontal_alignment="center"
# vertical_alignment = "top"
# id = "modify_variable"
# definition = "default"
# label = _ "Modify variable"
# [/button]
# [/column]
# [/row]
# [row]
# [column]
# [button]
# grow_factor = 0
# horizontal_alignment="center"
# vertical_alignment = "top"
# id = "delete_variable"
# definition = "default"
# label = _ "Delete variable"
# [/button]
# [/column]
# [/row]
[/grid]
[/column]
[/row]
[row] #status
grow_factor = 0
[column]
grow_factor = 7
border = "all"
border_size = 5
horizontal_alignment = "left"
[spacer]
definition = "default"
[/spacer]
[/column]
[column]
grow_factor = 0
[button]
id = "cancel"
definition = "default"
label = _ "Close"
[/button]
[/column]
[/row]
[/grid]
[/resolution]
[/window]

View file

@ -528,6 +528,23 @@ Also, 0..9 = $below_ten, one,two,three = $ascii and the bonus answer is $mixed."
text="dialog"
[/label]
[label]
x,y=18,4
text="Gamestate Inspector"
[/label]
[event]
name=moveto
first_time_only=no
[filter]
x,y,side=18,4,1
[/filter]
[inspect]
name="moveto(18,4)"
[/inspect]
[/event]
[event]
name=moveto
first_time_only=no

View file

@ -301,6 +301,8 @@
<Unit filename="..\..\src\gui\dialogs\game_load.hpp" />
<Unit filename="..\..\src\gui\dialogs\game_save.cpp" />
<Unit filename="..\..\src\gui\dialogs\game_save.hpp" />
<Unit filename="..\..\src\gui\dialogs\gamestate_inspector.cpp" />
<Unit filename="..\..\src\gui\dialogs\gamestate_inspector.hpp" />
<Unit filename="..\..\src\gui\dialogs\helper.hpp" />
<Unit filename="..\..\src\gui\dialogs\language_selection.cpp" />
<Unit filename="..\..\src\gui\dialogs\language_selection.hpp" />

View file

@ -330,6 +330,8 @@
<Unit filename="..\..\src\gui\dialogs\game_load.hpp" />
<Unit filename="..\..\src\gui\dialogs\game_save.cpp" />
<Unit filename="..\..\src\gui\dialogs\game_save.hpp" />
<Unit filename="..\..\src\gui\dialogs\gamestate_inspector.cpp" />
<Unit filename="..\..\src\gui\dialogs\gamestate_inspector.hpp" />
<Unit filename="..\..\src\gui\dialogs\helper.hpp" />
<Unit filename="..\..\src\gui\dialogs\language_selection.cpp" />
<Unit filename="..\..\src\gui\dialogs\language_selection.hpp" />

View file

@ -1987,6 +1987,34 @@
/>
</FileConfiguration>
</File>
<File
RelativePath="..\..\src\gui\dialogs\gamestate_inspector.cpp"
>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
ObjectFile="$(IntDir)\Gui\Dialogs\"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
ObjectFile="$(IntDir)\Gui\Dialogs\"
/>
</FileConfiguration>
<FileConfiguration
Name="Debug (fast)|Win32"
>
<Tool
Name="VCCLCompilerTool"
ObjectFile="$(IntDir)\Gui\Dialogs\"
/>
</FileConfiguration>
</File>
<File
RelativePath="..\..\src\gui\dialogs\language_selection.cpp"
>
@ -5466,6 +5494,10 @@
RelativePath="..\..\src\gui\dialogs\game_save.hpp"
>
</File>
<File
RelativePath="..\..\src\gui\dialogs\gamestate_inspector.hpp"
>
</File>
<File
RelativePath="..\..\src\gui\dialogs\helper.hpp"
>

View file

@ -251,6 +251,7 @@ set(wesnoth-main_SRC
gui/dialogs/game_load.cpp
gui/dialogs/game_delete.cpp
gui/dialogs/game_save.cpp
gui/dialogs/gamestate_inspector.cpp
gui/dialogs/language_selection.cpp
gui/dialogs/lobby_main.cpp
gui/dialogs/lobby_player_info.cpp

View file

@ -131,6 +131,7 @@ wesnoth_source = \
gui/dialogs/game_load.cpp \
gui/dialogs/game_delete.cpp \
gui/dialogs/game_save.cpp \
gui/dialogs/gamestate_inspector.cpp \
gui/dialogs/language_selection.cpp \
gui/dialogs/lobby_main.cpp \
gui/dialogs/lobby_player_info.cpp \

View file

@ -291,6 +291,7 @@ wesnoth_sources = Split("""
gui/dialogs/game_load.cpp
gui/dialogs/game_delete.cpp
gui/dialogs/game_save.cpp
gui/dialogs/gamestate_inspector.cpp
gui/dialogs/language_selection.cpp
gui/dialogs/lobby_main.cpp
gui/dialogs/lobby_player_info.cpp

View file

@ -27,6 +27,7 @@
#include "game_events.hpp"
#include "game_preferences.hpp"
#include "gettext.hpp"
#include "gui/dialogs/gamestate_inspector.hpp"
#include "gui/dialogs/wml_message.hpp"
#include "gui/widgets/settings.hpp"
#include "gui/widgets/window.hpp"
@ -827,6 +828,14 @@ WML_HANDLER_FUNCTION(gold, /*event_info*/, cfg)
}
}
WML_HANDLER_FUNCTION(inspect, /*event_info*/, cfg)
{
if (game_config::debug) {
gui2::tgamestate_inspector inspect_dialog(cfg);
inspect_dialog.show(resources::screen->video());
}
}
WML_HANDLER_FUNCTION(modify_ai, /*event_info*/, cfg)
{
std::string side = cfg["side"];

View file

@ -0,0 +1,163 @@
/* $Id$ */
/*
Copyright (C) 2009 by Yurii Chernyi <terraninfo@terraninfo.net>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2
or at your option any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
#define GETTEXT_DOMAIN "wesnoth-lib"
#include "gui/dialogs/gamestate_inspector.hpp"
#include "gui/dialogs/helper.hpp"
#include "gui/widgets/button.hpp"
#include "gui/widgets/listbox.hpp"
#include "gui/widgets/window.hpp"
#include "../../foreach.hpp"
#include "../../gamestatus.hpp"
#include "../../resources.hpp"
#include "../../team.hpp"
#include "../../ai/manager.hpp"
#include <boost/bind.hpp>
namespace gui2 {
/*WIKI
* @page = GUIWindowDefinitionWML
* @order = 2_gamestate_inspector
*
* == Gamestate inspector ==
*
* This shows the gamestate inspector
*
* @start_table = grid
* (inspector_name) (control) () Name of the inspector
* (stuff_list) (control) () List of various stuff that can be viewed
* (inspect) (control) () The state of the variable or event
* @end_table
*/
tgamestate_inspector::tgamestate_inspector(const vconfig &cfg)
: cfg_(cfg)
{
}
twindow* tgamestate_inspector::build_window(CVideo& video)
{
return build(video, get_id(GAMESTATE_INSPECTOR));
}
static void add_row_to_stuff_list(tlistbox& list, const std::string &id, const std::string &label)
{
std::map<std::string, string_map> data;
string_map item;
item["id"] = id;
item["label"] = label;
data.insert(std::make_pair("name", item));
list.add_row(data);
}
static void inspect_var(twindow& window, const std::string &s)
{
std::string s_ = s;
if (s_.length()>20000) {//workaround for known bug
s_.resize(20000);
}
tcontrol *i = NEW_find_widget<tcontrol>(&window, "inspect", false,true);
i->set_label(s_);
window.invalidate_layout();//workaround for assertion failure
}
static void inspect_vars(twindow& window)
{
tlistbox& list = NEW_find_widget<tlistbox>(
&window, "stuff_list", false);
int selected = list.get_selected_row();
if (selected==-1) {
inspect_var(window,"");
return;
}
int i = 0;//@todo: replace with precached data
const config &vars = resources::state_of_game->get_variables();
foreach( const config::attribute &a, vars.attribute_range()) {
if (selected==i) {
inspect_var(window, a.second);
return;
}
i++;
}
foreach( const config::any_child &c, vars.all_children_range()) {
if (selected==i) {
inspect_var(window, c.cfg.debug());
return;
}
i++;
}
}
/*
static void inspect_ai(twindow& window, int side)
{
const config &ai_cfg = ai::manager::to_config(side);
NEW_find_widget<tcontrol>(&window, "inspect", false).set_label(ai_cfg.debug());
}
*/
void tgamestate_inspector::pre_show(CVideo& /*video*/, twindow& window)
{
NEW_find_widget<tcontrol>(&window, "inspector_name", false).set_label(cfg_["name"]);
tlistbox& list = NEW_find_widget<tlistbox>(
&window, "stuff_list", false);
list.set_callback_value_change(
dialog_callback<tgamestate_inspector, &tgamestate_inspector::stuff_list_item_clicked>);
const config &vars = resources::state_of_game->get_variables();
foreach( const config::attribute &a, vars.attribute_range()) {
add_row_to_stuff_list(list,a.first,a.first);
}
foreach( const config::any_child &c, vars.all_children_range()) {
add_row_to_stuff_list(list,"["+c.key+"]","["+c.key+"]");
}
inspect_vars(window);
//add_row_to_stuff_list(list,"vars","vars");
//foreach team
//int sides = static_cast<int>((*resources::teams).size());
//for( int side = 1; side<=sides; ++side) {
// std::string side_str = str_cast(side);
// add_row_to_stuff_list(list,"AI"+side_str,"AI"+side_str);
// side++;
//}
}
void tgamestate_inspector::stuff_list_item_clicked(twindow &window)
{
inspect_vars(window);
}
} //end of namespace gui2

View file

@ -0,0 +1,38 @@
/* $Id$ */
/*
Copyright (C) 2009 by Yurii Chernyi <terraninfo@terraninfo.net>
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2
or at your option any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
#ifndef GUI_DIALOGS_GAMESTATE_INSPECTOR_HPP_INCLUDED
#define GUI_DIALOGS_GAMESTATE_INSPECTOR_HPP_INCLUDED
#include "gui/dialogs/dialog.hpp"
#include "../../variable.hpp"
namespace gui2 {
class tgamestate_inspector : public tdialog {
public:
tgamestate_inspector(const vconfig &cfg);
/** Inherited from tdialog. */
twindow* build_window(CVideo& video);
/** Inherited from tdialog. */
void pre_show(CVideo& video, twindow& window);
private:
vconfig cfg_;
void stuff_list_item_clicked(twindow &window);
};
}
#endif /* ! GUI_DIALOGS_GAMESTATE_INSPECTOR_HPP_INCLUDED */

View file

@ -103,6 +103,7 @@ static void fill_window_types()
window_type_list[LOBBY_PLAYER_INFO] = "lobby_player_info";
window_type_list[UNIT_CREATE] = "unit_create";
window_type_list[FORMULA_DEBUGGER] = "formula_debugger";
window_type_list[GAMESTATE_INSPECTOR] = "gamestate_inspector";
}
const std::string& get_id(const twindow_type window_type)

View file

@ -76,6 +76,7 @@ enum twindow_type {
LOBBY_PLAYER_INFO, /**< MP lobby player info dialog */
UNIT_CREATE, /**< Debug-mode unit creation dialog */
FORMULA_DEBUGGER, /**< Formula debugger dialog */
GAMESTATE_INSPECTOR, /**< Visual inspector of the game state (WML variables, events)*/
COUNT /**<
* The last one to hold the number of items and as
* sentinel.

View file

@ -30,6 +30,7 @@
#include "game_events.hpp"
#include "gettext.hpp"
#include "gui/dialogs/transient_message.hpp"
#include "gui/dialogs/gamestate_inspector.hpp"
#include "gui/dialogs/unit_create.hpp"
#include "gui/widgets/window.hpp"
#include "help.hpp"
@ -2287,6 +2288,7 @@ private:
void do_set_alias();
void do_set_var();
void do_show_var();
void do_inspect();
void do_unit();
// void do_buff();
// void do_unbuff();
@ -2369,6 +2371,8 @@ private:
_("Execute a Lua statement."));
register_command("custom", &console_handler::do_custom,
_("Set the command used by the custom command hotkey"), "<command>[;<command>...]");
register_command("inspect", &console_handler::do_inspect,
_("Launch the gamestate inspector"), "", "D");
register_command("alias", &console_handler::do_set_alias,
_("Set or show alias to a command"), "<name>[=<command>]");
register_command("set_var", &console_handler::do_set_var,
@ -3072,6 +3076,14 @@ private:
void console_handler::do_show_var() {
gui2::show_transient_message((*menu_handler_.gui_).video(),"",menu_handler_.gamestate_.get_variable(get_data()));
}
void console_handler::do_inspect() {
vconfig cfg;
gui2::tgamestate_inspector inspect_dialog(cfg);
inspect_dialog.show(resources::screen->video());
}
void console_handler::do_unit() {
// prevent SIGSEGV due to attempt to set HP during a fight
if (events::commands_disabled > 0)