OpenTTD Source: src/town_gui.cpp Source File

OpenTTD Source 15.0-beta1

town_gui.cpp
Go to the documentation of this file.
1/*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
7
10#include "stdafx.h"
11#include "town.h"
12#include "viewport_func.h"
13#include "error.h"
14#include "gui.h"
15#include "house.h"
16#include "newgrf_cargo.h"
17#include "newgrf_house.h"
18#include "newgrf_text.h"
19#include "picker_gui.h"
20#include "command_func.h"
21#include "company_func.h"
22#include "company_base.h"
23#include "company_gui.h"
24#include "network/network.h"
25#include "string_func.h"
26#include "strings_func.h"
27#include "sound_func.h"
28#include "tilehighlight_func.h"
29#include "sortlist_type.h"
30#include "road_cmd.h"
31#include "landscape.h"
32#include "querystring_gui.h"
33#include "window_func.h"
34#include "townname_func.h"
35#include "core/backup_type.hpp"
36#include "core/geometry_func.hpp"
37#include "genworld.h"
38#include "fios.h"
39#include "stringfilter_type.h"
40#include "dropdown_func.h"
41#include "town_kdtree.h"
42#include "town_cmd.h"
43#include "timer/timer.h"
44#include "timer/timer_game_calendar.h"
45#include "timer/timer_window.h"
46#include "zoom_func.h"
47#include "hotkeys.h"
48
49#include "widgets/town_widget.h"
50
51#include "table/strings.h"
52
53#include <sstream>
54
55#include "safeguards.h"
56
57 TownKdtree _town_local_authority_kdtree{};
58
59typedef GUIList<const Town*, const bool &> GUITownList;
60
61static constexpr NWidgetPart _nested_town_authority_widgets[] = {
62 NWidget(NWID_HORIZONTAL),
63 NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
64 NWidget(WWT_CAPTION, COLOUR_BROWN, WID_TA_CAPTION), SetDataTip(STR_LOCAL_AUTHORITY_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
65 NWidget(WWT_TEXTBTN, COLOUR_BROWN, WID_TA_ZONE_BUTTON), SetMinimalSize(50, 0), SetDataTip(STR_LOCAL_AUTHORITY_ZONE, STR_LOCAL_AUTHORITY_ZONE_TOOLTIP),
66 NWidget(WWT_SHADEBOX, COLOUR_BROWN),
67 NWidget(WWT_DEFSIZEBOX, COLOUR_BROWN),
68 NWidget(WWT_STICKYBOX, COLOUR_BROWN),
69 EndContainer(),
70 NWidget(WWT_PANEL, COLOUR_BROWN, WID_TA_RATING_INFO), SetMinimalSize(317, 92), SetResize(1, 1), EndContainer(),
71 NWidget(WWT_PANEL, COLOUR_BROWN, WID_TA_COMMAND_LIST), SetMinimalSize(317, 52), SetResize(1, 0), SetDataTip(0x0, STR_LOCAL_AUTHORITY_ACTIONS_TOOLTIP), EndContainer(),
72 NWidget(WWT_PANEL, COLOUR_BROWN, WID_TA_ACTION_INFO), SetMinimalSize(317, 52), SetResize(1, 0), EndContainer(),
73 NWidget(NWID_HORIZONTAL),
74 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),
75 NWidget(WWT_RESIZEBOX, COLOUR_BROWN),
76 EndContainer()
77};
78
80 struct TownAuthorityWindow : Window {
81private:
82 Town *town;
83 int sel_index;
84 uint displayed_actions_on_previous_painting;
85 TownActions enabled_actions;
86 TownActions available_actions;
87 StringID action_tooltips[TACT_COUNT];
88
89 Dimension icon_size;
90 Dimension exclusive_size;
91
100 int GetNthSetBit(int n)
101 {
102 if (n >= 0) {
103 for (uint i : SetBitIterator(this->enabled_actions)) {
104 n--;
105 if (n < 0) return i;
106 }
107 }
108 return -1;
109 }
110
116 static TownActions GetEnabledActions()
117 {
118 TownActions enabled = TACT_ALL;
119
120 if (!_settings_game.economy.fund_roads) CLRBITS(enabled, TACT_ROAD_REBUILD);
121 if (!_settings_game.economy.fund_buildings) CLRBITS(enabled, TACT_FUND_BUILDINGS);
122 if (!_settings_game.economy.exclusive_rights) CLRBITS(enabled, TACT_BUY_RIGHTS);
123 if (!_settings_game.economy.bribe) CLRBITS(enabled, TACT_BRIBE);
124
125 return enabled;
126 }
127
128public:
129 TownAuthorityWindow(WindowDesc &desc, WindowNumber window_number) : Window(desc), sel_index(-1), displayed_actions_on_previous_painting(0), available_actions(TACT_NONE)
130 {
131 this->town = Town::Get(window_number);
132 this->enabled_actions = GetEnabledActions();
133
134 auto realtime = TimerGameEconomy::UsingWallclockUnits();
135 this->action_tooltips[0] = STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_SMALL_ADVERTISING;
136 this->action_tooltips[1] = STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_MEDIUM_ADVERTISING;
137 this->action_tooltips[2] = STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_LARGE_ADVERTISING;
138 this->action_tooltips[3] = realtime ? STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_ROAD_RECONSTRUCTION_MINUTES : STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_ROAD_RECONSTRUCTION_MONTHS;
139 this->action_tooltips[4] = STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_STATUE_OF_COMPANY;
140 this->action_tooltips[5] = STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_NEW_BUILDINGS;
141 this->action_tooltips[6] = realtime ? STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_EXCLUSIVE_TRANSPORT_MINUTES : STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_EXCLUSIVE_TRANSPORT_MONTHS;
142 this->action_tooltips[7] = STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_BRIBE;
143
144 this->InitNested(window_number);
145 }
146
147 void OnInit() override
148 {
149 this->icon_size = GetSpriteSize(SPR_COMPANY_ICON);
150 this->exclusive_size = GetSpriteSize(SPR_EXCLUSIVE_TRANSPORT);
151 }
152
153 void OnPaint() override
154 {
155 this->available_actions = GetMaskOfTownActions(_local_company, this->town);
156 if (this->available_actions != displayed_actions_on_previous_painting) this->SetDirty();
157 displayed_actions_on_previous_painting = this->available_actions;
158
159 this->SetWidgetLoweredState(WID_TA_ZONE_BUTTON, this->town->show_zone);
160 this->SetWidgetDisabledState(WID_TA_EXECUTE, (this->sel_index == -1) || !HasBit(this->available_actions, this->sel_index));
161
162 this->DrawWidgets();
163 if (!this->IsShaded())
164 {
165 this->DrawRatings();
166 this->DrawActions();
167 }
168 }
169
171 void DrawRatings()
172 {
173 Rect r = this->GetWidget<NWidgetBase>(WID_TA_RATING_INFO)->GetCurrentRect().Shrink(WidgetDimensions::scaled.framerect);
174
175 int text_y_offset = (this->resize.step_height - GetCharacterHeight(FS_NORMAL)) / 2;
176 int icon_y_offset = (this->resize.step_height - this->icon_size.height) / 2;
177 int exclusive_y_offset = (this->resize.step_height - this->exclusive_size.height) / 2;
178
179 DrawString(r.left, r.right, r.top + text_y_offset, STR_LOCAL_AUTHORITY_COMPANY_RATINGS);
180 r.top += this->resize.step_height;
181
182 bool rtl = _current_text_dir == TD_RTL;
183 Rect icon = r.WithWidth(this->icon_size.width, rtl);
184 Rect exclusive = r.Indent(this->icon_size.width + WidgetDimensions::scaled.hsep_normal, rtl).WithWidth(this->exclusive_size.width, rtl);
185 Rect text = r.Indent(this->icon_size.width + WidgetDimensions::scaled.hsep_normal + this->exclusive_size.width + WidgetDimensions::scaled.hsep_normal, rtl);
186
187 /* Draw list of companies */
188 for (const Company *c : Company::Iterate()) {
189 if ((HasBit(this->town->have_ratings, c->index) || this->town->exclusivity == c->index)) {
190 DrawCompanyIcon(c->index, icon.left, text.top + icon_y_offset);
191
192 SetDParam(0, c->index);
193 SetDParam(1, c->index);
194
195 int rating = this->town->ratings[c->index];
196 StringID str = STR_CARGO_RATING_APPALLING;
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++;
204
205 SetDParam(2, str);
206 if (this->town->exclusivity == c->index) {
207 DrawSprite(SPR_EXCLUSIVE_TRANSPORT, COMPANY_SPRITE_COLOUR(c->index), exclusive.left, text.top + exclusive_y_offset);
208 }
209
210 DrawString(text.left, text.right, text.top + text_y_offset, STR_LOCAL_AUTHORITY_COMPANY_RATING);
211 text.top += this->resize.step_height;
212 }
213 }
214
215 text.bottom = text.top - 1;
216 if (text.bottom > r.bottom) {
217 /* If the company list is too big to fit, mark ourself dirty and draw again. */
218 ResizeWindow(this, 0, text.bottom - r.bottom, false);
219 }
220 }
221
223 void DrawActions()
224 {
225 Rect r = this->GetWidget<NWidgetBase>(WID_TA_COMMAND_LIST)->GetCurrentRect().Shrink(WidgetDimensions::scaled.framerect);
226
227 DrawString(r, STR_LOCAL_AUTHORITY_ACTIONS_TITLE);
228 r.top += GetCharacterHeight(FS_NORMAL);
229
230 /* Draw list of actions */
231 for (int i = 0; i < TACT_COUNT; i++) {
232 /* Don't show actions if disabled in settings. */
233 if (!HasBit(this->enabled_actions, i)) continue;
234
235 /* Set colour of action based on ability to execute and if selected. */
236 TextColour action_colour = TC_GREY | TC_NO_SHADE;
237 if (HasBit(this->available_actions, i)) action_colour = TC_ORANGE;
238 if (this->sel_index == i) action_colour = TC_WHITE;
239
240 DrawString(r, STR_LOCAL_AUTHORITY_ACTION_SMALL_ADVERTISING_CAMPAIGN + i, action_colour);
241 r.top += GetCharacterHeight(FS_NORMAL);
242 }
243 }
244
245 void SetStringParameters(WidgetID widget) const override
246 {
247 if (widget == WID_TA_CAPTION) SetDParam(0, this->window_number);
248 }
249
250 void DrawWidget(const Rect &r, WidgetID widget) const override
251 {
252 switch (widget) {
253 case WID_TA_ACTION_INFO:
254 if (this->sel_index != -1) {
255 Money action_cost = _price[PR_TOWN_ACTION] * _town_action_costs[this->sel_index] >> 8;
256 bool affordable = Company::IsValidID(_local_company) && action_cost < GetAvailableMoney(_local_company);
257
258 SetDParam(0, action_cost);
259 DrawStringMultiLine(r.Shrink(WidgetDimensions::scaled.framerect),
260 this->action_tooltips[this->sel_index],
261 affordable ? TC_YELLOW : TC_RED);
262 }
263 break;
264 }
265 }
266
267 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
268 {
269 switch (widget) {
270 case WID_TA_ACTION_INFO: {
271 assert(size.width > padding.width && size.height > padding.height);
272 Dimension d = {0, 0};
273 for (int i = 0; i < TACT_COUNT; i++) {
274 SetDParam(0, _price[PR_TOWN_ACTION] * _town_action_costs[i] >> 8);
275 d = maxdim(d, GetStringMultiLineBoundingBox(this->action_tooltips[i], size));
276 }
277 d.width += padding.width;
278 d.height += padding.height;
279 size = maxdim(size, d);
280 break;
281 }
282
283 case WID_TA_COMMAND_LIST:
284 size.height = (TACT_COUNT + 1) * GetCharacterHeight(FS_NORMAL) + padding.height;
285 size.width = GetStringBoundingBox(STR_LOCAL_AUTHORITY_ACTIONS_TITLE).width;
286 for (uint i = 0; i < TACT_COUNT; i++ ) {
287 size.width = std::max(size.width, GetStringBoundingBox(STR_LOCAL_AUTHORITY_ACTION_SMALL_ADVERTISING_CAMPAIGN + i).width + padding.width);
288 }
289 size.width += padding.width;
290 break;
291
292 case WID_TA_RATING_INFO:
293 resize.height = std::max({this->icon_size.height + WidgetDimensions::scaled.vsep_normal, this->exclusive_size.height + WidgetDimensions::scaled.vsep_normal, (uint)GetCharacterHeight(FS_NORMAL)});
294 size.height = 9 * resize.height + padding.height;
295 break;
296 }
297 }
298
299 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
300 {
301 switch (widget) {
302 case WID_TA_ZONE_BUTTON: {
303 bool new_show_state = !this->town->show_zone;
304 TownID index = this->town->index;
305
306 new_show_state ? _town_local_authority_kdtree.Insert(index) : _town_local_authority_kdtree.Remove(index);
307
308 this->town->show_zone = new_show_state;
309 this->SetWidgetLoweredState(widget, new_show_state);
310 MarkWholeScreenDirty();
311 break;
312 }
313
314 case WID_TA_COMMAND_LIST: {
315 int y = this->GetRowFromWidget(pt.y, WID_TA_COMMAND_LIST, 1, GetCharacterHeight(FS_NORMAL)) - 1;
316
317 y = GetNthSetBit(y);
318 if (y >= 0) {
319 this->sel_index = y;
320 this->SetDirty();
321 }
322
323 /* When double-clicking, continue */
324 if (click_count == 1 || y < 0 || !HasBit(this->available_actions, y)) break;
325 [[fallthrough]];
326 }
327
328 case WID_TA_EXECUTE:
329 Command<CMD_DO_TOWN_ACTION>::Post(STR_ERROR_CAN_T_DO_THIS, this->town->xy, this->window_number, this->sel_index);
330 break;
331 }
332 }
333
335 IntervalTimer<TimerWindow> redraw_interval = {std::chrono::seconds(3), [this](auto) {
336 this->SetDirty();
337 }};
338
339 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
340 {
341 if (!gui_scope) return;
342
343 this->enabled_actions = this->GetEnabledActions();
344 if (!HasBit(this->enabled_actions, this->sel_index)) {
345 this->sel_index = -1;
346 }
347 }
348};
349
350static WindowDesc _town_authority_desc(
351 WDP_AUTO, "view_town_authority", 317, 222,
352 WC_TOWN_AUTHORITY, WC_NONE,
353 0,
354 _nested_town_authority_widgets
355);
356
357static void ShowTownAuthorityWindow(uint town)
358{
359 AllocateWindowDescFront<TownAuthorityWindow>(_town_authority_desc, town);
360}
361
362
363/* Town view window. */
364 struct TownViewWindow : Window {
365private:
366 Town *town;
367
368public:
369 static const int WID_TV_HEIGHT_NORMAL = 150;
370
371 TownViewWindow(WindowDesc &desc, WindowNumber window_number) : Window(desc)
372 {
373 this->CreateNestedTree();
374
375 this->town = Town::Get(window_number);
376 if (this->town->larger_town) this->GetWidget<NWidgetCore>(WID_TV_CAPTION)->widget_data = STR_TOWN_VIEW_CITY_CAPTION;
377
378 this->FinishInitNested(window_number);
379
380 this->flags |= WF_DISABLE_VP_SCROLL;
381 NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(WID_TV_VIEWPORT);
382 nvp->InitializeViewport(this, this->town->xy, ScaleZoomGUI(ZOOM_LVL_TOWN));
383
384 /* disable renaming town in network games if you are not the server */
385 this->SetWidgetDisabledState(WID_TV_CHANGE_NAME, _networking && !_network_server);
386 }
387
388 void Close([[maybe_unused]] int data = 0) override
389 {
390 SetViewportCatchmentTown(Town::Get(this->window_number), false);
391 this->Window::Close();
392 }
393
394 void SetStringParameters(WidgetID widget) const override
395 {
396 if (widget == WID_TV_CAPTION) SetDParam(0, this->town->index);
397 }
398
399 void OnPaint() override
400 {
401 extern const Town *_viewport_highlight_town;
402 this->SetWidgetLoweredState(WID_TV_CATCHMENT, _viewport_highlight_town == this->town);
403
404 this->DrawWidgets();
405 }
406
407 void DrawWidget(const Rect &r, WidgetID widget) const override
408 {
409 if (widget != WID_TV_INFO) return;
410
411 Rect tr = r.Shrink(WidgetDimensions::scaled.framerect);
412
413 SetDParam(0, this->town->cache.population);
414 SetDParam(1, this->town->cache.num_houses);
415 DrawString(tr, STR_TOWN_VIEW_POPULATION_HOUSES);
416 tr.top += GetCharacterHeight(FS_NORMAL);
417
418 StringID str_last_period = TimerGameEconomy::UsingWallclockUnits() ? STR_TOWN_VIEW_CARGO_LAST_MINUTE_MAX : STR_TOWN_VIEW_CARGO_LAST_MONTH_MAX;
419
420 for (auto tpe : {TPE_PASSENGERS, TPE_MAIL}) {
421 for (const CargoSpec *cs : CargoSpec::town_production_cargoes[tpe]) {
422 CargoID cid = cs->Index();
423 SetDParam(0, 1ULL << cid);
424 SetDParam(1, this->town->supplied[cid].old_act);
425 SetDParam(2, this->town->supplied[cid].old_max);
426 DrawString(tr, str_last_period);
427 tr.top += GetCharacterHeight(FS_NORMAL);
428 }
429 }
430
431 bool first = true;
432 for (int i = TAE_BEGIN; i < TAE_END; i++) {
433 if (this->town->goal[i] == 0) continue;
434 if (this->town->goal[i] == TOWN_GROWTH_WINTER && (TileHeight(this->town->xy) < LowestSnowLine() || this->town->cache.population <= 90)) continue;
435 if (this->town->goal[i] == TOWN_GROWTH_DESERT && (GetTropicZone(this->town->xy) != TROPICZONE_DESERT || this->town->cache.population <= 60)) continue;
436
437 if (first) {
438 DrawString(tr, STR_TOWN_VIEW_CARGO_FOR_TOWNGROWTH);
439 tr.top += GetCharacterHeight(FS_NORMAL);
440 first = false;
441 }
442
443 bool rtl = _current_text_dir == TD_RTL;
444
445 const CargoSpec *cargo = FindFirstCargoWithTownAcceptanceEffect((TownAcceptanceEffect)i);
446 assert(cargo != nullptr);
447
448 StringID string;
449
450 if (this->town->goal[i] == TOWN_GROWTH_DESERT || this->town->goal[i] == TOWN_GROWTH_WINTER) {
451 /* For 'original' gameplay, don't show the amount required (you need 1 or more ..) */
452 string = STR_TOWN_VIEW_CARGO_FOR_TOWNGROWTH_DELIVERED_GENERAL;
453 if (this->town->received[i].old_act == 0) {
454 string = STR_TOWN_VIEW_CARGO_FOR_TOWNGROWTH_REQUIRED_GENERAL;
455
456 if (this->town->goal[i] == TOWN_GROWTH_WINTER && TileHeight(this->town->xy) < GetSnowLine()) {
457 string = STR_TOWN_VIEW_CARGO_FOR_TOWNGROWTH_REQUIRED_WINTER;
458 }
459 }
460
461 SetDParam(0, cargo->name);
462 } else {
463 string = STR_TOWN_VIEW_CARGO_FOR_TOWNGROWTH_DELIVERED;
464 if (this->town->received[i].old_act < this->town->goal[i]) {
465 string = STR_TOWN_VIEW_CARGO_FOR_TOWNGROWTH_REQUIRED;
466 }
467
468 SetDParam(0, cargo->Index());
469 SetDParam(1, this->town->received[i].old_act);
470 SetDParam(2, cargo->Index());
471 SetDParam(3, this->town->goal[i]);
472 }
473 DrawString(tr.Indent(20, rtl), string);
474 tr.top += GetCharacterHeight(FS_NORMAL);
475 }
476
477 if (HasBit(this->town->flags, TOWN_IS_GROWING)) {
478 SetDParam(0, RoundDivSU(this->town->growth_rate + 1, Ticks::DAY_TICKS));
479 DrawString(tr, this->town->fund_buildings_months == 0 ? STR_TOWN_VIEW_TOWN_GROWS_EVERY : STR_TOWN_VIEW_TOWN_GROWS_EVERY_FUNDED);
480 tr.top += GetCharacterHeight(FS_NORMAL);
481 } else {
482 DrawString(tr, STR_TOWN_VIEW_TOWN_GROW_STOPPED);
483 tr.top += GetCharacterHeight(FS_NORMAL);
484 }
485
486 /* only show the town noise, if the noise option is activated. */
487 if (_settings_game.economy.station_noise_level) {
488 SetDParam(0, this->town->noise_reached);
489 SetDParam(1, this->town->MaxTownNoise());
490 DrawString(tr, STR_TOWN_VIEW_NOISE_IN_TOWN);
491 tr.top += GetCharacterHeight(FS_NORMAL);
492 }
493
494 if (!this->town->text.empty()) {
495 SetDParamStr(0, this->town->text);
496 tr.top = DrawStringMultiLine(tr, STR_JUST_RAW_STRING, TC_BLACK);
497 }
498 }
499
500 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
501 {
502 switch (widget) {
503 case WID_TV_CENTER_VIEW: // scroll to location
504 if (_ctrl_pressed) {
505 ShowExtraViewportWindow(this->town->xy);
506 } else {
507 ScrollMainWindowToTile(this->town->xy);
508 }
509 break;
510
511 case WID_TV_SHOW_AUTHORITY: // town authority
512 ShowTownAuthorityWindow(this->window_number);
513 break;
514
515 case WID_TV_CHANGE_NAME: // rename
516 SetDParam(0, this->window_number);
517 ShowQueryString(STR_TOWN_NAME, STR_TOWN_VIEW_RENAME_TOWN_BUTTON, MAX_LENGTH_TOWN_NAME_CHARS, this, CS_ALPHANUMERAL, QSF_ENABLE_DEFAULT | QSF_LEN_IN_CHARS);
518 break;
519
520 case WID_TV_CATCHMENT:
521 SetViewportCatchmentTown(Town::Get(this->window_number), !this->IsWidgetLowered(WID_TV_CATCHMENT));
522 break;
523
524 case WID_TV_EXPAND: { // expand town - only available on Scenario editor
525 Command<CMD_EXPAND_TOWN>::Post(STR_ERROR_CAN_T_EXPAND_TOWN, this->window_number, 0);
526 break;
527 }
528
529 case WID_TV_DELETE: // delete town - only available on Scenario editor
530 Command<CMD_DELETE_TOWN>::Post(STR_ERROR_TOWN_CAN_T_DELETE, this->window_number);
531 break;
532 }
533 }
534
535 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
536 {
537 switch (widget) {
538 case WID_TV_INFO:
539 size.height = GetDesiredInfoHeight(size.width) + padding.height;
540 break;
541 }
542 }
543
548 uint GetDesiredInfoHeight(int width) const
549 {
550 uint aimed_height = static_cast<uint>(1 + CargoSpec::town_production_cargoes[TPE_PASSENGERS].size() + CargoSpec::town_production_cargoes[TPE_MAIL].size()) * GetCharacterHeight(FS_NORMAL);
551
552 bool first = true;
553 for (int i = TAE_BEGIN; i < TAE_END; i++) {
554 if (this->town->goal[i] == 0) continue;
555 if (this->town->goal[i] == TOWN_GROWTH_WINTER && (TileHeight(this->town->xy) < LowestSnowLine() || this->town->cache.population <= 90)) continue;
556 if (this->town->goal[i] == TOWN_GROWTH_DESERT && (GetTropicZone(this->town->xy) != TROPICZONE_DESERT || this->town->cache.population <= 60)) continue;
557
558 if (first) {
559 aimed_height += GetCharacterHeight(FS_NORMAL);
560 first = false;
561 }
562 aimed_height += GetCharacterHeight(FS_NORMAL);
563 }
564 aimed_height += GetCharacterHeight(FS_NORMAL);
565
566 if (_settings_game.economy.station_noise_level) aimed_height += GetCharacterHeight(FS_NORMAL);
567
568 if (!this->town->text.empty()) {
569 SetDParamStr(0, this->town->text);
570 aimed_height += GetStringHeight(STR_JUST_RAW_STRING, width - WidgetDimensions::scaled.framerect.Horizontal());
571 }
572
573 return aimed_height;
574 }
575
576 void ResizeWindowAsNeeded()
577 {
578 const NWidgetBase *nwid_info = this->GetWidget<NWidgetBase>(WID_TV_INFO);
579 uint aimed_height = GetDesiredInfoHeight(nwid_info->current_x);
580 if (aimed_height > nwid_info->current_y || (aimed_height < nwid_info->current_y && nwid_info->current_y > nwid_info->smallest_y)) {
581 this->ReInit();
582 }
583 }
584
585 void OnResize() override
586 {
587 if (this->viewport != nullptr) {
588 NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(WID_TV_VIEWPORT);
589 nvp->UpdateViewportCoordinates(this);
590
591 ScrollWindowToTile(this->town->xy, this, true); // Re-center viewport.
592 }
593 }
594
595 void OnMouseWheel(int wheel) override
596 {
597 if (_settings_client.gui.scrollwheel_scrolling != SWS_OFF) {
598 DoZoomInOutWindow(wheel < 0 ? ZOOM_IN : ZOOM_OUT, this);
599 }
600 }
601
607 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
608 {
609 if (!gui_scope) return;
610 /* Called when setting station noise or required cargoes have changed, in order to resize the window */
611 this->SetDirty(); // refresh display for current size. This will allow to avoid glitches when downgrading
612 this->ResizeWindowAsNeeded();
613 }
614
615 void OnQueryTextFinished(std::optional<std::string> str) override
616 {
617 if (!str.has_value()) return;
618
619 Command<CMD_RENAME_TOWN>::Post(STR_ERROR_CAN_T_RENAME_TOWN, this->window_number, *str);
620 }
621
622 IntervalTimer<TimerGameCalendar> daily_interval = {{TimerGameCalendar::DAY, TimerGameCalendar::Priority::NONE}, [this](auto) {
623 /* Refresh after possible snowline change */
624 this->SetDirty();
625 }};
626};
627
628static constexpr NWidgetPart _nested_town_game_view_widgets[] = {
629 NWidget(NWID_HORIZONTAL),
630 NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
631 NWidget(WWT_PUSHIMGBTN, COLOUR_BROWN, WID_TV_CHANGE_NAME), SetAspect(WidgetDimensions::ASPECT_RENAME), SetDataTip(SPR_RENAME, STR_TOWN_VIEW_RENAME_TOOLTIP),
632 NWidget(WWT_CAPTION, COLOUR_BROWN, WID_TV_CAPTION), SetDataTip(STR_TOWN_VIEW_TOWN_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
633 NWidget(WWT_PUSHIMGBTN, COLOUR_BROWN, WID_TV_CENTER_VIEW), SetAspect(WidgetDimensions::ASPECT_LOCATION), SetDataTip(SPR_GOTO_LOCATION, STR_TOWN_VIEW_CENTER_TOOLTIP),
634 NWidget(WWT_SHADEBOX, COLOUR_BROWN),
635 NWidget(WWT_DEFSIZEBOX, COLOUR_BROWN),
636 NWidget(WWT_STICKYBOX, COLOUR_BROWN),
637 EndContainer(),
638 NWidget(WWT_PANEL, COLOUR_BROWN),
639 NWidget(WWT_INSET, COLOUR_BROWN), SetPadding(2, 2, 2, 2),
640 NWidget(NWID_VIEWPORT, INVALID_COLOUR, WID_TV_VIEWPORT), SetMinimalSize(254, 86), SetFill(1, 0), SetResize(1, 1),
641 EndContainer(),
642 EndContainer(),
643 NWidget(WWT_PANEL, COLOUR_BROWN, WID_TV_INFO), SetMinimalSize(260, 32), SetResize(1, 0), SetFill(1, 0), EndContainer(),
644 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
645 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),
646 NWidget(WWT_TEXTBTN, COLOUR_BROWN, WID_TV_CATCHMENT), SetMinimalSize(40, 12), SetFill(1, 1), SetResize(1, 0), SetDataTip(STR_BUTTON_CATCHMENT, STR_TOOLTIP_CATCHMENT),
647 NWidget(WWT_RESIZEBOX, COLOUR_BROWN),
648 EndContainer(),
649};
650
651static WindowDesc _town_game_view_desc(
652 WDP_AUTO, "view_town", 260, TownViewWindow::WID_TV_HEIGHT_NORMAL,
653 WC_TOWN_VIEW, WC_NONE,
654 0,
655 _nested_town_game_view_widgets
656);
657
658static constexpr NWidgetPart _nested_town_editor_view_widgets[] = {
659 NWidget(NWID_HORIZONTAL),
660 NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
661 NWidget(WWT_PUSHIMGBTN, COLOUR_BROWN, WID_TV_CHANGE_NAME), SetAspect(WidgetDimensions::ASPECT_RENAME), SetDataTip(SPR_RENAME, STR_TOWN_VIEW_RENAME_TOOLTIP),
662 NWidget(WWT_CAPTION, COLOUR_BROWN, WID_TV_CAPTION), SetDataTip(STR_TOWN_VIEW_TOWN_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
663 NWidget(WWT_PUSHIMGBTN, COLOUR_BROWN, WID_TV_CENTER_VIEW), SetAspect(WidgetDimensions::ASPECT_LOCATION), SetDataTip(SPR_GOTO_LOCATION, STR_TOWN_VIEW_CENTER_TOOLTIP),
664 NWidget(WWT_SHADEBOX, COLOUR_BROWN),
665 NWidget(WWT_DEFSIZEBOX, COLOUR_BROWN),
666 NWidget(WWT_STICKYBOX, COLOUR_BROWN),
667 EndContainer(),
668 NWidget(WWT_PANEL, COLOUR_BROWN),
669 NWidget(WWT_INSET, COLOUR_BROWN), SetPadding(2, 2, 2, 2),
670 NWidget(NWID_VIEWPORT, INVALID_COLOUR, WID_TV_VIEWPORT), SetMinimalSize(254, 86), SetFill(1, 1), SetResize(1, 1),
671 EndContainer(),
672 EndContainer(),
673 NWidget(WWT_PANEL, COLOUR_BROWN, WID_TV_INFO), SetMinimalSize(260, 32), SetResize(1, 0), SetFill(1, 0), EndContainer(),
674 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
675 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),
676 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),
677 NWidget(WWT_TEXTBTN, COLOUR_BROWN, WID_TV_CATCHMENT), SetMinimalSize(40, 12), SetFill(1, 1), SetResize(1, 0), SetDataTip(STR_BUTTON_CATCHMENT, STR_TOOLTIP_CATCHMENT),
678 NWidget(WWT_RESIZEBOX, COLOUR_BROWN),
679 EndContainer(),
680};
681
682static WindowDesc _town_editor_view_desc(
683 WDP_AUTO, "view_town_scen", 260, TownViewWindow::WID_TV_HEIGHT_NORMAL,
684 WC_TOWN_VIEW, WC_NONE,
685 0,
686 _nested_town_editor_view_widgets
687);
688
689void ShowTownViewWindow(TownID town)
690{
691 if (_game_mode == GM_EDITOR) {
692 AllocateWindowDescFront<TownViewWindow>(_town_editor_view_desc, town);
693 } else {
694 AllocateWindowDescFront<TownViewWindow>(_town_game_view_desc, town);
695 }
696}
697
698static constexpr NWidgetPart _nested_town_directory_widgets[] = {
699 NWidget(NWID_HORIZONTAL),
700 NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
701 NWidget(WWT_CAPTION, COLOUR_BROWN, WID_TD_CAPTION), SetDataTip(STR_TOWN_DIRECTORY_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
702 NWidget(WWT_SHADEBOX, COLOUR_BROWN),
703 NWidget(WWT_DEFSIZEBOX, COLOUR_BROWN),
704 NWidget(WWT_STICKYBOX, COLOUR_BROWN),
705 EndContainer(),
706 NWidget(NWID_HORIZONTAL),
707 NWidget(NWID_VERTICAL),
708 NWidget(NWID_HORIZONTAL),
709 NWidget(WWT_TEXTBTN, COLOUR_BROWN, WID_TD_SORT_ORDER), SetDataTip(STR_BUTTON_SORT_BY, STR_TOOLTIP_SORT_ORDER),
710 NWidget(WWT_DROPDOWN, COLOUR_BROWN, WID_TD_SORT_CRITERIA), SetDataTip(STR_JUST_STRING, STR_TOOLTIP_SORT_CRITERIA),
711 NWidget(WWT_EDITBOX, COLOUR_BROWN, WID_TD_FILTER), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP),
712 EndContainer(),
713 NWidget(WWT_PANEL, COLOUR_BROWN, WID_TD_LIST), SetDataTip(0x0, STR_TOWN_DIRECTORY_LIST_TOOLTIP),
714 SetFill(1, 0), SetResize(1, 1), SetScrollbar(WID_TD_SCROLLBAR), EndContainer(),
715 NWidget(WWT_PANEL, COLOUR_BROWN),
716 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),
717 EndContainer(),
718 EndContainer(),
719 NWidget(NWID_VERTICAL),
720 NWidget(NWID_VSCROLLBAR, COLOUR_BROWN, WID_TD_SCROLLBAR),
721 NWidget(WWT_RESIZEBOX, COLOUR_BROWN),
722 EndContainer(),
723 EndContainer(),
724};
725
727 enum TownDirectoryHotkeys {
728 TDHK_FOCUS_FILTER_BOX,
729};
730
732 struct TownDirectoryWindow : public Window {
733private:
734 /* Runtime saved values */
735 static Listing last_sorting;
736
737 /* Constants for sorting towns */
738 static inline const StringID sorter_names[] = {
739 STR_SORT_BY_NAME,
740 STR_SORT_BY_POPULATION,
741 STR_SORT_BY_RATING,
742 };
743 static const std::initializer_list<GUITownList::SortFunction * const> sorter_funcs;
744
745 StringFilter string_filter;
746 QueryString townname_editbox;
747
748 GUITownList towns{TownDirectoryWindow::last_sorting.order};
749
750 Scrollbar *vscroll;
751
752 void BuildSortTownList()
753 {
754 if (this->towns.NeedRebuild()) {
755 this->towns.clear();
756 this->towns.reserve(Town::GetNumItems());
757
758 for (const Town *t : Town::Iterate()) {
759 if (this->string_filter.IsEmpty()) {
760 this->towns.push_back(t);
761 continue;
762 }
763 this->string_filter.ResetState();
764 this->string_filter.AddLine(t->GetCachedName());
765 if (this->string_filter.GetState()) this->towns.push_back(t);
766 }
767
768 this->towns.RebuildDone();
769 this->vscroll->SetCount(this->towns.size()); // Update scrollbar as well.
770 }
771 /* Always sort the towns. */
772 this->towns.Sort();
773 this->SetWidgetDirty(WID_TD_LIST); // Force repaint of the displayed towns.
774 }
775
777 static bool TownNameSorter(const Town * const &a, const Town * const &b, const bool &)
778 {
779 return StrNaturalCompare(a->GetCachedName(), b->GetCachedName()) < 0; // Sort by name (natural sorting).
780 }
781
783 static bool TownPopulationSorter(const Town * const &a, const Town * const &b, const bool &order)
784 {
785 uint32_t a_population = a->cache.population;
786 uint32_t b_population = b->cache.population;
787 if (a_population == b_population) return TownDirectoryWindow::TownNameSorter(a, b, order);
788 return a_population < b_population;
789 }
790
792 static bool TownRatingSorter(const Town * const &a, const Town * const &b, const bool &order)
793 {
794 bool before = !order; // Value to get 'a' before 'b'.
795
796 /* Towns without rating are always after towns with rating. */
797 if (HasBit(a->have_ratings, _local_company)) {
798 if (HasBit(b->have_ratings, _local_company)) {
799 int16_t a_rating = a->ratings[_local_company];
800 int16_t b_rating = b->ratings[_local_company];
801 if (a_rating == b_rating) return TownDirectoryWindow::TownNameSorter(a, b, order);
802 return a_rating < b_rating;
803 }
804 return before;
805 }
806 if (HasBit(b->have_ratings, _local_company)) return !before;
807
808 /* Sort unrated towns always on ascending town name. */
809 if (before) return TownDirectoryWindow::TownNameSorter(a, b, order);
810 return TownDirectoryWindow::TownNameSorter(b, a, order);
811 }
812
813public:
814 TownDirectoryWindow(WindowDesc &desc) : Window(desc), townname_editbox(MAX_LENGTH_TOWN_NAME_CHARS * MAX_CHAR_LENGTH, MAX_LENGTH_TOWN_NAME_CHARS)
815 {
816 this->CreateNestedTree();
817
818 this->vscroll = this->GetScrollbar(WID_TD_SCROLLBAR);
819
820 this->towns.SetListing(this->last_sorting);
821 this->towns.SetSortFuncs(TownDirectoryWindow::sorter_funcs);
822 this->towns.ForceRebuild();
823 this->BuildSortTownList();
824
825 this->FinishInitNested(0);
826
827 this->querystrings[WID_TD_FILTER] = &this->townname_editbox;
828 this->townname_editbox.cancel_button = QueryString::ACTION_CLEAR;
829 }
830
831 void SetStringParameters(WidgetID widget) const override
832 {
833 switch (widget) {
834 case WID_TD_CAPTION:
835 SetDParam(0, this->vscroll->GetCount());
836 SetDParam(1, Town::GetNumItems());
837 break;
838
839 case WID_TD_WORLD_POPULATION:
840 SetDParam(0, GetWorldPopulation());
841 break;
842
843 case WID_TD_SORT_CRITERIA:
844 SetDParam(0, TownDirectoryWindow::sorter_names[this->towns.SortType()]);
845 break;
846 }
847 }
848
854 static StringID GetTownString(const Town *t)
855 {
856 return t->larger_town ? STR_TOWN_DIRECTORY_CITY : STR_TOWN_DIRECTORY_TOWN;
857 }
858
859 void DrawWidget(const Rect &r, WidgetID widget) const override
860 {
861 switch (widget) {
862 case WID_TD_SORT_ORDER:
863 this->DrawSortButtonState(widget, this->towns.IsDescSortOrder() ? SBS_DOWN : SBS_UP);
864 break;
865
866 case WID_TD_LIST: {
867 Rect tr = r.Shrink(WidgetDimensions::scaled.framerect);
868 if (this->towns.empty()) { // No towns available.
869 DrawString(tr, STR_TOWN_DIRECTORY_NONE);
870 break;
871 }
872
873 /* At least one town available. */
874 bool rtl = _current_text_dir == TD_RTL;
875 Dimension icon_size = GetSpriteSize(SPR_TOWN_RATING_GOOD);
876 int icon_x = tr.WithWidth(icon_size.width, rtl).left;
877 tr = tr.Indent(icon_size.width + WidgetDimensions::scaled.hsep_normal, rtl);
878
879 auto [first, last] = this->vscroll->GetVisibleRangeIterators(this->towns);
880 for (auto it = first; it != last; ++it) {
881 const Town *t = *it;
882 assert(t->xy != INVALID_TILE);
883
884 /* Draw rating icon. */
885 if (_game_mode == GM_EDITOR || !HasBit(t->have_ratings, _local_company)) {
886 DrawSprite(SPR_TOWN_RATING_NA, PAL_NONE, icon_x, tr.top + (this->resize.step_height - icon_size.height) / 2);
887 } else {
888 SpriteID icon = SPR_TOWN_RATING_APALLING;
889 if (t->ratings[_local_company] > RATING_VERYPOOR) icon = SPR_TOWN_RATING_MEDIOCRE;
890 if (t->ratings[_local_company] > RATING_GOOD) icon = SPR_TOWN_RATING_GOOD;
891 DrawSprite(icon, PAL_NONE, icon_x, tr.top + (this->resize.step_height - icon_size.height) / 2);
892 }
893
894 SetDParam(0, t->index);
895 SetDParam(1, t->cache.population);
896 DrawString(tr.left, tr.right, tr.top + (this->resize.step_height - GetCharacterHeight(FS_NORMAL)) / 2, GetTownString(t));
897
898 tr.top += this->resize.step_height;
899 }
900 break;
901 }
902 }
903 }
904
905 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
906 {
907 switch (widget) {
908 case WID_TD_SORT_ORDER: {
909 Dimension d = GetStringBoundingBox(this->GetWidget<NWidgetCore>(widget)->widget_data);
910 d.width += padding.width + Window::SortButtonWidth() * 2; // Doubled since the string is centred and it also looks better.
911 d.height += padding.height;
912 size = maxdim(size, d);
913 break;
914 }
915 case WID_TD_SORT_CRITERIA: {
916 Dimension d = GetStringListBoundingBox(TownDirectoryWindow::sorter_names);
917 d.width += padding.width;
918 d.height += padding.height;
919 size = maxdim(size, d);
920 break;
921 }
922 case WID_TD_LIST: {
923 Dimension d = GetStringBoundingBox(STR_TOWN_DIRECTORY_NONE);
924 for (uint i = 0; i < this->towns.size(); i++) {
925 const Town *t = this->towns[i];
926
927 assert(t != nullptr);
928
929 SetDParam(0, t->index);
930 SetDParamMaxDigits(1, 8);
931 d = maxdim(d, GetStringBoundingBox(GetTownString(t)));
932 }
933 Dimension icon_size = GetSpriteSize(SPR_TOWN_RATING_GOOD);
934 d.width += icon_size.width + 2;
935 d.height = std::max(d.height, icon_size.height);
936 resize.height = d.height;
937 d.height *= 5;
938 d.width += padding.width;
939 d.height += padding.height;
940 size = maxdim(size, d);
941 break;
942 }
943 case WID_TD_WORLD_POPULATION: {
944 SetDParamMaxDigits(0, 10);
945 Dimension d = GetStringBoundingBox(STR_TOWN_POPULATION);
946 d.width += padding.width;
947 d.height += padding.height;
948 size = maxdim(size, d);
949 break;
950 }
951 }
952 }
953
954 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
955 {
956 switch (widget) {
957 case WID_TD_SORT_ORDER: // Click on sort order button
958 if (this->towns.SortType() != 2) { // A different sort than by rating.
959 this->towns.ToggleSortOrder();
960 this->last_sorting = this->towns.GetListing(); // Store new sorting order.
961 } else {
962 /* Some parts are always sorted ascending on name. */
963 this->last_sorting.order = !this->last_sorting.order;
964 this->towns.SetListing(this->last_sorting);
965 this->towns.ForceResort();
966 this->towns.Sort();
967 }
968 this->SetDirty();
969 break;
970
971 case WID_TD_SORT_CRITERIA: // Click on sort criteria dropdown
972 ShowDropDownMenu(this, TownDirectoryWindow::sorter_names, this->towns.SortType(), WID_TD_SORT_CRITERIA, 0, 0);
973 break;
974
975 case WID_TD_LIST: { // Click on Town Matrix
976 auto it = this->vscroll->GetScrolledItemFromWidget(this->towns, pt.y, this, WID_TD_LIST, WidgetDimensions::scaled.framerect.top);
977 if (it == this->towns.end()) return; // click out of town bounds
978
979 const Town *t = *it;
980 assert(t != nullptr);
981 if (_ctrl_pressed) {
982 ShowExtraViewportWindow(t->xy);
983 } else {
984 ScrollMainWindowToTile(t->xy);
985 }
986 break;
987 }
988 }
989 }
990
991 void OnDropdownSelect(WidgetID widget, int index) override
992 {
993 if (widget != WID_TD_SORT_CRITERIA) return;
994
995 if (this->towns.SortType() != index) {
996 this->towns.SetSortType(index);
997 this->last_sorting = this->towns.GetListing(); // Store new sorting order.
998 this->BuildSortTownList();
999 }
1000 }
1001
1002 void OnPaint() override
1003 {
1004 if (this->towns.NeedRebuild()) this->BuildSortTownList();
1005 this->DrawWidgets();
1006 }
1007
1009 IntervalTimer<TimerWindow> rebuild_interval = {std::chrono::seconds(3), [this](auto) {
1010 this->BuildSortTownList();
1011 this->SetDirty();
1012 }};
1013
1014 void OnResize() override
1015 {
1016 this->vscroll->SetCapacityFromWidget(this, WID_TD_LIST, WidgetDimensions::scaled.framerect.Vertical());
1017 }
1018
1019 void OnEditboxChanged(WidgetID wid) override
1020 {
1021 if (wid == WID_TD_FILTER) {
1022 this->string_filter.SetFilterTerm(this->townname_editbox.text.buf);
1023 this->InvalidateData(TDIWD_FORCE_REBUILD);
1024 }
1025 }
1026
1032 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
1033 {
1034 switch (data) {
1035 case TDIWD_FORCE_REBUILD:
1036 /* This needs to be done in command-scope to enforce rebuilding before resorting invalid data */
1037 this->towns.ForceRebuild();
1038 break;
1039
1040 case TDIWD_POPULATION_CHANGE:
1041 if (this->towns.SortType() == 1) this->towns.ForceResort();
1042 break;
1043
1044 default:
1045 this->towns.ForceResort();
1046 }
1047 }
1048
1049 EventState OnHotkey(int hotkey) override
1050 {
1051 switch (hotkey) {
1052 case TDHK_FOCUS_FILTER_BOX:
1053 this->SetFocusedWidget(WID_TD_FILTER);
1054 SetFocusedWindow(this); // The user has asked to give focus to the text box, so make sure this window is focused.
1055 break;
1056 default:
1057 return ES_NOT_HANDLED;
1058 }
1059 return ES_HANDLED;
1060 }
1061
1062 static inline HotkeyList hotkeys {"towndirectory", {
1063 Hotkey('F', "focus_filter_box", TDHK_FOCUS_FILTER_BOX),
1064 }};
1065};
1066
1067 Listing TownDirectoryWindow::last_sorting = {false, 0};
1068
1070 const std::initializer_list<GUITownList::SortFunction * const> TownDirectoryWindow::sorter_funcs = {
1071 &TownNameSorter,
1072 &TownPopulationSorter,
1073 &TownRatingSorter,
1074};
1075
1076static WindowDesc _town_directory_desc(
1077 WDP_AUTO, "list_towns", 208, 202,
1078 WC_TOWN_DIRECTORY, WC_NONE,
1079 0,
1080 _nested_town_directory_widgets,
1081 &TownDirectoryWindow::hotkeys
1082);
1083
1084void ShowTownDirectory()
1085{
1086 if (BringWindowToFrontById(WC_TOWN_DIRECTORY, 0)) return;
1087 new TownDirectoryWindow(_town_directory_desc);
1088}
1089
1090void CcFoundTown(Commands, const CommandCost &result, TileIndex tile)
1091{
1092 if (result.Failed()) return;
1093
1094 if (_settings_client.sound.confirm) SndPlayTileFx(SND_1F_CONSTRUCTION_OTHER, tile);
1095 if (!_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
1096}
1097
1098void CcFoundRandomTown(Commands, const CommandCost &result, Money, TownID town_id)
1099{
1100 if (result.Succeeded()) ScrollMainWindowToTile(Town::Get(town_id)->xy);
1101}
1102
1103static constexpr NWidgetPart _nested_found_town_widgets[] = {
1104 NWidget(NWID_HORIZONTAL),
1105 NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
1106 NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_FOUND_TOWN_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1107 NWidget(WWT_SHADEBOX, COLOUR_DARK_GREEN),
1108 NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN),
1109 EndContainer(),
1110 /* Construct new town(s) buttons. */
1111 NWidget(WWT_PANEL, COLOUR_DARK_GREEN),
1112 NWidget(NWID_VERTICAL), SetPIP(0, WidgetDimensions::unscaled.vsep_normal, 0), SetPadding(WidgetDimensions::unscaled.picker),
1113 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_TF_NEW_TOWN), SetDataTip(STR_FOUND_TOWN_NEW_TOWN_BUTTON, STR_FOUND_TOWN_NEW_TOWN_TOOLTIP), SetFill(1, 0),
1114 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_TF_TOWN_ACTION_SEL),
1115 NWidget(NWID_VERTICAL), SetPIP(0, WidgetDimensions::unscaled.vsep_normal, 0),
1116 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_TF_RANDOM_TOWN), SetDataTip(STR_FOUND_TOWN_RANDOM_TOWN_BUTTON, STR_FOUND_TOWN_RANDOM_TOWN_TOOLTIP), SetFill(1, 0),
1117 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_TF_MANY_RANDOM_TOWNS), SetDataTip(STR_FOUND_TOWN_MANY_RANDOM_TOWNS, STR_FOUND_TOWN_RANDOM_TOWNS_TOOLTIP), SetFill(1, 0),
1118 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_TF_LOAD_FROM_FILE), SetDataTip(STR_FOUND_TOWN_LOAD_FROM_FILE, STR_FOUND_TOWN_LOAD_FROM_FILE_TOOLTIP), SetFill(1, 0),
1119 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_TF_EXPAND_ALL_TOWNS), SetDataTip(STR_FOUND_TOWN_EXPAND_ALL_TOWNS, STR_FOUND_TOWN_EXPAND_ALL_TOWNS_TOOLTIP), SetFill(1, 0),
1120 EndContainer(),
1121 EndContainer(),
1122
1123 /* Town name selection. */
1124 NWidget(WWT_LABEL, COLOUR_DARK_GREEN), SetDataTip(STR_FOUND_TOWN_NAME_TITLE, STR_NULL),
1125 NWidget(WWT_EDITBOX, COLOUR_GREY, WID_TF_TOWN_NAME_EDITBOX), SetDataTip(STR_FOUND_TOWN_NAME_EDITOR_TITLE, STR_FOUND_TOWN_NAME_EDITOR_HELP), SetFill(1, 0),
1126 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_TF_TOWN_NAME_RANDOM), SetDataTip(STR_FOUND_TOWN_NAME_RANDOM_BUTTON, STR_FOUND_TOWN_NAME_RANDOM_TOOLTIP), SetFill(1, 0),
1127
1128 /* Town size selection. */
1129 NWidget(WWT_LABEL, COLOUR_DARK_GREEN), SetDataTip(STR_FOUND_TOWN_INITIAL_SIZE_TITLE, STR_NULL),
1130 NWidget(NWID_VERTICAL),
1131 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
1132 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_TF_SIZE_SMALL), SetDataTip(STR_FOUND_TOWN_INITIAL_SIZE_SMALL_BUTTON, STR_FOUND_TOWN_INITIAL_SIZE_TOOLTIP), SetFill(1, 0),
1133 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_TF_SIZE_MEDIUM), SetDataTip(STR_FOUND_TOWN_INITIAL_SIZE_MEDIUM_BUTTON, STR_FOUND_TOWN_INITIAL_SIZE_TOOLTIP), SetFill(1, 0),
1134 EndContainer(),
1135 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
1136 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_TF_SIZE_SEL),
1137 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_TF_SIZE_LARGE), SetDataTip(STR_FOUND_TOWN_INITIAL_SIZE_LARGE_BUTTON, STR_FOUND_TOWN_INITIAL_SIZE_TOOLTIP), SetFill(1, 0),
1138 EndContainer(),
1139 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_TF_SIZE_RANDOM), SetDataTip(STR_FOUND_TOWN_SIZE_RANDOM, STR_FOUND_TOWN_INITIAL_SIZE_TOOLTIP), SetFill(1, 0),
1140 EndContainer(),
1141 EndContainer(),
1142 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_TF_CITY), SetDataTip(STR_FOUND_TOWN_CITY, STR_FOUND_TOWN_CITY_TOOLTIP), SetFill(1, 0),
1143
1144 /* Town roads selection. */
1145 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_TF_ROAD_LAYOUT_SEL),
1146 NWidget(NWID_VERTICAL), SetPIP(0, WidgetDimensions::unscaled.vsep_normal, 0),
1147 NWidget(WWT_LABEL, COLOUR_DARK_GREEN), SetDataTip(STR_FOUND_TOWN_ROAD_LAYOUT, STR_NULL),
1148 NWidget(NWID_VERTICAL),
1149 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
1150 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_TF_LAYOUT_ORIGINAL), SetDataTip(STR_FOUND_TOWN_SELECT_LAYOUT_ORIGINAL, STR_FOUND_TOWN_SELECT_TOWN_ROAD_LAYOUT), SetFill(1, 0),
1151 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_TF_LAYOUT_BETTER), SetDataTip(STR_FOUND_TOWN_SELECT_LAYOUT_BETTER_ROADS, STR_FOUND_TOWN_SELECT_TOWN_ROAD_LAYOUT), SetFill(1, 0),
1152 EndContainer(),
1153 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
1154 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_TF_LAYOUT_GRID2), SetDataTip(STR_FOUND_TOWN_SELECT_LAYOUT_2X2_GRID, STR_FOUND_TOWN_SELECT_TOWN_ROAD_LAYOUT), SetFill(1, 0),
1155 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_TF_LAYOUT_GRID3), SetDataTip(STR_FOUND_TOWN_SELECT_LAYOUT_3X3_GRID, STR_FOUND_TOWN_SELECT_TOWN_ROAD_LAYOUT), SetFill(1, 0),
1156 EndContainer(),
1157 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_TF_LAYOUT_RANDOM), SetDataTip(STR_FOUND_TOWN_SELECT_LAYOUT_RANDOM, STR_FOUND_TOWN_SELECT_TOWN_ROAD_LAYOUT), SetFill(1, 0),
1158 EndContainer(),
1159 EndContainer(),
1160 EndContainer(),
1161 EndContainer(),
1162 EndContainer(),
1163};
1164
1166 struct FoundTownWindow : Window {
1167private:
1168 TownSize town_size;
1169 TownLayout town_layout;
1170 bool city;
1171 QueryString townname_editbox;
1172 bool townnamevalid;
1173 uint32_t townnameparts;
1174 TownNameParams params;
1175
1176public:
1177 FoundTownWindow(WindowDesc &desc, WindowNumber window_number) :
1178 Window(desc),
1179 town_size(TSZ_MEDIUM),
1180 town_layout(_settings_game.economy.town_layout),
1181 townname_editbox(MAX_LENGTH_TOWN_NAME_CHARS * MAX_CHAR_LENGTH, MAX_LENGTH_TOWN_NAME_CHARS),
1182 params(_settings_game.game_creation.town_name)
1183 {
1184 this->InitNested(window_number);
1185 this->querystrings[WID_TF_TOWN_NAME_EDITBOX] = &this->townname_editbox;
1186 this->RandomTownName();
1187 this->UpdateButtons(true);
1188 }
1189
1190 void OnInit() override
1191 {
1192 if (_game_mode == GM_EDITOR) return;
1193
1194 this->GetWidget<NWidgetStacked>(WID_TF_TOWN_ACTION_SEL)->SetDisplayedPlane(SZSP_HORIZONTAL);
1195 this->GetWidget<NWidgetStacked>(WID_TF_SIZE_SEL)->SetDisplayedPlane(SZSP_VERTICAL);
1196 if (_settings_game.economy.found_town != TF_CUSTOM_LAYOUT) {
1197 this->GetWidget<NWidgetStacked>(WID_TF_ROAD_LAYOUT_SEL)->SetDisplayedPlane(SZSP_HORIZONTAL);
1198 } else {
1199 this->GetWidget<NWidgetStacked>(WID_TF_ROAD_LAYOUT_SEL)->SetDisplayedPlane(0);
1200 }
1201 }
1202
1203 void RandomTownName()
1204 {
1205 this->townnamevalid = GenerateTownName(_interactive_random, &this->townnameparts);
1206
1207 if (!this->townnamevalid) {
1208 this->townname_editbox.text.DeleteAll();
1209 } else {
1210 this->townname_editbox.text.Assign(GetTownName(&this->params, this->townnameparts));
1211 }
1212 UpdateOSKOriginalText(this, WID_TF_TOWN_NAME_EDITBOX);
1213
1214 this->SetWidgetDirty(WID_TF_TOWN_NAME_EDITBOX);
1215 }
1216
1217 void UpdateButtons(bool check_availability)
1218 {
1219 if (check_availability && _game_mode != GM_EDITOR) {
1220 if (_settings_game.economy.found_town != TF_CUSTOM_LAYOUT) this->town_layout = _settings_game.economy.town_layout;
1221 this->ReInit();
1222 }
1223
1224 for (WidgetID i = WID_TF_SIZE_SMALL; i <= WID_TF_SIZE_RANDOM; i++) {
1225 this->SetWidgetLoweredState(i, i == WID_TF_SIZE_SMALL + this->town_size);
1226 }
1227
1228 this->SetWidgetLoweredState(WID_TF_CITY, this->city);
1229
1230 for (WidgetID i = WID_TF_LAYOUT_ORIGINAL; i <= WID_TF_LAYOUT_RANDOM; i++) {
1231 this->SetWidgetLoweredState(i, i == WID_TF_LAYOUT_ORIGINAL + this->town_layout);
1232 }
1233
1234 this->SetDirty();
1235 }
1236
1237 template <typename Tcallback>
1238 void ExecuteFoundTownCommand(TileIndex tile, bool random, StringID errstr, Tcallback cc)
1239 {
1240 std::string name;
1241
1242 if (!this->townnamevalid) {
1243 name = this->townname_editbox.text.buf;
1244 } else {
1245 /* If user changed the name, send it */
1246 std::string original_name = GetTownName(&this->params, this->townnameparts);
1247 if (original_name != this->townname_editbox.text.buf) name = this->townname_editbox.text.buf;
1248 }
1249
1250 bool success = Command<CMD_FOUND_TOWN>::Post(errstr, cc,
1251 tile, this->town_size, this->city, this->town_layout, random, townnameparts, name);
1252
1253 /* Rerandomise name, if success and no cost-estimation. */
1254 if (success && !_shift_pressed) this->RandomTownName();
1255 }
1256
1257 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
1258 {
1259 switch (widget) {
1260 case WID_TF_NEW_TOWN:
1261 HandlePlacePushButton(this, WID_TF_NEW_TOWN, SPR_CURSOR_TOWN, HT_RECT);
1262 break;
1263
1264 case WID_TF_RANDOM_TOWN:
1265 this->ExecuteFoundTownCommand(0, true, STR_ERROR_CAN_T_GENERATE_TOWN, CcFoundRandomTown);
1266 break;
1267
1268 case WID_TF_TOWN_NAME_RANDOM:
1269 this->RandomTownName();
1270 this->SetFocusedWidget(WID_TF_TOWN_NAME_EDITBOX);
1271 break;
1272
1273 case WID_TF_MANY_RANDOM_TOWNS: {
1274 Backup<bool> old_generating_world(_generating_world, true);
1275 UpdateNearestTownForRoadTiles(true);
1276 if (!GenerateTowns(this->town_layout)) {
1277 ShowErrorMessage(STR_ERROR_CAN_T_GENERATE_TOWN, STR_ERROR_NO_SPACE_FOR_TOWN, WL_INFO);
1278 }
1279 UpdateNearestTownForRoadTiles(false);
1280 old_generating_world.Restore();
1281 break;
1282 }
1283
1284 case WID_TF_LOAD_FROM_FILE:
1285 ShowSaveLoadDialog(FT_TOWN_DATA, SLO_LOAD);
1286 break;
1287
1288 case WID_TF_EXPAND_ALL_TOWNS:
1289 for (Town *t : Town::Iterate()) {
1290 Command<CMD_EXPAND_TOWN>::Do(DC_EXEC, t->index, 0);
1291 }
1292 break;
1293
1294 case WID_TF_SIZE_SMALL: case WID_TF_SIZE_MEDIUM: case WID_TF_SIZE_LARGE: case WID_TF_SIZE_RANDOM:
1295 this->town_size = (TownSize)(widget - WID_TF_SIZE_SMALL);
1296 this->UpdateButtons(false);
1297 break;
1298
1299 case WID_TF_CITY:
1300 this->city ^= true;
1301 this->SetWidgetLoweredState(WID_TF_CITY, this->city);
1302 this->SetDirty();
1303 break;
1304
1305 case WID_TF_LAYOUT_ORIGINAL: case WID_TF_LAYOUT_BETTER: case WID_TF_LAYOUT_GRID2:
1306 case WID_TF_LAYOUT_GRID3: case WID_TF_LAYOUT_RANDOM:
1307 this->town_layout = (TownLayout)(widget - WID_TF_LAYOUT_ORIGINAL);
1308
1309 /* If we are in the editor, sync the settings of the current game to the chosen layout,
1310 * so that importing towns from file uses the selected layout. */
1311 if (_game_mode == GM_EDITOR) _settings_game.economy.town_layout = this->town_layout;
1312
1313 this->UpdateButtons(false);
1314 break;
1315 }
1316 }
1317
1318 void OnPlaceObject([[maybe_unused]] Point pt, TileIndex tile) override
1319 {
1320 this->ExecuteFoundTownCommand(tile, false, STR_ERROR_CAN_T_FOUND_TOWN_HERE, CcFoundTown);
1321 }
1322
1323 void OnPlaceObjectAbort() override
1324 {
1325 this->RaiseButtons();
1326 this->UpdateButtons(false);
1327 }
1328
1334 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
1335 {
1336 if (!gui_scope) return;
1337 this->UpdateButtons(true);
1338 }
1339};
1340
1341static WindowDesc _found_town_desc(
1342 WDP_AUTO, "build_town", 160, 162,
1343 WC_FOUND_TOWN, WC_NONE,
1344 WDF_CONSTRUCTION,
1345 _nested_found_town_widgets
1346);
1347
1348void ShowFoundTownWindow()
1349{
1350 if (_game_mode != GM_EDITOR && !Company::IsValidID(_local_company)) return;
1351 AllocateWindowDescFront<FoundTownWindow>(_found_town_desc, 0);
1352}
1353
1354void InitializeTownGui()
1355{
1356 _town_local_authority_kdtree.Clear();
1357}
1358
1367 void DrawNewHouseTileInGUI(int x, int y, const HouseSpec *spec, HouseID house_id, int view)
1368{
1369 HouseResolverObject object(house_id, INVALID_TILE, nullptr, CBID_NO_CALLBACK, 0, 0, true, view);
1370 const SpriteGroup *group = object.Resolve();
1371 if (group == nullptr || group->type != SGT_TILELAYOUT) return;
1372
1373 uint8_t stage = TOWN_HOUSE_COMPLETED;
1374 const DrawTileSprites *dts = reinterpret_cast<const TileLayoutSpriteGroup *>(group)->ProcessRegisters(&stage);
1375
1376 PaletteID palette = GENERAL_SPRITE_COLOUR(spec->random_colour[0]);
1377 if (HasBit(spec->callback_mask, CBM_HOUSE_COLOUR)) {
1378 uint16_t callback = GetHouseCallback(CBID_HOUSE_COLOUR, 0, 0, house_id, nullptr, INVALID_TILE, true, view);
1379 if (callback != CALLBACK_FAILED) {
1380 /* If bit 14 is set, we should use a 2cc colour map, else use the callback value. */
1381 palette = HasBit(callback, 14) ? GB(callback, 0, 8) + SPR_2CCMAP_BASE : callback;
1382 }
1383 }
1384
1385 SpriteID image = dts->ground.sprite;
1386 PaletteID pal = dts->ground.pal;
1387
1388 if (HasBit(image, SPRITE_MODIFIER_CUSTOM_SPRITE)) image += stage;
1389 if (HasBit(pal, SPRITE_MODIFIER_CUSTOM_SPRITE)) pal += stage;
1390
1391 if (GB(image, 0, SPRITE_WIDTH) != 0) {
1392 DrawSprite(image, GroundSpritePaletteTransform(image, pal, palette), x, y);
1393 }
1394
1395 DrawNewGRFTileSeqInGUI(x, y, dts, stage, palette);
1396}
1397
1405 void DrawHouseInGUI(int x, int y, HouseID house_id, int view)
1406{
1407 auto draw = [](int x, int y, HouseID house_id, int view) {
1408 if (house_id >= NEW_HOUSE_OFFSET) {
1409 /* Houses don't necessarily need new graphics. If they don't have a
1410 * spritegroup associated with them, then the sprite for the substitute
1411 * house id is drawn instead. */
1412 const HouseSpec *spec = HouseSpec::Get(house_id);
1413 if (spec->grf_prop.spritegroup[0] != nullptr) {
1414 DrawNewHouseTileInGUI(x, y, spec, house_id, view);
1415 return;
1416 } else {
1417 house_id = HouseSpec::Get(house_id)->grf_prop.subst_id;
1418 }
1419 }
1420
1421 /* Retrieve data from the draw town tile struct */
1422 const DrawBuildingsTileStruct &dcts = GetTownDrawTileData()[house_id << 4 | view << 2 | TOWN_HOUSE_COMPLETED];
1423 DrawSprite(dcts.ground.sprite, dcts.ground.pal, x, y);
1424
1425 /* Add a house on top of the ground? */
1426 if (dcts.building.sprite != 0) {
1427 Point pt = RemapCoords(dcts.subtile_x, dcts.subtile_y, 0);
1428 DrawSprite(dcts.building.sprite, dcts.building.pal, x + UnScaleGUI(pt.x), y + UnScaleGUI(pt.y));
1429 }
1430 };
1431
1432 /* Houses can have 1x1, 1x2, 2x1 and 2x2 layouts which are individual HouseIDs. For the GUI we need
1433 * draw all of the tiles with appropriate positions. */
1434 int x_delta = ScaleGUITrad(TILE_PIXELS);
1435 int y_delta = ScaleGUITrad(TILE_PIXELS / 2);
1436
1437 const HouseSpec *hs = HouseSpec::Get(house_id);
1438 if (hs->building_flags & TILE_SIZE_2x2) {
1439 draw(x, y - y_delta - y_delta, house_id, view); // North corner.
1440 draw(x + x_delta, y - y_delta, house_id + 1, view); // West corner.
1441 draw(x - x_delta, y - y_delta, house_id + 2, view); // East corner.
1442 draw(x, y, house_id + 3, view); // South corner.
1443 } else if (hs->building_flags & TILE_SIZE_2x1) {
1444 draw(x + x_delta / 2, y - y_delta, house_id, view); // North east tile.
1445 draw(x - x_delta / 2, y, house_id + 1, view); // South west tile.
1446 } else if (hs->building_flags & TILE_SIZE_1x2) {
1447 draw(x - x_delta / 2, y - y_delta, house_id, view); // North west tile.
1448 draw(x + x_delta / 2, y, house_id + 1, view); // South east tile.
1449 } else {
1450 draw(x, y, house_id, view);
1451 }
1452}
1453
1459 static StringID GetHouseName(const HouseSpec *hs)
1460{
1461 uint16_t callback_res = GetHouseCallback(CBID_HOUSE_CUSTOM_NAME, 1, 0, hs->Index(), nullptr, INVALID_TILE, true);
1462 if (callback_res != CALLBACK_FAILED && callback_res != 0x400) {
1463 if (callback_res > 0x400) {
1464 ErrorUnknownCallbackResult(hs->grf_prop.grffile->grfid, CBID_HOUSE_CUSTOM_NAME, callback_res);
1465 } else {
1466 StringID new_name = GetGRFStringID(hs->grf_prop.grffile->grfid, 0xD000 + callback_res);
1467 if (new_name != STR_NULL && new_name != STR_UNDEFINED) {
1468 return new_name;
1469 }
1470 }
1471 }
1472
1473 return hs->building_name;
1474}
1475
1476 class HousePickerCallbacks : public PickerCallbacks {
1477public:
1478 HousePickerCallbacks() : PickerCallbacks("fav_houses") {}
1479
1483 void SetClimateMask()
1484 {
1485 switch (_settings_game.game_creation.landscape) {
1486 case LT_TEMPERATE: this->climate_mask = HZ_TEMP; break;
1487 case LT_ARCTIC: this->climate_mask = HZ_SUBARTC_ABOVE | HZ_SUBARTC_BELOW; break;
1488 case LT_TROPIC: this->climate_mask = HZ_SUBTROPIC; break;
1489 case LT_TOYLAND: this->climate_mask = HZ_TOYLND; break;
1490 default: NOT_REACHED();
1491 }
1492
1493 /* In some cases, not all 'classes' (house zones) have distinct houses, so we need to disable those.
1494 * As we need to check all types, and this cannot change with the picker window open, pre-calculate it.
1495 * This loop calls GetTypeName() instead of directly checking properties so that there is no discrepancy. */
1496 this->class_mask = 0;
1497
1498 int num_classes = this->GetClassCount();
1499 for (int cls_id = 0; cls_id < num_classes; ++cls_id) {
1500 int num_types = this->GetTypeCount(cls_id);
1501 for (int id = 0; id < num_types; ++id) {
1502 if (this->GetTypeName(cls_id, id) != INVALID_STRING_ID) {
1503 SetBit(this->class_mask, cls_id);
1504 break;
1505 }
1506 }
1507 }
1508 }
1509
1510 HouseZones climate_mask;
1511 uint8_t class_mask;
1512
1513 static inline int sel_class;
1514 static inline int sel_type;
1515 static inline int sel_view;
1516
1517 /* Houses do not have classes like NewGRFClass. We'll make up fake classes based on town zone
1518 * availability instead. */
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,
1525 };
1526
1527 StringID GetClassTooltip() const override { return STR_PICKER_HOUSE_CLASS_TOOLTIP; }
1528 StringID GetTypeTooltip() const override { return STR_PICKER_HOUSE_TYPE_TOOLTIP; }
1529 bool IsActive() const override { return true; }
1530
1531 bool HasClassChoice() const override { return true; }
1532 int GetClassCount() const override { return static_cast<int>(zone_names.size()); }
1533
1534 void Close([[maybe_unused]] int data) override { ResetObjectToPlace(); }
1535
1536 int GetSelectedClass() const override { return HousePickerCallbacks::sel_class; }
1537 void SetSelectedClass(int cls_id) const override { HousePickerCallbacks::sel_class = cls_id; }
1538
1539 StringID GetClassName(int id) const override
1540 {
1541 if (id >= GetClassCount()) return INVALID_STRING_ID;
1542 if (!HasBit(this->class_mask, id)) return INVALID_STRING_ID;
1543 return zone_names[id];
1544 }
1545
1546 int GetTypeCount(int cls_id) const override
1547 {
1548 if (cls_id < GetClassCount()) return static_cast<int>(HouseSpec::Specs().size());
1549 return 0;
1550 }
1551
1552 PickerItem GetPickerItem(int cls_id, int id) const override
1553 {
1554 const auto *spec = HouseSpec::Get(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};
1557 }
1558
1559 int GetSelectedType() const override { return sel_type; }
1560 void SetSelectedType(int id) const override { sel_type = id; }
1561
1562 StringID GetTypeName(int cls_id, int id) const override
1563 {
1564 const HouseSpec *spec = HouseSpec::Get(id);
1565 if (spec == nullptr) return INVALID_STRING_ID;
1566 if (!spec->enabled) return INVALID_STRING_ID;
1567 if ((spec->building_availability & climate_mask) == 0) return INVALID_STRING_ID;
1568 if (!HasBit(spec->building_availability, cls_id)) return INVALID_STRING_ID;
1569 for (int i = 0; i < cls_id; i++) {
1570 /* Don't include if it's already included in an earlier zone. */
1571 if (HasBit(spec->building_availability, i)) return INVALID_STRING_ID;
1572 }
1573
1574 return GetHouseName(spec);
1575 }
1576
1577 bool IsTypeAvailable(int, int id) const override
1578 {
1579 const HouseSpec *hs = HouseSpec::Get(id);
1580 return hs->enabled;
1581 }
1582
1583 void DrawType(int x, int y, int, int id) const override
1584 {
1585 DrawHouseInGUI(x, y, id, HousePickerCallbacks::sel_view);
1586 }
1587
1588 void FillUsedItems(std::set<PickerItem> &items) override
1589 {
1590 auto id_count = GetBuildingHouseIDCounts();
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));
1594 const HouseSpec *hs = HouseSpec::Get(house);
1595 int class_index = FindFirstBit(hs->building_availability & HZ_ZONALL);
1596 items.insert({0, house, class_index, house});
1597 }
1598 }
1599
1600 std::set<PickerItem> UpdateSavedItems(const std::set<PickerItem> &src) override
1601 {
1602 if (src.empty()) return src;
1603
1604 const auto specs = HouseSpec::Specs();
1605 std::set<PickerItem> dst;
1606 for (const auto &item : src) {
1607 if (item.grfid == 0) {
1608 dst.insert(item);
1609 } else {
1610 /* Search for spec by grfid and local index. */
1611 auto it = std::ranges::find_if(specs, [&item](const HouseSpec &spec) { return spec.grf_prop.grfid == item.grfid && spec.grf_prop.local_id == item.local_id; });
1612 if (it == specs.end()) {
1613 /* Not preset, hide from UI. */
1614 dst.insert({item.grfid, item.local_id, -1, -1});
1615 } else {
1616 int class_index = FindFirstBit(it->building_availability & HZ_ZONALL);
1617 dst.insert( {item.grfid, item.local_id, class_index, it->Index()});
1618 }
1619 }
1620 }
1621
1622 return dst;
1623 }
1624
1625 static HousePickerCallbacks instance;
1626};
1627/* static */ HousePickerCallbacks HousePickerCallbacks::instance;
1628
1629 struct BuildHouseWindow : public PickerWindow {
1630 std::string house_info;
1631
1632 BuildHouseWindow(WindowDesc &desc, Window *parent) : PickerWindow(desc, parent, 0, HousePickerCallbacks::instance)
1633 {
1634 HousePickerCallbacks::instance.SetClimateMask();
1635 this->ConstructWindow();
1636 this->InvalidateData();
1637 }
1638
1639 void UpdateSelectSize(const HouseSpec *spec)
1640 {
1641 if (spec == nullptr) {
1642 SetTileSelectSize(1, 1);
1643 ResetObjectToPlace();
1644 } else {
1645 SetObjectToPlaceWnd(SPR_CURSOR_TOWN, PAL_NONE, HT_RECT | HT_DIAGONAL, this);
1646 if (spec->building_flags & TILE_SIZE_2x2) {
1647 SetTileSelectSize(2, 2);
1648 } else if (spec->building_flags & TILE_SIZE_2x1) {
1649 SetTileSelectSize(2, 1);
1650 } else if (spec->building_flags & TILE_SIZE_1x2) {
1651 SetTileSelectSize(1, 2);
1652 } else if (spec->building_flags & TILE_SIZE_1x1) {
1653 SetTileSelectSize(1, 1);
1654 }
1655 }
1656 }
1657
1664 static std::string GetHouseYear(TimerGameCalendar::Year min_year, TimerGameCalendar::Year max_year)
1665 {
1666 if (min_year == CalendarTime::MIN_YEAR) {
1667 if (max_year == CalendarTime::MAX_YEAR) {
1668 return GetString(STR_HOUSE_PICKER_YEARS_ANY);
1669 }
1670 SetDParam(0, max_year);
1671 return GetString(STR_HOUSE_PICKER_YEARS_UNTIL);
1672 }
1673 if (max_year == CalendarTime::MAX_YEAR) {
1674 SetDParam(0, min_year);
1675 return GetString(STR_HOUSE_PICKER_YEARS_FROM);
1676 }
1677 SetDParam(0, min_year);
1678 SetDParam(1, max_year);
1679 return GetString(STR_HOUSE_PICKER_YEARS);
1680 }
1681
1687 static std::string GetHouseInformation(const HouseSpec *hs)
1688 {
1689 std::stringstream line;
1690
1691 SetDParam(0, GetHouseName(hs));
1692 line << GetString(STR_HOUSE_PICKER_NAME);
1693 line << "\n";
1694
1695 SetDParam(0, hs->population);
1696 line << GetString(STR_HOUSE_PICKER_POPULATION);
1697 line << "\n";
1698
1699 line << GetHouseYear(hs->min_year, hs->max_year);
1700 line << "\n";
1701
1702 uint8_t size = 0;
1703 if ((hs->building_flags & TILE_SIZE_1x1) != 0) size = 0x11;
1704 if ((hs->building_flags & TILE_SIZE_2x1) != 0) size = 0x21;
1705 if ((hs->building_flags & TILE_SIZE_1x2) != 0) size = 0x12;
1706 if ((hs->building_flags & TILE_SIZE_2x2) != 0) size = 0x22;
1707 SetDParam(0, GB(size, 0, 4));
1708 SetDParam(1, GB(size, 4, 4));
1709 line << GetString(STR_HOUSE_PICKER_SIZE);
1710 line << "\n";
1711
1712 auto cargo_string = BuildCargoAcceptanceString(GetAcceptedCargoOfHouse(hs), STR_HOUSE_PICKER_CARGO_ACCEPTED);
1713 if (cargo_string.has_value()) line << *cargo_string;
1714
1715 return line.str();
1716 }
1717
1718 void DrawWidget(const Rect &r, WidgetID widget) const override
1719 {
1720 if (widget == WID_BH_INFO) {
1721 if (!this->house_info.empty()) DrawStringMultiLine(r, this->house_info);
1722 } else {
1723 this->PickerWindow::DrawWidget(r, widget);
1724 }
1725 }
1726
1727 void OnInvalidateData(int data = 0, bool gui_scope = true) override
1728 {
1729 this->PickerWindow::OnInvalidateData(data, gui_scope);
1730 if (!gui_scope) return;
1731
1732 if ((data & PickerWindow::PFI_POSITION) != 0) {
1733 const HouseSpec *spec = HouseSpec::Get(HousePickerCallbacks::sel_type);
1734 UpdateSelectSize(spec);
1735 this->house_info = GetHouseInformation(spec);
1736 }
1737 }
1738
1739 void OnPlaceObject([[maybe_unused]] Point pt, TileIndex tile) override
1740 {
1741 const HouseSpec *spec = HouseSpec::Get(HousePickerCallbacks::sel_type);
1742 Command<CMD_PLACE_HOUSE>::Post(STR_ERROR_CAN_T_BUILD_HOUSE, CcPlaySound_CONSTRUCTION_OTHER, tile, spec->Index());
1743 }
1744
1745 IntervalTimer<TimerWindow> view_refresh_interval = {std::chrono::milliseconds(2500), [this](auto) {
1746 /* There are four different 'views' that are random based on house tile position. As this is not
1747 * user-controllable, instead we automatically cycle through them. */
1748 HousePickerCallbacks::sel_view = (HousePickerCallbacks::sel_view + 1) % 4;
1749 this->SetDirty();
1750 }};
1751
1752 static inline HotkeyList hotkeys{"buildhouse", {
1753 Hotkey('F', "focus_filter_box", PCWHK_FOCUS_FILTER_BOX),
1754 }};
1755};
1756
1758 static constexpr NWidgetPart _nested_build_house_widgets[] = {
1759 NWidget(NWID_HORIZONTAL),
1760 NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
1761 NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_HOUSE_PICKER_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1762 NWidget(WWT_SHADEBOX, COLOUR_DARK_GREEN),
1763 NWidget(WWT_DEFSIZEBOX, COLOUR_DARK_GREEN),
1764 NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN),
1765 EndContainer(),
1766 NWidget(NWID_HORIZONTAL),
1767 NWidget(NWID_VERTICAL),
1768 NWidgetFunction(MakePickerClassWidgets),
1769 NWidget(WWT_PANEL, COLOUR_DARK_GREEN),
1770 NWidget(NWID_VERTICAL), SetPIP(0, WidgetDimensions::unscaled.vsep_picker, 0), SetPadding(WidgetDimensions::unscaled.picker),
1771 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_BH_INFO), SetFill(1, 1), SetMinimalTextLines(10, 0),
1772 EndContainer(),
1773 EndContainer(),
1774 EndContainer(),
1775 NWidgetFunction(MakePickerTypeWidgets),
1776 EndContainer(),
1777};
1778
1779static WindowDesc _build_house_desc(
1780 WDP_AUTO, "build_house", 0, 0,
1781 WC_BUILD_HOUSE, WC_BUILD_TOOLBAR,
1782 WDF_CONSTRUCTION,
1783 _nested_build_house_widgets,
1784 &BuildHouseWindow::hotkeys
1785);
1786
1787void ShowBuildHousePicker(Window *parent)
1788{
1789 if (BringWindowToFrontById(WC_BUILD_HOUSE, 0)) return;
1790 new BuildHouseWindow(_build_house_desc, parent);
1791}
backup_type.hpp
Class for backupping variables and making sure they are restored later.
HasBit
debug_inline constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
Definition bitmath_func.hpp:103
CLRBITS
#define CLRBITS(x, y)
Clears several bits in a variable.
Definition bitmath_func.hpp:166
SetBit
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
Definition bitmath_func.hpp:121
FindFirstBit
constexpr uint8_t FindFirstBit(T x)
Search the first set bit in a value.
Definition bitmath_func.hpp:213
GB
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.
Definition bitmath_func.hpp:32
CargoID
uint8_t CargoID
Cargo slots to indicate a cargo type within a game.
Definition cargo_type.h:22
BuildCargoAcceptanceString
std::optional< std::string > BuildCargoAcceptanceString(const CargoArray &acceptance, StringID label)
Build comma-separated cargo acceptance string.
Definition cargotype.cpp:269
TPE_PASSENGERS
@ TPE_PASSENGERS
Cargo behaves passenger-like for production.
Definition cargotype.h:36
TPE_MAIL
@ TPE_MAIL
Cargo behaves mail-like for production.
Definition cargotype.h:37
TownAcceptanceEffect
TownAcceptanceEffect
Town growth effect when delivering cargo.
Definition cargotype.h:21
TAE_END
@ TAE_END
End of town effects.
Definition cargotype.h:29
CommandCost
Common return value for all commands.
Definition command_type.h:23
CommandCost::Succeeded
bool Succeeded() const
Did this command succeed?
Definition command_type.h:162
CommandCost::Failed
bool Failed() const
Did this command fail?
Definition command_type.h:171
GUIList
List template of 'things' T to sort in a GUI.
Definition sortlist_type.h:47
GUIList::RebuildDone
void RebuildDone()
Notify the sortlist that the rebuild is done.
Definition sortlist_type.h:409
GUIList::SetListing
void SetListing(Listing l)
Import sort conditions.
Definition sortlist_type.h:152
GUIList::IsDescSortOrder
bool IsDescSortOrder() const
Check if the sort order is descending.
Definition sortlist_type.h:246
GUIList::ToggleSortOrder
void ToggleSortOrder()
Toggle the sort order Since that is the worst condition for the sort function reverse the list here.
Definition sortlist_type.h:256
GUIList::NeedRebuild
bool NeedRebuild() const
Check if a rebuild is needed.
Definition sortlist_type.h:391
GUIList::ForceRebuild
void ForceRebuild()
Force that a rebuild is needed.
Definition sortlist_type.h:399
GUIList::Sort
bool Sort(Comp compare)
Sort the list.
Definition sortlist_type.h:270
GUIList::ForceResort
void ForceResort()
Force a resort next Sort call Reset the resort timer if used too.
Definition sortlist_type.h:236
GUIList::SortType
uint8_t SortType() const
Get the sorttype of the list.
Definition sortlist_type.h:114
GUIList::GetListing
Listing GetListing() const
Export current sort conditions.
Definition sortlist_type.h:138
GUIList::SetSortFuncs
void SetSortFuncs(std::span< SortFunction *const > n_funcs)
Hand the sort function pointers to the GUIList.
Definition sortlist_type.h:297
GUIList::SetSortType
void SetSortType(uint8_t n_type)
Set the sorttype of the list.
Definition sortlist_type.h:124
HousePickerCallbacks
Definition town_gui.cpp:1476
HousePickerCallbacks::GetPickerItem
PickerItem GetPickerItem(int cls_id, int id) const override
Get data about an item.
Definition town_gui.cpp:1552
HousePickerCallbacks::IsActive
bool IsActive() const override
Should picker class/type selection be enabled?
Definition town_gui.cpp:1529
HousePickerCallbacks::SetClimateMask
void SetClimateMask()
Set climate mask for filtering buildings from current landscape.
Definition town_gui.cpp:1483
HousePickerCallbacks::SetSelectedClass
void SetSelectedClass(int cls_id) const override
Set the selected class.
Definition town_gui.cpp:1537
HousePickerCallbacks::GetClassTooltip
StringID GetClassTooltip() const override
Get the tooltip string for the class list.
Definition town_gui.cpp:1527
HousePickerCallbacks::DrawType
void DrawType(int x, int y, int, int id) const override
Draw preview image of an item.
Definition town_gui.cpp:1583
HousePickerCallbacks::sel_view
static int sel_view
Currently selected 'view'. This is not controllable as its based on random data.
Definition town_gui.cpp:1515
HousePickerCallbacks::GetClassCount
int GetClassCount() const override
Get the number of classes.
Definition town_gui.cpp:1532
HousePickerCallbacks::FillUsedItems
void FillUsedItems(std::set< PickerItem > &items) override
Fill a set with all items that are used by the current player.
Definition town_gui.cpp:1588
HousePickerCallbacks::sel_type
static int sel_type
Currently selected HouseID.
Definition town_gui.cpp:1514
HousePickerCallbacks::GetSelectedClass
int GetSelectedClass() const override
Get the index of the selected class.
Definition town_gui.cpp:1536
HousePickerCallbacks::UpdateSavedItems
std::set< PickerItem > UpdateSavedItems(const std::set< PickerItem > &src) override
Update link between grfid/localidx and class_index/index in saved items.
Definition town_gui.cpp:1600
HousePickerCallbacks::GetTypeTooltip
StringID GetTypeTooltip() const override
Get the tooltip string for the type grid.
Definition town_gui.cpp:1528
HousePickerCallbacks::SetSelectedType
void SetSelectedType(int id) const override
Set the selected type.
Definition town_gui.cpp:1560
HousePickerCallbacks::GetTypeName
StringID GetTypeName(int cls_id, int id) const override
Get the item of a type.
Definition town_gui.cpp:1562
HousePickerCallbacks::GetSelectedType
int GetSelectedType() const override
Get the selected type.
Definition town_gui.cpp:1559
HousePickerCallbacks::IsTypeAvailable
bool IsTypeAvailable(int, int id) const override
Test if an item is currently buildable.
Definition town_gui.cpp:1577
HousePickerCallbacks::HasClassChoice
bool HasClassChoice() const override
Are there multiple classes to chose from?
Definition town_gui.cpp:1531
HousePickerCallbacks::class_mask
uint8_t class_mask
Mask of available 'classes'.
Definition town_gui.cpp:1511
HousePickerCallbacks::GetTypeCount
int GetTypeCount(int cls_id) const override
Get the number of types in a class.
Definition town_gui.cpp:1546
HousePickerCallbacks::GetClassName
StringID GetClassName(int id) const override
Get the name of a class.
Definition town_gui.cpp:1539
HousePickerCallbacks::sel_class
static int sel_class
Currently selected 'class'.
Definition town_gui.cpp:1513
IntervalTimer
An interval timer will fire every interval, and will continue to fire until it is deleted.
Definition timer.h:76
Kdtree
K-dimensional tree, specialised for 2-dimensional space.
Definition kdtree.hpp:35
Kdtree::Insert
void Insert(const T &element)
Insert a single element in the tree.
Definition kdtree.hpp:398
Kdtree::Remove
void Remove(const T &element)
Remove a single element from the tree, if it exists.
Definition kdtree.hpp:417
Kdtree::Clear
void Clear()
Clear the tree.
Definition kdtree.hpp:377
NWidgetBase
Baseclass for nested widgets.
Definition widget_type.h:145
NWidgetViewport
Nested widget to display a viewport in a window.
Definition widget_type.h:680
NWidgetViewport::UpdateViewportCoordinates
void UpdateViewportCoordinates(Window *w)
Update the position and size of the viewport (after eg a resize).
Definition widget.cpp:2354
NWidgetViewport::InitializeViewport
void InitializeViewport(Window *w, std::variant< TileIndex, VehicleID > focus, ZoomLevel zoom)
Initialize the viewport of the window.
Definition widget.cpp:2345
OverflowSafeInt< int64_t >
PickerCallbacks
Class for PickerClassWindow to collect information and retain state.
Definition picker_gui.h:37
PickerWindow
Definition picker_gui.h:148
PickerWindow::DrawWidget
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
Definition picker_gui.cpp:274
PickerWindow::PCWHK_FOCUS_FILTER_BOX
@ PCWHK_FOCUS_FILTER_BOX
Focus the edit box for editing the filter string.
Definition picker_gui.h:185
PickerWindow::PFI_POSITION
@ PFI_POSITION
Update scroll positions.
Definition picker_gui.h:159
PickerWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition picker_gui.cpp:390
Scrollbar
Scrollbar data structure.
Definition widget_type.h:694
Scrollbar::SetCount
void SetCount(size_t num)
Sets the number of elements in the list.
Definition widget_type.h:780
Scrollbar::GetScrolledItemFromWidget
auto GetScrolledItemFromWidget(Tcontainer &container, int clickpos, const Window *const w, WidgetID widget, int padding=0, int line_height=-1) const
Return an iterator pointing to the element of a scrolled widget that a user clicked in.
Definition widget_type.h:879
Scrollbar::SetCapacityFromWidget
void SetCapacityFromWidget(Window *w, WidgetID widget, int padding=0)
Set capacity of visible elements from the size and resize properties of a widget.
Definition widget.cpp:2451
Scrollbar::GetCount
size_type GetCount() const
Gets the number of elements in the list.
Definition widget_type.h:722
Scrollbar::GetVisibleRangeIterators
auto GetVisibleRangeIterators(Tcontainer &container) const
Get a pair of iterators for the range of visible elements in a container.
Definition widget_type.h:860
Ticks::DAY_TICKS
static constexpr TimerGameTick::Ticks DAY_TICKS
1 day is 74 ticks; TimerGameCalendar::date_fract used to be uint16_t and incremented by 885.
Definition timer_game_tick.h:75
TimerGameConst< struct Calendar >::MIN_YEAR
static constexpr TimerGame< struct Calendar >::Year MIN_YEAR
The absolute minimum year in OTTD.
Definition timer_game_common.h:176
TimerGameConst< struct Calendar >::MAX_YEAR
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,...
Definition timer_game_common.h:173
TimerGameEconomy::UsingWallclockUnits
static bool UsingWallclockUnits(bool newgame=false)
Check if we are using wallclock units.
Definition timer_game_economy.cpp:97
WidgetDimensions::framerect
RectPadding framerect
Standard padding inside many panels.
Definition window_gui.h:42
WidgetDimensions::scaled
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition window_gui.h:28
WidgetDimensions::vsep_normal
int vsep_normal
Normal vertical spacing.
Definition window_gui.h:60
WidgetDimensions::unscaled
static const WidgetDimensions unscaled
Unscaled widget dimensions.
Definition window_gui.h:96
WidgetDimensions::hsep_normal
int hsep_normal
Normal horizontal spacing.
Definition window_gui.h:63
command_func.h
Functions related to commands.
DC_EXEC
@ DC_EXEC
execute the given command
Definition command_type.h:376
Commands
Commands
List of commands.
Definition command_type.h:187
company_base.h
Definition of stuff that is very close to a company, like the company struct itself.
DrawCompanyIcon
void DrawCompanyIcon(CompanyID c, int x, int y)
Draw the icon of a company.
Definition company_cmd.cpp:161
GetAvailableMoney
Money GetAvailableMoney(CompanyID company)
Get the amount of money that a company has available, or INT64_MAX if there is no such valid company.
Definition company_cmd.cpp:216
_local_company
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition company_cmd.cpp:52
company_func.h
Functions related to companies.
company_gui.h
GUI Functions related to companies.
ShowDropDownMenu
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.
Definition dropdown.cpp:441
dropdown_func.h
Functions related to the drop down widget.
error.h
Functions related to errors.
ShowErrorMessage
void ShowErrorMessage(StringID summary_msg, int x, int y, CommandCost cc)
Display an error message in a window.
Definition error_gui.cpp:367
WL_INFO
@ WL_INFO
Used for DoCommand-like (and some non-fatal AI GUI) errors/information.
Definition error.h:24
FT_TOWN_DATA
@ FT_TOWN_DATA
town data file
Definition fileio_type.h:21
SLO_LOAD
@ SLO_LOAD
File is being loaded.
Definition fileio_type.h:55
fios.h
Declarations for savegames operations.
ShowSaveLoadDialog
void ShowSaveLoadDialog(AbstractFileType abstract_filetype, SaveLoadOperation fop)
Launch save/load dialog in the given mode.
Definition fios_gui.cpp:986
GetCharacterHeight
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Definition fontcache.cpp:77
_generating_world
bool _generating_world
Whether we are generating the map or not.
Definition genworld.cpp:67
genworld.h
Functions related to world/map generation.
maxdim
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
Definition geometry_func.cpp:22
geometry_func.hpp
Geometry functions.
GetStringHeight
int GetStringHeight(std::string_view str, int maxw, FontSize fontsize)
Calculates height of string (in pixels).
Definition gfx.cpp:704
GetSpriteSize
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition gfx.cpp:922
_shift_pressed
bool _shift_pressed
Is Shift pressed?
Definition gfx.cpp:39
GetStringBoundingBox
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition gfx.cpp:851
GetStringListBoundingBox
Dimension GetStringListBoundingBox(std::span< const StringID > list, FontSize fontsize)
Get maximum dimension of a list of strings.
Definition gfx.cpp:889
DrawString
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.
Definition gfx.cpp:657
_ctrl_pressed
bool _ctrl_pressed
Is Ctrl pressed?
Definition gfx.cpp:38
DrawSprite
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
Draw a sprite, not in a viewport.
Definition gfx.cpp:988
GetStringMultiLineBoundingBox
Dimension GetStringMultiLineBoundingBox(StringID str, const Dimension &suggestion)
Calculate string bounding box for multi-line strings.
Definition gfx.cpp:740
DrawStringMultiLine
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.
Definition gfx.cpp:774
SpriteID
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition gfx_type.h:18
FS_NORMAL
@ FS_NORMAL
Index of the normal font in the font tables.
Definition gfx_type.h:209
PaletteID
uint32_t PaletteID
The number of the palette.
Definition gfx_type.h:19
TextColour
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition gfx_type.h:260
TC_NO_SHADE
@ TC_NO_SHADE
Do not add shading to this text colour.
Definition gfx_type.h:284
NWidgetFunction
constexpr NWidgetPart NWidgetFunction(NWidgetFunctionType *func_ptr)
Obtain a nested widget (sub)tree from an external source.
Definition widget_type.h:1341
SetFill
constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
Widget part function for setting filling.
Definition widget_type.h:1181
SetPIP
constexpr NWidgetPart SetPIP(uint8_t pre, uint8_t inter, uint8_t post)
Widget part function for setting a pre/inter/post spaces.
Definition widget_type.h:1271
SetScrollbar
constexpr NWidgetPart SetScrollbar(WidgetID index)
Attach a scrollbar to a widget.
Definition widget_type.h:1295
SetPadding
constexpr NWidgetPart SetPadding(uint8_t top, uint8_t right, uint8_t bottom, uint8_t left)
Widget part function for setting additional space around a widget.
Definition widget_type.h:1228
SetDataTip
constexpr NWidgetPart SetDataTip(uint32_t data, StringID tip)
Widget part function for setting the data and tooltip.
Definition widget_type.h:1202
SetMinimalSize
constexpr NWidgetPart SetMinimalSize(int16_t x, int16_t y)
Widget part function for setting the minimal size.
Definition widget_type.h:1137
NWidget
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=-1)
Widget part function for starting a new 'real' widget.
Definition widget_type.h:1320
EndContainer
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition widget_type.h:1191
SetMinimalTextLines
constexpr NWidgetPart SetMinimalTextLines(uint8_t lines, uint8_t spacing, FontSize size=FS_NORMAL)
Widget part function for setting the minimal text lines.
Definition widget_type.h:1149
SetAspect
constexpr NWidgetPart SetAspect(float ratio, AspectFlags flags=AspectFlags::ResizeX)
Widget part function for setting the aspect ratio.
Definition widget_type.h:1306
SetResize
constexpr NWidgetPart SetResize(int16_t dx, int16_t dy)
Widget part function for setting the resize step.
Definition widget_type.h:1126
LowestSnowLine
uint8_t LowestSnowLine()
Get the lowest possible snow line height, either variable or static.
Definition landscape.cpp:632
GetSnowLine
uint8_t GetSnowLine()
Get the current snow line, either variable or static.
Definition landscape.cpp:609
Window::SetDirty
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition window.cpp:940
MarkWholeScreenDirty
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
Definition gfx.cpp:1529
gui.h
GUI functions that shouldn't be here.
ShowExtraViewportWindow
void ShowExtraViewportWindow(TileIndex tile=INVALID_TILE)
Show a new Extra Viewport window.
Definition viewport_gui.cpp:156
hotkeys.h
Hotkey related functions.
house.h
definition of HouseSpec and accessors
NEW_HOUSE_OFFSET
static const HouseID NEW_HOUSE_OFFSET
Offset for new houses.
Definition house.h:26
TOWN_HOUSE_COMPLETED
static const uint8_t TOWN_HOUSE_COMPLETED
Simple value that indicates the house has reached the final stage of construction.
Definition house.h:23
HouseZones
HouseZones
Definition house.h:66
HZ_SUBARTC_BELOW
@ HZ_SUBARTC_BELOW
13 2000 can appear in sub-arctic climate below the snow line
Definition house.h:76
HZ_ZONALL
@ HZ_ZONALL
1F This is just to englobe all above types at once
Definition house.h:73
HZ_TEMP
@ HZ_TEMP
12 1000 can appear in temperate climate
Definition house.h:75
HZ_TOYLND
@ HZ_TOYLND
15 8000 can appear in toyland climate
Definition house.h:78
HZ_SUBTROPIC
@ HZ_SUBTROPIC
14 4000 can appear in subtropical climate
Definition house.h:77
HZ_SUBARTC_ABOVE
@ HZ_SUBARTC_ABOVE
11 800 can appear in sub-arctic climate above the snow line
Definition house.h:74
HouseID
uint16_t HouseID
OpenTTD ID of house types.
Definition house_type.h:13
landscape.h
Functions related to OTTD's landscape.
RemapCoords
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.
Definition landscape.h:79
DoZoomInOutWindow
bool DoZoomInOutWindow(ZoomStateChange how, Window *w)
Zooms a viewport in a window in or out.
Definition main_gui.cpp:93
HandlePlacePushButton
bool HandlePlacePushButton(Window *w, WidgetID widget, CursorID cursor, HighLightStyle mode)
This code is shared for the majority of the pushbuttons.
Definition main_gui.cpp:63
RoundDivSU
constexpr int RoundDivSU(int a, uint b)
Computes round(a / b) for signed a and unsigned b.
Definition math_func.hpp:342
ShowQueryString
void ShowQueryString(StringID str, StringID caption, uint maxsize, Window *parent, CharSetFilter afilter, QueryStringFlags flags)
Show a query popup window with a textbox in it.
Definition misc_gui.cpp:1059
_networking
bool _networking
are we in networking mode?
Definition network.cpp:65
_network_server
bool _network_server
network-server is active
Definition network.cpp:66
network.h
Basic functions/variables used all over the place.
CBID_HOUSE_COLOUR
@ CBID_HOUSE_COLOUR
Called to determine the colour of a town building.
Definition newgrf_callbacks.h:75
CBID_NO_CALLBACK
@ CBID_NO_CALLBACK
Set when using the callback resolve system, but not to resolve a callback.
Definition newgrf_callbacks.h:22
CBID_HOUSE_CUSTOM_NAME
@ CBID_HOUSE_CUSTOM_NAME
Called on the Get Tile Description for an house tile.
Definition newgrf_callbacks.h:224
CALLBACK_FAILED
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
Definition newgrf_callbacks.h:427
CBM_HOUSE_COLOUR
@ CBM_HOUSE_COLOUR
decide the colour of the building
Definition newgrf_callbacks.h:341
newgrf_cargo.h
Cargo support for NewGRFs.
ErrorUnknownCallbackResult
void ErrorUnknownCallbackResult(uint32_t grfid, uint16_t cbid, uint16_t cb_res)
Record that a NewGRF returned an unknown/invalid callback result.
Definition newgrf_commons.cpp:505
GetBuildingHouseIDCounts
std::span< const uint > GetBuildingHouseIDCounts()
Get read-only span of total HouseID building counts.
Definition newgrf_house.cpp:179
newgrf_house.h
Functions related to NewGRF houses.
GetGRFStringID
StringID GetGRFStringID(uint32_t grfid, StringID stringid)
Returns the index for this stringid associated with its grfID.
Definition newgrf_text.cpp:587
newgrf_text.h
Header of Action 04 "universal holder" structure and functions.
UpdateOSKOriginalText
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...
Definition osk_gui.cpp:410
MakePickerClassWidgets
std::unique_ptr< NWidgetBase > MakePickerClassWidgets()
Create nested widgets for the class picker widgets.
Definition picker_gui.cpp:623
MakePickerTypeWidgets
std::unique_ptr< NWidgetBase > MakePickerTypeWidgets()
Create nested widgets for the type picker widgets.
Definition picker_gui.cpp:646
picker_gui.h
Functions/types etc.
querystring_gui.h
Base for the GUIs that have an edit box in them.
_interactive_random
Randomizer _interactive_random
Random used everywhere else, where it does not (directly) influence the game state.
Definition random_func.cpp:37
UpdateNearestTownForRoadTiles
void UpdateNearestTownForRoadTiles(bool invalidate)
Updates cached nearest town for all road tiles.
Definition road_cmd.cpp:1918
road_cmd.h
Road related functions.
safeguards.h
A number of safeguards to prevent using unsafe methods.
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition settings.cpp:57
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition settings.cpp:56
SWS_OFF
@ SWS_OFF
Scroll wheel has no effect.
Definition settings_type.h:133
sortlist_type.h
Base types for having sorted lists in GUIs.
sound_func.h
Functions related to sound.
SND_1F_CONSTRUCTION_OTHER
@ SND_1F_CONSTRUCTION_OTHER
29 == 0x1D Construction: other (non-water, non-rail, non-bridge)
Definition sound_type.h:76
DrawNewGRFTileSeqInGUI
void DrawNewGRFTileSeqInGUI(int x, int y, const DrawTileSprites *dts, uint32_t stage, PaletteID default_palette)
Draw NewGRF object in GUI.
Definition sprite.h:133
GroundSpritePaletteTransform
PaletteID GroundSpritePaletteTransform(SpriteID image, PaletteID pal, PaletteID default_pal)
Applies PALETTE_MODIFIER_COLOUR to a palette entry of a ground sprite.
Definition sprite.h:168
SPRITE_MODIFIER_CUSTOM_SPRITE
static constexpr uint8_t SPRITE_MODIFIER_CUSTOM_SPRITE
these masks change the colours of the palette for a sprite.
Definition sprites.h:1545
SPRITE_WIDTH
static constexpr uint8_t SPRITE_WIDTH
number of bits for the sprite number
Definition sprites.h:1535
stdafx.h
Definition of base types and functions in a cross-platform compatible way.
StrNaturalCompare
int StrNaturalCompare(std::string_view s1, std::string_view s2, bool ignore_garbage_at_front)
Compares two strings using case insensitive natural sort.
Definition string.cpp:589
string_func.h
Functions related to low-level strings.
CS_ALPHANUMERAL
@ CS_ALPHANUMERAL
Both numeric and alphabetic and spaces and stuff.
Definition string_type.h:25
stringfilter_type.h
Searching and filtering using a stringterm.
SetDParam
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
Definition strings.cpp:104
GetString
std::string GetString(StringID string)
Resolve the given StringID into a std::string with all the associated DParam lookups and formatting.
Definition strings.cpp:333
_current_text_dir
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition strings.cpp:56
SetDParamStr
void SetDParamStr(size_t n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
Definition strings.cpp:371
SetDParamMaxDigits
void SetDParamMaxDigits(size_t n, uint count, FontSize size)
Set DParam n to some number that is suitable for string size computations.
Definition strings.cpp:143
strings_func.h
Functions related to OTTD's strings.
TD_RTL
@ TD_RTL
Text is written right-to-left by default.
Definition strings_type.h:24
StringID
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition strings_type.h:16
INVALID_STRING_ID
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
Definition strings_type.h:17
MAX_CHAR_LENGTH
static const int MAX_CHAR_LENGTH
Max. length of UTF-8 encoded unicode character.
Definition strings_type.h:18
Backup
Class to backup a specific variable and restore it later.
Definition backup_type.hpp:21
BuildHouseWindow
Definition town_gui.cpp:1629
BuildHouseWindow::GetHouseYear
static std::string GetHouseYear(TimerGameCalendar::Year min_year, TimerGameCalendar::Year max_year)
Get a date range string for house availability year.
Definition town_gui.cpp:1664
BuildHouseWindow::OnPlaceObject
void OnPlaceObject(Point pt, TileIndex tile) override
The user clicked some place on the map when a tile highlight mode has been set.
Definition town_gui.cpp:1739
BuildHouseWindow::DrawWidget
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
Definition town_gui.cpp:1718
BuildHouseWindow::GetHouseInformation
static std::string GetHouseInformation(const HouseSpec *hs)
Get information string for a house.
Definition town_gui.cpp:1687
BuildHouseWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition town_gui.cpp:1727
CargoSpec
Specification of a cargo type.
Definition cargotype.h:76
CargoSpec::Index
CargoID Index() const
Determines index of this cargospec.
Definition cargotype.h:110
CargoSpec::name
StringID name
Name of this type of cargo.
Definition cargotype.h:93
CargoSpec::town_production_cargoes
static std::array< std::vector< const CargoSpec * >, NUM_TPE > town_production_cargoes
List of cargo specs for each Town Product Effect.
Definition cargotype.h:27
ClientSettings::sound
SoundSettings sound
sound effect settings
Definition settings_type.h:613
ClientSettings::gui
GUISettings gui
settings related to the GUI
Definition settings_type.h:610
CommandHelper
Definition command_func.h:83
Company
Definition company_base.h:133
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition geometry_type.hpp:30
DrawBuildingsTileStruct
This structure is the same for both Industries and Houses.
Definition sprite.h:67
DrawTileSprites
Ground palette sprite of a tile, together with its sprite layout.
Definition sprite.h:58
DrawTileSprites::ground
PalSpriteID ground
Palette and sprite for the ground.
Definition sprite.h:59
EconomySettings::bribe
bool bribe
enable bribing the local authority
Definition settings_type.h:515
EconomySettings::found_town
TownFounding found_town
town founding.
Definition settings_type.h:531
EconomySettings::exclusive_rights
bool exclusive_rights
allow buying exclusive rights
Definition settings_type.h:519
EconomySettings::town_layout
TownLayout town_layout
select town layout,
Definition settings_type.h:528
EconomySettings::station_noise_level
bool station_noise_level
build new airports when the town noise level is still within accepted limits
Definition settings_type.h:532
EconomySettings::fund_buildings
bool fund_buildings
allow funding new buildings
Definition settings_type.h:520
EconomySettings::fund_roads
bool fund_roads
allow funding local road reconstruction
Definition settings_type.h:521
FoundTownWindow
Found a town window class.
Definition town_gui.cpp:1166
FoundTownWindow::townnameparts
uint32_t townnameparts
Generated town name.
Definition town_gui.cpp:1173
FoundTownWindow::town_layout
TownLayout town_layout
Selected town layout.
Definition town_gui.cpp:1169
FoundTownWindow::OnPlaceObject
void OnPlaceObject(Point pt, TileIndex tile) override
The user clicked some place on the map when a tile highlight mode has been set.
Definition town_gui.cpp:1318
FoundTownWindow::townname_editbox
QueryString townname_editbox
Townname editbox.
Definition town_gui.cpp:1171
FoundTownWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition town_gui.cpp:1334
FoundTownWindow::OnInit
void OnInit() override
Notification that the nested widget tree gets initialized.
Definition town_gui.cpp:1190
FoundTownWindow::town_size
TownSize town_size
Selected town size.
Definition town_gui.cpp:1168
FoundTownWindow::townnamevalid
bool townnamevalid
Is generated town name valid?
Definition town_gui.cpp:1172
FoundTownWindow::params
TownNameParams params
Town name parameters.
Definition town_gui.cpp:1174
FoundTownWindow::OnClick
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition town_gui.cpp:1257
FoundTownWindow::OnPlaceObjectAbort
void OnPlaceObjectAbort() override
The user cancelled a tile highlight mode that has been set.
Definition town_gui.cpp:1323
FoundTownWindow::city
bool city
Are we building a city?
Definition town_gui.cpp:1170
GRFFilePropsBase::local_id
uint16_t local_id
id defined by the grf file for this entity
Definition newgrf_commons.h:311
GRFFilePropsBase::grfid
uint32_t grfid
grfid that introduced this entity.
Definition newgrf_commons.h:312
GRFFilePropsBase::grffile
const struct GRFFile * grffile
grf file that introduced this entity
Definition newgrf_commons.h:313
GRFFilePropsBase::spritegroup
std::array< const struct SpriteGroup *, Tcnt > spritegroup
pointers to the different sprites of the entity
Definition newgrf_commons.h:314
GUISettings::persistent_buildingtools
bool persistent_buildingtools
keep the building tools active after usage
Definition settings_type.h:198
GUISettings::scrollwheel_scrolling
uint8_t scrollwheel_scrolling
scrolling using the scroll wheel?
Definition settings_type.h:177
GameCreationSettings::landscape
uint8_t landscape
the landscape we're currently in
Definition settings_type.h:368
GameSettings::economy
EconomySettings economy
settings to change the economy
Definition settings_type.h:602
GameSettings::game_creation
GameCreationSettings game_creation
settings used during the creation of a game (map)
Definition settings_type.h:593
HotkeyList
List of hotkeys for a window.
Definition hotkeys.h:37
Hotkey
All data for a single hotkey.
Definition hotkeys.h:21
HouseResolverObject
Resolver object to be used for houses (feature 07 spritegroups).
Definition newgrf_house.h:52
HouseSpec
Definition house.h:93
HouseSpec::enabled
bool enabled
the house is available to build (true by default, but can be disabled by newgrf)
Definition house.h:106
HouseSpec::Get
static HouseSpec * Get(size_t house_id)
Get the spec for a house ID.
Definition newgrf_house.cpp:69
HouseSpec::building_flags
BuildingFlags building_flags
some flags that describe the house (size, stadium etc...)
Definition house.h:104
HouseSpec::max_year
TimerGameCalendar::Year max_year
last year it can be built
Definition house.h:96
HouseSpec::population
uint8_t population
population (Zero on other tiles in multi tile house.)
Definition house.h:97
HouseSpec::min_year
TimerGameCalendar::Year min_year
introduction year of the house
Definition house.h:95
HouseSpec::Index
HouseID Index() const
Gets the index of this spec.
Definition newgrf_house.cpp:59
HouseSpec::building_name
StringID building_name
building name
Definition house.h:99
HouseSpec::grf_prop
GRFFileProps grf_prop
Properties related the the grf file.
Definition house.h:109
HouseSpec::random_colour
Colours random_colour[4]
4 "random" colours
Definition house.h:111
HouseSpec::callback_mask
uint16_t callback_mask
Bitmask of house callbacks that have to be called.
Definition house.h:110
HouseSpec::building_availability
HouseZones building_availability
where can it be built (climates, zones)
Definition house.h:105
HouseSpec::Specs
static std::vector< HouseSpec > & Specs()
Get a reference to all HouseSpecs.
Definition newgrf_house.cpp:50
Listing
Data structure describing how to show the list (what sort direction and criteria).
Definition sortlist_type.h:30
Listing::order
bool order
Ascending/descending.
Definition sortlist_type.h:31
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition widget_type.h:1075
PalSpriteID::sprite
SpriteID sprite
The 'real' sprite.
Definition gfx_type.h:24
PalSpriteID::pal
PaletteID pal
The palette (use PAL_NONE) if not needed)
Definition gfx_type.h:25
PickerItem
Definition picker_gui.h:23
Point
Coordinates of a point in 2D.
Definition geometry_type.hpp:21
Pool::PoolItem::index
Tindex index
Index of this pool item.
Definition pool_type.hpp:238
Pool::PoolItem<&_town_pool >::GetNumItems
static size_t GetNumItems()
Returns number of valid items in the pool.
Definition pool_type.hpp:369
Pool::PoolItem<&_company_pool >::IsValidID
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Definition pool_type.hpp:328
Pool::PoolItem<&_company_pool >::Iterate
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Definition pool_type.hpp:388
Pool::PoolItem<&_town_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition pool_type.hpp:339
QueryString
Data stored about a string that can be modified in the GUI.
Definition querystring_gui.h:20
QueryString::cancel_button
int cancel_button
Widget button of parent window to simulate when pressing CANCEL in OSK.
Definition querystring_gui.h:28
QueryString::ACTION_CLEAR
static const int ACTION_CLEAR
Clear editbox.
Definition querystring_gui.h:24
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition geometry_type.hpp:75
Rect::WithWidth
Rect WithWidth(int width, bool end) const
Copy Rect and set its width.
Definition geometry_type.hpp:185
Rect::Shrink
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Definition geometry_type.hpp:98
Rect::Indent
Rect Indent(int indent, bool end) const
Copy Rect and indent it from its position.
Definition geometry_type.hpp:198
ResizeInfo::step_height
uint step_height
Step-size of height resize changes.
Definition window_gui.h:214
SetBitIterator
Iterable ensemble of each set bit in a value.
Definition bitmath_func.hpp:301
SoundSettings::confirm
bool confirm
Play sound effect on successful constructions or other actions.
Definition settings_type.h:248
SpriteGroup
Definition newgrf_spritegroup.h:57
SpriteGroup::Resolve
virtual const SpriteGroup * Resolve(ResolverObject &object) const
Base sprite group resolver.
Definition newgrf_spritegroup.h:61
StringFilter
String filter and state.
Definition stringfilter_type.h:30
StringFilter::IsEmpty
bool IsEmpty() const
Check whether any filter words were entered.
Definition stringfilter_type.h:60
StringFilter::SetFilterTerm
void SetFilterTerm(const char *str)
Set the term to filter on.
Definition stringfilter.cpp:28
StringFilter::ResetState
void ResetState()
Reset the matching state to process a new item.
Definition stringfilter.cpp:98
StringFilter::AddLine
void AddLine(const char *str)
Pass another text line from the current item to the filter.
Definition stringfilter.cpp:114
StringFilter::GetState
bool GetState() const
Get the matching state of the current item.
Definition stringfilter_type.h:71
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > >
Textbuf::DeleteAll
void DeleteAll()
Delete every character in the textbuffer.
Definition textbuf.cpp:114
Textbuf::Assign
void Assign(StringID string)
Render a string into the textbuffer.
Definition textbuf.cpp:431
Textbuf::buf
char *const buf
buffer in which text is saved
Definition textbuf_type.h:32
TileLayoutSpriteGroup
Action 2 sprite layout for houses, industry tiles, objects and airport tiles.
Definition newgrf_spritegroup.h:248
TownAuthorityWindow
Town authority window.
Definition town_gui.cpp:80
TownAuthorityWindow::SetStringParameters
void SetStringParameters(WidgetID widget) const override
Initialize string parameters for a widget.
Definition town_gui.cpp:245
TownAuthorityWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition town_gui.cpp:339
TownAuthorityWindow::DrawActions
void DrawActions()
Draws the contents of the actions panel.
Definition town_gui.cpp:223
TownAuthorityWindow::icon_size
Dimension icon_size
Dimensions of company icon.
Definition town_gui.cpp:89
TownAuthorityWindow::OnInit
void OnInit() override
Notification that the nested widget tree gets initialized.
Definition town_gui.cpp:147
TownAuthorityWindow::DrawWidget
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
Definition town_gui.cpp:250
TownAuthorityWindow::UpdateWidgetSize
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.
Definition town_gui.cpp:267
TownAuthorityWindow::town
Town * town
Town being displayed.
Definition town_gui.cpp:82
TownAuthorityWindow::enabled_actions
TownActions enabled_actions
Actions that are enabled in settings.
Definition town_gui.cpp:85
TownAuthorityWindow::sel_index
int sel_index
Currently selected town action, 0 to TACT_COUNT-1, -1 means no action selected.
Definition town_gui.cpp:83
TownAuthorityWindow::available_actions
TownActions available_actions
Actions that are available to execute for the current company.
Definition town_gui.cpp:86
TownAuthorityWindow::OnClick
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition town_gui.cpp:299
TownAuthorityWindow::DrawRatings
void DrawRatings()
Draw the contents of the ratings panel.
Definition town_gui.cpp:171
TownAuthorityWindow::GetNthSetBit
int GetNthSetBit(int n)
Get the position of the Nth set bit.
Definition town_gui.cpp:100
TownAuthorityWindow::displayed_actions_on_previous_painting
uint displayed_actions_on_previous_painting
Actions that were available on the previous call to OnPaint()
Definition town_gui.cpp:84
TownAuthorityWindow::exclusive_size
Dimension exclusive_size
Dimensions of exlusive icon.
Definition town_gui.cpp:90
TownAuthorityWindow::redraw_interval
IntervalTimer< TimerWindow > redraw_interval
Redraw the whole window on a regular interval.
Definition town_gui.cpp:335
TownAuthorityWindow::GetEnabledActions
static TownActions GetEnabledActions()
Gets all town authority actions enabled in settings.
Definition town_gui.cpp:116
TownAuthorityWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition town_gui.cpp:153
TownCache::population
uint32_t population
Current population of people.
Definition town.h:44
TownCache::num_houses
uint32_t num_houses
Amount of houses.
Definition town.h:43
TownDirectoryWindow
Town directory window class.
Definition town_gui.cpp:732
TownDirectoryWindow::sorter_funcs
static const std::initializer_list< GUITownList::SortFunction *const > sorter_funcs
Available town directory sorting functions.
Definition town_gui.cpp:1070
TownDirectoryWindow::DrawWidget
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
Definition town_gui.cpp:859
TownDirectoryWindow::TownPopulationSorter
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).
Definition town_gui.cpp:783
TownDirectoryWindow::rebuild_interval
IntervalTimer< TimerWindow > rebuild_interval
Redraw the whole window on a regular interval.
Definition town_gui.cpp:1009
TownDirectoryWindow::OnDropdownSelect
void OnDropdownSelect(WidgetID widget, int index) override
A dropdown option associated to this window has been selected.
Definition town_gui.cpp:991
TownDirectoryWindow::townname_editbox
QueryString townname_editbox
Filter editbox.
Definition town_gui.cpp:746
TownDirectoryWindow::OnEditboxChanged
void OnEditboxChanged(WidgetID wid) override
The text in an editbox has been edited.
Definition town_gui.cpp:1019
TownDirectoryWindow::TownRatingSorter
static bool TownRatingSorter(const Town *const &a, const Town *const &b, const bool &order)
Sort by town rating.
Definition town_gui.cpp:792
TownDirectoryWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition town_gui.cpp:1014
TownDirectoryWindow::string_filter
StringFilter string_filter
Filter for towns.
Definition town_gui.cpp:745
TownDirectoryWindow::SetStringParameters
void SetStringParameters(WidgetID widget) const override
Initialize string parameters for a widget.
Definition town_gui.cpp:831
TownDirectoryWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition town_gui.cpp:1032
TownDirectoryWindow::OnHotkey
EventState OnHotkey(int hotkey) override
A hotkey has been pressed.
Definition town_gui.cpp:1049
TownDirectoryWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition town_gui.cpp:1002
TownDirectoryWindow::OnClick
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition town_gui.cpp:954
TownDirectoryWindow::GetTownString
static StringID GetTownString(const Town *t)
Get the string to draw the town name.
Definition town_gui.cpp:854
TownDirectoryWindow::TownNameSorter
static bool TownNameSorter(const Town *const &a, const Town *const &b, const bool &)
Sort by town name.
Definition town_gui.cpp:777
TownDirectoryWindow::UpdateWidgetSize
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.
Definition town_gui.cpp:905
TownNameParams
Struct holding parameters used to generate town name.
Definition townname_type.h:28
TownViewWindow
Definition town_gui.cpp:364
TownViewWindow::OnClick
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition town_gui.cpp:500
TownViewWindow::town
Town * town
Town displayed by the window.
Definition town_gui.cpp:366
TownViewWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition town_gui.cpp:607
TownViewWindow::UpdateWidgetSize
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.
Definition town_gui.cpp:535
TownViewWindow::DrawWidget
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
Definition town_gui.cpp:407
TownViewWindow::GetDesiredInfoHeight
uint GetDesiredInfoHeight(int width) const
Gets the desired height for the information panel.
Definition town_gui.cpp:548
TownViewWindow::OnMouseWheel
void OnMouseWheel(int wheel) override
The mouse wheel has been turned.
Definition town_gui.cpp:595
TownViewWindow::Close
void Close(int data=0) override
Hide the window and all its child windows, and mark them for a later deletion.
Definition town_gui.cpp:388
TownViewWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition town_gui.cpp:399
TownViewWindow::OnQueryTextFinished
void OnQueryTextFinished(std::optional< std::string > str) override
The query window opened from this window has closed.
Definition town_gui.cpp:615
TownViewWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition town_gui.cpp:585
TownViewWindow::SetStringParameters
void SetStringParameters(WidgetID widget) const override
Initialize string parameters for a widget.
Definition town_gui.cpp:394
Town
Town data structure.
Definition town.h:54
Town::larger_town
bool larger_town
if this is a larger town and should grow more quickly
Definition town.h:101
Town::supplied
TransportedCargoStat< uint32_t > supplied[NUM_CARGO]
Cargo statistics about supplied cargo.
Definition town.h:79
Town::xy
TileIndex xy
town center tile
Definition town.h:55
Town::fund_buildings_months
uint8_t fund_buildings_months
fund buildings program in action?
Definition town.h:98
Town::noise_reached
uint16_t noise_reached
level of noise that all the airports are generating
Definition town.h:68
Town::ratings
int16_t ratings[MAX_COMPANIES]
ratings of each company for this town
Definition town.h:77
Town::received
TransportedCargoStat< uint16_t > received[NUM_TAE]
Cargo statistics about received cargotypes.
Definition town.h:80
Town::MaxTownNoise
uint16_t MaxTownNoise() const
Calculate the max town noise.
Definition town.h:125
Town::flags
uint8_t flags
See TownFlags.
Definition town.h:66
Town::cache
TownCache cache
Container for all cacheable data.
Definition town.h:57
Town::exclusivity
CompanyID exclusivity
which company has exclusivity
Definition town.h:75
Town::show_zone
bool show_zone
NOSAVE: mark town to show the local authority zone in the viewports.
Definition town.h:104
Town::goal
uint32_t goal[NUM_TAE]
Amount of cargo required for the town to grow.
Definition town.h:81
Town::text
std::string text
General text with additional information.
Definition town.h:83
Town::have_ratings
CompanyMask have_ratings
which companies have a rating
Definition town.h:73
Town::growth_rate
uint16_t growth_rate
town growth rate
Definition town.h:96
TransportedCargoStat::old_max
Tstorage old_max
Maximum amount last month.
Definition town_type.h:114
TransportedCargoStat::old_act
Tstorage old_act
Actually transported last month.
Definition town_type.h:116
WindowDesc
High level window description.
Definition window_gui.h:159
Window
Data structure for an opened window.
Definition window_gui.h:273
Window::ReInit
void ReInit(int rx=0, int ry=0, bool reposition=false)
Re-initialize a window, and optionally change its size.
Definition window.cpp:952
Window::Close
virtual void Close(int data=0)
Hide the window and all its child windows, and mark them for a later deletion.
Definition window.cpp:1047
Window::SortButtonWidth
static int SortButtonWidth()
Get width of up/down arrow of sort button state.
Definition widget.cpp:781
Window::FinishInitNested
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition window.cpp:1733
Window::querystrings
std::map< WidgetID, QueryString * > querystrings
QueryString associated to WWT_EDITBOX widgets.
Definition window_gui.h:320
Window::DrawWidgets
void DrawWidgets() const
Paint all widgets of a window.
Definition widget.cpp:732
Window::InvalidateData
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing)
Definition window.cpp:3159
Window::parent
Window * parent
Parent window.
Definition window_gui.h:328
Window::SetWidgetDirty
void SetWidgetDirty(WidgetID widget_index) const
Invalidate a widget, i.e.
Definition window.cpp:551
Window::DrawSortButtonState
void DrawSortButtonState(WidgetID widget, SortButtonState state) const
Draw a sort button's up or down arrow symbol.
Definition widget.cpp:764
Window::resize
ResizeInfo resize
Resize information.
Definition window_gui.h:314
Window::CreateNestedTree
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
Definition window.cpp:1723
Window::viewport
ViewportData * viewport
Pointer to viewport data, if present.
Definition window_gui.h:318
Window::SetFocusedWidget
bool SetFocusedWidget(WidgetID widget_index)
Set focus within this window to the given widget.
Definition window.cpp:486
Window::IsWidgetLowered
bool IsWidgetLowered(WidgetID widget_index) const
Gets the lowered state of a widget.
Definition window_gui.h:497
Window::RaiseButtons
void RaiseButtons(bool autoraise=false)
Raise the buttons of the window.
Definition window.cpp:525
Window::SetWidgetLoweredState
void SetWidgetLoweredState(WidgetID widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
Definition window_gui.h:447
Window::IsShaded
bool IsShaded() const
Is window shaded currently?
Definition window_gui.h:563
Window::GetRowFromWidget
int GetRowFromWidget(int clickpos, WidgetID widget, int padding, int line_height=-1) const
Compute the row of a widget that a user clicked in.
Definition window.cpp:213
Window::GetWidget
const NWID * GetWidget(WidgetID widnum) const
Get the nested widget with number widnum from the nested widget tree.
Definition window_gui.h:977
Window::InitNested
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
Definition window.cpp:1746
Window::flags
WindowFlags flags
Window flags.
Definition window_gui.h:300
Window::GetScrollbar
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
Definition window.cpp:314
Window::SetWidgetDisabledState
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition window_gui.h:387
Window::Iterate
AllWindows< false > Iterate
Iterate all windows in whatever order is easiest.
Definition window_gui.h:927
Window::width
int width
width of the window (number of pixels to the right in x direction)
Definition window_gui.h:311
Window::window_number
WindowNumber window_number
Window number within the window class.
Definition window_gui.h:302
QSF_ENABLE_DEFAULT
@ QSF_ENABLE_DEFAULT
enable the 'Default' button ("\0" is returned)
Definition textbuf_gui.h:21
QSF_LEN_IN_CHARS
@ QSF_LEN_IN_CHARS
the length of the string is counted in characters
Definition textbuf_gui.h:22
GetTropicZone
TropicZone GetTropicZone(Tile tile)
Get the tropic zone.
Definition tile_map.h:238
TileHeight
static debug_inline uint TileHeight(Tile tile)
Returns the height of a tile.
Definition tile_map.h:29
TROPICZONE_DESERT
@ TROPICZONE_DESERT
Tile is desert.
Definition tile_type.h:78
TILE_PIXELS
static const uint TILE_PIXELS
Pixel distance between tile columns/rows in ZOOM_BASE.
Definition tile_type.h:17
INVALID_TILE
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition tile_type.h:95
tilehighlight_func.h
Functions related to tile highlights.
ResetObjectToPlace
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows).
Definition viewport.cpp:3498
SetObjectToPlaceWnd
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...
Definition viewport.cpp:3435
HT_DIAGONAL
@ HT_DIAGONAL
Also allow 'diagonal rectangles'. Only usable in combination with HT_RECT or HT_POINT.
Definition tilehighlight_type.h:28
HT_RECT
@ HT_RECT
rectangle (stations, depots, ...)
Definition tilehighlight_type.h:21
timer.h
Definition of Interval and OneShot timers.
timer_game_calendar.h
Definition of the game-calendar-timer.
timer_window.h
Definition of the Window system.
town.h
Base of the town class.
TOWN_GROWTH_WINTER
static const uint TOWN_GROWTH_WINTER
The town only needs this cargo in the winter (any amount)
Definition town.h:33
GetMaskOfTownActions
TownActions GetMaskOfTownActions(CompanyID cid, const Town *t)
Get a list of available town authority actions.
Definition town_cmd.cpp:3605
FindFirstCargoWithTownAcceptanceEffect
const CargoSpec * FindFirstCargoWithTownAcceptanceEffect(TownAcceptanceEffect effect)
Determines the first cargo with a certain town effect.
Definition town_cmd.cpp:3052
TOWN_GROWTH_DESERT
static const uint TOWN_GROWTH_DESERT
The town needs the cargo for growth when on desert (any amount)
Definition town.h:34
TOWN_IS_GROWING
@ TOWN_IS_GROWING
Conditions for town growth are met. Grow according to Town::growth_rate.
Definition town.h:196
GetWorldPopulation
uint32_t GetWorldPopulation()
Get the total population, the sum of all towns in the world.
Definition town_cmd.cpp:462
TownActions
TownActions
Town actions of a company.
Definition town.h:212
TACT_ROAD_REBUILD
@ TACT_ROAD_REBUILD
Rebuild the roads.
Definition town.h:218
TACT_BUY_RIGHTS
@ TACT_BUY_RIGHTS
Buy exclusive transport rights.
Definition town.h:221
TACT_BRIBE
@ TACT_BRIBE
Try to bribe the council.
Definition town.h:222
TACT_COUNT
@ TACT_COUNT
Number of available town actions.
Definition town.h:224
TACT_ALL
@ TACT_ALL
All possible actions.
Definition town.h:229
TACT_FUND_BUILDINGS
@ TACT_FUND_BUILDINGS
Fund new buildings.
Definition town.h:220
TACT_NONE
@ TACT_NONE
Empty action set.
Definition town.h:213
_town_action_costs
const uint8_t _town_action_costs[TACT_COUNT]
Factor in the cost of each town action.
Definition town_cmd.cpp:3314
GetAcceptedCargoOfHouse
CargoArray GetAcceptedCargoOfHouse(const HouseSpec *hs)
Get accepted cargo of a house prototype.
Definition town_cmd.cpp:853
GenerateTowns
bool GenerateTowns(TownLayout layout)
Generate a number of towns with a given layout.
Definition town_cmd.cpp:2413
town_cmd.h
Command definitions related to towns.
_nested_build_house_widgets
static constexpr NWidgetPart _nested_build_house_widgets[]
Nested widget definition for the build NewGRF rail waypoint window.
Definition town_gui.cpp:1758
DrawHouseInGUI
void DrawHouseInGUI(int x, int y, HouseID house_id, int view)
Draw a house that does not exist.
Definition town_gui.cpp:1405
DrawNewHouseTileInGUI
void DrawNewHouseTileInGUI(int x, int y, const HouseSpec *spec, HouseID house_id, int view)
Draw representation of a house tile for GUI purposes.
Definition town_gui.cpp:1367
GetHouseName
static StringID GetHouseName(const HouseSpec *hs)
Get name for a prototype house.
Definition town_gui.cpp:1459
TownDirectoryHotkeys
TownDirectoryHotkeys
Enum referring to the Hotkeys in the town directory window.
Definition town_gui.cpp:727
TDHK_FOCUS_FILTER_BOX
@ TDHK_FOCUS_FILTER_BOX
Focus the filter box.
Definition town_gui.cpp:728
town_kdtree.h
Declarations for accessing the k-d tree of towns.
TownLayout
TownLayout
Town Layouts.
Definition town_type.h:79
TF_CUSTOM_LAYOUT
@ TF_CUSTOM_LAYOUT
Allowed, with custom town layout.
Definition town_type.h:97
TownSize
TownSize
Supported initial town sizes.
Definition town_type.h:19
TSZ_MEDIUM
@ TSZ_MEDIUM
Medium town.
Definition town_type.h:21
MAX_LENGTH_TOWN_NAME_CHARS
static const uint MAX_LENGTH_TOWN_NAME_CHARS
The maximum length of a town name in characters including '\0'.
Definition town_type.h:109
town_widget.h
Types related to the town widgets.
WID_TA_EXECUTE
@ WID_TA_EXECUTE
Do-it button.
Definition town_widget.h:32
WID_TA_ACTION_INFO
@ WID_TA_ACTION_INFO
Additional information about the action.
Definition town_widget.h:31
WID_TA_RATING_INFO
@ WID_TA_RATING_INFO
Overview with ratings for each company.
Definition town_widget.h:28
WID_TA_CAPTION
@ WID_TA_CAPTION
Caption of window.
Definition town_widget.h:26
WID_TA_ZONE_BUTTON
@ WID_TA_ZONE_BUTTON
Turn on/off showing local authority zone.
Definition town_widget.h:27
WID_TA_COMMAND_LIST
@ WID_TA_COMMAND_LIST
List of commands for the player.
Definition town_widget.h:29
WID_TV_VIEWPORT
@ WID_TV_VIEWPORT
View of the center of the town.
Definition town_widget.h:38
WID_TV_INFO
@ WID_TV_INFO
General information about the town.
Definition town_widget.h:39
WID_TV_EXPAND
@ WID_TV_EXPAND
Expand this town (scenario editor only).
Definition town_widget.h:44
WID_TV_CATCHMENT
@ WID_TV_CATCHMENT
Toggle catchment area highlight.
Definition town_widget.h:43
WID_TV_SHOW_AUTHORITY
@ WID_TV_SHOW_AUTHORITY
Show the town authority window.
Definition town_widget.h:41
WID_TV_CHANGE_NAME
@ WID_TV_CHANGE_NAME
Change the name of this town.
Definition town_widget.h:42
WID_TV_CENTER_VIEW
@ WID_TV_CENTER_VIEW
Center the main view on this town.
Definition town_widget.h:40
WID_TV_DELETE
@ WID_TV_DELETE
Delete this town (scenario editor only).
Definition town_widget.h:45
WID_TV_CAPTION
@ WID_TV_CAPTION
Caption of window.
Definition town_widget.h:37
WID_TF_LAYOUT_RANDOM
@ WID_TF_LAYOUT_RANDOM
Selection for a randomly chosen town layout.
Definition town_widget.h:69
WID_TF_LOAD_FROM_FILE
@ WID_TF_LOAD_FROM_FILE
Load town data from file.
Definition town_widget.h:54
WID_TF_SIZE_SEL
@ WID_TF_SIZE_SEL
Container of town size buttons.
Definition town_widget.h:58
WID_TF_SIZE_LARGE
@ WID_TF_SIZE_LARGE
Selection for a large town.
Definition town_widget.h:61
WID_TF_NEW_TOWN
@ WID_TF_NEW_TOWN
Create a new town.
Definition town_widget.h:50
WID_TF_EXPAND_ALL_TOWNS
@ WID_TF_EXPAND_ALL_TOWNS
Make all towns grow slightly.
Definition town_widget.h:55
WID_TF_MANY_RANDOM_TOWNS
@ WID_TF_MANY_RANDOM_TOWNS
Randomly place many towns.
Definition town_widget.h:53
WID_TF_SIZE_SMALL
@ WID_TF_SIZE_SMALL
Selection for a small town.
Definition town_widget.h:59
WID_TF_LAYOUT_GRID2
@ WID_TF_LAYOUT_GRID2
Selection for the 2x2 grid town layout.
Definition town_widget.h:67
WID_TF_LAYOUT_ORIGINAL
@ WID_TF_LAYOUT_ORIGINAL
Selection for the original town layout.
Definition town_widget.h:65
WID_TF_SIZE_RANDOM
@ WID_TF_SIZE_RANDOM
Selection for a randomly sized town.
Definition town_widget.h:62
WID_TF_TOWN_NAME_EDITBOX
@ WID_TF_TOWN_NAME_EDITBOX
Editor for the town name.
Definition town_widget.h:56
WID_TF_TOWN_ACTION_SEL
@ WID_TF_TOWN_ACTION_SEL
Container of town action buttons.
Definition town_widget.h:51
WID_TF_SIZE_MEDIUM
@ WID_TF_SIZE_MEDIUM
Selection for a medium town.
Definition town_widget.h:60
WID_TF_CITY
@ WID_TF_CITY
Selection for the town's city state.
Definition town_widget.h:63
WID_TF_RANDOM_TOWN
@ WID_TF_RANDOM_TOWN
Randomly place a town.
Definition town_widget.h:52
WID_TF_LAYOUT_BETTER
@ WID_TF_LAYOUT_BETTER
Selection for the better town layout.
Definition town_widget.h:66
WID_TF_ROAD_LAYOUT_SEL
@ WID_TF_ROAD_LAYOUT_SEL
Container of town road layout buttons.
Definition town_widget.h:64
WID_TF_LAYOUT_GRID3
@ WID_TF_LAYOUT_GRID3
Selection for the 3x3 grid town layout.
Definition town_widget.h:68
WID_TF_TOWN_NAME_RANDOM
@ WID_TF_TOWN_NAME_RANDOM
Generate a random town name.
Definition town_widget.h:57
WID_TD_LIST
@ WID_TD_LIST
List of towns.
Definition town_widget.h:19
WID_TD_CAPTION
@ WID_TD_CAPTION
Caption of the window.
Definition town_widget.h:15
WID_TD_FILTER
@ WID_TD_FILTER
Filter of name.
Definition town_widget.h:18
WID_TD_SORT_ORDER
@ WID_TD_SORT_ORDER
Direction of sort dropdown.
Definition town_widget.h:16
WID_TD_WORLD_POPULATION
@ WID_TD_WORLD_POPULATION
The world's population.
Definition town_widget.h:21
WID_TD_SCROLLBAR
@ WID_TD_SCROLLBAR
Scrollbar for the town list.
Definition town_widget.h:20
WID_TD_SORT_CRITERIA
@ WID_TD_SORT_CRITERIA
Criteria of sort dropdown.
Definition town_widget.h:17
WID_BH_INFO
@ WID_BH_INFO
Information panel of selected house.
Definition town_widget.h:74
GenerateTownName
bool GenerateTownName(Randomizer &randomizer, uint32_t *townnameparts, TownNames *town_names)
Generates valid town name.
Definition townname.cpp:136
townname_func.h
Town name generator stuff.
ScrollWindowToTile
bool ScrollWindowToTile(TileIndex tile, Window *w, bool instant)
Scrolls the viewport in a window to a given location.
Definition viewport.cpp:2504
SetTileSelectSize
void SetTileSelectSize(int w, int h)
Highlight w by h tiles at the cursor.
Definition viewport.cpp:2542
ScrollMainWindowToTile
bool ScrollMainWindowToTile(TileIndex tile, bool instant)
Scrolls the viewport of the main window to a given location.
Definition viewport.cpp:2515
SetViewportCatchmentTown
void SetViewportCatchmentTown(const Town *t, bool sel)
Select or deselect town for coverage area highlight.
Definition viewport.cpp:3658
_viewport_highlight_town
const Town * _viewport_highlight_town
Currently selected town for coverage area highlight.
Definition viewport.cpp:1007
viewport_func.h
Functions related to (drawing on) viewports.
ZOOM_IN
@ ZOOM_IN
Zoom in (get more detailed view).
Definition viewport_type.h:77
ZOOM_OUT
@ ZOOM_OUT
Zoom out (get helicopter view).
Definition viewport_type.h:78
ScaleGUITrad
static RectPadding ScaleGUITrad(const RectPadding &r)
Scale a RectPadding to GUI zoom level.
Definition widget.cpp:35
SZSP_HORIZONTAL
@ SZSP_HORIZONTAL
Display plane with zero size vertically, and filling and resizing horizontally.
Definition widget_type.h:483
SZSP_VERTICAL
@ SZSP_VERTICAL
Display plane with zero size horizontally, and filling and resizing vertically.
Definition widget_type.h:482
NC_EQUALSIZE
@ NC_EQUALSIZE
Value of the NCB_EQUALSIZE flag.
Definition widget_type.h:524
WWT_PUSHTXTBTN
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
Definition widget_type.h:113
WWT_INSET
@ WWT_INSET
Pressed (inset) panel, most commonly used as combo box text area.
Definition widget_type.h:51
WWT_PUSHIMGBTN
@ WWT_PUSHIMGBTN
Normal push-button (no toggle button) with image caption.
Definition widget_type.h:114
WWT_LABEL
@ WWT_LABEL
Centered label.
Definition widget_type.h:57
WWT_EDITBOX
@ WWT_EDITBOX
a textbox for typing
Definition widget_type.h:71
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition widget_type.h:75
WWT_TEXTBTN
@ WWT_TEXTBTN
(Toggle) Button with text
Definition widget_type.h:55
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition widget_type.h:50
WWT_STICKYBOX
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition widget_type.h:66
WWT_SHADEBOX
@ WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition widget_type.h:64
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition widget_type.h:61
NWID_VSCROLLBAR
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition widget_type.h:85
NWID_VERTICAL
@ NWID_VERTICAL
Vertical container.
Definition widget_type.h:77
WWT_CLOSEBOX
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition widget_type.h:69
WWT_EMPTY
@ WWT_EMPTY
Empty widget, place holder to reserve space in widget tree.
Definition widget_type.h:48
WWT_RESIZEBOX
@ WWT_RESIZEBOX
Resize box (normally at bottom-right of a window)
Definition widget_type.h:68
WWT_DEFSIZEBOX
@ WWT_DEFSIZEBOX
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX)
Definition widget_type.h:65
NWID_VIEWPORT
@ NWID_VIEWPORT
Nested widget containing a viewport.
Definition widget_type.h:82
WWT_DROPDOWN
@ WWT_DROPDOWN
Drop down list.
Definition widget_type.h:70
WWT_TEXT
@ WWT_TEXT
Pure simple text.
Definition widget_type.h:58
NWID_SELECTION
@ NWID_SELECTION
Stacked widgets, only one visible at a time (eg in a panel with tabs).
Definition widget_type.h:80
ResizeWindow
void ResizeWindow(Window *w, int delta_x, int delta_y, bool clamp_to_screen, bool schedule_resize)
Resize the window.
Definition window.cpp:2022
SetFocusedWindow
void SetFocusedWindow(Window *w)
Set the window that has the focus.
Definition window.cpp:422
BringWindowToFrontById
Window * BringWindowToFrontById(WindowClass cls, WindowNumber number)
Find a window and make it the relative top-window on the screen.
Definition window.cpp:1223
window_func.h
Window functions not directly related to making/drawing windows.
SBS_DOWN
@ SBS_DOWN
Sort ascending.
Definition window_gui.h:220
SBS_UP
@ SBS_UP
Sort descending.
Definition window_gui.h:221
WF_DISABLE_VP_SCROLL
@ WF_DISABLE_VP_SCROLL
Window does not do autoscroll,.
Definition window_gui.h:235
WDF_CONSTRUCTION
@ WDF_CONSTRUCTION
This window is used for construction; close it whenever changing company.
Definition window_gui.h:203
WDP_AUTO
@ WDP_AUTO
Find a place automatically.
Definition window_gui.h:147
WidgetID
int WidgetID
Widget ID.
Definition window_type.h:18
WindowNumber
int32_t WindowNumber
Number to differentiate different windows of the same class.
Definition window_type.h:740
EventState
EventState
State of handling an event.
Definition window_type.h:743
ES_HANDLED
@ ES_HANDLED
The passed event is handled.
Definition window_type.h:744
ES_NOT_HANDLED
@ ES_NOT_HANDLED
The passed event is not handled.
Definition window_type.h:745
WC_TOWN_AUTHORITY
@ WC_TOWN_AUTHORITY
Town authority; Window numbers:
Definition window_type.h:194
WC_FOUND_TOWN
@ WC_FOUND_TOWN
Found a town; Window numbers:
Definition window_type.h:435
WC_BUILD_HOUSE
@ WC_BUILD_HOUSE
Build house; Window numbers:
Definition window_type.h:382
WC_BUILD_TOOLBAR
@ WC_BUILD_TOOLBAR
Build toolbar; Window numbers:
Definition window_type.h:73
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition window_type.h:45
WC_TOWN_VIEW
@ WC_TOWN_VIEW
Town view; Window numbers:
Definition window_type.h:333
WC_TOWN_DIRECTORY
@ WC_TOWN_DIRECTORY
Town directory; Window numbers:
Definition window_type.h:254
zoom_func.h
Functions related to zooming.
ScaleZoomGUI
ZoomLevel ScaleZoomGUI(ZoomLevel value)
Scale zoom level relative to GUI zoom.
Definition zoom_func.h:87
UnScaleGUI
int UnScaleGUI(int value)
Short-hand to apply GUI zoom level.
Definition zoom_func.h:77
ZOOM_LVL_TOWN
@ ZOOM_LVL_TOWN
Default zoom level for the town view.
Definition zoom_type.h:31