Status icons in the side panel

This commit is contained in:
uid67456 2004-02-02 23:40:38 +00:00
parent db5867915e
commit 6c7aa40bbc
4 changed files with 144 additions and 49 deletions

View file

@ -282,7 +282,7 @@ height=600
[/unit_abilities]
[unit_status]
font_size=12
rect=900,398,1020,414
rect=958,241,1008,291
xanchor=right
yanchor=fixed
[/unit_status]

View file

@ -613,6 +613,43 @@ void display::draw_game_status(int x, int y)
}
}
void display::draw_image_for_report(scoped_sdl_surface& img, scoped_sdl_surface& surf, SDL_Rect& rect)
{
SDL_Rect visible_area = get_non_transperant_portion(img);
if(visible_area.x != 0 || visible_area.y != 0 || visible_area.w != img->w || visible_area.h != img->h) {
if(visible_area.w == 0 || visible_area.h == 0) {
return;
}
//since we're blitting a transperant image, we need to back up
//the surface for later restoration
surf.assign(get_surface_portion(screen_.getSurface(),rect));
SDL_Rect target = rect;
if(visible_area.w > rect.w || visible_area.h > rect.h) {
img.assign(get_surface_portion(img,visible_area));
img.assign(scale_surface(img,rect.w,rect.h));
visible_area.x = 0;
visible_area.y = 0;
visible_area.w = img->w;
visible_area.h = img->h;
} else {
target.x = rect.x + (rect.w - visible_area.w)/2;
target.y = rect.y + (rect.h - visible_area.h)/2;
target.w = visible_area.w;
target.h = visible_area.h;
}
SDL_BlitSurface(img,&visible_area,screen_.getSurface(),&target);
} else {
if(img->w != rect.w || img->h != rect.h) {
img.assign(scale_surface(img,rect.w,rect.h));
}
SDL_BlitSurface(img,NULL,screen_.getSurface(),&rect);
}
}
void display::draw_report(reports::TYPE report_num)
{
if(!team_valid())
@ -688,44 +725,62 @@ void display::draw_report(reports::TYPE report_num)
if(report.image.empty() == false) {
scoped_sdl_surface img(image::get_image(report.image,image::UNSCALED));
if(img == NULL) {
std::cerr << "could not find image for report: '" << report.image << "'\n";
return;
}
SDL_Rect visible_area = get_non_transperant_portion(img);
if(visible_area.x != 0 || visible_area.y != 0 || visible_area.w != img->w || visible_area.h != img->h) {
if(visible_area.w == 0 || visible_area.h == 0) {
//check if it's a talbe of images or a standalone image
if((report.image.find_first_of(",") == -1) &&
(report.image.find_first_of(";") == -1)) {
scoped_sdl_surface img(image::get_image(report.image,image::UNSCALED));
if(img == NULL) {
std::cerr << "could not find image for report: '" << report.image << "'\n";
return;
}
//since we're blitting a transperant image, we need to back up
//the surface for later restoration
surf.assign(get_surface_portion(screen_.getSurface(),rect));
SDL_Rect target = rect;
if(visible_area.w > rect.w || visible_area.h > rect.h) {
img.assign(get_surface_portion(img,visible_area));
img.assign(scale_surface(img,rect.w,rect.h));
visible_area.x = 0;
visible_area.y = 0;
visible_area.w = img->w;
visible_area.h = img->h;
} else {
target.x = rect.x + (rect.w - visible_area.w)/2;
target.y = rect.y + (rect.h - visible_area.h)/2;
target.w = visible_area.w;
target.h = visible_area.h;
}
SDL_BlitSurface(img,&visible_area,screen_.getSurface(),&target);
draw_image_for_report(img,surf,rect);
} else {
if(img->w != rect.w || img->h != rect.h) {
img.assign(scale_surface(img,rect.w,rect.h));
}
SDL_Rect composed_rect;
SDL_Surface *composed_img = SDL_CreateRGBSurface(SDL_SWSURFACE,
rect.w, rect.h, screen_.getSurface()->format->BitsPerPixel,
screen_.getSurface()->format->Rmask,
screen_.getSurface()->format->Gmask,
screen_.getSurface()->format->Bmask,
screen_.getSurface()->format->Amask);
SDL_BlitSurface(img,NULL,screen_.getSurface(),&rect);
int x_off;
int y_off = 0;
std::vector<std::string> rows = config::split(report.image,';');
for(std::vector<std::string>::iterator row = rows.begin(); row != rows.end(); ++row) {
int last_image_height = 0;
std::cerr << "Row: " << *row << std::endl;
x_off = 0;
std::vector<std::string> cols = config::split(*row);
for(std::vector<std::string>::iterator col = cols.begin(); col != cols.end(); ++col) {
std::cerr << "Col: " << *col << std::endl;
if(!col->empty()){
scoped_sdl_surface composing_img(image::get_image(*col,image::UNSCALED));
if(composing_img == NULL) {
std::cerr << "could not find image for report: '" << *col << "'\n";
return;
}
composed_rect.w = composing_img->w;
composed_rect.h = composing_img->h;
composed_rect.x = x_off;
composed_rect.y = y_off;
SDL_BlitSurface(composing_img,NULL,composed_img,&composed_rect);
x_off += composing_img->w;
last_image_height = composing_img->h;
std::cout << "\tImage: " << *col << std::endl;
}
}
y_off += last_image_height;
}
scoped_sdl_surface img(composed_img);
draw_image_for_report(img,surf,rect);
}
}
} else {

View file

@ -302,6 +302,8 @@ private:
SDL_Rect unitDescriptionRect_;
SDL_Rect unitProfileRect_;
void draw_image_for_report(scoped_sdl_surface& img,
scoped_sdl_surface& surf, SDL_Rect& rect);
void draw_report(reports::TYPE report_num);
SDL_Rect reportRects_[reports::NUM_REPORTS];
scoped_sdl_surface reportSurfaces_[reports::NUM_REPORTS];

View file

@ -75,23 +75,61 @@ report generate_report(TYPE type, const gamemap& map, const unit_map& units,
return res;
}
case UNIT_STATUS: {
std::string unit_status = "healthy", prefix = "";
std::stringstream unit_status;
std::stringstream tooltip;
const int cols = 3;
int num = 0;
if(map.on_board(loc) && u->second.invisible(map.underlying_terrain(map[loc.x][loc.y]),status.get_time_of_day().lawful_bonus,loc,units,teams)) {
unit_status = "invisible";
prefix = font::GOOD_TEXT;
} else if(u->second.has_flag("slowed")) {
unit_status = "slowed";
prefix = font::BAD_TEXT;
} else if(u->second.has_flag("poisoned")) {
unit_status = "poisoned";
prefix = font::BAD_TEXT;
} else if(u->second.has_flag("stone")) {
unit_status = "stone";
prefix = font::BAD_TEXT;
if(num != 0){
if((num % cols) == 0) unit_status << ";";
else unit_status << ",";
tooltip << std::endl;
}
num++;
unit_status << "misc/invisible.png";
tooltip << string_table["invisible"] << "; " <<
string_table["invisible_description"] << std::endl;
}
if(u->second.has_flag("slowed")) {
if(num != 0){
if((num % cols) == 0) unit_status << ";";
else unit_status << ",";
tooltip << std::endl;
}
num++;
unit_status << "misc/slowed.png";
tooltip << string_table["slowed"] << "; " <<
string_table["slowed_description"] << std::endl;
}
if(u->second.has_flag("poisoned")) {
if(num != 0){
if((num % cols) == 0) unit_status << ";";
else unit_status << ",";
tooltip << std::endl;
}
num++;
unit_status << "misc/poisoned.png";
tooltip << string_table["poisoned"] << "; " <<
string_table["poisoned_description"] << std::endl;
}
if(u->second.has_flag("stone")) {
if(num != 0){
if((num % cols) == 0) unit_status << ";";
else unit_status << ",";
tooltip << std::endl;
}
num++;
unit_status << "misc/stone.png";
tooltip << string_table["stone"] << "; " <<
string_table["stone_description"] << std::endl;
}
report res(prefix + string_table[unit_status]);
res.tooltip = string_table[unit_status + "_description"];
std::cerr << "Status report: " << unit_status.str() << std::endl;
report res("",unit_status.str());
res.tooltip = tooltip.str();
return res;
}
case UNIT_ALIGNMENT: {