Lifted unit drawing from game_display to display.
This commit is contained in:
parent
794713802a
commit
72fc103fe9
27 changed files with 541 additions and 421 deletions
|
@ -38,9 +38,6 @@ Version 1.11.0-svn:
|
|||
* Button for default zoom switching.
|
||||
* Space for a second row of editing tools.
|
||||
* Terrain group selection from a menu, saving a lot of space.
|
||||
* Terrain palette
|
||||
* is scaled to fit at all resolutions.
|
||||
* Removed the scrolling feature which is no longer needed.
|
||||
* Map label placement tool
|
||||
|
||||
* Language and i18n:
|
||||
|
|
|
@ -1257,7 +1257,7 @@ private:
|
|||
}
|
||||
|
||||
void display_label(const map_location& location, const std::string& text) const {
|
||||
game_display* gui = game_display::get_singleton();
|
||||
display* gui = display::get_singleton();
|
||||
std::string team_name;
|
||||
|
||||
SDL_Color color = int_to_color(team::get_side_rgb(ai_.get_side()));
|
||||
|
|
|
@ -53,15 +53,15 @@ static lg::log_domain log_ai_testing_ca_global_fallback("ai/ca/global_fallback")
|
|||
|
||||
static void display_label(int /*side*/, const map_location& location, const std::string& text, bool surrounded)
|
||||
{
|
||||
game_display* gui = game_display::get_singleton();
|
||||
std::string team_name;
|
||||
display* gui = display::get_singleton();
|
||||
std::string team_name;
|
||||
|
||||
SDL_Color color = int_to_color(team::get_side_rgb(surrounded ? 2 : 1 ) );//@fixme: for tests
|
||||
SDL_Color color = int_to_color(team::get_side_rgb(surrounded ? 2 : 1 ) );//@fixme: for tests
|
||||
|
||||
const terrain_label *res;
|
||||
res = gui->labels().set_label(location, text, team_name, color);
|
||||
if (res)
|
||||
recorder.add_label(res);
|
||||
const terrain_label *res;
|
||||
res = gui->labels().set_label(location, text, team_name, color);
|
||||
if (res)
|
||||
recorder.add_label(res);
|
||||
}
|
||||
|
||||
|
||||
|
|
230
src/display.cpp
230
src/display.cpp
|
@ -73,10 +73,15 @@ namespace {
|
|||
|
||||
int display::last_zoom_ = SmallZoom;
|
||||
|
||||
display::display(CVideo& video, const gamemap* map, const config& theme_cfg, const config& level) :
|
||||
display::display(unit_map* units, CVideo& video, const gamemap* map, const std::vector<team>* t,const config& theme_cfg, const config& level) :
|
||||
units_(units),
|
||||
exclusive_unit_draw_requests_(),
|
||||
screen_(video),
|
||||
map_(map),
|
||||
currentTeam_(0),
|
||||
teams_(t),
|
||||
viewpoint_(NULL),
|
||||
energy_bar_rects_(),
|
||||
xpos_(0),
|
||||
ypos_(0),
|
||||
theme_(theme_cfg, screen_area()),
|
||||
|
@ -113,6 +118,7 @@ display::display(CVideo& video, const gamemap* map, const config& theme_cfg, con
|
|||
keys_(),
|
||||
animate_map_(true),
|
||||
local_tod_light_(false),
|
||||
activeTeam_(0),
|
||||
drawing_buffer_(),
|
||||
map_screenshot_(false),
|
||||
fps_handle_(0),
|
||||
|
@ -130,6 +136,8 @@ display::display(CVideo& video, const gamemap* map, const config& theme_cfg, con
|
|||
, do_reverse_memcpy_workaround_(false)
|
||||
#endif
|
||||
{
|
||||
singleton_ = this;
|
||||
|
||||
read(level.child_or_empty("display"));
|
||||
|
||||
if(non_interactive()
|
||||
|
@ -162,6 +170,149 @@ display::display(CVideo& video, const gamemap* map, const config& theme_cfg, con
|
|||
|
||||
display::~display()
|
||||
{
|
||||
singleton_ = NULL;
|
||||
}
|
||||
|
||||
struct is_energy_color {
|
||||
bool operator()(Uint32 color) const { return (color&0xFF000000) > 0x10000000 &&
|
||||
(color&0x00FF0000) < 0x00100000 &&
|
||||
(color&0x0000FF00) < 0x00001000 &&
|
||||
(color&0x000000FF) < 0x00000010; }
|
||||
};
|
||||
|
||||
|
||||
const SDL_Rect& display::calculate_energy_bar(surface surf)
|
||||
{
|
||||
const std::map<surface,SDL_Rect>::const_iterator i = energy_bar_rects_.find(surf);
|
||||
if(i != energy_bar_rects_.end()) {
|
||||
return i->second;
|
||||
}
|
||||
|
||||
int first_row = -1, last_row = -1, first_col = -1, last_col = -1;
|
||||
|
||||
surface image(make_neutral_surface(surf));
|
||||
|
||||
const_surface_lock image_lock(image);
|
||||
const Uint32* const begin = image_lock.pixels();
|
||||
|
||||
for(int y = 0; y != image->h; ++y) {
|
||||
const Uint32* const i1 = begin + image->w*y;
|
||||
const Uint32* const i2 = i1 + image->w;
|
||||
const Uint32* const itor = std::find_if(i1,i2,is_energy_color());
|
||||
const int count = std::count_if(itor,i2,is_energy_color());
|
||||
|
||||
if(itor != i2) {
|
||||
if(first_row == -1) {
|
||||
first_row = y;
|
||||
}
|
||||
|
||||
first_col = itor - i1;
|
||||
last_col = first_col + count;
|
||||
last_row = y;
|
||||
}
|
||||
}
|
||||
|
||||
const SDL_Rect res = create_rect(first_col
|
||||
, first_row
|
||||
, last_col-first_col
|
||||
, last_row+1-first_row);
|
||||
energy_bar_rects_.insert(std::pair<surface,SDL_Rect>(surf,res));
|
||||
return calculate_energy_bar(surf);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void display::draw_bar(const std::string& image, int xpos, int ypos,
|
||||
const map_location& loc, size_t height, double filled,
|
||||
const SDL_Color& col, fixed_t alpha)
|
||||
{
|
||||
|
||||
filled = std::min<double>(std::max<double>(filled,0.0),1.0);
|
||||
height = static_cast<size_t>(height*get_zoom_factor());
|
||||
|
||||
surface surf(image::get_image(image,image::SCALED_TO_HEX));
|
||||
|
||||
// We use UNSCALED because scaling (and bilinear interpolaion)
|
||||
// is bad for calculate_energy_bar.
|
||||
// But we will do a geometric scaling later.
|
||||
surface bar_surf(image::get_image(image));
|
||||
if(surf == NULL || bar_surf == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
// calculate_energy_bar returns incorrect results if the surface colors
|
||||
// have changed (for example, due to bilinear interpolaion)
|
||||
const SDL_Rect& unscaled_bar_loc = calculate_energy_bar(bar_surf);
|
||||
|
||||
SDL_Rect bar_loc;
|
||||
if (surf->w == bar_surf->w && surf->h == bar_surf->h)
|
||||
bar_loc = unscaled_bar_loc;
|
||||
else {
|
||||
const fixed_t xratio = fxpdiv(surf->w,bar_surf->w);
|
||||
const fixed_t yratio = fxpdiv(surf->h,bar_surf->h);
|
||||
const SDL_Rect scaled_bar_loc = create_rect(
|
||||
fxptoi(unscaled_bar_loc. x * xratio)
|
||||
, fxptoi(unscaled_bar_loc. y * yratio + 127)
|
||||
, fxptoi(unscaled_bar_loc. w * xratio + 255)
|
||||
, fxptoi(unscaled_bar_loc. h * yratio + 255));
|
||||
bar_loc = scaled_bar_loc;
|
||||
}
|
||||
|
||||
if(height > bar_loc.h) {
|
||||
height = bar_loc.h;
|
||||
}
|
||||
|
||||
//if(alpha != ftofxp(1.0)) {
|
||||
// surf.assign(adjust_surface_alpha(surf,alpha));
|
||||
// if(surf == NULL) {
|
||||
// return;
|
||||
// }
|
||||
//}
|
||||
|
||||
const size_t skip_rows = bar_loc.h - height;
|
||||
|
||||
SDL_Rect top = create_rect(0, 0, surf->w, bar_loc.y);
|
||||
SDL_Rect bot = create_rect(0, bar_loc.y + skip_rows, surf->w, 0);
|
||||
bot.h = surf->w - bot.y;
|
||||
|
||||
drawing_buffer_add(LAYER_UNIT_BAR, loc, xpos, ypos, surf, top);
|
||||
drawing_buffer_add(LAYER_UNIT_BAR, loc, xpos, ypos + top.h, surf, bot);
|
||||
|
||||
size_t unfilled = static_cast<size_t>(height * (1.0 - filled));
|
||||
|
||||
if(unfilled < height && alpha >= ftofxp(0.3)) {
|
||||
const Uint8 r_alpha = std::min<unsigned>(unsigned(fxpmult(alpha,255)),255);
|
||||
surface filled_surf = create_compatible_surface(bar_surf, bar_loc.w, height - unfilled);
|
||||
SDL_Rect filled_area = create_rect(0, 0, bar_loc.w, height-unfilled);
|
||||
sdl_fill_rect(filled_surf,&filled_area,SDL_MapRGBA(bar_surf->format,col.r,col.g,col.b, r_alpha));
|
||||
drawing_buffer_add(LAYER_UNIT_BAR, loc, xpos + bar_loc.x, ypos + bar_loc.y + unfilled, filled_surf);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool display::add_exclusive_draw(const map_location& loc, unit& unit)
|
||||
{
|
||||
if (loc.valid() && exclusive_unit_draw_requests_.find(loc) == exclusive_unit_draw_requests_.end())
|
||||
{
|
||||
exclusive_unit_draw_requests_[loc] = unit.id();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
std::string display::remove_exclusive_draw(const map_location& loc)
|
||||
{
|
||||
std::string id = "";
|
||||
if(loc.valid())
|
||||
{
|
||||
id = exclusive_unit_draw_requests_[loc];
|
||||
//id will be set to the default "" string by the [] operator if the map doesn't have anything for that loc.
|
||||
exclusive_unit_draw_requests_.erase(loc);
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
const time_of_day & display::get_time_of_day(const map_location& /*loc*/) const
|
||||
|
@ -223,6 +374,17 @@ void display::change_map(const gamemap* m)
|
|||
builder_->change_map(m);
|
||||
}
|
||||
|
||||
void display::change_units(unit_map* umap)
|
||||
{
|
||||
units_ = umap;
|
||||
}
|
||||
|
||||
void display::change_teams(const std::vector<team>* teams)
|
||||
{
|
||||
teams_ = teams;
|
||||
}
|
||||
|
||||
|
||||
const SDL_Rect& display::max_map_area() const
|
||||
{
|
||||
static SDL_Rect max_area = {0, 0, 0, 0};
|
||||
|
@ -1438,6 +1600,38 @@ void display::draw_minimap()
|
|||
box_color, screen);
|
||||
}
|
||||
|
||||
void display::draw_minimap_units()
|
||||
{
|
||||
double xscaling = 1.0 * minimap_location_.w / get_map().w();
|
||||
double yscaling = 1.0 * minimap_location_.h / get_map().h();
|
||||
|
||||
for(unit_map::const_iterator u = units_->begin(); u != units_->end(); ++u) {
|
||||
if (fogged(u->get_location()) ||
|
||||
((*teams_)[currentTeam_].is_enemy(u->side()) &&
|
||||
u->invisible(u->get_location())) ||
|
||||
u->get_hidden()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int side = u->side();
|
||||
const SDL_Color col = team::get_minimap_color(side);
|
||||
const Uint32 mapped_col = SDL_MapRGB(video().getSurface()->format,col.r,col.g,col.b);
|
||||
|
||||
double u_x = u->get_location().x * xscaling;
|
||||
double u_y = (u->get_location().y + (is_odd(u->get_location().x) ? 1 : -1)/4.0) * yscaling;
|
||||
// use 4/3 to compensate the horizontal hexes imbrication
|
||||
double u_w = 4.0 / 3.0 * xscaling;
|
||||
double u_h = yscaling;
|
||||
|
||||
SDL_Rect r = create_rect(minimap_location_.x + round_double(u_x)
|
||||
, minimap_location_.y + round_double(u_y)
|
||||
, round_double(u_w)
|
||||
, round_double(u_h));
|
||||
|
||||
sdl_fill_rect(video().getSurface(), &r, mapped_col);
|
||||
}
|
||||
}
|
||||
|
||||
bool display::scroll(int xmove, int ymove)
|
||||
{
|
||||
const int orig_x = xpos_;
|
||||
|
@ -2010,6 +2204,15 @@ void display::draw_invalidated() {
|
|||
}
|
||||
}
|
||||
invalidated_hexes_ += invalidated_.size();
|
||||
|
||||
foreach (const map_location& loc, invalidated_) {
|
||||
unit_map::iterator u_it = units_->find(loc);
|
||||
exclusive_unit_draw_requests_t::iterator request = exclusive_unit_draw_requests_.find(loc);
|
||||
if (u_it != units_->end()
|
||||
&& (request == exclusive_unit_draw_requests_.end() || request->second == u_it->id()))
|
||||
u_it->redraw_unit();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void display::draw_hex(const map_location& loc) {
|
||||
|
@ -2024,10 +2227,10 @@ void display::draw_hex(const map_location& loc) {
|
|||
drawing_buffer_add(LAYER_TERRAIN_BG, loc, xpos, ypos,
|
||||
get_terrain_images(loc,tod.id, image_type, BACKGROUND));
|
||||
|
||||
drawing_buffer_add(LAYER_TERRAIN_FG, loc, xpos, ypos,
|
||||
drawing_buffer_add(LAYER_TERRAIN_FG, loc, xpos, ypos,
|
||||
get_terrain_images(loc,tod.id,image_type, FOREGROUND));
|
||||
|
||||
// Draw the grid, if that's been enabled
|
||||
// Draw the grid, if that's been enabled
|
||||
if(grid_ && on_map && !off_map_tile) {
|
||||
static const image::locator grid_top(game_config::images::grid_top);
|
||||
drawing_buffer_add(LAYER_GRID_TOP, loc, xpos, ypos,
|
||||
|
@ -2458,6 +2661,24 @@ void display::invalidate_animations()
|
|||
invalidate_animations_location(loc);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (unit& u, *units_) {
|
||||
u.refresh();
|
||||
}
|
||||
std::vector<unit*> unit_list;
|
||||
foreach (unit &u, *units_) {
|
||||
unit_list.push_back(&u);
|
||||
}
|
||||
bool new_inval;
|
||||
do {
|
||||
new_inval = false;
|
||||
#ifdef _OPENMP
|
||||
#pragma omp parallel for reduction(|:new_inval) shared(unit_list) schedule(guided)
|
||||
#endif //_OPENMP
|
||||
for(int i=0; i < static_cast<int>(unit_list.size()); i++) {
|
||||
new_inval |= unit_list[i]->invalidate(unit_list[i]->get_location());
|
||||
}
|
||||
}while(new_inval);
|
||||
}
|
||||
|
||||
void display::add_arrow(arrow& arrow)
|
||||
|
@ -2505,3 +2726,6 @@ void display::read(const config& cfg)
|
|||
color_adjust_.g = cfg["color_adjust_green"].to_int(0);
|
||||
color_adjust_.b = cfg["color_adjust_blue_"].to_int(0);
|
||||
}
|
||||
|
||||
display *display::singleton_ = NULL;
|
||||
|
||||
|
|
|
@ -58,9 +58,60 @@ class gamemap;
|
|||
class display
|
||||
{
|
||||
public:
|
||||
display(CVideo& video, const gamemap* map, const config& theme_cfg,
|
||||
const config& level);
|
||||
display(unit_map* units, CVideo& video, const gamemap* map, const std::vector<team>* t,
|
||||
const config& theme_cfg, const config& level);
|
||||
virtual ~display();
|
||||
static display* get_singleton() { return singleton_ ;}
|
||||
|
||||
//TODO sort
|
||||
|
||||
bool show_everything() const { return !viewpoint_; }
|
||||
|
||||
const std::vector<team>& get_teams() {return *teams_;}
|
||||
|
||||
/** The playing team is the team whose turn it is. */
|
||||
size_t playing_team() const { return activeTeam_; }
|
||||
|
||||
bool team_valid() const { return currentTeam_ < teams_->size(); }
|
||||
|
||||
/** The viewing team is the team currently viewing the game. */
|
||||
size_t viewing_team() const { return currentTeam_; }
|
||||
int viewing_side() const { return currentTeam_ + 1; }
|
||||
|
||||
/**
|
||||
* Cancels all the exclusive draw requests.
|
||||
*/
|
||||
void clear_exclusive_draws() { exclusive_unit_draw_requests_.clear(); }
|
||||
unit_map& get_units() {return *units_;}
|
||||
const unit_map& get_const_units() const {return *units_;}
|
||||
|
||||
/**
|
||||
* Allows a unit to request to be the only one drawn in its hex. Useful for situations where
|
||||
* multiple units (one real, multiple temporary) can end up stacked, such as with the whiteboard.
|
||||
* @param loc The location of the unit requesting exclusivity.
|
||||
* @param unit The unit requesting exlusivity.
|
||||
* @return false if there's already an exclusive draw request for this location.
|
||||
*/
|
||||
bool add_exclusive_draw(const map_location& loc, unit& unit);
|
||||
/**
|
||||
* Cancels an exclusive draw request.
|
||||
* @return The id of the unit whose exclusive draw request was canceled, or else
|
||||
* the empty string if there was no exclusive draw request for this location.
|
||||
*/
|
||||
std::string remove_exclusive_draw(const map_location& loc);
|
||||
|
||||
void draw_bar(const std::string& image, int xpos, int ypos,
|
||||
const map_location& loc, size_t height, double filled,
|
||||
const SDL_Color& col, fixed_t alpha);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Updates internals that cache map size. This should be called when the map
|
||||
|
@ -69,6 +120,8 @@ public:
|
|||
void reload_map();
|
||||
|
||||
void change_map(const gamemap* m);
|
||||
void change_teams(const std::vector<team>* teams);
|
||||
void change_units(unit_map* units);
|
||||
|
||||
static Uint32 rgb(Uint8 red, Uint8 green, Uint8 blue)
|
||||
{ return 0xFF000000 | (red << 16) | (green << 8) | blue; }
|
||||
|
@ -291,8 +344,7 @@ public:
|
|||
|
||||
void refresh_report(std::string const &report_name, const config &);
|
||||
|
||||
// Will be overridden in the display subclass
|
||||
virtual void draw_minimap_units() {};
|
||||
void draw_minimap_units();
|
||||
|
||||
/** Function to invalidate all tiles. */
|
||||
void invalidate_all();
|
||||
|
@ -488,7 +540,23 @@ public:
|
|||
private:
|
||||
void read(const config& cfg);
|
||||
|
||||
/**
|
||||
* Finds the start and end rows on the energy bar image.
|
||||
*
|
||||
* White pixels are substituted for the color of the energy.
|
||||
*/
|
||||
const SDL_Rect& calculate_energy_bar(surface surf);
|
||||
|
||||
|
||||
protected:
|
||||
//TODO sort
|
||||
unit_map* units_;
|
||||
|
||||
typedef std::map<map_location, std::string> exclusive_unit_draw_requests_t;
|
||||
/// map of hexes where only one unit should be drawn, the one identified by the associated id string
|
||||
exclusive_unit_draw_requests_t exclusive_unit_draw_requests_;
|
||||
|
||||
|
||||
/** Clear the screen contents */
|
||||
void clear_screen();
|
||||
|
||||
|
@ -569,7 +637,10 @@ protected:
|
|||
|
||||
CVideo& screen_;
|
||||
const gamemap* map_;
|
||||
size_t currentTeam_;
|
||||
const std::vector<team>* teams_;
|
||||
const team *viewpoint_;
|
||||
std::map<surface,SDL_Rect> energy_bar_rects_;
|
||||
int xpos_, ypos_;
|
||||
theme theme_;
|
||||
int zoom_;
|
||||
|
@ -710,6 +781,10 @@ public:
|
|||
SDL_Color color, double x_in_hex=0.5, double y_in_hex=0.5);
|
||||
|
||||
protected:
|
||||
|
||||
//TODO sort
|
||||
size_t activeTeam_;
|
||||
|
||||
/**
|
||||
* In order to render a hex properly it needs to be rendered per row. On
|
||||
* this row several layers need to be drawn at the same time. Mainly the
|
||||
|
@ -871,6 +946,9 @@ private:
|
|||
/** Flag for bug #17573 - this is set in the constructor **/
|
||||
bool do_reverse_memcpy_workaround_;
|
||||
#endif
|
||||
|
||||
protected:
|
||||
static display * singleton_;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -42,13 +42,11 @@ editor_action* editor_action_unit::perform(map_context& mc) const
|
|||
return undo.release();
|
||||
}
|
||||
|
||||
void editor_action_unit::perform_without_undo(map_context& /*mc*/) const
|
||||
void editor_action_unit::perform_without_undo(map_context& mc) const
|
||||
{
|
||||
/*
|
||||
mc.get_units().add(loc_,u_);
|
||||
mc.get_units().find(loc_)->set_location(loc_);
|
||||
mc.get_map().get_units().add(loc_,u_);
|
||||
mc.get_map().get_units().find(loc_)->set_location(loc_);
|
||||
mc.add_changed_location(loc_);
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
|
@ -57,13 +55,13 @@ editor_action_unit_delete* editor_action_unit_delete::clone() const
|
|||
return new editor_action_unit_delete(*this);
|
||||
}
|
||||
|
||||
editor_action* editor_action_unit_delete::perform(map_context& /*mc*/) const
|
||||
editor_action* editor_action_unit_delete::perform(map_context& mc) const
|
||||
{
|
||||
std::auto_ptr<editor_action> undo;
|
||||
// boost::scoped_ptr<editor_action> undo;
|
||||
//boost::scoped_ptr<editor_action> undo;
|
||||
|
||||
/*
|
||||
unit_map& units = mc.get_units();
|
||||
|
||||
unit_map& units = mc.get_map().get_units();
|
||||
unit_map::const_unit_iterator unit_it = units.find(loc_);
|
||||
|
||||
if (unit_it != units.end()) {
|
||||
|
@ -71,21 +69,19 @@ editor_action* editor_action_unit_delete::perform(map_context& /*mc*/) const
|
|||
perform_without_undo(mc);
|
||||
return undo.release();
|
||||
} else { return NULL; }
|
||||
*/
|
||||
|
||||
|
||||
return NULL; //can't be reached
|
||||
}
|
||||
|
||||
void editor_action_unit_delete::perform_without_undo(map_context& /*mc*/) const
|
||||
void editor_action_unit_delete::perform_without_undo(map_context& mc) const
|
||||
{
|
||||
/*
|
||||
unit_map& units = mc.get_units();
|
||||
unit_map& units = mc.get_map().get_units();
|
||||
if (!units.erase(loc_)) {
|
||||
ERR_ED << "Could not delete unit on " << loc_.x << "/" << loc_.y << "\n";
|
||||
} else {
|
||||
mc.add_changed_location(loc_);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
|
@ -102,18 +98,18 @@ editor_action* editor_action_unit_replace::perform(map_context& mc) const
|
|||
return undo.release();
|
||||
}
|
||||
|
||||
void editor_action_unit_replace::perform_without_undo(map_context& /*mc*/) const
|
||||
void editor_action_unit_replace::perform_without_undo(map_context& mc) const
|
||||
{
|
||||
//unit_map& units = mc.get_map().get_units();
|
||||
//units.move(loc_, new_loc_);
|
||||
//unit::clear_status_caches();
|
||||
unit_map& units = mc.get_map().get_units();
|
||||
units.move(loc_, new_loc_);
|
||||
unit::clear_status_caches();
|
||||
|
||||
//unit& u = *units.find(new_loc_);
|
||||
unit& u = *units.find(new_loc_);
|
||||
//TODO do we still need set_standing?
|
||||
//u.set_standing();
|
||||
u.set_standing();
|
||||
|
||||
//mc.add_changed_location(loc_);
|
||||
//mc.add_changed_location(new_loc_);
|
||||
mc.add_changed_location(loc_);
|
||||
mc.add_changed_location(new_loc_);
|
||||
|
||||
/* @todo
|
||||
if (mc.get_map().is_village(new_loc_)) {
|
||||
|
@ -140,17 +136,15 @@ editor_action* editor_action_unit_facing::perform(map_context& mc) const
|
|||
return undo.release();
|
||||
}
|
||||
|
||||
void editor_action_unit_facing::perform_without_undo(map_context& /*mc*/) const
|
||||
void editor_action_unit_facing::perform_without_undo(map_context& mc) const
|
||||
{
|
||||
/*
|
||||
unit_map& units = mc.get_units();
|
||||
unit_map::const_unit_iterator unit_it = units.find(loc_);
|
||||
unit_map& units = mc.get_map().get_units();
|
||||
unit_map::unit_iterator unit_it = units.find(loc_);
|
||||
|
||||
if (unit_it != units.end()) {
|
||||
unit_it->set_facing(new_direction_);
|
||||
unit_it->set_standing();
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -31,22 +31,23 @@ editor_action* mouse_action_unit::click_left(editor_display& disp, int x, int y)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
//const unit_map& units = disp.get_editor_map().get_const_units();
|
||||
const unit_map& units = disp.map().get_units();
|
||||
|
||||
|
||||
/*
|
||||
const unit_map::const_unit_iterator unit_it = units.find(start_hex_);
|
||||
if (unit_it != units.end()) {
|
||||
set_mouse_overlay_surface(disp, unit_it->still_image());
|
||||
//set_mouse_overlay_surface(disp, unit_it->still_image());
|
||||
//TODO set the mouse pointer to a dragging one.
|
||||
}
|
||||
*/
|
||||
|
||||
click_ = true;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
editor_action* mouse_action_unit::drag_left(editor_display& /*disp*/, int /*x*/, int /*y*/, bool& /*partial*/, editor_action* /*last_undo*/)
|
||||
{
|
||||
click_ = false;
|
||||
//TODO
|
||||
//click_ = false;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -58,49 +59,22 @@ editor_action* mouse_action_unit::up_left(editor_display& disp, int x, int y)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
//const unit_map& units = disp.get_editor_map().get_const_units();
|
||||
// const unit_map::const_unit_iterator unit_it = units.find(start_hex_);
|
||||
unit_type type = unit_palette_.selected_fg_item();
|
||||
|
||||
/*
|
||||
if (unit_it != units.end()) {
|
||||
//TODO open the modify unit dialog
|
||||
return NULL;
|
||||
}
|
||||
*/
|
||||
|
||||
gui2::tunit_create create_dlg;
|
||||
create_dlg.show(disp.video());
|
||||
|
||||
if(create_dlg.no_choice()) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const std::string& type_id = create_dlg.choice();
|
||||
const std::string& type_id = type.id();
|
||||
const unit_type *new_unit_type = unit_types.find(type_id);
|
||||
if (!new_unit_type) {
|
||||
//TODO rewrite the error message.
|
||||
ERR_ED << "create unit dialog returned inexistent or unusable unit_type id '" << type_id << "'\n";
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const unit_type &ut = *new_unit_type;
|
||||
unit_race::GENDER gender = create_dlg.gender();
|
||||
// Do not try to set bad genders, may mess up l10n
|
||||
// FIXME: is this actually necessary?
|
||||
if(ut.genders().end() == std::find(ut.genders().begin(), ut.genders().end(), gender)) {
|
||||
gender = ut.genders().front();
|
||||
}
|
||||
unit_race::GENDER gender = ut.genders().front();
|
||||
|
||||
//TODO
|
||||
//bool canrecruit = disp.map().get_teams()[disp.playing_side_index() ].no_leader();
|
||||
//if (canrecruit) disp.map().get_teams()[disp.get_playing_team() ].have_leader(true);
|
||||
// FIXME: This may NOT work as intended, as the unit_map to add the unit to cannot be specified.
|
||||
// Blame silene for removing that argument from unit's constructors
|
||||
//unit u(&disp.map().get_const_units(), utp, disp.playing_side(), false, gender, canrecruit);
|
||||
// unit u(utp, disp.playing_side(), false, gender, canrecruit);
|
||||
//unit new_unit(new_unit_type, disp.playing_side(), true, gender);
|
||||
//editor_action* action = new editor_action_unit(hex, new_unit);
|
||||
//return action;
|
||||
return NULL;
|
||||
unit new_unit(new_unit_type, 1, true, gender);
|
||||
editor_action* action = new editor_action_unit(hex, new_unit);
|
||||
return action;
|
||||
}
|
||||
|
||||
editor_action* mouse_action_unit::drag_end_left(editor_display& disp, int x, int y)
|
||||
|
@ -141,35 +115,36 @@ editor_action* mouse_action_unit::drag_right(editor_display& disp, int x, int y,
|
|||
|
||||
map_location hex = disp.hex_clicked_on(x, y);
|
||||
if (previous_move_hex_ != hex) {
|
||||
//const unit_map& units = disp.get_editor_map().get_const_units();
|
||||
const unit_map& units = disp.map().get_units();
|
||||
|
||||
// const unit_map::const_unit_iterator unit_it = units.find(start_hex_);
|
||||
// if (unit_it != units.end()) {
|
||||
// for (map_location::DIRECTION new_direction = map_location::NORTH;
|
||||
// new_direction <= map_location::NORTH_WEST;
|
||||
// new_direction = map_location::DIRECTION(new_direction +1)){
|
||||
// if (unit_it->get_location().get_direction(new_direction, 1) == hex) {
|
||||
// // unit_it->set_facing(new_direction);
|
||||
// // unit_it->set_standing();
|
||||
// new_direction_ = new_direction;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
const unit_map::const_unit_iterator unit_it = units.find(start_hex_);
|
||||
if (unit_it != units.end()) {
|
||||
for (map_location::DIRECTION new_direction = map_location::NORTH;
|
||||
new_direction <= map_location::NORTH_WEST;
|
||||
new_direction = map_location::DIRECTION(new_direction +1)){
|
||||
if (unit_it->get_location().get_direction(new_direction, 1) == hex) {
|
||||
//TODO
|
||||
// unit_it->set_facing(new_direction);
|
||||
// unit_it->set_standing();
|
||||
new_direction_ = new_direction;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
editor_action* mouse_action_unit::up_right(editor_display& /*disp*/, int /*x*/, int /*y*/)
|
||||
editor_action* mouse_action_unit::up_right(editor_display& disp, int /*x*/, int /*y*/)
|
||||
{
|
||||
if (!click_) return NULL;
|
||||
click_ = false;
|
||||
|
||||
//const unit_map& units = disp.get_editor_map().get_const_units();
|
||||
// const unit_map::const_unit_iterator unit_it = units.find(start_hex_);
|
||||
/* if (unit_it != units.end()) {
|
||||
const unit_map& units = disp.map().get_units();
|
||||
const unit_map::const_unit_iterator unit_it = units.find(start_hex_);
|
||||
if (unit_it != units.end()) {
|
||||
return new editor_action_unit_delete(start_hex_);
|
||||
}
|
||||
*/
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -183,12 +158,11 @@ editor_action* mouse_action_unit::drag_end_right(editor_display& disp, int x, in
|
|||
|
||||
if(new_direction_ != old_direction_) {
|
||||
|
||||
//const unit_map& units = disp.get_editor_map().get_const_units();
|
||||
// const unit_map::const_unit_iterator unit_it = units.find(start_hex_);
|
||||
// if (unit_it != units.end()) {
|
||||
// return new editor_action_unit_facing(start_hex_, new_direction_, old_direction_);
|
||||
// }
|
||||
|
||||
const unit_map& units = disp.map().get_units();
|
||||
const unit_map::const_unit_iterator unit_it = units.find(start_hex_);
|
||||
if (unit_it != units.end()) {
|
||||
return new editor_action_unit_facing(start_hex_, new_direction_, old_direction_);
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
|
|
|
@ -35,6 +35,7 @@ public:
|
|||
, start_hex_()
|
||||
, old_direction_(map_location::NORTH)
|
||||
, new_direction_(map_location::NORTH)
|
||||
, unit_palette_(palette)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -86,6 +87,7 @@ private:
|
|||
map_location start_hex_;
|
||||
map_location::DIRECTION old_direction_;
|
||||
map_location::DIRECTION new_direction_;
|
||||
unit_palette& unit_palette_;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -39,6 +39,8 @@
|
|||
#include "../rng.hpp"
|
||||
#include "../sound.hpp"
|
||||
|
||||
#include "halo.hpp"
|
||||
|
||||
#include <boost/bind.hpp>
|
||||
|
||||
namespace {
|
||||
|
@ -54,7 +56,7 @@ editor_controller::editor_controller(const config &game_config, CVideo& video)
|
|||
, active_menu_(editor::MAP)
|
||||
, rng_(NULL)
|
||||
, rng_setter_(NULL)
|
||||
, gui_(new editor_display(video, NULL, get_theme(game_config, "editor"), config()))
|
||||
, gui_(new editor_display(NULL, video, NULL, NULL, get_theme(game_config, "editor"), config()))
|
||||
, tods_()
|
||||
, context_manager_(new context_manager(*gui_.get(), game_config_))
|
||||
, toolkit_()
|
||||
|
@ -98,12 +100,15 @@ editor_controller::editor_controller(const config &game_config, CVideo& video)
|
|||
void editor_controller::init_gui()
|
||||
{
|
||||
gui_->change_map(&context_manager_->get_map());
|
||||
gui_->change_units(&context_manager_->get_map().get_units());
|
||||
gui_->change_teams(&context_manager_->get_map().get_teams());
|
||||
gui_->set_grid(preferences::grid());
|
||||
prefs_disp_manager_.reset(new preferences::display_manager(&gui()));
|
||||
gui_->add_redraw_observer(boost::bind(&editor_controller::display_redraw_callback, this, _1));
|
||||
floating_label_manager_.reset(new font::floating_label_context());
|
||||
gui().set_draw_coordinates(preferences::editor::draw_hex_coordinates());
|
||||
gui().set_draw_terrain_codes(preferences::editor::draw_terrain_codes());
|
||||
halo_manager_.reset(new halo::manager(*gui_));
|
||||
}
|
||||
|
||||
void editor_controller::init_tods(const config& game_config)
|
||||
|
@ -272,9 +277,9 @@ bool editor_controller::can_execute_command(hotkey::HOTKEY_COMMAND command, int
|
|||
case HOTKEY_EDITOR_TOOL_SELECT:
|
||||
case HOTKEY_EDITOR_TOOL_STARTING_POSITION:
|
||||
case HOTKEY_EDITOR_TOOL_LABEL:
|
||||
//TODO unit selection is not always possible
|
||||
return true;
|
||||
case HOTKEY_EDITOR_TOOL_UNIT:
|
||||
return true; //tool selection always possible
|
||||
return !context_manager_->get_map().get_teams().empty();
|
||||
case HOTKEY_EDITOR_CUT:
|
||||
case HOTKEY_EDITOR_COPY:
|
||||
case HOTKEY_EDITOR_EXPORT_SELECTION_COORDS:
|
||||
|
|
|
@ -48,6 +48,10 @@ namespace preferences {
|
|||
struct display_manager;
|
||||
} // namespace preferences
|
||||
|
||||
namespace halo {
|
||||
struct manager;
|
||||
} // namespace halo
|
||||
|
||||
namespace editor {
|
||||
|
||||
class editor_map;
|
||||
|
@ -210,9 +214,12 @@ class editor_controller : public controller_base,
|
|||
|
||||
boost::scoped_ptr<rand_rng::set_random_generator> rng_setter_;
|
||||
|
||||
unit_map units_;
|
||||
|
||||
/** The display object used and owned by the editor. */
|
||||
boost::scoped_ptr<editor_display> gui_;
|
||||
|
||||
std::vector<team> teams_;
|
||||
|
||||
/** Pre-defined time of day lighting settings for the settings dialog */
|
||||
std::vector<time_of_day> tods_;
|
||||
|
@ -226,6 +233,8 @@ class editor_controller : public controller_base,
|
|||
tooltips::manager tooltip_manager_;
|
||||
boost::scoped_ptr<font::floating_label_context> floating_label_manager_;
|
||||
|
||||
boost::scoped_ptr<halo::manager> halo_manager_;
|
||||
|
||||
/** Quit main loop flag */
|
||||
bool do_quit_;
|
||||
EXIT_STATUS quit_mode_;
|
||||
|
|
|
@ -19,9 +19,9 @@
|
|||
|
||||
namespace editor {
|
||||
|
||||
editor_display::editor_display(CVideo& video, const editor_map* map,
|
||||
const config& theme_cfg, const config& level)
|
||||
: display(video, map, theme_cfg, level)
|
||||
editor_display::editor_display(unit_map* units, CVideo& video, const editor_map* map,
|
||||
const std::vector<team>* t, const config& theme_cfg, const config& level)
|
||||
: display(units, video, map, t, theme_cfg, level)
|
||||
, brush_locations_()
|
||||
, toolbar_hint_()
|
||||
, palette_report_()
|
||||
|
|
|
@ -24,8 +24,8 @@ namespace editor {
|
|||
class editor_display : public display
|
||||
{
|
||||
public:
|
||||
editor_display(CVideo& video, const editor_map* map, const config& theme_cfg,
|
||||
const config& level);
|
||||
editor_display(unit_map* units, CVideo& video, const editor_map* map,
|
||||
const std::vector<team>* t, const config& theme_cfg, const config& level);
|
||||
|
||||
bool in_editor() const { return true; }
|
||||
|
||||
|
|
|
@ -57,7 +57,16 @@ public:
|
|||
}
|
||||
void refresh() {
|
||||
ec_.gui().change_map(&ec_.get_map());
|
||||
resources::game_map = &ec_.get_map();
|
||||
ec_.gui().change_units(&ec_.get_map().get_units());
|
||||
resources::units = &ec_.get_map().get_units();
|
||||
// TODO register the tod_manager with the gui?
|
||||
resources::tod_manager = &ec_.get_map().get_time_manager();
|
||||
ec_.gui().change_teams(&ec_.get_map().get_teams());
|
||||
resources::teams = &ec_.get_map().get_teams();
|
||||
ec_.reload_map();
|
||||
|
||||
resources::state_of_game = &ec_.get_map().get_game_state();
|
||||
}
|
||||
private:
|
||||
context_manager& ec_;
|
||||
|
|
|
@ -52,10 +52,27 @@ editor_map::editor_map(const config& terrain_cfg, const config& level, const dis
|
|||
: gamemap(terrain_cfg, level)
|
||||
, selection_()
|
||||
, labels_(disp, NULL)
|
||||
, units_()
|
||||
, teams_()
|
||||
, tod_manager_(level)
|
||||
{
|
||||
labels_.read(level);
|
||||
//labels_.disp().re
|
||||
//labels_.disp().d
|
||||
|
||||
foreach (const config& side, level.child_range("side"))
|
||||
{
|
||||
team t;
|
||||
t.build(side, *this, 100);
|
||||
//this is done because we don't count as observer is there is a human controller
|
||||
t.change_controller("null");
|
||||
//TODO alternative? : gamestatus::teambuilder
|
||||
|
||||
teams_.push_back(t);
|
||||
foreach (const config &a_unit, side.child_range("unit")) {
|
||||
map_location loc(a_unit, NULL);
|
||||
units_.add(loc, unit(a_unit, true));
|
||||
}
|
||||
}
|
||||
|
||||
sanity_check();
|
||||
}
|
||||
|
||||
|
|
|
@ -20,6 +20,9 @@
|
|||
|
||||
#include "../../map.hpp"
|
||||
#include "../../map_label.hpp"
|
||||
#include "unit_map.hpp"
|
||||
#include "tod_manager.hpp"
|
||||
#include "gamestatus.hpp"
|
||||
|
||||
#include <deque>
|
||||
|
||||
|
@ -73,6 +76,29 @@ class editor_map : public gamemap
|
|||
{
|
||||
public:
|
||||
|
||||
/** Get the team from the current map context object */
|
||||
std::vector<team>& get_teams() {
|
||||
return teams_;
|
||||
}
|
||||
|
||||
/** Get the unit map from the current map context object */
|
||||
unit_map& get_units() {
|
||||
return units_;
|
||||
}
|
||||
|
||||
const unit_map& get_units() const {
|
||||
return units_;
|
||||
}
|
||||
|
||||
tod_manager& get_time_manager() {
|
||||
return tod_manager_;
|
||||
}
|
||||
|
||||
game_state& get_game_state() {
|
||||
return state_;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Empty map constructor
|
||||
*/
|
||||
|
@ -217,10 +243,21 @@ protected:
|
|||
private:
|
||||
|
||||
/**
|
||||
* The labels of this map _context.
|
||||
* The labels of this map.
|
||||
*/
|
||||
map_labels labels_;
|
||||
|
||||
/**
|
||||
* TODO
|
||||
*/
|
||||
unit_map units_;
|
||||
|
||||
std::vector<team> teams_;
|
||||
|
||||
tod_manager tod_manager_;
|
||||
|
||||
game_state state_;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -87,6 +87,11 @@ public:
|
|||
|
||||
common_palette& active_palette(); //{ return (*mouse_action_)->get_palette(); };
|
||||
|
||||
//TODO
|
||||
// terrain_palette* terrain_palette() { return terrain_palette_; };
|
||||
// unit_palette* unit_palette() { return unit_palette_; };
|
||||
// empty_palette* empty_palette() { return empty_palette_; };
|
||||
|
||||
private:
|
||||
|
||||
editor_display& gui_;
|
||||
|
|
|
@ -59,21 +59,15 @@ std::map<map_location,fixed_t> game_display::debugHighlights_;
|
|||
game_display::game_display(unit_map& units, CVideo& video, const gamemap& map,
|
||||
const tod_manager& tod, const std::vector<team>& t,
|
||||
const config& theme_cfg, const config& level) :
|
||||
display(video, &map, theme_cfg, level),
|
||||
units_(units),
|
||||
display(&units, video, &map, &t, theme_cfg, level),
|
||||
fake_units_(),
|
||||
exclusive_unit_draw_requests_(),
|
||||
attack_indicator_src_(),
|
||||
attack_indicator_dst_(),
|
||||
energy_bar_rects_(),
|
||||
route_(),
|
||||
tod_manager_(tod),
|
||||
teams_(t),
|
||||
level_(level),
|
||||
displayedUnitHex_(),
|
||||
overlays_(),
|
||||
currentTeam_(0),
|
||||
activeTeam_(0),
|
||||
sidebarScaling_(1.0),
|
||||
first_turn_(true),
|
||||
in_game_(false),
|
||||
|
@ -85,18 +79,17 @@ game_display::game_display(unit_map& units, CVideo& video, const gamemap& map,
|
|||
game_mode_(RUNNING),
|
||||
flags_()
|
||||
{
|
||||
singleton_ = this;
|
||||
|
||||
// Inits the flag list and the team colors used by ~TC
|
||||
flags_.reserve(teams_.size());
|
||||
flags_.reserve(teams_->size());
|
||||
|
||||
std::vector<std::string> side_colors;
|
||||
side_colors.reserve(teams_.size());
|
||||
side_colors.reserve(teams_->size());
|
||||
|
||||
for(size_t i = 0; i != teams_.size(); ++i) {
|
||||
for(size_t i = 0; i != teams_->size(); ++i) {
|
||||
std::string side_color = team::get_side_color_index(i+1);
|
||||
side_colors.push_back(side_color);
|
||||
std::string flag = teams_[i].flag();
|
||||
std::string flag = (*teams_)[i].flag();
|
||||
std::string old_rgb = game_config::flag_rgb;
|
||||
std::string new_rgb = side_color;
|
||||
|
||||
|
@ -151,7 +144,6 @@ game_display::~game_display()
|
|||
{
|
||||
// SDL_FreeSurface(minimap_);
|
||||
prune_chat_messages(true);
|
||||
singleton_ = NULL;
|
||||
}
|
||||
|
||||
void game_display::new_turn()
|
||||
|
@ -217,15 +209,15 @@ void game_display::highlight_hex(map_location hex)
|
|||
{
|
||||
wb::future_map future; //< Lasts for whole method.
|
||||
|
||||
const unit *u = get_visible_unit(hex, teams_[viewing_team()], !viewpoint_);
|
||||
const unit *u = get_visible_unit(hex, (*teams_)[viewing_team()], !viewpoint_);
|
||||
if (u) {
|
||||
displayedUnitHex_ = hex;
|
||||
invalidate_unit();
|
||||
} else {
|
||||
u = get_visible_unit(mouseoverHex_, teams_[viewing_team()], !viewpoint_);
|
||||
u = get_visible_unit(mouseoverHex_, (*teams_)[viewing_team()], !viewpoint_);
|
||||
if (u) {
|
||||
// mouse moved from unit hex to non-unit hex
|
||||
if (units_.count(selectedHex_)) {
|
||||
if (units_->count(selectedHex_)) {
|
||||
displayedUnitHex_ = selectedHex_;
|
||||
invalidate_unit();
|
||||
}
|
||||
|
@ -244,7 +236,7 @@ void game_display::display_unit_hex(map_location hex)
|
|||
|
||||
wb::future_map future; //< Lasts for whole method.
|
||||
|
||||
const unit *u = get_visible_unit(hex, teams_[viewing_team()], !viewpoint_);
|
||||
const unit *u = get_visible_unit(hex, (*teams_)[viewing_team()], !viewpoint_);
|
||||
if (u) {
|
||||
displayedUnitHex_ = hex;
|
||||
invalidate_unit();
|
||||
|
@ -263,7 +255,7 @@ void game_display::scroll_to_leader(unit_map& units, int side, SCROLL_TYPE scrol
|
|||
{
|
||||
unit_map::const_iterator leader = units.find_leader(side);
|
||||
|
||||
if(leader != units_.end()) {
|
||||
if(leader != units_->end()) {
|
||||
// YogiHH: I can't see why we need another key_handler here,
|
||||
// therefore I will comment it out :
|
||||
/*
|
||||
|
@ -295,14 +287,6 @@ void game_display::draw_invalidated()
|
|||
temp_unit->redraw_unit();
|
||||
}
|
||||
|
||||
foreach (const map_location& loc, invalidated_) {
|
||||
unit_map::iterator u_it = units_.find(loc);
|
||||
exclusive_unit_draw_requests_t::iterator request = exclusive_unit_draw_requests_.find(loc);
|
||||
if (u_it != units_.end()
|
||||
&& (request == exclusive_unit_draw_requests_.end() || request->second == u_it->id()))
|
||||
u_it->redraw_unit();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void game_display::post_commit()
|
||||
|
@ -324,7 +308,7 @@ void game_display::draw_hex(const map_location& loc)
|
|||
|
||||
if(on_map && loc == mouseoverHex_) {
|
||||
tdrawing_layer hex_top_layer = LAYER_MOUSEOVER_BOTTOM;
|
||||
if( get_visible_unit(loc, teams_[viewing_team()] ) != NULL ) {
|
||||
if( get_visible_unit(loc, (*teams_)[viewing_team()] ) != NULL ) {
|
||||
hex_top_layer = LAYER_MOUSEOVER_TOP;
|
||||
}
|
||||
drawing_buffer_add( hex_top_layer,
|
||||
|
@ -338,7 +322,7 @@ void game_display::draw_hex(const map_location& loc)
|
|||
std::pair<Itor,Itor> overlays = overlays_.equal_range(loc);
|
||||
for( ; overlays.first != overlays.second; ++overlays.first) {
|
||||
if ((overlays.first->second.team_name == "" ||
|
||||
overlays.first->second.team_name.find(teams_[playing_team()].team_name()) != std::string::npos)
|
||||
overlays.first->second.team_name.find((*teams_)[playing_team()].team_name()) != std::string::npos)
|
||||
&& !(is_fogged && !overlays.first->second.visible_in_fog))
|
||||
{
|
||||
drawing_buffer_add(LAYER_TERRAIN_BG, loc, xpos, ypos,
|
||||
|
@ -431,7 +415,7 @@ void game_display::draw_sidebar()
|
|||
draw_report("report_clock");
|
||||
draw_report("report_countdown");
|
||||
|
||||
if(teams_.empty()) {
|
||||
if(teams_->empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -448,104 +432,6 @@ void game_display::draw_sidebar()
|
|||
}
|
||||
}
|
||||
|
||||
void game_display::draw_minimap_units()
|
||||
{
|
||||
double xscaling = 1.0 * minimap_location_.w / get_map().w();
|
||||
double yscaling = 1.0 * minimap_location_.h / get_map().h();
|
||||
|
||||
for(unit_map::const_iterator u = units_.begin(); u != units_.end(); ++u) {
|
||||
if (fogged(u->get_location()) ||
|
||||
(teams_[currentTeam_].is_enemy(u->side()) &&
|
||||
u->invisible(u->get_location())) ||
|
||||
u->get_hidden()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
int side = u->side();
|
||||
const SDL_Color col = team::get_minimap_color(side);
|
||||
const Uint32 mapped_col = SDL_MapRGB(video().getSurface()->format,col.r,col.g,col.b);
|
||||
|
||||
double u_x = u->get_location().x * xscaling;
|
||||
double u_y = (u->get_location().y + (is_odd(u->get_location().x) ? 1 : -1)/4.0) * yscaling;
|
||||
// use 4/3 to compensate the horizontal hexes imbrication
|
||||
double u_w = 4.0 / 3.0 * xscaling;
|
||||
double u_h = yscaling;
|
||||
|
||||
SDL_Rect r = create_rect(minimap_location_.x + round_double(u_x)
|
||||
, minimap_location_.y + round_double(u_y)
|
||||
, round_double(u_w)
|
||||
, round_double(u_h));
|
||||
|
||||
sdl_fill_rect(video().getSurface(), &r, mapped_col);
|
||||
}
|
||||
}
|
||||
|
||||
void game_display::draw_bar(const std::string& image, int xpos, int ypos,
|
||||
const map_location& loc, size_t height, double filled,
|
||||
const SDL_Color& col, fixed_t alpha)
|
||||
{
|
||||
|
||||
filled = std::min<double>(std::max<double>(filled,0.0),1.0);
|
||||
height = static_cast<size_t>(height*get_zoom_factor());
|
||||
|
||||
surface surf(image::get_image(image,image::SCALED_TO_HEX));
|
||||
|
||||
// We use UNSCALED because scaling (and bilinear interpolaion)
|
||||
// is bad for calculate_energy_bar.
|
||||
// But we will do a geometric scaling later.
|
||||
surface bar_surf(image::get_image(image));
|
||||
if(surf == NULL || bar_surf == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
// calculate_energy_bar returns incorrect results if the surface colors
|
||||
// have changed (for example, due to bilinear interpolaion)
|
||||
const SDL_Rect& unscaled_bar_loc = calculate_energy_bar(bar_surf);
|
||||
|
||||
SDL_Rect bar_loc;
|
||||
if (surf->w == bar_surf->w && surf->h == bar_surf->h)
|
||||
bar_loc = unscaled_bar_loc;
|
||||
else {
|
||||
const fixed_t xratio = fxpdiv(surf->w,bar_surf->w);
|
||||
const fixed_t yratio = fxpdiv(surf->h,bar_surf->h);
|
||||
const SDL_Rect scaled_bar_loc = create_rect(
|
||||
fxptoi(unscaled_bar_loc. x * xratio)
|
||||
, fxptoi(unscaled_bar_loc. y * yratio + 127)
|
||||
, fxptoi(unscaled_bar_loc. w * xratio + 255)
|
||||
, fxptoi(unscaled_bar_loc. h * yratio + 255));
|
||||
bar_loc = scaled_bar_loc;
|
||||
}
|
||||
|
||||
if(height > bar_loc.h) {
|
||||
height = bar_loc.h;
|
||||
}
|
||||
|
||||
//if(alpha != ftofxp(1.0)) {
|
||||
// surf.assign(adjust_surface_alpha(surf,alpha));
|
||||
// if(surf == NULL) {
|
||||
// return;
|
||||
// }
|
||||
//}
|
||||
|
||||
const size_t skip_rows = bar_loc.h - height;
|
||||
|
||||
SDL_Rect top = create_rect(0, 0, surf->w, bar_loc.y);
|
||||
SDL_Rect bot = create_rect(0, bar_loc.y + skip_rows, surf->w, 0);
|
||||
bot.h = surf->w - bot.y;
|
||||
|
||||
drawing_buffer_add(LAYER_UNIT_BAR, loc, xpos, ypos, surf, top);
|
||||
drawing_buffer_add(LAYER_UNIT_BAR, loc, xpos, ypos + top.h, surf, bot);
|
||||
|
||||
size_t unfilled = static_cast<size_t>(height * (1.0 - filled));
|
||||
|
||||
if(unfilled < height && alpha >= ftofxp(0.3)) {
|
||||
const Uint8 r_alpha = std::min<unsigned>(unsigned(fxpmult(alpha,255)),255);
|
||||
surface filled_surf = create_compatible_surface(bar_surf, bar_loc.w, height - unfilled);
|
||||
SDL_Rect filled_area = create_rect(0, 0, bar_loc.w, height-unfilled);
|
||||
sdl_fill_rect(filled_surf,&filled_area,SDL_MapRGBA(bar_surf->format,col.r,col.g,col.b, r_alpha));
|
||||
drawing_buffer_add(LAYER_UNIT_BAR, loc, xpos + bar_loc.x, ypos + bar_loc.y + unfilled, filled_surf);
|
||||
}
|
||||
}
|
||||
|
||||
void game_display::set_game_mode(const tgame_mode game_mode)
|
||||
{
|
||||
|
@ -565,8 +451,8 @@ void game_display::draw_movement_info(const map_location& loc)
|
|||
&& !route_.steps.empty() && route_.steps.front() != loc) {
|
||||
const unit_map::const_iterator un =
|
||||
resources::whiteboard->get_temp_move_unit().valid() ?
|
||||
resources::whiteboard->get_temp_move_unit() : units_.find(route_.steps.front());
|
||||
if(un != units_.end()) {
|
||||
resources::whiteboard->get_temp_move_unit() : units_->find(route_.steps.front());
|
||||
if(un != units_->end()) {
|
||||
// Display the def% of this terrain
|
||||
int def = 100 - un->defense_modifier(get_map().get_terrain(loc));
|
||||
std::stringstream def_text;
|
||||
|
@ -612,7 +498,7 @@ void game_display::draw_movement_info(const map_location& loc)
|
|||
{
|
||||
const unit_map::const_iterator selectedUnit = find_visible_unit(selectedHex_,resources::teams->at(currentTeam_));
|
||||
const unit_map::const_iterator mouseoveredUnit = find_visible_unit(mouseoverHex_,resources::teams->at(currentTeam_));
|
||||
if(selectedUnit != units_.end() && mouseoveredUnit == units_.end()) {
|
||||
if(selectedUnit != units_->end() && mouseoveredUnit == units_->end()) {
|
||||
// Display the def% of this terrain
|
||||
int def = 100 - selectedUnit->defense_modifier(get_map().get_terrain(loc));
|
||||
std::stringstream def_text;
|
||||
|
@ -652,8 +538,8 @@ std::vector<surface> game_display::footsteps_images(const map_location& loc)
|
|||
|
||||
// Check which footsteps images of game_config we will use
|
||||
int move_cost = 1;
|
||||
const unit_map::const_iterator u = units_.find(route_.steps.front());
|
||||
if(u != units_.end()) {
|
||||
const unit_map::const_iterator u = units_->find(route_.steps.front());
|
||||
if(u != units_->end()) {
|
||||
move_cost = u->movement_cost(get_map().get_terrain(loc));
|
||||
}
|
||||
int image_number = std::min<int>(move_cost, game_config::foot_speed_prefix.size());
|
||||
|
@ -711,9 +597,9 @@ surface game_display::get_flag(const map_location& loc)
|
|||
return surface(NULL);
|
||||
}
|
||||
|
||||
for(size_t i = 0; i != teams_.size(); ++i) {
|
||||
if(teams_[i].owns_village(loc) &&
|
||||
(!fogged(loc) || !teams_[currentTeam_].is_enemy(i+1)))
|
||||
for(size_t i = 0; i != teams_->size(); ++i) {
|
||||
if((*teams_)[i].owns_village(loc) &&
|
||||
(!fogged(loc) || !(*teams_)[currentTeam_].is_enemy(i+1)))
|
||||
{
|
||||
flags_[i].update_last_draw_time();
|
||||
const image::locator &image_flag = animate_map_ ?
|
||||
|
@ -828,57 +714,11 @@ void game_display::float_label(const map_location& loc, const std::string& text,
|
|||
font::add_floating_label(flabel);
|
||||
}
|
||||
|
||||
struct is_energy_color {
|
||||
bool operator()(Uint32 color) const { return (color&0xFF000000) > 0x10000000 &&
|
||||
(color&0x00FF0000) < 0x00100000 &&
|
||||
(color&0x0000FF00) < 0x00001000 &&
|
||||
(color&0x000000FF) < 0x00000010; }
|
||||
};
|
||||
|
||||
const SDL_Rect& game_display::calculate_energy_bar(surface surf)
|
||||
{
|
||||
const std::map<surface,SDL_Rect>::const_iterator i = energy_bar_rects_.find(surf);
|
||||
if(i != energy_bar_rects_.end()) {
|
||||
return i->second;
|
||||
}
|
||||
|
||||
int first_row = -1, last_row = -1, first_col = -1, last_col = -1;
|
||||
|
||||
surface image(make_neutral_surface(surf));
|
||||
|
||||
const_surface_lock image_lock(image);
|
||||
const Uint32* const begin = image_lock.pixels();
|
||||
|
||||
for(int y = 0; y != image->h; ++y) {
|
||||
const Uint32* const i1 = begin + image->w*y;
|
||||
const Uint32* const i2 = i1 + image->w;
|
||||
const Uint32* const itor = std::find_if(i1,i2,is_energy_color());
|
||||
const int count = std::count_if(itor,i2,is_energy_color());
|
||||
|
||||
if(itor != i2) {
|
||||
if(first_row == -1) {
|
||||
first_row = y;
|
||||
}
|
||||
|
||||
first_col = itor - i1;
|
||||
last_col = first_col + count;
|
||||
last_row = y;
|
||||
}
|
||||
}
|
||||
|
||||
const SDL_Rect res = create_rect(first_col
|
||||
, first_row
|
||||
, last_col-first_col
|
||||
, last_row+1-first_row);
|
||||
energy_bar_rects_.insert(std::pair<surface,SDL_Rect>(surf,res));
|
||||
return calculate_energy_bar(surf);
|
||||
}
|
||||
|
||||
void game_display::invalidate_animations_location(const map_location& loc) {
|
||||
if (get_map().is_village(loc)) {
|
||||
const int owner = player_teams::village_owner(loc);
|
||||
if (owner >= 0 && flags_[owner].need_update()
|
||||
&& (!fogged(loc) || !teams_[currentTeam_].is_enemy(owner+1))) {
|
||||
&& (!fogged(loc) || !(*teams_)[currentTeam_].is_enemy(owner+1))) {
|
||||
invalidate(loc);
|
||||
}
|
||||
}
|
||||
|
@ -887,16 +727,10 @@ void game_display::invalidate_animations_location(const map_location& loc) {
|
|||
void game_display::invalidate_animations()
|
||||
{
|
||||
display::invalidate_animations();
|
||||
foreach (unit& u, units_) {
|
||||
u.refresh();
|
||||
}
|
||||
foreach(unit* temp_unit, fake_units_) {
|
||||
temp_unit->refresh();
|
||||
}
|
||||
std::vector<unit*> unit_list;
|
||||
foreach (unit &u, units_) {
|
||||
unit_list.push_back(&u);
|
||||
}
|
||||
foreach (unit *u, fake_units_) {
|
||||
unit_list.push_back(u);
|
||||
}
|
||||
|
@ -980,31 +814,6 @@ int game_display::remove_temporary_unit(unit *u)
|
|||
return removed;
|
||||
}
|
||||
|
||||
bool game_display::add_exclusive_draw(const map_location& loc, unit& unit)
|
||||
{
|
||||
if (loc.valid() && exclusive_unit_draw_requests_.find(loc) == exclusive_unit_draw_requests_.end())
|
||||
{
|
||||
exclusive_unit_draw_requests_[loc] = unit.id();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
std::string game_display::remove_exclusive_draw(const map_location& loc)
|
||||
{
|
||||
std::string id = "";
|
||||
if(loc.valid())
|
||||
{
|
||||
id = exclusive_unit_draw_requests_[loc];
|
||||
//id will be set to the default "" string by the [] operator if the map doesn't have anything for that loc.
|
||||
exclusive_unit_draw_requests_.erase(loc);
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
void game_display::set_attack_indicator(const map_location& src, const map_location& dst)
|
||||
{
|
||||
if (attack_indicator_src_ != src || attack_indicator_dst_ != dst) {
|
||||
|
@ -1067,8 +876,8 @@ void game_display::remove_single_overlay(const map_location& loc, const std::str
|
|||
|
||||
void game_display::parse_team_overlays()
|
||||
{
|
||||
const team& curr_team = teams_[playing_team()];
|
||||
const team& prev_team = teams_[playing_team()-1 < teams_.size() ? playing_team()-1 : teams_.size()-1];
|
||||
const team& curr_team = (*teams_)[playing_team()];
|
||||
const team& prev_team = (*teams_)[playing_team()-1 < teams_->size() ? playing_team()-1 : teams_->size()-1];
|
||||
foreach (const game_display::overlay_map::value_type i, overlays_) {
|
||||
const overlay& ov = i.second;
|
||||
if (!ov.team_name.empty() &&
|
||||
|
@ -1084,7 +893,7 @@ std::string game_display::current_team_name() const
|
|||
{
|
||||
if (team_valid())
|
||||
{
|
||||
return teams_[currentTeam_].team_name();
|
||||
return (*teams_)[currentTeam_].team_name();
|
||||
}
|
||||
return std::string();
|
||||
}
|
||||
|
@ -1294,12 +1103,12 @@ void game_display::send_notification(const std::string& /*owner*/, const std::st
|
|||
|
||||
void game_display::set_team(size_t teamindex, bool show_everything)
|
||||
{
|
||||
assert(teamindex < teams_.size());
|
||||
assert(teamindex < teams_->size());
|
||||
currentTeam_ = teamindex;
|
||||
if (!show_everything)
|
||||
{
|
||||
labels().set_team(&teams_[teamindex]);
|
||||
viewpoint_ = &teams_[teamindex];
|
||||
labels().set_team(&(*teams_)[teamindex]);
|
||||
viewpoint_ = &(*teams_)[teamindex];
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1313,7 +1122,7 @@ void game_display::set_team(size_t teamindex, bool show_everything)
|
|||
|
||||
void game_display::set_playing_team(size_t teamindex)
|
||||
{
|
||||
assert(teamindex < teams_.size());
|
||||
assert(teamindex < teams_->size());
|
||||
activeTeam_ = teamindex;
|
||||
invalidate_game_status();
|
||||
}
|
||||
|
@ -1481,5 +1290,5 @@ void game_display::prune_chat_messages(bool remove_all)
|
|||
}
|
||||
}
|
||||
|
||||
game_display *game_display::singleton_ = NULL;
|
||||
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ public:
|
|||
static game_display* create_dummy_display(CVideo& video);
|
||||
|
||||
~game_display();
|
||||
static game_display* get_singleton() { return singleton_ ;}
|
||||
static game_display* get_singleton() { return (game_display*)singleton_ ;}
|
||||
|
||||
|
||||
/**
|
||||
|
@ -157,7 +157,6 @@ protected:
|
|||
*/
|
||||
void invalidate_animations_location(const map_location& loc);
|
||||
|
||||
virtual void draw_minimap_units();
|
||||
|
||||
public:
|
||||
/** A temporary unit that can be placed on the map.
|
||||
|
@ -208,25 +207,7 @@ private:
|
|||
int remove_temporary_unit(unit *u);
|
||||
public:
|
||||
|
||||
/**
|
||||
* Allows a unit to request to be the only one drawn in its hex. Useful for situations where
|
||||
* multiple units (one real, multiple temporary) can end up stacked, such as with the whiteboard.
|
||||
* @param loc The location of the unit requesting exclusivity.
|
||||
* @param unit The unit requesting exlusivity.
|
||||
* @return false if there's already an exclusive draw request for this location.
|
||||
*/
|
||||
bool add_exclusive_draw(const map_location& loc, unit& unit);
|
||||
/**
|
||||
* Cancels an exclusive draw request.
|
||||
* @return The id of the unit whose exclusive draw request was canceled, or else
|
||||
* the empty string if there was no exclusive draw request for this location.
|
||||
*/
|
||||
std::string remove_exclusive_draw(const map_location& loc);
|
||||
|
||||
/**
|
||||
* Cancels all the exclusive draw requests.
|
||||
*/
|
||||
void clear_exclusive_draws() { exclusive_unit_draw_requests_.clear(); }
|
||||
|
||||
/** Set the attack direction indicator. */
|
||||
void set_attack_indicator(const map_location& src, const map_location& dst);
|
||||
|
@ -275,13 +256,10 @@ public:
|
|||
*/
|
||||
void set_team(size_t team, bool observe=false);
|
||||
void set_playing_team(size_t team);
|
||||
const std::vector<team>& get_teams() {return teams_;}
|
||||
|
||||
unit_map& get_units() {return units_;}
|
||||
const unit_map& get_const_units() const {return units_;}
|
||||
|
||||
const map_location &displayed_unit_hex() const { return displayedUnitHex_; }
|
||||
bool show_everything() const { return !viewpoint_; }
|
||||
|
||||
|
||||
/**
|
||||
* annotate hex with number, useful for debugging or UI prototype
|
||||
|
@ -289,15 +267,11 @@ public:
|
|||
static int& debug_highlight(const map_location& loc);
|
||||
static void clear_debug_highlights() { debugHighlights_.clear(); }
|
||||
|
||||
/** The viewing team is the team currently viewing the game. */
|
||||
size_t viewing_team() const { return currentTeam_; }
|
||||
int viewing_side() const { return currentTeam_ + 1; }
|
||||
|
||||
/** The playing team is the team whose turn it is. */
|
||||
size_t playing_team() const { return activeTeam_; }
|
||||
int playing_side() const { return activeTeam_ + 1; }
|
||||
|
||||
bool team_valid() const { return currentTeam_ < teams_.size(); }
|
||||
|
||||
std::string current_team_name() const;
|
||||
|
||||
void add_observer(const std::string& name) { observers_.insert(name); }
|
||||
|
@ -311,9 +285,7 @@ public:
|
|||
void begin_game();
|
||||
|
||||
virtual bool in_game() const { return in_game_; }
|
||||
void draw_bar(const std::string& image, int xpos, int ypos,
|
||||
const map_location& loc, size_t height, double filled,
|
||||
const SDL_Color& col, fixed_t alpha);
|
||||
|
||||
|
||||
/**
|
||||
* Sets the linger mode for the display.
|
||||
|
@ -340,33 +312,19 @@ private:
|
|||
// This surface must be freed by the caller
|
||||
surface get_flag(const map_location& loc);
|
||||
|
||||
unit_map& units_;
|
||||
|
||||
/// collection of units destined to be drawn but not put into the unit map
|
||||
std::deque<unit*> fake_units_;
|
||||
|
||||
typedef std::map<map_location, std::string> exclusive_unit_draw_requests_t;
|
||||
/// map of hexes where only one unit should be drawn, the one identified by the associated id string
|
||||
exclusive_unit_draw_requests_t exclusive_unit_draw_requests_;
|
||||
|
||||
// Locations of the attack direction indicator's parts
|
||||
map_location attack_indicator_src_;
|
||||
map_location attack_indicator_dst_;
|
||||
|
||||
/**
|
||||
* Finds the start and end rows on the energy bar image.
|
||||
*
|
||||
* White pixels are substituted for the color of the energy.
|
||||
*/
|
||||
const SDL_Rect& calculate_energy_bar(surface surf);
|
||||
std::map<surface,SDL_Rect> energy_bar_rects_;
|
||||
|
||||
|
||||
pathfind::marked_route route_;
|
||||
|
||||
const tod_manager& tod_manager_;
|
||||
|
||||
const std::vector<team>& teams_;
|
||||
|
||||
const config& level_;
|
||||
|
||||
void invalidate_route();
|
||||
|
@ -388,7 +346,7 @@ private:
|
|||
|
||||
overlay_map overlays_;
|
||||
|
||||
size_t currentTeam_, activeTeam_;
|
||||
|
||||
|
||||
double sidebarScaling_;
|
||||
|
||||
|
@ -425,7 +383,7 @@ private:
|
|||
/** Animated flags for each team */
|
||||
std::vector<animated<image::locator> > flags_;
|
||||
|
||||
static game_display * singleton_;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -420,7 +420,7 @@ void twindow::update_screen_size()
|
|||
settings::gamemap_width = settings::screen_width;
|
||||
settings::gamemap_height = settings::screen_height;
|
||||
|
||||
game_display* display = game_display::get_singleton();
|
||||
display* display = display::get_singleton();
|
||||
if(display) {
|
||||
const unsigned w = display->map_outside_area().w;
|
||||
const unsigned h = display->map_outside_area().h;
|
||||
|
|
|
@ -19,10 +19,11 @@
|
|||
#include "map_location.hpp"
|
||||
#include "font.hpp"
|
||||
#include "tstring.hpp"
|
||||
#include "team.hpp"
|
||||
|
||||
class config;
|
||||
class display;
|
||||
class team;
|
||||
//class team;
|
||||
class terrain_label;
|
||||
|
||||
|
||||
|
|
21
src/unit.cpp
21
src/unit.cpp
|
@ -1743,7 +1743,7 @@ const surface unit::still_image(bool scaled) const
|
|||
|
||||
void unit::set_standing(bool with_bars)
|
||||
{
|
||||
game_display *disp = game_display::get_singleton();
|
||||
display *disp = display::get_singleton();
|
||||
if (preferences::show_standing_animations()&& !incapacitated()) {
|
||||
start_animation(INT_MAX, choose_animation(*disp, loc_, "standing"),
|
||||
with_bars, "", 0, STATE_STANDING);
|
||||
|
@ -1755,28 +1755,28 @@ void unit::set_standing(bool with_bars)
|
|||
|
||||
void unit::set_ghosted(bool with_bars)
|
||||
{
|
||||
game_display *disp = game_display::get_singleton();
|
||||
display *disp = display::get_singleton();
|
||||
start_animation(INT_MAX, choose_animation(*disp, loc_, "ghosted"),
|
||||
with_bars);
|
||||
}
|
||||
|
||||
void unit::set_disabled_ghosted(bool with_bars)
|
||||
{
|
||||
game_display *disp = game_display::get_singleton();
|
||||
display *disp = display::get_singleton();
|
||||
start_animation(INT_MAX, choose_animation(*disp, loc_, "disabled_ghosted"),
|
||||
with_bars);
|
||||
}
|
||||
|
||||
void unit::set_idling()
|
||||
{
|
||||
game_display *disp = game_display::get_singleton();
|
||||
display *disp = display::get_singleton();
|
||||
start_animation(INT_MAX, choose_animation(*disp, loc_, "idling"),
|
||||
true, "", 0, STATE_FORGET);
|
||||
}
|
||||
|
||||
void unit::set_selecting()
|
||||
{
|
||||
const game_display *disp = game_display::get_singleton();
|
||||
const display *disp = display::get_singleton();
|
||||
if (preferences::show_standing_animations() && !get_state(STATE_PETRIFIED)) {
|
||||
start_animation(INT_MAX, choose_animation(*disp, loc_, "selected"),
|
||||
true, "", 0, STATE_FORGET);
|
||||
|
@ -1789,7 +1789,7 @@ void unit::set_selecting()
|
|||
void unit::start_animation(int start_time, const unit_animation *animation,
|
||||
bool with_bars, const std::string &text, Uint32 text_color, STATE state)
|
||||
{
|
||||
const game_display * disp = game_display::get_singleton();
|
||||
const display * disp = display::get_singleton();
|
||||
state_ = state;
|
||||
if (!animation) {
|
||||
if (state != STATE_STANDING)
|
||||
|
@ -1823,7 +1823,7 @@ void unit::set_facing(map_location::DIRECTION dir) {
|
|||
|
||||
void unit::redraw_unit()
|
||||
{
|
||||
game_display &disp = *game_display::get_singleton();
|
||||
display &disp = *display::get_singleton();
|
||||
const gamemap &map = disp.get_map();
|
||||
|
||||
if ( hidden_ || !is_visible_to_team(disp.get_teams()[disp.viewing_team()],disp.show_everything(),map) )
|
||||
|
@ -2000,6 +2000,7 @@ void unit::redraw_unit()
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
assert(orb_img != NULL);
|
||||
surface orb(image::get_image(*orb_img,image::SCALED_TO_ZOOM));
|
||||
if (orb != NULL) {
|
||||
|
@ -2068,7 +2069,7 @@ bool unit::invalidate(const map_location &loc)
|
|||
// Very early calls, anim not initialized yet
|
||||
if(get_animation()) {
|
||||
frame_parameters params;
|
||||
const game_display * disp = game_display::get_singleton();
|
||||
const display * disp = display::get_singleton();
|
||||
const gamemap & map = disp->get_map();
|
||||
const t_translation::t_terrain terrain = map.get_terrain(loc);
|
||||
const terrain_type& terrain_info = map.get_terrain_info(terrain);
|
||||
|
@ -2698,7 +2699,7 @@ std::string unit::absolute_image() const {
|
|||
return cfg_["image_icon"].empty() ? cfg_["image"] : cfg_["image_icon"];
|
||||
}
|
||||
|
||||
const unit_animation* unit::choose_animation(const game_display& disp, const map_location& loc,const std::string& event,
|
||||
const unit_animation* unit::choose_animation(const display& disp, const map_location& loc,const std::string& event,
|
||||
const map_location& second_loc,const int value,const unit_animation::hit_type hit,
|
||||
const attack_type* attack, const attack_type* second_attack, int swing_num) const
|
||||
{
|
||||
|
@ -2912,7 +2913,7 @@ void unit::refresh()
|
|||
set_standing();
|
||||
return;
|
||||
}
|
||||
game_display &disp = *game_display::get_singleton();
|
||||
display &disp = *display::get_singleton();
|
||||
if (state_ != STATE_STANDING || get_current_animation_tick() < next_idling_ ||
|
||||
!disp.tile_nearly_on_screen(loc_) || incapacitated())
|
||||
{
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
#include "unit_types.hpp"
|
||||
#include "unit_map.hpp"
|
||||
|
||||
class game_display;
|
||||
class display;
|
||||
class game_state;
|
||||
class vconfig;
|
||||
class team;
|
||||
|
@ -290,7 +290,7 @@ public:
|
|||
unit_type::ALIGNMENT alignment() const { return alignment_; }
|
||||
const unit_race* race() const { return race_; }
|
||||
|
||||
const unit_animation* choose_animation(const game_display& disp,
|
||||
const unit_animation* choose_animation(const display& disp,
|
||||
const map_location& loc, const std::string& event,
|
||||
const map_location& second_loc = map_location::null_location,
|
||||
const int damage=0,
|
||||
|
|
|
@ -263,7 +263,7 @@ unit_animation::unit_animation(const config& cfg,const std::string& frame_string
|
|||
|
||||
}
|
||||
|
||||
int unit_animation::matches(const game_display &disp,const map_location& loc,const map_location& second_loc, const unit* my_unit,const std::string & event,const int value,hit_type hit,const attack_type* attack,const attack_type* second_attack, int value2) const
|
||||
int unit_animation::matches(const display &disp,const map_location& loc,const map_location& second_loc, const unit* my_unit,const std::string & event,const int value,hit_type hit,const attack_type* attack,const attack_type* second_attack, int value2) const
|
||||
{
|
||||
int result = base_score_;
|
||||
if(!event.empty()&&!event_.empty()) {
|
||||
|
@ -906,7 +906,7 @@ void unit_animation::clear_haloes()
|
|||
bool unit_animation::invalidate(frame_parameters& value)
|
||||
{
|
||||
if(invalidated_) return false;
|
||||
game_display*disp = game_display::get_singleton();
|
||||
display*disp = display::get_singleton();
|
||||
bool complete_redraw =disp->tile_nearly_on_screen(src_) || disp->tile_nearly_on_screen(dst_);
|
||||
if(overlaped_hex_.empty()) {
|
||||
if(complete_redraw) {
|
||||
|
@ -1003,7 +1003,7 @@ void unit_animator::add_animation(unit* animated_unit
|
|||
{
|
||||
if(!animated_unit) return;
|
||||
anim_elem tmp;
|
||||
game_display*disp = game_display::get_singleton();
|
||||
display*disp = display::get_singleton();
|
||||
tmp.my_unit = animated_unit;
|
||||
tmp.text = text;
|
||||
tmp.text_color = text_color;
|
||||
|
@ -1053,7 +1053,7 @@ void unit_animator::replace_anim_if_invalid(unit* animated_unit
|
|||
, int value2)
|
||||
{
|
||||
if(!animated_unit) return;
|
||||
game_display*disp = game_display::get_singleton();
|
||||
display*disp = display::get_singleton();
|
||||
if(animated_unit->get_animation() &&
|
||||
!animated_unit->get_animation()->animation_finished_potential() &&
|
||||
animated_unit->get_animation()->matches(*disp,src,dst,animated_unit,event,value,hit_type,attack,second_attack,value2) >unit_animation::MATCH_FAIL) {
|
||||
|
@ -1104,7 +1104,7 @@ bool unit_animator::would_end() const
|
|||
}
|
||||
void unit_animator::wait_until(int animation_time) const
|
||||
{
|
||||
game_display*disp = game_display::get_singleton();
|
||||
display*disp = display::get_singleton();
|
||||
double speed = disp->turbo_speed();
|
||||
resources::controller->play_slice(false);
|
||||
int end_tick = animated_units_[0].my_unit->get_animation()->time_to_tick(animation_time);
|
||||
|
@ -1124,7 +1124,7 @@ void unit_animator::wait_for_end() const
|
|||
{
|
||||
if (game_config::no_delay) return;
|
||||
bool finished = false;
|
||||
game_display*disp = game_display::get_singleton();
|
||||
display*disp = display::get_singleton();
|
||||
while(!finished) {
|
||||
resources::controller->play_slice(false);
|
||||
disp->delay(10);
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
#include "unit_frame.hpp"
|
||||
|
||||
class attack_type;
|
||||
class game_display;
|
||||
class display;
|
||||
class unit;
|
||||
|
||||
class unit_animation
|
||||
|
@ -35,7 +35,7 @@ class unit_animation
|
|||
static void fill_initial_animations( std::vector<unit_animation> & animations, const config & cfg);
|
||||
static void add_anims( std::vector<unit_animation> & animations, const config & cfg);
|
||||
|
||||
int matches(const game_display &disp,const map_location& loc,const map_location& second_loc,const unit* my_unit,const std::string & event="",const int value=0,hit_type hit=INVALID,const attack_type* attack=NULL,const attack_type* second_attack = NULL, int value2 =0) const;
|
||||
int matches(const display &disp,const map_location& loc,const map_location& second_loc,const unit* my_unit,const std::string & event="",const int value=0,hit_type hit=INVALID,const attack_type* attack=NULL,const attack_type* second_attack = NULL, int value2 =0) const;
|
||||
|
||||
|
||||
const unit_frame& get_last_frame() const{ return unit_anim_.get_last_frame() ; };
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
|
||||
static void teleport_unit_between( const map_location& a, const map_location& b, unit& temp_unit)
|
||||
{
|
||||
game_display* disp = game_display::get_singleton();
|
||||
display* disp = display::get_singleton();
|
||||
if(!disp || disp->video().update_locked() || disp->video().faked() || (disp->fogged(a) && disp->fogged(b))) {
|
||||
return;
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ static void teleport_unit_between( const map_location& a, const map_location& b,
|
|||
|
||||
static void move_unit_between(const map_location& a, const map_location& b, unit& temp_unit,unsigned int step_num,unsigned int step_left)
|
||||
{
|
||||
game_display* disp = game_display::get_singleton();
|
||||
display* disp = display::get_singleton();
|
||||
if(!disp || disp->video().update_locked() || disp->video().faked() || (disp->fogged(a) && disp->fogged(b))) {
|
||||
return;
|
||||
}
|
||||
|
@ -231,7 +231,7 @@ void reset_helpers(const unit *attacker,const unit *defender);
|
|||
void unit_draw_weapon(const map_location& loc, unit& attacker,
|
||||
const attack_type* attack,const attack_type* secondary_attack, const map_location& defender_loc,unit* defender)
|
||||
{
|
||||
game_display* disp = game_display::get_singleton();
|
||||
display* disp = display::get_singleton();
|
||||
if(!disp ||disp->video().update_locked() || disp->video().faked() || disp->fogged(loc) || preferences::show_combat() == false) {
|
||||
return;
|
||||
}
|
||||
|
@ -247,7 +247,7 @@ void unit_draw_weapon(const map_location& loc, unit& attacker,
|
|||
void unit_sheath_weapon(const map_location& primary_loc, unit* primary_unit,
|
||||
const attack_type* primary_attack,const attack_type* secondary_attack, const map_location& secondary_loc,unit* secondary_unit)
|
||||
{
|
||||
game_display* disp = game_display::get_singleton();
|
||||
display* disp = display::get_singleton();
|
||||
if(!disp ||disp->video().update_locked() || disp->video().faked() || disp->fogged(primary_loc) || preferences::show_combat() == false) {
|
||||
return;
|
||||
}
|
||||
|
@ -277,7 +277,7 @@ void unit_sheath_weapon(const map_location& primary_loc, unit* primary_unit,
|
|||
void unit_die(const map_location& loc, unit& loser,
|
||||
const attack_type* attack,const attack_type* secondary_attack, const map_location& winner_loc,unit* winner)
|
||||
{
|
||||
game_display* disp = game_display::get_singleton();
|
||||
display* disp = display::get_singleton();
|
||||
if(!disp ||disp->video().update_locked() || disp->video().faked() || disp->fogged(loc) || preferences::show_combat() == false) {
|
||||
return;
|
||||
}
|
||||
|
@ -303,7 +303,7 @@ void unit_attack(
|
|||
const attack_type& attack, const attack_type* secondary_attack,
|
||||
int swing,std::string hit_text,int drain_amount,std::string att_text)
|
||||
{
|
||||
game_display* disp = game_display::get_singleton();
|
||||
display* disp = display::get_singleton();
|
||||
if(!disp ||disp->video().update_locked() || disp->video().faked() ||
|
||||
(disp->fogged(a) && disp->fogged(b)) || preferences::show_combat() == false) {
|
||||
return;
|
||||
|
@ -412,7 +412,7 @@ void unit_attack(
|
|||
// private helper function, set all helpers to default position
|
||||
void reset_helpers(const unit *attacker,const unit *defender)
|
||||
{
|
||||
game_display* disp = game_display::get_singleton();
|
||||
display* disp = display::get_singleton();
|
||||
unit_map& units = disp->get_units();
|
||||
if(attacker) {
|
||||
unit_ability_list leaders = attacker->get_abilities("leadership");
|
||||
|
|
|
@ -516,7 +516,7 @@ void unit_frame::redraw(const int frame_time,bool first_time,const map_location
|
|||
// you need to add a '/n'
|
||||
// if (tmp_offset) std::cout << (int)(tmp_offset*100) << ",";
|
||||
|
||||
int d2 = game_display::get_singleton()->hex_size() / 2;
|
||||
int d2 = display::get_singleton()->hex_size() / 2;
|
||||
if(first_time ) {
|
||||
// stuff sthat should be done only once per frame
|
||||
if(!current_data.sound.empty() ) {
|
||||
|
@ -621,7 +621,7 @@ void unit_frame::redraw(const int frame_time,bool first_time,const map_location
|
|||
}
|
||||
std::set<map_location> unit_frame::get_overlaped_hex(const int frame_time,const map_location & src,const map_location & dst,const frame_parameters & animation_val,const frame_parameters & engine_val) const
|
||||
{
|
||||
game_display* disp = game_display::get_singleton();
|
||||
display* disp = display::get_singleton();
|
||||
const int xsrc = disp->get_location_x(src);
|
||||
const int ysrc = disp->get_location_y(src);
|
||||
const int xdst = disp->get_location_x(dst);
|
||||
|
|
|
@ -77,7 +77,7 @@ public:
|
|||
//this function returns a random animation out of the possible
|
||||
//animations for this attack. It will not return the same attack
|
||||
//each time.
|
||||
const unit_animation* animation(const game_display& disp, const map_location& loc,const unit* my_unit,const unit_animation::hit_type hit,const attack_type* secondary_attack,int swing_num,int damage) const;
|
||||
const unit_animation* animation(const display& disp, const map_location& loc,const unit* my_unit,const unit_animation::hit_type hit,const attack_type* secondary_attack,int swing_num,int damage) const;
|
||||
private:
|
||||
config cfg_;
|
||||
t_string description_;
|
||||
|
|
Loading…
Add table
Reference in a new issue