|
OpenTTD Source
13.0-beta2
|
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),
142 DrawString(r, STR_LOCAL_AUTHORITY_COMPANY_RATINGS);
146 int icon_width = icon_size.width;
150 int exclusive_width = exclusive_size.width;
155 uint icon_left = r.
WithWidth(icon_width, rtl).left;
160 if ((
HasBit(this->town->
have_ratings, c->index) || this->town->exclusivity == c->index)) {
166 int rating = this->town->
ratings[c->index];
167 StringID str = STR_CARGO_RATING_APPALLING;
168 if (rating > RATING_APPALLING) str++;
169 if (rating > RATING_VERYPOOR) str++;
170 if (rating > RATING_POOR) str++;
171 if (rating > RATING_MEDIOCRE) str++;
172 if (rating > RATING_GOOD) str++;
173 if (rating > RATING_VERYGOOD) str++;
174 if (rating > RATING_EXCELLENT) str++;
178 DrawSprite(SPR_EXCLUSIVE_TRANSPORT, COMPANY_SPRITE_COLOUR(c->index), exclusive_left, r.top + exclusive_y_offset);
181 DrawString(text, STR_LOCAL_AUTHORITY_COMPANY_RATING);
186 text.bottom = text.top - 1;
187 if (text.bottom > r.bottom) {
198 DrawString(r, STR_LOCAL_AUTHORITY_ACTIONS_TITLE);
204 if (!
HasBit(this->enabled_actions, i))
continue;
208 if (
HasBit(this->available_actions, i)) action_colour = TC_ORANGE;
209 if (this->sel_index == i) action_colour = TC_WHITE;
211 DrawString(r, STR_LOCAL_AUTHORITY_ACTION_SMALL_ADVERTISING_CAMPAIGN + i, action_colour);
225 if (this->sel_index != -1) {
231 STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_SMALL_ADVERTISING + this->sel_index,
232 affordable ? TC_YELLOW : TC_RED);
242 assert(size->width > padding.width && size->height > padding.height);
248 d.width += padding.width;
249 d.height += padding.height;
258 size->width = std::max(size->width,
GetStringBoundingBox(STR_LOCAL_AUTHORITY_ACTION_SMALL_ADVERTISING_CAMPAIGN + i).
width);
260 size->width += padding.width;
274 bool new_show_state = !this->town->
show_zone;
275 TownID index = this->town->
index;
277 new_show_state ? _town_local_authority_kdtree.
Insert(index) : _town_local_authority_kdtree.
Remove(index);
295 if (click_count == 1 || y < 0)
break;
312 if (!gui_scope)
return;
315 if (!
HasBit(this->enabled_actions, this->sel_index)) {
316 this->sel_index = -1;
322 WDP_AUTO,
"view_town_authority", 317, 222,
325 _nested_town_authority_widgets,
lengthof(_nested_town_authority_widgets)
328 static void ShowTownAuthorityWindow(uint town)
330 AllocateWindowDescFront<TownAuthorityWindow>(&_town_authority_desc, town);
340 static const int WID_TV_HEIGHT_NORMAL = 150;
386 DrawString(tr, STR_TOWN_VIEW_POPULATION_HOUSES);
392 DrawString(tr, STR_TOWN_VIEW_CARGO_LAST_MONTH_MAX);
398 DrawString(tr, STR_TOWN_VIEW_CARGO_LAST_MONTH_MAX);
402 for (
int i = TE_BEGIN; i <
TE_END; i++) {
403 if (this->town->
goal[i] == 0)
continue;
408 DrawString(tr, STR_TOWN_VIEW_CARGO_FOR_TOWNGROWTH);
416 assert(cargo !=
nullptr);
422 string = STR_TOWN_VIEW_CARGO_FOR_TOWNGROWTH_DELIVERED_GENERAL;
424 string = STR_TOWN_VIEW_CARGO_FOR_TOWNGROWTH_REQUIRED_GENERAL;
427 string = STR_TOWN_VIEW_CARGO_FOR_TOWNGROWTH_REQUIRED_WINTER;
433 string = STR_TOWN_VIEW_CARGO_FOR_TOWNGROWTH_DELIVERED;
435 string = STR_TOWN_VIEW_CARGO_FOR_TOWNGROWTH_REQUIRED;
452 DrawString(tr, STR_TOWN_VIEW_TOWN_GROW_STOPPED);
464 if (!this->town->
text.empty()) {
496 static bool _warn_town_no_roads =
false;
500 _warn_town_no_roads =
true;
531 for (
int i = TE_BEGIN; i <
TE_END; i++) {
532 if (this->town->
goal[i] == 0)
continue;
546 if (!this->town->
text.empty()) {
554 void ResizeWindowAsNeeded()
580 if (!gui_scope)
return;
583 this->ResizeWindowAsNeeded();
588 if (str ==
nullptr)
return;
594 static const NWidgetPart _nested_town_game_view_widgets[] = {
609 NWidget(
WWT_PANEL, COLOUR_BROWN,
WID_TV_INFO),
SetMinimalSize(260, 32),
SetResize(1, 0),
SetFill(1, 0),
EndContainer(),
611 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),
612 NWidget(
WWT_TEXTBTN, COLOUR_BROWN,
WID_TV_CATCHMENT),
SetMinimalSize(40, 12),
SetFill(1, 1),
SetResize(1, 0),
SetDataTip(STR_BUTTON_CATCHMENT, STR_TOOLTIP_CATCHMENT),
618 WDP_AUTO,
"view_town", 260, TownViewWindow::WID_TV_HEIGHT_NORMAL,
621 _nested_town_game_view_widgets,
lengthof(_nested_town_game_view_widgets)
624 static const NWidgetPart _nested_town_editor_view_widgets[] = {
639 NWidget(
WWT_PANEL, COLOUR_BROWN,
WID_TV_INFO),
SetMinimalSize(260, 32),
SetResize(1, 0),
SetFill(1, 0),
EndContainer(),
641 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),
642 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),
643 NWidget(
WWT_TEXTBTN, COLOUR_BROWN,
WID_TV_CATCHMENT),
SetMinimalSize(40, 12),
SetFill(1, 1),
SetResize(1, 0),
SetDataTip(STR_BUTTON_CATCHMENT, STR_TOOLTIP_CATCHMENT),
649 WDP_AUTO,
"view_town_scen", 260, TownViewWindow::WID_TV_HEIGHT_NORMAL,
652 _nested_town_editor_view_widgets,
lengthof(_nested_town_editor_view_widgets)
655 void ShowTownViewWindow(TownID town)
657 if (_game_mode == GM_EDITOR) {
658 AllocateWindowDescFront<TownViewWindow>(&_town_editor_view_desc, town);
660 AllocateWindowDescFront<TownViewWindow>(&_town_game_view_desc, town);
664 static const NWidgetPart _nested_town_directory_widgets[] = {
682 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),
709 void BuildSortTownList()
715 if (this->string_filter.
IsEmpty()) {
716 this->towns.push_back(t);
720 this->string_filter.
AddLine(t->GetCachedName());
721 if (this->string_filter.
GetState()) this->towns.push_back(t);
724 this->towns.shrink_to_fit();
726 this->vscroll->
SetCount((uint)this->towns.size());
736 return strnatcmp(a->GetCachedName(), b->GetCachedName()) < 0;
745 return a_population < b_population;
751 bool before = !TownDirectoryWindow::last_sorting.
order;
759 return a_rating < b_rating;
780 this->BuildSortTownList();
808 return t->
larger_town ? STR_TOWN_DIRECTORY_CITY : STR_TOWN_DIRECTORY_TOWN;
821 if (this->towns.size() == 0) {
829 int icon_x = tr.
WithWidth(icon_size.width, rtl).left;
832 for (uint i = this->vscroll->
GetPosition(); i < this->towns.size(); i++) {
833 const Town *t = this->towns[i];
838 DrawSprite(SPR_TOWN_RATING_NA, PAL_NONE, icon_x, tr.top + (this->resize.step_height - icon_size.height) / 2);
840 SpriteID icon = SPR_TOWN_RATING_APALLING;
843 DrawSprite(icon, PAL_NONE, icon_x, tr.top + (this->resize.step_height - icon_size.height) / 2);
864 d.height += padding.height;
873 d.width += padding.width;
874 d.height += padding.height;
880 for (uint i = 0; i < this->towns.size(); i++) {
881 const Town *t = this->towns[i];
883 assert(t !=
nullptr);
890 d.width += icon_size.width + 2;
891 d.height = std::max(d.height, icon_size.height);
892 resize->height = d.height;
894 d.width += padding.width;
895 d.height += padding.height;
902 d.width += padding.width;
903 d.height += padding.height;
916 this->last_sorting = this->towns.
GetListing();
919 this->last_sorting.
order = !this->last_sorting.
order;
933 if (id_v >= this->towns.size())
return;
935 const Town *t = this->towns[id_v];
936 assert(t !=
nullptr);
951 if (this->towns.
SortType() != index) {
953 this->last_sorting = this->towns.
GetListing();
954 this->BuildSortTownList();
960 if (this->towns.
NeedRebuild()) this->BuildSortTownList();
966 this->BuildSortTownList();
991 case TDIWD_FORCE_REBUILD:
996 case TDIWD_POPULATION_CHANGE:
1006 Listing TownDirectoryWindow::last_sorting = {
false, 0};
1011 STR_SORT_BY_POPULATION,
1019 &TownPopulationSorter,
1027 _nested_town_directory_widgets,
lengthof(_nested_town_directory_widgets)
1030 void ShowTownDirectory()
1038 if (result.
Failed())
return;
1049 static const NWidgetPart _nested_found_town_widgets[] = {
1060 SetDataTip(STR_FOUND_TOWN_NEW_TOWN_BUTTON, STR_FOUND_TOWN_NEW_TOWN_TOOLTIP),
SetPadding(0, 2, 1, 2),
1062 SetDataTip(STR_FOUND_TOWN_RANDOM_TOWN_BUTTON, STR_FOUND_TOWN_RANDOM_TOWN_TOOLTIP),
SetPadding(0, 2, 1, 2),
1064 SetDataTip(STR_FOUND_TOWN_MANY_RANDOM_TOWNS, STR_FOUND_TOWN_RANDOM_TOWNS_TOOLTIP),
SetPadding(0, 2, 0, 2),
1066 NWidget(
WWT_LABEL, COLOUR_DARK_GREEN),
SetMinimalSize(156, 14),
SetPadding(0, 2, 0, 2),
SetDataTip(STR_FOUND_TOWN_NAME_TITLE, STR_NULL),
1068 SetDataTip(STR_FOUND_TOWN_NAME_EDITOR_TITLE, STR_FOUND_TOWN_NAME_EDITOR_HELP),
1069 NWidget(
WWT_PUSHTXTBTN, COLOUR_GREY,
WID_TF_TOWN_NAME_RANDOM),
SetMinimalSize(78, 12),
SetPadding(0, 2, 0, 2),
SetFill(1, 0),
1070 SetDataTip(STR_FOUND_TOWN_NAME_RANDOM_BUTTON, STR_FOUND_TOWN_NAME_RANDOM_TOOLTIP),
1079 SetDataTip(STR_FOUND_TOWN_INITIAL_SIZE_SMALL_BUTTON, STR_FOUND_TOWN_INITIAL_SIZE_TOOLTIP),
1081 SetDataTip(STR_FOUND_TOWN_INITIAL_SIZE_MEDIUM_BUTTON, STR_FOUND_TOWN_INITIAL_SIZE_TOOLTIP),
1086 SetDataTip(STR_FOUND_TOWN_INITIAL_SIZE_LARGE_BUTTON, STR_FOUND_TOWN_INITIAL_SIZE_TOOLTIP),
1088 SetDataTip(STR_FOUND_TOWN_SIZE_RANDOM, STR_FOUND_TOWN_INITIAL_SIZE_TOOLTIP),
1091 NWidget(
WWT_TEXTBTN, COLOUR_GREY,
WID_TF_CITY),
SetPadding(0, 2, 0, 2),
SetMinimalSize(156, 12),
SetFill(1, 0),
1109 NWidget(
WWT_TEXTBTN, COLOUR_GREY,
WID_TF_LAYOUT_RANDOM),
SetPadding(0, 2, 0, 2),
SetMinimalSize(0, 12),
SetFill(1, 0),
1110 SetDataTip(STR_FOUND_TOWN_SELECT_LAYOUT_RANDOM, STR_FOUND_TOWN_SELECT_TOWN_ROAD_LAYOUT),
SetFill(1, 0),
1136 this->RandomTownName();
1137 this->UpdateButtons(
true);
1140 void RandomTownName()
1144 if (!this->townnamevalid) {
1145 this->townname_editbox.text.
DeleteAll();
1147 GetTownName(this->townname_editbox.text.
buf, &this->params, this->townnameparts, &this->townname_editbox.text.buf[this->townname_editbox.text.max_bytes - 1]);
1155 void UpdateButtons(
bool check_availability)
1157 if (check_availability && _game_mode != GM_EDITOR) {
1177 template <
typename Tcallback>
1178 void ExecuteFoundTownCommand(
TileIndex tile,
bool random,
StringID errstr, Tcallback cc)
1182 if (!this->townnamevalid) {
1183 name = this->townname_editbox.text.
buf;
1188 if (strcmp(buf, this->townname_editbox.text.
buf) != 0) name = this->townname_editbox.text.
buf;
1192 tile, this->town_size, this->city, this->town_layout, random,
townnameparts, name);
1206 this->ExecuteFoundTownCommand(0,
true, STR_ERROR_CAN_T_GENERATE_TOWN, CcFoundRandomTown);
1210 this->RandomTownName();
1221 old_generating_world.
Restore();
1227 this->UpdateButtons(
false);
1239 this->UpdateButtons(
false);
1246 this->ExecuteFoundTownCommand(tile,
false, STR_ERROR_CAN_T_FOUND_TOWN_HERE, CcFoundTown);
1252 this->UpdateButtons(
false);
1262 if (!gui_scope)
return;
1263 this->UpdateButtons(
true);
1271 _nested_found_town_widgets,
lengthof(_nested_found_town_widgets)
1274 void ShowFoundTownWindow()
1277 AllocateWindowDescFront<FoundTownWindow>(&_found_town_desc, 0);
1280 void InitializeTownGui()
1282 _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.
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
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?
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.
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.
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.