OpenTTD Source: src/misc_gui.cpp Source File

OpenTTD Source 14.1

misc_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 "debug.h"
12 #include "landscape.h"
13 #include "error.h"
14 #include "gui.h"
15 #include "command_func.h"
16 #include "company_func.h"
17 #include "town.h"
18 #include "string_func.h"
19 #include "company_base.h"
20 #include "texteff.hpp"
21 #include "strings_func.h"
22 #include "window_func.h"
23 #include "querystring_gui.h"
24 #include "core/geometry_func.hpp"
25 #include "newgrf_debug.h"
26 #include "zoom_func.h"
27 #include "viewport_func.h"
28 #include "landscape_cmd.h"
29 #include "rev.h"
30 #include "timer/timer.h"
31 #include "timer/timer_window.h"
32 #include "pathfinder/water_regions.h"
33
34 #include "widgets/misc_widget.h"
35
36 #include "table/strings.h"
37
38 #include <sstream>
39 #include <iomanip>
40
41 #include "safeguards.h"
42
44 enum OskActivation {
45 OSKA_DISABLED,
46 OSKA_DOUBLE_CLICK,
47 OSKA_SINGLE_CLICK,
48 OSKA_IMMEDIATELY,
49 };
50
51
52 static constexpr NWidgetPart _nested_land_info_widgets[] = {
53 NWidget(NWID_HORIZONTAL),
54 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
55 NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_LAND_AREA_INFORMATION_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
56 NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_LI_LOCATION), SetMinimalSize(12, 14), SetDataTip(SPR_GOTO_LOCATION, STR_LAND_AREA_INFORMATION_LOCATION_TOOLTIP),
57 NWidget(WWT_DEBUGBOX, COLOUR_GREY),
58 EndContainer(),
59 NWidget(WWT_PANEL, COLOUR_GREY, WID_LI_BACKGROUND), EndContainer(),
60 };
61
62 static WindowDesc _land_info_desc(__FILE__, __LINE__,
63 WDP_AUTO, nullptr, 0, 0,
64 WC_LAND_INFO, WC_NONE,
65 0,
66 std::begin(_nested_land_info_widgets), std::end(_nested_land_info_widgets)
67 );
68
69 class LandInfoWindow : public Window {
70 StringList landinfo_data;
71 std::string cargo_acceptance;
72
73 public:
74 TileIndex tile;
75
76 void DrawWidget(const Rect &r, WidgetID widget) const override
77 {
78 if (widget != WID_LI_BACKGROUND) return;
79
80 Rect ir = r.Shrink(WidgetDimensions::scaled.frametext);
81 for (size_t i = 0; i < this->landinfo_data.size(); i++) {
82 DrawString(ir, this->landinfo_data[i], i == 0 ? TC_LIGHT_BLUE : TC_FROMSTRING, SA_HOR_CENTER);
83 ir.top += GetCharacterHeight(FS_NORMAL) + (i == 0 ? WidgetDimensions::scaled.vsep_wide : WidgetDimensions::scaled.vsep_normal);
84 }
85
86 if (!this->cargo_acceptance.empty()) {
87 SetDParamStr(0, this->cargo_acceptance);
88 DrawStringMultiLine(ir, STR_JUST_RAW_STRING, TC_FROMSTRING, SA_CENTER);
89 }
90 }
91
92 void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override
93 {
94 if (widget != WID_LI_BACKGROUND) return;
95
96 size->height = WidgetDimensions::scaled.frametext.Vertical();
97 for (size_t i = 0; i < this->landinfo_data.size(); i++) {
98 uint width = GetStringBoundingBox(this->landinfo_data[i]).width + WidgetDimensions::scaled.frametext.Horizontal();
99 size->width = std::max(size->width, width);
100
101 size->height += GetCharacterHeight(FS_NORMAL) + (i == 0 ? WidgetDimensions::scaled.vsep_wide : WidgetDimensions::scaled.vsep_normal);
102 }
103
104 if (!this->cargo_acceptance.empty()) {
105 uint width = GetStringBoundingBox(this->cargo_acceptance).width + WidgetDimensions::scaled.frametext.Horizontal();
106 size->width = std::max(size->width, std::min(static_cast<uint>(ScaleGUITrad(300)), width));
107 SetDParamStr(0, cargo_acceptance);
108 size->height += GetStringHeight(STR_JUST_RAW_STRING, size->width - WidgetDimensions::scaled.frametext.Horizontal());
109 }
110 }
111
112 LandInfoWindow(Tile tile) : Window(&_land_info_desc), tile(tile)
113 {
114 this->InitNested();
115
116 #if defined(_DEBUG)
117 # define LANDINFOD_LEVEL 0
118 #else
119 # define LANDINFOD_LEVEL 1
120 #endif
121 Debug(misc, LANDINFOD_LEVEL, "TILE: 0x{:x} ({},{})", (TileIndex)tile, TileX(tile), TileY(tile));
122 Debug(misc, LANDINFOD_LEVEL, "type = 0x{:x}", tile.type());
123 Debug(misc, LANDINFOD_LEVEL, "height = 0x{:x}", tile.height());
124 Debug(misc, LANDINFOD_LEVEL, "m1 = 0x{:x}", tile.m1());
125 Debug(misc, LANDINFOD_LEVEL, "m2 = 0x{:x}", tile.m2());
126 Debug(misc, LANDINFOD_LEVEL, "m3 = 0x{:x}", tile.m3());
127 Debug(misc, LANDINFOD_LEVEL, "m4 = 0x{:x}", tile.m4());
128 Debug(misc, LANDINFOD_LEVEL, "m5 = 0x{:x}", tile.m5());
129 Debug(misc, LANDINFOD_LEVEL, "m6 = 0x{:x}", tile.m6());
130 Debug(misc, LANDINFOD_LEVEL, "m7 = 0x{:x}", tile.m7());
131 Debug(misc, LANDINFOD_LEVEL, "m8 = 0x{:x}", tile.m8());
132
133 PrintWaterRegionDebugInfo(tile);
134 #undef LANDINFOD_LEVEL
135 }
136
137 void OnInit() override
138 {
139 Town *t = ClosestTownFromTile(tile, _settings_game.economy.dist_local_authority);
140
141 /* Because build_date is not set yet in every TileDesc, we make sure it is empty */
142 TileDesc td;
143
144 td.build_date = CalendarTime::INVALID_DATE;
145
146 /* Most tiles have only one owner, but
147 * - drivethrough roadstops can be build on town owned roads (up to 2 owners) and
148 * - roads can have up to four owners (railroad, road, tram, 3rd-roadtype "highway").
149 */
150 td.owner_type[0] = STR_LAND_AREA_INFORMATION_OWNER; // At least one owner is displayed, though it might be "N/A".
151 td.owner_type[1] = STR_NULL; // STR_NULL results in skipping the owner
152 td.owner_type[2] = STR_NULL;
153 td.owner_type[3] = STR_NULL;
154 td.owner[0] = OWNER_NONE;
155 td.owner[1] = OWNER_NONE;
156 td.owner[2] = OWNER_NONE;
157 td.owner[3] = OWNER_NONE;
158
159 td.station_class = STR_NULL;
160 td.station_name = STR_NULL;
161 td.airport_class = STR_NULL;
162 td.airport_name = STR_NULL;
163 td.airport_tile_name = STR_NULL;
164 td.railtype = STR_NULL;
165 td.rail_speed = 0;
166 td.roadtype = STR_NULL;
167 td.road_speed = 0;
168 td.tramtype = STR_NULL;
169 td.tram_speed = 0;
170
171 td.grf = nullptr;
172
173 CargoArray acceptance{};
174 AddAcceptedCargo(tile, acceptance, nullptr);
175 GetTileDesc(tile, &td);
176
177 this->landinfo_data.clear();
178
179 /* Tiletype */
180 SetDParam(0, td.dparam);
181 this->landinfo_data.push_back(GetString(td.str));
182
183 /* Up to four owners */
184 for (uint i = 0; i < 4; i++) {
185 if (td.owner_type[i] == STR_NULL) continue;
186
187 SetDParam(0, STR_LAND_AREA_INFORMATION_OWNER_N_A);
188 if (td.owner[i] != OWNER_NONE && td.owner[i] != OWNER_WATER) SetDParamsForOwnedBy(td.owner[i], tile);
189 this->landinfo_data.push_back(GetString(td.owner_type[i]));
190 }
191
192 /* Cost to clear/revenue when cleared */
193 StringID str = STR_LAND_AREA_INFORMATION_COST_TO_CLEAR_N_A;
194 Company *c = Company::GetIfValid(_local_company);
195 if (c != nullptr) {
196 assert(_current_company == _local_company);
197 CommandCost costclear = Command<CMD_LANDSCAPE_CLEAR>::Do(DC_QUERY_COST, tile);
198 if (costclear.Succeeded()) {
199 Money cost = costclear.GetCost();
200 if (cost < 0) {
201 cost = -cost; // Negate negative cost to a positive revenue
202 str = STR_LAND_AREA_INFORMATION_REVENUE_WHEN_CLEARED;
203 } else {
204 str = STR_LAND_AREA_INFORMATION_COST_TO_CLEAR;
205 }
206 SetDParam(0, cost);
207 }
208 }
209 this->landinfo_data.push_back(GetString(str));
210
211 /* Location */
212 std::stringstream tile_ss;
213 tile_ss << "0x" << std::setfill('0') << std::setw(4) << std::hex << std::uppercase << tile.base(); // 0x%.4X
214
215 SetDParam(0, TileX(tile));
216 SetDParam(1, TileY(tile));
217 SetDParam(2, GetTileZ(tile));
218 SetDParamStr(3, tile_ss.str());
219 this->landinfo_data.push_back(GetString(STR_LAND_AREA_INFORMATION_LANDINFO_COORDS));
220
221 /* Local authority */
222 SetDParam(0, STR_LAND_AREA_INFORMATION_LOCAL_AUTHORITY_NONE);
223 if (t != nullptr) {
224 SetDParam(0, STR_TOWN_NAME);
225 SetDParam(1, t->index);
226 }
227 this->landinfo_data.push_back(GetString(STR_LAND_AREA_INFORMATION_LOCAL_AUTHORITY));
228
229 /* Build date */
230 if (td.build_date != CalendarTime::INVALID_DATE) {
231 SetDParam(0, td.build_date);
232 this->landinfo_data.push_back(GetString(STR_LAND_AREA_INFORMATION_BUILD_DATE));
233 }
234
235 /* Station class */
236 if (td.station_class != STR_NULL) {
237 SetDParam(0, td.station_class);
238 this->landinfo_data.push_back(GetString(STR_LAND_AREA_INFORMATION_STATION_CLASS));
239 }
240
241 /* Station type name */
242 if (td.station_name != STR_NULL) {
243 SetDParam(0, td.station_name);
244 this->landinfo_data.push_back(GetString(STR_LAND_AREA_INFORMATION_STATION_TYPE));
245 }
246
247 /* Airport class */
248 if (td.airport_class != STR_NULL) {
249 SetDParam(0, td.airport_class);
250 this->landinfo_data.push_back(GetString(STR_LAND_AREA_INFORMATION_AIRPORT_CLASS));
251 }
252
253 /* Airport name */
254 if (td.airport_name != STR_NULL) {
255 SetDParam(0, td.airport_name);
256 this->landinfo_data.push_back(GetString(STR_LAND_AREA_INFORMATION_AIRPORT_NAME));
257 }
258
259 /* Airport tile name */
260 if (td.airport_tile_name != STR_NULL) {
261 SetDParam(0, td.airport_tile_name);
262 this->landinfo_data.push_back(GetString(STR_LAND_AREA_INFORMATION_AIRPORTTILE_NAME));
263 }
264
265 /* Rail type name */
266 if (td.railtype != STR_NULL) {
267 SetDParam(0, td.railtype);
268 this->landinfo_data.push_back(GetString(STR_LANG_AREA_INFORMATION_RAIL_TYPE));
269 }
270
271 /* Rail speed limit */
272 if (td.rail_speed != 0) {
273 SetDParam(0, PackVelocity(td.rail_speed, VEH_TRAIN));
274 this->landinfo_data.push_back(GetString(STR_LANG_AREA_INFORMATION_RAIL_SPEED_LIMIT));
275 }
276
277 /* Road type name */
278 if (td.roadtype != STR_NULL) {
279 SetDParam(0, td.roadtype);
280 this->landinfo_data.push_back(GetString(STR_LANG_AREA_INFORMATION_ROAD_TYPE));
281 }
282
283 /* Road speed limit */
284 if (td.road_speed != 0) {
285 SetDParam(0, PackVelocity(td.road_speed, VEH_ROAD));
286 this->landinfo_data.push_back(GetString(STR_LANG_AREA_INFORMATION_ROAD_SPEED_LIMIT));
287 }
288
289 /* Tram type name */
290 if (td.tramtype != STR_NULL) {
291 SetDParam(0, td.tramtype);
292 this->landinfo_data.push_back(GetString(STR_LANG_AREA_INFORMATION_TRAM_TYPE));
293 }
294
295 /* Tram speed limit */
296 if (td.tram_speed != 0) {
297 SetDParam(0, PackVelocity(td.tram_speed, VEH_ROAD));
298 this->landinfo_data.push_back(GetString(STR_LANG_AREA_INFORMATION_TRAM_SPEED_LIMIT));
299 }
300
301 /* NewGRF name */
302 if (td.grf != nullptr) {
303 SetDParamStr(0, td.grf);
304 this->landinfo_data.push_back(GetString(STR_LAND_AREA_INFORMATION_NEWGRF_NAME));
305 }
306
307 /* Cargo acceptance is displayed in a extra multiline */
308 std::stringstream line;
309 line << GetString(STR_LAND_AREA_INFORMATION_CARGO_ACCEPTED);
310
311 bool found = false;
312 for (const CargoSpec *cs : _sorted_cargo_specs) {
313 CargoID cid = cs->Index();
314 if (acceptance[cid] > 0) {
315 /* Add a comma between each item. */
316 if (found) line << ", ";
317 found = true;
318
319 /* If the accepted value is less than 8, show it in 1/8:ths */
320 if (acceptance[cid] < 8) {
321 SetDParam(0, acceptance[cid]);
322 SetDParam(1, cs->name);
323 line << GetString(STR_LAND_AREA_INFORMATION_CARGO_EIGHTS);
324 } else {
325 line << GetString(cs->name);
326 }
327 }
328 }
329 if (found) {
330 this->cargo_acceptance = line.str();
331 } else {
332 this->cargo_acceptance.clear();
333 }
334 }
335
336 bool IsNewGRFInspectable() const override
337 {
338 return ::IsNewGRFInspectable(GetGrfSpecFeature(this->tile), this->tile.base());
339 }
340
341 void ShowNewGRFInspectWindow() const override
342 {
343 ::ShowNewGRFInspectWindow(GetGrfSpecFeature(this->tile), this->tile.base());
344 }
345
346 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
347 {
348 switch (widget) {
349 case WID_LI_LOCATION:
350 if (_ctrl_pressed) {
351 ShowExtraViewportWindow(this->tile);
352 } else {
353 ScrollMainWindowToTile(this->tile);
354 }
355 break;
356 }
357 }
358
364 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
365 {
366 if (!gui_scope) return;
367
368 /* ReInit, "debug" sprite might have changed */
369 if (data == 1) this->ReInit();
370 }
371 };
372
377 void ShowLandInfo(TileIndex tile)
378 {
379 CloseWindowById(WC_LAND_INFO, 0);
380 new LandInfoWindow(tile);
381 }
382
383 static constexpr NWidgetPart _nested_about_widgets[] = {
384 NWidget(NWID_HORIZONTAL),
385 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
386 NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_ABOUT_OPENTTD, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
387 EndContainer(),
388 NWidget(WWT_PANEL, COLOUR_GREY), SetPIP(4, 2, 4),
389 NWidget(WWT_LABEL, COLOUR_GREY), SetDataTip(STR_ABOUT_ORIGINAL_COPYRIGHT, STR_NULL),
390 NWidget(WWT_LABEL, COLOUR_GREY), SetDataTip(STR_ABOUT_VERSION, STR_NULL),
391 NWidget(WWT_FRAME, COLOUR_GREY), SetPadding(0, 5, 1, 5),
392 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_A_SCROLLING_TEXT),
393 EndContainer(),
394 NWidget(WWT_LABEL, COLOUR_GREY, WID_A_WEBSITE), SetDataTip(STR_JUST_RAW_STRING, STR_NULL),
395 NWidget(WWT_LABEL, COLOUR_GREY, WID_A_COPYRIGHT), SetDataTip(STR_ABOUT_COPYRIGHT_OPENTTD, STR_NULL),
396 EndContainer(),
397 };
398
399 static WindowDesc _about_desc(__FILE__, __LINE__,
400 WDP_CENTER, nullptr, 0, 0,
401 WC_GAME_OPTIONS, WC_NONE,
402 0,
403 std::begin(_nested_about_widgets), std::end(_nested_about_widgets)
404 );
405
406 static const char * const _credits[] = {
407 "Original design by Chris Sawyer",
408 "Original graphics by Simon Foster",
409 "",
410 "The OpenTTD team (in alphabetical order):",
411 " Matthijs Kooijman (blathijs) - Pathfinder-guru, Debian port (since 0.3)",
412 " Christoph Elsenhans (frosch) - General coding (since 0.6)",
413 " Lo\u00efc Guilloux (glx) - General / Windows Expert (since 0.4.5)",
414 " Koen Bussemaker (Kuhnovic) - General / Ship pathfinder (since 14)",
415 " Charles Pigott (LordAro) - General / Correctness police (since 1.9)",
416 " Michael Lutz (michi_cc) - Path based signals (since 0.7)",
417 " Niels Martin Hansen (nielsm) - Music system, general coding (since 1.9)",
418 " Owen Rudge (orudge) - Forum host, OS/2 port (since 0.1)",
419 " Peter Nelson (peter1138) - Spiritual descendant from NewGRF gods (since 0.4.5)",
420 " Remko Bijker (Rubidium) - Coder and way more (since 0.4.5)",
421 " Patric Stout (TrueBrain) - NoProgrammer (since 0.3), sys op",
422 " Tyler Trahan (2TallTyler) - General / Time Lord (since 13)",
423 "",
424 "Inactive Developers:",
425 " Grzegorz Duczy\u0144ski (adf88) - General coding (1.7 - 1.8)",
426 " Albert Hofkamp (Alberth) - GUI expert (0.7 - 1.9)",
427 " Jean-Fran\u00e7ois Claeys (Belugas) - GUI, NewGRF and more (0.4.5 - 1.0)",
428 " Bjarni Corfitzen (Bjarni) - MacOSX port, coder and vehicles (0.3 - 0.7)",
429 " Victor Fischer (Celestar) - Programming everywhere you need him to (0.3 - 0.6)",
430 " Ulf Hermann (fonsinchen) - Cargo Distribution (1.3 - 1.6)",
431 " Jaroslav Mazanec (KUDr) - YAPG (Yet Another Pathfinder God) ;) (0.4.5 - 0.6)",
432 " Jonathan Coome (Maedhros) - High priest of the NewGRF Temple (0.5 - 0.6)",
433 " Attila B\u00e1n (MiHaMiX) - Developer WebTranslator 1 and 2 (0.3 - 0.5)",
434 " Ingo von Borstel (planetmaker) - General coding, Support (1.1 - 1.9)",
435 " Zden\u011bk Sojka (SmatZ) - Bug finder and fixer (0.6 - 1.3)",
436 " Jos\u00e9 Soler (Terkhen) - General coding (1.0 - 1.4)",
437 " Christoph Mallon (Tron) - Programmer, code correctness police (0.3 - 0.5)",
438 " Thijs Marinussen (Yexo) - AI Framework, General (0.6 - 1.3)",
439 " Leif Linse (Zuu) - AI/Game Script (1.2 - 1.6)",
440 "",
441 "Retired Developers:",
442 " Tam\u00e1s Farag\u00f3 (Darkvater) - Ex-Lead coder (0.3 - 0.5)",
443 " Dominik Scherer (dominik81) - Lead programmer, GUI expert (0.3 - 0.3)",
444 " Emil Djupfeld (egladil) - MacOSX (0.4.5 - 0.6)",
445 " Simon Sasburg (HackyKid) - Many bugfixes (0.4 - 0.4.5)",
446 " Ludvig Strigeus (ludde) - Original author of OpenTTD, main coder (0.1 - 0.3)",
447 " Cian Duffy (MYOB) - BeOS port / manual writing (0.1 - 0.3)",
448 " Petr Baudi\u0161 (pasky) - Many patches, NewGRF support (0.3 - 0.3)",
449 " Benedikt Br\u00fcggemeier (skidd13) - Bug fixer and code reworker (0.6 - 0.7)",
450 " Serge Paquet (vurlix) - 2nd contributor after ludde (0.1 - 0.3)",
451 "",
452 "Special thanks go out to:",
453 " Josef Drexler - For his great work on TTDPatch",
454 " Marcin Grzegorczyk - Track foundations and for describing TTD internals",
455 " Stefan Mei\u00dfner (sign_de) - For his work on the console",
456 " Mike Ragsdale - OpenTTD installer",
457 " Christian Rosentreter (tokai) - MorphOS / AmigaOS port",
458 " Richard Kempton (richK) - additional airports, initial TGP implementation",
459 " Alberto Demichelis - Squirrel scripting language \u00a9 2003-2008",
460 " L. Peter Deutsch - MD5 implementation \u00a9 1999, 2000, 2002",
461 " Michael Blunck - Pre-signals and semaphores \u00a9 2003",
462 " George - Canal/Lock graphics \u00a9 2003-2004",
463 " Andrew Parkhouse (andythenorth) - River graphics",
464 " David Dallaston (Pikka) - Tram tracks",
465 " All Translators - Who made OpenTTD a truly international game",
466 " Bug Reporters - Without whom OpenTTD would still be full of bugs!",
467 "",
468 "",
469 "And last but not least:",
470 " Chris Sawyer - For an amazing game!"
471 };
472
473 struct AboutWindow : public Window {
474 int text_position;
475 int line_height;
476 static const int num_visible_lines = 19;
477
478 AboutWindow() : Window(&_about_desc)
479 {
480 this->InitNested(WN_GAME_OPTIONS_ABOUT);
481
482 this->text_position = this->GetWidget<NWidgetBase>(WID_A_SCROLLING_TEXT)->pos_y + this->GetWidget<NWidgetBase>(WID_A_SCROLLING_TEXT)->current_y;
483 }
484
485 void SetStringParameters(WidgetID widget) const override
486 {
487 if (widget == WID_A_WEBSITE) SetDParamStr(0, "Website: https://www.openttd.org");
488 if (widget == WID_A_COPYRIGHT) SetDParamStr(0, _openttd_revision_year);
489 }
490
491 void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override
492 {
493 if (widget != WID_A_SCROLLING_TEXT) return;
494
495 this->line_height = GetCharacterHeight(FS_NORMAL);
496
497 Dimension d;
498 d.height = this->line_height * num_visible_lines;
499
500 d.width = 0;
501 for (uint i = 0; i < lengthof(_credits); i++) {
502 d.width = std::max(d.width, GetStringBoundingBox(_credits[i]).width);
503 }
504 *size = maxdim(*size, d);
505 }
506
507 void DrawWidget(const Rect &r, WidgetID widget) const override
508 {
509 if (widget != WID_A_SCROLLING_TEXT) return;
510
511 int y = this->text_position;
512
513 /* Show all scrolling _credits */
514 for (uint i = 0; i < lengthof(_credits); i++) {
515 if (y >= r.top + 7 && y < r.bottom - this->line_height) {
516 DrawString(r.left, r.right, y, _credits[i], TC_BLACK, SA_LEFT | SA_FORCE);
517 }
518 y += this->line_height;
519 }
520 }
521
527 IntervalTimer<TimerWindow> scroll_interval = {std::chrono::milliseconds(2100) / GetCharacterHeight(FS_NORMAL), [this](uint count) {
528 this->text_position -= count;
529 /* If the last text has scrolled start a new from the start */
530 if (this->text_position < (int)(this->GetWidget<NWidgetBase>(WID_A_SCROLLING_TEXT)->pos_y - lengthof(_credits) * this->line_height)) {
531 this->text_position = this->GetWidget<NWidgetBase>(WID_A_SCROLLING_TEXT)->pos_y + this->GetWidget<NWidgetBase>(WID_A_SCROLLING_TEXT)->current_y;
532 }
533 this->SetWidgetDirty(WID_A_SCROLLING_TEXT);
534 }};
535 };
536
537 void ShowAboutWindow()
538 {
539 CloseWindowByClass(WC_GAME_OPTIONS);
540 new AboutWindow();
541 }
542
549 void ShowEstimatedCostOrIncome(Money cost, int x, int y)
550 {
551 StringID msg = STR_MESSAGE_ESTIMATED_COST;
552
553 if (cost < 0) {
554 cost = -cost;
555 msg = STR_MESSAGE_ESTIMATED_INCOME;
556 }
557 SetDParam(0, cost);
558 ShowErrorMessage(msg, INVALID_STRING_ID, WL_INFO, x, y);
559 }
560
568 void ShowCostOrIncomeAnimation(int x, int y, int z, Money cost)
569 {
570 if (cost == 0) {
571 return;
572 }
573 Point pt = RemapCoords(x, y, z);
574 StringID msg = STR_INCOME_FLOAT_COST;
575
576 if (cost < 0) {
577 cost = -cost;
578 msg = STR_INCOME_FLOAT_INCOME;
579 }
580 SetDParam(0, cost);
581 AddTextEffect(msg, pt.x, pt.y, Ticks::DAY_TICKS, TE_RISING);
582 }
583
592 void ShowFeederIncomeAnimation(int x, int y, int z, Money transfer, Money income)
593 {
594 Point pt = RemapCoords(x, y, z);
595
596 SetDParam(0, transfer);
597 if (income == 0) {
598 AddTextEffect(STR_FEEDER, pt.x, pt.y, Ticks::DAY_TICKS, TE_RISING);
599 } else {
600 StringID msg = STR_FEEDER_COST;
601 if (income < 0) {
602 income = -income;
603 msg = STR_FEEDER_INCOME;
604 }
605 SetDParam(1, income);
606 AddTextEffect(msg, pt.x, pt.y, Ticks::DAY_TICKS, TE_RISING);
607 }
608 }
609
619 TextEffectID ShowFillingPercent(int x, int y, int z, uint8_t percent, StringID string)
620 {
621 Point pt = RemapCoords(x, y, z);
622
623 assert(string != STR_NULL);
624
625 SetDParam(0, percent);
626 return AddTextEffect(string, pt.x, pt.y, 0, TE_STATIC);
627 }
628
634 void UpdateFillingPercent(TextEffectID te_id, uint8_t percent, StringID string)
635 {
636 assert(string != STR_NULL);
637
638 SetDParam(0, percent);
639 UpdateTextEffect(te_id, string);
640 }
641
646 void HideFillingPercent(TextEffectID *te_id)
647 {
648 if (*te_id == INVALID_TE_ID) return;
649
650 RemoveTextEffect(*te_id);
651 *te_id = INVALID_TE_ID;
652 }
653
654 static constexpr NWidgetPart _nested_tooltips_widgets[] = {
655 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_TT_BACKGROUND),
656 };
657
658 static WindowDesc _tool_tips_desc(__FILE__, __LINE__,
659 WDP_MANUAL, nullptr, 0, 0, // Coordinates and sizes are not used,
660 WC_TOOLTIPS, WC_NONE,
661 WDF_NO_FOCUS | WDF_NO_CLOSE,
662 std::begin(_nested_tooltips_widgets), std::end(_nested_tooltips_widgets)
663 );
664
666 struct TooltipsWindow : public Window
667 {
668 StringID string_id;
669 std::vector<StringParameterBackup> params;
670 TooltipCloseCondition close_cond;
671
672 TooltipsWindow(Window *parent, StringID str, uint paramcount, TooltipCloseCondition close_tooltip) : Window(&_tool_tips_desc)
673 {
674 this->parent = parent;
675 this->string_id = str;
676 CopyOutDParam(this->params, paramcount);
677 this->close_cond = close_tooltip;
678
679 this->InitNested();
680
681 CLRBITS(this->flags, WF_WHITE_BORDER);
682 }
683
684 Point OnInitialPosition([[maybe_unused]] int16_t sm_width, [[maybe_unused]] int16_t sm_height, [[maybe_unused]] int window_number) override
685 {
686 /* Find the free screen space between the main toolbar at the top, and the statusbar at the bottom.
687 * Add a fixed distance 2 so the tooltip floats free from both bars.
688 */
689 int scr_top = GetMainViewTop() + 2;
690 int scr_bot = GetMainViewBottom() - 2;
691
692 Point pt;
693
694 /* Correctly position the tooltip position, watch out for window and cursor size
695 * Clamp value to below main toolbar and above statusbar. If tooltip would
696 * go below window, flip it so it is shown above the cursor */
697 pt.y = SoftClamp(_cursor.pos.y + _cursor.total_size.y + _cursor.total_offs.y + 5, scr_top, scr_bot);
698 if (pt.y + sm_height > scr_bot) pt.y = std::min(_cursor.pos.y + _cursor.total_offs.y - 5, scr_bot) - sm_height;
699 pt.x = sm_width >= _screen.width ? 0 : SoftClamp(_cursor.pos.x - (sm_width >> 1), 0, _screen.width - sm_width);
700
701 return pt;
702 }
703
704 void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override
705 {
706 if (widget != WID_TT_BACKGROUND) return;
707 CopyInDParam(this->params);
708
709 size->width = std::min<uint>(GetStringBoundingBox(this->string_id).width, ScaleGUITrad(194));
710 size->height = GetStringHeight(this->string_id, size->width);
711
712 /* Increase slightly to have some space around the box. */
713 size->width += WidgetDimensions::scaled.framerect.Horizontal() + WidgetDimensions::scaled.fullbevel.Horizontal();
714 size->height += WidgetDimensions::scaled.framerect.Vertical() + WidgetDimensions::scaled.fullbevel.Vertical();
715 }
716
717 void DrawWidget(const Rect &r, WidgetID widget) const override
718 {
719 if (widget != WID_TT_BACKGROUND) return;
720 GfxFillRect(r, PC_BLACK);
721 GfxFillRect(r.Shrink(WidgetDimensions::scaled.bevel), PC_LIGHT_YELLOW);
722
723 CopyInDParam(this->params);
724 DrawStringMultiLine(r.Shrink(WidgetDimensions::scaled.framerect).Shrink(WidgetDimensions::scaled.fullbevel), this->string_id, TC_BLACK, SA_CENTER);
725 }
726
727 void OnMouseLoop() override
728 {
729 /* Always close tooltips when the cursor is not in our window. */
730 if (!_cursor.in_window) {
731 this->Close();
732 return;
733 }
734
735 /* We can show tooltips while dragging tools. These are shown as long as
736 * we are dragging the tool. Normal tooltips work with hover or rmb. */
737 switch (this->close_cond) {
738 case TCC_RIGHT_CLICK: if (!_right_button_down) this->Close(); break;
739 case TCC_HOVER: if (!_mouse_hovering) this->Close(); break;
740 case TCC_NONE: break;
741
742 case TCC_EXIT_VIEWPORT: {
743 Window *w = FindWindowFromPt(_cursor.pos.x, _cursor.pos.y);
744 if (w == nullptr || IsPtInWindowViewport(w, _cursor.pos.x, _cursor.pos.y) == nullptr) this->Close();
745 break;
746 }
747 }
748 }
749 };
750
758 void GuiShowTooltips(Window *parent, StringID str, TooltipCloseCondition close_tooltip, uint paramcount)
759 {
760 CloseWindowById(WC_TOOLTIPS, 0);
761
762 if (str == STR_NULL || !_cursor.in_window) return;
763
764 new TooltipsWindow(parent, str, paramcount, close_tooltip);
765 }
766
767 void QueryString::HandleEditBox(Window *w, WidgetID wid)
768 {
769 if (w->IsWidgetGloballyFocused(wid) && this->text.HandleCaret()) {
770 w->SetWidgetDirty(wid);
771
772 /* For the OSK also invalidate the parent window */
773 if (w->window_class == WC_OSK) w->InvalidateData();
774 }
775 }
776
777 static int GetCaretWidth()
778 {
779 return GetCharacterWidth(FS_NORMAL, '_');
780 }
781
782 void QueryString::DrawEditBox(const Window *w, WidgetID wid) const
783 {
784 const NWidgetLeaf *wi = w->GetWidget<NWidgetLeaf>(wid);
785
786 assert((wi->type & WWT_MASK) == WWT_EDITBOX);
787
788 bool rtl = _current_text_dir == TD_RTL;
789 Dimension sprite_size = GetScaledSpriteSize(rtl ? SPR_IMG_DELETE_RIGHT : SPR_IMG_DELETE_LEFT);
790 int clearbtn_width = sprite_size.width + WidgetDimensions::scaled.imgbtn.Horizontal();
791
792 Rect r = wi->GetCurrentRect();
793 Rect cr = r.WithWidth(clearbtn_width, !rtl);
794 Rect fr = r.Indent(clearbtn_width, !rtl);
795
796 DrawFrameRect(cr, wi->colour, wi->IsLowered() ? FR_LOWERED : FR_NONE);
797 DrawSpriteIgnorePadding(rtl ? SPR_IMG_DELETE_RIGHT : SPR_IMG_DELETE_LEFT, PAL_NONE, cr, SA_CENTER);
798 if (this->text.bytes == 1) GfxFillRect(cr.Shrink(WidgetDimensions::scaled.bevel), _colour_gradient[wi->colour & 0xF][2], FILLRECT_CHECKER);
799
800 DrawFrameRect(fr, wi->colour, FR_LOWERED | FR_DARKENED);
801 GfxFillRect(fr.Shrink(WidgetDimensions::scaled.bevel), PC_BLACK);
802
803 fr = fr.Shrink(WidgetDimensions::scaled.framerect);
804 /* Limit the drawing of the string inside the widget boundaries */
805 DrawPixelInfo dpi;
806 if (!FillDrawPixelInfo(&dpi, fr)) return;
807
808 AutoRestoreBackup dpi_backup(_cur_dpi, &dpi);
809
810 /* We will take the current widget length as maximum width, with a small
811 * space reserved at the end for the caret to show */
812 const Textbuf *tb = &this->text;
813 int delta = std::min(0, (fr.right - fr.left) - tb->pixels - GetCaretWidth());
814
815 if (tb->caretxoffs + delta < 0) delta = -tb->caretxoffs;
816
817 /* If we have a marked area, draw a background highlight. */
818 if (tb->marklength != 0) GfxFillRect(delta + tb->markxoffs, 0, delta + tb->markxoffs + tb->marklength - 1, fr.bottom - fr.top, PC_GREY);
819
820 DrawString(delta, tb->pixels, 0, tb->buf, TC_YELLOW);
821 bool focussed = w->IsWidgetGloballyFocused(wid) || IsOSKOpenedFor(w, wid);
822 if (focussed && tb->caret) {
823 int caret_width = GetStringBoundingBox("_").width;
824 DrawString(tb->caretxoffs + delta, tb->caretxoffs + delta + caret_width, 0, "_", TC_WHITE);
825 }
826 }
827
834 Point QueryString::GetCaretPosition(const Window *w, WidgetID wid) const
835 {
836 const NWidgetLeaf *wi = w->GetWidget<NWidgetLeaf>(wid);
837
838 assert((wi->type & WWT_MASK) == WWT_EDITBOX);
839
840 bool rtl = _current_text_dir == TD_RTL;
841 Dimension sprite_size = GetScaledSpriteSize(rtl ? SPR_IMG_DELETE_RIGHT : SPR_IMG_DELETE_LEFT);
842 int clearbtn_width = sprite_size.width + WidgetDimensions::scaled.imgbtn.Horizontal();
843
844 Rect r = wi->GetCurrentRect().Indent(clearbtn_width, !rtl).Shrink(WidgetDimensions::scaled.framerect);
845
846 /* Clamp caret position to be inside out current width. */
847 const Textbuf *tb = &this->text;
848 int delta = std::min(0, (r.right - r.left) - tb->pixels - GetCaretWidth());
849 if (tb->caretxoffs + delta < 0) delta = -tb->caretxoffs;
850
851 Point pt = {r.left + tb->caretxoffs + delta, r.top};
852 return pt;
853 }
854
863 Rect QueryString::GetBoundingRect(const Window *w, WidgetID wid, const char *from, const char *to) const
864 {
865 const NWidgetLeaf *wi = w->GetWidget<NWidgetLeaf>(wid);
866
867 assert((wi->type & WWT_MASK) == WWT_EDITBOX);
868
869 bool rtl = _current_text_dir == TD_RTL;
870 Dimension sprite_size = GetScaledSpriteSize(rtl ? SPR_IMG_DELETE_RIGHT : SPR_IMG_DELETE_LEFT);
871 int clearbtn_width = sprite_size.width + WidgetDimensions::scaled.imgbtn.Horizontal();
872
873 Rect r = wi->GetCurrentRect().Indent(clearbtn_width, !rtl).Shrink(WidgetDimensions::scaled.framerect);
874
875 /* Clamp caret position to be inside our current width. */
876 const Textbuf *tb = &this->text;
877 int delta = std::min(0, r.Width() - tb->pixels - GetCaretWidth());
878 if (tb->caretxoffs + delta < 0) delta = -tb->caretxoffs;
879
880 /* Get location of first and last character. */
881 Point p1 = GetCharPosInString(tb->buf, from, FS_NORMAL);
882 Point p2 = from != to ? GetCharPosInString(tb->buf, to, FS_NORMAL) : p1;
883
884 return { Clamp(r.left + p1.x + delta, r.left, r.right), r.top, Clamp(r.left + p2.x + delta, r.left, r.right), r.bottom };
885 }
886
894 ptrdiff_t QueryString::GetCharAtPosition(const Window *w, WidgetID wid, const Point &pt) const
895 {
896 const NWidgetLeaf *wi = w->GetWidget<NWidgetLeaf>(wid);
897
898 assert((wi->type & WWT_MASK) == WWT_EDITBOX);
899
900 bool rtl = _current_text_dir == TD_RTL;
901 Dimension sprite_size = GetScaledSpriteSize(rtl ? SPR_IMG_DELETE_RIGHT : SPR_IMG_DELETE_LEFT);
902 int clearbtn_width = sprite_size.width + WidgetDimensions::scaled.imgbtn.Horizontal();
903
904 Rect r = wi->GetCurrentRect().Indent(clearbtn_width, !rtl).Shrink(WidgetDimensions::scaled.framerect);
905
906 if (!IsInsideMM(pt.y, r.top, r.bottom)) return -1;
907
908 /* Clamp caret position to be inside our current width. */
909 const Textbuf *tb = &this->text;
910 int delta = std::min(0, r.Width() - tb->pixels - GetCaretWidth());
911 if (tb->caretxoffs + delta < 0) delta = -tb->caretxoffs;
912
913 return ::GetCharAtPosition(tb->buf, pt.x - delta - r.left);
914 }
915
916 void QueryString::ClickEditBox(Window *w, Point pt, WidgetID wid, int click_count, bool focus_changed)
917 {
918 const NWidgetLeaf *wi = w->GetWidget<NWidgetLeaf>(wid);
919
920 assert((wi->type & WWT_MASK) == WWT_EDITBOX);
921
922 bool rtl = _current_text_dir == TD_RTL;
923 Dimension sprite_size = GetScaledSpriteSize(rtl ? SPR_IMG_DELETE_RIGHT : SPR_IMG_DELETE_LEFT);
924 int clearbtn_width = sprite_size.width + WidgetDimensions::scaled.imgbtn.Horizontal();
925
926 Rect cr = wi->GetCurrentRect().WithWidth(clearbtn_width, !rtl);
927
928 if (IsInsideMM(pt.x, cr.left, cr.right)) {
929 if (this->text.bytes > 1) {
930 this->text.DeleteAll();
931 w->HandleButtonClick(wid);
932 w->OnEditboxChanged(wid);
933 }
934 return;
935 }
936
937 if (w->window_class != WC_OSK && _settings_client.gui.osk_activation != OSKA_DISABLED &&
938 (!focus_changed || _settings_client.gui.osk_activation == OSKA_IMMEDIATELY) &&
939 (click_count == 2 || _settings_client.gui.osk_activation != OSKA_DOUBLE_CLICK)) {
940 /* Open the OSK window */
941 ShowOnScreenKeyboard(w, wid);
942 }
943 }
944
946 struct QueryStringWindow : public Window
947 {
948 QueryString editbox;
949 QueryStringFlags flags;
950 Dimension warning_size;
951
952 QueryStringWindow(StringID str, StringID caption, uint max_bytes, uint max_chars, WindowDesc *desc, Window *parent, CharSetFilter afilter, QueryStringFlags flags) :
953 Window(desc), editbox(max_bytes, max_chars)
954 {
955 this->editbox.text.Assign(str);
956
957 if ((flags & QSF_ACCEPT_UNCHANGED) == 0) this->editbox.orig = this->editbox.text.buf;
958
959 this->querystrings[WID_QS_TEXT] = &this->editbox;
960 this->editbox.caption = caption;
961 this->editbox.cancel_button = WID_QS_CANCEL;
962 this->editbox.ok_button = WID_QS_OK;
963 this->editbox.text.afilter = afilter;
964 this->flags = flags;
965
966 this->InitNested(WN_QUERY_STRING);
967 this->UpdateWarningStringSize();
968
969 this->parent = parent;
970
971 this->SetFocusedWidget(WID_QS_TEXT);
972 }
973
974 void UpdateWarningStringSize()
975 {
976 if (this->flags & QSF_PASSWORD) {
977 assert(this->nested_root->smallest_x > 0);
978 this->warning_size.width = this->nested_root->current_x - WidgetDimensions::scaled.frametext.Horizontal() - WidgetDimensions::scaled.framerect.Horizontal();
979 this->warning_size.height = GetStringHeight(STR_WARNING_PASSWORD_SECURITY, this->warning_size.width);
980 this->warning_size.height += WidgetDimensions::scaled.frametext.Vertical() + WidgetDimensions::scaled.framerect.Vertical();
981 } else {
982 this->warning_size = Dimension{ 0, 0 };
983 }
984
985 this->ReInit();
986 }
987
988 void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override
989 {
990 if (widget == WID_QS_DEFAULT && (this->flags & QSF_ENABLE_DEFAULT) == 0) {
991 /* We don't want this widget to show! */
992 fill->width = 0;
993 resize->width = 0;
994 size->width = 0;
995 }
996
997 if (widget == WID_QS_WARNING) {
998 *size = this->warning_size;
999 }
1000 }
1001
1002 void DrawWidget(const Rect &r, WidgetID widget) const override
1003 {
1004 if (widget != WID_QS_WARNING) return;
1005
1006 if (this->flags & QSF_PASSWORD) {
1007 DrawStringMultiLine(r.Shrink(WidgetDimensions::scaled.framerect).Shrink(WidgetDimensions::scaled.frametext),
1008 STR_WARNING_PASSWORD_SECURITY, TC_FROMSTRING, SA_CENTER);
1009 }
1010 }
1011
1012 void SetStringParameters(WidgetID widget) const override
1013 {
1014 if (widget == WID_QS_CAPTION) SetDParam(0, this->editbox.caption);
1015 }
1016
1017 void OnOk()
1018 {
1019 if (!this->editbox.orig.has_value() || this->editbox.text.buf != this->editbox.orig) {
1020 assert(this->parent != nullptr);
1021
1022 this->parent->OnQueryTextFinished(this->editbox.text.buf);
1023 this->editbox.handled = true;
1024 }
1025 }
1026
1027 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
1028 {
1029 switch (widget) {
1030 case WID_QS_DEFAULT:
1031 this->editbox.text.DeleteAll();
1032 [[fallthrough]];
1033
1034 case WID_QS_OK:
1035 this->OnOk();
1036 [[fallthrough]];
1037
1038 case WID_QS_CANCEL:
1039 this->Close();
1040 break;
1041 }
1042 }
1043
1044 void Close([[maybe_unused]] int data = 0) override
1045 {
1046 if (!this->editbox.handled && this->parent != nullptr) {
1047 Window *parent = this->parent;
1048 this->parent = nullptr; // so parent doesn't try to close us again
1049 parent->OnQueryTextFinished(nullptr);
1050 }
1051 this->Window::Close();
1052 }
1053 };
1054
1055 static constexpr NWidgetPart _nested_query_string_widgets[] = {
1056 NWidget(NWID_HORIZONTAL),
1057 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
1058 NWidget(WWT_CAPTION, COLOUR_GREY, WID_QS_CAPTION), SetDataTip(STR_JUST_STRING, STR_NULL), SetTextStyle(TC_WHITE),
1059 EndContainer(),
1060 NWidget(WWT_PANEL, COLOUR_GREY),
1061 NWidget(WWT_EDITBOX, COLOUR_GREY, WID_QS_TEXT), SetMinimalSize(256, 12), SetFill(1, 1), SetPadding(2, 2, 2, 2),
1062 EndContainer(),
1063 NWidget(WWT_PANEL, COLOUR_GREY, WID_QS_WARNING), EndContainer(),
1064 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
1065 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_QS_DEFAULT), SetMinimalSize(87, 12), SetFill(1, 1), SetDataTip(STR_BUTTON_DEFAULT, STR_NULL),
1066 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_QS_CANCEL), SetMinimalSize(86, 12), SetFill(1, 1), SetDataTip(STR_BUTTON_CANCEL, STR_NULL),
1067 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_QS_OK), SetMinimalSize(87, 12), SetFill(1, 1), SetDataTip(STR_BUTTON_OK, STR_NULL),
1068 EndContainer(),
1069 };
1070
1071 static WindowDesc _query_string_desc(__FILE__, __LINE__,
1072 WDP_CENTER, nullptr, 0, 0,
1073 WC_QUERY_STRING, WC_NONE,
1074 0,
1075 std::begin(_nested_query_string_widgets), std::end(_nested_query_string_widgets)
1076 );
1077
1087 void ShowQueryString(StringID str, StringID caption, uint maxsize, Window *parent, CharSetFilter afilter, QueryStringFlags flags)
1088 {
1089 assert(parent != nullptr);
1090
1091 CloseWindowByClass(WC_QUERY_STRING);
1092 new QueryStringWindow(str, caption, ((flags & QSF_LEN_IN_CHARS) ? MAX_CHAR_LENGTH : 1) * maxsize, maxsize, &_query_string_desc, parent, afilter, flags);
1093 }
1094
1098 struct QueryWindow : public Window {
1099 QueryCallbackProc *proc;
1100 std::vector<StringParameterBackup> params;
1101 StringID message;
1102
1103 QueryWindow(WindowDesc *desc, StringID caption, StringID message, Window *parent, QueryCallbackProc *callback) : Window(desc)
1104 {
1105 /* Create a backup of the variadic arguments to strings because it will be
1106 * overridden pretty often. We will copy these back for drawing */
1107 CopyOutDParam(this->params, 10);
1108 this->message = message;
1109 this->proc = callback;
1110 this->parent = parent;
1111
1112 this->CreateNestedTree();
1113 this->GetWidget<NWidgetCore>(WID_Q_CAPTION)->SetDataTip(caption, STR_NULL);
1114 this->FinishInitNested(WN_CONFIRM_POPUP_QUERY);
1115 }
1116
1117 void Close([[maybe_unused]] int data = 0) override
1118 {
1119 if (this->proc != nullptr) this->proc(this->parent, false);
1120 this->Window::Close();
1121 }
1122
1123 void FindWindowPlacementAndResize([[maybe_unused]] int def_width, [[maybe_unused]] int def_height) override
1124 {
1125 /* Position query window over the calling window, ensuring it's within screen bounds. */
1126 this->left = SoftClamp(parent->left + (parent->width / 2) - (this->width / 2), 0, _screen.width - this->width);
1127 this->top = SoftClamp(parent->top + (parent->height / 2) - (this->height / 2), 0, _screen.height - this->height);
1128 this->SetDirty();
1129 }
1130
1131 void SetStringParameters(WidgetID widget) const override
1132 {
1133 switch (widget) {
1134 case WID_Q_CAPTION:
1135 case WID_Q_TEXT:
1136 CopyInDParam(this->params);
1137 break;
1138 }
1139 }
1140
1141 void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override
1142 {
1143 if (widget != WID_Q_TEXT) return;
1144
1145 *size = GetStringMultiLineBoundingBox(this->message, *size);
1146 }
1147
1148 void DrawWidget(const Rect &r, WidgetID widget) const override
1149 {
1150 if (widget != WID_Q_TEXT) return;
1151
1152 DrawStringMultiLine(r, this->message, TC_FROMSTRING, SA_CENTER);
1153 }
1154
1155 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
1156 {
1157 switch (widget) {
1158 case WID_Q_YES: {
1159 /* in the Generate New World window, clicking 'Yes' causes
1160 * CloseNonVitalWindows() to be called - we shouldn't be in a window then */
1161 QueryCallbackProc *proc = this->proc;
1162 Window *parent = this->parent;
1163 /* Prevent the destructor calling the callback function */
1164 this->proc = nullptr;
1165 this->Close();
1166 if (proc != nullptr) {
1167 proc(parent, true);
1168 proc = nullptr;
1169 }
1170 break;
1171 }
1172 case WID_Q_NO:
1173 this->Close();
1174 break;
1175 }
1176 }
1177
1178 EventState OnKeyPress([[maybe_unused]] char32_t key, uint16_t keycode) override
1179 {
1180 /* ESC closes the window, Enter confirms the action */
1181 switch (keycode) {
1182 case WKC_RETURN:
1183 case WKC_NUM_ENTER:
1184 if (this->proc != nullptr) {
1185 this->proc(this->parent, true);
1186 this->proc = nullptr;
1187 }
1188 [[fallthrough]];
1189
1190 case WKC_ESC:
1191 this->Close();
1192 return ES_HANDLED;
1193 }
1194 return ES_NOT_HANDLED;
1195 }
1196 };
1197
1198 static constexpr NWidgetPart _nested_query_widgets[] = {
1199 NWidget(NWID_HORIZONTAL),
1200 NWidget(WWT_CLOSEBOX, COLOUR_RED),
1201 NWidget(WWT_CAPTION, COLOUR_RED, WID_Q_CAPTION), // The caption's string is set in the constructor
1202 EndContainer(),
1203 NWidget(WWT_PANEL, COLOUR_RED),
1204 NWidget(NWID_VERTICAL), SetPIP(0, WidgetDimensions::unscaled.vsep_wide, 0), SetPadding(WidgetDimensions::unscaled.modalpopup),
1205 NWidget(WWT_TEXT, COLOUR_RED, WID_Q_TEXT), SetMinimalSize(200, 12),
1206 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(WidgetDimensions::unscaled.hsep_indent, WidgetDimensions::unscaled.hsep_indent, WidgetDimensions::unscaled.hsep_indent),
1207 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_Q_NO), SetMinimalSize(71, 12), SetFill(1, 1), SetDataTip(STR_QUIT_NO, STR_NULL),
1208 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_Q_YES), SetMinimalSize(71, 12), SetFill(1, 1), SetDataTip(STR_QUIT_YES, STR_NULL),
1209 EndContainer(),
1210 EndContainer(),
1211 EndContainer(),
1212 };
1213
1214 static WindowDesc _query_desc(__FILE__, __LINE__,
1215 WDP_CENTER, nullptr, 0, 0,
1216 WC_CONFIRM_POPUP_QUERY, WC_NONE,
1217 WDF_MODAL,
1218 std::begin(_nested_query_widgets), std::end(_nested_query_widgets)
1219 );
1220
1231 void ShowQuery(StringID caption, StringID message, Window *parent, QueryCallbackProc *callback, bool focus)
1232 {
1233 if (parent == nullptr) parent = GetMainWindow();
1234
1235 for (Window *w : Window::Iterate()) {
1236 if (w->window_class != WC_CONFIRM_POPUP_QUERY) continue;
1237
1238 QueryWindow *qw = dynamic_cast<QueryWindow *>(w);
1239 if (qw->parent != parent || qw->proc != callback) continue;
1240
1241 qw->Close();
1242 break;
1243 }
1244
1245 QueryWindow *q = new QueryWindow(&_query_desc, caption, message, parent, callback);
1246 if (focus) SetFocusedWindow(q);
1247 }
ES_HANDLED
@ ES_HANDLED
The passed event is handled.
Definition: window_type.h:739
TileY
static debug_inline uint TileY(TileIndex tile)
Get the Y component of a tile.
Definition: map_func.h:437
TileDesc::airport_class
StringID airport_class
Name of the airport class.
Definition: tile_cmd.h:60
SetFill
constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
Widget part function for setting filling.
Definition: widget_type.h:1143
TileDesc::grf
const char * grf
newGRF used for the tile contents
Definition: tile_cmd.h:63
CloseWindowByClass
void CloseWindowByClass(WindowClass cls, int data)
Close all windows of a given class.
Definition: window.cpp:1153
FindWindowFromPt
Window * FindWindowFromPt(int x, int y)
Do a search for a window at specific coordinates.
Definition: window.cpp:1769
CopyInDParam
void CopyInDParam(const std::span< const StringParameterBackup > backup)
Copy the parameters from the backup into the global string parameter array.
Definition: strings.cpp:159
WidgetDimensions::imgbtn
RectPadding imgbtn
Padding around image button image.
Definition: window_gui.h:36
ScrollMainWindowToTile
bool ScrollMainWindowToTile(TileIndex tile, bool instant)
Scrolls the viewport of the main window to a given location.
Definition: viewport.cpp:2509
QueryString::ok_button
int ok_button
Widget button of parent window to simulate when pressing OK in OSK.
Definition: querystring_gui.h:27
querystring_gui.h
ShowExtraViewportWindow
void ShowExtraViewportWindow(TileIndex tile=INVALID_TILE)
Show a new Extra Viewport window.
Definition: viewport_gui.cpp:156
ShowQuery
void ShowQuery(StringID caption, StringID message, Window *parent, QueryCallbackProc *callback, bool focus)
Show a confirmation window with standard 'yes' and 'no' buttons The window is aligned to the centre o...
Definition: misc_gui.cpp:1231
SetFocusedWindow
void SetFocusedWindow(Window *w)
Set the window that has the focus.
Definition: window.cpp:423
QSF_PASSWORD
@ QSF_PASSWORD
password entry box, show warning about password security
Definition: textbuf_gui.h:23
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition: geometry_type.hpp:30
command_func.h
IsInsideMM
constexpr bool IsInsideMM(const T x, const size_t min, const size_t max) noexcept
Checks if a value is in an interval.
Definition: math_func.hpp:268
WidgetDimensions::scaled
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition: window_gui.h:68
WID_A_WEBSITE
@ WID_A_WEBSITE
URL of OpenTTD website.
Definition: misc_widget.h:27
ShowErrorMessage
void ShowErrorMessage(StringID summary_msg, int x, int y, CommandCost cc)
Display an error message in a window.
Definition: error_gui.cpp:367
Pool::PoolItem<&_company_pool >::GetIfValid
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:350
WC_LAND_INFO
@ WC_LAND_INFO
Land info window; Window numbers:
Definition: window_type.h:150
QSF_ACCEPT_UNCHANGED
@ QSF_ACCEPT_UNCHANGED
return success even when the text didn't change
Definition: textbuf_gui.h:20
Rect::Shrink
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Definition: geometry_type.hpp:98
ClosestTownFromTile
Town * ClosestTownFromTile(TileIndex tile, uint threshold)
Return the town closest (in distance or ownership) to a given tile, within a given threshold.
Definition: town_cmd.cpp:3783
UpdateFillingPercent
void UpdateFillingPercent(TextEffectID te_id, uint8_t percent, StringID string)
Update vehicle loading indicators.
Definition: misc_gui.cpp:634
TileDesc::railtype
StringID railtype
Type of rail on the tile.
Definition: tile_cmd.h:64
_sorted_cargo_specs
std::vector< const CargoSpec * > _sorted_cargo_specs
Cargo specifications sorted alphabetically by name.
Definition: cargotype.cpp:168
company_base.h
TileDesc::owner
Owner owner[4]
Name of the owner(s)
Definition: tile_cmd.h:55
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:63
Window::SetWidgetDirty
void SetWidgetDirty(WidgetID widget_index) const
Invalidate a widget, i.e.
Definition: window.cpp:552
WID_Q_NO
@ WID_Q_NO
Yes button.
Definition: misc_widget.h:45
StringID
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
ShowOnScreenKeyboard
void ShowOnScreenKeyboard(Window *parent, WidgetID button)
Show the on-screen keyboard (osk) associated with a given textbox.
Definition: osk_gui.cpp:393
Textbuf::Assign
void Assign(StringID string)
Render a string into the textbuffer.
Definition: textbuf.cpp:405
TileDesc::station_class
StringID station_class
Class of station.
Definition: tile_cmd.h:58
TileDesc::road_speed
uint16_t road_speed
Speed limit of road (bridges and track)
Definition: tile_cmd.h:67
WWT_LABEL
@ WWT_LABEL
Centered label.
Definition: widget_type.h:59
CloseWindowById
void CloseWindowById(WindowClass cls, WindowNumber number, bool force, int data)
Close a window by its class and window number (if it is open).
Definition: window.cpp:1141
IntervalTimer< TimerWindow >
Pool::PoolItem::index
Tindex index
Index of this pool item.
Definition: pool_type.hpp:238
Textbuf::pixels
uint16_t pixels
the current size of the string in pixels
Definition: textbuf_type.h:37
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition: widget_type.h:77
CargoArray
Class for storing amounts of cargo.
Definition: cargo_type.h:114
WID_Q_TEXT
@ WID_Q_TEXT
Text of the query.
Definition: misc_widget.h:44
OSKA_DISABLED
@ OSKA_DISABLED
The OSK shall not be activated at all.
Definition: misc_gui.cpp:45
maxdim
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
Definition: geometry_func.cpp:22
Window::Close
virtual void Close(int data=0)
Hide the window and all its child windows, and mark them for a later deletion.
Definition: window.cpp:1048
GetTileZ
int GetTileZ(TileIndex tile)
Get bottom height of the tile.
Definition: tile_map.cpp:121
GetCharacterWidth
byte GetCharacterWidth(FontSize size, char32_t key)
Return width of character glyph.
Definition: gfx.cpp:1246
EndContainer
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition: widget_type.h:1153
HideFillingPercent
void HideFillingPercent(TextEffectID *te_id)
Hide vehicle loading indicators.
Definition: misc_gui.cpp:646
WDF_NO_FOCUS
@ WDF_NO_FOCUS
This window won't get focus/make any other window lose focus when click.
Definition: window_gui.h:199
_ctrl_pressed
bool _ctrl_pressed
Is Ctrl pressed?
Definition: gfx.cpp:37
FILLRECT_CHECKER
@ FILLRECT_CHECKER
Draw only every second pixel, used for greying-out.
Definition: gfx_type.h:294
zoom_func.h
SoftClamp
constexpr T SoftClamp(const T a, const T min, const T max)
Clamp a value between an interval.
Definition: math_func.hpp:102
Tile
Wrapper class to abstract away the way the tiles are stored.
Definition: map_func.h:25
NWidgetLeaf
Leaf widget.
Definition: widget_type.h:886
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:54
WC_OSK
@ WC_OSK
On Screen Keyboard; Window numbers:
Definition: window_type.h:162
CargoSpec
Specification of a cargo type.
Definition: cargotype.h:68
WWT_EMPTY
@ WWT_EMPTY
Empty widget, place holder to reserve space in widget tree.
Definition: widget_type.h:50
newgrf_debug.h
town.h
RectPadding::Vertical
constexpr uint Vertical() const
Get total vertical padding of RectPadding.
Definition: geometry_type.hpp:69
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > >
TileDesc::airport_tile_name
StringID airport_tile_name
Name of the airport tile.
Definition: tile_cmd.h:62
FR_LOWERED
@ FR_LOWERED
If set the frame is lowered and the background colour brighter (ie. buttons when pressed)
Definition: window_gui.h:28
VEH_ROAD
@ VEH_ROAD
Road vehicle type.
Definition: vehicle_type.h:25
WID_QS_CAPTION
@ WID_QS_CAPTION
Caption of the window.
Definition: misc_widget.h:33
TileDesc
Tile description for the 'land area information' tool.
Definition: tile_cmd.h:52
AboutWindow::text_position
int text_position
The top of the scrolling text.
Definition: misc_gui.cpp:474
TileDesc::airport_name
StringID airport_name
Name of the airport.
Definition: tile_cmd.h:61
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:1040
IsOSKOpenedFor
bool IsOSKOpenedFor(const Window *w, WidgetID button)
Check whether the OSK is opened for a specific editbox.
Definition: osk_gui.cpp:424
QueryString
Data stored about a string that can be modified in the GUI.
Definition: querystring_gui.h:20
QueryStringWindow::flags
QueryStringFlags flags
Flags controlling behaviour of the window.
Definition: misc_gui.cpp:949
Window::OnEditboxChanged
virtual void OnEditboxChanged([[maybe_unused]] WidgetID widget)
The text in an editbox has been edited.
Definition: window_gui.h:765
Debug
#define Debug(category, level, format_string,...)
Ouptut a line of debugging information.
Definition: debug.h:37
CommandCost::Succeeded
bool Succeeded() const
Did this command succeed?
Definition: command_type.h:162
_colour_gradient
byte _colour_gradient[COLOUR_END][8]
All 16 colour gradients 8 colours per gradient from darkest (0) to lightest (7)
Definition: palette.cpp:26
QueryStringWindow::editbox
QueryString editbox
Editbox.
Definition: misc_gui.cpp:948
Textbuf::buf
char *const buf
buffer in which text is saved
Definition: textbuf_type.h:32
TooltipsWindow
Window for displaying a tooltip.
Definition: misc_gui.cpp:666
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
WindowDesc
High level window description.
Definition: window_gui.h:153
WidgetID
int WidgetID
Widget ID.
Definition: window_type.h:18
GetGrfSpecFeature
GrfSpecFeature GetGrfSpecFeature(TileIndex tile)
Get the GrfSpecFeature associated with the tile.
Definition: newgrf_debug_gui.cpp:773
RectPadding::Horizontal
constexpr uint Horizontal() const
Get total horizontal padding of RectPadding.
Definition: geometry_type.hpp:63
ScaleGUITrad
int ScaleGUITrad(int value)
Scale traditional pixel dimensions to GUI zoom level.
Definition: zoom_func.h:117
TileDesc::build_date
TimerGameCalendar::Date build_date
Date of construction of tile contents.
Definition: tile_cmd.h:57
NC_EQUALSIZE
@ NC_EQUALSIZE
Value of the NCB_EQUALSIZE flag.
Definition: widget_type.h:510
SetPadding
constexpr NWidgetPart SetPadding(uint8_t top, uint8_t right, uint8_t bottom, uint8_t left)
Widget part function for setting additional space around a widget.
Definition: widget_type.h:1190
WC_CONFIRM_POPUP_QUERY
@ WC_CONFIRM_POPUP_QUERY
Popup with confirm question; Window numbers:
Definition: window_type.h:130
landscape_cmd.h
WC_QUERY_STRING
@ WC_QUERY_STRING
Query string window; Window numbers:
Definition: window_type.h:123
Textbuf::markxoffs
uint16_t markxoffs
the start position of the marked area in pixels
Definition: textbuf_type.h:43
WDP_AUTO
@ WDP_AUTO
Find a place automatically.
Definition: window_gui.h:141
Window::IsWidgetGloballyFocused
bool IsWidgetGloballyFocused(WidgetID widget_index) const
Check if given widget has user input focus.
Definition: window_gui.h:431
ShowFillingPercent
TextEffectID ShowFillingPercent(int x, int y, int z, uint8_t percent, StringID string)
Display vehicle loading indicators.
Definition: misc_gui.cpp:619
Window::resize
ResizeInfo resize
Resize information.
Definition: window_gui.h:308
CommandCost
Common return value for all commands.
Definition: command_type.h:23
WN_QUERY_STRING
@ WN_QUERY_STRING
Query string.
Definition: window_type.h:29
FS_NORMAL
@ FS_NORMAL
Index of the normal font in the font tables.
Definition: gfx_type.h:203
Window::InitNested
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
Definition: window.cpp:1747
Window::nested_root
std::unique_ptr< NWidgetBase > nested_root
Root of the nested tree.
Definition: window_gui.h:315
WWT_EDITBOX
@ WWT_EDITBOX
a textbox for typing
Definition: widget_type.h:73
NWidgetBase::type
WidgetType type
Type of the widget / nested widget.
Definition: widget_type.h:222
GUISettings::osk_activation
uint8_t osk_activation
Mouse gesture to trigger the OSK.
Definition: settings_type.h:195
Window::HandleButtonClick
void HandleButtonClick(WidgetID widget)
Do all things to make a button look clicked and mark it to be unclicked in a few ticks.
Definition: window.cpp:591
Window::height
int height
Height of the window (number of pixels down in y direction)
Definition: window_gui.h:306
LandInfoWindow
Definition: misc_gui.cpp:69
WF_WHITE_BORDER
@ WF_WHITE_BORDER
Window white border counter bit mask.
Definition: window_gui.h:230
QueryStringFlags
QueryStringFlags
Flags used in ShowQueryString() call.
Definition: textbuf_gui.h:18
Window::SetDirty
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition: window.cpp:941
Textbuf::bytes
uint16_t bytes
the current size of the string in bytes (including terminating '\0')
Definition: textbuf_type.h:35
TileDesc::roadtype
StringID roadtype
Type of road on the tile.
Definition: tile_cmd.h:66
WID_QS_WARNING
@ WID_QS_WARNING
Warning label about password security.
Definition: misc_widget.h:35
WN_CONFIRM_POPUP_QUERY
@ WN_CONFIRM_POPUP_QUERY
Query popup confirm.
Definition: window_type.h:32
WID_QS_TEXT
@ WID_QS_TEXT
Text of the query.
Definition: misc_widget.h:34
ES_NOT_HANDLED
@ ES_NOT_HANDLED
The passed event is not handled.
Definition: window_type.h:740
WWT_PUSHTXTBTN
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
Definition: widget_type.h:110
WID_LI_BACKGROUND
@ WID_LI_BACKGROUND
Background of the window.
Definition: misc_widget.h:16
QueryString::GetCharAtPosition
ptrdiff_t GetCharAtPosition(const Window *w, WidgetID wid, const Point &pt) const
Get the character that is rendered at a position.
Definition: misc_gui.cpp:894
QueryWindow::proc
QueryCallbackProc * proc
callback function executed on closing of popup. Window* points to parent, bool is true if 'yes' click...
Definition: misc_gui.cpp:1099
QueryStringWindow
Class for the string query window.
Definition: misc_gui.cpp:946
water_regions.h
QueryString::GetBoundingRect
Rect GetBoundingRect(const Window *w, WidgetID wid, const char *from, const char *to) const
Get the bounding rectangle for a range of the query string.
Definition: misc_gui.cpp:863
GetMainViewTop
int GetMainViewTop()
Return the top of the main view available for general use.
Definition: window.cpp:2067
_settings_game
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:55
Window::ReInit
void ReInit(int rx=0, int ry=0, bool reposition=false)
Re-initialize a window, and optionally change its size.
Definition: window.cpp:953
SA_FORCE
@ SA_FORCE
Force the alignment, i.e. don't swap for RTL languages.
Definition: gfx_type.h:350
CursorVars::total_size
Point total_size
union of sprite properties
Definition: gfx_type.h:131
GameSettings::economy
EconomySettings economy
settings to change the economy
Definition: settings_type.h:627
Window::parent
Window * parent
Parent window.
Definition: window_gui.h:322
WL_INFO
@ WL_INFO
Used for DoCommand-like (and some non-fatal AI GUI) errors/information.
Definition: error.h:24
NWidget
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1260
_local_company
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:50
StringList
std::vector< std::string > StringList
Type for a list of strings.
Definition: string_type.h:60
safeguards.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:1087
timer.h
Window::left
int left
x position of left edge of the window
Definition: window_gui.h:303
TooltipsWindow::params
std::vector< StringParameterBackup > params
The string parameters.
Definition: misc_gui.cpp:669
lengthof
#define lengthof(array)
Return the length of an fixed size array.
Definition: stdafx.h:303
Window::flags
WindowFlags flags
Window flags.
Definition: window_gui.h:294
CopyOutDParam
void CopyOutDParam(std::vector< StringParameterBackup > &backup, size_t num)
Copy num string parameters from the global string parameter array to the backup.
Definition: strings.cpp:176
Rect::Indent
Rect Indent(int indent, bool end) const
Copy Rect and indent it from its position.
Definition: geometry_type.hpp:198
CommandCost::GetCost
Money GetCost() const
The costs as made up to this moment.
Definition: command_type.h:83
LandInfoWindow::OnInit
void OnInit() override
Notification that the nested widget tree gets initialized.
Definition: misc_gui.cpp:137
Textbuf::caret
bool caret
is the caret ("_") visible or not
Definition: textbuf_type.h:38
GetStringHeight
int GetStringHeight(std::string_view str, int maxw, FontSize fontsize)
Calculates height of string (in pixels).
Definition: gfx.cpp:701
_mouse_hovering
bool _mouse_hovering
The mouse is hovering over the same point.
Definition: window.cpp:91
Rect::WithWidth
Rect WithWidth(int width, bool end) const
Copy Rect and set its width.
Definition: geometry_type.hpp:185
WDF_MODAL
@ WDF_MODAL
The window is a modal child of some other window, meaning the parent is 'inactive'.
Definition: window_gui.h:198
GetStringMultiLineBoundingBox
Dimension GetStringMultiLineBoundingBox(StringID str, const Dimension &suggestion)
Calculate string bounding box for multi-line strings.
Definition: gfx.cpp:737
SetDParamsForOwnedBy
void SetDParamsForOwnedBy(Owner owner, TileIndex tile)
Set the right DParams for STR_ERROR_OWNED_BY.
Definition: company_cmd.cpp:332
TooltipsWindow::OnMouseLoop
void OnMouseLoop() override
Called for every mouse loop run, which is at least once per (game) tick.
Definition: misc_gui.cpp:727
CargoID
byte CargoID
Cargo slots to indicate a cargo type within a game.
Definition: cargo_type.h:22
Point
Coordinates of a point in 2D.
Definition: geometry_type.hpp:21
Textbuf::afilter
CharSetFilter afilter
Allowed characters.
Definition: textbuf_type.h:31
TileDesc::station_name
StringID station_name
Type of station within the class.
Definition: tile_cmd.h:59
error.h
NWidgetCore::IsLowered
bool IsLowered() const
Return whether the widget is lowered.
Definition: widget_type.h:420
WDF_NO_CLOSE
@ WDF_NO_CLOSE
This window can't be interactively closed.
Definition: window_gui.h:200
WWT_FRAME
@ WWT_FRAME
Frame.
Definition: widget_type.h:62
stdafx.h
QueryString::GetCaretPosition
Point GetCaretPosition(const Window *w, WidgetID wid) const
Get the current caret position.
Definition: misc_gui.cpp:834
ShowCostOrIncomeAnimation
void ShowCostOrIncomeAnimation(int x, int y, int z, Money cost)
Display animated income or costs on the map.
Definition: misc_gui.cpp:568
Window::window_number
WindowNumber window_number
Window number within the window class.
Definition: window_gui.h:296
Window::SetFocusedWidget
bool SetFocusedWidget(WidgetID widget_index)
Set focus within this window to the given widget.
Definition: window.cpp:487
GfxFillRect
void GfxFillRect(int left, int top, int right, int bottom, int colour, FillRectMode mode)
Applies a certain FillRectMode-operation to a rectangle [left, right] x [top, bottom] on the screen.
Definition: gfx.cpp:113
landscape.h
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:3144
viewport_func.h
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:45
TE_STATIC
@ TE_STATIC
Keep the text effect static.
Definition: texteff.hpp:22
SA_HOR_CENTER
@ SA_HOR_CENTER
Horizontally center the text.
Definition: gfx_type.h:339
WID_LI_LOCATION
@ WID_LI_LOCATION
Scroll to location.
Definition: misc_widget.h:15
Window::AllWindows
Iterable ensemble of all valid Windows.
Definition: window_gui.h:907
LandInfoWindow::landinfo_data
StringList landinfo_data
Info lines to show.
Definition: misc_gui.cpp:70
NWID_VERTICAL
@ NWID_VERTICAL
Vertical container.
Definition: widget_type.h:79
FillDrawPixelInfo
bool FillDrawPixelInfo(DrawPixelInfo *n, int left, int top, int width, int height)
Set up a clipping area for only drawing into a certain area.
Definition: gfx.cpp:1567
LandInfoWindow::OnInvalidateData
void OnInvalidateData([[maybe_unused]] int data=0, [[maybe_unused]] bool gui_scope=true) override
Some data on this window has become invalid.
Definition: misc_gui.cpp:364
WidgetDimensions::unscaled
static const WidgetDimensions unscaled
Unscaled widget dimensions.
Definition: window_gui.h:67
PC_LIGHT_YELLOW
static const uint8_t PC_LIGHT_YELLOW
Light yellow palette colour.
Definition: palette_func.h:69
WWT_CLOSEBOX
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition: widget_type.h:71
QueryWindow::params
std::vector< StringParameterBackup > params
local copy of #_global_string_params
Definition: misc_gui.cpp:1100
EconomySettings::dist_local_authority
byte dist_local_authority
distance for town local authority, default 20
Definition: settings_type.h:542
TileDesc::tram_speed
uint16_t tram_speed
Speed limit of tram (bridges and track)
Definition: tile_cmd.h:69
texteff.hpp
string_func.h
WID_Q_YES
@ WID_Q_YES
No button.
Definition: misc_widget.h:46
OskActivation
OskActivation
Method to open the OSK.
Definition: misc_gui.cpp:44
WWT_PUSHIMGBTN
@ WWT_PUSHIMGBTN
Normal push-button (no toggle button) with image caption.
Definition: widget_type.h:111
Window::querystrings
std::map< WidgetID, QueryString * > querystrings
QueryString associated to WWT_EDITBOX widgets.
Definition: window_gui.h:314
QueryString::cancel_button
int cancel_button
Widget button of parent window to simulate when pressing CANCEL in OSK.
Definition: querystring_gui.h:28
DrawStringMultiLine
int DrawStringMultiLine(int left, int right, int top, int bottom, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly over multiple lines.
Definition: gfx.cpp:771
_current_company
CompanyID _current_company
Company currently doing an action.
Definition: company_cmd.cpp:51
GuiShowTooltips
void GuiShowTooltips(Window *parent, StringID str, TooltipCloseCondition close_tooltip, uint paramcount)
Shows a tooltip.
Definition: misc_gui.cpp:758
rev.h
WC_GAME_OPTIONS
@ WC_GAME_OPTIONS
Game options window; Window numbers:
Definition: window_type.h:619
LandInfoWindow::IsNewGRFInspectable
bool IsNewGRFInspectable() const override
Is the data related to this window NewGRF inspectable?
Definition: misc_gui.cpp:336
ShowFeederIncomeAnimation
void ShowFeederIncomeAnimation(int x, int y, int z, Money transfer, Money income)
Display animated feeder income.
Definition: misc_gui.cpp:592
Window::CreateNestedTree
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
Definition: window.cpp:1724
strings_func.h
WidgetDimensions::vsep_wide
int vsep_wide
Wide vertical spacing.
Definition: window_gui.h:62
WWT_TEXT
@ WWT_TEXT
Pure simple text.
Definition: widget_type.h:60
SetPIP
constexpr NWidgetPart SetPIP(uint8_t pre, uint8_t inter, uint8_t post)
Widget part function for setting a pre/inter/post spaces.
Definition: widget_type.h:1222
TileDesc::dparam
uint64_t dparam
Parameter of the str string.
Definition: tile_cmd.h:54
SetDParam
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings.cpp:104
GetMainWindow
Window * GetMainWindow()
Get the main window, i.e.
Definition: window.cpp:1128
geometry_func.hpp
WID_QS_OK
@ WID_QS_OK
OK button.
Definition: misc_widget.h:38
WC_TOOLTIPS
@ WC_TOOLTIPS
Tooltip window; Window numbers:
Definition: window_type.h:116
Window::OnQueryTextFinished
virtual void OnQueryTextFinished([[maybe_unused]] char *str)
The query window opened from this window has closed.
Definition: window_gui.h:773
LandInfoWindow::ShowNewGRFInspectWindow
void ShowNewGRFInspectWindow() const override
Show the NewGRF inspection window.
Definition: misc_gui.cpp:341
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition: widget_type.h:52
OWNER_NONE
@ OWNER_NONE
The tile has no ownership.
Definition: company_type.h:25
WidgetDimensions::vsep_normal
int vsep_normal
Normal vertical spacing.
Definition: window_gui.h:60
Textbuf::marklength
uint16_t marklength
the length of the marked area in pixels
Definition: textbuf_type.h:44
AutoRestoreBackup
Class to backup a specific variable and restore it upon destruction of this object to prevent stack v...
Definition: backup_type.hpp:153
QueryWindow
Window used for asking the user a YES/NO question.
Definition: misc_gui.cpp:1098
TimerGameConst< struct Calendar >::INVALID_DATE
static constexpr TimerGame< struct Calendar >::Date INVALID_DATE
Representation of an invalid date.
Definition: timer_game_common.h:193
GetString
std::string GetString(StringID string)
Resolve the given StringID into a std::string with all the associated DParam lookups and formatting.
Definition: strings.cpp:327
QueryStringWindow::warning_size
Dimension warning_size
How much space to use for the warning text.
Definition: misc_gui.cpp:950
AboutWindow::num_visible_lines
static const int num_visible_lines
The number of lines visible simultaneously.
Definition: misc_gui.cpp:476
OSKA_SINGLE_CLICK
@ OSKA_SINGLE_CLICK
Single click after focus click opens OSK.
Definition: misc_gui.cpp:47
EventState
EventState
State of handling an event.
Definition: window_type.h:738
ShowLandInfo
void ShowLandInfo(TileIndex tile)
Show land information window.
Definition: misc_gui.cpp:377
WID_TT_BACKGROUND
@ WID_TT_BACKGROUND
Background of the window.
Definition: misc_widget.h:21
PC_GREY
static const uint8_t PC_GREY
Grey palette colour.
Definition: palette_func.h:57
Window::window_class
WindowClass window_class
Window class.
Definition: window_gui.h:295
WID_QS_CANCEL
@ WID_QS_CANCEL
Cancel button.
Definition: misc_widget.h:37
NWidgetCore::colour
Colours colour
Colour of this widget.
Definition: widget_type.h:377
SetDParamStr
void SetDParamStr(size_t n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
Definition: strings.cpp:352
TE_RISING
@ TE_RISING
Make the text effect slowly go upwards.
Definition: texteff.hpp:21
TileDesc::str
StringID str
Description of the tile.
Definition: tile_cmd.h:53
PackVelocity
int64_t PackVelocity(uint speed, VehicleType type)
Pack velocity and vehicle type for use with SCC_VELOCITY string parameter.
Definition: strings_func.h:74
Window::FinishInitNested
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition: window.cpp:1734
PC_BLACK
static const uint8_t PC_BLACK
Black palette colour.
Definition: palette_func.h:55
OSKA_DOUBLE_CLICK
@ OSKA_DOUBLE_CLICK
Double click on the edit box opens OSK.
Definition: misc_gui.cpp:46
company_func.h
WidgetDimensions::fullbevel
RectPadding fullbevel
Always-scaled bevel thickness.
Definition: window_gui.h:41
Window::top
int top
y position of top edge of the window
Definition: window_gui.h:304
WID_QS_DEFAULT
@ WID_QS_DEFAULT
Default button.
Definition: misc_widget.h:36
IsPtInWindowViewport
Viewport * IsPtInWindowViewport(const Window *w, int x, int y)
Is a xy position inside the viewport of the window?
Definition: viewport.cpp:408
SA_LEFT
@ SA_LEFT
Left align the text.
Definition: gfx_type.h:338
DrawFrameRect
void DrawFrameRect(int left, int top, int right, int bottom, Colours colour, FrameFlags flags)
Draw frame rectangle.
Definition: widget.cpp:281
CommandHelper
Definition: command_func.h:93
window_func.h
SA_CENTER
@ SA_CENTER
Center both horizontally and vertically.
Definition: gfx_type.h:348
GetCharacterHeight
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Definition: fontcache.cpp:78
Town
Town data structure.
Definition: town.h:50
Window::width
int width
width of the window (number of pixels to the right in x direction)
Definition: window_gui.h:305
TooltipsWindow::string_id
StringID string_id
String to display as tooltip.
Definition: misc_gui.cpp:668
SetMinimalSize
constexpr NWidgetPart SetMinimalSize(int16_t x, int16_t y)
Widget part function for setting the minimal size.
Definition: widget_type.h:1099
WDP_MANUAL
@ WDP_MANUAL
Manually align the window (so no automatic location finding)
Definition: window_gui.h:140
OverflowSafeInt< int64_t >
WID_A_SCROLLING_TEXT
@ WID_A_SCROLLING_TEXT
The actually scrolling text.
Definition: misc_widget.h:26
FR_DARKENED
@ FR_DARKENED
If set the background is darker, allows for lowered frames with normal background colour when used wi...
Definition: window_gui.h:29
DrawString
int DrawString(int left, int right, int top, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Definition: gfx.cpp:654
timer_window.h
IsNewGRFInspectable
bool IsNewGRFInspectable(GrfSpecFeature feature, uint index)
Can we inspect the data given a certain feature and index.
Definition: newgrf_debug_gui.cpp:761
TileDesc::owner_type
StringID owner_type[4]
Type of each owner.
Definition: tile_cmd.h:56
WidgetDimensions::bevel
RectPadding bevel
Bevel thickness, affected by "scaled bevels" game option.
Definition: window_gui.h:40
gui.h
GetCharPosInString
Point GetCharPosInString(std::string_view str, const char *ch, FontSize start_fontsize)
Get the leading corner of a character in a single-line string relative to the start of the string.
Definition: gfx.cpp:888
WidgetDimensions::frametext
RectPadding frametext
Padding inside frame with text.
Definition: window_gui.h:43
TooltipsWindow::close_cond
TooltipCloseCondition close_cond
Condition for closing the window.
Definition: misc_gui.cpp:670
GetCharAtPosition
ptrdiff_t GetCharAtPosition(std::string_view str, int x, FontSize start_fontsize)
Get the character from a string that is drawn at a specific position.
Definition: gfx.cpp:905
Window
Data structure for an opened window.
Definition: window_gui.h:267
TileDesc::rail_speed
uint16_t rail_speed
Speed limit of rail (bridges and track)
Definition: tile_cmd.h:65
Ticks::DAY_TICKS
static constexpr TimerGameTick::Ticks DAY_TICKS
1 day is 74 ticks; TimerGameCalendar::date_fract used to be uint16_t and incremented by 885.
Definition: timer_game_tick.h:75
VEH_TRAIN
@ VEH_TRAIN
Train vehicle type.
Definition: vehicle_type.h:24
QueryCallbackProc
void QueryCallbackProc(Window *, bool)
Callback procedure for the ShowQuery method.
Definition: textbuf_gui.h:29
Clamp
constexpr T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Definition: math_func.hpp:79
TileX
static debug_inline uint TileX(TileIndex tile)
Get the X component of a tile.
Definition: map_func.h:427
TileDesc::tramtype
StringID tramtype
Type of tram on the tile.
Definition: tile_cmd.h:68
DC_QUERY_COST
@ DC_QUERY_COST
query cost only, don't build.
Definition: command_type.h:373
SetDataTip
constexpr NWidgetPart SetDataTip(uint32_t data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1164
Rect::Width
int Width() const
Get width of Rect.
Definition: geometry_type.hpp:85
GetScaledSpriteSize
Dimension GetScaledSpriteSize(SpriteID sprid)
Scale sprite size for GUI.
Definition: widget.cpp:54
GetMainViewBottom
int GetMainViewBottom()
Return the bottom of the main view available for general use.
Definition: window.cpp:2078
WWT_DEBUGBOX
@ WWT_DEBUGBOX
NewGRF debug box (at top-right of a window, between WWT_CAPTION and WWT_SHADEBOX)
Definition: widget_type.h:65
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:75
CursorVars::pos
Point pos
logical mouse position
Definition: gfx_type.h:117
Textbuf::caretxoffs
uint16_t caretxoffs
the current position of the caret in pixels
Definition: textbuf_type.h:40
Company
Definition: company_base.h:129
QueryWindow::message
StringID message
message shown for query window
Definition: misc_gui.cpp:1101
AboutWindow::line_height
int line_height
The height of a single line.
Definition: misc_gui.cpp:475
OWNER_WATER
@ OWNER_WATER
The tile/execution is done by "water".
Definition: company_type.h:26
QSF_ENABLE_DEFAULT
@ QSF_ENABLE_DEFAULT
enable the 'Default' button ("\0" is returned)
Definition: textbuf_gui.h:21
CursorVars::in_window
bool in_window
mouse inside this window, determines drawing logic
Definition: gfx_type.h:141
CLRBITS
#define CLRBITS(x, y)
Clears several bits in a variable.
Definition: bitmath_func.hpp:166
WidgetDimensions::framerect
RectPadding framerect
Standard padding inside many panels.
Definition: window_gui.h:42
AboutWindow::scroll_interval
IntervalTimer< TimerWindow > scroll_interval
Scroll the text in the about window slow.
Definition: misc_gui.cpp:527
WID_A_COPYRIGHT
@ WID_A_COPYRIGHT
Copyright string.
Definition: misc_widget.h:28
WDP_CENTER
@ WDP_CENTER
Center the window.
Definition: window_gui.h:142
OSKA_IMMEDIATELY
@ OSKA_IMMEDIATELY
Focusing click already opens OSK.
Definition: misc_gui.cpp:48
Textbuf::DeleteAll
void DeleteAll()
Delete every character in the textbuffer.
Definition: textbuf.cpp:113
TD_RTL
@ TD_RTL
Text is written right-to-left by default.
Definition: strings_type.h:24
_current_text_dir
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition: strings.cpp:56
SetTextStyle
constexpr NWidgetPart SetTextStyle(TextColour colour, FontSize size=FS_NORMAL)
Widget part function for setting the text style.
Definition: widget_type.h:1122
CharSetFilter
CharSetFilter
Valid filter types for IsValidChar.
Definition: string_type.h:24
misc_widget.h
GetStringBoundingBox
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:848
_right_button_down
bool _right_button_down
Is right mouse button pressed?
Definition: gfx.cpp:42
WN_GAME_OPTIONS_ABOUT
@ WN_GAME_OPTIONS_ABOUT
About window.
Definition: window_type.h:24
WWT_TEXTBTN
@ WWT_TEXTBTN
(Toggle) Button with text
Definition: widget_type.h:57
INVALID_STRING_ID
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
Definition: strings_type.h:17
LandInfoWindow::cargo_acceptance
std::string cargo_acceptance
Centered multi-line string for cargo acceptance.
Definition: misc_gui.cpp:71
ClientSettings::gui
GUISettings gui
settings related to the GUI
Definition: settings_type.h:635
RemapCoords
Point RemapCoords(int x, int y, int z)
Map 3D world or tile coordinate to equivalent 2D coordinate as used in the viewports and smallmap.
Definition: landscape.h:82
debug.h
ShowEstimatedCostOrIncome
void ShowEstimatedCostOrIncome(Money cost, int x, int y)
Display estimated costs.
Definition: misc_gui.cpp:549
DrawPixelInfo
Data about how and where to blit pixels.
Definition: gfx_type.h:151
WID_Q_CAPTION
@ WID_Q_CAPTION
Caption of the window.
Definition: misc_widget.h:43
AboutWindow
Definition: misc_gui.cpp:473
Textbuf
Helper/buffer for input fields.
Definition: textbuf_type.h:30
Window::GetWidget
const NWID * GetWidget(WidgetID widnum) const
Get the nested widget with number widnum from the nested widget tree.
Definition: window_gui.h:971