final changes for RC3

This commit is contained in:
Dave White 2003-10-29 05:34:48 +00:00
parent 4f133af73c
commit 7003c8da39
13 changed files with 96 additions and 47 deletions

View file

@ -23,6 +23,7 @@
#include "sdl_utils.hpp"
#include "show_dialog.hpp"
#include "sound.hpp"
#include "team.hpp"
#include "tooltips.hpp"
#include "util.hpp"
@ -97,7 +98,7 @@ display::display(unit_map& units, CVideo& video, const gamemap& map,
teams_(t), lastDraw_(0), drawSkips_(0),
invalidateAll_(true), invalidateUnit_(true),
invalidateGameStatus_(true), sideBarBgDrawn_(false),
currentTeam_(0), updatesLocked_(0),
currentTeam_(0), activeTeam_(0), updatesLocked_(0),
turbo_(false), grid_(false), sidebarScaling_(1.0)
{
gameStatusRect_.w = 0;
@ -560,8 +561,8 @@ void display::draw_game_status(int x, int y)
const int expenses = upkeep - teams_[currentTeam_].towers().size();
const int income = teams_[currentTeam_].income() - maximum(expenses,0);
details << string_table["turn"] << ": " << status_.turn() << "/"
<< status_.number_of_turns() << "\n"
details << char(activeTeam_+1) << string_table["turn"] << ": "
<< status_.turn() << "/" << status_.number_of_turns() << "\n"
<< string_table["gold"] << ": "
<< teams_[currentTeam_].gold() << "\n"
<< string_table["villages"] << ": "
@ -2382,6 +2383,13 @@ void display::set_team(size_t team)
currentTeam_ = team;
}
void display::set_playing_team(size_t team)
{
assert(team < teams_.size());
activeTeam_ = team;
invalidate_game_status();
}
void display::set_advancing_unit(const gamemap::location& loc, double amount)
{
advancingUnit_ = loc;

View file

@ -108,6 +108,7 @@ public:
gamemap::TERRAIN get_terrain_on(int palx, int paly, int x, int y);
void set_team(size_t team);
void set_playing_team(size_t team);
void set_advancing_unit(const gamemap::location& loc, double amount);
@ -206,7 +207,7 @@ private:
bool sideBarBgDrawn_;
size_t currentTeam_;
size_t currentTeam_, activeTeam_;
//used to store a unit that is not drawn, because it's currently
//being moved or otherwise changed

View file

@ -105,18 +105,36 @@ manager::~manager()
TTF_Quit();
}
SDL_Rect draw_text_line(display* gui, const SDL_Rect& area, int size,
COLOUR colour, const std::string& text, int x, int y,
SDL_Surface* bg, bool use_tooltips)
const SDL_Color NORMAL_COLOUR = {0xDD,0xDD,0xDD,0},
GOOD_COLOUR = {0x00,0xFF,0x00,0},
BAD_COLOUR = {0xFF,0x00,0x00,0},
BLACK_COLOUR = {0x00,0x00,0x00,0},
BUTTON_COLOUR = {0xFF,0xFF,0x00,0};
const SDL_Color& get_side_colour(int side)
{
static const SDL_Color colours[] =
// neutral good bad black
{ {0xDD,0xDD,0xDD,0}, {0,0xFF,0,0}, {0xFF,0,0,0}, {0,0,0,0},
side -= 1;
// button (yellow)
{0xFF,0xFF,0,0} };
static const SDL_Color sides[] = { {0xAA,0x00,0x00,0},
{0x00,0x00,0xFF,0},
{0x00,0xFF,0x00,0},
{0xFF,0xFF,0x00,0},
{0xFF,0x55,0x55,0},
{0xFF,0x55,0x55,0} };
const SDL_Color& col = colours[colour];
static const size_t nsides = sizeof(sides)/sizeof(*sides);
if(size_t(side) < nsides) {
return sides[side];
} else {
return BLACK_COLOUR;
}
}
SDL_Rect draw_text_line(display* gui, const SDL_Rect& area, int size,
const SDL_Color& colour, const std::string& text,
int x, int y, SDL_Surface* bg, bool use_tooltips)
{
TTF_Font* const font = get_font(size);
if(font == NULL) {
std::cerr << "Could not get font\n";
@ -125,7 +143,7 @@ SDL_Rect draw_text_line(display* gui, const SDL_Rect& area, int size,
return res;
}
scoped_sdl_surface surface(TTF_RenderText_Blended(font,text.c_str(),col));
scoped_sdl_surface surface(TTF_RenderText_Blended(font,text.c_str(),colour));
if(surface == NULL) {
std::cerr << "Could not render ttf: '" << text << "'\n";
SDL_Rect res;
@ -176,8 +194,9 @@ SDL_Rect draw_text_line(display* gui, const SDL_Rect& area, int size,
SDL_Rect draw_text(display* gui, const SDL_Rect& area, int size,
COLOUR colour, const std::string& txt, int x, int y,
SDL_Surface* bg, bool use_tooltips, MARKUP use_markup)
const SDL_Color& colour, const std::string& txt,
int x, int y, SDL_Surface* bg, bool use_tooltips,
MARKUP use_markup)
{
//make sure there's always at least a space, so we can ensure
//that we can return a rectangle for height
@ -194,7 +213,7 @@ SDL_Rect draw_text(display* gui, const SDL_Rect& area, int size,
std::string::const_iterator i2 = std::find(i1,text.end(),'\n');
for(;;) {
if(i1 != i2) {
COLOUR col = colour;
SDL_Color col = colour;
int sz = size;
if(use_markup == USE_MARKUP) {
if(*i1 == '#') {
@ -210,6 +229,11 @@ SDL_Rect draw_text(display* gui, const SDL_Rect& area, int size,
sz -= 2;
++i1;
}
if(i1 != i2 && *i1 >= 1 && *i1 <= 9) {
col = get_side_colour(*i1);
++i1;
}
}
if(i1 != i2) {

View file

@ -27,13 +27,16 @@ struct manager {
~manager();
};
enum COLOUR { NORMAL_COLOUR, GOOD_COLOUR, BAD_COLOUR, BLACK_COLOUR,
BUTTON_COLOUR };
const SDL_Color& get_side_colour(int side);
extern const SDL_Color NORMAL_COLOUR, GOOD_COLOUR, BAD_COLOUR, BLACK_COLOUR,
BUTTON_COLOUR;
enum MARKUP { USE_MARKUP, NO_MARKUP };
SDL_Rect draw_text(display* gui, const SDL_Rect& area, int size, COLOUR colour,
const std::string& text, int x, int y, SDL_Surface* bg=NULL,
SDL_Rect draw_text(display* gui, const SDL_Rect& area, int size,
const SDL_Color& colour, const std::string& text,
int x, int y, SDL_Surface* bg=NULL,
bool use_tooltips=false, MARKUP use_markup=USE_MARKUP);
}

View file

@ -22,7 +22,7 @@ namespace game_config
const int cure_amount = 8;
const int curer_heals_per_turn = 18;
const int recall_cost = 20;
const std::string version = "0.5-RC2";
const std::string version = "0.5-RC3";
bool debug = false;
#ifdef WESNOTH_PATH

View file

@ -40,6 +40,8 @@ LEVEL_RESULT play_level(game_data& gameinfo, config& terrain_config,
std::vector<team> teams;
int first_human_team = -1;
std::vector<config*>& unit_cfg = level->children["side"];
for(std::vector<config*>::iterator ui = unit_cfg.begin();
ui != unit_cfg.end(); ++ui) {
@ -69,6 +71,10 @@ LEVEL_RESULT play_level(game_data& gameinfo, config& terrain_config,
map.starting_position(new_unit.side()), new_unit));
teams.push_back(team(**ui,ngold));
if(first_human_team == -1 && teams.back().is_human()) {
first_human_team = teams.size()-1;
}
//if there are additional starting units on this side
std::vector<config*>& starting_units = (*ui)->children["unit"];
for(std::vector<config*>::iterator su = starting_units.begin();
@ -87,6 +93,11 @@ LEVEL_RESULT play_level(game_data& gameinfo, config& terrain_config,
}
display gui(units,video,map,status,teams);
if(first_human_team != -1) {
gui.set_team(first_human_team);
}
const preferences::display_manager prefs_disp_manager(&gui);
const tooltips::manager tooltips_manager(gui);
@ -146,6 +157,8 @@ LEVEL_RESULT play_level(game_data& gameinfo, config& terrain_config,
team_it != teams.end(); ++team_it) {
const int player_number = (team_it - teams.begin()) + 1;
gui.set_playing_team(size_t(player_number-1));
clear_shroud(gui,map,gameinfo,units,teams,player_number-1);
calculate_healing(gui,map,units,player_number);

View file

@ -1017,14 +1017,11 @@ bool turn_slice(game_data& gameinfo, game_state& state_of_game,
for(size_t n = 0; n != teams.size(); ++n) {
const team_data data = calculate_team_data(teams[n],n+1,units);
const bool on_side = n+1 == size_t(team_num) ||
!current_team.is_enemy(n+1);
std::stringstream str;
if(!on_side)
str << "#";
str << team_name(n+1,units) << ",";
//output the number of the side first, and this will
//cause it to be displayed in the correct colour
str << (char)(n+1) << team_name(n+1,units) << ",";
str << data.villages << ","
<< data.units << ","

View file

@ -591,13 +591,13 @@ TITLE_RESULT show_title(display& screen)
const std::string& version_str = string_table["version"] + " " +
game_config::version;
const SDL_Rect version_area = draw_text(NULL,screen.screen_area(),10,
const SDL_Rect version_area = font::draw_text(NULL,screen.screen_area(),10,
font::NORMAL_COLOUR,version_str,0,0);
const size_t versiony = screen.y() - version_area.h;
if(versiony < size_t(screen.y())) {
draw_text(&screen,screen.screen_area(),10,font::NORMAL_COLOUR,
version_str,0,versiony);
font::draw_text(&screen,screen.screen_area(),10,font::NORMAL_COLOUR,
version_str,0,versiony);
}
const int x = screen.x()/2 - title_surface->w/2;

View file

@ -244,14 +244,3 @@ const std::string& team::music() const
{
return info_.music;
}
std::string get_team_name(int side, const unit_map& units)
{
for(unit_map::const_iterator i = units.begin(); i != units.end(); ++i) {
if(i->second.can_recruit() && i->second.side() == side) {
return i->second.description();
}
}
return "-";
}

View file

@ -164,8 +164,8 @@ void process(int mousex, int mousey, bool lbutton)
}
SDL_Rect draw_text(display* gui, const SDL_Rect& area, int size,
font::COLOUR colour,
const std::string& text, int x, int y, SDL_Surface* bg)
const SDL_Color& colour, const std::string& text,
int x, int y, SDL_Surface* bg)
{
return font::draw_text(gui,area,size,colour,text,x,y,bg,true);
}

View file

@ -2,9 +2,10 @@
#define TOOLTIPS_HPP_INCLUDED
#include "font.hpp"
#include "SDL.h"
#include "video.hpp"
#include "SDL.h"
namespace tooltips {
struct manager
@ -21,8 +22,8 @@ void process(int mousex, int mousey, bool lbutton);
//a function exactly the same as font::draw_text, but will also register
//a tooltip
SDL_Rect draw_text(display* gui, const SDL_Rect& area, int size,
font::COLOUR colour,
const std::string& text, int x, int y, SDL_Surface* bg=NULL);
const SDL_Color& colour, const std::string& text,
int x, int y, SDL_Surface* bg=NULL);
}

View file

@ -729,3 +729,14 @@ team_data calculate_team_data(const team& tm, int side, const unit_map& units)
res.gold = tm.gold();
return res;
}
std::string get_team_name(int side, const unit_map& units)
{
for(unit_map::const_iterator i = units.begin(); i != units.end(); ++i) {
if(i->second.can_recruit() && i->second.side() == side) {
return i->second.description();
}
}
return "-";
}

View file

@ -185,4 +185,6 @@ struct team_data
team_data calculate_team_data(const team& tm, int side, const unit_map& units);
std::string get_team_name(int side, const unit_map& units);
#endif