Add topography and industries screenshot types

pull/271/head
Andreas Schmitt 3 years ago
parent a7d8c6fe0c
commit 5e3a244198

@ -1505,6 +1505,8 @@ DEF_CONSOLE_CMD(ConScreenShot)
"'world' makes a screenshot of the whole map using the current zoom level, "
"'heightmap' makes a heightmap screenshot of the map that can be loaded in as heightmap, "
"'minimap' makes a top-viewed minimap screenshot of the whole world which represents one tile by one pixel. "
"'topography' makes a top-viewed topography screenshot of the whole world which represents one tile by one pixel. "
"'industry' makes a top-viewed industries screenshot of the whole world which represents one tile by one pixel. "
"'no_con' hides the console to create the screenshot (only useful in combination with 'viewport'). "
"'size' sets the width and height of the viewport to make a screenshot of (only useful in combination with 'normal' or 'big').");
return true;
@ -1540,6 +1542,12 @@ DEF_CONSOLE_CMD(ConScreenShot)
} else if (strcmp(argv[arg_index], "minimap") == 0) {
type = SC_MINIMAP;
arg_index += 1;
} else if (strcmp(argv[arg_index], "topography") == 0) {
type = SC_TOPOGRAPHY;
arg_index += 1;
} else if (strcmp(argv[arg_index], "industry") == 0) {
type = SC_INDUSTRY;
arg_index += 1;
}
}

@ -5405,6 +5405,8 @@ STR_SCREENSHOT_WORLD_SCREENSHOT :{BLACK}Whole ma
STR_SCREENSHOT_WORLD_SCREENSHOT_CURRENT_ZOOM :{BLACK}Whole map current zoom screenshot
STR_SCREENSHOT_HEIGHTMAP_SCREENSHOT :{BLACK}Heightmap screenshot
STR_SCREENSHOT_MINIMAP_SCREENSHOT :{BLACK}Minimap screenshot
STR_SCREENSHOT_TOPOGRAPHY_SCREENSHOT :{BLACK}Topography screenshot
STR_SCREENSHOT_INDUSTRY_SCREENSHOT :{BLACK}Industries screenshot
# AI Parameters
STR_AI_SETTINGS_CAPTION :{WHITE}{STRING} Parameters

@ -20,6 +20,8 @@
#include "company_func.h"
#include "strings_func.h"
#include "error.h"
#include "industry.h"
#include "industrytype.h"
#include "textbuf_gui.h"
#include "window_gui.h"
#include "window_func.h"
@ -906,7 +908,7 @@ void MakeScreenshotWithConfirm(ScreenshotType t)
Viewport vp;
SetupScreenshotViewport(t, &vp);
bool heightmap_or_minimap = t == SC_HEIGHTMAP || t == SC_MINIMAP;
bool heightmap_or_minimap = t == SC_HEIGHTMAP || t == SC_MINIMAP || t == SC_TOPOGRAPHY || t == SC_INDUSTRY;
uint64_t width = (heightmap_or_minimap ? MapSizeX() : vp.width);
uint64_t height = (heightmap_or_minimap ? MapSizeY() : vp.height);
@ -996,6 +998,14 @@ static bool RealMakeScreenshot(ScreenshotType t, std::string name, uint32 width,
ret = MakeMinimapWorldScreenshot(name.empty() ? nullptr : name.c_str());
break;
case SC_TOPOGRAPHY:
ret = MakeTopographyScreenshot(name.empty() ? nullptr : name.c_str());
break;
case SC_INDUSTRY:
ret = MakeIndustryScreenshot(name.empty() ? nullptr : name.c_str());
break;
default:
NOT_REACHED();
}
@ -1088,7 +1098,13 @@ static Owner GetMinimapOwner(TileIndex tile)
}
}
static void MinimapScreenCallback(void *userdata, void *buf, uint y, uint pitch, uint n)
/**
* Return the color value of a tile to display it with in the minimap screenshot.
*
* @param tile The tile of which we would like to get the colour.
* @return The color palette value
*/
static byte GetMinimapValue(TileIndex tile)
{
/* Fill with the company colours */
byte owner_colours[OWNER_END + 1];
@ -1102,7 +1118,163 @@ static void MinimapScreenCallback(void *userdata, void *buf, uint y, uint pitch,
owner_colours[OWNER_WATER] = PC_WATER;
owner_colours[OWNER_DEITY] = PC_DARK_GREY; // industry
owner_colours[OWNER_END] = PC_BLACK;
Owner o = GetMinimapOwner(tile);
return owner_colours[o];
}
/**
* Return the color value of a tile to display it with in the topography screenshot.
*
* @param tile The tile of which we would like to get the colour.
* @return The color palette value
*/
static byte GetTopographyValue(TileIndex tile)
{
const auto tile_type = GetTileType(tile);
if (tile_type == MP_STATION) {
switch (GetStationType(tile)) {
case STATION_RAIL:
return MKCOLOUR(PC_GREY);
case STATION_AIRPORT:
return MKCOLOUR(PC_GREY);
case STATION_TRUCK:
return MKCOLOUR(PC_BLACK);
case STATION_BUS:
return MKCOLOUR(PC_BLACK);
case STATION_OILRIG: // FALLTHROUGH
case STATION_DOCK:
return MKCOLOUR(PC_GREY);
case STATION_BUOY:
return MKCOLOUR(PC_WATER);
case STATION_WAYPOINT:
return MKCOLOUR(PC_GREY);
default: NOT_REACHED();
}
}
if (IsBridgeAbove(tile)) {
return MKCOLOUR(PC_DARK_GREY);
}
switch (tile_type) {
case MP_TUNNELBRIDGE:
return MKCOLOUR(PC_DARK_GREY);
case MP_RAILWAY:
return MKCOLOUR(PC_GREY);
case MP_ROAD:
return MKCOLOUR(PC_BLACK);
case MP_HOUSE:
return MKCOLOUR(0xB5);
case MP_WATER:
return MKCOLOUR(PC_WATER);
case MP_INDUSTRY:
return MKCOLOUR(0xA2);
default: {
const auto tile_z = GetTileZ(tile);
const auto max_z = _settings_game.construction.map_height_limit;
const auto color_index = (tile_z * 16) / max_z;
switch (color_index) {
case 0:
return MKCOLOUR(0x50);
case 1:
return MKCOLOUR(0x51);
case 2:
return MKCOLOUR(0x52);
case 3:
return MKCOLOUR(0x53);
case 4:
return MKCOLOUR(0x54);
case 5:
return MKCOLOUR(0x55);
case 6:
return MKCOLOUR(0x56);
case 7:
return MKCOLOUR(0x57);
case 8:
return MKCOLOUR(0x3B);
case 9:
return MKCOLOUR(0x3A);
case 10:
return MKCOLOUR(0x39);
case 11:
return MKCOLOUR(0x38);
case 12:
return MKCOLOUR(0x37);
case 13:
return MKCOLOUR(0x36);
case 14:
return MKCOLOUR(0x35);
case 15:
return MKCOLOUR(0x69);
default:
return MKCOLOUR(0x46);
}
}
}
}
/**
* Return the color value of a tile to display it with in the industries screenshot.
*
* @param tile The tile of which we would like to get the colour.
* @return The color palette value
*/
static byte GetIndustryValue(TileIndex tile)
{
const auto tile_type = GetTileType(tile);
if (tile_type == MP_STATION) {
switch (GetStationType(tile)) {
case STATION_RAIL:
return MKCOLOUR(PC_DARK_GREY);
case STATION_AIRPORT:
return MKCOLOUR(GREY_SCALE(12));
case STATION_TRUCK:
return MKCOLOUR(PC_GREY);
case STATION_BUS:
return MKCOLOUR(PC_GREY);
case STATION_OILRIG: // FALLTHROUGH
case STATION_DOCK:
return MKCOLOUR(PC_GREY);
case STATION_BUOY:
return MKCOLOUR(PC_BLACK);
case STATION_WAYPOINT:
return MKCOLOUR(PC_GREY);
default: NOT_REACHED();
}
}
if (IsBridgeAbove(tile)) {
return MKCOLOUR(GREY_SCALE(12));
}
switch (tile_type) {
case MP_TUNNELBRIDGE:
return MKCOLOUR(GREY_SCALE(12));
case MP_RAILWAY:
return MKCOLOUR(PC_DARK_GREY);
case MP_ROAD:
return MKCOLOUR(PC_GREY);
case MP_HOUSE:
return MKCOLOUR(GREY_SCALE(4));
case MP_WATER:
return MKCOLOUR(0x12);
case MP_INDUSTRY: {
const IndustryType industry_type = Industry::GetByTile(tile)->type;
return GetIndustrySpec(industry_type)->map_colour * static_cast<byte>(0x01010101);
}
default:
return MKCOLOUR(GREY_SCALE(2));
}
}
static void MinimapScreenCallback(void *userdata, void *buf, uint y, uint pitch, uint n, std::function<byte(TileIndex)> colorCallback)
{
uint32 *ubuf = (uint32 *)buf;
uint num = (pitch * n);
for (uint i = 0; i < num; i++) {
@ -1110,8 +1282,7 @@ static void MinimapScreenCallback(void *userdata, void *buf, uint y, uint pitch,
uint col = (MapSizeX() - 1) - (i % pitch);
TileIndex tile = TileXY(col, row);
Owner o = GetMinimapOwner(tile);
byte val = owner_colours[o];
byte val = colorCallback(tile);
uint32 colour_buf = 0;
colour_buf = (_cur_palette.palette[val].b << 0);
@ -1123,6 +1294,45 @@ static void MinimapScreenCallback(void *userdata, void *buf, uint y, uint pitch,
}
}
static void MinimapScreenCallback(void *userdata, void *buf, uint y, uint pitch, uint n)
{
MinimapScreenCallback(userdata, buf, y, pitch, n, GetMinimapValue);
}
static void TopographyScreenCallback(void *userdata, void *buf, uint y, uint pitch, uint n)
{
MinimapScreenCallback(userdata, buf, y, pitch, n, GetTopographyValue);
}
static void IndustryScreenCallback(void *userdata, void *buf, uint y, uint pitch, uint n)
{
MinimapScreenCallback(userdata, buf, y, pitch, n, GetIndustryValue);
}
/**
* 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 screenshot_type The type of screenshot to create tile colors for.
* @return The colour of tile in the small map in mode "Owner"
*/
static byte GetMinimapPixels(TileIndex tile, ScreenshotType screenshot_type)
{
const auto tile_type = GetTileType(tile);
switch (screenshot_type) {
case SC_TOPOGRAPHY: {
}
case SC_INDUSTRY: {
}
default:
NOT_REACHED();
}
}
/**
* Make a minimap screenshot.
*/
@ -1134,3 +1344,27 @@ bool MakeMinimapWorldScreenshot(const char *name)
const ScreenshotFormat *sf = _screenshot_formats + _cur_screenshot_format;
return sf->proc(MakeScreenshotName(SCREENSHOT_NAME, sf->extension), MinimapScreenCallback, nullptr, MapSizeX(), MapSizeY(), 32, _cur_palette.palette);
}
/**
* Make a topography screenshot.
*/
bool MakeTopographyScreenshot(const char *name)
{
_screenshot_name[0] = '\0';
if (name != nullptr) strecpy(_screenshot_name, name, lastof(_screenshot_name));
const ScreenshotFormat *sf = _screenshot_formats + _cur_screenshot_format;
return sf->proc(MakeScreenshotName(SCREENSHOT_NAME, sf->extension), TopographyScreenCallback, nullptr, MapSizeX(), MapSizeY(), 32, _cur_palette.palette);
}
/**
* Make an industry screenshot.
*/
bool MakeIndustryScreenshot(const char *name)
{
_screenshot_name[0] = '\0';
if (name != nullptr) strecpy(_screenshot_name, name, lastof(_screenshot_name));
const ScreenshotFormat *sf = _screenshot_formats + _cur_screenshot_format;
return sf->proc(MakeScreenshotName(SCREENSHOT_NAME, sf->extension), IndustryScreenCallback, nullptr, MapSizeX(), MapSizeY(), 32, _cur_palette.palette);
}

@ -24,6 +24,8 @@ enum ScreenshotType {
SC_WORLD_ZOOM, ///< World screenshot using current zoom level.
SC_HEIGHTMAP, ///< Heightmap of the world.
SC_MINIMAP, ///< Minimap screenshot.
SC_TOPOGRAPHY, ///< Topography screenshot.
SC_INDUSTRY, ///< Industry screenshot.
SC_SMALLMAP, ///< Smallmap window screenshot.
};
@ -35,6 +37,8 @@ bool MakeSmallMapScreenshot(unsigned int width, unsigned int height, SmallMapWin
void MakeScreenshotWithConfirm(ScreenshotType t);
bool MakeScreenshot(ScreenshotType t, std::string name, uint32 width = 0, uint32 height = 0);
bool MakeMinimapWorldScreenshot(const char *name);
bool MakeTopographyScreenshot(const char *name);
bool MakeIndustryScreenshot(const char *name);
void SetScreenshotAuxiliaryText(const char *key, const char *value);
inline void ClearScreenshotAuxiliaryText() { SetScreenshotAuxiliaryText(nullptr, nullptr); }

@ -39,6 +39,8 @@ struct ScreenshotWindow : Window {
case WID_SC_TAKE_WORLD_ZOOM: st = SC_WORLD_ZOOM; break;
case WID_SC_TAKE_HEIGHTMAP: st = SC_HEIGHTMAP; break;
case WID_SC_TAKE_MINIMAP: st = SC_MINIMAP; break;
case WID_SC_TAKE_TOPOGRAPHY: st = SC_TOPOGRAPHY; break;
case WID_SC_TAKE_INDUSTRY: st = SC_INDUSTRY; break;
}
MakeScreenshotWithConfirm(st);
}
@ -59,6 +61,8 @@ static const NWidgetPart _nested_screenshot[] = {
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SC_TAKE_WORLD_ZOOM), SetFill(1, 1), SetDataTip(STR_SCREENSHOT_WORLD_SCREENSHOT_CURRENT_ZOOM, 0), SetMinimalTextLines(2, 0),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SC_TAKE_HEIGHTMAP), SetFill(1, 1), SetDataTip(STR_SCREENSHOT_HEIGHTMAP_SCREENSHOT, 0), SetMinimalTextLines(2, 0),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SC_TAKE_MINIMAP), SetFill(1, 1), SetDataTip(STR_SCREENSHOT_MINIMAP_SCREENSHOT, 0), SetMinimalTextLines(2, 0),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SC_TAKE_TOPOGRAPHY), SetFill(1, 1), SetDataTip(STR_SCREENSHOT_TOPOGRAPHY_SCREENSHOT, 0), SetMinimalTextLines(2, 0),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SC_TAKE_INDUSTRY), SetFill(1, 1), SetDataTip(STR_SCREENSHOT_INDUSTRY_SCREENSHOT, 0), SetMinimalTextLines(2, 0),
EndContainer(),
};

@ -20,6 +20,8 @@ enum ScreenshotWindowWidgets {
WID_SC_TAKE_WORLD_ZOOM, ///< Button for taking a screenshot of the whole world at the current zoom level
WID_SC_TAKE_HEIGHTMAP, ///< Button for taking a heightmap "screenshot"
WID_SC_TAKE_MINIMAP, ///< Button for taking a minimap screenshot
WID_SC_TAKE_TOPOGRAPHY, ///< Button for taking a topography screenshot
WID_SC_TAKE_INDUSTRY, ///< Button for taking a industry screenshot
};

Loading…
Cancel
Save