16 #define GETTEXT_DOMAIN "wesnoth-lib"
35 #define DBG_DP LOG_STREAM(debug, log_display)
36 #define WRN_DP LOG_STREAM(warn, log_display)
44 const std::map<map_location, unsigned int>* reach_map,
45 bool ignore_terrain_disabled)
48 const bool preferences_minimap_draw_terrain =
prefs::get().minimap_draw_terrain() || ignore_terrain_disabled;
49 const bool preferences_minimap_terrain_coding =
prefs::get().minimap_terrain_coding();
50 const bool preferences_minimap_draw_villages =
prefs::get().minimap_draw_villages();
51 const bool preferences_minimap_draw_units =
prefs::get().minimap_draw_units();
52 const bool preferences_minimap_unit_coding =
prefs::get().minimap_movement_coding();
54 const int scale = (preferences_minimap_draw_terrain && preferences_minimap_terrain_coding) ? 24 : 4;
56 DBG_DP <<
"Creating minimap: " <<
static_cast<int>(map.
w() *
scale * 0.75) <<
", " << map.
h() *
scale;
58 const std::size_t map_width =
static_cast<size_t>(std::max(0, map.
w())) *
scale * 3 / 4;
59 const std::size_t map_height =
static_cast<size_t>(std::max(0, map.
h())) *
scale;
62 if(map_width == 0 || map_height == 0) {
67 if(!preferences_minimap_draw_villages && !preferences_minimap_draw_terrain) {
75 return is_blindfolded || (vw && vw->
shrouded(loc));
80 return vw && !shrouded(loc) && vw->
fogged(loc);
100 texture minimap(map_width, map_height, SDL_TEXTUREACCESS_TARGET);
115 if(preferences_minimap_draw_terrain) {
117 const bool highlighted = reach_map && reach_map->count(loc) != 0 && !shrouded(loc);
123 rect dest = get_dst_rect(loc);
128 if(preferences_minimap_terrain_coding) {
130 const std::string base_file =
"terrain/" + terrain_info.
minimap_image() +
".png";
136 if(tile && map.
tdata()->get_terrain_info(terrain).is_combined()
147 using namespace std::string_literals;
171 col = it->second.rep();
176 for(
const auto& underlying_terrain : map.
tdata()->underlying_union_terrain(terrain)) {
177 const std::string& terrain_id = map.
tdata()->get_terrain_info(underlying_terrain).id();
184 color_t tmp = it->second.rep();
187 tmp.r = std::max(0, tmp.r - 50);
188 tmp.g = std::max(0, tmp.g - 50);
189 tmp.b = std::max(0, tmp.b - 50);
193 tmp.r = std::min(255, tmp.r + 50);
194 tmp.g = std::min(255, tmp.g + 50);
195 tmp.b = std::min(255, tmp.b + 50);
202 col.r = col.r - (col.r - tmp.r) / 2;
203 col.g = col.g - (col.g - tmp.g) / 2;
204 col.b = col.b - (col.b - tmp.b) / 2;
208 dest.w =
scale * 3 / 4;
217 if(preferences_minimap_draw_villages) {
219 if(is_blindfolded || (vw && (vw->
shrouded(loc) || vw->
fogged(loc)))) {
228 col = iter->second.min();
235 if(preferences_minimap_unit_coding || !vw) {
248 rect dest = get_dst_rect(loc);
249 dest.w =
scale * 3 / 4;
258 if(units && preferences_minimap_draw_units && !is_blindfolded) {
259 for(
const auto& u : *units) {
261 const int side = u.side();
262 const bool is_enemy = vw && vw->
is_enemy(side);
264 if((vw && vw->
fogged(u_loc)) || (is_enemy && disp && u.invisible(u_loc)) || u.get_hidden()) {
270 if(!preferences_minimap_unit_coding) {
275 }
else if(vw && vw->
side() == side) {
284 rect fillrect = get_dst_rect(u_loc);
285 fillrect.w =
scale * 3 / 4;
292 DBG_DP <<
"done generating minimap";
298 const double scale_ratio = std::min<double>(
304 const int scaled_w =
static_cast<int>(raw_w * scale_ratio);
305 const int scaled_h =
static_cast<int>(raw_h * scale_ratio);
308 dst.x = std::max(
dst.x,
dst.x + (
dst.w - scaled_w) / 2);
309 dst.y = std::max(
dst.y,
dst.y + (
dst.h - scaled_h) / 2);
color_t rep() const
High-contrast shade, intended for the minimap markers.
orb_status unit_orb_status(const unit &u) const
Returns an enumurated summary of whether this unit can move and/or attack.
int village_owner(const map_location &loc) const
Given the location of a village, will return the 1-based number of the team that currently owns it,...
Sort-of-Singleton that many classes, both GUI and non-GUI, use to access the game data.
bool is_blindfolded() const
const display_context & context() const
static display * get_singleton()
Returns the display object if a display object exists.
A class to manage automatic restoration of the render target.
int w() const
Effective map width.
int h() const
Effective map height.
void for_each_loc(const F &f) const
Encapsulates the map of the game.
const std::vector< map_location > & villages() const
Return a list of the locations of villages on the map.
const std::shared_ptr< terrain_type_data > & tdata() const
This class stores all the data for a single 'side' (in game nomenclature).
static color_t get_minimap_color(int side)
bool is_enemy(int n) const
bool owns_village(const map_location &loc) const
bool shrouded(const map_location &loc) const
bool fogged(const map_location &loc) const
const std::string & minimap_image() const
const std::string & id() const
const std::string & minimap_image_overlay() const
Wrapper class to encapsulate creation and management of an SDL_Texture.
point get_raw_size() const
The raw internal texture size.
Container associating units to locations.
map_display and display: classes which take care of displaying the map and game-data on the screen.
Drawing functions, for drawing things on the screen.
Standard logging facilities (interface).
constexpr bool is_odd(T num)
static lg::log_domain log_display("display")
void fill(const SDL_Rect &rect, uint8_t r, uint8_t g, uint8_t b, uint8_t a)
Fill an area with the given colour.
void clear()
Clear the current render target.
void blit(const texture &tex, const SDL_Rect &dst)
Draws a texture, or part of a texture, at the given location.
void rect(const SDL_Rect &rect)
Draw a rectangle.
std::map< std::string, color_range, std::less<> > team_rgb_range
Colors defined by WML [color_range] tags.
const color_range & color_info(std::string_view name)
Functions to load and save images from/to disk.
std::function< rect(rect)> prep_minimap_for_rendering(const gamemap &map, const team *vw, const unit_map *units, const std::map< map_location, unsigned int > *reach_map, bool ignore_terrain_disabled)
Prepares the minimap texture and returns a function which will render it to the current rendering tar...
texture get_texture(const image::locator &i_locator, TYPE type, bool skip_cache)
Returns an image texture suitable for hardware-accelerated rendering.
std::string get_orb_color(orb_status os)
Wrapper for the various prefs::get().unmoved_color(), moved_color(), etc methods, using the enum inst...
const terrain_code VOID_TERRAIN
VOID_TERRAIN is used for shrouded hexes.
void scale(size_t factor, const uint32_t *src, uint32_t *trg, int srcWidth, int srcHeight, ColorFormat colFmt, const ScalerCfg &cfg=ScalerCfg(), int yFirst=0, int yLast=std::numeric_limits< int >::max())
@ allied
Belongs to a friendly side.
@ enemy
Belongs to a non-friendly side; normally visualised by not displaying an orb.
rect dst
Location on the final composed sheet.
The basic class for representing 8-bit RGB or RGBA colour values.
Encapsulates the map of the game.
An abstract description of a rectangle with integer coordinates.
A terrain string which is converted to a terrain is a string with 1 or 2 layers the layers are separa...
static map_location::direction s
void set_texture_scale_quality(const char *value)
Sets the texture scale quality.