Changeset - r26471:07663e681e9c
[Not reviewed]
master
0 3 0
Artin Alavi - 20 months ago 2022-09-30 22:20:25
artin.alavi@gmail.com
Fix #8252: Remove duplicate functionality in `screenshot.cpp`
3 files changed with 20 insertions and 47 deletions:
0 comments (0 inline, 0 general)
src/screenshot.cpp
Show inline comments
 
@@ -27,6 +27,7 @@
 
#include "tile_map.h"
 
#include "landscape.h"
 
#include "video/video_driver.hpp"
 
#include "smallmap_gui.h"
 

	
 
#include "table/strings.h"
 

	
 
@@ -995,48 +996,8 @@ bool MakeScreenshot(ScreenshotType t, st
 
}
 

	
 

	
 
/**
 
 * Return the owner of a tile to display it with in the small map in mode "Owner".
 
 *
 
 * @param tile The tile of which we would like to get the colour.
 
 * @return The owner of tile in the small map in mode "Owner"
 
 */
 
static Owner GetMinimapOwner(TileIndex tile)
 
{
 
	Owner o;
 

	
 
	if (IsTileType(tile, MP_VOID)) {
 
		return OWNER_END;
 
	} else {
 
		switch (GetTileType(tile)) {
 
		case MP_INDUSTRY: o = OWNER_DEITY;        break;
 
		case MP_HOUSE:    o = OWNER_TOWN;         break;
 
		default:          o = GetTileOwner(tile); break;
 
			/* FIXME: For MP_ROAD there are multiple owners.
 
			 * GetTileOwner returns the rail owner (level crossing) resp. the owner of ROADTYPE_ROAD (normal road),
 
			 * even if there are no ROADTYPE_ROAD bits on the tile.
 
			 */
 
		}
 

	
 
		return o;
 
	}
 
}
 

	
 
static void MinimapScreenCallback(void *userdata, void *buf, uint y, uint pitch, uint n)
 
{
 
	/* Fill with the company colours */
 
	byte owner_colours[OWNER_END + 1];
 
	for (const Company *c : Company::Iterate()) {
 
		owner_colours[c->index] = MKCOLOUR(_colour_gradient[c->colour][5]);
 
	}
 

	
 
	/* Fill with some special colours */
 
	owner_colours[OWNER_TOWN]    = PC_DARK_RED;
 
	owner_colours[OWNER_NONE]    = PC_GRASS_LAND;
 
	owner_colours[OWNER_WATER]   = PC_WATER;
 
	owner_colours[OWNER_DEITY]   = PC_DARK_GREY; // industry
 
	owner_colours[OWNER_END]     = PC_BLACK;
 

	
 
	uint32 *ubuf = (uint32 *)buf;
 
	uint num = (pitch * n);
 
	for (uint i = 0; i < num; i++) {
 
@@ -1044,8 +1005,7 @@ static void MinimapScreenCallback(void *
 
		uint col = (MapSizeX() - 1) - (i % pitch);
 

	
 
		TileIndex tile = TileXY(col, row);
 
		Owner o = GetMinimapOwner(tile);
 
		byte val = owner_colours[o];
 
		byte val = GetSmallMapOwnerPixels(tile, GetTileType(tile), IncludeHeightmap::Never) & 0xFF;
 

	
 
		uint32 colour_buf = 0;
 
		colour_buf  = (_cur_palette.palette[val].b << 0);
src/smallmap_gui.cpp
Show inline comments
 
@@ -556,15 +556,18 @@ static inline uint32 GetSmallMapVegetati
 
/**
 
 * Return the colour a tile would be displayed with in the small map in mode "Owner".
 
 *
 
 * @param tile The tile of which we would like to get the colour.
 
 * @param t    Effective tile type of the tile (see #SmallMapWindow::GetTileColours).
 
 * @note If include_heightmap is IH_NEVER, the return value can safely be used as a palette colour (by masking it to a uint8)
 
 * @param tile              The tile of which we would like to get the colour.
 
 * @param t                 Effective tile type of the tile (see #SmallMapWindow::GetTileColours).
 
 * @param include_heightmap Whether to return the heightmap/contour colour of this tile (instead of the default land tile colour)
 
 * @return The colour of tile in the small map in mode "Owner"
 
 */
 
static inline uint32 GetSmallMapOwnerPixels(TileIndex tile, TileType t)
 
inline uint32 GetSmallMapOwnerPixels(TileIndex tile, TileType t, IncludeHeightmap include_heightmap)
 
{
 
	Owner o;
 

	
 
	switch (t) {
 
		case MP_VOID:     return MKCOLOUR_XXXX(PC_BLACK);
 
		case MP_INDUSTRY: return MKCOLOUR_XXXX(PC_DARK_GREY);
 
		case MP_HOUSE:    return MKCOLOUR_XXXX(PC_DARK_RED);
 
		default:          o = GetTileOwner(tile); break;
 
@@ -577,7 +580,8 @@ static inline uint32 GetSmallMapOwnerPix
 
	if ((o < MAX_COMPANIES && !_legend_land_owners[_company_to_list_pos[o]].show_on_map) || o == OWNER_NONE || o == OWNER_WATER) {
 
		if (t == MP_WATER) return MKCOLOUR_XXXX(PC_WATER);
 
		const SmallMapColourScheme *cs = &_heightmap_schemes[_settings_client.gui.smallmap_land_colour];
 
		return _smallmap_show_heightmap ? cs->height_colours[TileHeight(tile)] : cs->default_colour;
 
		return ((include_heightmap == IncludeHeightmap::IfEnabled && _smallmap_show_heightmap) || include_heightmap == IncludeHeightmap::Always)
 
			? cs->height_colours[TileHeight(tile)] : cs->default_colour;
 
	} else if (o == OWNER_TOWN) {
 
		return MKCOLOUR_XXXX(PC_DARK_RED);
 
	}
 
@@ -814,7 +818,7 @@ inline uint32 SmallMapWindow::GetTileCol
 
			return GetSmallMapVegetationPixels(tile, et);
 

	
 
		case SMT_OWNER:
 
			return GetSmallMapOwnerPixels(tile, et);
 
			return GetSmallMapOwnerPixels(tile, et, IncludeHeightmap::IfEnabled);
 

	
 
		default: NOT_REACHED();
 
	}
src/smallmap_gui.h
Show inline comments
 
@@ -27,6 +27,15 @@ void ShowSmallMap();
 
void BuildLandLegend();
 
void BuildOwnerLegend();
 

	
 
/** Enum for how to include the heightmap pixels/colours in small map related functions */
 
enum class IncludeHeightmap {
 
	Never,      ///< Never include the heightmap
 
	IfEnabled,  ///< Only include the heightmap if its enabled in the gui by the player
 
	Always      ///< Always include the heightmap
 
};
 

	
 
uint32 GetSmallMapOwnerPixels(TileIndex tile, TileType t, IncludeHeightmap include_heightmap);
 

	
 
/** Structure for holding relevant data for legends in small map */
 
struct LegendAndColour {
 
	uint8 colour;              ///< Colour of the item on the map.
0 comments (0 inline, 0 general)