16 #define GETTEXT_DOMAIN "wesnoth-lib"
53 inline std::string config_to_string(
const config& cfg)
60 inline std::string config_to_string(
const config& cfg, std::string only_children)
66 return config_to_string(filtered);
86 if(std::size_t(which_page) >=
pages.size()) {
89 return data.substr(
pages[which_page].first,
pages[which_page].second);
106 return std::max<int>(
pages.size(), 1);
113 std::size_t
start = 0;
133 std::vector<std::pair<std::size_t,int>>
pages;
187 std::ostringstream out;
319 for(
auto& node :
selected->parent_node().children()) {
358 if(std::shared_ptr<T>
p = std::dynamic_pointer_cast<T>(
c)) {
362 std::shared_ptr<T>
p = std::make_shared<T>(*
this);
370 C& sub_controller = *get_controller<C>();
371 callbacks.emplace(node_path, std::bind(fcn, sub_controller, std::placeholders::_1));
374 template<
typename C,
typename T>
377 C& sub_controller = *get_controller<C>();
378 callbacks.emplace(node_path, std::bind(fcn, sub_controller, std::placeholders::_1, param));
383 auto stuff_list = find_widget<tree_view>(&
window,
"stuff_list",
false,
true);
384 auto copy_button = find_widget<button>(&
window,
"copy",
false,
true);
385 auto lua_button = find_widget<button>(&
window,
"lua",
false,
true);
386 auto left_button = find_widget<button>(&
window,
"page_left",
false,
true);
387 auto right_button = find_widget<button>(&
window,
"page_right",
false,
true);
416 copy_button->set_active(
false);
417 copy_button->set_tooltip(
_(
"Clipboard support not found, contact your packager"));
427 .
widget(
"name",
"variables")
438 .
widget(
"name",
"menu items")
448 for(
int side = 1; side <= sides; side++) {
449 std::ostringstream
label;
450 label <<
"team " << side;
453 label <<
" (" << name <<
")";
463 callbacks[{0}](find_widget<tree_view>(&
window,
"stuff_list",
false).get_root_node().get_child_at(0));
512 for(
const auto& attr :
vars().attribute_range())
515 view().stuff_list_entry(&node,
"basic")
516 .
widget(
"name", attr.first)
521 std::map<std::string, std::size_t> wml_array_sizes;
523 for(
const auto ch :
vars().all_children_range())
526 std::ostringstream cur_str;
527 cur_str <<
"[" << ch.key <<
"][" << wml_array_sizes[ch.key] <<
"]";
530 view().stuff_list_entry(&node,
"basic")
531 .
widget(
"name", cur_str.str())
534 wml_array_sizes[ch.key]++;
550 const std::string& var = lbl->get_label();
551 std::size_t n_start = var.find_last_of(
'[') + 1;
552 std::size_t n_len = var.size() - n_start - 1;
553 int n = std::stoi(var.substr(n_start, n_len));
554 model().
set_data(config_to_string(
vars().mandatory_child(var.substr(1, n_start - 3),
n)));
566 for(
const auto & cfg :
events.child_range(is_wmi ?
"menu_item" :
"event"))
568 std::string name = is_wmi ? cfg[
"id"] : cfg[
"name"];
569 bool named_event = !is_wmi && !cfg[
"id"].empty();
571 auto progress =
view()
576 std::ostringstream out;
577 out <<
"id=\"" << cfg[
"id"] <<
'"';
578 progress.
widget(
"id", out.str());
599 progress.
widget(
"loc",
s.str());
603 s <<
"side=" << u.
side() <<
"</span>";
604 progress.
widget(
"side",
s.str(),
true);
607 progress.
widget(
"leader",
"<span color='yellow'>LEADER</span> ",
true);
611 s <<
"id=\"" << u.
id() <<
'"';
612 progress.
widget(
"id",
s.str());
618 progress.
widget(
"level",
s.str());
622 progress.
widget(
"xp",
s.str());
626 progress.
widget(
"hp",
s.str());
661 for(
const auto& attr : u->variables().attribute_range())
664 view().stuff_list_entry(&node,
"basic")
665 .
widget(
"name", attr.first)
670 std::map<std::string, std::size_t> wml_array_sizes;
672 for(
const auto ch : u->variables().all_children_range())
675 std::ostringstream cur_str;
676 cur_str <<
"[" << ch.key <<
"][" << wml_array_sizes[ch.key] <<
"]";
679 view().stuff_list_entry(&node,
"basic")
680 .
widget(
"name", cur_str.str())
683 wml_array_sizes[ch.key]++;
705 const std::string& var = lbl->get_label();
706 std::size_t n_start = var.find_last_of(
'[') + 1;
707 std::size_t n_len = var.size() - n_start - 1;
708 int n = std::stoi(var.substr(n_start, n_len));
709 model().
set_data(config_to_string(u->variables().mandatory_child(var.substr(1, n_start - 3),
n)));
724 view().stuff_list_entry(&node,
"basic")
730 view().stuff_list_entry(&node,
"basic")
731 .
widget(
"name",
"recall list")
736 view().stuff_list_entry(&node,
"basic")
742 view().stuff_list_entry(&node,
"basic")
743 .
widget(
"name",
"variables")
758 view().stuff_list_entry(&node,
"basic")
759 .
widget(
"name",
"engines")
764 view().stuff_list_entry(&node,
"basic")
770 view().stuff_list_entry(&node,
"basic")
771 .
widget(
"name",
"aspects")
776 view().stuff_list_entry(&node,
"basic")
782 view().stuff_list_entry(&node,
"basic")
783 .
widget(
"name",
"component structure")
793 std::string tag = lbl->get_label();
807 for(
const unit_ptr& u :
dc().get_team(side).recall_list()) {
831 std::ostringstream
s;
834 if(
i->side() != side) {
837 s <<
'(' <<
i->get_location() <<
") ";
838 if(
i->can_recruit()) {
842 s <<
"\nid=\"" <<
i->id() <<
"\" (" <<
i->type_id() <<
")\n"
843 <<
"L" <<
i->level() <<
"; " <<
i->experience() <<
'/'
844 <<
i->max_experience() <<
" XP; " <<
i->hitpoints() <<
'/'
845 <<
i->max_hitpoints() <<
" HP\n";
846 for(
const auto & str :
i->get_traits_list())
848 s <<
"\t" << str << std::endl;
865 for(
const auto& attr :
t.variables().attribute_range())
868 view().stuff_list_entry(&node,
"basic")
869 .
widget(
"name", attr.first)
875 std::map<std::string, std::size_t> wml_array_sizes;
877 for(
const auto ch :
t.variables().all_children_range())
880 std::ostringstream cur_str;
881 cur_str <<
"[" << ch.key <<
"][" << wml_array_sizes[ch.key] <<
"]";
884 view().stuff_list_entry(&node,
"basic")
885 .
widget(
"name", cur_str.str())
889 wml_array_sizes[ch.key]++;
907 const std::string& var = lbl->get_label();
908 std::size_t n_start = var.find_last_of(
'[') + 1;
909 std::size_t n_len = var.size() - n_start - 1;
910 int n = std::stoi(var.substr(n_start, n_len));
911 model().
set_data(config_to_string(
t.variables().mandatory_child(var.substr(1, n_start - 3),
n)));
924 model_.reset(
new model);
933 find_widget<styled_widget>(&
window,
"inspector_name",
false).set_label(
title_);
Managing the AIs lifecycle - headers TODO: Refactor history handling and internal commands.
static manager & get_singleton()
A config object defines a single node in a WML file, with access to child nodes.
void clear_children(T... keys)
child_itors child_range(config_key_type key)
config & add_child(config_key_type key)
Abstract class for exposing game data that doesn't depend on the GUI, however which for historical re...
const team & get_team(int side) const
This getter takes a 1-based side number, not a 0-based team number.
virtual const std::vector< team > & teams() const =0
virtual const unit_map & units() const =0
The game event manager loads the scenario configuration object, and ensures that events are handled a...
void write_events(config &cfg, bool include_nonserializable=false) const
void show_list(tree_view_node &node, bool is_wmi)
void show_event(tree_view_node &node, bool is_wmi)
event_mode_controller(gamestate_inspector::controller &c)
void handle_copy_button_clicked()
void handle_page_button_clicked(bool next)
std::map< std::vector< int >, node_callback > node_callback_map
void set_node_callback(const std::vector< int > &node_path, void(C::*fcn)(tree_view_node &, T), T param)
const game_events::manager & events_
void handle_stuff_list_item_clicked(widget &tree)
controller(model &m, view &v, const config &vars, const game_events::manager &events, const display_context &dc)
void handle_lua_button_clicked(window &window)
void bind(window &window)
node_callback_map callbacks
std::vector< std::shared_ptr< single_mode_controller > > controllers
std::function< void(tree_view_node &)> node_callback
std::shared_ptr< T > get_controller()
const display_context & dc_
void set_node_callback(const std::vector< int > &node_path, void(C::*fcn)(tree_view_node &))
void build_stuff_list(window &window)
std::string get_data_paged(int which_page)
static const unsigned int max_inspect_win_len
void set_data(const std::string &new_data)
std::string get_data_full() const
std::vector< std::pair< std::size_t, int > > pages
stuff_list_adder stuff_list_entry(tree_view_node *parent, const std::string &defn)
This shows the gamestate inspector.
const game_events::manager & events_
virtual void pre_show(window &window) override
Actions to be taken before showing the window.
std::shared_ptr< view > view_
std::shared_ptr< model > model_
std::shared_ptr< controller > controller_
const display_context & dc_
static void display(lua_kernel_base *lk)
Display a new console, using given video and lua kernel.
Abstract base class for all modal dialogs.
const game_events::manager & events() const
virtual ~single_mode_controller()
gamestate_inspector::view & view()
single_mode_controller(gamestate_inspector::controller &c)
gamestate_inspector::controller & c
const display_context & dc() const
const config & vars() const
gamestate_inspector::model & model()
tree_view_node & stuff_list_
stuff_list_adder(tree_view_node &stuff_list, const std::string &defn)
stuff_list_adder & widget(const std::string &ref, const std::string &label, bool markup=false)
void show_var(tree_view_node &node, int side)
void show_ai_tree(tree_view_node &node, int side)
void show_ai(tree_view_node &node, int side)
void show_vars(tree_view_node &node, int side)
void show_recall(tree_view_node &node, int side)
void show_unit(tree_view_node &node, int side)
void show_array(tree_view_node &node, int side)
void show_ai_components(tree_view_node &node, int side)
void show_units(tree_view_node &node, int side)
void show_list(tree_view_node &node, int side)
team_mode_controller(gamestate_inspector::controller &c)
void show_recall_unit(tree_view_node &node, int side)
void show_var(tree_view_node &node)
unit_mode_controller(gamestate_inspector::controller &c)
void show_array(tree_view_node &node)
void show_list(tree_view_node &node)
void show_unit(tree_view_node &node)
void show_array(tree_view_node &node)
variable_mode_controller(gamestate_inspector::controller &c)
void show_list(tree_view_node &node)
void show_var(tree_view_node &node)
A label displays text that can be wrapped but no scrollbars are provided.
std::vector< int > describe_path()
Calculates the node indices needed to get from the root node to this node.
widget * find(const std::string &id, const bool must_be_active) override
See widget::find.
std::size_t count_children() const
The number of children in this widget.
tree_view_node & add_child(const std::string &id, const widget_data &data, const int index=-1)
Constructs a new child node.
A tree view is a control that holds several items of the same or different types.
tree_view_node & get_root_node()
base class of top level items, the only item which needs to store the final canvases to draw on.
iterator begin()
begin iterator
This class stores all the data for a single 'side' (in game nomenclature).
const std::string & color() const
recall_list_manager & recall_list()
const t_string & user_team_name() const
This class represents a single unit of a specific type.
static std::string _(const char *str)
int max_hitpoints() const
The max number of hitpoints this unit can have.
int level() const
The current level of this unit.
int hitpoints() const
The current number of hitpoints this unit has.
const std::string & type_id() const
The id of this unit's type.
int experience() const
The current number of experience points this unit has.
bool can_recruit() const
Whether this unit can recruit other units - ie, are they a leader unit.
const std::string & id() const
Gets this unit's id.
int side() const
The side this unit belongs to.
int max_experience() const
The max number of experience points this unit can have.
const map_location & get_location() const
The current map location this unit is at.
std::vector< std::string > get_traits_list() const
Gets a list of the traits this unit currently has.
std::string label
What to show in the filter's drop-down list.
#define REGISTER_DIALOG(window_id)
Wrapper for REGISTER_DIALOG2.
void copy_to_clipboard(const std::string &text, const bool)
Copies text to the clipboard.
bool available()
Whether wesnoth was compiled with support for a clipboard.
EXIT_STATUS start(bool clear_id, const std::string &filename, bool take_screenshot, const std::string &screenshot_filename)
Main interface for launching the editor from the title screen.
Handling of system events.
std::string span_color(const color_t &color)
Returns a Pango formatting string using the provided color_t object.
const std::vector< color_t > & tc_info(const std::string &name)
static stuff_list_adder add_unit_entry(stuff_list_adder &progress, const unit &u, const display_context &dc)
void connect_signal_notify_modified(dispatcher &dispatcher, const signal_notification &signal)
Connects a signal handler for getting a notification upon modification.
void connect_signal_mouse_left_click(dispatcher &dispatcher, const signal &signal)
Connects a signal handler for a left mouse button click.
std::map< std::string, widget_item > widget_data
std::map< std::string, t_string > widget_item
T * find_widget(utils::const_clone_ptr< widget, T > widget, const std::string &id, const bool must_be_active, const bool must_exist)
Gets a widget with the wanted id.
std::pair< std::string, unsigned > item
std::string bool_string(const bool value)
Converts a bool value to 'true' or 'false'.
std::string join(const T &v, const std::string &s=",")
Generates a new string joining container items in a list.
std::shared_ptr< unit > unit_ptr
void write(std::ostream &out, const configr_of &cfg, unsigned int level)
This file contains the settings handling of the widget library.
The basic class for representing 8-bit RGB or RGBA colour values.
static map_location::DIRECTION n
static map_location::DIRECTION s