OpenTTD Source  14.0-beta3
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 "command_func.h"
16 #include "company_func.h"
17 #include "company_base.h"
18 #include "company_gui.h"
19 #include "network/network.h"
20 #include "string_func.h"
21 #include "strings_func.h"
22 #include "sound_func.h"
23 #include "tilehighlight_func.h"
24 #include "sortlist_type.h"
25 #include "road_cmd.h"
26 #include "landscape.h"
27 #include "querystring_gui.h"
28 #include "window_func.h"
29 #include "townname_func.h"
30 #include "core/backup_type.hpp"
31 #include "core/geometry_func.hpp"
32 #include "genworld.h"
33 #include "stringfilter_type.h"
34 #include "widgets/dropdown_func.h"
35 #include "town_kdtree.h"
36 #include "town_cmd.h"
37 #include "timer/timer.h"
39 #include "timer/timer_window.h"
40 #include "zoom_func.h"
41 #include "hotkeys.h"
42 
43 #include "widgets/town_widget.h"
44 
45 #include "table/strings.h"
46 
47 #include "safeguards.h"
48 
49 TownKdtree _town_local_authority_kdtree(&Kdtree_TownXYFunc);
50 
52 
53 static constexpr NWidgetPart _nested_town_authority_widgets[] = {
55  NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
56  NWidget(WWT_CAPTION, COLOUR_BROWN, WID_TA_CAPTION), SetDataTip(STR_LOCAL_AUTHORITY_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
57  NWidget(WWT_TEXTBTN, COLOUR_BROWN, WID_TA_ZONE_BUTTON), SetMinimalSize(50, 0), SetDataTip(STR_LOCAL_AUTHORITY_ZONE, STR_LOCAL_AUTHORITY_ZONE_TOOLTIP),
58  NWidget(WWT_SHADEBOX, COLOUR_BROWN),
59  NWidget(WWT_DEFSIZEBOX, COLOUR_BROWN),
60  NWidget(WWT_STICKYBOX, COLOUR_BROWN),
61  EndContainer(),
62  NWidget(WWT_PANEL, COLOUR_BROWN, WID_TA_RATING_INFO), SetMinimalSize(317, 92), SetResize(1, 1), EndContainer(),
63  NWidget(WWT_PANEL, COLOUR_BROWN, WID_TA_COMMAND_LIST), SetMinimalSize(317, 52), SetResize(1, 0), SetDataTip(0x0, STR_LOCAL_AUTHORITY_ACTIONS_TOOLTIP), EndContainer(),
64  NWidget(WWT_PANEL, COLOUR_BROWN, WID_TA_ACTION_INFO), SetMinimalSize(317, 52), SetResize(1, 0), EndContainer(),
66  NWidget(WWT_PUSHTXTBTN, COLOUR_BROWN, WID_TA_EXECUTE), SetMinimalSize(317, 12), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_LOCAL_AUTHORITY_DO_IT_BUTTON, STR_LOCAL_AUTHORITY_DO_IT_TOOLTIP),
67  NWidget(WWT_RESIZEBOX, COLOUR_BROWN),
68  EndContainer()
69 };
70 
73 private:
75  int sel_index;
79  StringID action_tooltips[TACT_COUNT];
80 
83 
92  int GetNthSetBit(int n)
93  {
94  if (n >= 0) {
95  for (uint i : SetBitIterator(this->enabled_actions)) {
96  n--;
97  if (n < 0) return i;
98  }
99  }
100  return -1;
101  }
102 
109  {
110  TownActions enabled = TACT_ALL;
111 
116 
117  return enabled;
118  }
119 
120 public:
122  {
123  this->town = Town::Get(window_number);
124  this->enabled_actions = GetEnabledActions();
125 
126  auto realtime = TimerGameEconomy::UsingWallclockUnits();
127  this->action_tooltips[0] = STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_SMALL_ADVERTISING;
128  this->action_tooltips[1] = STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_MEDIUM_ADVERTISING;
129  this->action_tooltips[2] = STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_LARGE_ADVERTISING;
130  this->action_tooltips[3] = realtime ? STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_ROAD_RECONSTRUCTION_MINUTES : STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_ROAD_RECONSTRUCTION_MONTHS;
131  this->action_tooltips[4] = STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_STATUE_OF_COMPANY;
132  this->action_tooltips[5] = STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_NEW_BUILDINGS;
133  this->action_tooltips[6] = realtime ? STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_EXCLUSIVE_TRANSPORT_MINUTES : STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_EXCLUSIVE_TRANSPORT_MONTHS;
134  this->action_tooltips[7] = STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_BRIBE;
135 
136  this->InitNested(window_number);
137  }
138 
139  void OnInit() override
140  {
141  this->icon_size = GetSpriteSize(SPR_COMPANY_ICON);
142  this->exclusive_size = GetSpriteSize(SPR_EXCLUSIVE_TRANSPORT);
143  }
144 
145  void OnPaint() override
146  {
147  this->available_actions = GetMaskOfTownActions(_local_company, this->town);
148  if (this->available_actions != displayed_actions_on_previous_painting) this->SetDirty();
149  displayed_actions_on_previous_painting = this->available_actions;
150 
152  this->SetWidgetDisabledState(WID_TA_EXECUTE, (this->sel_index == -1) || !HasBit(this->available_actions, this->sel_index));
153 
154  this->DrawWidgets();
155  if (!this->IsShaded())
156  {
157  this->DrawRatings();
158  this->DrawActions();
159  }
160  }
161 
163  void DrawRatings()
164  {
165  Rect r = this->GetWidget<NWidgetBase>(WID_TA_RATING_INFO)->GetCurrentRect().Shrink(WidgetDimensions::scaled.framerect);
166 
167  int text_y_offset = (this->resize.step_height - GetCharacterHeight(FS_NORMAL)) / 2;
168  int icon_y_offset = (this->resize.step_height - this->icon_size.height) / 2;
169  int exclusive_y_offset = (this->resize.step_height - this->exclusive_size.height) / 2;
170 
171  DrawString(r.left, r.right, r.top + text_y_offset, STR_LOCAL_AUTHORITY_COMPANY_RATINGS);
172  r.top += this->resize.step_height;
173 
174  bool rtl = _current_text_dir == TD_RTL;
175  Rect icon = r.WithWidth(this->icon_size.width, rtl);
176  Rect exclusive = r.Indent(this->icon_size.width + WidgetDimensions::scaled.hsep_normal, rtl).WithWidth(this->exclusive_size.width, rtl);
177  Rect text = r.Indent(this->icon_size.width + WidgetDimensions::scaled.hsep_normal + this->exclusive_size.width + WidgetDimensions::scaled.hsep_normal, rtl);
178 
179  /* Draw list of companies */
180  for (const Company *c : Company::Iterate()) {
181  if ((HasBit(this->town->have_ratings, c->index) || this->town->exclusivity == c->index)) {
182  DrawCompanyIcon(c->index, icon.left, text.top + icon_y_offset);
183 
184  SetDParam(0, c->index);
185  SetDParam(1, c->index);
186 
187  int rating = this->town->ratings[c->index];
188  StringID str = STR_CARGO_RATING_APPALLING;
189  if (rating > RATING_APPALLING) str++;
190  if (rating > RATING_VERYPOOR) str++;
191  if (rating > RATING_POOR) str++;
192  if (rating > RATING_MEDIOCRE) str++;
193  if (rating > RATING_GOOD) str++;
194  if (rating > RATING_VERYGOOD) str++;
195  if (rating > RATING_EXCELLENT) str++;
196 
197  SetDParam(2, str);
198  if (this->town->exclusivity == c->index) {
199  DrawSprite(SPR_EXCLUSIVE_TRANSPORT, COMPANY_SPRITE_COLOUR(c->index), exclusive.left, text.top + exclusive_y_offset);
200  }
201 
202  DrawString(text.left, text.right, text.top + text_y_offset, STR_LOCAL_AUTHORITY_COMPANY_RATING);
203  text.top += this->resize.step_height;
204  }
205  }
206 
207  text.bottom = text.top - 1;
208  if (text.bottom > r.bottom) {
209  /* If the company list is too big to fit, mark ourself dirty and draw again. */
210  ResizeWindow(this, 0, text.bottom - r.bottom, false);
211  }
212  }
213 
215  void DrawActions()
216  {
217  Rect r = this->GetWidget<NWidgetBase>(WID_TA_COMMAND_LIST)->GetCurrentRect().Shrink(WidgetDimensions::scaled.framerect);
218 
219  DrawString(r, STR_LOCAL_AUTHORITY_ACTIONS_TITLE);
220  r.top += GetCharacterHeight(FS_NORMAL);
221 
222  /* Draw list of actions */
223  for (int i = 0; i < TACT_COUNT; i++) {
224  /* Don't show actions if disabled in settings. */
225  if (!HasBit(this->enabled_actions, i)) continue;
226 
227  /* Set colour of action based on ability to execute and if selected. */
228  TextColour action_colour = TC_GREY | TC_NO_SHADE;
229  if (HasBit(this->available_actions, i)) action_colour = TC_ORANGE;
230  if (this->sel_index == i) action_colour = TC_WHITE;
231 
232  DrawString(r, STR_LOCAL_AUTHORITY_ACTION_SMALL_ADVERTISING_CAMPAIGN + i, action_colour);
233  r.top += GetCharacterHeight(FS_NORMAL);
234  }
235  }
236 
237  void SetStringParameters(WidgetID widget) const override
238  {
239  if (widget == WID_TA_CAPTION) SetDParam(0, this->window_number);
240  }
241 
242  void DrawWidget(const Rect &r, WidgetID widget) const override
243  {
244  switch (widget) {
245  case WID_TA_ACTION_INFO:
246  if (this->sel_index != -1) {
247  Money action_cost = _price[PR_TOWN_ACTION] * _town_action_costs[this->sel_index] >> 8;
248  bool affordable = Company::IsValidID(_local_company) && action_cost < GetAvailableMoney(_local_company);
249 
250  SetDParam(0, action_cost);
252  this->action_tooltips[this->sel_index],
253  affordable ? TC_YELLOW : TC_RED);
254  }
255  break;
256  }
257  }
258 
259  void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override
260  {
261  switch (widget) {
262  case WID_TA_ACTION_INFO: {
263  assert(size->width > padding.width && size->height > padding.height);
264  Dimension d = {0, 0};
265  for (int i = 0; i < TACT_COUNT; i++) {
266  SetDParam(0, _price[PR_TOWN_ACTION] * _town_action_costs[i] >> 8);
267  d = maxdim(d, GetStringMultiLineBoundingBox(this->action_tooltips[i], *size));
268  }
269  d.width += padding.width;
270  d.height += padding.height;
271  *size = maxdim(*size, d);
272  break;
273  }
274 
275  case WID_TA_COMMAND_LIST:
276  size->height = (TACT_COUNT + 1) * GetCharacterHeight(FS_NORMAL) + padding.height;
277  size->width = GetStringBoundingBox(STR_LOCAL_AUTHORITY_ACTIONS_TITLE).width;
278  for (uint i = 0; i < TACT_COUNT; i++ ) {
279  size->width = std::max(size->width, GetStringBoundingBox(STR_LOCAL_AUTHORITY_ACTION_SMALL_ADVERTISING_CAMPAIGN + i).width + padding.width);
280  }
281  size->width += padding.width;
282  break;
283 
284  case WID_TA_RATING_INFO:
285  resize->height = std::max({this->icon_size.height + WidgetDimensions::scaled.vsep_normal, this->exclusive_size.height + WidgetDimensions::scaled.vsep_normal, (uint)GetCharacterHeight(FS_NORMAL)});
286  size->height = 9 * resize->height + padding.height;
287  break;
288  }
289  }
290 
291  void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
292  {
293  switch (widget) {
294  case WID_TA_ZONE_BUTTON: {
295  bool new_show_state = !this->town->show_zone;
296  TownID index = this->town->index;
297 
298  new_show_state ? _town_local_authority_kdtree.Insert(index) : _town_local_authority_kdtree.Remove(index);
299 
300  this->town->show_zone = new_show_state;
301  this->SetWidgetLoweredState(widget, new_show_state);
303  break;
304  }
305 
306  case WID_TA_COMMAND_LIST: {
308 
309  y = GetNthSetBit(y);
310  if (y >= 0) {
311  this->sel_index = y;
312  this->SetDirty();
313  }
314 
315  /* When double-clicking, continue */
316  if (click_count == 1 || y < 0 || !HasBit(this->available_actions, y)) break;
317  [[fallthrough]];
318  }
319 
320  case WID_TA_EXECUTE:
321  Command<CMD_DO_TOWN_ACTION>::Post(STR_ERROR_CAN_T_DO_THIS, this->town->xy, this->window_number, this->sel_index);
322  break;
323  }
324  }
325 
327  IntervalTimer<TimerWindow> redraw_interval = {std::chrono::seconds(3), [this](auto) {
328  this->SetDirty();
329  }};
330 
331  void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
332  {
333  if (!gui_scope) return;
334 
335  this->enabled_actions = this->GetEnabledActions();
336  if (!HasBit(this->enabled_actions, this->sel_index)) {
337  this->sel_index = -1;
338  }
339  }
340 };
341 
342 static WindowDesc _town_authority_desc(__FILE__, __LINE__,
343  WDP_AUTO, "view_town_authority", 317, 222,
345  0,
346  std::begin(_nested_town_authority_widgets), std::end(_nested_town_authority_widgets)
347 );
348 
349 static void ShowTownAuthorityWindow(uint town)
350 {
351  AllocateWindowDescFront<TownAuthorityWindow>(&_town_authority_desc, town);
352 }
353 
354 
355 /* Town view window. */
357 private:
359 
360 public:
361  static const int WID_TV_HEIGHT_NORMAL = 150;
362 
364  {
365  this->CreateNestedTree();
366 
367  this->town = Town::Get(window_number);
368  if (this->town->larger_town) this->GetWidget<NWidgetCore>(WID_TV_CAPTION)->widget_data = STR_TOWN_VIEW_CITY_CAPTION;
369 
370  this->FinishInitNested(window_number);
371 
372  this->flags |= WF_DISABLE_VP_SCROLL;
373  NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(WID_TV_VIEWPORT);
374  nvp->InitializeViewport(this, this->town->xy, ScaleZoomGUI(ZOOM_LVL_TOWN));
375 
376  /* disable renaming town in network games if you are not the server */
378  }
379 
380  void Close([[maybe_unused]] int data = 0) override
381  {
383  this->Window::Close();
384  }
385 
386  void SetStringParameters(WidgetID widget) const override
387  {
388  if (widget == WID_TV_CAPTION) SetDParam(0, this->town->index);
389  }
390 
391  void OnPaint() override
392  {
393  extern const Town *_viewport_highlight_town;
394  this->SetWidgetLoweredState(WID_TV_CATCHMENT, _viewport_highlight_town == this->town);
395 
396  this->DrawWidgets();
397  }
398 
399  void DrawWidget(const Rect &r, WidgetID widget) const override
400  {
401  if (widget != WID_TV_INFO) return;
402 
403  Rect tr = r.Shrink(WidgetDimensions::scaled.framerect);
404 
405  SetDParam(0, this->town->cache.population);
406  SetDParam(1, this->town->cache.num_houses);
407  DrawString(tr, STR_TOWN_VIEW_POPULATION_HOUSES);
408  tr.top += GetCharacterHeight(FS_NORMAL);
409 
410  StringID str_last_period = TimerGameEconomy::UsingWallclockUnits() ? STR_TOWN_VIEW_CARGO_LAST_MINUTE_MAX : STR_TOWN_VIEW_CARGO_LAST_MONTH_MAX;
411 
412  for (auto tpe : {TPE_PASSENGERS, TPE_MAIL}) {
413  for (const CargoSpec *cs : CargoSpec::town_production_cargoes[tpe]) {
414  CargoID cid = cs->Index();
415  SetDParam(0, 1ULL << cid);
416  SetDParam(1, this->town->supplied[cid].old_act);
417  SetDParam(2, this->town->supplied[cid].old_max);
418  DrawString(tr, str_last_period);
419  tr.top += GetCharacterHeight(FS_NORMAL);
420  }
421  }
422 
423  bool first = true;
424  for (int i = TAE_BEGIN; i < TAE_END; i++) {
425  if (this->town->goal[i] == 0) continue;
426  if (this->town->goal[i] == TOWN_GROWTH_WINTER && (TileHeight(this->town->xy) < LowestSnowLine() || this->town->cache.population <= 90)) continue;
427  if (this->town->goal[i] == TOWN_GROWTH_DESERT && (GetTropicZone(this->town->xy) != TROPICZONE_DESERT || this->town->cache.population <= 60)) continue;
428 
429  if (first) {
430  DrawString(tr, STR_TOWN_VIEW_CARGO_FOR_TOWNGROWTH);
431  tr.top += GetCharacterHeight(FS_NORMAL);
432  first = false;
433  }
434 
435  bool rtl = _current_text_dir == TD_RTL;
436 
438  assert(cargo != nullptr);
439 
440  StringID string;
441 
442  if (this->town->goal[i] == TOWN_GROWTH_DESERT || this->town->goal[i] == TOWN_GROWTH_WINTER) {
443  /* For 'original' gameplay, don't show the amount required (you need 1 or more ..) */
444  string = STR_TOWN_VIEW_CARGO_FOR_TOWNGROWTH_DELIVERED_GENERAL;
445  if (this->town->received[i].old_act == 0) {
446  string = STR_TOWN_VIEW_CARGO_FOR_TOWNGROWTH_REQUIRED_GENERAL;
447 
448  if (this->town->goal[i] == TOWN_GROWTH_WINTER && TileHeight(this->town->xy) < GetSnowLine()) {
449  string = STR_TOWN_VIEW_CARGO_FOR_TOWNGROWTH_REQUIRED_WINTER;
450  }
451  }
452 
453  SetDParam(0, cargo->name);
454  } else {
455  string = STR_TOWN_VIEW_CARGO_FOR_TOWNGROWTH_DELIVERED;
456  if (this->town->received[i].old_act < this->town->goal[i]) {
457  string = STR_TOWN_VIEW_CARGO_FOR_TOWNGROWTH_REQUIRED;
458  }
459 
460  SetDParam(0, cargo->Index());
461  SetDParam(1, this->town->received[i].old_act);
462  SetDParam(2, cargo->Index());
463  SetDParam(3, this->town->goal[i]);
464  }
465  DrawString(tr.Indent(20, rtl), string);
466  tr.top += GetCharacterHeight(FS_NORMAL);
467  }
468 
469  if (HasBit(this->town->flags, TOWN_IS_GROWING)) {
470  SetDParam(0, RoundDivSU(this->town->growth_rate + 1, Ticks::DAY_TICKS));
471  DrawString(tr, this->town->fund_buildings_months == 0 ? STR_TOWN_VIEW_TOWN_GROWS_EVERY : STR_TOWN_VIEW_TOWN_GROWS_EVERY_FUNDED);
472  tr.top += GetCharacterHeight(FS_NORMAL);
473  } else {
474  DrawString(tr, STR_TOWN_VIEW_TOWN_GROW_STOPPED);
475  tr.top += GetCharacterHeight(FS_NORMAL);
476  }
477 
478  /* only show the town noise, if the noise option is activated. */
480  SetDParam(0, this->town->noise_reached);
481  SetDParam(1, this->town->MaxTownNoise());
482  DrawString(tr, STR_TOWN_VIEW_NOISE_IN_TOWN);
483  tr.top += GetCharacterHeight(FS_NORMAL);
484  }
485 
486  if (!this->town->text.empty()) {
487  SetDParamStr(0, this->town->text);
488  tr.top = DrawStringMultiLine(tr, STR_JUST_RAW_STRING, TC_BLACK);
489  }
490  }
491 
492  void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
493  {
494  switch (widget) {
495  case WID_TV_CENTER_VIEW: // scroll to location
496  if (_ctrl_pressed) {
497  ShowExtraViewportWindow(this->town->xy);
498  } else {
499  ScrollMainWindowToTile(this->town->xy);
500  }
501  break;
502 
503  case WID_TV_SHOW_AUTHORITY: // town authority
504  ShowTownAuthorityWindow(this->window_number);
505  break;
506 
507  case WID_TV_CHANGE_NAME: // rename
508  SetDParam(0, this->window_number);
509  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);
510  break;
511 
512  case WID_TV_CATCHMENT:
514  break;
515 
516  case WID_TV_EXPAND: { // expand town - only available on Scenario editor
517  Command<CMD_EXPAND_TOWN>::Post(STR_ERROR_CAN_T_EXPAND_TOWN, this->window_number, 0);
518  break;
519  }
520 
521  case WID_TV_DELETE: // delete town - only available on Scenario editor
522  Command<CMD_DELETE_TOWN>::Post(STR_ERROR_TOWN_CAN_T_DELETE, this->window_number);
523  break;
524  }
525  }
526 
527  void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override
528  {
529  switch (widget) {
530  case WID_TV_INFO:
531  size->height = GetDesiredInfoHeight(size->width) + padding.height;
532  break;
533  }
534  }
535 
540  uint GetDesiredInfoHeight(int width) const
541  {
543 
544  bool first = true;
545  for (int i = TAE_BEGIN; i < TAE_END; i++) {
546  if (this->town->goal[i] == 0) continue;
547  if (this->town->goal[i] == TOWN_GROWTH_WINTER && (TileHeight(this->town->xy) < LowestSnowLine() || this->town->cache.population <= 90)) continue;
548  if (this->town->goal[i] == TOWN_GROWTH_DESERT && (GetTropicZone(this->town->xy) != TROPICZONE_DESERT || this->town->cache.population <= 60)) continue;
549 
550  if (first) {
551  aimed_height += GetCharacterHeight(FS_NORMAL);
552  first = false;
553  }
554  aimed_height += GetCharacterHeight(FS_NORMAL);
555  }
556  aimed_height += GetCharacterHeight(FS_NORMAL);
557 
559 
560  if (!this->town->text.empty()) {
561  SetDParamStr(0, this->town->text);
562  aimed_height += GetStringHeight(STR_JUST_RAW_STRING, width - WidgetDimensions::scaled.framerect.Horizontal());
563  }
564 
565  return aimed_height;
566  }
567 
568  void ResizeWindowAsNeeded()
569  {
570  const NWidgetBase *nwid_info = this->GetWidget<NWidgetBase>(WID_TV_INFO);
571  uint aimed_height = GetDesiredInfoHeight(nwid_info->current_x);
572  if (aimed_height > nwid_info->current_y || (aimed_height < nwid_info->current_y && nwid_info->current_y > nwid_info->smallest_y)) {
573  this->ReInit();
574  }
575  }
576 
577  void OnResize() override
578  {
579  if (this->viewport != nullptr) {
580  NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(WID_TV_VIEWPORT);
581  nvp->UpdateViewportCoordinates(this);
582 
583  ScrollWindowToTile(this->town->xy, this, true); // Re-center viewport.
584  }
585  }
586 
592  void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
593  {
594  if (!gui_scope) return;
595  /* Called when setting station noise or required cargoes have changed, in order to resize the window */
596  this->SetDirty(); // refresh display for current size. This will allow to avoid glitches when downgrading
597  this->ResizeWindowAsNeeded();
598  }
599 
600  void OnQueryTextFinished(char *str) override
601  {
602  if (str == nullptr) return;
603 
604  Command<CMD_RENAME_TOWN>::Post(STR_ERROR_CAN_T_RENAME_TOWN, this->window_number, str);
605  }
606 
607  IntervalTimer<TimerGameCalendar> daily_interval = {{TimerGameCalendar::DAY, TimerGameCalendar::Priority::NONE}, [this](auto) {
608  /* Refresh after possible snowline change */
609  this->SetDirty();
610  }};
611 };
612 
613 static constexpr NWidgetPart _nested_town_game_view_widgets[] = {
615  NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
616  NWidget(WWT_PUSHIMGBTN, COLOUR_BROWN, WID_TV_CHANGE_NAME), SetMinimalSize(12, 14), SetDataTip(SPR_RENAME, STR_TOWN_VIEW_RENAME_TOOLTIP),
617  NWidget(WWT_CAPTION, COLOUR_BROWN, WID_TV_CAPTION), SetDataTip(STR_TOWN_VIEW_TOWN_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
618  NWidget(WWT_PUSHIMGBTN, COLOUR_BROWN, WID_TV_CENTER_VIEW), SetMinimalSize(12, 14), SetDataTip(SPR_GOTO_LOCATION, STR_TOWN_VIEW_CENTER_TOOLTIP),
619  NWidget(WWT_SHADEBOX, COLOUR_BROWN),
620  NWidget(WWT_DEFSIZEBOX, COLOUR_BROWN),
621  NWidget(WWT_STICKYBOX, COLOUR_BROWN),
622  EndContainer(),
623  NWidget(WWT_PANEL, COLOUR_BROWN),
624  NWidget(WWT_INSET, COLOUR_BROWN), SetPadding(2, 2, 2, 2),
625  NWidget(NWID_VIEWPORT, INVALID_COLOUR, WID_TV_VIEWPORT), SetMinimalSize(254, 86), SetFill(1, 0), SetResize(1, 1),
626  EndContainer(),
627  EndContainer(),
628  NWidget(WWT_PANEL, COLOUR_BROWN, WID_TV_INFO), SetMinimalSize(260, 32), SetResize(1, 0), SetFill(1, 0), EndContainer(),
630  NWidget(WWT_PUSHTXTBTN, COLOUR_BROWN, WID_TV_SHOW_AUTHORITY), SetMinimalSize(80, 12), SetFill(1, 1), SetResize(1, 0), SetDataTip(STR_TOWN_VIEW_LOCAL_AUTHORITY_BUTTON, STR_TOWN_VIEW_LOCAL_AUTHORITY_TOOLTIP),
631  NWidget(WWT_TEXTBTN, COLOUR_BROWN, WID_TV_CATCHMENT), SetMinimalSize(40, 12), SetFill(1, 1), SetResize(1, 0), SetDataTip(STR_BUTTON_CATCHMENT, STR_TOOLTIP_CATCHMENT),
632  NWidget(WWT_RESIZEBOX, COLOUR_BROWN),
633  EndContainer(),
634 };
635 
636 static WindowDesc _town_game_view_desc(__FILE__, __LINE__,
637  WDP_AUTO, "view_town", 260, TownViewWindow::WID_TV_HEIGHT_NORMAL,
639  0,
640  std::begin(_nested_town_game_view_widgets), std::end(_nested_town_game_view_widgets)
641 );
642 
643 static constexpr NWidgetPart _nested_town_editor_view_widgets[] = {
645  NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
646  NWidget(WWT_PUSHIMGBTN, COLOUR_BROWN, WID_TV_CHANGE_NAME), SetMinimalSize(12, 14), SetDataTip(SPR_RENAME, STR_TOWN_VIEW_RENAME_TOOLTIP),
647  NWidget(WWT_CAPTION, COLOUR_BROWN, WID_TV_CAPTION), SetDataTip(STR_TOWN_VIEW_TOWN_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
648  NWidget(WWT_PUSHIMGBTN, COLOUR_BROWN, WID_TV_CENTER_VIEW), SetMinimalSize(12, 14), SetDataTip(SPR_GOTO_LOCATION, STR_TOWN_VIEW_CENTER_TOOLTIP),
649  NWidget(WWT_SHADEBOX, COLOUR_BROWN),
650  NWidget(WWT_DEFSIZEBOX, COLOUR_BROWN),
651  NWidget(WWT_STICKYBOX, COLOUR_BROWN),
652  EndContainer(),
653  NWidget(WWT_PANEL, COLOUR_BROWN),
654  NWidget(WWT_INSET, COLOUR_BROWN), SetPadding(2, 2, 2, 2),
655  NWidget(NWID_VIEWPORT, INVALID_COLOUR, WID_TV_VIEWPORT), SetMinimalSize(254, 86), SetFill(1, 1), SetResize(1, 1),
656  EndContainer(),
657  EndContainer(),
658  NWidget(WWT_PANEL, COLOUR_BROWN, WID_TV_INFO), SetMinimalSize(260, 32), SetResize(1, 0), SetFill(1, 0), EndContainer(),
660  NWidget(WWT_PUSHTXTBTN, COLOUR_BROWN, WID_TV_EXPAND), SetMinimalSize(80, 12), SetFill(1, 1), SetResize(1, 0), SetDataTip(STR_TOWN_VIEW_EXPAND_BUTTON, STR_TOWN_VIEW_EXPAND_TOOLTIP),
661  NWidget(WWT_PUSHTXTBTN, COLOUR_BROWN, WID_TV_DELETE), SetMinimalSize(80, 12), SetFill(1, 1), SetResize(1, 0), SetDataTip(STR_TOWN_VIEW_DELETE_BUTTON, STR_TOWN_VIEW_DELETE_TOOLTIP),
662  NWidget(WWT_TEXTBTN, COLOUR_BROWN, WID_TV_CATCHMENT), SetMinimalSize(40, 12), SetFill(1, 1), SetResize(1, 0), SetDataTip(STR_BUTTON_CATCHMENT, STR_TOOLTIP_CATCHMENT),
663  NWidget(WWT_RESIZEBOX, COLOUR_BROWN),
664  EndContainer(),
665 };
666 
667 static WindowDesc _town_editor_view_desc(__FILE__, __LINE__,
668  WDP_AUTO, "view_town_scen", 260, TownViewWindow::WID_TV_HEIGHT_NORMAL,
670  0,
671  std::begin(_nested_town_editor_view_widgets), std::end(_nested_town_editor_view_widgets)
672 );
673 
674 void ShowTownViewWindow(TownID town)
675 {
676  if (_game_mode == GM_EDITOR) {
677  AllocateWindowDescFront<TownViewWindow>(&_town_editor_view_desc, town);
678  } else {
679  AllocateWindowDescFront<TownViewWindow>(&_town_game_view_desc, town);
680  }
681 }
682 
683 static constexpr NWidgetPart _nested_town_directory_widgets[] = {
685  NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
686  NWidget(WWT_CAPTION, COLOUR_BROWN), SetDataTip(STR_TOWN_DIRECTORY_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
687  NWidget(WWT_SHADEBOX, COLOUR_BROWN),
688  NWidget(WWT_DEFSIZEBOX, COLOUR_BROWN),
689  NWidget(WWT_STICKYBOX, COLOUR_BROWN),
690  EndContainer(),
694  NWidget(WWT_TEXTBTN, COLOUR_BROWN, WID_TD_SORT_ORDER), SetDataTip(STR_BUTTON_SORT_BY, STR_TOOLTIP_SORT_ORDER),
695  NWidget(WWT_DROPDOWN, COLOUR_BROWN, WID_TD_SORT_CRITERIA), SetDataTip(STR_JUST_STRING, STR_TOOLTIP_SORT_CRITERIA),
696  NWidget(WWT_EDITBOX, COLOUR_BROWN, WID_TD_FILTER), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP),
697  EndContainer(),
698  NWidget(WWT_PANEL, COLOUR_BROWN, WID_TD_LIST), SetDataTip(0x0, STR_TOWN_DIRECTORY_LIST_TOOLTIP),
700  NWidget(WWT_PANEL, COLOUR_BROWN),
701  NWidget(WWT_TEXT, COLOUR_BROWN, WID_TD_WORLD_POPULATION), SetPadding(2, 0, 2, 2), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_TOWN_POPULATION, STR_NULL),
702  EndContainer(),
703  EndContainer(),
705  NWidget(NWID_VSCROLLBAR, COLOUR_BROWN, WID_TD_SCROLLBAR),
706  NWidget(WWT_RESIZEBOX, COLOUR_BROWN),
707  EndContainer(),
708  EndContainer(),
709 };
710 
714 };
715 
717 struct TownDirectoryWindow : public Window {
718 private:
719  /* Runtime saved values */
720  static Listing last_sorting;
721 
722  /* Constants for sorting towns */
723  static const StringID sorter_names[];
725 
728 
729  GUITownList towns{TownDirectoryWindow::last_sorting.order};
730 
731  Scrollbar *vscroll;
732 
733  void BuildSortTownList()
734  {
735  if (this->towns.NeedRebuild()) {
736  this->towns.clear();
737 
738  for (const Town *t : Town::Iterate()) {
739  if (this->string_filter.IsEmpty()) {
740  this->towns.push_back(t);
741  continue;
742  }
743  this->string_filter.ResetState();
744  this->string_filter.AddLine(t->GetCachedName());
745  if (this->string_filter.GetState()) this->towns.push_back(t);
746  }
747 
748  this->towns.shrink_to_fit();
749  this->towns.RebuildDone();
750  this->vscroll->SetCount(this->towns.size()); // Update scrollbar as well.
751  }
752  /* Always sort the towns. */
753  this->towns.Sort();
754  this->SetWidgetDirty(WID_TD_LIST); // Force repaint of the displayed towns.
755  }
756 
758  static bool TownNameSorter(const Town * const &a, const Town * const &b, const bool &)
759  {
760  return StrNaturalCompare(a->GetCachedName(), b->GetCachedName()) < 0; // Sort by name (natural sorting).
761  }
762 
764  static bool TownPopulationSorter(const Town * const &a, const Town * const &b, const bool &order)
765  {
766  uint32_t a_population = a->cache.population;
767  uint32_t b_population = b->cache.population;
768  if (a_population == b_population) return TownDirectoryWindow::TownNameSorter(a, b, order);
769  return a_population < b_population;
770  }
771 
773  static bool TownRatingSorter(const Town * const &a, const Town * const &b, const bool &order)
774  {
775  bool before = !order; // Value to get 'a' before 'b'.
776 
777  /* Towns without rating are always after towns with rating. */
780  int16_t a_rating = a->ratings[_local_company];
781  int16_t b_rating = b->ratings[_local_company];
782  if (a_rating == b_rating) return TownDirectoryWindow::TownNameSorter(a, b, order);
783  return a_rating < b_rating;
784  }
785  return before;
786  }
787  if (HasBit(b->have_ratings, _local_company)) return !before;
788 
789  /* Sort unrated towns always on ascending town name. */
790  if (before) return TownDirectoryWindow::TownNameSorter(a, b, order);
791  return TownDirectoryWindow::TownNameSorter(b, a, order);
792  }
793 
794 public:
796  {
797  this->CreateNestedTree();
798 
799  this->vscroll = this->GetScrollbar(WID_TD_SCROLLBAR);
800 
801  this->towns.SetListing(this->last_sorting);
803  this->towns.ForceRebuild();
804  this->BuildSortTownList();
805 
806  this->FinishInitNested(0);
807 
809  this->townname_editbox.cancel_button = QueryString::ACTION_CLEAR;
810  }
811 
812  void SetStringParameters(WidgetID widget) const override
813  {
814  switch (widget) {
817  break;
818 
821  break;
822  }
823  }
824 
830  static StringID GetTownString(const Town *t)
831  {
832  return t->larger_town ? STR_TOWN_DIRECTORY_CITY : STR_TOWN_DIRECTORY_TOWN;
833  }
834 
835  void DrawWidget(const Rect &r, WidgetID widget) const override
836  {
837  switch (widget) {
838  case WID_TD_SORT_ORDER:
839  this->DrawSortButtonState(widget, this->towns.IsDescSortOrder() ? SBS_DOWN : SBS_UP);
840  break;
841 
842  case WID_TD_LIST: {
843  int n = 0;
844  Rect tr = r.Shrink(WidgetDimensions::scaled.framerect);
845  if (this->towns.empty()) { // No towns available.
846  DrawString(tr, STR_TOWN_DIRECTORY_NONE);
847  break;
848  }
849 
850  /* At least one town available. */
851  bool rtl = _current_text_dir == TD_RTL;
852  Dimension icon_size = GetSpriteSize(SPR_TOWN_RATING_GOOD);
853  int icon_x = tr.WithWidth(icon_size.width, rtl).left;
854  tr = tr.Indent(icon_size.width + WidgetDimensions::scaled.hsep_normal, rtl);
855 
856  for (uint i = this->vscroll->GetPosition(); i < this->towns.size(); i++) {
857  const Town *t = this->towns[i];
858  assert(t->xy != INVALID_TILE);
859 
860  /* Draw rating icon. */
861  if (_game_mode == GM_EDITOR || !HasBit(t->have_ratings, _local_company)) {
862  DrawSprite(SPR_TOWN_RATING_NA, PAL_NONE, icon_x, tr.top + (this->resize.step_height - icon_size.height) / 2);
863  } else {
864  SpriteID icon = SPR_TOWN_RATING_APALLING;
865  if (t->ratings[_local_company] > RATING_VERYPOOR) icon = SPR_TOWN_RATING_MEDIOCRE;
866  if (t->ratings[_local_company] > RATING_GOOD) icon = SPR_TOWN_RATING_GOOD;
867  DrawSprite(icon, PAL_NONE, icon_x, tr.top + (this->resize.step_height - icon_size.height) / 2);
868  }
869 
870  SetDParam(0, t->index);
871  SetDParam(1, t->cache.population);
872  DrawString(tr.left, tr.right, tr.top + (this->resize.step_height - GetCharacterHeight(FS_NORMAL)) / 2, GetTownString(t));
873 
874  tr.top += this->resize.step_height;
875  if (++n == this->vscroll->GetCapacity()) break; // max number of towns in 1 window
876  }
877  break;
878  }
879  }
880  }
881 
882  void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override
883  {
884  switch (widget) {
885  case WID_TD_SORT_ORDER: {
886  Dimension d = GetStringBoundingBox(this->GetWidget<NWidgetCore>(widget)->widget_data);
887  d.width += padding.width + Window::SortButtonWidth() * 2; // Doubled since the string is centred and it also looks better.
888  d.height += padding.height;
889  *size = maxdim(*size, d);
890  break;
891  }
892  case WID_TD_SORT_CRITERIA: {
893  Dimension d = {0, 0};
894  for (uint i = 0; TownDirectoryWindow::sorter_names[i] != INVALID_STRING_ID; i++) {
896  }
897  d.width += padding.width;
898  d.height += padding.height;
899  *size = maxdim(*size, d);
900  break;
901  }
902  case WID_TD_LIST: {
903  Dimension d = GetStringBoundingBox(STR_TOWN_DIRECTORY_NONE);
904  for (uint i = 0; i < this->towns.size(); i++) {
905  const Town *t = this->towns[i];
906 
907  assert(t != nullptr);
908 
909  SetDParam(0, t->index);
910  SetDParamMaxDigits(1, 8);
912  }
913  Dimension icon_size = GetSpriteSize(SPR_TOWN_RATING_GOOD);
914  d.width += icon_size.width + 2;
915  d.height = std::max(d.height, icon_size.height);
916  resize->height = d.height;
917  d.height *= 5;
918  d.width += padding.width;
919  d.height += padding.height;
920  *size = maxdim(*size, d);
921  break;
922  }
924  SetDParamMaxDigits(0, 10);
925  Dimension d = GetStringBoundingBox(STR_TOWN_POPULATION);
926  d.width += padding.width;
927  d.height += padding.height;
928  *size = maxdim(*size, d);
929  break;
930  }
931  }
932  }
933 
934  void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
935  {
936  switch (widget) {
937  case WID_TD_SORT_ORDER: // Click on sort order button
938  if (this->towns.SortType() != 2) { // A different sort than by rating.
939  this->towns.ToggleSortOrder();
940  this->last_sorting = this->towns.GetListing(); // Store new sorting order.
941  } else {
942  /* Some parts are always sorted ascending on name. */
943  this->last_sorting.order = !this->last_sorting.order;
944  this->towns.SetListing(this->last_sorting);
945  this->towns.ForceResort();
946  this->towns.Sort();
947  }
948  this->SetDirty();
949  break;
950 
951  case WID_TD_SORT_CRITERIA: // Click on sort criteria dropdown
953  break;
954 
955  case WID_TD_LIST: { // Click on Town Matrix
956  auto it = this->vscroll->GetScrolledItemFromWidget(this->towns, pt.y, this, WID_TD_LIST, WidgetDimensions::scaled.framerect.top);
957  if (it == this->towns.end()) return; // click out of town bounds
958 
959  const Town *t = *it;
960  assert(t != nullptr);
961  if (_ctrl_pressed) {
963  } else {
965  }
966  break;
967  }
968  }
969  }
970 
971  void OnDropdownSelect(WidgetID widget, int index) override
972  {
973  if (widget != WID_TD_SORT_CRITERIA) return;
974 
975  if (this->towns.SortType() != index) {
976  this->towns.SetSortType(index);
977  this->last_sorting = this->towns.GetListing(); // Store new sorting order.
978  this->BuildSortTownList();
979  }
980  }
981 
982  void OnPaint() override
983  {
984  if (this->towns.NeedRebuild()) this->BuildSortTownList();
985  this->DrawWidgets();
986  }
987 
989  IntervalTimer<TimerWindow> rebuild_interval = {std::chrono::seconds(3), [this](auto) {
990  this->BuildSortTownList();
991  this->SetDirty();
992  }};
993 
994  void OnResize() override
995  {
996  this->vscroll->SetCapacityFromWidget(this, WID_TD_LIST);
997  }
998 
999  void OnEditboxChanged(WidgetID wid) override
1000  {
1001  if (wid == WID_TD_FILTER) {
1002  this->string_filter.SetFilterTerm(this->townname_editbox.text.buf);
1003  this->InvalidateData(TDIWD_FORCE_REBUILD);
1004  }
1005  }
1006 
1012  void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
1013  {
1014  switch (data) {
1015  case TDIWD_FORCE_REBUILD:
1016  /* This needs to be done in command-scope to enforce rebuilding before resorting invalid data */
1017  this->towns.ForceRebuild();
1018  break;
1019 
1020  case TDIWD_POPULATION_CHANGE:
1021  if (this->towns.SortType() == 1) this->towns.ForceResort();
1022  break;
1023 
1024  default:
1025  this->towns.ForceResort();
1026  }
1027  }
1028 
1029  EventState OnHotkey(int hotkey) override
1030  {
1031  switch (hotkey) {
1032  case TDHK_FOCUS_FILTER_BOX:
1034  SetFocusedWindow(this); // The user has asked to give focus to the text box, so make sure this window is focused.
1035  break;
1036  default:
1037  return ES_NOT_HANDLED;
1038  }
1039  return ES_HANDLED;
1040  }
1041 
1042  static inline HotkeyList hotkeys {"towndirectory", {
1043  Hotkey('F', "focus_filter_box", TDHK_FOCUS_FILTER_BOX),
1044  }};
1045 };
1046 
1047 Listing TownDirectoryWindow::last_sorting = {false, 0};
1048 
1051  STR_SORT_BY_NAME,
1052  STR_SORT_BY_POPULATION,
1053  STR_SORT_BY_RATING,
1055 };
1056 
1059  &TownNameSorter,
1060  &TownPopulationSorter,
1061  &TownRatingSorter,
1062 };
1063 
1064 static WindowDesc _town_directory_desc(__FILE__, __LINE__,
1065  WDP_AUTO, "list_towns", 208, 202,
1067  0,
1068  std::begin(_nested_town_directory_widgets), std::end(_nested_town_directory_widgets),
1069  &TownDirectoryWindow::hotkeys
1070 );
1071 
1072 void ShowTownDirectory()
1073 {
1074  if (BringWindowToFrontById(WC_TOWN_DIRECTORY, 0)) return;
1075  new TownDirectoryWindow(&_town_directory_desc);
1076 }
1077 
1078 void CcFoundTown(Commands, const CommandCost &result, TileIndex tile)
1079 {
1080  if (result.Failed()) return;
1081 
1082  if (_settings_client.sound.confirm) SndPlayTileFx(SND_1F_CONSTRUCTION_OTHER, tile);
1084 }
1085 
1086 void CcFoundRandomTown(Commands, const CommandCost &result, Money, TownID town_id)
1087 {
1088  if (result.Succeeded()) ScrollMainWindowToTile(Town::Get(town_id)->xy);
1089 }
1090 
1091 static constexpr NWidgetPart _nested_found_town_widgets[] = {
1093  NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
1094  NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_FOUND_TOWN_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1095  NWidget(WWT_SHADEBOX, COLOUR_DARK_GREEN),
1096  NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN),
1097  EndContainer(),
1098  /* Construct new town(s) buttons. */
1099  NWidget(WWT_PANEL, COLOUR_DARK_GREEN),
1101  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),
1102  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),
1103  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),
1104  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),
1105 
1106  /* Town name selection. */
1107  NWidget(WWT_LABEL, COLOUR_DARK_GREEN), SetDataTip(STR_FOUND_TOWN_NAME_TITLE, STR_NULL),
1108  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),
1109  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),
1110 
1111  /* Town size selection. */
1112  NWidget(WWT_LABEL, COLOUR_DARK_GREEN), SetDataTip(STR_FOUND_TOWN_INITIAL_SIZE_TITLE, STR_NULL),
1115  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),
1116  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),
1117  EndContainer(),
1119  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),
1120  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_TF_SIZE_RANDOM), SetDataTip(STR_FOUND_TOWN_SIZE_RANDOM, STR_FOUND_TOWN_INITIAL_SIZE_TOOLTIP), SetFill(1, 0),
1121  EndContainer(),
1122  EndContainer(),
1123  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_TF_CITY), SetDataTip(STR_FOUND_TOWN_CITY, STR_FOUND_TOWN_CITY_TOOLTIP), SetFill(1, 0),
1124 
1125  /* Town roads selection. */
1126  NWidget(WWT_LABEL, COLOUR_DARK_GREEN), SetDataTip(STR_FOUND_TOWN_ROAD_LAYOUT, STR_NULL),
1129  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),
1130  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),
1131  EndContainer(),
1133  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),
1134  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),
1135  EndContainer(),
1136  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),
1137  EndContainer(),
1138  EndContainer(),
1139  EndContainer(),
1140 };
1141 
1144 private:
1147  bool city;
1150  uint32_t townnameparts;
1152 
1153 public:
1155  Window(desc),
1159  params(_settings_game.game_creation.town_name)
1160  {
1161  this->InitNested(window_number);
1163  this->RandomTownName();
1164  this->UpdateButtons(true);
1165  }
1166 
1167  void RandomTownName()
1168  {
1169  this->townnamevalid = GenerateTownName(_interactive_random, &this->townnameparts);
1170 
1171  if (!this->townnamevalid) {
1172  this->townname_editbox.text.DeleteAll();
1173  } else {
1174  this->townname_editbox.text.Assign(GetTownName(&this->params, this->townnameparts));
1175  }
1177 
1179  }
1180 
1181  void UpdateButtons(bool check_availability)
1182  {
1183  if (check_availability && _game_mode != GM_EDITOR) {
1188  }
1189 
1190  for (WidgetID i = WID_TF_SIZE_SMALL; i <= WID_TF_SIZE_RANDOM; i++) {
1191  this->SetWidgetLoweredState(i, i == WID_TF_SIZE_SMALL + this->town_size);
1192  }
1193 
1194  this->SetWidgetLoweredState(WID_TF_CITY, this->city);
1195 
1197  this->SetWidgetLoweredState(i, i == WID_TF_LAYOUT_ORIGINAL + this->town_layout);
1198  }
1199 
1200  this->SetDirty();
1201  }
1202 
1203  template <typename Tcallback>
1204  void ExecuteFoundTownCommand(TileIndex tile, bool random, StringID errstr, Tcallback cc)
1205  {
1206  std::string name;
1207 
1208  if (!this->townnamevalid) {
1209  name = this->townname_editbox.text.buf;
1210  } else {
1211  /* If user changed the name, send it */
1212  std::string original_name = GetTownName(&this->params, this->townnameparts);
1213  if (original_name != this->townname_editbox.text.buf) name = this->townname_editbox.text.buf;
1214  }
1215 
1216  bool success = Command<CMD_FOUND_TOWN>::Post(errstr, cc,
1217  tile, this->town_size, this->city, this->town_layout, random, townnameparts, name);
1218 
1219  /* Rerandomise name, if success and no cost-estimation. */
1220  if (success && !_shift_pressed) this->RandomTownName();
1221  }
1222 
1223  void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
1224  {
1225  switch (widget) {
1226  case WID_TF_NEW_TOWN:
1227  HandlePlacePushButton(this, WID_TF_NEW_TOWN, SPR_CURSOR_TOWN, HT_RECT);
1228  break;
1229 
1230  case WID_TF_RANDOM_TOWN:
1231  this->ExecuteFoundTownCommand(0, true, STR_ERROR_CAN_T_GENERATE_TOWN, CcFoundRandomTown);
1232  break;
1233 
1235  this->RandomTownName();
1237  break;
1238 
1239  case WID_TF_MANY_RANDOM_TOWNS: {
1240  Backup<bool> old_generating_world(_generating_world, true, FILE_LINE);
1242  if (!GenerateTowns(this->town_layout)) {
1243  ShowErrorMessage(STR_ERROR_CAN_T_GENERATE_TOWN, STR_ERROR_NO_SPACE_FOR_TOWN, WL_INFO);
1244  }
1246  old_generating_world.Restore();
1247  break;
1248  }
1249 
1251  for (Town *t : Town::Iterate()) {
1253  }
1254  break;
1255 
1257  this->town_size = (TownSize)(widget - WID_TF_SIZE_SMALL);
1258  this->UpdateButtons(false);
1259  break;
1260 
1261  case WID_TF_CITY:
1262  this->city ^= true;
1263  this->SetWidgetLoweredState(WID_TF_CITY, this->city);
1264  this->SetDirty();
1265  break;
1266 
1269  this->town_layout = (TownLayout)(widget - WID_TF_LAYOUT_ORIGINAL);
1270  this->UpdateButtons(false);
1271  break;
1272  }
1273  }
1274 
1275  void OnPlaceObject([[maybe_unused]] Point pt, TileIndex tile) override
1276  {
1277  this->ExecuteFoundTownCommand(tile, false, STR_ERROR_CAN_T_FOUND_TOWN_HERE, CcFoundTown);
1278  }
1279 
1280  void OnPlaceObjectAbort() override
1281  {
1282  this->RaiseButtons();
1283  this->UpdateButtons(false);
1284  }
1285 
1291  void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
1292  {
1293  if (!gui_scope) return;
1294  this->UpdateButtons(true);
1295  }
1296 };
1297 
1298 static WindowDesc _found_town_desc(__FILE__, __LINE__,
1299  WDP_AUTO, "build_town", 160, 162,
1302  std::begin(_nested_found_town_widgets), std::end(_nested_found_town_widgets)
1303 );
1304 
1305 void ShowFoundTownWindow()
1306 {
1307  if (_game_mode != GM_EDITOR && !Company::IsValidID(_local_company)) return;
1308  AllocateWindowDescFront<FoundTownWindow>(&_found_town_desc, 0);
1309 }
1310 
1311 void InitializeTownGui()
1312 {
1313  _town_local_authority_kdtree.Clear();
1314 }
ES_HANDLED
@ ES_HANDLED
The passed event is handled.
Definition: window_type.h:739
SetFill
constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
Widget part function for setting filling.
Definition: widget_type.h:1141
TACT_BRIBE
@ TACT_BRIBE
Try to bribe the council.
Definition: town.h:218
Town::have_ratings
CompanyMask have_ratings
which companies have a rating
Definition: town.h:69
TROPICZONE_DESERT
@ TROPICZONE_DESERT
Tile is desert.
Definition: tile_type.h:78
sound_func.h
TownDirectoryWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition: town_gui.cpp:982
TPE_MAIL
@ TPE_MAIL
Cargo behaves mail-like for production.
Definition: cargotype.h:37
WID_TV_EXPAND
@ WID_TV_EXPAND
Expand this town (scenario editor only).
Definition: town_widget.h:43
TownViewWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition: town_gui.cpp:391
WID_TD_FILTER
@ WID_TD_FILTER
Filter of name.
Definition: town_widget.h:17
Pool::PoolItem<&_town_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:335
ScrollMainWindowToTile
bool ScrollMainWindowToTile(TileIndex tile, bool instant)
Scrolls the viewport of the main window to a given location.
Definition: viewport.cpp:2509
querystring_gui.h
ShowExtraViewportWindow
void ShowExtraViewportWindow(TileIndex tile=INVALID_TILE)
Show a new Extra Viewport window.
Definition: viewport_gui.cpp:156
HotkeyList
List of hotkeys for a window.
Definition: hotkeys.h:37
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
SetFocusedWindow
void SetFocusedWindow(Window *w)
Set the window that has the focus.
Definition: window.cpp:423
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition: geometry_type.hpp:30
command_func.h
WidgetDimensions::scaled
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition: window_gui.h:68
EconomySettings::town_layout
TownLayout town_layout
select town layout,
Definition: settings_type.h:553
WWT_STICKYBOX
@ WWT_STICKYBOX
Sticky box (at top-right of a window, after WWT_DEFSIZEBOX)
Definition: widget_type.h:68
ShowErrorMessage
void ShowErrorMessage(StringID summary_msg, int x, int y, CommandCost cc)
Display an error message in a window.
Definition: error_gui.cpp:367
WDF_CONSTRUCTION
@ WDF_CONSTRUCTION
This window is used for construction; close it whenever changing company.
Definition: window_gui.h:197
dropdown_func.h
WID_TV_CENTER_VIEW
@ WID_TV_CENTER_VIEW
Center the main view on this town.
Definition: town_widget.h:39
Rect::Shrink
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Definition: geometry_type.hpp:98
Kdtree
K-dimensional tree, specialised for 2-dimensional space.
Definition: kdtree.hpp:35
WID_TF_LAYOUT_GRID3
@ WID_TF_LAYOUT_GRID3
Selection for the 3x3 grid town layout.
Definition: town_widget.h:63
StringFilter::IsEmpty
bool IsEmpty() const
Check whether any filter words were entered.
Definition: stringfilter_type.h:60
Backup
Class to backup a specific variable and restore it later.
Definition: backup_type.hpp:21
TownDirectoryWindow::OnHotkey
EventState OnHotkey(int hotkey) override
A hotkey has been pressed.
Definition: town_gui.cpp:1029
company_base.h
TDHK_FOCUS_FILTER_BOX
@ TDHK_FOCUS_FILTER_BOX
Focus the filter box.
Definition: town_gui.cpp:713
StringFilter::SetFilterTerm
void SetFilterTerm(const char *str)
Set the term to filter on.
Definition: stringfilter.cpp:28
timer_game_calendar.h
NWidgetViewport
Nested widget to display a viewport in a window.
Definition: widget_type.h:664
WC_FOUND_TOWN
@ WC_FOUND_TOWN
Found a town; Window numbers:
Definition: window_type.h:429
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:63
company_gui.h
Window::SetWidgetDirty
void SetWidgetDirty(WidgetID widget_index) const
Invalidate a widget, i.e.
Definition: window.cpp:552
StringID
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
NWidgetViewport::InitializeViewport
void InitializeViewport(Window *w, std::variant< TileIndex, VehicleID > focus, ZoomLevel zoom)
Initialize the viewport of the window.
Definition: widget.cpp:2228
WF_DISABLE_VP_SCROLL
@ WF_DISABLE_VP_SCROLL
Window does not do autoscroll,.
Definition: window_gui.h:229
GUIList< const Town *, const bool & >
Window::viewport
ViewportData * viewport
Pointer to viewport data, if present.
Definition: window_gui.h:312
Textbuf::Assign
void Assign(StringID string)
Render a string into the textbuffer.
Definition: textbuf.cpp:405
_network_server
bool _network_server
network-server is active
Definition: network.cpp:60
FoundTownWindow::townname_editbox
QueryString townname_editbox
Townname editbox.
Definition: town_gui.cpp:1148
WID_TV_CHANGE_NAME
@ WID_TV_CHANGE_NAME
Change the name of this town.
Definition: town_widget.h:41
WWT_LABEL
@ WWT_LABEL
Centered label.
Definition: widget_type.h:59
WWT_DEFSIZEBOX
@ WWT_DEFSIZEBOX
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX)
Definition: widget_type.h:67
IntervalTimer< TimerWindow >
TownSize
TownSize
Supported initial town sizes.
Definition: town_type.h:19
Pool::PoolItem::index
Tindex index
Index of this pool item.
Definition: pool_type.hpp:234
WID_TF_CITY
@ WID_TF_CITY
Selection for the town's city state.
Definition: town_widget.h:59
TACT_FUND_BUILDINGS
@ TACT_FUND_BUILDINGS
Fund new buildings.
Definition: town.h:216
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition: widget_type.h:77
WID_TD_WORLD_POPULATION
@ WID_TD_WORLD_POPULATION
The world's population.
Definition: town_widget.h:20
maxdim
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
Definition: geometry_func.cpp:22
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:1048
INVALID_TILE
constexpr TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:95
TSZ_MEDIUM
@ TSZ_MEDIUM
Medium town.
Definition: town_type.h:21
EndContainer
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition: widget_type.h:1151
Town::growth_rate
uint16_t growth_rate
town growth rate
Definition: town.h:92
TownDirectoryWindow::townname_editbox
QueryString townname_editbox
Filter editbox.
Definition: town_gui.cpp:727
_ctrl_pressed
bool _ctrl_pressed
Is Ctrl pressed?
Definition: gfx.cpp:37
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
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:764
TextColour
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition: gfx_type.h:253
GUIList::SetSortType
void SetSortType(uint8_t n_type)
Set the sorttype of the list.
Definition: sortlist_type.h:124
zoom_func.h
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:2334
Window::RaiseButtons
void RaiseButtons(bool autoraise=false)
Raise the buttons of the window.
Definition: window.cpp:526
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:585
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:54
TownViewWindow::GetDesiredInfoHeight
uint GetDesiredInfoHeight(int width) const
Gets the desired height for the information panel.
Definition: town_gui.cpp:540
Town::xy
TileIndex xy
town center tile
Definition: town.h:51
WID_TV_CATCHMENT
@ WID_TV_CATCHMENT
Toggle catchment area highlight.
Definition: town_widget.h:42
CargoSpec
Specification of a cargo type.
Definition: cargotype.h:68
WID_TD_LIST
@ WID_TD_LIST
List of towns.
Definition: town_widget.h:18
WID_TF_RANDOM_TOWN
@ WID_TF_RANDOM_TOWN
Randomly place a town.
Definition: town_widget.h:50
TownDirectoryWindow::sorter_names
static const StringID sorter_names[]
Names of the sorting functions.
Definition: town_gui.cpp:723
TimerGameEconomy::UsingWallclockUnits
static bool UsingWallclockUnits(bool newgame=false)
Check if we are using wallclock units.
Definition: timer_game_economy.cpp:97
town.h
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > >
StringFilter::AddLine
void AddLine(const char *str)
Pass another text line from the current item to the filter.
Definition: stringfilter.cpp:114
WID_TA_RATING_INFO
@ WID_TA_RATING_INFO
Overview with ratings for each company.
Definition: town_widget.h:27
TownLayout
TownLayout
Town Layouts.
Definition: town_type.h:80
WID_TF_LAYOUT_GRID2
@ WID_TF_LAYOUT_GRID2
Selection for the 2x2 grid town layout.
Definition: town_widget.h:62
ScaleZoomGUI
ZoomLevel ScaleZoomGUI(ZoomLevel value)
Scale zoom level relative to GUI zoom.
Definition: zoom_func.h:87
NWidgetBase::smallest_y
uint smallest_y
Smallest vertical size of the widget in a filled window.
Definition: widget_type.h:231
Scrollbar
Scrollbar data structure.
Definition: widget_type.h:678
Window::GetScrollbar
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
Definition: window.cpp:315
Town::fund_buildings_months
byte fund_buildings_months
fund buildings program in action?
Definition: town.h:94
DC_EXEC
@ DC_EXEC
execute the given command
Definition: command_type.h:371
TownAuthorityWindow::exclusive_size
Dimension exclusive_size
Dimensions of exlusive icon.
Definition: town_gui.cpp:82
TownAuthorityWindow::available_actions
TownActions available_actions
Actions that are available to execute for the current company.
Definition: town_gui.cpp:78
TownDirectoryWindow::rebuild_interval
IntervalTimer< TimerWindow > rebuild_interval
Redraw the whole window on a regular interval.
Definition: town_gui.cpp:989
Town::show_zone
bool show_zone
NOSAVE: mark town to show the local authority zone in the viewports.
Definition: town.h:100
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:1038
genworld.h
GUIList::NeedRebuild
bool NeedRebuild() const
Check if a rebuild is needed.
Definition: sortlist_type.h:387
Scrollbar::GetPosition
uint16_t GetPosition() const
Gets the position of the first visible element in the list.
Definition: widget_type.h:720
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:76
QueryString
Data stored about a string that can be modified in the GUI.
Definition: querystring_gui.h:20
CommandCost::Succeeded
bool Succeeded() const
Did this command succeed?
Definition: command_type.h:162
EconomySettings::bribe
bool bribe
enable bribing the local authority
Definition: settings_type.h:540
Textbuf::buf
char *const buf
buffer in which text is saved
Definition: textbuf_type.h:32
Kdtree::Remove
void Remove(const T &element)
Remove a single element from the tree, if it exists.
Definition: kdtree.hpp:417
_interactive_random
Randomizer _interactive_random
Random used everywhere else, where it does not (directly) influence the game state.
Definition: random_func.cpp:37
QSF_LEN_IN_CHARS
@ QSF_LEN_IN_CHARS
the length of the string is counted in characters
Definition: textbuf_gui.h:22
MAX_CHAR_LENGTH
static const int MAX_CHAR_LENGTH
Max. length of UTF-8 encoded unicode character.
Definition: strings_type.h:18
FoundTownWindow::town_size
TownSize town_size
Selected town size.
Definition: town_gui.cpp:1145
WID_TA_ZONE_BUTTON
@ WID_TA_ZONE_BUTTON
Turn on/off showing local authority zone.
Definition: town_widget.h:26
TF_CUSTOM_LAYOUT
@ TF_CUSTOM_LAYOUT
Allowed, with custom town layout.
Definition: town_type.h:98
WindowDesc
High level window description.
Definition: window_gui.h:153
WidgetID
int WidgetID
Widget ID.
Definition: window_type.h:18
RoundDivSU
constexpr int RoundDivSU(int a, uint b)
Computes round(a / b) for signed a and unsigned b.
Definition: math_func.hpp:342
townname_func.h
WID_TF_SIZE_RANDOM
@ WID_TF_SIZE_RANDOM
Selection for a randomly sized town.
Definition: town_widget.h:58
NC_EQUALSIZE
@ NC_EQUALSIZE
Value of the NCB_EQUALSIZE flag.
Definition: widget_type.h:508
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:1188
EconomySettings::fund_buildings
bool fund_buildings
allow funding new buildings
Definition: settings_type.h:545
CargoSpec::Index
CargoID Index() const
Determines index of this cargospec.
Definition: cargotype.h:102
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:557
town_widget.h
Town::supplied
TransportedCargoStat< uint32_t > supplied[NUM_CARGO]
Cargo statistics about supplied cargo.
Definition: town.h:75
SetResize
constexpr NWidgetPart SetResize(int16_t dx, int16_t dy)
Widget part function for setting the resize step.
Definition: widget_type.h:1086
WDP_AUTO
@ WDP_AUTO
Find a place automatically.
Definition: window_gui.h:141
Listing
Data structure describing how to show the list (what sort direction and criteria).
Definition: sortlist_type.h:30
WID_TD_SORT_ORDER
@ WID_TD_SORT_ORDER
Direction of sort dropdown.
Definition: town_widget.h:15
Window::resize
ResizeInfo resize
Resize information.
Definition: window_gui.h:308
CommandCost
Common return value for all commands.
Definition: command_type.h:23
GetSnowLine
byte GetSnowLine()
Get the current snow line, either variable or static.
Definition: landscape.cpp:611
TownAuthorityWindow::town
Town * town
Town being displayed.
Definition: town_gui.cpp:74
SetBitIterator
Iterable ensemble of each set bit in a value.
Definition: bitmath_func.hpp:282
NWidgetViewport::UpdateViewportCoordinates
void UpdateViewportCoordinates(Window *w)
Update the position and size of the viewport (after eg a resize).
Definition: widget.cpp:2237
town_cmd.h
tilehighlight_func.h
ClientSettings::sound
SoundSettings sound
sound effect settings
Definition: settings_type.h:639
WindowNumber
int32_t WindowNumber
Number to differentiate different windows of the same class.
Definition: window_type.h:732
TownAuthorityWindow::DrawActions
void DrawActions()
Draws the contents of the actions panel.
Definition: town_gui.cpp:215
FS_NORMAL
@ FS_NORMAL
Index of the normal font in the font tables.
Definition: gfx_type.h:203
WC_TOWN_AUTHORITY
@ WC_TOWN_AUTHORITY
Town authority; Window numbers:
Definition: window_type.h:194
TownAcceptanceEffect
TownAcceptanceEffect
Town growth effect when delivering cargo.
Definition: cargotype.h:21
Window::InitNested
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
Definition: window.cpp:1747
NWID_VIEWPORT
@ NWID_VIEWPORT
Nested widget containing a viewport.
Definition: widget_type.h:83
SetScrollbar
constexpr NWidgetPart SetScrollbar(WidgetID index)
Attach a scrollbar to a widget.
Definition: widget_type.h:1244
WWT_EDITBOX
@ WWT_EDITBOX
a textbox for typing
Definition: widget_type.h:73
TownViewWindow
Definition: town_gui.cpp:356
FoundTownWindow::OnInvalidateData
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
Definition: town_gui.cpp:1291
TownAuthorityWindow::OnInvalidateData
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
Definition: town_gui.cpp:331
TOWN_GROWTH_DESERT
static const uint TOWN_GROWTH_DESERT
The town needs the cargo for growth when on desert (any amount)
Definition: town.h:32
Window::SetDirty
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition: window.cpp:941
GUIList::SortFunction
std::conditional_t< std::is_same_v< P, std::nullptr_t >, bool(const T &, const T &), bool(const T &, const T &, const P)> SortFunction
Signature of sort function.
Definition: sortlist_type.h:49
Kdtree::Insert
void Insert(const T &element)
Insert a single element in the tree.
Definition: kdtree.hpp:398
GUIList::ForceResort
void ForceResort()
Force a resort next Sort call Reset the resort timer if used too.
Definition: sortlist_type.h:234
ScrollWindowToTile
bool ScrollWindowToTile(TileIndex tile, Window *w, bool instant)
Scrolls the viewport in a window to a given location.
Definition: viewport.cpp:2498
TownAuthorityWindow::sel_index
int sel_index
Currently selected town action, 0 to TACT_COUNT-1, -1 means no action selected.
Definition: town_gui.cpp:75
Listing::order
bool order
Ascending/descending.
Definition: sortlist_type.h:31
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:190
TownDirectoryWindow::GetTownString
static StringID GetTownString(const Town *t)
Get the string to draw the town name.
Definition: town_gui.cpp:830
WID_TV_DELETE
@ WID_TV_DELETE
Delete this town (scenario editor only).
Definition: town_widget.h:44
ES_NOT_HANDLED
@ ES_NOT_HANDLED
The passed event is not handled.
Definition: window_type.h:740
CommandCost::Failed
bool Failed() const
Did this command fail?
Definition: command_type.h:171
WWT_PUSHTXTBTN
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
Definition: widget_type.h:110
NWidgetBase
Baseclass for nested widgets.
Definition: widget_type.h:135
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:254
WID_TF_EXPAND_ALL_TOWNS
@ WID_TF_EXPAND_ALL_TOWNS
Make all towns grow slightly.
Definition: town_widget.h:52
Scrollbar::GetCapacity
uint16_t GetCapacity() const
Gets the number of visible elements of the scrollbar.
Definition: widget_type.h:711
TACT_ROAD_REBUILD
@ TACT_ROAD_REBUILD
Rebuild the roads.
Definition: town.h:214
Town::MaxTownNoise
uint16_t MaxTownNoise() const
Calculate the max town noise.
Definition: town.h:121
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:55
TownDirectoryWindow::string_filter
StringFilter string_filter
Filter for towns.
Definition: town_gui.cpp:726
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:953
GetMaskOfTownActions
TownActions GetMaskOfTownActions(CompanyID cid, const Town *t)
Get a list of available town authority actions.
Definition: town_cmd.cpp:3462
GameSettings::economy
EconomySettings economy
settings to change the economy
Definition: settings_type.h:628
WL_INFO
@ WL_INFO
Used for DoCommand-like (and some non-fatal AI GUI) errors/information.
Definition: error.h:24
ZOOM_LVL_TOWN
@ ZOOM_LVL_TOWN
Default zoom level for the town view.
Definition: zoom_type.h:34
NWidget
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1258
GUIList::IsDescSortOrder
bool IsDescSortOrder() const
Check if the sort order is descending.
Definition: sortlist_type.h:244
_local_company
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:49
safeguards.h
sortlist_type.h
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:1086
TownViewWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition: town_gui.cpp:577
WID_TF_SIZE_MEDIUM
@ WID_TF_SIZE_MEDIUM
Selection for a medium town.
Definition: town_widget.h:56
TownAuthorityWindow::GetNthSetBit
int GetNthSetBit(int n)
Get the position of the Nth set bit.
Definition: town_gui.cpp:92
timer.h
Window::flags
WindowFlags flags
Window flags.
Definition: window_gui.h:294
Rect::Indent
Rect Indent(int indent, bool end) const
Copy Rect and indent it from its position.
Definition: geometry_type.hpp:198
GetStringHeight
int GetStringHeight(std::string_view str, int maxw, FontSize fontsize)
Calculates height of string (in pixels).
Definition: gfx.cpp:705
TownAuthorityWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition: town_gui.cpp:145
TC_NO_SHADE
@ TC_NO_SHADE
Do not add shading to this text colour.
Definition: gfx_type.h:277
Rect::WithWidth
Rect WithWidth(int width, bool end) const
Copy Rect and set its width.
Definition: geometry_type.hpp:185
LowestSnowLine
byte LowestSnowLine()
Get the lowest possible snow line height, either variable or static.
Definition: landscape.cpp:634
_networking
bool _networking
are we in networking mode?
Definition: network.cpp:59
_shift_pressed
bool _shift_pressed
Is Shift pressed?
Definition: gfx.cpp:38
EconomySettings::exclusive_rights
bool exclusive_rights
allow buying exclusive rights
Definition: settings_type.h:544
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:1007
GetStringMultiLineBoundingBox
Dimension GetStringMultiLineBoundingBox(StringID str, const Dimension &suggestion)
Calculate string bounding box for multi-line strings.
Definition: gfx.cpp:741
FoundTownWindow::townnamevalid
bool townnamevalid
Is generated town name valid?
Definition: town_gui.cpp:1149
CargoID
byte CargoID
Cargo slots to indicate a cargo type within a game.
Definition: cargo_type.h:22
Point
Coordinates of a point in 2D.
Definition: geometry_type.hpp:21
EconomySettings::found_town
TownFounding found_town
town founding.
Definition: settings_type.h:556
error.h
Scrollbar::GetScrolledItemFromWidget
Tcontainer::iterator 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:845
_town_action_costs
const byte _town_action_costs[TACT_COUNT]
Factor in the cost of each town action.
Definition: town_cmd.cpp:3171
ShowDropDownMenu
void ShowDropDownMenu(Window *w, const StringID *strings, int selected, WidgetID button, uint32_t disabled_mask, uint32_t hidden_mask, uint width)
Show a dropdown menu window near a widget of the parent window.
Definition: dropdown.cpp:386
WID_TV_SHOW_AUTHORITY
@ WID_TV_SHOW_AUTHORITY
Show the town authority window.
Definition: town_widget.h:40
_viewport_highlight_town
const Town * _viewport_highlight_town
Currently selected town for coverage area highlight.
Definition: viewport.cpp:1004
FoundTownWindow::city
bool city
Are we building a city?
Definition: town_gui.cpp:1147
stdafx.h
Window::window_number
WindowNumber window_number
Window number within the window class.
Definition: window_gui.h:296
Window::SetFocusedWidget
bool SetFocusedWidget(WidgetID widget_index)
Set focus within this window to the given widget.
Definition: window.cpp:487
FoundTownWindow::params
TownNameParams params
Town name parameters.
Definition: town_gui.cpp:1151
landscape.h
ResizeInfo::step_height
uint step_height
Step-size of height resize changes.
Definition: window_gui.h:208
SpriteID
uint32_t SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition: gfx_type.h:17
FoundTownWindow::OnPlaceObjectAbort
void OnPlaceObjectAbort() override
The user cancelled a tile highlight mode that has been set.
Definition: town_gui.cpp:1280
TownDirectoryWindow::OnInvalidateData
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
Definition: town_gui.cpp:1012
UpdateNearestTownForRoadTiles
void UpdateNearestTownForRoadTiles(bool invalidate)
Updates cached nearest town for all road tiles.
Definition: road_cmd.cpp:1909
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:3140
CS_ALPHANUMERAL
@ CS_ALPHANUMERAL
Both numeric and alphabetic and spaces and stuff.
Definition: string_type.h:25
WID_TV_INFO
@ WID_TV_INFO
General information about the town.
Definition: town_widget.h:38
viewport_func.h
NWidgetBase::current_y
uint current_y
Current vertical size (after resizing).
Definition: widget_type.h:234
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:45
FindFirstCargoWithTownAcceptanceEffect
const CargoSpec * FindFirstCargoWithTownAcceptanceEffect(TownAcceptanceEffect effect)
Determines the first cargo with a certain town effect.
Definition: town_cmd.cpp:2909
Window::SetWidgetLoweredState
void SetWidgetLoweredState(WidgetID widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
Definition: window_gui.h:441
WID_TV_VIEWPORT
@ WID_TV_VIEWPORT
View of the center of the town.
Definition: town_widget.h:37
WC_TOWN_DIRECTORY
@ WC_TOWN_DIRECTORY
Town directory; Window numbers:
Definition: window_type.h:254
NWID_VERTICAL
@ NWID_VERTICAL
Vertical container.
Definition: widget_type.h:79
TownCache::population
uint32_t population
Current population of people.
Definition: town.h:42
DrawCompanyIcon
void DrawCompanyIcon(CompanyID c, int x, int y)
Draw the icon of a company.
Definition: company_cmd.cpp:158
WidgetDimensions::unscaled
static const WidgetDimensions unscaled
Unscaled widget dimensions.
Definition: window_gui.h:67
Window::SetWidgetDisabledState
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition: window_gui.h:381
TownAuthorityWindow
Town authority window.
Definition: town_gui.cpp:72
GetSpriteSize
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition: gfx.cpp:941
WWT_CLOSEBOX
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition: widget_type.h:71
WWT_RESIZEBOX
@ WWT_RESIZEBOX
Resize box (normally at bottom-right of a window)
Definition: widget_type.h:70
_generating_world
bool _generating_world
Whether we are generating the map or not.
Definition: genworld.cpp:62
TransportedCargoStat::old_max
Tstorage old_max
Maximum amount last month.
Definition: town_type.h:115
WID_TF_LAYOUT_RANDOM
@ WID_TF_LAYOUT_RANDOM
Selection for a randomly chosen town layout.
Definition: town_widget.h:64
WID_TF_TOWN_NAME_RANDOM
@ WID_TF_TOWN_NAME_RANDOM
Generate a random town name.
Definition: town_widget.h:54
TOWN_GROWTH_WINTER
static const uint TOWN_GROWTH_WINTER
The town only needs this cargo in the winter (any amount)
Definition: town.h:31
GUIList::ForceRebuild
void ForceRebuild()
Force that a rebuild is needed.
Definition: sortlist_type.h:395
string_func.h
TownAuthorityWindow::redraw_interval
IntervalTimer< TimerWindow > redraw_interval
Redraw the whole window on a regular interval.
Definition: town_gui.cpp:327
Window::IsWidgetLowered
bool IsWidgetLowered(WidgetID widget_index) const
Gets the lowered state of a widget.
Definition: window_gui.h:491
WWT_PUSHIMGBTN
@ WWT_PUSHIMGBTN
Normal push-button (no toggle button) with image caption.
Definition: widget_type.h:111
Window::querystrings
std::map< WidgetID, QueryString * > querystrings
QueryString associated to WWT_EDITBOX widgets.
Definition: window_gui.h:314
Town::text
std::string text
General text with additional information.
Definition: town.h:79
WID_TA_EXECUTE
@ WID_TA_EXECUTE
Do-it button.
Definition: town_widget.h:31
SBS_DOWN
@ SBS_DOWN
Sort ascending.
Definition: window_gui.h:214
SoundSettings::confirm
bool confirm
Play sound effect on successful constructions or other actions.
Definition: settings_type.h:240
QueryString::cancel_button
int cancel_button
Widget button of parent window to simulate when pressing CANCEL in OSK.
Definition: querystring_gui.h:28
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:775
Window::DrawSortButtonState
void DrawSortButtonState(WidgetID widget, SortButtonState state) const
Draw a sort button's up or down arrow symbol.
Definition: widget.cpp:763
WID_TF_MANY_RANDOM_TOWNS
@ WID_TF_MANY_RANDOM_TOWNS
Randomly place many towns.
Definition: town_widget.h:51
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:384
Window::CreateNestedTree
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
Definition: window.cpp:1724
strings_func.h
WID_TF_NEW_TOWN
@ WID_TF_NEW_TOWN
Create a new town.
Definition: town_widget.h:49
NWID_VSCROLLBAR
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition: widget_type.h:86
GenerateTowns
bool GenerateTowns(TownLayout layout)
Generate a number of towns with a given layout.
Definition: town_cmd.cpp:2329
WID_TA_COMMAND_LIST
@ WID_TA_COMMAND_LIST
List of commands for the player.
Definition: town_widget.h:28
Window::IsShaded
bool IsShaded() const
Is window shaded currently?
Definition: window_gui.h:556
TACT_COUNT
@ TACT_COUNT
Number of available town actions.
Definition: town.h:220
GUIList::GetListing
Listing GetListing() const
Export current sort conditions.
Definition: sortlist_type.h:137
TownAuthorityWindow::enabled_actions
TownActions enabled_actions
Actions that are enabled in settings.
Definition: town_gui.cpp:77
WID_TA_ACTION_INFO
@ WID_TA_ACTION_INFO
Additional information about the action.
Definition: town_widget.h:30
WWT_TEXT
@ WWT_TEXT
Pure simple text.
Definition: widget_type.h:60
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:1220
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
WID_TA_CAPTION
@ WID_TA_CAPTION
Caption of window.
Definition: town_widget.h:25
FoundTownWindow
Found a town window class.
Definition: town_gui.cpp:1143
geometry_func.hpp
GetTownName
static void GetTownName(StringBuilder &builder, const TownNameParams *par, uint32_t townnameparts)
Fills builder with specified town name.
Definition: townname.cpp:48
WID_TD_SCROLLBAR
@ WID_TD_SCROLLBAR
Scrollbar for the town list.
Definition: town_widget.h:19
TownDirectoryWindow::sorter_funcs
static GUITownList::SortFunction *const sorter_funcs[]
Available town directory sorting functions.
Definition: town_gui.cpp:724
Town::goal
uint32_t goal[NUM_TAE]
Amount of cargo required for the town to grow.
Definition: town.h:77
StringFilter::ResetState
void ResetState()
Reset the matching state to process a new item.
Definition: stringfilter.cpp:98
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition: widget_type.h:52
WidgetDimensions::vsep_normal
int vsep_normal
Normal vertical spacing.
Definition: window_gui.h:60
WID_TF_SIZE_SMALL
@ WID_TF_SIZE_SMALL
Selection for a small town.
Definition: town_widget.h:55
TransportedCargoStat::old_act
Tstorage old_act
Actually transported last month.
Definition: town_type.h:117
TownAuthorityWindow::GetEnabledActions
static TownActions GetEnabledActions()
Gets all town authority actions enabled in settings.
Definition: town_gui.cpp:108
Scrollbar::SetCount
void SetCount(size_t num)
Sets the number of elements in the list.
Definition: widget_type.h:760
Town::cache
TownCache cache
Container for all cacheable data.
Definition: town.h:53
EventState
EventState
State of handling an event.
Definition: window_type.h:738
HT_RECT
@ HT_RECT
rectangle (stations, depots, ...)
Definition: tilehighlight_type.h:21
TownNameParams
Struct holding parameters used to generate town name.
Definition: townname_type.h:28
StringFilter::GetState
bool GetState() const
Get the matching state of the current item.
Definition: stringfilter_type.h:71
TOWN_IS_GROWING
@ TOWN_IS_GROWING
Conditions for town growth are met. Grow according to Town::growth_rate.
Definition: town.h:192
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:352
CargoSpec::name
StringID name
Name of this type of cargo.
Definition: cargotype.h:85
EconomySettings::fund_roads
bool fund_roads
allow funding local road reconstruction
Definition: settings_type.h:546
Window::FinishInitNested
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition: window.cpp:1734
TownAuthorityWindow::OnInit
void OnInit() override
Notification that the nested widget tree gets initialized.
Definition: town_gui.cpp:139
company_func.h
WWT_INSET
@ WWT_INSET
Pressed (inset) panel, most commonly used as combo box text area.
Definition: widget_type.h:53
TownCache::num_houses
uint32_t num_houses
Amount of houses.
Definition: town.h:41
QueryString::ACTION_CLEAR
static const int ACTION_CLEAR
Clear editbox.
Definition: querystring_gui.h:24
TACT_NONE
@ TACT_NONE
Empty action set.
Definition: town.h:209
TownDirectoryWindow::TownNameSorter
static bool TownNameSorter(const Town *const &a, const Town *const &b, const bool &)
Sort by town name.
Definition: town_gui.cpp:758
Kdtree::Clear
void Clear()
Clear the tree.
Definition: kdtree.hpp:377
network.h
CommandHelper
Definition: command_func.h:93
GUIList::SortType
uint8_t SortType() const
Get the sorttype of the list.
Definition: sortlist_type.h:114
window_func.h
GetCharacterHeight
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Definition: fontcache.cpp:78
TownAuthorityWindow::DrawRatings
void DrawRatings()
Draw the contents of the ratings panel.
Definition: town_gui.cpp:163
Town
Town data structure.
Definition: town.h:50
Window::width
int width
width of the window (number of pixels to the right in x direction)
Definition: window_gui.h:305
stringfilter_type.h
SetMinimalSize
constexpr NWidgetPart SetMinimalSize(int16_t x, int16_t y)
Widget part function for setting the minimal size.
Definition: widget_type.h:1097
MarkWholeScreenDirty
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
Definition: gfx.cpp:1552
TownDirectoryWindow
Town directory window class.
Definition: town_gui.cpp:717
Window::SortButtonWidth
static int SortButtonWidth()
Get width of up/down arrow of sort button state.
Definition: widget.cpp:780
GUIList::SetSortFuncs
void SetSortFuncs(SortFunction *const *n_funcs)
Hand the array of sort function pointers to the sort list.
Definition: sortlist_type.h:295
GUIList::RebuildDone
void RebuildDone()
Notify the sortlist that the rebuild is done.
Definition: sortlist_type.h:405
TileHeight
static debug_inline uint TileHeight(Tile tile)
Returns the height of a tile.
Definition: tile_map.h:29
SND_1F_CONSTRUCTION_OTHER
@ SND_1F_CONSTRUCTION_OTHER
29 == 0x1D Construction: other (non-water, non-rail, non-bridge)
Definition: sound_type.h:68
OverflowSafeInt< int64_t >
WID_TF_LAYOUT_ORIGINAL
@ WID_TF_LAYOUT_ORIGINAL
Selection for the original town layout.
Definition: town_widget.h:60
TAE_END
@ TAE_END
End of town effects.
Definition: cargotype.h:29
Town::ratings
int16_t ratings[MAX_COMPANIES]
ratings of each company for this town
Definition: town.h:73
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:658
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:214
Town::received
TransportedCargoStat< uint16_t > received[NUM_TAE]
Cargo statistics about received cargotypes.
Definition: town.h:76
timer_window.h
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:408
WC_TOWN_VIEW
@ WC_TOWN_VIEW
Town view; Window numbers:
Definition: window_type.h:333
GenerateTownName
bool GenerateTownName(Randomizer &randomizer, uint32_t *townnameparts, TownNames *town_names)
Generates valid town name.
Definition: townname.cpp:136
Town::noise_reached
uint16_t noise_reached
level of noise that all the airports are generating
Definition: town.h:64
gui.h
TownDirectoryHotkeys
TownDirectoryHotkeys
Enum referring to the Hotkeys in the town directory window.
Definition: town_gui.cpp:712
WID_TF_SIZE_LARGE
@ WID_TF_SIZE_LARGE
Selection for a large town.
Definition: town_widget.h:57
Window
Data structure for an opened window.
Definition: window_gui.h:267
Commands
Commands
List of commands.
Definition: command_type.h:187
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:48
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:213
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:324
TPE_PASSENGERS
@ TPE_PASSENGERS
Cargo behaves passenger-like for production.
Definition: cargotype.h:36
Window::DrawWidgets
void DrawWidgets() const
Paint all widgets of a window.
Definition: widget.cpp:731
WID_TF_TOWN_NAME_EDITBOX
@ WID_TF_TOWN_NAME_EDITBOX
Editor for the town name.
Definition: town_widget.h:53
Town::larger_town
bool larger_town
if this is a larger town and should grow more quickly
Definition: town.h:97
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:110
SetDataTip
constexpr NWidgetPart SetDataTip(uint32_t data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1162
FoundTownWindow::town_layout
TownLayout town_layout
Selected town layout.
Definition: town_gui.cpp:1146
SBS_UP
@ SBS_UP
Sort descending.
Definition: window_gui.h:215
GetWorldPopulation
uint32_t GetWorldPopulation()
Get the total population, the sum of all towns in the world.
Definition: town_cmd.cpp:455
WID_TD_SORT_CRITERIA
@ WID_TD_SORT_CRITERIA
Criteria of sort dropdown.
Definition: town_widget.h:16
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:75
Company
Definition: company_base.h:116
BringWindowToFrontById
Window * BringWindowToFrontById(WindowClass cls, WindowNumber number)
Find a window and make it the relative top-window on the screen.
Definition: window.cpp:1224
Town::exclusivity
CompanyID exclusivity
which company has exclusivity
Definition: town.h:71
GUIList::Sort
bool Sort(Comp compare)
Sort the list.
Definition: sortlist_type.h:268
Window::SetWidgetsDisabledState
void SetWidgetsDisabledState(bool disab_stat, Args... widgets)
Sets the enabled/disabled status of a list of widgets.
Definition: window_gui.h:515
TACT_ALL
@ TACT_ALL
All possible actions.
Definition: town.h:225
GetTropicZone
TropicZone GetTropicZone(Tile tile)
Get the tropic zone.
Definition: tile_map.h:238
QSF_ENABLE_DEFAULT
@ QSF_ENABLE_DEFAULT
enable the 'Default' button ("\0" is returned)
Definition: textbuf_gui.h:21
CLRBITS
#define CLRBITS(x, y)
Clears several bits in a variable.
Definition: bitmath_func.hpp:166
NWidgetBase::current_x
uint current_x
Current horizontal size (after resizing).
Definition: widget_type.h:233
WidgetDimensions::framerect
RectPadding framerect
Standard padding inside many panels.
Definition: window_gui.h:42
WidgetDimensions::hsep_normal
int hsep_normal
Normal horizontal spacing.
Definition: window_gui.h:63
WID_TV_CAPTION
@ WID_TV_CAPTION
Caption of window.
Definition: town_widget.h:36
ResetObjectToPlace
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows).
Definition: viewport.cpp:3483
town_kdtree.h
Textbuf::DeleteAll
void DeleteAll()
Delete every character in the textbuffer.
Definition: textbuf.cpp:113
TD_RTL
@ TD_RTL
Text is written right-to-left by default.
Definition: strings_type.h:24
_current_text_dir
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition: strings.cpp:56
TownActions
TownActions
Town actions of a company.
Definition: town.h:208
GetStringBoundingBox
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:852
StringFilter
String filter and state.
Definition: stringfilter_type.h:30
FoundTownWindow::townnameparts
uint32_t townnameparts
Generated town name.
Definition: town_gui.cpp:1150
road_cmd.h
WWT_TEXTBTN
@ WWT_TEXTBTN
(Toggle) Button with text
Definition: widget_type.h:57
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
ClientSettings::gui
GUISettings gui
settings related to the GUI
Definition: settings_type.h:636
WID_TF_LAYOUT_BETTER
@ WID_TF_LAYOUT_BETTER
Selection for the better town layout.
Definition: town_widget.h:61
WWT_DROPDOWN
@ WWT_DROPDOWN
Drop down list.
Definition: widget_type.h:72
SetViewportCatchmentTown
void SetViewportCatchmentTown(const Town *t, bool sel)
Select or deselect town for coverage area highlight.
Definition: viewport.cpp:3643
GUISettings::persistent_buildingtools
bool persistent_buildingtools
keep the building tools active after usage
Definition: settings_type.h:190
GUIList::SetListing
void SetListing(Listing l)
Import sort conditions.
Definition: sortlist_type.h:151
Town::flags
byte flags
See TownFlags.
Definition: town.h:62
TownDirectoryWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition: town_gui.cpp:994
Hotkey
All data for a single hotkey.
Definition: hotkeys.h:21
TACT_BUY_RIGHTS
@ TACT_BUY_RIGHTS
Buy exclusive transport rights.
Definition: town.h:217
hotkeys.h
TownDirectoryWindow::TownRatingSorter
static bool TownRatingSorter(const Town *const &a, const Town *const &b, const bool &order)
Sort by town rating.
Definition: town_gui.cpp:773
ResizeWindow
void ResizeWindow(Window *w, int delta_x, int delta_y, bool clamp_to_screen)
Resize the window.
Definition: window.cpp:2027
TownViewWindow::OnInvalidateData
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
Definition: town_gui.cpp:592
TownAuthorityWindow::icon_size
Dimension icon_size
Dimensions of company icon.
Definition: town_gui.cpp:81
WWT_SHADEBOX
@ WWT_SHADEBOX
Shade box (at top-right of a window, between WWT_DEBUGBOX and WWT_DEFSIZEBOX)
Definition: widget_type.h:66
TownViewWindow::town
Town * town
Town displayed by the window.
Definition: town_gui.cpp:358
backup_type.hpp
HasBit
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:103