mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-20 16:05:19 +00:00
Merge team-coloring work into 1.2
This commit is contained in:
parent
9f59754d3f
commit
f979e2924b
@ -53,4 +53,10 @@ name= _ "Teal"
|
||||
[/team_color]
|
||||
|
||||
|
||||
[team_colors]
|
||||
magenta=244,154,193,63,0,22,85,0,42,105,0,57,123,0,69,140,0,81,158,0,93,177,0,105,195,0,116,214,0,127,236,0,140,238,61,150,239,91,161,241,114,172,242,135,182,246,173,205,248,193,217,250,213,229,253,233,241
|
||||
[/team_colors]
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -509,7 +509,7 @@ name=prestart
|
||||
# units can be color shifted by using the team color system
|
||||
|
||||
#define MAGENTA_IS_THE_TEAM_COLOR
|
||||
flag_rgb=244,154,193,63,0,22,85,0,42,105,0,57,123,0,69,140,0,81,158,0,93,177,0,105,195,0,116,214,0,127,236,0,140,238,61,150,239,91,161,241,114,172,242,135,182,246,173,205,248,193,217,250,213,229,253,233,241
|
||||
flag_rgb=magenta
|
||||
#enddef
|
||||
|
||||
|
||||
|
@ -71,7 +71,9 @@ namespace game_config
|
||||
|
||||
std::map<int, color_range > team_rgb_range;
|
||||
std::map<int, std::string > team_rgb_name;
|
||||
|
||||
|
||||
std::map<std::string, std::vector<Uint32> > team_rgb_colors;
|
||||
|
||||
namespace sounds {
|
||||
const std::string turn_bell = "bell.wav",
|
||||
receive_message = "receive.wav",
|
||||
@ -170,5 +172,22 @@ namespace game_config
|
||||
team_rgb_name[side] = (**teamC)["name"];
|
||||
}
|
||||
}
|
||||
|
||||
const config* rgbv = v.child("team_colors");
|
||||
if(rgbv) {
|
||||
for(string_map::const_iterator rgb_it = rgbv->values.begin(); rgb_it != rgbv->values.end(); ++rgb_it) {
|
||||
team_rgb_colors.insert(std::make_pair(rgb_it->first,string2rgb(rgb_it->second)));
|
||||
}
|
||||
}
|
||||
}
|
||||
const std::vector<Uint32>& tc_info(const std::string& name)
|
||||
{
|
||||
std::map<std::string, std::vector<Uint32> >::const_iterator i = team_rgb_colors.find(name);
|
||||
if(i == team_rgb_colors.end()) {
|
||||
static std::vector<Uint32> stv;
|
||||
//throw config::error("Unknown team color: " + name);
|
||||
return stv;
|
||||
}
|
||||
return i->second;
|
||||
}
|
||||
}
|
||||
|
@ -54,11 +54,14 @@ namespace game_config
|
||||
|
||||
extern std::map<int, color_range> team_rgb_range;
|
||||
extern std::map<int, std::string > team_rgb_name;
|
||||
|
||||
extern std::map<std::string, std::vector<Uint32> > team_rgb_colors;
|
||||
namespace sounds {
|
||||
extern const std::string turn_bell, receive_message, user_arrive, user_leave;
|
||||
}
|
||||
|
||||
|
||||
void load_config(const config* cfg);
|
||||
const std::vector<Uint32>& tc_info(const std::string& name);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include "image.hpp"
|
||||
#include "log.hpp"
|
||||
#include "sdl_utils.hpp"
|
||||
#include "team.hpp"
|
||||
#include "util.hpp"
|
||||
#include "wassert.hpp"
|
||||
#include "wesconfig.h"
|
||||
@ -118,6 +119,29 @@ void locator::init_index()
|
||||
index_ = i->second;
|
||||
}
|
||||
}
|
||||
void locator::get_tc_info()
|
||||
{
|
||||
std::string& fn(val_.filename_);
|
||||
if(fn.empty()) {
|
||||
return;
|
||||
}
|
||||
size_t open_field = fn.find('(');
|
||||
size_t close_field = fn.find(')');
|
||||
if(open_field == std::string::npos || close_field == std::string::npos) {
|
||||
return;
|
||||
}
|
||||
std::string field = fn.substr(open_field+1,close_field-open_field-1);
|
||||
fn = fn.substr(0,open_field);
|
||||
// field should be of the format "team,team_color_id"
|
||||
size_t comma = field.find(',');
|
||||
if(comma == std::string::npos) {
|
||||
return;
|
||||
}
|
||||
int team_n = lexical_cast_default<int>(field.substr(0,comma));
|
||||
std::string color_id = field.substr(comma+1);
|
||||
val_.new_color = team::get_side_color_range(team_n);
|
||||
val_.swap_colors = game_config::tc_info(color_id);
|
||||
}
|
||||
|
||||
locator::locator() :
|
||||
index_(-1)
|
||||
@ -133,27 +157,29 @@ locator::locator(const char *filename) :
|
||||
val_(filename)
|
||||
{
|
||||
init_index();
|
||||
get_tc_info();
|
||||
}
|
||||
|
||||
locator::locator(const std::string &filename) :
|
||||
val_(filename)
|
||||
{
|
||||
init_index();
|
||||
get_tc_info();
|
||||
}
|
||||
|
||||
locator::locator(const char *filename, color_range new_rgb, std::vector<Uint32> swap_rgb) :
|
||||
locator::locator(const char *filename, const color_range& new_rgb, const std::vector<Uint32>& swap_rgb) :
|
||||
val_(filename, new_rgb, swap_rgb)
|
||||
{
|
||||
init_index();
|
||||
}
|
||||
|
||||
locator::locator(const std::string &filename, color_range new_rgb, std::vector<Uint32> swap_rgb) :
|
||||
locator::locator(const std::string &filename, const color_range& new_rgb, const std::vector<Uint32>& swap_rgb) :
|
||||
val_(filename, new_rgb, swap_rgb)
|
||||
{
|
||||
init_index();
|
||||
}
|
||||
|
||||
locator::locator(const std::string &filename, const gamemap::location &loc, color_range new_rgb, std::vector<Uint32> swap_rgb) :
|
||||
locator::locator(const std::string &filename, const gamemap::location &loc, const color_range& new_rgb, const std::vector<Uint32>& swap_rgb) :
|
||||
val_(filename, loc, new_rgb, swap_rgb)
|
||||
{
|
||||
init_index();
|
||||
@ -183,7 +209,7 @@ locator::value::value(const char *filename) :
|
||||
}
|
||||
|
||||
|
||||
locator::value::value(const char *filename, color_range new_rgb, std::vector<Uint32> swap_rgb) :
|
||||
locator::value::value(const char *filename, const color_range& new_rgb, const std::vector<Uint32>& swap_rgb) :
|
||||
type_(SUB_FILE), filename_(filename), new_color(new_rgb), swap_colors(swap_rgb)
|
||||
{
|
||||
}
|
||||
@ -193,12 +219,12 @@ locator::value::value(const std::string& filename) :
|
||||
{
|
||||
}
|
||||
|
||||
locator::value::value(const std::string& filename, color_range new_rgb, std::vector<Uint32> swap_rgb) :
|
||||
locator::value::value(const std::string& filename, const color_range& new_rgb, const std::vector<Uint32>& swap_rgb) :
|
||||
type_(SUB_FILE), filename_(filename), new_color(new_rgb), swap_colors(swap_rgb)
|
||||
{
|
||||
}
|
||||
|
||||
locator::value::value(const std::string& filename, const gamemap::location& loc, color_range new_rgb, std::vector<Uint32> swap_rgb) :
|
||||
locator::value::value(const std::string& filename, const gamemap::location& loc, const color_range& new_rgb, const std::vector<Uint32>& swap_rgb) :
|
||||
type_(SUB_FILE), filename_(filename), loc_(loc), new_color(new_rgb), swap_colors(swap_rgb)
|
||||
{
|
||||
}
|
||||
@ -264,6 +290,10 @@ surface locator::load_image_file() const
|
||||
|
||||
if (res.null()) {
|
||||
ERR_DP << "could not open image '" << val_.filename_ << "'\n";
|
||||
} else {
|
||||
if(val_.swap_colors.size()){
|
||||
res=recolor_image(res,get_new_color(),get_swap_colors());
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
|
@ -47,6 +47,7 @@ namespace image {
|
||||
// Called by each constructor after actual construction to
|
||||
// initialize the index_ field
|
||||
void init_index();
|
||||
void get_tc_info();
|
||||
public:
|
||||
enum type { NONE, FILE, SUB_FILE };
|
||||
|
||||
@ -54,10 +55,10 @@ namespace image {
|
||||
value();
|
||||
value(const value &a);
|
||||
value(const char *filename);
|
||||
value(const char *filename, color_range new_rgb, std::vector<Uint32> swap_rgb);
|
||||
value(const char *filename, const color_range& new_rgb, const std::vector<Uint32>& swap_rgb);
|
||||
value(const std::string& filename);
|
||||
value(const std::string& filename, color_range new_rgb, std::vector<Uint32> swap_rgb);
|
||||
value(const std::string& filename, const gamemap::location& loc, color_range new_rgb, std::vector<Uint32> swap_rgb);
|
||||
value(const std::string& filename, const color_range& new_rgb, const std::vector<Uint32>& swap_rgb);
|
||||
value(const std::string& filename, const gamemap::location& loc, const color_range& new_rgb, const std::vector<Uint32>& swap_rgb);
|
||||
|
||||
bool operator==(const value& a) const;
|
||||
bool operator<(const value& a) const;
|
||||
@ -76,10 +77,10 @@ namespace image {
|
||||
locator();
|
||||
locator(const locator &a);
|
||||
locator(const char *filename);
|
||||
locator(const char *filename, color_range new_rgb, std::vector<Uint32> swap_rgb);
|
||||
locator(const char *filename, const color_range& new_rgb, const std::vector<Uint32>& swap_rgb);
|
||||
locator(const std::string& filename);
|
||||
locator(const std::string& filename, color_range new_rgb, std::vector<Uint32> swap_rgb);
|
||||
locator(const std::string& filename, const gamemap::location& loc, color_range new_rgb = std::vector<Uint32>(), std::vector<Uint32> swap_rgb = std::vector<Uint32>());
|
||||
locator(const std::string& filename, const color_range& new_rgb, const std::vector<Uint32>& swap_rgb);
|
||||
locator(const std::string& filename, const gamemap::location& loc, const color_range& new_rgb = std::vector<Uint32>(), const std::vector<Uint32>& swap_rgb = std::vector<Uint32>());
|
||||
|
||||
locator& operator=(const locator &a);
|
||||
bool operator==(const locator &a) const { return index_ == a.index_; }
|
||||
|
@ -180,23 +180,23 @@ namespace events{
|
||||
|
||||
switch(res) {
|
||||
case 0:
|
||||
items_sub = create_unit_table(stats.recruits);
|
||||
items_sub = create_unit_table(stats.recruits,gui_->viewing_team()+1);
|
||||
title = _("Recruits");
|
||||
break;
|
||||
case 1:
|
||||
items_sub = create_unit_table(stats.recalls);
|
||||
items_sub = create_unit_table(stats.recalls,gui_->viewing_team()+1);
|
||||
title = _("Recalls");
|
||||
break;
|
||||
case 2:
|
||||
items_sub = create_unit_table(stats.advanced_to);
|
||||
items_sub = create_unit_table(stats.advanced_to,gui_->viewing_team()+1);
|
||||
title = _("Advancements");
|
||||
break;
|
||||
case 3:
|
||||
items_sub = create_unit_table(stats.deaths);
|
||||
items_sub = create_unit_table(stats.deaths,gui_->viewing_team()+1);
|
||||
title = _("Losses");
|
||||
break;
|
||||
case 4:
|
||||
items_sub = create_unit_table(stats.killed);
|
||||
items_sub = create_unit_table(stats.killed,gui_->viewing_team()+1); // FIXME? Perhaps killed units shouldn't have the same team-color as your own.
|
||||
title = _("Kills");
|
||||
break;
|
||||
default:
|
||||
@ -208,7 +208,7 @@ namespace events{
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::string> menu_handler::create_unit_table(const statistics::stats::str_int_map& m)
|
||||
std::vector<std::string> menu_handler::create_unit_table(const statistics::stats::str_int_map& m,unsigned int team)
|
||||
{
|
||||
std::vector<std::string> table;
|
||||
for(statistics::stats::str_int_map::const_iterator i = m.begin(); i != m.end(); ++i) {
|
||||
@ -218,7 +218,7 @@ namespace events{
|
||||
}
|
||||
|
||||
std::stringstream str;
|
||||
str << IMAGE_PREFIX << type->second.image() << COLUMN_SEPARATOR
|
||||
str << IMAGE_PREFIX << type->second.image() << "(" << team << "," << type->second.flag_rgb() << ")" << COLUMN_SEPARATOR
|
||||
<< type->second.language_name() << COLUMN_SEPARATOR << i->second << "\n";
|
||||
table.push_back(str.str());
|
||||
}
|
||||
@ -337,7 +337,7 @@ namespace events{
|
||||
//output the number of the side first, and this will
|
||||
//cause it to be displayed in the correct colour
|
||||
if(leader != units_.end()) {
|
||||
str << IMAGE_PREFIX << leader->second.absolute_image() << COLUMN_SEPARATOR
|
||||
str << IMAGE_PREFIX << leader->second.absolute_image() << "(" << (n+1) << "," << leader->second.team_color() << ")" << COLUMN_SEPARATOR
|
||||
<< "\033[3" << lexical_cast<char, size_t>(n+1) << 'm' << leader->second.description() << COLUMN_SEPARATOR;
|
||||
} else {
|
||||
str << ' ' << COLUMN_SEPARATOR << "\033[3" << lexical_cast<char, size_t>(n+1) << "m-" << COLUMN_SEPARATOR;
|
||||
@ -563,7 +563,7 @@ namespace events{
|
||||
|
||||
std::stringstream description;
|
||||
|
||||
description << font::IMAGE << type.image() << COLUMN_SEPARATOR << font::LARGE_TEXT
|
||||
description << font::IMAGE << type.image() << "(" << team_num << "," << type.flag_rgb() << ")" << COLUMN_SEPARATOR << font::LARGE_TEXT
|
||||
<< prefix << type.language_name() << "\n"
|
||||
<< prefix << type.cost() << " " << sgettext("unit^Gold");
|
||||
items.push_back(description.str());
|
||||
@ -698,7 +698,7 @@ namespace events{
|
||||
for(std::vector<unit>::const_iterator u = recall_list.begin(); u != recall_list.end(); ++u) {
|
||||
std::stringstream option;
|
||||
const std::string& description = u->description().empty() ? "-" : u->description();
|
||||
option << IMAGE_PREFIX << u->absolute_image() << COLUMN_SEPARATOR
|
||||
option << IMAGE_PREFIX << u->absolute_image() << "(" << team_num << "," << u->team_color() << ")" << COLUMN_SEPARATOR
|
||||
<< u->language_name() << COLUMN_SEPARATOR
|
||||
<< description << COLUMN_SEPARATOR
|
||||
<< u->level() << COLUMN_SEPARATOR
|
||||
|
@ -116,7 +116,7 @@ protected:
|
||||
private:
|
||||
//void do_speak(const std::string& message, bool allies_only);
|
||||
void do_recruit(const std::string& name, const unsigned int team_num, const gamemap::location& last_hex);
|
||||
std::vector<std::string> create_unit_table(const statistics::stats::str_int_map& m);
|
||||
std::vector<std::string> create_unit_table(const statistics::stats::str_int_map& m,unsigned int team);
|
||||
void write_game_snapshot(config& start) const;
|
||||
bool has_friends() const;
|
||||
bool clear_shroud(const unsigned int team_num);
|
||||
|
21
src/unit.cpp
21
src/unit.cpp
@ -621,7 +621,7 @@ Uint32 unit::team_rgb() const
|
||||
}
|
||||
const std::vector<Uint32>& unit::flag_rgb() const
|
||||
{
|
||||
return flag_rgb_;
|
||||
return game_config::tc_info(flag_rgb_);
|
||||
}
|
||||
std::vector<Uint32> unit::team_rgb_range() const
|
||||
{
|
||||
@ -631,6 +631,10 @@ std::vector<Uint32> unit::team_rgb_range() const
|
||||
temp.push_back(team::get_side_rgb_min(side()));
|
||||
return(temp);
|
||||
}
|
||||
const std::string& unit::team_color() const
|
||||
{
|
||||
return flag_rgb_;
|
||||
}
|
||||
unit_race::GENDER unit::gender() const
|
||||
{
|
||||
return gender_;
|
||||
@ -1061,7 +1065,7 @@ void unit::read(const config& cfg)
|
||||
language_name_ = cfg["language_name"];
|
||||
undead_variation_ = cfg["undead_variation"];
|
||||
|
||||
flag_rgb_ = string2rgb(cfg["flag_rgb"]);
|
||||
flag_rgb_ = cfg["flag_rgb"];
|
||||
alpha_ = lexical_cast_default<fixed_t>(cfg["alpha"]);
|
||||
|
||||
level_ = lexical_cast_default<int>(cfg["level"]);
|
||||
@ -1363,18 +1367,7 @@ void unit::write(config& cfg) const
|
||||
default:
|
||||
cfg["alignment"] = "neutral";
|
||||
}
|
||||
std::stringstream flg_rgb;
|
||||
for(std::vector<Uint32>::const_iterator j = flag_rgb_.begin(); j != flag_rgb_.end(); ++j) {
|
||||
flg_rgb << (((*j)&0xFF0000)>>16);
|
||||
flg_rgb << ",";
|
||||
flg_rgb << (((*j)&0xFF00)>>8);
|
||||
flg_rgb << ",";
|
||||
flg_rgb << (((*j)&0xFF));
|
||||
if(j+1 != flag_rgb_.end()) {
|
||||
flg_rgb << ",";
|
||||
}
|
||||
}
|
||||
cfg["flag_rgb"] = flg_rgb.str();
|
||||
cfg["flag_rgb"] = flag_rgb_;
|
||||
cfg["unrenamable"] = unrenamable_ ? "yes" : "no";
|
||||
cfg["alpha"] = lexical_cast_default<std::string>(alpha_);
|
||||
|
||||
|
@ -98,6 +98,7 @@ class unit
|
||||
Uint32 team_rgb() const;
|
||||
std::vector<Uint32> team_rgb_range() const;
|
||||
const std::vector<Uint32>& flag_rgb() const;
|
||||
const std::string& team_color() const;
|
||||
unit_race::GENDER gender() const;
|
||||
void set_side(unsigned int new_side);
|
||||
fixed_t alpha() const;
|
||||
@ -299,7 +300,7 @@ class unit
|
||||
int max_experience_, max_experience_b_;
|
||||
int level_;
|
||||
unit_type::ALIGNMENT alignment_;
|
||||
std::vector<Uint32> flag_rgb_;
|
||||
std::string flag_rgb_;
|
||||
|
||||
bool unrenamable_;
|
||||
unsigned int side_;
|
||||
|
@ -863,7 +863,7 @@ unit_type::unit_type(const config& cfg, const movement_type_map& mv_types,
|
||||
healing_animations_.push_back(healing_animation(cfg["image_healing"],cfg["image_halo_healing"]));
|
||||
// always have a healing animation
|
||||
}
|
||||
flag_rgb_ = string2rgb(cfg["flag_rgb"]);
|
||||
flag_rgb_ = cfg["flag_rgb"];
|
||||
// deprecation messages, only seen when unit is parsed for the first time
|
||||
}
|
||||
|
||||
@ -1192,7 +1192,7 @@ void unit_type::add_advancement(const unit_type &to_unit,int xp)
|
||||
}
|
||||
}
|
||||
|
||||
const std::vector<Uint32>& unit_type::flag_rgb() const
|
||||
const std::string& unit_type::flag_rgb() const
|
||||
{
|
||||
return flag_rgb_;
|
||||
}
|
||||
|
@ -190,7 +190,7 @@ public:
|
||||
const std::string& image_profile() const;
|
||||
const t_string& unit_description() const;
|
||||
|
||||
const std::vector<Uint32>& flag_rgb() const;
|
||||
const std::string& flag_rgb() const;
|
||||
|
||||
int hitpoints() const;
|
||||
std::vector<attack_type> attacks() const;
|
||||
@ -288,7 +288,7 @@ private:
|
||||
std::vector<leading_animation> leading_animations_;
|
||||
|
||||
std::vector<healing_animation> healing_animations_;
|
||||
std::vector<Uint32> flag_rgb_;
|
||||
std::string flag_rgb_;
|
||||
};
|
||||
|
||||
struct game_data
|
||||
|
Loading…
x
Reference in New Issue
Block a user