64 #include <boost/make_shared.hpp>
65 #include <boost/shared_ptr.hpp>
74 #define LOG_NG LOG_STREAM(info, log_engine)
75 #define ERR_NG LOG_STREAM(err, log_engine)
78 #define LOG_DP LOG_STREAM(info, log_display)
80 #define ERR_G LOG_STREAM(err, lg::general)
83 #define ERR_CF LOG_STREAM(err, log_config)
103 template<
typename T>
void dump(
const T &
units)
107 LOG_DP <<
"size: " << units.size() <<
"\n";
110 LOG_DP <<
"unit[" << (idx++) <<
"]: " << u_ptr->id() <<
" name = '" << u_ptr->name() <<
"'\n";
121 const unit & u = *u_ptr;
128 message <<
_(
"This unit is loyal and requires no upkeep. ") << (u.
gender() ==
unit_race::MALE ?
_(
"Do you really want to dismiss him?")
129 : _(
"Do you really want to dismiss her?"));
130 }
else if(u.
level() > 1) {
132 message <<
_(
"This unit is an experienced one, having advanced levels. ") << (u.
gender() ==
unit_race::MALE ?
_(
"Do you really want to dismiss him?")
133 : _(
"Do you really want to dismiss her?"));
137 message <<
_(
"This unit is close to advancing a level. ") << (u.
gender() ==
unit_race::MALE ?
_(
"Do you really want to dismiss him?")
138 : _(
"Do you really want to dismiss her?"));
141 if(!message.str().empty()) {
153 LOG_DP <<
"Dismissing a unit, side = " << u.
side() <<
" id = '" << u.
id() <<
"'\n";
154 LOG_DP <<
"That side's recall list:\n";
158 unit_ptr dismissed_unit = (*resources::teams)[u.
side() -1].recall_list().find_if_matches_id(u.
id());
159 assert(dismissed_unit);
176 const std::vector<std::string>&
options = u->advances_to();
178 std::vector<std::string> lang_options;
181 for(std::vector<std::string>::const_iterator op = options.begin(); op != options.end(); ++op) {
183 const unit&
type = *sample_units->back();
195 bool always_display =
false;
196 for (
const config &mod : u->get_modification_advances())
198 if (mod[
"always_display"].to_bool()) always_display =
true;
200 const unit&
type = *sample_units->back();
201 if (!mod[
"image"].empty()) {
214 assert(!lang_options.empty());
216 if (lang_options.size() > 1 || always_display)
219 std::vector<gui::preview_pane*> preview_panes;
220 preview_panes.push_back(&unit_preview);
224 _(
"What should our victorious unit become?"),
228 return advances.
show();
239 LOG_DP <<
"animate_unit_advancement suppressed: invalid unit\n";
241 }
else if (!u->advances()) {
242 LOG_DP <<
"animate_unit_advancement suppressed: unit does not advance\n";
246 const std::vector<std::string>&
options = u->advances_to();
247 std::vector<config> mod_options = u->get_modification_advances();
249 if(choice >= options.size() + mod_options.size()) {
250 LOG_DP <<
"animate_unit_advancement suppressed: invalid option\n";
259 bool with_bars =
true;
265 if(choice < options.size()) {
270 const config &mod_option = mod_options[choice - options.size()];
304 _(
"unit list^Traits");
311 std::vector<std::string>
items;
312 items.push_back(heading);
314 std::vector<map_location> locations_list;
325 std::stringstream
row;
329 selected = units_list->size();
334 if (
i->can_recruit() ) {
335 row <<
"<205,173,0>";
338 if (
i->can_recruit() ) {
339 row <<
"<205,173,0>";
344 if (
i->movement_left() == 0) {
346 }
else if (
i->movement_left() <
i->total_movement() ) {
347 row <<
"<255,255,0>";
360 if(
i->invisible(
i->get_location(),
false))
372 row <<
"<150,150,150>";
373 }
else if(level == 1) {
375 }
else if(level == 2) {
377 }
else if(level > 2 ) {
384 row <<
i->experience() <<
"/";
385 if (
i->can_advance()) {
386 row <<
i->max_experience();
394 items.push_back(row.str());
396 locations_list.push_back(
i->get_location());
397 units_list->push_back(
i.get_shared_ptr());
406 umenu.add_pane(&unit_preview);
408 umenu.get_menu().sort_by(0);
415 selected = umenu.show();
418 if(selected >= 0 && selected <
int(locations_list.size())) {
427 static const std::string no_objectives(
_(
"No objectives available"));
429 (objectives.empty() ? no_objectives : objectives),
"",
true);
435 units,
nullptr, side);
436 std::vector<gui::preview_pane*> preview_panes;
437 preview_panes.push_back(&unit_preview);
457 rmenu.set_menu(units_menu);
458 rmenu.set_panes(preview_panes);
469 std::vector<std::string>
options, options_to_filter;
471 std::ostringstream heading;
482 options.push_back(heading.str());
483 options_to_filter.push_back(options.back());
487 std::stringstream
option, option_to_filter;
503 option <<
"~BLIT(" <<
overlay <<
")";
510 cost = team_recall_cost;
513 if(cost > team_recall_cost) {
516 else if(cost == team_recall_cost) {
519 else if(cost < team_recall_cost) {
522 option << cost <<
" Gold" << COLUMN_SEPARATOR
528 option <<
"<150,150,150>";
529 }
else if(level == 1) {
531 }
else if(level == 2) {
533 }
else if(level > 2 ) {
544 option_to_filter << u->
type_name() <<
" " << name <<
" " << u->
level();
548 option << trait <<
'\n';
549 option_to_filter <<
" " << trait;
552 options.push_back(option.str());
553 options_to_filter.push_back(option_to_filter.str());
566 rmenu.set_menu(units_menu);
569 _(
"Filter: "),
options, options_to_filter, 1, rmenu, 200);
570 rmenu.set_textbox(filter);
572 delete_recall_unit recall_deleter(disp, *filter, units);
574 rmenu.add_button(delete_button);
580 rmenu.add_pane(&unit_preview);
583 static int sort_by = 3;
584 static bool sort_reversed =
false;
587 rmenu.get_menu().sort_by(sort_by);
590 rmenu.get_menu().sort_by(sort_by);
594 int res = rmenu.show();
597 sort_by = rmenu.get_menu().get_sort_by();
598 sort_reversed = rmenu.get_menu().get_sort_reversed();
604 static const int unit_preview_border = 10;
632 gui::button::TYPE_PRESS,
"button_normal/button_small_H22",
gui::button::MINIMUM_SPACE),
661 index = std::min<int>(
static_cast<int>(
size())-1,index);
676 if(index_ < 0 || index_ >=
int(
size())) {
686 , loc.y + unit_preview_border
687 , loc.w - unit_preview_border * 2
688 , loc.h - unit_preview_border * 2);
691 GPU_SetClip(get_render_target(), area.x, area.y, area.w, area.h);
693 sdl::timage unit_image = det.
image;
700 if(!unit_image.null()) {
704 : area.x + area.w - unit_image.width()
707 , unit_image.height());
709 video().draw_texture(unit_image, rect.x, rect.y);
714 sdl::timage oi = image::get_texture(overlay);
720 if(oi.width() > rect.w || oi.height() > rect.h) {
721 oi.set_scale(
float(rect.w) / oi.width(), float(rect.h) / oi.height());
724 video().draw_texture(oi, rect.x, rect.y);
734 , image_rect.y + image_rect.h
744 if(det.
name.empty() ==
false) {
745 std::stringstream desc;
749 sdl::timage
img = font::draw_text_to_texture(area,
752 video().draw_texture(img, right_align ? image_rect.x :
753 image_rect.x + image_rect.w - description_rect.w,
757 std::stringstream text;
761 <<
_(
"level") <<
" " << det.
level <<
"\n"
765 for(std::vector<t_string>::const_iterator
a = det.
abilities.begin();
a != det.
abilities.end(); ++
a) {
784 for(std::vector<attack_type>::const_iterator at_it = det.
attacks.begin();
785 at_it != det.
attacks.end(); ++at_it) {
790 << at_it->num_attacks()
791 <<
" " << at_it->name() <<
"\n";
797 std::string accuracy_parry = at_it->accuracy_parry_description();
798 if(accuracy_parry.empty() ==
false) {
803 if (!special.empty()) {
810 const std::vector<std::string> lines =
utils::split(text.str(),
'\n',
820 for(std::vector<std::string>::const_iterator line = lines.begin(); line != lines.end(); ++line) {
825 if (line_area.w < area.w)
826 xpos = area.x + area.w - line_area.w;
830 video().draw_texture(img, xpos, ypos);
831 ypos += img.height();
845 if(unit_image !=
nullptr) {
849 : area.x + area.w - unit_image->w
854 sdl_blit(unit_image,
nullptr,screen,&rect);
865 if(os->w > rect.w || os->h > rect.h) {
869 sdl_blit(os,
nullptr, screen, &rect);
879 , image_rect.y + image_rect.h
890 if(det.
name.empty() ==
false) {
891 std::stringstream desc;
897 desc.str(), right_align ? image_rect.x :
898 image_rect.x + image_rect.w - description_rect.w,
902 std::stringstream text;
906 <<
_(
"level") <<
" " << det.
level <<
"\n"
910 for(std::vector<t_string>::const_iterator
a = det.
abilities.begin();
a != det.
abilities.end(); ++
a) {
929 for(std::vector<attack_type>::const_iterator at_it = det.
attacks.begin();
930 at_it != det.
attacks.end(); ++at_it) {
935 << at_it->num_attacks()
936 <<
" " << at_it->name() <<
"\n";
942 std::string accuracy_parry = at_it->accuracy_parry_description();
943 if(accuracy_parry.empty() ==
false) {
948 if (!special.empty()) {
955 const std::vector<std::string> lines
965 for(std::vector<std::string>::const_iterator line = lines.begin(); line != lines.end(); ++line) {
970 if (line_area.w < area.w)
971 xpos = area.x + area.w - line_area.w;
1028 const std::vector<boost::tuple<t_string,t_string,t_string> > &abilities = u.
ability_tooltips();
1029 for(std::vector<boost::tuple<t_string,t_string,t_string> >::const_iterator
a = abilities.begin();
1030 a != abilities.end(); ++
a) {
1068 int side,
TYPE type,
bool on_left_side)
1070 unit_types_(&unit_types), side_(side)
1101 if (tr[
"availability"] !=
"musthave")
continue;
1104 "female_name" :
"male_name";
1109 if (!name.
empty()) {
1110 if (!det.
traits.empty()) {
1132 if (!adv[
"strict_amla"].to_bool() || !t->
can_advance()) {
1150 if (type !=
nullptr)
1157 if (video.
faked()) {
1200 return std::move(res);
std::string image_mods() const
read_wesnothd_connection_data(twesnothd_connection &conn)
void advance_unit(map_location loc, const std::string &advance_to, const bool &fire_event, const config *mod_option)
Function which will advance the unit at loc to 'advance_to'.
SDL_Rect text_area(const std::string &text, int size, int style)
Calculate the size of a text (in pixels) if it were to be drawn.
surface get_image(const image::locator &i_locator, TYPE type)
function to get the surface corresponding to an image.
virtual void poll() override
void GPU_UnsetClip(GPU_Target *target)
int total_movement() const
sdl_handler_vector handler_members()
const std::string & id() const
char const IMG_TEXT_SEPARATOR
virtual void select_hex(map_location hex)
std::unique_ptr< twesnothd_connection > network_connect_dialog(CVideo &video, const std::string &msg, const std::string &hostname, int port)
std::string const & gender_string(unit_race::GENDER gender)
std::string absolute_image() const
The name of the file to game_display (used in menus).
std::size_t bytes_read() const
const std::string & team_color() const
virtual bool finished() override
bool invalidate(const map_location &loc)
Function to invalidate a specific tile for redrawing.
const t_string & type_name() const
The name of the unit in the current language setting.
int max_hitpoints() const
const std::vector< t_string > & abilities() const
int get_index(int selection) const
const std::string weapon_details_sep
std::vector< events::sdl_handler * > sdl_handler_vector
Dialog that tracks network transmissions.
int recall_dialog(display &disp, const boost::shared_ptr< std::vector< unit_const_ptr > > &units, int side, const std::string &title_suffix, const int team_recall_cost)
const t_string & name() const
The unit name for display.
const t_string & type_name() const
The unit type name.
const t_string & name(GENDER gender=MALE) const
int recruit_dialog(display &disp, std::vector< const unit_type * > &units, const std::vector< std::string > &items, int side, const std::string &title_suffix)
config::const_child_itors modification_advancements() const
unit_types_preview_pane(std::vector< const unit_type * > &unit_types, const gui::filter_textbox *filterbox=nullptr, int side=1, TYPE type=SHOW_ALL, bool left_side=true)
Various functions that implement attacks and attack calculations.
Add a special kind of assert to validate whether the input from WML doesn't contain any problems that...
GLuint GLuint GLsizei GLenum type
std::vector< boost::tuple< t_string, t_string, t_string > > ability_tooltips(std::vector< bool > *active_list=nullptr) const
Tuple of: neutral ability name, gendered ability name, description.
surface reverse_image(const surface &surf)
function to reverse an image.
bool show(CVideo &video, const unsigned auto_close_time=0)
Shows the window.
const details get_details() const
std::size_t bytes_to_read() const
int relative_size(int size)
static const style & default_style
virtual void cancel() override
void add_button(dialog_button *const btn, BUTTON_LOCATION loc)
void invalidate_unit()
Function to invalidate that unit status displayed on the sidebar.
REMOVE_EMPTY : remove empty elements.
bool receive_data(config &result)
connect_wesnothd_connection_data(twesnothd_connection &conn)
unit_ptr get_advanced_unit(const unit &u, const std::string &advance_to)
Returns the advanced version of a unit (with traits and items retained).
unit_type_data unit_types
const unit_race * race() const
Never returns nullptr, but may point to the null race.
const std::string & image() const
void show_transient_message(CVideo &video, const std::string &title, const std::string &message, const std::string &image, const bool message_use_markup, const bool title_use_markup, const bool restore_background)
Shows a transient message to the user.
virtual void poll() override
SDL_Color xp_color() const
Colors for the unit's XP.
const std::vector< std::string > items
surface scale_surface(const surface &surf, int w, int h)
void show_unit_description(CVideo &video, const unit &u)
virtual void draw()
Draws invalidated items.
static lg::log_domain log_display("display")
int show(int xloc, int yloc)
const SDL_Color NORMAL_COLOR
int advance_unit_dialog(const map_location &loc)
Lets the user to select a unit advancement.
twesnothd_connection & conn_
units_list_preview_pane(unit_const_ptr u, TYPE type=SHOW_ALL, bool left_side=true)
STRIP_SPACES : strips leading and trailing blank spaces.
gui::filter_textbox & filter_
static UNUSEDNOWARN std::string _(const char *str)
static const std::string & leader_crown()
The path to the leader crown overlay.
const std::string & flag_rgb() const
std::size_t poll()
Handle all pending asynchonous events and return.
A class that represents a TCP/IP connection to the wesnothd server.
const std::vector< std::string > & overlays() const
std::vector< team > * teams
unit_type::ALIGNMENT alignment() const
bool animate_unit_advancement(const map_location &loc, size_t choice, const bool &fire_event, const bool animate)
Actually levels a unit up.
unit_ptr get_amla_unit(const unit &u, const config &mod_option)
Returns the AMLA-advanced version of a unit (with traits and items retained).
Dialog is closed with the cancel button.
GLubyte GLubyte GLubyte GLubyte w
void set_menu(menu *const m)
void show_message(CVideo &video, const std::string &title, const std::string &message, const std::string &button_caption, const bool auto_close, const bool message_use_markup)
Shows a message to the user.
unit_preview_pane(const gui::filter_textbox *filter=nullptr, TYPE type=SHOW_ALL, bool left_side=true)
GLboolean GLboolean GLboolean GLboolean a
void show_unit_list(display &gui)
Show unit-stats in a side-pane to unit-list, recall-list, etc.
const std::vector< unit_race::GENDER > & genders() const
The returned vector will not be empty, provided this has been built to the HELP_INDEXED status...
void build_unit_type(const unit_type &ut, unit_type::BUILD_STATUS status) const
Makes sure the provided unit_type is built to the specified level.
const std::string unicode_em_dash
unit_race::GENDER gender() const
virtual void cancel() override
#define log_scope2(domain, description)
static lg::log_domain log_engine("engine")
virtual bool finished()=0
int movement_left() const
Returns how far a unit can move this turn (zero if incapacitated).
void invalidate_all()
Function to invalidate all tiles.
typedef int(WINAPI *PFNWGLRELEASEPBUFFERDCARBPROC)(HPBUFFERARB hPbuffer
GPU_Rect GPU_SetClip(GPU_Target *target, Sint16 x, Sint16 y, Uint16 w, Uint16 h)
const std::vector< attack_type > & attacks() const
Various uncategorised dialogs.
const unit_map & get_units() const
std::string join(T const &v, const std::string &s=",")
Generates a new string joining container items in a list.
Encapsulates the map of the game.
std::string color2markup(const SDL_Color &color)
Create string of color-markup, such as "<255,255,0>" for yellow.
virtual bool finished() override
bool handshake_finished() const
True if connected and no high-level operation is in progress.
SDL_Rect draw_text(surface &dst, const SDL_Rect &area, int size, const SDL_Color &color, const std::string &txt, int x, int y, bool use_tooltips, int style)
Function to draw text on a surface.
virtual size_t current() override
bool network_receive_dialog(CVideo &video, const std::string &msg, config &cfg, twesnothd_connection &wesnothd_connection)
std::vector< std::string > overlays
void scroll_to_tile(const map_location &loc, SCROLL_TYPE scroll_type=ONSCREEN, bool check_fogged=true, bool force=true)
Scroll such that location loc is on-screen.
boost::shared_ptr< const std::vector< unit_const_ptr > > units_
config::const_child_itors possible_traits() const
const std::string weapon_details
gui::button details_button_
GLfloat GLfloat GLfloat GLfloat h
static void msg(const char *act, debug_info &i, const char *to="", const char *result="")
std::set< std::string > & encountered_units()
bool fire_event(const tevent event, std::vector< std::pair< twidget *, tevent > > &event_chain, twidget *dispatcher, twidget *widget, F functor)
Helper function for fire_event.
boost::shared_ptr< std::vector< unit_const_ptr > > units_
static config get_disband(const std::string &unit_id)
void add_animation(const unit *animated_unit, const unit_animation *animation, const map_location &src=map_location::null_location(), bool with_bars=false, const std::string &text="", const Uint32 text_color=0)
GLuint const GLchar * name
twesnothd_connection & conn_
int experience_needed(bool with_acceleration=true) const
SDL_Rect create_rect(const int x, const int y, const int w, const int h)
Creates an empty SDL_Rect.
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
static bool run_and_throw(const std::string &commandname, const config &data, bool use_undo=true, bool show=true, synced_command::error_handler_function error_handler=default_error_function)
GLenum GLenum GLvoid * row
void set_selection(int index)
char const HEADING_PREFIX
int max_experience() const
char const COLUMN_SEPARATOR
const std::string weapon_numbers_sep
const std::vector< t_string > & trait_names() const
SDL_Color hp_color() const
Colors for the unit's current hitpoints.
virtual size_t size() const =0
static const int max_menu_width
std::vector< const unit_type * > * unit_types_
symbol_table string_table
const details get_details() const
std::vector< attack_type > attacks() const
virtual const details get_details() const =0
Various functions that implement the undoing (and redoing) of in-game commands.
this module manages the cache of images.
Standard logging facilities (interface).
std::vector< t_string > abilities
CVideo & video()
Gets the underlying screen object.
std::vector< attack_type > attacks
Container associating units to locations.
GLsizei GLenum GLuint GLuint GLsizei char * message
const gui::filter_textbox * filter_
static std::string get_side_color_index(int side)
std::vector< std::string > split(std::string const &val, const char c, const int flags)
Splits a (comma-)separated string into a vector of pieces.
unit_iterator find(size_t id)
void sdl_blit(const surface &src, SDL_Rect *src_rect, surface &dst, SDL_Rect *dst_rect)
bool has_data_received() const
static void network_transmission_dialog(CVideo &video, gui2::tnetwork_transmission::connection_data &conn, const std::string &msg1, const std::string &msg2)
A config object defines a single node in a WML file, with access to child nodes.
static std::string alignment_description(ALIGNMENT align, unit_race::GENDER gender=unit_race::MALE)
void delete_item(int selection)
const std::string unit_type
const unit_race * race() const
Never returns nullptr, but may point to the null race.
GLsizei const GLcharARB ** string
Shows a yes and no button.
static lg::log_domain log_config("config")
preview_pane(CVideo &video)
void show_objectives(const std::string &scenarioname, const std::string &objectives)
const map_location & selected_hex() const
void set_panes(std::vector< preview_pane * > panes)
void wait_for_end() const