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