mirror of https://github.com/OpenTTD/OpenTTD
Fix #8252: Remove duplicate functionality in `screenshot.cpp`
parent
721d98a7d0
commit
c536bde19e
|
@ -27,6 +27,7 @@
|
||||||
#include "tile_map.h"
|
#include "tile_map.h"
|
||||||
#include "landscape.h"
|
#include "landscape.h"
|
||||||
#include "video/video_driver.hpp"
|
#include "video/video_driver.hpp"
|
||||||
|
#include "smallmap_gui.h"
|
||||||
|
|
||||||
#include "table/strings.h"
|
#include "table/strings.h"
|
||||||
|
|
||||||
|
@ -995,48 +996,8 @@ bool MakeScreenshot(ScreenshotType t, std::string name, uint32 width, uint32 hei
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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)
|
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;
|
uint32 *ubuf = (uint32 *)buf;
|
||||||
uint num = (pitch * n);
|
uint num = (pitch * n);
|
||||||
for (uint i = 0; i < num; i++) {
|
for (uint i = 0; i < num; i++) {
|
||||||
|
@ -1044,8 +1005,7 @@ static void MinimapScreenCallback(void *userdata, void *buf, uint y, uint pitch,
|
||||||
uint col = (MapSizeX() - 1) - (i % pitch);
|
uint col = (MapSizeX() - 1) - (i % pitch);
|
||||||
|
|
||||||
TileIndex tile = TileXY(col, row);
|
TileIndex tile = TileXY(col, row);
|
||||||
Owner o = GetMinimapOwner(tile);
|
byte val = GetSmallMapOwnerPixels(tile, GetTileType(tile), IncludeHeightmap::Never) & 0xFF;
|
||||||
byte val = owner_colours[o];
|
|
||||||
|
|
||||||
uint32 colour_buf = 0;
|
uint32 colour_buf = 0;
|
||||||
colour_buf = (_cur_palette.palette[val].b << 0);
|
colour_buf = (_cur_palette.palette[val].b << 0);
|
||||||
|
|
|
@ -556,15 +556,18 @@ static inline uint32 GetSmallMapVegetationPixels(TileIndex tile, TileType t)
|
||||||
/**
|
/**
|
||||||
* Return the colour a tile would be displayed with in the small map in mode "Owner".
|
* 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.
|
* @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 t Effective tile type of the tile (see #SmallMapWindow::GetTileColours).
|
* @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"
|
* @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;
|
Owner o;
|
||||||
|
|
||||||
switch (t) {
|
switch (t) {
|
||||||
|
case MP_VOID: return MKCOLOUR_XXXX(PC_BLACK);
|
||||||
case MP_INDUSTRY: return MKCOLOUR_XXXX(PC_DARK_GREY);
|
case MP_INDUSTRY: return MKCOLOUR_XXXX(PC_DARK_GREY);
|
||||||
case MP_HOUSE: return MKCOLOUR_XXXX(PC_DARK_RED);
|
case MP_HOUSE: return MKCOLOUR_XXXX(PC_DARK_RED);
|
||||||
default: o = GetTileOwner(tile); break;
|
default: o = GetTileOwner(tile); break;
|
||||||
|
@ -577,7 +580,8 @@ static inline uint32 GetSmallMapOwnerPixels(TileIndex tile, TileType t)
|
||||||
if ((o < MAX_COMPANIES && !_legend_land_owners[_company_to_list_pos[o]].show_on_map) || o == OWNER_NONE || o == OWNER_WATER) {
|
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);
|
if (t == MP_WATER) return MKCOLOUR_XXXX(PC_WATER);
|
||||||
const SmallMapColourScheme *cs = &_heightmap_schemes[_settings_client.gui.smallmap_land_colour];
|
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) {
|
} else if (o == OWNER_TOWN) {
|
||||||
return MKCOLOUR_XXXX(PC_DARK_RED);
|
return MKCOLOUR_XXXX(PC_DARK_RED);
|
||||||
}
|
}
|
||||||
|
@ -814,7 +818,7 @@ inline uint32 SmallMapWindow::GetTileColours(const TileArea &ta) const
|
||||||
return GetSmallMapVegetationPixels(tile, et);
|
return GetSmallMapVegetationPixels(tile, et);
|
||||||
|
|
||||||
case SMT_OWNER:
|
case SMT_OWNER:
|
||||||
return GetSmallMapOwnerPixels(tile, et);
|
return GetSmallMapOwnerPixels(tile, et, IncludeHeightmap::IfEnabled);
|
||||||
|
|
||||||
default: NOT_REACHED();
|
default: NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,15 @@ void ShowSmallMap();
|
||||||
void BuildLandLegend();
|
void BuildLandLegend();
|
||||||
void BuildOwnerLegend();
|
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 */
|
/** Structure for holding relevant data for legends in small map */
|
||||||
struct LegendAndColour {
|
struct LegendAndColour {
|
||||||
uint8 colour; ///< Colour of the item on the map.
|
uint8 colour; ///< Colour of the item on the map.
|
||||||
|
|
Loading…
Reference in New Issue