Skip to content

Commit

Permalink
Connect Engine: cleaned up color handling a bit
Browse files Browse the repository at this point in the history
* Got rid of custom color class member variable. It was no longer used except in the ctor, so it could
  be demoted to a local value.
* Use color id instead of color index for coloring unknown unit image in MP Staging.
  • Loading branch information
Vultraz authored and GregoryLundberg committed Nov 30, 2017
1 parent f33570c commit 88e47a8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
16 changes: 6 additions & 10 deletions src/game_initialization/connect_engine.cpp
Expand Up @@ -865,9 +865,8 @@ side_engine::side_engine(const config& cfg, connect_engine& parent_engine, const
, flg_(parent_.era_factions_, cfg_, parent_.force_lock_settings_, parent_.params_.use_map_settings, parent_.params_.saved_game)
, allow_changes_(!parent_.params_.saved_game && !(flg_.choosable_factions().size() == 1 && flg_.choosable_leaders().size() == 1 && flg_.choosable_genders().size() == 1))
, waiting_to_choose_faction_(allow_changes_)
, custom_color_()
, color_id_()
, color_options_()
, color_options_(game_config::default_colors)
, color_id_(color_options_[color_])
{
// Save default attributes that could be overwirtten by the faction, so that correct faction lists would be
// initialized by flg_manager when the new side config is sent over network.
Expand Down Expand Up @@ -944,25 +943,22 @@ side_engine::side_engine(const config& cfg, connect_engine& parent_engine, const
team_ = team_name_index;
}

color_options_ = game_config::default_colors;
color_id_ = color_options_[color_];

if(!cfg["color"].empty()) {
if(cfg["color"].to_int()) {
color_ = cfg["color"].to_int() - 1;
color_id_ = color_options_[color_];
} else {
custom_color_ = cfg["color"].str();
const std::string custom_color = cfg["color"].str();

const auto iter = std::find(color_options_.begin(), color_options_.end(), custom_color_);
const auto iter = std::find(color_options_.begin(), color_options_.end(), custom_color);

if(iter != color_options_.end()) {
color_id_ = *iter;
color_ = iter - color_options_.begin();
} else {
color_options_.push_back(custom_color_);
color_options_.push_back(custom_color);

color_id_ = custom_color_;
color_id_ = custom_color;
color_ = color_options_.size() - 1;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/game_initialization/connect_engine.hpp
Expand Up @@ -268,10 +268,10 @@ class side_engine
flg_manager flg_;
const bool allow_changes_;
bool waiting_to_choose_faction_;
std::string custom_color_;
std::string color_id_;

std::vector<std::string> color_options_;

std::string color_id_;
};

} // end namespace ng
2 changes: 1 addition & 1 deletion src/gui/dialogs/multiplayer/mp_staging.cpp
Expand Up @@ -143,7 +143,7 @@ void mp_staging::add_side_node(window& window, ng::side_engine_ptr side)
data.emplace("side_number", item);

// TODO: don't hardcode magenta?
item["label"] = "units/unknown-unit.png~RC(magenta>" + std::to_string(side->color() + 1) + ")";
item["label"] = "units/unknown-unit.png~RC(magenta>" + side->color_id() + ")";
data.emplace("leader_image", item);

item["label"] = "icons/icon-random.png";
Expand Down

0 comments on commit 88e47a8

Please sign in to comment.