OpenTTD Source 20250924-master-gbec4e71d53
toolbar_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 "gui.h"
12#include "window_gui.h"
13#include "window_func.h"
14#include "viewport_func.h"
15#include "command_func.h"
16#include "dropdown_type.h"
17#include "dropdown_func.h"
18#include "house.h"
19#include "vehicle_gui.h"
20#include "rail_gui.h"
21#include "road.h"
22#include "road_gui.h"
23#include "vehicle_func.h"
24#include "sound_func.h"
25#include "terraform_gui.h"
26#include "strings_func.h"
27#include "company_func.h"
28#include "company_gui.h"
29#include "vehicle_base.h"
30#include "cheat_func.h"
31#include "transparency_gui.h"
32#include "screenshot.h"
33#include "signs_func.h"
34#include "fios.h"
35#include "console_gui.h"
36#include "news_gui.h"
37#include "ai/ai_gui.hpp"
38#include "game/game_gui.hpp"
39#include "script/script_gui.h"
40#include "tilehighlight_func.h"
41#include "smallmap_gui.h"
42#include "graph_gui.h"
43#include "textbuf_gui.h"
45#include "newgrf_debug.h"
46#include "hotkeys.h"
47#include "engine_base.h"
48#include "highscore.h"
49#include "game/game.hpp"
50#include "goal_base.h"
51#include "story_base.h"
52#include "toolbar_gui.h"
53#include "framerate_type.h"
54#include "screenshot_gui.h"
55#include "misc_cmd.h"
56#include "league_gui.h"
57#include "league_base.h"
58#include "timer/timer.h"
59#include "timer/timer_window.h"
61#include "help_gui.h"
63
65
66#include "network/network.h"
67#include "network/network_gui.h"
69
70#include "table/strings.h"
71
73
74#include "safeguards.h"
75
76
79
80RailType _last_built_railtype;
81RoadType _last_built_roadtype;
82RoadType _last_built_tramtype;
83
85enum ToolbarMode : uint8_t {
86 TB_NORMAL,
87 TB_UPPER,
88 TB_LOWER
89};
90
92enum CallBackFunction : uint8_t {
93 CBF_NONE,
94 CBF_PLACE_SIGN,
95 CBF_PLACE_LANDINFO,
96};
97
99
103class DropDownListCompanyItem : public DropDownIcon<DropDownIcon<DropDownString<DropDownListItem>, true>> {
104public:
105 DropDownListCompanyItem(CompanyID company, bool shaded) : DropDownIcon<DropDownIcon<DropDownString<DropDownListItem>, true>>(SPR_COMPANY_ICON, GetCompanyPalette(company), NetworkCanJoinCompany(company) ? SPR_EMPTY : SPR_LOCK, PAL_NONE, GetString(STR_COMPANY_NAME_COMPANY_NUM, company, company), company.base(), false, shaded)
106 {
107 }
108};
109
117static void PopupMainToolbarMenu(Window *w, WidgetID widget, DropDownList &&list, int def)
118{
119 ShowDropDownList(w, std::move(list), def, widget, 0, _settings_client.gui.toolbar_dropdown_autoselect);
120}
121
128static void PopupMainToolbarMenu(Window *w, WidgetID widget, const std::initializer_list<StringID> &strings)
129{
130 DropDownList list;
131 int i = 0;
132 for (StringID string : strings) {
133 if (string == STR_NULL) {
134 list.push_back(MakeDropDownListDividerItem());
135 } else {
136 list.push_back(MakeDropDownListStringItem(string, i));
137 i++;
138 }
139 }
140 PopupMainToolbarMenu(w, widget, std::move(list), 0);
141}
142
144static const int CTMN_CLIENT_LIST = -1;
145static const int CTMN_SPECTATE = -2;
146static const int CTMN_SPECTATOR = -3;
147
154static void PopupMainCompanyToolbMenu(Window *w, WidgetID widget, CompanyMask grey = {})
155{
156 DropDownList list;
157
158 switch (widget) {
159 case WID_TN_COMPANIES:
160 if (!_networking) break;
161
162 /* Add the client list button for the companies menu */
163 list.push_back(MakeDropDownListStringItem(STR_NETWORK_COMPANY_LIST_CLIENT_LIST, CTMN_CLIENT_LIST));
164
166 list.push_back(MakeDropDownListStringItem(STR_NETWORK_COMPANY_LIST_SPECTATE, CTMN_SPECTATE));
167 }
168 break;
169 case WID_TN_STORY:
170 list.push_back(MakeDropDownListStringItem(STR_STORY_BOOK_SPECTATOR, CTMN_SPECTATOR));
171 break;
172
173 case WID_TN_GOAL:
174 list.push_back(MakeDropDownListStringItem(STR_GOALS_SPECTATOR, CTMN_SPECTATOR));
175 break;
176 }
177
178 for (CompanyID c = CompanyID::Begin(); c < MAX_COMPANIES; ++c) {
179 if (!Company::IsValidID(c)) continue;
180 list.push_back(std::make_unique<DropDownListCompanyItem>(c, grey.Test(c)));
181 }
182
184}
185
186static ToolbarMode _toolbar_mode;
187
188static CallBackFunction SelectSignTool()
189{
190 if (_last_started_action == CBF_PLACE_SIGN) {
192 return CBF_NONE;
193 } else {
194 SetObjectToPlace(SPR_CURSOR_SIGN, PAL_NONE, HT_RECT, WC_MAIN_TOOLBAR, 0);
195 return CBF_PLACE_SIGN;
196 }
197}
198
199/* --- Pausing --- */
200
201static CallBackFunction ToolbarPauseClick(Window *)
202{
203 if (_networking && !_network_server) return CBF_NONE; // only server can pause the game
204
207 }
208 return CBF_NONE;
209}
210
217{
218 if (_networking) return CBF_NONE; // no fast forward in network game
219
220 ChangeGameSpeed(_game_speed == 100);
221
222 SndClickBeep();
223 return CBF_NONE;
224}
225
229enum OptionMenuEntries : uint8_t {
230 OME_GAMEOPTIONS,
231 OME_AI_SETTINGS,
232 OME_GAMESCRIPT_SETTINGS,
233 OME_NEWGRFSETTINGS,
234 OME_SANDBOX,
235 OME_TRANSPARENCIES,
236 OME_SHOW_TOWNNAMES,
237 OME_SHOW_STATIONNAMES,
238 OME_SHOW_STATIONNAMES_TRAIN,
239 OME_SHOW_STATIONNAMES_LORRY,
240 OME_SHOW_STATIONNAMES_BUS,
241 OME_SHOW_STATIONNAMES_SHIP,
242 OME_SHOW_STATIONNAMES_PLANE,
243 OME_SHOW_STATIONNAMES_GHOST,
244 OME_SHOW_WAYPOINTNAMES,
245 OME_SHOW_SIGNS,
246 OME_SHOW_COMPETITOR_SIGNS,
247 OME_FULL_ANIMATION,
248 OME_FULL_DETAILS,
249 OME_TRANSPARENTBUILDINGS,
250 OME_SHOW_STATIONSIGNS,
251};
252
260{
261 DropDownList list;
262 list.push_back(MakeDropDownListStringItem(STR_SETTINGS_MENU_GAME_OPTIONS, OME_GAMEOPTIONS));
263 /* Changes to the per-AI settings don't get send from the server to the clients. Clients get
264 * the settings once they join but never update it. As such don't show the window at all
265 * to network clients. */
267 list.push_back(MakeDropDownListStringItem(STR_SETTINGS_MENU_AI_SETTINGS, OME_AI_SETTINGS));
268 list.push_back(MakeDropDownListStringItem(STR_SETTINGS_MENU_GAMESCRIPT_SETTINGS, OME_GAMESCRIPT_SETTINGS));
269 }
270 list.push_back(MakeDropDownListStringItem(STR_SETTINGS_MENU_NEWGRF_SETTINGS, OME_NEWGRFSETTINGS));
271 if (_game_mode != GM_EDITOR && !_networking) {
272 list.push_back(MakeDropDownListStringItem(STR_SETTINGS_MENU_SANDBOX_OPTIONS, OME_SANDBOX));
273 }
274 list.push_back(MakeDropDownListStringItem(STR_SETTINGS_MENU_TRANSPARENCY_OPTIONS, OME_TRANSPARENCIES));
275 list.push_back(MakeDropDownListDividerItem());
276 list.push_back(MakeDropDownListCheckedItem(HasBit(_display_opt, DO_SHOW_TOWN_NAMES), STR_SETTINGS_MENU_TOWN_NAMES_DISPLAYED, OME_SHOW_TOWNNAMES));
277 list.push_back(MakeDropDownListCheckedItem(HasBit(_display_opt, DO_SHOW_STATION_NAMES), STR_SETTINGS_MENU_STATION_NAMES_DISPLAYED, OME_SHOW_STATIONNAMES));
278 list.push_back(MakeDropDownListCheckedItem(_facility_display_opt.Test(StationFacility::Train), STR_SETTINGS_MENU_STATION_NAMES_TRAIN, OME_SHOW_STATIONNAMES_TRAIN, false, false, 1));
279 list.push_back(MakeDropDownListCheckedItem(_facility_display_opt.Test(StationFacility::TruckStop), STR_SETTINGS_MENU_STATION_NAMES_LORRY, OME_SHOW_STATIONNAMES_LORRY, false, false, 1));
280 list.push_back(MakeDropDownListCheckedItem(_facility_display_opt.Test(StationFacility::BusStop), STR_SETTINGS_MENU_STATION_NAMES_BUS, OME_SHOW_STATIONNAMES_BUS, false, false, 1));
281 list.push_back(MakeDropDownListCheckedItem(_facility_display_opt.Test(StationFacility::Dock), STR_SETTINGS_MENU_STATION_NAMES_SHIP, OME_SHOW_STATIONNAMES_SHIP, false, false, 1));
282 list.push_back(MakeDropDownListCheckedItem(_facility_display_opt.Test(StationFacility::Airport), STR_SETTINGS_MENU_STATION_NAMES_PLANE, OME_SHOW_STATIONNAMES_PLANE, false, false, 1));
283 list.push_back(MakeDropDownListCheckedItem(_facility_display_opt.Test(STATION_FACILITY_GHOST), STR_SETTINGS_MENU_STATION_NAMES_GHOST, OME_SHOW_STATIONNAMES_GHOST, false, false, 1));
284 list.push_back(MakeDropDownListCheckedItem(HasBit(_display_opt, DO_SHOW_WAYPOINT_NAMES), STR_SETTINGS_MENU_WAYPOINTS_DISPLAYED, OME_SHOW_WAYPOINTNAMES));
285 list.push_back(MakeDropDownListCheckedItem(HasBit(_display_opt, DO_SHOW_SIGNS), STR_SETTINGS_MENU_SIGNS_DISPLAYED, OME_SHOW_SIGNS));
286 list.push_back(MakeDropDownListCheckedItem(HasBit(_display_opt, DO_SHOW_COMPETITOR_SIGNS), STR_SETTINGS_MENU_SHOW_COMPETITOR_SIGNS, OME_SHOW_COMPETITOR_SIGNS));
287 list.push_back(MakeDropDownListCheckedItem(HasBit(_display_opt, DO_FULL_ANIMATION), STR_SETTINGS_MENU_FULL_ANIMATION, OME_FULL_ANIMATION));
288 list.push_back(MakeDropDownListCheckedItem(HasBit(_display_opt, DO_FULL_DETAIL), STR_SETTINGS_MENU_FULL_DETAIL, OME_FULL_DETAILS));
289 list.push_back(MakeDropDownListCheckedItem(IsTransparencySet(TO_HOUSES), STR_SETTINGS_MENU_TRANSPARENT_BUILDINGS, OME_TRANSPARENTBUILDINGS));
290 list.push_back(MakeDropDownListCheckedItem(IsTransparencySet(TO_SIGNS), STR_SETTINGS_MENU_TRANSPARENT_SIGNS, OME_SHOW_STATIONSIGNS));
291
293 return CBF_NONE;
294}
295
303{
304 switch (index) {
305 case OME_GAMEOPTIONS: ShowGameOptions(); return CBF_NONE;
306 case OME_AI_SETTINGS: ShowAIConfigWindow(); return CBF_NONE;
307 case OME_GAMESCRIPT_SETTINGS: ShowGSConfigWindow(); return CBF_NONE;
308 case OME_NEWGRFSETTINGS: ShowNewGRFSettings(!_networking && _settings_client.gui.UserIsAllowedToChangeNewGRFs(), true, true, _grfconfig); return CBF_NONE;
309 case OME_SANDBOX: ShowCheatWindow(); break;
310 case OME_TRANSPARENCIES: ShowTransparencyToolbar(); break;
311
312 case OME_SHOW_TOWNNAMES: ToggleBit(_display_opt, DO_SHOW_TOWN_NAMES); break;
313 case OME_SHOW_STATIONNAMES: ToggleBit(_display_opt, DO_SHOW_STATION_NAMES); break;
314 case OME_SHOW_STATIONNAMES_TRAIN: _facility_display_opt.Flip(StationFacility::Train); break;
315 case OME_SHOW_STATIONNAMES_LORRY: _facility_display_opt.Flip(StationFacility::TruckStop); break;
316 case OME_SHOW_STATIONNAMES_BUS: _facility_display_opt.Flip(StationFacility::BusStop); break;
317 case OME_SHOW_STATIONNAMES_SHIP: _facility_display_opt.Flip(StationFacility::Dock); break;
318 case OME_SHOW_STATIONNAMES_PLANE: _facility_display_opt.Flip(StationFacility::Airport); break;
319 case OME_SHOW_STATIONNAMES_GHOST: _facility_display_opt.Flip(STATION_FACILITY_GHOST); break;
320 case OME_SHOW_WAYPOINTNAMES: ToggleBit(_display_opt, DO_SHOW_WAYPOINT_NAMES); break;
321 case OME_SHOW_SIGNS: ToggleBit(_display_opt, DO_SHOW_SIGNS); break;
322 case OME_SHOW_COMPETITOR_SIGNS:
325 break;
326 case OME_FULL_ANIMATION: ToggleBit(_display_opt, DO_FULL_ANIMATION); CheckBlitter(); break;
327 case OME_FULL_DETAILS: ToggleBit(_display_opt, DO_FULL_DETAIL); break;
328 case OME_TRANSPARENTBUILDINGS: ToggleTransparency(TO_HOUSES); break;
329 case OME_SHOW_STATIONSIGNS: ToggleTransparency(TO_SIGNS); break;
330 }
332 return CBF_NONE;
333}
334
339 SLEME_SAVE_SCENARIO = 0,
340 SLEME_LOAD_SCENARIO,
341 SLEME_SAVE_HEIGHTMAP,
342 SLEME_LOAD_HEIGHTMAP,
343 SLEME_EXIT_TOINTRO,
344 SLEME_EXIT_GAME,
345};
346
351 SLNME_SAVE_GAME = 0,
352 SLNME_LOAD_GAME,
353 SLNME_EXIT_TOINTRO,
354 SLNME_EXIT_GAME,
355};
356
364{
365 PopupMainToolbarMenu(w, WID_TN_SAVE, {STR_FILE_MENU_SAVE_GAME, STR_FILE_MENU_LOAD_GAME, STR_FILE_MENU_QUIT_GAME,
366 STR_NULL, STR_FILE_MENU_EXIT});
367 return CBF_NONE;
368}
369
377{
378 PopupMainToolbarMenu(w, WID_TE_SAVE, {STR_SCENEDIT_FILE_MENU_SAVE_SCENARIO, STR_SCENEDIT_FILE_MENU_LOAD_SCENARIO,
379 STR_SCENEDIT_FILE_MENU_SAVE_HEIGHTMAP, STR_SCENEDIT_FILE_MENU_LOAD_HEIGHTMAP,
380 STR_SCENEDIT_FILE_MENU_QUIT_EDITOR, STR_NULL, STR_SCENEDIT_FILE_MENU_QUIT});
381 return CBF_NONE;
382}
383
391{
392 if (_game_mode == GM_EDITOR) {
393 switch (index) {
394 case SLEME_SAVE_SCENARIO: ShowSaveLoadDialog(FT_SCENARIO, SLO_SAVE); break;
395 case SLEME_LOAD_SCENARIO: ShowSaveLoadDialog(FT_SCENARIO, SLO_LOAD); break;
396 case SLEME_SAVE_HEIGHTMAP: ShowSaveLoadDialog(FT_HEIGHTMAP, SLO_SAVE); break;
397 case SLEME_LOAD_HEIGHTMAP: ShowSaveLoadDialog(FT_HEIGHTMAP, SLO_LOAD); break;
398 case SLEME_EXIT_TOINTRO: AskExitToGameMenu(); break;
399 case SLEME_EXIT_GAME: HandleExitGameRequest(); break;
400 }
401 } else {
402 switch (index) {
403 case SLNME_SAVE_GAME: ShowSaveLoadDialog(FT_SAVEGAME, SLO_SAVE); break;
404 case SLNME_LOAD_GAME: ShowSaveLoadDialog(FT_SAVEGAME, SLO_LOAD); break;
405 case SLNME_EXIT_TOINTRO: AskExitToGameMenu(); break;
406 case SLNME_EXIT_GAME: HandleExitGameRequest(); break;
407 }
408 }
409 return CBF_NONE;
410}
411
412/* --- Map button menu --- */
413
414enum MapMenuEntries : uint8_t {
415 MME_SHOW_SMALLMAP = 0,
416 MME_SHOW_EXTRAVIEWPORTS,
417 MME_SHOW_LINKGRAPH,
418 MME_SHOW_SIGNLISTS,
419 MME_SHOW_TOWNDIRECTORY,
420 MME_SHOW_INDUSTRYDIRECTORY,
421};
422
423static CallBackFunction ToolbarMapClick(Window *w)
424{
425 DropDownList list;
426 list.push_back(MakeDropDownListStringItem(STR_MAP_MENU_MAP_OF_WORLD, MME_SHOW_SMALLMAP));
427 list.push_back(MakeDropDownListStringItem(STR_MAP_MENU_EXTRA_VIEWPORT, MME_SHOW_EXTRAVIEWPORTS));
428 list.push_back(MakeDropDownListStringItem(STR_MAP_MENU_LINGRAPH_LEGEND, MME_SHOW_LINKGRAPH));
429 list.push_back(MakeDropDownListStringItem(STR_MAP_MENU_SIGN_LIST, MME_SHOW_SIGNLISTS));
430 PopupMainToolbarMenu(w, WID_TN_SMALL_MAP, std::move(list), 0);
431 return CBF_NONE;
432}
433
434static CallBackFunction ToolbarScenMapTownDir(Window *w)
435{
436 DropDownList list;
437 list.push_back(MakeDropDownListStringItem(STR_MAP_MENU_MAP_OF_WORLD, MME_SHOW_SMALLMAP));
438 list.push_back(MakeDropDownListStringItem(STR_MAP_MENU_EXTRA_VIEWPORT, MME_SHOW_EXTRAVIEWPORTS));
439 list.push_back(MakeDropDownListStringItem(STR_MAP_MENU_SIGN_LIST, MME_SHOW_SIGNLISTS));
440 list.push_back(MakeDropDownListStringItem(STR_TOWN_MENU_TOWN_DIRECTORY, MME_SHOW_TOWNDIRECTORY));
441 list.push_back(MakeDropDownListStringItem(STR_INDUSTRY_MENU_INDUSTRY_DIRECTORY, MME_SHOW_INDUSTRYDIRECTORY));
442 PopupMainToolbarMenu(w, WID_TE_SMALL_MAP, std::move(list), 0);
443 return CBF_NONE;
444}
445
453{
454 switch (index) {
455 case MME_SHOW_SMALLMAP: ShowSmallMap(); break;
456 case MME_SHOW_EXTRAVIEWPORTS: ShowExtraViewportWindow(); break;
457 case MME_SHOW_LINKGRAPH: ShowLinkGraphLegend(); break;
458 case MME_SHOW_SIGNLISTS: ShowSignList(); break;
459 case MME_SHOW_TOWNDIRECTORY: ShowTownDirectory(); break;
460 case MME_SHOW_INDUSTRYDIRECTORY: ShowIndustryDirectory(); break;
461 }
462 return CBF_NONE;
463}
464
465/* --- Town button menu --- */
466
467enum TownMenuEntries {
468 TME_SHOW_DIRECTORY = 0,
469 TME_SHOW_FOUND_TOWN,
470 TME_SHOW_PLACE_HOUSES,
471};
472
473static CallBackFunction ToolbarTownClick(Window *w)
474{
475 DropDownList list;
476 list.push_back(MakeDropDownListStringItem(STR_TOWN_MENU_TOWN_DIRECTORY, TME_SHOW_DIRECTORY));
477 if (_settings_game.economy.found_town != TF_FORBIDDEN) list.push_back(MakeDropDownListStringItem(STR_TOWN_MENU_FOUND_TOWN, TME_SHOW_FOUND_TOWN));
478 if (_settings_game.economy.place_houses != PH_FORBIDDEN) list.push_back(MakeDropDownListStringItem(STR_SCENEDIT_TOWN_MENU_PACE_HOUSE, TME_SHOW_PLACE_HOUSES));
479
480 PopupMainToolbarMenu(w, WID_TN_TOWNS, std::move(list), 0);
481
482 return CBF_NONE;
483}
484
492{
493 switch (index) {
494 case TME_SHOW_DIRECTORY: ShowTownDirectory(); break;
495 case TME_SHOW_FOUND_TOWN: // Setting could be changed when the dropdown was open
496 if (_settings_game.economy.found_town != TF_FORBIDDEN) ShowFoundTownWindow();
497 break;
498 case TME_SHOW_PLACE_HOUSES: // Setting could be changed when the dropdown was open
499 if (_settings_game.economy.place_houses != PH_FORBIDDEN) ShowBuildHousePicker(nullptr);
500 break;
501 }
502 return CBF_NONE;
503}
504
505/* --- Subidies button menu --- */
506
507static CallBackFunction ToolbarSubsidiesClick(Window *w)
508{
509 PopupMainToolbarMenu(w, WID_TN_SUBSIDIES, {STR_SUBSIDIES_MENU_SUBSIDIES});
510 return CBF_NONE;
511}
512
519{
520 ShowSubsidiesList();
521 return CBF_NONE;
522}
523
524/* --- Stations button menu --- */
525
526static CallBackFunction ToolbarStationsClick(Window *w)
527{
529 return CBF_NONE;
530}
531
539{
541 return CBF_NONE;
542}
543
544/* --- Finances button menu --- */
545
546static CallBackFunction ToolbarFinancesClick(Window *w)
547{
549 return CBF_NONE;
550}
551
559{
561 return CBF_NONE;
562}
563
564/* --- Company's button menu --- */
565
566static CallBackFunction ToolbarCompaniesClick(Window *w)
567{
569 return CBF_NONE;
570}
571
579{
580 if (_networking) {
581 switch (index) {
582 case CTMN_CLIENT_LIST:
583 ShowClientList();
584 return CBF_NONE;
585
586 case CTMN_SPECTATE:
587 if (_network_server) {
590 } else {
592 }
593 return CBF_NONE;
594 }
595 }
596 ShowCompany((CompanyID)index);
597 return CBF_NONE;
598}
599
600/* --- Story button menu --- */
601
602static CallBackFunction ToolbarStoryClick(Window *w)
603{
605 return CBF_NONE;
606}
607
615{
616 ShowStoryBook(index == CTMN_SPECTATOR ? CompanyID::Invalid() : (CompanyID)index);
617 return CBF_NONE;
618}
619
620/* --- Goal button menu --- */
621
622static CallBackFunction ToolbarGoalClick(Window *w)
623{
625 return CBF_NONE;
626}
627
635{
636 ShowGoalsList(index == CTMN_SPECTATOR ? CompanyID::Invalid() : (CompanyID)index);
637 return CBF_NONE;
638}
639
640/* --- Graphs and League Table button menu --- */
641
646static const int GRMN_OPERATING_PROFIT_GRAPH = -1;
647static const int GRMN_INCOME_GRAPH = -2;
648static const int GRMN_DELIVERED_CARGO_GRAPH = -3;
649static const int GRMN_PERFORMANCE_HISTORY_GRAPH = -4;
650static const int GRMN_COMPANY_VALUE_GRAPH = -5;
651static const int GRMN_CARGO_PAYMENT_RATES = -6;
652static const int LTMN_PERFORMANCE_LEAGUE = -7;
653static const int LTMN_PERFORMANCE_RATING = -8;
654static const int LTMN_HIGHSCORE = -9;
655
656static void AddDropDownLeagueTableOptions(DropDownList &list)
657{
658 if (LeagueTable::GetNumItems() > 0) {
659 for (LeagueTable *lt : LeagueTable::Iterate()) {
660 list.push_back(MakeDropDownListStringItem(lt->title.GetDecodedString(), lt->index.base()));
661 }
662 } else {
663 list.push_back(MakeDropDownListStringItem(STR_GRAPH_MENU_COMPANY_LEAGUE_TABLE, LTMN_PERFORMANCE_LEAGUE));
664 list.push_back(MakeDropDownListStringItem(STR_GRAPH_MENU_DETAILED_PERFORMANCE_RATING, LTMN_PERFORMANCE_RATING));
665 if (!_networking) {
666 list.push_back(MakeDropDownListStringItem(STR_GRAPH_MENU_HIGHSCORE, LTMN_HIGHSCORE));
667 }
668 }
669}
670
671static CallBackFunction ToolbarGraphsClick(Window *w)
672{
673 DropDownList list;
674
675 list.push_back(MakeDropDownListStringItem(STR_GRAPH_MENU_OPERATING_PROFIT_GRAPH, GRMN_OPERATING_PROFIT_GRAPH));
676 list.push_back(MakeDropDownListStringItem(STR_GRAPH_MENU_INCOME_GRAPH, GRMN_INCOME_GRAPH));
677 list.push_back(MakeDropDownListStringItem(STR_GRAPH_MENU_DELIVERED_CARGO_GRAPH, GRMN_DELIVERED_CARGO_GRAPH));
678 list.push_back(MakeDropDownListStringItem(STR_GRAPH_MENU_PERFORMANCE_HISTORY_GRAPH, GRMN_PERFORMANCE_HISTORY_GRAPH));
679 list.push_back(MakeDropDownListStringItem(STR_GRAPH_MENU_COMPANY_VALUE_GRAPH, GRMN_COMPANY_VALUE_GRAPH));
680 list.push_back(MakeDropDownListStringItem(STR_GRAPH_MENU_CARGO_PAYMENT_RATES, GRMN_CARGO_PAYMENT_RATES));
681
682 if (_toolbar_mode != TB_NORMAL) AddDropDownLeagueTableOptions(list);
683
685 return CBF_NONE;
686}
687
688static CallBackFunction ToolbarLeagueClick(Window *w)
689{
690 DropDownList list;
691
692 AddDropDownLeagueTableOptions(list);
693
694 int selected = list[0]->result;
696 return CBF_NONE;
697}
698
706{
707 switch (index) {
708 case GRMN_OPERATING_PROFIT_GRAPH: ShowOperatingProfitGraph(); break;
709 case GRMN_INCOME_GRAPH: ShowIncomeGraph(); break;
710 case GRMN_DELIVERED_CARGO_GRAPH: ShowDeliveredCargoGraph(); break;
711 case GRMN_PERFORMANCE_HISTORY_GRAPH: ShowPerformanceHistoryGraph(); break;
712 case GRMN_COMPANY_VALUE_GRAPH: ShowCompanyValueGraph(); break;
713 case GRMN_CARGO_PAYMENT_RATES: ShowCargoPaymentRates(); break;
714 case LTMN_PERFORMANCE_LEAGUE: ShowPerformanceLeagueTable(); break;
715 case LTMN_PERFORMANCE_RATING: ShowPerformanceRatingDetail(); break;
716 case LTMN_HIGHSCORE: ShowHighscoreTable(); break;
717 default: {
718 if (LeagueTable::IsValidID(index)) {
719 ShowScriptLeagueTable((LeagueTableID)index);
720 }
721 }
722 }
723 return CBF_NONE;
724}
725
726
727
728/* --- Industries button menu --- */
729
730static CallBackFunction ToolbarIndustryClick(Window *w)
731{
732 /* Disable build-industry menu if we are a spectator */
734 PopupMainToolbarMenu(w, WID_TN_INDUSTRIES, {STR_INDUSTRY_MENU_INDUSTRY_DIRECTORY, STR_INDUSTRY_MENU_INDUSTRY_CHAIN});
735 } else {
736 PopupMainToolbarMenu(w, WID_TN_INDUSTRIES, {STR_INDUSTRY_MENU_INDUSTRY_DIRECTORY, STR_INDUSTRY_MENU_INDUSTRY_CHAIN, STR_INDUSTRY_MENU_FUND_NEW_INDUSTRY});
737 }
738 return CBF_NONE;
739}
740
748{
749 switch (index) {
750 case 0: ShowIndustryDirectory(); break;
751 case 1: ShowIndustryCargoesWindow(); break;
752 case 2: ShowBuildIndustryWindow(); break;
753 }
754 return CBF_NONE;
755}
756
757/* --- Trains button menu + 1 helper function for all vehicles. --- */
758
759static void ToolbarVehicleClick(Window *w, VehicleType veh)
760{
761 CompanyMask dis{};
762
763 for (const Company *c : Company::Iterate()) {
764 if (c->group_all[veh].num_vehicle == 0) dis.Set(c->index);
765 }
767}
768
769
770static CallBackFunction ToolbarTrainClick(Window *w)
771{
772 ToolbarVehicleClick(w, VEH_TRAIN);
773 return CBF_NONE;
774}
775
783{
784 ShowVehicleListWindow((CompanyID)index, VEH_TRAIN);
785 return CBF_NONE;
786}
787
788/* --- Road vehicle button menu --- */
789
790static CallBackFunction ToolbarRoadClick(Window *w)
791{
792 ToolbarVehicleClick(w, VEH_ROAD);
793 return CBF_NONE;
794}
795
803{
804 ShowVehicleListWindow((CompanyID)index, VEH_ROAD);
805 return CBF_NONE;
806}
807
808/* --- Ship button menu --- */
809
810static CallBackFunction ToolbarShipClick(Window *w)
811{
812 ToolbarVehicleClick(w, VEH_SHIP);
813 return CBF_NONE;
814}
815
823{
824 ShowVehicleListWindow((CompanyID)index, VEH_SHIP);
825 return CBF_NONE;
826}
827
828/* --- Aircraft button menu --- */
829
830static CallBackFunction ToolbarAirClick(Window *w)
831{
832 ToolbarVehicleClick(w, VEH_AIRCRAFT);
833 return CBF_NONE;
834}
835
843{
844 ShowVehicleListWindow((CompanyID)index, VEH_AIRCRAFT);
845 return CBF_NONE;
846}
847
848/* --- Zoom in button --- */
849
850static CallBackFunction ToolbarZoomInClick(Window *w)
851{
853 w->HandleButtonClick((_game_mode == GM_EDITOR) ? (WidgetID)WID_TE_ZOOM_IN : (WidgetID)WID_TN_ZOOM_IN);
854 }
855 return CBF_NONE;
856}
857
858/* --- Zoom out button --- */
859
860static CallBackFunction ToolbarZoomOutClick(Window *w)
861{
863 w->HandleButtonClick((_game_mode == GM_EDITOR) ? (WidgetID)WID_TE_ZOOM_OUT : (WidgetID)WID_TN_ZOOM_OUT);
864 }
865 return CBF_NONE;
866}
867
868/* --- Rail button menu --- */
869
870static CallBackFunction ToolbarBuildRailClick(Window *w)
871{
873 return CBF_NONE;
874}
875
883{
884 _last_built_railtype = (RailType)index;
885 ShowBuildRailToolbar(_last_built_railtype);
886 return CBF_NONE;
887}
888
889/* --- Road button menu --- */
890
891static CallBackFunction ToolbarBuildRoadClick(Window *w)
892{
893 ShowDropDownList(w, GetRoadTypeDropDownList(RTTB_ROAD), _last_built_roadtype, WID_TN_ROADS, 140, _settings_client.gui.toolbar_dropdown_autoselect);
894 return CBF_NONE;
895}
896
904{
905 _last_built_roadtype = (RoadType)index;
906 ShowBuildRoadToolbar(_last_built_roadtype);
907 return CBF_NONE;
908}
909
910/* --- Tram button menu --- */
911
912static CallBackFunction ToolbarBuildTramClick(Window *w)
913{
914 ShowDropDownList(w, GetRoadTypeDropDownList(RTTB_TRAM), _last_built_tramtype, WID_TN_TRAMS, 140, _settings_client.gui.toolbar_dropdown_autoselect);
915 return CBF_NONE;
916}
917
925{
926 _last_built_tramtype = (RoadType)index;
927 ShowBuildRoadToolbar(_last_built_tramtype);
928 return CBF_NONE;
929}
930
931/* --- Water button menu --- */
932
933static CallBackFunction ToolbarBuildWaterClick(Window *w)
934{
935 DropDownList list;
936 list.push_back(MakeDropDownListIconItem(SPR_IMG_BUILD_CANAL, PAL_NONE, STR_WATERWAYS_MENU_WATERWAYS_CONSTRUCTION, 0));
938 return CBF_NONE;
939}
940
947{
949 return CBF_NONE;
950}
951
952/* --- Airport button menu --- */
953
954static CallBackFunction ToolbarBuildAirClick(Window *w)
955{
956 DropDownList list;
957 list.push_back(MakeDropDownListIconItem(SPR_IMG_AIRPORT, PAL_NONE, STR_AIRCRAFT_MENU_AIRPORT_CONSTRUCTION, 0));
959 return CBF_NONE;
960}
961
968{
970 return CBF_NONE;
971}
972
973/* --- Forest button menu --- */
974
975static CallBackFunction ToolbarForestClick(Window *w)
976{
977 DropDownList list;
978 list.push_back(MakeDropDownListIconItem(SPR_IMG_LANDSCAPING, PAL_NONE, STR_LANDSCAPING_MENU_LANDSCAPING, 0));
979 list.push_back(MakeDropDownListIconItem(SPR_IMG_PLANTTREES, PAL_NONE, STR_LANDSCAPING_MENU_PLANT_TREES, 1));
980 list.push_back(MakeDropDownListIconItem(SPR_IMG_SIGN, PAL_NONE, STR_LANDSCAPING_MENU_PLACE_SIGN, 2));
982 return CBF_NONE;
983}
984
992{
993 switch (index) {
994 case 0: ShowTerraformToolbar(); break;
995 case 1: ShowBuildTreesToolbar(); break;
996 case 2: return SelectSignTool();
997 }
998 return CBF_NONE;
999}
1000
1001/* --- Music button menu --- */
1002
1003static CallBackFunction ToolbarMusicClick(Window *w)
1004{
1005 PopupMainToolbarMenu(w, _game_mode == GM_EDITOR ? (WidgetID)WID_TE_MUSIC_SOUND : (WidgetID)WID_TN_MUSIC_SOUND, {STR_TOOLBAR_SOUND_MUSIC});
1006 return CBF_NONE;
1007}
1008
1015{
1016 ShowMusicWindow();
1017 return CBF_NONE;
1018}
1019
1020/* --- Newspaper button menu --- */
1021
1022static CallBackFunction ToolbarNewspaperClick(Window *w)
1023{
1024 PopupMainToolbarMenu(w, WID_TN_MESSAGES, {STR_NEWS_MENU_LAST_MESSAGE_NEWS_REPORT, STR_NEWS_MENU_MESSAGE_HISTORY_MENU, STR_NEWS_MENU_DELETE_ALL_MESSAGES});
1025 return CBF_NONE;
1026}
1027
1035{
1036 switch (index) {
1037 case 0: ShowLastNewsMessage(); break;
1038 case 1: ShowMessageHistory(); break;
1039 case 2: DeleteAllMessages(); break;
1040 }
1041 return CBF_NONE;
1042}
1043
1044/* --- Help button menu --- */
1045
1046static CallBackFunction PlaceLandBlockInfo()
1047{
1048 if (_last_started_action == CBF_PLACE_LANDINFO) {
1050 return CBF_NONE;
1051 } else {
1052 SetObjectToPlace(SPR_CURSOR_QUERY, PAL_NONE, HT_RECT, WC_MAIN_TOOLBAR, 0);
1053 return CBF_PLACE_LANDINFO;
1054 }
1055}
1056
1057static CallBackFunction ToolbarHelpClick(Window *w)
1058{
1060 PopupMainToolbarMenu(w, _game_mode == GM_EDITOR ? (WidgetID)WID_TE_HELP : (WidgetID)WID_TN_HELP, {STR_ABOUT_MENU_LAND_BLOCK_INFO,
1061 STR_ABOUT_MENU_HELP, STR_NULL, STR_ABOUT_MENU_TOGGLE_CONSOLE, STR_ABOUT_MENU_AI_DEBUG,
1062 STR_ABOUT_MENU_SCREENSHOT, STR_ABOUT_MENU_SHOW_FRAMERATE, STR_ABOUT_MENU_ABOUT_OPENTTD,
1063 STR_ABOUT_MENU_SPRITE_ALIGNER, STR_ABOUT_MENU_TOGGLE_BOUNDING_BOXES, STR_ABOUT_MENU_TOGGLE_DIRTY_BLOCKS,
1064 STR_ABOUT_MENU_TOGGLE_WIDGET_OUTLINES});
1065 } else {
1066 PopupMainToolbarMenu(w, _game_mode == GM_EDITOR ? (WidgetID)WID_TE_HELP : (WidgetID)WID_TN_HELP, {STR_ABOUT_MENU_LAND_BLOCK_INFO,
1067 STR_ABOUT_MENU_HELP, STR_NULL, STR_ABOUT_MENU_TOGGLE_CONSOLE, STR_ABOUT_MENU_AI_DEBUG,
1068 STR_ABOUT_MENU_SCREENSHOT, STR_ABOUT_MENU_SHOW_FRAMERATE, STR_ABOUT_MENU_ABOUT_OPENTTD});
1069 }
1070 return CBF_NONE;
1071}
1072
1081{
1082 extern bool _draw_bounding_boxes;
1083 /* Always allow to toggle them off */
1084 if (_settings_client.gui.newgrf_developer_tools || _draw_bounding_boxes) {
1085 _draw_bounding_boxes = !_draw_bounding_boxes;
1087 }
1088}
1089
1098{
1099 extern bool _draw_dirty_blocks;
1100 /* Always allow to toggle them off */
1101 if (_settings_client.gui.newgrf_developer_tools || _draw_dirty_blocks) {
1102 _draw_dirty_blocks = !_draw_dirty_blocks;
1104 }
1105}
1106
1112{
1113 extern bool _draw_widget_outlines;
1114 /* Always allow to toggle them off */
1115 if (_settings_client.gui.newgrf_developer_tools || _draw_widget_outlines) {
1116 _draw_widget_outlines = !_draw_widget_outlines;
1118 }
1119}
1120
1126{
1129 TimerGameEconomy::Date new_economy_date{new_calendar_date.base()};
1130
1131 /* We must set both Calendar and Economy dates to keep them in sync. Calendar first. */
1132 TimerGameCalendar::SetDate(new_calendar_date, 0);
1133
1134 /* If you open a savegame as a scenario, there may already be link graphs and/or vehicles. These use economy date. */
1136 for (auto v : Vehicle::Iterate()) v->ShiftDates(new_economy_date - TimerGameEconomy::date);
1137
1138 /* Only change the date after changing cached values above. */
1139 TimerGameEconomy::SetDate(new_economy_date, 0);
1140}
1141
1148{
1149 switch (index) {
1150 case 0: return PlaceLandBlockInfo();
1151 case 1: ShowHelpWindow(); break;
1152 case 2: IConsoleSwitch(); break;
1153 case 3: ShowScriptDebugWindow(CompanyID::Invalid(), _ctrl_pressed); break;
1154 case 4: ShowScreenshotWindow(); break;
1155 case 5: ShowFramerateWindow(); break;
1156 case 6: ShowAboutWindow(); break;
1157 case 7: ShowSpriteAlignerWindow(); break;
1158 case 8: ToggleBoundingBoxes(); break;
1159 case 9: ToggleDirtyBlocks(); break;
1160 case 10: ToggleWidgetOutlines(); break;
1161 }
1162 return CBF_NONE;
1163}
1164
1165/* --- Switch toolbar button --- */
1166
1167static CallBackFunction ToolbarSwitchClick(Window *w)
1168{
1169 if (_toolbar_mode != TB_LOWER) {
1170 _toolbar_mode = TB_LOWER;
1171 } else {
1172 _toolbar_mode = TB_UPPER;
1173 }
1174
1175 w->ReInit();
1176 w->SetWidgetLoweredState(_game_mode == GM_EDITOR ? (WidgetID)WID_TE_SWITCH_BAR : (WidgetID)WID_TN_SWITCH_BAR, _toolbar_mode == TB_LOWER);
1177 SndClickBeep();
1178 return CBF_NONE;
1179}
1180
1181/* --- Scenario editor specific handlers. */
1182
1187{
1188 ShowQueryString(GetString(STR_JUST_INT, _settings_game.game_creation.starting_year), STR_MAPGEN_START_DATE_QUERY_CAPT, 8, w, CS_NUMERAL, QueryStringFlag::EnableDefault);
1189 return CBF_NONE;
1190}
1191
1192static CallBackFunction ToolbarScenDateBackward(Window *w)
1193{
1194 /* don't allow too fast scrolling */
1195 if (!w->flags.Test(WindowFlag::Timeout) || w->timeout_timer <= 1) {
1197 w->SetDirty();
1198
1200 }
1201 _left_button_clicked = false;
1202 return CBF_NONE;
1203}
1204
1205static CallBackFunction ToolbarScenDateForward(Window *w)
1206{
1207 /* don't allow too fast scrolling */
1208 if (!w->flags.Test(WindowFlag::Timeout) || w->timeout_timer <= 1) {
1210 w->SetDirty();
1211
1213 }
1214 _left_button_clicked = false;
1215 return CBF_NONE;
1216}
1217
1218static CallBackFunction ToolbarScenGenLand(Window *w)
1219{
1221
1223 return CBF_NONE;
1224}
1225
1226static CallBackFunction ToolbarScenGenTownClick(Window *w)
1227{
1228 PopupMainToolbarMenu(w, WID_TE_TOWN_GENERATE, {STR_SCENEDIT_TOWN_MENU_BUILD_TOWN, STR_SCENEDIT_TOWN_MENU_PACE_HOUSE});
1229 return CBF_NONE;
1230}
1231
1232static CallBackFunction ToolbarScenGenTown(int index)
1233{
1234 switch (index) {
1235 case 0: ShowFoundTownWindow(); break;
1236 case 1: ShowBuildHousePicker(nullptr); break;
1237 }
1238 return CBF_NONE;
1239}
1240
1241static CallBackFunction ToolbarScenGenIndustry(Window *w)
1242{
1244 ShowBuildIndustryWindow();
1245 return CBF_NONE;
1246}
1247
1248static CallBackFunction ToolbarScenBuildRoadClick(Window *w)
1249{
1250 ShowDropDownList(w, GetScenRoadTypeDropDownList(RTTB_ROAD), _last_built_roadtype, WID_TE_ROADS, 140, _settings_client.gui.toolbar_dropdown_autoselect);
1251 return CBF_NONE;
1252}
1253
1261{
1262 _last_built_roadtype = (RoadType)index;
1263 ShowBuildRoadScenToolbar(_last_built_roadtype);
1264 return CBF_NONE;
1265}
1266
1267static CallBackFunction ToolbarScenBuildTramClick(Window *w)
1268{
1269 ShowDropDownList(w, GetScenRoadTypeDropDownList(RTTB_TRAM), _last_built_tramtype, WID_TE_TRAMS, 140, _settings_client.gui.toolbar_dropdown_autoselect);
1270 return CBF_NONE;
1271}
1272
1280{
1281 _last_built_tramtype = (RoadType)index;
1282 ShowBuildRoadScenToolbar(_last_built_tramtype);
1283 return CBF_NONE;
1284}
1285
1286static CallBackFunction ToolbarScenBuildDocks(Window *w)
1287{
1290 return CBF_NONE;
1291}
1292
1293static CallBackFunction ToolbarScenPlantTrees(Window *w)
1294{
1296 ShowBuildTreesToolbar();
1297 return CBF_NONE;
1298}
1299
1300static CallBackFunction ToolbarScenPlaceSign(Window *w)
1301{
1303 return SelectSignTool();
1304}
1305
1306static CallBackFunction ToolbarBtn_NULL(Window *)
1307{
1308 return CBF_NONE;
1309}
1310
1311typedef CallBackFunction MenuClickedProc(int index);
1312
1313static MenuClickedProc * const _menu_clicked_procs[] = {
1314 nullptr, // 0
1315 nullptr, // 1
1316 MenuClickSettings, // 2
1317 MenuClickSaveLoad, // 3
1318 MenuClickMap, // 4
1319 MenuClickTown, // 5
1320 MenuClickSubsidies, // 6
1321 MenuClickStations, // 7
1322 MenuClickFinances, // 8
1323 MenuClickCompany, // 9
1324 MenuClickStory, // 10
1325 MenuClickGoal, // 11
1328 MenuClickIndustry, // 14
1329 MenuClickShowTrains, // 15
1330 MenuClickShowRoad, // 16
1331 MenuClickShowShips, // 17
1332 MenuClickShowAir, // 18
1333 MenuClickMap, // 19
1334 nullptr, // 20
1335 MenuClickBuildRail, // 21
1336 MenuClickBuildRoad, // 22
1337 MenuClickBuildTram, // 23
1338 MenuClickBuildWater, // 24
1339 MenuClickBuildAir, // 25
1340 MenuClickForest, // 26
1342 MenuClickNewspaper, // 28
1343 MenuClickHelp, // 29
1344};
1345
1348protected:
1349 uint spacers = 0;
1350
1351public:
1353 {
1354 }
1355
1362 {
1363 return type == WWT_IMGBTN || type == WWT_IMGBTN_2 || type == WWT_PUSHIMGBTN;
1364 }
1365
1366 void SetupSmallestSize(Window *w) override
1367 {
1368 this->smallest_x = 0; // Biggest child
1369 this->smallest_y = 0; // Biggest child
1370 this->fill_x = 1;
1371 this->fill_y = 0;
1372 this->resize_x = 1; // We only resize in this direction
1373 this->resize_y = 0; // We never resize in this direction
1374 this->spacers = 0;
1375
1376 uint nbuttons = 0;
1377 /* First initialise some variables... */
1378 for (const auto &child_wid : this->children) {
1379 child_wid->SetupSmallestSize(w);
1380 this->smallest_y = std::max(this->smallest_y, child_wid->smallest_y + child_wid->padding.Vertical());
1381 if (this->IsButton(child_wid->type)) {
1382 nbuttons++;
1383 this->smallest_x = std::max(this->smallest_x, child_wid->smallest_x + child_wid->padding.Horizontal());
1384 } else if (child_wid->type == NWID_SPACER) {
1385 this->spacers++;
1386 }
1387 }
1388
1389 /* ... then in a second pass make sure the 'current' heights are set. Won't change ever. */
1390 for (const auto &child_wid : this->children) {
1391 child_wid->current_y = this->smallest_y;
1392 if (!this->IsButton(child_wid->type)) {
1393 child_wid->current_x = child_wid->smallest_x;
1394 }
1395 }
1396
1397 /* Exclude the switcher button which is not displayed when the toolbar fits the screen. When the switch is
1398 * displayed there will be no spacers anyway. */
1399 --nbuttons;
1400
1401 /* Allow space for all buttons, and include spacers at quarter the width of buttons. */
1402 _toolbar_width = nbuttons * this->smallest_x + this->spacers * this->smallest_x / 4;
1403 }
1404
1405 void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override
1406 {
1407 assert(given_width >= this->smallest_x && given_height >= this->smallest_y);
1408
1409 this->pos_x = x;
1410 this->pos_y = y;
1411 this->current_x = given_width;
1412 this->current_y = given_height;
1413
1414 /* Figure out what are the visible buttons */
1415 uint arrangeable_count, button_count, spacer_count;
1416 const WidgetID *arrangement = GetButtonArrangement(given_width, arrangeable_count, button_count, spacer_count);
1417
1418 /* Create us ourselves a quick lookup table from WidgetID to slot. */
1419 std::map<WidgetID, uint> lookup;
1420 for (auto it = std::begin(this->children); it != std::end(this->children); ++it) {
1421 NWidgetBase *nwid = it->get();
1422 nwid->current_x = 0; /* Hide widget, it will be revealed in the next step. */
1423 if (nwid->type == NWID_SPACER) continue;
1424 NWidgetCore *nwc = dynamic_cast<NWidgetCore *>(nwid);
1425 assert(nwc != nullptr);
1426 lookup[nwc->GetIndex()] = std::distance(this->children.begin(), it);
1427 }
1428
1429 /* Now assign the widgets to their rightful place */
1430 uint position = 0; // Place to put next child relative to origin of the container.
1431 uint spacer_space = std::max(0, (int)given_width - (int)(button_count * this->smallest_x)); // Remaining spacing for 'spacer' widgets
1432 uint button_space = given_width - spacer_space; // Remaining spacing for the buttons
1433 uint spacer_i = 0;
1434 uint button_i = 0;
1435
1436 /* Index into the arrangement indices. */
1437 const WidgetID *slotp = rtl ? &arrangement[arrangeable_count - 1] : arrangement;
1438 for (uint i = 0; i < arrangeable_count; i++) {
1439 uint slot = lookup[*slotp];
1440 auto &child_wid = this->children[slot];
1441 /* If we have space to give to the spacers, do that. */
1442 if (spacer_space > 0 && slot > 0 && slot < this->children.size() - 1) {
1443 const auto &possible_spacer = this->children[slot + (rtl ? 1 : -1)];
1444 if (possible_spacer != nullptr && possible_spacer->type == NWID_SPACER) {
1445 uint add = spacer_space / (spacer_count - spacer_i);
1446 position += add;
1447 spacer_space -= add;
1448 spacer_i++;
1449 }
1450 }
1451
1452 /* Buttons can be scaled, the others not. */
1453 if (this->IsButton(child_wid->type)) {
1454 child_wid->current_x = button_space / (button_count - button_i);
1455 button_space -= child_wid->current_x;
1456 button_i++;
1457 } else {
1458 child_wid->current_x = child_wid->smallest_x;
1459 }
1460 child_wid->AssignSizePosition(sizing, x + position, y, child_wid->current_x, this->current_y, rtl);
1461 position += child_wid->current_x;
1462
1463 if (rtl) {
1464 slotp--;
1465 } else {
1466 slotp++;
1467 }
1468 }
1469 }
1470
1471 void Draw(const Window *w) override
1472 {
1473 /* Draw brown-red toolbar bg. */
1474 const Rect r = this->GetCurrentRect();
1477
1478 this->NWidgetContainer::Draw(w);
1479 }
1480
1489 virtual const WidgetID *GetButtonArrangement(uint &width, uint &arrangeable_count, uint &button_count, uint &spacer_count) const = 0;
1490};
1491
1494 const WidgetID *GetButtonArrangement(uint &width, uint &arrangeable_count, uint &button_count, uint &spacer_count) const override
1495 {
1496 static const uint SMALLEST_ARRANGEMENT = 14;
1497 static const uint BIGGEST_ARRANGEMENT = 20;
1498
1499 /* The number of buttons of each row of the toolbar should match the number of items which we want to be visible.
1500 * The total number of buttons should be equal to arrangeable_count * 2.
1501 * No bad things happen, but we could see strange behaviours if we have buttons < (arrangeable_count * 2) like a
1502 * pause button appearing on the right of the lower toolbar and weird resizing of the widgets even if there is
1503 * enough space.
1504 */
1505 static const WidgetID arrange14[] = {
1517 WID_TN_AIR,
1520 /* lower toolbar */
1535 };
1536 static const WidgetID arrange15[] = {
1547 WID_TN_AIR,
1552 /* lower toolbar */
1568 };
1569 static const WidgetID arrange16[] = {
1581 WID_TN_AIR,
1586 /* lower toolbar */
1603 };
1604 static const WidgetID arrange17[] = {
1617 WID_TN_AIR,
1622 /* lower toolbar */
1640 };
1641 static const WidgetID arrange18[] = {
1655 WID_TN_AIR,
1660 /* lower toolbar */
1679 };
1680 static const WidgetID arrange19[] = {
1694 WID_TN_AIR,
1700 /* lower toolbar */
1714 WID_TN_AIR,
1720 };
1721 static const WidgetID arrange20[] = {
1735 WID_TN_AIR,
1742 /* lower toolbar */
1756 WID_TN_AIR,
1763 };
1764 static const WidgetID arrange_all[] = {
1790 WID_TN_AIR,
1795 };
1796
1797 /* If at least BIGGEST_ARRANGEMENT fit, just spread all the buttons nicely */
1798 uint full_buttons = std::max(CeilDiv(width, this->smallest_x), SMALLEST_ARRANGEMENT);
1799 if (full_buttons > BIGGEST_ARRANGEMENT) {
1800 button_count = arrangeable_count = lengthof(arrange_all);
1801 spacer_count = this->spacers;
1802 return arrange_all;
1803 }
1804
1805 /* Introduce the split toolbar */
1806 static const WidgetID * const arrangements[] = { arrange14, arrange15, arrange16, arrange17, arrange18, arrange19, arrange20 };
1807
1808 button_count = arrangeable_count = full_buttons;
1809 spacer_count = this->spacers;
1810 return arrangements[full_buttons - SMALLEST_ARRANGEMENT] + ((_toolbar_mode == TB_LOWER) ? full_buttons : 0);
1811 }
1812};
1813
1816 std::array<uint, 2> panel_widths{};
1817
1818 void SetupSmallestSize(Window *w) override
1819 {
1821
1822 /* Find the size of panel_widths */
1823 auto it = this->panel_widths.begin();
1824 for (const auto &child_wid : this->children) {
1825 if (child_wid->type == NWID_SPACER || this->IsButton(child_wid->type)) continue;
1826
1827 assert(it != this->panel_widths.end());
1828 *it = child_wid->current_x;
1829 _toolbar_width += child_wid->current_x;
1830 ++it;
1831 }
1832 }
1833
1834 const WidgetID *GetButtonArrangement(uint &width, uint &arrangeable_count, uint &button_count, uint &spacer_count) const override
1835 {
1836 static const WidgetID arrange_all[] = {
1856 };
1857 static const WidgetID arrange_nopanel[] = {
1876 };
1877 static const WidgetID arrange_switch[] = {
1889 /* lower toolbar */
1901 };
1902
1903 /* If we can place all buttons *and* the panels, show them. */
1904 size_t min_full_width = (lengthof(arrange_all) - std::size(this->panel_widths)) * this->smallest_x + this->panel_widths[0] + this->panel_widths[1];
1905 if (width >= min_full_width) {
1906 width -= this->panel_widths[0] + this->panel_widths[1];
1907 arrangeable_count = lengthof(arrange_all);
1908 button_count = arrangeable_count - 2;
1909 spacer_count = this->spacers;
1910 return arrange_all;
1911 }
1912
1913 /* Otherwise don't show the date panel and if we can't fit half the buttons and the panels anymore, split the toolbar in two */
1914 size_t min_small_width = (lengthof(arrange_switch) - std::size(this->panel_widths)) * this->smallest_x / 2 + this->panel_widths[1];
1915 if (width > min_small_width) {
1916 width -= this->panel_widths[1];
1917 arrangeable_count = lengthof(arrange_nopanel);
1918 button_count = arrangeable_count - 1;
1919 spacer_count = this->spacers - 1;
1920 return arrange_nopanel;
1921 }
1922
1923 /* Split toolbar */
1924 width -= this->panel_widths[1];
1925 arrangeable_count = lengthof(arrange_switch) / 2;
1926 button_count = arrangeable_count - 1;
1927 spacer_count = 0;
1928 return arrange_switch + ((_toolbar_mode == TB_LOWER) ? arrangeable_count : 0);
1929 }
1930};
1931
1932/* --- Toolbar handling for the 'normal' case */
1933
1934typedef CallBackFunction ToolbarButtonProc(Window *w);
1935
1936static ToolbarButtonProc * const _toolbar_button_procs[] = {
1937 ToolbarPauseClick,
1941 ToolbarMapClick,
1942 ToolbarTownClick,
1943 ToolbarSubsidiesClick,
1944 ToolbarStationsClick,
1945 ToolbarFinancesClick,
1946 ToolbarCompaniesClick,
1947 ToolbarStoryClick,
1948 ToolbarGoalClick,
1949 ToolbarGraphsClick,
1950 ToolbarLeagueClick,
1951 ToolbarIndustryClick,
1952 ToolbarTrainClick,
1953 ToolbarRoadClick,
1954 ToolbarShipClick,
1955 ToolbarAirClick,
1956 ToolbarZoomInClick,
1957 ToolbarZoomOutClick,
1958 ToolbarBuildRailClick,
1959 ToolbarBuildRoadClick,
1960 ToolbarBuildTramClick,
1961 ToolbarBuildWaterClick,
1962 ToolbarBuildAirClick,
1963 ToolbarForestClick,
1964 ToolbarMusicClick,
1965 ToolbarNewspaperClick,
1966 ToolbarHelpClick,
1967 ToolbarSwitchClick,
1968};
1969
1972 MainToolbarWindow(WindowDesc &desc) : Window(desc)
1973 {
1974 this->InitNested(0);
1975
1976 _last_started_action = CBF_NONE;
1978 this->SetWidgetDisabledState(WID_TN_PAUSE, _networking && !_network_server); // if not server, disable pause button
1979 this->SetWidgetDisabledState(WID_TN_FAST_FORWARD, _networking); // if networking, disable fast-forward button
1980 PositionMainToolbar(this);
1982 }
1983
1984 void FindWindowPlacementAndResize(int, int def_height, bool allow_resize) override
1985 {
1986 Window::FindWindowPlacementAndResize(_toolbar_width, def_height, allow_resize);
1987 }
1988
1989 void OnPaint() override
1990 {
1991 /* If spectator, disable all construction buttons
1992 * ie : Build road, rail, ships, airports and landscaping
1993 * Since enabled state is the default, just disable when needed */
1995 /* disable company list drop downs, if there are no companies */
1997
2000
2001 this->DrawWidgets();
2002 }
2003
2004 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
2005 {
2006 if (_game_mode != GM_MENU && !this->IsWidgetDisabled(widget)) _toolbar_button_procs[widget](this);
2007 }
2008
2009 void OnDropdownSelect(WidgetID widget, int index, int) override
2010 {
2011 CallBackFunction cbf = _menu_clicked_procs[widget](index);
2012 if (cbf != CBF_NONE) _last_started_action = cbf;
2013 }
2014
2015 EventState OnHotkey(int hotkey) override
2016 {
2017 CallBackFunction cbf = CBF_NONE;
2018 switch (hotkey) {
2019 case MTHK_PAUSE: ToolbarPauseClick(this); break;
2020 case MTHK_FASTFORWARD: ToolbarFastForwardClick(this); break;
2021 case MTHK_SETTINGS: ShowGameOptions(); break;
2022 case MTHK_SAVEGAME: MenuClickSaveLoad(); break;
2023 case MTHK_LOADGAME: ShowSaveLoadDialog(FT_SAVEGAME, SLO_LOAD); break;
2024 case MTHK_SMALLMAP: ShowSmallMap(); break;
2025 case MTHK_TOWNDIRECTORY: ShowTownDirectory(); break;
2026 case MTHK_SUBSIDIES: ShowSubsidiesList(); break;
2027 case MTHK_STATIONS: ShowCompanyStations(_local_company); break;
2028 case MTHK_FINANCES: ShowCompanyFinances(_local_company); break;
2029 case MTHK_COMPANIES: ShowCompany(_local_company); break;
2030 case MTHK_STORY: ShowStoryBook(_local_company); break;
2031 case MTHK_GOAL: ShowGoalsList(_local_company); break;
2032 case MTHK_GRAPHS: ShowOperatingProfitGraph(); break;
2033 case MTHK_LEAGUE: ShowFirstLeagueTable(); break;
2034 case MTHK_INDUSTRIES: ShowBuildIndustryWindow(); break;
2035 case MTHK_TRAIN_LIST: ShowVehicleListWindow(_local_company, VEH_TRAIN); break;
2036 case MTHK_ROADVEH_LIST: ShowVehicleListWindow(_local_company, VEH_ROAD); break;
2037 case MTHK_SHIP_LIST: ShowVehicleListWindow(_local_company, VEH_SHIP); break;
2038 case MTHK_AIRCRAFT_LIST: ShowVehicleListWindow(_local_company, VEH_AIRCRAFT); break;
2039 case MTHK_ZOOM_IN: ToolbarZoomInClick(this); break;
2040 case MTHK_ZOOM_OUT: ToolbarZoomOutClick(this); break;
2041 case MTHK_BUILD_RAIL: ShowBuildRailToolbar(_last_built_railtype); break;
2042 case MTHK_BUILD_ROAD: ShowBuildRoadToolbar(_last_built_roadtype); break;
2043 case MTHK_BUILD_TRAM: ShowBuildRoadToolbar(_last_built_tramtype); break;
2044 case MTHK_BUILD_DOCKS: ShowBuildDocksToolbar(); break;
2045 case MTHK_BUILD_AIRPORT: ShowBuildAirToolbar(); break;
2046 case MTHK_BUILD_TREES: ShowBuildTreesToolbar(); break;
2047 case MTHK_MUSIC: ShowMusicWindow(); break;
2048 case MTHK_SCRIPT_DEBUG: ShowScriptDebugWindow(); break;
2049 case MTHK_SMALL_SCREENSHOT: MakeScreenshotWithConfirm(SC_VIEWPORT); break;
2050 case MTHK_ZOOMEDIN_SCREENSHOT: MakeScreenshotWithConfirm(SC_ZOOMEDIN); break;
2051 case MTHK_DEFAULTZOOM_SCREENSHOT: MakeScreenshotWithConfirm(SC_DEFAULTZOOM); break;
2052 case MTHK_GIANT_SCREENSHOT: MakeScreenshotWithConfirm(SC_WORLD); break;
2053 case MTHK_CHEATS: if (!_networking) ShowCheatWindow(); break;
2054 case MTHK_TERRAFORM: ShowTerraformToolbar(); break;
2055 case MTHK_EXTRA_VIEWPORT: ShowExtraViewportWindowForTileUnderCursor(); break;
2056 case MTHK_CLIENT_LIST: if (_networking) ShowClientList(); break;
2057 case MTHK_SIGN_LIST: ShowSignList(); break;
2058 case MTHK_LANDINFO: cbf = PlaceLandBlockInfo(); break;
2059 default: return ES_NOT_HANDLED;
2060 }
2061 if (cbf != CBF_NONE) _last_started_action = cbf;
2062 return ES_HANDLED;
2063 }
2064
2065 void OnPlaceObject([[maybe_unused]] Point pt, TileIndex tile) override
2066 {
2067 switch (_last_started_action) {
2068 case CBF_PLACE_SIGN:
2069 PlaceProc_Sign(tile);
2070 break;
2071
2072 case CBF_PLACE_LANDINFO:
2073 ShowLandInfo(tile);
2074 break;
2075
2076 default: NOT_REACHED();
2077 }
2078 }
2079
2080 void OnPlaceObjectAbort() override
2081 {
2082 _last_started_action = CBF_NONE;
2083 }
2084
2086 const IntervalTimer<TimerWindow> refresh_interval = {std::chrono::milliseconds(30), [this](auto) {
2087 if (this->IsWidgetLowered(WID_TN_PAUSE) != _pause_mode.Any()) {
2090 }
2091
2092 if (this->IsWidgetLowered(WID_TN_FAST_FORWARD) != (_game_speed != 100)) {
2095 }
2096 }};
2097
2103 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
2104 {
2105 if (!gui_scope) return;
2107 }
2108
2109 static inline HotkeyList hotkeys{"maintoolbar", {
2110 Hotkey({WKC_F1, WKC_PAUSE}, "pause", MTHK_PAUSE),
2111 Hotkey(0, "fastforward", MTHK_FASTFORWARD),
2112 Hotkey(WKC_F2, "settings", MTHK_SETTINGS),
2113 Hotkey(WKC_F3, "saveload", MTHK_SAVEGAME),
2114 Hotkey(0, "load_game", MTHK_LOADGAME),
2115 Hotkey({WKC_F4, 'M'}, "smallmap", MTHK_SMALLMAP),
2116 Hotkey(WKC_F5, "town_list", MTHK_TOWNDIRECTORY),
2117 Hotkey(WKC_F6, "subsidies", MTHK_SUBSIDIES),
2118 Hotkey(WKC_F7, "station_list", MTHK_STATIONS),
2119 Hotkey(WKC_F8, "finances", MTHK_FINANCES),
2120 Hotkey(WKC_F9, "companies", MTHK_COMPANIES),
2121 Hotkey(0, "story_book", MTHK_STORY),
2122 Hotkey(0, "goal_list", MTHK_GOAL),
2123 Hotkey(WKC_F10, "graphs", MTHK_GRAPHS),
2124 Hotkey(WKC_F11, "league", MTHK_LEAGUE),
2125 Hotkey(WKC_F12, "industry_list", MTHK_INDUSTRIES),
2126 Hotkey(WKC_SHIFT | WKC_F1, "train_list", MTHK_TRAIN_LIST),
2127 Hotkey(WKC_SHIFT | WKC_F2, "roadveh_list", MTHK_ROADVEH_LIST),
2128 Hotkey(WKC_SHIFT | WKC_F3, "ship_list", MTHK_SHIP_LIST),
2129 Hotkey(WKC_SHIFT | WKC_F4, "aircraft_list", MTHK_AIRCRAFT_LIST),
2130 Hotkey({WKC_NUM_PLUS, WKC_EQUALS, WKC_SHIFT | WKC_EQUALS, WKC_SHIFT | WKC_F5}, "zoomin", MTHK_ZOOM_IN),
2131 Hotkey({WKC_NUM_MINUS, WKC_MINUS, WKC_SHIFT | WKC_MINUS, WKC_SHIFT | WKC_F6}, "zoomout", MTHK_ZOOM_OUT),
2132 Hotkey(WKC_SHIFT | WKC_F7, "build_rail", MTHK_BUILD_RAIL),
2133 Hotkey(WKC_SHIFT | WKC_F8, "build_road", MTHK_BUILD_ROAD),
2134 Hotkey(0, "build_tram", MTHK_BUILD_TRAM),
2135 Hotkey(WKC_SHIFT | WKC_F9, "build_docks", MTHK_BUILD_DOCKS),
2136 Hotkey(WKC_SHIFT | WKC_F10, "build_airport", MTHK_BUILD_AIRPORT),
2137 Hotkey(WKC_SHIFT | WKC_F11, "build_trees", MTHK_BUILD_TREES),
2138 Hotkey(WKC_SHIFT | WKC_F12, "music", MTHK_MUSIC),
2139 Hotkey(0, "ai_debug", MTHK_SCRIPT_DEBUG),
2140 Hotkey(WKC_CTRL | 'S', "small_screenshot", MTHK_SMALL_SCREENSHOT),
2141 Hotkey(WKC_CTRL | 'P', "zoomedin_screenshot", MTHK_ZOOMEDIN_SCREENSHOT),
2142 Hotkey(WKC_CTRL | 'D', "defaultzoom_screenshot", MTHK_DEFAULTZOOM_SCREENSHOT),
2143 Hotkey(0, "giant_screenshot", MTHK_GIANT_SCREENSHOT),
2144 Hotkey(WKC_CTRL | WKC_ALT | 'C', "cheats", MTHK_CHEATS),
2145 Hotkey('L', "terraform", MTHK_TERRAFORM),
2146 Hotkey('V', "extra_viewport", MTHK_EXTRA_VIEWPORT),
2147 Hotkey(0, "client_list", MTHK_CLIENT_LIST),
2148 Hotkey(0, "sign_list", MTHK_SIGN_LIST),
2149 Hotkey(0, "land_info", MTHK_LANDINFO),
2150 }};
2151};
2152
2153static std::unique_ptr<NWidgetBase> MakeMainToolbar()
2154{
2156 static const std::tuple<WidgetID, WidgetType, SpriteID> toolbar_button_sprites[] = {
2157 {WID_TN_PAUSE, WWT_IMGBTN, SPR_IMG_PAUSE},
2158 {WID_TN_FAST_FORWARD, WWT_IMGBTN, SPR_IMG_FASTFORWARD},
2159 {WID_TN_SETTINGS, WWT_IMGBTN, SPR_IMG_SETTINGS},
2160 {WID_TN_SAVE, WWT_IMGBTN_2, SPR_IMG_SAVE},
2161 {WID_TN_SMALL_MAP, WWT_IMGBTN, SPR_IMG_SMALLMAP},
2162 {WID_TN_TOWNS, WWT_IMGBTN, SPR_IMG_TOWN},
2163 {WID_TN_SUBSIDIES, WWT_IMGBTN, SPR_IMG_SUBSIDIES},
2164 {WID_TN_STATIONS, WWT_IMGBTN, SPR_IMG_COMPANY_LIST},
2165 {WID_TN_FINANCES, WWT_IMGBTN, SPR_IMG_COMPANY_FINANCE},
2166 {WID_TN_COMPANIES, WWT_IMGBTN, SPR_IMG_COMPANY_GENERAL},
2167 {WID_TN_STORY, WWT_IMGBTN, SPR_IMG_STORY_BOOK},
2168 {WID_TN_GOAL, WWT_IMGBTN, SPR_IMG_GOAL},
2169 {WID_TN_GRAPHS, WWT_IMGBTN, SPR_IMG_GRAPHS},
2170 {WID_TN_LEAGUE, WWT_IMGBTN, SPR_IMG_COMPANY_LEAGUE},
2171 {WID_TN_INDUSTRIES, WWT_IMGBTN, SPR_IMG_INDUSTRY},
2172 {WID_TN_TRAINS, WWT_IMGBTN, SPR_IMG_TRAINLIST},
2173 {WID_TN_ROADVEHS, WWT_IMGBTN, SPR_IMG_TRUCKLIST},
2174 {WID_TN_SHIPS, WWT_IMGBTN, SPR_IMG_SHIPLIST},
2175 {WID_TN_AIRCRAFT, WWT_IMGBTN, SPR_IMG_AIRPLANESLIST},
2176 {WID_TN_ZOOM_IN, WWT_PUSHIMGBTN, SPR_IMG_ZOOMIN},
2177 {WID_TN_ZOOM_OUT, WWT_PUSHIMGBTN, SPR_IMG_ZOOMOUT},
2178 {WID_TN_RAILS, WWT_IMGBTN, SPR_IMG_BUILDRAIL},
2179 {WID_TN_ROADS, WWT_IMGBTN, SPR_IMG_BUILDROAD},
2180 {WID_TN_TRAMS, WWT_IMGBTN, SPR_IMG_BUILDTRAMS},
2181 {WID_TN_WATER, WWT_IMGBTN, SPR_IMG_BUILDWATER},
2182 {WID_TN_AIR, WWT_IMGBTN, SPR_IMG_BUILDAIR},
2183 {WID_TN_LANDSCAPE, WWT_IMGBTN, SPR_IMG_LANDSCAPING},
2184 {WID_TN_MUSIC_SOUND, WWT_IMGBTN, SPR_IMG_MUSIC},
2185 {WID_TN_MESSAGES, WWT_IMGBTN, SPR_IMG_MESSAGES},
2186 {WID_TN_HELP, WWT_IMGBTN, SPR_IMG_QUERY},
2187 {WID_TN_SWITCH_BAR, WWT_IMGBTN, SPR_IMG_SWITCH_TOOLBAR},
2188 };
2189
2190 auto hor = std::make_unique<NWidgetMainToolbarContainer>();
2191 for (const auto &[widget, tp, sprite] : toolbar_button_sprites) {
2192 switch (widget) {
2193 case WID_TN_SMALL_MAP:
2194 case WID_TN_FINANCES:
2196 case WID_TN_ZOOM_IN:
2198 case WID_TN_MUSIC_SOUND:
2199 hor->Add(std::make_unique<NWidgetSpacer>(0, 0));
2200 break;
2201 }
2202 auto leaf = std::make_unique<NWidgetLeaf>(tp, COLOUR_GREY, widget, WidgetData{.sprite = sprite}, STR_TOOLBAR_TOOLTIP_PAUSE_GAME + widget);
2203 leaf->SetMinimalSize(20, 20);
2204 hor->Add(std::move(leaf));
2205 }
2206
2207 return hor;
2208}
2209
2210static constexpr NWidgetPart _nested_toolbar_normal_widgets[] = {
2212};
2213
2214static WindowDesc _toolb_normal_desc(
2215 WDP_MANUAL, {}, 0, 0,
2218 _nested_toolbar_normal_widgets,
2219 &MainToolbarWindow::hotkeys
2220);
2221
2222
2223/* --- Toolbar handling for the scenario editor */
2224
2225static MenuClickedProc * const _scen_toolbar_dropdown_procs[] = {
2226 nullptr, // 0
2227 nullptr, // 1
2228 MenuClickSettings, // 2
2229 MenuClickSaveLoad, // 3
2230 nullptr, // 4
2231 nullptr, // 5
2232 nullptr, // 6
2233 nullptr, // 7
2234 MenuClickMap, // 8
2235 nullptr, // 9
2236 nullptr, // 10
2237 nullptr, // 11
2238 ToolbarScenGenTown, // 12
2239 nullptr, // 13
2242 nullptr, // 16
2243 nullptr, // 17
2244 nullptr, // 18
2245 nullptr, // 19
2247 MenuClickHelp, // 21
2248 nullptr, // 22
2249};
2250
2251static ToolbarButtonProc * const _scen_toolbar_button_procs[] = {
2252 ToolbarPauseClick,
2256 ToolbarBtn_NULL,
2258 ToolbarScenDateBackward,
2259 ToolbarScenDateForward,
2260 ToolbarScenMapTownDir,
2261 ToolbarZoomInClick,
2262 ToolbarZoomOutClick,
2263 ToolbarScenGenLand,
2264 ToolbarScenGenTownClick,
2265 ToolbarScenGenIndustry,
2266 ToolbarScenBuildRoadClick,
2267 ToolbarScenBuildTramClick,
2268 ToolbarScenBuildDocks,
2269 ToolbarScenPlantTrees,
2270 ToolbarScenPlaceSign,
2271 ToolbarBtn_NULL,
2272 ToolbarMusicClick,
2273 ToolbarHelpClick,
2274 ToolbarSwitchClick,
2275};
2276
2277enum MainToolbarEditorHotkeys : int32_t {
2278 MTEHK_PAUSE,
2279 MTEHK_FASTFORWARD,
2280 MTEHK_SETTINGS,
2281 MTEHK_SAVEGAME,
2282 MTEHK_GENLAND,
2283 MTEHK_GENTOWN,
2284 MTEHK_GENINDUSTRY,
2285 MTEHK_BUILD_ROAD,
2286 MTEHK_BUILD_TRAM,
2287 MTEHK_BUILD_DOCKS,
2288 MTEHK_BUILD_TREES,
2289 MTEHK_SIGN,
2290 MTEHK_MUSIC,
2291 MTEHK_LANDINFO,
2292 MTEHK_SMALL_SCREENSHOT,
2293 MTEHK_ZOOMEDIN_SCREENSHOT,
2294 MTEHK_DEFAULTZOOM_SCREENSHOT,
2295 MTEHK_GIANT_SCREENSHOT,
2296 MTEHK_ZOOM_IN,
2297 MTEHK_ZOOM_OUT,
2298 MTEHK_TERRAFORM,
2299 MTEHK_SMALLMAP,
2300 MTEHK_EXTRA_VIEWPORT,
2301};
2302
2305 {
2306 this->InitNested(0);
2307
2308 _last_started_action = CBF_NONE;
2310 PositionMainToolbar(this);
2312 }
2313
2314 void FindWindowPlacementAndResize(int, int def_height, bool allow_resize) override
2315 {
2316 Window::FindWindowPlacementAndResize(_toolbar_width, def_height, allow_resize);
2317 }
2318
2328
2329 std::string GetWidgetString(WidgetID widget, StringID stringid) const override
2330 {
2331 switch (widget) {
2332 case WID_TE_DATE:
2334
2335 default:
2336 return this->Window::GetWidgetString(widget, stringid);
2337 }
2338 }
2339
2340 void DrawWidget(const Rect &r, WidgetID widget) const override
2341 {
2342 switch (widget) {
2343 case WID_TE_SPACER: {
2344 int height = r.Height();
2345 if (height > 2 * GetCharacterHeight(FS_NORMAL)) {
2346 DrawString(r.left, r.right, height / 2 - GetCharacterHeight(FS_NORMAL), STR_SCENEDIT_TOOLBAR_OPENTTD, TC_FROMSTRING, SA_HOR_CENTER);
2347 DrawString(r.left, r.right, height / 2, STR_SCENEDIT_TOOLBAR_SCENARIO_EDITOR, TC_FROMSTRING, SA_HOR_CENTER);
2348 } else {
2349 DrawString(r.left, r.right, (height - GetCharacterHeight(FS_NORMAL)) / 2, STR_SCENEDIT_TOOLBAR_SCENARIO_EDITOR, TC_FROMSTRING, SA_HOR_CENTER);
2350 }
2351 break;
2352 }
2353 }
2354 }
2355
2356 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
2357 {
2358 switch (widget) {
2359 case WID_TE_SPACER:
2360 size.width = std::max(GetStringBoundingBox(STR_SCENEDIT_TOOLBAR_OPENTTD).width, GetStringBoundingBox(STR_SCENEDIT_TOOLBAR_SCENARIO_EDITOR).width) + padding.width;
2361 break;
2362
2363 case WID_TE_DATE:
2365 break;
2366 }
2367 }
2368
2369 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
2370 {
2371 if (_game_mode == GM_MENU) return;
2372 CallBackFunction cbf = _scen_toolbar_button_procs[widget](this);
2373 if (cbf != CBF_NONE) _last_started_action = cbf;
2374 }
2375
2376 void OnDropdownSelect(WidgetID widget, int index, int) override
2377 {
2378 CallBackFunction cbf = _scen_toolbar_dropdown_procs[widget](index);
2379 if (cbf != CBF_NONE) _last_started_action = cbf;
2380 SndClickBeep();
2381 }
2382
2383 EventState OnHotkey(int hotkey) override
2384 {
2385 CallBackFunction cbf = CBF_NONE;
2386 switch (hotkey) {
2387 case MTEHK_PAUSE: ToolbarPauseClick(this); break;
2388 case MTEHK_FASTFORWARD: ToolbarFastForwardClick(this); break;
2389 case MTEHK_SETTINGS: ShowGameOptions(); break;
2390 case MTEHK_SAVEGAME: MenuClickSaveLoad(); break;
2391 case MTEHK_GENLAND: ToolbarScenGenLand(this); break;
2392 case MTEHK_GENTOWN: ToolbarScenGenTownClick(this); break;
2393 case MTEHK_GENINDUSTRY: ToolbarScenGenIndustry(this); break;
2394 case MTEHK_BUILD_ROAD: ToolbarScenBuildRoadClick(this); break;
2395 case MTEHK_BUILD_TRAM: ToolbarScenBuildTramClick(this); break;
2396 case MTEHK_BUILD_DOCKS: ToolbarScenBuildDocks(this); break;
2397 case MTEHK_BUILD_TREES: ToolbarScenPlantTrees(this); break;
2398 case MTEHK_SIGN: cbf = ToolbarScenPlaceSign(this); break;
2399 case MTEHK_MUSIC: ShowMusicWindow(); break;
2400 case MTEHK_LANDINFO: cbf = PlaceLandBlockInfo(); break;
2401 case MTEHK_SMALL_SCREENSHOT: MakeScreenshotWithConfirm(SC_VIEWPORT); break;
2402 case MTEHK_ZOOMEDIN_SCREENSHOT: MakeScreenshotWithConfirm(SC_ZOOMEDIN); break;
2403 case MTEHK_DEFAULTZOOM_SCREENSHOT: MakeScreenshotWithConfirm(SC_DEFAULTZOOM); break;
2404 case MTEHK_GIANT_SCREENSHOT: MakeScreenshotWithConfirm(SC_WORLD); break;
2405 case MTEHK_ZOOM_IN: ToolbarZoomInClick(this); break;
2406 case MTEHK_ZOOM_OUT: ToolbarZoomOutClick(this); break;
2407 case MTEHK_TERRAFORM: ShowEditorTerraformToolbar(); break;
2408 case MTEHK_SMALLMAP: ShowSmallMap(); break;
2409 case MTEHK_EXTRA_VIEWPORT: ShowExtraViewportWindowForTileUnderCursor(); break;
2410 default: return ES_NOT_HANDLED;
2411 }
2412 if (cbf != CBF_NONE) _last_started_action = cbf;
2413 return ES_HANDLED;
2414 }
2415
2416 void OnPlaceObject([[maybe_unused]] Point pt, TileIndex tile) override
2417 {
2418 switch (_last_started_action) {
2419 case CBF_PLACE_SIGN:
2420 PlaceProc_Sign(tile);
2421 break;
2422
2423 case CBF_PLACE_LANDINFO:
2424 ShowLandInfo(tile);
2425 break;
2426
2427 default: NOT_REACHED();
2428 }
2429 }
2430
2431 void OnPlaceObjectAbort() override
2432 {
2433 _last_started_action = CBF_NONE;
2434 }
2435
2442
2444 const IntervalTimer<TimerWindow> refresh_interval = {std::chrono::milliseconds(30), [this](auto) {
2445 if (this->IsWidgetLowered(WID_TE_PAUSE) != _pause_mode.Any()) {
2447 this->SetDirty();
2448 }
2449
2450 if (this->IsWidgetLowered(WID_TE_FAST_FORWARD) != (_game_speed != 100)) {
2452 this->SetDirty();
2453 }
2454 }};
2455
2461 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
2462 {
2463 if (!gui_scope) return;
2465 }
2466
2467 void OnQueryTextFinished(std::optional<std::string> str) override
2468 {
2469 /* Was 'cancel' pressed? */
2470 if (!str.has_value()) return;
2471
2473 if (!str->empty()) {
2474 auto val = ParseInteger(*str, 10, true);
2475 if (!val.has_value()) return;
2476 value = static_cast<TimerGameCalendar::Year>(*val);
2477 } else {
2478 /* An empty string means revert to the default */
2480 }
2481 SetStartingYear(value);
2482
2483 this->SetDirty();
2484 }
2485
2486 static inline HotkeyList hotkeys{"scenedit_maintoolbar", {
2487 Hotkey({WKC_F1, WKC_PAUSE}, "pause", MTEHK_PAUSE),
2488 Hotkey(0, "fastforward", MTEHK_FASTFORWARD),
2489 Hotkey(WKC_F2, "settings", MTEHK_SETTINGS),
2490 Hotkey(WKC_F3, "saveload", MTEHK_SAVEGAME),
2491 Hotkey(WKC_F4, "gen_land", MTEHK_GENLAND),
2492 Hotkey(WKC_F5, "gen_town", MTEHK_GENTOWN),
2493 Hotkey(WKC_F6, "gen_industry", MTEHK_GENINDUSTRY),
2494 Hotkey(WKC_F7, "build_road", MTEHK_BUILD_ROAD),
2495 Hotkey(0, "build_tram", MTEHK_BUILD_TRAM),
2496 Hotkey(WKC_F8, "build_docks", MTEHK_BUILD_DOCKS),
2497 Hotkey(WKC_F9, "build_trees", MTEHK_BUILD_TREES),
2498 Hotkey(WKC_F10, "build_sign", MTEHK_SIGN),
2499 Hotkey(WKC_F11, "music", MTEHK_MUSIC),
2500 Hotkey(WKC_F12, "land_info", MTEHK_LANDINFO),
2501 Hotkey(WKC_CTRL | 'S', "small_screenshot", MTEHK_SMALL_SCREENSHOT),
2502 Hotkey(WKC_CTRL | 'P', "zoomedin_screenshot", MTEHK_ZOOMEDIN_SCREENSHOT),
2503 Hotkey(WKC_CTRL | 'D', "defaultzoom_screenshot", MTEHK_DEFAULTZOOM_SCREENSHOT),
2504 Hotkey(0, "giant_screenshot", MTEHK_GIANT_SCREENSHOT),
2505 Hotkey({WKC_NUM_PLUS, WKC_EQUALS, WKC_SHIFT | WKC_EQUALS, WKC_SHIFT | WKC_F5}, "zoomin", MTEHK_ZOOM_IN),
2506 Hotkey({WKC_NUM_MINUS, WKC_MINUS, WKC_SHIFT | WKC_MINUS, WKC_SHIFT | WKC_F6}, "zoomout", MTEHK_ZOOM_OUT),
2507 Hotkey('L', "terraform", MTEHK_TERRAFORM),
2508 Hotkey('M', "smallmap", MTEHK_SMALLMAP),
2509 Hotkey('V', "extra_viewport", MTEHK_EXTRA_VIEWPORT),
2510 }};
2511};
2512
2513static constexpr NWidgetPart _nested_toolb_scen_inner_widgets[] = {
2514 NWidget(WWT_IMGBTN, COLOUR_GREY, WID_TE_PAUSE), SetSpriteTip(SPR_IMG_PAUSE, STR_TOOLBAR_TOOLTIP_PAUSE_GAME),
2515 NWidget(WWT_IMGBTN, COLOUR_GREY, WID_TE_FAST_FORWARD), SetSpriteTip(SPR_IMG_FASTFORWARD, STR_TOOLBAR_TOOLTIP_FORWARD),
2516 NWidget(WWT_IMGBTN, COLOUR_GREY, WID_TE_SETTINGS), SetSpriteTip(SPR_IMG_SETTINGS, STR_TOOLBAR_TOOLTIP_OPTIONS),
2517 NWidget(WWT_IMGBTN_2, COLOUR_GREY, WID_TE_SAVE), SetSpriteTip(SPR_IMG_SAVE, STR_SCENEDIT_TOOLBAR_SAVE_SCENARIO_LOAD_SCENARIO_TOOLTIP),
2519 NWidget(WWT_PANEL, COLOUR_GREY, WID_TE_SPACER), EndContainer(),
2521 NWidget(WWT_PANEL, COLOUR_GREY, WID_TE_DATE_PANEL),
2523 NWidget(WWT_IMGBTN, COLOUR_GREY, WID_TE_DATE_BACKWARD), SetSpriteTip(SPR_ARROW_DOWN, STR_SCENEDIT_TOOLBAR_MOVE_THE_STARTING_DATE_BACKWARD_TOOLTIP), SetFill(0, 1),
2524 NWidget(WWT_TEXT, INVALID_COLOUR, WID_TE_DATE), SetToolTip(STR_SCENEDIT_TOOLBAR_SET_DATE_TOOLTIP), SetTextStyle(TC_WHITE), SetAlignment(SA_CENTER), SetFill(0, 1),
2525 NWidget(WWT_IMGBTN, COLOUR_GREY, WID_TE_DATE_FORWARD), SetSpriteTip(SPR_ARROW_UP, STR_SCENEDIT_TOOLBAR_MOVE_THE_STARTING_DATE_FORWARD_TOOLTIP), SetFill(0, 1),
2526 EndContainer(),
2527 EndContainer(),
2529 NWidget(WWT_IMGBTN, COLOUR_GREY, WID_TE_SMALL_MAP), SetSpriteTip(SPR_IMG_SMALLMAP, STR_SCENEDIT_TOOLBAR_DISPLAY_MAP_TOWN_DIRECTORY_TOOLTIP),
2531 NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_TE_ZOOM_IN), SetSpriteTip(SPR_IMG_ZOOMIN, STR_TOOLBAR_TOOLTIP_ZOOM_THE_VIEW_IN),
2532 NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_TE_ZOOM_OUT), SetSpriteTip(SPR_IMG_ZOOMOUT, STR_TOOLBAR_TOOLTIP_ZOOM_THE_VIEW_OUT),
2534 NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_TE_LAND_GENERATE), SetSpriteTip(SPR_IMG_LANDSCAPING, STR_SCENEDIT_TOOLBAR_LANDSCAPE_GENERATION_TOOLTIP),
2535 NWidget(WWT_IMGBTN, COLOUR_GREY, WID_TE_TOWN_GENERATE), SetSpriteTip(SPR_IMG_TOWN, STR_SCENEDIT_TOOLBAR_TOWN_GENERATION_TOOLTIP),
2536 NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_TE_INDUSTRY), SetSpriteTip(SPR_IMG_INDUSTRY, STR_SCENEDIT_TOOLBAR_INDUSTRY_GENERATION_TOOLTIP),
2537 NWidget(WWT_IMGBTN, COLOUR_GREY, WID_TE_ROADS), SetSpriteTip(SPR_IMG_BUILDROAD, STR_SCENEDIT_TOOLBAR_ROAD_CONSTRUCTION_TOOLTIP),
2538 NWidget(WWT_IMGBTN, COLOUR_GREY, WID_TE_TRAMS), SetSpriteTip(SPR_IMG_BUILDTRAMS, STR_SCENEDIT_TOOLBAR_TRAM_CONSTRUCTION_TOOLTIP),
2539 NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_TE_WATER), SetSpriteTip(SPR_IMG_BUILDWATER, STR_TOOLBAR_TOOLTIP_BUILD_SHIP_DOCKS),
2540 NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_TE_TREES), SetSpriteTip(SPR_IMG_PLANTTREES, STR_SCENEDIT_TOOLBAR_PLANT_TREES_TOOLTIP),
2541 NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_TE_SIGNS), SetSpriteTip(SPR_IMG_SIGN, STR_SCENEDIT_TOOLBAR_PLACE_SIGN_TOOLTIP),
2543 NWidget(WWT_IMGBTN, COLOUR_GREY, WID_TE_MUSIC_SOUND), SetSpriteTip(SPR_IMG_MUSIC, STR_TOOLBAR_TOOLTIP_SHOW_SOUND_MUSIC_WINDOW),
2544 NWidget(WWT_IMGBTN, COLOUR_GREY, WID_TE_HELP), SetSpriteTip(SPR_IMG_QUERY, STR_TOOLBAR_TOOLTIP_LAND_BLOCK_INFORMATION),
2545 NWidget(WWT_IMGBTN, COLOUR_GREY, WID_TE_SWITCH_BAR), SetSpriteTip(SPR_IMG_SWITCH_TOOLBAR, STR_TOOLBAR_TOOLTIP_SWITCH_TOOLBAR),
2546};
2547
2548static std::unique_ptr<NWidgetBase> MakeScenarioToolbar()
2549{
2550 return MakeNWidgets(_nested_toolb_scen_inner_widgets, std::make_unique<NWidgetScenarioToolbarContainer>());
2551}
2552
2553static constexpr NWidgetPart _nested_toolb_scen_widgets[] = {
2554 NWidgetFunction(MakeScenarioToolbar),
2555};
2556
2557static WindowDesc _toolb_scen_desc(
2558 WDP_MANUAL, {}, 0, 0,
2561 _nested_toolb_scen_widgets,
2562 &ScenarioEditorToolbarWindow::hotkeys
2563);
2564
2567{
2568 /* Clean old GUI values; railtype is (re)set by rail_gui.cpp */
2569 _last_built_roadtype = ROADTYPE_ROAD;
2570 _last_built_tramtype = ROADTYPE_TRAM;
2571
2572 if (_game_mode == GM_EDITOR) {
2573 new ScenarioEditorToolbarWindow(_toolb_scen_desc);
2574 } else {
2575 new MainToolbarWindow(_toolb_normal_desc);
2576 }
2577}
void ShowAIConfigWindow()
Open the AI config window.
Definition ai_gui.cpp:334
Window for configuring the AIs
Window * ShowBuildAirToolbar()
Open the build airport toolbar window.
debug_inline constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
constexpr T ToggleBit(T &x, const uint8_t y)
Toggles a bit in a variable.
Functions related to cheating.
void ShowCheatWindow()
Open cheat window.
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
constexpr bool None() const
Test if none of the values are set.
constexpr Timpl & Reset()
Reset all bits.
constexpr Timpl & Flip(Tvalue_type value)
Flip the value-th bit.
constexpr Timpl & Set()
Set all bits.
constexpr bool Any(const Timpl &other) const
Test if any of the given values are set.
Drop down icon component.
Company name list item, with company-colour icon, name, and lock components.
An interval timer will fire every interval, and will continue to fire until it is deleted.
Definition timer.h:76
static LinkGraphSchedule instance
Static instance of LinkGraphSchedule.
void ShiftDates(TimerGameEconomy::Date interval)
Shift all dates (join dates and edge annotations) of link graphs and link graph jobs by the number of...
Baseclass for nested widgets.
WidgetType type
Type of the widget / nested widget.
uint resize_x
Horizontal resize step (0 means not resizable).
uint fill_x
Horizontal fill stepsize (from initial size, 0 means not resizable).
uint smallest_x
Smallest horizontal size of the widget in a filled window.
uint current_x
Current horizontal size (after resizing).
int pos_y
Vertical position of top-left corner of the widget in the window.
int pos_x
Horizontal position of top-left corner of the widget in the window.
uint smallest_y
Smallest vertical size of the widget in a filled window.
uint fill_y
Vertical fill stepsize (from initial size, 0 means not resizable).
uint resize_y
Vertical resize step (0 means not resizable).
uint current_y
Current vertical size (after resizing).
Baseclass for container widgets.
void Draw(const Window *w) override
Draw the widgets of the tree.
Definition widget.cpp:1305
std::vector< std::unique_ptr< NWidgetBase > > children
Child widgets in container.
Base class for a 'real' widget.
Container for the 'normal' main toolbar.
const WidgetID * GetButtonArrangement(uint &width, uint &arrangeable_count, uint &button_count, uint &spacer_count) const override
Get the arrangement of the buttons for the toolbar.
Container for the scenario editor's toolbar.
std::array< uint, 2 > panel_widths
The width of the two panels (the text panel and date panel)
const WidgetID * GetButtonArrangement(uint &width, uint &arrangeable_count, uint &button_count, uint &spacer_count) const override
Get the arrangement of the buttons for the toolbar.
void SetupSmallestSize(Window *w) override
Compute smallest size needed by the widget.
Full blown container to make it behave exactly as we want :)
uint spacers
Number of spacer widgets in this toolbar.
void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override
Assign size and position to the widget.
void SetupSmallestSize(Window *w) override
Compute smallest size needed by the widget.
bool IsButton(WidgetType type) const
Check whether the given widget type is a button for us.
void Draw(const Window *w) override
Draw the widgets of the tree.
virtual const WidgetID * GetButtonArrangement(uint &width, uint &arrangeable_count, uint &button_count, uint &spacer_count) const =0
Get the arrangement of the buttons for the toolbar.
static Date ConvertYMDToDate(Year year, Month month, Day day)
Converts a tuple of Year, Month and Day to a Date.
static void SetDate(Date date, DateFract fract)
Set the date.
static constexpr TimerGame< struct Calendar >::Year DEF_START_YEAR
The default starting year.
static constexpr TimerGame< struct Calendar >::Year MIN_YEAR
The absolute minimum year in OTTD.
static constexpr TimerGame< struct Calendar >::Year MAX_YEAR
MAX_YEAR, nicely rounded value of the number of years that can be encoded in a single 32 bits date,...
static Date date
Current date in days (day counter).
static void SetDate(Date date, DateFract fract)
Set the date.
Functions related to commands.
PaletteID GetCompanyPalette(CompanyID company)
Get the palette for recolouring with a company colour.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Functions related to companies.
void ShowCompanyFinances(CompanyID company)
Open the finances window of a company.
void ShowCompany(CompanyID company)
Show the window with the overview of the company.
GUI Functions related to companies.
void ShowCompanyStations(CompanyID company)
Opens window with list of company's stations.
static constexpr CompanyID COMPANY_SPECTATOR
The client is spectating.
void ShowFramerateWindow()
Open the general framerate window.
void IConsoleSwitch()
Toggle in-game console between opened and closed.
GUI related functions in the console.
Window * ShowBuildDocksScenToolbar()
Open the build water toolbar window for the scenario editor.
Definition dock_gui.cpp:410
Window * ShowBuildDocksToolbar()
Open the build water toolbar window.
Definition dock_gui.cpp:369
void ShowDropDownList(Window *w, DropDownList &&list, int selected, WidgetID button, uint width, bool instant_close, bool persist)
Show a drop down list.
Definition dropdown.cpp:415
Common drop down list components.
Functions related to the drop down widget.
Types related to the drop down widget.
std::vector< std::unique_ptr< const DropDownListItem > > DropDownList
A drop down list is a collection of drop down list items.
Base class for engines.
@ SLO_SAVE
File is being saved.
Definition fileio_type.h:55
@ SLO_LOAD
File is being loaded.
Definition fileio_type.h:54
@ FT_SCENARIO
old or new scenario
Definition fileio_type.h:20
@ FT_HEIGHTMAP
heightmap file
Definition fileio_type.h:21
@ FT_SAVEGAME
old or new savegame
Definition fileio_type.h:19
Declarations for savegames operations.
void ShowSaveLoadDialog(AbstractFileType abstract_filetype, SaveLoadOperation fop)
Launch save/load dialog in the given mode.
Definition fios_gui.cpp:999
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Definition fontcache.cpp:87
Types for recording game performance data.
Base functions for all Games.
void ShowGSConfigWindow()
Open the GS config window.
Definition game_gui.cpp:425
Window for configuring the Games
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition gfx.cpp:895
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:666
bool _ctrl_pressed
Is Ctrl pressed?
Definition gfx.cpp:39
bool _left_button_clicked
Is left mouse button clicked?
Definition gfx.cpp:43
uint16_t _game_speed
Current game-speed; 100 is 1x, 0 is infinite.
Definition gfx.cpp:41
PauseModes _pause_mode
The current pause mode.
Definition gfx.cpp:51
void GfxFillRect(int left, int top, int right, int bottom, const std::variant< PixelColour, PaletteID > &colour, FillRectMode mode)
Applies a certain FillRectMode-operation to a rectangle [left, right] x [top, bottom] on the screen.
Definition gfx.cpp:116
void CheckBlitter()
Check whether we still use the right blitter, or use another (better) one.
Definition gfxinit.cpp:325
@ FS_NORMAL
Index of the normal font in the font tables.
Definition gfx_type.h:249
@ SA_HOR_CENTER
Horizontally center the text.
Definition gfx_type.h:389
@ SA_CENTER
Center both horizontally and vertically.
Definition gfx_type.h:398
@ FILLRECT_CHECKER
Draw only every second pixel, used for greying-out.
Definition gfx_type.h:346
@ WKC_MINUS
Definition gfx_type.h:106
@ WKC_EQUALS
= Equals
Definition gfx_type.h:99
Goal base class.
void ShowGoalsList(CompanyID company)
Open a goal list window.
Definition goal_gui.cpp:311
Graph GUI functions.
constexpr NWidgetPart NWidgetFunction(NWidgetFunctionType *func_ptr)
Obtain a nested widget (sub)tree from an external source.
constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
Widget part function for setting filling.
constexpr NWidgetPart SetSpriteTip(SpriteID sprite, StringID tip={})
Widget part function for setting the sprite and tooltip.
constexpr NWidgetPart SetPIP(uint8_t pre, uint8_t inter, uint8_t post)
Widget part function for setting a pre/inter/post spaces.
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.
constexpr NWidgetPart SetTextStyle(TextColour colour, FontSize size=FS_NORMAL)
Widget part function for setting the text style.
std::unique_ptr< NWidgetBase > MakeNWidgets(std::span< const NWidgetPart > nwid_parts, std::unique_ptr< NWidgetBase > &&container)
Construct a nested widget tree from an array of parts.
Definition widget.cpp:3372
constexpr NWidgetPart SetToolTip(StringID tip)
Widget part function for setting tooltip and clearing the widget data.
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=INVALID_WIDGET)
Widget part function for starting a new 'real' widget.
constexpr NWidgetPart SetAlignment(StringAlignment align)
Widget part function for setting the alignment of text/images.
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition window.cpp:966
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
Definition gfx.cpp:1547
GUI functions that shouldn't be here.
void ShowStoryBook(CompanyID company, StoryPageID page_id=StoryPageID::Invalid(), bool centered=false)
Raise or create the story book window for company, at page page_id.
void ShowIndustryCargoesWindow()
Open the industry and cargoes window with an industry.
void ShowLandInfo(TileIndex tile)
Show land information window.
Definition misc_gui.cpp:316
void ShowExtraViewportWindowForTileUnderCursor()
Show a new Extra Viewport window.
void ShowExtraViewportWindow(TileIndex tile=INVALID_TILE)
Show a new Extra Viewport window.
void ShowGameOptions()
Open the game options window.
GUI to access manuals and related.
Declaration of functions and types defined in highscore.h and highscore_gui.h.
void ShowHighscoreTable(int difficulty=SP_CUSTOM, int8_t rank=-1)
Show the highscore table for a given difficulty.
Hotkey related functions.
definition of HouseSpec and accessors
LeagueTable base class.
League table GUI functions.
void ShowLinkGraphLegend()
Open a link graph legend window.
Declaration of linkgraph overlay GUI.
bool DoZoomInOutWindow(ZoomStateChange how, Window *w)
Zooms a viewport in a window in or out.
Definition main_gui.cpp:93
constexpr uint CeilDiv(uint a, uint b)
Computes ceil(a / b) for non-negative a and b.
constexpr T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Definition math_func.hpp:79
Miscellaneous command definitions.
void ShowQueryString(std::string_view str, StringID caption, uint maxsize, Window *parent, CharSetFilter afilter, QueryStringFlags flags)
Show a query popup window with a textbox in it.
bool _networking
are we in networking mode?
Definition network.cpp:67
bool _network_server
network-server is active
Definition network.cpp:68
bool NetworkCanJoinCompany(CompanyID company_id)
Returns whether the given company can be joined by this client.
Definition network.cpp:143
Basic functions/variables used all over the place.
void NetworkClientRequestMove(CompanyID company_id)
Notify the server of this client wanting to be moved to another company.
Network functions used by other parts of OpenTTD.
void NetworkServerDoMove(ClientID client_id, CompanyID company_id)
Handle the tid-bits of moving a client from one company to another.
GUIs related to networking.
@ CLIENT_ID_SERVER
Servers always have this ID.
GRFConfigList _grfconfig
First item in list of current GRF set up.
void ShowNewGRFSettings(bool editable, bool show_params, bool exec_changes, GRFConfigList &config)
Setup the NewGRF gui.
Functions/types related to NewGRF debugging.
void ShowSpriteAlignerWindow()
Show the window for aligning sprites.
void ShowLastNewsMessage()
Show previous news item.
void ShowMessageHistory()
Display window with news messages history.
GUI functions related to the news.
@ DO_SHOW_TOWN_NAMES
Display town names.
Definition openttd.h:46
@ DO_SHOW_COMPETITOR_SIGNS
Display signs, station names and waypoint names of opponent companies. Buoys and oilrig-stations are ...
Definition openttd.h:52
@ DO_FULL_DETAIL
Also draw details of track and roads.
Definition openttd.h:50
@ DO_SHOW_SIGNS
Display signs.
Definition openttd.h:48
@ DO_SHOW_WAYPOINT_NAMES
Display waypoint names.
Definition openttd.h:51
@ DO_SHOW_STATION_NAMES
Display station names.
Definition openttd.h:47
@ DO_FULL_ANIMATION
Perform palette animation.
Definition openttd.h:49
@ Normal
A game normally paused.
static constexpr PixelColour PC_VERY_DARK_RED
Almost-black red palette colour.
static constexpr PixelColour PC_DARK_RED
Dark red palette colour.
Window * ShowBuildRailToolbar(RailType railtype)
Open the build rail toolbar window for a specific rail type.
Definition rail_gui.cpp:919
DropDownList GetRailTypeDropDownList(bool for_replacement, bool all_option)
Create a drop down list for all the rail types of the local company.
Functions/types etc.
RailType
Enumeration for all possible railtypes.
Definition rail_type.h:25
RoadTypes GetRoadTypes(bool introduces)
Get list of road types, regardless of company availability.
Definition road.cpp:226
Road specific functions.
RoadTypes GetMaskForRoadTramType(RoadTramType rtt)
Get the mask for road types of the given RoadTramType.
Definition road.h:195
Window * ShowBuildRoadScenToolbar(RoadType roadtype)
Show the road building toolbar in the scenario editor.
Window * ShowBuildRoadToolbar(RoadType roadtype)
Open the build road toolbar window.
Functions/types related to the road GUIs.
RoadType
The different roadtypes we support.
Definition road_type.h:23
@ ROADTYPE_TRAM
Trams.
Definition road_type.h:26
@ ROADTYPE_ROAD
Basic road type.
Definition road_type.h:25
A number of safeguards to prevent using unsafe methods.
void MakeScreenshotWithConfirm(ScreenshotType t)
Make a screenshot.
Functions to make screenshots.
@ SC_VIEWPORT
Screenshot of viewport.
Definition screenshot.h:17
@ SC_ZOOMEDIN
Fully zoomed in screenshot of the visible area.
Definition screenshot.h:19
@ SC_WORLD
World screenshot.
Definition screenshot.h:21
@ SC_DEFAULTZOOM
Zoomed to default zoom level screenshot of the visible area.
Definition screenshot.h:20
GUI functions related to screenshots.
Window * ShowScriptDebugWindow(CompanyID show_company, bool new_window)
Open the Script debug window and select the given company.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition settings.cpp:61
ClientSettings _settings_client
The current settings for this game.
Definition settings.cpp:60
void PlaceProc_Sign(TileIndex tile)
PlaceProc function, called when someone pressed the button if the sign-tool is selected.
Functions related to signs.
Window * ShowSignList()
Open the sign list window.
void ShowSmallMap()
Show the smallmap window.
Smallmap GUI functions.
void SndConfirmBeep()
Play a beep sound for a confirm event if enabled in settings.
Definition sound.cpp:261
void SndClickBeep()
Play a beep sound for a click event if enabled in settings.
Definition sound.cpp:253
Functions related to sound.
static constexpr StationFacility STATION_FACILITY_GHOST
Fake 'facility' to allow toggling display of recently-removed station signs.
@ Dock
Station with a dock.
@ TruckStop
Station with truck stops.
@ Train
Station with train station.
@ Airport
Station with an airport.
@ BusStop
Station with bus stops.
Definition of base types and functions in a cross-platform compatible way.
#define lengthof(array)
Return the length of an fixed size array.
Definition stdafx.h:271
StoryPage base class.
Parse strings.
static std::optional< T > ParseInteger(std::string_view arg, int base=10, bool clamp=false)
Change a string into its number representation.
@ CS_NUMERAL
Only numeric ones.
Definition string_type.h:26
std::string GetString(StringID string)
Resolve the given StringID into a std::string with formatting but no parameters.
Definition strings.cpp:424
Functions related to OTTD's strings.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
GUISettings gui
settings related to the GUI
Dimensions (a width and height) of a rectangle in 2D.
TownFounding found_town
town founding.
PlaceHouses place_houses
players are allowed to place town houses.
bool UserIsAllowedToChangeNewGRFs() const
Returns true when the user has sufficient privileges to edit newgrfs on a running game.
bool toolbar_dropdown_autoselect
should toolbar dropdown buttons autoselect when releasing the mouse button
bool newgrf_developer_tools
activate NewGRF developer tools and allow modifying NewGRFs in an existing game
TimerGameCalendar::Year starting_year
starting date
EconomySettings economy
settings to change the economy
GameCreationSettings game_creation
settings used during the creation of a game (map)
List of hotkeys for a window.
Definition hotkeys.h:37
All data for a single hotkey.
Definition hotkeys.h:21
Struct about custom league tables.
Definition league_base.h:55
EventState OnHotkey(int hotkey) override
A hotkey has been pressed.
void OnPaint() override
The window must be repainted.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
void FindWindowPlacementAndResize(int, int def_height, bool allow_resize) override
Resize window towards the default size.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
void OnDropdownSelect(WidgetID widget, int index, int) override
A dropdown option associated to this window has been selected.
void OnPlaceObjectAbort() override
The user cancelled a tile highlight mode that has been set.
const IntervalTimer< TimerWindow > refresh_interval
Refresh the state of pause / game-speed on a regular interval.
void OnPlaceObject(Point pt, TileIndex tile) override
The user clicked some place on the map when a tile highlight mode has been set.
Partial widget specification to allow NWidgets to be written nested.
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
static size_t GetNumItems()
Returns number of valid items in the pool.
static bool IsValidID(auto index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Specification of a rectangle with absolute coordinates of all edges.
int Height() const
Get height of Rect.
void OnPlaceObject(Point pt, TileIndex tile) override
The user clicked some place on the map when a tile highlight mode has been set.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
void OnPaint() override
The window must be repainted.
void OnPlaceObjectAbort() override
The user cancelled a tile highlight mode that has been set.
void OnTimeout() override
Called when this window's timeout has been reached.
void OnDropdownSelect(WidgetID widget, int index, int) override
A dropdown option associated to this window has been selected.
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
const IntervalTimer< TimerWindow > refresh_interval
Refresh the state of pause / game-speed on a regular interval.
EventState OnHotkey(int hotkey) override
A hotkey has been pressed.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
void FindWindowPlacementAndResize(int, int def_height, bool allow_resize) override
Resize window towards the default size.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
void OnQueryTextFinished(std::optional< std::string > str) override
The query window opened from this window has closed.
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
Templated helper to make a type-safe 'typedef' representing a single POD value.
Container with the data associated to a single widget.
High level window description.
Definition window_gui.h:167
Data structure for an opened window.
Definition window_gui.h:273
void ReInit(int rx=0, int ry=0, bool reposition=false)
Re-initialize a window, and optionally change its size.
Definition window.cpp:978
void DrawWidgets() const
Paint all widgets of a window.
Definition widget.cpp:764
void SetWidgetDirty(WidgetID widget_index) const
Invalidate a widget, i.e.
Definition window.cpp:556
uint8_t timeout_timer
Timer value of the WindowFlag::Timeout for flags.
Definition window_gui.h:306
std::unique_ptr< ViewportData > viewport
Pointer to viewport data, if present.
Definition window_gui.h:318
virtual std::string GetWidgetString(WidgetID widget, StringID stringid) const
Get the raw string for a widget.
Definition window.cpp:504
ResizeInfo resize
Resize information.
Definition window_gui.h:314
void SetWidgetsDisabledState(bool disab_stat, Args... widgets)
Sets the enabled/disabled status of a list of widgets.
Definition window_gui.h:515
bool IsWidgetLowered(WidgetID widget_index) const
Gets the lowered state of a widget.
Definition window_gui.h:491
bool IsWidgetDisabled(WidgetID widget_index) const
Gets the enabled/disabled status of a widget.
Definition window_gui.h:410
void SetWidgetsLoweredState(bool lowered_stat, Args... widgets)
Sets the lowered/raised status of a list of widgets.
Definition window_gui.h:526
void SetWidgetLoweredState(WidgetID widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
Definition window_gui.h:441
virtual void FindWindowPlacementAndResize(int def_width, int def_height, bool allow_resize)
Resize window towards the default size.
Definition window.cpp:1474
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:595
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
Definition window.cpp:1802
WindowFlags flags
Window flags.
Definition window_gui.h:300
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition window_gui.h:381
int height
Height of the window (number of pixels down in y direction)
Definition window_gui.h:312
int width
width of the window (number of pixels to the right in x direction)
Definition window_gui.h:311
void ToggleWidgetLoweredState(WidgetID widget_index)
Invert the lowered/raised status of a widget.
Definition window_gui.h:450
Window * ShowEditorTerraformToolbar()
Show the toolbar for terraforming in the scenario editor.
Window * ShowTerraformToolbar(Window *link)
Show the toolbar for terraforming in the game.
GUI stuff related to terraforming.
Stuff related to the text buffer GUI.
@ EnableDefault
enable the 'Default' button ("\0" is returned)
Functions related to tile highlights.
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows).
void SetObjectToPlace(CursorID icon, PaletteID pal, HighLightStyle mode, WindowClass window_class, WindowNumber window_num)
Change the cursor and mouse click/drag handling to a mode for performing special operations like tile...
@ HT_RECT
rectangle (stations, depots, ...)
Definition of Interval and OneShot timers.
Definition of the game-calendar-timer.
Definition of the Window system.
static CallBackFunction MenuClickForest(int index)
Handle click on the entry in the landscaping menu.
SaveLoadEditorMenuEntries
SaveLoad entries in scenario editor mode.
static void PopupMainToolbarMenu(Window *w, WidgetID widget, DropDownList &&list, int def)
Pop up a generic text only menu.
static CallBackFunction MenuClickCompany(int index)
Handle click on the entry in the Company menu.
static CallBackFunction MenuClickStations(int index)
Handle click on the entry in the Stations menu.
static CallBackFunction MenuClickTown(int index)
Handle click on one of the entries in the Town menu.
static const int LTMN_PERFORMANCE_LEAGUE
Show default league table.
ToolbarMode
Toolbar modes.
static CallBackFunction MenuClickNewspaper(int index)
Handle click on the entry in the Newspaper menu.
static const int LTMN_PERFORMANCE_RATING
Show detailed performance rating.
CallBackFunction
Callback functions.
static CallBackFunction ToolbarSaveClick(Window *w)
Handle click on Save button in toolbar in normal game mode.
SaveLoadNormalMenuEntries
SaveLoad entries in normal game mode.
static CallBackFunction MenuClickShowRoad(int index)
Handle click on the entry in the Road Vehicles menu.
static const int GRMN_DELIVERED_CARGO_GRAPH
Show delivered cargo graph.
static CallBackFunction MenuClickGraphsOrLeague(int index)
Handle click on the entry in the Graphs or CompanyLeague.
static CallBackFunction MenuClickHelp(int index)
Choose the proper callback function for the main toolbar's help menu.
uint _toolbar_width
Width of the toolbar, shared by statusbar.
static const int GRMN_PERFORMANCE_HISTORY_GRAPH
Show performance history graph.
static CallBackFunction ToolbarOptionsClick(Window *w)
Handle click on Options button in toolbar.
static CallBackFunction MenuClickShowShips(int index)
Handle click on the entry in the Ships menu.
static std::unique_ptr< NWidgetBase > MakeMainToolbar()
static CallBackFunction MenuClickSaveLoad(int index=0)
Handle click on one of the entries in the SaveLoad menu.
static const int CTMN_CLIENT_LIST
Enum for the Company Toolbar's network related buttons.
static const int GRMN_INCOME_GRAPH
Show income graph.
static CallBackFunction MenuClickMusicWindow(int)
Handle click on the entry in the Music menu.
static CallBackFunction ToolbarScenBuildTram(int index)
Handle click on the entry in the Build Tram menu.
static const int GRMN_COMPANY_VALUE_GRAPH
Show company value graph.
void ToggleDirtyBlocks()
Toggle drawing of the dirty blocks.
static CallBackFunction MenuClickGoal(int index)
Handle click on the entry in the Goal menu.
static CallBackFunction ToolbarScenBuildRoad(int index)
Handle click on the entry in the Build Road menu.
static CallBackFunction MenuClickBuildRoad(int index)
Handle click on the entry in the Build Road menu.
static CallBackFunction _last_started_action
Last started user action.
static CallBackFunction MenuClickShowTrains(int index)
Handle click on the entry in the Train menu.
static CallBackFunction MenuClickMap(int index)
Handle click on one of the entries in the Map menu.
static const int GRMN_OPERATING_PROFIT_GRAPH
Enum for the League Toolbar's and Graph Toolbar's related buttons.
static CallBackFunction MenuClickBuildRail(int index)
Handle click on the entry in the Build Rail menu.
static CallBackFunction MenuClickShowAir(int index)
Handle click on the entry in the Aircraft menu.
void AllocateToolbar()
Allocate the toolbar.
static const int GRMN_CARGO_PAYMENT_RATES
Show cargo payment rates graph.
static CallBackFunction ToolbarScenSaveOrLoad(Window *w)
Handle click on SaveLoad button in toolbar in the scenario editor.
static CallBackFunction MenuClickBuildTram(int index)
Handle click on the entry in the Build Tram menu.
static CallBackFunction ToolbarFastForwardClick(Window *)
Toggle fast forward mode.
OptionMenuEntries
Game Option button menu entries.
static CallBackFunction ToolbarScenDatePanel(Window *w)
Called when clicking at the date panel of the scenario editor toolbar.
static void PopupMainCompanyToolbMenu(Window *w, WidgetID widget, CompanyMask grey={})
Pop up a generic company list menu.
static CallBackFunction MenuClickBuildWater(int)
Handle click on the entry in the Build Waterways menu.
static const int CTMN_SPECTATE
Become spectator.
static CallBackFunction MenuClickSubsidies(int)
Handle click on the entry in the Subsidies menu.
void SetStartingYear(TimerGameCalendar::Year year)
Set the starting year for a scenario.
static const int LTMN_HIGHSCORE
Show highscrore table.
static CallBackFunction MenuClickStory(int index)
Handle click on the entry in the Story menu.
void ToggleBoundingBoxes()
Toggle drawing of sprites' bounding boxes.
static CallBackFunction MenuClickBuildAir(int)
Handle click on the entry in the Build Air menu.
void ToggleWidgetOutlines()
Toggle drawing of widget outlines.
static CallBackFunction MenuClickSettings(int index)
Handle click on one of the entries in the Options button menu.
static CallBackFunction MenuClickFinances(int index)
Handle click on the entry in the finances overview menu.
static CallBackFunction MenuClickIndustry(int index)
Handle click on the entry in the Industry menu.
static const int CTMN_SPECTATOR
Show a company window as spectator.
Stuff related to the (main) toolbar.
Types related to the toolbar widgets.
@ WID_TE_SMALL_MAP
Small map menu.
@ WID_TE_TREES
Tree building toolbar.
@ WID_TE_TRAMS
Tram building menu.
@ WID_TE_DATE
The date of the scenario.
@ WID_TE_ZOOM_IN
Zoom in the main viewport.
@ WID_TE_DATE_PANEL
Container for the date widgets.
@ WID_TE_HELP
Help menu.
@ WID_TE_ZOOM_OUT
Zoom out the main viewport.
@ WID_TE_INDUSTRY
Industry building window.
@ WID_TE_PAUSE
Pause the game.
@ WID_TE_DATE_FORWARD
Increase the date of the scenario.
@ WID_TE_SPACER
Spacer with "scenario editor" text.
@ WID_TE_WATER
Water building toolbar.
@ WID_TE_MUSIC_SOUND
Music/sound configuration menu.
@ WID_TE_SAVE
Save menu.
@ WID_TE_LAND_GENERATE
Land generation.
@ WID_TE_TOWN_GENERATE
Town building window.
@ WID_TE_SWITCH_BAR
Only available when toolbar has been split to switch between different subsets.
@ WID_TE_ROADS
Road building menu.
@ WID_TE_FAST_FORWARD
Fast forward the game.
@ WID_TE_SIGNS
Sign building.
@ WID_TE_SETTINGS
Settings menu.
@ WID_TE_DATE_BACKWARD
Reduce the date of the scenario.
@ WID_TN_LANDSCAPE
Landscaping toolbar.
@ WID_TN_AIR
Airport building toolbar.
@ WID_TN_SHIPS
Ship menu.
@ WID_TN_SETTINGS
Settings menu.
@ WID_TN_GOAL
Goal menu.
@ WID_TN_MUSIC_SOUND
Music/sound configuration menu.
@ WID_TN_RAILS
Rail building menu.
@ WID_TN_SUBSIDIES
Subsidy menu.
@ WID_TN_BUILDING_TOOLS_START
Helper for the offset of the building tools.
@ WID_TN_TRAMS
Tram building menu.
@ WID_TN_HELP
Help menu.
@ WID_TN_SAVE
Save menu.
@ WID_TN_STORY
Story menu.
@ WID_TN_MESSAGES
Messages menu.
@ WID_TN_ROADVEHS
Road vehicle menu.
@ WID_TN_VEHICLE_START
Helper for the offset of the vehicle menus.
@ WID_TN_FINANCES
Finance menu.
@ WID_TN_GRAPHS
Graph menu.
@ WID_TN_LEAGUE
Company league menu.
@ WID_TN_STATIONS
Station menu.
@ WID_TN_SWITCH_BAR
Only available when toolbar has been split to switch between different subsets.
@ WID_TN_COMPANIES
Company menu.
@ WID_TN_INDUSTRIES
Industry menu.
@ WID_TN_AIRCRAFT
Aircraft menu.
@ WID_TN_ZOOM_OUT
Zoom out the main viewport.
@ WID_TN_FAST_FORWARD
Fast forward the game.
@ WID_TN_ZOOM_IN
Zoom in the main viewport.
@ WID_TN_PAUSE
Pause the game.
@ WID_TN_WATER
Water building toolbar.
@ WID_TN_ROADS
Road building menu.
@ WID_TN_TRAINS
Train menu.
@ WID_TN_TOWNS
Town menu.
@ WID_TN_SMALL_MAP
Small map menu.
@ TF_FORBIDDEN
Forbidden.
Definition town_type.h:105
StationFacilities _facility_display_opt
What station facilities to draw.
void ToggleTransparency(TransparencyOption to)
Toggle the transparency option bit.
bool IsTransparencySet(TransparencyOption to)
Check if the transparency option bit is set and if we aren't in the game menu (there's never transpar...
uint8_t _display_opt
What do we want to draw/do?
@ TO_HOUSES
town buildings
@ TO_SIGNS
signs
void ShowTransparencyToolbar()
Show the transparency toolbar.
GUI functions related to transparency.
Base class for all vehicles.
Functions related to vehicles.
Functions related to the vehicle's GUIs.
VehicleType
Available vehicle types.
@ VEH_ROAD
Road vehicle type.
@ VEH_AIRCRAFT
Aircraft vehicle type.
@ VEH_SHIP
Ship vehicle type.
@ VEH_TRAIN
Train vehicle type.
void HandleZoomMessage(Window *w, const Viewport &vp, WidgetID widget_zoom_in, WidgetID widget_zoom_out)
Update the status of the zoom-buttons according to the zoom-level of the viewport.
Definition viewport.cpp:486
Functions related to (drawing on) viewports.
@ ZOOM_IN
Zoom in (get more detailed view).
@ ZOOM_NONE
Hack, used to update the button status.
@ ZOOM_OUT
Zoom out (get helicopter view).
WidgetType
Window widget types, nested widget types, and nested widget part types.
Definition widget_type.h:36
@ WWT_IMGBTN
(Toggle) Button with image
Definition widget_type.h:42
@ WWT_IMGBTN_2
(Toggle) Button with diff image when clicked
Definition widget_type.h:43
@ WWT_PUSHIMGBTN
Normal push-button (no toggle button) with image caption.
@ NWID_SPACER
Invisible widget that takes some space.
Definition widget_type.h:71
@ NWID_HORIZONTAL
Horizontal container.
Definition widget_type.h:67
@ WWT_PANEL
Simple depressed panel.
Definition widget_type.h:40
@ WWT_TEXT
Pure simple text.
Definition widget_type.h:50
SizingType
Different forms of sizing nested widgets, using NWidgetBase::AssignSizePosition()
Window * GetMainWindow()
Get the main window, i.e.
Definition window.cpp:1180
int PositionMainToolbar(Window *w)
(Re)position main toolbar window at the screen.
Definition window.cpp:3447
void DeleteAllMessages()
Delete all messages and close their corresponding window (if any).
Definition window.cpp:3350
void InvalidateWindowClassesData(WindowClass cls, int data, bool gui_scope)
Mark window data of all windows of a given class as invalid (in need of re-computing) Note that by de...
Definition window.cpp:3293
Window functions not directly related to making/drawing windows.
Functions, definitions and such used only by the GUI.
@ NoClose
This window can't be interactively closed.
@ NoFocus
This window won't get focus/make any other window lose focus when click.
@ WhiteBorder
Window white border counter bit mask.
@ Timeout
Window timeout counter.
@ WDP_MANUAL
Manually align the window (so no automatic location finding)
Definition window_gui.h:143
int WidgetID
Widget ID.
Definition window_type.h:20
EventState
State of handling an event.
@ ES_HANDLED
The passed event is handled.
@ ES_NOT_HANDLED
The passed event is not handled.
@ WC_SIGN_LIST
Sign list; Window numbers:
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition window_type.h:50
@ WC_MAIN_TOOLBAR
Main toolbar (the long bar at the top); Window numbers:
Definition window_type.h:63