[[Fixes for LOW_MEM behavior]]

This commit is contained in:
John W. C. McNabb 2006-11-12 18:38:34 +00:00
parent 4cb8110359
commit 28b06edc9d
26 changed files with 347 additions and 259 deletions

View file

@ -41,6 +41,7 @@ Version 1.3-svn:
* show leader's name and colour at status table even when that team is fogged
(patch #605)
* WML engine
* overhaul of team coloring engine. Now possible to apply multiple TC to an image.
* added fourth color in team_rgb definitions for representative color in minimap
* added a 'hide_help' key that prevents a unit type from being listed in the
in-game help (bug #5701)

View file

@ -107,6 +107,12 @@ name=moveto
stone=on
[/status]
[/unit]
[unit]
x,y=4,9
type="Thief"
generate_description=yes
[/unit]
[/side]
[side]
@ -124,6 +130,12 @@ name=moveto
type="Orcish Archer"
generate_description=yes
[/unit]
[unit]
x,y=10,7
type="Orcish Archer"
generate_description=yes
[/unit]
[/side]
[item]
@ -212,16 +224,11 @@ name=moveto
x="0-38"
y="0-20"
[/remove_shroud]
[message]
speaker=narrator
image=units/elves-wood/captain.png~TC(3,magenta)
message=_ "Now I am on the green team."
[/message]
[/event]
[item]
x,y=12,6
image="items/orcish-flag.png"
image="terrain/color-hex.png~TC(red>4)~TC(blue>5)"
[/item]
[label]
x,y=12,6
@ -238,9 +245,16 @@ name=moveto
[/filter]
[message]
speaker=narrator
image=units/elves-wood/captain.png~TC(3,magenta)
message=_ "Now I am on the green team."
image=units/elves-wood/captain.png~TC(magenta>3)
message=_ "Now you can spy on the green team.
Does not work yet."
[/message]
[effect]
apply_to=image
[image_mod]
type=TC(magenta>3)
[/image_mod]
[/effect]
[/event]
[item]

View file

@ -1,42 +1,42 @@
[color_range]
id=1
team_rgb=255,0,0,255,255,255,0,0,0,255,0,0
rgb=255,0,0,255,255,255,0,0,0,255,0,0
name= _ "Red"
[/color_range]
[color_range]
id=2
team_rgb=46,65,155,255,255,255,15,15,15,0,0,255
rgb=46,65,155,255,255,255,15,15,15,0,0,255
name= _ "Blue"
[/color_range]
[color_range]
id=3
team_rgb=98,182,100,255,255,255,0,0,0,0,255,0
rgb=98,182,100,255,255,255,0,0,0,0,255,0
name= _ "Green"
[/color_range]
[color_range]
id=4
team_rgb=147,0,157,255,255,255,0,0,0,255,0,255
rgb=147,0,157,255,255,255,0,0,0,255,0,255
name= _ "Purple"
[/color_range]
[color_range]
id=7
team_rgb=240,114,0,240,240,240,0,0,0,255,170,0
rgb=240,114,0,240,240,240,0,0,0,255,170,0
name= _ "Orange"
[/color_range]
[color_range]
id=5
team_rgb=90,90,90,255,255,255,0,0,0,0,0,0
rgb=90,90,90,255,255,255,0,0,0,0,0,0
name= _ "Black"
[/color_range]
[color_range]
id=8
team_rgb=225,225,225,255,255,255,30,30,30,255,255,255
rgb=225,225,225,255,255,255,30,30,30,255,255,255
name= _ "White"
[/color_range]
@ -48,14 +48,15 @@ name= _ "Brown"
[color_range]
id=9
team_rgb=48,203,192,255,255,255,0,0,0,0,240,200
rgb=48,203,192,255,255,255,0,0,0,0,240,200
name= _ "Teal"
[/color_range]
[color_palette]
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
green=0,200,0,0,255,0,0,254,0,0,253,0,0,252,0,0,251,0,0,250,0,0,249,0,0,248,0,0,247,0,0,246,0,0,245,0,0,244,0,0,243,0,0,242,0,0,241,0,0,240,0,0,239,0,0,238,0,0,237,0,0,236,0,0,235,0,0,234,0,0,233,0,0,232,0,0,231,0,0,230,0,0,229,0,0,228,0,0,227,0,0,226,0,0,225,0,0,224,0,0,223,0,0,222,0,0,221,0,0,220,0,0,219,0,0,218,0,0,217,0,0,216,0,0,215,0,0,214,0,0,213,0,0,212,0,0,211,0,0,210,0,0,209,0,0,208,0,0,207,0,0,206,0,0,205,0,0,204,0,0,203,0,0,202,0,0,201,0,0,199,0,0,198,0,0,197,0,0,196,0,0,195,0,0,194,0,0,193,0,0,192,0,0,191,0,0,190,0,0,189,0,0,188,0,0,187,0,0,186,0,0,185,0,0,184,0,0,183,0,0,182,0,0,181,0,0,180,0,0,179,0,0,178,0,0,177,0,0,176,0,0,175,0,0,174,0,0,173,0,0,172,0,0,171,0,0,170,0,0,169,0,0,168,0,0,167,0,0,166,0,0,165,0,0,164,0,0,163,0,0,162,0,0,161,0,0,160,0,0,159,0,0,158,0,0,157,0,0,156,0,0,155,0,0,154,0,0,153,0,0,152,0,0,151,0,0,150,0,0,149,0,0,148,0,0,147,0,0,146,0,0,145,0,0,144,0,0,143,0,0,142,0,0,141,0,0,140,0,0,139,0,0,138,0,0,137,0,0,136,0,0,135,0,0,134,0,0,133,0,0,132,0,0,131,0,0,130,0,0,129,0,0,128,0,0,127,0,0,126,0,0,125,0,0,124,0,0,123,0,0,122,0,0,121,0,0,120,0,0,119,0,0,118,0,0,117,0,0,116,0,0,115,0,0,114,0,0,113,0,0,112,0,0,111,0,0,110,0,0,109,0,0,108,0,0,107,0,0,106,0,0,105,0,0,104,0,0,103,0,0,102,0,0,101,0,0,100,0,0,99,0,0,98,0,0,97,0,0,96,0,0,95,0,0,94,0,0,93,0,0,92,0,0,91,0,0,90,0,0,89,0,0,88,0,0,87,0,0,86,0,0,85,0,0,84,0,0,83,0,0,82,0,0,81,0,0,80,0,0,79,0,0,78,0,0,77,0,0,76,0,0,75,0,0,74,0,0,73,0,0,72,0,0,71,0,0,70,0,0,69,0,0,68,0,0,67,0,0,66,0,0,65,0,0,64,0,0,63,0,0,62,0,0,61,0,0,60,0,0,59,0,0,58,0,0,57,0,0,56,0,0,55,0,0,54,0,0,53,0,0,52,0,0,51,0,0,50,0,0,49,0,0,48,0,0,47,0,0,46,0,0,45,0,0,44,0,0,43,0,0,42,0,0,41,0,0,40,0,0,39,0,0,38,0,0,37,0,0,36,0,0,35,0,0,34,0,0,33,0,0,32,0,0,31,0,0,30,0,0,29,0,0,28,0,0,27,0,0,26,0,0,25,0,0,24,0,0,23,0,0,22,0,0,21,0,0,20,0,0,19,0,0,18,0,0,17,0,0,16,0,0,15,0,0,14,0,0,13,0,0,12,0,0,11,0,0,10,0,0,9,0,0,8,0,0,7,0,0,6,0,0,5,0,0,4,0,0,3,0,0,2,0,0,1,0
red=200,0,0,255,0,0,254,0,0,253,0,0,252,0,0,251,0,0,250,0,0,249,0,0,248,0,0,247,0,0,246,0,0,245,0,0,244,0,0,243,0,0,242,0,0,241,0,0,240,0,0,239,0,0,238,0,0,237,0,0,236,0,0,235,0,0,234,0,0,233,0,0,232,0,0,231,0,0,230,0,0,229,0,0,228,0,0,227,0,0,226,0,0,225,0,0,224,0,0,223,0,0,222,0,0,221,0,0,220,0,0,219,0,0,218,0,0,217,0,0,216,0,0,215,0,0,214,0,0,213,0,0,212,0,0,211,0,0,210,0,0,209,0,0,208,0,0,207,0,0,206,0,0,205,0,0,204,0,0,203,0,0,202,0,0,201,0,0,199,0,0,198,0,0,197,0,0,196,0,0,195,0,0,194,0,0,193,0,0,192,0,0,191,0,0,190,0,0,189,0,0,188,0,0,187,0,0,186,0,0,185,0,0,184,0,0,183,0,0,182,0,0,181,0,0,180,0,0,179,0,0,178,0,0,177,0,0,176,0,0,175,0,0,174,0,0,173,0,0,172,0,0,171,0,0,170,0,0,169,0,0,168,0,0,167,0,0,166,0,0,165,0,0,164,0,0,163,0,0,162,0,0,161,0,0,160,0,0,159,0,0,158,0,0,157,0,0,156,0,0,155,0,0,154,0,0,153,0,0,152,0,0,151,0,0,150,0,0,149,0,0,148,0,0,147,0,0,146,0,0,145,0,0,144,0,0,143,0,0,142,0,0,141,0,0,140,0,0,139,0,0,138,0,0,137,0,0,136,0,0,135,0,0,134,0,0,133,0,0,132,0,0,131,0,0,130,0,0,129,0,0,128,0,0,127,0,0,126,0,0,125,0,0,124,0,0,123,0,0,122,0,0,121,0,0,120,0,0,119,0,0,118,0,0,117,0,0,116,0,0,115,0,0,114,0,0,113,0,0,112,0,0,111,0,0,110,0,0,109,0,0,108,0,0,107,0,0,106,0,0,105,0,0,104,0,0,103,0,0,102,0,0,101,0,0,100,0,0,99,0,0,98,0,0,97,0,0,96,0,0,95,0,0,94,0,0,93,0,0,92,0,0,91,0,0,90,0,0,89,0,0,88,0,0,87,0,0,86,0,0,85,0,0,84,0,0,83,0,0,82,0,0,81,0,0,80,0,0,79,0,0,78,0,0,77,0,0,76,0,0,75,0,0,74,0,0,73,0,0,72,0,0,71,0,0,70,0,0,69,0,0,68,0,0,67,0,0,66,0,0,65,0,0,64,0,0,63,0,0,62,0,0,61,0,0,60,0,0,59,0,0,58,0,0,57,0,0,56,0,0,55,0,0,54,0,0,53,0,0,52,0,0,51,0,0,50,0,0,49,0,0,48,0,0,47,0,0,46,0,0,45,0,0,44,0,0,43,0,0,42,0,0,41,0,0,40,0,0,39,0,0,38,0,0,37,0,0,36,0,0,35,0,0,34,0,0,33,0,0,32,0,0,31,0,0,30,0,0,29,0,0,28,0,0,27,0,0,26,0,0,25,0,0,24,0,0,23,0,0,22,0,0,21,0,0,20,0,0,19,0,0,18,0,0,17,0,0,16,0,0,15,0,0,14,0,0,13,0,0,12,0,0,11,0,0,10,0,0,9,0,0,8,0,0,7,0,0,6,0,0,5,0,0,4,0,0,3,0,0,2,0,0,1,0,0
blue=0,0,200,0,0,255,0,0,254,0,0,253,0,0,252,0,0,251,0,0,250,0,0,249,0,0,248,0,0,247,0,0,246,0,0,245,0,0,244,0,0,243,0,0,242,0,0,241,0,0,240,0,0,239,0,0,238,0,0,237,0,0,236,0,0,235,0,0,234,0,0,233,0,0,232,0,0,231,0,0,230,0,0,229,0,0,228,0,0,227,0,0,226,0,0,225,0,0,224,0,0,223,0,0,222,0,0,221,0,0,220,0,0,219,0,0,218,0,0,217,0,0,216,0,0,215,0,0,214,0,0,213,0,0,212,0,0,211,0,0,210,0,0,209,0,0,208,0,0,207,0,0,206,0,0,205,0,0,204,0,0,203,0,0,202,0,0,201,0,0,199,0,0,198,0,0,197,0,0,196,0,0,195,0,0,194,0,0,193,0,0,192,0,0,191,0,0,190,0,0,189,0,0,188,0,0,187,0,0,186,0,0,185,0,0,184,0,0,183,0,0,182,0,0,181,0,0,180,0,0,179,0,0,178,0,0,177,0,0,176,0,0,175,0,0,174,0,0,173,0,0,172,0,0,171,0,0,170,0,0,169,0,0,168,0,0,167,0,0,166,0,0,165,0,0,164,0,0,163,0,0,162,0,0,161,0,0,160,0,0,159,0,0,158,0,0,157,0,0,156,0,0,155,0,0,154,0,0,153,0,0,152,0,0,151,0,0,150,0,0,149,0,0,148,0,0,147,0,0,146,0,0,145,0,0,144,0,0,143,0,0,142,0,0,141,0,0,140,0,0,139,0,0,138,0,0,137,0,0,136,0,0,135,0,0,134,0,0,133,0,0,132,0,0,131,0,0,130,0,0,129,0,0,128,0,0,127,0,0,126,0,0,125,0,0,124,0,0,123,0,0,122,0,0,121,0,0,120,0,0,119,0,0,118,0,0,117,0,0,116,0,0,115,0,0,114,0,0,113,0,0,112,0,0,111,0,0,110,0,0,109,0,0,108,0,0,107,0,0,106,0,0,105,0,0,104,0,0,103,0,0,102,0,0,101,0,0,100,0,0,99,0,0,98,0,0,97,0,0,96,0,0,95,0,0,94,0,0,93,0,0,92,0,0,91,0,0,90,0,0,89,0,0,88,0,0,87,0,0,86,0,0,85,0,0,84,0,0,83,0,0,82,0,0,81,0,0,80,0,0,79,0,0,78,0,0,77,0,0,76,0,0,75,0,0,74,0,0,73,0,0,72,0,0,71,0,0,70,0,0,69,0,0,68,0,0,67,0,0,66,0,0,65,0,0,64,0,0,63,0,0,62,0,0,61,0,0,60,0,0,59,0,0,58,0,0,57,0,0,56,0,0,55,0,0,54,0,0,53,0,0,52,0,0,51,0,0,50,0,0,49,0,0,48,0,0,47,0,0,46,0,0,45,0,0,44,0,0,43,0,0,42,0,0,41,0,0,40,0,0,39,0,0,38,0,0,37,0,0,36,0,0,35,0,0,34,0,0,33,0,0,32,0,0,31,0,0,30,0,0,29,0,0,28,0,0,27,0,0,26,0,0,25,0,0,24,0,0,23,0,0,22,0,0,21,0,0,20,0,0,19,0,0,18,0,0,17,0,0,16,0,0,15,0,0,14,0,0,13,0,0,12,0,0,11,0,0,10,0,0,9,0,0,8,0,0,7,0,0,6,0,0,5,0,0,4,0,0,3,0,0,2,0,0,1,
[/color_palette]

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

View file

@ -14,10 +14,11 @@
#include "global.hpp"
#include "color_range.hpp"
#include "serialization/string_utils.hpp"
#include "sdl_utils.hpp"
#include <string>
#include <vector>
#include <set>
std::vector<Uint32> string2rgb(std::string s){
std::vector<Uint32> out;
@ -41,3 +42,31 @@ std::vector<Uint32> string2rgb(std::string s){
}
return(out);
}
std::vector<Uint32> palette(color_range cr){
//generate a color palette from a color range
std::vector<Uint32> temp,res;
std::set<Uint32> clist;
//use blue to make master set of possible colors
for(int i=255;i!=0;i--){
int j=255-i;
Uint32 rgb = i;
temp.push_back(rgb);
rgb = (j << 16) + (j << 8) + 255;
temp.push_back(rgb);
}
//use recolor function to generate list of possible colors.
//could use a special function, would be more efficient, but
//harder to maintain.
std::map<Uint32,Uint32> cmap = recolor_range(cr,temp);
for(std::map<Uint32,Uint32>::const_iterator k=cmap.begin(); k!=cmap.end();k++){
clist.insert(k->second);
}
res.push_back(cmap[255]);
for(std::set<Uint32>::const_iterator c=clist.begin();c!=clist.end();c++){
if(*c != res[0] && *c!=0 && *c != 0x00FFFFFF){
res.push_back(*c);}
}
return(res);
}

View file

@ -20,7 +20,7 @@
//convert comma separated string into rgb values
std::vector<Uint32> string2rgb(std::string s);
class color_range
{
public:
@ -51,5 +51,6 @@ public:
private:
Uint32 mid_ , max_ , min_ , rep_;
};
std::vector<Uint32> palette(color_range cr); //return color palette from color range
#endif

View file

@ -75,7 +75,7 @@ void advance_unit(const game_data& info,
#ifdef LOW_MEM
lang_options.push_back(IMAGE_PREFIX + type.absolute_image() + COLUMN_SEPARATOR + type.language_name());
#else
lang_options.push_back(IMAGE_PREFIX + type.absolute_image() + "~TC(" + lexical_cast_default<std::string>(u->second.side()) + "," + type.team_color() + ")" + COLUMN_SEPARATOR + type.language_name());
lang_options.push_back(IMAGE_PREFIX + type.absolute_image() + u->second.image_mods() + COLUMN_SEPARATOR + type.language_name());
#endif
preferences::encountered_units().insert(*op);
}
@ -92,7 +92,7 @@ void advance_unit(const game_data& info,
#ifdef LOW_MEM
lang_options.push_back(IMAGE_PREFIX + type.absolute_image() + COLUMN_SEPARATOR + (**mod)["description"].str());
#else
lang_options.push_back(IMAGE_PREFIX + type.absolute_image() + "~TC(" + lexical_cast_default<std::string>(u->second.side()) + "," + type.team_color() + ")" + COLUMN_SEPARATOR + (**mod)["description"].str());
lang_options.push_back(IMAGE_PREFIX + type.absolute_image() + u->second.image_mods() + COLUMN_SEPARATOR + (**mod)["description"].str());
#endif
}
}
@ -339,7 +339,7 @@ void save_preview_pane::draw_contents()
#ifdef LOW_MEM
const surface image(image::get_image(leader->second.image(),image::UNSCALED));
#else
const surface image(image::get_image(leader->second.image() + "~TC(1," + leader->second.flag_rgb() + ")",image::UNSCALED));
const surface image(image::get_image(leader->second.image() + "~TC(" + leader->second.flag_rgb() + ">1)",image::UNSCALED));
#endif
if(image != NULL) {

View file

@ -103,13 +103,13 @@ display::display(unit_map& units, CVideo& video, const gamemap& map,
flags_.reserve(teams_.size());
for(size_t i = 0; i != teams_.size(); ++i) {
std::string flag;
color_range new_rgb;
std::vector<Uint32> old_rgb;
std::string new_rgb;
std::string old_rgb;
if(teams_[i].flag().empty()) {
flag = game_config::flag_image;
old_rgb = game_config::flag_rgb;
new_rgb = team::get_side_color_range(i+1);
new_rgb = team::get_side_colour_index(i+1);
} else {
flag = teams_[i].flag();
}
@ -133,8 +133,9 @@ display::display(unit_map& units, CVideo& video, const gamemap& map,
str = *itor;
time = 100;
}
image::locator flag_image(str, new_rgb, old_rgb);
std::stringstream temp;
temp << str << "~TC(" << old_rgb << ">"<< new_rgb << ")";
image::locator flag_image(temp.str());
temp_anim.add_frame(time, flag_image);
}
flags_.push_back(temp_anim);
@ -1043,7 +1044,7 @@ void display::draw_report(reports::TYPE report_num)
reports::report report = reports::generate_report(report_num,map_,
units_, teams_,
teams_[viewing_team()],
currentTeam_+1,activeTeam_+1,
size_t(currentTeam_+1),size_t(activeTeam_+1),
selectedHex_,mouseoverHex_,status_,observers_);
SDL_Rect& rect = reportRects_[report_num];

View file

@ -14,12 +14,15 @@
#include "global.hpp"
#include "config.hpp"
#include "log.hpp"
#include "gettext.hpp"
#include "game_config.hpp"
#include "wesconfig.h"
#include "serialization/string_utils.hpp"
#include <cstdlib>
#include <sstream>
#define LOG_NG LOG_STREAM(info, engine)
namespace game_config
{
@ -53,7 +56,7 @@ namespace game_config
std::string enemy_ball_image = "misc/ball-enemy.png";
std::string ally_ball_image = "misc/ball-ally.png";
std::string flag_image = "terrain/flag-1.png:150,terrain/flag-2.png:150";
std::vector<Uint32> flag_rgb;
std::string flag_rgb;
std::string dot_image = "misc/dot.png";
std::string cross_image = "misc/cross.png";
@ -70,8 +73,8 @@ namespace game_config
std::string level_image;
std::string ellipsis_image;
std::map<int, color_range > team_rgb_range;
std::map<int, std::string > team_rgb_name;
std::map<std::string, color_range > team_rgb_range;
std::map<std::string, std::string > team_rgb_name;
std::map<std::string, std::vector<Uint32> > team_rgb_colors;
@ -164,32 +167,51 @@ namespace game_config
const config::child_list& team_colors = v.get_children("color_range");
for(config::child_list::const_iterator teamC = team_colors.begin(); teamC != team_colors.end(); ++teamC) {
if(!(**teamC)["id"].empty() && !(**teamC)["team_rgb"].empty()){
int side = atoi((**teamC)["id"].c_str());
std::vector<Uint32> temp = string2rgb((**teamC)["team_rgb"]);
team_rgb_range[side] = color_range(temp);
team_rgb_name[side] = (**teamC)["name"];
}
if(!(**teamC)["id"].empty() && !(**teamC)["rgb"].empty()){
std::string id = (**teamC)["id"];
std::vector<Uint32> temp = string2rgb((**teamC)["rgb"]);
team_rgb_range[id] = color_range(temp);
team_rgb_name[id] = (**teamC)["name"];
//generate palette of same name;
std::vector<Uint32> tp = palette(team_rgb_range[id]);
if(tp.size()){
team_rgb_colors[id]=tp;
//if this is being used, output log of palette for artists use.
LOG_NG << "color palette creation:\n";
std::stringstream str;
str << id <<" = ";
for(std::vector<Uint32>::const_iterator r=tp.begin();r!=tp.end();r++){
int red = ((*r) & 0x00FF0000)>>16;
int green = ((*r) & 0x0000FF00)>>8;
int blue = ((*r) & 0x000000FF);
if(r!=tp.begin()) {
str<<",";
}
str << red << "," << green << "," << blue;
}
LOG_NG << str.str() <<"\n";
}
}
}
const config* rgbv = v.child("color_palette");
if(rgbv) {
for(string_map::const_iterator rgb_it = rgbv->values.begin(); rgb_it != rgbv->values.end(); ++rgb_it) {
try {
team_rgb_colors.insert(std::make_pair(rgb_it->first,string2rgb(rgb_it->second)));
// team_rgb_colors.insert(std::make_pair(rgb_it->first,string2rgb(rgb_it->second)));
//should new colors overwrite old colors?
team_rgb_colors[rgb_it->first]=string2rgb(rgb_it->second);
} catch(bad_lexical_cast&) {
//throw config::error(_("Invalid team color: ") + rgb_it->second);
}
}
}
flag_rgb = tc_info(v["flag_rgb"]);
flag_rgb = v["flag_rgb"];
if( !flag_rgb.size()){
//set green as old_flag_color
for(int i=255;i>0;i--){
flag_rgb.push_back((Uint32)(i<<8));
}
flag_rgb="green";
}
}
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);

View file

@ -46,14 +46,14 @@ namespace game_config
terrain_mask_image, observer_image, download_campaign_image,
checked_menu_image, unchecked_menu_image, level_image,ellipsis_image;
extern std::vector<Uint32> flag_rgb;
extern std::string flag_rgb;
extern std::vector<std::string> foot_left_nw,foot_left_n,foot_right_nw,foot_right_n;
extern int title_logo_x, title_logo_y, title_buttons_x, title_buttons_y, title_buttons_padding, title_tip_x, title_tip_y, title_tip_width, title_tip_padding;
extern std::map<int, color_range> team_rgb_range;
extern std::map<int, std::string > team_rgb_name;
extern std::map<std::string, color_range> team_rgb_range;
extern std::map<std::string, std::string> team_rgb_name;
extern std::map<std::string, std::vector<Uint32> > team_rgb_colors;
namespace sounds {

View file

@ -1436,9 +1436,7 @@ bool event_handler::handle_event_command(const queued_event& event_info,
#ifdef LOW_MEM
ss << image;
#else
ss << image << "~TC("
<< speaker->second.side() << ","
<< speaker->second.team_color() << ")";
ss << image << speaker->second.image_mods();
#endif
image = ss.str();

View file

@ -1090,14 +1090,14 @@ public:
#ifdef LOW_MEM
ss << "<img>src='" << male_type.image() << "'</img> ";
#else
ss << "<img>src='" << male_type.image() << "~TC(1," << male_type.flag_rgb() << ")" << "'</img> ";
ss << "<img>src='" << male_type.image() << "~TC(" << male_type.flag_rgb() << ">1)" << "'</img> ";
#endif
if (&female_type != &male_type)
#ifdef LOW_MEM
ss << "<img>src='" << female_type.image() << "'</img> ";
#else
ss << "<img>src='" << female_type.image() << "~TC(1," << female_type.flag_rgb() << ")" << "'</img> ";
ss << "<img>src='" << female_type.image() << "~TC(" << female_type.flag_rgb() << ">1)" << "'</img> ";
#endif

View file

@ -120,19 +120,7 @@ void locator::init_index()
index_ = i->second;
}
}
void locator::get_tc_info(const std::string& 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);
val_.type_ = SUB_FILE;
}
void locator::parse_arguments()
{
std::string& fn = val_.filename_;
@ -140,23 +128,11 @@ void locator::parse_arguments()
return;
}
size_t markup_field = fn.find('~');
std::string left_par="(";
std::string right_par=")";
if(markup_field != std::string::npos) {
std::string markup_string = fn.substr(markup_field+1, fn.size() - markup_field );
val_.type_ = SUB_FILE;
val_.modifications_ = fn.substr(markup_field, fn.size() - markup_field);
fn = fn.substr(0,markup_field);
std::vector<std::string> farg = utils::paranthetical_split(markup_string,left_par,right_par);
std::vector<std::string>::const_iterator i = farg.begin();
while(i!=farg.end()){
std::string function=*i++;
if(i==farg.end()){
return;
}
std::string field = *i++;
if(function == "TC") {
get_tc_info(field);
}
}
}
}
@ -165,9 +141,15 @@ locator::locator() :
{
}
locator::locator(const locator &a):
index_(a.index_), val_(a.val_)
locator::locator(const locator &a, const std::string& mods):
val_(a.val_)
{
if(mods.size()){
val_.modifications_ += mods;
val_.type_=SUB_FILE;
init_index();
}
else index_=a.index_;
}
locator::locator(const char *filename) :
@ -184,20 +166,20 @@ locator::locator(const std::string &filename) :
init_index();
}
locator::locator(const char *filename, const color_range& new_rgb, const std::vector<Uint32>& swap_rgb) :
val_(filename, new_rgb, swap_rgb)
locator::locator(const char *filename, const std::string& modifications) :
val_(filename, modifications)
{
init_index();
}
locator::locator(const std::string &filename, const color_range& new_rgb, const std::vector<Uint32>& swap_rgb) :
val_(filename, new_rgb, swap_rgb)
locator::locator(const std::string &filename, const std::string& modifications) :
val_(filename, modifications)
{
init_index();
}
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)
locator::locator(const std::string &filename, const gamemap::location &loc, const std::string& modifications) :
val_(filename, loc, modifications)
{
init_index();
}
@ -212,7 +194,7 @@ locator& locator::operator=(const locator &a)
locator::value::value(const locator::value& a) :
type_(a.type_), filename_(a.filename_), loc_(a.loc_),
new_color(a.new_color), swap_colors(a.swap_colors)
modifications_(a.modifications_)
{
}
@ -226,8 +208,8 @@ locator::value::value(const char *filename) :
}
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)
locator::value::value(const char *filename, const std::string& modifications) :
type_(SUB_FILE), filename_(filename), modifications_(modifications)
{
}
@ -236,13 +218,13 @@ locator::value::value(const std::string& filename) :
{
}
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 std::string& modifications) :
type_(SUB_FILE), filename_(filename), modifications_(modifications)
{
}
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)
locator::value::value(const std::string& filename, const gamemap::location& loc, const std::string& modifications) :
type_(SUB_FILE), filename_(filename), loc_(loc), modifications_(modifications)
{
}
@ -253,7 +235,7 @@ bool locator::value::operator==(const value& a) const
} else if(type_ == FILE) {
return filename_ == a.filename_;
} else if(type_ == SUB_FILE) {
return filename_ == a.filename_ && loc_ == a.loc_ && new_color == a.new_color; //note not checking swap_colors purposely
return filename_ == a.filename_ && loc_ == a.loc_ && modifications_ == a.modifications_;
} else {
return false;
}
@ -270,7 +252,7 @@ bool locator::value::operator<(const value& a) const
return filename_ < a.filename_;
if(loc_ != a.loc_)
return loc_ < a.loc_;
return(new_color < a.new_color);
return(modifications_ < a.modifications_);
} else {
return false;
}
@ -334,10 +316,38 @@ surface locator::load_image_sub_file() const
surf=mask_surface(tmp, mask);
}
if(val_.swap_colors.size()){
surf=recolor_image(surf,get_new_color(),get_swap_colors());
if(val_.modifications_.size()){
std::map<Uint32, Uint32> recolor_map;
std::vector<std::string> modlist = utils::split(val_.modifications_,'~');
for(std::vector<std::string>::const_iterator i=modlist.begin();
i!= modlist.end();i++){
std::vector<std::string> tmpmod = utils::paranthetical_split(*i);
std::vector<std::string>::const_iterator j=tmpmod.begin();
while(j!= tmpmod.end()){
std::string function=*j++;
if(j==tmpmod.end()){
if(function.size()){
ERR_DP << "error parsing image modifications: "
<< val_.modifications_<< "\n";
}
break;
}
std::string field = *j++;
if("TC" == function){
std::vector<std::string> recolor=utils::split(field,'>');
if(recolor.size()>1){
color_range new_color = game_config::team_rgb_range.find(recolor[1])->second;
std::vector<Uint32> old_color = game_config::tc_info(recolor[0]);
std::map<Uint32, Uint32> tmp_map = recolor_range(new_color,old_color);
for(std::map<Uint32, Uint32>::const_iterator tmp = tmp_map.begin(); tmp!= tmp_map.end(); tmp++){
recolor_map[tmp->first] = tmp->second;
}
}
}
}
}
surf = recolor_image(surf,recolor_map);
}
return surf;
}
@ -715,7 +725,7 @@ locator get_alternative(const image::locator &i_locator, const std::string &alt,
res = locator(alternative);
break;
case locator::SUB_FILE:
res = locator(alternative, i_locator.get_loc(), i_locator.get_new_color(), i_locator.get_swap_colors());
res = locator(alternative, i_locator.get_loc(), i_locator.get_modifications());
break;
default:
wassert(false);

View file

@ -47,7 +47,6 @@ namespace image {
// Called by each constructor after actual construction to
// initialize the index_ field
void init_index();
void get_tc_info(const std::string& field);
void parse_arguments();
public:
enum type { NONE, FILE, SUB_FILE };
@ -56,10 +55,10 @@ namespace image {
value();
value(const value &a);
value(const char *filename);
value(const char *filename, const color_range& new_rgb, const std::vector<Uint32>& swap_rgb);
value(const char *filename, const std::string& modifications);
value(const std::string& filename);
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);
value(const std::string& filename, const std::string& modifications);
value(const std::string& filename, const gamemap::location& loc, const std::string& modifications);
bool operator==(const value& a) const;
bool operator<(const value& a) const;
@ -67,8 +66,7 @@ namespace image {
type type_;
std::string filename_;
gamemap::location loc_;
color_range new_color;
std::vector<Uint32> swap_colors;
std::string modifications_;
};
// Constructing locators is somewhat slow, accessing image
@ -76,12 +74,12 @@ namespace image {
// should store locators, and not strings to construct locators
// (the second will work, of course, but will be slower)
locator();
locator(const locator &a);
locator(const locator &a, const std::string &mods ="");
locator(const char *filename);
locator(const char *filename, const color_range& new_rgb, const std::vector<Uint32>& swap_rgb);
locator(const char *filename, const std::string& modifications);
locator(const std::string& filename);
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(const std::string& filename, const std::string& modifications);
locator(const std::string& filename, const gamemap::location& loc, const std::string& modifications="");
locator& operator=(const locator &a);
bool operator==(const locator &a) const { return index_ == a.index_; }
@ -90,8 +88,7 @@ namespace image {
const std::string &get_filename() const { return val_.filename_; }
const gamemap::location& get_loc() const { return val_.loc_ ; }
const color_range& get_new_color() const { return val_.new_color ; }
const std::vector<Uint32>& get_swap_colors() const { return val_.swap_colors ; }
const std::string& get_modifications() const {return val_.modifications_;}
const type get_type() const { return val_.type_; };
// const int get_index() const { return index_; };

View file

@ -101,7 +101,7 @@ void leader_list_manager::populate_combo(int selected_index) {
#ifdef LOW_MEM
leader_strings.push_back(IMAGE_PREFIX + image + COLUMN_SEPARATOR + name);
#else
leader_strings.push_back(IMAGE_PREFIX + image + std::string("~TC(1," + utypes.find(*itor)->second.flag_rgb() + ")") + COLUMN_SEPARATOR + name);
leader_strings.push_back(IMAGE_PREFIX + image + std::string("~TC(" + utypes.find(*itor)->second.flag_rgb() + ">1)") + COLUMN_SEPARATOR + name);
#endif
} else {
if(*itor == "random") {

View file

@ -273,7 +273,7 @@ namespace events{
str << IMAGE_PREFIX << type->second.image();
#ifndef LOW_MEM
str << "~TC(" << team << "," << type->second.flag_rgb() << ")";
str << "~TC(" << type->second.flag_rgb() << ">" << team << ")";
#endif
str << COLUMN_SEPARATOR << type->second.language_name() << COLUMN_SEPARATOR << i->second << "\n";
table.push_back(str.str());
@ -398,7 +398,7 @@ namespace events{
}
#ifndef LOW_MEM
str << "~TC(" << (n+1) << "," << leader->second.team_color() << ")";
str << "~TC(" << leader->second.team_color() << ">" << team::get_side_colour_index(n+1) << ")";
#endif
str << COLUMN_SEPARATOR << "\033[3" << lexical_cast<char, size_t>(n+1) << 'm';
// Delete all tags before name
@ -665,10 +665,9 @@ namespace events{
const char prefix = (type.cost() > current_team.gold() ? font::BAD_TEXT : font::NULL_MARKUP);
std::stringstream description;
description << font::IMAGE << type.image();
#ifndef LOW_MEM
description << "~TC(" << team_num << "," << type.flag_rgb() << ")";
description << "~TC(" << type.flag_rgb() << ">" << team::get_side_colour_index(team_num) << ")";
#endif
description << COLUMN_SEPARATOR << font::LARGE_TEXT << prefix << type.language_name() << "\n"
<< prefix << type.cost() << " " << sgettext("unit^Gold");
@ -809,7 +808,7 @@ namespace events{
option << IMAGE_PREFIX << u->absolute_image();
#ifndef LOW_MEM
option << "~TC(" << team_num << "," << u->team_color() << ")";
option << "~TC(" << u->team_color() << ">" << team::get_side_colour_index(team_num) << ")";
#endif
option << COLUMN_SEPARATOR
<< u->language_name() << COLUMN_SEPARATOR

View file

@ -72,7 +72,9 @@ std::string get_colour_string(int id)
{
std::string prefix("\033[3 m");
prefix[3] = lexical_cast<char, int>(id + 1);
std::map<int, std::string>::iterator name = game_config::team_rgb_name.find(id+1);
std::stringstream side_id;
side_id << (id + 1);
std::map<std::string, std::string>::iterator name = game_config::team_rgb_name.find(side_id.str());
if(name != game_config::team_rgb_name.end()){
return prefix + _(name->second.c_str());
}else{

View file

@ -93,7 +93,7 @@ void wait::leader_preview_pane::draw_contents()
#ifdef LOW_MEM
image = utypes.find(leader)->second.image();
#else
image = utypes.find(leader)->second.image() + "~TC(1," + utypes.find(leader)->second.flag_rgb() + ")";
image = utypes.find(leader)->second.image() + "~TC(" + utypes.find(leader)->second.flag_rgb() + ">1)";
#endif
}
@ -400,8 +400,8 @@ void wait::generate_menu()
#ifdef LOW_MEM
leader_image = utypes.find(leader_type)->second.image();
#else
leader_image = utypes.find(leader_type)->second.image() + std::string("~TC(" + sd["side"] + ",") + std::string(utypes.find(leader_type)->second.flag_rgb() + ")");
#else
leader_image = utypes.find(leader_type)->second.image() + std::string("~TC(") + std::string(utypes.find(leader_type)->second.flag_rgb() + ">" + sd["side"] + ")");
#endif
} else {

View file

@ -76,7 +76,7 @@ void report::add_image(const std::string& image, const std::string& tooltip) {
report generate_report(TYPE type, const gamemap& map, unit_map& units,
const std::vector<team>& teams, const team& current_team,
int current_side, int playing_side,
unsigned int current_side, unsigned int playing_side,
const gamemap::location& loc, const gamemap::location& mouseover,
const gamestatus& status, const std::set<std::string>& observers)
{
@ -310,10 +310,9 @@ Units cannot be killed by poison alone. The poison will not reduce it below 1 HP
}
case UNIT_IMAGE:
{
const std::vector<Uint32>& old_rgb = u->second.team_rgb_range();
color_range new_rgb = team::get_side_color_range(u->second.side());
return report("",image::locator(u->second.absolute_image(), new_rgb, old_rgb),"");
// const std::vector<Uint32>& old_rgb = u->second.team_rgb_range();
// color_range new_rgb = team::get_side_color_range(u->second.side());
return report("",image::locator(u->second.absolute_image(),u->second.image_mods()),"");
}
case UNIT_PROFILE:
return report("",u->second.profile(),"");
@ -379,7 +378,7 @@ Units cannot be killed by poison alone. The poison will not reduce it below 1 HP
const std::string& underlying = map.underlying_union_terrain(terrain);
if(map.is_village(mouseover)) {
const int owner = village_owner(mouseover,teams)+1;
const unsigned int owner = village_owner(mouseover,teams)+1;
if(owner == 0 || current_team.fogged(mouseover.x,mouseover.y)) {
str << _("Village");
} else if(owner == current_side) {
@ -434,22 +433,24 @@ Units cannot be killed by poison alone. The poison will not reduce it below 1 HP
case SIDE_PLAYING: {
std::string flag;
color_range new_rgb;
std::vector<Uint32> old_rgb;
std::string new_rgb;
std::string old_rgb;
std::string mods;
if(current_team.flag().empty()) {
flag = game_config::flag_image;
old_rgb = game_config::flag_rgb;
new_rgb = team::get_side_color_range(playing_side);
new_rgb = team::get_side_colour_index(playing_side);
mods = "~TC(" + old_rgb + ">" + new_rgb + ")";
} else {
flag = current_team.flag();
}
// remove animation stuff we don't care about
const std::vector<std::string> items = utils::split(flag);
const std::vector<std::string> sub_items = utils::split(items[0], ':');
image::locator flag_image(sub_items[0], new_rgb, old_rgb);
image::locator flag_image(sub_items[0],mods);
return report("",flag_image,teams[playing_side-1].current_player());
}

View file

@ -89,7 +89,7 @@ namespace reports {
report generate_report(TYPE type, const gamemap& map, unit_map& units,
const std::vector<team>& teams, const team& current_team,
int current_side, int active_side,
unsigned int current_side, int unsigned active_side,
const gamemap::location& loc, const gamemap::location& mouseover,
const gamestatus& status, const std::set<std::string>& observers);
// Set what will be shown for the report with type

View file

@ -469,95 +469,104 @@ surface darken_image(surface const &surf)
return create_optimized_surface(nsurf);
}
surface recolor_image(surface surf, const color_range& new_rgb, const std::vector<Uint32>& old_rgb)
{
// function to replace vectors of colors with new color-range
// parallel input vectors chosen to prevent need to include SDL structures
// elsewhere in code or create new rgb structure. It might be better to
// just pass a vector of SDL colors instead...
std::map<Uint32, Uint32> recolor_range(const color_range& new_range, const std::vector<Uint32>& old_rgb){
std::map<Uint32, Uint32> map_rgb;
if(old_rgb.size()){
Uint16 new_red = (new_rgb.mid() & 0x00FF0000)>>16;
Uint16 new_green= (new_rgb.mid() & 0x0000FF00)>>8;
Uint16 new_blue = (new_rgb.mid() & 0x000000FF);
Uint16 max_red = (new_rgb.max() & 0x00FF0000)>>16;
Uint16 max_green= (new_rgb.max() & 0x0000FF00)>>8 ;
Uint16 max_blue = (new_rgb.max() & 0x000000FF) ;
Uint16 min_red = (new_rgb.min() & 0x00FF0000)>>16;
Uint16 min_green= (new_rgb.min() & 0x0000FF00)>>8 ;
Uint16 min_blue = (new_rgb.min() & 0x000000FF) ;
if(surf == NULL)
return NULL;
surface nsurf(make_neutral_surface(surf));
if(nsurf == NULL) {
std::cerr << "failed to make neutral surface\n";
return NULL;
}
Uint16 reference_avg=0;
Uint16 new_red = (new_range.mid() & 0x00FF0000)>>16;
Uint16 new_green= (new_range.mid() & 0x0000FF00)>>8;
Uint16 new_blue = (new_range.mid() & 0x000000FF);
Uint16 max_red = (new_range.max() & 0x00FF0000)>>16;
Uint16 max_green= (new_range.max() & 0x0000FF00)>>8 ;
Uint16 max_blue = (new_range.max() & 0x000000FF) ;
Uint16 min_red = (new_range.min() & 0x00FF0000)>>16;
Uint16 min_green= (new_range.min() & 0x0000FF00)>>8 ;
Uint16 min_blue = (new_range.min() & 0x000000FF) ;
//map first color in vector to exact new color
Uint32 temp_rgb=old_rgb[0];
int old_r=(temp_rgb & 0X00FF0000)>>16;
int old_g=(temp_rgb & 0X0000FF00)>>8;
int old_b=(temp_rgb & 0X000000FF);
reference_avg = (Uint16)(((Uint16) old_r + (Uint16)old_g + (Uint16)old_b)
Uint16 reference_avg = (Uint16)(((Uint16) old_r + (Uint16)old_g + (Uint16)old_b)
/ 3);
{
for(std::vector<Uint32>::const_iterator temp_rgb = old_rgb.begin();
for(std::vector<Uint32>::const_iterator temp_rgb = old_rgb.begin();
temp_rgb!=old_rgb.end();temp_rgb++)
{
int old_r=((*temp_rgb) & 0X00FF0000)>>16;
int old_g=((*temp_rgb) & 0X0000FF00)>>8;
int old_b=((*temp_rgb) & 0X000000FF);
// std::cout<<"recolor:"<<old_r<<","<<old_g<<","<<old_b<<"\n";
surface_lock lock(nsurf);
Uint32* beg = lock.pixels();
Uint32* end = beg + nsurf->w*surf->h;
//const Uint16 old_grey = (Uint16)((77*(Uint16) old_r +
// 150*(Uint16)old_g +
// 29*(Uint16)old_b) / 256);
const Uint16 old_avg = (Uint16)(((Uint16) old_r +
(Uint16) old_g +
(Uint16) old_b) / 3);
{
int old_r=((*temp_rgb) & 0X00FF0000)>>16;
int old_g=((*temp_rgb) & 0X0000FF00)>>8;
int old_b=((*temp_rgb) & 0X000000FF);
const Uint16 old_avg = (Uint16)(((Uint16) old_r +
(Uint16) old_g + (Uint16) old_b) / 3);
//calculate new color
Uint8 new_r, new_g, new_b;
Uint32 new_r, new_g, new_b;
if(reference_avg && old_avg <= reference_avg){
float old_rat = ((float)old_avg)/reference_avg;
new_r=(Uint8)( old_rat * new_red + (1 - old_rat) * min_red);
new_g=(Uint8)( old_rat * new_green + (1 - old_rat) * min_green);
new_b=(Uint8)( old_rat * new_blue + (1 - old_rat) * min_blue);
}else if(255 - reference_avg){
float old_rat = ((float) 255 - old_avg) / (255 - reference_avg);
new_r=(Uint8)( old_rat * new_red + (1 - old_rat) * max_red);
new_g=(Uint8)( old_rat * new_green + (1 - old_rat) * max_green);
new_b=(Uint8)( old_rat * new_blue + (1 - old_rat) * max_blue);
}else{
if(reference_avg && old_avg <= reference_avg){
float old_rat = ((float)old_avg)/reference_avg;
new_r=Uint32( old_rat * new_red + (1 - old_rat) * min_red);
new_g=Uint32( old_rat * new_green + (1 - old_rat) * min_green);
new_b=Uint32( old_rat * new_blue + (1 - old_rat) * min_blue);
}else if(255 - reference_avg){
float old_rat = ((float) 255 - old_avg) / (255 - reference_avg);
new_r=Uint32( old_rat * new_red + (1 - old_rat) * max_red);
new_g=Uint32( old_rat * new_green + (1 - old_rat) * max_green);
new_b=Uint32( old_rat * new_blue + (1 - old_rat) * max_blue);
}else{
new_r=0; new_g=0; new_b=0; //supress warning
wassert(false);
//should never get here
//would imply old_avg > reference_avg = 255
}
while(beg != end) {
Uint8 red, green, blue, alpha;
SDL_GetRGBA(*beg,nsurf->format,&red,&green,&blue,&alpha);
if(red==old_r && green==old_g && blue==old_b){
*beg = SDL_MapRGBA(nsurf->format,new_r,new_g,new_b,alpha);
}
++beg;
}
}
//should never get here
//would imply old_avg > reference_avg = 255
}
if(new_r>255) new_r=255;
if(new_g>255) new_g=255;
if(new_b>255) new_b=255;
Uint32 newrgb = (new_r << 16) + (new_g << 8) + (new_b );
map_rgb[*temp_rgb]=newrgb;
}
return create_optimized_surface(nsurf);
}
return NULL;
return map_rgb;
}
surface recolor_image(surface surf, const std::map<Uint32, Uint32>& map_rgb){
if(map_rgb.size()){
if(surf == NULL)
return NULL;
surface nsurf(make_neutral_surface(surf));
if(nsurf == NULL) {
std::cerr << "failed to make neutral surface\n";
return NULL;
}
surface_lock lock(nsurf);
Uint32* beg = lock.pixels();
Uint32* end = beg + nsurf->w*surf->h;
while(beg != end) {
Uint8 red, green, blue, alpha;
SDL_GetRGBA(*beg,nsurf->format,&red,&green,&blue,&alpha);
if(alpha){//don't recolor invisible pixels.
Uint32 oldrgb = (red<<16) + (green<<8) + (blue);
for(std::map<Uint32, Uint32>::const_iterator i=map_rgb.begin(); i!= map_rgb.end(); i++){
if(oldrgb==i->first){
Uint32 new_rgb = i->second;
Uint8 new_r = (new_rgb & 0x00FF0000)>>16;
Uint8 new_g = (new_rgb & 0x0000FF00)>>8;
Uint8 new_b = (new_rgb & 0x000000FF);
*beg = SDL_MapRGBA(nsurf->format,new_r,new_g,new_b,alpha);
break; //no double replacements.
}
}
}
++beg;
}
return create_optimized_surface(nsurf);
}
return surf;
}
surface brighten_image(surface const &surf, fixed_t amount)

View file

@ -111,7 +111,8 @@ surface scale_surface_blended(surface const &surf, int w, int h);
surface adjust_surface_colour(surface const &surf, int r, int g, int b);
surface greyscale_image(surface const &surf);
surface darken_image(surface const &surf);
surface recolor_image(surface surf, const color_range& new_rgb, const std::vector<Uint32>& old_rgb);
std::map<Uint32, Uint32> recolor_range(const color_range& new_rgb, const std::vector<Uint32>& old_rgb);
surface recolor_image(surface surf, const std::map<Uint32, Uint32>& map_rgb);
surface brighten_image(surface const &surf, fixed_t amount);
surface get_surface_portion(surface const &surf, SDL_Rect &rect);

View file

@ -115,14 +115,12 @@ team::team_info::team_info(const config& cfg)
else
action_bonus_count = atoi(bonus.c_str());
colour = lexical_cast_default<int>(cfg["colour"],-1);
if(colour == -1)
colour = lexical_cast_default<int>(cfg["side"],-1);
colour = cfg["colour"].size()?cfg["colour"]:cfg["side"];
int side = atoi(cfg["side"].c_str());
std::vector<Uint32> temp_rgb = string2rgb(cfg["team_rgb"]);
std::map<int, color_range>::iterator global_rgb = game_config::team_rgb_range.find(side);
std::map<std::string, color_range>::iterator global_rgb = game_config::team_rgb_range.find(cfg["side"]);
if(temp_rgb.size()){
team_color_range_[side] = color_range(temp_rgb);
@ -779,7 +777,7 @@ const std::string& team::music() const
return info_.music;
}
int team::map_colour_to() const
std::string team::map_colour_to() const
{
return info_.colour;
}
@ -953,13 +951,10 @@ bool team::shroud_map::copy_from(const std::vector<const shroud_map*>& maps)
std::map<int, color_range> team::team_color_range_;
const color_range team::get_side_color_range(int side){
size_t index = size_t(get_side_colour_index(side));
std::map<int, color_range>::iterator p=team_color_range_.find(index);
std::map<int, color_range>::iterator gp=game_config::team_rgb_range.find(index);
std::string index = get_side_colour_index(side);
std::map<std::string, color_range>::iterator gp=game_config::team_rgb_range.find(index);
if(p != team_color_range_.end()){
return(p->second);
}else if(gp != game_config::team_rgb_range.end()){
if(gp != game_config::team_rgb_range.end()){
return(gp->second);
}
@ -988,17 +983,19 @@ const SDL_Color team::get_side_colour(int side)
return color;
}
int team::get_side_colour_index(int side)
std::string team::get_side_colour_index(int side)
{
size_t index = size_t(side-1);
if(teams != NULL && index < teams->size()) {
const int side_map = (*teams)[index].map_colour_to();
if(side_map >= 1) {
const std::string side_map = (*teams)[index].map_colour_to();
if(side_map.size()) {
return side_map;
}
}
return side;
}
std::stringstream id;
id<<side;
return id.str();
}
void team::log_recruitable(){

View file

@ -106,7 +106,7 @@ public:
std::string music;
int colour;
std::string colour;
};
static std::map<int, color_range> team_color_range_;
@ -224,7 +224,7 @@ public:
const std::string& music() const;
int map_colour_to() const;
std::string map_colour_to() const;
static int nteams();
@ -234,7 +234,7 @@ public:
static const Uint32 get_side_rgb_max(int side);
static const Uint32 get_side_rgb_min(int side);
static const SDL_Color get_side_colour(int side);
static int get_side_colour_index(int side);
static std::string get_side_colour_index(int side);
void log_recruitable();

View file

@ -1579,11 +1579,13 @@ const surface unit::still_image() const
{
image::locator loc;
#ifdef LOW_MEM
loc = image::locator(absolute_image());
#else
if(flag_rgb().size()){
loc = image::locator(absolute_image(),team_rgb_range(),flag_rgb());
std::string mods=image_mods();
if(mods.size()){
loc = image::locator(absolute_image(),mods);
} else {
loc = image::locator(absolute_image());
}
@ -1897,18 +1899,25 @@ void unit::redraw_unit(display& disp,gamemap::location hex)
if(loc.is_void()) {
loc = absolute_image();
}
#ifndef LOW_MEM
std::string mod=image_mods();
if(mod.size()){
loc = image::locator(loc,mod);
}
#endif
surface image(image::get_image(loc,
utils::string_bool(get_state("stoned"))?image::GREYED : image::UNSCALED,image::ADJUST_COLOUR,
#ifndef LOW_MEM
true));
#else
state_ == STATE_STANDING?true:false));
#endif
if(image == NULL) {
image = still_image();
}
#ifndef LOW_MEM
if(flag_rgb().size()){
image = recolor_image(image,team_rgb_range(),flag_rgb());
}
#endif
if(facing_ == gamemap::location::NORTH_WEST || facing_ == gamemap::location::SOUTH_WEST) {
image.assign(image::reverse_image(image));
}
@ -1946,10 +1955,13 @@ void unit::redraw_unit(display& disp,gamemap::location hex)
if(ellipse.empty()){
ellipse="misc/ellipse";
}
snprintf(buf,sizeof(buf),"%s-%stop.png",ellipse.c_str(),selected);
ellipse_back.assign(image::get_image(image::locator(buf,team_rgb_range(),temp_rgb)));
snprintf(buf,sizeof(buf),"%s-%sbottom.png",ellipse.c_str(),selected);
ellipse_front.assign(image::get_image(image::locator(buf,team_rgb_range(),temp_rgb)));
std::string tc=team::get_side_colour_index(side_);
snprintf(buf,sizeof(buf),"%s-%stop.png~TC(%s>%s)",ellipse.c_str(),selected,"red",tc.c_str());
ellipse_back.assign(image::get_image(image::locator(buf)));
snprintf(buf,sizeof(buf),"%s-%sbottom.png~TC(%s>%s)",ellipse.c_str(),selected,"red",tc.c_str());
ellipse_front.assign(image::get_image(image::locator(buf)));
}
disp.draw_unit(x, y -height_adjust, image, false, highlight_ratio,
@ -3116,23 +3128,6 @@ bool unit::invisible(const gamemap::location& loc,
return false;
}
int team_units(const unit_map& units, unsigned int side)
{
int res = 0;
@ -3253,3 +3248,12 @@ temporary_unit_placer::~temporary_unit_placer()
m_.add(temp_);
}
}
std::string unit::image_mods() const{
std::stringstream modifier;
if(flag_rgb_.size()){
modifier << "~TC("<< flag_rgb_ << ">" << team::get_side_colour_index(side()) << ")";
}
return modifier.str();
}

View file

@ -275,6 +275,7 @@ class unit
const unit_map& units,const std::vector<team>& teams) const;
unit_race::GENDER generate_gender(const unit_type& type, bool gen);
std::string image_mods() const;
private: