51#include "table/strings.h"
61static constexpr NWidgetPart _nested_town_authority_widgets[] = {
74 NWidget(
WWT_PUSHTXTBTN, COLOUR_BROWN,
WID_TA_EXECUTE),
SetMinimalSize(317, 12),
SetResize(1, 0),
SetFill(1, 0),
SetStringTip(STR_LOCAL_AUTHORITY_DO_IT_BUTTON, STR_LOCAL_AUTHORITY_DO_IT_TOOLTIP),
150 this->exclusive_size =
GetSpriteSize(SPR_EXCLUSIVE_TRANSPORT);
195 int rating = this->town->
ratings[c->index];
197 if (rating > RATING_APPALLING) str++;
198 if (rating > RATING_VERYPOOR) str++;
199 if (rating > RATING_POOR) str++;
200 if (rating > RATING_MEDIOCRE) str++;
201 if (rating > RATING_GOOD) str++;
202 if (rating > RATING_VERYGOOD) str++;
203 if (rating > RATING_EXCELLENT) str++;
215 text.bottom = text.top - 1;
216 if (text.bottom > r.bottom) {
233 if (!
HasBit(this->enabled_actions, i))
continue;
254 if (this->sel_index != -1) {
260 this->action_tooltips[
this->sel_index],
271 assert(size.width > padding.width && size.height > padding.height);
277 d.width += padding.width;
278 d.height += padding.height;
289 size.width += padding.width;
294 size.height = 9 *
resize.height + padding.height;
304 TownID index = this->town->
index;
324 if (click_count == 1 || y < 0 || !
HasBit(this->available_actions, y))
break;
344 if (!
HasBit(this->enabled_actions, this->sel_index)) {
345 this->sel_index = -1;
351 WDP_AUTO,
"view_town_authority", 317, 222,
354 _nested_town_authority_widgets
357static void ShowTownAuthorityWindow(uint town)
359 AllocateWindowDescFront<TownAuthorityWindow>(_town_authority_desc, town);
369 static const int WID_TV_HEIGHT_NORMAL = 150;
432 for (
int i = TAE_BEGIN; i <
TAE_END; i++) {
433 if (this->town->
goal[i] == 0)
continue;
494 if (!this->town->
text.empty()) {
553 for (
int i = TAE_BEGIN; i <
TAE_END; i++) {
554 if (this->town->
goal[i] == 0)
continue;
568 if (!this->town->
text.empty()) {
576 void ResizeWindowAsNeeded()
612 this->ResizeWindowAsNeeded();
617 if (!str.has_value())
return;
628static constexpr NWidgetPart _nested_town_game_view_widgets[] = {
643 NWidget(
WWT_PANEL, COLOUR_BROWN,
WID_TV_INFO),
SetMinimalSize(260, 32),
SetResize(1, 0),
SetFill(1, 0),
EndContainer(),
645 NWidget(
WWT_PUSHTXTBTN, COLOUR_BROWN,
WID_TV_SHOW_AUTHORITY),
SetMinimalSize(80, 12),
SetFill(1, 1),
SetResize(1, 0),
SetStringTip(STR_TOWN_VIEW_LOCAL_AUTHORITY_BUTTON, STR_TOWN_VIEW_LOCAL_AUTHORITY_TOOLTIP),
646 NWidget(
WWT_TEXTBTN, COLOUR_BROWN,
WID_TV_CATCHMENT),
SetMinimalSize(40, 12),
SetFill(1, 1),
SetResize(1, 0),
SetStringTip(STR_BUTTON_CATCHMENT, STR_TOOLTIP_CATCHMENT),
652 WDP_AUTO,
"view_town", 260, TownViewWindow::WID_TV_HEIGHT_NORMAL,
655 _nested_town_game_view_widgets
658static constexpr NWidgetPart _nested_town_editor_view_widgets[] = {
673 NWidget(
WWT_PANEL, COLOUR_BROWN,
WID_TV_INFO),
SetMinimalSize(260, 32),
SetResize(1, 0),
SetFill(1, 0),
EndContainer(),
675 NWidget(
WWT_PUSHTXTBTN, COLOUR_BROWN,
WID_TV_EXPAND),
SetMinimalSize(80, 12),
SetFill(1, 1),
SetResize(1, 0),
SetStringTip(STR_TOWN_VIEW_EXPAND_BUTTON, STR_TOWN_VIEW_EXPAND_TOOLTIP),
676 NWidget(
WWT_PUSHTXTBTN, COLOUR_BROWN,
WID_TV_DELETE),
SetMinimalSize(80, 12),
SetFill(1, 1),
SetResize(1, 0),
SetStringTip(STR_TOWN_VIEW_DELETE_BUTTON, STR_TOWN_VIEW_DELETE_TOOLTIP),
677 NWidget(
WWT_TEXTBTN, COLOUR_BROWN,
WID_TV_CATCHMENT),
SetMinimalSize(40, 12),
SetFill(1, 1),
SetResize(1, 0),
SetStringTip(STR_BUTTON_CATCHMENT, STR_TOOLTIP_CATCHMENT),
683 WDP_AUTO,
"view_town_scen", 260, TownViewWindow::WID_TV_HEIGHT_NORMAL,
686 _nested_town_editor_view_widgets
689void ShowTownViewWindow(TownID town)
691 if (_game_mode == GM_EDITOR) {
692 AllocateWindowDescFront<TownViewWindow>(_town_editor_view_desc, town);
694 AllocateWindowDescFront<TownViewWindow>(_town_game_view_desc, town);
698static constexpr NWidgetPart _nested_town_directory_widgets[] = {
716 NWidget(
WWT_TEXT, INVALID_COLOUR,
WID_TD_WORLD_POPULATION),
SetPadding(2, 0, 2, 2),
SetFill(1, 0),
SetResize(1, 0),
SetStringTip(STR_TOWN_POPULATION),
738 static inline const StringID sorter_names[] = {
743 static const std::initializer_list<GUITownList::SortFunction * const>
sorter_funcs;
752 void BuildSortTownList()
759 if (this->string_filter.
IsEmpty()) {
760 this->towns.push_back(t);
764 this->string_filter.
AddLine(t->GetCachedName());
765 if (this->string_filter.
GetState()) this->towns.push_back(t);
769 this->vscroll->
SetCount(this->towns.size());
823 this->BuildSortTownList();
868 if (this->towns.empty()) {
876 int icon_x =
tr.WithWidth(icon_size.width,
rtl).left;
880 for (
auto it = first; it !=
last; ++it) {
886 DrawSprite(SPR_TOWN_RATING_NA, PAL_NONE,
icon_x,
tr.top + (
this->resize.step_height - icon_size.height) / 2);
888 SpriteID icon = SPR_TOWN_RATING_APALLING;
911 d.height += padding.height;
917 d.width += padding.width;
918 d.height += padding.height;
924 for (uint i = 0; i < this->towns.size(); i++) {
925 const Town *t = this->towns[i];
934 d.width += icon_size.width + 2;
935 d.height = std::max(
d.height, icon_size.height);
938 d.width += padding.width;
939 d.height += padding.height;
946 d.width += padding.width;
947 d.height += padding.height;
960 this->last_sorting = this->towns.
GetListing();
963 this->last_sorting.
order = !this->last_sorting.
order;
977 if (it == this->towns.end())
return;
995 if (this->towns.
SortType() != index) {
997 this->last_sorting = this->towns.
GetListing();
998 this->BuildSortTownList();
1004 if (this->towns.
NeedRebuild()) this->BuildSortTownList();
1010 this->BuildSortTownList();
1035 case TDIWD_FORCE_REBUILD:
1040 case TDIWD_POPULATION_CHANGE:
1062 static inline HotkeyList hotkeys {
"towndirectory", {
1067Listing TownDirectoryWindow::last_sorting = {
false, 0};
1072 &TownPopulationSorter,
1080 _nested_town_directory_widgets,
1081 &TownDirectoryWindow::hotkeys
1084void ShowTownDirectory()
1092 if (result.
Failed())
return;
1103static constexpr NWidgetPart _nested_found_town_widgets[] = {
1186 this->RandomTownName();
1187 this->UpdateButtons(
true);
1192 if (_game_mode == GM_EDITOR)
return;
1203 void RandomTownName()
1207 if (!this->townnamevalid) {
1208 this->townname_editbox.text.
DeleteAll();
1210 this->townname_editbox.text.
Assign(GetTownName(&this->params, this->townnameparts));
1237 template <
typename Tcallback>
1242 if (!this->townnamevalid) {
1243 name = this->townname_editbox.text.
GetText();
1246 std::string
original_name = GetTownName(&this->params, this->townnameparts);
1251 tile, this->town_size, this->city, this->town_layout, random,
townnameparts, name);
1269 this->RandomTownName();
1296 this->UpdateButtons(
false);
1313 this->UpdateButtons(
false);
1326 this->UpdateButtons(
false);
1337 this->UpdateButtons(
true);
1345 _nested_found_town_widgets
1348void ShowFoundTownWindow()
1351 AllocateWindowDescFront<FoundTownWindow>(_found_town_desc, 0);
1354void InitializeTownGui()
1356 _town_local_authority_kdtree.
Clear();
1371 if (group ==
nullptr || group->type != SGT_TILELAYOUT)
return;
1381 palette =
HasBit(callback, 14) ?
GB(callback, 0, 8) + SPR_2CCMAP_BASE : callback;
1407 auto draw = [](
int x,
int y,
HouseID house_id,
int view) {
1426 if (dcts.building.
sprite != 0) {
1439 draw(x, y - y_delta - y_delta, house_id, view);
1440 draw(x + x_delta, y - y_delta, house_id + 1, view);
1441 draw(x - x_delta, y - y_delta, house_id + 2, view);
1442 draw(x, y, house_id + 3, view);
1444 draw(x + x_delta / 2, y - y_delta, house_id, view);
1445 draw(x - x_delta / 2, y, house_id + 1, view);
1447 draw(x - x_delta / 2, y - y_delta, house_id, view);
1448 draw(x + x_delta / 2, y, house_id + 1, view);
1450 draw(x, y, house_id, view);
1463 if (callback_res > 0x400) {
1467 if (new_name != STR_NULL && new_name != STR_UNDEFINED) {
1486 case LandscapeType::Temperate: this->climate_mask =
HZ_TEMP;
break;
1488 case LandscapeType::Tropic: this->climate_mask =
HZ_SUBTROPIC;
break;
1489 case LandscapeType::Toyland: this->climate_mask =
HZ_TOYLND;
break;
1490 default: NOT_REACHED();
1499 for (
int cls_id = 0; cls_id < num_classes; ++cls_id) {
1501 for (
int id = 0;
id < num_types; ++id) {
1519 static inline const std::array<StringID, HZB_END> zone_names = {
1520 STR_HOUSE_PICKER_CLASS_ZONE1,
1521 STR_HOUSE_PICKER_CLASS_ZONE2,
1522 STR_HOUSE_PICKER_CLASS_ZONE3,
1523 STR_HOUSE_PICKER_CLASS_ZONE4,
1524 STR_HOUSE_PICKER_CLASS_ZONE5,
1532 int GetClassCount()
const override {
return static_cast<int>(zone_names.size()); }
1543 return zone_names[id];
1555 if (!spec->grf_prop.HasGrfFile())
return {0, spec->Index(), cls_id,
id};
1556 return {spec->grf_prop.grfid, spec->grf_prop.local_id, cls_id,
id};
1569 for (
int i = 0; i < cls_id; i++) {
1583 void DrawType(
int x,
int y,
int,
int id)
const override
1591 for (
auto it = id_count.begin(); it != id_count.end(); ++it) {
1592 if (*it == 0)
continue;
1593 HouseID house =
static_cast<HouseID>(std::distance(id_count.begin(), it));
1596 items.insert({0, house, class_index, house});
1602 if (src.empty())
return src;
1605 std::set<PickerItem> dst;
1606 for (
const auto &item : src) {
1607 if (item.grfid == 0) {
1612 if (it == specs.end()) {
1614 dst.insert({item.grfid, item.local_id, -1, -1});
1617 dst.insert( {item.grfid, item.local_id, class_index, it->Index()});
1630 std::string house_info;
1635 this->ConstructWindow();
1639 void UpdateSelectSize(
const HouseSpec *spec)
1641 if (spec ==
nullptr) {
1689 std::stringstream line;
1734 UpdateSelectSize(spec);
1752 static inline HotkeyList hotkeys{
"buildhouse", {
1784 &BuildHouseWindow::hotkeys
1787void ShowBuildHousePicker(
Window *parent)
Class for backupping variables and making sure they are restored later.
debug_inline constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
#define CLRBITS(x, y)
Clears several bits in a variable.
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
constexpr uint8_t FindFirstBit(T x)
Search the first set bit in a value.
debug_inline static constexpr uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
uint8_t CargoType
Cargo slots to indicate a cargo type within a game.
std::optional< std::string > BuildCargoAcceptanceString(const CargoArray &acceptance, StringID label)
Build comma-separated cargo acceptance string.
@ TPE_PASSENGERS
Cargo behaves passenger-like for production.
@ TPE_MAIL
Cargo behaves mail-like for production.
TownAcceptanceEffect
Town growth effect when delivering cargo.
@ TAE_END
End of town effects.
Common return value for all commands.
bool Succeeded() const
Did this command succeed?
bool Failed() const
Did this command fail?
constexpr EnumBitSet & Set(Tenum value)
Set the enum value.
constexpr bool Test(Tenum value) const
Test if the enum value is set.
List template of 'things' T to sort in a GUI.
void RebuildDone()
Notify the sortlist that the rebuild is done.
void SetListing(Listing l)
Import sort conditions.
bool IsDescSortOrder() const
Check if the sort order is descending.
void ToggleSortOrder()
Toggle the sort order Since that is the worst condition for the sort function reverse the list here.
bool NeedRebuild() const
Check if a rebuild is needed.
void ForceRebuild()
Force that a rebuild is needed.
bool Sort(Comp compare)
Sort the list.
void ForceResort()
Force a resort next Sort call Reset the resort timer if used too.
uint8_t SortType() const
Get the sorttype of the list.
Listing GetListing() const
Export current sort conditions.
void SetSortFuncs(std::span< SortFunction *const > n_funcs)
Hand the sort function pointers to the GUIList.
void SetSortType(uint8_t n_type)
Set the sorttype of the list.
PickerItem GetPickerItem(int cls_id, int id) const override
Get data about an item.
bool IsActive() const override
Should picker class/type selection be enabled?
void SetClimateMask()
Set climate mask for filtering buildings from current landscape.
void SetSelectedClass(int cls_id) const override
Set the selected class.
StringID GetClassTooltip() const override
Get the tooltip string for the class list.
void DrawType(int x, int y, int, int id) const override
Draw preview image of an item.
static int sel_view
Currently selected 'view'. This is not controllable as its based on random data.
int GetClassCount() const override
Get the number of classes.
void FillUsedItems(std::set< PickerItem > &items) override
Fill a set with all items that are used by the current player.
static int sel_type
Currently selected HouseID.
int GetSelectedClass() const override
Get the index of the selected class.
std::set< PickerItem > UpdateSavedItems(const std::set< PickerItem > &src) override
Update link between grfid/localidx and class_index/index in saved items.
StringID GetTypeTooltip() const override
Get the tooltip string for the type grid.
void SetSelectedType(int id) const override
Set the selected type.
StringID GetTypeName(int cls_id, int id) const override
Get the item of a type.
int GetSelectedType() const override
Get the selected type.
bool IsTypeAvailable(int, int id) const override
Test if an item is currently buildable.
bool HasClassChoice() const override
Are there multiple classes to chose from?
uint8_t class_mask
Mask of available 'classes'.
int GetTypeCount(int cls_id) const override
Get the number of types in a class.
StringID GetClassName(int id) const override
Get the name of a class.
static int sel_class
Currently selected 'class'.
An interval timer will fire every interval, and will continue to fire until it is deleted.
K-dimensional tree, specialised for 2-dimensional space.
void Insert(const T &element)
Insert a single element in the tree.
void Remove(const T &element)
Remove a single element from the tree, if it exists.
void Clear()
Clear the tree.
Class for PickerClassWindow to collect information and retain state.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
@ PCWHK_FOCUS_FILTER_BOX
Focus the edit box for editing the filter string.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
@ PFI_POSITION
Update scroll positions.
static constexpr TimerGameTick::Ticks DAY_TICKS
1 day is 74 ticks; TimerGameCalendar::date_fract used to be uint16_t and incremented by 885.
static constexpr TimerGame< struct Calendar >::Year MIN_YEAR
The absolute minimum year in OTTD.
static constexpr TimerGame< struct Calendar >::Year MAX_YEAR
MAX_YEAR, nicely rounded value of the number of years that can be encoded in a single 32 bits date,...
static bool UsingWallclockUnits(bool newgame=false)
Check if we are using wallclock units.
Functions related to commands.
@ DC_EXEC
execute the given command
Commands
List of commands.
Definition of stuff that is very close to a company, like the company struct itself.
void DrawCompanyIcon(CompanyID c, int x, int y)
Draw the icon of a company.
Money GetAvailableMoney(CompanyID company)
Get the amount of money that a company has available, or INT64_MAX if there is no such valid company.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Functions related to companies.
GUI Functions related to companies.
void ShowDropDownMenu(Window *w, std::span< 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.
Functions related to the drop down widget.
Functions related to errors.
@ WL_INFO
Used for DoCommand-like (and some non-fatal AI GUI) errors/information.
void ShowErrorMessage(StringID summary_msg, int x, int y, CommandCost cc)
Display an error message in a window.
@ SLO_LOAD
File is being loaded.
@ FT_TOWN_DATA
town data file
Declarations for savegames operations.
void ShowSaveLoadDialog(AbstractFileType abstract_filetype, SaveLoadOperation fop)
Launch save/load dialog in the given mode.
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
bool _generating_world
Whether we are generating the map or not.
Functions related to world/map generation.
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
int GetStringHeight(std::string_view 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 _shift_pressed
Is Shift pressed?
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
Dimension GetStringListBoundingBox(std::span< const StringID > list, FontSize fontsize)
Get maximum dimension of a list of strings.
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.
bool _ctrl_pressed
Is Ctrl pressed?
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.
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.
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
@ FS_NORMAL
Index of the normal font in the font tables.
uint32_t PaletteID
The number of the palette.
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
@ TC_NO_SHADE
Do not add shading to this text colour.
uint8_t LowestSnowLine()
Get the lowest possible snow line height, either variable or static.
uint8_t GetSnowLine()
Get the current snow line, either variable or static.
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
GUI functions that shouldn't be here.
void ShowExtraViewportWindow(TileIndex tile=INVALID_TILE)
Show a new Extra Viewport window.
Hotkey related functions.
definition of HouseSpec and accessors
static const HouseID NEW_HOUSE_OFFSET
Offset for new houses.
static const uint8_t TOWN_HOUSE_COMPLETED
Simple value that indicates the house has reached the final stage of construction.
@ HZ_SUBARTC_BELOW
13 2000 can appear in sub-arctic climate below the snow line
@ HZ_ZONALL
1F This is just to englobe all above types at once
@ HZ_TEMP
12 1000 can appear in temperate climate
@ HZ_TOYLND
15 8000 can appear in toyland climate
@ HZ_SUBTROPIC
14 4000 can appear in subtropical climate
@ HZ_SUBARTC_ABOVE
11 800 can appear in sub-arctic climate above the snow line
uint16_t HouseID
OpenTTD ID of house types.
Functions related to OTTD's landscape.
Point RemapCoords(int x, int y, int z)
Map 3D world or tile coordinate to equivalent 2D coordinate as used in the viewports and smallmap.
bool DoZoomInOutWindow(ZoomStateChange how, Window *w)
Zooms a viewport in a window in or out.
bool HandlePlacePushButton(Window *w, WidgetID widget, CursorID cursor, HighLightStyle mode)
This code is shared for the majority of the pushbuttons.
constexpr int RoundDivSU(int a, uint b)
Computes round(a / b) for signed a and unsigned b.
void ShowQueryString(StringID str, StringID caption, uint maxsize, Window *parent, CharSetFilter afilter, QueryStringFlags flags)
Show a query popup window with a textbox in it.
bool _networking
are we in networking mode?
bool _network_server
network-server is active
Basic functions/variables used all over the place.
@ CBID_HOUSE_COLOUR
Called to determine the colour of a town building.
@ CBID_NO_CALLBACK
Set when using the callback resolve system, but not to resolve a callback.
@ CBID_HOUSE_CUSTOM_NAME
Called on the Get Tile Description for an house tile.
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
@ Colour
decide the colour of the building
Cargo support for NewGRFs.
void ErrorUnknownCallbackResult(uint32_t grfid, uint16_t cbid, uint16_t cb_res)
Record that a NewGRF returned an unknown/invalid callback result.
std::span< const uint > GetBuildingHouseIDCounts()
Get read-only span of total HouseID building counts.
Functions related to NewGRF houses.
StringID GetGRFStringID(uint32_t grfid, GRFStringID stringid)
Returns the index for this stringid associated with its grfID.
Header of Action 04 "universal holder" structure and functions.
static constexpr GRFStringID GRFSTR_MISC_GRF_TEXT
Miscellaneous GRF text range.
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...
std::unique_ptr< NWidgetBase > MakePickerClassWidgets()
Create nested widgets for the class picker widgets.
std::unique_ptr< NWidgetBase > MakePickerTypeWidgets()
Create nested widgets for the type picker widgets.
Base for the GUIs that have an edit box in them.
Randomizer _interactive_random
Random used everywhere else, where it does not (directly) influence the game state.
void UpdateNearestTownForRoadTiles(bool invalidate)
Updates cached nearest town for all road tiles.
A number of safeguards to prevent using unsafe methods.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
ClientSettings _settings_client
The current settings for this game.
@ SWS_OFF
Scroll wheel has no effect.
Base types for having sorted lists in GUIs.
Functions related to sound.
@ SND_1F_CONSTRUCTION_OTHER
29 == 0x1D Construction: other (non-water, non-rail, non-bridge)
void DrawNewGRFTileSeqInGUI(int x, int y, const DrawTileSprites *dts, uint32_t stage, PaletteID default_palette)
Draw NewGRF object in GUI.
PaletteID GroundSpritePaletteTransform(SpriteID image, PaletteID pal, PaletteID default_pal)
Applies PALETTE_MODIFIER_COLOUR to a palette entry of a ground sprite.
static constexpr uint8_t SPRITE_MODIFIER_CUSTOM_SPRITE
these masks change the colours of the palette for a sprite.
static constexpr uint8_t SPRITE_WIDTH
number of bits for the sprite number
Definition of base types and functions in a cross-platform compatible way.
int StrNaturalCompare(std::string_view s1, std::string_view s2, bool ignore_garbage_at_front)
Compares two strings using case insensitive natural sort.
Functions related to low-level strings.
@ CS_ALPHANUMERAL
Both numeric and alphabetic and spaces and stuff.
Searching and filtering using a stringterm.
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
std::string GetString(StringID string)
Resolve the given StringID into a std::string with all the associated DParam lookups and formatting.
TextDirection _current_text_dir
Text direction of the currently selected language.
void SetDParamStr(size_t n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
void SetDParamMaxDigits(size_t n, uint count, FontSize size)
Set DParam n to some number that is suitable for string size computations.
Functions related to OTTD's strings.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
@ TD_RTL
Text is written right-to-left by default.
static const int MAX_CHAR_LENGTH
Max. length of UTF-8 encoded unicode character.
Class to backup a specific variable and restore it later.
static std::string GetHouseYear(TimerGameCalendar::Year min_year, TimerGameCalendar::Year max_year)
Get a date range string for house availability year.
void OnPlaceObject(Point pt, TileIndex tile) override
The user clicked some place on the map when a tile highlight mode has been set.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
static std::string GetHouseInformation(const HouseSpec *hs)
Get information string for a house.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Specification of a cargo type.
CargoType Index() const
Determines index of this cargospec.
StringID name
Name of this type of cargo.
static std::array< std::vector< const CargoSpec * >, NUM_TPE > town_production_cargoes
List of cargo specs for each Town Product Effect.
SoundSettings sound
sound effect settings
GUISettings gui
settings related to the GUI
Dimensions (a width and height) of a rectangle in 2D.
This structure is the same for both Industries and Houses.
Ground palette sprite of a tile, together with its sprite layout.
PalSpriteID ground
Palette and sprite for the ground.
bool bribe
enable bribing the local authority
TownFounding found_town
town founding.
bool exclusive_rights
allow buying exclusive rights
TownLayout town_layout
select town layout,
bool station_noise_level
build new airports when the town noise level is still within accepted limits
bool fund_buildings
allow funding new buildings
bool fund_roads
allow funding local road reconstruction
Found a town window class.
uint32_t townnameparts
Generated town name.
TownLayout town_layout
Selected town layout.
void OnPlaceObject(Point pt, TileIndex tile) override
The user clicked some place on the map when a tile highlight mode has been set.
QueryString townname_editbox
Townname editbox.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
void OnInit() override
Notification that the nested widget tree gets initialized.
TownSize town_size
Selected town size.
bool townnamevalid
Is generated town name valid?
TownNameParams params
Town name parameters.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
void OnPlaceObjectAbort() override
The user cancelled a tile highlight mode that has been set.
bool city
Are we building a city?
uint16_t local_id
id defined by the grf file for this entity
uint32_t grfid
grfid that introduced this entity.
const struct GRFFile * grffile
grf file that introduced this entity
std::array< const struct SpriteGroup *, Tcnt > spritegroup
pointers to the different sprites of the entity
bool persistent_buildingtools
keep the building tools active after usage
uint8_t scrollwheel_scrolling
scrolling using the scroll wheel?
LandscapeType landscape
the landscape we're currently in
EconomySettings economy
settings to change the economy
GameCreationSettings game_creation
settings used during the creation of a game (map)
List of hotkeys for a window.
All data for a single hotkey.
Resolver object to be used for houses (feature 07 spritegroups).
bool enabled
the house is available to build (true by default, but can be disabled by newgrf)
static HouseSpec * Get(size_t house_id)
Get the spec for a house ID.
BuildingFlags building_flags
some flags that describe the house (size, stadium etc...)
TimerGameCalendar::Year max_year
last year it can be built
HouseCallbackMasks callback_mask
Bitmask of house callbacks that have to be called.
uint8_t population
population (Zero on other tiles in multi tile house.)
TimerGameCalendar::Year min_year
introduction year of the house
HouseID Index() const
Gets the index of this spec.
StringID building_name
building name
GRFFileProps grf_prop
Properties related the the grf file.
Colours random_colour[4]
4 "random" colours
HouseZones building_availability
where can it be built (climates, zones)
static std::vector< HouseSpec > & Specs()
Get a reference to all HouseSpecs.
Data structure describing how to show the list (what sort direction and criteria).
bool order
Ascending/descending.
SpriteID sprite
The 'real' sprite.
PaletteID pal
The palette (use PAL_NONE) if not needed)
Coordinates of a point in 2D.
Tindex index
Index of this pool item.
static size_t GetNumItems()
Returns number of valid items in the pool.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
static Titem * Get(size_t index)
Returns Titem with given index.
Data stored about a string that can be modified in the GUI.
int cancel_button
Widget button of parent window to simulate when pressing CANCEL in OSK.
static const int ACTION_CLEAR
Clear editbox.
Specification of a rectangle with absolute coordinates of all edges.
Rect WithWidth(int width, bool end) const
Copy Rect and set its width.
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Rect Indent(int indent, bool end) const
Copy Rect and indent it from its position.
uint step_height
Step-size of height resize changes.
Iterable ensemble of each set bit in a value.
bool confirm
Play sound effect on successful constructions or other actions.
virtual const SpriteGroup * Resolve(ResolverObject &object) const
Base sprite group resolver.
bool IsEmpty() const
Check whether any filter words were entered.
void SetFilterTerm(const char *str)
Set the term to filter on.
void ResetState()
Reset the matching state to process a new item.
void AddLine(const char *str)
Pass another text line from the current item to the filter.
bool GetState() const
Get the matching state of the current item.
void DeleteAll()
Delete every character in the textbuffer.
void Assign(StringID string)
Render a string into the textbuffer.
const char * GetText() const
Get the current text.
Action 2 sprite layout for houses, industry tiles, objects and airport tiles.
void SetStringParameters(WidgetID widget) const override
Initialize string parameters for a widget.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
void DrawActions()
Draws the contents of the actions panel.
Dimension icon_size
Dimensions of company icon.
void OnInit() override
Notification that the nested widget tree gets initialized.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
Town * town
Town being displayed.
TownActions enabled_actions
Actions that are enabled in settings.
int sel_index
Currently selected town action, 0 to TACT_COUNT-1, -1 means no action selected.
TownActions available_actions
Actions that are available to execute for the current company.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
void DrawRatings()
Draw the contents of the ratings panel.
int GetNthSetBit(int n)
Get the position of the Nth set bit.
uint displayed_actions_on_previous_painting
Actions that were available on the previous call to OnPaint()
Dimension exclusive_size
Dimensions of exlusive icon.
IntervalTimer< TimerWindow > redraw_interval
Redraw the whole window on a regular interval.
static TownActions GetEnabledActions()
Gets all town authority actions enabled in settings.
void OnPaint() override
The window must be repainted.
uint32_t population
Current population of people.
uint32_t num_houses
Amount of houses.
Town directory window class.
static const std::initializer_list< GUITownList::SortFunction *const > sorter_funcs
Available town directory sorting functions.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
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).
IntervalTimer< TimerWindow > rebuild_interval
Redraw the whole window on a regular interval.
void OnDropdownSelect(WidgetID widget, int index) override
A dropdown option associated to this window has been selected.
QueryString townname_editbox
Filter editbox.
void OnEditboxChanged(WidgetID wid) override
The text in an editbox has been edited.
static bool TownRatingSorter(const Town *const &a, const Town *const &b, const bool &order)
Sort by town rating.
void OnResize() override
Called after the window got resized.
StringFilter string_filter
Filter for towns.
void SetStringParameters(WidgetID widget) const override
Initialize string parameters for a widget.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
EventState OnHotkey(int hotkey) override
A hotkey has been pressed.
void OnPaint() override
The window must be repainted.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
static StringID GetTownString(const Town *t)
Get the string to draw the town name.
static bool TownNameSorter(const Town *const &a, const Town *const &b, const bool &)
Sort by town name.
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
Struct holding parameters used to generate town name.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
Town * town
Town displayed by the window.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
uint GetDesiredInfoHeight(int width) const
Gets the desired height for the information panel.
void OnMouseWheel(int wheel) override
The mouse wheel has been turned.
void Close(int data=0) override
Hide the window and all its child windows, and mark them for a later deletion.
void OnPaint() override
The window must be repainted.
void OnQueryTextFinished(std::optional< std::string > str) override
The query window opened from this window has closed.
void OnResize() override
Called after the window got resized.
void SetStringParameters(WidgetID widget) const override
Initialize string parameters for a widget.
bool larger_town
if this is a larger town and should grow more quickly
TransportedCargoStat< uint32_t > supplied[NUM_CARGO]
Cargo statistics about supplied cargo.
TileIndex xy
town center tile
uint8_t fund_buildings_months
fund buildings program in action?
uint16_t noise_reached
level of noise that all the airports are generating
int16_t ratings[MAX_COMPANIES]
ratings of each company for this town
TransportedCargoStat< uint16_t > received[NUM_TAE]
Cargo statistics about received cargotypes.
uint16_t MaxTownNoise() const
Calculate the max town noise.
uint8_t flags
See TownFlags.
TownCache cache
Container for all cacheable data.
CompanyID exclusivity
which company has exclusivity
bool show_zone
NOSAVE: mark town to show the local authority zone in the viewports.
uint32_t goal[NUM_TAE]
Amount of cargo required for the town to grow.
std::string text
General text with additional information.
CompanyMask have_ratings
which companies have a rating
uint16_t growth_rate
town growth rate
Tstorage old_max
Maximum amount last month.
Tstorage old_act
Actually transported last month.
High level window description.
Number to differentiate different windows of the same class.
Data structure for an opened window.
void ReInit(int rx=0, int ry=0, bool reposition=false)
Re-initialize a window, and optionally change its size.
virtual void Close(int data=0)
Hide the window and all its child windows, and mark them for a later deletion.
static int SortButtonWidth()
Get width of up/down arrow of sort button state.
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
std::map< WidgetID, QueryString * > querystrings
QueryString associated to WWT_EDITBOX widgets.
void DrawWidgets() const
Paint all widgets of a window.
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing)
Window * parent
Parent window.
void SetWidgetDirty(WidgetID widget_index) const
Invalidate a widget, i.e.
void DrawSortButtonState(WidgetID widget, SortButtonState state) const
Draw a sort button's up or down arrow symbol.
ResizeInfo resize
Resize information.
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
ViewportData * viewport
Pointer to viewport data, if present.
bool SetFocusedWidget(WidgetID widget_index)
Set focus within this window to the given widget.
bool IsWidgetLowered(WidgetID widget_index) const
Gets the lowered state of a widget.
void RaiseButtons(bool autoraise=false)
Raise the buttons of the window.
void SetWidgetLoweredState(WidgetID widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
bool IsShaded() const
Is window shaded currently?
int GetRowFromWidget(int clickpos, WidgetID widget, int padding, int line_height=-1) const
Compute the row of a widget that a user clicked in.
const NWID * GetWidget(WidgetID widnum) const
Get the nested widget with number widnum from the nested widget tree.
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
WindowFlags flags
Window flags.
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
AllWindows< false > Iterate
Iterate all windows in whatever order is easiest.
int width
width of the window (number of pixels to the right in x direction)
WindowNumber window_number
Window number within the window class.
@ QSF_ENABLE_DEFAULT
enable the 'Default' button ("\0" is returned)
@ QSF_LEN_IN_CHARS
the length of the string is counted in characters
TropicZone GetTropicZone(Tile tile)
Get the tropic zone.
static debug_inline uint TileHeight(Tile tile)
Returns the height of a tile.
static const uint TILE_PIXELS
Pixel distance between tile columns/rows in ZOOM_BASE.
@ TROPICZONE_DESERT
Tile is desert.
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Functions related to tile highlights.
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows).
void SetObjectToPlaceWnd(CursorID icon, PaletteID pal, HighLightStyle mode, Window *w)
Change the cursor and mouse click/drag handling to a mode for performing special operations like tile...
@ HT_DIAGONAL
Also allow 'diagonal rectangles'. Only usable in combination with HT_RECT or HT_POINT.
@ HT_RECT
rectangle (stations, depots, ...)
Definition of Interval and OneShot timers.
Definition of the game-calendar-timer.
Definition of the Window system.
static const uint TOWN_GROWTH_WINTER
The town only needs this cargo in the winter (any amount)
TownActions GetMaskOfTownActions(CompanyID cid, const Town *t)
Get a list of available town authority actions.
const CargoSpec * FindFirstCargoWithTownAcceptanceEffect(TownAcceptanceEffect effect)
Determines the first cargo with a certain town effect.
static const uint TOWN_GROWTH_DESERT
The town needs the cargo for growth when on desert (any amount)
@ TOWN_IS_GROWING
Conditions for town growth are met. Grow according to Town::growth_rate.
uint32_t GetWorldPopulation()
Get the total population, the sum of all towns in the world.
TownActions
Town actions of a company.
@ TACT_ROAD_REBUILD
Rebuild the roads.
@ TACT_BUY_RIGHTS
Buy exclusive transport rights.
@ TACT_BRIBE
Try to bribe the council.
@ TACT_COUNT
Number of available town actions.
@ TACT_ALL
All possible actions.
@ TACT_FUND_BUILDINGS
Fund new buildings.
@ TACT_NONE
Empty action set.
const uint8_t _town_action_costs[TACT_COUNT]
Factor in the cost of each town action.
CargoArray GetAcceptedCargoOfHouse(const HouseSpec *hs)
Get accepted cargo of a house prototype.
bool GenerateTowns(TownLayout layout)
Generate a number of towns with a given layout.
Command definitions related to towns.
TownDirectoryHotkeys
Enum referring to the Hotkeys in the town directory window.
@ TDHK_FOCUS_FILTER_BOX
Focus the filter box.
static constexpr NWidgetPart _nested_build_house_widgets[]
Nested widget definition for the build NewGRF rail waypoint window.
void DrawHouseInGUI(int x, int y, HouseID house_id, int view)
Draw a house that does not exist.
void DrawNewHouseTileInGUI(int x, int y, const HouseSpec *spec, HouseID house_id, int view)
Draw representation of a house tile for GUI purposes.
static StringID GetHouseName(const HouseSpec *hs)
Get name for a prototype house.
Declarations for accessing the k-d tree of towns.
@ TF_CUSTOM_LAYOUT
Allowed, with custom town layout.
TownSize
Supported initial town sizes.
static const uint MAX_LENGTH_TOWN_NAME_CHARS
The maximum length of a town name in characters including '\0'.
bool GenerateTownName(Randomizer &randomizer, uint32_t *townnameparts, TownNames *town_names)
Generates valid town name.
Town name generator stuff.
bool ScrollWindowToTile(TileIndex tile, Window *w, bool instant)
Scrolls the viewport in a window to a given location.
void SetTileSelectSize(int w, int h)
Highlight w by h tiles at the cursor.
bool ScrollMainWindowToTile(TileIndex tile, bool instant)
Scrolls the viewport of the main window to a given location.
void SetViewportCatchmentTown(const Town *t, bool sel)
Select or deselect town for coverage area highlight.
const Town * _viewport_highlight_town
Currently selected town for coverage area highlight.
Functions related to (drawing on) viewports.
@ ZOOM_IN
Zoom in (get more detailed view).
@ ZOOM_OUT
Zoom out (get helicopter view).
void ResizeWindow(Window *w, int delta_x, int delta_y, bool clamp_to_screen, bool schedule_resize)
Resize the window.
void SetFocusedWindow(Window *w)
Set the window that has the focus.
Window * BringWindowToFrontById(WindowClass cls, WindowNumber number)
Find a window and make it the relative top-window on the screen.
Window functions not directly related to making/drawing windows.
@ Construction
This window is used for construction; close it whenever changing company.
@ DisableVpScroll
Window does not do autoscroll,.
@ SBS_DOWN
Sort ascending.
@ WDP_AUTO
Find a place automatically.
EventState
State of handling an event.
@ ES_HANDLED
The passed event is handled.
@ ES_NOT_HANDLED
The passed event is not handled.
@ WC_TOWN_AUTHORITY
Town authority; Window numbers:
@ WC_FOUND_TOWN
Found a town; Window numbers:
@ WC_BUILD_HOUSE
Build house; Window numbers:
@ WC_BUILD_TOOLBAR
Build toolbar; Window numbers:
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
@ WC_TOWN_VIEW
Town view; Window numbers:
@ WC_TOWN_DIRECTORY
Town directory; Window numbers:
Functions related to zooming.
ZoomLevel ScaleZoomGUI(ZoomLevel value)
Scale zoom level relative to GUI zoom.
int UnScaleGUI(int value)
Short-hand to apply GUI zoom level.
@ ZOOM_LVL_TOWN
Default zoom level for the town view.