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);
105 return std::max<int>(
pages.size(), 1);
112 std::size_t
start = 0;
118 if(end == std::string::npos || end < start) {
121 len = end - start + 1;
123 pages.emplace_back(start, len);
126 if(start <
data.size()) {
132 std::vector<std::pair<std::size_t,int>>
pages;
139 : stuff_list_(stuff_list)
146 return stuff_list_.add_child(defn_, data_).describe_path();
152 item[
"label"] =
label;
177 return stuff_list_adder(parent ? *parent : stuff_list_->get_root_node(), defn);
183 current_page_ = std::min(n_pages - 1, std::max(0, current_page_));
186 std::ostringstream out;
187 out << current_page_ + 1 <<
'/' << n_pages;
188 pages_->set_label(out.str());
192 pages_->set_label(
"");
200 stuff_list_->clear();
201 pages_->set_label(
"");
208 current_page_ += where;
212 int current_page_ = 0;
235 const config& vars()
const;
317 if(!selected->is_root_node()) {
318 for(
auto& node : selected->parent_node().children()) {
341 view_.clear_stuff_list();
342 build_stuff_list(window);
349 view_.page(next ? 1 : -1);
356 for(
auto&
c : controllers) {
357 if(std::shared_ptr<T>
p = std::dynamic_pointer_cast<T>(
c)) {
361 std::shared_ptr<T>
p = std::make_shared<T>(*this);
362 controllers.push_back(p);
369 C& sub_controller = *get_controller<C>();
370 callbacks.emplace(node_path, std::bind(fcn, sub_controller, std::placeholders::_1));
373 template<
typename C,
typename T>
376 C& sub_controller = *get_controller<C>();
377 callbacks.emplace(node_path, std::bind(fcn, sub_controller, std::placeholders::_1, param));
382 auto stuff_list = find_widget<tree_view>(&
window,
"stuff_list",
false,
true);
383 auto copy_button = find_widget<button>(&
window,
"copy",
false,
true);
384 auto lua_button = find_widget<button>(&
window,
"lua",
false,
true);
385 auto left_button = find_widget<button>(&
window,
"page_left",
false,
true);
386 auto right_button = find_widget<button>(&
window,
"page_right",
false,
true);
399 this, std::ref(window)));
415 copy_button->set_active(
false);
416 copy_button->set_tooltip(
_(
"Clipboard support not found, contact your packager"));
419 build_stuff_list(window);
425 view_.stuff_list_entry(
nullptr,
"basic")
426 .widget(
"name",
"variables")
430 view_.stuff_list_entry(
nullptr,
"basic")
431 .widget(
"name",
"events")
436 view_.stuff_list_entry(
nullptr,
"basic")
437 .widget(
"name",
"menu items")
442 view_.stuff_list_entry(
nullptr,
"basic")
443 .widget(
"name",
"units")
447 for(
int side = 1; side <= sides; side++) {
448 std::ostringstream
label;
449 label <<
"team " << side;
452 label <<
" (" << name <<
")";
455 view_.stuff_list_entry(
nullptr,
"basic")
456 .widget(
"name", label.str())
462 callbacks[{0}](find_widget<tree_view>(&
window,
"stuff_list",
false).get_root_node().get_child_at(0));
514 view().stuff_list_entry(&node,
"basic")
515 .
widget(
"name", attr.first)
520 std::map<std::string, std::size_t> wml_array_sizes;
525 std::ostringstream cur_str;
526 cur_str <<
"[" << ch.key <<
"][" << wml_array_sizes[ch.key] <<
"]";
529 view().stuff_list_entry(&node,
"basic")
530 .
widget(
"name", cur_str.str())
533 wml_array_sizes[ch.key]++;
540 if(
label* lbl = dynamic_cast<label*>(w)) {
548 if(
label* lbl = dynamic_cast<label*>(w)) {
549 const std::string& var = lbl->get_label();
550 std::size_t n_start = var.find_last_of(
'[') + 1;
551 std::size_t n_len = var.size() - n_start - 1;
552 int n = std::stoi(var.substr(n_start, n_len));
565 for(
const auto & cfg :
events.child_range(is_wmi ?
"menu_item" :
"event"))
567 std::string name = is_wmi ? cfg[
"id"] : cfg[
"name"];
568 bool named_event = !is_wmi && !cfg[
"id"].empty();
570 auto progress =
view()
575 std::ostringstream out;
576 out <<
"id=\"" << cfg[
"id"] <<
'"';
577 progress.
widget(
"id", out.str());
598 progress.
widget(
"loc", s.str());
602 s <<
"side=" << u.
side() <<
"</span>";
603 progress.
widget(
"side", s.str(),
true);
606 progress.
widget(
"leader",
"<span color='yellow'>LEADER</span> ",
true);
610 s <<
"id=\"" << u.
id() <<
'"';
611 progress.
widget(
"id", s.str());
616 s <<
"L" << u.
level();
617 progress.
widget(
"level", s.str());
621 progress.
widget(
"xp", s.str());
625 progress.
widget(
"hp", s.str());
660 for(
const auto& attr : u->variables().attribute_range())
663 view().stuff_list_entry(&node,
"basic")
664 .
widget(
"name", attr.first)
669 std::map<std::string, std::size_t> wml_array_sizes;
671 for(
const auto ch : u->variables().all_children_range())
674 std::ostringstream cur_str;
675 cur_str <<
"[" << ch.key <<
"][" << wml_array_sizes[ch.key] <<
"]";
678 view().stuff_list_entry(&node,
"basic")
679 .
widget(
"name", cur_str.str())
682 wml_array_sizes[ch.key]++;
692 if(
label* lbl = dynamic_cast<label*>(w)) {
703 if(
label* lbl = dynamic_cast<label*>(w)) {
704 const std::string& var = lbl->get_label();
705 std::size_t n_start = var.find_last_of(
'[') + 1;
706 std::size_t n_len = var.size() - n_start - 1;
707 int n = std::stoi(var.substr(n_start, n_len));
708 model().
set_data(config_to_string(u->variables().child(var.substr(1, n_start - 3),
n)));
723 view().stuff_list_entry(&node,
"basic")
729 view().stuff_list_entry(&node,
"basic")
730 .
widget(
"name",
"recall list")
735 view().stuff_list_entry(&node,
"basic")
741 view().stuff_list_entry(&node,
"basic")
742 .
widget(
"name",
"variables")
757 view().stuff_list_entry(&node,
"basic")
758 .
widget(
"name",
"engines")
763 view().stuff_list_entry(&node,
"basic")
769 view().stuff_list_entry(&node,
"basic")
770 .
widget(
"name",
"aspects")
775 view().stuff_list_entry(&node,
"basic")
781 view().stuff_list_entry(&node,
"basic")
782 .
widget(
"name",
"component structure")
791 if(
label* lbl = dynamic_cast<label*>(w)) {
792 std::string tag = lbl->get_label();
830 std::ostringstream
s;
833 if(
i->side() != side) {
836 s <<
'(' <<
i->get_location() <<
") ";
837 if(
i->can_recruit()) {
841 s <<
"\nid=\"" <<
i->id() <<
"\" (" <<
i->type_id() <<
")\n" 842 <<
"L" <<
i->level() <<
"; " <<
i->experience() <<
'/' 843 <<
i->max_experience() <<
" XP; " <<
i->hitpoints() <<
'/' 844 <<
i->max_hitpoints() <<
" HP\n";
845 for(
const auto & str :
i->get_traits_list())
847 s <<
"\t" << str << std::endl;
867 view().stuff_list_entry(&node,
"basic")
868 .
widget(
"name", attr.first)
874 std::map<std::string, std::size_t> wml_array_sizes;
879 std::ostringstream cur_str;
880 cur_str <<
"[" << ch.key <<
"][" << wml_array_sizes[ch.key] <<
"]";
883 view().stuff_list_entry(&node,
"basic")
884 .
widget(
"name", cur_str.str())
888 wml_array_sizes[ch.key]++;
896 if(
label* lbl = dynamic_cast<label*>(w)) {
905 if(
label* lbl = dynamic_cast<label*>(w)) {
906 const std::string& var = lbl->get_label();
907 std::size_t n_start = var.find_last_of(
'[') + 1;
908 std::size_t n_len = var.size() - n_start - 1;
909 int n = std::stoi(var.substr(n_start, n_len));
923 model_.reset(
new model);
928 view_.reset(
new view(window));
929 controller_.reset(
new controller(*model_, *view_, vars_, events_, dc_));
931 if(!title_.empty()) {
932 find_widget<styled_widget>(&window,
"inspector_name",
false).set_label(title_);
934 controller_->bind(window);
935 view_->update(*model_);
window(const builder_window::window_resolution &definition)
< Needs to be initialized in show.
void show_list(tree_view_node &node)
#define REGISTER_DIALOG(window_id)
Wrapper for REGISTER_DIALOG2.
std::shared_ptr< model > model_
config & child(config_key_type key, int n=0)
Returns the nth child with the given key, or a reference to an invalid config if there is none...
void show_var(tree_view_node &node, int side)
const_all_children_itors all_children_range() const
In-order iteration over all children.
void show_list(tree_view_node &node)
std::vector< std::shared_ptr< single_mode_controller > > controllers
const team & get_team(int side) const
std::function< void(tree_view_node &)> node_callback
void clear_children(T... keys)
This class represents a single unit of a specific type.
const std::string & type_id() const
The id of this unit's type.
bool available()
Whether wesnoth was compiled with support for a clipboard.
std::string join(const T &v, const std::string &s=",")
Generates a new string joining container items in a list.
std::vector< int > describe_path()
Calculates the node indices needed to get from the root node to this node.
static manager & get_singleton()
void connect_signal_mouse_left_click(dispatcher &dispatcher, const signal &signal)
Connects a signal handler for a left mouse button click.
void show_ai_tree(tree_view_node &node, int side)
const game_events::manager & events_
int hitpoints() const
The current number of hitpoints this unit has.
const config & vars() const
void write_events(config &cfg, bool include_nonserializable=false) const
child_itors child_range(config_key_type key)
This shows the gamestate inspector.
std::string get_data_paged(int which_page)
void show_var(tree_view_node &node)
void show_recall(tree_view_node &node, int side)
A label displays a text, the text can be wrapped but no scrollbars are provided.
void set_node_callback(const std::vector< int > &node_path, void(C::*fcn)(tree_view_node &, T), T param)
widget * find(const std::string &id, const bool must_be_active) override
See widget::find.
static std::string _(const char *str)
void show_unit(tree_view_node &node)
void show_list(tree_view_node &node, bool is_wmi)
std::shared_ptr< unit > unit_ptr
event_mode_controller(gamestate_inspector::controller &c)
const_attr_itors attribute_range() const
static void display(lua_kernel_base *lk)
Display a new console, using given video and lua kernel.
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.
void show_array(tree_view_node &node)
std::size_t count_children() const
The number of children in this widget.
std::string span_color(const color_t &color)
Returns a Pango formatting string using the provided color_t object.
void write(std::ostream &out, const configr_of &cfg, unsigned int level)
This class stores all the data for a single 'side' (in game nomenclature).
const game_events::manager & events() const
std::map< std::string, t_string > widget_item
gamestate_inspector::view & view()
const std::string & id() const
Gets this unit's id.
void show_vars(tree_view_node &node, int side)
std::string get_data_full() const
std::string label
What to show in the filter's drop-down list.
variable_mode_controller(gamestate_inspector::controller &c)
This file contains the settings handling of the widget library.
EXIT_STATUS start(const std::string &filename, bool take_screenshot, const std::string &screenshot_filename)
Main interface for launching the editor from the title screen.
void set_data(const std::string &new_data)
gamestate_inspector::controller & c
gamestate_inspector::model & model()
iterator begin()
begin iterator
void build_stuff_list(window &window)
The basic class for representing 8-bit RGB or RGBA colour values.
void show_array(tree_view_node &node, int side)
int max_experience() const
The max number of experience points this unit can have.
int level() const
The current level of this unit.
stuff_list_adder(tree_view_node &stuff_list, const std::string &defn)
const display_context & dc_
Managing the AIs lifecycle - headers TODO: Refactor history handling and internal commands...
std::shared_ptr< T > get_controller()
A tree view is a control that holds several items of the same or different types. ...
virtual const unit_map & units() const =0
void show_event(tree_view_node &node, bool is_wmi)
void show_units(tree_view_node &node, int side)
virtual ~single_mode_controller()
void set_node_callback(const std::vector< int > &node_path, void(C::*fcn)(tree_view_node &))
void show_recall_unit(tree_view_node &node, int side)
void handle_stuff_list_item_clicked(widget &tree)
stuff_list_adder stuff_list_entry(tree_view_node *parent, const std::string &defn)
void show_ai_components(tree_view_node &node, int side)
std::vector< std::pair< std::size_t, int > > pages
node_callback_map callbacks
void handle_lua_button_clicked(window &window)
virtual const std::vector< team > & teams() const =0
unit_mode_controller(gamestate_inspector::controller &c)
int max_hitpoints() const
The max number of hitpoints this unit can have.
void bind(window &window)
static map_location::DIRECTION s
bool can_recruit() const
Whether this unit can recruit other units - ie, are they a leader unit.
std::string bool_string(const bool value)
Converts a bool value to 'true' or 'false'.
virtual void pre_show(window &window) override
Actions to be taken before showing the window.
static const unsigned int max_inspect_win_len
void show_var(tree_view_node &node)
std::vector< std::string > get_traits_list() const
Gets a list of the traits this unit currently has.
The game event manager loads the scenario configuration object, and ensures that events are handled a...
single_mode_controller(gamestate_inspector::controller &c)
stuff_list_adder & widget(const std::string &ref, const std::string &label, bool markup=false)
config & add_child(config_key_type key)
Handling of system events.
void copy_to_clipboard(const std::string &text, const bool)
Copies text to the clipboard.
int experience() const
The current number of experience points this unit has.
std::map< std::vector< int >, node_callback > node_callback_map
const map_location & get_location() const
The current map location this unit is at.
void show_array(tree_view_node &node)
const game_events::manager & events_
Abstract base class for all modal dialogs.
recall_list_manager & recall_list()
void show_list(tree_view_node &node, int side)
const std::vector< color_t > & tc_info(const std::string &name)
const display_context & dc_
team_mode_controller(gamestate_inspector::controller &c)
std::map< std::string, widget_item > widget_data
int side() const
The side this unit belongs to.
void show_ai(tree_view_node &node, int side)
void handle_page_button_clicked(bool next)
static stuff_list_adder add_unit_entry(stuff_list_adder &progress, const unit &u, const display_context &dc)
A config object defines a single node in a WML file, with access to child nodes.
controller(model &m, view &v, const config &vars, const game_events::manager &events, const display_context &dc)
tree_view_node & stuff_list_
static map_location::DIRECTION n
base class of top level items, the only item which needs to store the final canvases to draw on...
void handle_copy_button_clicked()
const t_string & user_team_name() const
void connect_signal_notify_modified(dispatcher &dispatcher, const signal_notification &signal)
Connects a signal handler for getting a notification upon modification.
std::pair< std::string, unsigned > item
std::shared_ptr< view > view_
const display_context & dc() const