|
OpenTTD Source
14.0-beta3
|
Go to the documentation of this file.
34 #include "table/strings.h"
62 #define MK(a, b) {a, b, INVALID_INDUSTRYTYPE, 0, INVALID_COMPANY, true, false, false}
65 #define MC(col_break) {0, STR_TINY_BLACK_HEIGHT, INVALID_INDUSTRYTYPE, 0, INVALID_COMPANY, true, false, col_break}
68 #define MO(a, b) {a, b, INVALID_INDUSTRYTYPE, 0, INVALID_COMPANY, true, false, false}
71 #define MOEND() {0, 0, INVALID_INDUSTRYTYPE, 0, OWNER_NONE, true, true, false}
74 #define MKEND() {0, STR_NULL, INVALID_INDUSTRYTYPE, 0, INVALID_COMPANY, true, true, false}
80 #define MS(a, b) {a, b, INVALID_INDUSTRYTYPE, 0, INVALID_COMPANY, true, false, true}
85 MK(
PC_GREY, STR_SMALLMAP_LEGENDA_RAILROADS),
109 MK(
PC_RED, STR_SMALLMAP_LEGENDA_TRAINS),
114 MS(
PC_BLACK, STR_SMALLMAP_LEGENDA_TRANSPORT_ROUTES),
121 MK(
PC_GREY, STR_SMALLMAP_LEGENDA_RAILROADS),
125 MK(
PC_ORANGE, STR_SMALLMAP_LEGENDA_TRUCK_LOADING_BAY),
127 MK(
PC_RED, STR_SMALLMAP_LEGENDA_AIRPORT_HELIPORT),
144 MK(
PC_BLACK, STR_SMALLMAP_LEGENDA_TRANSPORT_ROUTES),
151 MO(0x00, STR_SMALLMAP_LEGENDA_NO_OWNER),
256 #define MKCOLOUR(x) TO_LE32X(x)
258 #define MKCOLOUR_XXXX(x) (MKCOLOUR(0x01010101) * (uint)(x))
259 #define MKCOLOUR_X0X0(x) (MKCOLOUR(0x01000100) * (uint)(x))
260 #define MKCOLOUR_0X0X(x) (MKCOLOUR(0x00010001) * (uint)(x))
261 #define MKCOLOUR_0XX0(x) (MKCOLOUR(0x00010100) * (uint)(x))
262 #define MKCOLOUR_X00X(x) (MKCOLOUR(0x01000001) * (uint)(x))
264 #define MKCOLOUR_XYXY(x, y) (MKCOLOUR_X0X0(x) | MKCOLOUR_0X0X(y))
265 #define MKCOLOUR_XYYX(x, y) (MKCOLOUR_X00X(x) | MKCOLOUR_0XX0(y))
267 #define MKCOLOUR_0000 MKCOLOUR_XXXX(0x00)
268 #define MKCOLOUR_0FF0 MKCOLOUR_0XX0(0xFF)
269 #define MKCOLOUR_F00F MKCOLOUR_X00X(0xFF)
270 #define MKCOLOUR_FFFF MKCOLOUR_XXXX(0xFF)
317 uint deltas[][2] = { { 24, 2 }, { 48, 4 }, { 72, 6 }, { 120, 10 }, { 180, 15 }, { 240, 20 }, {
MAX_TILE_HEIGHT + 1, 25 }};
322 uint delta = deltas[i][1];
325 int rows =
CeilDiv(total_entries, 2);
350 _legend_land_owners[i].
company = c->index;
352 _legend_land_owners[i].
col_break =
false;
353 _legend_land_owners[i].
end =
false;
359 _legend_land_owners[i].
end =
true;
370 static inline uint32_t ApplyMask(uint32_t colour,
const AndOr *mask)
372 return (colour & mask->mand) | mask->mor;
378 {MKCOLOUR_0000 , MKCOLOUR_FFFF},
379 {MKCOLOUR_0XX0(
PC_GREY ), MKCOLOUR_F00F},
380 {MKCOLOUR_0XX0(
PC_BLACK ), MKCOLOUR_F00F},
382 {MKCOLOUR_0000 , MKCOLOUR_FFFF},
384 {MKCOLOUR_XXXX(
PC_WATER ), MKCOLOUR_0000},
385 {MKCOLOUR_0000 , MKCOLOUR_FFFF},
387 {MKCOLOUR_0000 , MKCOLOUR_FFFF},
389 {MKCOLOUR_0XX0(
PC_GREY ), MKCOLOUR_F00F},
394 {MKCOLOUR_0000 , MKCOLOUR_FFFF},
395 {MKCOLOUR_0XX0(
PC_BLACK ), MKCOLOUR_F00F},
396 {MKCOLOUR_0XX0(
PC_BLACK ), MKCOLOUR_F00F},
398 {MKCOLOUR_0000 , MKCOLOUR_FFFF},
399 {MKCOLOUR_0XX0(
PC_BLACK ), MKCOLOUR_F00F},
400 {MKCOLOUR_XXXX(
PC_WATER ), MKCOLOUR_0000},
401 {MKCOLOUR_0000 , MKCOLOUR_FFFF},
403 {MKCOLOUR_0000 , MKCOLOUR_FFFF},
405 {MKCOLOUR_0XX0(
PC_BLACK ), MKCOLOUR_F00F},
476 case STATION_AIRPORT:
return MKCOLOUR_XXXX(
PC_RED);
477 case STATION_TRUCK:
return MKCOLOUR_XXXX(
PC_ORANGE);
478 case STATION_BUS:
return MKCOLOUR_XXXX(
PC_YELLOW);
480 default:
return MKCOLOUR_FFFF;
500 if (rti !=
nullptr) {
531 static const uint32_t _vegetation_clear_bits[] = {
640 static const uint INDUSTRY_MIN_NUMBER_OF_COLUMNS = 2;
652 std::unique_ptr<LinkGraphOverlay> overlay;
660 static inline Point SmallmapRemapCoords(
int x,
int y)
707 return width / this->column_width;
754 for (
int z = 0; z < heights; z++) {
779 return std::max({this->min_number_of_fixed_rows, num_rows_linkstats, num_rows_others});
797 bool changes =
false;
798 for (
int i = begin_legend_item; i != end_legend_item; i++) {
799 bool new_state = (i == click_pos);
800 if (legend[i].show_on_map != new_state) {
807 for (
int i = begin_legend_item; i != end_legend_item; i++) {
815 if (this->map_type == SMT_INDUSTRY) this->BreakIndustryChainLink();
825 this->map_type = map_type;
828 this->SetupWidgetData();
830 if (map_type == SMT_LINKSTATS) this->overlay->SetDirty();
831 if (map_type != SMT_INDUSTRY) this->BreakIndustryChainLink();
868 this->subscroll = sub;
869 if (this->map_type == SMT_LINKSTATS) this->overlay->SetDirty();
883 Point upper_left = this->RemapTile(upper_left_smallmap_coord.x / (
int)
TILE_SIZE, upper_left_smallmap_coord.y / (
int)
TILE_SIZE);
884 upper_left.x -= this->subscroll;
886 Point lower_right = this->RemapTile(lower_right_smallmap_coord.x / (
int)
TILE_SIZE, lower_right_smallmap_coord.y / (
int)
TILE_SIZE);
887 lower_right.x -= this->subscroll;
911 void *dst_ptr_abs_end = blitter->
MoveTo(_screen.dst_ptr, 0, _screen.height);
919 if (dst < _screen.dst_ptr)
continue;
920 if (dst >= dst_ptr_abs_end)
continue;
924 if (min_xy == 1 && (xc == 0 || yc == 0)) {
925 if (this->zoom == 1)
continue;
927 ta =
TileArea(
TileXY(std::max(min_xy, xc), std::max(min_xy, yc)), this->zoom - (xc == 0), this->zoom - (yc == 0));
933 uint32_t val = this->GetTileColours(ta);
934 uint8_t *val8 = (uint8_t *)&val;
935 int idx = std::max(0, -start_pos);
936 for (
int pos = std::max(0, start_pos); pos < end_pos; pos++) {
937 blitter->
SetPixel(dst, idx, 0, val8[idx]);
941 }
while (xc += this->zoom, yc += this->zoom, dst = blitter->
MoveTo(dst, pitch, 0), --reps != 0);
958 int y = pt.y - dpi->top;
962 int x = pt.x - this->subscroll - 3 - dpi->left;
966 if (++x != 0)
continue;
968 }
else if (x >= dpi->width - 1) {
970 if (x != dpi->width - 1)
continue;
978 blitter->
SetPixel(dpi->dst_ptr, x, y, colour);
979 if (!skip) blitter->
SetPixel(dpi->dst_ptr, x + 1, y, colour);
992 int x = pt.x - this->subscroll - (t->cache.sign.width_small >> 1);
996 if (x + t->cache.sign.width_small > dpi->left &&
997 x < dpi->left + dpi->width &&
999 y < dpi->top + dpi->height) {
1002 DrawString(x, x + t->cache.sign.width_small, y, STR_SMALLMAP_TOWN);
1024 GfxFillRect(dpi->left, dpi->top, dpi->left + dpi->width - 1, dpi->top + dpi->height - 1,
PC_BLACK);
1028 Point tile = this->PixelToTile(dpi->left, dpi->top, &dx);
1029 int tile_x = this->scroll_x / (int)
TILE_SIZE + tile.x;
1030 int tile_y = this->scroll_y / (
int)
TILE_SIZE + tile.y;
1032 void *ptr = blitter->
MoveTo(dpi->dst_ptr, -dx - 4, 0);
1039 if (x >= dpi->width)
break;
1041 int end_pos = std::min(dpi->width, x + 4);
1042 int reps = (dpi->height - y + 1) / 2;
1044 this->DrawSmallMapColumn(ptr, tile_x, tile_y, dpi->pitch * 2, reps, x, end_pos, blitter);
1049 tile_y += this->zoom;
1051 ptr = blitter->
MoveTo(ptr, 0, 1);
1053 tile_x -= this->zoom;
1055 ptr = blitter->
MoveTo(ptr, 0, -1);
1057 ptr = blitter->
MoveTo(ptr, 2, 0);
1062 if (this->map_type == SMT_CONTOUR || this->map_type == SMT_VEHICLES) this->DrawVehicles(dpi, blitter);
1065 if (this->map_type == SMT_LINKSTATS) this->overlay->Draw(dpi);
1068 if (this->show_towns) this->DrawTowns(dpi);
1071 this->DrawMapIndicators();
1082 int x_offset = tile_x - this->scroll_x / (int)
TILE_SIZE;
1083 int y_offset = tile_y - this->scroll_y / (int)
TILE_SIZE;
1085 if (this->zoom == 1)
return SmallmapRemapCoords(x_offset, y_offset);
1088 if (x_offset < 0) x_offset -= this->zoom - 1;
1089 if (y_offset < 0) y_offset -= this->zoom - 1;
1091 return SmallmapRemapCoords(x_offset / this->zoom, y_offset / this->zoom);
1106 if (add_sub) px += this->subscroll;
1110 Point pt = {((py >> 1) - (px >> 2)) * this->zoom, ((py >> 1) + (px >> 2)) * this->zoom};
1138 assert(x >= 0 && y >= 0);
1141 Point tile_xy = PixelToTile(x, y, &new_sub,
false);
1148 scroll.x = (tx + this->zoom) *
TILE_SIZE;
1149 scroll.y = (ty - this->zoom) *
TILE_SIZE;
1152 scroll.x = (tx + 2 * this->zoom) *
TILE_SIZE;
1153 scroll.y = (ty - 2 * this->zoom) *
TILE_SIZE;
1166 static const int zoomlevels[] = {1, 2, 4, 6, 8};
1167 static const int MIN_ZOOM_INDEX = 0;
1168 static const int MAX_ZOOM_INDEX =
lengthof(zoomlevels) - 1;
1170 int new_index, cur_index, sub;
1173 case ZLC_INITIALIZE:
1175 new_index = MIN_ZOOM_INDEX;
1176 tile.x = tile.y = 0;
1181 for (cur_index = MIN_ZOOM_INDEX; cur_index <= MAX_ZOOM_INDEX; cur_index++) {
1182 if (this->zoom == zoomlevels[cur_index])
break;
1184 assert(cur_index <= MAX_ZOOM_INDEX);
1186 tile = this->PixelToTile(zoom_pt->x, zoom_pt->y, &sub);
1187 new_index =
Clamp(cur_index + ((change == ZLC_ZOOM_IN) ? -1 : 1), MIN_ZOOM_INDEX, MAX_ZOOM_INDEX);
1190 default: NOT_REACHED();
1193 if (new_index != cur_index) {
1194 this->zoom = zoomlevels[new_index];
1195 if (cur_index >= 0) {
1196 Point new_tile = this->PixelToTile(zoom_pt->x, zoom_pt->y, &sub);
1197 this->SetNewScroll(this->scroll_x + (tile.x - new_tile.x) *
TILE_SIZE,
1198 this->scroll_y + (tile.y - new_tile.y) *
TILE_SIZE, sub);
1199 }
else if (this->map_type == SMT_LINKSTATS) {
1200 this->overlay->SetDirty();
1202 this->SetWidgetDisabledState(
WID_SM_ZOOM_IN, this->zoom == zoomlevels[MIN_ZOOM_INDEX]);
1203 this->SetWidgetDisabledState(
WID_SM_ZOOM_OUT, this->zoom == zoomlevels[MAX_ZOOM_INDEX]);
1213 CargoTypes cargo_mask = 0;
1217 this->overlay->SetCargoMask(cargo_mask);
1229 switch (this->map_type) {
1231 legend_tooltip = STR_SMALLMAP_TOOLTIP_INDUSTRY_SELECTION;
1232 enable_all_tooltip = STR_SMALLMAP_TOOLTIP_ENABLE_ALL_INDUSTRIES;
1233 disable_all_tooltip = STR_SMALLMAP_TOOLTIP_DISABLE_ALL_INDUSTRIES;
1238 legend_tooltip = STR_SMALLMAP_TOOLTIP_COMPANY_SELECTION;
1239 enable_all_tooltip = STR_SMALLMAP_TOOLTIP_ENABLE_ALL_COMPANIES;
1240 disable_all_tooltip = STR_SMALLMAP_TOOLTIP_DISABLE_ALL_COMPANIES;
1245 legend_tooltip = STR_SMALLMAP_TOOLTIP_CARGO_SELECTION;
1246 enable_all_tooltip = STR_SMALLMAP_TOOLTIP_ENABLE_ALL_CARGOS;
1247 disable_all_tooltip = STR_SMALLMAP_TOOLTIP_DISABLE_ALL_CARGOS;
1252 legend_tooltip = STR_NULL;
1253 enable_all_tooltip = STR_NULL;
1254 disable_all_tooltip = STR_NULL;
1259 this->GetWidget<NWidgetCore>(
WID_SM_LEGEND)->SetDataTip(STR_NULL, legend_tooltip);
1260 this->GetWidget<NWidgetCore>(
WID_SM_ENABLE_ALL)->SetDataTip(STR_SMALLMAP_ENABLE_ALL, enable_all_tooltip);
1261 this->GetWidget<NWidgetCore>(
WID_SM_DISABLE_ALL)->SetDataTip(STR_SMALLMAP_DISABLE_ALL, disable_all_tooltip);
1293 if (this->map_type == SMT_INDUSTRY) {
1320 switch (this->map_type) {
1336 case SMT_VEGETATION:
1342 default: NOT_REACHED();
1355 uint columns = this->GetNumberColumnsLegend(wi->
current_x);
1356 uint number_of_rows = this->GetNumberRowsLegend(columns);
1357 if (line >= number_of_rows)
return -1;
1360 int x = pt.x - wi->
pos_x;
1364 return (column * number_of_rows) + line;
1370 if (this->map_type == SMT_LINKSTATS) {
1371 CompanyMask company_mask = this->GetOverlayCompanyMask();
1372 if (this->overlay->GetCompanyMask() != company_mask) {
1373 this->overlay->SetCompanyMask(company_mask);
1375 this->overlay->SetDirty();
1387 this->UpdateLinks();
1396 this->UpdateLinks();
1406 this->overlay = std::make_unique<LinkGraphOverlay>(
this,
WID_SM_MAP, 0, this->GetOverlayCompanyMask(), 1);
1407 this->InitNested(window_number);
1410 this->RebuildColourIndexIfNecessary();
1416 this->SetupWidgetData();
1418 this->SetZoomLevel(ZLC_INITIALIZE,
nullptr);
1419 this->SmallMapCenterOnCurrentPos();
1420 this->SetOverlayCargoMask();
1435 this->SetNewScroll(sxy.x, sxy.y, sub);
1448 Point ret = this->RemapTile(x, y);
1453 ret.x -= 3 + this->subscroll;
1457 void Close([[maybe_unused]]
int data)
override
1459 this->BreakIndustryChainLink();
1463 void SetStringParameters(
WidgetID widget)
const override
1467 SetDParam(0, STR_SMALLMAP_TYPE_CONTOURS + this->map_type);
1475 this->min_number_of_columns = INDUSTRY_MIN_NUMBER_OF_COLUMNS;
1477 for (uint i = 0; i <
lengthof(_legend_table); i++) {
1479 uint num_columns = 1;
1482 if (i == SMT_INDUSTRY) {
1485 str = STR_SMALLMAP_INDUSTRY;
1486 }
else if (i == SMT_LINKSTATS) {
1488 str = STR_SMALLMAP_LINKSTATS;
1489 }
else if (i == SMT_OWNER) {
1499 str = STR_SMALLMAP_COMPANY;
1504 if (tbl->col_break) {
1505 this->min_number_of_fixed_rows = std::max(this->min_number_of_fixed_rows, height);
1514 this->min_number_of_fixed_rows = std::max(this->min_number_of_fixed_rows, height);
1515 this->min_number_of_columns = std::max(this->min_number_of_columns, num_columns);
1527 if (this->map_type == SMT_OWNER) {
1532 this->InvalidateData(1);
1538 this->DrawWidgets();
1541 void DrawWidget(
const Rect &r,
WidgetID widget)
const override
1548 this->DrawSmallMap(&new_dpi);
1553 uint columns = this->GetNumberColumnsLegend(r.
Width());
1554 uint number_of_rows = this->GetNumberRowsLegend(columns);
1565 switch (this->map_type) {
1567 string = STR_SMALLMAP_INDUSTRY;
1570 string = STR_SMALLMAP_LINKSTATS;
1573 string = STR_SMALLMAP_COMPANY;
1580 if (tbl->col_break || ((this->map_type == SMT_INDUSTRY || this->map_type == SMT_OWNER || this->map_type == SMT_LINKSTATS) && i++ >= number_of_rows)) {
1583 int x = rtl ? -(int)this->column_width : this->column_width;
1584 int y = origin.top - text.top;
1590 uint8_t legend_colour = tbl->colour;
1592 switch (this->map_type) {
1609 if (this->map_type == SMT_OWNER)
SetDParam(0, tbl->company);
1610 if (!tbl->show_on_map) {
1638 void OnClick([[maybe_unused]]
Point pt,
WidgetID widget, [[maybe_unused]]
int click_count)
override
1642 if (click_count > 0) this->mouse_capture_widget = widget;
1647 pt = this->PixelToTile(pt.x - wid->
pos_x, pt.y - wid->
pos_y, &sub);
1658 this->SetZoomLevel((widget ==
WID_SM_ZOOM_IN) ? ZLC_ZOOM_IN : ZLC_ZOOM_OUT, &zoom_pt);
1675 this->SmallMapCenterOnCurrentPos();
1681 this->show_towns = !this->show_towns;
1689 if (this->map_type == SMT_INDUSTRY || this->map_type == SMT_LINKSTATS || this->map_type == SMT_OWNER) {
1690 int click_pos = this->GetPositionOnLegend(pt);
1691 if (click_pos < 0)
break;
1694 if (this->map_type == SMT_INDUSTRY) {
1699 }
else if (this->map_type == SMT_LINKSTATS) {
1702 this->SetOverlayCargoMask();
1704 }
else if (this->map_type == SMT_OWNER) {
1716 switch (this->map_type) {
1719 this->BreakIndustryChainLink();
1730 for (;!tbl->
end && tbl->
legend != STR_LINKGRAPH_LEGEND_UNUSED; ++tbl) {
1733 if (this->map_type == SMT_LINKSTATS) this->SetOverlayCargoMask();
1756 if (!gui_scope)
return;
1766 if (this->map_type != SMT_INDUSTRY) this->SwitchMapType(SMT_INDUSTRY);
1775 this->RebuildColourIndexIfNecessary();
1778 default: NOT_REACHED();
1791 void OnMouseWheel(
int wheel)
override
1795 int cursor_x = _cursor.
pos.x - this->left - wid->
pos_x;
1796 int cursor_y = _cursor.
pos.y - this->top - wid->
pos_y;
1798 Point pt = {cursor_x, cursor_y};
1799 this->SetZoomLevel((wheel < 0) ? ZLC_ZOOM_IN : ZLC_ZOOM_OUT, &pt);
1804 void OnScroll(
Point delta)
override
1810 Point pt = this->PixelToTile(delta.x, delta.y, &sub);
1811 this->SetNewScroll(this->scroll_x + pt.x *
TILE_SIZE, this->scroll_y + pt.y *
TILE_SIZE, sub);
1816 void OnMouseOver([[maybe_unused]]
Point pt,
WidgetID widget)
override
1819 if (widget ==
WID_SM_LEGEND && this->map_type == SMT_INDUSTRY) {
1820 int industry_pos = GetPositionOnLegend(pt);
1851 this->smallmap_window =
nullptr;
1856 assert(this->
children.size() == 2);
1864 assert(this->smallmap_window !=
nullptr);
1880 assert(this->
children.size() == 2);
1892 uint bar_height = std::max(bar->
smallest_y, this->smallmap_window->GetLegendHeight(this->smallmap_window->GetNumberColumnsLegend(given_width - bar->
smallest_x)));
1893 uint display_height = given_height - bar_height;
1902 NWidget(
WWT_INSET, COLOUR_BROWN,
WID_SM_MAP),
SetMinimalSize(346, 140),
SetResize(1, 1),
SetPadding(2, 2, 2, 2),
EndContainer(),
1915 SetDataTip(SPR_IMG_ZOOMIN, STR_TOOLBAR_TOOLTIP_ZOOM_THE_VIEW_IN),
SetFill(1, 1),
1921 SetDataTip(SPR_IMG_SHOW_COUNTOURS, STR_SMALLMAP_TOOLTIP_SHOW_LAND_CONTOURS_ON_MAP),
SetFill(1, 1),
1923 SetDataTip(SPR_IMG_SHOW_VEHICLES, STR_SMALLMAP_TOOLTIP_SHOW_VEHICLES_ON_MAP),
SetFill(1, 1),
1925 SetDataTip(SPR_IMG_INDUSTRY, STR_SMALLMAP_TOOLTIP_SHOW_INDUSTRIES_ON_MAP),
SetFill(1, 1),
1930 SetDataTip(SPR_IMG_ZOOMOUT, STR_TOOLBAR_TOOLTIP_ZOOM_THE_VIEW_OUT),
SetFill(1, 1),
1932 SetDataTip(SPR_IMG_TOWN, STR_SMALLMAP_TOOLTIP_TOGGLE_TOWN_NAMES_ON_OFF),
SetFill(1, 1),
1934 SetDataTip(SPR_IMG_CARGOFLOW, STR_SMALLMAP_TOOLTIP_SHOW_LINK_STATS_ON_MAP),
SetFill(1, 1),
1936 SetDataTip(SPR_IMG_SHOW_ROUTES, STR_SMALLMAP_TOOLTIP_SHOW_TRANSPORT_ROUTES_ON),
SetFill(1, 1),
1938 SetDataTip(SPR_IMG_PLANTTREES, STR_SMALLMAP_TOOLTIP_SHOW_VEGETATION_ON_MAP),
SetFill(1, 1),
1940 SetDataTip(SPR_IMG_COMPANY_GENERAL, STR_SMALLMAP_TOOLTIP_SHOW_LAND_OWNERS_ON_MAP),
SetFill(1, 1),
1948 static std::unique_ptr<NWidgetBase> SmallMapDisplay()
1950 std::unique_ptr<NWidgetBase> map_display = std::make_unique<NWidgetSmallmapDisplay>();
1958 static constexpr
NWidgetPart _nested_smallmap_widgets[] = {
1984 static WindowDesc _smallmap_desc(__FILE__, __LINE__,
1988 std::begin(_nested_smallmap_widgets), std::end(_nested_smallmap_widgets)
1996 AllocateWindowDescFront<SmallMapWindow>(&_smallmap_desc, 0);
2015 if (res)
return res;
2030 return static_cast<const SmallMapWindow *
>(w)->GetStationMiddle(st);
std::array< IndustryType, NUM_INDUSTRYTYPES > _sorted_industry_types
Industry types sorted by name.
static debug_inline uint TileY(TileIndex tile)
Get the Y component of a tile.
uint32_t default_colour
Default colour of the land.
@ MP_CLEAR
A tile without any structures, i.e. grass, rocks, farm fields etc.
@ MP_HOUSE
A house by a town.
void BuildOwnerLegend()
Completes the array for the owned property legend.
IndustryType type
Type of industry. Only valid for industry entries.
static uint32_t GetSmallMapVehiclesPixels(TileIndex, TileType t)
Return the colour a tile would be displayed with in the small map in mode "Vehicles".
static const IndustryType NUM_INDUSTRYTYPES
total number of industry types, new and old; limited to 240 because we need some special ids like INV...
uint min_number_of_fixed_rows
Minimal number of rows in the legends for the fixed layouts only (all except #SMT_INDUSTRY).
bool IsClearGround(Tile t, ClearGround ct)
Set the type of clear tile.
byte map_colour
colour used for the small map
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
static bool _smallmap_show_heightmap
Show heightmap in industry and owner mode of smallmap window.
@ WC_INDUSTRY_CARGOES
Industry cargoes chain; Window numbers:
static const uint8_t PC_VERY_DARK_BROWN
Almost-black brown palette colour.
bool ScrollWindowTo(int x, int y, int z, Window *w, bool instant)
Scrolls the viewport in a window to a given location.
static void BreakIndustryChainLink()
Notify the industry chain window to stop sending newly selected industries.
constexpr bool IsInsideMM(const T x, const size_t min, const size_t max) noexcept
Checks if a value is in an interval.
TreeGround GetTreeGround(Tile t)
Returns the groundtype for tree tiles.
static const uint8_t PC_RAINFOREST
Pale green palette colour for rainforest.
const RailTypeInfo * GetRailTypeInfo(RailType railtype)
Returns a pointer to the Railtype information for a given railtype.
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
byte landscape
the landscape we're currently in
static debug_inline uint MaxX()
Gets the maximum X coordinate within the map, including MP_VOID.
std::vector< const CargoSpec * > _sorted_cargo_specs
Cargo specifications sorted alphabetically by name.
#define MOEND()
Macro used for forcing a rebuild of the owner legend the first time it is used.
void OnPaint() override
The window must be repainted.
How all blitters should look like.
static int _smallmap_cargo_count
Number of cargos in the link stats legend.
void SmallMapCenterOnCurrentPos()
Center the small map on the current center of the viewport.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
uint32_t * height_colours
Cached colours for each level in a map.
static const uint8_t PC_WHITE
White palette colour.
ViewportData * viewport
Pointer to viewport data, if present.
static void DrawHorizMapIndicator(int x, int x2, int y)
Draws horizontal part of map indicator.
CompanyID company
Company to display. Only valid for company entries of the owner legend.
#define MS(a, b)
Macro for break marker in arrays of LegendAndColour.
int32_t scroll_x
Horizontal world coordinate of the base tile left of the top-left corner of the smallmap display.
@ TROPICZONE_RAINFOREST
Rainforest tile.
virtual void SetPixel(void *video, int x, int y, uint8_t colour)=0
Draw a pixel with a given colour on the video-buffer.
virtual void Close(int data=0)
Hide the window and all its child windows, and mark them for a later deletion.
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
int32_t subscroll
Number of pixels (0..3) between the right end of the base tile and the pixel at the top-left corner o...
uint8_t smallmap_land_colour
colour used for land and heightmap at the smallmap
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
void SetupWidgetData()
Function to set up widgets depending on the information being shown on the smallmap.
CompanyMask GetOverlayCompanyMask() const
Get a bitmask for company links to be displayed.
bool _ctrl_pressed
Is Ctrl pressed?
@ SND_15_BEEP
19 == 0x13 GUI button click
static const uint TILE_SIZE
Tile size in world coordinates.
constexpr uint CeilDiv(uint a, uint b)
Computes ceil(a / b) for non-negative a and b.
ClientSettings _settings_client
The current settings for this game.
Specification of a cargo type.
@ VSM_VIEWPORT_RMB_FIXED
Viewport moves with mouse movement on holding right mouse button, cursor position is fixed.
@ MP_INDUSTRY
Part of an industry.
constexpr uint Vertical() const
Get total vertical padding of RectPadding.
static int _smallmap_industry_count
Number of used industries.
int zoom
Zoom level. Bigger number means more zoom-out (further away).
static const uint MAX_TILE_HEIGHT
Maximum allowed tile height.
RailType GetRailType(Tile t)
Gets the rail type of the given tile.
int32_t scroll_y
Vertical world coordinate of the base tile left of the top-left corner of the smallmap display.
int virtual_top
Virtual top coordinate.
void SwitchMapType(SmallMapType map_type)
Select a new map type.
Owner
Enum for all companies/owners.
void UpdateLinks()
Update all the links on the map.
@ MP_ROAD
A tile with road (or tram tracks)
Rect WithHeight(int height, bool end=false) const
Copy Rect and set its height.
void OnInit() override
Notification that the nested widget tree gets initialized.
uint column_width
Width of a column in the WID_SM_LEGEND widget.
uint min_number_of_columns
Minimal number of columns in legends.
@ INVALID_ROADTYPE
flag for invalid roadtype
Class managing the smallmap window.
static const uint8_t PC_FIELDS
Light brown palette colour for fields.
static bool show_towns
Display town names in the smallmap.
@ IfEnabled
Only include the heightmap if its enabled in the gui by the player.
byte _colour_gradient[COLOUR_END][8]
All 16 colour gradients 8 colours per gradient from darkest (0) to lightest (7)
static uint8_t _linkstat_colours_in_legenda[]
Link stat colours shown in legenda.
uint GetNumberColumnsLegend(uint width) const
Return number of columns that can be displayed in width pixels.
void DrawSmallMap(DrawPixelInfo *dpi) const
Draws the small map.
GameCreationSettings game_creation
settings used during the creation of a game (map)
Point GetStationMiddle(const Station *st) const
Get the center of the given station as point on the screen in the smallmap window.
void SetZoomLevel(ZoomLevelChange change, const Point *zoom_pt)
Initialize or change the zoom level.
static debug_inline TileType GetTileType(Tile tile)
Get the tiletype of a given tile.
static bool _smallmap_industry_highlight_state
State of highlight blinking.
High level window description.
constexpr uint Horizontal() const
Get total horizontal padding of RectPadding.
static constexpr size_t MAX_SIZE
Make template parameter accessible from outside.
int ScaleGUITrad(int value)
Scale traditional pixel dimensions to GUI zoom level.
static const uint32_t _dark_green_map_heights[]
Height map colours for the dark green colour scheme, ordered by height.
uint GetMinLegendWidth() const
Compute minimal required width of the legends.
@ VS_HIDDEN
Vehicle is not visible.
CargoID Index() const
Determines index of this cargospec.
static const uint8_t PC_GREEN
Green palette colour.
Data structure for viewport, display of a part of the world.
@ TRANSPORT_RAIL
Transport by train.
@ WDP_AUTO
Find a place automatically.
ZoomLevelChange
Available kinds of zoomlevel changes.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
uint GetNumberRowsLegend(uint columns) const
Get the number of rows in the legend from the number of columns.
void DrawVehicles(const DrawPixelInfo *dpi, Blitter *blitter) const
Adds vehicles to the smallmap.
SoundSettings sound
sound effect settings
Rect Translate(int x, int y) const
Copy and translate Rect by x,y pixels.
static Industry * GetByTile(TileIndex tile)
Get the industry of the given tile.
static const byte _vehicle_type_colours[6]
Vehicle colours in #SMT_VEHICLES mode.
static void DrawVertMapIndicator(int x, int y, int y2)
Draws vertical part of map indicator.
int virtual_left
Virtual left coordinate.
IndustryType type
type of industry.
StationRect rect
NOSAVE: Station spread out rectangle maintained by StationRect::xxx() functions.
bool col_break
Perform a column break and go further at the next column.
static uint32_t GetSmallMapVegetationPixels(TileIndex tile, TileType t)
Return the colour a tile would be displayed with in the smallmap in mode "Vegetation".
uint8_t map_height_limit
the maximum allowed heightlevel
TransportType
Available types of transport.
static LegendAndColour _legend_land_contours[]
Legend text giving the colours to look for on the minimap.
@ FS_SMALL
Index of the small font in the font tables.
void DrawMapIndicators() const
Adds map indicators to the smallmap.
static const AndOr _smallmap_contours_andor[]
Colour masks for "Contour" and "Routes" modes.
static uint32_t GetSmallMapRoutesPixels(TileIndex tile, TileType t)
Return the colour a tile would be displayed with in the small map in mode "Routes".
Colour scheme of the smallmap.
ClearGround GetClearGround(Tile t)
Get the type of clear tile.
static int _smallmap_company_count
Number of entries in the owner legend.
static const byte _tiletype_importance[]
Mapping of tile type to importance of the tile (higher number means more interesting to show).
static LegendAndColour _legend_from_industries[NUM_INDUSTRYTYPES+1]
Allow room for all industries, plus a terminator entry This is required in order to have the industry...
static IndustryType _smallmap_industry_highlight
Highlight a specific industry type.
Represents the covered area of e.g.
@ VEH_EFFECT
Effect vehicle type (smoke, explosions, sparks, bubbles)
#define MC(col_break)
Macro for a height legend entry with configurable colour.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
static Blitter * GetCurrentBlitter()
Get the current active blitter (always set by calling SelectBlitter).
bool IsTileOnWater(Tile t)
Tests if the tile was built on water.
int GetPositionOnLegend(Point pt)
Determines the mouse position on the legend.
StringID legend
String corresponding to the coloured item.
uint8_t linkgraph_colours
linkgraph overlay colours
Point GetSmallMapStationMiddle(const Window *w, const Station *st)
Determine the middle of a station in the smallmap window.
@ MAX_COMPANIES
Maximum number of companies.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
bool freeform_edges
allow terraforming the tiles at the map edges
Rect Indent(int indent, bool end) const
Copy Rect and indent it from its position.
bool fix_at
mouse is moving, but cursor is not (used for scrolling)
static uint _industry_to_list_pos[NUM_INDUSTRYTYPES]
For connecting industry type to position in industries list(small map legend)
std::bitset< NUM_INDUSTRYTYPES > _displayed_industries
Communication from the industry chain window to the smallmap window about what industries to display.
uint8_t colour
Colour of the item on the map.
Rect WithWidth(int width, bool end) const
Copy Rect and set its width.
Owner GetTileOwner(Tile tile)
Returns the owner of a tile.
static const uint8_t PC_GRASS_LAND
Dark green palette colour for grass land.
static const AndOr _smallmap_vehicles_andor[]
Colour masks for "Vehicles", "Industry", and "Vegetation" modes.
@ MP_TUNNELBRIDGE
Tunnel entry/exit and bridge heads.
static SmallMapColourScheme _heightmap_schemes[]
Available colour schemes for height maps.
@ VSM_MAP_RMB_FIXED
Map moves with mouse movement on holding right mouse button, cursor position is fixed.
static const uint8_t PC_VERY_LIGHT_YELLOW
Almost-white yellow palette colour.
int virtual_width
width << zoom
Coordinates of a point in 2D.
bool ScrollMainWindowTo(int x, int y, int z, bool instant)
Scrolls the main window to given coordinates.
uint legend_width
Width of legend 'blob'.
@ Always
Always include the heightmap.
int CenterBounds(int min, int max, int size)
Determine where to draw a centred object inside a widget.
void ForceRefresh()
Force a full refresh of the map.
uint8_t scroll_mode
viewport scroll mode
void GfxFillRect(int left, int top, int right, int bottom, int colour, FillRectMode mode)
Applies a certain FillRectMode-operation to a rectangle [left, right] x [top, bottom] on the screen.
static constexpr NWidgetPart _nested_smallmap_display[]
Widget parts of the smallmap display.
Defines the data structure for constructing industry.
void DrawSmallMapColumn(void *dst, uint xc, uint yc, int pitch, int reps, int start_pos, int end_pos, Blitter *blitter) const
Draws one column of tiles of the small map in a certain mode onto the screen buffer,...
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
StationType GetStationType(Tile t)
Get the station type of this tile.
Point InverseRemapCoords2(int x, int y, bool clamp_to_map, bool *clamped)
Map 2D viewport or smallmap coordinate to 3D world or tile coordinate.
#define DECLARE_ENUM_AS_ADDABLE(EnumType)
Operator that allows this enumeration to be added to any other enumeration.
bool FillDrawPixelInfo(DrawPixelInfo *n, int left, int top, int width, int height)
Set up a clipping area for only drawing into a certain area.
void BuildIndustriesLegend()
Fills an array for the industries legends.
bool IsTileForestIndustry(TileIndex tile)
Check whether the tile is a forest.
@ MP_TREES
Tile got trees.
const RoadTypeInfo * GetRoadTypeInfo(RoadType roadtype)
Returns a pointer to the Roadtype information for a given roadtype.
#define MK(a, b)
Macro for ordinary entry of LegendAndColour.
bool enabled
entity still available (by default true).newgrf can disable it, though
#define MKEND()
Macro for end of list marker in arrays of LegendAndColour.
static const uint8_t PC_YELLOW
Yellow palette colour.
static const uint8_t PC_DARK_RED
Dark red palette colour.
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
static uint MaxY()
Gets the maximum Y coordinate within the map, including MP_VOID.
@ MP_VOID
Invisible tiles at the SW and SE border.
virtual void * MoveTo(void *video, int x, int y)=0
Move the destination pointer the requested amount x and y, keeping in mind any pitch and bpp of the r...
static const uint8_t PC_TREES
Green palette colour for trees.
static const IndustryType INVALID_INDUSTRYTYPE
one above amount is considered invalid
void SetOverlayCargoMask()
Set the link graph overlay cargo mask from the legend.
void SetNewScroll(int sx, int sy, int sub)
Set new scroll_x, scroll_y, and subscroll values after limiting them such that the center of the smal...
TileType
The different types of tiles.
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
Window * GetMainWindow()
Get the main window, i.e.
static const uint8_t PC_ORANGE
Orange palette colour.
void InvalidateWindowClassesData(WindowClass cls, int data, bool gui_scope)
Mark window data of all windows of a given class as invalid (in need of re-computing) Note that by de...
@ OWNER_NONE
The tile has no ownership.
Class to backup a specific variable and restore it upon destruction of this object to prevent stack v...
void ShowSmallMap()
Show the smallmap window.
@ MP_STATION
A tile of a station.
bool show_on_map
For filtering industries, if true, industry is shown on the map in colour.
byte map_colour
Colour on mini-map.
static uint16_t GetIndustryTypeCount(IndustryType type)
Get the count of industries for this type.
void DrawTowns(const DrawPixelInfo *dpi) const
Adds town names to the smallmap.
TransportType GetTunnelBridgeTransportType(Tile t)
Tunnel: Get the transport type of the tunnel (road or rail) Bridge: Get the transport type of the bri...
static const uint8_t PC_GREY
Grey palette colour.
#define MAX_UVALUE(type)
The largest value that can be entered in a variable.
static uint _company_to_list_pos[MAX_COMPANIES]
For connecting company ID to position in owner list (small map legend)
static const uint8_t PC_WATER
Dark blue palette colour for water.
uint8_t scrollwheel_scrolling
scrolling using the scroll wheel?
StringID name
Name of this type of cargo.
static const uint8_t PC_BLACK
Black palette colour.
static SmallMapType map_type
Currently displayed legends.
OrthogonalTileArea TileArea
Shorthand for the much more common orthogonal tile area.
Point RemapTile(int tile_x, int tile_y) const
Remap tile to location on this smallmap.
static const uint32_t _violet_map_heights[]
Height map colours for the violet colour scheme, ordered by height.
void Blink()
Blink the industries (if hover over an industry).
@ VS_UNCLICKABLE
Vehicle is not clickable by the user (shadow vehicles).
static LegendAndColour _legend_linkstats[NUM_CARGO+lengthof(_linkstat_colours_in_legenda)+1]
Legend entries for the link stats view.
bool click_beep
Beep on a random selection of buttons.
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
#define lengthof(x)
Return the length of an fixed size array.
static debug_inline TileIndex TileXY(uint x, uint y)
Returns the TileIndex of a coordinate.
uint32_t GetTileColours(const TileArea &ta) const
Decide which colours to show to the user for a group of tiles.
static const uint32_t _green_map_heights[]
Height map colours for the green colour scheme, ordered by height.
static const uint8_t PC_ROUGH_LAND
Dark green palette colour for rough land.
static debug_inline uint TileHeight(Tile tile)
Returns the height of a tile.
static uint32_t GetSmallMapIndustriesPixels(TileIndex tile, TileType t)
Return the colour a tile would be displayed with in the small map in mode "Industries".
int DrawString(int left, int right, int top, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
@ INVALID_COMPANY
An invalid company.
@ TRANSPORT_ROAD
Transport by road vehicle.
static const int TILE_HEIGHT_STEP
One Z unit tile height difference is displayed as 50m.
static uint32_t GetSmallMapLinkStatsPixels(TileIndex tile, TileType t)
Return the colour a tile would be displayed with in the small map in mode "link stats".
@ TREE_GROUND_SNOW_DESERT
a desert or snow tile, depend on landscape
IncludeHeightmap
Enum for how to include the heightmap pixels/colours in small map related functions.
ConstructionSettings construction
construction of things in-game
const IndustrySpec * GetIndustrySpec(IndustryType thistype)
Accessor for array _industry_specs.
Data structure for an opened window.
StringID name
Displayed name of the industry.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
static const uint8_t PC_RED
Red palette colour.
void SelectLegendItem(int click_pos, LegendAndColour *legend, int end_legend_item, int begin_legend_item=0)
Select and toggle a legend item.
static const uint8_t PC_DARK_GREY
Dark grey palette colour.
constexpr T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
void RebuildColourIndexIfNecessary()
Rebuilds the colour indices used for fast access to the smallmap contour colours based on the heightl...
static debug_inline uint TileX(TileIndex tile)
Get the X component of a tile.
int virtual_height
height << zoom
static const CargoID NUM_CARGO
Maximum number of cargo types in a game.
static int map_height_limit
Currently used/cached map height limit.
@ ZLC_INITIALIZE
Initialize zoom level.
Point InverseRemapCoords(int x, int y)
Map 2D viewport or smallmap coordinate to 3D world or tile coordinate.
int Width() const
Get width of Rect.
void ClampToMap()
Clamp the tile area to map borders.
Point ComputeScroll(int tx, int ty, int x, int y, int *sub) const
Compute base parameters of the smallmap such that tile (tx, ty) starts at pixel (x,...
#define MO(a, b)
Macro for non-company owned property entry of LegendAndColour.
Structure for holding relevant data for legends in small map.
Specification of a rectangle with absolute coordinates of all edges.
Point pos
logical mouse position
static const uint8_t LINK_COLOURS[][12]
Colours for the various "load" states of links.
bool end
This is the end of the list.
static uint32_t GetSmallMapContoursPixels(TileIndex tile, TileType t)
Return the colour a tile would be displayed with in the small map in mode "Contour".
@ OWNER_WATER
The tile/execution is done by "water".
TropicZone GetTropicZone(Tile tile)
Get the tropic zone.
static constexpr NWidgetPart _nested_smallmap_bar[]
Widget parts of the smallmap legend bar + image buttons.
void BuildLinkStatsLegend()
Populate legend table for the link stat view.
uint32_t GetSmallMapOwnerPixels(TileIndex tile, TileType t, IncludeHeightmap include_heightmap)
Return the colour a tile would be displayed with in the small map in mode "Owner".
bool _scrolling_viewport
A viewport is being scrolled with the mouse.
@ WC_SMALLMAP
Small map; Window numbers:
Point PixelToTile(int px, int py, int *sub, bool add_sub=true) const
Determine the tile relative to the base tile of the smallmap, and the pixel position at that tile for...
@ TD_RTL
Text is written right-to-left by default.
TextDirection _current_text_dir
Text direction of the currently selected language.
const uint32_t * height_colours_base
Base table for determining the colours.
uint GetClearDensity(Tile t)
Get the density of a non-field clear tile.
static const uint8_t PC_LIGHT_BLUE
Light blue palette colour.
static const int NUM_NO_COMPANY_ENTRIES
Number of entries in the owner legend that are not companies.
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
@ OWNER_TOWN
A town owns the tile, or a town is expanding.
uint GetLegendHeight(uint num_columns) const
Compute height given a number of columns.
SmallMapType
Types of legends in the WID_SM_LEGEND widget.
GUISettings gui
settings related to the GUI
uint8_t height
Height in tiles. Only valid for height legend entries.
void BuildLandLegend()
(Re)build the colour tables for the legends.
size_t colour_count
The number of colours.
Data about how and where to blit pixels.
static const uint8_t PC_BARE_LAND
Brown palette colour for bare land.
@ TREE_GROUND_ROUGH_SNOW
A snow tile that is rough underneath.