diff --git a/src/lang/english.txt b/src/lang/english.txt index 7936796d61..f0320f55a4 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -3510,7 +3510,9 @@ STR_TOWN_DIRECTORY_NONE :{ORANGE}- None STR_TOWN_DIRECTORY_TOWN :{ORANGE}{TOWN}{BLACK} ({COMMA}) STR_TOWN_DIRECTORY_CITY :{ORANGE}{TOWN}{YELLOW} (City){BLACK} ({COMMA}) STR_TOWN_DIRECTORY_LIST_TOOLTIP :{BLACK}Town names - click on name to centre main view on town. Ctrl+Click opens a new viewport on town location -STR_TOWN_POPULATION :{BLACK}World population: {COMMA} +STR_NUM_TOWNS :{BLACK}Towns: {ORANGE}{COMMA} +STR_NUM_CITIES :{BLACK}Cities: {ORANGE}{COMMA} +STR_TOWN_POPULATION :{BLACK}World population: {ORANGE}{COMMA} # Town view window STR_TOWN_VIEW_TOWN_CAPTION :{WHITE}{TOWN} diff --git a/src/town.h b/src/town.h index c33a05a6a1..5af4436c88 100644 --- a/src/town.h +++ b/src/town.h @@ -143,6 +143,7 @@ private: void FillCachedName() const; }; +uint CountTowns(bool cities); uint32_t GetWorldPopulation(); void UpdateAllTownVirtCoords(); diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp index 50b38fea37..05ef7dd15a 100644 --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -456,6 +456,20 @@ uint32_t GetWorldPopulation() return pop; } +/** + * Get the number of towns or cities on the map. + * @param cities Count cities instead of towns. + * @return The number of towns or cities. + */ +uint CountTowns(bool cities) +{ + uint total = 0; + for (const Town *t : Town::Iterate()) { + if (cities == t->larger_town) total++; + } + return total; +} + /** * Remove stations from nearby station list if a town is no longer in the catchment area of each. * To improve performance only checks stations that cover the provided house area (doesn't need to contain an actual house). diff --git a/src/town_gui.cpp b/src/town_gui.cpp index 15c1be5b27..6a580cfa05 100644 --- a/src/town_gui.cpp +++ b/src/town_gui.cpp @@ -692,7 +692,9 @@ static const NWidgetPart _nested_town_directory_widgets[] = { NWidget(WWT_PANEL, COLOUR_BROWN, WID_TD_LIST), SetDataTip(0x0, STR_TOWN_DIRECTORY_LIST_TOOLTIP), SetFill(1, 0), SetResize(1, 1), SetScrollbar(WID_TD_SCROLLBAR), EndContainer(), NWidget(WWT_PANEL, COLOUR_BROWN), - NWidget(WWT_TEXT, COLOUR_BROWN, WID_TD_WORLD_POPULATION), SetPadding(2, 0, 2, 2), SetMinimalTextLines(1, 0), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_TOWN_POPULATION, STR_NULL), + NWidget(WWT_TEXT, COLOUR_BROWN, WID_TD_NUM_TOWNS), SetPadding(2, 0, 0, 2), SetMinimalTextLines(1, 0), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_NUM_TOWNS, STR_NULL), + NWidget(WWT_TEXT, COLOUR_BROWN, WID_TD_NUM_CITIES), SetPadding(0, 0, 0, 2), SetMinimalTextLines(1, 0), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_NUM_CITIES, STR_NULL), + NWidget(WWT_TEXT, COLOUR_BROWN, WID_TD_WORLD_POPULATION), SetPadding(0, 0, 2, 2), SetMinimalTextLines(1, 0), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_TOWN_POPULATION, STR_NULL), EndContainer(), EndContainer(), NWidget(NWID_VERTICAL), @@ -801,6 +803,14 @@ public: void SetStringParameters(int widget) const override { switch (widget) { + case WID_TD_NUM_TOWNS: + SetDParam(0, CountTowns(false)); + break; + + case WID_TD_NUM_CITIES: + SetDParam(0, CountTowns(true)); + break; + case WID_TD_WORLD_POPULATION: SetDParam(0, GetWorldPopulation()); break; @@ -909,6 +919,22 @@ public: *size = maxdim(*size, d); break; } + case WID_TD_NUM_TOWNS: { + SetDParamMaxDigits(0, 5); + Dimension d = GetStringBoundingBox(STR_NUM_TOWNS); + d.width += padding.width; + d.height += padding.height; + *size = maxdim(*size, d); + break; + } + case WID_TD_NUM_CITIES: { + SetDParamMaxDigits(0, 5); + Dimension d = GetStringBoundingBox(STR_NUM_CITIES); + d.width += padding.width; + d.height += padding.height; + *size = maxdim(*size, d); + break; + } case WID_TD_WORLD_POPULATION: { SetDParamMaxDigits(0, 10); Dimension d = GetStringBoundingBox(STR_TOWN_POPULATION); diff --git a/src/widgets/town_widget.h b/src/widgets/town_widget.h index f16a8a585e..9f7b5139b5 100644 --- a/src/widgets/town_widget.h +++ b/src/widgets/town_widget.h @@ -17,6 +17,8 @@ enum TownDirectoryWidgets { WID_TD_FILTER, ///< Filter of name. WID_TD_LIST, ///< List of towns. WID_TD_SCROLLBAR, ///< Scrollbar for the town list. + WID_TD_NUM_TOWNS, ///< Total number of towns. + WID_TD_NUM_CITIES, ///< Total number of cities. WID_TD_WORLD_POPULATION, ///< The world's population. };