Add 'immutable' key to [label], defaulting to true (bug #16078)

This commit is contained in:
Alexander van Gessel 2010-05-30 05:30:44 +01:00
parent 2bfebcaf61
commit d2af7f1d5d
10 changed files with 53 additions and 24 deletions

View file

@ -124,6 +124,7 @@ Version 1.9.0-svn:
* Added scroll_to_leader attribute to side tag.
Default value is 'yes' (bug #15921)
* Draw the map border over _off^_usr tiles too.
* Add 'immutable' key to [label], defaulting to true (feature #16078)
* Miscellaneous and bug fixes:
* Added help entry when new unit is created directly in the recall list
* Defaulted log level to warning again

View file

@ -1586,6 +1586,12 @@ For game purposes, the races group into factions; for example, orcs often cooper
text="This is not a forest"
[/label]
[label]
x,y=4,10
text="This label is not immutable"
immutable="no"
[/label]
[label]
x,y = 25,6
text = "Let it snow"

View file

@ -2563,7 +2563,7 @@ WML_HANDLER_FUNCTION(label, /*event_info*/, cfg)
terrain_label label(screen.labels(), cfg.get_config());
screen.labels().set_label(label.location(), label.text(),
label.team_name(), label.colour(), label.visible_in_fog(), label.visible_in_shroud());
label.team_name(), label.colour(), label.visible_in_fog(), label.visible_in_shroud(), label.immutable());
}
WML_HANDLER_FUNCTION(heal_unit, event_info, cfg)

View file

@ -130,7 +130,8 @@ const terrain_label* map_labels::set_label(const map_location& loc,
const std::string& team_name,
const SDL_Color colour,
const bool visible_in_fog,
const bool visible_in_shroud)
const bool visible_in_shroud,
const bool immutable)
{
terrain_label* res = 0;
team_label_map::iterator current_label_map = labels_.find(team_name);
@ -143,7 +144,7 @@ const terrain_label* map_labels::set_label(const map_location& loc,
if(text.empty())
{
current_label->second->set_text("");
res = new terrain_label("",team_name,loc,*this,colour,visible_in_fog,visible_in_shroud);
res = new terrain_label("",team_name,loc,*this,colour,visible_in_fog,visible_in_shroud,immutable);
delete current_label->second;
current_label_map->second.erase(loc);
@ -182,7 +183,8 @@ const terrain_label* map_labels::set_label(const map_location& loc,
*this,
colour,
visible_in_fog,
visible_in_shroud);
visible_in_shroud,
immutable);
add_label(loc,label);
res = label;
@ -201,35 +203,37 @@ void map_labels::add_label(const map_location &loc, terrain_label *new_label)
labels_[new_label->team_name()][loc] = new_label;
}
void map_labels::clear(const std::string& team_name)
void map_labels::clear(const std::string& team_name, bool force)
{
team_label_map::iterator i = labels_.find(team_name);
if (i != labels_.end())
{
clear_map(i->second);
clear_map(i->second, force);
}
i = labels_.find("");
if (i != labels_.end())
{
clear_map(i->second);
clear_map(i->second, force);
}
}
void map_labels::clear_map(label_map &m)
void map_labels::clear_map(label_map &m, bool force)
{
foreach (label_map::value_type &v, m)
{
delete v.second;
if (!v.second->immutable() || force) {
delete v.second;
m.erase(v.first);
}
}
m.clear();
}
void map_labels::clear_all()
{
foreach (team_label_map::value_type &m, labels_)
{
clear_map(m.second);
clear_map(m.second, true);
}
labels_.clear();
}
@ -271,12 +275,14 @@ terrain_label::terrain_label(const std::string& text,
const map_labels& parent,
const SDL_Color colour,
const bool visible_in_fog,
const bool visible_in_shroud) :
const bool visible_in_shroud,
const bool immutable) :
handle_(0),
text_(text),
team_name_(team_name),
visible_in_fog_(visible_in_fog),
visible_in_shroud_(visible_in_shroud),
immutable_(immutable),
colour_(colour),
parent_(&parent),
loc_(loc)
@ -292,6 +298,7 @@ terrain_label::terrain_label(const map_labels &parent, const config &cfg) :
team_name_(),
visible_in_fog_(true),
visible_in_shroud_(false),
immutable_(true),
colour_(),
parent_(&parent),
loc_()
@ -317,6 +324,7 @@ void terrain_label::read(const config &cfg)
team_name_ = cfg["team_name"].str();
visible_in_fog_ = cfg["visible_in_fog"].to_bool(true);
visible_in_shroud_ = cfg["visible_in_shroud"].to_bool();
immutable_ = cfg["immutable"].to_bool(true);
text_ = utils::interpolate_variables_into_string(text_, vs);
team_name_ = utils::interpolate_variables_into_string(team_name_, vs);
@ -344,6 +352,7 @@ void terrain_label::write(config& cfg) const
cfg["colour"] = cfg_colour();
cfg["visible_in_fog"] = visible_in_fog_;
cfg["visible_in_shroud"] = visible_in_shroud_;
cfg["immutable"] = immutable_;
}
const std::string& terrain_label::text() const
@ -366,6 +375,11 @@ bool terrain_label::visible_in_shroud() const
return visible_in_shroud_;
}
bool terrain_label::immutable() const
{
return immutable_;
}
const map_location& terrain_label::location() const
{
return loc_;

View file

@ -49,11 +49,12 @@ public:
const std::string& team = "",
const SDL_Color colour = font::NORMAL_COLOUR,
const bool visible_in_fog = true,
const bool visible_in_shroud = false);
const bool visible_in_shroud = false,
const bool immutable = false);
void add_label(const map_location &, terrain_label *);
void clear(const std::string&);
void clear(const std::string&, bool force);
void recalculate_labels();
bool visible_global_label(const map_location&) const;
@ -68,7 +69,7 @@ public:
void clear_all();
private:
void clear_map(label_map &);
void clear_map(label_map &, bool);
map_labels(const map_labels&);
void operator=(const map_labels&);
@ -89,7 +90,8 @@ public:
const map_labels&,
const SDL_Color colour = font::NORMAL_COLOUR,
const bool visible_in_fog = true,
const bool visible_in_shroud = false);
const bool visible_in_shroud = false,
const bool immutable = false);
terrain_label(const map_labels &, const config &);
@ -102,6 +104,7 @@ public:
const std::string& team_name() const;
bool visible_in_fog() const;
bool visible_in_shroud() const;
bool immutable() const;
const map_location& location() const;
const SDL_Colour& colour() const;
@ -129,6 +132,7 @@ private:
std::string team_name_;
bool visible_in_fog_;
bool visible_in_shroud_;
bool immutable_;
SDL_Color colour_;

View file

@ -1576,8 +1576,8 @@ void menu_handler::clear_labels()
if (gui_->team_valid()
&& !is_observer())
{
gui_->labels().clear(gui_->current_team_name());
recorder.clear_labels(gui_->current_team_name());
gui_->labels().clear(gui_->current_team_name(), false);
recorder.clear_labels(gui_->current_team_name(), false);
}
}

View file

@ -39,6 +39,7 @@
#include "game_preferences.hpp"
#include "wml_exception.hpp"
#include "formula_string_utils.hpp"
#include "map_label.hpp"
#include "ai/manager.hpp"
#include "ai/testing.hpp"

View file

@ -977,12 +977,14 @@ bool playsingle_controller::can_execute_command(hotkey::HOTKEY_COMMAND command,
res = !is_observer();
break;
case hotkey::HOTKEY_LABEL_TEAM_TERRAIN:
case hotkey::HOTKEY_LABEL_TERRAIN:
case hotkey::HOTKEY_LABEL_TERRAIN: {
const terrain_label *label = resources::screen->labels().get_label(mouse_handler_.get_last_hex());
res = !events::commands_disabled && map_.on_board(mouse_handler_.get_last_hex())
&& !gui_->shrouded(mouse_handler_.get_last_hex())
&& !is_observer();
&& !is_observer()
&& (!label || !label->immutable());
break;
}
case hotkey::HOTKEY_CONTINUE_MOVE: {
if(browse_ || events::commands_disabled)
return false;

View file

@ -328,13 +328,14 @@ void replay::add_label(const terrain_label* label)
cmd->add_child("label",val);
}
void replay::clear_labels(const std::string& team_name)
void replay::clear_labels(const std::string& team_name, bool force)
{
config* const cmd = add_command(false);
(*cmd)["undo"] = false;
config val;
val["team_name"] = team_name;
val["force"] = force;
cmd->add_child("clear_labels",val);
}
@ -858,7 +859,7 @@ bool do_replay_handle(int side_num, const std::string &do_untill)
}
else if (const config &child = cfg->child("clear_labels"))
{
resources::screen->labels().clear(std::string(child["team_name"]));
resources::screen->labels().clear(std::string(child["team_name"]), child["force"].to_bool());
}
else if (const config &child = cfg->child("rename"))
{

View file

@ -57,7 +57,7 @@ public:
void choose_option(int index);
void text_input(std::string input);
void add_label(const terrain_label*);
void clear_labels(const std::string&);
void clear_labels(const std::string&, bool);
void add_rename(const std::string& name, const map_location& loc);
void init_side();
void end_turn();