OpenTTD
misc_gui.cpp
Go to the documentation of this file.
1 /* $Id: misc_gui.cpp 27194 2015-03-17 22:08:48Z frosch $ */
2 
3 /*
4  * This file is part of OpenTTD.
5  * 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.
6  * 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.
7  * 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/>.
8  */
9 
12 #include "stdafx.h"
13 #include "debug.h"
14 #include "landscape.h"
15 #include "error.h"
16 #include "gui.h"
17 #include "command_func.h"
18 #include "company_func.h"
19 #include "town.h"
20 #include "string_func.h"
21 #include "company_base.h"
22 #include "texteff.hpp"
23 #include "strings_func.h"
24 #include "window_func.h"
25 #include "querystring_gui.h"
26 #include "core/geometry_func.hpp"
27 #include "newgrf_debug.h"
28 #include "zoom_func.h"
29 
30 #include "widgets/misc_widget.h"
31 
32 #include "table/strings.h"
33 
34 #include "safeguards.h"
35 
42 };
43 
44 
45 static const NWidgetPart _nested_land_info_widgets[] = {
47  NWidget(WWT_CLOSEBOX, COLOUR_GREY),
48  NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_LAND_AREA_INFORMATION_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
49  NWidget(WWT_DEBUGBOX, COLOUR_GREY),
50  EndContainer(),
52 };
53 
54 static WindowDesc _land_info_desc(
55  WDP_AUTO, "land_info", 0, 0,
57  0,
58  _nested_land_info_widgets, lengthof(_nested_land_info_widgets)
59 );
60 
61 class LandInfoWindow : public Window {
65  LAND_INFO_LINE_END,
66  };
67 
68  static const uint LAND_INFO_LINE_BUFF_SIZE = 512;
69 
70 public:
71  char landinfo_data[LAND_INFO_LINE_END][LAND_INFO_LINE_BUFF_SIZE];
72  TileIndex tile;
73 
74  virtual void DrawWidget(const Rect &r, int widget) const
75  {
76  if (widget != WID_LI_BACKGROUND) return;
77 
78  uint y = r.top + WD_TEXTPANEL_TOP;
79  for (uint i = 0; i < LAND_INFO_CENTERED_LINES; i++) {
80  if (StrEmpty(this->landinfo_data[i])) break;
81 
82  DrawString(r.left + WD_FRAMETEXT_LEFT, r.right - WD_FRAMETEXT_RIGHT, y, this->landinfo_data[i], i == 0 ? TC_LIGHT_BLUE : TC_FROMSTRING, SA_HOR_CENTER);
84  if (i == 0) y += 4;
85  }
86 
87  if (!StrEmpty(this->landinfo_data[LAND_INFO_MULTICENTER_LINE])) {
88  SetDParamStr(0, this->landinfo_data[LAND_INFO_MULTICENTER_LINE]);
89  DrawStringMultiLine(r.left + WD_FRAMETEXT_LEFT, r.right - WD_FRAMETEXT_RIGHT, y, r.bottom - WD_TEXTPANEL_BOTTOM, STR_JUST_RAW_STRING, TC_FROMSTRING, SA_CENTER);
90  }
91  }
92 
93  virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
94  {
95  if (widget != WID_LI_BACKGROUND) return;
96 
97  size->height = WD_TEXTPANEL_TOP + WD_TEXTPANEL_BOTTOM;
98  for (uint i = 0; i < LAND_INFO_CENTERED_LINES; i++) {
99  if (StrEmpty(this->landinfo_data[i])) break;
100 
101  uint width = GetStringBoundingBox(this->landinfo_data[i]).width + WD_FRAMETEXT_LEFT + WD_FRAMETEXT_RIGHT;
102  size->width = max(size->width, width);
103 
104  size->height += FONT_HEIGHT_NORMAL + WD_PAR_VSEP_NORMAL;
105  if (i == 0) size->height += 4;
106  }
107 
108  if (!StrEmpty(this->landinfo_data[LAND_INFO_MULTICENTER_LINE])) {
109  uint width = GetStringBoundingBox(this->landinfo_data[LAND_INFO_MULTICENTER_LINE]).width + WD_FRAMETEXT_LEFT + WD_FRAMETEXT_RIGHT;
110  size->width = max(size->width, min(300u, width));
111  SetDParamStr(0, this->landinfo_data[LAND_INFO_MULTICENTER_LINE]);
112  size->height += GetStringHeight(STR_JUST_RAW_STRING, size->width - WD_FRAMETEXT_LEFT - WD_FRAMETEXT_RIGHT);
113  }
114  }
115 
116  LandInfoWindow(TileIndex tile) : Window(&_land_info_desc), tile(tile)
117  {
118  this->InitNested();
119 
120 #if defined(_DEBUG)
121 # define LANDINFOD_LEVEL 0
122 #else
123 # define LANDINFOD_LEVEL 1
124 #endif
125  DEBUG(misc, LANDINFOD_LEVEL, "TILE: %#x (%i,%i)", tile, TileX(tile), TileY(tile));
126  DEBUG(misc, LANDINFOD_LEVEL, "type = %#x", _m[tile].type);
127  DEBUG(misc, LANDINFOD_LEVEL, "height = %#x", _m[tile].height);
128  DEBUG(misc, LANDINFOD_LEVEL, "m1 = %#x", _m[tile].m1);
129  DEBUG(misc, LANDINFOD_LEVEL, "m2 = %#x", _m[tile].m2);
130  DEBUG(misc, LANDINFOD_LEVEL, "m3 = %#x", _m[tile].m3);
131  DEBUG(misc, LANDINFOD_LEVEL, "m4 = %#x", _m[tile].m4);
132  DEBUG(misc, LANDINFOD_LEVEL, "m5 = %#x", _m[tile].m5);
133  DEBUG(misc, LANDINFOD_LEVEL, "m6 = %#x", _me[tile].m6);
134  DEBUG(misc, LANDINFOD_LEVEL, "m7 = %#x", _me[tile].m7);
135 #undef LANDINFOD_LEVEL
136  }
137 
138  virtual void OnInit()
139  {
141 
142  /* Because build_date is not set yet in every TileDesc, we make sure it is empty */
143  TileDesc td;
144 
146 
147  /* Most tiles have only one owner, but
148  * - drivethrough roadstops can be build on town owned roads (up to 2 owners) and
149  * - roads can have up to four owners (railroad, road, tram, 3rd-roadtype "highway").
150  */
151  td.owner_type[0] = STR_LAND_AREA_INFORMATION_OWNER; // At least one owner is displayed, though it might be "N/A".
152  td.owner_type[1] = STR_NULL; // STR_NULL results in skipping the owner
153  td.owner_type[2] = STR_NULL;
154  td.owner_type[3] = STR_NULL;
155  td.owner[0] = OWNER_NONE;
156  td.owner[1] = OWNER_NONE;
157  td.owner[2] = OWNER_NONE;
158  td.owner[3] = OWNER_NONE;
159 
160  td.station_class = STR_NULL;
161  td.station_name = STR_NULL;
162  td.airport_class = STR_NULL;
163  td.airport_name = STR_NULL;
164  td.airport_tile_name = STR_NULL;
165  td.rail_speed = 0;
166  td.road_speed = 0;
167 
168  td.grf = NULL;
169 
170  CargoArray acceptance;
171  AddAcceptedCargo(tile, acceptance, NULL);
172  GetTileDesc(tile, &td);
173 
174  uint line_nr = 0;
175 
176  /* Tiletype */
177  SetDParam(0, td.dparam[0]);
178  GetString(this->landinfo_data[line_nr], td.str, lastof(this->landinfo_data[line_nr]));
179  line_nr++;
180 
181  /* Up to four owners */
182  for (uint i = 0; i < 4; i++) {
183  if (td.owner_type[i] == STR_NULL) continue;
184 
185  SetDParam(0, STR_LAND_AREA_INFORMATION_OWNER_N_A);
186  if (td.owner[i] != OWNER_NONE && td.owner[i] != OWNER_WATER) GetNameOfOwner(td.owner[i], tile);
187  GetString(this->landinfo_data[line_nr], td.owner_type[i], lastof(this->landinfo_data[line_nr]));
188  line_nr++;
189  }
190 
191  /* Cost to clear/revenue when cleared */
192  StringID str = STR_LAND_AREA_INFORMATION_COST_TO_CLEAR_N_A;
194  if (c != NULL) {
195  Money old_money = c->money;
196  c->money = INT64_MAX;
197  assert(_current_company == _local_company);
198  CommandCost costclear = DoCommand(tile, 0, 0, DC_NONE, CMD_LANDSCAPE_CLEAR);
199  c->money = old_money;
200  if (costclear.Succeeded()) {
201  Money cost = costclear.GetCost();
202  if (cost < 0) {
203  cost = -cost; // Negate negative cost to a positive revenue
204  str = STR_LAND_AREA_INFORMATION_REVENUE_WHEN_CLEARED;
205  } else {
206  str = STR_LAND_AREA_INFORMATION_COST_TO_CLEAR;
207  }
208  SetDParam(0, cost);
209  }
210  }
211  GetString(this->landinfo_data[line_nr], str, lastof(this->landinfo_data[line_nr]));
212  line_nr++;
213 
214  /* Location */
215  char tmp[16];
216  seprintf(tmp, lastof(tmp), "0x%.4X", tile);
217  SetDParam(0, TileX(tile));
218  SetDParam(1, TileY(tile));
219  SetDParam(2, GetTileZ(tile));
220  SetDParamStr(3, tmp);
221  GetString(this->landinfo_data[line_nr], STR_LAND_AREA_INFORMATION_LANDINFO_COORDS, lastof(this->landinfo_data[line_nr]));
222  line_nr++;
223 
224  /* Local authority */
225  SetDParam(0, STR_LAND_AREA_INFORMATION_LOCAL_AUTHORITY_NONE);
226  if (t != NULL) {
227  SetDParam(0, STR_TOWN_NAME);
228  SetDParam(1, t->index);
229  }
230  GetString(this->landinfo_data[line_nr], STR_LAND_AREA_INFORMATION_LOCAL_AUTHORITY, lastof(this->landinfo_data[line_nr]));
231  line_nr++;
232 
233  /* Build date */
234  if (td.build_date != INVALID_DATE) {
235  SetDParam(0, td.build_date);
236  GetString(this->landinfo_data[line_nr], STR_LAND_AREA_INFORMATION_BUILD_DATE, lastof(this->landinfo_data[line_nr]));
237  line_nr++;
238  }
239 
240  /* Station class */
241  if (td.station_class != STR_NULL) {
242  SetDParam(0, td.station_class);
243  GetString(this->landinfo_data[line_nr], STR_LAND_AREA_INFORMATION_STATION_CLASS, lastof(this->landinfo_data[line_nr]));
244  line_nr++;
245  }
246 
247  /* Station type name */
248  if (td.station_name != STR_NULL) {
249  SetDParam(0, td.station_name);
250  GetString(this->landinfo_data[line_nr], STR_LAND_AREA_INFORMATION_STATION_TYPE, lastof(this->landinfo_data[line_nr]));
251  line_nr++;
252  }
253 
254  /* Airport class */
255  if (td.airport_class != STR_NULL) {
256  SetDParam(0, td.airport_class);
257  GetString(this->landinfo_data[line_nr], STR_LAND_AREA_INFORMATION_AIRPORT_CLASS, lastof(this->landinfo_data[line_nr]));
258  line_nr++;
259  }
260 
261  /* Airport name */
262  if (td.airport_name != STR_NULL) {
263  SetDParam(0, td.airport_name);
264  GetString(this->landinfo_data[line_nr], STR_LAND_AREA_INFORMATION_AIRPORT_NAME, lastof(this->landinfo_data[line_nr]));
265  line_nr++;
266  }
267 
268  /* Airport tile name */
269  if (td.airport_tile_name != STR_NULL) {
271  GetString(this->landinfo_data[line_nr], STR_LAND_AREA_INFORMATION_AIRPORTTILE_NAME, lastof(this->landinfo_data[line_nr]));
272  line_nr++;
273  }
274 
275  /* Rail speed limit */
276  if (td.rail_speed != 0) {
277  SetDParam(0, td.rail_speed);
278  GetString(this->landinfo_data[line_nr], STR_LANG_AREA_INFORMATION_RAIL_SPEED_LIMIT, lastof(this->landinfo_data[line_nr]));
279  line_nr++;
280  }
281 
282  /* Road speed limit */
283  if (td.road_speed != 0) {
284  SetDParam(0, td.road_speed);
285  GetString(this->landinfo_data[line_nr], STR_LANG_AREA_INFORMATION_ROAD_SPEED_LIMIT, lastof(this->landinfo_data[line_nr]));
286  line_nr++;
287  }
288 
289  /* NewGRF name */
290  if (td.grf != NULL) {
291  SetDParamStr(0, td.grf);
292  GetString(this->landinfo_data[line_nr], STR_LAND_AREA_INFORMATION_NEWGRF_NAME, lastof(this->landinfo_data[line_nr]));
293  line_nr++;
294  }
295 
296  assert(line_nr < LAND_INFO_CENTERED_LINES);
297 
298  /* Mark last line empty */
299  this->landinfo_data[line_nr][0] = '\0';
300 
301  /* Cargo acceptance is displayed in a extra multiline */
302  char *strp = GetString(this->landinfo_data[LAND_INFO_MULTICENTER_LINE], STR_LAND_AREA_INFORMATION_CARGO_ACCEPTED, lastof(this->landinfo_data[LAND_INFO_MULTICENTER_LINE]));
303  bool found = false;
304 
305  for (CargoID i = 0; i < NUM_CARGO; ++i) {
306  if (acceptance[i] > 0) {
307  /* Add a comma between each item. */
308  if (found) {
309  *strp++ = ',';
310  *strp++ = ' ';
311  }
312  found = true;
313 
314  /* If the accepted value is less than 8, show it in 1/8:ths */
315  if (acceptance[i] < 8) {
316  SetDParam(0, acceptance[i]);
317  SetDParam(1, CargoSpec::Get(i)->name);
318  strp = GetString(strp, STR_LAND_AREA_INFORMATION_CARGO_EIGHTS, lastof(this->landinfo_data[LAND_INFO_MULTICENTER_LINE]));
319  } else {
320  strp = GetString(strp, CargoSpec::Get(i)->name, lastof(this->landinfo_data[LAND_INFO_MULTICENTER_LINE]));
321  }
322  }
323  }
324  if (!found) this->landinfo_data[LAND_INFO_MULTICENTER_LINE][0] = '\0';
325  }
326 
327  virtual bool IsNewGRFInspectable() const
328  {
329  return ::IsNewGRFInspectable(GetGrfSpecFeature(this->tile), this->tile);
330  }
331 
332  virtual void ShowNewGRFInspectWindow() const
333  {
334  ::ShowNewGRFInspectWindow(GetGrfSpecFeature(this->tile), this->tile);
335  }
336 
342  virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
343  {
344  if (!gui_scope) return;
345  switch (data) {
346  case 1:
347  /* ReInit, "debug" sprite might have changed */
348  this->ReInit();
349  break;
350  }
351  }
352 };
353 
359 {
361  new LandInfoWindow(tile);
362 }
363 
364 static const NWidgetPart _nested_about_widgets[] = {
366  NWidget(WWT_CLOSEBOX, COLOUR_GREY),
367  NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_ABOUT_OPENTTD, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
368  EndContainer(),
369  NWidget(WWT_PANEL, COLOUR_GREY), SetPIP(4, 2, 4),
370  NWidget(WWT_LABEL, COLOUR_GREY), SetDataTip(STR_ABOUT_ORIGINAL_COPYRIGHT, STR_NULL),
371  NWidget(WWT_LABEL, COLOUR_GREY), SetDataTip(STR_ABOUT_VERSION, STR_NULL),
372  NWidget(WWT_FRAME, COLOUR_GREY), SetPadding(0, 5, 1, 5),
373  NWidget(WWT_EMPTY, INVALID_COLOUR, WID_A_SCROLLING_TEXT),
374  EndContainer(),
375  NWidget(WWT_LABEL, COLOUR_GREY, WID_A_WEBSITE), SetDataTip(STR_BLACK_RAW_STRING, STR_NULL),
376  NWidget(WWT_LABEL, COLOUR_GREY), SetDataTip(STR_ABOUT_COPYRIGHT_OPENTTD, STR_NULL),
377  EndContainer(),
378 };
379 
380 static WindowDesc _about_desc(
381  WDP_CENTER, NULL, 0, 0,
383  0,
384  _nested_about_widgets, lengthof(_nested_about_widgets)
385 );
386 
387 static const char * const _credits[] = {
388  "Original design by Chris Sawyer",
389  "Original graphics by Simon Foster",
390  "",
391  "The OpenTTD team (in alphabetical order):",
392  " Albert Hofkamp (Alberth) - GUI expert (since 0.7)",
393  " Matthijs Kooijman (blathijs) - Pathfinder-guru, Debian port (since 0.3)",
394  " Ulf Hermann (fonsinchen) - Cargo Distribution (since 1.3)",
395  " Christoph Elsenhans (frosch) - General coding (since 0.6)",
396  " Lo\xC3\xAF""c Guilloux (glx) - General / Windows Expert (since 0.4.5)",
397  " Michael Lutz (michi_cc) - Path based signals (since 0.7)",
398  " Owen Rudge (orudge) - Forum host, OS/2 port (since 0.1)",
399  " Peter Nelson (peter1138) - Spiritual descendant from NewGRF gods (since 0.4.5)",
400  " Ingo von Borstel (planetmaker) - General, Support (since 1.1)",
401  " Remko Bijker (Rubidium) - Lead coder and way more (since 0.4.5)",
402  " Jos\xC3\xA9 Soler (Terkhen) - General coding (since 1.0)",
403  " Leif Linse (Zuu) - AI/Game Script (since 1.2)",
404  "",
405  "Inactive Developers:",
406  " Jean-Fran\xC3\xA7ois Claeys (Belugas) - GUI, NewGRF and more (0.4.5 - 1.0)",
407  " Bjarni Corfitzen (Bjarni) - MacOSX port, coder and vehicles (0.3 - 0.7)",
408  " Victor Fischer (Celestar) - Programming everywhere you need him to (0.3 - 0.6)",
409  " Jaroslav Mazanec (KUDr) - YAPG (Yet Another Pathfinder God) ;) (0.4.5 - 0.6)",
410  " Jonathan Coome (Maedhros) - High priest of the NewGRF Temple (0.5 - 0.6)",
411  " Attila B\xC3\xA1n (MiHaMiX) - Developer WebTranslator 1 and 2 (0.3 - 0.5)",
412  " Zden\xC4\x9Bk Sojka (SmatZ) - Bug finder and fixer (0.6 - 1.3)",
413  " Christoph Mallon (Tron) - Programmer, code correctness police (0.3 - 0.5)",
414  " Patric Stout (TrueBrain) - NoAI, NoGo, Network (0.3 - 1.2), sys op (active)",
415  " Thijs Marinussen (Yexo) - AI Framework, General (0.6 - 1.3)",
416  "",
417  "Retired Developers:",
418  " Tam\xC3\xA1s Farag\xC3\xB3 (Darkvater) - Ex-Lead coder (0.3 - 0.5)",
419  " Dominik Scherer (dominik81) - Lead programmer, GUI expert (0.3 - 0.3)",
420  " Emil Djupfeld (egladil) - MacOSX (0.4.5 - 0.6)",
421  " Simon Sasburg (HackyKid) - Many bugfixes (0.4 - 0.4.5)",
422  " Ludvig Strigeus (ludde) - Original author of OpenTTD, main coder (0.1 - 0.3)",
423  " Cian Duffy (MYOB) - BeOS port / manual writing (0.1 - 0.3)",
424  " Petr Baudi\xC5\xA1 (pasky) - Many patches, NewGRF support (0.3 - 0.3)",
425  " Benedikt Br\xC3\xBCggemeier (skidd13) - Bug fixer and code reworker (0.6 - 0.7)",
426  " Serge Paquet (vurlix) - 2nd contributor after ludde (0.1 - 0.3)",
427  "",
428  "Special thanks go out to:",
429  " Josef Drexler - For his great work on TTDPatch",
430  " Marcin Grzegorczyk - Track foundations and for describing TTD internals",
431  " Stefan Mei\xC3\x9Fner (sign_de) - For his work on the console",
432  " Mike Ragsdale - OpenTTD installer",
433  " Christian Rosentreter (tokai) - MorphOS / AmigaOS port",
434  " Richard Kempton (richK) - additional airports, initial TGP implementation",
435  " Emperor Jake - titlegame",
436  "",
437  " Alberto Demichelis - Squirrel scripting language \xC2\xA9 2003-2008",
438  " L. Peter Deutsch - MD5 implementation \xC2\xA9 1999, 2000, 2002",
439  " Michael Blunck - Pre-signals and semaphores \xC2\xA9 2003",
440  " George - Canal/Lock graphics \xC2\xA9 2003-2004",
441  " Andrew Parkhouse (andythenorth) - River graphics",
442  " David Dallaston (Pikka) - Tram tracks",
443  " All Translators - Who made OpenTTD a truly international game",
444  " Bug Reporters - Without whom OpenTTD would still be full of bugs!",
445  "",
446  "",
447  "And last but not least:",
448  " Chris Sawyer - For an amazing game!"
449 };
450 
451 struct AboutWindow : public Window {
453  byte counter;
455  static const int num_visible_lines = 19;
456 
457  AboutWindow() : Window(&_about_desc)
458  {
460 
461  this->counter = 5;
462  this->text_position = this->GetWidget<NWidgetBase>(WID_A_SCROLLING_TEXT)->pos_y + this->GetWidget<NWidgetBase>(WID_A_SCROLLING_TEXT)->current_y;
463  }
464 
465  virtual void SetStringParameters(int widget) const
466  {
467  if (widget == WID_A_WEBSITE) SetDParamStr(0, "Website: http://www.openttd.org");
468  }
469 
470  virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
471  {
472  if (widget != WID_A_SCROLLING_TEXT) return;
473 
475 
476  Dimension d;
477  d.height = this->line_height * num_visible_lines;
478 
479  d.width = 0;
480  for (uint i = 0; i < lengthof(_credits); i++) {
481  d.width = max(d.width, GetStringBoundingBox(_credits[i]).width);
482  }
483  *size = maxdim(*size, d);
484  }
485 
486  virtual void DrawWidget(const Rect &r, int widget) const
487  {
488  if (widget != WID_A_SCROLLING_TEXT) return;
489 
490  int y = this->text_position;
491 
492  /* Show all scrolling _credits */
493  for (uint i = 0; i < lengthof(_credits); i++) {
494  if (y >= r.top + 7 && y < r.bottom - this->line_height) {
495  DrawString(r.left, r.right, y, _credits[i], TC_BLACK, SA_LEFT | SA_FORCE);
496  }
497  y += this->line_height;
498  }
499  }
500 
501  virtual void OnTick()
502  {
503  if (--this->counter == 0) {
504  this->counter = 5;
505  this->text_position--;
506  /* If the last text has scrolled start a new from the start */
507  if (this->text_position < (int)(this->GetWidget<NWidgetBase>(WID_A_SCROLLING_TEXT)->pos_y - lengthof(_credits) * this->line_height)) {
508  this->text_position = this->GetWidget<NWidgetBase>(WID_A_SCROLLING_TEXT)->pos_y + this->GetWidget<NWidgetBase>(WID_A_SCROLLING_TEXT)->current_y;
509  }
510  this->SetDirty();
511  }
512  }
513 };
514 
515 void ShowAboutWindow()
516 {
518  new AboutWindow();
519 }
520 
527 void ShowEstimatedCostOrIncome(Money cost, int x, int y)
528 {
529  StringID msg = STR_MESSAGE_ESTIMATED_COST;
530 
531  if (cost < 0) {
532  cost = -cost;
533  msg = STR_MESSAGE_ESTIMATED_INCOME;
534  }
535  SetDParam(0, cost);
537 }
538 
546 void ShowCostOrIncomeAnimation(int x, int y, int z, Money cost)
547 {
548  Point pt = RemapCoords(x, y, z);
549  StringID msg = STR_INCOME_FLOAT_COST;
550 
551  if (cost < 0) {
552  cost = -cost;
553  msg = STR_INCOME_FLOAT_INCOME;
554  }
555  SetDParam(0, cost);
556  AddTextEffect(msg, pt.x, pt.y, DAY_TICKS, TE_RISING);
557 }
558 
567 void ShowFeederIncomeAnimation(int x, int y, int z, Money transfer, Money income)
568 {
569  Point pt = RemapCoords(x, y, z);
570 
571  SetDParam(0, transfer);
572  if (income == 0) {
573  AddTextEffect(STR_FEEDER, pt.x, pt.y, DAY_TICKS, TE_RISING);
574  } else {
575  StringID msg = STR_FEEDER_COST;
576  if (income < 0) {
577  income = -income;
578  msg = STR_FEEDER_INCOME;
579  }
580  SetDParam(1, income);
581  AddTextEffect(msg, pt.x, pt.y, DAY_TICKS, TE_RISING);
582  }
583 }
584 
594 TextEffectID ShowFillingPercent(int x, int y, int z, uint8 percent, StringID string)
595 {
596  Point pt = RemapCoords(x, y, z);
597 
598  assert(string != STR_NULL);
599 
600  SetDParam(0, percent);
601  return AddTextEffect(string, pt.x, pt.y, 0, TE_STATIC);
602 }
603 
609 void UpdateFillingPercent(TextEffectID te_id, uint8 percent, StringID string)
610 {
611  assert(string != STR_NULL);
612 
613  SetDParam(0, percent);
614  UpdateTextEffect(te_id, string);
615 }
616 
621 void HideFillingPercent(TextEffectID *te_id)
622 {
623  if (*te_id == INVALID_TE_ID) return;
624 
625  RemoveTextEffect(*te_id);
626  *te_id = INVALID_TE_ID;
627 }
628 
629 static const NWidgetPart _nested_tooltips_widgets[] = {
630  NWidget(WWT_PANEL, COLOUR_GREY, WID_TT_BACKGROUND), SetMinimalSize(200, 32), EndContainer(),
631 };
632 
633 static WindowDesc _tool_tips_desc(
634  WDP_MANUAL, NULL, 0, 0, // Coordinates and sizes are not used,
636  WDF_NO_FOCUS,
637  _nested_tooltips_widgets, lengthof(_nested_tooltips_widgets)
638 );
639 
641 struct TooltipsWindow : public Window
642 {
644  byte paramcount;
645  uint64 params[5];
646  TooltipCloseCondition close_cond;
647 
648  TooltipsWindow(Window *parent, StringID str, uint paramcount, const uint64 params[], TooltipCloseCondition close_tooltip) : Window(&_tool_tips_desc)
649  {
650  this->parent = parent;
651  this->string_id = str;
652  assert_compile(sizeof(this->params[0]) == sizeof(params[0]));
653  assert(paramcount <= lengthof(this->params));
654  memcpy(this->params, params, sizeof(this->params[0]) * paramcount);
655  this->paramcount = paramcount;
656  this->close_cond = close_tooltip;
657 
658  this->InitNested();
659 
660  CLRBITS(this->flags, WF_WHITE_BORDER);
661  }
662 
663  virtual Point OnInitialPosition(int16 sm_width, int16 sm_height, int window_number)
664  {
665  /* Find the free screen space between the main toolbar at the top, and the statusbar at the bottom.
666  * Add a fixed distance 2 so the tooltip floats free from both bars.
667  */
668  int scr_top = GetMainViewTop() + 2;
669  int scr_bot = GetMainViewBottom() - 2;
670 
671  Point pt;
672 
673  /* Correctly position the tooltip position, watch out for window and cursor size
674  * Clamp value to below main toolbar and above statusbar. If tooltip would
675  * go below window, flip it so it is shown above the cursor */
676  pt.y = Clamp(_cursor.pos.y + _cursor.size.y + _cursor.offs.y + 5, scr_top, scr_bot);
677  if (pt.y + sm_height > scr_bot) pt.y = min(_cursor.pos.y + _cursor.offs.y - 5, scr_bot) - sm_height;
678  pt.x = sm_width >= _screen.width ? 0 : Clamp(_cursor.pos.x - (sm_width >> 1), 0, _screen.width - sm_width);
679 
680  return pt;
681  }
682 
683  virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
684  {
685  /* There is only one widget. */
686  for (uint i = 0; i != this->paramcount; i++) SetDParam(i, this->params[i]);
687 
688  size->width = min(GetStringBoundingBox(this->string_id).width, ScaleGUITrad(194));
689  size->height = GetStringHeight(this->string_id, size->width);
690 
691  /* Increase slightly to have some space around the box. */
692  size->width += 2 + WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT;
693  size->height += 2 + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
694  }
695 
696  virtual void DrawWidget(const Rect &r, int widget) const
697  {
698  /* There is only one widget. */
699  GfxFillRect(r.left, r.top, r.right, r.bottom, PC_BLACK);
700  GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, PC_LIGHT_YELLOW);
701 
702  for (uint arg = 0; arg < this->paramcount; arg++) {
703  SetDParam(arg, this->params[arg]);
704  }
705  DrawStringMultiLine(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP, r.bottom - WD_FRAMERECT_BOTTOM, this->string_id, TC_FROMSTRING, SA_CENTER);
706  }
707 
708  virtual void OnMouseLoop()
709  {
710  /* Always close tooltips when the cursor is not in our window. */
711  if (!_cursor.in_window) {
712  delete this;
713  return;
714  }
715 
716  /* We can show tooltips while dragging tools. These are shown as long as
717  * we are dragging the tool. Normal tooltips work with hover or rmb. */
718  switch (this->close_cond) {
719  case TCC_RIGHT_CLICK: if (!_right_button_down) delete this; break;
720  case TCC_LEFT_CLICK: if (!_left_button_down) delete this; break;
721  case TCC_HOVER: if (!_mouse_hovering) delete this; break;
722  }
723  }
724 };
725 
734 void GuiShowTooltips(Window *parent, StringID str, uint paramcount, const uint64 params[], TooltipCloseCondition close_tooltip)
735 {
737 
738  if (str == STR_NULL) return;
739 
740  new TooltipsWindow(parent, str, paramcount, params, close_tooltip);
741 }
742 
743 void QueryString::HandleEditBox(Window *w, int wid)
744 {
745  if (w->IsWidgetGloballyFocused(wid) && this->text.HandleCaret()) {
746  w->SetWidgetDirty(wid);
747 
748  /* For the OSK also invalidate the parent window */
749  if (w->window_class == WC_OSK) w->InvalidateData();
750  }
751 }
752 
753 void QueryString::DrawEditBox(const Window *w, int wid) const
754 {
755  const NWidgetLeaf *wi = w->GetWidget<NWidgetLeaf>(wid);
756 
757  assert((wi->type & WWT_MASK) == WWT_EDITBOX);
758 
759  bool rtl = _current_text_dir == TD_RTL;
760  Dimension sprite_size = GetSpriteSize(rtl ? SPR_IMG_DELETE_RIGHT : SPR_IMG_DELETE_LEFT);
761  int clearbtn_width = sprite_size.width + WD_IMGBTN_LEFT + WD_IMGBTN_RIGHT;
762 
763  int clearbtn_left = wi->pos_x + (rtl ? 0 : wi->current_x - clearbtn_width);
764  int clearbtn_right = wi->pos_x + (rtl ? clearbtn_width : wi->current_x) - 1;
765  int left = wi->pos_x + (rtl ? clearbtn_width : 0);
766  int right = wi->pos_x + (rtl ? wi->current_x : wi->current_x - clearbtn_width) - 1;
767 
768  int top = wi->pos_y;
769  int bottom = wi->pos_y + wi->current_y - 1;
770 
771  DrawFrameRect(clearbtn_left, top, clearbtn_right, bottom, wi->colour, wi->IsLowered() ? FR_LOWERED : FR_NONE);
772  DrawSprite(rtl ? SPR_IMG_DELETE_RIGHT : SPR_IMG_DELETE_LEFT, PAL_NONE, clearbtn_left + WD_IMGBTN_LEFT + (wi->IsLowered() ? 1 : 0), (top + bottom - sprite_size.height) / 2 + (wi->IsLowered() ? 1 : 0));
773  if (this->text.bytes == 1) GfxFillRect(clearbtn_left + 1, top + 1, clearbtn_right - 1, bottom - 1, _colour_gradient[wi->colour & 0xF][2], FILLRECT_CHECKER);
774 
775  DrawFrameRect(left, top, right, bottom, wi->colour, FR_LOWERED | FR_DARKENED);
776  GfxFillRect(left + 1, top + 1, right - 1, bottom - 1, PC_BLACK);
777 
778  /* Limit the drawing of the string inside the widget boundaries */
779  DrawPixelInfo dpi;
780  if (!FillDrawPixelInfo(&dpi, left + WD_FRAMERECT_LEFT, top + WD_FRAMERECT_TOP, right - left - WD_FRAMERECT_RIGHT, bottom - top - WD_FRAMERECT_BOTTOM)) return;
781 
782  DrawPixelInfo *old_dpi = _cur_dpi;
783  _cur_dpi = &dpi;
784 
785  /* We will take the current widget length as maximum width, with a small
786  * space reserved at the end for the caret to show */
787  const Textbuf *tb = &this->text;
788  int delta = min(0, (right - left) - tb->pixels - 10);
789 
790  if (tb->caretxoffs + delta < 0) delta = -tb->caretxoffs;
791 
792  /* If we have a marked area, draw a background highlight. */
793  if (tb->marklength != 0) GfxFillRect(delta + tb->markxoffs, 0, delta + tb->markxoffs + tb->marklength - 1, bottom - top, PC_GREY);
794 
795  DrawString(delta, tb->pixels, 0, tb->buf, TC_YELLOW);
796  bool focussed = w->IsWidgetGloballyFocused(wid) || IsOSKOpenedFor(w, wid);
797  if (focussed && tb->caret) {
798  int caret_width = GetStringBoundingBox("_").width;
799  DrawString(tb->caretxoffs + delta, tb->caretxoffs + delta + caret_width, 0, "_", TC_WHITE);
800  }
801 
802  _cur_dpi = old_dpi;
803 }
804 
812 {
813  const NWidgetLeaf *wi = w->GetWidget<NWidgetLeaf>(wid);
814 
815  assert((wi->type & WWT_MASK) == WWT_EDITBOX);
816 
817  bool rtl = _current_text_dir == TD_RTL;
818  Dimension sprite_size = GetSpriteSize(rtl ? SPR_IMG_DELETE_RIGHT : SPR_IMG_DELETE_LEFT);
819  int clearbtn_width = sprite_size.width + WD_IMGBTN_LEFT + WD_IMGBTN_RIGHT;
820 
821  int left = wi->pos_x + (rtl ? clearbtn_width : 0);
822  int right = wi->pos_x + (rtl ? wi->current_x : wi->current_x - clearbtn_width) - 1;
823 
824  /* Clamp caret position to be inside out current width. */
825  const Textbuf *tb = &this->text;
826  int delta = min(0, (right - left) - tb->pixels - 10);
827  if (tb->caretxoffs + delta < 0) delta = -tb->caretxoffs;
828 
829  Point pt = {left + WD_FRAMERECT_LEFT + tb->caretxoffs + delta, wi->pos_y + WD_FRAMERECT_TOP};
830  return pt;
831 }
832 
841 Rect QueryString::GetBoundingRect(const Window *w, int wid, const char *from, const char *to) const
842 {
843  const NWidgetLeaf *wi = w->GetWidget<NWidgetLeaf>(wid);
844 
845  assert((wi->type & WWT_MASK) == WWT_EDITBOX);
846 
847  bool rtl = _current_text_dir == TD_RTL;
848  Dimension sprite_size = GetSpriteSize(rtl ? SPR_IMG_DELETE_RIGHT : SPR_IMG_DELETE_LEFT);
849  int clearbtn_width = sprite_size.width + WD_IMGBTN_LEFT + WD_IMGBTN_RIGHT;
850 
851  int left = wi->pos_x + (rtl ? clearbtn_width : 0);
852  int right = wi->pos_x + (rtl ? wi->current_x : wi->current_x - clearbtn_width) - 1;
853 
854  int top = wi->pos_y + WD_FRAMERECT_TOP;
855  int bottom = wi->pos_y + wi->current_y - 1 - WD_FRAMERECT_BOTTOM;
856 
857  /* Clamp caret position to be inside our current width. */
858  const Textbuf *tb = &this->text;
859  int delta = min(0, (right - left) - tb->pixels - 10);
860  if (tb->caretxoffs + delta < 0) delta = -tb->caretxoffs;
861 
862  /* Get location of first and last character. */
863  Point p1 = GetCharPosInString(tb->buf, from, FS_NORMAL);
864  Point p2 = from != to ? GetCharPosInString(tb->buf, to, FS_NORMAL) : p1;
865 
866  Rect r = { Clamp(left + p1.x + delta + WD_FRAMERECT_LEFT, left, right), top, Clamp(left + p2.x + delta + WD_FRAMERECT_LEFT, left, right - WD_FRAMERECT_RIGHT), bottom };
867 
868  return r;
869 }
870 
878 const char *QueryString::GetCharAtPosition(const Window *w, int wid, const Point &pt) const
879 {
880  const NWidgetLeaf *wi = w->GetWidget<NWidgetLeaf>(wid);
881 
882  assert((wi->type & WWT_MASK) == WWT_EDITBOX);
883 
884  bool rtl = _current_text_dir == TD_RTL;
885  Dimension sprite_size = GetSpriteSize(rtl ? SPR_IMG_DELETE_RIGHT : SPR_IMG_DELETE_LEFT);
886  int clearbtn_width = sprite_size.width + WD_IMGBTN_LEFT + WD_IMGBTN_RIGHT;
887 
888  int left = wi->pos_x + (rtl ? clearbtn_width : 0);
889  int right = wi->pos_x + (rtl ? wi->current_x : wi->current_x - clearbtn_width) - 1;
890 
891  int top = wi->pos_y + WD_FRAMERECT_TOP;
892  int bottom = wi->pos_y + wi->current_y - 1 - WD_FRAMERECT_BOTTOM;
893 
894  if (!IsInsideMM(pt.y, top, bottom)) return NULL;
895 
896  /* Clamp caret position to be inside our current width. */
897  const Textbuf *tb = &this->text;
898  int delta = min(0, (right - left) - tb->pixels - 10);
899  if (tb->caretxoffs + delta < 0) delta = -tb->caretxoffs;
900 
901  return ::GetCharAtPosition(tb->buf, pt.x - delta - left);
902 }
903 
904 void QueryString::ClickEditBox(Window *w, Point pt, int wid, int click_count, bool focus_changed)
905 {
906  const NWidgetLeaf *wi = w->GetWidget<NWidgetLeaf>(wid);
907 
908  assert((wi->type & WWT_MASK) == WWT_EDITBOX);
909 
910  bool rtl = _current_text_dir == TD_RTL;
911  int clearbtn_width = GetSpriteSize(rtl ? SPR_IMG_DELETE_RIGHT : SPR_IMG_DELETE_LEFT).width;
912 
913  int clearbtn_left = wi->pos_x + (rtl ? 0 : wi->current_x - clearbtn_width);
914 
915  if (IsInsideBS(pt.x, clearbtn_left, clearbtn_width)) {
916  if (this->text.bytes > 1) {
917  this->text.DeleteAll();
918  w->HandleButtonClick(wid);
919  w->OnEditboxChanged(wid);
920  }
921  return;
922  }
923 
925  (!focus_changed || _settings_client.gui.osk_activation == OSKA_IMMEDIATELY) &&
926  (click_count == 2 || _settings_client.gui.osk_activation != OSKA_DOUBLE_CLICK)) {
927  /* Open the OSK window */
928  ShowOnScreenKeyboard(w, wid);
929  }
930 }
931 
933 struct QueryStringWindow : public Window
934 {
937 
938  QueryStringWindow(StringID str, StringID caption, uint max_bytes, uint max_chars, WindowDesc *desc, Window *parent, CharSetFilter afilter, QueryStringFlags flags) :
939  Window(desc), editbox(max_bytes, max_chars)
940  {
941  char *last_of = &this->editbox.text.buf[this->editbox.text.max_bytes - 1];
942  GetString(this->editbox.text.buf, str, last_of);
943  str_validate(this->editbox.text.buf, last_of, SVS_NONE);
944 
945  /* Make sure the name isn't too long for the text buffer in the number of
946  * characters (not bytes). max_chars also counts the '\0' characters. */
947  while (Utf8StringLength(this->editbox.text.buf) + 1 > this->editbox.text.max_chars) {
948  *Utf8PrevChar(this->editbox.text.buf + strlen(this->editbox.text.buf)) = '\0';
949  }
950 
951  this->editbox.text.UpdateSize();
952 
953  if ((flags & QSF_ACCEPT_UNCHANGED) == 0) this->editbox.orig = stredup(this->editbox.text.buf);
954 
955  this->querystrings[WID_QS_TEXT] = &this->editbox;
956  this->editbox.caption = caption;
958  this->editbox.ok_button = WID_QS_OK;
959  this->editbox.text.afilter = afilter;
960  this->flags = flags;
961 
963 
964  this->parent = parent;
965 
967  }
968 
969  virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
970  {
971  if (widget == WID_QS_DEFAULT && (this->flags & QSF_ENABLE_DEFAULT) == 0) {
972  /* We don't want this widget to show! */
973  fill->width = 0;
974  resize->width = 0;
975  size->width = 0;
976  }
977  }
978 
979  virtual void SetStringParameters(int widget) const
980  {
981  if (widget == WID_QS_CAPTION) SetDParam(0, this->editbox.caption);
982  }
983 
984  void OnOk()
985  {
986  if (this->editbox.orig == NULL || strcmp(this->editbox.text.buf, this->editbox.orig) != 0) {
987  /* If the parent is NULL, the editbox is handled by general function
988  * HandleOnEditText */
989  if (this->parent != NULL) {
990  this->parent->OnQueryTextFinished(this->editbox.text.buf);
991  } else {
992  HandleOnEditText(this->editbox.text.buf);
993  }
994  this->editbox.handled = true;
995  }
996  }
997 
998  virtual void OnClick(Point pt, int widget, int click_count)
999  {
1000  switch (widget) {
1001  case WID_QS_DEFAULT:
1002  this->editbox.text.DeleteAll();
1003  /* FALL THROUGH */
1004  case WID_QS_OK:
1005  this->OnOk();
1006  /* FALL THROUGH */
1007  case WID_QS_CANCEL:
1008  delete this;
1009  break;
1010  }
1011  }
1012 
1014  {
1015  if (!this->editbox.handled && this->parent != NULL) {
1016  Window *parent = this->parent;
1017  this->parent = NULL; // so parent doesn't try to delete us again
1018  parent->OnQueryTextFinished(NULL);
1019  }
1020  }
1021 };
1022 
1023 static const NWidgetPart _nested_query_string_widgets[] = {
1025  NWidget(WWT_CLOSEBOX, COLOUR_GREY),
1026  NWidget(WWT_CAPTION, COLOUR_GREY, WID_QS_CAPTION), SetDataTip(STR_WHITE_STRING, STR_NULL),
1027  EndContainer(),
1028  NWidget(WWT_PANEL, COLOUR_GREY),
1029  NWidget(WWT_EDITBOX, COLOUR_GREY, WID_QS_TEXT), SetMinimalSize(256, 12), SetFill(1, 1), SetPadding(2, 2, 2, 2),
1030  EndContainer(),
1032  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_QS_DEFAULT), SetMinimalSize(87, 12), SetFill(1, 1), SetDataTip(STR_BUTTON_DEFAULT, STR_NULL),
1033  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_QS_CANCEL), SetMinimalSize(86, 12), SetFill(1, 1), SetDataTip(STR_BUTTON_CANCEL, STR_NULL),
1034  NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_QS_OK), SetMinimalSize(87, 12), SetFill(1, 1), SetDataTip(STR_BUTTON_OK, STR_NULL),
1035  EndContainer(),
1036 };
1037 
1038 static WindowDesc _query_string_desc(
1039  WDP_CENTER, "query_string", 0, 0,
1041  0,
1042  _nested_query_string_widgets, lengthof(_nested_query_string_widgets)
1043 );
1044 
1055 void ShowQueryString(StringID str, StringID caption, uint maxsize, Window *parent, CharSetFilter afilter, QueryStringFlags flags)
1056 {
1058  new QueryStringWindow(str, caption, ((flags & QSF_LEN_IN_CHARS) ? MAX_CHAR_LENGTH : 1) * maxsize, maxsize, &_query_string_desc, parent, afilter, flags);
1059 }
1060 
1064 struct QueryWindow : public Window {
1066  uint64 params[10];
1069 
1071  {
1072  /* Create a backup of the variadic arguments to strings because it will be
1073  * overridden pretty often. We will copy these back for drawing */
1074  CopyOutDParam(this->params, 0, lengthof(this->params));
1075  this->caption = caption;
1076  this->message = message;
1077  this->proc = callback;
1078 
1080 
1081  this->parent = parent;
1082  this->left = parent->left + (parent->width / 2) - (this->width / 2);
1083  this->top = parent->top + (parent->height / 2) - (this->height / 2);
1084  }
1085 
1086  ~QueryWindow()
1087  {
1088  if (this->proc != NULL) this->proc(this->parent, false);
1089  }
1090 
1091  virtual void SetStringParameters(int widget) const
1092  {
1093  switch (widget) {
1094  case WID_Q_CAPTION:
1095  CopyInDParam(1, this->params, lengthof(this->params));
1096  SetDParam(0, this->caption);
1097  break;
1098 
1099  case WID_Q_TEXT:
1100  CopyInDParam(0, this->params, lengthof(this->params));
1101  break;
1102  }
1103  }
1104 
1105  virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
1106  {
1107  if (widget != WID_Q_TEXT) return;
1108 
1111  d.height += WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
1112  *size = d;
1113  }
1114 
1115  virtual void DrawWidget(const Rect &r, int widget) const
1116  {
1117  if (widget != WID_Q_TEXT) return;
1118 
1120  this->message, TC_FROMSTRING, SA_CENTER);
1121  }
1122 
1123  virtual void OnClick(Point pt, int widget, int click_count)
1124  {
1125  switch (widget) {
1126  case WID_Q_YES: {
1127  /* in the Generate New World window, clicking 'Yes' causes
1128  * DeleteNonVitalWindows() to be called - we shouldn't be in a window then */
1129  QueryCallbackProc *proc = this->proc;
1130  Window *parent = this->parent;
1131  /* Prevent the destructor calling the callback function */
1132  this->proc = NULL;
1133  delete this;
1134  if (proc != NULL) {
1135  proc(parent, true);
1136  proc = NULL;
1137  }
1138  break;
1139  }
1140  case WID_Q_NO:
1141  delete this;
1142  break;
1143  }
1144  }
1145 
1146  virtual EventState OnKeyPress(WChar key, uint16 keycode)
1147  {
1148  /* ESC closes the window, Enter confirms the action */
1149  switch (keycode) {
1150  case WKC_RETURN:
1151  case WKC_NUM_ENTER:
1152  if (this->proc != NULL) {
1153  this->proc(this->parent, true);
1154  this->proc = NULL;
1155  }
1156  /* FALL THROUGH */
1157  case WKC_ESC:
1158  delete this;
1159  return ES_HANDLED;
1160  }
1161  return ES_NOT_HANDLED;
1162  }
1163 };
1164 
1165 static const NWidgetPart _nested_query_widgets[] = {
1167  NWidget(WWT_CLOSEBOX, COLOUR_RED),
1168  NWidget(WWT_CAPTION, COLOUR_RED, WID_Q_CAPTION), SetDataTip(STR_JUST_STRING, STR_NULL),
1169  EndContainer(),
1170  NWidget(WWT_PANEL, COLOUR_RED), SetPIP(8, 15, 8),
1171  NWidget(WWT_TEXT, COLOUR_RED, WID_Q_TEXT), SetMinimalSize(200, 12),
1172  NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(20, 29, 20),
1173  NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_Q_NO), SetMinimalSize(71, 12), SetFill(1, 1), SetDataTip(STR_QUIT_NO, STR_NULL),
1174  NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_Q_YES), SetMinimalSize(71, 12), SetFill(1, 1), SetDataTip(STR_QUIT_YES, STR_NULL),
1175  EndContainer(),
1176  EndContainer(),
1177 };
1178 
1179 static WindowDesc _query_desc(
1180  WDP_CENTER, NULL, 0, 0,
1182  WDF_MODAL,
1183  _nested_query_widgets, lengthof(_nested_query_widgets)
1184 );
1185 
1195 void ShowQuery(StringID caption, StringID message, Window *parent, QueryCallbackProc *callback)
1196 {
1197  if (parent == NULL) parent = FindWindowById(WC_MAIN_WINDOW, 0);
1198 
1199  const Window *w;
1200  FOR_ALL_WINDOWS_FROM_BACK(w) {
1201  if (w->window_class != WC_CONFIRM_POPUP_QUERY) continue;
1202 
1203  const QueryWindow *qw = (const QueryWindow *)w;
1204  if (qw->parent != parent || qw->proc != callback) continue;
1205 
1206  delete qw;
1207  break;
1208  }
1209 
1210  new QueryWindow(&_query_desc, caption, message, parent, callback);
1211 }