added colors to themes and modified sidebar unit information layout

This commit is contained in:
John W. C. McNabb 2005-11-23 07:03:14 +00:00
parent 4d20540d3c
commit 8ded490aa4
7 changed files with 205 additions and 36 deletions

View file

@ -35,6 +35,8 @@ SVN trunk (1.1.x):
* The Dark Hordes
* Underground Pool no longer has units off map and in walls
* user interface
* added font colors to theme
* reorganized side-bar information
* fix untranslated unit create dialog (#4424)
* changed recall to show recall list even when gold < 20
* added advancement and AMLA indicator icons, tooltips to dfool theme

View file

@ -203,6 +203,7 @@ height=768
ref=unit-panel
id=label-hp
font_size=10
font_rgb=180,180,180
text= _ "HP"
rect="=+84,=+1,+54,+12"
xanchor=right
@ -212,6 +213,7 @@ height=768
ref=unit-panel
id=label-xp
font_size=10
font_rgb=180,180,180
text= _ "XP"
rect="=+84,=+28,=+54,+12"
xanchor=right
@ -221,6 +223,7 @@ height=768
ref=unit-panel
id=label-mp
font_size=10
font_rgb=180,180,180
text= _ "MP"
rect="=+84,=+55,=+54,+12"
xanchor=right
@ -399,6 +402,7 @@ height=768
[unit_traits]
id=unit-traits
font_size=12
font_rgb=165,165,165
rect="=,+0,+130,+16"
xanchor=right
yanchor=fixed
@ -414,6 +418,7 @@ height=768
[unit_level]
id=unit-level
font_size=12
font_rgb=165,165,165
rect="=,+0,=,+16"
prefix= _ "statuspanel^level"
prefix_literal=" "
@ -423,6 +428,7 @@ height=768
[unit_alignment]
id=unit-alignment
font_size=12
font_rgb=165,165,165
rect="=,+0,=,+16"
xanchor=right
yanchor=fixed
@ -431,6 +437,7 @@ height=768
[unit_abilities]
id=unit-abilities
font_size=12
font_rgb=165,165,165
rect="=,+0,=,+16"
xanchor=right
yanchor=fixed

View file

@ -696,7 +696,23 @@ void draw_label(CVideo& video, surface target, const theme::label& label)
{
//log_scope("draw label");
const std::string& text = label.text();
std::stringstream temp;
Uint32 RGB=label.font_rgb();
int red = (RGB & 0x00FF0000)>>16;
int green = (RGB & 0x0000FF00)>>8;
int blue = (RGB & 0x000000FF);
std::string c_start="<";
std::string c_sep=",";
std::string c_end=">";
std::stringstream color;
color<< c_start << red << c_sep << green << c_sep << blue << c_end;
std::string text = label.text();
if(label.font_rgb_set()){
color<<text;
text = color.str();
}
const std::string& icon = label.icon();
SDL_Rect& loc = label.location(screen_area());
@ -979,27 +995,44 @@ void display::draw_report(reports::TYPE report_num)
if(!report.empty()) {
// Add prefix, postfix elements. Make sure that they get the same tooltip as the guys
// around them.
std::string str = item->prefix();
std::stringstream temp;
Uint32 RGB = item->font_rgb();
int red = (RGB & 0x00FF0000)>>16;
int green = (RGB & 0x0000FF00)>>8;
int blue = (RGB & 0x000000FF);
std::string c_start="<";
std::string c_sep=",";
std::string c_end=">";
std::stringstream color;
color<< c_start << red << c_sep << green << c_sep << blue << c_end;
std::string str;
str = item->prefix();
if(str.empty() == false) {
report.insert(report.begin(), reports::element(str,"",report.begin()->tooltip));
report.insert(report.begin(), reports::element(str,"",report.begin()->tooltip));
}
str = item->postfix();
if(str.empty() == false) {
report.push_back(reports::element(str,"",report.end()->tooltip));
report.push_back(reports::element(str,"",report.end()->tooltip));
}
// Loop through and display each report element
size_t tallest = 0;
int image_count = 0;
bool used_ellipsis=false;
std::stringstream ellipsis_tooltip;
SDL_Rect ellipsis_area =rect;
for(reports::report::iterator i = report.begin(); i != report.end(); ++i) {
temp.str("");
if(i->text.empty() == false){
if(used_ellipsis == false) {
// Draw a text element
area = font::draw_text(&screen_,rect,item->font_size(),font::NORMAL_COLOUR,i->text,x,y);
if(item->font_rgb_set()){
temp <<color.str();
}
temp << i->text;
str = temp.str();
area = font::draw_text(&screen_,rect,item->font_size(),font::NORMAL_COLOUR,str,x,y);
if(area.h > tallest) tallest = area.h;
if(i->text[i->text.size() - 1] == '\n') {
x = rect.x;

View file

@ -21,7 +21,8 @@
namespace font {
const char LARGE_TEXT='*', SMALL_TEXT='`', GOOD_TEXT='@', BAD_TEXT='#',
NORMAL_TEXT='{', BLACK_TEXT='}', BOLD_TEXT='~', IMAGE='&', NULL_MARKUP='^';
NORMAL_TEXT='{', BLACK_TEXT='}', BOLD_TEXT='~', IMAGE='&',
COLOR_TEXT='<', NULL_MARKUP='^';
namespace {
@ -80,10 +81,48 @@ std::string::const_iterator parse_markup(std::string::const_iterator i1, std::st
}
}
break;
case COLOR_TEXT:
{
//very primitive parsing for rgb value
//should look like <213,14,151>
//but no checking on commas or end '>',
//could be any non-# char
++i1;
Uint8 red=0, green=0, blue=0, temp=0;
int count=0;
while(i1 != i2 && *i1 >= '0' && *i1<='9'){
temp*=10;
temp += lexical_cast<int, char>(*i1);
++i1;
}
red=temp;
temp=0;
if(i1 != i2){
++i1;
while(i1 != i2 && *i1 >= '0' && *i1<='9'){
temp*=10;
temp += lexical_cast<int, char>(*i1);
++i1;
}
green=temp;
temp=0;
}
if(i1 != i2){
++i1;
while(i1 != i2 && *i1 >= '0' && *i1<='9'){
temp*=10;
temp += lexical_cast<int, char>(*i1);
++i1;
}
}
blue=temp;
*colour = (SDL_Color){red,green,blue,0};
break;
}
default:
return i1;
return i1;
}
++i1;
}

View file

@ -176,9 +176,12 @@ Units cannot be killed by poison alone. The poison will not reduce it below 1 HP
}
case UNIT_HP:
if(u->second.hitpoints() <= u->second.max_hitpoints()/3)
str << font::BAD_TEXT;
str << "<200,0,0>";
else if(u->second.hitpoints() > 2*(u->second.max_hitpoints()/3))
str << font::GOOD_TEXT;
str << "<0,200,0>";
else
str << "<200,200,0>";
str << u->second.hitpoints()
<< "/" << u->second.max_hitpoints();
@ -188,12 +191,9 @@ Units cannot be killed by poison alone. The poison will not reduce it below 1 HP
if(u->second.can_advance() == false) {
str << u->second.experience() << "/-";
} else {
//if killing a unit of the same level as us lets us advance, display in 'good' colour
if(u->second.max_experience() - u->second.experience() <= game_config::kill_experience*u->second.type().level()) {
str << font::GOOD_TEXT;
}
str << u->second.experience() << "/" << u->second.max_experience();
int x = (int)(180 + ((255-180)*((float)u->second.experience())/u->second.max_experience()));
str << "<" << x << "," << x << "," << x <<">";
str << u->second.experience() << "/" << u->second.max_experience();
}
break;
@ -206,9 +206,17 @@ Units cannot be killed by poison alone. The poison will not reduce it below 1 HP
return(res);
}
case UNIT_MOVES:
str << u->second.movement_left() << "/" << u->second.total_movement();
case UNIT_MOVES: {
int x = 180;
if(u->second.stone()){
x = 140;
}else{
x = (int)(180 + (255-180)*((float)u->second.movement_left()/u->second.total_movement()));
}
str << "<" << x << "," << x << "," << x <<">";
str << u->second.movement_left() << "/" << u->second.total_movement();
break;
}
case UNIT_WEAPONS: {
report res;
std::stringstream tooltip;
@ -223,7 +231,7 @@ Units cannot be killed by poison alone. The poison will not reduce it below 1 HP
for(std::vector<attack_type>::const_iterator at_it = attacks.begin();
at_it != attacks.end(); ++at_it) {
const std::string& lang_type = gettext(at_it->type().c_str());
str.str("");
str << at_it->name() << " (" << lang_type << ")\n";
tooltip << at_it->name() << " (" << lang_type << ")\n";
@ -256,19 +264,7 @@ Units cannot be killed by poison alone. The poison will not reduce it below 1 HP
res.add_text(str,tooltip);
str << " ";
static const std::string swarm_string("swarm");
if (!at_it->special().empty()) {
if(at_it->special() == swarm_string){
str << gettext(at_it->special().c_str())<<"("<< at_it->num_attacks() <<")" << "\n";
}else{
str << gettext(at_it->special().c_str()) << "\n";
}
tooltip << string_table["weapon_special_" + at_it->special() + "_description"];
res.add_text(str,tooltip);
}
str << " ";
str << "<165,165,165> ";
str << at_it->damage() << "-" ;
str << at_it->num_swarm_attacks(u->second.hitpoints(), u->second.max_hitpoints());
str << " -- "
@ -281,6 +277,20 @@ Units cannot be killed by poison alone. The poison will not reduce it below 1 HP
str << "\n";
res.add_text(str,tooltip);
str << "<165,165,165> ";
static const std::string swarm_string("swarm");
if (!at_it->special().empty()) {
if(at_it->special() == swarm_string){
str << gettext(at_it->special().c_str())<<"("<<at_it->num_swarm_attacks(u->second.hitpoints(),u->second.max_hitpoints())<<"/"<< at_it->num_attacks() <<")" << "\n";
}else{
str << gettext(at_it->special().c_str()) << "\n";
}
tooltip << string_table["weapon_special_" + at_it->special() + "_description"];
res.add_text(str,tooltip);
}
}
return res;

View file

@ -34,6 +34,7 @@ namespace {
const int YDim = 768;
const size_t DefaultFontSize = font::SIZE_NORMAL;
const Uint32 DefaultFontRGB = 0x00C8C8C8;
typedef struct { size_t x1,y1,x2,y2; } _rect;
_rect ref_rect = { 0, 0, 0, 0 };
@ -351,10 +352,35 @@ theme::label::label()
theme::label::label(const config& cfg)
: object(cfg), text_(cfg["prefix"].str() + cfg["text"].str() + cfg["postfix"].str()),
icon_(cfg["icon"]), font_(atoi(cfg["font_size"].c_str()))
icon_(cfg["icon"]), font_(atoi(cfg["font_size"].c_str()))
{
if(font_ == 0)
font_ = DefaultFontSize;
font_rgb_ = DefaultFontRGB;
font_rgb_set_ = false;
if(cfg["font_rgb"].size()){
std::vector<std::string> rgb_vec = utils::split(cfg["font_rgb"]);
if(3 <= rgb_vec.size()){
std::vector<std::string>::iterator c=rgb_vec.begin();
int r,g,b;
r = (atoi(c->c_str()));
c++;
if(c != rgb_vec.end()){
g = (atoi(c->c_str()));
}else{
g=0;
}
c++;
if(c != rgb_vec.end()){
b=(atoi(c->c_str()));
}else{
b=0;
}
font_rgb_ = (((r<<16) & 0x00FF0000) + ((g<<8) & 0x0000FF00) + ((b) & 0x000000FF));
font_rgb_set_=true;
}
}
}
const std::string& theme::label::text() const
@ -377,6 +403,16 @@ size_t theme::label::font_size() const
return font_;
}
Uint32 theme::label::font_rgb() const
{
return font_rgb_;
}
bool theme::label::font_rgb_set() const
{
return font_rgb_set_;
}
theme::status_item::status_item(const config& cfg)
: object(cfg),
prefix_(cfg["prefix"].str() + cfg["prefix_literal"].str()),
@ -390,6 +426,31 @@ theme::status_item::status_item(const config& cfg)
if(label_child != NULL) {
label_ = label(*label_child);
}
font_rgb_ = DefaultFontRGB;
font_rgb_set_ = false;
if(cfg["font_rgb"].size()){
std::vector<std::string> rgb_vec = utils::split(cfg["font_rgb"]);
if(3 <= rgb_vec.size()){
std::vector<std::string>::iterator c=rgb_vec.begin();
int r,g,b;
r = (atoi(c->c_str()));
c++;
if(c != rgb_vec.end()){
g = (atoi(c->c_str()));
}else{
g=0;
}
c++;
if(c != rgb_vec.end()){
b=(atoi(c->c_str()));
}else{
b=0;
}
font_rgb_ = (((r<<16) & 0x00FF0000) + ((g<<8) & 0x0000FF00) + ((b) & 0x000000FF));
font_rgb_set_=true;
}
}
}
const std::string& theme::status_item::prefix() const
@ -412,6 +473,16 @@ size_t theme::status_item::font_size() const
return font_;
}
Uint32 theme::status_item::font_rgb() const
{
return font_rgb_;
}
bool theme::status_item::font_rgb_set() const
{
return font_rgb_set_;
}
theme::panel::panel(const config& cfg) : object(cfg), image_(cfg["image"])
{}

View file

@ -70,10 +70,13 @@ public:
bool empty() const;
size_t font_size() const;
Uint32 font_rgb() const;
bool font_rgb_set() const;
private:
std::string text_, icon_;
size_t font_;
bool font_rgb_set_;
Uint32 font_rgb_;
};
class status_item : private object
@ -91,11 +94,15 @@ public:
const label* get_label() const;
size_t font_size() const;
Uint32 font_rgb() const;
bool font_rgb_set() const;
private:
std::string prefix_, postfix_;
label label_;
size_t font_;
bool font_rgb_set_;
Uint32 font_rgb_;
};
class panel : private object