mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-08-20 04:59:11 +00:00
Feature: Count the number of towns and cities in town directory
This commit is contained in:
@@ -3510,7 +3510,9 @@ STR_TOWN_DIRECTORY_NONE :{ORANGE}- None
|
|||||||
STR_TOWN_DIRECTORY_TOWN :{ORANGE}{TOWN}{BLACK} ({COMMA})
|
STR_TOWN_DIRECTORY_TOWN :{ORANGE}{TOWN}{BLACK} ({COMMA})
|
||||||
STR_TOWN_DIRECTORY_CITY :{ORANGE}{TOWN}{YELLOW} (City){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_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
|
# Town view window
|
||||||
STR_TOWN_VIEW_TOWN_CAPTION :{WHITE}{TOWN}
|
STR_TOWN_VIEW_TOWN_CAPTION :{WHITE}{TOWN}
|
||||||
|
@@ -143,6 +143,7 @@ private:
|
|||||||
void FillCachedName() const;
|
void FillCachedName() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
uint CountTowns(bool cities);
|
||||||
uint32_t GetWorldPopulation();
|
uint32_t GetWorldPopulation();
|
||||||
|
|
||||||
void UpdateAllTownVirtCoords();
|
void UpdateAllTownVirtCoords();
|
||||||
|
@@ -456,6 +456,20 @@ uint32_t GetWorldPopulation()
|
|||||||
return pop;
|
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.
|
* 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).
|
* To improve performance only checks stations that cover the provided house area (doesn't need to contain an actual house).
|
||||||
|
@@ -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),
|
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(),
|
SetFill(1, 0), SetResize(1, 1), SetScrollbar(WID_TD_SCROLLBAR), EndContainer(),
|
||||||
NWidget(WWT_PANEL, COLOUR_BROWN),
|
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(),
|
||||||
EndContainer(),
|
EndContainer(),
|
||||||
NWidget(NWID_VERTICAL),
|
NWidget(NWID_VERTICAL),
|
||||||
@@ -801,6 +803,14 @@ public:
|
|||||||
void SetStringParameters(int widget) const override
|
void SetStringParameters(int widget) const override
|
||||||
{
|
{
|
||||||
switch (widget) {
|
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:
|
case WID_TD_WORLD_POPULATION:
|
||||||
SetDParam(0, GetWorldPopulation());
|
SetDParam(0, GetWorldPopulation());
|
||||||
break;
|
break;
|
||||||
@@ -909,6 +919,22 @@ public:
|
|||||||
*size = maxdim(*size, d);
|
*size = maxdim(*size, d);
|
||||||
break;
|
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: {
|
case WID_TD_WORLD_POPULATION: {
|
||||||
SetDParamMaxDigits(0, 10);
|
SetDParamMaxDigits(0, 10);
|
||||||
Dimension d = GetStringBoundingBox(STR_TOWN_POPULATION);
|
Dimension d = GetStringBoundingBox(STR_TOWN_POPULATION);
|
||||||
|
@@ -17,6 +17,8 @@ enum TownDirectoryWidgets {
|
|||||||
WID_TD_FILTER, ///< Filter of name.
|
WID_TD_FILTER, ///< Filter of name.
|
||||||
WID_TD_LIST, ///< List of towns.
|
WID_TD_LIST, ///< List of towns.
|
||||||
WID_TD_SCROLLBAR, ///< Scrollbar for the town list.
|
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.
|
WID_TD_WORLD_POPULATION, ///< The world's population.
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user