49 #include "table/strings.h"
57 static constexpr
NWidgetPart _nested_town_authority_widgets[] = {
67 NWidget(
WWT_PANEL, COLOUR_BROWN,
WID_TA_COMMAND_LIST),
SetMinimalSize(317, 52),
SetResize(1, 0),
SetDataTip(0x0, STR_LOCAL_AUTHORITY_ACTIONS_TOOLTIP),
EndContainer(),
70 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),
131 this->action_tooltips[0] = STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_SMALL_ADVERTISING;
132 this->action_tooltips[1] = STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_MEDIUM_ADVERTISING;
133 this->action_tooltips[2] = STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_LARGE_ADVERTISING;
134 this->action_tooltips[3] = realtime ? STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_ROAD_RECONSTRUCTION_MINUTES : STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_ROAD_RECONSTRUCTION_MONTHS;
135 this->action_tooltips[4] = STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_STATUE_OF_COMPANY;
136 this->action_tooltips[5] = STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_NEW_BUILDINGS;
137 this->action_tooltips[6] = realtime ? STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_EXCLUSIVE_TRANSPORT_MINUTES : STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_EXCLUSIVE_TRANSPORT_MONTHS;
138 this->action_tooltips[7] = STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_BRIBE;
146 this->exclusive_size =
GetSpriteSize(SPR_EXCLUSIVE_TRANSPORT);
173 int exclusive_y_offset = (this->
resize.
step_height - this->exclusive_size.height) / 2;
175 DrawString(r.left, r.right, r.top + text_y_offset, STR_LOCAL_AUTHORITY_COMPANY_RATINGS);
185 if ((
HasBit(this->town->
have_ratings, c->index) || this->town->exclusivity == c->index)) {
191 int rating = this->town->
ratings[c->index];
192 StringID str = STR_CARGO_RATING_APPALLING;
193 if (rating > RATING_APPALLING) str++;
194 if (rating > RATING_VERYPOOR) str++;
195 if (rating > RATING_POOR) str++;
196 if (rating > RATING_MEDIOCRE) str++;
197 if (rating > RATING_GOOD) str++;
198 if (rating > RATING_VERYGOOD) str++;
199 if (rating > RATING_EXCELLENT) str++;
203 DrawSprite(SPR_EXCLUSIVE_TRANSPORT, COMPANY_SPRITE_COLOUR(c->index), exclusive.left, text.top + exclusive_y_offset);
206 DrawString(text.left, text.right, text.top + text_y_offset, STR_LOCAL_AUTHORITY_COMPANY_RATING);
211 text.bottom = text.top - 1;
212 if (text.bottom > r.bottom) {
223 DrawString(r, STR_LOCAL_AUTHORITY_ACTIONS_TITLE);
229 if (!
HasBit(this->enabled_actions, i))
continue;
233 if (
HasBit(this->available_actions, i)) action_colour = TC_ORANGE;
234 if (this->sel_index == i) action_colour = TC_WHITE;
236 DrawString(r, STR_LOCAL_AUTHORITY_ACTION_SMALL_ADVERTISING_CAMPAIGN + i, action_colour);
241 void SetStringParameters(
WidgetID widget)
const override
246 void DrawWidget(
const Rect &r,
WidgetID widget)
const override
250 if (this->sel_index != -1) {
256 this->action_tooltips[this->sel_index],
257 affordable ? TC_YELLOW : TC_RED);
267 assert(size.width > padding.width && size.height > padding.height);
273 d.width += padding.width;
274 d.height += padding.height;
283 size.width = std::max(size.width,
GetStringBoundingBox(STR_LOCAL_AUTHORITY_ACTION_SMALL_ADVERTISING_CAMPAIGN + i).
width + padding.width);
285 size.width += padding.width;
290 size.height = 9 *
resize.height + padding.height;
295 void OnClick([[maybe_unused]]
Point pt,
WidgetID widget, [[maybe_unused]]
int click_count)
override
299 bool new_show_state = !this->town->
show_zone;
300 TownID index = this->town->
index;
302 new_show_state ? _town_local_authority_kdtree.
Insert(index) : _town_local_authority_kdtree.
Remove(index);
320 if (click_count == 1 || y < 0 || !
HasBit(this->available_actions, y))
break;
335 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
337 if (!gui_scope)
return;
340 if (!
HasBit(this->enabled_actions, this->sel_index)) {
341 this->sel_index = -1;
347 WDP_AUTO,
"view_town_authority", 317, 222,
350 _nested_town_authority_widgets
353 static void ShowTownAuthorityWindow(uint town)
355 AllocateWindowDescFront<TownAuthorityWindow>(_town_authority_desc, town);
365 static const int WID_TV_HEIGHT_NORMAL = 150;
384 void Close([[maybe_unused]]
int data = 0)
override
390 void SetStringParameters(
WidgetID widget)
const override
403 void DrawWidget(
const Rect &r,
WidgetID widget)
const override
411 DrawString(tr, STR_TOWN_VIEW_POPULATION_HOUSES);
428 for (
int i = TAE_BEGIN; i <
TAE_END; i++) {
429 if (this->town->
goal[i] == 0)
continue;
434 DrawString(tr, STR_TOWN_VIEW_CARGO_FOR_TOWNGROWTH);
442 assert(cargo !=
nullptr);
448 string = STR_TOWN_VIEW_CARGO_FOR_TOWNGROWTH_DELIVERED_GENERAL;
450 string = STR_TOWN_VIEW_CARGO_FOR_TOWNGROWTH_REQUIRED_GENERAL;
453 string = STR_TOWN_VIEW_CARGO_FOR_TOWNGROWTH_REQUIRED_WINTER;
459 string = STR_TOWN_VIEW_CARGO_FOR_TOWNGROWTH_DELIVERED;
461 string = STR_TOWN_VIEW_CARGO_FOR_TOWNGROWTH_REQUIRED;
478 DrawString(tr, STR_TOWN_VIEW_TOWN_GROW_STOPPED);
490 if (!this->town->
text.empty()) {
496 void OnClick([[maybe_unused]]
Point pt,
WidgetID widget, [[maybe_unused]]
int click_count)
override
549 for (
int i = TAE_BEGIN; i <
TAE_END; i++) {
550 if (this->town->
goal[i] == 0)
continue;
564 if (!this->town->
text.empty()) {
572 void ResizeWindowAsNeeded()
591 void OnMouseWheel(
int wheel)
override
603 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
605 if (!gui_scope)
return;
608 this->ResizeWindowAsNeeded();
611 void OnQueryTextFinished(std::optional<std::string> str)
override
613 if (!str.has_value())
return;
624 static constexpr
NWidgetPart _nested_town_game_view_widgets[] = {
639 NWidget(
WWT_PANEL, COLOUR_BROWN,
WID_TV_INFO),
SetMinimalSize(260, 32),
SetResize(1, 0),
SetFill(1, 0),
EndContainer(),
641 NWidget(
WWT_PUSHTXTBTN, COLOUR_BROWN,
WID_TV_SHOW_AUTHORITY),
SetMinimalSize(80, 12),
SetFill(1, 1),
SetResize(1, 0),
SetDataTip(STR_TOWN_VIEW_LOCAL_AUTHORITY_BUTTON, STR_TOWN_VIEW_LOCAL_AUTHORITY_TOOLTIP),
642 NWidget(
WWT_TEXTBTN, COLOUR_BROWN,
WID_TV_CATCHMENT),
SetMinimalSize(40, 12),
SetFill(1, 1),
SetResize(1, 0),
SetDataTip(STR_BUTTON_CATCHMENT, STR_TOOLTIP_CATCHMENT),
648 WDP_AUTO,
"view_town", 260, TownViewWindow::WID_TV_HEIGHT_NORMAL,
651 _nested_town_game_view_widgets
654 static constexpr
NWidgetPart _nested_town_editor_view_widgets[] = {
669 NWidget(
WWT_PANEL, COLOUR_BROWN,
WID_TV_INFO),
SetMinimalSize(260, 32),
SetResize(1, 0),
SetFill(1, 0),
EndContainer(),
671 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),
672 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),
673 NWidget(
WWT_TEXTBTN, COLOUR_BROWN,
WID_TV_CATCHMENT),
SetMinimalSize(40, 12),
SetFill(1, 1),
SetResize(1, 0),
SetDataTip(STR_BUTTON_CATCHMENT, STR_TOOLTIP_CATCHMENT),
679 WDP_AUTO,
"view_town_scen", 260, TownViewWindow::WID_TV_HEIGHT_NORMAL,
682 _nested_town_editor_view_widgets
685 void ShowTownViewWindow(TownID town)
687 if (_game_mode == GM_EDITOR) {
688 AllocateWindowDescFront<TownViewWindow>(_town_editor_view_desc, town);
690 AllocateWindowDescFront<TownViewWindow>(_town_game_view_desc, town);
694 static constexpr
NWidgetPart _nested_town_directory_widgets[] = {
712 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),
734 static inline const StringID sorter_names[] = {
736 STR_SORT_BY_POPULATION,
739 static const std::initializer_list<GUITownList::SortFunction * const>
sorter_funcs;
748 void BuildSortTownList()
755 if (this->string_filter.
IsEmpty()) {
756 this->towns.push_back(t);
760 this->string_filter.
AddLine(t->GetCachedName());
761 if (this->string_filter.
GetState()) this->towns.push_back(t);
765 this->vscroll->
SetCount(this->towns.size());
784 return a_population < b_population;
790 bool before = !order;
798 return a_rating < b_rating;
819 this->BuildSortTownList();
827 void SetStringParameters(
WidgetID widget)
const override
852 return t->
larger_town ? STR_TOWN_DIRECTORY_CITY : STR_TOWN_DIRECTORY_TOWN;
855 void DrawWidget(
const Rect &r,
WidgetID widget)
const override
864 if (this->towns.empty()) {
872 int icon_x = tr.
WithWidth(icon_size.width, rtl).left;
876 for (
auto it = first; it != last; ++it) {
882 DrawSprite(SPR_TOWN_RATING_NA, PAL_NONE, icon_x, tr.top + (this->resize.step_height - icon_size.height) / 2);
884 SpriteID icon = SPR_TOWN_RATING_APALLING;
887 DrawSprite(icon, PAL_NONE, icon_x, tr.top + (this->resize.step_height - icon_size.height) / 2);
894 tr.top += this->resize.step_height;
907 d.height += padding.height;
913 d.width += padding.width;
914 d.height += padding.height;
920 for (uint i = 0; i < this->towns.size(); i++) {
921 const Town *t = this->towns[i];
923 assert(t !=
nullptr);
930 d.width += icon_size.width + 2;
931 d.height = std::max(d.height, icon_size.height);
934 d.width += padding.width;
935 d.height += padding.height;
942 d.width += padding.width;
943 d.height += padding.height;
950 void OnClick([[maybe_unused]]
Point pt,
WidgetID widget, [[maybe_unused]]
int click_count)
override
956 this->last_sorting = this->towns.
GetListing();
959 this->last_sorting.
order = !this->last_sorting.
order;
973 if (it == this->towns.end())
return;
976 assert(t !=
nullptr);
987 void OnDropdownSelect(
WidgetID widget,
int index)
override
991 if (this->towns.
SortType() != index) {
993 this->last_sorting = this->towns.
GetListing();
994 this->BuildSortTownList();
1000 if (this->towns.
NeedRebuild()) this->BuildSortTownList();
1006 this->BuildSortTownList();
1015 void OnEditboxChanged(
WidgetID wid)
override
1028 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
1031 case TDIWD_FORCE_REBUILD:
1036 case TDIWD_POPULATION_CHANGE:
1058 static inline HotkeyList hotkeys {
"towndirectory", {
1063 Listing TownDirectoryWindow::last_sorting = {
false, 0};
1068 &TownPopulationSorter,
1076 _nested_town_directory_widgets,
1077 &TownDirectoryWindow::hotkeys
1080 void ShowTownDirectory()
1088 if (result.
Failed())
return;
1099 static constexpr
NWidgetPart _nested_found_town_widgets[] = {
1172 this->RandomTownName();
1173 this->UpdateButtons(
true);
1176 void RandomTownName()
1180 if (!this->townnamevalid) {
1181 this->townname_editbox.text.
DeleteAll();
1183 this->townname_editbox.text.
Assign(
GetTownName(&this->params, this->townnameparts));
1190 void UpdateButtons(
bool check_availability)
1192 if (check_availability && _game_mode != GM_EDITOR) {
1212 template <
typename Tcallback>
1213 void ExecuteFoundTownCommand(
TileIndex tile,
bool random,
StringID errstr, Tcallback cc)
1217 if (!this->townnamevalid) {
1218 name = this->townname_editbox.text.
buf;
1221 std::string original_name =
GetTownName(&this->params, this->townnameparts);
1222 if (original_name != this->townname_editbox.text.
buf) name = this->townname_editbox.text.
buf;
1226 tile, this->town_size, this->city, this->town_layout, random,
townnameparts, name);
1232 void OnClick([[maybe_unused]]
Point pt,
WidgetID widget, [[maybe_unused]]
int click_count)
override
1240 this->ExecuteFoundTownCommand(0,
true, STR_ERROR_CAN_T_GENERATE_TOWN, CcFoundRandomTown);
1244 this->RandomTownName();
1255 old_generating_world.Restore();
1271 this->UpdateButtons(
false);
1288 this->UpdateButtons(
false);
1293 void OnPlaceObject([[maybe_unused]]
Point pt,
TileIndex tile)
override
1295 this->ExecuteFoundTownCommand(tile,
false, STR_ERROR_CAN_T_FOUND_TOWN_HERE, CcFoundTown);
1301 this->UpdateButtons(
false);
1309 void OnInvalidateData([[maybe_unused]]
int data = 0, [[maybe_unused]]
bool gui_scope =
true)
override
1311 if (!gui_scope)
return;
1312 this->UpdateButtons(
true);
1320 _nested_found_town_widgets
1323 void ShowFoundTownWindow()
1326 AllocateWindowDescFront<FoundTownWindow>(_found_town_desc, 0);
1329 void InitializeTownGui()
1331 _town_local_authority_kdtree.
Clear();
1346 if (group ==
nullptr || group->type != SGT_TILELAYOUT)
return;
1356 palette =
HasBit(callback, 14) ?
GB(callback, 0, 8) + SPR_2CCMAP_BASE : callback;
1382 auto draw = [](
int x,
int y,
HouseID house_id,
int view) {
1401 if (dcts.building.
sprite != 0) {
1414 draw(x, y - y_delta - y_delta, house_id, view);
1415 draw(x + x_delta, y - y_delta, house_id + 1, view);
1416 draw(x - x_delta, y - y_delta, house_id + 2, view);
1417 draw(x, y, house_id + 3, view);
1419 draw(x + x_delta / 2, y - y_delta, house_id, view);
1420 draw(x - x_delta / 2, y, house_id + 1, view);
1422 draw(x - x_delta / 2, y - y_delta, house_id, view);
1423 draw(x + x_delta / 2, y, house_id + 1, view);
1425 draw(x, y, house_id, view);
1440 case LT_TEMPERATE: this->climate_mask =
HZ_TEMP;
break;
1442 case LT_TROPIC: this->climate_mask =
HZ_SUBTROPIC;
break;
1443 case LT_TOYLAND: this->climate_mask =
HZ_TOYLND;
break;
1444 default: NOT_REACHED();
1453 for (
int cls_id = 0; cls_id < num_classes; ++cls_id) {
1455 for (
int id = 0;
id < num_types; ++id) {
1473 static inline const std::array<StringID, HZB_END> zone_names = {
1474 STR_HOUSE_PICKER_CLASS_ZONE1,
1475 STR_HOUSE_PICKER_CLASS_ZONE2,
1476 STR_HOUSE_PICKER_CLASS_ZONE3,
1477 STR_HOUSE_PICKER_CLASS_ZONE4,
1478 STR_HOUSE_PICKER_CLASS_ZONE5,
1486 int GetClassCount()
const override {
return static_cast<int>(zone_names.size()); }
1497 return zone_names[id];
1509 if (spec->grf_prop.grffile ==
nullptr)
return {0, spec->Index(), cls_id,
id};
1510 return {spec->grf_prop.grffile->grfid, spec->grf_prop.local_id, cls_id,
id};
1523 for (
int i = 0; i < cls_id; i++) {
1537 void DrawType(
int x,
int y,
int,
int id)
const override
1545 for (
auto it = id_count.begin(); it != id_count.end(); ++it) {
1546 if (*it == 0)
continue;
1547 HouseID house =
static_cast<HouseID>(std::distance(id_count.begin(), it));
1550 items.insert({0, house, class_index, house});
1556 if (src.empty())
return src;
1559 std::set<PickerItem> dst;
1560 for (
const auto &item : src) {
1561 if (item.grfid == 0) {
1565 auto it = std::find_if(specs.begin(), specs.end(), [&item](
const HouseSpec &spec) { return spec.grf_prop.grffile != nullptr && spec.grf_prop.grffile->grfid == item.grfid && spec.grf_prop.local_id == item.local_id; });
1566 if (it == specs.end()) {
1568 dst.insert({item.grfid, item.local_id, -1, -1});
1571 dst.insert( {item.grfid, item.local_id, class_index, it->Index()});
1587 this->ConstructWindow();
1591 void UpdateSelectSize(
const HouseSpec *spec)
1593 if (spec ==
nullptr) {
1610 void OnInvalidateData(
int data = 0,
bool gui_scope =
true)
override
1612 this->PickerWindow::OnInvalidateData(data, gui_scope);
1613 if (!gui_scope)
return;
1617 UpdateSelectSize(spec);
1621 void OnPlaceObject([[maybe_unused]]
Point pt,
TileIndex tile)
override
1634 static inline HotkeyList hotkeys{
"buildhouse", {
1659 &BuildHouseWindow::hotkeys
1662 void ShowBuildHousePicker(
Window *parent)
Class for backupping variables and making sure they are restored later.
constexpr debug_inline 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.
constexpr static debug_inline uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
uint8_t CargoID
Cargo slots to indicate a cargo type within a game.
@ 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?
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.
std::set< PickerItem > UpdateSavedItems(const std::set< PickerItem > &src) override
Update link between grfid/localidx and class_index/index in saved items.
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.
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'.
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.
@ PCWHK_FOCUS_FILTER_BOX
Focus the edit box for editing the filter string.
@ 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 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.
void ShowErrorMessage(StringID summary_msg, int x, int y, CommandCost cc)
Display an error message in a window.
@ WL_INFO
Used for DoCommand-like (and some non-fatal AI GUI) errors/information.
@ FT_TOWN_DATA
town data file
@ SLO_LOAD
File is being loaded.
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.
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
@ CBM_HOUSE_COLOUR
decide the colour of the building
std::span< const uint > GetBuildingHouseIDCounts()
Get read-only span of total HouseID building counts.
Functions related to NewGRF houses.
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 > MakePickerTypeWidgets()
Create nested widgets for the type picker widgets.
std::unique_ptr< NWidgetBase > MakePickerClassWidgets()
Create nested widgets for the class 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.
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.
@ TD_RTL
Text is written right-to-left by default.
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)
static const int MAX_CHAR_LENGTH
Max. length of UTF-8 encoded unicode character.
Class to backup a specific variable and restore it later.
Specification of a cargo type.
CargoID 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.
QueryString townname_editbox
Townname editbox.
TownSize town_size
Selected town size.
bool townnamevalid
Is generated town name valid?
TownNameParams params
Town name parameters.
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
void OnPlaceObjectAbort() override
The user cancelled a tile highlight mode that has been set.
bool city
Are we building a city?
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?
uint8_t 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...)
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
uint16_t callback_mask
Bitmask of house callbacks that have to be called.
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 Titem * Get(size_t index)
Returns Titem with given index.
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.
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([[maybe_unused]] 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.
char *const buf
buffer in which text is saved
Action 2 sprite layout for houses, industry tiles, objects and airport tiles.
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] 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.
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 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.
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.
QueryString townname_editbox
Filter editbox.
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.
EventState OnHotkey(int hotkey) override
A hotkey has been pressed.
void OnPaint() override
The window must be repainted.
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
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.
Struct holding parameters used to generate town name.
Town * town
Town displayed by the window.
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
uint GetDesiredInfoHeight(int width) const
Gets the desired height for the information panel.
void OnPaint() override
The window must be repainted.
void OnResize() override
Called after the window got resized.
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.
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 SetWidgetsDisabledState(bool disab_stat, Args... widgets)
Sets the enabled/disabled status of a list of widgets.
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.
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.
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.
@ TROPICZONE_DESERT
Tile is desert.
static const uint TILE_PIXELS
Pixel distance between tile columns/rows in #ZOOM_BASE.
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)
const CargoSpec * FindFirstCargoWithTownAcceptanceEffect(TownAcceptanceEffect effect)
Determines the first cargo with a certain town effect.
TownActions GetMaskOfTownActions(CompanyID cid, const Town *t)
Get a list of available town authority actions.
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.
bool GenerateTowns(TownLayout layout)
Generate a number of towns with a given layout.
Command definitions related to towns.
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.
TownDirectoryHotkeys
Enum referring to the Hotkeys in the town directory window.
@ TDHK_FOCUS_FILTER_BOX
Focus the filter box.
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.
static void GetTownName(StringBuilder &builder, const TownNameParams *par, uint32_t townnameparts)
Fills builder with specified 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).
Window * BringWindowToFrontById(WindowClass cls, WindowNumber number)
Find a window and make it the relative top-window on the screen.
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 functions not directly related to making/drawing windows.
@ SBS_DOWN
Sort ascending.
@ WF_DISABLE_VP_SCROLL
Window does not do autoscroll,.
@ WDF_CONSTRUCTION
This window is used for construction; close it whenever changing company.
@ WDP_AUTO
Find a place automatically.
int32_t WindowNumber
Number to differentiate different windows of the same class.
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.
int ScaleGUITrad(int value)
Scale traditional pixel dimensions to GUI zoom level.
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.