Add new "category" and "creator" properties to map labels

- The "category" property is mainly for use by scenario designers; players will be able to hide labels based on this
- The "creator" property is meant to allow players to hide labels placed by specific other players
- Map editor allows setting the "category" property
This commit is contained in:
Celtic Minstrel 2015-08-06 23:27:11 -04:00
parent 8c098c3264
commit af6d3060e2
18 changed files with 124 additions and 22 deletions

View file

@ -91,6 +91,41 @@
[/row]
[row]
grow_factor = 1
[column]
grow_factor = 0
border = "all"
border_size = 5
horizontal_alignment = "left"
[label]
definition = "default"
label = _ "Category:"
[/label]
[/column]
[column]
grow_factor = 1
border = "all"
border_size = 5
horizontal_grow = "true"
[text_box]
id = "category"
definition = "default"
label = ""
[/text_box]
[/column]
[/row]
[/grid]
[/column]
@ -113,7 +148,7 @@
[/toggle_button]
[/column]
[/row]
[/row]
[row]
grow_factor = 0

View file

@ -1367,7 +1367,7 @@ private:
SDL_Color color = int_to_color(team::get_side_rgb(ai_.get_side()));
const terrain_label *res;
res = gui->labels().set_label(location, text, team_name, color);
res = gui->labels().set_label(location, text, ai_.get_side() - 1, team_name, color);
if (res && resources::recorder)
resources::recorder->add_label(res);
}

View file

@ -57,7 +57,7 @@ static void display_label(int /*side*/, const map_location& location, const std:
SDL_Color color = int_to_color(team::get_side_rgb(surrounded ? 2 : 1 ) );//@fixme: for tests
const terrain_label *res;
res = gui->labels().set_label(location, text, team_name, color);
res = gui->labels().set_label(location, text, surrounded, team_name, color);
if (res && resources::recorder)
resources::recorder->add_label(res);
}

View file

@ -54,6 +54,7 @@ public:
virtual const std::vector<team> & teams() const = 0;
virtual const gamemap & map() const = 0;
virtual const unit_map & units() const = 0;
virtual const std::vector<std::string> & hidden_label_categories() const = 0;
// Helper for is_visible_to_team

View file

@ -37,7 +37,7 @@ editor_action* editor_action_label::perform(map_context& mc) const
const terrain_label *old_label = mc.get_labels().get_label(loc_);
if (old_label) {
undo.reset(new editor_action_label(loc_, old_label->text(), old_label->team_name(), old_label->color()
, old_label->visible_in_fog(), old_label->visible_in_shroud(), old_label->immutable()) );
, old_label->visible_in_fog(), old_label->visible_in_shroud(), old_label->immutable(), old_label->category()) );
} else {
undo.reset(new editor_action_label_delete(loc_));
}
@ -49,7 +49,7 @@ editor_action* editor_action_label::perform(map_context& mc) const
void editor_action_label::perform_without_undo(map_context& mc) const
{
mc.get_labels()
.set_label(loc_, text_, team_name_, color_, visible_fog_, visible_shroud_, immutable_);
.set_label(loc_, text_, -1, team_name_, color_, visible_fog_, visible_shroud_, immutable_, category_);
}
editor_action_label_delete* editor_action_label_delete::clone() const
@ -66,7 +66,7 @@ editor_action* editor_action_label_delete::perform(map_context& mc) const
if (!deleted) return NULL;
undo.reset(new editor_action_label(loc_, deleted->text(), deleted->team_name()
, deleted->color(), deleted->visible_in_fog(), deleted->visible_in_shroud(), deleted->immutable()));
, deleted->color(), deleted->visible_in_fog(), deleted->visible_in_shroud(), deleted->immutable(), deleted->category()));
perform_without_undo(mc);
return undo.release();

View file

@ -41,8 +41,8 @@ class editor_action_label : public editor_action_location
{
public:
editor_action_label(map_location loc, const std::string& text, const std::string& team_name,
SDL_Color color, bool visible_fog, bool visible_shroud, bool immutable)
: editor_action_location(loc), text_(text) , team_name_(team_name), color_(color)
SDL_Color color, bool visible_fog, bool visible_shroud, bool immutable, std::string category)
: editor_action_location(loc), text_(text) , team_name_(team_name), category_(category), color_(color)
, visible_fog_(visible_fog), visible_shroud_(visible_shroud), immutable_(immutable)
{
}
@ -53,6 +53,7 @@ class editor_action_label : public editor_action_location
protected:
const std::string text_;
const std::string team_name_;
const std::string category_;
SDL_Color color_;
bool visible_fog_;
bool visible_shroud_;

View file

@ -52,7 +52,7 @@ editor_action* mouse_action_map_label::drag_left(editor_display& disp, int x, in
partial = true;
chain = new editor_action_chain(new editor_action_label_delete(last_draged_));
chain->append_action(new editor_action_label(hex, label->text(), label->team_name(), label->color(),
label->visible_in_shroud(), label->visible_in_fog(), label->immutable()));
label->visible_in_shroud(), label->visible_in_fog(), label->immutable(), label->category()));
}
last_draged_ = hex;
@ -72,16 +72,17 @@ editor_action* mouse_action_map_label::up_left(editor_display& disp, int x, int
const terrain_label* old_label = editor::get_current_labels()->get_label(hex);
std::string label = old_label ? old_label->text() : "";
std::string team_name = old_label ? old_label->team_name() : "";
std::string category = old_label ? old_label->category() : "";
bool visible_shroud = old_label ? old_label->visible_in_shroud() : false;
bool visible_fog = old_label ? old_label->visible_in_fog() : true;
bool immutable = old_label ? old_label->immutable() : true;
gui2::teditor_edit_label d(label, immutable, visible_fog, visible_shroud);
gui2::teditor_edit_label d(label, immutable, visible_fog, visible_shroud, category);
editor_action* a = NULL;
if(d.show(disp.video())) {
a = new editor_action_label(hex, label, team_name, font::NORMAL_COLOR
, visible_fog, visible_shroud, immutable);
, visible_fog, visible_shroud, immutable, category);
update_brush_highlights(disp, hex);
}
return a;

View file

@ -35,14 +35,16 @@ class dummy_editor_display_context : public display_context
editor_map em;
unit_map u;
std::vector<team> t;
std::vector<std::string> lbls;
public:
dummy_editor_display_context() : dummy_cfg1(), em(dummy_cfg1), u(), t() {}
dummy_editor_display_context() : dummy_cfg1(), em(dummy_cfg1), u(), t(), lbls() {}
virtual ~dummy_editor_display_context(){}
virtual const gamemap & map() const { return em; }
virtual const unit_map & units() const { return u; }
virtual const std::vector<team> & teams() const { return t; }
virtual const std::vector<std::string> & hidden_label_categories() const { return lbls; }
};
const display_context * get_dummy_display_context() {

View file

@ -136,6 +136,9 @@ public:
virtual const gamemap & map() const {
return map_;
}
virtual const std::vector<std::string>& hidden_label_categories() const {
return lbl_categories_;
}
/**
* Replace the [time]s of the currently active area.
@ -478,6 +481,7 @@ private:
map_labels labels_;
unit_map units_;
std::vector<team> teams_;
std::vector<std::string> lbl_categories_;
boost::scoped_ptr<tod_manager> tod_manager_;
mp_game_settings mp_settings_;
game_classification game_classification_;

View file

@ -54,6 +54,7 @@ namespace events {
class game_board : public display_context {
std::vector<team> teams_;
std::vector<std::string> labels_;
boost::scoped_ptr<gamemap> map_;
unit_map units_;
@ -93,6 +94,7 @@ class game_board : public display_context {
virtual const std::vector<team> & teams() const { return teams_; }
virtual const gamemap & map() const { return *map_; }
virtual const unit_map & units() const { return units_; }
virtual const std::vector<std::string> & hidden_label_categories() const { return labels_; }
// Copy and swap idiom, because we have a scoped pointer.

View file

@ -49,7 +49,8 @@ REGISTER_DIALOG(editor_edit_label)
teditor_edit_label::teditor_edit_label(std::string& text,
bool& immutable,
bool& visible_fog,
bool& visible_shroud)
bool& visible_shroud,
std::string& category)
{
// std::string text = label.text();
// bool immutable = label.immutable();
@ -65,6 +66,7 @@ teditor_edit_label::teditor_edit_label(std::string& text,
// true;
register_text("label", true, text, true);
register_text("category", true, category, false);
register_bool("immutable_toggle", true, immutable);
register_bool("visible_fog_toggle", true, visible_fog);
register_bool("visible_shroud_toggle", true, visible_shroud);

View file

@ -36,16 +36,18 @@ public:
teditor_edit_label(std::string& text,
bool& immutable,
bool& visible_fog,
bool& visible_shroud);
bool& visible_shroud,
std::string& category);
/** The execute function see @ref tdialog for more information. */
static bool execute(std::string& text,
bool& immutable,
bool& visible_fog,
bool& visible_shroud,
std::string& category,
CVideo& video)
{
return teditor_edit_label(text, immutable, visible_fog, visible_shroud)
return teditor_edit_label(text, immutable, visible_fog, visible_shroud, /*color,*/ category)
.show(video);
}

View file

@ -145,11 +145,13 @@ void map_labels::set_team(const team* team)
const terrain_label* map_labels::set_label(const map_location& loc,
const t_string& text,
const int creator,
const std::string& team_name,
const SDL_Color color,
const bool visible_in_fog,
const bool visible_in_shroud,
const bool immutable,
const std::string& category,
const t_string& tooltip )
{
terrain_label* res = NULL;
@ -176,7 +178,7 @@ const terrain_label* map_labels::set_label(const map_location& loc,
}
else
{
current_label->second->update_info(text, tooltip, team_name, color, visible_in_fog, visible_in_shroud, immutable);
current_label->second->update_info(text, creator, tooltip, team_name, color, visible_in_fog, visible_in_shroud, immutable, category);
res = current_label->second;
}
}
@ -187,6 +189,7 @@ const terrain_label* map_labels::set_label(const map_location& loc,
// Add the new label.
res = new terrain_label(text,
creator,
team_name,
loc,
*this,
@ -194,6 +197,7 @@ const terrain_label* map_labels::set_label(const map_location& loc,
visible_in_fog,
visible_in_shroud,
immutable,
category,
tooltip);
add_label(loc, res);
@ -289,6 +293,7 @@ void map_labels::recalculate_shroud()
/// creating new label
terrain_label::terrain_label(const t_string& text,
const int creator,
const std::string& team_name,
const map_location& loc,
const map_labels& parent,
@ -296,14 +301,17 @@ terrain_label::terrain_label(const t_string& text,
const bool visible_in_fog,
const bool visible_in_shroud,
const bool immutable,
const std::string& category,
const t_string& tooltip ) :
handle_(0),
text_(text),
tooltip_(tooltip),
category_(category),
team_name_(team_name),
visible_in_fog_(visible_in_fog),
visible_in_shroud_(visible_in_shroud),
immutable_(immutable),
creator_(creator),
color_(color),
parent_(&parent),
loc_(loc)
@ -320,6 +328,7 @@ terrain_label::terrain_label(const map_labels &parent, const config &cfg) :
visible_in_fog_(true),
visible_in_shroud_(false),
immutable_(true),
creator_(-1),
color_(),
parent_(&parent),
loc_()
@ -347,6 +356,17 @@ void terrain_label::read(const config &cfg)
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);
category_ = cfg["category"].str();
int side = cfg["side"].to_int(-1);
if(side >= 0) {
creator_ = side - 1;
} else if(cfg["side"].str() == "current") {
config::attribute_value current_side = vs.get_variable_const("side_number");
if(!current_side.empty()) {
creator_ = current_side.to_int();
}
}
text_ = utils::interpolate_variables_into_tstring(text_, vs); // Not moved to rendering, as that would depend on variables at render-time
team_name_ = utils::interpolate_variables_into_string(team_name_, vs);
@ -371,6 +391,8 @@ void terrain_label::write(config& cfg) const
cfg["visible_in_fog"] = visible_in_fog_;
cfg["visible_in_shroud"] = visible_in_shroud_;
cfg["immutable"] = immutable_;
cfg["category"] = category_;
cfg["side"] = creator_ + 1;
}
const t_string& terrain_label::text() const
@ -383,6 +405,16 @@ const t_string& terrain_label::tooltip() const
return tooltip_;
}
int terrain_label::creator() const
{
return creator_;
}
const std::string& terrain_label::category() const
{
return category_;
}
const std::string& terrain_label::team_name() const
{
return team_name_;
@ -434,6 +466,7 @@ void terrain_label::set_text(const t_string& text)
}
void terrain_label::update_info(const t_string& text,
const int creator,
const t_string& tooltip,
const std::string& team_name,
const SDL_Color color)
@ -442,21 +475,25 @@ void terrain_label::update_info(const t_string& text,
text_ = text;
tooltip_ = tooltip;
team_name_ = team_name;
creator_ = creator;
draw();
}
void terrain_label::update_info(const t_string& text,
const int creator,
const t_string& tooltip,
const std::string& team_name,
const SDL_Color color,
const bool visible_in_fog,
const bool visible_in_shroud,
const bool immutable)
const bool immutable,
const std::string& category)
{
visible_in_fog_ = visible_in_fog;
visible_in_shroud_ = visible_in_shroud;
immutable_ = immutable;
update_info(text, tooltip, team_name, color);
category_ = category;
update_info(text, creator, tooltip, team_name, color);
}
void terrain_label::recalculate()

View file

@ -47,11 +47,13 @@ public:
const terrain_label* get_label(const map_location& loc) const;
const terrain_label* set_label(const map_location& loc,
const t_string& text,
const int creator = -1,
const std::string& team = "",
const SDL_Color color = font::NORMAL_COLOR,
const bool visible_in_fog = true,
const bool visible_in_shroud = false,
const bool immutable = false,
const std::string& category = "",
const t_string& tooltip = "" );
bool enabled() const { return enabled_; }
@ -99,6 +101,7 @@ class terrain_label
{
public:
terrain_label(const t_string& text,
const int creator,
const std::string& team_name,
const map_location& loc,
const map_labels& parent,
@ -106,6 +109,7 @@ public:
const bool visible_in_fog = true,
const bool visible_in_shroud = false,
const bool immutable = false,
const std::string& category = "",
const t_string& tooltip = "" );
terrain_label(const map_labels &, const config &);
@ -117,7 +121,9 @@ public:
const t_string& text() const;
const t_string& tooltip() const;
int creator() const;
const std::string& team_name() const;
const std::string& category() const;
bool visible_in_fog() const;
bool visible_in_shroud() const;
bool immutable() const;
@ -127,17 +133,20 @@ public:
void set_text(const t_string&);
void update_info(const t_string&,
const int creator,
const t_string&,
const std::string&,
const SDL_Color);
void update_info(const t_string& text,
const int creator,
const t_string& tooltip,
const std::string& team_name,
const SDL_Color color,
const bool visible_in_fog,
const bool visible_in_shroud,
const bool immutable);
const bool immutable,
const std::string& category);
void recalculate();
void calculate_shroud();
@ -156,10 +165,12 @@ private:
t_string text_;
t_string tooltip_;
std::string category_;
std::string team_name_;
bool visible_in_fog_;
bool visible_in_shroud_;
bool immutable_;
int creator_;
SDL_Color color_;

View file

@ -1180,7 +1180,7 @@ void menu_handler::label_terrain(mouse_handler& mousehandler, bool team_only)
} else {
color = int_to_color(team::get_side_rgb(gui_->viewing_side()));
}
const terrain_label* res = gui_->labels().set_label(loc, label, team_name, color);
const terrain_label* res = gui_->labels().set_label(loc, label, gui_->viewing_team(), team_name, color);
if (res)
resources::recorder->add_label(res);
}

View file

@ -68,6 +68,7 @@ public:
: um_()
, gm_(&dc.map())
, tm_(&dc.teams())
, lbls_(&dc.hidden_label_categories())
{
static unit_map empty_unit_map;
um_ = &empty_unit_map;
@ -75,11 +76,13 @@ public:
const unit_map & units() const { return *um_; }
const gamemap & map() const { return *gm_; }
const std::vector<team> & teams() const { return *tm_; }
const std::vector<std::string> & hidden_label_categories() const { return *lbls_; }
private:
const unit_map * um_;
const gamemap * gm_;
const std::vector<team> * tm_;
const std::vector<std::string> * lbls_;
};
class ignore_units_filter_context : public filter_context {

View file

@ -717,6 +717,7 @@ REPLAY_RETURN do_replay_handle(bool one_move)
resources::screen->labels().set_label(label.location(),
label.text(),
label.creator(),
label.team_name(),
label.color());
}

View file

@ -3585,8 +3585,8 @@ int game_lua_kernel::intf_label(lua_State *L)
terrain_label label(screen.labels(), cfg.get_config());
screen.labels().set_label(label.location(), label.text(), label.team_name(), label.color(),
label.visible_in_fog(), label.visible_in_shroud(), label.immutable(), label.tooltip());
screen.labels().set_label(label.location(), label.text(), label.creator(), label.team_name(), label.color(),
label.visible_in_fog(), label.visible_in_shroud(), label.immutable(), label.category(), label.tooltip());
}
return 0;
}