|
OpenTTD Source
14.0-beta1
|
Go to the documentation of this file.
45 #include "table/strings.h"
49 TownKdtree _town_local_authority_kdtree(&Kdtree_TownXYFunc);
53 static constexpr
NWidgetPart _nested_town_authority_widgets[] = {
63 NWidget(
WWT_PANEL, COLOUR_BROWN,
WID_TA_COMMAND_LIST),
SetMinimalSize(317, 52),
SetResize(1, 0),
SetDataTip(0x0, STR_LOCAL_AUTHORITY_ACTIONS_TOOLTIP),
EndContainer(),
66 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),
127 this->action_tooltips[0] = STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_SMALL_ADVERTISING;
128 this->action_tooltips[1] = STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_MEDIUM_ADVERTISING;
129 this->action_tooltips[2] = STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_LARGE_ADVERTISING;
130 this->action_tooltips[3] = realtime ? STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_ROAD_RECONSTRUCTION_MINUTES : STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_ROAD_RECONSTRUCTION_MONTHS;
131 this->action_tooltips[4] = STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_STATUE_OF_COMPANY;
132 this->action_tooltips[5] = STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_NEW_BUILDINGS;
133 this->action_tooltips[6] = realtime ? STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_EXCLUSIVE_TRANSPORT_MINUTES : STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_EXCLUSIVE_TRANSPORT_MONTHS;
134 this->action_tooltips[7] = STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_BRIBE;
142 this->exclusive_size =
GetSpriteSize(SPR_EXCLUSIVE_TRANSPORT);
169 int exclusive_y_offset = (this->
resize.
step_height - this->exclusive_size.height) / 2;
171 DrawString(r.left, r.right, r.top + text_y_offset, STR_LOCAL_AUTHORITY_COMPANY_RATINGS);
181 if ((
HasBit(this->town->
have_ratings, c->index) || this->town->exclusivity == c->index)) {
187 int rating = this->town->
ratings[c->index];
188 StringID str = STR_CARGO_RATING_APPALLING;
189 if (rating > RATING_APPALLING) str++;
190 if (rating > RATING_VERYPOOR) str++;
191 if (rating > RATING_POOR) str++;
192 if (rating > RATING_MEDIOCRE) str++;
193 if (rating > RATING_GOOD) str++;
194 if (rating > RATING_VERYGOOD) str++;
195 if (rating > RATING_EXCELLENT) str++;
199 DrawSprite(SPR_EXCLUSIVE_TRANSPORT, COMPANY_SPRITE_COLOUR(c->index), exclusive.left, text.top + exclusive_y_offset);
202 DrawString(text.left, text.right, text.top + text_y_offset, STR_LOCAL_AUTHORITY_COMPANY_RATING);
207 text.bottom = text.top - 1;
208 if (text.bottom > r.bottom) {
219 DrawString(r, STR_LOCAL_AUTHORITY_ACTIONS_TITLE);
225 if (!
HasBit(this->enabled_actions, i))
continue;
229 if (
HasBit(this->available_actions, i)) action_colour = TC_ORANGE;
230 if (this->sel_index == i) action_colour = TC_WHITE;
232 DrawString(r, STR_LOCAL_AUTHORITY_ACTION_SMALL_ADVERTISING_CAMPAIGN + i, action_colour);
237 void SetStringParameters(
WidgetID widget)
const override
242 void DrawWidget(
const Rect &r,
WidgetID widget)
const override
246 if (this->sel_index != -1) {
252 this->action_tooltips[this->sel_index],
253 affordable ? TC_YELLOW : TC_RED);
263 assert(size->width > padding.width && size->height > padding.height);
269 d.width += padding.width;
270 d.height += padding.height;
279 size->width = std::max(size->width,
GetStringBoundingBox(STR_LOCAL_AUTHORITY_ACTION_SMALL_ADVERTISING_CAMPAIGN + i).
width + padding.width);
281 size->width += padding.width;
286 size->height = 9 *
resize->height + padding.height;
291 void OnClick([[maybe_unused]]
Point pt,
WidgetID widget, [[maybe_unused]]
int click_count)
override
295 bool new_show_state = !this->town->
show_zone;
296 TownID index = this->town->
index;
298 new_show_state ? _town_local_authority_kdtree.
Insert(index) : _town_local_authority_kdtree.
Remove(index);
316 if (click_count == 1 || y < 0 || !
HasBit(this->available_actions, y))
break;
331 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
333 if (!gui_scope)
return;
336 if (!
HasBit(this->enabled_actions, this->sel_index)) {
337 this->sel_index = -1;
342 static WindowDesc _town_authority_desc(__FILE__, __LINE__,
343 WDP_AUTO,
"view_town_authority", 317, 222,
346 std::begin(_nested_town_authority_widgets), std::end(_nested_town_authority_widgets)
349 static void ShowTownAuthorityWindow(uint town)
351 AllocateWindowDescFront<TownAuthorityWindow>(&_town_authority_desc, town);
361 static const int WID_TV_HEIGHT_NORMAL = 150;
380 void Close([[maybe_unused]]
int data = 0)
override
386 void SetStringParameters(
WidgetID widget)
const override
399 void DrawWidget(
const Rect &r,
WidgetID widget)
const override
407 DrawString(tr, STR_TOWN_VIEW_POPULATION_HOUSES);
424 for (
int i = TAE_BEGIN; i <
TAE_END; i++) {
425 if (this->town->
goal[i] == 0)
continue;
430 DrawString(tr, STR_TOWN_VIEW_CARGO_FOR_TOWNGROWTH);
438 assert(cargo !=
nullptr);
444 string = STR_TOWN_VIEW_CARGO_FOR_TOWNGROWTH_DELIVERED_GENERAL;
446 string = STR_TOWN_VIEW_CARGO_FOR_TOWNGROWTH_REQUIRED_GENERAL;
449 string = STR_TOWN_VIEW_CARGO_FOR_TOWNGROWTH_REQUIRED_WINTER;
455 string = STR_TOWN_VIEW_CARGO_FOR_TOWNGROWTH_DELIVERED;
457 string = STR_TOWN_VIEW_CARGO_FOR_TOWNGROWTH_REQUIRED;
474 DrawString(tr, STR_TOWN_VIEW_TOWN_GROW_STOPPED);
486 if (!this->town->
text.empty()) {
492 void OnClick([[maybe_unused]]
Point pt,
WidgetID widget, [[maybe_unused]]
int click_count)
override
545 for (
int i = TAE_BEGIN; i <
TAE_END; i++) {
546 if (this->town->
goal[i] == 0)
continue;
560 if (!this->town->
text.empty()) {
568 void ResizeWindowAsNeeded()
592 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
594 if (!gui_scope)
return;
597 this->ResizeWindowAsNeeded();
600 void OnQueryTextFinished(
char *str)
override
602 if (str ==
nullptr)
return;
613 static constexpr
NWidgetPart _nested_town_game_view_widgets[] = {
628 NWidget(
WWT_PANEL, COLOUR_BROWN,
WID_TV_INFO),
SetMinimalSize(260, 32),
SetResize(1, 0),
SetFill(1, 0),
EndContainer(),
630 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),
631 NWidget(
WWT_TEXTBTN, COLOUR_BROWN,
WID_TV_CATCHMENT),
SetMinimalSize(40, 12),
SetFill(1, 1),
SetResize(1, 0),
SetDataTip(STR_BUTTON_CATCHMENT, STR_TOOLTIP_CATCHMENT),
636 static WindowDesc _town_game_view_desc(__FILE__, __LINE__,
637 WDP_AUTO,
"view_town", 260, TownViewWindow::WID_TV_HEIGHT_NORMAL,
640 std::begin(_nested_town_game_view_widgets), std::end(_nested_town_game_view_widgets)
643 static constexpr
NWidgetPart _nested_town_editor_view_widgets[] = {
658 NWidget(
WWT_PANEL, COLOUR_BROWN,
WID_TV_INFO),
SetMinimalSize(260, 32),
SetResize(1, 0),
SetFill(1, 0),
EndContainer(),
660 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),
661 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),
662 NWidget(
WWT_TEXTBTN, COLOUR_BROWN,
WID_TV_CATCHMENT),
SetMinimalSize(40, 12),
SetFill(1, 1),
SetResize(1, 0),
SetDataTip(STR_BUTTON_CATCHMENT, STR_TOOLTIP_CATCHMENT),
667 static WindowDesc _town_editor_view_desc(__FILE__, __LINE__,
668 WDP_AUTO,
"view_town_scen", 260, TownViewWindow::WID_TV_HEIGHT_NORMAL,
671 std::begin(_nested_town_editor_view_widgets), std::end(_nested_town_editor_view_widgets)
674 void ShowTownViewWindow(TownID town)
676 if (_game_mode == GM_EDITOR) {
677 AllocateWindowDescFront<TownViewWindow>(&_town_editor_view_desc, town);
679 AllocateWindowDescFront<TownViewWindow>(&_town_game_view_desc, town);
683 static constexpr
NWidgetPart _nested_town_directory_widgets[] = {
701 NWidget(
WWT_TEXT, COLOUR_BROWN,
WID_TD_WORLD_POPULATION),
SetPadding(2, 0, 2, 2),
SetFill(1, 0),
SetResize(1, 0),
SetDataTip(STR_TOWN_POPULATION, STR_NULL),
733 void BuildSortTownList()
739 if (this->string_filter.
IsEmpty()) {
740 this->towns.push_back(t);
744 this->string_filter.
AddLine(t->GetCachedName());
745 if (this->string_filter.
GetState()) this->towns.push_back(t);
748 this->towns.shrink_to_fit();
750 this->vscroll->
SetCount(this->towns.size());
769 return a_population < b_population;
775 bool before = !order;
783 return a_rating < b_rating;
804 this->BuildSortTownList();
812 void SetStringParameters(
WidgetID widget)
const override
832 return t->
larger_town ? STR_TOWN_DIRECTORY_CITY : STR_TOWN_DIRECTORY_TOWN;
835 void DrawWidget(
const Rect &r,
WidgetID widget)
const override
845 if (this->towns.empty()) {
853 int icon_x = tr.
WithWidth(icon_size.width, rtl).left;
856 for (uint i = this->vscroll->
GetPosition(); i < this->towns.size(); i++) {
857 const Town *t = this->towns[i];
862 DrawSprite(SPR_TOWN_RATING_NA, PAL_NONE, icon_x, tr.top + (this->resize.step_height - icon_size.height) / 2);
864 SpriteID icon = SPR_TOWN_RATING_APALLING;
867 DrawSprite(icon, PAL_NONE, icon_x, tr.top + (this->resize.step_height - icon_size.height) / 2);
874 tr.top += this->resize.step_height;
888 d.height += padding.height;
897 d.width += padding.width;
898 d.height += padding.height;
904 for (uint i = 0; i < this->towns.size(); i++) {
905 const Town *t = this->towns[i];
907 assert(t !=
nullptr);
914 d.width += icon_size.width + 2;
915 d.height = std::max(d.height, icon_size.height);
916 resize->height = d.height;
918 d.width += padding.width;
919 d.height += padding.height;
926 d.width += padding.width;
927 d.height += padding.height;
934 void OnClick([[maybe_unused]]
Point pt,
WidgetID widget, [[maybe_unused]]
int click_count)
override
940 this->last_sorting = this->towns.
GetListing();
943 this->last_sorting.
order = !this->last_sorting.
order;
957 if (it == this->towns.end())
return;
960 assert(t !=
nullptr);
971 void OnDropdownSelect(
WidgetID widget,
int index)
override
975 if (this->towns.
SortType() != index) {
977 this->last_sorting = this->towns.
GetListing();
978 this->BuildSortTownList();
984 if (this->towns.
NeedRebuild()) this->BuildSortTownList();
990 this->BuildSortTownList();
999 void OnEditboxChanged(
WidgetID wid)
override
1012 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
1015 case TDIWD_FORCE_REBUILD:
1020 case TDIWD_POPULATION_CHANGE:
1042 static inline HotkeyList hotkeys {
"towndirectory", {
1047 Listing TownDirectoryWindow::last_sorting = {
false, 0};
1052 STR_SORT_BY_POPULATION,
1060 &TownPopulationSorter,
1064 static WindowDesc _town_directory_desc(__FILE__, __LINE__,
1068 std::begin(_nested_town_directory_widgets), std::end(_nested_town_directory_widgets),
1069 &TownDirectoryWindow::hotkeys
1072 void ShowTownDirectory()
1080 if (result.
Failed())
return;
1091 static constexpr
NWidgetPart _nested_found_town_widgets[] = {
1163 this->RandomTownName();
1164 this->UpdateButtons(
true);
1167 void RandomTownName()
1171 if (!this->townnamevalid) {
1172 this->townname_editbox.text.
DeleteAll();
1174 this->townname_editbox.text.
Assign(
GetTownName(&this->params, this->townnameparts));
1181 void UpdateButtons(
bool check_availability)
1183 if (check_availability && _game_mode != GM_EDITOR) {
1203 template <
typename Tcallback>
1204 void ExecuteFoundTownCommand(
TileIndex tile,
bool random,
StringID errstr, Tcallback cc)
1208 if (!this->townnamevalid) {
1209 name = this->townname_editbox.text.
buf;
1212 std::string original_name =
GetTownName(&this->params, this->townnameparts);
1213 if (original_name != this->townname_editbox.text.
buf) name = this->townname_editbox.text.
buf;
1217 tile, this->town_size, this->city, this->town_layout, random,
townnameparts, name);
1223 void OnClick([[maybe_unused]]
Point pt,
WidgetID widget, [[maybe_unused]]
int click_count)
override
1231 this->ExecuteFoundTownCommand(0,
true, STR_ERROR_CAN_T_GENERATE_TOWN, CcFoundRandomTown);
1235 this->RandomTownName();
1246 old_generating_world.Restore();
1258 this->UpdateButtons(
false);
1270 this->UpdateButtons(
false);
1275 void OnPlaceObject([[maybe_unused]]
Point pt,
TileIndex tile)
override
1277 this->ExecuteFoundTownCommand(tile,
false, STR_ERROR_CAN_T_FOUND_TOWN_HERE, CcFoundTown);
1283 this->UpdateButtons(
false);
1291 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
1293 if (!gui_scope)
return;
1294 this->UpdateButtons(
true);
1298 static WindowDesc _found_town_desc(__FILE__, __LINE__,
1302 std::begin(_nested_found_town_widgets), std::end(_nested_found_town_widgets)
1305 void ShowFoundTownWindow()
1308 AllocateWindowDescFront<FoundTownWindow>(&_found_town_desc, 0);
1311 void InitializeTownGui()
1313 _town_local_authority_kdtree.
Clear();
@ ES_HANDLED
The passed event is handled.
@ 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.
@ TPE_MAIL
Cargo behaves mail-like for production.
void OnPaint() override
The window must be repainted.
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 ShowExtraViewportWindow(TileIndex tile=INVALID_TILE)
Show a new Extra Viewport window.
List of hotkeys for a window.
void SetDParamMaxDigits(size_t n, uint count, FontSize size)
Set DParam n to some number that is suitable for string size computations.
void SetFocusedWindow(Window *w)
Set the window that has the focus.
Dimensions (a width and height) of a rectangle in 2D.
TownLayout town_layout
select town layout,
void ShowErrorMessage(StringID summary_msg, int x, int y, CommandCost cc)
Display an error message in a window.
@ WDF_CONSTRUCTION
This window is used for construction; close it whenever changing company.
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
K-dimensional tree, specialised for 2-dimensional space.
bool IsEmpty() const
Check whether any filter words were entered.
Class to backup a specific variable and restore it later.
EventState OnHotkey(int hotkey) override
A hotkey has been pressed.
@ TDHK_FOCUS_FILTER_BOX
Focus the filter box.
void SetFilterTerm(const char *str)
Set the term to filter on.
@ WC_FOUND_TOWN
Found a town; Window numbers:
void SetWidgetDirty(WidgetID widget_index) const
Invalidate a widget, i.e.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
@ WF_DISABLE_VP_SCROLL
Window does not do autoscroll,.
ViewportData * viewport
Pointer to viewport data, if present.
void Assign(StringID string)
Render a string into the textbuffer.
bool _network_server
network-server is active
QueryString townname_editbox
Townname editbox.
TownSize
Supported initial town sizes.
Tindex index
Index of this pool item.
@ TACT_FUND_BUILDINGS
Fund new buildings.
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
virtual void Close(int data=0)
Hide the window and all its child windows, and mark them for a later deletion.
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
uint16_t growth_rate
town growth rate
QueryString townname_editbox
Filter editbox.
bool _ctrl_pressed
Is Ctrl pressed?
bool HandlePlacePushButton(Window *w, WidgetID widget, CursorID cursor, HighLightStyle mode)
This code is shared for the majority of the pushbuttons.
static bool TownPopulationSorter(const Town *const &a, const Town *const &b, const bool &order)
Sort by population (default descending, as big towns are of the most interest).
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
void SetSortType(uint8_t n_type)
Set the sorttype of the list.
void RaiseButtons(bool autoraise=false)
Raise the buttons of the window.
int StrNaturalCompare(std::string_view s1, std::string_view s2, bool ignore_garbage_at_front)
Compares two strings using case insensitive natural sort.
ClientSettings _settings_client
The current settings for this game.
uint GetDesiredInfoHeight(int width) const
Gets the desired height for the information panel.
TileIndex xy
town center tile
Specification of a cargo type.
static const StringID sorter_names[]
Names of the sorting functions.
static bool UsingWallclockUnits(bool newgame=false)
Check if we are using wallclock units.
void AddLine(const char *str)
Pass another text line from the current item to the filter.
ZoomLevel ScaleZoomGUI(ZoomLevel value)
Scale zoom level relative to GUI zoom.
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
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.
IntervalTimer< TimerWindow > rebuild_interval
Redraw the whole window on a regular interval.
bool show_zone
NOSAVE: mark town to show the local authority zone in the viewports.
bool NeedRebuild() const
Check if a rebuild is needed.
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?
bool bribe
enable bribing the local authority
char *const buf
buffer in which text is saved
void Remove(const T &element)
Remove a single element from the tree, if it exists.
Randomizer _interactive_random
Random used everywhere else, where it does not (directly) influence the game state.
@ 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.
High level window description.
constexpr int RoundDivSU(int a, uint b)
Computes round(a / b) for signed a and unsigned b.
bool fund_buildings
allow funding new buildings
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
TransportedCargoStat< uint32_t > supplied[NUM_CARGO]
Cargo statistics about supplied cargo.
@ 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.
SoundSettings sound
sound effect settings
int32_t WindowNumber
Number to differentiate different windows of the same class.
void DrawActions()
Draws the contents of the actions panel.
@ FS_NORMAL
Index of the normal font in the font tables.
@ WC_TOWN_AUTHORITY
Town authority; Window numbers:
TownAcceptanceEffect
Town growth effect when delivering cargo.
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
static const uint TOWN_GROWTH_DESERT
The town needs the cargo for growth when on desert (any amount)
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
std::conditional_t< std::is_same_v< P, std::nullptr_t >, bool(const T &, const T &), bool(const T &, const T &, const P)> SortFunction
Signature of sort function.
void Insert(const T &element)
Insert a single element in the tree.
void ForceResort()
Force a resort next Sort call Reset the resort timer if used too.
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 std::array< std::vector< const CargoSpec * >, NUM_TPE > town_production_cargoes
List of cargo specs for each Town Product Effect.
static StringID GetTownString(const Town *t)
Get the string to draw the town name.
@ ES_NOT_HANDLED
The passed event is not handled.
bool Failed() const
Did this command fail?
void ToggleSortOrder()
Toggle the sort order Since that is the worst condition for the sort function reverse the list here.
@ TACT_ROAD_REBUILD
Rebuild the roads.
uint16_t MaxTownNoise() const
Calculate the max town noise.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
StringFilter string_filter
Filter for towns.
void ReInit(int rx=0, int ry=0, bool reposition=false)
Re-initialize a window, and optionally change its size.
TownActions GetMaskOfTownActions(CompanyID cid, const Town *t)
Get a list of available town authority actions.
EconomySettings economy
settings to change the economy
@ WL_INFO
Used for DoCommand-like (and some non-fatal AI GUI) errors/information.
@ ZOOM_LVL_TOWN
Default zoom level for the town view.
bool IsDescSortOrder() const
Check if the sort order is descending.
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.
WindowFlags flags
Window flags.
Rect Indent(int indent, bool end) const
Copy Rect and indent it from its position.
int GetStringHeight(std::string_view str, int maxw, FontSize fontsize)
Calculates height of string (in pixels).
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
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.
const byte _town_action_costs[TACT_COUNT]
Factor in the cost of each town action.
void ShowDropDownMenu(Window *w, const StringID *strings, int selected, WidgetID button, uint32_t disabled_mask, uint32_t hidden_mask, uint width)
Show a dropdown menu window near a widget of the parent window.
const Town * _viewport_highlight_town
Currently selected town for coverage area highlight.
bool city
Are we building a city?
WindowNumber window_number
Window number within the window class.
bool SetFocusedWidget(WidgetID widget_index)
Set focus within this window to the given widget.
TownNameParams params
Town name parameters.
uint step_height
Step-size of height resize changes.
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
void OnPlaceObjectAbort() override
The user cancelled a tile highlight mode that has been set.
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
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.
const CargoSpec * FindFirstCargoWithTownAcceptanceEffect(TownAcceptanceEffect effect)
Determines the first cargo with a certain town effect.
void SetWidgetLoweredState(WidgetID widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
@ WC_TOWN_DIRECTORY
Town directory; Window numbers:
uint32_t population
Current population of people.
void DrawCompanyIcon(CompanyID c, int x, int y)
Draw the icon of a company.
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
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.
Tstorage old_max
Maximum amount last month.
static const uint TOWN_GROWTH_WINTER
The town only needs this cargo in the winter (any amount)
void ForceRebuild()
Force that a rebuild is needed.
IntervalTimer< TimerWindow > redraw_interval
Redraw the whole window on a regular interval.
bool IsWidgetLowered(WidgetID widget_index) const
Gets the lowered state of a widget.
std::map< WidgetID, QueryString * > querystrings
QueryString associated to WWT_EDITBOX widgets.
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.
int DrawStringMultiLine(int left, int right, int top, int bottom, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly over multiple lines.
void DrawSortButtonState(WidgetID widget, SortButtonState state) const
Draw a sort button's up or down arrow symbol.
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
bool GenerateTowns(TownLayout layout)
Generate a number of towns with a given layout.
bool IsShaded() const
Is window shaded currently?
@ TACT_COUNT
Number of available town actions.
Listing GetListing() const
Export current sort conditions.
TownActions enabled_actions
Actions that are enabled in settings.
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
Found a town window class.
static void GetTownName(StringBuilder &builder, const TownNameParams *par, uint32_t townnameparts)
Fills builder with specified town name.
static GUITownList::SortFunction *const sorter_funcs[]
Available town directory sorting functions.
uint32_t goal[NUM_TAE]
Amount of cargo required for the town to grow.
void ResetState()
Reset the matching state to process a new item.
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.
EventState
State of handling an event.
@ 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 SetDParamStr(size_t n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
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.
uint32_t num_houses
Amount of houses.
static const int ACTION_CLEAR
Clear editbox.
@ TACT_NONE
Empty action set.
static bool TownNameSorter(const Town *const &a, const Town *const &b, const bool &)
Sort by town name.
void Clear()
Clear the tree.
uint8_t SortType() const
Get the sorttype of the list.
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
void DrawRatings()
Draw the contents of the ratings panel.
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.
void SetSortFuncs(SortFunction *const *n_funcs)
Hand the array of sort function pointers to the sort list.
void RebuildDone()
Notify the sortlist that the rebuild is done.
static debug_inline uint TileHeight(Tile tile)
Returns the height of a tile.
@ SND_1F_CONSTRUCTION_OTHER
29 == 0x1D Construction: other (non-water, non-rail, non-bridge)
byte CargoID
Cargo slots to indicate a cargo type within a game.
@ TAE_END
End of town effects.
int16_t ratings[MAX_COMPANIES]
ratings of each company for this town
int DrawString(int left, int right, int top, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
int GetRowFromWidget(int clickpos, WidgetID widget, int padding, int line_height=-1) const
Compute the row of a widget that a user clicked in.
TransportedCargoStat< uint16_t > received[NUM_TAE]
Cargo statistics about received cargotypes.
void UpdateOSKOriginalText(const Window *parent, WidgetID button)
Updates the original text of the OSK so when the 'parent' changes the original and you press on cance...
@ WC_TOWN_VIEW
Town view; Window numbers:
bool GenerateTownName(Randomizer &randomizer, uint32_t *townnameparts, TownNames *town_names)
Generates valid town name.
uint16_t noise_reached
level of noise that all the airports are generating
TownDirectoryHotkeys
Enum referring to the Hotkeys in the town directory window.
Data structure for an opened window.
Commands
List of commands.
static constexpr TimerGameTick::Ticks DAY_TICKS
1 day is 74 ticks; TimerGameCalendar::date_fract used to be uint16_t and incremented by 885.
Money GetAvailableMoney(CompanyID company)
Get the amount of money that a company has available, or INT64_MAX if there is no such valid company.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
@ TPE_PASSENGERS
Cargo behaves passenger-like for production.
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.
uint32_t GetWorldPopulation()
Get the total population, the sum of all towns in the world.
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.
CompanyID exclusivity
which company has exclusivity
bool Sort(Comp compare)
Sort the list.
void SetWidgetsDisabledState(bool disab_stat, Args... widgets)
Sets the enabled/disabled status of a list of widgets.
@ TACT_ALL
All possible actions.
TropicZone GetTropicZone(Tile tile)
Get the tropic zone.
@ QSF_ENABLE_DEFAULT
enable the 'Default' button ("\0" is returned)
#define CLRBITS(x, y)
Clears several bits in a variable.
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows).
void DeleteAll()
Delete every character in the textbuffer.
@ TD_RTL
Text is written right-to-left by default.
TextDirection _current_text_dir
Text direction of the currently selected language.
TownActions
Town actions of a company.
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
uint32_t townnameparts
Generated town name.
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
GUISettings gui
settings related to the GUI
void SetViewportCatchmentTown(const Town *t, bool sel)
Select or deselect town for coverage area highlight.
bool persistent_buildingtools
keep the building tools active after usage
void SetListing(Listing l)
Import sort conditions.
void OnResize() override
Called after the window got resized.
All data for a single hotkey.
@ TACT_BUY_RIGHTS
Buy exclusive transport rights.
static bool TownRatingSorter(const Town *const &a, const Town *const &b, const bool &order)
Sort by town rating.
void ResizeWindow(Window *w, int delta_x, int delta_y, bool clamp_to_screen)
Resize the window.
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
Dimension icon_size
Dimensions of company icon.
Town * town
Town displayed by the window.
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.