Tooltip for the moves now displays the movement costs in the sidebar.

This commit is contained in:
Fabian Müller 2013-01-16 16:20:52 +00:00
parent 177605fbaf
commit df24cf3360
3 changed files with 47 additions and 2 deletions

View file

@ -45,6 +45,8 @@ Version 1.11.1+svn:
* User interface:
* Allow copying the selection in the old (default) lobby using
Ctrl+C/Command+C (bug #5877)
* Color coded the resistance table in the hp display's tooltip.
* Tooltip for the movement points display shows the movement costs.
* WML engine:
* [unit_overlay] and [remove_unit_overlay] now return a more meaningful
error message if the image= key is missing

View file

@ -36,6 +36,8 @@ Version 1.11.1+svn:
* User interface:
* Allow copying the selection in the old (default) lobby using
Ctrl+C/Command+C.
* Color coded the resistance table in the hp display's tooltip.
* Tooltip for the movement points display shows the movement costs.
* Miscellaneous and bug fixes:
* The undo stack is preserved across a save-reload.

View file

@ -572,7 +572,7 @@ REPORT_GENERATOR(selected_unit_vision)
static config unit_moves(const unit* u)
{
if (!u) return report();
std::ostringstream str;
std::ostringstream str, tooltip;
double movement_frac = 1.0;
if (u->side() == resources::screen->playing_side()) {
movement_frac = double(u->movement_left()) / std::max<int>(1, u->total_movement());
@ -580,10 +580,51 @@ static config unit_moves(const unit* u)
movement_frac = 1.0;
}
std::set<t_translation::t_terrain>::const_iterator terrain_it =
preferences::encountered_terrains().begin();
tooltip << "Movement Costs:\n";
for (; terrain_it != preferences::encountered_terrains().end();
++terrain_it) {
const t_translation::t_terrain terrain = *terrain_it;
if (terrain == t_translation::FOGGED || terrain == t_translation::VOID_TERRAIN || terrain == t_translation::OFF_MAP_USER)
continue;
const terrain_type& info = resources::game_map->get_terrain_info(terrain);
if (info.union_type().size() == 1 && info.union_type()[0] == info.number() && info.is_nonnull()) {
const std::string& name = info.name();
const std::string id = info.id();
const int moves = u->movement_cost(terrain);
tooltip << name << ": ";
std::string color;
//movement - range: 1 .. 5, unit_movement_type::UNREACHABLE=impassable
const bool cannot_move = moves > u->total_movement();
if (cannot_move) // cannot move in this terrain
color = "red";
else if (moves > 1)
color = "yellow";
else
color = "white";
tooltip << "<span foreground=\"" << color << "\">";
// A 5 MP margin; if the movement costs go above
// the unit's max moves + 5, we replace it with dashes.
if(cannot_move && (moves > u->total_movement() + 5)) {
tooltip << utils::unicode_figure_dash;
} else {
tooltip << moves;
}
tooltip << "</span>\n";
}
}
int grey = 128 + int((255 - 128) * movement_frac);
SDL_Color c = create_color(grey, grey, grey);
str << span_color(c) << u->movement_left() << '/' << u->total_movement() << naps;
return text_report(str.str());
return text_report(str.str(), tooltip.str());
}
REPORT_GENERATOR(unit_moves)
{