Go to the documentation of this file.
40 #include "table/strings.h"
45 TownKdtree _town_local_authority_kdtree(&Kdtree_TownXYFunc);
49 static const NWidgetPart _nested_town_authority_widgets[] = {
59 NWidget(
WWT_PANEL, COLOUR_BROWN,
WID_TA_COMMAND_LIST),
SetMinimalSize(317, 52),
SetResize(1, 0),
SetDataTip(0x0, STR_LOCAL_AUTHORITY_ACTIONS_TOOLTIP),
EndContainer(),
62 NWidget(
WWT_PUSHTXTBTN, COLOUR_BROWN,
WID_TA_EXECUTE),
SetMinimalSize(317, 12),
SetResize(1, 0),
SetFill(1, 0),
SetDataTip(STR_LOCAL_AUTHORITY_DO_IT_BUTTON, STR_LOCAL_AUTHORITY_DO_IT_TOOLTIP),
126 this->exclusive_size =
GetSpriteSize(SPR_EXCLUSIVE_TRANSPORT);
153 int exclusive_y_offset = (this->
resize.
step_height - this->exclusive_size.height) / 2;
155 DrawString(r.left, r.right, r.top + text_y_offset, STR_LOCAL_AUTHORITY_COMPANY_RATINGS);
165 if ((
HasBit(this->town->
have_ratings, c->index) || this->town->exclusivity == c->index)) {
171 int rating = this->town->
ratings[c->index];
172 StringID str = STR_CARGO_RATING_APPALLING;
173 if (rating > RATING_APPALLING) str++;
174 if (rating > RATING_VERYPOOR) str++;
175 if (rating > RATING_POOR) str++;
176 if (rating > RATING_MEDIOCRE) str++;
177 if (rating > RATING_GOOD) str++;
178 if (rating > RATING_VERYGOOD) str++;
179 if (rating > RATING_EXCELLENT) str++;
183 DrawSprite(SPR_EXCLUSIVE_TRANSPORT, COMPANY_SPRITE_COLOUR(c->index), exclusive.left, text.top + exclusive_y_offset);
186 DrawString(text.left, text.right, text.top + text_y_offset, STR_LOCAL_AUTHORITY_COMPANY_RATING);
191 text.bottom = text.top - 1;
192 if (text.bottom > r.bottom) {
203 DrawString(r, STR_LOCAL_AUTHORITY_ACTIONS_TITLE);
209 if (!
HasBit(this->enabled_actions, i))
continue;
213 if (
HasBit(this->available_actions, i)) action_colour = TC_ORANGE;
214 if (this->sel_index == i) action_colour = TC_WHITE;
216 DrawString(r, STR_LOCAL_AUTHORITY_ACTION_SMALL_ADVERTISING_CAMPAIGN + i, action_colour);
230 if (this->sel_index != -1) {
236 STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_SMALL_ADVERTISING + this->sel_index,
237 affordable ? TC_YELLOW : TC_RED);
247 assert(size->width > padding.width && size->height > padding.height);
253 d.width += padding.width;
254 d.height += padding.height;
263 size->width = std::max(size->width,
GetStringBoundingBox(STR_LOCAL_AUTHORITY_ACTION_SMALL_ADVERTISING_CAMPAIGN + i).
width + padding.width);
265 size->width += padding.width;
270 size->height = 9 *
resize->height + padding.height;
279 bool new_show_state = !this->town->
show_zone;
280 TownID index = this->town->
index;
282 new_show_state ? _town_local_authority_kdtree.
Insert(index) : _town_local_authority_kdtree.
Remove(index);
300 if (click_count == 1 || y < 0 || !
HasBit(this->available_actions, y))
break;
317 if (!gui_scope)
return;
320 if (!
HasBit(this->enabled_actions, this->sel_index)) {
321 this->sel_index = -1;
327 WDP_AUTO,
"view_town_authority", 317, 222,
330 _nested_town_authority_widgets,
lengthof(_nested_town_authority_widgets)
333 static void ShowTownAuthorityWindow(uint town)
335 AllocateWindowDescFront<TownAuthorityWindow>(&_town_authority_desc, town);
345 static const int WID_TV_HEIGHT_NORMAL = 150;
391 DrawString(tr, STR_TOWN_VIEW_POPULATION_HOUSES);
397 DrawString(tr, STR_TOWN_VIEW_CARGO_LAST_MONTH_MAX);
403 DrawString(tr, STR_TOWN_VIEW_CARGO_LAST_MONTH_MAX);
407 for (
int i = TE_BEGIN; i <
TE_END; i++) {
408 if (this->town->
goal[i] == 0)
continue;
413 DrawString(tr, STR_TOWN_VIEW_CARGO_FOR_TOWNGROWTH);
421 assert(cargo !=
nullptr);
427 string = STR_TOWN_VIEW_CARGO_FOR_TOWNGROWTH_DELIVERED_GENERAL;
429 string = STR_TOWN_VIEW_CARGO_FOR_TOWNGROWTH_REQUIRED_GENERAL;
432 string = STR_TOWN_VIEW_CARGO_FOR_TOWNGROWTH_REQUIRED_WINTER;
438 string = STR_TOWN_VIEW_CARGO_FOR_TOWNGROWTH_DELIVERED;
440 string = STR_TOWN_VIEW_CARGO_FOR_TOWNGROWTH_REQUIRED;
457 DrawString(tr, STR_TOWN_VIEW_TOWN_GROW_STOPPED);
469 if (!this->town->
text.empty()) {
501 static bool _warn_town_no_roads =
false;
505 _warn_town_no_roads =
true;
536 for (
int i = TE_BEGIN; i <
TE_END; i++) {
537 if (this->town->
goal[i] == 0)
continue;
551 if (!this->town->
text.empty()) {
559 void ResizeWindowAsNeeded()
585 if (!gui_scope)
return;
588 this->ResizeWindowAsNeeded();
593 if (str ==
nullptr)
return;
599 static const NWidgetPart _nested_town_game_view_widgets[] = {
614 NWidget(
WWT_PANEL, COLOUR_BROWN,
WID_TV_INFO),
SetMinimalSize(260, 32),
SetResize(1, 0),
SetFill(1, 0),
EndContainer(),
616 NWidget(
WWT_PUSHTXTBTN, COLOUR_BROWN,
WID_TV_SHOW_AUTHORITY),
SetMinimalSize(80, 12),
SetFill(1, 1),
SetResize(1, 0),
SetDataTip(STR_TOWN_VIEW_LOCAL_AUTHORITY_BUTTON, STR_TOWN_VIEW_LOCAL_AUTHORITY_TOOLTIP),
617 NWidget(
WWT_TEXTBTN, COLOUR_BROWN,
WID_TV_CATCHMENT),
SetMinimalSize(40, 12),
SetFill(1, 1),
SetResize(1, 0),
SetDataTip(STR_BUTTON_CATCHMENT, STR_TOOLTIP_CATCHMENT),
623 WDP_AUTO,
"view_town", 260, TownViewWindow::WID_TV_HEIGHT_NORMAL,
626 _nested_town_game_view_widgets,
lengthof(_nested_town_game_view_widgets)
629 static const NWidgetPart _nested_town_editor_view_widgets[] = {
644 NWidget(
WWT_PANEL, COLOUR_BROWN,
WID_TV_INFO),
SetMinimalSize(260, 32),
SetResize(1, 0),
SetFill(1, 0),
EndContainer(),
646 NWidget(
WWT_PUSHTXTBTN, COLOUR_BROWN,
WID_TV_EXPAND),
SetMinimalSize(80, 12),
SetFill(1, 1),
SetResize(1, 0),
SetDataTip(STR_TOWN_VIEW_EXPAND_BUTTON, STR_TOWN_VIEW_EXPAND_TOOLTIP),
647 NWidget(
WWT_PUSHTXTBTN, COLOUR_BROWN,
WID_TV_DELETE),
SetMinimalSize(80, 12),
SetFill(1, 1),
SetResize(1, 0),
SetDataTip(STR_TOWN_VIEW_DELETE_BUTTON, STR_TOWN_VIEW_DELETE_TOOLTIP),
648 NWidget(
WWT_TEXTBTN, COLOUR_BROWN,
WID_TV_CATCHMENT),
SetMinimalSize(40, 12),
SetFill(1, 1),
SetResize(1, 0),
SetDataTip(STR_BUTTON_CATCHMENT, STR_TOOLTIP_CATCHMENT),
654 WDP_AUTO,
"view_town_scen", 260, TownViewWindow::WID_TV_HEIGHT_NORMAL,
657 _nested_town_editor_view_widgets,
lengthof(_nested_town_editor_view_widgets)
660 void ShowTownViewWindow(TownID town)
662 if (_game_mode == GM_EDITOR) {
663 AllocateWindowDescFront<TownViewWindow>(&_town_editor_view_desc, town);
665 AllocateWindowDescFront<TownViewWindow>(&_town_game_view_desc, town);
669 static const NWidgetPart _nested_town_directory_widgets[] = {
687 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),
714 void BuildSortTownList()
720 if (this->string_filter.
IsEmpty()) {
721 this->towns.push_back(t);
725 this->string_filter.
AddLine(t->GetCachedName());
726 if (this->string_filter.
GetState()) this->towns.push_back(t);
729 this->towns.shrink_to_fit();
731 this->vscroll->
SetCount((uint)this->towns.size());
741 return strnatcmp(a->GetCachedName(), b->GetCachedName()) < 0;
750 return a_population < b_population;
756 bool before = !TownDirectoryWindow::last_sorting.
order;
764 return a_rating < b_rating;
785 this->BuildSortTownList();
813 return t->
larger_town ? STR_TOWN_DIRECTORY_CITY : STR_TOWN_DIRECTORY_TOWN;
826 if (this->towns.size() == 0) {
834 int icon_x = tr.
WithWidth(icon_size.width, rtl).left;
837 for (uint i = this->vscroll->
GetPosition(); i < this->towns.size(); i++) {
838 const Town *t = this->towns[i];
843 DrawSprite(SPR_TOWN_RATING_NA, PAL_NONE, icon_x, tr.top + (this->resize.step_height - icon_size.height) / 2);
845 SpriteID icon = SPR_TOWN_RATING_APALLING;
848 DrawSprite(icon, PAL_NONE, icon_x, tr.top + (this->resize.step_height - icon_size.height) / 2);
869 d.height += padding.height;
878 d.width += padding.width;
879 d.height += padding.height;
885 for (uint i = 0; i < this->towns.size(); i++) {
886 const Town *t = this->towns[i];
888 assert(t !=
nullptr);
895 d.width += icon_size.width + 2;
896 d.height = std::max(d.height, icon_size.height);
897 resize->height = d.height;
899 d.width += padding.width;
900 d.height += padding.height;
907 d.width += padding.width;
908 d.height += padding.height;
921 this->last_sorting = this->towns.
GetListing();
924 this->last_sorting.
order = !this->last_sorting.
order;
938 if (id_v >= this->towns.size())
return;
940 const Town *t = this->towns[id_v];
941 assert(t !=
nullptr);
956 if (this->towns.
SortType() != index) {
958 this->last_sorting = this->towns.
GetListing();
959 this->BuildSortTownList();
965 if (this->towns.
NeedRebuild()) this->BuildSortTownList();
971 this->BuildSortTownList();
996 case TDIWD_FORCE_REBUILD:
1001 case TDIWD_POPULATION_CHANGE:
1011 Listing TownDirectoryWindow::last_sorting = {
false, 0};
1016 STR_SORT_BY_POPULATION,
1024 &TownPopulationSorter,
1032 _nested_town_directory_widgets,
lengthof(_nested_town_directory_widgets)
1035 void ShowTownDirectory()
1043 if (result.
Failed())
return;
1054 static const NWidgetPart _nested_found_town_widgets[] = {
1065 SetDataTip(STR_FOUND_TOWN_NEW_TOWN_BUTTON, STR_FOUND_TOWN_NEW_TOWN_TOOLTIP),
SetPadding(0, 2, 1, 2),
1067 SetDataTip(STR_FOUND_TOWN_RANDOM_TOWN_BUTTON, STR_FOUND_TOWN_RANDOM_TOWN_TOOLTIP),
SetPadding(0, 2, 1, 2),
1069 SetDataTip(STR_FOUND_TOWN_MANY_RANDOM_TOWNS, STR_FOUND_TOWN_RANDOM_TOWNS_TOOLTIP),
SetPadding(0, 2, 1, 2),
1071 SetDataTip(STR_FOUND_TOWN_EXPAND_ALL_TOWNS, STR_FOUND_TOWN_EXPAND_ALL_TOWNS_TOOLTIP),
SetPadding(0, 2, 0, 2),
1073 NWidget(
WWT_LABEL, COLOUR_DARK_GREEN),
SetMinimalSize(156, 14),
SetPadding(0, 2, 0, 2),
SetDataTip(STR_FOUND_TOWN_NAME_TITLE, STR_NULL),
1075 SetDataTip(STR_FOUND_TOWN_NAME_EDITOR_TITLE, STR_FOUND_TOWN_NAME_EDITOR_HELP),
1076 NWidget(
WWT_PUSHTXTBTN, COLOUR_GREY,
WID_TF_TOWN_NAME_RANDOM),
SetMinimalSize(78, 12),
SetPadding(0, 2, 0, 2),
SetFill(1, 0),
1077 SetDataTip(STR_FOUND_TOWN_NAME_RANDOM_BUTTON, STR_FOUND_TOWN_NAME_RANDOM_TOOLTIP),
1086 SetDataTip(STR_FOUND_TOWN_INITIAL_SIZE_SMALL_BUTTON, STR_FOUND_TOWN_INITIAL_SIZE_TOOLTIP),
1088 SetDataTip(STR_FOUND_TOWN_INITIAL_SIZE_MEDIUM_BUTTON, STR_FOUND_TOWN_INITIAL_SIZE_TOOLTIP),
1093 SetDataTip(STR_FOUND_TOWN_INITIAL_SIZE_LARGE_BUTTON, STR_FOUND_TOWN_INITIAL_SIZE_TOOLTIP),
1095 SetDataTip(STR_FOUND_TOWN_SIZE_RANDOM, STR_FOUND_TOWN_INITIAL_SIZE_TOOLTIP),
1098 NWidget(
WWT_TEXTBTN, COLOUR_GREY,
WID_TF_CITY),
SetPadding(0, 2, 0, 2),
SetMinimalSize(156, 12),
SetFill(1, 0),
1116 NWidget(
WWT_TEXTBTN, COLOUR_GREY,
WID_TF_LAYOUT_RANDOM),
SetPadding(0, 2, 0, 2),
SetMinimalSize(0, 12),
SetFill(1, 0),
1117 SetDataTip(STR_FOUND_TOWN_SELECT_LAYOUT_RANDOM, STR_FOUND_TOWN_SELECT_TOWN_ROAD_LAYOUT),
SetFill(1, 0),
1143 this->RandomTownName();
1144 this->UpdateButtons(
true);
1147 void RandomTownName()
1151 if (!this->townnamevalid) {
1152 this->townname_editbox.text.
DeleteAll();
1154 GetTownName(this->townname_editbox.text.
buf, &this->params, this->townnameparts, &this->townname_editbox.text.buf[this->townname_editbox.text.max_bytes - 1]);
1162 void UpdateButtons(
bool check_availability)
1164 if (check_availability && _game_mode != GM_EDITOR) {
1184 template <
typename Tcallback>
1185 void ExecuteFoundTownCommand(
TileIndex tile,
bool random,
StringID errstr, Tcallback cc)
1189 if (!this->townnamevalid) {
1190 name = this->townname_editbox.text.
buf;
1195 if (strcmp(buf, this->townname_editbox.text.
buf) != 0) name = this->townname_editbox.text.
buf;
1199 tile, this->town_size, this->city, this->town_layout, random,
townnameparts, name);
1213 this->ExecuteFoundTownCommand(0,
true, STR_ERROR_CAN_T_GENERATE_TOWN, CcFoundRandomTown);
1217 this->RandomTownName();
1228 old_generating_world.
Restore();
1240 this->UpdateButtons(
false);
1252 this->UpdateButtons(
false);
1259 this->ExecuteFoundTownCommand(tile,
false, STR_ERROR_CAN_T_FOUND_TOWN_HERE, CcFoundTown);
1265 this->UpdateButtons(
false);
1275 if (!gui_scope)
return;
1276 this->UpdateButtons(
true);
1284 _nested_found_town_widgets,
lengthof(_nested_found_town_widgets)
1287 void ShowFoundTownWindow()
1290 AllocateWindowDescFront<FoundTownWindow>(&_found_town_desc, 0);
1293 void InitializeTownGui()
1295 _town_local_authority_kdtree.
Clear();
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
@ TACT_BRIBE
Try to bribe the council.
CompanyMask have_ratings
which companies have a rating
@ TROPICZONE_DESERT
Tile is desert.
void OnPaint() override
The window must be repainted.
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
Update size and resize step of a widget in the window.
void OnPaint() override
The window must be repainted.
uint8 SortType() const
Get the sorttype of the list.
static Titem * Get(size_t index)
Returns Titem with given index.
bool ScrollMainWindowToTile(TileIndex tile, bool instant)
Scrolls the viewport of the main window to a given location.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
void ShowExtraViewportWindow(TileIndex tile=INVALID_TILE)
Show a new Extra Viewport window.
Dimensions (a width and height) of a rectangle in 2D.
void DrawSortButtonState(int widget, SortButtonState state) const
Draw a sort button's up or down arrow symbol.
TownLayout town_layout
select town layout,
bool Sort(Comp compare)
Sort the list.
const Scrollbar * GetScrollbar(uint widnum) const
Return the Scrollbar to a widget index.
@ WDF_CONSTRUCTION
This window is used for construction; close it whenever changing company.
Commands
List of commands.
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
K-dimensional tree, specialised for 2-dimensional space.
@ WL_WARNING
Other information.
bool IsEmpty() const
Check whether any filter words were entered.
Class to backup a specific variable and restore it later.
void ReInit(int rx=0, int ry=0)
Re-initialize a window, and optionally change its size.
void SetFilterTerm(const char *str)
Set the term to filter on.
@ WC_FOUND_TOWN
Found a town; Window numbers:
void OnPlaceObject(Point pt, TileIndex tile) override
The user clicked some place on the map when a tile highlight mode has been set.
@ WF_DISABLE_VP_SCROLL
Window does not do autoscroll,.
ViewportData * viewport
Pointer to viewport data, if present.
bool _network_server
network-server is active
QueryString townname_editbox
Townname editbox.
void OnEditboxChanged(int wid) override
The text in an editbox has been edited.
void OnDropdownSelect(int widget, int index) override
A dropdown option associated to this window has been selected.
uint16 noise_reached
level of noise that all the airports are generating
void CreateNestedTree(bool fill_nested=true)
Perform the first part of the initialization of a nested widget tree.
TownSize
Supported initial town sizes.
Tindex index
Index of this pool item.
void OnHundredthTick() override
Called once every 100 (game) ticks, or once every 3s, whichever comes last.
@ TACT_FUND_BUILDINGS
Fund new buildings.
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
static constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
uint32 goal[NUM_TE]
Amount of cargo required for the town to grow.
QueryString townname_editbox
Filter editbox.
bool _ctrl_pressed
Is Ctrl pressed?
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
void RaiseButtons(bool autoraise=false)
Raise the buttons of the window.
ClientSettings _settings_client
The current settings for this game.
uint GetDesiredInfoHeight(int width) const
Gets the desired height for the information panel.
int DrawString(int left, int right, int top, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
TileIndex xy
town center tile
Specification of a cargo type.
static const StringID sorter_names[]
Names of the sorting functions.
void AddLine(const char *str)
Pass another text line from the current item to the filter.
int32 WindowNumber
Number to differentiate different windows of the same class.
const CargoSpec * FindFirstCargoWithTownEffect(TownEffect effect)
Determines the first cargo with a certain town effect.
void SetSortType(uint8 n_type)
Set the sorttype of the list.
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
byte fund_buildings_months
fund buildings program in action?
@ DC_EXEC
execute the given command
Dimension exclusive_size
Dimensions of exlusive icon.
TownActions available_actions
Actions that are available to execute for the current company.
void OnHundredthTick() override
Called once every 100 (game) ticks, or once every 3s, whichever comes last.
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
bool show_zone
NOSAVE: mark town to show the local authority zone in the viewports.
uint displayed_actions_on_previous_painting
Actions that were available on the previous call to OnPaint()
Data stored about a string that can be modified in the GUI.
bool Succeeded() const
Did this command succeed?
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
bool bribe
enable bribing the local authority
char *const buf
buffer in which text is saved
TownEffect
Town growth effect when delivering cargo.
SmallMap< int, QueryString * > querystrings
QueryString associated to WWT_EDITBOX widgets.
void Remove(const T &element)
Remove a single element from the tree, if it exists.
void ShowErrorMessage(StringID summary_msg, StringID detailed_msg, WarningLevel wl, int x=0, int y=0, const GRFFile *textref_stack_grffile=nullptr, uint textref_stack_size=0, const uint32 *textref_stack=nullptr)
Display an error message in a window.
int DrawStringMultiLine(int left, int right, int top, int bottom, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly over multiple lines.
@ QSF_LEN_IN_CHARS
the length of the string is counted in characters
static const int MAX_CHAR_LENGTH
Max. length of UTF-8 encoded unicode character.
TownSize town_size
Selected town size.
@ TF_CUSTOM_LAYOUT
Allowed, with custom town layout.
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
High level window description.
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
bool fund_buildings
allow funding new buildings
uint32 population
Current population of people.
static bool TownPopulationSorter(const Town *const &a, const Town *const &b)
Sort by population (default descending, as big towns are of the most interest).
CargoID Index() const
Determines index of this cargospec.
bool station_noise_level
build new airports when the town noise level is still within accepted limits
bool IsDescSortOrder() const
Check if the sort order is descending.
@ WDP_AUTO
Find a place automatically.
Data structure describing how to show the list (what sort direction and criteria).
ResizeInfo resize
Resize information.
Common return value for all commands.
byte GetSnowLine()
Get the current snow line, either variable or static.
Town * town
Town being displayed.
Iterable ensemble of each set bit in a value.
char * GetTownName(char *buff, const TownNameParams *par, uint32 townnameparts, const char *last)
Fills buffer with specified town name.
static uint TileHeight(TileIndex tile)
Returns the height of a tile.
SoundSettings sound
sound effect settings
void DrawActions()
Draws the contents of the actions panel.
@ WC_TOWN_AUTHORITY
Town authority; Window numbers:
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
static const uint TOWN_GROWTH_DESERT
The town needs the cargo for growth when on desert (any amount)
bool SortFunction(const const Town * &, const const Town * &)
Signature of sort function.
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
void SetListing(Listing l)
Import sort conditions.
void Insert(const T &element)
Insert a single element in the tree.
bool ScrollWindowToTile(TileIndex tile, Window *w, bool instant)
Scrolls the viewport in a window to a given location.
int sel_index
Currently selected town action, 0 to TACT_COUNT-1, -1 means no action selected.
bool order
Ascending/descending.
static StringID GetTownString(const Town *t)
Get the string to draw the town name.
bool Failed() const
Did this command fail?
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
static bool TownRatingSorter(const Town *const &a, const Town *const &b)
Sort by town rating.
@ TACT_ROAD_REBUILD
Rebuild the roads.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
StringFilter string_filter
Filter for towns.
TownActions GetMaskOfTownActions(CompanyID cid, const Town *t)
Get a list of available actions to do at a town.
static TropicZone GetTropicZone(TileIndex tile)
Get the tropic zone.
uint16 MaxTownNoise() const
Calculate the max town noise.
EconomySettings economy
settings to change the economy
void SetWidgetDisabledState(byte widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
@ WL_INFO
Used for DoCommand-like (and some non-fatal AI GUI) errors/information.
@ ZOOM_LVL_TOWN
Default zoom level for the town view.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
void ShowQueryString(StringID str, StringID caption, uint maxsize, Window *parent, CharSetFilter afilter, QueryStringFlags flags)
Show a query popup window with a textbox in it.
void OnResize() override
Called after the window got resized.
int GetNthSetBit(int n)
Get the position of the Nth set bit.
bool HandlePlacePushButton(Window *w, int widget, CursorID cursor, HighLightStyle mode)
This code is shared for the majority of the pushbuttons.
WindowFlags flags
Window flags.
Rect Indent(int indent, bool end) const
Copy Rect and indent it from its position.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
void OnPaint() override
The window must be repainted.
@ TC_NO_SHADE
Do not add shading to this text colour.
Rect WithWidth(int width, bool end) const
Copy Rect and set its width.
byte LowestSnowLine()
Get the lowest possible snow line height, either variable or static.
bool _networking
are we in networking mode?
bool _shift_pressed
Is Shift pressed?
bool exclusive_rights
allow buying exclusive rights
uint32 GetWorldPopulation()
Determines the world population Basically, count population of all towns, one by one.
uint16 growth_rate
town growth rate
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
Draw a sprite, not in a viewport.
Dimension GetStringMultiLineBoundingBox(StringID str, const Dimension &suggestion)
Calculate string bounding box for multi-line strings.
bool townnamevalid
Is generated town name valid?
Coordinates of a point in 2D.
TownFounding found_town
town founding.
void ShowDropDownMenu(Window *w, const StringID *strings, int selected, int button, uint32 disabled_mask, uint32 hidden_mask, uint width)
Show a dropdown menu window near a widget of the parent window.
const byte _town_action_costs[TACT_COUNT]
Factor in the cost of each town action.
const Town * _viewport_highlight_town
Currently selected town for coverage area highlight.
bool SetFocusedWidget(int widget_index)
Set focus within this window to the given widget.
bool city
Are we building a city?
WindowNumber window_number
Window number within the window class.
static int RoundDivSU(int a, uint b)
Computes round(a / b) for signed a and unsigned b.
TownNameParams params
Town name parameters.
uint step_height
Step-size of height resize changes.
void ToggleSortOrder()
Toggle the sort order Since that is the worst condition for the sort function reverse the list here.
void OnPlaceObjectAbort() override
The user cancelled a tile highlight mode that has been set.
void UpdateNearestTownForRoadTiles(bool invalidate)
Updates cached nearest town for all road tiles.
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing)
@ CS_ALPHANUMERAL
Both numeric and alphabetic and spaces and stuff.
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
int16 ratings[MAX_COMPANIES]
ratings of each company for this town
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
@ WC_TOWN_DIRECTORY
Town directory; Window numbers:
void DrawCompanyIcon(CompanyID c, int x, int y)
Draw the icon of a company.
int GetStringHeight(const char *str, int maxw, FontSize fontsize)
Calculates height of string (in pixels).
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
bool _generating_world
Whether we are generating the map or not.
bool NeedRebuild() const
Check if a rebuild is needed.
Tstorage old_max
Maximum amount last month.
static const uint TOWN_GROWTH_WINTER
The town only needs this cargo in the winter (any amount)
uint32 StringID
Numeric value that represents a string, independent of the selected language.
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
std::string text
General text with additional information.
@ SBS_DOWN
Sort ascending.
bool confirm
Play sound effect on successful constructions or other actions.
int cancel_button
Widget button of parent window to simulate when pressing CANCEL in OSK.
void Close() override
Hide the window and all its child windows, and mark them for a later deletion.
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
bool GenerateTowns(TownLayout layout)
This function will generate a certain amount of towns, with a certain layout It can be called from th...
bool IsShaded() const
Is window shaded currently?
@ TACT_COUNT
Number of available town actions.
void Restore()
Restore the variable.
TownActions enabled_actions
Actions that are enabled in settings.
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
static ZoomLevel ScaleZoomGUI(ZoomLevel value)
Scale zoom level relative to GUI zoom.
Found a town window class.
void UpdateOSKOriginalText(const Window *parent, int button)
Updates the original text of the OSK so when the 'parent' changes the original and you press on cance...
static GUITownList::SortFunction *const sorter_funcs[]
Available town directory sorting functions.
void UpdateSize()
Update Textbuf type with its actual physical character and screenlength Get the count of characters i...
void ResetState()
Reset the matching state to process a new item.
Listing GetListing() const
Export current sort conditions.
void CDECL SetWidgetsDisabledState(bool disab_stat, int widgets,...)
Sets the enabled/disabled status of a list of widgets.
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
bool IsWidgetLowered(byte widget_index) const
Gets the lowered state of a widget.
Tstorage old_act
Actually transported last month.
static TownActions GetEnabledActions()
Gets all town authority actions enabled in settings.
TownCache cache
Container for all cacheable data.
@ HT_RECT
rectangle (stations, depots, ...)
Struct holding parameters used to generate town name.
bool GetState() const
Get the matching state of the current item.
@ TOWN_IS_GROWING
Conditions for town growth are met. Grow according to Town::growth_rate.
StringID name
Name of this type of cargo.
bool fund_roads
allow funding local road reconstruction
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
void OnInit() override
Notification that the nested widget tree gets initialized.
static const int ACTION_CLEAR
Clear editbox.
@ TACT_NONE
Empty action set.
static bool TownNameSorter(const Town *const &a, const Town *const &b)
Sort by town name.
void ForceResort()
Force a resort next Sort call Reset the resort timer if used too.
void Clear()
Clear the tree.
uint32 townnameparts
Generated town name.
void ForceRebuild()
Force that a rebuild is needed.
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
void DrawRatings()
Draw the contents of the ratings panel.
#define lengthof(x)
Return the length of an fixed size array.
int width
width of the window (number of pixels to the right in x direction)
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
Town directory window class.
static int SortButtonWidth()
Get width of up/down arrow of sort button state.
@ SND_1F_CONSTRUCTION_OTHER
29 == 0x1D Construction: other (non-water, non-rail, non-bridge)
uint32 num_houses
Amount of houses.
int strnatcmp(const char *s1, const char *s2, bool ignore_garbage_at_front)
Compares two strings using case insensitive natural sort.
@ WC_TOWN_VIEW
Town view; Window numbers:
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
Update size and resize step of a widget in the window.
Data structure for an opened window.
void RebuildDone()
Notify the sortlist that the rebuild is done.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
void DrawWidgets() const
Paint all widgets of a window.
bool larger_town
if this is a larger town and should grow more quickly
static const uint MAX_LENGTH_TOWN_NAME_CHARS
The maximum length of a town name in characters including '\0'.
TownLayout town_layout
Selected town layout.
void SetWidgetDirty(byte widget_index) const
Invalidate a widget, i.e.
@ TE_END
End of town effects.
Specification of a rectangle with absolute coordinates of all edges.
Window * BringWindowToFrontById(WindowClass cls, WindowNumber number)
Find a window and make it the relative top-window on the screen.
TransportedCargoStat< uint32 > supplied[NUM_CARGO]
Cargo statistics about supplied cargo.
CompanyID exclusivity
which company has exclusivity
int GetRowFromWidget(int clickpos, int widget, int padding, int line_height=-1) const
Compute the row of a widget that a user clicked in.
@ TACT_ALL
All possible actions.
@ QSF_ENABLE_DEFAULT
enable the 'Default' button ("\0" is returned)
#define CLRBITS(x, y)
Clears several bits in a variable.
#define lastof(x)
Get the last element of an fixed size array.
bool allow_town_roads
towns are allowed to build roads (always allowed when generating world / in SE)
void SetDParamMaxDigits(uint n, uint count, FontSize size)
Set DParam n to some number that is suitable for string size computations.
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows).
void SetWidgetLoweredState(byte widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
void CDECL void DeleteAll()
Delete every character in the textbuffer.
@ TD_RTL
Text is written right-to-left by default.
static const int DAY_TICKS
1 day is 74 ticks; _date_fract used to be uint16 and incremented by 885.
TextDirection _current_text_dir
Text direction of the currently selected language.
void OnQueryTextFinished(char *str) override
The query window opened from this window has closed.
TownActions
Town actions of a company.
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
Update size and resize step of a widget in the window.
void SetDParamStr(uint n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
bool GenerateTownName(uint32 *townnameparts, TownNames *town_names)
Generates valid town name.
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
GUISettings gui
settings related to the GUI
TransportedCargoStat< uint16 > received[NUM_TE]
Cargo statistics about received cargotypes.
void SetViewportCatchmentTown(const Town *t, bool sel)
Select or deselect town for coverage area highlight.
void SetSortFuncs(SortFunction *const *n_funcs)
Hand the array of sort function pointers to the sort list.
bool persistent_buildingtools
keep the building tools active after usage
void OnResize() override
Called after the window got resized.
@ TACT_BUY_RIGHTS
Buy exclusive transport rights.
void ResizeWindow(Window *w, int delta_x, int delta_y, bool clamp_to_screen)
Resize the window.
Dimension icon_size
Dimensions of company icon.
virtual void Close()
Hide the window and all its child windows, and mark them for a later deletion.
Town * town
Town displayed by the window.