OpenTTD
toolbar_gui.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of OpenTTD.
3  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6  */
7 
10 #include "stdafx.h"
11 #include "gui.h"
12 #include "window_gui.h"
13 #include "window_func.h"
14 #include "viewport_func.h"
15 #include "command_func.h"
16 #include "vehicle_gui.h"
17 #include "rail_gui.h"
18 #include "road.h"
19 #include "road_gui.h"
20 #include "date_func.h"
21 #include "vehicle_func.h"
22 #include "sound_func.h"
23 #include "terraform_gui.h"
24 #include "strings_func.h"
25 #include "company_func.h"
26 #include "company_gui.h"
27 #include "vehicle_base.h"
28 #include "cheat_func.h"
29 #include "transparency_gui.h"
30 #include "screenshot.h"
31 #include "signs_func.h"
32 #include "fios.h"
33 #include "console_gui.h"
34 #include "news_gui.h"
35 #include "ai/ai_gui.hpp"
36 #include "tilehighlight_func.h"
37 #include "smallmap_gui.h"
38 #include "graph_gui.h"
39 #include "textbuf_gui.h"
41 #include "newgrf_debug.h"
42 #include "hotkeys.h"
43 #include "engine_base.h"
44 #include "highscore.h"
45 #include "game/game.hpp"
46 #include "goal_base.h"
47 #include "story_base.h"
48 #include "toolbar_gui.h"
49 #include "framerate_type.h"
50 #include "guitimer_func.h"
51 
52 #include "widgets/toolbar_widget.h"
53 
54 #include "network/network.h"
55 #include "network/network_gui.h"
56 #include "network/network_func.h"
57 
58 #include "safeguards.h"
59 
60 
62 uint _toolbar_width = 0;
63 
64 RailType _last_built_railtype;
65 RoadType _last_built_roadtype;
66 RoadType _last_built_tramtype;
67 
69 
72  TB_NORMAL,
73  TB_UPPER,
74  TB_LOWER
75 };
76 
79  CBF_NONE,
80  CBF_PLACE_SIGN,
81  CBF_PLACE_LANDINFO,
82 };
83 
85 
86 
91  uint checkmark_width;
92 public:
93  bool checked;
94 
95  DropDownListCheckedItem(StringID string, int result, bool masked, bool checked) : DropDownListStringItem(string, result, masked), checked(checked)
96  {
97  this->checkmark_width = GetStringBoundingBox(STR_JUST_CHECKMARK).width + 3;
98  }
99 
100  uint Width() const
101  {
102  return DropDownListStringItem::Width() + this->checkmark_width;
103  }
104 
105  void Draw(int left, int right, int top, int bottom, bool sel, Colours bg_colour) const
106  {
107  bool rtl = _current_text_dir == TD_RTL;
108  if (this->checked) {
109  DrawString(left + WD_FRAMERECT_LEFT, right - WD_FRAMERECT_RIGHT, top, STR_JUST_CHECKMARK, sel ? TC_WHITE : TC_BLACK);
110  }
111  DrawString(left + WD_FRAMERECT_LEFT + (rtl ? 0 : this->checkmark_width), right - WD_FRAMERECT_RIGHT - (rtl ? this->checkmark_width : 0), top, this->String(), sel ? TC_WHITE : TC_BLACK);
112  }
113 };
114 
119  Dimension icon_size;
120  Dimension lock_size;
121 public:
122  bool greyed;
123 
124  DropDownListCompanyItem(int result, bool masked, bool greyed) : DropDownListItem(result, masked), greyed(greyed)
125  {
126  this->icon_size = GetSpriteSize(SPR_COMPANY_ICON);
127  this->lock_size = GetSpriteSize(SPR_LOCK);
128  }
129 
130  bool Selectable() const override
131  {
132  return true;
133  }
134 
135  uint Width() const override
136  {
137  CompanyID company = (CompanyID)this->result;
138  SetDParam(0, company);
139  SetDParam(1, company);
140  return GetStringBoundingBox(STR_COMPANY_NAME_COMPANY_NUM).width + this->icon_size.width + this->lock_size.width + 6;
141  }
142 
143  uint Height(uint width) const override
144  {
145  return max(max(this->icon_size.height, this->lock_size.height) + 2U, (uint)FONT_HEIGHT_NORMAL);
146  }
147 
148  void Draw(int left, int right, int top, int bottom, bool sel, Colours bg_colour) const override
149  {
150  CompanyID company = (CompanyID)this->result;
151  bool rtl = _current_text_dir == TD_RTL;
152 
153  /* It's possible the company is deleted while the dropdown is open */
154  if (!Company::IsValidID(company)) return;
155 
156  int icon_offset = (bottom - top - icon_size.height) / 2;
157  int text_offset = (bottom - top - FONT_HEIGHT_NORMAL) / 2;
158  int lock_offset = (bottom - top - lock_size.height) / 2;
159 
160  DrawCompanyIcon(company, rtl ? right - this->icon_size.width - WD_FRAMERECT_RIGHT : left + WD_FRAMERECT_LEFT, top + icon_offset);
161  if (NetworkCompanyIsPassworded(company)) {
162  DrawSprite(SPR_LOCK, PAL_NONE, rtl ? left + WD_FRAMERECT_LEFT : right - this->lock_size.width - WD_FRAMERECT_RIGHT, top + lock_offset);
163  }
164 
165  SetDParam(0, company);
166  SetDParam(1, company);
167  TextColour col;
168  if (this->greyed) {
169  col = (sel ? TC_SILVER : TC_GREY) | TC_NO_SHADE;
170  } else {
171  col = sel ? TC_WHITE : TC_BLACK;
172  }
173  DrawString(left + WD_FRAMERECT_LEFT + (rtl ? 3 + this->lock_size.width : 3 + this->icon_size.width), right - WD_FRAMERECT_RIGHT - (rtl ? 3 + this->icon_size.width : 3 + this->lock_size.width), top + text_offset, STR_COMPANY_NAME_COMPANY_NUM, col);
174  }
175 };
176 
184 static void PopupMainToolbMenu(Window *w, int widget, DropDownList &&list, int def)
185 {
186  ShowDropDownList(w, std::move(list), def, widget, 0, true, true);
187  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
188 }
189 
197 static void PopupMainToolbMenu(Window *w, int widget, StringID string, int count)
198 {
199  DropDownList list;
200  for (int i = 0; i < count; i++) {
201  list.emplace_back(new DropDownListStringItem(string + i, i, false));
202  }
203  PopupMainToolbMenu(w, widget, std::move(list), 0);
204 }
205 
207 static const int CTMN_CLIENT_LIST = -1;
208 static const int CTMN_NEW_COMPANY = -2;
209 static const int CTMN_SPECTATE = -3;
210 static const int CTMN_SPECTATOR = -4;
211 
218 static void PopupMainCompanyToolbMenu(Window *w, int widget, int grey = 0)
219 {
220  DropDownList list;
221 
222  switch (widget) {
223  case WID_TN_COMPANIES:
224  if (!_networking) break;
225 
226  /* Add the client list button for the companies menu */
227  list.emplace_back(new DropDownListStringItem(STR_NETWORK_COMPANY_LIST_CLIENT_LIST, CTMN_CLIENT_LIST, false));
228 
230  list.emplace_back(new DropDownListStringItem(STR_NETWORK_COMPANY_LIST_NEW_COMPANY, CTMN_NEW_COMPANY, NetworkMaxCompaniesReached()));
231  } else {
232  list.emplace_back(new DropDownListStringItem(STR_NETWORK_COMPANY_LIST_SPECTATE, CTMN_SPECTATE, NetworkMaxSpectatorsReached()));
233  }
234  break;
235 
236  case WID_TN_STORY:
237  list.emplace_back(new DropDownListStringItem(STR_STORY_BOOK_SPECTATOR, CTMN_SPECTATOR, false));
238  break;
239 
240  case WID_TN_GOAL:
241  list.emplace_back(new DropDownListStringItem(STR_GOALS_SPECTATOR, CTMN_SPECTATOR, false));
242  break;
243  }
244 
245  for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) {
246  if (!Company::IsValidID(c)) continue;
247  list.emplace_back(new DropDownListCompanyItem(c, false, HasBit(grey, c)));
248  }
249 
251 }
252 
253 
254 static ToolbarMode _toolbar_mode;
255 
256 static CallBackFunction SelectSignTool()
257 {
258  if (_last_started_action == CBF_PLACE_SIGN) {
260  return CBF_NONE;
261  } else {
262  SetObjectToPlace(SPR_CURSOR_SIGN, PAL_NONE, HT_RECT, WC_MAIN_TOOLBAR, 0);
263  return CBF_PLACE_SIGN;
264  }
265 }
266 
267 /* --- Pausing --- */
268 
269 static CallBackFunction ToolbarPauseClick(Window *w)
270 {
271  if (_networking && !_network_server) return CBF_NONE; // only server can pause the game
272 
274  if (_settings_client.sound.confirm) SndPlayFx(SND_15_BEEP);
275  }
276  return CBF_NONE;
277 }
278 
286 {
287  _fast_forward ^= true;
288  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
289  return CBF_NONE;
290 }
291 
296  OME_GAMEOPTIONS,
297  OME_SETTINGS,
298  OME_SCRIPT_SETTINGS,
299  OME_NEWGRFSETTINGS,
300  OME_TRANSPARENCIES,
301  OME_SHOW_TOWNNAMES,
302  OME_SHOW_STATIONNAMES,
303  OME_SHOW_WAYPOINTNAMES,
304  OME_SHOW_SIGNS,
305  OME_SHOW_COMPETITOR_SIGNS,
306  OME_FULL_ANIMATION,
307  OME_FULL_DETAILS,
308  OME_TRANSPARENTBUILDINGS,
309  OME_SHOW_STATIONSIGNS,
310 };
311 
319 {
320  DropDownList list;
321  list.emplace_back(new DropDownListStringItem(STR_SETTINGS_MENU_GAME_OPTIONS, OME_GAMEOPTIONS, false));
322  list.emplace_back(new DropDownListStringItem(STR_SETTINGS_MENU_CONFIG_SETTINGS_TREE, OME_SETTINGS, false));
323  /* Changes to the per-AI settings don't get send from the server to the clients. Clients get
324  * the settings once they join but never update it. As such don't show the window at all
325  * to network clients. */
326  if (!_networking || _network_server) list.emplace_back(new DropDownListStringItem(STR_SETTINGS_MENU_SCRIPT_SETTINGS, OME_SCRIPT_SETTINGS, false));
327  list.emplace_back(new DropDownListStringItem(STR_SETTINGS_MENU_NEWGRF_SETTINGS, OME_NEWGRFSETTINGS, false));
328  list.emplace_back(new DropDownListStringItem(STR_SETTINGS_MENU_TRANSPARENCY_OPTIONS, OME_TRANSPARENCIES, false));
329  list.emplace_back(new DropDownListItem(-1, false));
330  list.emplace_back(new DropDownListCheckedItem(STR_SETTINGS_MENU_TOWN_NAMES_DISPLAYED, OME_SHOW_TOWNNAMES, false, HasBit(_display_opt, DO_SHOW_TOWN_NAMES)));
331  list.emplace_back(new DropDownListCheckedItem(STR_SETTINGS_MENU_STATION_NAMES_DISPLAYED, OME_SHOW_STATIONNAMES, false, HasBit(_display_opt, DO_SHOW_STATION_NAMES)));
332  list.emplace_back(new DropDownListCheckedItem(STR_SETTINGS_MENU_WAYPOINTS_DISPLAYED, OME_SHOW_WAYPOINTNAMES, false, HasBit(_display_opt, DO_SHOW_WAYPOINT_NAMES)));
333  list.emplace_back(new DropDownListCheckedItem(STR_SETTINGS_MENU_SIGNS_DISPLAYED, OME_SHOW_SIGNS, false, HasBit(_display_opt, DO_SHOW_SIGNS)));
334  list.emplace_back(new DropDownListCheckedItem(STR_SETTINGS_MENU_SHOW_COMPETITOR_SIGNS, OME_SHOW_COMPETITOR_SIGNS, false, HasBit(_display_opt, DO_SHOW_COMPETITOR_SIGNS)));
335  list.emplace_back(new DropDownListCheckedItem(STR_SETTINGS_MENU_FULL_ANIMATION, OME_FULL_ANIMATION, false, HasBit(_display_opt, DO_FULL_ANIMATION)));
336  list.emplace_back(new DropDownListCheckedItem(STR_SETTINGS_MENU_FULL_DETAIL, OME_FULL_DETAILS, false, HasBit(_display_opt, DO_FULL_DETAIL)));
337  list.emplace_back(new DropDownListCheckedItem(STR_SETTINGS_MENU_TRANSPARENT_BUILDINGS, OME_TRANSPARENTBUILDINGS, false, IsTransparencySet(TO_HOUSES)));
338  list.emplace_back(new DropDownListCheckedItem(STR_SETTINGS_MENU_TRANSPARENT_SIGNS, OME_SHOW_STATIONSIGNS, false, IsTransparencySet(TO_SIGNS)));
339 
340  ShowDropDownList(w, std::move(list), 0, WID_TN_SETTINGS, 140, true, true);
341  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
342  return CBF_NONE;
343 }
344 
352 {
353  switch (index) {
354  case OME_GAMEOPTIONS: ShowGameOptions(); return CBF_NONE;
355  case OME_SETTINGS: ShowGameSettings(); return CBF_NONE;
356  case OME_SCRIPT_SETTINGS: ShowAIConfigWindow(); return CBF_NONE;
357  case OME_NEWGRFSETTINGS: ShowNewGRFSettings(!_networking && _settings_client.gui.UserIsAllowedToChangeNewGRFs(), true, true, &_grfconfig); return CBF_NONE;
358  case OME_TRANSPARENCIES: ShowTransparencyToolbar(); break;
359 
360  case OME_SHOW_TOWNNAMES: ToggleBit(_display_opt, DO_SHOW_TOWN_NAMES); break;
361  case OME_SHOW_STATIONNAMES: ToggleBit(_display_opt, DO_SHOW_STATION_NAMES); break;
362  case OME_SHOW_WAYPOINTNAMES: ToggleBit(_display_opt, DO_SHOW_WAYPOINT_NAMES); break;
363  case OME_SHOW_SIGNS: ToggleBit(_display_opt, DO_SHOW_SIGNS); break;
364  case OME_SHOW_COMPETITOR_SIGNS:
367  break;
368  case OME_FULL_ANIMATION: ToggleBit(_display_opt, DO_FULL_ANIMATION); CheckBlitter(); break;
369  case OME_FULL_DETAILS: ToggleBit(_display_opt, DO_FULL_DETAIL); break;
370  case OME_TRANSPARENTBUILDINGS: ToggleTransparency(TO_HOUSES); break;
371  case OME_SHOW_STATIONSIGNS: ToggleTransparency(TO_SIGNS); break;
372  }
374  return CBF_NONE;
375 }
376 
381  SLEME_SAVE_SCENARIO = 0,
382  SLEME_LOAD_SCENARIO,
383  SLEME_SAVE_HEIGHTMAP,
384  SLEME_LOAD_HEIGHTMAP,
385  SLEME_EXIT_TOINTRO,
386  SLEME_EXIT_GAME = 6,
387  SLEME_MENUCOUNT,
388 };
389 
394  SLNME_SAVE_GAME = 0,
395  SLNME_LOAD_GAME,
396  SLNME_EXIT_TOINTRO,
397  SLNME_EXIT_GAME = 4,
398  SLNME_MENUCOUNT,
399 };
400 
408 {
409  PopupMainToolbMenu(w, WID_TN_SAVE, STR_FILE_MENU_SAVE_GAME, SLNME_MENUCOUNT);
410  return CBF_NONE;
411 }
412 
420 {
421  PopupMainToolbMenu(w, WID_TE_SAVE, STR_SCENEDIT_FILE_MENU_SAVE_SCENARIO, SLEME_MENUCOUNT);
422  return CBF_NONE;
423 }
424 
431 static CallBackFunction MenuClickSaveLoad(int index = 0)
432 {
433  if (_game_mode == GM_EDITOR) {
434  switch (index) {
435  case SLEME_SAVE_SCENARIO: ShowSaveLoadDialog(FT_SCENARIO, SLO_SAVE); break;
436  case SLEME_LOAD_SCENARIO: ShowSaveLoadDialog(FT_SCENARIO, SLO_LOAD); break;
437  case SLEME_SAVE_HEIGHTMAP: ShowSaveLoadDialog(FT_HEIGHTMAP,SLO_SAVE); break;
438  case SLEME_LOAD_HEIGHTMAP: ShowSaveLoadDialog(FT_HEIGHTMAP,SLO_LOAD); break;
439  case SLEME_EXIT_TOINTRO: AskExitToGameMenu(); break;
440  case SLEME_EXIT_GAME: HandleExitGameRequest(); break;
441  }
442  } else {
443  switch (index) {
444  case SLNME_SAVE_GAME: ShowSaveLoadDialog(FT_SAVEGAME, SLO_SAVE); break;
445  case SLNME_LOAD_GAME: ShowSaveLoadDialog(FT_SAVEGAME, SLO_LOAD); break;
446  case SLNME_EXIT_TOINTRO: AskExitToGameMenu(); break;
447  case SLNME_EXIT_GAME: HandleExitGameRequest(); break;
448  }
449  }
450  return CBF_NONE;
451 }
452 
453 /* --- Map button menu --- */
454 
455 enum MapMenuEntries {
456  MME_SHOW_SMALLMAP = 0,
457  MME_SHOW_EXTRAVIEWPORTS,
458  MME_SHOW_LINKGRAPH,
459  MME_SHOW_SIGNLISTS,
460  MME_SHOW_TOWNDIRECTORY,
461  MME_SHOW_INDUSTRYDIRECTORY,
462 };
463 
464 static CallBackFunction ToolbarMapClick(Window *w)
465 {
466  DropDownList list;
467  list.emplace_back(new DropDownListStringItem(STR_MAP_MENU_MAP_OF_WORLD, MME_SHOW_SMALLMAP, false));
468  list.emplace_back(new DropDownListStringItem(STR_MAP_MENU_EXTRA_VIEW_PORT, MME_SHOW_EXTRAVIEWPORTS, false));
469  list.emplace_back(new DropDownListStringItem(STR_MAP_MENU_LINGRAPH_LEGEND, MME_SHOW_LINKGRAPH, false));
470  list.emplace_back(new DropDownListStringItem(STR_MAP_MENU_SIGN_LIST, MME_SHOW_SIGNLISTS, false));
471  PopupMainToolbMenu(w, WID_TN_SMALL_MAP, std::move(list), 0);
472  return CBF_NONE;
473 }
474 
475 static CallBackFunction ToolbarScenMapTownDir(Window *w)
476 {
477  DropDownList list;
478  list.emplace_back(new DropDownListStringItem(STR_MAP_MENU_MAP_OF_WORLD, MME_SHOW_SMALLMAP, false));
479  list.emplace_back(new DropDownListStringItem(STR_MAP_MENU_EXTRA_VIEW_PORT, MME_SHOW_EXTRAVIEWPORTS, false));
480  list.emplace_back(new DropDownListStringItem(STR_MAP_MENU_SIGN_LIST, MME_SHOW_SIGNLISTS, false));
481  list.emplace_back(new DropDownListStringItem(STR_TOWN_MENU_TOWN_DIRECTORY, MME_SHOW_TOWNDIRECTORY, false));
482  list.emplace_back(new DropDownListStringItem(STR_INDUSTRY_MENU_INDUSTRY_DIRECTORY, MME_SHOW_INDUSTRYDIRECTORY, false));
483  PopupMainToolbMenu(w, WID_TE_SMALL_MAP, std::move(list), 0);
484  return CBF_NONE;
485 }
486 
494 {
495  switch (index) {
496  case MME_SHOW_SMALLMAP: ShowSmallMap(); break;
497  case MME_SHOW_EXTRAVIEWPORTS: ShowExtraViewPortWindow(); break;
498  case MME_SHOW_LINKGRAPH: ShowLinkGraphLegend(); break;
499  case MME_SHOW_SIGNLISTS: ShowSignList(); break;
500  case MME_SHOW_TOWNDIRECTORY: ShowTownDirectory(); break;
501  case MME_SHOW_INDUSTRYDIRECTORY: ShowIndustryDirectory(); break;
502  }
503  return CBF_NONE;
504 }
505 
506 /* --- Town button menu --- */
507 
508 static CallBackFunction ToolbarTownClick(Window *w)
509 {
510  PopupMainToolbMenu(w, WID_TN_TOWNS, STR_TOWN_MENU_TOWN_DIRECTORY, (_settings_game.economy.found_town == TF_FORBIDDEN) ? 1 : 2);
511  return CBF_NONE;
512 }
513 
521 {
522  switch (index) {
523  case 0: ShowTownDirectory(); break;
524  case 1: // setting could be changed when the dropdown was open
525  if (_settings_game.economy.found_town != TF_FORBIDDEN) ShowFoundTownWindow();
526  break;
527  }
528  return CBF_NONE;
529 }
530 
531 /* --- Subidies button menu --- */
532 
533 static CallBackFunction ToolbarSubsidiesClick(Window *w)
534 {
535  PopupMainToolbMenu(w, WID_TN_SUBSIDIES, STR_SUBSIDIES_MENU_SUBSIDIES, 1);
536  return CBF_NONE;
537 }
538 
546 {
547  switch (index) {
548  case 0: ShowSubsidiesList(); break;
549  }
550  return CBF_NONE;
551 }
552 
553 /* --- Stations button menu --- */
554 
555 static CallBackFunction ToolbarStationsClick(Window *w)
556 {
558  return CBF_NONE;
559 }
560 
568 {
570  return CBF_NONE;
571 }
572 
573 /* --- Finances button menu --- */
574 
575 static CallBackFunction ToolbarFinancesClick(Window *w)
576 {
578  return CBF_NONE;
579 }
580 
588 {
590  return CBF_NONE;
591 }
592 
593 /* --- Company's button menu --- */
594 
595 static CallBackFunction ToolbarCompaniesClick(Window *w)
596 {
598  return CBF_NONE;
599 }
600 
608 {
609  if (_networking) {
610  switch (index) {
611  case CTMN_CLIENT_LIST:
612  ShowClientList();
613  return CBF_NONE;
614 
615  case CTMN_NEW_COMPANY:
616  if (_network_server) {
618  } else {
619  NetworkSendCommand(0, CCA_NEW, 0, CMD_COMPANY_CTRL, nullptr, nullptr, _local_company);
620  }
621  return CBF_NONE;
622 
623  case CTMN_SPECTATE:
624  if (_network_server) {
627  } else {
629  }
630  return CBF_NONE;
631  }
632  }
633  ShowCompany((CompanyID)index);
634  return CBF_NONE;
635 }
636 
637 /* --- Story button menu --- */
638 
639 static CallBackFunction ToolbarStoryClick(Window *w)
640 {
642  return CBF_NONE;
643 }
644 
652 {
654  return CBF_NONE;
655 }
656 
657 /* --- Goal button menu --- */
658 
659 static CallBackFunction ToolbarGoalClick(Window *w)
660 {
662  return CBF_NONE;
663 }
664 
672 {
674  return CBF_NONE;
675 }
676 
677 /* --- Graphs button menu --- */
678 
679 static CallBackFunction ToolbarGraphsClick(Window *w)
680 {
681  PopupMainToolbMenu(w, WID_TN_GRAPHS, STR_GRAPH_MENU_OPERATING_PROFIT_GRAPH, (_toolbar_mode == TB_NORMAL) ? 6 : 8);
682  return CBF_NONE;
683 }
684 
692 {
693  switch (index) {
694  case 0: ShowOperatingProfitGraph(); break;
695  case 1: ShowIncomeGraph(); break;
696  case 2: ShowDeliveredCargoGraph(); break;
697  case 3: ShowPerformanceHistoryGraph(); break;
698  case 4: ShowCompanyValueGraph(); break;
699  case 5: ShowCargoPaymentRates(); break;
700  /* functions for combined graphs/league button */
701  case 6: ShowCompanyLeagueTable(); break;
702  case 7: ShowPerformanceRatingDetail(); break;
703  }
704  return CBF_NONE;
705 }
706 
707 /* --- League button menu --- */
708 
709 static CallBackFunction ToolbarLeagueClick(Window *w)
710 {
711  PopupMainToolbMenu(w, WID_TN_LEAGUE, STR_GRAPH_MENU_COMPANY_LEAGUE_TABLE, _networking ? 2 : 3);
712  return CBF_NONE;
713 }
714 
722 {
723  switch (index) {
724  case 0: ShowCompanyLeagueTable(); break;
725  case 1: ShowPerformanceRatingDetail(); break;
726  case 2: ShowHighscoreTable(); break;
727  }
728  return CBF_NONE;
729 }
730 
731 /* --- Industries button menu --- */
732 
733 static CallBackFunction ToolbarIndustryClick(Window *w)
734 {
735  /* Disable build-industry menu if we are a spectator */
736  PopupMainToolbMenu(w, WID_TN_INDUSTRIES, STR_INDUSTRY_MENU_INDUSTRY_DIRECTORY, (_local_company == COMPANY_SPECTATOR) ? 2 : 3);
737  return CBF_NONE;
738 }
739 
747 {
748  switch (index) {
749  case 0: ShowIndustryDirectory(); break;
750  case 1: ShowIndustryCargoesWindow(); break;
751  case 2: ShowBuildIndustryWindow(); break;
752  }
753  return CBF_NONE;
754 }
755 
756 /* --- Trains button menu + 1 helper function for all vehicles. --- */
757 
758 static void ToolbarVehicleClick(Window *w, VehicleType veh)
759 {
760  int dis = ~0;
761 
762  for (const Vehicle *v : Vehicle::Iterate()) {
763  if (v->type == veh && v->IsPrimaryVehicle()) ClrBit(dis, v->owner);
764  }
766 }
767 
768 
769 static CallBackFunction ToolbarTrainClick(Window *w)
770 {
771  ToolbarVehicleClick(w, VEH_TRAIN);
772  return CBF_NONE;
773 }
774 
782 {
783  ShowVehicleListWindow((CompanyID)index, VEH_TRAIN);
784  return CBF_NONE;
785 }
786 
787 /* --- Road vehicle button menu --- */
788 
789 static CallBackFunction ToolbarRoadClick(Window *w)
790 {
791  ToolbarVehicleClick(w, VEH_ROAD);
792  return CBF_NONE;
793 }
794 
802 {
803  ShowVehicleListWindow((CompanyID)index, VEH_ROAD);
804  return CBF_NONE;
805 }
806 
807 /* --- Ship button menu --- */
808 
809 static CallBackFunction ToolbarShipClick(Window *w)
810 {
811  ToolbarVehicleClick(w, VEH_SHIP);
812  return CBF_NONE;
813 }
814 
822 {
823  ShowVehicleListWindow((CompanyID)index, VEH_SHIP);
824  return CBF_NONE;
825 }
826 
827 /* --- Aircraft button menu --- */
828 
829 static CallBackFunction ToolbarAirClick(Window *w)
830 {
831  ToolbarVehicleClick(w, VEH_AIRCRAFT);
832  return CBF_NONE;
833 }
834 
842 {
843  ShowVehicleListWindow((CompanyID)index, VEH_AIRCRAFT);
844  return CBF_NONE;
845 }
846 
847 /* --- Zoom in button --- */
848 
849 static CallBackFunction ToolbarZoomInClick(Window *w)
850 {
852  w->HandleButtonClick((_game_mode == GM_EDITOR) ? (byte)WID_TE_ZOOM_IN : (byte)WID_TN_ZOOM_IN);
853  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
854  }
855  return CBF_NONE;
856 }
857 
858 /* --- Zoom out button --- */
859 
860 static CallBackFunction ToolbarZoomOutClick(Window *w)
861 {
863  w->HandleButtonClick((_game_mode == GM_EDITOR) ? (byte)WID_TE_ZOOM_OUT : (byte)WID_TN_ZOOM_OUT);
864  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
865  }
866  return CBF_NONE;
867 }
868 
869 /* --- Rail button menu --- */
870 
871 static CallBackFunction ToolbarBuildRailClick(Window *w)
872 {
873  ShowDropDownList(w, GetRailTypeDropDownList(), _last_built_railtype, WID_TN_RAILS, 140, true, true);
874  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
875  return CBF_NONE;
876 }
877 
885 {
886  _last_built_railtype = (RailType)index;
887  ShowBuildRailToolbar(_last_built_railtype);
888  return CBF_NONE;
889 }
890 
891 /* --- Road button menu --- */
892 
893 static CallBackFunction ToolbarBuildRoadClick(Window *w)
894 {
895  ShowDropDownList(w, GetRoadTypeDropDownList(RTTB_ROAD), _last_built_roadtype, WID_TN_ROADS, 140, true, true);
896  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
897  return CBF_NONE;
898 }
899 
907 {
908  _last_built_roadtype = (RoadType)index;
909  ShowBuildRoadToolbar(_last_built_roadtype);
910  return CBF_NONE;
911 }
912 
913 /* --- Tram button menu --- */
914 
915 static CallBackFunction ToolbarBuildTramClick(Window *w)
916 {
917  ShowDropDownList(w, GetRoadTypeDropDownList(RTTB_TRAM), _last_built_tramtype, WID_TN_TRAMS, 140, true, true);
918  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
919  return CBF_NONE;
920 }
921 
929 {
930  _last_built_tramtype = (RoadType)index;
931  ShowBuildRoadToolbar(_last_built_tramtype);
932  return CBF_NONE;
933 }
934 
935 /* --- Water button menu --- */
936 
937 static CallBackFunction ToolbarBuildWaterClick(Window *w)
938 {
939  DropDownList list;
940  list.emplace_back(new DropDownListIconItem(SPR_IMG_BUILD_CANAL, PAL_NONE, STR_WATERWAYS_MENU_WATERWAYS_CONSTRUCTION, 0, false));
941  ShowDropDownList(w, std::move(list), 0, WID_TN_WATER, 140, true, true);
942  return CBF_NONE;
943 }
944 
952 {
954  return CBF_NONE;
955 }
956 
957 /* --- Airport button menu --- */
958 
959 static CallBackFunction ToolbarBuildAirClick(Window *w)
960 {
961  DropDownList list;
962  list.emplace_back(new DropDownListIconItem(SPR_IMG_AIRPORT, PAL_NONE, STR_AIRCRAFT_MENU_AIRPORT_CONSTRUCTION, 0, false));
963  ShowDropDownList(w, std::move(list), 0, WID_TN_AIR, 140, true, true);
964  return CBF_NONE;
965 }
966 
974 {
976  return CBF_NONE;
977 }
978 
979 /* --- Forest button menu --- */
980 
981 static CallBackFunction ToolbarForestClick(Window *w)
982 {
983  DropDownList list;
984  list.emplace_back(new DropDownListIconItem(SPR_IMG_LANDSCAPING, PAL_NONE, STR_LANDSCAPING_MENU_LANDSCAPING, 0, false));
985  list.emplace_back(new DropDownListIconItem(SPR_IMG_PLANTTREES, PAL_NONE, STR_LANDSCAPING_MENU_PLANT_TREES, 1, false));
986  list.emplace_back(new DropDownListIconItem(SPR_IMG_SIGN, PAL_NONE, STR_LANDSCAPING_MENU_PLACE_SIGN, 2, false));
987  ShowDropDownList(w, std::move(list), 0, WID_TN_LANDSCAPE, 100, true, true);
988  return CBF_NONE;
989 }
990 
998 {
999  switch (index) {
1000  case 0: ShowTerraformToolbar(); break;
1001  case 1: ShowBuildTreesToolbar(); break;
1002  case 2: return SelectSignTool();
1003  }
1004  return CBF_NONE;
1005 }
1006 
1007 /* --- Music button menu --- */
1008 
1009 static CallBackFunction ToolbarMusicClick(Window *w)
1010 {
1011  PopupMainToolbMenu(w, _game_mode == GM_EDITOR ? (int)WID_TE_MUSIC_SOUND : (int)WID_TN_MUSIC_SOUND, STR_TOOLBAR_SOUND_MUSIC, 1);
1012  return CBF_NONE;
1013 }
1014 
1022 {
1023  ShowMusicWindow();
1024  return CBF_NONE;
1025 }
1026 
1027 /* --- Newspaper button menu --- */
1028 
1029 static CallBackFunction ToolbarNewspaperClick(Window *w)
1030 {
1031  PopupMainToolbMenu(w, WID_TN_MESSAGES, STR_NEWS_MENU_LAST_MESSAGE_NEWS_REPORT, 3);
1032  return CBF_NONE;
1033 }
1034 
1042 {
1043  switch (index) {
1044  case 0: ShowLastNewsMessage(); break;
1045  case 1: ShowMessageHistory(); break;
1046  case 2: DeleteAllMessages(); break;
1047  }
1048  return CBF_NONE;
1049 }
1050 
1051 /* --- Help button menu --- */
1052 
1053 static CallBackFunction PlaceLandBlockInfo()
1054 {
1055  if (_last_started_action == CBF_PLACE_LANDINFO) {
1057  return CBF_NONE;
1058  } else {
1059  SetObjectToPlace(SPR_CURSOR_QUERY, PAL_NONE, HT_RECT, WC_MAIN_TOOLBAR, 0);
1060  return CBF_PLACE_LANDINFO;
1061  }
1062 }
1063 
1064 static CallBackFunction ToolbarHelpClick(Window *w)
1065 {
1066  PopupMainToolbMenu(w, _game_mode == GM_EDITOR ? (int)WID_TE_HELP : (int)WID_TN_HELP, STR_ABOUT_MENU_LAND_BLOCK_INFO, _settings_client.gui.newgrf_developer_tools ? 13 : 10);
1067  return CBF_NONE;
1068 }
1069 
1070 static void MenuClickSmallScreenshot()
1071 {
1072  MakeScreenshot(SC_VIEWPORT, nullptr);
1073 }
1074 
1080 static void ScreenshotConfirmCallback(Window *w, bool confirmed)
1081 {
1082  if (confirmed) MakeScreenshot(_confirmed_screenshot_type, nullptr);
1083 }
1084 
1091 {
1092  ViewPort vp;
1093  SetupScreenshotViewport(t, &vp);
1094  if ((uint64)vp.width * (uint64)vp.height > 8192 * 8192) {
1095  /* Ask for confirmation */
1096  SetDParam(0, vp.width);
1097  SetDParam(1, vp.height);
1099  ShowQuery(STR_WARNING_SCREENSHOT_SIZE_CAPTION, STR_WARNING_SCREENSHOT_SIZE_MESSAGE, nullptr, ScreenshotConfirmCallback);
1100  } else {
1101  /* Less than 64M pixels, just do it */
1102  MakeScreenshot(t, nullptr);
1103  }
1104 }
1105 
1114 {
1115  extern bool _draw_bounding_boxes;
1116  /* Always allow to toggle them off */
1117  if (_settings_client.gui.newgrf_developer_tools || _draw_bounding_boxes) {
1118  _draw_bounding_boxes = !_draw_bounding_boxes;
1120  }
1121 }
1122 
1131 {
1132  extern bool _draw_dirty_blocks;
1133  /* Always allow to toggle them off */
1134  if (_settings_client.gui.newgrf_developer_tools || _draw_dirty_blocks) {
1135  _draw_dirty_blocks = !_draw_dirty_blocks;
1137  }
1138 }
1139 
1145 {
1148  /* If you open a savegame as scenario there may already be link graphs.*/
1150  SetDate(new_date, 0);
1151 }
1152 
1159 {
1160  switch (index) {
1161  case 0: return PlaceLandBlockInfo();
1162  case 2: IConsoleSwitch(); break;
1163  case 3: ShowAIDebugWindow(); break;
1164  case 4: MenuClickSmallScreenshot(); break;
1167  case 7: MenuClickLargeWorldScreenshot(SC_WORLD); break;
1168  case 8: ShowFramerateWindow(); break;
1169  case 9: ShowAboutWindow(); break;
1170  case 10: ShowSpriteAlignerWindow(); break;
1171  case 11: ToggleBoundingBoxes(); break;
1172  case 12: ToggleDirtyBlocks(); break;
1173  }
1174  return CBF_NONE;
1175 }
1176 
1177 /* --- Switch toolbar button --- */
1178 
1179 static CallBackFunction ToolbarSwitchClick(Window *w)
1180 {
1181  if (_toolbar_mode != TB_LOWER) {
1182  _toolbar_mode = TB_LOWER;
1183  } else {
1184  _toolbar_mode = TB_UPPER;
1185  }
1186 
1187  w->ReInit();
1188  w->SetWidgetLoweredState(_game_mode == GM_EDITOR ? (uint)WID_TE_SWITCH_BAR : (uint)WID_TN_SWITCH_BAR, _toolbar_mode == TB_LOWER);
1189  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
1190  return CBF_NONE;
1191 }
1192 
1193 /* --- Scenario editor specific handlers. */
1194 
1199 {
1201  ShowQueryString(STR_JUST_INT, STR_MAPGEN_START_DATE_QUERY_CAPT, 8, w, CS_NUMERAL, QSF_ENABLE_DEFAULT);
1202  _left_button_clicked = false;
1203  return CBF_NONE;
1204 }
1205 
1206 static CallBackFunction ToolbarScenDateBackward(Window *w)
1207 {
1208  /* don't allow too fast scrolling */
1209  if (!(w->flags & WF_TIMEOUT) || w->timeout_timer <= 1) {
1211  w->SetDirty();
1212 
1214  }
1215  _left_button_clicked = false;
1216  return CBF_NONE;
1217 }
1218 
1219 static CallBackFunction ToolbarScenDateForward(Window *w)
1220 {
1221  /* don't allow too fast scrolling */
1222  if (!(w->flags & WF_TIMEOUT) || w->timeout_timer <= 1) {
1224  w->SetDirty();
1225 
1227  }
1228  _left_button_clicked = false;
1229  return CBF_NONE;
1230 }
1231 
1232 static CallBackFunction ToolbarScenGenLand(Window *w)
1233 {
1235  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
1236 
1238  return CBF_NONE;
1239 }
1240 
1241 
1242 static CallBackFunction ToolbarScenGenTown(Window *w)
1243 {
1245  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
1246  ShowFoundTownWindow();
1247  return CBF_NONE;
1248 }
1249 
1250 static CallBackFunction ToolbarScenGenIndustry(Window *w)
1251 {
1253  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
1254  ShowBuildIndustryWindow();
1255  return CBF_NONE;
1256 }
1257 
1258 static CallBackFunction ToolbarScenBuildRoadClick(Window *w)
1259 {
1260  ShowDropDownList(w, GetScenRoadTypeDropDownList(RTTB_ROAD), _last_built_roadtype, WID_TE_ROADS, 140, true, true);
1261  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
1262  return CBF_NONE;
1263 }
1264 
1272 {
1273  _last_built_roadtype = (RoadType)index;
1274  ShowBuildRoadScenToolbar(_last_built_roadtype);
1275  return CBF_NONE;
1276 }
1277 
1278 static CallBackFunction ToolbarScenBuildTramClick(Window *w)
1279 {
1280  ShowDropDownList(w, GetScenRoadTypeDropDownList(RTTB_TRAM), _last_built_tramtype, WID_TE_TRAMS, 140, true, true);
1281  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
1282  return CBF_NONE;
1283 }
1284 
1292 {
1293  _last_built_tramtype = (RoadType)index;
1294  ShowBuildRoadScenToolbar(_last_built_tramtype);
1295  return CBF_NONE;
1296 }
1297 
1298 static CallBackFunction ToolbarScenBuildDocks(Window *w)
1299 {
1301  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
1303  return CBF_NONE;
1304 }
1305 
1306 static CallBackFunction ToolbarScenPlantTrees(Window *w)
1307 {
1309  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
1310  ShowBuildTreesToolbar();
1311  return CBF_NONE;
1312 }
1313 
1314 static CallBackFunction ToolbarScenPlaceSign(Window *w)
1315 {
1317  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
1318  return SelectSignTool();
1319 }
1320 
1321 static CallBackFunction ToolbarBtn_NULL(Window *w)
1322 {
1323  return CBF_NONE;
1324 }
1325 
1326 typedef CallBackFunction MenuClickedProc(int index);
1327 
1328 static MenuClickedProc * const _menu_clicked_procs[] = {
1329  nullptr, // 0
1330  nullptr, // 1
1331  MenuClickSettings, // 2
1332  MenuClickSaveLoad, // 3
1333  MenuClickMap, // 4
1334  MenuClickTown, // 5
1335  MenuClickSubsidies, // 6
1336  MenuClickStations, // 7
1337  MenuClickFinances, // 8
1338  MenuClickCompany, // 9
1339  MenuClickStory, // 10
1340  MenuClickGoal, // 11
1341  MenuClickGraphs, // 12
1342  MenuClickLeague, // 13
1343  MenuClickIndustry, // 14
1344  MenuClickShowTrains, // 15
1345  MenuClickShowRoad, // 16
1346  MenuClickShowShips, // 17
1347  MenuClickShowAir, // 18
1348  MenuClickMap, // 19
1349  nullptr, // 20
1350  MenuClickBuildRail, // 21
1351  MenuClickBuildRoad, // 22
1352  MenuClickBuildTram, // 23
1353  MenuClickBuildWater, // 24
1354  MenuClickBuildAir, // 25
1355  MenuClickForest, // 26
1356  MenuClickMusicWindow, // 27
1357  MenuClickNewspaper, // 28
1358  MenuClickHelp, // 29
1359 };
1360 
1363  bool visible[WID_TN_END];
1364 protected:
1365  uint spacers;
1366 
1367 public:
1369  {
1370  }
1371 
1377  bool IsButton(WidgetType type) const
1378  {
1379  return type == WWT_IMGBTN || type == WWT_IMGBTN_2 || type == WWT_PUSHIMGBTN;
1380  }
1381 
1382  void SetupSmallestSize(Window *w, bool init_array) override
1383  {
1384  this->smallest_x = 0; // Biggest child
1385  this->smallest_y = 0; // Biggest child
1386  this->fill_x = 1;
1387  this->fill_y = 0;
1388  this->resize_x = 1; // We only resize in this direction
1389  this->resize_y = 0; // We never resize in this direction
1390  this->spacers = 0;
1391 
1392  uint nbuttons = 0;
1393  /* First initialise some variables... */
1394  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1395  child_wid->SetupSmallestSize(w, init_array);
1396  this->smallest_y = max(this->smallest_y, child_wid->smallest_y + child_wid->padding_top + child_wid->padding_bottom);
1397  if (this->IsButton(child_wid->type)) {
1398  nbuttons++;
1399  this->smallest_x = max(this->smallest_x, child_wid->smallest_x + child_wid->padding_left + child_wid->padding_right);
1400  } else if (child_wid->type == NWID_SPACER) {
1401  this->spacers++;
1402  }
1403  }
1404 
1405  /* ... then in a second pass make sure the 'current' heights are set. Won't change ever. */
1406  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1407  child_wid->current_y = this->smallest_y;
1408  if (!this->IsButton(child_wid->type)) {
1409  child_wid->current_x = child_wid->smallest_x;
1410  }
1411  }
1412  _toolbar_width = nbuttons * this->smallest_x;
1413  }
1414 
1415  void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl) override
1416  {
1417  assert(given_width >= this->smallest_x && given_height >= this->smallest_y);
1418 
1419  this->pos_x = x;
1420  this->pos_y = y;
1421  this->current_x = given_width;
1422  this->current_y = given_height;
1423 
1424  /* Figure out what are the visible buttons */
1425  memset(this->visible, 0, sizeof(this->visible));
1426  uint arrangable_count, button_count, spacer_count;
1427  const byte *arrangement = GetButtonArrangement(given_width, arrangable_count, button_count, spacer_count);
1428  for (uint i = 0; i < arrangable_count; i++) {
1429  this->visible[arrangement[i]] = true;
1430  }
1431 
1432  /* Create us ourselves a quick lookup table */
1433  NWidgetBase *widgets[WID_TN_END];
1434  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1435  if (child_wid->type == NWID_SPACER) continue;
1436  widgets[((NWidgetCore*)child_wid)->index] = child_wid;
1437  }
1438 
1439  /* Now assign the widgets to their rightful place */
1440  uint position = 0; // Place to put next child relative to origin of the container.
1441  uint spacer_space = max(0, (int)given_width - (int)(button_count * this->smallest_x)); // Remaining spacing for 'spacer' widgets
1442  uint button_space = given_width - spacer_space; // Remaining spacing for the buttons
1443  uint spacer_i = 0;
1444  uint button_i = 0;
1445 
1446  /* Index into the arrangement indices. The macro lastof cannot be used here! */
1447  const byte *cur_wid = rtl ? &arrangement[arrangable_count - 1] : arrangement;
1448  for (uint i = 0; i < arrangable_count; i++) {
1449  NWidgetBase *child_wid = widgets[*cur_wid];
1450  /* If we have to give space to the spacers, do that */
1451  if (spacer_space != 0) {
1452  NWidgetBase *possible_spacer = rtl ? child_wid->next : child_wid->prev;
1453  if (possible_spacer != nullptr && possible_spacer->type == NWID_SPACER) {
1454  uint add = spacer_space / (spacer_count - spacer_i);
1455  position += add;
1456  spacer_space -= add;
1457  spacer_i++;
1458  }
1459  }
1460 
1461  /* Buttons can be scaled, the others not. */
1462  if (this->IsButton(child_wid->type)) {
1463  child_wid->current_x = button_space / (button_count - button_i);
1464  button_space -= child_wid->current_x;
1465  button_i++;
1466  }
1467  child_wid->AssignSizePosition(sizing, x + position, y, child_wid->current_x, this->current_y, rtl);
1468  position += child_wid->current_x;
1469 
1470  if (rtl) {
1471  cur_wid--;
1472  } else {
1473  cur_wid++;
1474  }
1475  }
1476  }
1477 
1478  void Draw(const Window *w) override
1479  {
1480  /* Draw brown-red toolbar bg. */
1481  GfxFillRect(this->pos_x, this->pos_y, this->pos_x + this->current_x - 1, this->pos_y + this->current_y - 1, PC_VERY_DARK_RED);
1482  GfxFillRect(this->pos_x, this->pos_y, this->pos_x + this->current_x - 1, this->pos_y + this->current_y - 1, PC_DARK_RED, FILLRECT_CHECKER);
1483 
1484  bool rtl = _current_text_dir == TD_RTL;
1485  for (NWidgetBase *child_wid = rtl ? this->tail : this->head; child_wid != nullptr; child_wid = rtl ? child_wid->prev : child_wid->next) {
1486  if (child_wid->type == NWID_SPACER) continue;
1487  if (!this->visible[((NWidgetCore*)child_wid)->index]) continue;
1488 
1489  child_wid->Draw(w);
1490  }
1491  }
1492 
1493  NWidgetCore *GetWidgetFromPos(int x, int y) override
1494  {
1495  if (!IsInsideBS(x, this->pos_x, this->current_x) || !IsInsideBS(y, this->pos_y, this->current_y)) return nullptr;
1496 
1497  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1498  if (child_wid->type == NWID_SPACER) continue;
1499  if (!this->visible[((NWidgetCore*)child_wid)->index]) continue;
1500 
1501  NWidgetCore *nwid = child_wid->GetWidgetFromPos(x, y);
1502  if (nwid != nullptr) return nwid;
1503  }
1504  return nullptr;
1505  }
1506 
1515  virtual const byte *GetButtonArrangement(uint &width, uint &arrangable_count, uint &button_count, uint &spacer_count) const = 0;
1516 };
1517 
1520  const byte *GetButtonArrangement(uint &width, uint &arrangable_count, uint &button_count, uint &spacer_count) const override
1521  {
1522  static const uint SMALLEST_ARRANGEMENT = 14;
1523  static const uint BIGGEST_ARRANGEMENT = 20;
1524 
1525  /* The number of buttons of each row of the toolbar should match the number of items which we want to be visible.
1526  * The total number of buttons should be equal to arrangable_count * 2.
1527  * No bad things happen, but we could see strange behaviours if we have buttons < (arrangable_count * 2) like a
1528  * pause button appearing on the right of the lower toolbar and weird resizing of the widgets even if there is
1529  * enough space.
1530  */
1531  static const byte arrange14[] = {
1532  WID_TN_PAUSE,
1534  WID_TN_TRAINS,
1536  WID_TN_SHIPS,
1540  WID_TN_RAILS,
1541  WID_TN_ROADS,
1542  WID_TN_WATER,
1543  WID_TN_AIR,
1546  // lower toolbar
1548  WID_TN_SAVE,
1550  WID_TN_TOWNS,
1555  WID_TN_GRAPHS,
1559  WID_TN_HELP,
1561  };
1562  static const byte arrange15[] = {
1563  WID_TN_PAUSE,
1566  WID_TN_TRAINS,
1568  WID_TN_SHIPS,
1570  WID_TN_RAILS,
1571  WID_TN_ROADS,
1572  WID_TN_WATER,
1573  WID_TN_AIR,
1578  // lower toolbar
1579  WID_TN_PAUSE,
1582  WID_TN_SAVE,
1583  WID_TN_TOWNS,
1588  WID_TN_GRAPHS,
1592  WID_TN_HELP,
1594  };
1595  static const byte arrange16[] = {
1596  WID_TN_PAUSE,
1600  WID_TN_TRAINS,
1602  WID_TN_SHIPS,
1604  WID_TN_RAILS,
1605  WID_TN_ROADS,
1606  WID_TN_WATER,
1607  WID_TN_AIR,
1612  // lower toolbar
1613  WID_TN_PAUSE,
1615  WID_TN_SAVE,
1616  WID_TN_TOWNS,
1621  WID_TN_GRAPHS,
1625  WID_TN_HELP,
1629  };
1630  static const byte arrange17[] = {
1631  WID_TN_PAUSE,
1636  WID_TN_TRAINS,
1638  WID_TN_SHIPS,
1640  WID_TN_RAILS,
1641  WID_TN_ROADS,
1642  WID_TN_WATER,
1643  WID_TN_AIR,
1648  // lower toolbar
1649  WID_TN_PAUSE,
1651  WID_TN_SAVE,
1654  WID_TN_TOWNS,
1658  WID_TN_GRAPHS,
1662  WID_TN_HELP,
1666  };
1667  static const byte arrange18[] = {
1668  WID_TN_PAUSE,
1672  WID_TN_TOWNS,
1678  WID_TN_RAILS,
1679  WID_TN_ROADS,
1680  WID_TN_WATER,
1681  WID_TN_AIR,
1686  // lower toolbar
1687  WID_TN_PAUSE,
1689  WID_TN_SAVE,
1691  WID_TN_TOWNS,
1694  WID_TN_GRAPHS,
1695  WID_TN_TRAINS,
1697  WID_TN_SHIPS,
1701  WID_TN_HELP,
1705  };
1706  static const byte arrange19[] = {
1707  WID_TN_PAUSE,
1711  WID_TN_TOWNS,
1713  WID_TN_TRAINS,
1715  WID_TN_SHIPS,
1717  WID_TN_RAILS,
1718  WID_TN_ROADS,
1719  WID_TN_WATER,
1720  WID_TN_AIR,
1726  // lower toolbar
1727  WID_TN_PAUSE,
1729  WID_TN_SAVE,
1734  WID_TN_GRAPHS,
1737  WID_TN_RAILS,
1738  WID_TN_ROADS,
1739  WID_TN_WATER,
1740  WID_TN_AIR,
1742  WID_TN_HELP,
1746  };
1747  static const byte arrange20[] = {
1748  WID_TN_PAUSE,
1752  WID_TN_TOWNS,
1754  WID_TN_TRAINS,
1756  WID_TN_SHIPS,
1758  WID_TN_RAILS,
1759  WID_TN_ROADS,
1760  WID_TN_WATER,
1761  WID_TN_AIR,
1764  WID_TN_GOAL,
1768  // lower toolbar
1769  WID_TN_PAUSE,
1771  WID_TN_SAVE,
1776  WID_TN_GRAPHS,
1779  WID_TN_RAILS,
1780  WID_TN_ROADS,
1781  WID_TN_WATER,
1782  WID_TN_AIR,
1784  WID_TN_STORY,
1785  WID_TN_HELP,
1789  };
1790  static const byte arrange_all[] = {
1791  WID_TN_PAUSE,
1794  WID_TN_SAVE,
1796  WID_TN_TOWNS,
1801  WID_TN_STORY,
1802  WID_TN_GOAL,
1803  WID_TN_GRAPHS,
1804  WID_TN_LEAGUE,
1806  WID_TN_TRAINS,
1808  WID_TN_SHIPS,
1812  WID_TN_RAILS,
1813  WID_TN_ROADS,
1814  WID_TN_TRAMS,
1815  WID_TN_WATER,
1816  WID_TN_AIR,
1820  WID_TN_HELP
1821  };
1822 
1823  /* If at least BIGGEST_ARRANGEMENT fit, just spread all the buttons nicely */
1824  uint full_buttons = max(CeilDiv(width, this->smallest_x), SMALLEST_ARRANGEMENT);
1825  if (full_buttons > BIGGEST_ARRANGEMENT) {
1826  button_count = arrangable_count = lengthof(arrange_all);
1827  spacer_count = this->spacers;
1828  return arrange_all;
1829  }
1830 
1831  /* Introduce the split toolbar */
1832  static const byte * const arrangements[] = { arrange14, arrange15, arrange16, arrange17, arrange18, arrange19, arrange20 };
1833 
1834  button_count = arrangable_count = full_buttons;
1835  spacer_count = this->spacers;
1836  return arrangements[full_buttons - SMALLEST_ARRANGEMENT] + ((_toolbar_mode == TB_LOWER) ? full_buttons : 0);
1837  }
1838 };
1839 
1842  uint panel_widths[2];
1843 
1844  void SetupSmallestSize(Window *w, bool init_array) override
1845  {
1846  this->NWidgetToolbarContainer::SetupSmallestSize(w, init_array);
1847 
1848  /* Find the size of panel_widths */
1849  uint i = 0;
1850  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1851  if (child_wid->type == NWID_SPACER || this->IsButton(child_wid->type)) continue;
1852 
1853  assert(i < lengthof(this->panel_widths));
1854  this->panel_widths[i++] = child_wid->current_x;
1855  _toolbar_width += child_wid->current_x;
1856  }
1857  }
1858 
1859  const byte *GetButtonArrangement(uint &width, uint &arrangable_count, uint &button_count, uint &spacer_count) const override
1860  {
1861  static const byte arrange_all[] = {
1862  WID_TE_PAUSE,
1865  WID_TE_SAVE,
1866  WID_TE_SPACER,
1874  WID_TE_ROADS,
1875  WID_TE_TRAMS,
1876  WID_TE_WATER,
1877  WID_TE_TREES,
1878  WID_TE_SIGNS,
1880  WID_TE_HELP,
1881  };
1882  static const byte arrange_nopanel[] = {
1883  WID_TE_PAUSE,
1886  WID_TE_SAVE,
1894  WID_TE_ROADS,
1895  WID_TE_TRAMS,
1896  WID_TE_WATER,
1897  WID_TE_TREES,
1898  WID_TE_SIGNS,
1900  WID_TE_HELP,
1901  };
1902  static const byte arrange_switch[] = {
1908  WID_TE_ROADS,
1909  WID_TE_TRAMS,
1910  WID_TE_WATER,
1911  WID_TE_TREES,
1912  WID_TE_SIGNS,
1914  // lower toolbar
1915  WID_TE_PAUSE,
1918  WID_TE_SAVE,
1924  WID_TE_HELP,
1926  };
1927 
1928  /* If we can place all buttons *and* the panels, show them. */
1929  uint min_full_width = (lengthof(arrange_all) - lengthof(this->panel_widths)) * this->smallest_x + this->panel_widths[0] + this->panel_widths[1];
1930  if (width >= min_full_width) {
1931  width -= this->panel_widths[0] + this->panel_widths[1];
1932  arrangable_count = lengthof(arrange_all);
1933  button_count = arrangable_count - 2;
1934  spacer_count = this->spacers;
1935  return arrange_all;
1936  }
1937 
1938  /* 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 */
1939  uint min_small_width = (lengthof(arrange_switch) - lengthof(this->panel_widths)) * this->smallest_x / 2 + this->panel_widths[1];
1940  if (width > min_small_width) {
1941  width -= this->panel_widths[1];
1942  arrangable_count = lengthof(arrange_nopanel);
1943  button_count = arrangable_count - 1;
1944  spacer_count = this->spacers - 1;
1945  return arrange_nopanel;
1946  }
1947 
1948  /* Split toolbar */
1949  width -= this->panel_widths[1];
1950  arrangable_count = lengthof(arrange_switch) / 2;
1951  button_count = arrangable_count - 1;
1952  spacer_count = 0;
1953  return arrange_switch + ((_toolbar_mode == TB_LOWER) ? arrangable_count : 0);
1954  }
1955 };
1956 
1957 /* --- Toolbar handling for the 'normal' case */
1958 
1959 typedef CallBackFunction ToolbarButtonProc(Window *w);
1960 
1961 static ToolbarButtonProc * const _toolbar_button_procs[] = {
1962  ToolbarPauseClick,
1966  ToolbarMapClick,
1967  ToolbarTownClick,
1968  ToolbarSubsidiesClick,
1969  ToolbarStationsClick,
1970  ToolbarFinancesClick,
1971  ToolbarCompaniesClick,
1972  ToolbarStoryClick,
1973  ToolbarGoalClick,
1974  ToolbarGraphsClick,
1975  ToolbarLeagueClick,
1976  ToolbarIndustryClick,
1977  ToolbarTrainClick,
1978  ToolbarRoadClick,
1979  ToolbarShipClick,
1980  ToolbarAirClick,
1981  ToolbarZoomInClick,
1982  ToolbarZoomOutClick,
1983  ToolbarBuildRailClick,
1984  ToolbarBuildRoadClick,
1985  ToolbarBuildTramClick,
1986  ToolbarBuildWaterClick,
1987  ToolbarBuildAirClick,
1988  ToolbarForestClick,
1989  ToolbarMusicClick,
1990  ToolbarNewspaperClick,
1991  ToolbarHelpClick,
1992  ToolbarSwitchClick,
1993 };
1994 
1995 enum MainToolbarHotkeys {
1996  MTHK_PAUSE,
1997  MTHK_FASTFORWARD,
1998  MTHK_SETTINGS,
1999  MTHK_SAVEGAME,
2000  MTHK_LOADGAME,
2001  MTHK_SMALLMAP,
2002  MTHK_TOWNDIRECTORY,
2003  MTHK_SUBSIDIES,
2004  MTHK_STATIONS,
2005  MTHK_FINANCES,
2006  MTHK_COMPANIES,
2007  MTHK_STORY,
2008  MTHK_GOAL,
2009  MTHK_GRAPHS,
2010  MTHK_LEAGUE,
2011  MTHK_INDUSTRIES,
2012  MTHK_TRAIN_LIST,
2013  MTHK_ROADVEH_LIST,
2014  MTHK_SHIP_LIST,
2015  MTHK_AIRCRAFT_LIST,
2016  MTHK_ZOOM_IN,
2017  MTHK_ZOOM_OUT,
2018  MTHK_BUILD_RAIL,
2019  MTHK_BUILD_ROAD,
2020  MTHK_BUILD_TRAM,
2021  MTHK_BUILD_DOCKS,
2022  MTHK_BUILD_AIRPORT,
2023  MTHK_BUILD_TREES,
2024  MTHK_MUSIC,
2025  MTHK_AI_DEBUG,
2026  MTHK_SMALL_SCREENSHOT,
2027  MTHK_ZOOMEDIN_SCREENSHOT,
2028  MTHK_DEFAULTZOOM_SCREENSHOT,
2029  MTHK_GIANT_SCREENSHOT,
2030  MTHK_CHEATS,
2031  MTHK_TERRAFORM,
2032  MTHK_EXTRA_VIEWPORT,
2033  MTHK_CLIENT_LIST,
2034  MTHK_SIGN_LIST,
2035 };
2036 
2039  GUITimer timer;
2040 
2041  MainToolbarWindow(WindowDesc *desc) : Window(desc)
2042  {
2043  this->InitNested(0);
2044 
2045  _last_started_action = CBF_NONE;
2046  CLRBITS(this->flags, WF_WHITE_BORDER);
2047  this->SetWidgetDisabledState(WID_TN_PAUSE, _networking && !_network_server); // if not server, disable pause button
2048  this->SetWidgetDisabledState(WID_TN_FAST_FORWARD, _networking); // if networking, disable fast-forward button
2049  PositionMainToolbar(this);
2051 
2052  this->timer.SetInterval(MILLISECONDS_PER_TICK);
2053  }
2054 
2055  void FindWindowPlacementAndResize(int def_width, int def_height) override
2056  {
2058  }
2059 
2060  void OnPaint() override
2061  {
2062  /* If spectator, disable all construction buttons
2063  * ie : Build road, rail, ships, airports and landscaping
2064  * Since enabled state is the default, just disable when needed */
2066  /* disable company list drop downs, if there are no companies */
2068 
2069  this->SetWidgetDisabledState(WID_TN_GOAL, Goal::GetNumItems() == 0);
2070  this->SetWidgetDisabledState(WID_TN_STORY, StoryPage::GetNumItems() == 0);
2071 
2072  this->SetWidgetDisabledState(WID_TN_RAILS, !CanBuildVehicleInfrastructure(VEH_TRAIN));
2073  this->SetWidgetDisabledState(WID_TN_ROADS, !CanBuildVehicleInfrastructure(VEH_ROAD, RTT_ROAD));
2074  this->SetWidgetDisabledState(WID_TN_TRAMS, !CanBuildVehicleInfrastructure(VEH_ROAD, RTT_TRAM));
2075  this->SetWidgetDisabledState(WID_TN_AIR, !CanBuildVehicleInfrastructure(VEH_AIRCRAFT));
2076 
2077  this->DrawWidgets();
2078  }
2079 
2080  void OnClick(Point pt, int widget, int click_count) override
2081  {
2082  if (_game_mode != GM_MENU && !this->IsWidgetDisabled(widget)) _toolbar_button_procs[widget](this);
2083  }
2084 
2085  void OnDropdownSelect(int widget, int index) override
2086  {
2087  CallBackFunction cbf = _menu_clicked_procs[widget](index);
2088  if (cbf != CBF_NONE) _last_started_action = cbf;
2089  }
2090 
2091  EventState OnHotkey(int hotkey) override
2092  {
2093  switch (hotkey) {
2094  case MTHK_PAUSE: ToolbarPauseClick(this); break;
2095  case MTHK_FASTFORWARD: ToolbarFastForwardClick(this); break;
2096  case MTHK_SETTINGS: ShowGameOptions(); break;
2097  case MTHK_SAVEGAME: MenuClickSaveLoad(); break;
2098  case MTHK_LOADGAME: ShowSaveLoadDialog(FT_SAVEGAME, SLO_LOAD); break;
2099  case MTHK_SMALLMAP: ShowSmallMap(); break;
2100  case MTHK_TOWNDIRECTORY: ShowTownDirectory(); break;
2101  case MTHK_SUBSIDIES: ShowSubsidiesList(); break;
2102  case MTHK_STATIONS: ShowCompanyStations(_local_company); break;
2103  case MTHK_FINANCES: ShowCompanyFinances(_local_company); break;
2104  case MTHK_COMPANIES: ShowCompany(_local_company); break;
2105  case MTHK_STORY: ShowStoryBook(_local_company); break;
2106  case MTHK_GOAL: ShowGoalsList(_local_company); break;
2107  case MTHK_GRAPHS: ShowOperatingProfitGraph(); break;
2108  case MTHK_LEAGUE: ShowCompanyLeagueTable(); break;
2109  case MTHK_INDUSTRIES: ShowBuildIndustryWindow(); break;
2110  case MTHK_TRAIN_LIST: ShowVehicleListWindow(_local_company, VEH_TRAIN); break;
2111  case MTHK_ROADVEH_LIST: ShowVehicleListWindow(_local_company, VEH_ROAD); break;
2112  case MTHK_SHIP_LIST: ShowVehicleListWindow(_local_company, VEH_SHIP); break;
2113  case MTHK_AIRCRAFT_LIST: ShowVehicleListWindow(_local_company, VEH_AIRCRAFT); break;
2114  case MTHK_ZOOM_IN: ToolbarZoomInClick(this); break;
2115  case MTHK_ZOOM_OUT: ToolbarZoomOutClick(this); break;
2116  case MTHK_BUILD_RAIL: if (CanBuildVehicleInfrastructure(VEH_TRAIN)) ShowBuildRailToolbar(_last_built_railtype); break;
2117  case MTHK_BUILD_ROAD: ShowBuildRoadToolbar(_last_built_roadtype); break;
2118  case MTHK_BUILD_TRAM: if (CanBuildVehicleInfrastructure(VEH_ROAD, RTT_TRAM)) ShowBuildRoadToolbar(_last_built_tramtype); break;
2119  case MTHK_BUILD_DOCKS: ShowBuildDocksToolbar(); break;
2120  case MTHK_BUILD_AIRPORT: if (CanBuildVehicleInfrastructure(VEH_AIRCRAFT)) ShowBuildAirToolbar(); break;
2121  case MTHK_BUILD_TREES: ShowBuildTreesToolbar(); break;
2122  case MTHK_MUSIC: ShowMusicWindow(); break;
2123  case MTHK_AI_DEBUG: ShowAIDebugWindow(); break;
2124  case MTHK_SMALL_SCREENSHOT: MenuClickSmallScreenshot(); break;
2125  case MTHK_ZOOMEDIN_SCREENSHOT: MenuClickLargeWorldScreenshot(SC_ZOOMEDIN); break;
2126  case MTHK_DEFAULTZOOM_SCREENSHOT: MenuClickLargeWorldScreenshot(SC_DEFAULTZOOM); break;
2127  case MTHK_GIANT_SCREENSHOT: MenuClickLargeWorldScreenshot(SC_WORLD); break;
2128  case MTHK_CHEATS: if (!_networking) ShowCheatWindow(); break;
2129  case MTHK_TERRAFORM: ShowTerraformToolbar(); break;
2130  case MTHK_EXTRA_VIEWPORT: ShowExtraViewPortWindowForTileUnderCursor(); break;
2131  case MTHK_CLIENT_LIST: if (_networking) ShowClientList(); break;
2132  case MTHK_SIGN_LIST: ShowSignList(); break;
2133  default: return ES_NOT_HANDLED;
2134  }
2135  return ES_HANDLED;
2136  }
2137 
2138  void OnPlaceObject(Point pt, TileIndex tile) override
2139  {
2140  switch (_last_started_action) {
2141  case CBF_PLACE_SIGN:
2142  PlaceProc_Sign(tile);
2143  break;
2144 
2145  case CBF_PLACE_LANDINFO:
2146  ShowLandInfo(tile);
2147  break;
2148 
2149  default: NOT_REACHED();
2150  }
2151  }
2152 
2153  void OnPlaceObjectAbort() override
2154  {
2155  _last_started_action = CBF_NONE;
2156  }
2157 
2158  void OnRealtimeTick(uint delta_ms) override
2159  {
2160  if (!this->timer.Elapsed(delta_ms)) return;
2161  this->timer.SetInterval(MILLISECONDS_PER_TICK);
2162 
2163  if (this->IsWidgetLowered(WID_TN_PAUSE) != !!_pause_mode) {
2164  this->ToggleWidgetLoweredState(WID_TN_PAUSE);
2165  this->SetWidgetDirty(WID_TN_PAUSE);
2166  }
2167 
2168  if (this->IsWidgetLowered(WID_TN_FAST_FORWARD) != !!_fast_forward) {
2169  this->ToggleWidgetLoweredState(WID_TN_FAST_FORWARD);
2170  this->SetWidgetDirty(WID_TN_FAST_FORWARD);
2171  }
2172  }
2173 
2174  void OnTimeout() override
2175  {
2176  /* We do not want to automatically raise the pause, fast forward and
2177  * switchbar buttons; they have to stay down when pressed etc. */
2178  for (uint i = WID_TN_SETTINGS; i < WID_TN_SWITCH_BAR; i++) {
2179  if (this->IsWidgetLowered(i)) {
2180  this->RaiseWidget(i);
2181  this->SetWidgetDirty(i);
2182  }
2183  }
2184  }
2185 
2191  void OnInvalidateData(int data = 0, bool gui_scope = true) override
2192  {
2193  if (!gui_scope) return;
2195  }
2196 
2197  static HotkeyList hotkeys;
2198 };
2199 
2200 const uint16 _maintoolbar_pause_keys[] = {WKC_F1, WKC_PAUSE, 0};
2201 const uint16 _maintoolbar_zoomin_keys[] = {WKC_NUM_PLUS, WKC_EQUALS, WKC_SHIFT | WKC_EQUALS, WKC_SHIFT | WKC_F5, 0};
2202 const uint16 _maintoolbar_zoomout_keys[] = {WKC_NUM_MINUS, WKC_MINUS, WKC_SHIFT | WKC_MINUS, WKC_SHIFT | WKC_F6, 0};
2203 const uint16 _maintoolbar_smallmap_keys[] = {WKC_F4, 'M', 0};
2204 
2205 static Hotkey maintoolbar_hotkeys[] = {
2206  Hotkey(_maintoolbar_pause_keys, "pause", MTHK_PAUSE),
2207  Hotkey((uint16)0, "fastforward", MTHK_FASTFORWARD),
2208  Hotkey(WKC_F2, "settings", MTHK_SETTINGS),
2209  Hotkey(WKC_F3, "saveload", MTHK_SAVEGAME),
2210  Hotkey((uint16)0, "load_game", MTHK_LOADGAME),
2211  Hotkey(_maintoolbar_smallmap_keys, "smallmap", MTHK_SMALLMAP),
2212  Hotkey(WKC_F5, "town_list", MTHK_TOWNDIRECTORY),
2213  Hotkey(WKC_F6, "subsidies", MTHK_SUBSIDIES),
2214  Hotkey(WKC_F7, "station_list", MTHK_STATIONS),
2215  Hotkey(WKC_F8, "finances", MTHK_FINANCES),
2216  Hotkey(WKC_F9, "companies", MTHK_COMPANIES),
2217  Hotkey((uint16)0, "story_book", MTHK_STORY),
2218  Hotkey((uint16)0, "goal_list", MTHK_GOAL),
2219  Hotkey(WKC_F10, "graphs", MTHK_GRAPHS),
2220  Hotkey(WKC_F11, "league", MTHK_LEAGUE),
2221  Hotkey(WKC_F12, "industry_list", MTHK_INDUSTRIES),
2222  Hotkey(WKC_SHIFT | WKC_F1, "train_list", MTHK_TRAIN_LIST),
2223  Hotkey(WKC_SHIFT | WKC_F2, "roadveh_list", MTHK_ROADVEH_LIST),
2224  Hotkey(WKC_SHIFT | WKC_F3, "ship_list", MTHK_SHIP_LIST),
2225  Hotkey(WKC_SHIFT | WKC_F4, "aircraft_list", MTHK_AIRCRAFT_LIST),
2226  Hotkey(_maintoolbar_zoomin_keys, "zoomin", MTHK_ZOOM_IN),
2227  Hotkey(_maintoolbar_zoomout_keys, "zoomout", MTHK_ZOOM_OUT),
2228  Hotkey(WKC_SHIFT | WKC_F7, "build_rail", MTHK_BUILD_RAIL),
2229  Hotkey(WKC_SHIFT | WKC_F8, "build_road", MTHK_BUILD_ROAD),
2230  Hotkey((uint16)0, "build_tram", MTHK_BUILD_TRAM),
2231  Hotkey(WKC_SHIFT | WKC_F9, "build_docks", MTHK_BUILD_DOCKS),
2232  Hotkey(WKC_SHIFT | WKC_F10, "build_airport", MTHK_BUILD_AIRPORT),
2233  Hotkey(WKC_SHIFT | WKC_F11, "build_trees", MTHK_BUILD_TREES),
2234  Hotkey(WKC_SHIFT | WKC_F12, "music", MTHK_MUSIC),
2235  Hotkey((uint16)0, "ai_debug", MTHK_AI_DEBUG),
2236  Hotkey(WKC_CTRL | 'S', "small_screenshot", MTHK_SMALL_SCREENSHOT),
2237  Hotkey(WKC_CTRL | 'P', "zoomedin_screenshot", MTHK_ZOOMEDIN_SCREENSHOT),
2238  Hotkey(WKC_CTRL | 'D', "defaultzoom_screenshot", MTHK_DEFAULTZOOM_SCREENSHOT),
2239  Hotkey((uint16)0, "giant_screenshot", MTHK_GIANT_SCREENSHOT),
2240  Hotkey(WKC_CTRL | WKC_ALT | 'C', "cheats", MTHK_CHEATS),
2241  Hotkey('L', "terraform", MTHK_TERRAFORM),
2242  Hotkey('V', "extra_viewport", MTHK_EXTRA_VIEWPORT),
2243  Hotkey((uint16)0, "client_list", MTHK_CLIENT_LIST),
2244  Hotkey((uint16)0, "sign_list", MTHK_SIGN_LIST),
2245  HOTKEY_LIST_END
2246 };
2247 HotkeyList MainToolbarWindow::hotkeys("maintoolbar", maintoolbar_hotkeys);
2248 
2249 static NWidgetBase *MakeMainToolbar(int *biggest_index)
2250 {
2252  static const SpriteID toolbar_button_sprites[] = {
2253  SPR_IMG_PAUSE, // WID_TN_PAUSE
2254  SPR_IMG_FASTFORWARD, // WID_TN_FAST_FORWARD
2255  SPR_IMG_SETTINGS, // WID_TN_SETTINGS
2256  SPR_IMG_SAVE, // WID_TN_SAVE
2257  SPR_IMG_SMALLMAP, // WID_TN_SMALL_MAP
2258  SPR_IMG_TOWN, // WID_TN_TOWNS
2259  SPR_IMG_SUBSIDIES, // WID_TN_SUBSIDIES
2260  SPR_IMG_COMPANY_LIST, // WID_TN_STATIONS
2261  SPR_IMG_COMPANY_FINANCE, // WID_TN_FINANCES
2262  SPR_IMG_COMPANY_GENERAL, // WID_TN_COMPANIES
2263  SPR_IMG_STORY_BOOK, // WID_TN_STORY
2264  SPR_IMG_GOAL, // WID_TN_GOAL
2265  SPR_IMG_GRAPHS, // WID_TN_GRAPHS
2266  SPR_IMG_COMPANY_LEAGUE, // WID_TN_LEAGUE
2267  SPR_IMG_INDUSTRY, // WID_TN_INDUSTRIES
2268  SPR_IMG_TRAINLIST, // WID_TN_TRAINS
2269  SPR_IMG_TRUCKLIST, // WID_TN_ROADVEHS
2270  SPR_IMG_SHIPLIST, // WID_TN_SHIPS
2271  SPR_IMG_AIRPLANESLIST, // WID_TN_AIRCRAFT
2272  SPR_IMG_ZOOMIN, // WID_TN_ZOOMIN
2273  SPR_IMG_ZOOMOUT, // WID_TN_ZOOMOUT
2274  SPR_IMG_BUILDRAIL, // WID_TN_RAILS
2275  SPR_IMG_BUILDROAD, // WID_TN_ROADS
2276  SPR_IMG_BUILDTRAMS, // WID_TN_TRAMS
2277  SPR_IMG_BUILDWATER, // WID_TN_WATER
2278  SPR_IMG_BUILDAIR, // WID_TN_AIR
2279  SPR_IMG_LANDSCAPING, // WID_TN_LANDSCAPE
2280  SPR_IMG_MUSIC, // WID_TN_MUSIC_SOUND
2281  SPR_IMG_MESSAGES, // WID_TN_MESSAGES
2282  SPR_IMG_QUERY, // WID_TN_HELP
2283  SPR_IMG_SWITCH_TOOLBAR, // WID_TN_SWITCH_BAR
2284  };
2285 
2287  for (uint i = 0; i < WID_TN_END; i++) {
2288  switch (i) {
2289  case WID_TN_SMALL_MAP:
2290  case WID_TN_FINANCES:
2291  case WID_TN_VEHICLE_START:
2292  case WID_TN_ZOOM_IN:
2294  case WID_TN_MUSIC_SOUND:
2295  hor->Add(new NWidgetSpacer(0, 0));
2296  break;
2297  }
2298  hor->Add(new NWidgetLeaf(i == WID_TN_SAVE ? WWT_IMGBTN_2 : WWT_IMGBTN, COLOUR_GREY, i, toolbar_button_sprites[i], STR_TOOLBAR_TOOLTIP_PAUSE_GAME + i));
2299  }
2300 
2301  *biggest_index = max<int>(*biggest_index, WID_TN_SWITCH_BAR);
2302  return hor;
2303 }
2304 
2305 static const NWidgetPart _nested_toolbar_normal_widgets[] = {
2307 };
2308 
2309 static WindowDesc _toolb_normal_desc(
2310  WDP_MANUAL, nullptr, 0, 0,
2312  WDF_NO_FOCUS,
2313  _nested_toolbar_normal_widgets, lengthof(_nested_toolbar_normal_widgets),
2314  &MainToolbarWindow::hotkeys
2315 );
2316 
2317 
2318 /* --- Toolbar handling for the scenario editor */
2319 
2320 static MenuClickedProc * const _scen_toolbar_dropdown_procs[] = {
2321  nullptr, // 0
2322  nullptr, // 1
2323  MenuClickSettings, // 2
2324  MenuClickSaveLoad, // 3
2325  nullptr, // 4
2326  nullptr, // 5
2327  nullptr, // 6
2328  nullptr, // 7
2329  MenuClickMap, // 8
2330  nullptr, // 9
2331  nullptr, // 10
2332  nullptr, // 11
2333  nullptr, // 12
2334  nullptr, // 13
2335  ToolbarScenBuildRoad, // 14
2336  ToolbarScenBuildTram, // 15
2337  nullptr, // 16
2338  nullptr, // 17
2339  nullptr, // 18
2340  nullptr, // 19
2341  MenuClickMusicWindow, // 20
2342  MenuClickHelp, // 21
2343  nullptr, // 22
2344 };
2345 
2346 static ToolbarButtonProc * const _scen_toolbar_button_procs[] = {
2347  ToolbarPauseClick,
2351  ToolbarBtn_NULL,
2353  ToolbarScenDateBackward,
2354  ToolbarScenDateForward,
2355  ToolbarScenMapTownDir,
2356  ToolbarZoomInClick,
2357  ToolbarZoomOutClick,
2358  ToolbarScenGenLand,
2359  ToolbarScenGenTown,
2360  ToolbarScenGenIndustry,
2361  ToolbarScenBuildRoadClick,
2362  ToolbarScenBuildTramClick,
2363  ToolbarScenBuildDocks,
2364  ToolbarScenPlantTrees,
2365  ToolbarScenPlaceSign,
2366  ToolbarBtn_NULL,
2367  ToolbarMusicClick,
2368  ToolbarHelpClick,
2369  ToolbarSwitchClick,
2370 };
2371 
2372 enum MainToolbarEditorHotkeys {
2373  MTEHK_PAUSE,
2374  MTEHK_FASTFORWARD,
2375  MTEHK_SETTINGS,
2376  MTEHK_SAVEGAME,
2377  MTEHK_GENLAND,
2378  MTEHK_GENTOWN,
2379  MTEHK_GENINDUSTRY,
2380  MTEHK_BUILD_ROAD,
2381  MTEHK_BUILD_TRAM,
2382  MTEHK_BUILD_DOCKS,
2383  MTEHK_BUILD_TREES,
2384  MTEHK_SIGN,
2385  MTEHK_MUSIC,
2386  MTEHK_LANDINFO,
2387  MTEHK_SMALL_SCREENSHOT,
2388  MTEHK_ZOOMEDIN_SCREENSHOT,
2389  MTEHK_DEFAULTZOOM_SCREENSHOT,
2390  MTEHK_GIANT_SCREENSHOT,
2391  MTEHK_ZOOM_IN,
2392  MTEHK_ZOOM_OUT,
2393  MTEHK_TERRAFORM,
2394  MTEHK_SMALLMAP,
2395  MTEHK_EXTRA_VIEWPORT,
2396 };
2397 
2399  GUITimer timer;
2400 
2402  {
2403  this->InitNested(0);
2404 
2405  _last_started_action = CBF_NONE;
2406  CLRBITS(this->flags, WF_WHITE_BORDER);
2407  PositionMainToolbar(this);
2409 
2410  this->timer.SetInterval(MILLISECONDS_PER_TICK);
2411  }
2412 
2413  void FindWindowPlacementAndResize(int def_width, int def_height) override
2414  {
2416  }
2417 
2418  void OnPaint() override
2419  {
2420  this->SetWidgetDisabledState(WID_TE_DATE_BACKWARD, _settings_game.game_creation.starting_year <= MIN_YEAR);
2421  this->SetWidgetDisabledState(WID_TE_DATE_FORWARD, _settings_game.game_creation.starting_year >= MAX_YEAR);
2422  this->SetWidgetDisabledState(WID_TE_ROADS, (GetRoadTypes(true) & ~_roadtypes_type) == ROADTYPES_NONE);
2423  this->SetWidgetDisabledState(WID_TE_TRAMS, (GetRoadTypes(true) & _roadtypes_type) == ROADTYPES_NONE);
2424 
2425  this->DrawWidgets();
2426  }
2427 
2428  void DrawWidget(const Rect &r, int widget) const override
2429  {
2430  switch (widget) {
2431  case WID_TE_DATE:
2433  DrawString(r.left, r.right, (this->height - FONT_HEIGHT_NORMAL) / 2, STR_WHITE_DATE_LONG, TC_FROMSTRING, SA_HOR_CENTER);
2434  break;
2435 
2436  case WID_TE_SPACER: {
2437  int height = r.bottom - r.top;
2438  if (height > 2 * FONT_HEIGHT_NORMAL) {
2439  DrawString(r.left, r.right, (height + 1) / 2 - FONT_HEIGHT_NORMAL, STR_SCENEDIT_TOOLBAR_OPENTTD, TC_FROMSTRING, SA_HOR_CENTER);
2440  DrawString(r.left, r.right, (height + 1) / 2, STR_SCENEDIT_TOOLBAR_SCENARIO_EDITOR, TC_FROMSTRING, SA_HOR_CENTER);
2441  } else {
2442  DrawString(r.left, r.right, (height - FONT_HEIGHT_NORMAL) / 2, STR_SCENEDIT_TOOLBAR_SCENARIO_EDITOR, TC_FROMSTRING, SA_HOR_CENTER);
2443  }
2444  break;
2445  }
2446  }
2447  }
2448 
2449  void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
2450  {
2451  switch (widget) {
2452  case WID_TE_SPACER:
2453  size->width = max(GetStringBoundingBox(STR_SCENEDIT_TOOLBAR_OPENTTD).width, GetStringBoundingBox(STR_SCENEDIT_TOOLBAR_SCENARIO_EDITOR).width) + WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT;
2454  break;
2455 
2456  case WID_TE_DATE:
2457  SetDParam(0, ConvertYMDToDate(MAX_YEAR, 0, 1));
2458  *size = GetStringBoundingBox(STR_WHITE_DATE_LONG);
2459  size->height = max(size->height, GetSpriteSize(SPR_IMG_SAVE).height + WD_IMGBTN_TOP + WD_IMGBTN_BOTTOM);
2460  break;
2461  }
2462  }
2463 
2464  void OnClick(Point pt, int widget, int click_count) override
2465  {
2466  if (_game_mode == GM_MENU) return;
2467  CallBackFunction cbf = _scen_toolbar_button_procs[widget](this);
2468  if (cbf != CBF_NONE) _last_started_action = cbf;
2469  }
2470 
2471  void OnDropdownSelect(int widget, int index) override
2472  {
2473  CallBackFunction cbf = _scen_toolbar_dropdown_procs[widget](index);
2474  if (cbf != CBF_NONE) _last_started_action = cbf;
2475  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
2476  }
2477 
2478  EventState OnHotkey(int hotkey) override
2479  {
2480  CallBackFunction cbf = CBF_NONE;
2481  switch (hotkey) {
2482  case MTEHK_PAUSE: ToolbarPauseClick(this); break;
2483  case MTEHK_FASTFORWARD: ToolbarFastForwardClick(this); break;
2484  case MTEHK_SETTINGS: ShowGameOptions(); break;
2485  case MTEHK_SAVEGAME: MenuClickSaveLoad(); break;
2486  case MTEHK_GENLAND: ToolbarScenGenLand(this); break;
2487  case MTEHK_GENTOWN: ToolbarScenGenTown(this); break;
2488  case MTEHK_GENINDUSTRY: ToolbarScenGenIndustry(this); break;
2489  case MTEHK_BUILD_ROAD: ToolbarScenBuildRoadClick(this); break;
2490  case MTEHK_BUILD_TRAM: ToolbarScenBuildTramClick(this); break;
2491  case MTEHK_BUILD_DOCKS: ToolbarScenBuildDocks(this); break;
2492  case MTEHK_BUILD_TREES: ToolbarScenPlantTrees(this); break;
2493  case MTEHK_SIGN: cbf = ToolbarScenPlaceSign(this); break;
2494  case MTEHK_MUSIC: ShowMusicWindow(); break;
2495  case MTEHK_LANDINFO: cbf = PlaceLandBlockInfo(); break;
2496  case MTEHK_SMALL_SCREENSHOT: MenuClickSmallScreenshot(); break;
2497  case MTEHK_ZOOMEDIN_SCREENSHOT: MenuClickLargeWorldScreenshot(SC_ZOOMEDIN); break;
2498  case MTEHK_DEFAULTZOOM_SCREENSHOT: MenuClickLargeWorldScreenshot(SC_DEFAULTZOOM); break;
2499  case MTEHK_GIANT_SCREENSHOT: MenuClickLargeWorldScreenshot(SC_WORLD); break;
2500  case MTEHK_ZOOM_IN: ToolbarZoomInClick(this); break;
2501  case MTEHK_ZOOM_OUT: ToolbarZoomOutClick(this); break;
2502  case MTEHK_TERRAFORM: ShowEditorTerraformToolbar(); break;
2503  case MTEHK_SMALLMAP: ShowSmallMap(); break;
2504  case MTEHK_EXTRA_VIEWPORT: ShowExtraViewPortWindowForTileUnderCursor(); break;
2505  default: return ES_NOT_HANDLED;
2506  }
2507  if (cbf != CBF_NONE) _last_started_action = cbf;
2508  return ES_HANDLED;
2509  }
2510 
2511  void OnPlaceObject(Point pt, TileIndex tile) override
2512  {
2513  switch (_last_started_action) {
2514  case CBF_PLACE_SIGN:
2515  PlaceProc_Sign(tile);
2516  break;
2517 
2518  case CBF_PLACE_LANDINFO:
2519  ShowLandInfo(tile);
2520  break;
2521 
2522  default: NOT_REACHED();
2523  }
2524  }
2525 
2526  void OnPlaceObjectAbort() override
2527  {
2528  _last_started_action = CBF_NONE;
2529  }
2530 
2531  void OnTimeout() override
2532  {
2533  this->SetWidgetsLoweredState(false, WID_TE_DATE_BACKWARD, WID_TE_DATE_FORWARD, WIDGET_LIST_END);
2534  this->SetWidgetDirty(WID_TE_DATE_BACKWARD);
2535  this->SetWidgetDirty(WID_TE_DATE_FORWARD);
2536  }
2537 
2538  void OnRealtimeTick(uint delta_ms) override
2539  {
2540  if (!this->timer.Elapsed(delta_ms)) return;
2541  this->timer.SetInterval(MILLISECONDS_PER_TICK);
2542 
2543  if (this->IsWidgetLowered(WID_TE_PAUSE) != !!_pause_mode) {
2544  this->ToggleWidgetLoweredState(WID_TE_PAUSE);
2545  this->SetDirty();
2546  }
2547 
2548  if (this->IsWidgetLowered(WID_TE_FAST_FORWARD) != !!_fast_forward) {
2549  this->ToggleWidgetLoweredState(WID_TE_FAST_FORWARD);
2550  this->SetDirty();
2551  }
2552  }
2553 
2559  void OnInvalidateData(int data = 0, bool gui_scope = true) override
2560  {
2561  if (!gui_scope) return;
2563  }
2564 
2565  void OnQueryTextFinished(char *str) override
2566  {
2567  /* Was 'cancel' pressed? */
2568  if (str == nullptr) return;
2569 
2570  int32 value;
2571  if (!StrEmpty(str)) {
2572  value = atoi(str);
2573  } else {
2574  /* An empty string means revert to the default */
2575  value = DEF_START_YEAR;
2576  }
2577  SetStartingYear(value);
2578 
2579  this->SetDirty();
2580  }
2581 
2582  static HotkeyList hotkeys;
2583 };
2584 
2585 static Hotkey scenedit_maintoolbar_hotkeys[] = {
2586  Hotkey(_maintoolbar_pause_keys, "pause", MTEHK_PAUSE),
2587  Hotkey((uint16)0, "fastforward", MTEHK_FASTFORWARD),
2588  Hotkey(WKC_F2, "settings", MTEHK_SETTINGS),
2589  Hotkey(WKC_F3, "saveload", MTEHK_SAVEGAME),
2590  Hotkey(WKC_F4, "gen_land", MTEHK_GENLAND),
2591  Hotkey(WKC_F5, "gen_town", MTEHK_GENTOWN),
2592  Hotkey(WKC_F6, "gen_industry", MTEHK_GENINDUSTRY),
2593  Hotkey(WKC_F7, "build_road", MTEHK_BUILD_ROAD),
2594  Hotkey((uint16)0, "build_tram", MTEHK_BUILD_TRAM),
2595  Hotkey(WKC_F8, "build_docks", MTEHK_BUILD_DOCKS),
2596  Hotkey(WKC_F9, "build_trees", MTEHK_BUILD_TREES),
2597  Hotkey(WKC_F10, "build_sign", MTEHK_SIGN),
2598  Hotkey(WKC_F11, "music", MTEHK_MUSIC),
2599  Hotkey(WKC_F12, "land_info", MTEHK_LANDINFO),
2600  Hotkey(WKC_CTRL | 'S', "small_screenshot", MTEHK_SMALL_SCREENSHOT),
2601  Hotkey(WKC_CTRL | 'P', "zoomedin_screenshot", MTEHK_ZOOMEDIN_SCREENSHOT),
2602  Hotkey(WKC_CTRL | 'D', "defaultzoom_screenshot", MTEHK_DEFAULTZOOM_SCREENSHOT),
2603  Hotkey((uint16)0, "giant_screenshot", MTEHK_GIANT_SCREENSHOT),
2604  Hotkey(_maintoolbar_zoomin_keys, "zoomin", MTEHK_ZOOM_IN),
2605  Hotkey(_maintoolbar_zoomout_keys, "zoomout", MTEHK_ZOOM_OUT),
2606  Hotkey('L', "terraform", MTEHK_TERRAFORM),
2607  Hotkey('M', "smallmap", MTEHK_SMALLMAP),
2608  Hotkey('V', "extra_viewport", MTEHK_EXTRA_VIEWPORT),
2609  HOTKEY_LIST_END
2610 };
2611 HotkeyList ScenarioEditorToolbarWindow::hotkeys("scenedit_maintoolbar", scenedit_maintoolbar_hotkeys);
2612 
2613 static const NWidgetPart _nested_toolb_scen_inner_widgets[] = {
2614  NWidget(WWT_IMGBTN, COLOUR_GREY, WID_TE_PAUSE), SetDataTip(SPR_IMG_PAUSE, STR_TOOLBAR_TOOLTIP_PAUSE_GAME),
2615  NWidget(WWT_IMGBTN, COLOUR_GREY, WID_TE_FAST_FORWARD), SetDataTip(SPR_IMG_FASTFORWARD, STR_TOOLBAR_TOOLTIP_FORWARD),
2616  NWidget(WWT_IMGBTN, COLOUR_GREY, WID_TE_SETTINGS), SetDataTip(SPR_IMG_SETTINGS, STR_TOOLBAR_TOOLTIP_OPTIONS),
2617  NWidget(WWT_IMGBTN_2, COLOUR_GREY, WID_TE_SAVE), SetDataTip(SPR_IMG_SAVE, STR_SCENEDIT_TOOLBAR_TOOLTIP_SAVE_SCENARIO_LOAD_SCENARIO),
2619  NWidget(WWT_PANEL, COLOUR_GREY, WID_TE_SPACER), EndContainer(),
2621  NWidget(WWT_PANEL, COLOUR_GREY, WID_TE_DATE_PANEL),
2622  NWidget(NWID_HORIZONTAL), SetPIP(3, 2, 3),
2623  NWidget(WWT_IMGBTN, COLOUR_GREY, WID_TE_DATE_BACKWARD), SetDataTip(SPR_ARROW_DOWN, STR_SCENEDIT_TOOLBAR_TOOLTIP_MOVE_THE_STARTING_DATE_BACKWARD),
2624  NWidget(WWT_EMPTY, COLOUR_GREY, WID_TE_DATE), SetDataTip(STR_NULL, STR_SCENEDIT_TOOLBAR_TOOLTIP_SET_DATE),
2625  NWidget(WWT_IMGBTN, COLOUR_GREY, WID_TE_DATE_FORWARD), SetDataTip(SPR_ARROW_UP, STR_SCENEDIT_TOOLBAR_TOOLTIP_MOVE_THE_STARTING_DATE_FORWARD),
2626  EndContainer(),
2627  EndContainer(),
2629  NWidget(WWT_IMGBTN, COLOUR_GREY, WID_TE_SMALL_MAP), SetDataTip(SPR_IMG_SMALLMAP, STR_SCENEDIT_TOOLBAR_TOOLTIP_DISPLAY_MAP_TOWN_DIRECTORY),
2631  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_TE_ZOOM_IN), SetDataTip(SPR_IMG_ZOOMIN, STR_TOOLBAR_TOOLTIP_ZOOM_THE_VIEW_IN),
2632  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_TE_ZOOM_OUT), SetDataTip(SPR_IMG_ZOOMOUT, STR_TOOLBAR_TOOLTIP_ZOOM_THE_VIEW_OUT),
2634  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_TE_LAND_GENERATE), SetDataTip(SPR_IMG_LANDSCAPING, STR_SCENEDIT_TOOLBAR_LANDSCAPE_GENERATION),
2635  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_TE_TOWN_GENERATE), SetDataTip(SPR_IMG_TOWN, STR_SCENEDIT_TOOLBAR_TOWN_GENERATION),
2636  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_TE_INDUSTRY), SetDataTip(SPR_IMG_INDUSTRY, STR_SCENEDIT_TOOLBAR_INDUSTRY_GENERATION),
2637  NWidget(WWT_IMGBTN, COLOUR_GREY, WID_TE_ROADS), SetDataTip(SPR_IMG_BUILDROAD, STR_SCENEDIT_TOOLBAR_ROAD_CONSTRUCTION),
2638  NWidget(WWT_IMGBTN, COLOUR_GREY, WID_TE_TRAMS), SetDataTip(SPR_IMG_BUILDTRAMS, STR_SCENEDIT_TOOLBAR_TRAM_CONSTRUCTION),
2639  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_TE_WATER), SetDataTip(SPR_IMG_BUILDWATER, STR_TOOLBAR_TOOLTIP_BUILD_SHIP_DOCKS),
2640  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_TE_TREES), SetDataTip(SPR_IMG_PLANTTREES, STR_SCENEDIT_TOOLBAR_PLANT_TREES),
2641  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_TE_SIGNS), SetDataTip(SPR_IMG_SIGN, STR_SCENEDIT_TOOLBAR_PLACE_SIGN),
2643  NWidget(WWT_IMGBTN, COLOUR_GREY, WID_TE_MUSIC_SOUND), SetDataTip(SPR_IMG_MUSIC, STR_TOOLBAR_TOOLTIP_SHOW_SOUND_MUSIC_WINDOW),
2644  NWidget(WWT_IMGBTN, COLOUR_GREY, WID_TE_HELP), SetDataTip(SPR_IMG_QUERY, STR_TOOLBAR_TOOLTIP_LAND_BLOCK_INFORMATION),
2645  NWidget(WWT_IMGBTN, COLOUR_GREY, WID_TE_SWITCH_BAR), SetDataTip(SPR_IMG_SWITCH_TOOLBAR, STR_TOOLBAR_TOOLTIP_SWITCH_TOOLBAR),
2646 };
2647 
2648 static NWidgetBase *MakeScenarioToolbar(int *biggest_index)
2649 {
2650  return MakeNWidgets(_nested_toolb_scen_inner_widgets, lengthof(_nested_toolb_scen_inner_widgets), biggest_index, new NWidgetScenarioToolbarContainer());
2651 }
2652 
2653 static const NWidgetPart _nested_toolb_scen_widgets[] = {
2654  NWidgetFunction(MakeScenarioToolbar),
2655 };
2656 
2657 static WindowDesc _toolb_scen_desc(
2658  WDP_MANUAL, nullptr, 0, 0,
2660  WDF_NO_FOCUS,
2661  _nested_toolb_scen_widgets, lengthof(_nested_toolb_scen_widgets),
2662  &ScenarioEditorToolbarWindow::hotkeys
2663 );
2664 
2667 {
2668  /* Clean old GUI values; railtype is (re)set by rail_gui.cpp */
2669  _last_built_roadtype = ROADTYPE_ROAD;
2670  _last_built_tramtype = ROADTYPE_TRAM;
2671 
2672  if (_game_mode == GM_EDITOR) {
2673  new ScenarioEditorToolbarWindow(&_toolb_scen_desc);
2674  } else {
2675  new MainToolbarWindow(&_toolb_normal_desc);
2676  }
2677 }
EventState
State of handling an event.
Definition: window_type.h:711
World screenshot.
Definition: screenshot.h:23
bool DoZoomInOutWindow(ZoomStateChange how, Window *w)
Zooms a viewport in a window in or out.
Definition: main_gui.cpp:136
Functions related to OTTD&#39;s strings.
Window * ShowBuildRailToolbar(RailType railtype)
Open the build rail toolbar window for a specific rail type.
Definition: rail_gui.cpp:868
const byte * GetButtonArrangement(uint &width, uint &arrangable_count, uint &button_count, uint &spacer_count) const override
Get the arrangement of the buttons for the toolbar.
Owner
Enum for all companies/owners.
Definition: company_type.h:18
Empty widget, place holder to reserve space in widget array.
Definition: widget_type.h:46
Functions/types related to NewGRF debugging.
void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl) override
Assign size and position to the widget.
SizingType
Different forms of sizing nested widgets, using NWidgetBase::AssignSizePosition() ...
Definition: widget_type.h:109
Full blown container to make it behave exactly as we want :)
Normal push-button (no toggle button) with image caption.
Definition: widget_type.h:103
static void ScreenshotConfirmCallback(Window *w, bool confirmed)
Callback on the confirmation window for huge screenshots.
Window * ShowBuildRoadScenToolbar(RoadType roadtype)
Show the road building toolbar in the scenario editor.
Definition: road_gui.cpp:954
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:79
used in multiplayer to create a new companies etc.
Definition: command_type.h:278
bool _networking
are we in networking mode?
Definition: network.cpp:52
static CallBackFunction MenuClickHelp(int index)
Choose the proper callback function for the main toolbar&#39;s help menu.
static CallBackFunction MenuClickShowAir(int index)
Handle click on the entry in the Aircraft menu.
EventState OnHotkey(int hotkey) override
A hotkey has been pressed.
void NetworkSendCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback, const char *text, CompanyID company)
Prepare a DoCommand to be send over the network.
Horizontally center the text.
Definition: gfx_func.h:95
void GfxFillRect(int left, int top, int right, int bottom, int colour, FillRectMode mode)
Applies a certain FillRectMode-operation to a rectangle [left, right] x [top, bottom] on the screen...
Definition: gfx.cpp:110
Sign building.
GRFConfig * _grfconfig
First item in list of current GRF set up.
static NWidgetPart NWidgetFunction(NWidgetFunctionType *func_ptr)
Obtain a nested widget (sub)tree from an external source.
Definition: widget_type.h:1144
void SetWidgetLoweredState(byte widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
Definition: window_gui.h:453
RoadTypes _roadtypes_type
Bitmap of road/tram types.
Definition: road_cmd.cpp:57
Subsidy menu.
All data for a single hotkey.
Definition: hotkeys.h:22
High level window description.
Definition: window_gui.h:166
(Toggle) Button with diff image when clicked
Definition: widget_type.h:51
signs
Definition: transparency.h:23
void ShowSpriteAlignerWindow()
Show the window for aligning sprites.
byte _display_opt
What do we want to draw/do?
EconomySettings economy
settings to change the economy
WindowFlags flags
Window flags.
Definition: window_gui.h:310
void OnDropdownSelect(int widget, int index) override
A dropdown option associated to this window has been selected.
NWidgetCore * GetWidgetFromPos(int x, int y) override
Retrieve a widget by its position.
Definition: widget.cpp:903
Train vehicle type.
Definition: vehicle_type.h:24
Help menu.
Zoom out (get helicopter view).
Definition: viewport_type.h:82
int height
Screen height of the viewport.
Definition: viewport_type.h:26
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
Update size and resize step of a widget in the window.
void OnPlaceObjectAbort() override
The user cancelled a tile highlight mode that has been set.
Display waypoint names.
Definition: openttd.h:46
static CallBackFunction MenuClickShowTrains(int index)
Handle click on the entry in the Train menu.
Baseclass for container widgets.
Definition: widget_type.h:366
void HandleZoomMessage(Window *w, const ViewPort *vp, byte widget_zoom_in, byte widget_zoom_out)
Update the status of the zoom-buttons according to the zoom-level of the viewport.
Definition: viewport.cpp:476
Hotkey related functions.
Functions related to dates.
GUIs related to networking.
Tree building toolbar.
static T ToggleBit(T &x, const uint8 y)
Toggles a bit in a variable.
Road vehicle menu.
Basic road type.
Definition: road_type.h:24
Window for configuring the AIs
static const int CTMN_SPECTATOR
Show a company window as spectator.
uint spacers
Number of spacer widgets in this toolbar.
Window * ShowTerraformToolbar(Window *link)
Show the toolbar for terraforming in the game.
Horizontal container.
Definition: widget_type.h:73
void ShowSmallMap()
Show the smallmap window.
Functions/types related to the road GUIs.
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
Definition: window.cpp:1130
The passed event is not handled.
Definition: window_type.h:713
Display station names.
Definition: openttd.h:42
bool Elapsed(uint delta)
Test if a timer has elapsed.
Definition: guitimer_func.h:55
int PositionMainToolbar(Window *w)
(Re)position main toolbar window at the screen.
Definition: window.cpp:3502
void ShowQueryString(StringID str, StringID caption, uint maxsize, Window *parent, CharSetFilter afilter, QueryStringFlags flags)
Show a query popup window with a textbox in it.
Definition: misc_gui.cpp:1119
Ship vehicle type.
Definition: vehicle_type.h:26
WidgetType type
Type of the widget / nested widget.
Definition: widget_type.h:161
Settings menu.
Aircraft menu.
Types for recording game performance data.
VehicleType
Available vehicle types.
Definition: vehicle_type.h:21
Small map menu.
Road specific functions.
Window * ShowSignList()
Open the sign list window.
Definition: signs_gui.cpp:404
Sign list; Window numbers:
Definition: window_type.h:271
Screenshot of viewport.
Definition: screenshot.h:19
Window * ShowBuildRoadToolbar(RoadType roadtype)
Open the build road toolbar window.
Definition: road_gui.cpp:867
Functions related to vehicles.
void DrawCompanyIcon(CompanyID c, int x, int y)
Draw the icon of a company.
= Equals
Definition: gfx_type.h:97
void ShowGoalsList(CompanyID company)
Open a goal list window.
Definition: goal_gui.cpp:345
Window * ShowBuildDocksToolbar()
Open the build water toolbar window.
Definition: dock_gui.cpp:347
Vehicle data structure.
Definition: vehicle_base.h:210
TownFounding found_town
town founding.
static CallBackFunction MenuClickStory(int index)
Handle click on the entry in the Story menu.
Display town names.
Definition: openttd.h:41
void NetworkClientRequestMove(CompanyID company_id, const char *pass)
Notify the server of this client wanting to be moved to another company.
void NetworkServerDoMove(ClientID client_id, CompanyID company_id)
Handle the tid-bits of moving a client from one company to another.
Display signs, station names and waypoint names of opponent companies. Buoys and oilrig-stations are ...
Definition: openttd.h:47
EventState OnHotkey(int hotkey) override
A hotkey has been pressed.
Also draw details of track and roads.
Definition: openttd.h:45
void ShowAIConfigWindow()
Open the AI config window.
Definition: ai_gui.cpp:962
Zoom in (get more detailed view).
Definition: viewport_type.h:81
static CallBackFunction MenuClickSettings(int index)
Handle click on one of the entries in the Options button menu.
void ReInit(int rx=0, int ry=0)
Re-initialize a window, and optionally change its size.
Definition: window.cpp:995
bool NetworkCompanyIsPassworded(CompanyID company_id)
Check if the company we want to join requires a password.
Definition: network.cpp:213
Stuff related to the text buffer GUI.
Functions to make screenshots.
bool NetworkMaxSpectatorsReached()
Check if max_spectatos has been reached on the server (local check only).
#define CLRBITS(x, y)
Clears several bits in a variable.
void DeleteAllMessages()
Delete all messages and their corresponding window (if any).
Definition: window.cpp:3413
Spacer widget.
Definition: widget_type.h:527
DropDownList GetRailTypeDropDownList(bool for_replacement, bool all_option)
Create a drop down list for all the rail types of the local company.
Definition: rail_gui.cpp:1994
int32 Year
Type for the year, note: 0 based, i.e. starts at the year 0.
Definition: date_type.h:18
Functions related to signs.
RoadType
The different roadtypes we support.
Definition: road_type.h:22
const byte * GetButtonArrangement(uint &width, uint &arrangable_count, uint &button_count, uint &spacer_count) const override
Get the arrangement of the buttons for the toolbar.
static T max(const T a, const T b)
Returns the maximum of two values.
Definition: math_func.hpp:24
Zoom in the main viewport.
NWidgetCore * GetWidgetFromPos(int x, int y) override
Retrieve a widget by its position.
Fully zoomed in screenshot of the visible area.
Definition: screenshot.h:21
Town menu.
Common string list item.
Definition: dropdown_type.h:39
void FindWindowPlacementAndResize(int def_width, int def_height) override
Resize window towards the default size.
NWidgetContainer * MakeNWidgets(const NWidgetPart *parts, int count, int *biggest_index, NWidgetContainer *container)
Construct a nested widget tree from an array of parts.
Definition: widget.cpp:2790
Functions related to the vehicle&#39;s GUIs.
CallBackFunction
Callback functions.
Definition: toolbar_gui.cpp:78
File is being saved.
Definition: fileio_type.h:50
void OnDropdownSelect(int widget, int index) override
A dropdown option associated to this window has been selected.
Small map menu.
Forbidden.
Definition: town_type.h:94
void Draw(const Window *w) override
Draw the widgets of the tree.
Functions/types etc.
Functions, definitions and such used only by the GUI.
Industry building window.
Messages menu.
Graph GUI functions.
void ToggleBoundingBoxes()
Toggle drawing of sprites&#39; bounding boxes.
bool _left_button_clicked
Is left mouse button clicked?
Definition: gfx.cpp:39
static bool IsInsideBS(const T x, const size_t base, const size_t size)
Checks if a value is between a window started at some base point.
Definition: math_func.hpp:248
Display signs.
Definition: openttd.h:43
Industry menu.
static const Year DEF_START_YEAR
The default starting year.
Definition: date_type.h:86
Leaf widget.
Definition: widget_type.h:768
void AllocateToolbar()
Allocate the toolbar.
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:908
void ShowLandInfo(TileIndex tile)
Show land information window.
Definition: misc_gui.cpp:384
Functions related to (drawing on) viewports.
void SetupScreenshotViewport(ScreenshotType t, ViewPort *vp)
Configure a ViewPort for rendering (a part of) the map into a screenshot.
Definition: screenshot.cpp:710
Declaration of linkgraph overlay GUI.
void ShiftDates(int interval)
Shift all dates (join dates and edge annotations) of link graphs and link graph jobs by the number of...
Data structure for an opened window.
Definition: window_gui.h:276
Fast forward the game.
Container for the scenario editor&#39;s toolbar.
Only available when toolbar has been split to switch between different subsets.
NWidgetBase * next
Pointer to next widget in container. Managed by parent container widget.
Definition: widget_type.h:178
old or new savegame
Definition: fileio_type.h:18
old or new scenario
Definition: fileio_type.h:19
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:3334
Fast forward the game.
static CallBackFunction ToolbarOptionsClick(Window *w)
Handle click on Options button in toolbar.
Bottom offset of image in the button.
Definition: window_gui.h:41
town buildings
Definition: transparency.h:25
Main window; Window numbers:
Definition: window_type.h:44
void SetDate(Date date, DateFract fract)
Set the date.
Definition: date.cpp:35
enable the &#39;Default&#39; button ("\0" is returned)
Definition: textbuf_gui.h:21
void Add(NWidgetBase *wid)
Append widget wid to container.
Definition: widget.cpp:942
SaveLoadNormalMenuEntries
SaveLoad entries in normal game mode.
Only numeric ones.
Definition: string_type.h:28
void FindWindowPlacementAndResize(int def_width, int def_height) override
Resize window towards the default size.
Music/sound configuration menu.
void ShowCompanyStations(CompanyID company)
Opens window with list of company&#39;s stations.
Invisible widget that takes some space.
Definition: widget_type.h:77
static NWidgetBase * MakeMainToolbar(int *biggest_index)
GUI Timers.
void OnPlaceObjectAbort() override
The user cancelled a tile highlight mode that has been set.
void ShowCompany(CompanyID company)
Show the window with the overview of the company.
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
A normal unpaused game.
Definition: openttd.h:56
The client is spectating.
Definition: company_type.h:35
Only available when toolbar has been split to switch between different subsets.
List item with icon and string.
Definition: dropdown_type.h:81
SoundSettings sound
sound effect settings
Train menu.
void ShowQuery(StringID caption, StringID message, Window *parent, QueryCallbackProc *callback)
Show a modal confirmation window with standard &#39;yes&#39; and &#39;no&#39; buttons The window is aligned to the ce...
Definition: misc_gui.cpp:1260
GUI functions related to the news.
static CallBackFunction _last_started_action
Last started user action.
Definition: toolbar_gui.cpp:84
static LinkGraphSchedule instance
Static instance of LinkGraphSchedule.
void ShowMessageHistory()
Display window with news messages history.
Definition: news_gui.cpp:1242
static CallBackFunction MenuClickLeague(int index)
Handle click on the entry in the CompanyLeague menu.
Tram building menu.
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
Definition: gfx_func.h:176
static NWidgetPart SetDataTip(uint32 data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1012
static CallBackFunction MenuClickStations(int index)
Handle click on the entry in the Stations menu.
ClientID _network_own_client_id
Our client identifier.
Definition: network.cpp:59
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:78
bool masked
Masked and unselectable item.
Definition: dropdown_type.h:25
Definition of base types and functions in a cross-platform compatible way.
Helper for the offset of the vehicle menus.
void OnPlaceObject(Point pt, TileIndex tile) override
The user clicked some place on the map when a tile highlight mode has been set.
OptionMenuEntries
Game Option button menu entries.
A number of safeguards to prevent using unsafe methods.
Trams.
Definition: road_type.h:25
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition: gfx_type.h:245
List of hotkeys for a window.
Definition: hotkeys.h:40
static CallBackFunction ToolbarScenBuildRoad(int index)
Handle click on the entry in the Build Road menu.
rectangle (stations, depots, ...)
Simple depressed panel.
Definition: widget_type.h:48
void ShowFramerateWindow()
Open the general framerate window.
static uint CeilDiv(uint a, uint b)
Computes ceil(a / b) for non-negative a and b.
Definition: math_func.hpp:314
Company menu.
static CallBackFunction MenuClickBuildRoad(int index)
Handle click on the entry in the Build Road menu.
static const uint MILLISECONDS_PER_TICK
The number of milliseconds per game tick.
Definition: gfx_type.h:305
Drop down list entry for showing a checked/unchecked toggle item.
Definition: toolbar_gui.cpp:90
Window timeout counter.
Definition: window_gui.h:232
static CallBackFunction MenuClickForest(int index)
Handle click on the entry in the landscaping menu.
GUI functions related to transparency.
GUI Functions related to companies.
Window * ShowEditorTerraformToolbar()
Show the toolbar for terraforming in the scenario editor.
GUI stuff related to terraforming.
void ShowLastNewsMessage()
Show previous news item.
Definition: news_gui.cpp:1026
Road building menu.
static void PopupMainCompanyToolbMenu(Window *w, int widget, int grey=0)
Pop up a generic company list menu.
GUI related functions in the console.
void ShowCheatWindow()
Open cheat window.
Definition: cheat_gui.cpp:416
static NWidgetPart NWidget(WidgetType tp, Colours col, int16 idx=-1)
Widget part function for starting a new &#39;real&#39; widget.
Definition: widget_type.h:1112
A game normally paused.
Definition: openttd.h:57
Baseclass for nested widgets.
Definition: widget_type.h:124
Graph menu.
int DrawString(int left, int right, int top, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Definition: gfx.cpp:498
Functions related to cheating.
Basic functions/variables used all over the place.
static CallBackFunction MenuClickGraphs(int index)
Handle click on the entry in the Graphs menu.
Land generation.
bool DoCommandP(const CommandContainer *container, bool my_cmd)
Shortcut for the long DoCommandP when having a container with the data.
Definition: command.cpp:532
Rail building menu.
static CallBackFunction MenuClickSaveLoad(int index=0)
Handle click on one of the entries in the SaveLoad menu.
static void ToggleTransparency(TransparencyOption to)
Toggle the transparency option bit.
Definition: transparency.h:69
#define lengthof(x)
Return the length of an fixed size array.
Definition: depend.cpp:40
static CallBackFunction MenuClickBuildWater(int index)
Handle click on the entry in the Build Waterways menu.
File is being loaded.
Definition: fileio_type.h:49
Helper for the offset of the building tools.
virtual void Draw(const Window *w)=0
Draw the widgets of the tree.
Save menu.
NWidgetBase * prev
Pointer to previous widget in container. Managed by parent container widget.
Definition: widget_type.h:179
Window * ShowBuildAirToolbar()
Open the build airport toolbar window.
PauseMode _pause_mode
The current pause mode.
Definition: gfx.cpp:47
Airport building toolbar.
static CallBackFunction MenuClickTown(int index)
Handle click on one of the entries in the Town menu.
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Functions related to sound.
Finance menu.
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
static const int CTMN_SPECTATE
Become spectator.
void SetStartingYear(Year year)
Set the starting year for a scenario.
static CallBackFunction MenuClickSubsidies(int index)
Handle click on the entry in the Subsidies menu.
void ToggleDirtyBlocks()
Toggle drawing of the dirty blocks.
Water building toolbar.
static CallBackFunction MenuClickShowRoad(int index)
Handle click on the entry in the Road Vehicles menu.
static void PopupMainToolbMenu(Window *w, int widget, DropDownList &&list, int def)
Pop up a generic text only menu.
Window * ShowAIDebugWindow(CompanyID show_company)
Open the AI debug window and select the given company.
Definition: ai_gui.cpp:1525
The date of the scenario.
static const int WIDGET_LIST_END
indicate the end of widgets&#39; list for vararg functions
Definition: widget_type.h:20
bool CanBuildVehicleInfrastructure(VehicleType type, byte subtype)
Check whether we can build infrastructure for the given vehicle type.
Definition: vehicle.cpp:1754
static T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Definition: math_func.hpp:137
bool IsButton(WidgetType type) const
Check whether the given widget type is a button for us.
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition: window.cpp:984
Pause the game.
void ShowExtraViewPortWindow(TileIndex tile=INVALID_TILE)
Show a new Extra Viewport window.
bool MakeScreenshot(ScreenshotType t, const char *name)
Make an actual screenshot.
Definition: screenshot.cpp:809
void OnPlaceObject(Point pt, TileIndex tile) override
The user clicked some place on the map when a tile highlight mode has been set.
bool newgrf_developer_tools
activate NewGRF developer tools and allow modifying NewGRFs in an existing game
void ShowHighscoreTable(int difficulty=SP_CUSTOM, int8 rank=-1)
Show the highscore table for a given difficulty.
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:700
static const uint8 PC_VERY_DARK_RED
Almost-black red palette colour.
Definition: gfx_func.h:208
void OnRealtimeTick(uint delta_ms) override
Called periodically.
static CallBackFunction ToolbarSaveClick(Window *w)
Handle click on Save button in toolbar in normal game mode.
Road building menu.
Draw only every second pixel, used for greying-out.
Definition: gfx_type.h:283
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:38
Zoom out the main viewport.
Save menu.
static const uint8 PC_DARK_RED
Dark red palette colour.
Definition: gfx_func.h:209
Smallmap GUI functions.
static CallBackFunction MenuClickCompany(int index)
Handle click on the entry in the Company menu.
Functions related to companies.
WidgetType
Window widget types, nested widget types, and nested widget part types.
Definition: widget_type.h:44
An invalid company.
Definition: company_type.h:30
Base class for engines.
void ShowNewGRFSettings(bool editable, bool show_params, bool exec_changes, GRFConfig **config)
Setup the NewGRF gui.
virtual void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl)=0
Assign size and position to the widget.
static T ClrBit(T &x, const uint8 y)
Clears a bit in a variable.
RailType
Enumeration for all possible railtypes.
Definition: rail_type.h:27
Declaration of functions and types defined in highscore.h and highscore_gui.h.
Zoom in the main viewport.
GUISettings gui
settings related to the GUI
static Pool::IterateWrapper< Titem > Iterate(size_t from=0)
Returns an iterable ensemble of all valid Titem.
Definition: pool_type.hpp:340
Story menu.
Base class for all vehicles.
Data structure for viewport, display of a part of the world.
Definition: viewport_type.h:22
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition: gfx_type.h:17
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
Definition: string_func.h:57
static CallBackFunction MenuClickFinances(int index)
Handle click on the entry in the finances overview menu.
Declarations for savegames operations.
Zoomed to default zoom level screenshot of the visible area.
Definition: screenshot.h:22
void OnPaint() override
The window must be repainted.
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:78
void ShowSaveLoadDialog(AbstractFileType abstract_filetype, SaveLoadOperation fop)
Launch save/load dialog in the given mode.
Definition: fios_gui.cpp:888
uint _toolbar_width
Width of the toolbar, shared by statusbar.
Definition: toolbar_gui.cpp:62
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
static size_t GetNumItems()
Returns number of valid items in the pool.
Definition: pool_type.hpp:321
Water building toolbar.
First company, same as owner.
Definition: company_type.h:22
void SetupSmallestSize(Window *w, bool init_array) override
Compute smallest size needed by the widget.
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition: strings.cpp:48
int result
Result code to return to window on selection.
Definition: dropdown_type.h:24
static ScreenshotType _confirmed_screenshot_type
Screenshot type the current query is about to confirm.
Definition: toolbar_gui.cpp:68
This window won&#39;t get focus/make any other window lose focus when click.
Definition: window_gui.h:210
Station menu.
static CallBackFunction MenuClickBuildTram(int index)
Handle click on the entry in the Build Tram menu.
void ShowIndustryCargoesWindow()
Open the industry and cargoes window with an industry.
Goal menu.
Top offset of image in the button.
Definition: window_gui.h:40
Pause the game.
void ShowLinkGraphLegend()
Open a link graph legend window.
static NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME, WWT_INSET, or WWT_PANEL).
Definition: widget_type.h:997
Do not add shading to this text colour.
Definition: gfx_type.h:269
Container for the &#39;normal&#39; main toolbar.
void OnPaint() override
The window must be repainted.
Main toolbar.
uint current_x
Current horizontal size (after resizing).
Definition: widget_type.h:172
Goal base class.
Maximum number of companies.
Definition: company_type.h:23
Drop down list entry for showing a company entry, with companies &#39;blob&#39;.
Company league menu.
static CallBackFunction ToolbarScenSaveOrLoad(Window *w)
Handle click on SaveLoad button in toolbar in the scenario editor.
void OnQueryTextFinished(char *str) override
The query window opened from this window has closed.
Types related to the toolbar widgets.
static CallBackFunction MenuClickBuildRail(int index)
Handle click on the entry in the Build Rail menu.
bool confirm
Play sound effect on successful constructions or other actions.
Music/sound configuration menu.
static CallBackFunction MenuClickMap(int index)
Handle click on one of the entries in the Map menu.
Base functions for all Games.
Increase the date of the scenario.
Functions related to commands.
bool NetworkMaxCompaniesReached()
Check if max_companies has been reached on the server (local check only).
static CallBackFunction ToolbarScenBuildTram(int index)
Handle click on the entry in the Build Tram menu.
Network functions used by other parts of OpenTTD.
Helper for knowing the amount of widgets.
void SetupSmallestSize(Window *w, bool init_array) override
Compute smallest size needed by the widget.
bool _network_server
network-server is active
Definition: network.cpp:53
void ShowStoryBook(CompanyID company, uint16 page_id=INVALID_STORY_PAGE)
Raise or create the story book window for company, at page page_id.
Definition: story_gui.cpp:750
Main toolbar (the long bar at the top); Window numbers:
Definition: window_type.h:51
Coordinates of a point in 2D.
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition: gfx.cpp:770
Spacer with "scenario editor" text.
static CallBackFunction MenuClickGoal(int index)
Handle click on the entry in the Goal menu.
Perform palette animation.
Definition: openttd.h:44
void ShowCompanyFinances(CompanyID company)
Open the finances window of a company.
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Definition: pool_type.hpp:280
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...
Definition: viewport.cpp:3305
heightmap file
Definition: fileio_type.h:20
bool UserIsAllowedToChangeNewGRFs() const
Returns true when the user has sufficient privileges to edit newgrfs on a running game...
static const Year MIN_YEAR
The absolute minimum & maximum years in OTTD.
Definition: date_type.h:83
StoryPage base class.
Container for the date widgets.
int32 Date
The type to store our dates in.
Definition: date_type.h:14
Aircraft vehicle type.
Definition: vehicle_type.h:27
Town building window.
void HandleButtonClick(byte widget)
Do all things to make a button look clicked and mark it to be unclicked in a few ticks.
Definition: window.cpp:635
static const int CTMN_NEW_COMPANY
Create a new company.
virtual void FindWindowPlacementAndResize(int def_width, int def_height)
Resize window towards the default size.
Definition: window.cpp:1522
static const int CTMN_CLIENT_LIST
Enum for the Company Toolbar&#39;s network related buttons.
Reduce the date of the scenario.
void ShowGameSettings()
Open advanced settings window.
Offset at right to draw the frame rectangular area.
Definition: window_gui.h:61
Zoom out the main viewport.
Tram building menu.
ToolbarMode
Toobar modes.
Definition: toolbar_gui.cpp:71
SaveLoadEditorMenuEntries
SaveLoad entries in scenario editor mode.
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
static CallBackFunction ToolbarFastForwardClick(Window *w)
Toggle fast forward mode.
Create a new company.
Definition: company_type.h:65
Servers always have this ID.
Definition: network_type.h:41
void ShowExtraViewPortWindowForTileUnderCursor()
Show a new Extra Viewport window.
GameCreationSettings game_creation
settings used during the creation of a game (map)
void IConsoleSwitch()
Toggle in-game console between opened and closed.
void ResetObjectToPlace()
Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows)...
Definition: viewport.cpp:3353
void OnTimeout() override
Called when this window&#39;s timeout has been reached.
Specification of a rectangle with absolute coordinates of all edges.
void ShowGameOptions()
Open the game options window.
The passed event is handled.
Definition: window_type.h:712
Text is written right-to-left by default.
Definition: strings_type.h:24
Date ConvertYMDToDate(Year year, Month month, Day day)
Converts a tuple of Year, Month and Day to a Date.
Definition: date.cpp:147
Functions related to tile highlights.
static CallBackFunction MenuClickNewspaper(int index)
Handle click on the entry in the Newspaper menu.
Window functions not directly related to making/drawing windows.
static CallBackFunction MenuClickMusicWindow(int index)
Handle click on the entry in the Music menu.
static CallBackFunction ToolbarScenDatePanel(Window *w)
Called when clicking at the date panel of the scenario editor toolbar.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
(Toggle) Button with image
Definition: widget_type.h:50
Manually align the window (so no automatic location finding)
Definition: window_gui.h:153
Help menu.
Ship menu.
GUI functions that shouldn&#39;t be here.
Window * ShowBuildDocksScenToolbar()
Open the build water toolbar window for the scenario editor.
Definition: dock_gui.cpp:388
void PlaceProc_Sign(TileIndex tile)
PlaceProc function, called when someone pressed the button if the sign-tool is selected.
Definition: signs_cmd.cpp:133
uint8 timeout_timer
Timer value of the WF_TIMEOUT for flags.
Definition: window_gui.h:314
RoadTypes GetRoadTypes(bool introduces)
Get list of road types, regardless of company availability.
Definition: road.cpp:216
Date _date
Current date in days (day counter)
Definition: date.cpp:26
Window white border counter bit mask.
Definition: window_gui.h:240
Hack, used to update the button status.
Definition: viewport_type.h:83
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:44
Base list item class from which others are derived.
Definition: dropdown_type.h:22
Dimensions (a width and height) of a rectangle in 2D.
bool click_beep
Beep on a random selection of buttons.
Offset at left to draw the frame rectangular area.
Definition: window_gui.h:60
static const Year MAX_YEAR
MAX_YEAR, nicely rounded value of the number of years that can be encoded in a single 32 bits date...
Definition: date_type.h:92
void CheckBlitter()
Check whether we still use the right blitter, or use another (better) one.
Definition: gfxinit.cpp:328
void ShowTransparencyToolbar()
Show the transparency toolbar.
Year starting_year
starting date
static CallBackFunction MenuClickBuildAir(int index)
Handle click on the entry in the Build Air menu.
void OnRealtimeTick(uint delta_ms) override
Called periodically.
static bool IsTransparencySet(TransparencyOption to)
Check if the transparency option bit is set and if we aren&#39;t in the game menu (there&#39;s never transpar...
Definition: transparency.h:48
Road vehicle type.
Definition: vehicle_type.h:25
static CallBackFunction MenuClickIndustry(int index)
Handle click on the entry in the Industry menu.
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
Draw a sprite, not in a viewport.
Definition: gfx.cpp:835
static NWidgetPart SetPIP(uint8 pre, uint8 inter, uint8 post)
Widget part function for setting a pre/inter/post spaces.
Definition: widget_type.h:1074
static void MenuClickLargeWorldScreenshot(ScreenshotType t)
Make a screenshot of the world.
static CallBackFunction MenuClickShowShips(int index)
Handle click on the entry in the Ships menu.
No roadtypes.
Definition: road_type.h:37
Settings menu.
Landscaping toolbar.
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
Definition: gfx.cpp:1462
void OnTimeout() override
Called when this window&#39;s timeout has been reached.
ScreenshotType
Type of requested screenshot.
Definition: screenshot.h:18
Stuff related to the (main) toolbar.
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings_func.h:199
Base class for a &#39;real&#39; widget.
Definition: widget_type.h:282
int width
Screen width of the viewport.
Definition: viewport_type.h:25
pause the game
Definition: command_type.h:254