15 #define GETTEXT_DOMAIN "wesnoth-lib"
41 const color_t color_outdated {255, 127, 0};
43 const unsigned CONTROL_STACK_LAYER_INSTALL = 0;
44 const unsigned CONTROL_STACK_LAYER_UPDATE = 1;
45 const unsigned CONTROL_STACK_LAYER_PUBLISH = 2;
54 , install_status_visibility_(builder.install_status_visibility)
55 , install_buttons_visibility_(builder.install_buttons_visibility)
57 , uninstall_function_()
83 colorname = color_outdated;
102 tx =
info.can_publish ?
_(
"addon_state^Published, not installed") :
_(
"addon_state^Not installed");
110 tx =
info.can_publish ?
_(
"addon_state^Published") :
_(
"addon_state^Installed");
113 tx =
info.can_publish ?
_(
"addon_state^Ready to publish") :
_(
"addon_state^Installed, not ready to publish");
117 tx =
info.can_publish ?
_(
"addon_state^Published, upgradable") :
_(
"addon_state^Installed, upgradable");
121 tx =
info.can_publish ?
_(
"addon_state^Published, outdated on server") :
_(
"addon_state^Installed, outdated on server");
125 tx =
info.can_publish ?
_(
"addon_state^Published, broken") :
_(
"addon_state^Installed, broken");
129 tx =
_(
"addon_state^Unknown");
140 handled = halt =
true;
150 if(local_title.empty()) {
151 return display_title;
153 return local_title +
"\n" +
markup::tag(
"small",
"(", display_title,
")");
163 for(
const auto& a : addons) {
174 data.emplace(
"icon", item);
177 data.emplace(
"name", item);
179 item[
"label"] = addon.
display_icon() +
"~SCALE(72,72)~BLIT(icons/icon-addon-publish.png,8,8)";
180 data.emplace(
"icon", item);
184 item[
"label"] = publish_name;
185 data.emplace(
"name", item);
189 data.emplace(
"installation_status", item);
193 const bool special_version_display =
197 std::ostringstream ss;
198 if(special_version_display) {
202 ss << (*addon.
versions.begin()).str();
204 if(special_version_display) {
208 item[
"label"] = ss.str();
209 data.emplace(
"version", item);
211 item[
"label"] = addon.
author;
212 data.emplace(
"author", item);
215 data.emplace(
"size", item);
217 item[
"label"] = std::to_string(addon.
downloads);
218 data.emplace(
"downloads", item);
221 data.emplace(
"type", item);
252 install_update_stack.
select_layer(CONTROL_STACK_LAYER_PUBLISH);
254 publish_button.set_active(
true);
260 install_button.set_tooltip(
_(
"Publish add-on"));
263 install_update_stack.
select_layer(CONTROL_STACK_LAYER_UPDATE);
265 update_button.set_active(
true);
272 install_update_stack.
select_layer(CONTROL_STACK_LAYER_INSTALL);
274 install_button.set_active(!is_installed);
285 uninstall_button.set_active(!is_local);
291 uninstall_button.set_tooltip(
_(
"Delete add-on from server"));
295 uninstall_button.set_active(is_installed);
316 }
catch(
const std::out_of_range&) {
336 [&
id](
const addon_info* a) { return a->id == id; }
416 load_resolutions<resolution>(cfg);
429 grid = std::make_shared<builder_grid>(*child);
437 if(str ==
"visible") {
439 }
else if(str ==
"hidden") {
441 }
else if(str ==
"invisible") {
444 FAIL(
"Invalid visibility value");
448 builder_addon_list::builder_addon_list(
const config& cfg)
450 , install_status_visibility(
widget::visibility::visible)
451 , install_buttons_visibility(
widget::visibility::invisible)
464 auto widget = std::make_unique<addon_list>(*
this);
466 DBG_GUI_G <<
"Window builder: placed add-on list '" <<
id <<
470 assert(conf !=
nullptr);
472 widget->init_grid(*conf->grid);
A config object defines a single node in a WML file, with access to child nodes.
bool has_attribute(config_key_type key) const
optional_config_impl< config > optional_child(config_key_type key, int n=0)
Equivalent to mandatory_child, but returns an empty optional if the nth child was not found.
addon_op_func_t uninstall_function_
std::function< bool(const addon_info &, const addon_info &)> addon_sort_func
void add_list_to_keyboard_chain()
Adds the internal listbox to the keyboard event chain.
void addon_action_wrapper(addon_op_func_t &func, const addon_info &addon, bool &handled, bool &halt)
Helper to wrap the execution of any of the addon operation functions.
const addon_info * get_selected_addon() const
Returns the selected add-on.
visibility install_buttons_visibility_
listbox & get_listbox()
Returns the underlying list box.
std::string get_remote_addon_id()
Returns the selected add-on id, for use with remote publish/delete ops.
const std::string display_title_full_shift(const addon_info &addon) const
static const int DEFAULT_ACTION_RETVAL
Special retval for the toggle panels in the addons list.
static std::string colorize_addon_state_string(const std::string &str, ADDON_STATUS state, bool verbose=false)
Changes the color of an add-on state string (installed, outdated, etc.) according to the state itself...
static std::string describe_status(const addon_tracking_info &info)
std::vector< const addon_info * > addon_vector_
addon_op_func_t update_function_
void select_first_addon()
Choose the item at the top of the list (taking account of sort order).
addon_op_func_t delete_function_
addon_op_func_t publish_function_
visibility install_status_visibility_
void set_addon_order(const addon_sort_func &func)
void select_addon(const std::string &id)
Selects the add-on with the given ID.
std::function< void(const addon_info &)> addon_op_func_t
void set_addons(const addons_list &addons)
Sets the add-ons to show.
addon_op_func_t install_function_
A generic container base class.
const grid & get_grid() const
std::function< bool(unsigned, unsigned)> order_func
void mark_as_unsorted()
Deactivates all sorting toggle buttons at the top, making the list look like it's not sorted.
void order_by(const generator_base::order_func &func)
grid & add_row(const widget_item &item, const int index=-1)
When an item in the list is selected by the user we need to update the state.
const grid * get_row_grid(const unsigned row) const
Returns the grid of the wanted row.
void set_active_sorter(std::string_view id, sort_order::type order, bool select_first=false)
Sorts the listbox by a pre-set sorting option.
void set_sorters(Args &&... functors)
Registers sorting controls using magic index IDs.
bool select_row(const unsigned row, const bool select=true)
Selects a row.
void clear()
Removes all the rows in the listbox, clearing it.
int get_selected_row() const
Returns the first selected row.
unsigned get_item_count() const
Returns the number of items in the listbox.
bool select_row_at(const unsigned row, const bool select=true)
Selects a row at the given position, regardless of sorting order.
base class of top level items, the only item which needs to store the final canvases to draw on.
void add_to_keyboard_chain(widget *widget)
Adds the widget to the keyboard chain.
std::string base_str() const
std::string str() const
Serializes the version number into string form.
Networked add-ons (campaignd) client interface.
static std::string _(const char *str)
std::string size_display_string(double size)
Get a human-readable representation of the specified byte count.
std::map< std::string, addon_info > addons_list
const color_t YELLOW_COLOR
const color_t weapon_details_color
const color_t NORMAL_COLOR
void connect_signal_mouse_left_click(dispatcher &dispatcher, const signal &signal)
Connects a signal handler for a left mouse button click.
static widget::visibility parse_visibility(const std::string &str)
std::map< std::string, widget_item > widget_data
std::map< std::string, t_string > widget_item
Contains the implementation details for lexical_cast and shouldn't be used directly.
std::string tag(const std::string &tag_name, Args &&... contents)
std::string span_color(const color_t &color, Args &&... data)
addon_tracking_info get_addon_tracking_info(const addon_info &addon)
Get information about an add-on comparing its local state with the add-ons server entry.
bool is_installed_addon_status(ADDON_STATUS s)
ADDON_STATUS
Defines various add-on installation statuses.
@ ADDON_NOT_TRACKED
No tracking information available.
@ ADDON_INSTALLED_OUTDATED
Version in the server is older than local installation.
@ ADDON_NONE
Add-on is not installed.
@ ADDON_INSTALLED_UPGRADABLE
Version in the server is newer than local installation.
@ ADDON_INSTALLED
Version in the server matches local installation.
@ ADDON_INSTALLED_LOCAL_ONLY
No version in the server.
@ ADDON_INSTALLED_BROKEN
Dependencies not satisfied.
std::string display_type() const
Get an add-on type identifier for display in the user's language.
std::string display_title_translated() const
std::string display_icon() const
Get an icon path fixed for display (e.g.
std::string display_title() const
Get a title or automatic title for display.
std::set< version_info, std::greater< version_info > > versions
Stores additional status information about add-ons.
version_info installed_version
The basic class for representing 8-bit RGB or RGBA colour values.
resolution(const config &cfg)
addon_list_definition(const config &cfg)
widget::visibility install_buttons_visibility
virtual std::unique_ptr< widget > build() const override
widget::visibility install_status_visibility
std::vector< state_definition > state
Add a special kind of assert to validate whether the input from WML doesn't contain any problems that...
#define VALIDATE(cond, message)
The macro to use for the validation of WML.