OpenTTD Source
1.11.0-beta2
|
Go to the documentation of this file.
38 #include "table/strings.h"
42 TownKdtree _town_local_authority_kdtree(&Kdtree_TownXYFunc);
46 static const NWidgetPart _nested_town_authority_widgets[] = {
57 NWidget(
WWT_PANEL, COLOUR_BROWN,
WID_TA_COMMAND_LIST),
SetMinimalSize(305, 52),
SetResize(1, 0),
SetDataTip(0x0, STR_LOCAL_AUTHORITY_ACTIONS_TOOLTIP),
SetScrollbar(
WID_TA_SCROLLBAR),
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),
110 displayed_actions_on_previous_painting = buttons;
112 this->vscroll->
SetCount(numact + 1);
114 if (this->sel_index != -1 && !
HasBit(buttons, this->sel_index)) {
115 this->sel_index = -1;
138 int icon_width = icon_size.width;
142 int exclusive_width = exclusive_size.width;
146 uint text_left =
left + (rtl ? 0 : icon_width + exclusive_width + 4);
147 uint text_right = right - (rtl ? icon_width + exclusive_width + 4 : 0);
148 uint icon_left = rtl ? right - icon_width :
left;
149 uint exclusive_left = rtl ? right - icon_width - exclusive_width - 2 :
left + icon_width + 2;
159 int r = this->town->
ratings[c->index];
160 StringID str = STR_CARGO_RATING_APPALLING;
161 if (r > RATING_APPALLING) str++;
162 if (r > RATING_VERYPOOR) str++;
163 if (r > RATING_POOR) str++;
164 if (r > RATING_MEDIOCRE) str++;
165 if (r > RATING_GOOD) str++;
166 if (r > RATING_VERYGOOD) str++;
167 if (r > RATING_EXCELLENT) str++;
171 DrawSprite(SPR_EXCLUSIVE_TRANSPORT, COMPANY_SPRITE_COLOUR(c->index), exclusive_left, y + exclusive_y_offset);
174 DrawString(text_left, text_right, y, STR_LOCAL_AUTHORITY_COMPANY_RATING);
195 if (this->sel_index != -1) {
198 STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_SMALL_ADVERTISING + this->sel_index);
212 for (
int i = 0; buttons; i++, buttons >>= 1) {
213 if (pos <= -5)
break;
215 if ((buttons & 1) && --pos < 0) {
217 STR_LOCAL_AUTHORITY_ACTION_SMALL_ADVERTISING_CAMPAIGN + i, this->sel_index == i ? TC_WHITE : TC_ORANGE);
230 assert(size->width > padding.width && size->height > padding.height);
248 size->width = std::max(size->width,
GetStringBoundingBox(STR_LOCAL_AUTHORITY_ACTION_SMALL_ADVERTISING_CAMPAIGN + i).
width);
264 bool new_show_state = !this->town->
show_zone;
265 TownID index = this->town->
index;
267 new_show_state ? _town_local_authority_kdtree.
Insert(index) : _town_local_authority_kdtree.
Remove(index);
285 if (click_count == 1 || y < 0)
break;
302 WDP_AUTO,
"view_town_authority", 317, 222,
305 _nested_town_authority_widgets,
lengthof(_nested_town_authority_widgets)
308 static void ShowTownAuthorityWindow(uint town)
310 AllocateWindowDescFront<TownAuthorityWindow>(&_town_authority_desc, town);
320 static const int WID_TV_HEIGHT_NORMAL = 150;
378 for (
int i = TE_BEGIN; i <
TE_END; i++) {
379 if (this->town->
goal[i] == 0)
continue;
393 assert(cargo !=
nullptr);
399 string = STR_TOWN_VIEW_CARGO_FOR_TOWNGROWTH_DELIVERED_GENERAL;
401 string = STR_TOWN_VIEW_CARGO_FOR_TOWNGROWTH_REQUIRED_GENERAL;
404 string = STR_TOWN_VIEW_CARGO_FOR_TOWNGROWTH_REQUIRED_WINTER;
410 string = STR_TOWN_VIEW_CARGO_FOR_TOWNGROWTH_DELIVERED;
412 string = STR_TOWN_VIEW_CARGO_FOR_TOWNGROWTH_REQUIRED;
437 if (!this->town->
text.empty()) {
455 ShowTownAuthorityWindow(this->window_number);
469 static bool _warn_town_no_roads =
false;
473 _warn_town_no_roads =
true;
504 for (
int i = TE_BEGIN; i <
TE_END; i++) {
505 if (this->town->
goal[i] == 0)
continue;
519 if (!this->town->
text.empty()) {
527 void ResizeWindowAsNeeded()
553 if (!gui_scope)
return;
556 this->ResizeWindowAsNeeded();
561 if (str ==
nullptr)
return;
567 static const NWidgetPart _nested_town_game_view_widgets[] = {
579 NWidget(
NWID_VIEWPORT, INVALID_COLOUR,
WID_TV_VIEWPORT),
SetMinimalSize(254, 86),
SetFill(1, 0),
SetResize(1, 1),
SetPadding(1, 1, 1, 1),
582 NWidget(
WWT_PANEL, COLOUR_BROWN,
WID_TV_INFO),
SetMinimalSize(260, 32),
SetResize(1, 0),
SetFill(1, 0),
EndContainer(),
584 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),
585 NWidget(
WWT_TEXTBTN, COLOUR_BROWN,
WID_TV_CATCHMENT),
SetMinimalSize(40, 12),
SetFill(1, 1),
SetResize(1, 0),
SetDataTip(STR_BUTTON_CATCHMENT, STR_TOOLTIP_CATCHMENT),
591 WDP_AUTO,
"view_town", 260, TownViewWindow::WID_TV_HEIGHT_NORMAL,
594 _nested_town_game_view_widgets,
lengthof(_nested_town_game_view_widgets)
597 static const NWidgetPart _nested_town_editor_view_widgets[] = {
609 NWidget(
NWID_VIEWPORT, INVALID_COLOUR,
WID_TV_VIEWPORT),
SetMinimalSize(254, 86),
SetFill(1, 1),
SetResize(1, 1),
SetPadding(1, 1, 1, 1),
612 NWidget(
WWT_PANEL, COLOUR_BROWN,
WID_TV_INFO),
SetMinimalSize(260, 32),
SetResize(1, 0),
SetFill(1, 0),
EndContainer(),
614 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),
615 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),
616 NWidget(
WWT_TEXTBTN, COLOUR_BROWN,
WID_TV_CATCHMENT),
SetMinimalSize(40, 12),
SetFill(1, 1),
SetResize(1, 0),
SetDataTip(STR_BUTTON_CATCHMENT, STR_TOOLTIP_CATCHMENT),
622 WDP_AUTO,
"view_town_scen", 260, TownViewWindow::WID_TV_HEIGHT_NORMAL,
625 _nested_town_editor_view_widgets,
lengthof(_nested_town_editor_view_widgets)
628 void ShowTownViewWindow(TownID town)
630 if (_game_mode == GM_EDITOR) {
631 AllocateWindowDescFront<TownViewWindow>(&_town_editor_view_desc, town);
633 AllocateWindowDescFront<TownViewWindow>(&_town_game_view_desc, town);
637 static const NWidgetPart _nested_town_directory_widgets[] = {
655 NWidget(
WWT_TEXT, COLOUR_BROWN,
WID_TD_WORLD_POPULATION),
SetPadding(2, 0, 0, 2),
SetMinimalSize(196, 12),
SetFill(1, 0),
SetDataTip(STR_TOWN_POPULATION, STR_NULL),
682 void BuildSortTownList()
688 if (this->string_filter.
IsEmpty()) {
689 this->towns.push_back(t);
693 this->string_filter.
AddLine(t->GetCachedName());
694 if (this->string_filter.
GetState()) this->towns.push_back(t);
697 this->towns.shrink_to_fit();
699 this->vscroll->
SetCount((uint)this->towns.size());
709 return strnatcmp(a->GetCachedName(), b->GetCachedName()) < 0;
718 return a_population < b_population;
724 bool before = !TownDirectoryWindow::last_sorting.
order;
732 return a_rating < b_rating;
753 this->BuildSortTownList();
781 return t->
larger_town ? STR_TOWN_DIRECTORY_CITY : STR_TOWN_DIRECTORY_TOWN;
794 if (this->towns.size() == 0) {
806 for (uint i = this->vscroll->
GetPosition(); i < this->towns.size(); i++) {
807 const Town *t = this->towns[i];
814 SpriteID icon = SPR_TOWN_RATING_APALLING;
838 d.height += padding.height;
847 d.width += padding.width;
848 d.height += padding.height;
854 for (uint i = 0; i < this->towns.size(); i++) {
855 const Town *t = this->towns[i];
857 assert(t !=
nullptr);
864 d.width += icon_size.width + 2;
865 d.height = std::max(d.height, icon_size.height);
866 resize->height = d.height;
876 d.width += padding.width;
877 d.height += padding.height;
890 this->last_sorting = this->towns.
GetListing();
893 this->last_sorting.
order = !this->last_sorting.
order;
907 if (id_v >= this->towns.size())
return;
909 const Town *t = this->towns[id_v];
910 assert(t !=
nullptr);
925 if (this->towns.
SortType() != index) {
927 this->last_sorting = this->towns.
GetListing();
928 this->BuildSortTownList();
934 if (this->towns.
NeedRebuild()) this->BuildSortTownList();
940 this->BuildSortTownList();
965 case TDIWD_FORCE_REBUILD:
970 case TDIWD_POPULATION_CHANGE:
980 Listing TownDirectoryWindow::last_sorting = {
false, 0};
985 STR_SORT_BY_POPULATION,
993 &TownPopulationSorter,
1001 _nested_town_directory_widgets,
lengthof(_nested_town_directory_widgets)
1004 void ShowTownDirectory()
1012 if (result.
Failed())
return;
1018 void CcFoundRandomTown(
const CommandCost &result,
TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
1023 static const NWidgetPart _nested_found_town_widgets[] = {
1034 SetDataTip(STR_FOUND_TOWN_NEW_TOWN_BUTTON, STR_FOUND_TOWN_NEW_TOWN_TOOLTIP),
SetPadding(0, 2, 1, 2),
1036 SetDataTip(STR_FOUND_TOWN_RANDOM_TOWN_BUTTON, STR_FOUND_TOWN_RANDOM_TOWN_TOOLTIP),
SetPadding(0, 2, 1, 2),
1038 SetDataTip(STR_FOUND_TOWN_MANY_RANDOM_TOWNS, STR_FOUND_TOWN_RANDOM_TOWNS_TOOLTIP),
SetPadding(0, 2, 0, 2),
1040 NWidget(
WWT_LABEL, COLOUR_DARK_GREEN),
SetMinimalSize(156, 14),
SetPadding(0, 2, 0, 2),
SetDataTip(STR_FOUND_TOWN_NAME_TITLE, STR_NULL),
1042 SetDataTip(STR_FOUND_TOWN_NAME_EDITOR_TITLE, STR_FOUND_TOWN_NAME_EDITOR_HELP),
1043 NWidget(
WWT_PUSHTXTBTN, COLOUR_GREY,
WID_TF_TOWN_NAME_RANDOM),
SetMinimalSize(78, 12),
SetPadding(0, 2, 0, 2),
SetFill(1, 0),
1044 SetDataTip(STR_FOUND_TOWN_NAME_RANDOM_BUTTON, STR_FOUND_TOWN_NAME_RANDOM_TOOLTIP),
1053 SetDataTip(STR_FOUND_TOWN_INITIAL_SIZE_SMALL_BUTTON, STR_FOUND_TOWN_INITIAL_SIZE_TOOLTIP),
1055 SetDataTip(STR_FOUND_TOWN_INITIAL_SIZE_MEDIUM_BUTTON, STR_FOUND_TOWN_INITIAL_SIZE_TOOLTIP),
1060 SetDataTip(STR_FOUND_TOWN_INITIAL_SIZE_LARGE_BUTTON, STR_FOUND_TOWN_INITIAL_SIZE_TOOLTIP),
1062 SetDataTip(STR_FOUND_TOWN_SIZE_RANDOM, STR_FOUND_TOWN_INITIAL_SIZE_TOOLTIP),
1065 NWidget(
WWT_TEXTBTN, COLOUR_GREY,
WID_TF_CITY),
SetPadding(0, 2, 0, 2),
SetMinimalSize(156, 12),
SetFill(1, 0),
1083 NWidget(
WWT_TEXTBTN, COLOUR_GREY,
WID_TF_LAYOUT_RANDOM),
SetPadding(0, 2, 0, 2),
SetMinimalSize(0, 12),
SetFill(1, 0),
1084 SetDataTip(STR_FOUND_TOWN_SELECT_LAYOUT_RANDOM, STR_FOUND_TOWN_SELECT_TOWN_ROAD_LAYOUT),
SetFill(1, 0),
1110 this->RandomTownName();
1111 this->UpdateButtons(
true);
1114 void RandomTownName()
1118 if (!this->townnamevalid) {
1119 this->townname_editbox.text.
DeleteAll();
1121 GetTownName(this->townname_editbox.text.
buf, &this->params, this->townnameparts, &this->townname_editbox.text.buf[this->townname_editbox.text.max_bytes - 1]);
1129 void UpdateButtons(
bool check_availability)
1131 if (check_availability && _game_mode != GM_EDITOR) {
1153 const char *name =
nullptr;
1155 if (!this->townnamevalid) {
1156 name = this->townname_editbox.text.
buf;
1161 if (strcmp(buf, this->townname_editbox.text.
buf) != 0) name = this->townname_editbox.text.
buf;
1164 bool success =
DoCommandP(tile, this->town_size | this->city << 2 | this->town_layout << 3 | random << 6,
1179 this->ExecuteFoundTownCommand(0,
true, STR_ERROR_CAN_T_GENERATE_TOWN, CcFoundRandomTown);
1183 this->RandomTownName();
1199 this->UpdateButtons(
false);
1211 this->UpdateButtons(
false);
1218 this->ExecuteFoundTownCommand(tile,
false, STR_ERROR_CAN_T_FOUND_TOWN_HERE, CcFoundTown);
1224 this->UpdateButtons(
false);
1234 if (!gui_scope)
return;
1235 this->UpdateButtons(
true);
1243 _nested_found_town_widgets,
lengthof(_nested_found_town_widgets)
1246 void ShowFoundTownWindow()
1249 AllocateWindowDescFront<FoundTownWindow>(&_found_town_desc, 0);
1252 void InitializeTownGui()
1254 _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.
CompanyMask have_ratings
which companies have a rating
@ WD_FRAMERECT_TOP
Offset at top to draw the frame rectangular area.
#define CMD_MSG(x)
Used to combine a StringID with the command.
uint32 TileIndex
The index/ID of a Tile.
@ 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.
@ CMD_DO_TOWN_ACTION
do a action from the town detail window (like advertises or bribe)
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.
K-dimensional tree, specialised for 2-dimensional space.
@ WL_WARNING
Other information.
bool IsEmpty() const
Check whether any filter words were entered.
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.
Tindex index
Index of this pool item.
void OnHundredthTick() override
Called once every 100 (game) ticks, or once every 3s, whichever comes last.
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 int GetNthSetBit(uint32 bits, int n)
Get the position of the Nth set bit.
TownSize
Supported initial town sizes.
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
uint32 goal[NUM_TE]
Amount of cargo required for the town to grow.
QueryString townname_editbox
Filter editbox.
bool _ctrl_pressed
Is Ctrl pressed?
void CommandCallback(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
Define a callback function for the client, after the command is finished.
void RaiseButtons(bool autoraise=false)
Raise the buttons of the window.
@ CMD_RENAME_TOWN
rename a town
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.
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.
char *const buf
buffer in which text is saved
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.
static bool IsInsideMM(const T x, const size_t min, const size_t max)
Checks if a value is in an interval.
@ 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.
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).
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.
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
bool DoCommandP(const CommandContainer *container, bool my_cmd)
Shortcut for the long DoCommandP when having a container with the data.
@ 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.
@ WD_FRAMERECT_LEFT
Offset at left to draw the frame rectangular area.
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.
@ TE_END
End of town effects.
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.
@ WD_FRAMERECT_RIGHT
Offset at right to draw the frame rectangular area.
@ WD_FRAMERECT_BOTTOM
Offset at bottom to draw the frame rectangular area.
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.
uint GetMaskOfTownActions(int *nump, CompanyID cid, const Town *t)
Get a list of available actions to do at a town.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
StringFilter string_filter
Filter for towns.
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.
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.
bool HandlePlacePushButton(Window *w, int widget, CursorID cursor, HighLightStyle mode)
This code is shared for the majority of the pushbuttons.
int left
x position of left edge of the window
WindowFlags flags
Window flags.
void OnPaint() override
The window must be repainted.
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?
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.
TownEffect
Town growth effect when delivering cargo.
@ 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.
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.
@ CMD_EXPAND_TOWN
expand a town
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
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.
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.
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.
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.
@ CMD_FOUND_TOWN
found a town
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)
@ ZOOM_LVL_NEWS
Default zoom level for the news messages.
uint32 num_houses
Amount of houses.
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
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.
@ CMD_DELETE_TOWN
delete a town
void SetWidgetDirty(byte widget_index) const
Invalidate a widget, i.e.
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.
@ QSF_ENABLE_DEFAULT
enable the 'Default' button ("\0" is returned)
#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.
#define FOR_EACH_SET_BIT(bitpos_var, bitset_value)
Do an operation for each set set bit in a value.
void OnQueryTextFinished(char *str) override
The query window opened from this window has closed.
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.
void ResizeWindow(Window *w, int delta_x, int delta_y, bool clamp_to_screen)
Resize the window.
Town * town
Town displayed by the window.