OpenTTD Source 20260820-master-g39da062c0c
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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
9
10#include "stdafx.h"
12#include "gui.h"
13#include "spritecache.h"
14#include "window_gui.h"
15#include "window_func.h"
16#include "viewport_func.h"
17#include "command_func.h"
18#include "dropdown_type.h"
19#include "dropdown_func.h"
20#include "house.h"
21#include "vehicle_gui.h"
22#include "rail_gui.h"
23#include "road.h"
24#include "road_gui.h"
25#include "vehicle_func.h"
26#include "sound_func.h"
27#include "terraform_gui.h"
28#include "object.h"
29#include "newgrf_object.h"
30#include "strings_func.h"
31#include "company_func.h"
32#include "company_gui.h"
33#include "vehicle_base.h"
34#include "cheat_func.h"
35#include "transparency_gui.h"
36#include "screenshot.h"
37#include "signs_func.h"
38#include "fios.h"
39#include "console_gui.h"
40#include "news_gui.h"
41#include "ai/ai_gui.hpp"
42#include "game/game_gui.hpp"
43#include "script/script_gui.h"
44#include "tilehighlight_func.h"
45#include "smallmap_gui.h"
46#include "graph_gui.h"
47#include "textbuf_gui.h"
49#include "newgrf_debug.h"
50#include "hotkeys.h"
51#include "engine_base.h"
52#include "highscore.h"
53#include "game/game.hpp"
54#include "goal_base.h"
55#include "goal_gui.h"
56#include "story_base.h"
57#include "toolbar_gui.h"
58#include "framerate_type.h"
59#include "screenshot_gui.h"
60#include "misc_cmd.h"
61#include "league_gui.h"
62#include "league_base.h"
63#include "timer/timer.h"
64#include "timer/timer_window.h"
66#include "help_gui.h"
68#include "screensaver.h"
69
71
72#include "network/network.h"
73#include "network/network_gui.h"
75
76#include "table/strings.h"
77
79
80#include "safeguards.h"
81
82
85
89
91enum class ToolbarMode : uint8_t {
95};
96
103
105
109class DropDownListCompanyItem : public DropDownIcon<DropDownIcon<DropDownString<DropDownListItem>, true>> {
110public:
111 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)
112 {
113 }
114};
115
122{
123 if (_settings_client.gui.toolbar_dropdown_autoselect) options.Set(DropDownOption::InstantClose).Reset(DropDownOption::Filterable);
124 return options;
125}
126
134static void PopupMainToolbarMenu(Window *w, WidgetID widget, DropDownList &&list, int def)
135{
136 ShowDropDownList(w, std::move(list), def, widget, 0, GetToolbarDropDownOptions());
137}
138
145static void PopupMainToolbarMenu(Window *w, WidgetID widget, const std::initializer_list<StringID> &strings)
146{
147 DropDownList list;
148 int i = 0;
149 for (StringID string : strings) {
150 if (string == STR_NULL) {
151 list.push_back(MakeDropDownListDividerItem());
152 } else {
153 list.push_back(MakeDropDownListStringItem(string, i));
154 i++;
155 }
156 }
157 PopupMainToolbarMenu(w, widget, std::move(list), 0);
158}
159
160/* Special values used in the dropdowns related to companies.
161 * They cannot interfere with valid IDs for companies. */
162static const int CTMN_CLIENT_LIST = MAX_COMPANIES;
163static const int CTMN_SPECTATE = COMPANY_SPECTATOR.base();
164static const int CTMN_SPECTATOR = CompanyID::Invalid().base();
165
172static void PopupMainCompanyToolbMenu(Window *w, WidgetID widget, CompanyMask grey = {})
173{
174 DropDownList list;
175
176 switch (widget) {
177 case WID_TN_COMPANIES:
178 if (!_networking) break;
179
180 /* Add the client list button for the companies menu */
181 list.push_back(MakeDropDownListStringItem(STR_NETWORK_COMPANY_LIST_CLIENT_LIST, CTMN_CLIENT_LIST));
182
184 list.push_back(MakeDropDownListStringItem(STR_NETWORK_COMPANY_LIST_SPECTATE, CTMN_SPECTATE));
185 }
186 break;
187 case WID_TN_STORY:
188 list.push_back(MakeDropDownListStringItem(STR_STORY_BOOK_SPECTATOR, CTMN_SPECTATOR));
189 break;
190
191 case WID_TN_GOAL:
192 list.push_back(MakeDropDownListStringItem(STR_GOALS_SPECTATOR, CTMN_SPECTATOR));
193 break;
194 }
195
196 for (CompanyID c = CompanyID::Begin(); c < MAX_COMPANIES; ++c) {
197 if (!Company::IsValidID(c)) continue;
198 list.push_back(std::make_unique<DropDownListCompanyItem>(c, grey.Test(c)));
199 }
200
202}
203
204static ToolbarMode _toolbar_mode;
205
206static CallBackFunction SelectSignTool()
207{
211 } else {
212 SetObjectToPlace(SPR_CURSOR_SIGN, PAL_NONE, HT_RECT, WindowClass::MainToolbar, 0);
214 }
215}
216
217/* --- Pausing --- */
218
219static CallBackFunction ToolbarPauseClick(Window *)
220{
221 if (_networking && !_network_server) return CallBackFunction::None; // only server can pause the game
222
223 if (Command<Commands::Pause>::Post(PauseMode::Normal, _pause_mode.None())) {
225 }
227}
228
235{
236 if (_networking) return CallBackFunction::None; // no fast forward in network game
237
238 ChangeGameSpeed(_game_speed == 100);
239
240 SndClickBeep();
242}
243
270
278{
279 DropDownList list;
280 list.push_back(MakeDropDownListStringItem(STR_SETTINGS_MENU_GAME_OPTIONS, OptionMenuEntries::GameOptions));
281 /* Changes to the per-AI settings don't get send from the server to the clients. Clients get
282 * the settings once they join but never update it. As such don't show the window at all
283 * to network clients. */
285 list.push_back(MakeDropDownListStringItem(STR_SETTINGS_MENU_AI_SETTINGS, OptionMenuEntries::AISettings));
286 list.push_back(MakeDropDownListStringItem(STR_SETTINGS_MENU_GAMESCRIPT_SETTINGS, OptionMenuEntries::GameScriptSettings));
287 }
288 list.push_back(MakeDropDownListStringItem(STR_SETTINGS_MENU_NEWGRF_SETTINGS, OptionMenuEntries::NewGRFSettings));
289 if (_game_mode != GameMode::Editor && !_networking) {
290 list.push_back(MakeDropDownListStringItem(STR_SETTINGS_MENU_SANDBOX_OPTIONS, OptionMenuEntries::SandboxOptions));
291 }
292 list.push_back(MakeDropDownListStringItem(STR_SETTINGS_MENU_TRANSPARENCY_OPTIONS, OptionMenuEntries::Transparencies));
293 list.push_back(MakeDropDownListDividerItem());
294 list.push_back(MakeDropDownListCheckedItem(_display_opt.Test(DisplayOption::ShowTownNames), STR_SETTINGS_MENU_TOWN_NAMES_DISPLAYED, OptionMenuEntries::ShowTownNames));
295 list.push_back(MakeDropDownListCheckedItem(_display_opt.Test(DisplayOption::ShowStationNames), STR_SETTINGS_MENU_STATION_NAMES_DISPLAYED, OptionMenuEntries::ShowStationNames));
296 list.push_back(MakeDropDownListCheckedItem(_facility_display_opt.Test(StationFacility::Train), STR_SETTINGS_MENU_STATION_NAMES_TRAIN, OptionMenuEntries::ShowTrainStationNames, false, false, 1));
297 list.push_back(MakeDropDownListCheckedItem(_facility_display_opt.Test(StationFacility::TruckStop), STR_SETTINGS_MENU_STATION_NAMES_LORRY, OptionMenuEntries::ShowLorryStationNames, false, false, 1));
298 list.push_back(MakeDropDownListCheckedItem(_facility_display_opt.Test(StationFacility::BusStop), STR_SETTINGS_MENU_STATION_NAMES_BUS, OptionMenuEntries::ShowBusStationNames, false, false, 1));
299 list.push_back(MakeDropDownListCheckedItem(_facility_display_opt.Test(StationFacility::Dock), STR_SETTINGS_MENU_STATION_NAMES_SHIP, OptionMenuEntries::ShowDockNames, false, false, 1));
300 list.push_back(MakeDropDownListCheckedItem(_facility_display_opt.Test(StationFacility::Airport), STR_SETTINGS_MENU_STATION_NAMES_PLANE, OptionMenuEntries::ShowAirportNames, false, false, 1));
301 list.push_back(MakeDropDownListCheckedItem(_facility_display_opt.Test(STATION_FACILITY_GHOST), STR_SETTINGS_MENU_STATION_NAMES_GHOST, OptionMenuEntries::ShowGhostStationNames, false, false, 1));
302 list.push_back(MakeDropDownListCheckedItem(_display_opt.Test(DisplayOption::ShowWaypointNames), STR_SETTINGS_MENU_WAYPOINTS_DISPLAYED, OptionMenuEntries::ShowWaypointNames));
303 list.push_back(MakeDropDownListCheckedItem(_display_opt.Test(DisplayOption::ShowSigns), STR_SETTINGS_MENU_SIGNS_DISPLAYED, OptionMenuEntries::ShowSigns));
304 list.push_back(MakeDropDownListCheckedItem(_display_opt.Test(DisplayOption::ShowCompetitorSigns), STR_SETTINGS_MENU_SHOW_COMPETITOR_SIGNS, OptionMenuEntries::ShowCompetitorSigns));
305 list.push_back(MakeDropDownListCheckedItem(_display_opt.Test(DisplayOption::FullAnimation), STR_SETTINGS_MENU_FULL_ANIMATION, OptionMenuEntries::FullAnimation));
306 list.push_back(MakeDropDownListCheckedItem(_display_opt.Test(DisplayOption::FullDetail), STR_SETTINGS_MENU_FULL_DETAIL, OptionMenuEntries::FullDetails));
309
310 ShowDropDownList(w, std::move(list), 0, WID_TN_SETTINGS, 140, GetToolbarDropDownOptions());
312}
313
321{
322 switch (OptionMenuEntries(index)) {
326 case OptionMenuEntries::NewGRFSettings: ShowNewGRFSettings(!_networking && _settings_client.gui.UserIsAllowedToChangeNewGRFs(), true, true, _grfconfig); return CallBackFunction::None;
329
342 InvalidateWindowClassesData(WindowClass::SignList, -1);
343 break;
348 }
351}
352
364
374
382{
383 PopupMainToolbarMenu(w, WID_TN_SAVE, {STR_FILE_MENU_SAVE_GAME, STR_FILE_MENU_LOAD_GAME, STR_FILE_MENU_QUIT_GAME,
384 STR_NULL, STR_FILE_MENU_EXIT});
386}
387
395{
396 PopupMainToolbarMenu(w, WID_TE_SAVE, {STR_SCENEDIT_FILE_MENU_SAVE_SCENARIO, STR_SCENEDIT_FILE_MENU_LOAD_SCENARIO,
397 STR_SCENEDIT_FILE_MENU_SAVE_HEIGHTMAP, STR_SCENEDIT_FILE_MENU_LOAD_HEIGHTMAP,
398 STR_SCENEDIT_FILE_MENU_QUIT_EDITOR, STR_NULL, STR_SCENEDIT_FILE_MENU_QUIT});
400}
401
429
430/* --- Map button menu --- */
431
433enum class MapMenuEntries : uint8_t {
438 ShowTownDirectory,
439 ShowIndustryDirectory,
440};
441
442static CallBackFunction ToolbarMapClick(Window *w)
443{
444 DropDownList list;
445 list.push_back(MakeDropDownListStringItem(STR_MAP_MENU_MAP_OF_WORLD, MapMenuEntries::ShowSmallMap));
446 list.push_back(MakeDropDownListStringItem(STR_MAP_MENU_EXTRA_VIEWPORT, MapMenuEntries::ShowExtraViewport));
447 list.push_back(MakeDropDownListStringItem(STR_MAP_MENU_LINGRAPH_LEGEND, MapMenuEntries::ShowLinkGraph));
448 list.push_back(MakeDropDownListStringItem(STR_MAP_MENU_SIGN_LIST, MapMenuEntries::ShowSignList));
449 PopupMainToolbarMenu(w, WID_TN_SMALL_MAP, std::move(list), 0);
451}
452
453static CallBackFunction ToolbarScenMapTownDir(Window *w)
454{
455 DropDownList list;
456 list.push_back(MakeDropDownListStringItem(STR_MAP_MENU_MAP_OF_WORLD, MapMenuEntries::ShowSmallMap));
457 list.push_back(MakeDropDownListStringItem(STR_MAP_MENU_EXTRA_VIEWPORT, MapMenuEntries::ShowExtraViewport));
458 list.push_back(MakeDropDownListStringItem(STR_MAP_MENU_SIGN_LIST, MapMenuEntries::ShowSignList));
459 list.push_back(MakeDropDownListStringItem(STR_TOWN_MENU_TOWN_DIRECTORY, MapMenuEntries::ShowTownDirectory));
460 list.push_back(MakeDropDownListStringItem(STR_INDUSTRY_MENU_INDUSTRY_DIRECTORY, MapMenuEntries::ShowIndustryDirectory));
461 PopupMainToolbarMenu(w, WID_TE_SMALL_MAP, std::move(list), 0);
463}
464
483
484/* --- Town button menu --- */
485
492
493static CallBackFunction ToolbarTownClick(Window *w)
494{
495 DropDownList list;
496 list.push_back(MakeDropDownListStringItem(STR_TOWN_MENU_TOWN_DIRECTORY, TownMenuEntries::ShowDirectory));
497 if (_settings_game.economy.found_town != TownFounding::Forbidden) list.push_back(MakeDropDownListStringItem(STR_TOWN_MENU_FOUND_TOWN, TownMenuEntries::ShowFoundTown));
498 if (_settings_game.economy.place_houses != PlaceHouses::Forbidden) list.push_back(MakeDropDownListStringItem(STR_SCENEDIT_TOWN_MENU_PACE_HOUSE, TownMenuEntries::ShowPlaceHouses));
499
500 PopupMainToolbarMenu(w, WID_TN_TOWNS, std::move(list), 0);
501
503}
504
512{
513 switch (TownMenuEntries(index)) {
515 case TownMenuEntries::ShowFoundTown: // Setting could be changed when the dropdown was open
516 if (_settings_game.economy.found_town != TownFounding::Forbidden) ShowFoundTownWindow();
517 break;
518 case TownMenuEntries::ShowPlaceHouses: // Setting could be changed when the dropdown was open
519 if (_settings_game.economy.place_houses != PlaceHouses::Forbidden) ShowBuildHousePicker(nullptr);
520 break;
521 }
523}
524
525/* --- Subidies button menu --- */
526
527static CallBackFunction ToolbarSubsidiesClick(Window *w)
528{
529 PopupMainToolbarMenu(w, WID_TN_SUBSIDIES, {STR_SUBSIDIES_MENU_SUBSIDIES});
531}
532
539{
540 ShowSubsidiesList();
542}
543
544/* --- Stations button menu --- */
545
546static CallBackFunction ToolbarStationsClick(Window *w)
547{
550}
551
559{
560 ShowCompanyStations((CompanyID)index);
562}
563
564/* --- Finances button menu --- */
565
566static CallBackFunction ToolbarFinancesClick(Window *w)
567{
570}
571
579{
580 ShowCompanyFinances((CompanyID)index);
582}
583
584/* --- Company's button menu --- */
585
586static CallBackFunction ToolbarCompaniesClick(Window *w)
587{
590}
591
599{
600 if (_networking) {
601 switch (index) {
602 case CTMN_CLIENT_LIST:
605
606 case CTMN_SPECTATE:
607 if (_network_server) {
610 } else {
612 }
614 }
615 }
616 ShowCompany((CompanyID)index);
618}
619
620/* --- Story button menu --- */
621
622static CallBackFunction ToolbarStoryClick(Window *w)
623{
626}
627
635{
636 ShowStoryBook(CompanyID(index));
638}
639
640/* --- Goal button menu --- */
641
642static CallBackFunction ToolbarGoalClick(Window *w)
643{
646}
647
655{
656 ShowGoalsList(CompanyID(index));
658}
659
660/* --- Graphs and League Table button menu --- */
661
666static const int GRMN_OPERATING_PROFIT_GRAPH = -1;
667static const int GRMN_INCOME_GRAPH = -2;
668static const int GRMN_DELIVERED_CARGO_GRAPH = -3;
669static const int GRMN_PERFORMANCE_HISTORY_GRAPH = -4;
670static const int GRMN_COMPANY_VALUE_GRAPH = -5;
671static const int GRMN_CARGO_PAYMENT_RATES = -6;
672static const int LTMN_PERFORMANCE_LEAGUE = -7;
673static const int LTMN_PERFORMANCE_RATING = -8;
674static const int LTMN_HIGHSCORE = -9;
675
676static void AddDropDownLeagueTableOptions(DropDownList &list)
677{
678 if (LeagueTable::GetNumItems() > 0) {
679 for (LeagueTable *lt : LeagueTable::Iterate()) {
680 list.push_back(MakeDropDownListStringItem(lt->title.GetDecodedString(), lt->index.base()));
681 }
682 } else {
683 list.push_back(MakeDropDownListStringItem(STR_GRAPH_MENU_COMPANY_LEAGUE_TABLE, LTMN_PERFORMANCE_LEAGUE));
684 list.push_back(MakeDropDownListStringItem(STR_GRAPH_MENU_DETAILED_PERFORMANCE_RATING, LTMN_PERFORMANCE_RATING));
685 if (!_networking) {
686 list.push_back(MakeDropDownListStringItem(STR_GRAPH_MENU_HIGHSCORE, LTMN_HIGHSCORE));
687 }
688 }
689}
690
691static CallBackFunction ToolbarGraphsClick(Window *w)
692{
693 DropDownList list;
694
695 list.push_back(MakeDropDownListStringItem(STR_GRAPH_MENU_OPERATING_PROFIT_GRAPH, GRMN_OPERATING_PROFIT_GRAPH));
696 list.push_back(MakeDropDownListStringItem(STR_GRAPH_MENU_INCOME_GRAPH, GRMN_INCOME_GRAPH));
697 list.push_back(MakeDropDownListStringItem(STR_GRAPH_MENU_DELIVERED_CARGO_GRAPH, GRMN_DELIVERED_CARGO_GRAPH));
698 list.push_back(MakeDropDownListStringItem(STR_GRAPH_MENU_PERFORMANCE_HISTORY_GRAPH, GRMN_PERFORMANCE_HISTORY_GRAPH));
699 list.push_back(MakeDropDownListStringItem(STR_GRAPH_MENU_COMPANY_VALUE_GRAPH, GRMN_COMPANY_VALUE_GRAPH));
700 list.push_back(MakeDropDownListStringItem(STR_GRAPH_MENU_CARGO_PAYMENT_RATES, GRMN_CARGO_PAYMENT_RATES));
701
702 if (_toolbar_mode != ToolbarMode::Normal) AddDropDownLeagueTableOptions(list);
703
706}
707
708static CallBackFunction ToolbarLeagueClick(Window *w)
709{
710 DropDownList list;
711
712 AddDropDownLeagueTableOptions(list);
713
714 int selected = list[0]->result;
715 ShowDropDownList(w, std::move(list), selected, WID_TN_LEAGUE, 140, GetToolbarDropDownOptions());
717}
718
726{
727 switch (index) {
728 case GRMN_OPERATING_PROFIT_GRAPH: ShowOperatingProfitGraph(); break;
729 case GRMN_INCOME_GRAPH: ShowIncomeGraph(); break;
730 case GRMN_DELIVERED_CARGO_GRAPH: ShowDeliveredCargoGraph(); break;
731 case GRMN_PERFORMANCE_HISTORY_GRAPH: ShowPerformanceHistoryGraph(); break;
732 case GRMN_COMPANY_VALUE_GRAPH: ShowCompanyValueGraph(); break;
733 case GRMN_CARGO_PAYMENT_RATES: ShowCargoPaymentRates(); break;
734 case LTMN_PERFORMANCE_LEAGUE: ShowPerformanceLeagueTable(); break;
735 case LTMN_PERFORMANCE_RATING: ShowPerformanceRatingDetail(); break;
736 case LTMN_HIGHSCORE: ShowHighscoreTable(); break;
737 default: {
738 if (LeagueTable::IsValidID(index)) {
739 ShowScriptLeagueTable((LeagueTableID)index);
740 }
741 }
742 }
744}
745
746
747
748/* --- Industries button menu --- */
749
750static CallBackFunction ToolbarIndustryClick(Window *w)
751{
752 /* Disable build-industry menu if we are a spectator */
754 PopupMainToolbarMenu(w, WID_TN_INDUSTRIES, {STR_INDUSTRY_MENU_INDUSTRY_DIRECTORY, STR_INDUSTRY_MENU_INDUSTRY_CHAIN});
755 } else {
756 PopupMainToolbarMenu(w, WID_TN_INDUSTRIES, {STR_INDUSTRY_MENU_INDUSTRY_DIRECTORY, STR_INDUSTRY_MENU_INDUSTRY_CHAIN, STR_INDUSTRY_MENU_FUND_NEW_INDUSTRY});
757 }
759}
760
768{
769 switch (index) {
770 case 0: ShowIndustryDirectory(); break;
771 case 1: ShowIndustryCargoesWindow(); break;
772 case 2: ShowBuildIndustryWindow(); break;
773 }
775}
776
777/* --- Trains button menu + 1 helper function for all vehicles. --- */
778
779static void ToolbarVehicleClick(Window *w, VehicleType veh)
780{
781 CompanyMask dis{};
782
783 for (const Company *c : Company::Iterate()) {
784 if (c->group_all[veh].num_vehicle == 0) dis.Set(c->index);
785 }
787}
788
789
790static CallBackFunction ToolbarTrainClick(Window *w)
791{
792 ToolbarVehicleClick(w, VehicleType::Train);
794}
795
803{
804 ShowVehicleListWindow((CompanyID)index, VehicleType::Train);
806}
807
808/* --- Road vehicle button menu --- */
809
810static CallBackFunction ToolbarRoadClick(Window *w)
811{
812 ToolbarVehicleClick(w, VehicleType::Road);
814}
815
823{
824 ShowVehicleListWindow((CompanyID)index, VehicleType::Road);
826}
827
828/* --- Ship button menu --- */
829
830static CallBackFunction ToolbarShipClick(Window *w)
831{
832 ToolbarVehicleClick(w, VehicleType::Ship);
834}
835
843{
844 ShowVehicleListWindow((CompanyID)index, VehicleType::Ship);
846}
847
848/* --- Aircraft button menu --- */
849
850static CallBackFunction ToolbarAirClick(Window *w)
851{
852 ToolbarVehicleClick(w, VehicleType::Aircraft);
854}
855
863{
864 ShowVehicleListWindow((CompanyID)index, VehicleType::Aircraft);
866}
867
868/* --- Zoom in button --- */
869
870static CallBackFunction ToolbarZoomInClick(Window *w)
871{
874 }
876}
877
878/* --- Zoom out button --- */
879
880static CallBackFunction ToolbarZoomOutClick(Window *w)
881{
884 }
886}
887
888/* --- Rail button menu --- */
889
890static std::string _railtype_filter;
891static std::string _roadtype_filter;
892static std::string _tramtype_filter;
893
894static CallBackFunction ToolbarBuildRailClick(Window *w)
895{
898}
899
912
913/* --- Road button menu --- */
914
915static CallBackFunction ToolbarBuildRoadClick(Window *w)
916{
919}
920
933
934/* --- Tram button menu --- */
935
936static CallBackFunction ToolbarBuildTramClick(Window *w)
937{
940}
941
954
955/* --- Water button menu --- */
956
957static CallBackFunction ToolbarBuildWaterClick(Window *w)
958{
959 DropDownList list;
960 list.push_back(MakeDropDownListIconItem(SPR_IMG_BUILD_CANAL, PAL_NONE, STR_WATERWAYS_MENU_WATERWAYS_CONSTRUCTION, 0));
961 ShowDropDownList(w, std::move(list), 0, WID_TN_WATER, 140, GetToolbarDropDownOptions());
963}
964
975
976/* --- Airport button menu --- */
977
978static CallBackFunction ToolbarBuildAirClick(Window *w)
979{
980 DropDownList list;
981 list.push_back(MakeDropDownListIconItem(SPR_IMG_AIRPORT, PAL_NONE, STR_AIRCRAFT_MENU_AIRPORT_CONSTRUCTION, 0));
982 ShowDropDownList(w, std::move(list), 0, WID_TN_AIR, 140, GetToolbarDropDownOptions());
984}
985
996
997/* --- Forest button menu --- */
998
999static CallBackFunction ToolbarForestClick(Window *w)
1000{
1001 DropDownList list;
1002 list.push_back(MakeDropDownListIconItem(SPR_IMG_LANDSCAPING, PAL_NONE, STR_LANDSCAPING_MENU_LANDSCAPING, 0));
1003 list.push_back(MakeDropDownListIconItem(SPR_IMG_PLANTTREES, PAL_NONE, STR_LANDSCAPING_MENU_PLANT_TREES, 1));
1004 list.push_back(MakeDropDownListIconItem(SPR_IMG_SIGN, PAL_NONE, STR_LANDSCAPING_MENU_PLACE_SIGN, 2));
1005 if (ObjectClass::GetUIClassCount() != 0) {
1006 list.push_back(MakeDropDownListIconItem(SPR_IMG_TRANSMITTER, PAL_NONE, STR_LANDSCAPING_MENU_PLACE_OBJECT, 3));
1007 }
1008 ShowDropDownList(w, std::move(list), 0, WID_TN_LANDSCAPE, 100, GetToolbarDropDownOptions());
1010}
1011
1019{
1020 switch (index) {
1021 case 0: ShowTerraformToolbar(); break;
1022 case 1: ShowBuildTreesToolbar(); break;
1023 case 2: return SelectSignTool();
1024 case 3: ShowBuildObjectPicker(); break;
1025 }
1027}
1028
1029/* --- Music button menu --- */
1030
1031static CallBackFunction ToolbarMusicClick(Window *w)
1032{
1033 PopupMainToolbarMenu(w, _game_mode == GameMode::Editor ? (WidgetID)WID_TE_MUSIC_SOUND : (WidgetID)WID_TN_MUSIC_SOUND, {STR_TOOLBAR_SOUND_MUSIC});
1035}
1036
1043{
1044 ShowMusicWindow();
1046}
1047
1048/* --- Newspaper button menu --- */
1049
1050static CallBackFunction ToolbarNewspaperClick(Window *w)
1051{
1052 PopupMainToolbarMenu(w, WID_TN_MESSAGES, {STR_NEWS_MENU_LAST_MESSAGE_NEWS_REPORT, STR_NEWS_MENU_MESSAGE_HISTORY_MENU, STR_NEWS_MENU_DELETE_ALL_MESSAGES});
1054}
1055
1063{
1064 switch (index) {
1065 case 0: ShowLastNewsMessage(); break;
1066 case 1: ShowMessageHistory(); break;
1067 case 2: DeleteAllMessages(); break;
1068 }
1070}
1071
1072/* --- Help button menu --- */
1073
1074static CallBackFunction PlaceLandBlockInfo()
1075{
1079 } else {
1080 SetObjectToPlace(SPR_CURSOR_QUERY, PAL_NONE, HT_RECT, WindowClass::MainToolbar, 0);
1082 }
1083}
1084
1085static CallBackFunction ToolbarHelpClick(Window *w)
1086{
1087 if (_settings_client.gui.newgrf_developer_tools) {
1088 PopupMainToolbarMenu(w, _game_mode == GameMode::Editor ? (WidgetID)WID_TE_HELP : (WidgetID)WID_TN_HELP, {STR_ABOUT_MENU_LAND_BLOCK_INFO,
1089 STR_ABOUT_MENU_HELP, STR_NULL, STR_ABOUT_MENU_ENTER_SCREENSAVER_MODE,
1090 STR_ABOUT_MENU_TOGGLE_CONSOLE, STR_ABOUT_MENU_AI_DEBUG,
1091 STR_ABOUT_MENU_SCREENSHOT, STR_ABOUT_MENU_SHOW_FRAMERATE, STR_ABOUT_MENU_ABOUT_OPENTTD,
1092 STR_ABOUT_MENU_SPRITE_ALIGNER, STR_ABOUT_MENU_TOGGLE_BOUNDING_BOXES, STR_ABOUT_MENU_TOGGLE_DIRTY_BLOCKS,
1093 STR_ABOUT_MENU_TOGGLE_WIDGET_OUTLINES});
1094 } else {
1095 PopupMainToolbarMenu(w, _game_mode == GameMode::Editor ? (WidgetID)WID_TE_HELP : (WidgetID)WID_TN_HELP, {STR_ABOUT_MENU_LAND_BLOCK_INFO,
1096 STR_ABOUT_MENU_HELP, STR_NULL, STR_ABOUT_MENU_ENTER_SCREENSAVER_MODE, STR_ABOUT_MENU_TOGGLE_CONSOLE, STR_ABOUT_MENU_AI_DEBUG,
1097 STR_ABOUT_MENU_SCREENSHOT, STR_ABOUT_MENU_SHOW_FRAMERATE, STR_ABOUT_MENU_ABOUT_OPENTTD});
1098 }
1100}
1101
1110{
1111 extern bool _draw_bounding_boxes;
1112 /* Always allow to toggle them off */
1113 if (_settings_client.gui.newgrf_developer_tools || _draw_bounding_boxes) {
1114 _draw_bounding_boxes = !_draw_bounding_boxes;
1116 }
1117}
1118
1127{
1128 extern bool _draw_dirty_blocks;
1129 /* Always allow to toggle them off */
1130 if (_settings_client.gui.newgrf_developer_tools || _draw_dirty_blocks) {
1131 _draw_dirty_blocks = !_draw_dirty_blocks;
1133 }
1134}
1135
1141{
1142 extern bool _draw_widget_outlines;
1143 /* Always allow to toggle them off */
1144 if (_settings_client.gui.newgrf_developer_tools || _draw_widget_outlines) {
1145 _draw_widget_outlines = !_draw_widget_outlines;
1147 }
1148}
1149
1155{
1156 _settings_game.game_creation.starting_year = Clamp(year, CalendarTime::MIN_YEAR, CalendarTime::MAX_YEAR);
1157 TimerGameCalendar::Date new_calendar_date = TimerGameCalendar::ConvertYMDToDate(_settings_game.game_creation.starting_year, 0, 1);
1158 TimerGameEconomy::Date new_economy_date{new_calendar_date.base()};
1159
1160 /* We must set both Calendar and Economy dates to keep them in sync. Calendar first. */
1161 TimerGameCalendar::SetDate(new_calendar_date, 0);
1162
1163 /* If you open a savegame as a scenario, there may already be link graphs and/or vehicles. These use economy date. */
1164 LinkGraphSchedule::instance.ShiftDates(new_economy_date - TimerGameEconomy::date);
1165 for (auto v : Vehicle::Iterate()) v->ShiftDates(new_economy_date - TimerGameEconomy::date);
1166
1167 /* Only change the date after changing cached values above. */
1168 TimerGameEconomy::SetDate(new_economy_date, 0);
1169}
1170
1177{
1178 switch (index) {
1179 case 0: return PlaceLandBlockInfo();
1180 case 1: ShowHelpWindow(); break;
1181 case 2: ToggleScreensaverMode(); break;
1182 case 3: IConsoleSwitch(); break;
1183 case 4: ShowScriptDebugWindow(CompanyID::Invalid(), _ctrl_pressed); break;
1184 case 5: ShowScreenshotWindow(); break;
1185 case 6: ShowFramerateWindow(); break;
1186 case 7: ShowAboutWindow(); break;
1187 case 8: ShowSpriteAlignerWindow(); break;
1188 case 9: ToggleBoundingBoxes(); break;
1189 case 10: ToggleDirtyBlocks(); break;
1190 case 11: ToggleWidgetOutlines(); break;
1191 }
1193}
1194
1195/* --- Switch toolbar button --- */
1196
1197static CallBackFunction ToolbarSwitchClick(Window *w)
1198{
1199 if (_toolbar_mode != ToolbarMode::Lower) {
1200 _toolbar_mode = ToolbarMode::Lower;
1201 } else {
1202 _toolbar_mode = ToolbarMode::Upper;
1203 }
1204
1205 w->ReInit();
1207 SndClickBeep();
1209}
1210
1211/* --- Scenario editor specific handlers. */
1212
1218{
1219 ShowQueryString(GetString(STR_JUST_INT, _settings_game.game_creation.starting_year), STR_MAPGEN_START_DATE_QUERY_CAPT, 8, w, CS_NUMERAL, QueryStringFlag::EnableDefault);
1221}
1222
1223static CallBackFunction ToolbarScenDateBackward(Window *w)
1224{
1225 /* don't allow too fast scrolling */
1226 if (!w->flags.Test(WindowFlag::Timeout) || w->timeout_timer <= 1) {
1228 w->SetDirty();
1229
1230 SetStartingYear(_settings_game.game_creation.starting_year - 1);
1231 }
1232 _left_button_clicked = false;
1234}
1235
1236static CallBackFunction ToolbarScenDateForward(Window *w)
1237{
1238 /* don't allow too fast scrolling */
1239 if (!w->flags.Test(WindowFlag::Timeout) || w->timeout_timer <= 1) {
1241 w->SetDirty();
1242
1243 SetStartingYear(_settings_game.game_creation.starting_year + 1);
1244 }
1245 _left_button_clicked = false;
1247}
1248
1249static CallBackFunction ToolbarScenGenLand(Window *w)
1250{
1252
1255}
1256
1257static CallBackFunction ToolbarScenGenTownClick(Window *w)
1258{
1259 PopupMainToolbarMenu(w, WID_TE_TOWN_GENERATE, {STR_SCENEDIT_TOWN_MENU_BUILD_TOWN, STR_SCENEDIT_TOWN_MENU_PACE_HOUSE});
1261}
1262
1263static CallBackFunction ToolbarScenGenTown(int index)
1264{
1265 switch (index) {
1266 case 0: ShowFoundTownWindow(); break;
1267 case 1: ShowBuildHousePicker(nullptr); break;
1268 }
1270}
1271
1272static CallBackFunction ToolbarScenGenIndustry(Window *w)
1273{
1275 ShowBuildIndustryWindow();
1277}
1278
1279static CallBackFunction ToolbarScenBuildRoadClick(Window *w)
1280{
1283}
1284
1297
1298static CallBackFunction ToolbarScenBuildTramClick(Window *w)
1299{
1302}
1303
1316
1317static CallBackFunction ToolbarScenBuildDocks(Window *w)
1318{
1322}
1323
1324static CallBackFunction ToolbarScenPlantTrees(Window *w)
1325{
1327 ShowBuildTreesToolbar();
1329}
1330
1331static CallBackFunction ToolbarScenPlaceSign(Window *w)
1332{
1334 return SelectSignTool();
1335}
1336
1337static CallBackFunction ToolbarBtn_NULL(Window *)
1338{
1340}
1341
1342typedef CallBackFunction MenuClickedProc(int index);
1343
1344static MenuClickedProc * const _menu_clicked_procs[] = {
1345 nullptr, // 0
1346 nullptr, // 1
1347 MenuClickSettings, // 2
1348 MenuClickSaveLoad, // 3
1349 MenuClickMap, // 4
1350 MenuClickTown, // 5
1351 MenuClickSubsidies, // 6
1352 MenuClickStations, // 7
1353 MenuClickFinances, // 8
1354 MenuClickCompany, // 9
1355 MenuClickStory, // 10
1356 MenuClickGoal, // 11
1359 MenuClickIndustry, // 14
1360 MenuClickShowTrains, // 15
1361 MenuClickShowRoad, // 16
1362 MenuClickShowShips, // 17
1363 MenuClickShowAir, // 18
1364 MenuClickMap, // 19
1365 nullptr, // 20
1366 MenuClickBuildRail, // 21
1367 MenuClickBuildRoad, // 22
1368 MenuClickBuildTram, // 23
1369 MenuClickBuildWater, // 24
1370 MenuClickBuildAir, // 25
1371 MenuClickForest, // 26
1373 MenuClickNewspaper, // 28
1374 MenuClickHelp, // 29
1375};
1376
1378class NWidgetToolbarContainer : public NWidgetContainer {
1379protected:
1380 uint spacers = 0;
1381
1382public:
1383 NWidgetToolbarContainer() : NWidgetContainer(NWID_HORIZONTAL)
1384 {
1385 }
1386
1393 {
1394 return type == WWT_IMGBTN || type == WWT_IMGBTN_2 || type == WWT_PUSHIMGBTN;
1395 }
1396
1397 void SetupSmallestSize(Window *w) override
1398 {
1399 this->smallest_x = 0; // Biggest child
1400 this->smallest_y = 0; // Biggest child
1401 this->fill_x = 1;
1402 this->fill_y = 0;
1403 this->resize_x = 1; // We only resize in this direction
1404 this->resize_y = 0; // We never resize in this direction
1405 this->spacers = 0;
1406
1407 uint nbuttons = 0;
1408 /* First initialise some variables... */
1409 for (const auto &child_wid : this->children) {
1410 child_wid->SetupSmallestSize(w);
1411 this->smallest_y = std::max(this->smallest_y, child_wid->smallest_y + child_wid->padding.Vertical());
1412 if (this->IsButton(child_wid->type)) {
1413 nbuttons++;
1414 this->smallest_x = std::max(this->smallest_x, child_wid->smallest_x + child_wid->padding.Horizontal());
1415 } else if (child_wid->type == NWID_SPACER) {
1416 this->spacers++;
1417 }
1418 }
1419
1420 /* ... then in a second pass make sure the 'current' heights are set. Won't change ever. */
1421 for (const auto &child_wid : this->children) {
1422 child_wid->current_y = this->smallest_y;
1423 if (!this->IsButton(child_wid->type)) {
1424 child_wid->current_x = child_wid->smallest_x;
1425 }
1426 }
1427
1428 /* Exclude the switcher button which is not displayed when the toolbar fits the screen. When the switch is
1429 * displayed there will be no spacers anyway. */
1430 --nbuttons;
1431
1432 /* Allow space for all buttons, and include spacers at quarter the width of buttons. */
1433 _toolbar_width = nbuttons * this->smallest_x + this->spacers * this->smallest_x / 4;
1434 }
1435
1436 void AssignSizePosition(SizingType sizing, int x, int y, uint given_width, uint given_height, bool rtl) override
1437 {
1438 assert(given_width >= this->smallest_x && given_height >= this->smallest_y);
1439
1440 this->pos_x = x;
1441 this->pos_y = y;
1442 this->current_x = given_width;
1443 this->current_y = given_height;
1444
1445 /* Figure out what are the visible buttons */
1446 uint arrangeable_count, button_count, spacer_count;
1447 const WidgetID *arrangement = GetButtonArrangement(given_width, arrangeable_count, button_count, spacer_count);
1448
1449 /* Create us ourselves a quick lookup table from WidgetID to slot. */
1450 std::map<WidgetID, uint> lookup;
1451 for (auto it = std::begin(this->children); it != std::end(this->children); ++it) {
1452 NWidgetBase *nwid = it->get();
1453 nwid->current_x = 0; /* Hide widget, it will be revealed in the next step. */
1454 if (nwid->type == NWID_SPACER) continue;
1455 NWidgetCore *nwc = dynamic_cast<NWidgetCore *>(nwid);
1456 assert(nwc != nullptr);
1457 lookup[nwc->GetIndex()] = std::distance(this->children.begin(), it);
1458 }
1459
1460 /* Now assign the widgets to their rightful place */
1461 uint position = 0; // Place to put next child relative to origin of the container.
1462 uint spacer_space = std::max(0, (int)given_width - (int)(button_count * this->smallest_x)); // Remaining spacing for 'spacer' widgets
1463 uint button_space = given_width - spacer_space; // Remaining spacing for the buttons
1464 uint spacer_i = 0;
1465 uint button_i = 0;
1466
1467 /* Index into the arrangement indices. */
1468 const WidgetID *slotp = rtl ? &arrangement[arrangeable_count - 1] : arrangement;
1469 for (uint i = 0; i < arrangeable_count; i++) {
1470 uint slot = lookup[*slotp];
1471 auto &child_wid = this->children[slot];
1472 /* If we have space to give to the spacers, do that. */
1473 if (spacer_space > 0 && slot > 0 && slot < this->children.size() - 1) {
1474 const auto &possible_spacer = this->children[slot + (rtl ? 1 : -1)];
1475 if (possible_spacer != nullptr && possible_spacer->type == NWID_SPACER) {
1476 uint add = spacer_space / (spacer_count - spacer_i);
1477 position += add;
1478 spacer_space -= add;
1479 spacer_i++;
1480 }
1481 }
1482
1483 /* Buttons can be scaled, the others not. */
1484 if (this->IsButton(child_wid->type)) {
1485 child_wid->current_x = button_space / (button_count - button_i);
1486 button_space -= child_wid->current_x;
1487 button_i++;
1488 } else {
1489 child_wid->current_x = child_wid->smallest_x;
1490 }
1491 child_wid->AssignSizePosition(sizing, x + position, y, child_wid->current_x, this->current_y, rtl);
1492 position += child_wid->current_x;
1493
1494 if (rtl) {
1495 slotp--;
1496 } else {
1497 slotp++;
1498 }
1499 }
1500 }
1501
1502 void Draw(const Window *w) override
1503 {
1504 /* Draw brown-red toolbar bg. */
1505 const Rect r = this->GetCurrentRect();
1508
1509 this->NWidgetContainer::Draw(w);
1510 }
1511
1520 virtual const WidgetID *GetButtonArrangement(uint &width, uint &arrangeable_count, uint &button_count, uint &spacer_count) const = 0;
1521};
1522
1524class NWidgetMainToolbarContainer : public NWidgetToolbarContainer {
1525 const WidgetID *GetButtonArrangement(uint &width, uint &arrangeable_count, uint &button_count, uint &spacer_count) const override
1526 {
1527 static const uint SMALLEST_ARRANGEMENT = 14;
1528 static const uint BIGGEST_ARRANGEMENT = 20;
1529
1530 /* The number of buttons of each row of the toolbar should match the number of items which we want to be visible.
1531 * The total number of buttons should be equal to arrangeable_count * 2.
1532 * No bad things happen, but we could see strange behaviours if we have buttons < (arrangeable_count * 2) like a
1533 * pause button appearing on the right of the lower toolbar and weird resizing of the widgets even if there is
1534 * enough space.
1535 */
1536 static const WidgetID arrange14[] = {
1548 WID_TN_AIR,
1551 /* lower toolbar */
1566 };
1567 static const WidgetID arrange15[] = {
1578 WID_TN_AIR,
1583 /* lower toolbar */
1599 };
1600 static const WidgetID arrange16[] = {
1612 WID_TN_AIR,
1617 /* lower toolbar */
1634 };
1635 static const WidgetID arrange17[] = {
1648 WID_TN_AIR,
1653 /* lower toolbar */
1671 };
1672 static const WidgetID arrange18[] = {
1686 WID_TN_AIR,
1691 /* lower toolbar */
1710 };
1711 static const WidgetID arrange19[] = {
1725 WID_TN_AIR,
1731 /* lower toolbar */
1745 WID_TN_AIR,
1751 };
1752 static const WidgetID arrange20[] = {
1766 WID_TN_AIR,
1773 /* lower toolbar */
1787 WID_TN_AIR,
1794 };
1795 static const WidgetID arrange_all[] = {
1821 WID_TN_AIR,
1826 };
1827
1828 /* If at least BIGGEST_ARRANGEMENT fit, just spread all the buttons nicely */
1829 uint full_buttons = std::max(CeilDiv(width, this->smallest_x), SMALLEST_ARRANGEMENT);
1830 if (full_buttons > BIGGEST_ARRANGEMENT) {
1831 _toolbar_mode = ToolbarMode::Normal;
1832 button_count = arrangeable_count = lengthof(arrange_all);
1833 spacer_count = this->spacers;
1834 return arrange_all;
1835 }
1836
1837 /* Introduce the split toolbar */
1838 static const WidgetID * const arrangements[] = { arrange14, arrange15, arrange16, arrange17, arrange18, arrange19, arrange20 };
1839
1840 button_count = arrangeable_count = full_buttons;
1841 spacer_count = this->spacers;
1842 return arrangements[full_buttons - SMALLEST_ARRANGEMENT] + ((_toolbar_mode == ToolbarMode::Lower) ? full_buttons : 0);
1843 }
1844};
1845
1847class NWidgetScenarioToolbarContainer : public NWidgetToolbarContainer {
1848 std::array<uint, 2> panel_widths{};
1849
1850 void SetupSmallestSize(Window *w) override
1851 {
1853
1854 /* Find the size of panel_widths */
1855 auto it = this->panel_widths.begin();
1856 for (const auto &child_wid : this->children) {
1857 if (child_wid->type == NWID_SPACER || this->IsButton(child_wid->type)) continue;
1858
1859 assert(it != this->panel_widths.end());
1860 *it = child_wid->current_x;
1861 _toolbar_width += child_wid->current_x;
1862 ++it;
1863 }
1864 }
1865
1866 const WidgetID *GetButtonArrangement(uint &width, uint &arrangeable_count, uint &button_count, uint &spacer_count) const override
1867 {
1868 static const WidgetID arrange_all[] = {
1888 };
1889 static const WidgetID arrange_nopanel[] = {
1908 };
1909 static const WidgetID arrange_switch[] = {
1921 /* lower toolbar */
1933 };
1934
1935 /* If we can place all buttons *and* the panels, show them. */
1936 size_t min_full_width = (lengthof(arrange_all) - std::size(this->panel_widths)) * this->smallest_x + this->panel_widths[0] + this->panel_widths[1];
1937 if (width >= min_full_width) {
1938 width -= this->panel_widths[0] + this->panel_widths[1];
1939 arrangeable_count = lengthof(arrange_all);
1940 button_count = arrangeable_count - 2;
1941 spacer_count = this->spacers;
1942 return arrange_all;
1943 }
1944
1945 /* 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 */
1946 size_t min_small_width = (lengthof(arrange_switch) - std::size(this->panel_widths)) * this->smallest_x / 2 + this->panel_widths[1];
1947 if (width > min_small_width) {
1948 width -= this->panel_widths[1];
1949 arrangeable_count = lengthof(arrange_nopanel);
1950 button_count = arrangeable_count - 1;
1951 spacer_count = this->spacers - 1;
1952 return arrange_nopanel;
1953 }
1954
1955 /* Split toolbar */
1956 width -= this->panel_widths[1];
1957 arrangeable_count = lengthof(arrange_switch) / 2;
1958 button_count = arrangeable_count - 1;
1959 spacer_count = 0;
1960 return arrange_switch + ((_toolbar_mode == ToolbarMode::Lower) ? arrangeable_count : 0);
1961 }
1962};
1963
1964/* --- Toolbar handling for the 'normal' case */
1965
1972
1973static ToolbarButtonProc * const _toolbar_button_procs[] = {
1974 ToolbarPauseClick,
1978 ToolbarMapClick,
1979 ToolbarTownClick,
1980 ToolbarSubsidiesClick,
1981 ToolbarStationsClick,
1982 ToolbarFinancesClick,
1983 ToolbarCompaniesClick,
1984 ToolbarStoryClick,
1985 ToolbarGoalClick,
1986 ToolbarGraphsClick,
1987 ToolbarLeagueClick,
1988 ToolbarIndustryClick,
1989 ToolbarTrainClick,
1990 ToolbarRoadClick,
1991 ToolbarShipClick,
1992 ToolbarAirClick,
1993 ToolbarZoomInClick,
1994 ToolbarZoomOutClick,
1995 ToolbarBuildRailClick,
1996 ToolbarBuildRoadClick,
1997 ToolbarBuildTramClick,
1998 ToolbarBuildWaterClick,
1999 ToolbarBuildAirClick,
2000 ToolbarForestClick,
2001 ToolbarMusicClick,
2002 ToolbarNewspaperClick,
2003 ToolbarHelpClick,
2004 ToolbarSwitchClick,
2005};
2006
2008struct MainToolbarWindow : Window {
2009 MainToolbarWindow(WindowDesc &desc) : Window(desc)
2010 {
2011 this->InitNested(0);
2012
2014 this->flags.Reset(WindowFlag::WhiteBorder);
2015 this->SetWidgetDisabledState(WID_TN_PAUSE, _networking && !_network_server); // if not server, disable pause button
2016 this->SetWidgetDisabledState(WID_TN_FAST_FORWARD, _networking); // if networking, disable fast-forward button
2017 PositionMainToolbar(this);
2019 }
2020
2021 void FindWindowPlacementAndResize(int, int def_height, bool allow_resize) override
2022 {
2023 Window::FindWindowPlacementAndResize(_toolbar_width, def_height, allow_resize);
2024 }
2025
2026 void OnPaint() override
2027 {
2028 /* If spectator, disable all construction buttons
2029 * ie : Build road, rail, ships, airports and landscaping
2030 * Since enabled state is the default, just disable when needed */
2032 /* disable company list drop downs, if there are no companies */
2034
2037
2038 this->DrawWidgets();
2039 }
2040
2041 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
2042 {
2043 if (_game_mode != GameMode::Menu && !this->IsWidgetDisabled(widget)) _toolbar_button_procs[widget](this);
2044 }
2045
2046 void OnDropdownSelect(WidgetID widget, int index, int) override
2047 {
2048 CallBackFunction cbf = _menu_clicked_procs[widget](index);
2050 }
2051
2052 EventState OnHotkey(int hotkey) override
2053 {
2055 switch (hotkey) {
2056 case MTHK_PAUSE: ToolbarPauseClick(this); break;
2057 case MTHK_FASTFORWARD: ToolbarFastForwardClick(this); break;
2058 case MTHK_SETTINGS: ShowGameOptions(); break;
2059 case MTHK_SAVEGAME: MenuClickSaveLoad(); break;
2061 case MTHK_SMALLMAP: ShowSmallMap(); break;
2062 case MTHK_TOWNDIRECTORY: ShowTownDirectory(); break;
2063 case MTHK_SUBSIDIES: ShowSubsidiesList(); break;
2064 case MTHK_STATIONS: ShowCompanyStations(_local_company); break;
2065 case MTHK_FINANCES: ShowCompanyFinances(_local_company); break;
2066 case MTHK_COMPANIES: ShowCompany(_local_company); break;
2067 case MTHK_STORY: ShowStoryBook(_local_company); break;
2068 case MTHK_GOAL: ShowGoalsList(_local_company); break;
2069 case MTHK_GRAPHS: ShowOperatingProfitGraph(); break;
2070 case MTHK_LEAGUE: ShowFirstLeagueTable(); break;
2071 case MTHK_INDUSTRIES: ShowBuildIndustryWindow(); break;
2072 case MTHK_TRAIN_LIST: ShowVehicleListWindow(_local_company, VehicleType::Train); break;
2073 case MTHK_ROADVEH_LIST: ShowVehicleListWindow(_local_company, VehicleType::Road); break;
2074 case MTHK_SHIP_LIST: ShowVehicleListWindow(_local_company, VehicleType::Ship); break;
2075 case MTHK_AIRCRAFT_LIST: ShowVehicleListWindow(_local_company, VehicleType::Aircraft); break;
2076 case MTHK_ZOOM_IN: ToolbarZoomInClick(this); break;
2077 case MTHK_ZOOM_OUT: ToolbarZoomOutClick(this); break;
2078 case MTHK_BUILD_RAIL: ShowBuildRailToolbar(_last_built_railtype); break;
2079 case MTHK_BUILD_ROAD: ShowBuildRoadToolbar(_last_built_roadtype); break;
2080 case MTHK_BUILD_TRAM: ShowBuildRoadToolbar(_last_built_tramtype); break;
2081 case MTHK_BUILD_DOCKS: ShowBuildDocksToolbar(); break;
2082 case MTHK_BUILD_AIRPORT: ShowBuildAirToolbar(); break;
2083 case MTHK_BUILD_TREES: ShowBuildTreesToolbar(); break;
2084 case MTHK_MUSIC: ShowMusicWindow(); break;
2085 case MTHK_SCRIPT_DEBUG: ShowScriptDebugWindow(); break;
2086 case MTHK_SMALL_SCREENSHOT: MakeScreenshotWithConfirm(SC_VIEWPORT); break;
2087 case MTHK_ZOOMEDIN_SCREENSHOT: MakeScreenshotWithConfirm(SC_ZOOMEDIN); break;
2088 case MTHK_DEFAULTZOOM_SCREENSHOT: MakeScreenshotWithConfirm(SC_DEFAULTZOOM); break;
2089 case MTHK_GIANT_SCREENSHOT: MakeScreenshotWithConfirm(SC_WORLD); break;
2090 case MTHK_CHEATS: if (!_networking) ShowCheatWindow(); break;
2091 case MTHK_TERRAFORM: ShowTerraformToolbar(); break;
2092 case MTHK_EXTRA_VIEWPORT: ShowExtraViewportWindowForTileUnderCursor(); break;
2093 case MTHK_CLIENT_LIST: if (_networking) ShowClientList(); break;
2094 case MTHK_SIGN_LIST: ShowSignList(); break;
2095 case MTHK_LANDINFO: cbf = PlaceLandBlockInfo(); break;
2096 default: return EventState::NotHandled;
2097 }
2099 return EventState::Handled;
2100 }
2101
2102 void OnPlaceObject([[maybe_unused]] Point pt, TileIndex tile) override
2103 {
2104 switch (_last_started_action) {
2106 PlaceProc_Sign(tile);
2107 break;
2108
2110 ShowLandInfo(tile);
2111 break;
2112
2113 default: NOT_REACHED();
2114 }
2115 }
2116
2121
2123 const IntervalTimer<TimerWindow> refresh_interval = {std::chrono::milliseconds(30), [this](auto) {
2124 if (this->IsWidgetLowered(WID_TN_PAUSE) != _pause_mode.Any()) {
2127 }
2128
2129 if (this->IsWidgetLowered(WID_TN_FAST_FORWARD) != (_game_speed != 100)) {
2132 }
2133 }};
2134
2140 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
2141 {
2142 if (!gui_scope) return;
2144 }
2145
2146 static inline HotkeyList hotkeys{"maintoolbar", {
2147 Hotkey({WKC_F1, WKC_PAUSE}, "pause", MTHK_PAUSE),
2148 Hotkey(0, "fastforward", MTHK_FASTFORWARD),
2149 Hotkey(WKC_F2, "settings", MTHK_SETTINGS),
2150 Hotkey(WKC_F3, "saveload", MTHK_SAVEGAME),
2151 Hotkey(0, "load_game", MTHK_LOADGAME),
2152 Hotkey({WKC_F4, 'M'}, "smallmap", MTHK_SMALLMAP),
2153 Hotkey(WKC_F5, "town_list", MTHK_TOWNDIRECTORY),
2154 Hotkey(WKC_F6, "subsidies", MTHK_SUBSIDIES),
2155 Hotkey(WKC_F7, "station_list", MTHK_STATIONS),
2156 Hotkey(WKC_F8, "finances", MTHK_FINANCES),
2157 Hotkey(WKC_F9, "companies", MTHK_COMPANIES),
2158 Hotkey(0, "story_book", MTHK_STORY),
2159 Hotkey(0, "goal_list", MTHK_GOAL),
2160 Hotkey(WKC_F10, "graphs", MTHK_GRAPHS),
2161 Hotkey(WKC_F11, "league", MTHK_LEAGUE),
2162 Hotkey(WKC_F12, "industry_list", MTHK_INDUSTRIES),
2163 Hotkey(WKC_SHIFT | WKC_F1, "train_list", MTHK_TRAIN_LIST),
2164 Hotkey(WKC_SHIFT | WKC_F2, "roadveh_list", MTHK_ROADVEH_LIST),
2165 Hotkey(WKC_SHIFT | WKC_F3, "ship_list", MTHK_SHIP_LIST),
2166 Hotkey(WKC_SHIFT | WKC_F4, "aircraft_list", MTHK_AIRCRAFT_LIST),
2167 Hotkey({WKC_NUM_PLUS, WKC_EQUALS, WKC_SHIFT | WKC_EQUALS, WKC_SHIFT | WKC_F5}, "zoomin", MTHK_ZOOM_IN),
2168 Hotkey({WKC_NUM_MINUS, WKC_MINUS, WKC_SHIFT | WKC_MINUS, WKC_SHIFT | WKC_F6}, "zoomout", MTHK_ZOOM_OUT),
2169 Hotkey(WKC_SHIFT | WKC_F7, "build_rail", MTHK_BUILD_RAIL),
2170 Hotkey(WKC_SHIFT | WKC_F8, "build_road", MTHK_BUILD_ROAD),
2171 Hotkey(0, "build_tram", MTHK_BUILD_TRAM),
2172 Hotkey(WKC_SHIFT | WKC_F9, "build_docks", MTHK_BUILD_DOCKS),
2173 Hotkey(WKC_SHIFT | WKC_F10, "build_airport", MTHK_BUILD_AIRPORT),
2174 Hotkey(WKC_SHIFT | WKC_F11, "build_trees", MTHK_BUILD_TREES),
2175 Hotkey(WKC_SHIFT | WKC_F12, "music", MTHK_MUSIC),
2176 Hotkey(0, "ai_debug", MTHK_SCRIPT_DEBUG),
2177 Hotkey(WKC_CTRL | 'S', "small_screenshot", MTHK_SMALL_SCREENSHOT),
2178 Hotkey(WKC_CTRL | 'P', "zoomedin_screenshot", MTHK_ZOOMEDIN_SCREENSHOT),
2179 Hotkey(WKC_CTRL | 'D', "defaultzoom_screenshot", MTHK_DEFAULTZOOM_SCREENSHOT),
2180 Hotkey(0, "giant_screenshot", MTHK_GIANT_SCREENSHOT),
2181 Hotkey(WKC_CTRL | WKC_ALT | 'C', "cheats", MTHK_CHEATS),
2182 Hotkey('L', "terraform", MTHK_TERRAFORM),
2183 Hotkey('V', "extra_viewport", MTHK_EXTRA_VIEWPORT),
2184 Hotkey(0, "client_list", MTHK_CLIENT_LIST),
2185 Hotkey(0, "sign_list", MTHK_SIGN_LIST),
2186 Hotkey(0, "land_info", MTHK_LANDINFO),
2187 }};
2188};
2189
2191static constexpr std::tuple<WidgetID, WidgetType, SpriteID> _toolbar_button_sprites[] = {
2222 {WID_TN_SWITCH_BAR, WWT_IMGBTN, SPR_IMG_SWITCH_TOOLBAR},
2223};
2224
2230{
2231 Dimension d{};
2232 for (const auto &[widget, tp, sprite] : _toolbar_button_sprites) {
2233 if (!SpriteExists(sprite)) continue;
2234 d = maxdim(d, GetSquareScaledSpriteSize(sprite));
2235 }
2236 return d;
2237}
2238
2243static std::unique_ptr<NWidgetBase> MakeMainToolbar()
2244{
2245 auto hor = std::make_unique<NWidgetMainToolbarContainer>();
2246 for (const auto &[widget, tp, sprite] : _toolbar_button_sprites) {
2247 switch (widget) {
2248 case WID_TN_SMALL_MAP:
2249 case WID_TN_FINANCES:
2251 case WID_TN_ZOOM_IN:
2253 case WID_TN_MUSIC_SOUND:
2254 hor->Add(std::make_unique<NWidgetSpacer>(0, 0));
2255 break;
2256 }
2257 auto leaf = std::make_unique<NWidgetLeaf>(tp, Colours::Grey, widget, WidgetData{.sprite = sprite}, STR_TOOLBAR_TOOLTIP_PAUSE_GAME + widget);
2258 leaf->SetToolbarMinimalSize(1);
2259 hor->Add(std::move(leaf));
2260 }
2261
2262 return hor;
2263}
2264
2265static constexpr std::initializer_list<NWidgetPart> _nested_toolbar_normal_widgets = {
2267};
2268
2271 WindowPosition::Manual, {}, 0, 0,
2272 WindowClass::MainToolbar, WindowClass::None,
2274 _nested_toolbar_normal_widgets,
2275 &MainToolbarWindow::hotkeys
2276);
2277
2278
2279/* --- Toolbar handling for the scenario editor */
2280
2281static MenuClickedProc * const _scen_toolbar_dropdown_procs[] = {
2282 nullptr, // 0
2283 nullptr, // 1
2284 MenuClickSettings, // 2
2285 MenuClickSaveLoad, // 3
2286 nullptr, // 4
2287 nullptr, // 5
2288 nullptr, // 6
2289 nullptr, // 7
2290 MenuClickMap, // 8
2291 nullptr, // 9
2292 nullptr, // 10
2293 nullptr, // 11
2294 ToolbarScenGenTown, // 12
2295 nullptr, // 13
2298 nullptr, // 16
2299 nullptr, // 17
2300 nullptr, // 18
2301 nullptr, // 19
2303 MenuClickHelp, // 21
2304 nullptr, // 22
2305};
2306
2307static ToolbarButtonProc * const _scen_toolbar_button_procs[] = {
2308 ToolbarPauseClick,
2312 ToolbarBtn_NULL,
2314 ToolbarScenDateBackward,
2315 ToolbarScenDateForward,
2316 ToolbarScenMapTownDir,
2317 ToolbarZoomInClick,
2318 ToolbarZoomOutClick,
2319 ToolbarScenGenLand,
2320 ToolbarScenGenTownClick,
2321 ToolbarScenGenIndustry,
2322 ToolbarScenBuildRoadClick,
2323 ToolbarScenBuildTramClick,
2324 ToolbarScenBuildDocks,
2325 ToolbarScenPlantTrees,
2326 ToolbarScenPlaceSign,
2327 ToolbarBtn_NULL,
2328 ToolbarMusicClick,
2329 ToolbarHelpClick,
2330 ToolbarSwitchClick,
2331};
2332
2363
2364struct ScenarioEditorToolbarWindow : Window {
2365 ScenarioEditorToolbarWindow(WindowDesc &desc) : Window(desc)
2366 {
2367 this->InitNested(0);
2368
2370 this->flags.Reset(WindowFlag::WhiteBorder);
2371 PositionMainToolbar(this);
2373 }
2374
2375 void FindWindowPlacementAndResize(int, int def_height, bool allow_resize) override
2376 {
2377 Window::FindWindowPlacementAndResize(_toolbar_width, def_height, allow_resize);
2378 }
2379
2389
2390 std::string GetWidgetString(WidgetID widget, StringID stringid) const override
2391 {
2392 switch (widget) {
2393 case WID_TE_DATE:
2394 return GetString(STR_JUST_DATE_LONG, TimerGameCalendar::ConvertYMDToDate(_settings_game.game_creation.starting_year, 0, 1));
2395
2396 default:
2397 return this->Window::GetWidgetString(widget, stringid);
2398 }
2399 }
2400
2401 void DrawWidget(const Rect &r, WidgetID widget) const override
2402 {
2403 switch (widget) {
2404 case WID_TE_SPACER: {
2405 int height = r.Height();
2407 DrawString(r.left, r.right, height / 2 - GetCharacterHeight(FontSize::Normal), STR_SCENEDIT_TOOLBAR_OPENTTD, TextColour::FromString, AlignmentH::Centre);
2408 DrawString(r.left, r.right, height / 2, STR_SCENEDIT_TOOLBAR_SCENARIO_EDITOR, TextColour::FromString, AlignmentH::Centre);
2409 } else {
2410 DrawString(r.left, r.right, (height - GetCharacterHeight(FontSize::Normal)) / 2, STR_SCENEDIT_TOOLBAR_SCENARIO_EDITOR, TextColour::FromString, AlignmentH::Centre);
2411 }
2412 break;
2413 }
2414 }
2415 }
2416
2417 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
2418 {
2419 switch (widget) {
2420 case WID_TE_SPACER:
2421 size.width = std::max(GetStringBoundingBox(STR_SCENEDIT_TOOLBAR_OPENTTD).width, GetStringBoundingBox(STR_SCENEDIT_TOOLBAR_SCENARIO_EDITOR).width) + padding.width;
2422 break;
2423
2424 case WID_TE_DATE:
2426 break;
2427 }
2428 }
2429
2430 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
2431 {
2432 if (_game_mode == GameMode::Menu) return;
2433 CallBackFunction cbf = _scen_toolbar_button_procs[widget](this);
2435 }
2436
2437 void OnDropdownSelect(WidgetID widget, int index, int) override
2438 {
2439 CallBackFunction cbf = _scen_toolbar_dropdown_procs[widget](index);
2441 SndClickBeep();
2442 }
2443
2444 EventState OnHotkey(int hotkey) override
2445 {
2446 if (IsSpecialHotkey(hotkey)) {
2448 switch (MainToolbarEditorHotkeys(hotkey)) {
2451 case MainToolbarEditorHotkeys::Music: ShowMusicWindow(); break;
2452 case MainToolbarEditorHotkeys::LandInfo: cbf = PlaceLandBlockInfo(); break;
2460 case MainToolbarEditorHotkeys::GenerateTown: ShowFoundTownWindow(); break;
2463 default: return EventState::NotHandled;
2464 }
2466 } else {
2467 this->OnClick({}, hotkey, 0);
2468 }
2469 return EventState::Handled;
2470 }
2471
2472 void OnPlaceObject([[maybe_unused]] Point pt, TileIndex tile) override
2473 {
2474 switch (_last_started_action) {
2476 PlaceProc_Sign(tile);
2477 break;
2478
2480 ShowLandInfo(tile);
2481 break;
2482
2483 default: NOT_REACHED();
2484 }
2485 }
2486
2491
2498
2500 const IntervalTimer<TimerWindow> refresh_interval = {std::chrono::milliseconds(30), [this](auto) {
2501 if (this->IsWidgetLowered(WID_TE_PAUSE) != _pause_mode.Any()) {
2503 this->SetDirty();
2504 }
2505
2506 if (this->IsWidgetLowered(WID_TE_FAST_FORWARD) != (_game_speed != 100)) {
2508 this->SetDirty();
2509 }
2510 }};
2511
2517 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
2518 {
2519 if (!gui_scope) return;
2521 }
2522
2523 void OnQueryTextFinished(std::optional<std::string> str) override
2524 {
2525 /* Was 'cancel' pressed? */
2526 if (!str.has_value()) return;
2527
2529 if (!str->empty()) {
2530 auto val = ParseInteger(*str, 10, true);
2531 if (!val.has_value()) return;
2532 value = static_cast<TimerGameCalendar::Year>(*val);
2533 } else {
2534 /* An empty string means revert to the default */
2536 }
2537 SetStartingYear(value);
2538
2539 this->SetDirty();
2540 }
2541
2542 static inline HotkeyList hotkeys{"scenedit_maintoolbar", {
2543 Hotkey({WKC_F1, WKC_PAUSE}, "pause", MainToolbarEditorHotkeys::Pause),
2544 Hotkey(0, "fastforward", MainToolbarEditorHotkeys::FastForward),
2545 Hotkey(WKC_F2, "settings", MainToolbarEditorHotkeys::Settings),
2546 Hotkey(WKC_F3, "saveload", MainToolbarEditorHotkeys::SaveGame),
2547 Hotkey(WKC_F4, "gen_land", MainToolbarEditorHotkeys::GenerateLand),
2548 Hotkey(WKC_F5, "gen_town", MainToolbarEditorHotkeys::GenerateTown),
2549 Hotkey(WKC_F6, "gen_industry", MainToolbarEditorHotkeys::GenerateIndustry),
2550 Hotkey(WKC_F7, "build_road", MainToolbarEditorHotkeys::BuildRoad),
2551 Hotkey(0, "build_tram", MainToolbarEditorHotkeys::BuildTram),
2552 Hotkey(WKC_F8, "build_docks", MainToolbarEditorHotkeys::BuildWater),
2553 Hotkey(WKC_F9, "build_trees", MainToolbarEditorHotkeys::BuildTrees),
2554 Hotkey(WKC_F10, "build_sign", MainToolbarEditorHotkeys::Sign),
2555 Hotkey(WKC_F11, "music", MainToolbarEditorHotkeys::Music),
2556 Hotkey(WKC_F12, "land_info", MainToolbarEditorHotkeys::LandInfo),
2557 Hotkey(WKC_CTRL | 'S', "small_screenshot", MainToolbarEditorHotkeys::SmallScreenshot),
2558 Hotkey(WKC_CTRL | 'P', "zoomedin_screenshot", MainToolbarEditorHotkeys::ZoomedInScreenshot),
2559 Hotkey(WKC_CTRL | 'D', "defaultzoom_screenshot", MainToolbarEditorHotkeys::DefaultZoomScreenshot),
2560 Hotkey(0, "giant_screenshot", MainToolbarEditorHotkeys::GiantScreenshot),
2561 Hotkey({WKC_NUM_PLUS, WKC_EQUALS, WKC_SHIFT | WKC_EQUALS, WKC_SHIFT | WKC_F5}, "zoomin", MainToolbarEditorHotkeys::ZoomIn),
2562 Hotkey({WKC_NUM_MINUS, WKC_MINUS, WKC_SHIFT | WKC_MINUS, WKC_SHIFT | WKC_F6}, "zoomout", MainToolbarEditorHotkeys::ZoomOut),
2563 Hotkey('L', "terraform", MainToolbarEditorHotkeys::Terraform),
2564 Hotkey('M', "smallmap", MainToolbarEditorHotkeys::SmallMap),
2565 Hotkey('V', "extra_viewport", MainToolbarEditorHotkeys::ExtraViewport),
2566 }};
2567};
2568
2569static constexpr std::initializer_list<NWidgetPart> _nested_toolb_scen_inner_widgets = {
2570 NWidget(WWT_IMGBTN, Colours::Grey, WID_TE_PAUSE), SetSpriteTip(SPR_IMG_PAUSE, STR_TOOLBAR_TOOLTIP_PAUSE_GAME),
2573 NWidget(WWT_IMGBTN_2, Colours::Grey, WID_TE_SAVE), SetSpriteTip(SPR_IMG_SAVE, STR_SCENEDIT_TOOLBAR_SAVE_SCENARIO_LOAD_SCENARIO_TOOLTIP),
2579 NWidget(WWT_IMGBTN, Colours::Grey, WID_TE_DATE_BACKWARD), SetSpriteTip(SPR_ARROW_DOWN, STR_SCENEDIT_TOOLBAR_MOVE_THE_STARTING_DATE_BACKWARD_TOOLTIP), SetFill(0, 1),
2581 NWidget(WWT_IMGBTN, Colours::Grey, WID_TE_DATE_FORWARD), SetSpriteTip(SPR_ARROW_UP, STR_SCENEDIT_TOOLBAR_MOVE_THE_STARTING_DATE_FORWARD_TOOLTIP), SetFill(0, 1),
2582 EndContainer(),
2583 EndContainer(),
2585 NWidget(WWT_IMGBTN, Colours::Grey, WID_TE_SMALL_MAP), SetSpriteTip(SPR_IMG_SMALLMAP, STR_SCENEDIT_TOOLBAR_DISPLAY_MAP_TOWN_DIRECTORY_TOOLTIP),
2587 NWidget(WWT_PUSHIMGBTN, Colours::Grey, WID_TE_ZOOM_IN), SetSpriteTip(SPR_IMG_ZOOMIN, STR_TOOLBAR_TOOLTIP_ZOOM_THE_VIEW_IN),
2588 NWidget(WWT_PUSHIMGBTN, Colours::Grey, WID_TE_ZOOM_OUT), SetSpriteTip(SPR_IMG_ZOOMOUT, STR_TOOLBAR_TOOLTIP_ZOOM_THE_VIEW_OUT),
2590 NWidget(WWT_PUSHIMGBTN, Colours::Grey, WID_TE_LAND_GENERATE), SetSpriteTip(SPR_IMG_LANDSCAPING, STR_SCENEDIT_TOOLBAR_LANDSCAPE_GENERATION_TOOLTIP),
2591 NWidget(WWT_IMGBTN, Colours::Grey, WID_TE_TOWN_GENERATE), SetSpriteTip(SPR_IMG_TOWN, STR_SCENEDIT_TOOLBAR_TOWN_GENERATION_TOOLTIP),
2592 NWidget(WWT_PUSHIMGBTN, Colours::Grey, WID_TE_INDUSTRY), SetSpriteTip(SPR_IMG_INDUSTRY, STR_SCENEDIT_TOOLBAR_INDUSTRY_GENERATION_TOOLTIP),
2593 NWidget(WWT_IMGBTN, Colours::Grey, WID_TE_ROADS), SetSpriteTip(SPR_IMG_BUILDROAD, STR_SCENEDIT_TOOLBAR_ROAD_CONSTRUCTION_TOOLTIP),
2594 NWidget(WWT_IMGBTN, Colours::Grey, WID_TE_TRAMS), SetSpriteTip(SPR_IMG_BUILDTRAMS, STR_SCENEDIT_TOOLBAR_TRAM_CONSTRUCTION_TOOLTIP),
2595 NWidget(WWT_PUSHIMGBTN, Colours::Grey, WID_TE_WATER), SetSpriteTip(SPR_IMG_BUILDWATER, STR_TOOLBAR_TOOLTIP_BUILD_SHIP_DOCKS),
2596 NWidget(WWT_PUSHIMGBTN, Colours::Grey, WID_TE_TREES), SetSpriteTip(SPR_IMG_PLANTTREES, STR_SCENEDIT_TOOLBAR_PLANT_TREES_TOOLTIP),
2597 NWidget(WWT_PUSHIMGBTN, Colours::Grey, WID_TE_SIGNS), SetSpriteTip(SPR_IMG_SIGN, STR_SCENEDIT_TOOLBAR_PLACE_SIGN_TOOLTIP),
2599 NWidget(WWT_IMGBTN, Colours::Grey, WID_TE_MUSIC_SOUND), SetSpriteTip(SPR_IMG_MUSIC, STR_TOOLBAR_TOOLTIP_SHOW_SOUND_MUSIC_WINDOW),
2600 NWidget(WWT_IMGBTN, Colours::Grey, WID_TE_HELP), SetSpriteTip(SPR_IMG_QUERY, STR_TOOLBAR_TOOLTIP_LAND_BLOCK_INFORMATION),
2601 NWidget(WWT_IMGBTN, Colours::Grey, WID_TE_SWITCH_BAR), SetSpriteTip(SPR_IMG_SWITCH_TOOLBAR, STR_TOOLBAR_TOOLTIP_SWITCH_TOOLBAR),
2602};
2603
2604static std::unique_ptr<NWidgetBase> MakeScenarioToolbar()
2605{
2606 return MakeNWidgets(_nested_toolb_scen_inner_widgets, std::make_unique<NWidgetScenarioToolbarContainer>());
2607}
2608
2609static constexpr std::initializer_list<NWidgetPart> _nested_toolb_scen_widgets = {
2610 NWidgetFunction(MakeScenarioToolbar),
2611};
2612
2615 WindowPosition::Manual, {}, 0, 0,
2616 WindowClass::MainToolbar, WindowClass::None,
2618 _nested_toolb_scen_widgets,
2619 &ScenarioEditorToolbarWindow::hotkeys
2620);
2621
2624{
2625 if (_game_mode == GameMode::Editor) {
2627 } else {
2629 }
2630}
void ShowAIConfigWindow()
Open the AI config window.
Definition ai_gui.cpp:338
Window for configuring the AIs.
Window * ShowBuildAirToolbar()
Open the build airport toolbar window.
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 Timpl & Set()
Set all bits.
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.
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).
void Draw(const Window *w) override
Draw the widgets of the tree.
Definition widget.cpp:1343
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.
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
static constexpr TimerGame< struct Calendar >::Year MIN_YEAR
static constexpr TimerGame< struct Calendar >::Year MAX_YEAR
static Date date
Current date in days (day counter).
static void SetDate(Date date, DateFract fract)
Set the date.
StrongType::Typedef< int32_t, struct YearTag< struct Calendar >, StrongType::Compare, StrongType::Integer > Year
StrongType::Typedef< int32_t, DateTag< struct Calendar >, StrongType::Compare, StrongType::Integer > 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:416
Window * ShowBuildDocksToolbar()
Open the build water toolbar window.
Definition dock_gui.cpp:375
std::unique_ptr< DropDownListItem > MakeDropDownListDividerItem()
Creates new DropDownListDividerItem.
Definition dropdown.cpp:36
std::unique_ptr< DropDownListItem > MakeDropDownListIconItem(SpriteID sprite, PaletteID palette, StringID str, int value, bool masked, bool shaded)
Creates new DropDownListIconItem.
Definition dropdown.cpp:70
std::unique_ptr< DropDownListItem > MakeDropDownListStringItem(StringID str, int value, bool masked, bool shaded)
Creates new DropDownListStringItem.
Definition dropdown.cpp:49
std::unique_ptr< DropDownListItem > MakeDropDownListCheckedItem(bool checked, StringID str, int value, bool masked, bool shaded, uint indent)
Creates new DropDownListCheckedItem.
Definition dropdown.cpp:94
void ShowDropDownList(Window *w, DropDownList &&list, int selected, WidgetID button, uint width, DropDownOptions options, std::string *const persistent_filter_text)
Show a drop down list.
Definition dropdown.cpp:587
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.
@ InstantClose
Set if releasing mouse button should close the list regardless of where the cursor is.
@ Filterable
Set if the dropdown is filterable.
EnumBitSet< DropDownOption, uint8_t > DropDownOptions
Bitset of DropDownOption elements.
Base class for engines.
@ Save
File is being saved.
Definition fileio_type.h:55
@ Load
File is being loaded.
Definition fileio_type.h:54
@ Savegame
old or new savegame
Definition fileio_type.h:19
@ Scenario
old or new scenario
Definition fileio_type.h:20
@ Heightmap
heightmap file
Definition fileio_type.h:21
Declarations for savegames operations.
void ShowSaveLoadDialog(AbstractFileType abstract_filetype, SaveLoadOperation fop)
Launch save/load dialog in the given mode.
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Definition fontcache.cpp:88
Types for recording game performance data.
Base functions for all Games.
void ShowGSConfigWindow()
Open the GS config window.
Definition game_gui.cpp:427
Window for configuring GS.
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
Geometry functions.
@ Centre
Align to the centre.
@ Middle
Align to the middle.
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition gfx.cpp:899
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
int DrawString(int left, int right, int top, std::string_view str, ExtendedTextColour colour, Alignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Definition gfx.cpp:668
Dimension GetSquareScaledSpriteSize(SpriteID sprid)
Scale sprite size for GUI, as a square.
Definition widget.cpp:85
void CheckBlitter()
Check whether we still use the right blitter, or use another (better) one.
Definition gfxinit.cpp:324
@ Normal
Index of the normal font in the font tables.
Definition gfx_type.h:249
@ Invalid
Invalid marker.
Definition gfx_type.h:302
@ Grey
Grey.
Definition gfx_type.h:299
@ White
White colour.
Definition gfx_type.h:330
@ FromString
Marker for telling to use the colour from the string.
Definition gfx_type.h:317
@ Checker
Draw only every second pixel, used for greying-out.
Definition gfx_type.h:393
@ 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:312
Goal GUI functions.
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.
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:3431
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 SetTextStyle(TextColour colour, FontSize size=FontSize::Normal)
Widget part function for setting the text style.
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=INVALID_WIDGET)
Widget part function for starting a new 'real' widget.
constexpr NWidgetPart SetAlignment(Alignment align)
Widget part function for setting the alignment of text/images.
static const CursorID SPR_CURSOR_SIGN
Definition sprites.h:1573
static const CursorID SPR_CURSOR_QUERY
Definition sprites.h:1570
void SetDirty() const
Mark entire window as dirty (in need of re-paint).
Definition window.cpp:975
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
Definition gfx.cpp:1553
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:315
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.
bool LoadHeightmap(DetailedFileType dft, std::string_view filename)
Load a heightmap from file and change the map in its current dimensions to a landscape representing t...
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.
static constexpr int SPECIAL_HOTKEY_BIT
Bit which denotes that hotkey isn't bound to UI button.
Definition hotkeys.h:77
bool IsSpecialHotkey(const int &hotkey)
Checks if hotkey index is special or not.
Definition hotkeys.h:84
Definition of HouseSpec and accessors.
LeagueTable base class.
League table GUI functions.
PoolID< uint8_t, struct LeagueTableIDTag, 255, 0xFF > LeagueTableID
ID of a league table.
Definition league_type.h:35
void ShowLinkGraphLegend()
Open a link graph legend window.
Declaration of linkgraph overlay GUI.
#define Point
Macro that prevents name conflicts between included headers.
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.
void ShowClientList()
Open the client list window.
GUIs related to networking.
@ 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.
@ Any
Use first found.
Functions/types related to NewGRF debugging.
void ShowSpriteAlignerWindow()
Show the window for aligning sprites.
Functions related to NewGRF objects.
void ShowLastNewsMessage()
Show previous news item.
void ShowMessageHistory()
Display window with news messages history.
GUI functions related to the news.
Functions related to objects.
Window * ShowBuildObjectPicker()
Show our object picker.
@ ShowSigns
Display signs.
Definition openttd.h:48
@ FullDetail
Also draw details of track and roads.
Definition openttd.h:50
@ ShowWaypointNames
Display waypoint names.
Definition openttd.h:51
@ ShowTownNames
Display town names.
Definition openttd.h:46
@ ShowStationNames
Display station names.
Definition openttd.h:47
@ FullAnimation
Perform palette animation.
Definition openttd.h:49
@ ShowCompetitorSigns
Display signs, station names and waypoint names of opponent companies. Buoys and oilrig-stations are ...
Definition openttd.h:52
@ Normal
A game normally paused.
Definition openttd.h:72
@ Editor
In the scenario editor.
Definition openttd.h:21
@ Menu
In the main menu.
Definition openttd.h:19
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:975
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:26
RoadTypes GetRoadTypes(bool introduces)
Get list of road types, regardless of company availability.
Definition road.cpp:238
Road specific functions.
RoadTypes GetMaskForRoadTramType(RoadTramType rtt)
Get the mask for road types of the given RoadTramType.
Definition road.h:185
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:24
@ Tram
Tram type.
Definition road_type.h:40
@ Road
Road type.
Definition road_type.h:39
A number of safeguards to prevent using unsafe methods.
void ToggleScreensaverMode()
Enters or exits "Screensaver Mode".
Exports a function to turn on and off a screensaver mode.
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.
Window for configuring the scripts.
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:262
void SndClickBeep()
Play a beep sound for a click event if enabled in settings.
Definition sound.cpp:254
Functions related to sound.
Functions to cache sprites in memory.
static const SpriteID SPR_IMG_PLANTTREES
Definition sprites.h:1259
static const SpriteID SPR_IMG_COMPANY_GENERAL
Definition sprites.h:1252
static const SpriteID SPR_IMG_BUILDAIR
Definition sprites.h:1270
static const SpriteID SPR_IMG_AIRPORT
Definition sprites.h:1457
static const SpriteID SPR_IMG_TRAINLIST
Definition sprites.h:1260
static const SpriteID SPR_IMG_INDUSTRY
Definition sprites.h:1258
static const SpriteID SPR_IMG_BUILDWATER
Definition sprites.h:1269
static const SpriteID SPR_IMG_BUILD_CANAL
Definition sprites.h:1240
static const SpriteID SPR_IMG_SIGN
Definition sprites.h:1275
static const SpriteID SPR_IMG_TRANSMITTER
Definition sprites.h:1238
static const SpriteID SPR_IMG_COMPANY_LIST
Definition sprites.h:1250
static const SpriteID SPR_IMG_MUSIC
Definition sprites.h:1272
static const SpriteID SPR_IMG_GRAPHS
Definition sprites.h:1253
static const SpriteID SPR_IMG_PAUSE
Definition sprites.h:1243
static const SpriteID SPR_IMG_BUILDTRAMS
Definition sprites.h:1268
static const SpriteID SPR_IMG_SAVE
Definition sprites.h:1246
static const SpriteID SPR_IMG_COMPANY_FINANCE
Definition sprites.h:1251
static const SpriteID SPR_COMPANY_ICON
Icon showing company colour.
Definition sprites.h:385
static const SpriteID SPR_IMG_ZOOMIN
Definition sprites.h:1264
static const SpriteID SPR_IMG_MESSAGES
Definition sprites.h:1273
static const SpriteID SPR_LOCK
Lock icon (for password protected servers).
Definition sprites.h:73
static const SpriteID SPR_IMG_TRUCKLIST
Definition sprites.h:1261
static const SpriteID SPR_IMG_ZOOMOUT
Definition sprites.h:1265
static const SpriteID SPR_IMG_AIRPLANESLIST
Definition sprites.h:1263
static const SpriteID SPR_IMG_SUBSIDIES
Definition sprites.h:1249
static const SpriteID SPR_IMG_FASTFORWARD
Definition sprites.h:1244
static const SpriteID SPR_IMG_SHIPLIST
Definition sprites.h:1262
static const SpriteID SPR_IMG_TOWN
Definition sprites.h:1248
static const SpriteID SPR_IMG_SETTINGS
Definition sprites.h:1245
static const SpriteID SPR_IMG_COMPANY_LEAGUE
Definition sprites.h:1254
static const SpriteID SPR_EMPTY
Empty (transparent blue) sprite.
Definition sprites.h:46
static const SpriteID SPR_IMG_QUERY
Definition sprites.h:1274
static const SpriteID SPR_ARROW_DOWN
Definition sprites.h:85
static const SpriteID SPR_ARROW_UP
Definition sprites.h:86
static const SpriteID SPR_IMG_STORY_BOOK
Definition sprites.h:1277
static const SpriteID SPR_IMG_GOAL
Definition sprites.h:1545
static const SpriteID SPR_IMG_SMALLMAP
Definition sprites.h:1247
static const SpriteID SPR_IMG_BUILDROAD
Definition sprites.h:1267
static const SpriteID SPR_IMG_LANDSCAPING
Definition sprites.h:1271
static const SpriteID SPR_IMG_BUILDRAIL
Definition sprites.h:1266
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:261
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.
StrongType::Typedef< uint32_t, struct StringIDTag, StrongType::Compare, StrongType::Integer > StringID
Numeric value that represents a string, independent of the selected language.
Settings related to the AI.
Dimensions (a width and height) of a rectangle in 2D.
List of hotkeys for a window.
Definition hotkeys.h:46
All data for a single hotkey.
Definition hotkeys.h:22
Struct about custom league tables.
Definition league_base.h:52
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.
static Pool::IterateWrapper< LeagueTable > Iterate(size_t from=0)
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.
Container with the data associated to a single widget.
High level window description.
Definition window_gui.h:172
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:987
void DrawWidgets() const
Paint all widgets of a window.
Definition widget.cpp:792
void SetWidgetDirty(WidgetID widget_index) const
Invalidate a widget, i.e.
Definition window.cpp:565
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:513
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:1485
Window(WindowDesc &desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
Definition window.cpp:1841
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:604
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
Definition window.cpp:1831
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)
Definition textbuf_gui.h:20
StrongType::Typedef< uint32_t, struct TileIndexTag, StrongType::Compare, StrongType::Integer, StrongType::Compatible< int32_t >, StrongType::Compatible< int64_t > > TileIndex
The index/ID of a Tile.
Definition tile_type.h:92
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.
@ LoadScenario
Load a scenario.
@ ExitGame
Exit to desktop.
@ SaveScenario
Save the scenario.
@ LoadHeightmap
Load a heightmap.
@ SaveHeightmap
Save the heightmap.
@ ExitToMainMenu
Exit to main menu.
RailType _last_built_railtype
The most recently used type of rail.
MainToolbarEditorHotkeys
List of hotkeys available in scenario editor.
@ GenerateTown
Open town generation window.
@ GenerateLand
Open land generation window.
@ Pause
(Un)pause the game.
@ Terraform
Open land generation window.
@ Sign
Toggle sign creation tool.
@ SmallMap
Open small map window.
@ GenerateIndustry
Open industry funding window.
@ Music
Open sound end music window.
@ GiantScreenshot
Take detailed screenshot of whole map.
@ BuildWater
Open window for building locks, canals, rivers and aqueducts.
@ ZoomedInScreenshot
Take zoomed in screenshot.
@ DefaultZoomScreenshot
Take screenshot with default zoom.
@ FastForward
Toggle the fast-forward mode.
@ SaveGame
Open save scenario window.
@ SmallScreenshot
Take small screenshot.
@ LandInfo
Toggle land info tool.
@ BuildTram
Open toolbar window with tools for building tramways.
@ BuildTrees
Open tree selection window.
@ BuildRoad
Open toolbar window with tools for building roads.
@ Settings
Open game options window.
@ ExtraViewport
Open new extra viewport window.
static std::string _railtype_filter
Persistent filter text for railtype dropdown menu.
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 std::string _roadtype_filter
Persistent filter text for roadtype dropdown 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.
@ Upper
Toolbar is in split mode and the first part is selected.
@ Normal
Toolbar is in normal mode, in which all 30 buttons are accessible.
@ Lower
Toolbar is in split mode and the second part is selected.
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.
@ PlaceSign
A new sign will be placed when tile is selected afterwards.
@ None
No action will happen when tile is selected afterwards.
@ PlaceLandInfo
Land info window will appear when tile is selected afterwards.
static CallBackFunction ToolbarSaveClick(Window *w)
Handle click on Save button in toolbar in normal game mode.
static std::string _tramtype_filter
Persistent filter text for tramtype dropdown menu.
SaveLoadNormalMenuEntries
SaveLoad entries in normal game mode.
@ ExitGame
Exit to desktop.
@ ExitToMainMenu
Exit to main menu.
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 DropDownOptions GetToolbarDropDownOptions(DropDownOptions options={})
Get options for toolbar dropdown menus,.
static std::unique_ptr< NWidgetBase > MakeMainToolbar()
Make widgets for the main toolbar.
static CallBackFunction MenuClickSaveLoad(int index=0)
Handle click on one of the entries in the SaveLoad menu.
RoadType _last_built_tramtype
The most recently used type of tram track.
static const int CTMN_CLIENT_LIST
Indicates the "all connected players" entry.
static const int GRMN_INCOME_GRAPH
Show income graph.
static CallBackFunction MenuClickMusicWindow(int)
Handle click on the entry in the Music menu.
RoadType _last_built_roadtype
The most recently used type of road.
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.
TownMenuEntries
Town button menu entries.
@ ShowDirectory
Open window with list of towns.
@ ShowPlaceHouses
Open house selection window.
@ ShowFoundTown
Open town generation window.
void ToggleDirtyBlocks()
Toggle drawing of the dirty blocks.
static WindowDesc _toolb_normal_desc(WindowPosition::Manual, {}, 0, 0, WindowClass::MainToolbar, WindowClass::None, {WindowDefaultFlag::NoFocus, WindowDefaultFlag::NoClose}, _nested_toolbar_normal_widgets, &MainToolbarWindow::hotkeys)
Window definition for the normal (top) toolbar.
static CallBackFunction MenuClickGoal(int index)
Handle click on the entry in the Goal menu.
static WindowDesc _toolb_scen_desc(WindowPosition::Manual, {}, 0, 0, WindowClass::MainToolbar, WindowClass::None, {WindowDefaultFlag::NoFocus, WindowDefaultFlag::NoClose}, _nested_toolb_scen_widgets, &ScenarioEditorToolbarWindow::hotkeys)
Window definition for the scenario editor (top) toolbar window.
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.
MapMenuEntries
Map button menu entries.
@ ShowIndustryDirectory
Open window with list of industries.
@ ShowExtraViewport
Open new extra viewport window.
@ ShowSmallMap
Open small map window.
@ ShowLinkGraph
Open cargo flow legend window.
@ ShowTownDirectory
Open window with list of towns.
@ ShowSignList
Open sign list window.
static CallBackFunction _last_started_action
Last started user action.
Dimension GetToolbarMaximalImageSize()
Get maximal square size of a toolbar image.
static CallBackFunction MenuClickShowTrains(int index)
Handle click on the entry in the Train menu.
CallBackFunction(Window *w) ToolbarButtonProc
Callback for when a button is clicked in the given window.
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.
@ ShowBusStationNames
Toggle visibility of bus station names.
@ FullDetails
Toggle full details.
@ ShowSigns
Toggle visibility of signs.
@ ShowLorryStationNames
Toggle visibility of lorry station names.
@ ShowWaypointNames
Toggle visibility of waypoint names.
@ ShowDockNames
Toggle visibility of dock names.
@ TransparentStationSigns
Toggle transparency of signs and names.
@ ShowGhostStationNames
Toggle visibility of ghost station names.
@ GameScriptSettings
Open GS settings window.
@ ShowTownNames
Toggle visibility of town names.
@ AISettings
Open AI settings window.
@ ShowStationNames
Toggle visibility of station names.
@ TransparentBuildings
Toggle buildings transparency.
@ NewGRFSettings
Open NewGRF settings window.
@ ShowTrainStationNames
Toggle visibility of train station names.
@ Transparencies
Open transparency options window.
@ ShowAirportNames
Toggle visibility of airport names.
@ SandboxOptions
Open sandbox options window.
@ FullAnimation
Toggle full animations.
@ GameOptions
Open game options window.
@ ShowCompetitorSigns
Toggle visibility of competitor signs and names.
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
Indicates the "become spectator" entry.
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 constexpr std::tuple< WidgetID, WidgetType, SpriteID > _toolbar_button_sprites[]
Sprites to use for the different toolbar buttons.
static CallBackFunction MenuClickIndustry(int index)
Handle click on the entry in the Industry menu.
static const int CTMN_SPECTATOR
Indicates that a window is being opened for the 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.
@ 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...
DisplayOptions _display_opt
What do we want to draw/do?
@ Houses
town buildings
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.
@ Ship
Ship vehicle type.
@ Aircraft
Aircraft vehicle type.
@ Road
Road vehicle type.
@ 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:35
@ WWT_IMGBTN
(Toggle) Button with image
Definition widget_type.h:41
@ WWT_IMGBTN_2
(Toggle) Button with diff image when clicked
Definition widget_type.h:42
@ WWT_PUSHIMGBTN
Normal push-button (no toggle button) with image caption.
@ NWID_SPACER
Invisible widget that takes some space.
Definition widget_type.h:70
@ NWID_HORIZONTAL
Horizontal container.
Definition widget_type.h:66
@ WWT_PANEL
Simple depressed panel.
Definition widget_type.h:39
@ WWT_TEXT
Pure simple text.
Definition widget_type.h:49
SizingType
Different forms of sizing nested widgets, using NWidgetBase::AssignSizePosition().
Window * GetMainWindow()
Get the main window, i.e.
Definition window.cpp:1190
int PositionMainToolbar(Window *w)
(Re)position main toolbar window at the screen.
Definition window.cpp:3490
void DeleteAllMessages()
Delete all messages and close their corresponding window (if any).
Definition window.cpp:3393
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:3336
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.
Definition window_gui.h:158
@ NoFocus
This window won't get focus/make any other window lose focus when click.
Definition window_gui.h:157
@ WhiteBorder
Window white border counter bit mask.
Definition window_gui.h:232
@ Timeout
Window timeout counter.
Definition window_gui.h:224
@ Manual
Manually align the window (so no automatic location finding).
Definition window_gui.h:145
int WidgetID
Widget ID.
Definition window_type.h:21
EventState
State of handling an event.
@ Handled
The passed event is handled.
@ NotHandled
The passed event is not handled.