Merge branch 'master' of github.com:wesnoth/wesnoth-old

This commit is contained in:
Alexander van Gessel 2014-02-24 02:14:59 +01:00
commit e838206f65
4 changed files with 86 additions and 48 deletions

View file

@ -6,6 +6,8 @@ Version 1.11.10+dev:
* Miscellaneous and bug fixes:
* Units can no longer be moved in linger mode (bug #21450).
* Changed: Updated valgrind suppression file.
* Labels are now removed when shroud/fog is removed, rather than waiting
for a new turn (bug #21434).
Version 1.11.10:
* Add-ons client:

View file

@ -7,6 +7,8 @@ Version 1.11.10+dev:
* Updated translations:
* Miscellaneous and bug fixes:
* Units can no longer be moved in linger mode (bug #21450).
* Labels are now removed when shroud/fog is removed, rather than waiting
for a new turn (bug #21434).
Version 1.11.10:

View file

@ -22,15 +22,23 @@
#include <boost/foreach.hpp>
//our definition of map labels being obscured is if the tile is obscured,
//Our definition of map labels being obscured is if the tile is obscured,
//or the tile below is obscured. This is because in the case where the tile
//itself is visible, but the tile below is obscured, the bottom half of the
//tile will still be shrouded, and the label being drawn looks weird
static bool is_shrouded(const display& disp, const map_location& loc)
//tile will still be shrouded, and the label being drawn looks weird.
inline bool is_shrouded(const display& disp, const map_location& loc)
{
return disp.shrouded(loc) || disp.shrouded(map_location(loc.x,loc.y+1));
}
/// Rather simple test for a hex being fogged.
/// This only exists because is_shrouded() does. (The code looks nicer if
/// the test for being fogged looks similar to the test for being shrouded.)
inline bool is_fogged(const display& disp, const map_location& loc)
{
return disp.fogged(loc);
}
map_labels::map_labels(const display &disp, const team *team) :
disp_(disp), team_(team), labels_(), enabled_(true)
{
@ -143,7 +151,11 @@ const terrain_label* map_labels::set_label(const map_location& loc,
const bool visible_in_shroud,
const bool immutable)
{
terrain_label* res = 0;
terrain_label* res = NULL;
// See if there is already a label in this location for this team.
// (We do not use get_label_private() here because we might need
// the label_map as well as the terrain_label.)
team_label_map::iterator current_label_map = labels_.find(team_name);
label_map::iterator current_label;
@ -153,23 +165,13 @@ const terrain_label* map_labels::set_label(const map_location& loc,
// Found old checking if need to erase it
if(text.str().empty())
{
current_label->second->set_text("");
res = NULL;
// Erase the old label.
delete current_label->second;
current_label_map->second.erase(loc);
team_label_map::iterator global_label_map = labels_.find("");
label_map::iterator itor;
bool update = false;
if(global_label_map != labels_.end()) {
itor = global_label_map->second.find(loc);
update = itor != global_label_map->second.end();
}
if (update)
{
itor->second->recalculate();
}
current_label_map->second.erase(current_label);
// Restore the global label in the same spot, if any.
if ( terrain_label* global_label = get_label_private(loc, "") )
global_label->recalculate();
}
else
{
@ -179,15 +181,11 @@ const terrain_label* map_labels::set_label(const map_location& loc,
}
else if(!text.str().empty())
{
team_label_map::iterator global_label_map = labels_.find("");
label_map::iterator itor;
bool update = false;
if(global_label_map != labels_.end()) {
itor = global_label_map->second.find(loc);
update = itor != global_label_map->second.end();
}
// See if we will be replacing a global label.
terrain_label* global_label = get_label_private(loc, "");
terrain_label* label = new terrain_label(text,
// Add the new label.
terrain_label* res = new terrain_label(text,
team_name,
loc,
*this,
@ -195,15 +193,11 @@ const terrain_label* map_labels::set_label(const map_location& loc,
visible_in_fog,
visible_in_shroud,
immutable);
add_label(loc,label);
res = label;
if (update)
{
itor->second->recalculate();
}
add_label(loc, res);
// Hide the old label.
if ( global_label != NULL )
global_label->recalculate();
}
return res;
}
@ -267,6 +261,11 @@ void map_labels::enable(bool is_enabled) {
}
}
/**
* Returns whether or not a global (non-team) label can be shown at a
* specified location.
* (Global labels are suppressed in favor of team labels.)
*/
bool map_labels::visible_global_label(const map_location& loc) const
{
const team_label_map::const_iterator glabels = labels_.find(team_name());
@ -448,11 +447,9 @@ void terrain_label::recalculate()
void terrain_label::calculate_shroud() const
{
if (handle_)
{
bool shrouded = visible_in_shroud_ || !is_shrouded(parent_->disp(), loc_);
font::show_floating_label(handle_, shrouded);
font::show_floating_label(handle_, !hidden());
}
}
@ -462,7 +459,7 @@ void terrain_label::draw()
return;
clear();
if (!visible())
if ( !viewable() )
return;
const map_location loc_nextx(loc_.x+1,loc_.y);
@ -491,16 +488,46 @@ void terrain_label::draw()
}
bool terrain_label::visible() const
/**
* This is a lightweight test used to see if labels are revealed as a result
* of unit actions (i.e. fog/shroud clearing). It should not contain any tests
* that are invariant during unit movement (disregarding potential WML events);
* those belong in visible().
*/
bool terrain_label::hidden() const
{
if (!parent_->enabled()) return false;
if ((!visible_in_fog_ && parent_->disp().fogged(loc_))
|| (!visible_in_shroud_ && parent_->disp().shrouded(loc_))) {
return false;
}
// Fog can hide some labels.
if ( !visible_in_fog_ && is_fogged(parent_->disp(), loc_) )
return true;
return ((parent_->team_name() == team_name_ && (!is_observer() || !team::nteams()))
|| (team_name_.empty() && parent_->visible_global_label(loc_)));
// Shroud can hide some labels.
if ( !visible_in_shroud_ && is_shrouded(parent_->disp(), loc_) )
return true;
return false;
}
/**
* This is a test used to see if we should bother with the overhead of actually
* creating a label. Conditions that can change during unit movement (disregarding
* potential WML events) should not be listed here; they belong in hidden().
*/
bool terrain_label::viewable() const
{
if ( !parent_->enabled() )
return false;
// Observers are not privvy to team labels. (Unless this is the map editor,
// in which we want location labels initially visible; this is implied by
// case team::nteams() being zero.)
bool can_see_team_labels = (!is_observer() || !team::nteams());
// Global labels are shown unless covered by a team label.
if ( team_name_.empty() )
return !can_see_team_labels || parent_->visible_global_label(loc_);
// Team labels are only shown to members of the team.
return can_see_team_labels && parent_->team_name() == team_name_;
}
void terrain_label::clear()

View file

@ -74,6 +74,12 @@ public:
private:
void clear_map(label_map &, bool);
/// For our private use, a wrapper for get_label() that can return a pointer
/// to a non-const terrain_label.
terrain_label* get_label_private(const map_location& loc, const std::string& team_name)
{ return const_cast<terrain_label*>(get_label(loc, team_name)); }
// Note: this is not an overload of get_label() so that we do not block
// outsiders from calling get_label for a non-const map_labels object.
const display& disp_;
const team* team_;
@ -132,7 +138,8 @@ private:
const terrain_label& operator=(const terrain_label&);
void clear();
void draw();
bool visible() const;
bool hidden() const;
bool viewable() const;
std::string cfg_color() const;
int handle_;