Fix some daylength issues, possible division by zero in main menu.
[openttd-joker.git] / src / misc_gui.cpp
blob410ee540d845c6e6ce7efcb99dc15f6e16ff8e99
1 /* $Id$ */
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 */
10 /** @file misc_gui.cpp GUIs for a number of misc windows. */
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 "newgrf_cargo.h"
29 #include "zoom_func.h"
30 #include "industry.h"
31 #include "station_base.h"
32 #include "waypoint_base.h"
33 #include "tunnelbridge_map.h"
35 #include "widgets/misc_widget.h"
37 #include "table/strings.h"
39 #include "safeguards.h"
41 /** Method to open the OSK. */
42 enum OskActivation {
43 OSKA_DISABLED, ///< The OSK shall not be activated at all.
44 OSKA_DOUBLE_CLICK, ///< Double click on the edit box opens OSK.
45 OSKA_SINGLE_CLICK, ///< Single click after focus click opens OSK.
46 OSKA_IMMEDIATELY, ///< Focusing click already opens OSK.
50 static const NWidgetPart _nested_land_info_widgets[] = {
51 NWidget(NWID_HORIZONTAL),
52 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
53 NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_LAND_AREA_INFORMATION_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
54 NWidget(WWT_DEBUGBOX, COLOUR_GREY),
55 EndContainer(),
56 NWidget(WWT_PANEL, COLOUR_GREY, WID_LI_BACKGROUND), EndContainer(),
59 static WindowDesc _land_info_desc(
60 WDP_AUTO, "land_info", 0, 0,
61 WC_LAND_INFO, WC_NONE,
63 _nested_land_info_widgets, lengthof(_nested_land_info_widgets)
66 class LandInfoWindow : public Window {
67 enum LandInfoLines {
68 LAND_INFO_CENTERED_LINES = 32, ///< Up to 32 centered lines (arbitrary limit)
69 LAND_INFO_MULTICENTER_LINE = LAND_INFO_CENTERED_LINES, ///< One multicenter line
70 LAND_INFO_LINE_END,
73 static const uint LAND_INFO_LINE_BUFF_SIZE = 512;
75 public:
76 char landinfo_data[LAND_INFO_LINE_END][LAND_INFO_LINE_BUFF_SIZE];
77 TileIndex tile;
79 virtual void DrawWidget(const Rect &r, int widget) const
81 if (widget != WID_LI_BACKGROUND) return;
83 GfxDrawLine(r.left, r.top, r.right, r.top, PC_BLACK);
84 GfxDrawLine(r.left, r.bottom, r.right, r.bottom, PC_BLACK);
85 GfxDrawLine(r.left, r.top, r.left, r.bottom, PC_BLACK);
86 GfxDrawLine(r.right, r.top, r.right, r.bottom, PC_BLACK);
88 uint y = r.top + WD_TEXTPANEL_TOP;
89 for (uint i = 0; i < LAND_INFO_CENTERED_LINES; i++) {
90 if (StrEmpty(this->landinfo_data[i])) break;
92 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);
93 y += FONT_HEIGHT_NORMAL + WD_PAR_VSEP_NORMAL;
94 if (i == 0) y += 4;
97 if (!StrEmpty(this->landinfo_data[LAND_INFO_MULTICENTER_LINE])) {
98 SetDParamStr(0, this->landinfo_data[LAND_INFO_MULTICENTER_LINE]);
99 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);
103 virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
105 if (widget != WID_LI_BACKGROUND) return;
107 size->height = WD_TEXTPANEL_TOP + WD_TEXTPANEL_BOTTOM;
108 for (uint i = 0; i < LAND_INFO_CENTERED_LINES; i++) {
109 if (StrEmpty(this->landinfo_data[i])) break;
111 uint width = GetStringBoundingBox(this->landinfo_data[i]).width + WD_FRAMETEXT_LEFT + WD_FRAMETEXT_RIGHT;
112 size->width = max(size->width, width);
114 size->height += FONT_HEIGHT_NORMAL + WD_PAR_VSEP_NORMAL;
115 if (i == 0) size->height += 4;
118 if (!StrEmpty(this->landinfo_data[LAND_INFO_MULTICENTER_LINE])) {
119 uint width = GetStringBoundingBox(this->landinfo_data[LAND_INFO_MULTICENTER_LINE]).width + WD_FRAMETEXT_LEFT + WD_FRAMETEXT_RIGHT;
120 size->width = max(size->width, min(300u, width));
121 SetDParamStr(0, this->landinfo_data[LAND_INFO_MULTICENTER_LINE]);
122 size->height += GetStringHeight(STR_JUST_RAW_STRING, size->width - WD_FRAMETEXT_LEFT - WD_FRAMETEXT_RIGHT);
126 LandInfoWindow(TileIndex tile) : Window(&_land_info_desc), tile(tile)
128 this->InitNested();
130 #if defined(_DEBUG)
131 # define LANDINFOD_LEVEL 0
132 #else
133 # define LANDINFOD_LEVEL 1
134 #endif
135 DEBUG(misc, LANDINFOD_LEVEL, "TILE: %#x (%i,%i)", tile, TileX(tile), TileY(tile));
136 if(IsTunnelTile(tile)) {
137 DEBUG(misc, LANDINFOD_LEVEL, "tunnel pool size: %u", (uint)Tunnel::GetPoolSize());
138 DEBUG(misc, LANDINFOD_LEVEL, "index: %#x" , Tunnel::GetByTile(tile)->index);
139 DEBUG(misc, LANDINFOD_LEVEL, "north tile: %#x" , Tunnel::GetByTile(tile)->tile_n);
140 DEBUG(misc, LANDINFOD_LEVEL, "south tile: %#x" , Tunnel::GetByTile(tile)->tile_s);
141 DEBUG(misc, LANDINFOD_LEVEL, "is chunnel: %u" , Tunnel::GetByTile(tile)->is_chunnel);
143 DEBUG(misc, LANDINFOD_LEVEL, "type = %#x", _m[tile].type);
144 DEBUG(misc, LANDINFOD_LEVEL, "height = %#x", _m[tile].height);
145 DEBUG(misc, LANDINFOD_LEVEL, "m1 = %#x", _m[tile].m1);
146 DEBUG(misc, LANDINFOD_LEVEL, "m2 = %#x", _m[tile].m2);
147 DEBUG(misc, LANDINFOD_LEVEL, "m3 = %#x", _m[tile].m3);
148 DEBUG(misc, LANDINFOD_LEVEL, "m4 = %#x", _m[tile].m4);
149 DEBUG(misc, LANDINFOD_LEVEL, "m5 = %#x", _m[tile].m5);
150 DEBUG(misc, LANDINFOD_LEVEL, "m6 = %#x", _me[tile].m6);
151 DEBUG(misc, LANDINFOD_LEVEL, "m7 = %#x", _me[tile].m7);
152 #undef LANDINFOD_LEVEL
155 virtual void OnInit()
157 Town *t = ClosestTownFromTile(tile, _settings_game.economy.dist_local_authority);
159 /* Because build_date is not set yet in every TileDesc, we make sure it is empty */
160 TileDesc td;
162 td.build_date = INVALID_DATE;
164 /* Most tiles have only one owner, but
165 * - drivethrough roadstops can be build on town owned roads (up to 2 owners) and
166 * - roads can have up to four owners (railroad, road, tram, 3rd-roadtype "highway").
168 td.owner_type[0] = STR_LAND_AREA_INFORMATION_OWNER; // At least one owner is displayed, though it might be "N/A".
169 td.owner_type[1] = STR_NULL; // STR_NULL results in skipping the owner
170 td.owner_type[2] = STR_NULL;
171 td.owner_type[3] = STR_NULL;
172 td.owner[0] = OWNER_NONE;
173 td.owner[1] = OWNER_NONE;
174 td.owner[2] = OWNER_NONE;
175 td.owner[3] = OWNER_NONE;
177 td.station_class = STR_NULL;
178 td.station_name = STR_NULL;
179 td.airport_class = STR_NULL;
180 td.airport_name = STR_NULL;
181 td.airport_tile_name = STR_NULL;
182 td.railtype = STR_NULL;
183 td.rail_speed = 0;
184 td.road_speed = 0;
186 td.grf = NULL;
188 CargoArray acceptance;
189 AddAcceptedCargo(tile, acceptance, NULL);
190 GetTileDesc(tile, &td);
192 uint line_nr = 0;
194 /* Tiletype */
195 SetDParam(0, td.dparam[0]);
196 SetDParam(1, td.dparam[1]);
197 GetString(this->landinfo_data[line_nr], td.str, lastof(this->landinfo_data[line_nr]));
198 line_nr++;
200 /* Up to four owners */
201 for (uint i = 0; i < 4; i++) {
202 if (td.owner_type[i] == STR_NULL) continue;
204 SetDParam(0, STR_LAND_AREA_INFORMATION_OWNER_N_A);
205 if (td.owner[i] != OWNER_NONE && td.owner[i] != OWNER_WATER) GetNameOfOwner(td.owner[i], tile);
206 GetString(this->landinfo_data[line_nr], td.owner_type[i], lastof(this->landinfo_data[line_nr]));
207 line_nr++;
210 /* Cost to clear/revenue when cleared */
211 StringID str = STR_LAND_AREA_INFORMATION_COST_TO_CLEAR_N_A;
212 Company *c = Company::GetIfValid(_local_company);
213 if (c != NULL) {
214 Money old_money = c->money;
215 c->money = INT64_MAX;
216 assert(_current_company == _local_company);
217 CommandCost costclear = DoCommand(tile, 0, 0, DC_NONE, CMD_LANDSCAPE_CLEAR);
218 c->money = old_money;
219 if (costclear.Succeeded()) {
220 Money cost = costclear.GetCost();
221 if (cost < 0) {
222 cost = -cost; // Negate negative cost to a positive revenue
223 str = STR_LAND_AREA_INFORMATION_REVENUE_WHEN_CLEARED;
224 } else {
225 str = STR_LAND_AREA_INFORMATION_COST_TO_CLEAR;
227 SetDParam(0, cost);
230 GetString(this->landinfo_data[line_nr], str, lastof(this->landinfo_data[line_nr]));
231 line_nr++;
233 /* Location */
234 char tmp[16];
235 seprintf(tmp, lastof(tmp), "0x%.4X", tile);
236 SetDParam(0, TileX(tile));
237 SetDParam(1, TileY(tile));
238 SetDParam(2, GetTileZ(tile));
239 SetDParamStr(3, tmp);
240 GetString(this->landinfo_data[line_nr], STR_LAND_AREA_INFORMATION_LANDINFO_COORDS, lastof(this->landinfo_data[line_nr]));
241 line_nr++;
243 /* Local authority */
244 SetDParam(0, STR_LAND_AREA_INFORMATION_LOCAL_AUTHORITY_NONE);
245 if (t != NULL) {
246 SetDParam(0, STR_TOWN_NAME);
247 SetDParam(1, t->index);
249 GetString(this->landinfo_data[line_nr], STR_LAND_AREA_INFORMATION_LOCAL_AUTHORITY, lastof(this->landinfo_data[line_nr]));
250 line_nr++;
252 /* Build date */
253 if (td.build_date != INVALID_DATE) {
254 SetDParam(0, td.build_date);
255 GetString(this->landinfo_data[line_nr], STR_LAND_AREA_INFORMATION_BUILD_DATE, lastof(this->landinfo_data[line_nr]));
256 line_nr++;
259 /* Station class */
260 if (td.station_class != STR_NULL) {
261 SetDParam(0, td.station_class);
262 GetString(this->landinfo_data[line_nr], STR_LAND_AREA_INFORMATION_STATION_CLASS, lastof(this->landinfo_data[line_nr]));
263 line_nr++;
266 /* Station type name */
267 if (td.station_name != STR_NULL) {
268 SetDParam(0, td.station_name);
269 GetString(this->landinfo_data[line_nr], STR_LAND_AREA_INFORMATION_STATION_TYPE, lastof(this->landinfo_data[line_nr]));
270 line_nr++;
273 /* Airport class */
274 if (td.airport_class != STR_NULL) {
275 SetDParam(0, td.airport_class);
276 GetString(this->landinfo_data[line_nr], STR_LAND_AREA_INFORMATION_AIRPORT_CLASS, lastof(this->landinfo_data[line_nr]));
277 line_nr++;
280 /* Airport name */
281 if (td.airport_name != STR_NULL) {
282 SetDParam(0, td.airport_name);
283 GetString(this->landinfo_data[line_nr], STR_LAND_AREA_INFORMATION_AIRPORT_NAME, lastof(this->landinfo_data[line_nr]));
284 line_nr++;
287 /* Airport tile name */
288 if (td.airport_tile_name != STR_NULL) {
289 SetDParam(0, td.airport_tile_name);
290 GetString(this->landinfo_data[line_nr], STR_LAND_AREA_INFORMATION_AIRPORTTILE_NAME, lastof(this->landinfo_data[line_nr]));
291 line_nr++;
294 /* Rail type name */
295 if (td.railtype != STR_NULL) {
296 SetDParam(0, td.railtype);
297 GetString(this->landinfo_data[line_nr], STR_LANG_AREA_INFORMATION_RAIL_TYPE, lastof(this->landinfo_data[line_nr]));
298 line_nr++;
301 /* Rail speed limit */
302 if (td.rail_speed != 0) {
303 SetDParam(0, td.rail_speed);
304 GetString(this->landinfo_data[line_nr], STR_LANG_AREA_INFORMATION_RAIL_SPEED_LIMIT, lastof(this->landinfo_data[line_nr]));
305 line_nr++;
308 /* Road speed limit */
309 if (td.road_speed != 0) {
310 SetDParam(0, td.road_speed);
311 GetString(this->landinfo_data[line_nr], STR_LANG_AREA_INFORMATION_ROAD_SPEED_LIMIT, lastof(this->landinfo_data[line_nr]));
312 line_nr++;
315 /* NewGRF name */
316 if (td.grf != NULL) {
317 SetDParamStr(0, td.grf);
318 GetString(this->landinfo_data[line_nr], STR_LAND_AREA_INFORMATION_NEWGRF_NAME, lastof(this->landinfo_data[line_nr]));
319 line_nr++;
322 assert(line_nr < LAND_INFO_CENTERED_LINES);
324 /* Mark last line empty */
325 this->landinfo_data[line_nr][0] = '\0';
327 /* Cargo acceptance is displayed in a extra multiline */
328 char *strp = GetString(this->landinfo_data[LAND_INFO_MULTICENTER_LINE], STR_LAND_AREA_INFORMATION_CARGO_ACCEPTED, lastof(this->landinfo_data[LAND_INFO_MULTICENTER_LINE]));
329 bool found = false;
331 for (CargoID i = 0; i < NUM_CARGO; ++i) {
332 if (acceptance[i] > 0) {
333 /* Add a comma between each item. */
334 if (found) {
335 *strp++ = ',';
336 *strp++ = ' ';
338 found = true;
340 /* If the accepted value is less than 8, show it in 1/8:ths */
341 if (acceptance[i] < 8) {
342 SetDParam(0, acceptance[i]);
343 SetDParam(1, CargoSpec::Get(i)->name);
344 strp = GetString(strp, STR_LAND_AREA_INFORMATION_CARGO_EIGHTS, lastof(this->landinfo_data[LAND_INFO_MULTICENTER_LINE]));
345 } else {
346 strp = GetString(strp, CargoSpec::Get(i)->name, lastof(this->landinfo_data[LAND_INFO_MULTICENTER_LINE]));
350 if (!found) this->landinfo_data[LAND_INFO_MULTICENTER_LINE][0] = '\0';
353 virtual bool IsNewGRFInspectable() const
355 return ::IsNewGRFInspectable(GetGrfSpecFeature(this->tile), this->tile);
358 virtual void ShowNewGRFInspectWindow() const
360 ::ShowNewGRFInspectWindow(GetGrfSpecFeature(this->tile), this->tile);
364 * Some data on this window has become invalid.
365 * @param data Information about the changed data.
366 * @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
368 virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
370 if (!gui_scope) return;
371 switch (data) {
372 case 1:
373 /* ReInit, "debug" sprite might have changed */
374 this->ReInit();
375 break;
381 * Show land information window.
382 * @param tile The tile to show information about.
384 void ShowLandInfo(TileIndex tile)
386 DeleteWindowById(WC_LAND_INFO, 0);
387 new LandInfoWindow(tile);
390 static const NWidgetPart _nested_about_widgets[] = {
391 NWidget(NWID_HORIZONTAL),
392 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
393 NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_ABOUT_OPENTTD, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
394 EndContainer(),
395 NWidget(WWT_PANEL, COLOUR_GREY), SetPIP(4, 2, 4),
396 NWidget(WWT_LABEL, COLOUR_GREY), SetDataTip(STR_ABOUT_ORIGINAL_COPYRIGHT, STR_NULL),
397 NWidget(WWT_LABEL, COLOUR_GREY), SetDataTip(STR_ABOUT_VERSION, STR_NULL),
398 NWidget(WWT_FRAME, COLOUR_GREY), SetPadding(0, 5, 1, 5),
399 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_A_SCROLLING_TEXT),
400 EndContainer(),
401 NWidget(WWT_LABEL, COLOUR_GREY, WID_A_WEBSITE), SetDataTip(STR_BLACK_RAW_STRING, STR_NULL),
402 NWidget(WWT_LABEL, COLOUR_GREY, WID_A_WEBSITE1), SetDataTip(STR_BLACK_RAW_STRING, STR_NULL),
403 NWidget(WWT_LABEL, COLOUR_GREY, WID_A_WEBSITE2), SetDataTip(STR_BLACK_RAW_STRING, STR_NULL),
404 NWidget(WWT_LABEL, COLOUR_GREY), SetDataTip(STR_ABOUT_COPYRIGHT_OPENTTD, STR_NULL),
405 EndContainer(),
408 static WindowDesc _about_desc(
409 WDP_CENTER, NULL, 0, 0,
410 WC_GAME_OPTIONS, WC_NONE,
412 _nested_about_widgets, lengthof(_nested_about_widgets)
415 static const char * const _credits[] = {
416 "Original design by Chris Sawyer",
417 "Original graphics by Simon Foster",
419 "The OpenTTD team (in alphabetical order):",
420 " Grzegorz Duczy\xC5\x84ski (adf88) - General coding (since 1.7.2)",
421 " Albert Hofkamp (Alberth) - GUI expert (since 0.7)",
422 " Matthijs Kooijman (blathijs) - Pathfinder-guru, Debian port (since 0.3)",
423 " Ulf Hermann (fonsinchen) - Cargo Distribution (since 1.3)",
424 " Christoph Elsenhans (frosch) - General coding (since 0.6)",
425 " Lo\xC3\xAF""c Guilloux (glx) - General / Windows Expert (since 0.4.5)",
426 " Michael Lutz (michi_cc) - Path based signals (since 0.7)",
427 " Owen Rudge (orudge) - Forum host, OS/2 port (since 0.1)",
428 " Peter Nelson (peter1138) - Spiritual descendant from NewGRF gods (since 0.4.5)",
429 " Ingo von Borstel (planetmaker) - General, Support (since 1.1)",
430 " Remko Bijker (Rubidium) - Lead coder and way more (since 0.4.5)",
431 " Jos\xC3\xA9 Soler (Terkhen) - General coding (since 1.0)",
432 " Leif Linse (Zuu) - AI/Game Script (since 1.2)",
434 "Inactive Developers:",
435 " Jean-Fran\xC3\xA7ois Claeys (Belugas) - GUI, NewGRF and more (0.4.5 - 1.0)",
436 " Bjarni Corfitzen (Bjarni) - MacOSX port, coder and vehicles (0.3 - 0.7)",
437 " Victor Fischer (Celestar) - Programming everywhere you need him to (0.3 - 0.6)",
438 " Jaroslav Mazanec (KUDr) - YAPG (Yet Another Pathfinder God) ;) (0.4.5 - 0.6)",
439 " Jonathan Coome (Maedhros) - High priest of the NewGRF Temple (0.5 - 0.6)",
440 " Attila B\xC3\xA1n (MiHaMiX) - Developer WebTranslator 1 and 2 (0.3 - 0.5)",
441 " Zden\xC4\x9Bk Sojka (SmatZ) - Bug finder and fixer (0.6 - 1.3)",
442 " Christoph Mallon (Tron) - Programmer, code correctness police (0.3 - 0.5)",
443 " Patric Stout (TrueBrain) - NoAI, NoGo, Network (0.3 - 1.2), sys op (active)",
444 " Thijs Marinussen (Yexo) - AI Framework, General (0.6 - 1.3)",
446 "Retired Developers:",
447 " Tam\xC3\xA1s Farag\xC3\xB3 (Darkvater) - Ex-Lead coder (0.3 - 0.5)",
448 " Dominik Scherer (dominik81) - Lead programmer, GUI expert (0.3 - 0.3)",
449 " Emil Djupfeld (egladil) - MacOSX (0.4.5 - 0.6)",
450 " Simon Sasburg (HackyKid) - Many bugfixes (0.4 - 0.4.5)",
451 " Ludvig Strigeus (ludde) - Original author of OpenTTD, main coder (0.1 - 0.3)",
452 " Cian Duffy (MYOB) - BeOS port / manual writing (0.1 - 0.3)",
453 " Petr Baudi\xC5\xA1 (pasky) - Many patches, NewGRF support (0.3 - 0.3)",
454 " Benedikt Br\xC3\xBCggemeier (skidd13) - Bug fixer and code reworker (0.6 - 0.7)",
455 " Serge Paquet (vurlix) - 2nd contributor after ludde (0.1 - 0.3)",
457 "Special thanks go out to:",
458 " Josef Drexler - For his great work on TTDPatch",
459 " Marcin Grzegorczyk - Track foundations and for describing TTD internals",
460 " Stefan Mei\xC3\x9Fner (sign_de) - For his work on the console",
461 " Mike Ragsdale - OpenTTD installer",
462 " Christian Rosentreter (tokai) - MorphOS / AmigaOS port",
463 " Richard Kempton (richK) - additional airports, initial TGP implementation",
465 " Alberto Demichelis - Squirrel scripting language \xC2\xA9 2003-2008",
466 " L. Peter Deutsch - MD5 implementation \xC2\xA9 1999, 2000, 2002",
467 " Michael Blunck - Pre-signals and semaphores \xC2\xA9 2003",
468 " George - Canal/Lock graphics \xC2\xA9 2003-2004",
469 " Andrew Parkhouse (andythenorth) - River graphics",
470 " David Dallaston (Pikka) - Tram tracks",
471 " All Translators - Who made OpenTTD a truly international game",
472 " Bug Reporters - Without whom OpenTTD would still be full of bugs!",
475 "Developer of this patchpack:",
476 " Andreas Schmitt (Lt_Joker)",
479 "Several features imported from the JGR Patch Pack developed by:",
480 " Jonathan G. Rennison (JGR)",
483 "And last but not least:",
484 " Chris Sawyer - For an amazing game!"
487 struct AboutWindow : public Window {
488 int text_position; ///< The top of the scrolling text
489 byte counter; ///< Used to scroll the text every 5 ticks
490 int line_height; ///< The height of a single line
491 static const int num_visible_lines = 19; ///< The number of lines visible simultaneously
493 AboutWindow() : Window(&_about_desc)
495 this->InitNested(WN_GAME_OPTIONS_ABOUT);
497 this->counter = 5;
498 this->text_position = this->GetWidget<NWidgetBase>(WID_A_SCROLLING_TEXT)->pos_y + this->GetWidget<NWidgetBase>(WID_A_SCROLLING_TEXT)->current_y;
501 virtual void SetStringParameters(int widget) const
503 if (widget == WID_A_WEBSITE) SetDParamStr(0, "Main project website: http://www.openttd.org");
504 if (widget == WID_A_WEBSITE1) SetDParamStr(0, "Patchpack thread: https://www.tt-forums.net/viewtopic.php?f=33&t=74365");
505 if (widget == WID_A_WEBSITE2) SetDParamStr(0, "Patchpack Github: https://github.com/KeldorKatarn/OpenTTD_PatchPack");
508 virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
510 if (widget != WID_A_SCROLLING_TEXT) return;
512 this->line_height = FONT_HEIGHT_NORMAL;
514 Dimension d;
515 d.height = this->line_height * num_visible_lines;
517 d.width = 0;
518 for (uint i = 0; i < lengthof(_credits); i++) {
519 d.width = max(d.width, GetStringBoundingBox(_credits[i]).width);
521 *size = maxdim(*size, d);
524 virtual void DrawWidget(const Rect &r, int widget) const
526 if (widget != WID_A_SCROLLING_TEXT) return;
528 int y = this->text_position;
530 /* Show all scrolling _credits */
531 for (uint i = 0; i < lengthof(_credits); i++) {
532 if (y >= r.top + 7 && y < r.bottom - this->line_height) {
533 DrawString(r.left, r.right, y, _credits[i], TC_BLACK, SA_LEFT | SA_FORCE);
535 y += this->line_height;
539 virtual void OnTick()
541 if (--this->counter == 0) {
542 this->counter = 5;
543 this->text_position--;
544 /* If the last text has scrolled start a new from the start */
545 if (this->text_position < (int)(this->GetWidget<NWidgetBase>(WID_A_SCROLLING_TEXT)->pos_y - lengthof(_credits) * this->line_height)) {
546 this->text_position = this->GetWidget<NWidgetBase>(WID_A_SCROLLING_TEXT)->pos_y + this->GetWidget<NWidgetBase>(WID_A_SCROLLING_TEXT)->current_y;
548 this->SetDirty();
553 void ShowAboutWindow()
555 DeleteWindowByClass(WC_GAME_OPTIONS);
556 new AboutWindow();
560 * Display estimated costs.
561 * @param cost Estimated cost (or income if negative).
562 * @param x X position of the notification window.
563 * @param y Y position of the notification window.
565 void ShowEstimatedCostOrIncome(Money cost, int x, int y)
567 StringID msg = STR_MESSAGE_ESTIMATED_COST;
569 if (cost < 0) {
570 cost = -cost;
571 msg = STR_MESSAGE_ESTIMATED_INCOME;
573 SetDParam(0, cost);
574 ShowErrorMessage(msg, INVALID_STRING_ID, WL_INFO, x, y);
578 * Display animated income or costs on the map.
579 * @param x World X position of the animation location.
580 * @param y World Y position of the animation location.
581 * @param z World Z position of the animation location.
582 * @param cost Estimated cost (or income if negative).
584 void ShowCostOrIncomeAnimation(int x, int y, int z, Money cost)
586 Point pt = RemapCoords(x, y, z);
587 StringID msg = STR_INCOME_FLOAT_COST;
589 if (cost < 0) {
590 cost = -cost;
591 msg = STR_INCOME_FLOAT_INCOME;
593 SetDParam(0, cost);
594 AddTextEffect(msg, pt.x, pt.y, DAY_TICKS, TE_RISING);
598 * Display animated feeder income.
599 * @param x World X position of the animation location.
600 * @param y World Y position of the animation location.
601 * @param z World Z position of the animation location.
602 * @param transfer Estimated feeder income.
603 * @param income Real income from goods being delivered to their final destination.
605 void ShowFeederIncomeAnimation(int x, int y, int z, Money transfer, Money income)
607 Point pt = RemapCoords(x, y, z);
609 SetDParam(0, transfer);
610 if (income == 0) {
611 AddTextEffect(STR_FEEDER, pt.x, pt.y, DAY_TICKS, TE_RISING);
612 } else {
613 StringID msg = STR_FEEDER_COST;
614 if (income < 0) {
615 income = -income;
616 msg = STR_FEEDER_INCOME;
618 SetDParam(1, income);
619 AddTextEffect(msg, pt.x, pt.y, DAY_TICKS, TE_RISING);
624 * Display vehicle loading indicators.
625 * @param x World X position of the animation location.
626 * @param y World Y position of the animation location.
627 * @param z World Z position of the animation location.
628 * @param percent Estimated feeder income.
629 * @param string String which is drawn on the map.
630 * @return TextEffectID to be used for future updates of the loading indicators.
632 TextEffectID ShowFillingPercent(int x, int y, int z, uint8 percent, StringID string)
634 Point pt = RemapCoords(x, y, z);
636 assert(string != STR_NULL);
638 SetDParam(0, percent);
639 return AddTextEffect(string, pt.x, pt.y, 0, TE_STATIC);
643 * Update vehicle loading indicators.
644 * @param te_id TextEffectID to be updated.
645 * @param string String which is printed.
647 void UpdateFillingPercent(TextEffectID te_id, uint8 percent, StringID string)
649 assert(string != STR_NULL);
651 SetDParam(0, percent);
652 UpdateTextEffect(te_id, string);
656 * Hide vehicle loading indicators.
657 * @param *te_id TextEffectID which is supposed to be hidden.
659 void HideFillingPercent(TextEffectID *te_id)
661 if (*te_id == INVALID_TE_ID) return;
663 RemoveTextEffect(*te_id);
664 *te_id = INVALID_TE_ID;
667 static const NWidgetPart _nested_tooltips_widgets[] = {
668 NWidget(WWT_PANEL, COLOUR_GREY, WID_TT_BACKGROUND), SetMinimalSize(200, 32), EndContainer(),
671 static WindowDesc _tool_tips_desc(
672 WDP_MANUAL, NULL, 0, 0, // Coordinates and sizes are not used,
673 WC_TOOLTIPS, WC_NONE,
674 WDF_NO_FOCUS,
675 _nested_tooltips_widgets, lengthof(_nested_tooltips_widgets)
678 /** Window for displaying a tooltip. */
679 struct TooltipsWindow : public Window
681 const char *tip; ///< The text being displayed in the window.
682 TooltipCloseCondition close_cond; ///< Condition for closing the window.
683 char buffer[DRAW_STRING_BUFFER]; ///< Text to draw
685 TooltipsWindow(Window *parent, const char *tip, TooltipCloseCondition close_tooltip) : Window(&_tool_tips_desc)
687 this->parent = parent;
688 this->tip = stredup(tip);
689 this->close_cond = close_tooltip;
691 this->InitNested();
693 CLRBITS(this->flags, WF_WHITE_BORDER);
696 virtual ~TooltipsWindow()
698 free(this->tip);
701 virtual Point OnInitialPosition(int16 sm_width, int16 sm_height, int window_number)
703 /* Find the free screen space between the main toolbar at the top, and the statusbar at the bottom.
704 * Add a fixed distance 2 so the tooltip floats free from both bars.
706 int scr_top = GetMainViewTop() + 2;
707 int scr_bot = GetMainViewBottom() - 2;
709 Point pt;
711 /* Correctly position the tooltip position, watch out for window and cursor size
712 * Clamp value to below main toolbar and above statusbar. If tooltip would
713 * go below window, flip it so it is shown above the cursor */
714 pt.y = Clamp(_cursor.pos.y + _cursor.total_size.y + _cursor.total_offs.y + 5, scr_top, scr_bot);
715 if (pt.y + sm_height > scr_bot) pt.y = min(_cursor.pos.y + _cursor.total_offs.y - 5, scr_bot) - sm_height;
716 pt.x = sm_width >= _screen.width ? 0 : Clamp(_cursor.pos.x - (sm_width >> 1), 0, _screen.width - sm_width);
718 return pt;
721 virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
723 /* There is only one widget. */
724 size->width = min(GetStringBoundingBox(this->tip).width, ScaleGUITrad(194));
725 size->height = GetStringHeight(this->tip, size->width);
727 /* Increase slightly to have some space around the box. */
728 size->width += 2 + WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT;
729 size->height += 2 + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
732 virtual void DrawWidget(const Rect &r, int widget) const
734 /* There is only one widget. */
735 GfxFillRect(r.left, r.top, r.right, r.bottom, PC_BLACK);
736 GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, PC_LIGHT_YELLOW);
738 DrawStringMultiLine(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP, r.bottom - WD_FRAMERECT_BOTTOM, this->tip, TC_FROMSTRING, SA_CENTER);
741 virtual void OnMouseLoop()
743 /* Always close tooltips when the cursor is not in our window. */
744 if (!_cursor.in_window) {
745 delete this;
746 return;
749 /* We can show tooltips while dragging tools. These are shown as long as
750 * we are dragging the tool. Normal tooltips work with hover or rmb. */
751 switch (this->close_cond) {
752 case TCC_RIGHT_CLICK: if (!_right_button_down) delete this; break;
753 case TCC_LEFT_CLICK: if (!_left_button_down) delete this; break;
754 case TCC_HOVER: if (!_mouse_hovering) delete this; break;
758 virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
760 if (!gui_scope) return;
762 /* This hover has ended (_mouse_hovering might be true for a new hover). */
763 if (this->close_cond == TCC_HOVER) delete this;
768 * Shows a tooltip
769 * @param parent The window this tooltip is related to.
770 * @param str String to be displayed
771 * @param close_tooltip Close condition.
773 void GuiShowTooltips(Window *parent, StringID str, TooltipCloseCondition close_tooltip)
775 char buff[DRAW_STRING_BUFFER] = "";
776 if (str != STR_NULL) GetString(buff, str, lastof(buff));
778 GuiShowTooltips(parent, buff, close_tooltip);
782 * Shows a tooltip
783 * @param parent The window this tooltip is related to.
784 * @param str String to be displayed.
785 * @param close_tooltip Close condition.
787 void GuiShowTooltips(Window *parent, const char *str, TooltipCloseCondition close_tooltip)
789 DeleteWindowById(WC_TOOLTIPS, 0);
791 if (StrEmpty(str)) return;
794 new TooltipsWindow(parent, str, close_tooltip);
798 * Get tooltip string for an industry tile.
799 * @param iid ID of the industry.
800 * @param buff Buffer to store the string in.
801 * @param last Last character of the buffer.
803 static void GetTileTooltipsForIndustry(IndustryID iid, char *buff, const char *last)
805 if (!Industry::IsValidID(iid)) return;
807 SetDParam(0, iid);
808 buff = GetString(buff, STR_TILE_TOOLTIP_INDUSTRY_NAME, last);
810 const Industry *industry = Industry::Get(iid);
811 for (size_t i = 0; i < lengthof(industry->produced_cargo); i++) {
812 if (industry->produced_cargo[i] != CT_INVALID) {
813 buff = strecpy(buff, "\n", last);
814 SetDParam(0, industry->produced_cargo[i]);
815 SetDParam(1, industry->last_month_production[i]);
816 SetDParam(2, ToPercent8(industry->last_month_pct_transported[i]));
817 buff = GetString(buff, STR_TILE_TOOLTIP_CARGO_ITEM, last);
823 * Get tooltip string for a station tile.
824 * @param iid ID of the station.
825 * @param buff Buffer to store the string in.
826 * @param last Last character of the buffer.
828 void GetTileTooltipsForStation(StationID sid, char *buff, const char *last)
830 SetDParam(0, sid);
831 if (Waypoint::IsValidID(sid)) {
832 GetString(buff, STR_TILE_TOOLTIP_WAYPOINT_NAME, last);
833 } else if (Station::IsValidID(sid)) {
834 Station *station = Station::Get(sid);
835 SetDParam(1, station->facilities);
836 buff = GetString(buff, STR_TILE_TOOLTIP_STATION_NAME_FEATURES, last);
837 for (CargoID i = 0; i < lengthof(station->goods); i++) {
838 if (station->goods[i].HasRating()) {
839 buff = strecpy(buff, "\n", last);
840 SetDParam(0, i);
841 SetDParam(1, station->goods[i].cargo.TotalCount());
842 SetDParam(2, ToPercent8(station->goods[i].rating));
843 buff = GetString(buff, STR_TILE_TOOLTIP_CARGO_ITEM, last);
850 * Get tooltip string for a town tile.
851 * @param iid ID of the town.
852 * @return The string.
854 static StringID GetTileTooltipsForTown(TownID tid)
856 if (!Town::IsValidID(tid)) return STR_NULL;
858 SetDParam(0, tid);
859 SetDParam(1, Town::Get(tid)->cache.population);
860 return STR_TILE_TOOLTIP_TOWN_NAME_POP;
864 * Get tooltip string for a company owned tile.
865 * @param iid ID of the company.
866 * @return The string.
868 static StringID GetTileTooltipsForCompany(CompanyID cid)
870 if (!Company::IsValidID(cid) || IsInteractiveCompany(cid)) return STR_NULL;
872 SetDParam(0, cid);
873 return STR_TILE_TOOLTIP_COMPANY_NAME;
877 * Show tooltip for a given tile.
878 * @param parent Parent window of the tooltip.
879 * @param tile The tile to show the tip for.
880 * @param close_tooltip Close condition for the tooltip.
882 void GuiShowTooltipsForTile(Window *parent, TileIndex tile, TooltipCloseCondition close_tooltip)
884 StringID tip = STR_NULL;
886 if (tile < MapSize()) {
887 TileType tt = GetTileType(tile);
888 switch (tt) {
889 case MP_STATION:
890 case MP_INDUSTRY: {
891 char buff[DRAW_STRING_BUFFER] = "";
892 if (tt == MP_STATION) {
893 GetTileTooltipsForStation(GetStationIndex(tile), buff, lastof(buff));
894 } else {
895 GetTileTooltipsForIndustry(GetIndustryIndex(tile), buff, lastof(buff));
897 GuiShowTooltips(parent, buff, close_tooltip);
898 return;
901 case MP_RAILWAY:
902 case MP_ROAD:
903 case MP_WATER:
904 case MP_TUNNELBRIDGE:
905 case MP_OBJECT:
906 Owner o;
907 o = GetTileOwner(tile);
908 if (o != OWNER_TOWN) {
909 tip = GetTileTooltipsForCompany(o);
910 break;
912 /* FALLTHROUGH */
913 case MP_HOUSE:
914 tip = GetTileTooltipsForTown(tt != MP_TUNNELBRIDGE ? GetTownIndex(tile) : CalcClosestTownFromTile(tile)->index);
915 break;
917 default:
918 break;
922 GuiShowTooltips(parent, tip, close_tooltip);
925 void QueryString::HandleEditBox(Window *w, int wid)
927 if (w->IsWidgetGloballyFocused(wid) && this->text.HandleCaret()) {
928 w->SetWidgetDirty(wid);
930 /* For the OSK also invalidate the parent window */
931 if (w->window_class == WC_OSK) w->InvalidateData();
935 void QueryString::DrawEditBox(const Window *w, int wid) const
937 const NWidgetLeaf *wi = w->GetWidget<NWidgetLeaf>(wid);
939 assert((wi->type & WWT_MASK) == WWT_EDITBOX);
941 bool rtl = _current_text_dir == TD_RTL;
942 Dimension sprite_size = GetSpriteSize(rtl ? SPR_IMG_DELETE_RIGHT : SPR_IMG_DELETE_LEFT);
943 int clearbtn_width = sprite_size.width + WD_IMGBTN_LEFT + WD_IMGBTN_RIGHT;
945 int clearbtn_left = wi->pos_x + (rtl ? 0 : wi->current_x - clearbtn_width);
946 int clearbtn_right = wi->pos_x + (rtl ? clearbtn_width : wi->current_x) - 1;
947 int left = wi->pos_x + (rtl ? clearbtn_width : 0);
948 int right = wi->pos_x + (rtl ? wi->current_x : wi->current_x - clearbtn_width) - 1;
950 int top = wi->pos_y;
951 int bottom = wi->pos_y + wi->current_y - 1;
953 DrawFrameRect(clearbtn_left, top, clearbtn_right, bottom, wi->colour, wi->IsLowered() ? FR_LOWERED : FR_NONE);
954 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));
955 if (this->text.bytes == 1) GfxFillRect(clearbtn_left + 1, top + 1, clearbtn_right - 1, bottom - 1, _colour_gradient[wi->colour & 0xF][2], FILLRECT_CHECKER);
957 DrawFrameRect(left, top, right, bottom, wi->colour, FR_LOWERED | FR_DARKENED);
958 GfxFillRect(left + 1, top + 1, right - 1, bottom - 1, PC_BLACK);
960 /* Limit the drawing of the string inside the widget boundaries */
961 DrawPixelInfo dpi;
962 if (!FillDrawPixelInfo(&dpi, left + WD_FRAMERECT_LEFT, top + WD_FRAMERECT_TOP, right - left - WD_FRAMERECT_RIGHT, bottom - top - WD_FRAMERECT_BOTTOM)) return;
964 DrawPixelInfo *old_dpi = _cur_dpi;
965 _cur_dpi = &dpi;
967 /* We will take the current widget length as maximum width, with a small
968 * space reserved at the end for the caret to show */
969 const Textbuf *tb = &this->text;
970 int delta = min(0, (right - left) - tb->pixels - 10);
972 if (tb->caretxoffs + delta < 0) delta = -tb->caretxoffs;
974 /* If we have a marked area, draw a background highlight. */
975 if (tb->marklength != 0) GfxFillRect(delta + tb->markxoffs, 0, delta + tb->markxoffs + tb->marklength - 1, bottom - top, PC_GREY);
977 DrawString(delta, tb->pixels, 0, tb->buf, TC_YELLOW);
978 bool focussed = w->IsWidgetGloballyFocused(wid) || IsOSKOpenedFor(w, wid);
979 if (focussed && tb->caret) {
980 int caret_width = GetStringBoundingBox("_").width;
981 DrawString(tb->caretxoffs + delta, tb->caretxoffs + delta + caret_width, 0, "_", TC_WHITE);
984 _cur_dpi = old_dpi;
988 * Get the current caret position.
989 * @param w Window the edit box is in.
990 * @param wid Widget index.
991 * @return Top-left location of the caret, relative to the window.
993 Point QueryString::GetCaretPosition(const Window *w, int wid) const
995 const NWidgetLeaf *wi = w->GetWidget<NWidgetLeaf>(wid);
997 assert((wi->type & WWT_MASK) == WWT_EDITBOX);
999 bool rtl = _current_text_dir == TD_RTL;
1000 Dimension sprite_size = GetSpriteSize(rtl ? SPR_IMG_DELETE_RIGHT : SPR_IMG_DELETE_LEFT);
1001 int clearbtn_width = sprite_size.width + WD_IMGBTN_LEFT + WD_IMGBTN_RIGHT;
1003 int left = wi->pos_x + (rtl ? clearbtn_width : 0);
1004 int right = wi->pos_x + (rtl ? wi->current_x : wi->current_x - clearbtn_width) - 1;
1006 /* Clamp caret position to be inside out current width. */
1007 const Textbuf *tb = &this->text;
1008 int delta = min(0, (right - left) - tb->pixels - 10);
1009 if (tb->caretxoffs + delta < 0) delta = -tb->caretxoffs;
1011 Point pt = {left + WD_FRAMERECT_LEFT + tb->caretxoffs + delta, (int)wi->pos_y + WD_FRAMERECT_TOP};
1012 return pt;
1016 * Get the bounding rectangle for a range of the query string.
1017 * @param w Window the edit box is in.
1018 * @param wid Widget index.
1019 * @param from Start of the string range.
1020 * @param to End of the string range.
1021 * @return Rectangle encompassing the string range, relative to the window.
1023 Rect QueryString::GetBoundingRect(const Window *w, int wid, const char *from, const char *to) const
1025 const NWidgetLeaf *wi = w->GetWidget<NWidgetLeaf>(wid);
1027 assert((wi->type & WWT_MASK) == WWT_EDITBOX);
1029 bool rtl = _current_text_dir == TD_RTL;
1030 Dimension sprite_size = GetSpriteSize(rtl ? SPR_IMG_DELETE_RIGHT : SPR_IMG_DELETE_LEFT);
1031 int clearbtn_width = sprite_size.width + WD_IMGBTN_LEFT + WD_IMGBTN_RIGHT;
1033 int left = wi->pos_x + (rtl ? clearbtn_width : 0);
1034 int right = wi->pos_x + (rtl ? wi->current_x : wi->current_x - clearbtn_width) - 1;
1036 int top = wi->pos_y + WD_FRAMERECT_TOP;
1037 int bottom = wi->pos_y + wi->current_y - 1 - WD_FRAMERECT_BOTTOM;
1039 /* Clamp caret position to be inside our current width. */
1040 const Textbuf *tb = &this->text;
1041 int delta = min(0, (right - left) - tb->pixels - 10);
1042 if (tb->caretxoffs + delta < 0) delta = -tb->caretxoffs;
1044 /* Get location of first and last character. */
1045 Point p1 = GetCharPosInString(tb->buf, from, FS_NORMAL);
1046 Point p2 = from != to ? GetCharPosInString(tb->buf, to, FS_NORMAL) : p1;
1048 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 };
1050 return r;
1054 * Get the character that is rendered at a position.
1055 * @param w Window the edit box is in.
1056 * @param wid Widget index.
1057 * @param pt Position to test.
1058 * @return Pointer to the character at the position or NULL if no character is at the position.
1060 const char *QueryString::GetCharAtPosition(const Window *w, int wid, const Point &pt) const
1062 const NWidgetLeaf *wi = w->GetWidget<NWidgetLeaf>(wid);
1064 assert((wi->type & WWT_MASK) == WWT_EDITBOX);
1066 bool rtl = _current_text_dir == TD_RTL;
1067 Dimension sprite_size = GetSpriteSize(rtl ? SPR_IMG_DELETE_RIGHT : SPR_IMG_DELETE_LEFT);
1068 int clearbtn_width = sprite_size.width + WD_IMGBTN_LEFT + WD_IMGBTN_RIGHT;
1070 int left = wi->pos_x + (rtl ? clearbtn_width : 0);
1071 int right = wi->pos_x + (rtl ? wi->current_x : wi->current_x - clearbtn_width) - 1;
1073 int top = wi->pos_y + WD_FRAMERECT_TOP;
1074 int bottom = wi->pos_y + wi->current_y - 1 - WD_FRAMERECT_BOTTOM;
1076 if (!IsInsideMM(pt.y, top, bottom)) return NULL;
1078 /* Clamp caret position to be inside our current width. */
1079 const Textbuf *tb = &this->text;
1080 int delta = min(0, (right - left) - tb->pixels - 10);
1081 if (tb->caretxoffs + delta < 0) delta = -tb->caretxoffs;
1083 return ::GetCharAtPosition(tb->buf, pt.x - delta - left);
1086 void QueryString::ClickEditBox(Window *w, Point pt, int wid, int click_count, bool focus_changed)
1088 const NWidgetLeaf *wi = w->GetWidget<NWidgetLeaf>(wid);
1090 assert((wi->type & WWT_MASK) == WWT_EDITBOX);
1092 bool rtl = _current_text_dir == TD_RTL;
1093 int clearbtn_width = GetSpriteSize(rtl ? SPR_IMG_DELETE_RIGHT : SPR_IMG_DELETE_LEFT).width;
1095 int clearbtn_left = wi->pos_x + (rtl ? 0 : wi->current_x - clearbtn_width);
1097 if (IsInsideBS(pt.x, clearbtn_left, clearbtn_width)) {
1098 if (this->text.bytes > 1) {
1099 this->text.DeleteAll();
1100 w->HandleButtonClick(wid);
1101 w->OnEditboxChanged(wid);
1103 return;
1106 if (w->window_class != WC_OSK && _settings_client.gui.osk_activation != OSKA_DISABLED &&
1107 (!focus_changed || _settings_client.gui.osk_activation == OSKA_IMMEDIATELY) &&
1108 (click_count == 2 || _settings_client.gui.osk_activation != OSKA_DOUBLE_CLICK)) {
1109 /* Open the OSK window */
1110 ShowOnScreenKeyboard(w, wid);
1114 /** Class for the string query window. */
1115 struct QueryStringWindow : public Window
1117 QueryString editbox; ///< Editbox.
1118 QueryStringFlags flags; ///< Flags controlling behaviour of the window.
1120 QueryStringWindow(StringID str, StringID caption, uint max_bytes, uint max_chars, WindowDesc *desc, Window *parent, CharSetFilter afilter, QueryStringFlags flags) :
1121 Window(desc), editbox(max_bytes, max_chars)
1123 char *last_of = &this->editbox.text.buf[this->editbox.text.max_bytes - 1];
1124 GetString(this->editbox.text.buf, str, last_of);
1125 str_validate(this->editbox.text.buf, last_of, SVS_NONE);
1127 /* Make sure the name isn't too long for the text buffer in the number of
1128 * characters (not bytes). max_chars also counts the '\0' characters. */
1129 while (Utf8StringLength(this->editbox.text.buf) + 1 > this->editbox.text.max_chars) {
1130 *Utf8PrevChar(this->editbox.text.buf + strlen(this->editbox.text.buf)) = '\0';
1133 this->editbox.text.UpdateSize();
1135 if ((flags & QSF_ACCEPT_UNCHANGED) == 0) this->editbox.orig = stredup(this->editbox.text.buf);
1137 this->querystrings[WID_QS_TEXT] = &this->editbox;
1138 this->editbox.caption = caption;
1139 this->editbox.cancel_button = WID_QS_CANCEL;
1140 this->editbox.ok_button = WID_QS_OK;
1141 this->editbox.text.afilter = afilter;
1142 this->flags = flags;
1144 this->InitNested(WN_QUERY_STRING);
1146 this->parent = parent;
1148 this->SetFocusedWidget(WID_QS_TEXT);
1151 virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
1153 if (widget == WID_QS_DEFAULT && (this->flags & QSF_ENABLE_DEFAULT) == 0) {
1154 /* We don't want this widget to show! */
1155 fill->width = 0;
1156 resize->width = 0;
1157 size->width = 0;
1161 virtual void SetStringParameters(int widget) const
1163 if (widget == WID_QS_CAPTION) SetDParam(0, this->editbox.caption);
1166 void OnOk()
1168 if (this->editbox.orig == NULL || strcmp(this->editbox.text.buf, this->editbox.orig) != 0) {
1169 /* If the parent is NULL, the editbox is handled by general function
1170 * HandleOnEditText */
1171 if (this->parent != NULL) {
1172 this->parent->OnQueryTextFinished(this->editbox.text.buf);
1173 } else {
1174 HandleOnEditText(this->editbox.text.buf);
1176 this->editbox.handled = true;
1180 virtual void OnClick(Point pt, int widget, int click_count)
1182 switch (widget) {
1183 case WID_QS_DEFAULT:
1184 this->editbox.text.DeleteAll();
1185 FALLTHROUGH;
1187 case WID_QS_OK:
1188 this->OnOk();
1189 FALLTHROUGH;
1191 case WID_QS_CANCEL:
1192 delete this;
1193 break;
1197 ~QueryStringWindow()
1199 if (!this->editbox.handled && this->parent != NULL) {
1200 Window *parent = this->parent;
1201 this->parent = NULL; // so parent doesn't try to delete us again
1202 parent->OnQueryTextFinished(NULL);
1207 static const NWidgetPart _nested_query_string_widgets[] = {
1208 NWidget(NWID_HORIZONTAL),
1209 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
1210 NWidget(WWT_CAPTION, COLOUR_GREY, WID_QS_CAPTION), SetDataTip(STR_WHITE_STRING, STR_NULL),
1211 EndContainer(),
1212 NWidget(WWT_PANEL, COLOUR_GREY),
1213 NWidget(WWT_EDITBOX, COLOUR_GREY, WID_QS_TEXT), SetMinimalSize(256, 12), SetFill(1, 1), SetPadding(2, 2, 2, 2),
1214 EndContainer(),
1215 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
1216 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_QS_DEFAULT), SetMinimalSize(87, 12), SetFill(1, 1), SetDataTip(STR_BUTTON_DEFAULT, STR_NULL),
1217 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_QS_CANCEL), SetMinimalSize(86, 12), SetFill(1, 1), SetDataTip(STR_BUTTON_CANCEL, STR_NULL),
1218 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_QS_OK), SetMinimalSize(87, 12), SetFill(1, 1), SetDataTip(STR_BUTTON_OK, STR_NULL),
1219 EndContainer(),
1222 static WindowDesc _query_string_desc(
1223 WDP_CENTER, "query_string", 0, 0,
1224 WC_QUERY_STRING, WC_NONE,
1226 _nested_query_string_widgets, lengthof(_nested_query_string_widgets)
1230 * Show a query popup window with a textbox in it.
1231 * @param str StringID for the text shown in the textbox
1232 * @param caption StringID of text shown in caption of querywindow
1233 * @param maxsize maximum size in bytes or characters (including terminating '\0') depending on flags
1234 * @param parent pointer to a Window that will handle the events (ok/cancel) of this
1235 * window. If NULL, results are handled by global function HandleOnEditText
1236 * @param afilter filters out unwanted character input
1237 * @param flags various flags, @see QueryStringFlags
1239 void ShowQueryString(StringID str, StringID caption, uint maxsize, Window *parent, CharSetFilter afilter, QueryStringFlags flags)
1241 DeleteWindowByClass(WC_QUERY_STRING);
1242 new QueryStringWindow(str, caption, ((flags & QSF_LEN_IN_CHARS) ? MAX_CHAR_LENGTH : 1) * maxsize, maxsize, &_query_string_desc, parent, afilter, flags);
1246 * Window used for asking the user a YES/NO question.
1248 struct QueryWindow : public Window {
1249 QueryCallbackProc *proc; ///< callback function executed on closing of popup. Window* points to parent, bool is true if 'yes' clicked, false otherwise
1250 uint64 params[10]; ///< local copy of _decode_parameters
1251 StringID message; ///< message shown for query window
1252 StringID caption; ///< title of window
1254 QueryWindow(WindowDesc *desc, StringID caption, StringID message, Window *parent, QueryCallbackProc *callback) : Window(desc)
1256 /* Create a backup of the variadic arguments to strings because it will be
1257 * overridden pretty often. We will copy these back for drawing */
1258 CopyOutDParam(this->params, 0, lengthof(this->params));
1259 this->caption = caption;
1260 this->message = message;
1261 this->proc = callback;
1263 this->InitNested(WN_CONFIRM_POPUP_QUERY);
1265 this->parent = parent;
1266 this->left = parent->left + (parent->width / 2) - (this->width / 2);
1267 this->top = parent->top + (parent->height / 2) - (this->height / 2);
1270 ~QueryWindow()
1272 if (this->proc != NULL) this->proc(this->parent, false);
1275 virtual void SetStringParameters(int widget) const
1277 switch (widget) {
1278 case WID_Q_CAPTION:
1279 CopyInDParam(1, this->params, lengthof(this->params));
1280 SetDParam(0, this->caption);
1281 break;
1283 case WID_Q_TEXT:
1284 CopyInDParam(0, this->params, lengthof(this->params));
1285 break;
1289 virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
1291 if (widget != WID_Q_TEXT) return;
1293 Dimension d = GetStringMultiLineBoundingBox(this->message, *size);
1294 d.width += WD_FRAMETEXT_LEFT + WD_FRAMETEXT_RIGHT;
1295 d.height += WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
1296 *size = d;
1299 virtual void DrawWidget(const Rect &r, int widget) const
1301 if (widget != WID_Q_TEXT) return;
1303 DrawStringMultiLine(r.left + WD_FRAMETEXT_LEFT, r.right - WD_FRAMETEXT_RIGHT, r.top + WD_FRAMERECT_TOP, r.bottom - WD_FRAMERECT_BOTTOM,
1304 this->message, TC_FROMSTRING, SA_CENTER);
1307 virtual void OnClick(Point pt, int widget, int click_count)
1309 switch (widget) {
1310 case WID_Q_YES: {
1311 /* in the Generate New World window, clicking 'Yes' causes
1312 * DeleteNonVitalWindows() to be called - we shouldn't be in a window then */
1313 QueryCallbackProc *proc = this->proc;
1314 Window *parent = this->parent;
1315 /* Prevent the destructor calling the callback function */
1316 this->proc = NULL;
1317 delete this;
1318 if (proc != NULL) {
1319 proc(parent, true);
1320 proc = NULL;
1322 break;
1324 case WID_Q_NO:
1325 delete this;
1326 break;
1330 virtual EventState OnKeyPress(WChar key, uint16 keycode)
1332 /* ESC closes the window, Enter confirms the action */
1333 switch (keycode) {
1334 case WKC_RETURN:
1335 case WKC_NUM_ENTER:
1336 if (this->proc != NULL) {
1337 this->proc(this->parent, true);
1338 this->proc = NULL;
1340 FALLTHROUGH;
1342 case WKC_ESC:
1343 delete this;
1344 return ES_HANDLED;
1346 return ES_NOT_HANDLED;
1350 static const NWidgetPart _nested_query_widgets[] = {
1351 NWidget(NWID_HORIZONTAL),
1352 NWidget(WWT_CLOSEBOX, COLOUR_RED),
1353 NWidget(WWT_CAPTION, COLOUR_RED, WID_Q_CAPTION), SetDataTip(STR_JUST_STRING, STR_NULL),
1354 EndContainer(),
1355 NWidget(WWT_PANEL, COLOUR_RED), SetPIP(8, 15, 8),
1356 NWidget(WWT_TEXT, COLOUR_RED, WID_Q_TEXT), SetMinimalSize(200, 12),
1357 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(20, 29, 20),
1358 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_Q_NO), SetMinimalSize(71, 12), SetFill(1, 1), SetDataTip(STR_QUIT_NO, STR_NULL),
1359 NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_Q_YES), SetMinimalSize(71, 12), SetFill(1, 1), SetDataTip(STR_QUIT_YES, STR_NULL),
1360 EndContainer(),
1361 EndContainer(),
1364 static WindowDesc _query_desc(
1365 WDP_CENTER, NULL, 0, 0,
1366 WC_CONFIRM_POPUP_QUERY, WC_NONE,
1367 WDF_MODAL,
1368 _nested_query_widgets, lengthof(_nested_query_widgets)
1372 * Show a modal confirmation window with standard 'yes' and 'no' buttons
1373 * The window is aligned to the centre of its parent.
1374 * @param caption string shown as window caption
1375 * @param message string that will be shown for the window
1376 * @param parent pointer to parent window, if this pointer is NULL the parent becomes
1377 * the main window WC_MAIN_WINDOW
1378 * @param callback callback function pointer to set in the window descriptor
1380 void ShowQuery(StringID caption, StringID message, Window *parent, QueryCallbackProc *callback)
1382 if (parent == NULL) parent = FindWindowById(WC_MAIN_WINDOW, 0);
1384 const Window *w;
1385 FOR_ALL_WINDOWS_FROM_BACK(w) {
1386 if (w->window_class != WC_CONFIRM_POPUP_QUERY) continue;
1388 const QueryWindow *qw = (const QueryWindow *)w;
1389 if (qw->parent != parent || qw->proc != callback) continue;
1391 delete qw;
1392 break;
1395 new QueryWindow(&_query_desc, caption, message, parent, callback);
1398 static const NWidgetPart _nested_station_rating_tooltip_widgets[] = {
1399 NWidget(WWT_PANEL, COLOUR_GREY, WID_TT_BACKGROUND), SetMinimalSize(64, 32), EndContainer(),
1402 static WindowDesc _station_rating_tooltip_desc(
1403 WDP_MANUAL, NULL, 0, 0,
1404 WC_STATION_RATING_TOOLTIP, WC_NONE,
1406 _nested_station_rating_tooltip_widgets, lengthof(_nested_station_rating_tooltip_widgets)
1409 static const int STATION_RATING_AGE[] = { 0, 10, 20, 33 };
1410 static const int STATION_RATING_WAITUNITS[] = { -90, -38, 14, 66, 118, 170 };
1413 struct StationRatingTooltipWindow : public Window
1415 TileType tiletype;
1416 uint16 objIndex;
1417 TooltipCloseCondition close_cond;
1418 const Station *st;
1419 const CargoSpec *cs;
1420 bool newgrf_rating_used;
1422 static const uint RATING_TOOLTIP_LINE_BUFF_SIZE = 512;
1423 static const uint RATING_TOOLTIP_MAX_LINES = 8;
1424 static const uint RATING_TOOLTIP_NEWGRF_INDENT = 20;
1426 public:
1427 char data[RATING_TOOLTIP_MAX_LINES + 1][RATING_TOOLTIP_LINE_BUFF_SIZE];
1429 StationRatingTooltipWindow(Window *parent, const Station *st, const CargoSpec *cs) : Window(&_station_rating_tooltip_desc)
1431 this->parent = parent;
1432 this->st = st;
1433 this->cs = cs;
1434 this->InitNested();
1435 CLRBITS(this->flags, WF_WHITE_BORDER);
1438 virtual Point OnInitialPosition(int16 sm_width, int16 sm_height, int window_number)
1440 int scr_top = GetMainViewTop() + 2;
1441 int scr_bot = GetMainViewBottom() - 2;
1442 Point pt;
1443 pt.y = Clamp(_cursor.pos.y + _cursor.total_size.y + _cursor.total_offs.y + 5, scr_top, scr_bot);
1444 if (pt.y + sm_height > scr_bot) pt.y = min(_cursor.pos.y + _cursor.total_offs.y - 5, scr_bot) - sm_height;
1445 pt.x = sm_width >= _screen.width ? 0 : Clamp(_cursor.pos.x - (sm_width >> 1), 0, _screen.width - sm_width);
1446 return pt;
1449 int RoundRating(int rating) {
1450 return RoundDivSU(rating * 101, 256);
1453 virtual void OnInit() {
1454 const GoodsEntry *ge = &this->st->goods[this->cs->Index()];
1456 SetDParam(0, this->cs->name);
1457 GetString(this->data[0], STR_STATION_RATING_TOOLTIP_RATING_DETAILS, lastof(this->data[0]));
1458 if (!ge->HasRating()) {
1459 this->data[1][0] = '\0';
1460 return;
1463 uint line_nr = 1;
1464 int total_rating = 0;
1466 if (HasBit(cs->callback_mask, CBM_CARGO_STATION_RATING_CALC)) {
1467 uint last_speed = ge->HasVehicleEverTriedLoading() ? ge->last_speed : 0xFF;
1469 uint32 var18 = min(ge->time_since_pickup, 0xFF) | (min(ge->max_waiting_cargo, 0xFFFF) << 8) | (min(last_speed, 0xFF) << 24);
1470 uint32 var10 = (ge->last_vehicle_type == VEH_INVALID) ? 0x0 : (ge->last_vehicle_type + 0x10);
1471 uint16 callback = GetCargoCallback(CBID_CARGO_STATION_RATING_CALC, var10, var18, this->cs);
1472 int newgrf_rating = 0;
1473 if (callback != CALLBACK_FAILED) {
1474 newgrf_rating = GB(callback, 0, 14);
1475 if (HasBit(callback, 14)) newgrf_rating -= 0x4000;
1477 this->newgrf_rating_used = true;
1479 total_rating += newgrf_rating;
1480 newgrf_rating = this->RoundRating(newgrf_rating);
1482 SetDParam(0, STR_STATION_RATING_TOOLTIP_NEWGRF_RATING_0 + (newgrf_rating <= 0 ? 0 : 1));
1483 SetDParam(1, newgrf_rating);
1484 GetString(this->data[line_nr], STR_STATION_RATING_TOOLTIP_NEWGRF_RATING, lastof(this->data[line_nr]));
1485 line_nr++;
1487 SetDParam(0, min(ge->last_unprocessed_speed, 0xFF));
1489 switch (ge->last_vehicle_type)
1491 case VEH_TRAIN:
1492 SetDParam(1, STR_STATION_RATING_TOOLTIP_TRAIN);
1493 break;
1494 case VEH_ROAD:
1495 SetDParam(1, STR_STATION_RATING_TOOLTIP_ROAD_VEHICLE);
1496 break;
1497 case VEH_SHIP:
1498 SetDParam(1, STR_STATION_RATING_TOOLTIP_SHIP);
1499 break;
1500 case VEH_AIRCRAFT:
1501 SetDParam(1, STR_STATION_RATING_TOOLTIP_AIRCRAFT);
1502 break;
1503 default:
1504 SetDParam(1, STR_STATION_RATING_TOOLTIP_INVALID);
1505 break;
1508 GetString(this->data[line_nr], STR_STATION_RATING_TOOLTIP_NEWGRF_SPEED, lastof(this->data[line_nr]));
1509 line_nr++;
1511 SetDParam(0, min(ge->max_waiting_cargo, 0xFFFF));
1512 GetString(this->data[line_nr],
1513 (ge->punishment_in_effect || ge->punishment_triggered) ?
1514 STR_STATION_RATING_TOOLTIP_NEWGRF_WAITUNITS_FEEDBACK :
1515 STR_STATION_RATING_TOOLTIP_NEWGRF_WAITUNITS,
1516 lastof(this->data[line_nr]));
1517 line_nr++;
1519 SetDParam(0, ge->time_since_pickup * STATION_RATING_TICKS / DAY_TICKS);
1520 GetString(this->data[line_nr], STR_STATION_RATING_TOOLTIP_NEWGRF_WAITTIME, lastof(this->data[line_nr]));
1521 line_nr++;
1525 if (!this->newgrf_rating_used) {
1527 uint waitunits = ge->max_waiting_cargo;
1528 int waitunits_stage = 0;
1529 (ge->max_waiting_cargo > 2000) ||
1530 (waitunits_stage = 1, ge->max_waiting_cargo > 1000) ||
1531 (waitunits_stage = 2, ge->max_waiting_cargo > 500) ||
1532 (waitunits_stage = 3, ge->max_waiting_cargo > 250) ||
1533 (waitunits_stage = 4, ge->max_waiting_cargo > 125) ||
1534 (waitunits_stage = 5, true);
1535 total_rating += STATION_RATING_WAITUNITS[waitunits_stage];
1537 SetDParam(0, STR_STATION_RATING_TOOLTIP_WAITUNITS_0 + waitunits_stage);
1538 SetDParam(1, ge->max_waiting_cargo);
1539 SetDParam(2, this->RoundRating(STATION_RATING_WAITUNITS[waitunits_stage]));
1540 GetString(this->data[line_nr],
1541 (ge->punishment_in_effect || ge->punishment_triggered) ? STR_STATION_RATING_TOOLTIP_WAITUNITS_FEEDBACK : STR_STATION_RATING_TOOLTIP_WAITUNITS,
1542 lastof(this->data[line_nr]));
1543 line_nr++;
1545 int b = ge->last_speed - 15;
1546 int r_speed = b >= 0 ? b >> 2 : 0;
1547 int r_speed_round = this->RoundRating(r_speed);
1548 total_rating += r_speed;
1549 if (ge->last_speed == 255) {
1550 SetDParam(0, STR_STATION_RATING_TOOLTIP_SPEED_3);
1552 else if (r_speed_round == 0) {
1553 SetDParam(0, STR_STATION_RATING_TOOLTIP_SPEED_ZERO);
1555 else {
1556 SetDParam(0, STR_STATION_RATING_TOOLTIP_SPEED_0 + min(3, r_speed / 15));
1558 SetDParam(1, ge->last_unprocessed_speed);
1559 SetDParam(2, r_speed_round);
1561 switch (ge->last_vehicle_type)
1563 case VEH_TRAIN:
1564 SetDParam(3, STR_STATION_RATING_TOOLTIP_TRAIN);
1565 break;
1566 case VEH_ROAD:
1567 SetDParam(3, STR_STATION_RATING_TOOLTIP_ROAD_VEHICLE);
1568 break;
1569 case VEH_SHIP:
1570 SetDParam(3, STR_STATION_RATING_TOOLTIP_SHIP);
1571 break;
1572 case VEH_AIRCRAFT:
1573 SetDParam(3, STR_STATION_RATING_TOOLTIP_AIRCRAFT);
1574 break;
1575 default:
1576 SetDParam(3, STR_STATION_RATING_TOOLTIP_INVALID);
1577 break;
1580 GetString(this->data[line_nr], STR_STATION_RATING_TOOLTIP_SPEED, lastof(this->data[line_nr]));
1581 line_nr++;
1584 int age_stage = 0;
1585 (ge->last_age >= 30) ||
1586 (age_stage = 1, ge->last_age >= 20) ||
1587 (age_stage = 2, ge->last_age >= 10) ||
1588 (age_stage = 3, true);
1590 total_rating += STATION_RATING_AGE[age_stage];
1591 SetDParam(0, STR_STATION_RATING_TOOLTIP_AGE_0 + age_stage);
1592 SetDParam(1, ge->last_age);
1593 SetDParam(2, this->RoundRating(STATION_RATING_AGE[age_stage]));
1594 GetString(this->data[line_nr], STR_STATION_RATING_TOOLTIP_AGE, lastof(this->data[line_nr]));
1595 line_nr++;
1597 if (Company::IsValidID(st->owner) && HasBit(st->town->statues, st->owner)) {
1598 SetDParam(0, STR_STATION_RATING_TOOLTIP_STATUE_YES);
1599 total_rating += 26;
1601 else {
1602 SetDParam(0, STR_STATION_RATING_TOOLTIP_STATUE_NO);
1604 GetString(this->data[line_nr], STR_STATION_RATING_TOOLTIP_STATUE, lastof(this->data[line_nr]));
1605 line_nr++;
1607 SetDParam(0, ToPercent8(Clamp(total_rating, 0, 255)));
1608 GetString(this->data[line_nr], STR_STATION_RATING_TOOLTIP_TOTAL_RATING, lastof(this->data[line_nr]));
1609 line_nr++;
1611 this->data[line_nr][0] = '\0';
1614 virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
1616 if (widget != WID_LI_BACKGROUND) return;
1618 size->height = WD_FRAMETEXT_TOP + WD_FRAMETEXT_BOTTOM + 2;
1619 for (uint i = 0; i <= RATING_TOOLTIP_MAX_LINES; i++) {
1620 if (StrEmpty(this->data[i])) break;
1622 uint width = GetStringBoundingBox(this->data[i]).width + WD_FRAMETEXT_LEFT + WD_FRAMETEXT_RIGHT + 2;
1623 if (this->newgrf_rating_used && i >= 2 && i <= 4)
1624 width += RATING_TOOLTIP_NEWGRF_INDENT;
1625 size->width = max(size->width, width);
1626 size->height += FONT_HEIGHT_NORMAL + WD_PAR_VSEP_NORMAL;
1628 size->height -= WD_PAR_VSEP_NORMAL;
1631 virtual void DrawWidget(const Rect &r, int widget) const
1633 uint icon_size = ScaleGUITrad(10);
1634 uint line_height = max((uint)FONT_HEIGHT_NORMAL, icon_size) + 2;
1635 uint text_ofs = (line_height - FONT_HEIGHT_NORMAL) >> 1;
1636 uint icon_ofs = (line_height - icon_size) >> 1;
1638 GfxDrawLine(r.left, r.top, r.right, r.top, PC_BLACK);
1639 GfxDrawLine(r.left, r.bottom, r.right, r.bottom, PC_BLACK);
1640 GfxDrawLine(r.left, r.top, r.left, r.bottom, PC_BLACK);
1641 GfxDrawLine(r.right, r.top, r.right, r.bottom, PC_BLACK);
1643 int y = r.top + WD_FRAMETEXT_TOP + 1;
1644 int left0 = r.left + WD_FRAMETEXT_LEFT + 1;
1645 int right0 = r.right - WD_FRAMETEXT_RIGHT - 1;
1646 DrawString(left0, right0, y, this->data[0], TC_LIGHT_BLUE, SA_CENTER);
1647 y += FONT_HEIGHT_NORMAL + WD_PAR_VSEP_NORMAL;
1648 for (uint i = 1; i <= RATING_TOOLTIP_MAX_LINES; i++) {
1649 if (StrEmpty(this->data[i])) break;
1650 int left = left0, right = right0;
1651 if (this->newgrf_rating_used && i >= 2 && i <= 4) {
1652 if (_current_text_dir == TD_RTL) {
1653 right -= RATING_TOOLTIP_NEWGRF_INDENT;
1655 else {
1656 left += RATING_TOOLTIP_NEWGRF_INDENT;
1659 DrawString(left, right, y, this->data[i], TC_BLACK);
1660 y += FONT_HEIGHT_NORMAL + WD_PAR_VSEP_NORMAL;
1664 virtual void OnMouseLoop()
1666 if (!_cursor.in_window || !_mouse_hovering) {
1667 delete this;
1672 void GuiShowStationRatingTooltip(Window *parent, const Station *st, const CargoSpec *cs) {
1673 DeleteWindowById(WC_STATION_RATING_TOOLTIP, 0);
1674 new StationRatingTooltipWindow(parent, st, cs);