Update unit stats display after fight (comment in bug #10763).
Also update it after moves, after undo/redo moves etc. The trick was to do all this without reselecting the unit.
This commit is contained in:
parent
7bdbfb8e2a
commit
45ffd1367a
5 changed files with 42 additions and 28 deletions
|
@ -69,6 +69,7 @@ game_display::game_display(unit_map& units, CVideo& video, const gamemap& map,
|
|||
teams_(t),
|
||||
level_(level),
|
||||
invalidateUnit_(true),
|
||||
displayedUnitHex_(),
|
||||
overlays_(),
|
||||
currentTeam_(0),
|
||||
activeTeam_(0),
|
||||
|
@ -212,17 +213,35 @@ void game_display::select_hex(gamemap::location hex)
|
|||
return;
|
||||
}
|
||||
display::select_hex(hex);
|
||||
invalidate_unit();
|
||||
|
||||
if (units_.count(hex)) {
|
||||
displayedUnitHex_ = hex;
|
||||
invalidate_unit();
|
||||
}
|
||||
}
|
||||
|
||||
void game_display::highlight_hex(gamemap::location hex)
|
||||
{
|
||||
const int has_unit = units_.count(mouseoverHex_) + units_.count(hex);
|
||||
if (units_.count(hex)) {
|
||||
displayedUnitHex_ = hex;
|
||||
invalidate_unit();
|
||||
} else if (units_.count(mouseoverHex_)) {
|
||||
// mouse moved from unit hex to non-unit hex
|
||||
if (units_.count(selectedHex_)) {
|
||||
displayedUnitHex_ = selectedHex_;
|
||||
invalidate_unit();
|
||||
}
|
||||
}
|
||||
|
||||
display::highlight_hex(hex);
|
||||
invalidate_game_status();
|
||||
}
|
||||
|
||||
if(has_unit) {
|
||||
|
||||
void game_display::invalidate_unit_after_move(const gamemap::location& src, const gamemap::location& dst)
|
||||
{
|
||||
if (src == displayedUnitHex_) {
|
||||
displayedUnitHex_ = dst;
|
||||
invalidate_unit();
|
||||
}
|
||||
}
|
||||
|
@ -487,7 +506,7 @@ void game_display::draw_report(reports::TYPE report_num)
|
|||
units_, teams_,
|
||||
teams_[viewing_team()],
|
||||
size_t(currentTeam_+1),size_t(activeTeam_+1),
|
||||
selectedHex_,mouseoverHex_,status_,observers_,level_);
|
||||
selectedHex_,mouseoverHex_,displayedUnitHex_,status_,observers_,level_);
|
||||
|
||||
brighten = false;
|
||||
if(report_num == reports::TIME_OF_DAY) {
|
||||
|
@ -528,16 +547,10 @@ void game_display::draw_sidebar()
|
|||
// We display the unit the mouse is over if it is over a unit,
|
||||
// otherwise we display the unit that is selected.
|
||||
unit_map::const_iterator i =
|
||||
find_visible_unit(units_,mouseoverHex_,
|
||||
find_visible_unit(units_,displayedUnitHex_,
|
||||
map_,
|
||||
teams_,teams_[viewing_team()]);
|
||||
|
||||
if(i == units_.end()) {
|
||||
i = find_visible_unit(units_,selectedHex_,
|
||||
map_,
|
||||
teams_,teams_[viewing_team()]);
|
||||
}
|
||||
|
||||
if(i != units_.end()) {
|
||||
for(size_t r = reports::UNIT_REPORTS_BEGIN; r != reports::UNIT_REPORTS_END; ++r) {
|
||||
draw_report(reports::TYPE(r));
|
||||
|
|
|
@ -111,6 +111,9 @@ public:
|
|||
//! Function to invalidate that unit status displayed on the sidebar.
|
||||
void invalidate_unit() { invalidateUnit_ = true; }
|
||||
|
||||
//! Same as invalidate_unit() if moving the displayed unit.
|
||||
void invalidate_unit_after_move(const gamemap::location& src, const gamemap::location& dst);
|
||||
|
||||
private:
|
||||
//! Function to invalidate animated terrains which may have changed.
|
||||
void invalidate_animations();
|
||||
|
@ -234,6 +237,7 @@ private:
|
|||
void invalidate_route();
|
||||
|
||||
bool invalidateUnit_;
|
||||
gamemap::location displayedUnitHex_;
|
||||
|
||||
struct overlay {
|
||||
overlay(const std::string& img, const std::string& halo_img,
|
||||
|
|
|
@ -40,26 +40,19 @@ report generate_report(TYPE type,
|
|||
const gamemap& map, unit_map& units,
|
||||
const std::vector<team>& teams, const team& current_team,
|
||||
unsigned int current_side, unsigned int playing_side,
|
||||
const gamemap::location& loc, const gamemap::location& mouseover,
|
||||
const gamemap::location& loc, const gamemap::location& mouseover, const gamemap::location& displayed_unit_hex,
|
||||
const gamestatus& status, const std::set<std::string>& observers,
|
||||
const config& level)
|
||||
{
|
||||
unit_map::iterator u = units.end();
|
||||
bool mouseover_unit = true;
|
||||
|
||||
if(int(type) >= int(UNIT_REPORTS_BEGIN) && int(type) < int(UNIT_REPORTS_END) || type == POSITION) {
|
||||
|
||||
u = find_visible_unit(units,mouseover,
|
||||
map,
|
||||
teams,current_team);
|
||||
if(u == units.end()) {
|
||||
mouseover_unit = false;
|
||||
u = find_visible_unit(units,loc,
|
||||
map,
|
||||
teams,current_team);
|
||||
if(u == units.end() && type != POSITION) {
|
||||
return report();
|
||||
}
|
||||
u = find_visible_unit(units,displayed_unit_hex,
|
||||
map,
|
||||
teams,current_team);
|
||||
if(u == units.end() && type != POSITION) {
|
||||
return report();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -443,7 +436,11 @@ Units cannot be killed by poison alone. The poison will not reduce it below 1 HP
|
|||
|
||||
str << mouseover;
|
||||
|
||||
if(u == units.end() || current_team.shrouded(mouseover))
|
||||
if(u == units.end())
|
||||
break;
|
||||
if(displayed_unit_hex != mouseover && displayed_unit_hex != loc)
|
||||
break;
|
||||
if(current_team.shrouded(mouseover))
|
||||
break;
|
||||
|
||||
const int move_cost = u->second.movement_cost(terrain);
|
||||
|
@ -451,7 +448,7 @@ Units cannot be killed by poison alone. The poison will not reduce it below 1 HP
|
|||
|
||||
if(move_cost < 99) {
|
||||
str << " (" << defense << "%," << move_cost << ")";
|
||||
} else if (mouseover_unit) {
|
||||
} else if (mouseover == displayed_unit_hex) {
|
||||
str << " (" << defense << "%,-)";
|
||||
} else {
|
||||
str << " (-)";
|
||||
|
|
|
@ -97,7 +97,7 @@ namespace reports {
|
|||
const gamemap& map, unit_map& units,
|
||||
const std::vector<team>& teams, const team& current_team,
|
||||
unsigned int current_side, int unsigned active_side,
|
||||
const gamemap::location& loc, const gamemap::location& mouseover,
|
||||
const gamemap::location& loc, const gamemap::location& mouseover, const gamemap::location& displayed_unit_hex,
|
||||
const gamestatus& status, const std::set<std::string>& observers,
|
||||
const config& level);
|
||||
}
|
||||
|
|
|
@ -141,7 +141,7 @@ void move_unit(const std::vector<gamemap::location>& path, unit& u, const std::v
|
|||
u.set_standing(path[path.size()-1]);
|
||||
|
||||
u.set_hidden(was_hidden);
|
||||
disp->invalidate_unit();
|
||||
disp->invalidate_unit_after_move(path[0], path[path.size()-1]);
|
||||
}
|
||||
|
||||
void unit_die(const gamemap::location& loc, unit& loser,
|
||||
|
|
Loading…
Add table
Reference in a new issue