15 #define GETTEXT_DOMAIN "wesnoth-lib" 51 inline std::string config_to_string(
const config& cfg)
58 inline std::string config_to_string(
const config& cfg, std::string only_children)
64 return config_to_string(filtered);
84 if(std::size_t(which_page) >=
pages.size()) {
87 return data.substr(
pages[which_page].first,
pages[which_page].second);
103 return std::max<int>(
pages.size(), 1);
110 std::size_t
start = 0;
111 while(start <
data.size()) {
113 if(end == std::string::npos) {
114 end =
data.size() - 1;
116 int len = end - start + 1;
117 pages.emplace_back(start, len);
123 std::vector<std::pair<std::size_t,int>>
pages;
130 : stuff_list_(stuff_list)
137 return stuff_list_.add_child(defn_, data_).describe_path();
143 item[
"label"] = label;
151 std::map<std::string, string_map>
data_;
168 return stuff_list_adder(parent ? *parent : stuff_list_->get_root_node(), defn);
174 current_page_ = std::min(n_pages - 1, std::max(0, current_page_));
177 std::ostringstream out;
178 out << current_page_ + 1 <<
'/' << n_pages;
179 pages_->set_label(out.str());
183 pages_->set_label(
"");
191 stuff_list_->clear();
192 pages_->set_label(
"");
199 current_page_ += where;
203 int current_page_ = 0;
226 const config& vars()
const;
303 if(!selected->is_root_node()) {
304 for(
auto& node : selected->parent_node().children()) {
327 view_.clear_stuff_list();
328 build_stuff_list(window);
335 view_.page(next ? 1 : -1);
342 for(
auto&
c : controllers) {
343 if(std::shared_ptr<T>
p = std::dynamic_pointer_cast<T>(
c)) {
347 std::shared_ptr<T>
p = std::make_shared<T>(*this);
348 controllers.push_back(p);
355 C& sub_controller = *get_controller<C>();
356 callbacks.emplace(node_path, std::bind(fcn, sub_controller, std::placeholders::_1));
359 template<
typename C,
typename T>
362 C& sub_controller = *get_controller<C>();
363 callbacks.emplace(node_path, std::bind(fcn, sub_controller, std::placeholders::_1, param));
368 auto stuff_list = find_widget<tree_view>(&window,
"stuff_list",
false,
true);
369 auto copy_button = find_widget<button>(&window,
"copy",
false,
true);
370 auto lua_button = find_widget<button>(&window,
"lua",
false,
true);
371 auto left_button = find_widget<button>(&window,
"page_left",
false,
true);
372 auto right_button = find_widget<button>(&window,
"page_right",
false,
true);
385 this, std::ref(window)));
401 copy_button->set_active(
false);
402 copy_button->set_tooltip(
_(
"Clipboard support not found, contact your packager"));
405 build_stuff_list(window);
411 view_.stuff_list_entry(
nullptr,
"basic")
412 .widget(
"name",
"variables")
416 view_.stuff_list_entry(
nullptr,
"basic")
417 .widget(
"name",
"events")
422 view_.stuff_list_entry(
nullptr,
"basic")
423 .widget(
"name",
"menu items")
428 view_.stuff_list_entry(
nullptr,
"basic")
429 .widget(
"name",
"units")
433 for(
int side = 1; side <= sides; side++) {
434 std::ostringstream
label;
435 label <<
"team " << side;
438 label <<
" (" << name <<
")";
441 view_.stuff_list_entry(
nullptr,
"basic")
442 .widget(
"name", label.str())
448 callbacks[{0}](find_widget<tree_view>(&window,
"stuff_list",
false).get_root_node().get_child_at(0));
500 view().stuff_list_entry(&node,
"basic")
501 .
widget(
"name", attr.first)
506 std::map<std::string, std::size_t> wml_array_sizes;
511 std::ostringstream cur_str;
512 cur_str <<
"[" << ch.key <<
"][" << wml_array_sizes[ch.key] <<
"]";
515 view().stuff_list_entry(&node,
"basic")
516 .
widget(
"name", cur_str.str())
519 wml_array_sizes[ch.key]++;
526 if(
label* lbl = dynamic_cast<label*>(w)) {
534 if(
label* lbl = dynamic_cast<label*>(w)) {
535 const std::string& var = lbl->get_label();
536 std::size_t n_start = var.find_last_of(
'[') + 1;
537 std::size_t n_len = var.size() - n_start - 1;
538 int n = std::stoi(var.substr(n_start, n_len));
551 for(
const auto & cfg :
events.child_range(is_wmi ?
"menu_item" :
"event"))
553 std::string
name = is_wmi ? cfg[
"id"] : cfg[
"name"];
554 bool named_event = !is_wmi && !cfg[
"id"].empty();
556 auto progress =
view()
561 std::ostringstream out;
562 out <<
"id=\"" << cfg[
"id"] <<
'"';
563 progress.
widget(
"id", out.str());
584 progress.
widget(
"loc", s.str());
588 s <<
"side=" << u.
side() <<
"</span>";
589 progress.
widget(
"side", s.str(),
true);
592 progress.
widget(
"leader",
"<span color='yellow'>LEADER</span> ",
true);
596 s <<
"id=\"" << u.
id() <<
'"';
597 progress.
widget(
"id", s.str());
602 s <<
"L" << u.
level();
603 progress.
widget(
"level", s.str());
607 progress.
widget(
"xp", s.str());
611 progress.
widget(
"hp", s.str());
654 view().stuff_list_entry(&node,
"basic")
660 view().stuff_list_entry(&node,
"basic")
661 .
widget(
"name",
"recall list")
666 view().stuff_list_entry(&node,
"basic")
682 view().stuff_list_entry(&node,
"basic")
683 .
widget(
"name",
"engines")
688 view().stuff_list_entry(&node,
"basic")
694 view().stuff_list_entry(&node,
"basic")
695 .
widget(
"name",
"aspects")
700 view().stuff_list_entry(&node,
"basic")
706 view().stuff_list_entry(&node,
"basic")
707 .
widget(
"name",
"component structure")
716 if(
label* lbl = dynamic_cast<label*>(w)) {
717 std::string tag = lbl->get_label();
755 std::ostringstream
s;
758 if(
i->side() != side) {
761 s <<
'(' <<
i->get_location() <<
") ";
762 if(
i->can_recruit()) {
766 s <<
"\nid=\"" <<
i->id() <<
"\" (" <<
i->type_id() <<
")\n" 767 <<
"L" <<
i->level() <<
"; " <<
i->experience() <<
'/' 768 <<
i->max_experience() <<
" XP; " <<
i->hitpoints() <<
'/' 769 <<
i->max_hitpoints() <<
" HP\n";
770 for(
const auto & str :
i->get_traits_list())
772 s <<
"\t" << str << std::endl;
787 model_.reset(
new model);
792 view_.reset(
new view(window));
793 controller_.reset(
new controller(*model_, *view_, vars_, events_, dc_));
795 if(!title_.empty()) {
796 find_widget<styled_widget>(&window,
"inspector_name",
false).set_label(title_);
798 controller_->bind(window);
799 view_->update(*model_);
void show_list(tree_view_node &node)
#define REGISTER_DIALOG(window_id)
Wrapper for REGISTER_DIALOG2.
std::shared_ptr< model > model_
std::map< std::string, string_map > data_
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 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
child_itors child_range(config_key_type key)
This shows the gamestate inspector.
std::string get_data_paged(int which_page)
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.
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)
const game_events::manager & events() const
gamestate_inspector::view & view()
const std::string & id() const
Gets this unit's id.
void connect_signal_notify_modified(dispatcher &dispatcher, const signal_notification_function &signal)
Connects a signal handler for getting a notification upon modification.
std::string get_data_full() const
variable_mode_controller(gamestate_inspector::controller &c)
This file contains the settings handling of the widget library.
void set_data(const std::string &new_data)
gamestate_inspector::controller & c
void connect_signal_mouse_left_click(dispatcher &dispatcher, const signal_function &signal)
Connects a signal handler for a left mouse button click.
gamestate_inspector::model & model()
iterator begin()
begin iterator
void build_stuff_list(window &window)
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)
void write_events(config &cfg) const
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
Inherited from modal_dialog.
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_
recall_list_manager & recall_list()
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 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)
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
std::pair< std::string, unsigned > item
std::shared_ptr< view > view_
const display_context & dc() const