OpenTTD Source  12.0-beta2
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 
37 #include "widgets/town_widget.h"
38 
39 #include "table/strings.h"
40 
41 #include "safeguards.h"
42 
43 TownKdtree _town_local_authority_kdtree(&Kdtree_TownXYFunc);
44 
46 
47 static const NWidgetPart _nested_town_authority_widgets[] = {
49  NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
50  NWidget(WWT_CAPTION, COLOUR_BROWN, WID_TA_CAPTION), SetDataTip(STR_LOCAL_AUTHORITY_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
51  NWidget(WWT_TEXTBTN, COLOUR_BROWN, WID_TA_ZONE_BUTTON), SetMinimalSize(50, 0), SetMinimalTextLines(1, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM + 2), SetDataTip(STR_LOCAL_AUTHORITY_ZONE, STR_LOCAL_AUTHORITY_ZONE_TOOLTIP),
52  NWidget(WWT_SHADEBOX, COLOUR_BROWN),
53  NWidget(WWT_DEFSIZEBOX, COLOUR_BROWN),
54  NWidget(WWT_STICKYBOX, COLOUR_BROWN),
55  EndContainer(),
56  NWidget(WWT_PANEL, COLOUR_BROWN, WID_TA_RATING_INFO), SetMinimalSize(317, 92), SetResize(1, 1), EndContainer(),
58  NWidget(WWT_PANEL, COLOUR_BROWN, WID_TA_COMMAND_LIST), SetMinimalSize(305, 52), SetResize(1, 0), SetDataTip(0x0, STR_LOCAL_AUTHORITY_ACTIONS_TOOLTIP), SetScrollbar(WID_TA_SCROLLBAR), EndContainer(),
60  EndContainer(),
61  NWidget(WWT_PANEL, COLOUR_BROWN, WID_TA_ACTION_INFO), SetMinimalSize(317, 52), SetResize(1, 0), EndContainer(),
63  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),
64  NWidget(WWT_RESIZEBOX, COLOUR_BROWN),
65  EndContainer()
66 };
67 
70 private:
72  int sel_index;
73  Scrollbar *vscroll;
75 
85  static int GetNthSetBit(uint32 bits, int n)
86  {
87  if (n >= 0) {
88  for (uint i : SetBitIterator(bits)) {
89  n--;
90  if (n < 0) return i;
91  }
92  }
93  return -1;
94  }
95 
96 public:
98  {
99  this->town = Town::Get(window_number);
100  this->InitNested(window_number);
101  this->vscroll = this->GetScrollbar(WID_TA_SCROLLBAR);
102  this->vscroll->SetCapacity((this->GetWidget<NWidgetBase>(WID_TA_COMMAND_LIST)->current_y - WD_FRAMERECT_TOP - WD_FRAMERECT_BOTTOM) / FONT_HEIGHT_NORMAL);
103  }
104 
105  void OnPaint() override
106  {
107  int numact;
108  uint buttons = GetMaskOfTownActions(&numact, _local_company, this->town);
109  if (buttons != displayed_actions_on_previous_painting) this->SetDirty();
110  displayed_actions_on_previous_painting = buttons;
111 
112  this->vscroll->SetCount(numact + 1);
113 
114  if (this->sel_index != -1 && !HasBit(buttons, this->sel_index)) {
115  this->sel_index = -1;
116  }
117 
119  this->SetWidgetDisabledState(WID_TA_EXECUTE, this->sel_index == -1);
120 
121  this->DrawWidgets();
122  if (!this->IsShaded()) this->DrawRatings();
123  }
124 
126  void DrawRatings()
127  {
128  NWidgetBase *nwid = this->GetWidget<NWidgetBase>(WID_TA_RATING_INFO);
129  uint left = nwid->pos_x + WD_FRAMERECT_LEFT;
130  uint right = nwid->pos_x + nwid->current_x - 1 - WD_FRAMERECT_RIGHT;
131 
132  uint y = nwid->pos_y + WD_FRAMERECT_TOP;
133 
134  DrawString(left, right, y, STR_LOCAL_AUTHORITY_COMPANY_RATINGS);
135  y += FONT_HEIGHT_NORMAL;
136 
137  Dimension icon_size = GetSpriteSize(SPR_COMPANY_ICON);
138  int icon_width = icon_size.width;
139  int icon_y_offset = (FONT_HEIGHT_NORMAL - icon_size.height) / 2;
140 
141  Dimension exclusive_size = GetSpriteSize(SPR_EXCLUSIVE_TRANSPORT);
142  int exclusive_width = exclusive_size.width;
143  int exclusive_y_offset = (FONT_HEIGHT_NORMAL - exclusive_size.height) / 2;
144 
145  bool rtl = _current_text_dir == TD_RTL;
146  uint text_left = left + (rtl ? 0 : icon_width + exclusive_width + 4);
147  uint text_right = right - (rtl ? icon_width + exclusive_width + 4 : 0);
148  uint icon_left = rtl ? right - icon_width : left;
149  uint exclusive_left = rtl ? right - icon_width - exclusive_width - 2 : left + icon_width + 2;
150 
151  /* Draw list of companies */
152  for (const Company *c : Company::Iterate()) {
153  if ((HasBit(this->town->have_ratings, c->index) || this->town->exclusivity == c->index)) {
154  DrawCompanyIcon(c->index, icon_left, y + icon_y_offset);
155 
156  SetDParam(0, c->index);
157  SetDParam(1, c->index);
158 
159  int r = this->town->ratings[c->index];
160  StringID str = STR_CARGO_RATING_APPALLING;
161  if (r > RATING_APPALLING) str++;
162  if (r > RATING_VERYPOOR) str++;
163  if (r > RATING_POOR) str++;
164  if (r > RATING_MEDIOCRE) str++;
165  if (r > RATING_GOOD) str++;
166  if (r > RATING_VERYGOOD) str++;
167  if (r > RATING_EXCELLENT) str++;
168 
169  SetDParam(2, str);
170  if (this->town->exclusivity == c->index) {
171  DrawSprite(SPR_EXCLUSIVE_TRANSPORT, COMPANY_SPRITE_COLOUR(c->index), exclusive_left, y + exclusive_y_offset);
172  }
173 
174  DrawString(text_left, text_right, y, STR_LOCAL_AUTHORITY_COMPANY_RATING);
175  y += FONT_HEIGHT_NORMAL;
176  }
177  }
178 
179  y = y + WD_FRAMERECT_BOTTOM - nwid->pos_y; // Compute needed size of the widget.
180  if (y > nwid->current_y) {
181  /* If the company list is too big to fit, mark ourself dirty and draw again. */
182  ResizeWindow(this, 0, y - nwid->current_y, false);
183  }
184  }
185 
186  void SetStringParameters(int widget) const override
187  {
188  if (widget == WID_TA_CAPTION) SetDParam(0, this->window_number);
189  }
190 
191  void DrawWidget(const Rect &r, int widget) const override
192  {
193  switch (widget) {
194  case WID_TA_ACTION_INFO:
195  if (this->sel_index != -1) {
196  SetDParam(0, _price[PR_TOWN_ACTION] * _town_action_costs[this->sel_index] >> 8);
198  STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_SMALL_ADVERTISING + this->sel_index);
199  }
200  break;
201  case WID_TA_COMMAND_LIST: {
202  int numact;
203  uint buttons = GetMaskOfTownActions(&numact, _local_company, this->town);
204  int y = r.top + WD_FRAMERECT_TOP;
205  int pos = this->vscroll->GetPosition();
206 
207  if (--pos < 0) {
208  DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_LOCAL_AUTHORITY_ACTIONS_TITLE);
209  y += FONT_HEIGHT_NORMAL;
210  }
211 
212  for (int i = 0; buttons; i++, buttons >>= 1) {
213  if (pos <= -5) break;
214 
215  if ((buttons & 1) && --pos < 0) {
216  DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y,
217  STR_LOCAL_AUTHORITY_ACTION_SMALL_ADVERTISING_CAMPAIGN + i, this->sel_index == i ? TC_WHITE : TC_ORANGE);
218  y += FONT_HEIGHT_NORMAL;
219  }
220  }
221  break;
222  }
223  }
224  }
225 
226  void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
227  {
228  switch (widget) {
229  case WID_TA_ACTION_INFO: {
230  assert(size->width > padding.width && size->height > padding.height);
231  size->width -= WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT;
232  size->height -= WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
233  Dimension d = {0, 0};
234  for (int i = 0; i < TACT_COUNT; i++) {
235  SetDParam(0, _price[PR_TOWN_ACTION] * _town_action_costs[i] >> 8);
236  d = maxdim(d, GetStringMultiLineBoundingBox(STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_SMALL_ADVERTISING + i, *size));
237  }
238  *size = maxdim(*size, d);
239  size->width += WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT;
240  size->height += WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
241  break;
242  }
243 
244  case WID_TA_COMMAND_LIST:
246  size->width = GetStringBoundingBox(STR_LOCAL_AUTHORITY_ACTIONS_TITLE).width;
247  for (uint i = 0; i < TACT_COUNT; i++ ) {
248  size->width = std::max(size->width, GetStringBoundingBox(STR_LOCAL_AUTHORITY_ACTION_SMALL_ADVERTISING_CAMPAIGN + i).width);
249  }
250  size->width += WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT;
251  break;
252 
253  case WID_TA_RATING_INFO:
254  resize->height = FONT_HEIGHT_NORMAL;
256  break;
257  }
258  }
259 
260  void OnClick(Point pt, int widget, int click_count) override
261  {
262  switch (widget) {
263  case WID_TA_ZONE_BUTTON: {
264  bool new_show_state = !this->town->show_zone;
265  TownID index = this->town->index;
266 
267  new_show_state ? _town_local_authority_kdtree.Insert(index) : _town_local_authority_kdtree.Remove(index);
268 
269  this->town->show_zone = new_show_state;
270  this->SetWidgetLoweredState(widget, new_show_state);
272  break;
273  }
274 
275  case WID_TA_COMMAND_LIST: {
277  if (!IsInsideMM(y, 0, 5)) return;
278 
279  y = GetNthSetBit(GetMaskOfTownActions(nullptr, _local_company, this->town), y + this->vscroll->GetPosition() - 1);
280  if (y >= 0) {
281  this->sel_index = y;
282  this->SetDirty();
283  }
284  /* When double-clicking, continue */
285  if (click_count == 1 || y < 0) break;
286  FALLTHROUGH;
287  }
288 
289  case WID_TA_EXECUTE:
290  DoCommandP(this->town->xy, this->window_number, this->sel_index, CMD_DO_TOWN_ACTION | CMD_MSG(STR_ERROR_CAN_T_DO_THIS));
291  break;
292  }
293  }
294 
295  void OnHundredthTick() override
296  {
297  this->SetDirty();
298  }
299 };
300 
301 static WindowDesc _town_authority_desc(
302  WDP_AUTO, "view_town_authority", 317, 222,
304  0,
305  _nested_town_authority_widgets, lengthof(_nested_town_authority_widgets)
306 );
307 
308 static void ShowTownAuthorityWindow(uint town)
309 {
310  AllocateWindowDescFront<TownAuthorityWindow>(&_town_authority_desc, town);
311 }
312 
313 
314 /* Town view window. */
316 private:
318 
319 public:
320  static const int WID_TV_HEIGHT_NORMAL = 150;
321 
323  {
324  this->CreateNestedTree();
325 
326  this->town = Town::Get(window_number);
327  if (this->town->larger_town) this->GetWidget<NWidgetCore>(WID_TV_CAPTION)->widget_data = STR_TOWN_VIEW_CITY_CAPTION;
328 
329  this->FinishInitNested(window_number);
330 
331  this->flags |= WF_DISABLE_VP_SCROLL;
332  NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(WID_TV_VIEWPORT);
333  nvp->InitializeViewport(this, this->town->xy, ZOOM_LVL_NEWS);
334 
335  /* disable renaming town in network games if you are not the server */
337  }
338 
339  void Close() override
340  {
341  SetViewportCatchmentTown(Town::Get(this->window_number), false);
342  this->Window::Close();
343  }
344 
345  void SetStringParameters(int widget) const override
346  {
347  if (widget == WID_TV_CAPTION) SetDParam(0, this->town->index);
348  }
349 
350  void OnPaint() override
351  {
352  extern const Town *_viewport_highlight_town;
353  this->SetWidgetLoweredState(WID_TV_CATCHMENT, _viewport_highlight_town == this->town);
354 
355  this->DrawWidgets();
356  }
357 
358  void DrawWidget(const Rect &r, int widget) const override
359  {
360  if (widget != WID_TV_INFO) return;
361 
362  uint y = r.top + WD_FRAMERECT_TOP;
363 
364  SetDParam(0, this->town->cache.population);
365  SetDParam(1, this->town->cache.num_houses);
366  DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_LEFT, y, STR_TOWN_VIEW_POPULATION_HOUSES);
367 
368  SetDParam(0, 1 << CT_PASSENGERS);
369  SetDParam(1, this->town->supplied[CT_PASSENGERS].old_act);
370  SetDParam(2, this->town->supplied[CT_PASSENGERS].old_max);
371  DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_LEFT, y += FONT_HEIGHT_NORMAL, STR_TOWN_VIEW_CARGO_LAST_MONTH_MAX);
372 
373  SetDParam(0, 1 << CT_MAIL);
374  SetDParam(1, this->town->supplied[CT_MAIL].old_act);
375  SetDParam(2, this->town->supplied[CT_MAIL].old_max);
376  DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_LEFT, y += FONT_HEIGHT_NORMAL, STR_TOWN_VIEW_CARGO_LAST_MONTH_MAX);
377 
378  bool first = true;
379  for (int i = TE_BEGIN; i < TE_END; i++) {
380  if (this->town->goal[i] == 0) continue;
381  if (this->town->goal[i] == TOWN_GROWTH_WINTER && (TileHeight(this->town->xy) < LowestSnowLine() || this->town->cache.population <= 90)) continue;
382  if (this->town->goal[i] == TOWN_GROWTH_DESERT && (GetTropicZone(this->town->xy) != TROPICZONE_DESERT || this->town->cache.population <= 60)) continue;
383 
384  if (first) {
385  DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_LEFT, y += FONT_HEIGHT_NORMAL, STR_TOWN_VIEW_CARGO_FOR_TOWNGROWTH);
386  first = false;
387  }
388 
389  bool rtl = _current_text_dir == TD_RTL;
390  uint cargo_text_left = r.left + WD_FRAMERECT_LEFT + (rtl ? 0 : 20);
391  uint cargo_text_right = r.right - WD_FRAMERECT_RIGHT - (rtl ? 20 : 0);
392 
394  assert(cargo != nullptr);
395 
396  StringID string;
397 
398  if (this->town->goal[i] == TOWN_GROWTH_DESERT || this->town->goal[i] == TOWN_GROWTH_WINTER) {
399  /* For 'original' gameplay, don't show the amount required (you need 1 or more ..) */
400  string = STR_TOWN_VIEW_CARGO_FOR_TOWNGROWTH_DELIVERED_GENERAL;
401  if (this->town->received[i].old_act == 0) {
402  string = STR_TOWN_VIEW_CARGO_FOR_TOWNGROWTH_REQUIRED_GENERAL;
403 
404  if (this->town->goal[i] == TOWN_GROWTH_WINTER && TileHeight(this->town->xy) < GetSnowLine()) {
405  string = STR_TOWN_VIEW_CARGO_FOR_TOWNGROWTH_REQUIRED_WINTER;
406  }
407  }
408 
409  SetDParam(0, cargo->name);
410  } else {
411  string = STR_TOWN_VIEW_CARGO_FOR_TOWNGROWTH_DELIVERED;
412  if (this->town->received[i].old_act < this->town->goal[i]) {
413  string = STR_TOWN_VIEW_CARGO_FOR_TOWNGROWTH_REQUIRED;
414  }
415 
416  SetDParam(0, cargo->Index());
417  SetDParam(1, this->town->received[i].old_act);
418  SetDParam(2, cargo->Index());
419  SetDParam(3, this->town->goal[i]);
420  }
421  DrawString(cargo_text_left, cargo_text_right, y += FONT_HEIGHT_NORMAL, string);
422  }
423 
424  if (HasBit(this->town->flags, TOWN_IS_GROWING)) {
425  SetDParam(0, RoundDivSU(this->town->growth_rate + 1, DAY_TICKS));
426  DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_LEFT, y += FONT_HEIGHT_NORMAL, this->town->fund_buildings_months == 0 ? STR_TOWN_VIEW_TOWN_GROWS_EVERY : STR_TOWN_VIEW_TOWN_GROWS_EVERY_FUNDED);
427  } else {
428  DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_LEFT, y += FONT_HEIGHT_NORMAL, STR_TOWN_VIEW_TOWN_GROW_STOPPED);
429  }
430 
431  /* only show the town noise, if the noise option is activated. */
433  SetDParam(0, this->town->noise_reached);
434  SetDParam(1, this->town->MaxTownNoise());
435  DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_LEFT, y += FONT_HEIGHT_NORMAL, STR_TOWN_VIEW_NOISE_IN_TOWN);
436  }
437 
438  if (!this->town->text.empty()) {
439  SetDParamStr(0, this->town->text);
440  DrawStringMultiLine(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y += FONT_HEIGHT_NORMAL, UINT16_MAX, STR_JUST_RAW_STRING, TC_BLACK);
441  }
442  }
443 
444  void OnClick(Point pt, int widget, int click_count) override
445  {
446  switch (widget) {
447  case WID_TV_CENTER_VIEW: // scroll to location
448  if (_ctrl_pressed) {
449  ShowExtraViewportWindow(this->town->xy);
450  } else {
451  ScrollMainWindowToTile(this->town->xy);
452  }
453  break;
454 
455  case WID_TV_SHOW_AUTHORITY: // town authority
456  ShowTownAuthorityWindow(this->window_number);
457  break;
458 
459  case WID_TV_CHANGE_NAME: // rename
460  SetDParam(0, this->window_number);
461  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);
462  break;
463 
464  case WID_TV_CATCHMENT:
466  break;
467 
468  case WID_TV_EXPAND: { // expand town - only available on Scenario editor
469  /* Warn the user if towns are not allowed to build roads, but do this only once per OpenTTD run. */
470  static bool _warn_town_no_roads = false;
471 
472  if (!_settings_game.economy.allow_town_roads && !_warn_town_no_roads) {
473  ShowErrorMessage(STR_ERROR_TOWN_EXPAND_WARN_NO_ROADS, INVALID_STRING_ID, WL_WARNING);
474  _warn_town_no_roads = true;
475  }
476 
477  DoCommandP(0, this->window_number, 0, CMD_EXPAND_TOWN | CMD_MSG(STR_ERROR_CAN_T_EXPAND_TOWN));
478  break;
479  }
480 
481  case WID_TV_DELETE: // delete town - only available on Scenario editor
482  DoCommandP(0, this->window_number, 0, CMD_DELETE_TOWN | CMD_MSG(STR_ERROR_TOWN_CAN_T_DELETE));
483  break;
484  }
485  }
486 
487  void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
488  {
489  switch (widget) {
490  case WID_TV_INFO:
491  size->height = GetDesiredInfoHeight(size->width);
492  break;
493  }
494  }
495 
500  uint GetDesiredInfoHeight(int width) const
501  {
502  uint aimed_height = 3 * FONT_HEIGHT_NORMAL + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
503 
504  bool first = true;
505  for (int i = TE_BEGIN; i < TE_END; i++) {
506  if (this->town->goal[i] == 0) continue;
507  if (this->town->goal[i] == TOWN_GROWTH_WINTER && (TileHeight(this->town->xy) < LowestSnowLine() || this->town->cache.population <= 90)) continue;
508  if (this->town->goal[i] == TOWN_GROWTH_DESERT && (GetTropicZone(this->town->xy) != TROPICZONE_DESERT || this->town->cache.population <= 60)) continue;
509 
510  if (first) {
511  aimed_height += FONT_HEIGHT_NORMAL;
512  first = false;
513  }
514  aimed_height += FONT_HEIGHT_NORMAL;
515  }
516  aimed_height += FONT_HEIGHT_NORMAL;
517 
519 
520  if (!this->town->text.empty()) {
521  SetDParamStr(0, this->town->text);
522  aimed_height += GetStringHeight(STR_JUST_RAW_STRING, width - WD_FRAMERECT_LEFT - WD_FRAMERECT_RIGHT);
523  }
524 
525  return aimed_height;
526  }
527 
528  void ResizeWindowAsNeeded()
529  {
530  const NWidgetBase *nwid_info = this->GetWidget<NWidgetBase>(WID_TV_INFO);
531  uint aimed_height = GetDesiredInfoHeight(nwid_info->current_x);
532  if (aimed_height > nwid_info->current_y || (aimed_height < nwid_info->current_y && nwid_info->current_y > nwid_info->smallest_y)) {
533  this->ReInit();
534  }
535  }
536 
537  void OnResize() override
538  {
539  if (this->viewport != nullptr) {
540  NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(WID_TV_VIEWPORT);
541  nvp->UpdateViewportCoordinates(this);
542 
543  ScrollWindowToTile(this->town->xy, this, true); // Re-center viewport.
544  }
545  }
546 
552  void OnInvalidateData(int data = 0, bool gui_scope = true) override
553  {
554  if (!gui_scope) return;
555  /* Called when setting station noise or required cargoes have changed, in order to resize the window */
556  this->SetDirty(); // refresh display for current size. This will allow to avoid glitches when downgrading
557  this->ResizeWindowAsNeeded();
558  }
559 
560  void OnQueryTextFinished(char *str) override
561  {
562  if (str == nullptr) return;
563 
564  DoCommandP(0, this->window_number, 0, CMD_RENAME_TOWN | CMD_MSG(STR_ERROR_CAN_T_RENAME_TOWN), nullptr, str);
565  }
566 };
567 
568 static const NWidgetPart _nested_town_game_view_widgets[] = {
570  NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
571  NWidget(WWT_PUSHIMGBTN, COLOUR_BROWN, WID_TV_CHANGE_NAME), SetMinimalSize(12, 14), SetDataTip(SPR_RENAME, STR_TOWN_VIEW_RENAME_TOOLTIP),
572  NWidget(WWT_CAPTION, COLOUR_BROWN, WID_TV_CAPTION), SetDataTip(STR_TOWN_VIEW_TOWN_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
573  NWidget(WWT_PUSHIMGBTN, COLOUR_BROWN, WID_TV_CENTER_VIEW), SetMinimalSize(12, 14), SetDataTip(SPR_GOTO_LOCATION, STR_TOWN_VIEW_CENTER_TOOLTIP),
574  NWidget(WWT_SHADEBOX, COLOUR_BROWN),
575  NWidget(WWT_DEFSIZEBOX, COLOUR_BROWN),
576  NWidget(WWT_STICKYBOX, COLOUR_BROWN),
577  EndContainer(),
578  NWidget(WWT_PANEL, COLOUR_BROWN),
579  NWidget(WWT_INSET, COLOUR_BROWN), SetPadding(2, 2, 2, 2),
580  NWidget(NWID_VIEWPORT, INVALID_COLOUR, WID_TV_VIEWPORT), SetMinimalSize(254, 86), SetFill(1, 0), SetResize(1, 1),
581  EndContainer(),
582  EndContainer(),
583  NWidget(WWT_PANEL, COLOUR_BROWN, WID_TV_INFO), SetMinimalSize(260, 32), SetResize(1, 0), SetFill(1, 0), EndContainer(),
585  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),
586  NWidget(WWT_TEXTBTN, COLOUR_BROWN, WID_TV_CATCHMENT), SetMinimalSize(40, 12), SetFill(1, 1), SetResize(1, 0), SetDataTip(STR_BUTTON_CATCHMENT, STR_TOOLTIP_CATCHMENT),
587  NWidget(WWT_RESIZEBOX, COLOUR_BROWN),
588  EndContainer(),
589 };
590 
591 static WindowDesc _town_game_view_desc(
592  WDP_AUTO, "view_town", 260, TownViewWindow::WID_TV_HEIGHT_NORMAL,
594  0,
595  _nested_town_game_view_widgets, lengthof(_nested_town_game_view_widgets)
596 );
597 
598 static const NWidgetPart _nested_town_editor_view_widgets[] = {
600  NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
601  NWidget(WWT_PUSHIMGBTN, COLOUR_BROWN, WID_TV_CHANGE_NAME), SetMinimalSize(12, 14), SetDataTip(SPR_RENAME, STR_TOWN_VIEW_RENAME_TOOLTIP),
602  NWidget(WWT_CAPTION, COLOUR_BROWN, WID_TV_CAPTION), SetDataTip(STR_TOWN_VIEW_TOWN_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
603  NWidget(WWT_PUSHIMGBTN, COLOUR_BROWN, WID_TV_CENTER_VIEW), SetMinimalSize(12, 14), SetDataTip(SPR_GOTO_LOCATION, STR_TOWN_VIEW_CENTER_TOOLTIP),
604  NWidget(WWT_SHADEBOX, COLOUR_BROWN),
605  NWidget(WWT_DEFSIZEBOX, COLOUR_BROWN),
606  NWidget(WWT_STICKYBOX, COLOUR_BROWN),
607  EndContainer(),
608  NWidget(WWT_PANEL, COLOUR_BROWN),
609  NWidget(WWT_INSET, COLOUR_BROWN), SetPadding(2, 2, 2, 2),
610  NWidget(NWID_VIEWPORT, INVALID_COLOUR, WID_TV_VIEWPORT), SetMinimalSize(254, 86), SetFill(1, 1), SetResize(1, 1),
611  EndContainer(),
612  EndContainer(),
613  NWidget(WWT_PANEL, COLOUR_BROWN, WID_TV_INFO), SetMinimalSize(260, 32), SetResize(1, 0), SetFill(1, 0), EndContainer(),
615  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),
616  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),
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_editor_view_desc(
623  WDP_AUTO, "view_town_scen", 260, TownViewWindow::WID_TV_HEIGHT_NORMAL,
625  0,
626  _nested_town_editor_view_widgets, lengthof(_nested_town_editor_view_widgets)
627 );
628 
629 void ShowTownViewWindow(TownID town)
630 {
631  if (_game_mode == GM_EDITOR) {
632  AllocateWindowDescFront<TownViewWindow>(&_town_editor_view_desc, town);
633  } else {
634  AllocateWindowDescFront<TownViewWindow>(&_town_game_view_desc, town);
635  }
636 }
637 
638 static const NWidgetPart _nested_town_directory_widgets[] = {
640  NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
641  NWidget(WWT_CAPTION, COLOUR_BROWN), SetDataTip(STR_TOWN_DIRECTORY_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
642  NWidget(WWT_SHADEBOX, COLOUR_BROWN),
643  NWidget(WWT_DEFSIZEBOX, COLOUR_BROWN),
644  NWidget(WWT_STICKYBOX, COLOUR_BROWN),
645  EndContainer(),
649  NWidget(WWT_TEXTBTN, COLOUR_BROWN, WID_TD_SORT_ORDER), SetDataTip(STR_BUTTON_SORT_BY, STR_TOOLTIP_SORT_ORDER),
650  NWidget(WWT_DROPDOWN, COLOUR_BROWN, WID_TD_SORT_CRITERIA), SetDataTip(STR_JUST_STRING, STR_TOOLTIP_SORT_CRITERIA),
651  NWidget(WWT_EDITBOX, COLOUR_BROWN, WID_TD_FILTER), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP),
652  EndContainer(),
653  NWidget(WWT_PANEL, COLOUR_BROWN, WID_TD_LIST), SetDataTip(0x0, STR_TOWN_DIRECTORY_LIST_TOOLTIP),
655  NWidget(WWT_PANEL, COLOUR_BROWN),
656  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),
657  EndContainer(),
658  EndContainer(),
660  NWidget(NWID_VSCROLLBAR, COLOUR_BROWN, WID_TD_SCROLLBAR),
661  NWidget(WWT_RESIZEBOX, COLOUR_BROWN),
662  EndContainer(),
663  EndContainer(),
664 };
665 
667 struct TownDirectoryWindow : public Window {
668 private:
669  /* Runtime saved values */
670  static Listing last_sorting;
671 
672  /* Constants for sorting towns */
673  static const StringID sorter_names[];
675 
678 
679  GUITownList towns;
680 
681  Scrollbar *vscroll;
682 
683  void BuildSortTownList()
684  {
685  if (this->towns.NeedRebuild()) {
686  this->towns.clear();
687 
688  for (const Town *t : Town::Iterate()) {
689  if (this->string_filter.IsEmpty()) {
690  this->towns.push_back(t);
691  continue;
692  }
693  this->string_filter.ResetState();
694  this->string_filter.AddLine(t->GetCachedName());
695  if (this->string_filter.GetState()) this->towns.push_back(t);
696  }
697 
698  this->towns.shrink_to_fit();
699  this->towns.RebuildDone();
700  this->vscroll->SetCount((uint)this->towns.size()); // Update scrollbar as well.
701  }
702  /* Always sort the towns. */
703  this->towns.Sort();
704  this->SetWidgetDirty(WID_TD_LIST); // Force repaint of the displayed towns.
705  }
706 
708  static bool TownNameSorter(const Town * const &a, const Town * const &b)
709  {
710  return strnatcmp(a->GetCachedName(), b->GetCachedName()) < 0; // Sort by name (natural sorting).
711  }
712 
714  static bool TownPopulationSorter(const Town * const &a, const Town * const &b)
715  {
716  uint32 a_population = a->cache.population;
717  uint32 b_population = b->cache.population;
718  if (a_population == b_population) return TownDirectoryWindow::TownNameSorter(a, b);
719  return a_population < b_population;
720  }
721 
723  static bool TownRatingSorter(const Town * const &a, const Town * const &b)
724  {
725  bool before = !TownDirectoryWindow::last_sorting.order; // Value to get 'a' before 'b'.
726 
727  /* Towns without rating are always after towns with rating. */
730  int16 a_rating = a->ratings[_local_company];
731  int16 b_rating = b->ratings[_local_company];
732  if (a_rating == b_rating) return TownDirectoryWindow::TownNameSorter(a, b);
733  return a_rating < b_rating;
734  }
735  return before;
736  }
737  if (HasBit(b->have_ratings, _local_company)) return !before;
738 
739  /* Sort unrated towns always on ascending town name. */
740  if (before) return TownDirectoryWindow::TownNameSorter(a, b);
742  }
743 
744 public:
746  {
747  this->CreateNestedTree();
748 
749  this->vscroll = this->GetScrollbar(WID_TD_SCROLLBAR);
750 
751  this->towns.SetListing(this->last_sorting);
753  this->towns.ForceRebuild();
754  this->BuildSortTownList();
755 
756  this->FinishInitNested(0);
757 
759  this->townname_editbox.cancel_button = QueryString::ACTION_CLEAR;
760  }
761 
762  void SetStringParameters(int widget) const override
763  {
764  switch (widget) {
767  break;
768 
771  break;
772  }
773  }
774 
780  static StringID GetTownString(const Town *t)
781  {
782  return t->larger_town ? STR_TOWN_DIRECTORY_CITY : STR_TOWN_DIRECTORY_TOWN;
783  }
784 
785  void DrawWidget(const Rect &r, int widget) const override
786  {
787  switch (widget) {
788  case WID_TD_SORT_ORDER:
789  this->DrawSortButtonState(widget, this->towns.IsDescSortOrder() ? SBS_DOWN : SBS_UP);
790  break;
791 
792  case WID_TD_LIST: {
793  int n = 0;
794  int y = r.top + WD_FRAMERECT_TOP;
795  if (this->towns.size() == 0) { // No towns available.
796  DrawString(r.left + WD_FRAMERECT_LEFT, r.right, y, STR_TOWN_DIRECTORY_NONE);
797  break;
798  }
799 
800  /* At least one town available. */
801  bool rtl = _current_text_dir == TD_RTL;
802  Dimension icon_size = GetSpriteSize(SPR_TOWN_RATING_GOOD);
803  int text_left = r.left + WD_FRAMERECT_LEFT + (rtl ? 0 : icon_size.width + 2);
804  int text_right = r.right - WD_FRAMERECT_RIGHT - (rtl ? icon_size.width + 2 : 0);
805  int icon_x = rtl ? r.right - WD_FRAMERECT_RIGHT - icon_size.width : r.left + WD_FRAMERECT_LEFT;
806 
807  for (uint i = this->vscroll->GetPosition(); i < this->towns.size(); i++) {
808  const Town *t = this->towns[i];
809  assert(t->xy != INVALID_TILE);
810 
811  /* Draw rating icon. */
812  if (_game_mode == GM_EDITOR || !HasBit(t->have_ratings, _local_company)) {
813  DrawSprite(SPR_TOWN_RATING_NA, PAL_NONE, icon_x, y + (this->resize.step_height - icon_size.height) / 2);
814  } else {
815  SpriteID icon = SPR_TOWN_RATING_APALLING;
816  if (t->ratings[_local_company] > RATING_VERYPOOR) icon = SPR_TOWN_RATING_MEDIOCRE;
817  if (t->ratings[_local_company] > RATING_GOOD) icon = SPR_TOWN_RATING_GOOD;
818  DrawSprite(icon, PAL_NONE, icon_x, y + (this->resize.step_height - icon_size.height) / 2);
819  }
820 
821  SetDParam(0, t->index);
822  SetDParam(1, t->cache.population);
823  DrawString(text_left, text_right, y + (this->resize.step_height - FONT_HEIGHT_NORMAL) / 2, GetTownString(t));
824 
825  y += this->resize.step_height;
826  if (++n == this->vscroll->GetCapacity()) break; // max number of towns in 1 window
827  }
828  break;
829  }
830  }
831  }
832 
833  void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
834  {
835  switch (widget) {
836  case WID_TD_SORT_ORDER: {
837  Dimension d = GetStringBoundingBox(this->GetWidget<NWidgetCore>(widget)->widget_data);
838  d.width += padding.width + Window::SortButtonWidth() * 2; // Doubled since the string is centred and it also looks better.
839  d.height += padding.height;
840  *size = maxdim(*size, d);
841  break;
842  }
843  case WID_TD_SORT_CRITERIA: {
844  Dimension d = {0, 0};
845  for (uint i = 0; TownDirectoryWindow::sorter_names[i] != INVALID_STRING_ID; i++) {
847  }
848  d.width += padding.width;
849  d.height += padding.height;
850  *size = maxdim(*size, d);
851  break;
852  }
853  case WID_TD_LIST: {
854  Dimension d = GetStringBoundingBox(STR_TOWN_DIRECTORY_NONE);
855  for (uint i = 0; i < this->towns.size(); i++) {
856  const Town *t = this->towns[i];
857 
858  assert(t != nullptr);
859 
860  SetDParam(0, t->index);
861  SetDParamMaxDigits(1, 8);
863  }
864  Dimension icon_size = GetSpriteSize(SPR_TOWN_RATING_GOOD);
865  d.width += icon_size.width + 2;
866  d.height = std::max(d.height, icon_size.height);
867  resize->height = d.height;
868  d.height *= 5;
869  d.width += padding.width + WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT;
870  d.height += padding.height + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
871  *size = maxdim(*size, d);
872  break;
873  }
875  SetDParamMaxDigits(0, 10);
876  Dimension d = GetStringBoundingBox(STR_TOWN_POPULATION);
877  d.width += padding.width;
878  d.height += padding.height;
879  *size = maxdim(*size, d);
880  break;
881  }
882  }
883  }
884 
885  void OnClick(Point pt, int widget, int click_count) override
886  {
887  switch (widget) {
888  case WID_TD_SORT_ORDER: // Click on sort order button
889  if (this->towns.SortType() != 2) { // A different sort than by rating.
890  this->towns.ToggleSortOrder();
891  this->last_sorting = this->towns.GetListing(); // Store new sorting order.
892  } else {
893  /* Some parts are always sorted ascending on name. */
894  this->last_sorting.order = !this->last_sorting.order;
895  this->towns.SetListing(this->last_sorting);
896  this->towns.ForceResort();
897  this->towns.Sort();
898  }
899  this->SetDirty();
900  break;
901 
902  case WID_TD_SORT_CRITERIA: // Click on sort criteria dropdown
904  break;
905 
906  case WID_TD_LIST: { // Click on Town Matrix
907  uint id_v = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_TD_LIST, WD_FRAMERECT_TOP);
908  if (id_v >= this->towns.size()) return; // click out of town bounds
909 
910  const Town *t = this->towns[id_v];
911  assert(t != nullptr);
912  if (_ctrl_pressed) {
914  } else {
916  }
917  break;
918  }
919  }
920  }
921 
922  void OnDropdownSelect(int widget, int index) override
923  {
924  if (widget != WID_TD_SORT_CRITERIA) return;
925 
926  if (this->towns.SortType() != index) {
927  this->towns.SetSortType(index);
928  this->last_sorting = this->towns.GetListing(); // Store new sorting order.
929  this->BuildSortTownList();
930  }
931  }
932 
933  void OnPaint() override
934  {
935  if (this->towns.NeedRebuild()) this->BuildSortTownList();
936  this->DrawWidgets();
937  }
938 
939  void OnHundredthTick() override
940  {
941  this->BuildSortTownList();
942  this->SetDirty();
943  }
944 
945  void OnResize() override
946  {
947  this->vscroll->SetCapacityFromWidget(this, WID_TD_LIST);
948  }
949 
950  void OnEditboxChanged(int wid) override
951  {
952  if (wid == WID_TD_FILTER) {
953  this->string_filter.SetFilterTerm(this->townname_editbox.text.buf);
954  this->InvalidateData(TDIWD_FORCE_REBUILD);
955  }
956  }
957 
963  void OnInvalidateData(int data = 0, bool gui_scope = true) override
964  {
965  switch (data) {
966  case TDIWD_FORCE_REBUILD:
967  /* This needs to be done in command-scope to enforce rebuilding before resorting invalid data */
968  this->towns.ForceRebuild();
969  break;
970 
971  case TDIWD_POPULATION_CHANGE:
972  if (this->towns.SortType() == 1) this->towns.ForceResort();
973  break;
974 
975  default:
976  this->towns.ForceResort();
977  }
978  }
979 };
980 
981 Listing TownDirectoryWindow::last_sorting = {false, 0};
982 
985  STR_SORT_BY_NAME,
986  STR_SORT_BY_POPULATION,
987  STR_SORT_BY_RATING,
989 };
990 
993  &TownNameSorter,
994  &TownPopulationSorter,
995  &TownRatingSorter,
996 };
997 
998 static WindowDesc _town_directory_desc(
999  WDP_AUTO, "list_towns", 208, 202,
1001  0,
1002  _nested_town_directory_widgets, lengthof(_nested_town_directory_widgets)
1003 );
1004 
1005 void ShowTownDirectory()
1006 {
1007  if (BringWindowToFrontById(WC_TOWN_DIRECTORY, 0)) return;
1008  new TownDirectoryWindow(&_town_directory_desc);
1009 }
1010 
1011 void CcFoundTown(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
1012 {
1013  if (result.Failed()) return;
1014 
1015  if (_settings_client.sound.confirm) SndPlayTileFx(SND_1F_CONSTRUCTION_OTHER, tile);
1017 }
1018 
1019 void CcFoundRandomTown(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
1020 {
1021  if (result.Succeeded()) ScrollMainWindowToTile(Town::Get(_new_town_id)->xy);
1022 }
1023 
1024 static const NWidgetPart _nested_found_town_widgets[] = {
1026  NWidget(WWT_CLOSEBOX, COLOUR_DARK_GREEN),
1027  NWidget(WWT_CAPTION, COLOUR_DARK_GREEN), SetDataTip(STR_FOUND_TOWN_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1028  NWidget(WWT_SHADEBOX, COLOUR_DARK_GREEN),
1029  NWidget(WWT_STICKYBOX, COLOUR_DARK_GREEN),
1030  EndContainer(),
1031  /* Construct new town(s) buttons. */
1032  NWidget(WWT_PANEL, COLOUR_DARK_GREEN),
1034  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_TF_NEW_TOWN), SetMinimalSize(156, 12), SetFill(1, 0),
1035  SetDataTip(STR_FOUND_TOWN_NEW_TOWN_BUTTON, STR_FOUND_TOWN_NEW_TOWN_TOOLTIP), SetPadding(0, 2, 1, 2),
1036  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_TF_RANDOM_TOWN), SetMinimalSize(156, 12), SetFill(1, 0),
1037  SetDataTip(STR_FOUND_TOWN_RANDOM_TOWN_BUTTON, STR_FOUND_TOWN_RANDOM_TOWN_TOOLTIP), SetPadding(0, 2, 1, 2),
1038  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_TF_MANY_RANDOM_TOWNS), SetMinimalSize(156, 12), SetFill(1, 0),
1039  SetDataTip(STR_FOUND_TOWN_MANY_RANDOM_TOWNS, STR_FOUND_TOWN_RANDOM_TOWNS_TOOLTIP), SetPadding(0, 2, 0, 2),
1040  /* Town name selection. */
1041  NWidget(WWT_LABEL, COLOUR_DARK_GREEN), SetMinimalSize(156, 14), SetPadding(0, 2, 0, 2), SetDataTip(STR_FOUND_TOWN_NAME_TITLE, STR_NULL),
1042  NWidget(WWT_EDITBOX, COLOUR_GREY, WID_TF_TOWN_NAME_EDITBOX), SetMinimalSize(156, 12), SetPadding(0, 2, 3, 2),
1043  SetDataTip(STR_FOUND_TOWN_NAME_EDITOR_TITLE, STR_FOUND_TOWN_NAME_EDITOR_HELP),
1044  NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_TF_TOWN_NAME_RANDOM), SetMinimalSize(78, 12), SetPadding(0, 2, 0, 2), SetFill(1, 0),
1045  SetDataTip(STR_FOUND_TOWN_NAME_RANDOM_BUTTON, STR_FOUND_TOWN_NAME_RANDOM_TOOLTIP),
1046  /* Town size selection. */
1047  NWidget(NWID_HORIZONTAL), SetPIP(2, 0, 2),
1048  NWidget(NWID_SPACER), SetFill(1, 0),
1049  NWidget(WWT_LABEL, COLOUR_DARK_GREEN), SetMinimalSize(148, 14), SetDataTip(STR_FOUND_TOWN_INITIAL_SIZE_TITLE, STR_NULL),
1050  NWidget(NWID_SPACER), SetFill(1, 0),
1051  EndContainer(),
1053  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_TF_SIZE_SMALL), SetMinimalSize(78, 12), SetFill(1, 0),
1054  SetDataTip(STR_FOUND_TOWN_INITIAL_SIZE_SMALL_BUTTON, STR_FOUND_TOWN_INITIAL_SIZE_TOOLTIP),
1055  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_TF_SIZE_MEDIUM), SetMinimalSize(78, 12), SetFill(1, 0),
1056  SetDataTip(STR_FOUND_TOWN_INITIAL_SIZE_MEDIUM_BUTTON, STR_FOUND_TOWN_INITIAL_SIZE_TOOLTIP),
1057  EndContainer(),
1060  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_TF_SIZE_LARGE), SetMinimalSize(78, 12), SetFill(1, 0),
1061  SetDataTip(STR_FOUND_TOWN_INITIAL_SIZE_LARGE_BUTTON, STR_FOUND_TOWN_INITIAL_SIZE_TOOLTIP),
1062  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_TF_SIZE_RANDOM), SetMinimalSize(78, 12), SetFill(1, 0),
1063  SetDataTip(STR_FOUND_TOWN_SIZE_RANDOM, STR_FOUND_TOWN_INITIAL_SIZE_TOOLTIP),
1064  EndContainer(),
1066  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_TF_CITY), SetPadding(0, 2, 0, 2), SetMinimalSize(156, 12), SetFill(1, 0),
1067  SetDataTip(STR_FOUND_TOWN_CITY, STR_FOUND_TOWN_CITY_TOOLTIP), SetFill(1, 0),
1068  /* Town roads selection. */
1069  NWidget(NWID_HORIZONTAL), SetPIP(2, 0, 2),
1070  NWidget(NWID_SPACER), SetFill(1, 0),
1071  NWidget(WWT_LABEL, COLOUR_DARK_GREEN), SetMinimalSize(148, 14), SetDataTip(STR_FOUND_TOWN_ROAD_LAYOUT, STR_NULL),
1072  NWidget(NWID_SPACER), SetFill(1, 0),
1073  EndContainer(),
1075  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),
1076  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),
1077  EndContainer(),
1080  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),
1081  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),
1082  EndContainer(),
1084  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_TF_LAYOUT_RANDOM), SetPadding(0, 2, 0, 2), SetMinimalSize(0, 12), SetFill(1, 0),
1085  SetDataTip(STR_FOUND_TOWN_SELECT_LAYOUT_RANDOM, STR_FOUND_TOWN_SELECT_TOWN_ROAD_LAYOUT), SetFill(1, 0),
1087  EndContainer(),
1088 };
1089 
1092 private:
1095  bool city;
1098  uint32 townnameparts;
1100 
1101 public:
1103  Window(desc),
1107  params(_settings_game.game_creation.town_name)
1108  {
1109  this->InitNested(window_number);
1111  this->RandomTownName();
1112  this->UpdateButtons(true);
1113  }
1114 
1115  void RandomTownName()
1116  {
1117  this->townnamevalid = GenerateTownName(&this->townnameparts);
1118 
1119  if (!this->townnamevalid) {
1120  this->townname_editbox.text.DeleteAll();
1121  } else {
1122  GetTownName(this->townname_editbox.text.buf, &this->params, this->townnameparts, &this->townname_editbox.text.buf[this->townname_editbox.text.max_bytes - 1]);
1123  this->townname_editbox.text.UpdateSize();
1124  }
1126 
1128  }
1129 
1130  void UpdateButtons(bool check_availability)
1131  {
1132  if (check_availability && _game_mode != GM_EDITOR) {
1137  }
1138 
1139  for (int i = WID_TF_SIZE_SMALL; i <= WID_TF_SIZE_RANDOM; i++) {
1140  this->SetWidgetLoweredState(i, i == WID_TF_SIZE_SMALL + this->town_size);
1141  }
1142 
1143  this->SetWidgetLoweredState(WID_TF_CITY, this->city);
1144 
1145  for (int i = WID_TF_LAYOUT_ORIGINAL; i <= WID_TF_LAYOUT_RANDOM; i++) {
1146  this->SetWidgetLoweredState(i, i == WID_TF_LAYOUT_ORIGINAL + this->town_layout);
1147  }
1148 
1149  this->SetDirty();
1150  }
1151 
1152  void ExecuteFoundTownCommand(TileIndex tile, bool random, StringID errstr, CommandCallback cc)
1153  {
1154  std::string name;
1155 
1156  if (!this->townnamevalid) {
1157  name = this->townname_editbox.text.buf;
1158  } else {
1159  /* If user changed the name, send it */
1161  GetTownName(buf, &this->params, this->townnameparts, lastof(buf));
1162  if (strcmp(buf, this->townname_editbox.text.buf) != 0) name = this->townname_editbox.text.buf;
1163  }
1164 
1165  bool success = DoCommandP(tile, this->town_size | this->city << 2 | this->town_layout << 3 | random << 6,
1166  townnameparts, CMD_FOUND_TOWN | CMD_MSG(errstr), cc, name);
1167 
1168  /* Rerandomise name, if success and no cost-estimation. */
1169  if (success && !_shift_pressed) this->RandomTownName();
1170  }
1171 
1172  void OnClick(Point pt, int widget, int click_count) override
1173  {
1174  switch (widget) {
1175  case WID_TF_NEW_TOWN:
1176  HandlePlacePushButton(this, WID_TF_NEW_TOWN, SPR_CURSOR_TOWN, HT_RECT);
1177  break;
1178 
1179  case WID_TF_RANDOM_TOWN:
1180  this->ExecuteFoundTownCommand(0, true, STR_ERROR_CAN_T_GENERATE_TOWN, CcFoundRandomTown);
1181  break;
1182 
1184  this->RandomTownName();
1186  break;
1187 
1188  case WID_TF_MANY_RANDOM_TOWNS: {
1189  Backup<bool> old_generating_world(_generating_world, true, FILE_LINE);
1191  if (!GenerateTowns(this->town_layout)) {
1192  ShowErrorMessage(STR_ERROR_CAN_T_GENERATE_TOWN, STR_ERROR_NO_SPACE_FOR_TOWN, WL_INFO);
1193  }
1195  old_generating_world.Restore();
1196  break;
1197  }
1198 
1200  this->town_size = (TownSize)(widget - WID_TF_SIZE_SMALL);
1201  this->UpdateButtons(false);
1202  break;
1203 
1204  case WID_TF_CITY:
1205  this->city ^= true;
1206  this->SetWidgetLoweredState(WID_TF_CITY, this->city);
1207  this->SetDirty();
1208  break;
1209 
1212  this->town_layout = (TownLayout)(widget - WID_TF_LAYOUT_ORIGINAL);
1213  this->UpdateButtons(false);
1214  break;
1215  }
1216  }
1217 
1218  void OnPlaceObject(Point pt, TileIndex tile) override
1219  {
1220  this->ExecuteFoundTownCommand(tile, false, STR_ERROR_CAN_T_FOUND_TOWN_HERE, CcFoundTown);
1221  }
1222 
1223  void OnPlaceObjectAbort() override
1224  {
1225  this->RaiseButtons();
1226  this->UpdateButtons(false);
1227  }
1228 
1234  void OnInvalidateData(int data = 0, bool gui_scope = true) override
1235  {
1236  if (!gui_scope) return;
1237  this->UpdateButtons(true);
1238  }
1239 };
1240 
1241 static WindowDesc _found_town_desc(
1242  WDP_AUTO, "build_town", 160, 162,
1245  _nested_found_town_widgets, lengthof(_nested_found_town_widgets)
1246 );
1247 
1248 void ShowFoundTownWindow()
1249 {
1250  if (_game_mode != GM_EDITOR && !Company::IsValidID(_local_company)) return;
1251  AllocateWindowDescFront<FoundTownWindow>(&_found_town_desc, 0);
1252 }
1253 
1254 void InitializeTownGui()
1255 {
1256  _town_local_authority_kdtree.Clear();
1257 }
WID_TF_TOWN_NAME_EDITBOX
@ WID_TF_TOWN_NAME_EDITBOX
Editor for the town name.
Definition: town_widget.h:52
TownAuthorityWindow::DrawWidget
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: town_gui.cpp:191
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:260
Town::have_ratings
CompanyMask have_ratings
which companies have a rating
Definition: town.h:69
WD_FRAMERECT_TOP
@ WD_FRAMERECT_TOP
Offset at top to draw the frame rectangular area.
Definition: window_gui.h:64
CMD_MSG
#define CMD_MSG(x)
Used to combine a StringID with the command.
Definition: command_type.h:372
TileIndex
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:83
TROPICZONE_DESERT
@ TROPICZONE_DESERT
Tile is desert.
Definition: tile_type.h:76
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:933
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:226
TownViewWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition: town_gui.cpp:350
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:2445
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:552
querystring_gui.h
SetScrollbar
static NWidgetPart SetScrollbar(int index)
Attach a scrollbar to a widget.
Definition: widget_type.h:1188
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
CMD_DO_TOWN_ACTION
@ CMD_DO_TOWN_ACTION
do a action from the town detail window (like advertises or bribe)
Definition: command_type.h:264
Scrollbar::GetCapacity
uint16 GetCapacity() const
Gets the number of visible elements of the scrollbar.
Definition: widget_type.h:662
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:670
EconomySettings::town_layout
TownLayout town_layout
select town layout,
Definition: settings_type.h:515
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:1139
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:320
WDF_CONSTRUCTION
@ WDF_CONSTRUCTION
This window is used for construction; close it whenever changing company.
Definition: window_gui.h:210
dropdown_func.h
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:1004
company_base.h
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:53
NWidgetViewport
Nested widget to display a viewport in a window.
Definition: widget_type.h:615
WC_FOUND_TOWN
@ WC_FOUND_TOWN
Found a town; Window numbers:
Definition: window_type.h:421
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:1218
WF_DISABLE_VP_SCROLL
@ WF_DISABLE_VP_SCROLL
Window does not do autoscroll,.
Definition: window_gui.h:241
GUIList< const Town * >
Window::viewport
ViewportData * viewport
Pointer to viewport data, if present.
Definition: window_gui.h:321
_network_server
bool _network_server
network-server is active
Definition: network.cpp:57
FoundTownWindow::townname_editbox
QueryString townname_editbox
Townname editbox.
Definition: town_gui.cpp:1096
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:950
TownDirectoryWindow::OnDropdownSelect
void OnDropdownSelect(int widget, int index) override
A dropdown option associated to this window has been selected.
Definition: town_gui.cpp:922
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:1760
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:939
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:444
maxdim
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
Definition: geometry_func.cpp:22
TownAuthorityWindow::GetNthSetBit
static int GetNthSetBit(uint32 bits, int n)
Get the position of the Nth set bit.
Definition: town_gui.cpp:85
TownSize
TownSize
Supported initial town sizes.
Definition: town_type.h:19
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
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:677
WID_TF_CITY
@ WID_TF_CITY
Selection for the town's city state.
Definition: town_widget.h:58
Scrollbar::SetCount
void SetCount(int num)
Sets the number of elements in the list.
Definition: widget_type.h:710
_ctrl_pressed
bool _ctrl_pressed
Is Ctrl pressed?
Definition: gfx.cpp:35
WID_TV_CHANGE_NAME
@ WID_TV_CHANGE_NAME
Change the name of this town.
Definition: town_widget.h:41
CommandCallback
void CommandCallback(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
Define a callback function for the client, after the command is finished.
Definition: command_type.h:474
SetResize
static NWidgetPart SetResize(int16 dx, int16 dy)
Widget part function for setting the resize step.
Definition: widget_type.h:993
Window::RaiseButtons
void RaiseButtons(bool autoraise=false)
Raise the buttons of the window.
Definition: window.cpp:584
CMD_RENAME_TOWN
@ CMD_RENAME_TOWN
rename a town
Definition: command_type.h:263
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:52
TownViewWindow::GetDesiredInfoHeight
uint GetDesiredInfoHeight(int width) const
Gets the desired height for the information panel.
Definition: town_gui.cpp:500
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:642
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:673
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:78
WindowNumber
int32 WindowNumber
Number to differentiate different windows of the same class.
Definition: window_type.h:711
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:2780
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:2098
NWidgetBase::smallest_y
uint smallest_y
Smallest vertical size of the widget in a filled window.
Definition: widget_type.h:184
TownViewWindow::SetStringParameters
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
Definition: town_gui.cpp:345
Scrollbar
Scrollbar data structure.
Definition: widget_type.h:629
WID_TF_SIZE_RANDOM
@ WID_TF_SIZE_RANDOM
Selection for a randomly sized town.
Definition: town_widget.h:57
TownAuthorityWindow::OnHundredthTick
void OnHundredthTick() override
Called once every 100 (game) ticks, or once every 3s, whichever comes last.
Definition: town_gui.cpp:295
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:971
genworld.h
SetDataTip
static NWidgetPart SetDataTip(uint32 data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1107
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:74
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:150
GetStringBoundingBox
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:888
Textbuf::buf
char *const buf
buffer in which text is saved
Definition: textbuf_type.h:32
Window::querystrings
SmallMap< int, QueryString * > querystrings
QueryString associated to WWT_EDITBOX widgets.
Definition: window_gui.h:323
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:383
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:787
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:1093
IsInsideMM
static bool IsInsideMM(const T x, const size_t min, const size_t max)
Checks if a value is in an interval.
Definition: math_func.hpp:204
TF_CUSTOM_LAYOUT
@ TF_CUSTOM_LAYOUT
Allowed, with custom town layout.
Definition: town_type.h:96
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:168
TSZ_MEDIUM
@ TSZ_MEDIUM
Medium town.
Definition: town_type.h:21
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:885
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:463
WID_TF_SIZE_SMALL
@ WID_TF_SIZE_SMALL
Selection for a small town.
Definition: town_widget.h:54
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:714
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:519
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:156
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:317
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:645
TownAuthorityWindow::town
Town * town
Town being displayed.
Definition: town_gui.cpp:71
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:2076
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:596
DoCommandP
bool DoCommandP(const CommandContainer *container, bool my_cmd)
Shortcut for the long DoCommandP when having a container with the data.
Definition: command.cpp:541
WC_TOWN_AUTHORITY
@ WC_TOWN_AUTHORITY
Town authority; Window numbers:
Definition: window_type.h:186
Window::InitNested
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
Definition: window.cpp:1789
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:55
TownViewWindow
Definition: town_gui.cpp:315
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:993
GUIList::SetListing
void SetListing(Listing l)
Import sort conditions.
Definition: sortlist_type.h:130
WD_FRAMERECT_LEFT
@ WD_FRAMERECT_LEFT
Offset at left to draw the frame rectangular area.
Definition: window_gui.h:62
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:2434
TE_END
@ TE_END
End of town effects.
Definition: cargotype.h:34
TownAuthorityWindow::sel_index
int sel_index
Currently selected town action, 0 to TACT_COUNT-1, -1 means no action selected.
Definition: town_gui.cpp:72
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:780
WD_FRAMERECT_RIGHT
@ WD_FRAMERECT_RIGHT
Offset at right to draw the frame rectangular area.
Definition: window_gui.h:63
WD_FRAMERECT_BOTTOM
@ WD_FRAMERECT_BOTTOM
Offset at bottom to draw the frame rectangular area.
Definition: window_gui.h:65
CommandCost::Failed
bool Failed() const
Did this command fail?
Definition: command_type.h:159
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:186
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:723
GetMaskOfTownActions
uint GetMaskOfTownActions(int *nump, CompanyID cid, const Town *t)
Get a list of available actions to do at a town.
Definition: town_cmd.cpp:3298
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:53
TownDirectoryWindow::string_filter
StringFilter string_filter
Filter for towns.
Definition: town_gui.cpp:676
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:60
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:585
Window::SetWidgetDisabledState
void SetWidgetDisabledState(byte widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition: window_gui.h:386
WL_INFO
@ WL_INFO
Used for DoCommand-like (and some non-fatal AI GUI) errors/information.
Definition: error.h:22
_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:1118
TownViewWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition: town_gui.cpp:537
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:61
Window::left
int left
x position of left edge of the window
Definition: window_gui.h:312
Window::flags
WindowFlags flags
Window flags.
Definition: window_gui.h:305
TownAuthorityWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition: town_gui.cpp:105
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
LowestSnowLine
byte LowestSnowLine()
Get the lowest possible snow line height, either variable or static.
Definition: landscape.cpp:669
_networking
bool _networking
are we in networking mode?
Definition: network.cpp:56
_shift_pressed
bool _shift_pressed
Is Shift pressed?
Definition: gfx.cpp:36
GetWorldPopulation
uint32 GetWorldPopulation()
Determines the world population Basically, count population of all towns, one by one.
Definition: town_cmd.cpp:450
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:1041
GetStringMultiLineBoundingBox
Dimension GetStringMultiLineBoundingBox(StringID str, const Dimension &suggestion)
Calculate string bounding box for multi-line strings.
Definition: gfx.cpp:753
FoundTownWindow::townnamevalid
bool townnamevalid
Is generated town name valid?
Definition: town_gui.cpp:1097
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:518
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:480
_town_action_costs
const byte _town_action_costs[TACT_COUNT]
Factor in the cost of each town action.
Definition: town_cmd.cpp:3055
_viewport_highlight_town
const Town * _viewport_highlight_town
Currently selected town for coverage area highlight.
Definition: viewport.cpp:991
Window::SetFocusedWidget
bool SetFocusedWidget(int widget_index)
Set focus within this window to the given widget.
Definition: window.cpp:506
FoundTownWindow::city
bool city
Are we building a city?
Definition: town_gui.cpp:1095
stdafx.h
Window::window_number
WindowNumber window_number
Window number within the window class.
Definition: window_gui.h:307
RoundDivSU
static int RoundDivSU(int a, uint b)
Computes round(a / b) for signed a and unsigned b.
Definition: math_func.hpp:276
FoundTownWindow::params
TownNameParams params
Town name parameters.
Definition: town_gui.cpp:1099
landscape.h
ResizeInfo::step_height
uint step_height
Step-size of height resize changes.
Definition: window_gui.h:220
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:1223
UpdateNearestTownForRoadTiles
void UpdateNearestTownForRoadTiles(bool invalidate)
Updates cached nearest town for all road tiles.
Definition: road_cmd.cpp:1843
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:3158
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:187
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:37
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:762
WID_TV_SHOW_AUTHORITY
@ WID_TV_SHOW_AUTHORITY
Show the town authority window.
Definition: town_widget.h:40
TownEffect
TownEffect
Town growth effect when delivering cargo.
Definition: cargotype.h:26
WC_TOWN_DIRECTORY
@ WC_TOWN_DIRECTORY
Town directory; Window numbers:
Definition: window_type.h:246
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:143
GetStringHeight
int GetStringHeight(const char *str, int maxw, FontSize fontsize)
Calculates height of string (in pixels).
Definition: gfx.cpp:713
TownAuthorityWindow
Town authority window.
Definition: town_gui.cpp:69
GetSpriteSize
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition: gfx.cpp:976
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:113
WID_TF_LAYOUT_ORIGINAL
@ WID_TF_LAYOUT_ORIGINAL
Selection for the original town layout.
Definition: town_widget.h:59
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
Scrollbar::SetCapacity
void SetCapacity(int capacity)
Set the capacity of visible elements.
Definition: widget_type.h:726
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:358
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:226
SoundSettings::confirm
bool confirm
Play sound effect on successful constructions or other actions.
Definition: settings_type.h:208
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:1092
TownViewWindow::Close
void Close() override
Hide the window and all its child windows, and mark them for a later deletion.
Definition: town_gui.cpp:339
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:2205
Window::IsShaded
bool IsShaded() const
Is window shaded currently?
Definition: window_gui.h:520
WID_TF_LAYOUT_GRID3
@ WID_TF_LAYOUT_GRID3
Selection for the 3x3 grid town layout.
Definition: town_widget.h:62
TACT_COUNT
@ TACT_COUNT
Number of available town actions.
Definition: town.h:221
NWidgetBase::pos_x
int pos_x
Horizontal position of top-left corner of the widget in the window.
Definition: widget_type.h:189
CMD_EXPAND_TOWN
@ CMD_EXPAND_TOWN
expand a town
Definition: command_type.h:269
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
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:165
NWidget
static NWidgetPart NWidget(WidgetType tp, Colours col, int16 idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1207
FoundTownWindow
Found a town window class.
Definition: town_gui.cpp:1091
geometry_func.hpp
SetMinimalSize
static NWidgetPart SetMinimalSize(int16 x, int16 y)
Widget part function for setting the minimal size.
Definition: widget_type.h:1010
NWidgetViewport::InitializeViewport
void InitializeViewport(Window *w, uint32 follow_flags, ZoomLevel zoom)
Initialize the viewport of the window.
Definition: widget.cpp:2067
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:674
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:547
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:1172
Window::IsWidgetLowered
bool IsWidgetLowered(byte widget_index) const
Gets the lowered state of a widget.
Definition: window_gui.h:487
TransportedCargoStat::old_act
Tstorage old_act
Actually transported last month.
Definition: town_type.h:115
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:63
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:671
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:181
WID_TD_SCROLLBAR
@ WID_TD_SCROLLBAR
Scrollbar for the town list.
Definition: town_widget.h:19
Window::FinishInitNested
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition: window.cpp:1776
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
TownDirectoryWindow::TownNameSorter
static bool TownNameSorter(const Town *const &a, const Town *const &b)
Sort by town name.
Definition: town_gui.cpp:708
GUIList::ForceResort
void ForceResort()
Force a resort next Sort call Reset the resort timer if used too.
Definition: sortlist_type.h:213
Kdtree::Clear
void Clear()
Clear the tree.
Definition: kdtree.hpp:379
network.h
FoundTownWindow::townnameparts
uint32 townnameparts
Generated town name.
Definition: town_gui.cpp:1098
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:785
TownAuthorityWindow::DrawRatings
void DrawRatings()
Draw the contents of the ratings panel.
Definition: town_gui.cpp:126
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:378
Town
Town data structure.
Definition: town.h:50
CMD_FOUND_TOWN
@ CMD_FOUND_TOWN
found a town
Definition: command_type.h:262
Window::width
int width
width of the window (number of pixels to the right in x direction)
Definition: window_gui.h:314
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:2172
MarkWholeScreenDirty
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
Definition: gfx.cpp:1689
TownDirectoryWindow
Town directory window class.
Definition: town_gui.cpp:667
Window::SortButtonWidth
static int SortButtonWidth()
Get width of up/down arrow of sort button state.
Definition: widget.cpp:690
SetPIP
static NWidgetPart SetPIP(uint8 pre, uint8 inter, uint8 post)
Widget part function for setting a pre/inter/post spaces.
Definition: widget_type.h:1169
SND_1F_CONSTRUCTION_OTHER
@ SND_1F_CONSTRUCTION_OTHER
29 == 0x1D Construction: other (non-water, non-rail, non-bridge)
Definition: sound_type.h:68
ZOOM_LVL_NEWS
@ ZOOM_LVL_NEWS
Default zoom level for the news messages.
Definition: zoom_type.h:36
NWidgetBase::pos_y
int pos_y
Vertical position of top-left corner of the widget in the window.
Definition: widget_type.h:190
TownCache::num_houses
uint32 num_houses
Amount of houses.
Definition: town.h:41
INVALID_TILE
static const TileIndex INVALID_TILE
The very nice invalid tile marker.
Definition: tile_type.h:88
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:718
WID_TF_LAYOUT_GRID2
@ WID_TF_LAYOUT_GRID2
Selection for the 2x2 grid town layout.
Definition: town_widget.h:61
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:1076
WC_TOWN_VIEW
@ WC_TOWN_VIEW
Town view; Window numbers:
Definition: window_type.h:325
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:487
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:279
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:963
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:636
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:108
FoundTownWindow::town_layout
TownLayout town_layout
Selected town layout.
Definition: town_gui.cpp:1094
SBS_UP
@ SBS_UP
Sort descending.
Definition: window_gui.h:227
WID_TA_SCROLLBAR
@ WID_TA_SCROLLBAR
Scrollbar of the list of commands.
Definition: town_widget.h:29
CMD_DELETE_TOWN
@ CMD_DELETE_TOWN
delete a town
Definition: command_type.h:270
Window::SetWidgetDirty
void SetWidgetDirty(byte widget_index) const
Invalidate a widget, i.e.
Definition: window.cpp:608
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:47
Company
Definition: company_base.h:115
BringWindowToFrontById
Window * BringWindowToFrontById(WindowClass cls, WindowNumber number)
Find a window and make it the relative top-window on the screen.
Definition: window.cpp:1259
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:212
QSF_ENABLE_DEFAULT
@ QSF_ENABLE_DEFAULT
enable the 'Default' button ("\0" is returned)
Definition: textbuf_gui.h:21
NWidgetBase::current_x
uint current_x
Current horizontal size (after resizing).
Definition: widget_type.h:186
lastof
#define lastof(x)
Get the last element of an fixed size array.
Definition: stdafx.h:394
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:517
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:110
ResetObjectToPlace
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows).
Definition: viewport.cpp:3423
Window::SetWidgetLoweredState
void SetWidgetLoweredState(byte widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
Definition: window_gui.h:447
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:48
TownViewWindow::OnQueryTextFinished
void OnQueryTextFinished(char *str) override
The query window opened from this window has closed.
Definition: town_gui.cpp:560
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:833
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:296
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:1234
ClientSettings::gui
GUISettings gui
settings related to the GUI
Definition: settings_type.h:593
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:1028
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:3546
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:162
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:945
ResizeWindow
void ResizeWindow(Window *w, int delta_x, int delta_y, bool clamp_to_screen)
Resize the window.
Definition: window.cpp:2069
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:1092
TownViewWindow::town
Town * town
Town displayed by the window.
Definition: town_gui.cpp:317
backup_type.hpp
WID_TF_SIZE_LARGE
@ WID_TF_SIZE_LARGE
Selection for a large town.
Definition: town_widget.h:56