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),
171 StringID GetRatingString(
int rating)
const
209 int rating = this->town->
ratings[c->index];
215 text.bottom = text.top - 1;
216 if (text.bottom > r.bottom) {
231 for (
TownAction i = {}; i != TownAction::End; ++i) {
256 if (this->sel_action != TownAction::End) {
272 assert(size.width > padding.width && size.height > padding.height);
274 for (
TownAction i = {}; i != TownAction::End; ++i) {
278 d.width += padding.width;
279 d.height += padding.height;
287 for (
TownAction i = {}; i != TownAction::End; ++i) {
290 size.width += padding.width;
295 size.height = 9 *
resize.height + padding.height;
320 this->sel_action =
static_cast<TownAction>(y);
346 this->sel_action = TownAction::End;
352 WDP_AUTO,
"view_town_authority", 317, 222,
355 _nested_town_authority_widgets
358static void ShowTownAuthorityWindow(uint town)
360 AllocateWindowDescFront<TownAuthorityWindow>(_town_authority_desc, town);
370 static const int WID_TV_HEIGHT_NORMAL = 150;
430 for (
int i = TAE_BEGIN; i <
TAE_END; i++) {
431 if (this->town->
goal[i] == 0)
continue;
451 if (this->town->
received[i].old_act == 0) {
462 if (this->town->
received[i].old_act <
this->town->goal[i]) {
484 if (!this->town->
text.empty()) {
541 for (
int i = TAE_BEGIN; i <
TAE_END; i++) {
542 if (this->town->
goal[i] == 0)
continue;
556 if (!this->town->
text.empty()) {
563 void ResizeWindowAsNeeded()
599 this->ResizeWindowAsNeeded();
604 if (!str.has_value())
return;
615static constexpr NWidgetPart _nested_town_game_view_widgets[] = {
630 NWidget(
WWT_PANEL, COLOUR_BROWN,
WID_TV_INFO),
SetMinimalSize(260, 32),
SetResize(1, 0),
SetFill(1, 0),
EndContainer(),
632 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),
633 NWidget(
WWT_TEXTBTN, COLOUR_BROWN,
WID_TV_CATCHMENT),
SetMinimalSize(40, 12),
SetFill(1, 1),
SetResize(1, 0),
SetStringTip(STR_BUTTON_CATCHMENT, STR_TOOLTIP_CATCHMENT),
639 WDP_AUTO,
"view_town", 260, TownViewWindow::WID_TV_HEIGHT_NORMAL,
642 _nested_town_game_view_widgets
645static constexpr NWidgetPart _nested_town_editor_view_widgets[] = {
660 NWidget(
WWT_PANEL, COLOUR_BROWN,
WID_TV_INFO),
SetMinimalSize(260, 32),
SetResize(1, 0),
SetFill(1, 0),
EndContainer(),
662 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),
663 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),
664 NWidget(
WWT_TEXTBTN, COLOUR_BROWN,
WID_TV_CATCHMENT),
SetMinimalSize(40, 12),
SetFill(1, 1),
SetResize(1, 0),
SetStringTip(STR_BUTTON_CATCHMENT, STR_TOOLTIP_CATCHMENT),
670 WDP_AUTO,
"view_town_scen", 260, TownViewWindow::WID_TV_HEIGHT_NORMAL,
673 _nested_town_editor_view_widgets
676void ShowTownViewWindow(
TownID town)
678 if (_game_mode == GM_EDITOR) {
679 AllocateWindowDescFront<TownViewWindow>(_town_editor_view_desc, town);
681 AllocateWindowDescFront<TownViewWindow>(_town_game_view_desc, town);
685static constexpr NWidgetPart _nested_town_directory_widgets[] = {
703 NWidget(
WWT_TEXT, INVALID_COLOUR,
WID_TD_WORLD_POPULATION),
SetPadding(2, 0, 2, 2),
SetFill(1, 0),
SetResize(1, 0),
725 static inline const StringID sorter_names[] = {
730 static const std::initializer_list<GUITownList::SortFunction * const>
sorter_funcs;
739 void BuildSortTownList()
747 this->towns.push_back(t);
756 this->vscroll->
SetCount(this->towns.size());
810 this->BuildSortTownList();
854 if (this->towns.empty()) {
862 int icon_x =
tr.WithWidth(icon_size.width,
rtl).left;
866 for (
auto it = first; it !=
last; ++it) {
872 DrawSprite(SPR_TOWN_RATING_NA, PAL_NONE,
icon_x,
tr.top + (
this->resize.step_height - icon_size.height) / 2);
874 SpriteID icon = SPR_TOWN_RATING_APALLING;
895 d.height += padding.height;
901 d.width += padding.width;
902 d.height += padding.height;
909 for (uint i = 0; i < this->towns.size(); i++) {
910 const Town *t = this->towns[i];
917 d.width += icon_size.width + 2;
918 d.height = std::max(
d.height, icon_size.height);
921 d.width += padding.width;
922 d.height += padding.height;
928 d.width += padding.width;
929 d.height += padding.height;
942 this->last_sorting = this->towns.
GetListing();
945 this->last_sorting.
order = !this->last_sorting.
order;
959 if (it == this->towns.end())
return;
977 if (this->towns.
SortType() != index) {
979 this->last_sorting = this->towns.
GetListing();
980 this->BuildSortTownList();
986 if (this->towns.
NeedRebuild()) this->BuildSortTownList();
992 this->BuildSortTownList();
1017 case TDIWD_FORCE_REBUILD:
1022 case TDIWD_POPULATION_CHANGE:
1044 static inline HotkeyList hotkeys {
"towndirectory", {
1049Listing TownDirectoryWindow::last_sorting = {
false, 0};
1054 &TownPopulationSorter,
1062 _nested_town_directory_widgets,
1063 &TownDirectoryWindow::hotkeys
1066void ShowTownDirectory()
1074 if (result.
Failed())
return;
1085static constexpr NWidgetPart _nested_found_town_widgets[] = {
1167 this->RandomTownName();
1168 this->UpdateButtons(
true);
1173 if (_game_mode == GM_EDITOR)
return;
1184 void RandomTownName()
1188 if (!this->townnamevalid) {
1189 this->townname_editbox.text.
DeleteAll();
1191 this->townname_editbox.text.
Assign(GetTownName(&this->params, this->townnameparts));
1218 template <
typename Tcallback>
1223 if (!this->townnamevalid) {
1224 name = this->townname_editbox.text.
GetText();
1227 std::string
original_name = GetTownName(&this->params, this->townnameparts);
1250 this->RandomTownName();
1261 old_generating_world.
Restore();
1277 this->UpdateButtons(
false);
1294 this->UpdateButtons(
false);
1307 this->UpdateButtons(
false);
1318 this->UpdateButtons(
true);
1326 _nested_found_town_widgets
1329void ShowFoundTownWindow()
1332 AllocateWindowDescFront<FoundTownWindow>(_found_town_desc, 0);
1335void InitializeTownGui()
1337 _town_local_authority_kdtree.
Clear();
1352 if (group ==
nullptr || group->type != SGT_TILELAYOUT)
return;
1362 palette =
HasBit(callback, 14) ?
GB(callback, 0, 8) + SPR_2CCMAP_BASE : callback;
1388 auto draw = [](
int x,
int y,
HouseID house_id,
int view) {
1407 if (dcts.building.
sprite != 0) {
1420 draw(x, y - y_delta - y_delta, house_id, view);
1421 draw(x + x_delta, y - y_delta, house_id + 1, view);
1422 draw(x - x_delta, y - y_delta, house_id + 2, view);
1423 draw(x, y, house_id + 3, view);
1425 draw(x + x_delta / 2, y - y_delta, house_id, view);
1426 draw(x - x_delta / 2, y, house_id + 1, view);
1428 draw(x - x_delta / 2, y - y_delta, house_id, view);
1429 draw(x + x_delta / 2, y, house_id + 1, view);
1431 draw(x, y, house_id, view);
1444 if (callback_res > 0x400) {
1448 if (new_name != STR_NULL && new_name != STR_UNDEFINED) {
1467 case LandscapeType::Temperate: this->climate_mask =
HZ_TEMP;
break;
1469 case LandscapeType::Tropic: this->climate_mask =
HZ_SUBTROPIC;
break;
1470 case LandscapeType::Toyland: this->climate_mask =
HZ_TOYLND;
break;
1471 default: NOT_REACHED();
1480 for (
int cls_id = 0; cls_id < num_classes; ++cls_id) {
1482 for (
int id = 0;
id < num_types; ++id) {
1500 static inline const std::array<StringID, HZB_END> zone_names = {
1501 STR_HOUSE_PICKER_CLASS_ZONE1,
1502 STR_HOUSE_PICKER_CLASS_ZONE2,
1503 STR_HOUSE_PICKER_CLASS_ZONE3,
1504 STR_HOUSE_PICKER_CLASS_ZONE4,
1505 STR_HOUSE_PICKER_CLASS_ZONE5,
1508 GrfSpecFeature GetFeature()
const override {
return GSF_HOUSES; }
1515 int GetClassCount()
const override {
return static_cast<int>(zone_names.size()); }
1526 return zone_names[id];
1538 if (!spec->grf_prop.HasGrfFile())
return {0, spec->Index(), cls_id,
id};
1539 return {spec->grf_prop.grfid, spec->grf_prop.local_id, cls_id,
id};
1552 for (
int i = 0; i < cls_id; i++) {
1563 if (spec ==
nullptr)
return {};
1564 if (!spec->enabled)
return {};
1565 if ((spec->building_availability & climate_mask) == 0)
return {};
1566 if (!
HasBit(spec->building_availability, cls_id))
return {};
1567 for (
int i = 0; i < cls_id; i++) {
1569 if (
HasBit(spec->building_availability, i))
return {};
1572 return spec->badges;
1581 void DrawType(
int x,
int y,
int,
int id)
const override
1589 for (
auto it = id_count.begin(); it != id_count.end(); ++it) {
1590 if (*it == 0)
continue;
1591 HouseID house =
static_cast<HouseID>(std::distance(id_count.begin(), it));
1594 items.insert({0, house, class_index, house});
1600 if (src.empty())
return src;
1603 std::set<PickerItem> dst;
1604 for (
const auto &item : src) {
1605 if (item.grfid == 0) {
1610 if (it == specs.end()) {
1612 dst.insert({item.grfid, item.local_id, -1, -1});
1615 dst.insert( {item.grfid, item.local_id, class_index, it->Index()});
1634 CargoTypes produced{};
1636 for (uint i = 0; i < 256; i++) {
1644 uint amt =
GB(callback, 0, 8);
1645 if (amt == 0)
continue;
1658 std::string house_info{};
1659 bool house_protected =
false;
1664 this->ConstructWindow();
1667 void UpdateSelectSize(
const HouseSpec *spec)
1669 if (spec ==
nullptr) {
1713 std::stringstream line;
1738 if (produced != 0) {
1791 UpdateSelectSize(spec);
1797 if (
hasflag) this->house_protected =
true;
1819 static inline HotkeyList hotkeys{
"buildhouse", {
1857 &BuildHouseWindow::hotkeys
1860void 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.
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.
bool IsValidCargoType(CargoType t)
Test whether cargo type is not INVALID_CARGO.
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.
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
constexpr Tstorage base() const noexcept
Retrieve the raw value behind this bit set.
constexpr Timpl & Set()
Set all bits.
Common return value for all commands.
bool Succeeded() const
Did this command succeed?
bool Failed() const
Did this command fail?
std::string GetDecodedString() const
Decode the encoded string.
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.
std::span< const BadgeID > GetTypeBadges(int cls_id, int id) const override
Get the item of a type.
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.
@ Position
Update scroll positions.
@ PCWHK_FOCUS_FILTER_BOX
Focus the edit box for editing the filter string.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
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.
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.
@ Execute
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.
constexpr std::underlying_type_t< enum_type > to_underlying(enum_type e)
Implementation of std::to_underlying (from C++23)
Functions related to errors.
@ WL_INFO
Used for DoCommand-like (and some non-fatal AI GUI) errors/information.
void ShowErrorMessage(EncodedString &&summary_msg, int x, int y, const 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
@ BuildingIsProtected
towns and AI will not remove this house, while human players will be able to
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(std::string_view 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.
@ CBID_HOUSE_PRODUCE_CARGO
Called to determine how much cargo a town building produces.
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
@ ProduceCargo
custom cargo production
@ Colour
decide the colour of the building
static const uint CALLBACK_HOUSEPRODCARGO_END
Sentinel indicating that the loop for CBID_HOUSE_PRODUCE_CARGO has ended.
CargoType GetCargoTranslation(uint8_t cargo, const GRFFile *grffile, bool usebit)
Translate a GRF-local cargo slot/bitnum into a CargoType.
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_15_BEEP
19 == 0x13 GUI button click
@ 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.
EncodedString GetEncodedString(StringID str)
Encode a string with no parameters into an encoded string.
std::string GetString(StringID string)
Resolve the given StringID into a std::string with formatting but no parameters.
TextDirection _current_text_dir
Text direction of the currently selected language.
uint64_t GetParamMaxDigits(uint count, FontSize size)
Get 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.
void Restore()
Restore the variable.
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.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
void OnInit() override
Notification that the nested widget tree gets initialized.
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
const struct SpriteGroup * GetSpriteGroup(size_t index=0) const
Get the SpriteGroup at the specified index.
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?
const struct GRFFile * grffile
grf file that introduced this entity
uint16_t local_id
id defined by the grf file for this entity
uint32_t grfid
grfid that introduced this 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.)
HouseExtraFlags extra_flags
some more flags
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.
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
static Titem * Get(auto index)
Returns Titem with given index.
static size_t GetNumItems()
Returns number of valid items in the pool.
Tindex index
Index of this pool item.
static bool IsValidID(auto index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
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.
constexpr uint Horizontal() const
Get total horizontal padding of RectPadding.
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 click_beep
Beep on a random selection of buttons.
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(std::string_view 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(const std::string_view text)
Copy 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 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.
TownAction sel_action
Currently selected town action, TownAction::End 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.
Dimension exclusive_size
Dimensions of exclusive icon.
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
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.
TownActions displayed_actions_on_previous_painting
Actions that were available on the previous call to OnPaint()
uint32_t population
Current population of people.
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 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 std::string GetTownString(const Town *t, uint64_t population)
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.
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
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.
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
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.
EncodedString text
General text with additional information.
bool larger_town
if this is a larger town and should grow more quickly
ReferenceThroughBaseContainer< std::array< int16_t, MAX_COMPANIES > > ratings
ratings of each company for this town
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
uint8_t flags
See TownFlags.
TownCache cache
Container for all cacheable data.
CompanyID exclusivity
which company has exclusivity
std::array< TransportedCargoStat< uint32_t >, NUM_CARGO > supplied
Cargo statistics about supplied cargo.
bool show_zone
NOSAVE: mark town to show the local authority zone in the viewports.
CompanyMask have_ratings
which companies have a rating
uint16_t growth_rate
town growth rate
std::array< TransportedCargoStat< uint16_t >, NUM_TAE > received
Cargo statistics about received cargotypes.
std::array< uint32_t, NUM_TAE > goal
Amount of cargo required for the town to grow.
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.
virtual std::string GetWidgetString(WidgetID widget, StringID stringid) const
Get the raw string for a widget.
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.
@ EnableDefault
enable the 'Default' button ("\0" is returned)
@ LengthIsInChars
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.
CargoArray GetAcceptedCargoOfHouse(const HouseSpec *hs)
Get accepted cargo of a house prototype.
uint8_t GetTownActionCost(TownAction action)
Get cost factors for a TownAction.
TownAction
Town actions of a company.
@ RoadRebuild
Rebuild the roads.
@ Bribe
Try to bribe the council.
@ BuyRights
Buy exclusive transport rights.
@ FundBuildings
Fund new buildings.
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.
static CargoTypes GetProducedCargoOfHouse(const HouseSpec *hs)
Get the cargo types produced by a 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.