OpenTTD Source  1.10.0-RC1
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 #include "screenshot_gui.h"
52 
53 #include "widgets/toolbar_widget.h"
54 
55 #include "network/network.h"
56 #include "network/network_gui.h"
57 #include "network/network_func.h"
58 
59 #include "safeguards.h"
60 
61 
63 uint _toolbar_width = 0;
64 
65 RailType _last_built_railtype;
66 RoadType _last_built_roadtype;
67 RoadType _last_built_tramtype;
68 
70 
73  TB_NORMAL,
74  TB_UPPER,
75  TB_LOWER
76 };
77 
80  CBF_NONE,
81  CBF_PLACE_SIGN,
82  CBF_PLACE_LANDINFO,
83 };
84 
86 
87 
92  uint checkmark_width;
93 public:
94  bool checked;
95 
96  DropDownListCheckedItem(StringID string, int result, bool masked, bool checked) : DropDownListStringItem(string, result, masked), checked(checked)
97  {
98  this->checkmark_width = GetStringBoundingBox(STR_JUST_CHECKMARK).width + 3;
99  }
100 
101  uint Width() const
102  {
103  return DropDownListStringItem::Width() + this->checkmark_width;
104  }
105 
106  void Draw(int left, int right, int top, int bottom, bool sel, Colours bg_colour) const
107  {
108  bool rtl = _current_text_dir == TD_RTL;
109  if (this->checked) {
110  DrawString(left + WD_FRAMERECT_LEFT, right - WD_FRAMERECT_RIGHT, top, STR_JUST_CHECKMARK, sel ? TC_WHITE : TC_BLACK);
111  }
112  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);
113  }
114 };
115 
120  Dimension icon_size;
121  Dimension lock_size;
122 public:
123  bool greyed;
124 
125  DropDownListCompanyItem(int result, bool masked, bool greyed) : DropDownListItem(result, masked), greyed(greyed)
126  {
127  this->icon_size = GetSpriteSize(SPR_COMPANY_ICON);
128  this->lock_size = GetSpriteSize(SPR_LOCK);
129  }
130 
131  bool Selectable() const override
132  {
133  return true;
134  }
135 
136  uint Width() const override
137  {
138  CompanyID company = (CompanyID)this->result;
139  SetDParam(0, company);
140  SetDParam(1, company);
141  return GetStringBoundingBox(STR_COMPANY_NAME_COMPANY_NUM).width + this->icon_size.width + this->lock_size.width + 6;
142  }
143 
144  uint Height(uint width) const override
145  {
146  return max(max(this->icon_size.height, this->lock_size.height) + 2U, (uint)FONT_HEIGHT_NORMAL);
147  }
148 
149  void Draw(int left, int right, int top, int bottom, bool sel, Colours bg_colour) const override
150  {
151  CompanyID company = (CompanyID)this->result;
152  bool rtl = _current_text_dir == TD_RTL;
153 
154  /* It's possible the company is deleted while the dropdown is open */
155  if (!Company::IsValidID(company)) return;
156 
157  int icon_offset = (bottom - top - icon_size.height) / 2;
158  int text_offset = (bottom - top - FONT_HEIGHT_NORMAL) / 2;
159  int lock_offset = (bottom - top - lock_size.height) / 2;
160 
161  DrawCompanyIcon(company, rtl ? right - this->icon_size.width - WD_FRAMERECT_RIGHT : left + WD_FRAMERECT_LEFT, top + icon_offset);
162  if (NetworkCompanyIsPassworded(company)) {
163  DrawSprite(SPR_LOCK, PAL_NONE, rtl ? left + WD_FRAMERECT_LEFT : right - this->lock_size.width - WD_FRAMERECT_RIGHT, top + lock_offset);
164  }
165 
166  SetDParam(0, company);
167  SetDParam(1, company);
168  TextColour col;
169  if (this->greyed) {
170  col = (sel ? TC_SILVER : TC_GREY) | TC_NO_SHADE;
171  } else {
172  col = sel ? TC_WHITE : TC_BLACK;
173  }
174  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);
175  }
176 };
177 
185 static void PopupMainToolbMenu(Window *w, int widget, DropDownList &&list, int def)
186 {
187  ShowDropDownList(w, std::move(list), def, widget, 0, true, true);
188  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
189 }
190 
198 static void PopupMainToolbMenu(Window *w, int widget, StringID string, int count)
199 {
200  DropDownList list;
201  for (int i = 0; i < count; i++) {
202  list.emplace_back(new DropDownListStringItem(string + i, i, false));
203  }
204  PopupMainToolbMenu(w, widget, std::move(list), 0);
205 }
206 
208 static const int CTMN_CLIENT_LIST = -1;
209 static const int CTMN_NEW_COMPANY = -2;
210 static const int CTMN_SPECTATE = -3;
211 static const int CTMN_SPECTATOR = -4;
212 
219 static void PopupMainCompanyToolbMenu(Window *w, int widget, int grey = 0)
220 {
221  DropDownList list;
222 
223  switch (widget) {
224  case WID_TN_COMPANIES:
225  if (!_networking) break;
226 
227  /* Add the client list button for the companies menu */
228  list.emplace_back(new DropDownListStringItem(STR_NETWORK_COMPANY_LIST_CLIENT_LIST, CTMN_CLIENT_LIST, false));
229 
231  list.emplace_back(new DropDownListStringItem(STR_NETWORK_COMPANY_LIST_NEW_COMPANY, CTMN_NEW_COMPANY, NetworkMaxCompaniesReached()));
232  } else {
233  list.emplace_back(new DropDownListStringItem(STR_NETWORK_COMPANY_LIST_SPECTATE, CTMN_SPECTATE, NetworkMaxSpectatorsReached()));
234  }
235  break;
236 
237  case WID_TN_STORY:
238  list.emplace_back(new DropDownListStringItem(STR_STORY_BOOK_SPECTATOR, CTMN_SPECTATOR, false));
239  break;
240 
241  case WID_TN_GOAL:
242  list.emplace_back(new DropDownListStringItem(STR_GOALS_SPECTATOR, CTMN_SPECTATOR, false));
243  break;
244  }
245 
246  for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) {
247  if (!Company::IsValidID(c)) continue;
248  list.emplace_back(new DropDownListCompanyItem(c, false, HasBit(grey, c)));
249  }
250 
252 }
253 
254 
255 static ToolbarMode _toolbar_mode;
256 
257 static CallBackFunction SelectSignTool()
258 {
259  if (_last_started_action == CBF_PLACE_SIGN) {
261  return CBF_NONE;
262  } else {
263  SetObjectToPlace(SPR_CURSOR_SIGN, PAL_NONE, HT_RECT, WC_MAIN_TOOLBAR, 0);
264  return CBF_PLACE_SIGN;
265  }
266 }
267 
268 /* --- Pausing --- */
269 
270 static CallBackFunction ToolbarPauseClick(Window *w)
271 {
272  if (_networking && !_network_server) return CBF_NONE; // only server can pause the game
273 
275  if (_settings_client.sound.confirm) SndPlayFx(SND_15_BEEP);
276  }
277  return CBF_NONE;
278 }
279 
287 {
288  _fast_forward ^= true;
289  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
290  return CBF_NONE;
291 }
292 
297  OME_GAMEOPTIONS,
298  OME_SETTINGS,
299  OME_SCRIPT_SETTINGS,
300  OME_NEWGRFSETTINGS,
301  OME_TRANSPARENCIES,
302  OME_SHOW_TOWNNAMES,
303  OME_SHOW_STATIONNAMES,
304  OME_SHOW_WAYPOINTNAMES,
305  OME_SHOW_SIGNS,
306  OME_SHOW_COMPETITOR_SIGNS,
307  OME_FULL_ANIMATION,
308  OME_FULL_DETAILS,
309  OME_TRANSPARENTBUILDINGS,
310  OME_SHOW_STATIONSIGNS,
311 };
312 
320 {
321  DropDownList list;
322  list.emplace_back(new DropDownListStringItem(STR_SETTINGS_MENU_GAME_OPTIONS, OME_GAMEOPTIONS, false));
323  list.emplace_back(new DropDownListStringItem(STR_SETTINGS_MENU_CONFIG_SETTINGS_TREE, OME_SETTINGS, false));
324  /* Changes to the per-AI settings don't get send from the server to the clients. Clients get
325  * the settings once they join but never update it. As such don't show the window at all
326  * to network clients. */
327  if (!_networking || _network_server) list.emplace_back(new DropDownListStringItem(STR_SETTINGS_MENU_SCRIPT_SETTINGS, OME_SCRIPT_SETTINGS, false));
328  list.emplace_back(new DropDownListStringItem(STR_SETTINGS_MENU_NEWGRF_SETTINGS, OME_NEWGRFSETTINGS, false));
329  list.emplace_back(new DropDownListStringItem(STR_SETTINGS_MENU_TRANSPARENCY_OPTIONS, OME_TRANSPARENCIES, false));
330  list.emplace_back(new DropDownListItem(-1, false));
331  list.emplace_back(new DropDownListCheckedItem(STR_SETTINGS_MENU_TOWN_NAMES_DISPLAYED, OME_SHOW_TOWNNAMES, false, HasBit(_display_opt, DO_SHOW_TOWN_NAMES)));
332  list.emplace_back(new DropDownListCheckedItem(STR_SETTINGS_MENU_STATION_NAMES_DISPLAYED, OME_SHOW_STATIONNAMES, false, HasBit(_display_opt, DO_SHOW_STATION_NAMES)));
333  list.emplace_back(new DropDownListCheckedItem(STR_SETTINGS_MENU_WAYPOINTS_DISPLAYED, OME_SHOW_WAYPOINTNAMES, false, HasBit(_display_opt, DO_SHOW_WAYPOINT_NAMES)));
334  list.emplace_back(new DropDownListCheckedItem(STR_SETTINGS_MENU_SIGNS_DISPLAYED, OME_SHOW_SIGNS, false, HasBit(_display_opt, DO_SHOW_SIGNS)));
335  list.emplace_back(new DropDownListCheckedItem(STR_SETTINGS_MENU_SHOW_COMPETITOR_SIGNS, OME_SHOW_COMPETITOR_SIGNS, false, HasBit(_display_opt, DO_SHOW_COMPETITOR_SIGNS)));
336  list.emplace_back(new DropDownListCheckedItem(STR_SETTINGS_MENU_FULL_ANIMATION, OME_FULL_ANIMATION, false, HasBit(_display_opt, DO_FULL_ANIMATION)));
337  list.emplace_back(new DropDownListCheckedItem(STR_SETTINGS_MENU_FULL_DETAIL, OME_FULL_DETAILS, false, HasBit(_display_opt, DO_FULL_DETAIL)));
338  list.emplace_back(new DropDownListCheckedItem(STR_SETTINGS_MENU_TRANSPARENT_BUILDINGS, OME_TRANSPARENTBUILDINGS, false, IsTransparencySet(TO_HOUSES)));
339  list.emplace_back(new DropDownListCheckedItem(STR_SETTINGS_MENU_TRANSPARENT_SIGNS, OME_SHOW_STATIONSIGNS, false, IsTransparencySet(TO_SIGNS)));
340 
341  ShowDropDownList(w, std::move(list), 0, WID_TN_SETTINGS, 140, true, true);
342  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
343  return CBF_NONE;
344 }
345 
353 {
354  switch (index) {
355  case OME_GAMEOPTIONS: ShowGameOptions(); return CBF_NONE;
356  case OME_SETTINGS: ShowGameSettings(); return CBF_NONE;
357  case OME_SCRIPT_SETTINGS: ShowAIConfigWindow(); return CBF_NONE;
358  case OME_NEWGRFSETTINGS: ShowNewGRFSettings(!_networking && _settings_client.gui.UserIsAllowedToChangeNewGRFs(), true, true, &_grfconfig); return CBF_NONE;
359  case OME_TRANSPARENCIES: ShowTransparencyToolbar(); break;
360 
361  case OME_SHOW_TOWNNAMES: ToggleBit(_display_opt, DO_SHOW_TOWN_NAMES); break;
362  case OME_SHOW_STATIONNAMES: ToggleBit(_display_opt, DO_SHOW_STATION_NAMES); break;
363  case OME_SHOW_WAYPOINTNAMES: ToggleBit(_display_opt, DO_SHOW_WAYPOINT_NAMES); break;
364  case OME_SHOW_SIGNS: ToggleBit(_display_opt, DO_SHOW_SIGNS); break;
365  case OME_SHOW_COMPETITOR_SIGNS:
368  break;
369  case OME_FULL_ANIMATION: ToggleBit(_display_opt, DO_FULL_ANIMATION); CheckBlitter(); break;
370  case OME_FULL_DETAILS: ToggleBit(_display_opt, DO_FULL_DETAIL); break;
371  case OME_TRANSPARENTBUILDINGS: ToggleTransparency(TO_HOUSES); break;
372  case OME_SHOW_STATIONSIGNS: ToggleTransparency(TO_SIGNS); break;
373  }
375  return CBF_NONE;
376 }
377 
382  SLEME_SAVE_SCENARIO = 0,
383  SLEME_LOAD_SCENARIO,
384  SLEME_SAVE_HEIGHTMAP,
385  SLEME_LOAD_HEIGHTMAP,
386  SLEME_EXIT_TOINTRO,
387  SLEME_EXIT_GAME = 6,
388  SLEME_MENUCOUNT,
389 };
390 
395  SLNME_SAVE_GAME = 0,
396  SLNME_LOAD_GAME,
397  SLNME_EXIT_TOINTRO,
398  SLNME_EXIT_GAME = 4,
399  SLNME_MENUCOUNT,
400 };
401 
409 {
410  PopupMainToolbMenu(w, WID_TN_SAVE, STR_FILE_MENU_SAVE_GAME, SLNME_MENUCOUNT);
411  return CBF_NONE;
412 }
413 
421 {
422  PopupMainToolbMenu(w, WID_TE_SAVE, STR_SCENEDIT_FILE_MENU_SAVE_SCENARIO, SLEME_MENUCOUNT);
423  return CBF_NONE;
424 }
425 
432 static CallBackFunction MenuClickSaveLoad(int index = 0)
433 {
434  if (_game_mode == GM_EDITOR) {
435  switch (index) {
436  case SLEME_SAVE_SCENARIO: ShowSaveLoadDialog(FT_SCENARIO, SLO_SAVE); break;
437  case SLEME_LOAD_SCENARIO: ShowSaveLoadDialog(FT_SCENARIO, SLO_LOAD); break;
438  case SLEME_SAVE_HEIGHTMAP: ShowSaveLoadDialog(FT_HEIGHTMAP,SLO_SAVE); break;
439  case SLEME_LOAD_HEIGHTMAP: ShowSaveLoadDialog(FT_HEIGHTMAP,SLO_LOAD); break;
440  case SLEME_EXIT_TOINTRO: AskExitToGameMenu(); break;
441  case SLEME_EXIT_GAME: HandleExitGameRequest(); break;
442  }
443  } else {
444  switch (index) {
445  case SLNME_SAVE_GAME: ShowSaveLoadDialog(FT_SAVEGAME, SLO_SAVE); break;
446  case SLNME_LOAD_GAME: ShowSaveLoadDialog(FT_SAVEGAME, SLO_LOAD); break;
447  case SLNME_EXIT_TOINTRO: AskExitToGameMenu(); break;
448  case SLNME_EXIT_GAME: HandleExitGameRequest(); break;
449  }
450  }
451  return CBF_NONE;
452 }
453 
454 /* --- Map button menu --- */
455 
456 enum MapMenuEntries {
457  MME_SHOW_SMALLMAP = 0,
458  MME_SHOW_EXTRAVIEWPORTS,
459  MME_SHOW_LINKGRAPH,
460  MME_SHOW_SIGNLISTS,
461  MME_SHOW_TOWNDIRECTORY,
462  MME_SHOW_INDUSTRYDIRECTORY,
463 };
464 
465 static CallBackFunction ToolbarMapClick(Window *w)
466 {
467  DropDownList list;
468  list.emplace_back(new DropDownListStringItem(STR_MAP_MENU_MAP_OF_WORLD, MME_SHOW_SMALLMAP, false));
469  list.emplace_back(new DropDownListStringItem(STR_MAP_MENU_EXTRA_VIEW_PORT, MME_SHOW_EXTRAVIEWPORTS, false));
470  list.emplace_back(new DropDownListStringItem(STR_MAP_MENU_LINGRAPH_LEGEND, MME_SHOW_LINKGRAPH, false));
471  list.emplace_back(new DropDownListStringItem(STR_MAP_MENU_SIGN_LIST, MME_SHOW_SIGNLISTS, false));
472  PopupMainToolbMenu(w, WID_TN_SMALL_MAP, std::move(list), 0);
473  return CBF_NONE;
474 }
475 
476 static CallBackFunction ToolbarScenMapTownDir(Window *w)
477 {
478  DropDownList list;
479  list.emplace_back(new DropDownListStringItem(STR_MAP_MENU_MAP_OF_WORLD, MME_SHOW_SMALLMAP, false));
480  list.emplace_back(new DropDownListStringItem(STR_MAP_MENU_EXTRA_VIEW_PORT, MME_SHOW_EXTRAVIEWPORTS, false));
481  list.emplace_back(new DropDownListStringItem(STR_MAP_MENU_SIGN_LIST, MME_SHOW_SIGNLISTS, false));
482  list.emplace_back(new DropDownListStringItem(STR_TOWN_MENU_TOWN_DIRECTORY, MME_SHOW_TOWNDIRECTORY, false));
483  list.emplace_back(new DropDownListStringItem(STR_INDUSTRY_MENU_INDUSTRY_DIRECTORY, MME_SHOW_INDUSTRYDIRECTORY, false));
484  PopupMainToolbMenu(w, WID_TE_SMALL_MAP, std::move(list), 0);
485  return CBF_NONE;
486 }
487 
495 {
496  switch (index) {
497  case MME_SHOW_SMALLMAP: ShowSmallMap(); break;
498  case MME_SHOW_EXTRAVIEWPORTS: ShowExtraViewPortWindow(); break;
499  case MME_SHOW_LINKGRAPH: ShowLinkGraphLegend(); break;
500  case MME_SHOW_SIGNLISTS: ShowSignList(); break;
501  case MME_SHOW_TOWNDIRECTORY: ShowTownDirectory(); break;
502  case MME_SHOW_INDUSTRYDIRECTORY: ShowIndustryDirectory(); break;
503  }
504  return CBF_NONE;
505 }
506 
507 /* --- Town button menu --- */
508 
509 static CallBackFunction ToolbarTownClick(Window *w)
510 {
511  PopupMainToolbMenu(w, WID_TN_TOWNS, STR_TOWN_MENU_TOWN_DIRECTORY, (_settings_game.economy.found_town == TF_FORBIDDEN) ? 1 : 2);
512  return CBF_NONE;
513 }
514 
522 {
523  switch (index) {
524  case 0: ShowTownDirectory(); break;
525  case 1: // setting could be changed when the dropdown was open
526  if (_settings_game.economy.found_town != TF_FORBIDDEN) ShowFoundTownWindow();
527  break;
528  }
529  return CBF_NONE;
530 }
531 
532 /* --- Subidies button menu --- */
533 
534 static CallBackFunction ToolbarSubsidiesClick(Window *w)
535 {
536  PopupMainToolbMenu(w, WID_TN_SUBSIDIES, STR_SUBSIDIES_MENU_SUBSIDIES, 1);
537  return CBF_NONE;
538 }
539 
547 {
548  switch (index) {
549  case 0: ShowSubsidiesList(); break;
550  }
551  return CBF_NONE;
552 }
553 
554 /* --- Stations button menu --- */
555 
556 static CallBackFunction ToolbarStationsClick(Window *w)
557 {
559  return CBF_NONE;
560 }
561 
569 {
571  return CBF_NONE;
572 }
573 
574 /* --- Finances button menu --- */
575 
576 static CallBackFunction ToolbarFinancesClick(Window *w)
577 {
579  return CBF_NONE;
580 }
581 
589 {
591  return CBF_NONE;
592 }
593 
594 /* --- Company's button menu --- */
595 
596 static CallBackFunction ToolbarCompaniesClick(Window *w)
597 {
599  return CBF_NONE;
600 }
601 
609 {
610  if (_networking) {
611  switch (index) {
612  case CTMN_CLIENT_LIST:
613  ShowClientList();
614  return CBF_NONE;
615 
616  case CTMN_NEW_COMPANY:
617  if (_network_server) {
619  } else {
620  NetworkSendCommand(0, CCA_NEW, 0, CMD_COMPANY_CTRL, nullptr, nullptr, _local_company);
621  }
622  return CBF_NONE;
623 
624  case CTMN_SPECTATE:
625  if (_network_server) {
628  } else {
630  }
631  return CBF_NONE;
632  }
633  }
634  ShowCompany((CompanyID)index);
635  return CBF_NONE;
636 }
637 
638 /* --- Story button menu --- */
639 
640 static CallBackFunction ToolbarStoryClick(Window *w)
641 {
643  return CBF_NONE;
644 }
645 
653 {
655  return CBF_NONE;
656 }
657 
658 /* --- Goal button menu --- */
659 
660 static CallBackFunction ToolbarGoalClick(Window *w)
661 {
663  return CBF_NONE;
664 }
665 
673 {
675  return CBF_NONE;
676 }
677 
678 /* --- Graphs button menu --- */
679 
680 static CallBackFunction ToolbarGraphsClick(Window *w)
681 {
682  PopupMainToolbMenu(w, WID_TN_GRAPHS, STR_GRAPH_MENU_OPERATING_PROFIT_GRAPH, (_toolbar_mode == TB_NORMAL) ? 6 : 8);
683  return CBF_NONE;
684 }
685 
693 {
694  switch (index) {
695  case 0: ShowOperatingProfitGraph(); break;
696  case 1: ShowIncomeGraph(); break;
697  case 2: ShowDeliveredCargoGraph(); break;
698  case 3: ShowPerformanceHistoryGraph(); break;
699  case 4: ShowCompanyValueGraph(); break;
700  case 5: ShowCargoPaymentRates(); break;
701  /* functions for combined graphs/league button */
702  case 6: ShowCompanyLeagueTable(); break;
703  case 7: ShowPerformanceRatingDetail(); break;
704  }
705  return CBF_NONE;
706 }
707 
708 /* --- League button menu --- */
709 
710 static CallBackFunction ToolbarLeagueClick(Window *w)
711 {
712  PopupMainToolbMenu(w, WID_TN_LEAGUE, STR_GRAPH_MENU_COMPANY_LEAGUE_TABLE, _networking ? 2 : 3);
713  return CBF_NONE;
714 }
715 
723 {
724  switch (index) {
725  case 0: ShowCompanyLeagueTable(); break;
726  case 1: ShowPerformanceRatingDetail(); break;
727  case 2: ShowHighscoreTable(); break;
728  }
729  return CBF_NONE;
730 }
731 
732 /* --- Industries button menu --- */
733 
734 static CallBackFunction ToolbarIndustryClick(Window *w)
735 {
736  /* Disable build-industry menu if we are a spectator */
737  PopupMainToolbMenu(w, WID_TN_INDUSTRIES, STR_INDUSTRY_MENU_INDUSTRY_DIRECTORY, (_local_company == COMPANY_SPECTATOR) ? 2 : 3);
738  return CBF_NONE;
739 }
740 
748 {
749  switch (index) {
750  case 0: ShowIndustryDirectory(); break;
751  case 1: ShowIndustryCargoesWindow(); break;
752  case 2: ShowBuildIndustryWindow(); break;
753  }
754  return CBF_NONE;
755 }
756 
757 /* --- Trains button menu + 1 helper function for all vehicles. --- */
758 
759 static void ToolbarVehicleClick(Window *w, VehicleType veh)
760 {
761  int dis = ~0;
762 
763  for (const Vehicle *v : Vehicle::Iterate()) {
764  if (v->type == veh && v->IsPrimaryVehicle()) ClrBit(dis, v->owner);
765  }
767 }
768 
769 
770 static CallBackFunction ToolbarTrainClick(Window *w)
771 {
772  ToolbarVehicleClick(w, VEH_TRAIN);
773  return CBF_NONE;
774 }
775 
783 {
784  ShowVehicleListWindow((CompanyID)index, VEH_TRAIN);
785  return CBF_NONE;
786 }
787 
788 /* --- Road vehicle button menu --- */
789 
790 static CallBackFunction ToolbarRoadClick(Window *w)
791 {
792  ToolbarVehicleClick(w, VEH_ROAD);
793  return CBF_NONE;
794 }
795 
803 {
804  ShowVehicleListWindow((CompanyID)index, VEH_ROAD);
805  return CBF_NONE;
806 }
807 
808 /* --- Ship button menu --- */
809 
810 static CallBackFunction ToolbarShipClick(Window *w)
811 {
812  ToolbarVehicleClick(w, VEH_SHIP);
813  return CBF_NONE;
814 }
815 
823 {
824  ShowVehicleListWindow((CompanyID)index, VEH_SHIP);
825  return CBF_NONE;
826 }
827 
828 /* --- Aircraft button menu --- */
829 
830 static CallBackFunction ToolbarAirClick(Window *w)
831 {
832  ToolbarVehicleClick(w, VEH_AIRCRAFT);
833  return CBF_NONE;
834 }
835 
843 {
844  ShowVehicleListWindow((CompanyID)index, VEH_AIRCRAFT);
845  return CBF_NONE;
846 }
847 
848 /* --- Zoom in button --- */
849 
850 static CallBackFunction ToolbarZoomInClick(Window *w)
851 {
853  w->HandleButtonClick((_game_mode == GM_EDITOR) ? (byte)WID_TE_ZOOM_IN : (byte)WID_TN_ZOOM_IN);
854  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
855  }
856  return CBF_NONE;
857 }
858 
859 /* --- Zoom out button --- */
860 
861 static CallBackFunction ToolbarZoomOutClick(Window *w)
862 {
864  w->HandleButtonClick((_game_mode == GM_EDITOR) ? (byte)WID_TE_ZOOM_OUT : (byte)WID_TN_ZOOM_OUT);
865  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
866  }
867  return CBF_NONE;
868 }
869 
870 /* --- Rail button menu --- */
871 
872 static CallBackFunction ToolbarBuildRailClick(Window *w)
873 {
874  ShowDropDownList(w, GetRailTypeDropDownList(), _last_built_railtype, WID_TN_RAILS, 140, true, true);
875  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
876  return CBF_NONE;
877 }
878 
886 {
887  _last_built_railtype = (RailType)index;
888  ShowBuildRailToolbar(_last_built_railtype);
889  return CBF_NONE;
890 }
891 
892 /* --- Road button menu --- */
893 
894 static CallBackFunction ToolbarBuildRoadClick(Window *w)
895 {
896  ShowDropDownList(w, GetRoadTypeDropDownList(RTTB_ROAD), _last_built_roadtype, WID_TN_ROADS, 140, true, true);
897  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
898  return CBF_NONE;
899 }
900 
908 {
909  _last_built_roadtype = (RoadType)index;
910  ShowBuildRoadToolbar(_last_built_roadtype);
911  return CBF_NONE;
912 }
913 
914 /* --- Tram button menu --- */
915 
916 static CallBackFunction ToolbarBuildTramClick(Window *w)
917 {
918  ShowDropDownList(w, GetRoadTypeDropDownList(RTTB_TRAM), _last_built_tramtype, WID_TN_TRAMS, 140, true, true);
919  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
920  return CBF_NONE;
921 }
922 
930 {
931  _last_built_tramtype = (RoadType)index;
932  ShowBuildRoadToolbar(_last_built_tramtype);
933  return CBF_NONE;
934 }
935 
936 /* --- Water button menu --- */
937 
938 static CallBackFunction ToolbarBuildWaterClick(Window *w)
939 {
940  DropDownList list;
941  list.emplace_back(new DropDownListIconItem(SPR_IMG_BUILD_CANAL, PAL_NONE, STR_WATERWAYS_MENU_WATERWAYS_CONSTRUCTION, 0, false));
942  ShowDropDownList(w, std::move(list), 0, WID_TN_WATER, 140, true, true);
943  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
944  return CBF_NONE;
945 }
946 
954 {
956  return CBF_NONE;
957 }
958 
959 /* --- Airport button menu --- */
960 
961 static CallBackFunction ToolbarBuildAirClick(Window *w)
962 {
963  DropDownList list;
964  list.emplace_back(new DropDownListIconItem(SPR_IMG_AIRPORT, PAL_NONE, STR_AIRCRAFT_MENU_AIRPORT_CONSTRUCTION, 0, false));
965  ShowDropDownList(w, std::move(list), 0, WID_TN_AIR, 140, true, true);
966  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
967  return CBF_NONE;
968 }
969 
977 {
979  return CBF_NONE;
980 }
981 
982 /* --- Forest button menu --- */
983 
984 static CallBackFunction ToolbarForestClick(Window *w)
985 {
986  DropDownList list;
987  list.emplace_back(new DropDownListIconItem(SPR_IMG_LANDSCAPING, PAL_NONE, STR_LANDSCAPING_MENU_LANDSCAPING, 0, false));
988  list.emplace_back(new DropDownListIconItem(SPR_IMG_PLANTTREES, PAL_NONE, STR_LANDSCAPING_MENU_PLANT_TREES, 1, false));
989  list.emplace_back(new DropDownListIconItem(SPR_IMG_SIGN, PAL_NONE, STR_LANDSCAPING_MENU_PLACE_SIGN, 2, false));
990  ShowDropDownList(w, std::move(list), 0, WID_TN_LANDSCAPE, 100, true, true);
991  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
992  return CBF_NONE;
993 }
994 
1002 {
1003  switch (index) {
1004  case 0: ShowTerraformToolbar(); break;
1005  case 1: ShowBuildTreesToolbar(); break;
1006  case 2: return SelectSignTool();
1007  }
1008  return CBF_NONE;
1009 }
1010 
1011 /* --- Music button menu --- */
1012 
1013 static CallBackFunction ToolbarMusicClick(Window *w)
1014 {
1015  PopupMainToolbMenu(w, _game_mode == GM_EDITOR ? (int)WID_TE_MUSIC_SOUND : (int)WID_TN_MUSIC_SOUND, STR_TOOLBAR_SOUND_MUSIC, 1);
1016  return CBF_NONE;
1017 }
1018 
1026 {
1027  ShowMusicWindow();
1028  return CBF_NONE;
1029 }
1030 
1031 /* --- Newspaper button menu --- */
1032 
1033 static CallBackFunction ToolbarNewspaperClick(Window *w)
1034 {
1035  PopupMainToolbMenu(w, WID_TN_MESSAGES, STR_NEWS_MENU_LAST_MESSAGE_NEWS_REPORT, 3);
1036  return CBF_NONE;
1037 }
1038 
1046 {
1047  switch (index) {
1048  case 0: ShowLastNewsMessage(); break;
1049  case 1: ShowMessageHistory(); break;
1050  case 2: DeleteAllMessages(); break;
1051  }
1052  return CBF_NONE;
1053 }
1054 
1055 /* --- Help button menu --- */
1056 
1057 static CallBackFunction PlaceLandBlockInfo()
1058 {
1059  if (_last_started_action == CBF_PLACE_LANDINFO) {
1061  return CBF_NONE;
1062  } else {
1063  SetObjectToPlace(SPR_CURSOR_QUERY, PAL_NONE, HT_RECT, WC_MAIN_TOOLBAR, 0);
1064  return CBF_PLACE_LANDINFO;
1065  }
1066 }
1067 
1068 static CallBackFunction ToolbarHelpClick(Window *w)
1069 {
1070  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 ? 10 : 7);
1071  return CBF_NONE;
1072 }
1073 
1079 static void ScreenshotConfirmCallback(Window *w, bool confirmed)
1080 {
1081  if (confirmed) MakeScreenshot(_confirmed_screenshot_type, nullptr);
1082 }
1083 
1090 {
1091  ViewPort vp;
1092  SetupScreenshotViewport(t, &vp);
1093  if ((uint64)vp.width * (uint64)vp.height > 8192 * 8192) {
1094  /* Ask for confirmation */
1095  SetDParam(0, vp.width);
1096  SetDParam(1, vp.height);
1098  ShowQuery(STR_WARNING_SCREENSHOT_SIZE_CAPTION, STR_WARNING_SCREENSHOT_SIZE_MESSAGE, nullptr, ScreenshotConfirmCallback);
1099  } else {
1100  /* Less than 64M pixels, just do it */
1101  MakeScreenshot(t, nullptr);
1102  }
1103 }
1104 
1113 {
1114  extern bool _draw_bounding_boxes;
1115  /* Always allow to toggle them off */
1116  if (_settings_client.gui.newgrf_developer_tools || _draw_bounding_boxes) {
1117  _draw_bounding_boxes = !_draw_bounding_boxes;
1119  }
1120 }
1121 
1130 {
1131  extern bool _draw_dirty_blocks;
1132  /* Always allow to toggle them off */
1133  if (_settings_client.gui.newgrf_developer_tools || _draw_dirty_blocks) {
1134  _draw_dirty_blocks = !_draw_dirty_blocks;
1136  }
1137 }
1138 
1144 {
1147  /* If you open a savegame as scenario there may already be link graphs.*/
1149  SetDate(new_date, 0);
1150 }
1151 
1158 {
1159  switch (index) {
1160  case 0: return PlaceLandBlockInfo();
1161  case 2: IConsoleSwitch(); break;
1162  case 3: ShowAIDebugWindow(); break;
1163  case 4: ShowScreenshotWindow(); break;
1164  case 5: ShowFramerateWindow(); break;
1165  case 6: ShowAboutWindow(); break;
1166  case 7: ShowSpriteAlignerWindow(); break;
1167  case 8: ToggleBoundingBoxes(); break;
1168  case 9: ToggleDirtyBlocks(); break;
1169  }
1170  return CBF_NONE;
1171 }
1172 
1173 /* --- Switch toolbar button --- */
1174 
1175 static CallBackFunction ToolbarSwitchClick(Window *w)
1176 {
1177  if (_toolbar_mode != TB_LOWER) {
1178  _toolbar_mode = TB_LOWER;
1179  } else {
1180  _toolbar_mode = TB_UPPER;
1181  }
1182 
1183  w->ReInit();
1184  w->SetWidgetLoweredState(_game_mode == GM_EDITOR ? (uint)WID_TE_SWITCH_BAR : (uint)WID_TN_SWITCH_BAR, _toolbar_mode == TB_LOWER);
1185  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
1186  return CBF_NONE;
1187 }
1188 
1189 /* --- Scenario editor specific handlers. */
1190 
1195 {
1197  ShowQueryString(STR_JUST_INT, STR_MAPGEN_START_DATE_QUERY_CAPT, 8, w, CS_NUMERAL, QSF_ENABLE_DEFAULT);
1198  _left_button_clicked = false;
1199  return CBF_NONE;
1200 }
1201 
1202 static CallBackFunction ToolbarScenDateBackward(Window *w)
1203 {
1204  /* don't allow too fast scrolling */
1205  if (!(w->flags & WF_TIMEOUT) || w->timeout_timer <= 1) {
1207  w->SetDirty();
1208 
1210  }
1211  _left_button_clicked = false;
1212  return CBF_NONE;
1213 }
1214 
1215 static CallBackFunction ToolbarScenDateForward(Window *w)
1216 {
1217  /* don't allow too fast scrolling */
1218  if (!(w->flags & WF_TIMEOUT) || w->timeout_timer <= 1) {
1220  w->SetDirty();
1221 
1223  }
1224  _left_button_clicked = false;
1225  return CBF_NONE;
1226 }
1227 
1228 static CallBackFunction ToolbarScenGenLand(Window *w)
1229 {
1231  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
1232 
1234  return CBF_NONE;
1235 }
1236 
1237 
1238 static CallBackFunction ToolbarScenGenTown(Window *w)
1239 {
1241  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
1242  ShowFoundTownWindow();
1243  return CBF_NONE;
1244 }
1245 
1246 static CallBackFunction ToolbarScenGenIndustry(Window *w)
1247 {
1249  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
1250  ShowBuildIndustryWindow();
1251  return CBF_NONE;
1252 }
1253 
1254 static CallBackFunction ToolbarScenBuildRoadClick(Window *w)
1255 {
1256  ShowDropDownList(w, GetScenRoadTypeDropDownList(RTTB_ROAD), _last_built_roadtype, WID_TE_ROADS, 140, true, true);
1257  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
1258  return CBF_NONE;
1259 }
1260 
1268 {
1269  _last_built_roadtype = (RoadType)index;
1270  ShowBuildRoadScenToolbar(_last_built_roadtype);
1271  return CBF_NONE;
1272 }
1273 
1274 static CallBackFunction ToolbarScenBuildTramClick(Window *w)
1275 {
1276  ShowDropDownList(w, GetScenRoadTypeDropDownList(RTTB_TRAM), _last_built_tramtype, WID_TE_TRAMS, 140, true, true);
1277  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
1278  return CBF_NONE;
1279 }
1280 
1288 {
1289  _last_built_tramtype = (RoadType)index;
1290  ShowBuildRoadScenToolbar(_last_built_tramtype);
1291  return CBF_NONE;
1292 }
1293 
1294 static CallBackFunction ToolbarScenBuildDocks(Window *w)
1295 {
1297  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
1299  return CBF_NONE;
1300 }
1301 
1302 static CallBackFunction ToolbarScenPlantTrees(Window *w)
1303 {
1305  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
1306  ShowBuildTreesToolbar();
1307  return CBF_NONE;
1308 }
1309 
1310 static CallBackFunction ToolbarScenPlaceSign(Window *w)
1311 {
1313  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
1314  return SelectSignTool();
1315 }
1316 
1317 static CallBackFunction ToolbarBtn_NULL(Window *w)
1318 {
1319  return CBF_NONE;
1320 }
1321 
1322 typedef CallBackFunction MenuClickedProc(int index);
1323 
1324 static MenuClickedProc * const _menu_clicked_procs[] = {
1325  nullptr, // 0
1326  nullptr, // 1
1327  MenuClickSettings, // 2
1328  MenuClickSaveLoad, // 3
1329  MenuClickMap, // 4
1330  MenuClickTown, // 5
1331  MenuClickSubsidies, // 6
1332  MenuClickStations, // 7
1333  MenuClickFinances, // 8
1334  MenuClickCompany, // 9
1335  MenuClickStory, // 10
1336  MenuClickGoal, // 11
1337  MenuClickGraphs, // 12
1338  MenuClickLeague, // 13
1339  MenuClickIndustry, // 14
1340  MenuClickShowTrains, // 15
1341  MenuClickShowRoad, // 16
1342  MenuClickShowShips, // 17
1343  MenuClickShowAir, // 18
1344  MenuClickMap, // 19
1345  nullptr, // 20
1346  MenuClickBuildRail, // 21
1347  MenuClickBuildRoad, // 22
1348  MenuClickBuildTram, // 23
1349  MenuClickBuildWater, // 24
1350  MenuClickBuildAir, // 25
1351  MenuClickForest, // 26
1352  MenuClickMusicWindow, // 27
1353  MenuClickNewspaper, // 28
1354  MenuClickHelp, // 29
1355 };
1356 
1359  bool visible[WID_TN_END];
1360 protected:
1361  uint spacers;
1362 
1363 public:
1365  {
1366  }
1367 
1373  bool IsButton(WidgetType type) const
1374  {
1375  return type == WWT_IMGBTN || type == WWT_IMGBTN_2 || type == WWT_PUSHIMGBTN;
1376  }
1377 
1378  void SetupSmallestSize(Window *w, bool init_array) override
1379  {
1380  this->smallest_x = 0; // Biggest child
1381  this->smallest_y = 0; // Biggest child
1382  this->fill_x = 1;
1383  this->fill_y = 0;
1384  this->resize_x = 1; // We only resize in this direction
1385  this->resize_y = 0; // We never resize in this direction
1386  this->spacers = 0;
1387 
1388  uint nbuttons = 0;
1389  /* First initialise some variables... */
1390  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1391  child_wid->SetupSmallestSize(w, init_array);
1392  this->smallest_y = max(this->smallest_y, child_wid->smallest_y + child_wid->padding_top + child_wid->padding_bottom);
1393  if (this->IsButton(child_wid->type)) {
1394  nbuttons++;
1395  this->smallest_x = max(this->smallest_x, child_wid->smallest_x + child_wid->padding_left + child_wid->padding_right);
1396  } else if (child_wid->type == NWID_SPACER) {
1397  this->spacers++;
1398  }
1399  }
1400 
1401  /* ... then in a second pass make sure the 'current' heights are set. Won't change ever. */
1402  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1403  child_wid->current_y = this->smallest_y;
1404  if (!this->IsButton(child_wid->type)) {
1405  child_wid->current_x = child_wid->smallest_x;
1406  }
1407  }
1408  _toolbar_width = nbuttons * this->smallest_x;
1409  }
1410 
1411  void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl) override
1412  {
1413  assert(given_width >= this->smallest_x && given_height >= this->smallest_y);
1414 
1415  this->pos_x = x;
1416  this->pos_y = y;
1417  this->current_x = given_width;
1418  this->current_y = given_height;
1419 
1420  /* Figure out what are the visible buttons */
1421  memset(this->visible, 0, sizeof(this->visible));
1422  uint arrangable_count, button_count, spacer_count;
1423  const byte *arrangement = GetButtonArrangement(given_width, arrangable_count, button_count, spacer_count);
1424  for (uint i = 0; i < arrangable_count; i++) {
1425  this->visible[arrangement[i]] = true;
1426  }
1427 
1428  /* Create us ourselves a quick lookup table */
1429  NWidgetBase *widgets[WID_TN_END];
1430  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1431  if (child_wid->type == NWID_SPACER) continue;
1432  widgets[((NWidgetCore*)child_wid)->index] = child_wid;
1433  }
1434 
1435  /* Now assign the widgets to their rightful place */
1436  uint position = 0; // Place to put next child relative to origin of the container.
1437  uint spacer_space = max(0, (int)given_width - (int)(button_count * this->smallest_x)); // Remaining spacing for 'spacer' widgets
1438  uint button_space = given_width - spacer_space; // Remaining spacing for the buttons
1439  uint spacer_i = 0;
1440  uint button_i = 0;
1441 
1442  /* Index into the arrangement indices. The macro lastof cannot be used here! */
1443  const byte *cur_wid = rtl ? &arrangement[arrangable_count - 1] : arrangement;
1444  for (uint i = 0; i < arrangable_count; i++) {
1445  NWidgetBase *child_wid = widgets[*cur_wid];
1446  /* If we have to give space to the spacers, do that */
1447  if (spacer_space != 0) {
1448  NWidgetBase *possible_spacer = rtl ? child_wid->next : child_wid->prev;
1449  if (possible_spacer != nullptr && possible_spacer->type == NWID_SPACER) {
1450  uint add = spacer_space / (spacer_count - spacer_i);
1451  position += add;
1452  spacer_space -= add;
1453  spacer_i++;
1454  }
1455  }
1456 
1457  /* Buttons can be scaled, the others not. */
1458  if (this->IsButton(child_wid->type)) {
1459  child_wid->current_x = button_space / (button_count - button_i);
1460  button_space -= child_wid->current_x;
1461  button_i++;
1462  }
1463  child_wid->AssignSizePosition(sizing, x + position, y, child_wid->current_x, this->current_y, rtl);
1464  position += child_wid->current_x;
1465 
1466  if (rtl) {
1467  cur_wid--;
1468  } else {
1469  cur_wid++;
1470  }
1471  }
1472  }
1473 
1474  void Draw(const Window *w) override
1475  {
1476  /* Draw brown-red toolbar bg. */
1477  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);
1478  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);
1479 
1480  bool rtl = _current_text_dir == TD_RTL;
1481  for (NWidgetBase *child_wid = rtl ? this->tail : this->head; child_wid != nullptr; child_wid = rtl ? child_wid->prev : child_wid->next) {
1482  if (child_wid->type == NWID_SPACER) continue;
1483  if (!this->visible[((NWidgetCore*)child_wid)->index]) continue;
1484 
1485  child_wid->Draw(w);
1486  }
1487  }
1488 
1489  NWidgetCore *GetWidgetFromPos(int x, int y) override
1490  {
1491  if (!IsInsideBS(x, this->pos_x, this->current_x) || !IsInsideBS(y, this->pos_y, this->current_y)) return nullptr;
1492 
1493  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1494  if (child_wid->type == NWID_SPACER) continue;
1495  if (!this->visible[((NWidgetCore*)child_wid)->index]) continue;
1496 
1497  NWidgetCore *nwid = child_wid->GetWidgetFromPos(x, y);
1498  if (nwid != nullptr) return nwid;
1499  }
1500  return nullptr;
1501  }
1502 
1511  virtual const byte *GetButtonArrangement(uint &width, uint &arrangable_count, uint &button_count, uint &spacer_count) const = 0;
1512 };
1513 
1516  const byte *GetButtonArrangement(uint &width, uint &arrangable_count, uint &button_count, uint &spacer_count) const override
1517  {
1518  static const uint SMALLEST_ARRANGEMENT = 14;
1519  static const uint BIGGEST_ARRANGEMENT = 20;
1520 
1521  /* The number of buttons of each row of the toolbar should match the number of items which we want to be visible.
1522  * The total number of buttons should be equal to arrangable_count * 2.
1523  * No bad things happen, but we could see strange behaviours if we have buttons < (arrangable_count * 2) like a
1524  * pause button appearing on the right of the lower toolbar and weird resizing of the widgets even if there is
1525  * enough space.
1526  */
1527  static const byte arrange14[] = {
1528  WID_TN_PAUSE,
1530  WID_TN_TRAINS,
1532  WID_TN_SHIPS,
1536  WID_TN_RAILS,
1537  WID_TN_ROADS,
1538  WID_TN_WATER,
1539  WID_TN_AIR,
1542  // lower toolbar
1544  WID_TN_SAVE,
1546  WID_TN_TOWNS,
1551  WID_TN_GRAPHS,
1555  WID_TN_HELP,
1557  };
1558  static const byte arrange15[] = {
1559  WID_TN_PAUSE,
1562  WID_TN_TRAINS,
1564  WID_TN_SHIPS,
1566  WID_TN_RAILS,
1567  WID_TN_ROADS,
1568  WID_TN_WATER,
1569  WID_TN_AIR,
1574  // lower toolbar
1575  WID_TN_PAUSE,
1578  WID_TN_SAVE,
1579  WID_TN_TOWNS,
1584  WID_TN_GRAPHS,
1588  WID_TN_HELP,
1590  };
1591  static const byte arrange16[] = {
1592  WID_TN_PAUSE,
1596  WID_TN_TRAINS,
1598  WID_TN_SHIPS,
1600  WID_TN_RAILS,
1601  WID_TN_ROADS,
1602  WID_TN_WATER,
1603  WID_TN_AIR,
1608  // lower toolbar
1609  WID_TN_PAUSE,
1611  WID_TN_SAVE,
1612  WID_TN_TOWNS,
1617  WID_TN_GRAPHS,
1621  WID_TN_HELP,
1625  };
1626  static const byte arrange17[] = {
1627  WID_TN_PAUSE,
1632  WID_TN_TRAINS,
1634  WID_TN_SHIPS,
1636  WID_TN_RAILS,
1637  WID_TN_ROADS,
1638  WID_TN_WATER,
1639  WID_TN_AIR,
1644  // lower toolbar
1645  WID_TN_PAUSE,
1647  WID_TN_SAVE,
1650  WID_TN_TOWNS,
1654  WID_TN_GRAPHS,
1658  WID_TN_HELP,
1662  };
1663  static const byte arrange18[] = {
1664  WID_TN_PAUSE,
1668  WID_TN_TOWNS,
1674  WID_TN_RAILS,
1675  WID_TN_ROADS,
1676  WID_TN_WATER,
1677  WID_TN_AIR,
1682  // lower toolbar
1683  WID_TN_PAUSE,
1685  WID_TN_SAVE,
1687  WID_TN_TOWNS,
1690  WID_TN_GRAPHS,
1691  WID_TN_TRAINS,
1693  WID_TN_SHIPS,
1697  WID_TN_HELP,
1701  };
1702  static const byte arrange19[] = {
1703  WID_TN_PAUSE,
1707  WID_TN_TOWNS,
1709  WID_TN_TRAINS,
1711  WID_TN_SHIPS,
1713  WID_TN_RAILS,
1714  WID_TN_ROADS,
1715  WID_TN_WATER,
1716  WID_TN_AIR,
1722  // lower toolbar
1723  WID_TN_PAUSE,
1725  WID_TN_SAVE,
1730  WID_TN_GRAPHS,
1733  WID_TN_RAILS,
1734  WID_TN_ROADS,
1735  WID_TN_WATER,
1736  WID_TN_AIR,
1738  WID_TN_HELP,
1742  };
1743  static const byte arrange20[] = {
1744  WID_TN_PAUSE,
1748  WID_TN_TOWNS,
1750  WID_TN_TRAINS,
1752  WID_TN_SHIPS,
1754  WID_TN_RAILS,
1755  WID_TN_ROADS,
1756  WID_TN_WATER,
1757  WID_TN_AIR,
1760  WID_TN_GOAL,
1764  // lower toolbar
1765  WID_TN_PAUSE,
1767  WID_TN_SAVE,
1772  WID_TN_GRAPHS,
1775  WID_TN_RAILS,
1776  WID_TN_ROADS,
1777  WID_TN_WATER,
1778  WID_TN_AIR,
1780  WID_TN_STORY,
1781  WID_TN_HELP,
1785  };
1786  static const byte arrange_all[] = {
1787  WID_TN_PAUSE,
1790  WID_TN_SAVE,
1792  WID_TN_TOWNS,
1797  WID_TN_STORY,
1798  WID_TN_GOAL,
1799  WID_TN_GRAPHS,
1800  WID_TN_LEAGUE,
1802  WID_TN_TRAINS,
1804  WID_TN_SHIPS,
1808  WID_TN_RAILS,
1809  WID_TN_ROADS,
1810  WID_TN_TRAMS,
1811  WID_TN_WATER,
1812  WID_TN_AIR,
1816  WID_TN_HELP
1817  };
1818 
1819  /* If at least BIGGEST_ARRANGEMENT fit, just spread all the buttons nicely */
1820  uint full_buttons = max(CeilDiv(width, this->smallest_x), SMALLEST_ARRANGEMENT);
1821  if (full_buttons > BIGGEST_ARRANGEMENT) {
1822  button_count = arrangable_count = lengthof(arrange_all);
1823  spacer_count = this->spacers;
1824  return arrange_all;
1825  }
1826 
1827  /* Introduce the split toolbar */
1828  static const byte * const arrangements[] = { arrange14, arrange15, arrange16, arrange17, arrange18, arrange19, arrange20 };
1829 
1830  button_count = arrangable_count = full_buttons;
1831  spacer_count = this->spacers;
1832  return arrangements[full_buttons - SMALLEST_ARRANGEMENT] + ((_toolbar_mode == TB_LOWER) ? full_buttons : 0);
1833  }
1834 };
1835 
1838  uint panel_widths[2];
1839 
1840  void SetupSmallestSize(Window *w, bool init_array) override
1841  {
1842  this->NWidgetToolbarContainer::SetupSmallestSize(w, init_array);
1843 
1844  /* Find the size of panel_widths */
1845  uint i = 0;
1846  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1847  if (child_wid->type == NWID_SPACER || this->IsButton(child_wid->type)) continue;
1848 
1849  assert(i < lengthof(this->panel_widths));
1850  this->panel_widths[i++] = child_wid->current_x;
1851  _toolbar_width += child_wid->current_x;
1852  }
1853  }
1854 
1855  const byte *GetButtonArrangement(uint &width, uint &arrangable_count, uint &button_count, uint &spacer_count) const override
1856  {
1857  static const byte arrange_all[] = {
1858  WID_TE_PAUSE,
1861  WID_TE_SAVE,
1862  WID_TE_SPACER,
1870  WID_TE_ROADS,
1871  WID_TE_TRAMS,
1872  WID_TE_WATER,
1873  WID_TE_TREES,
1874  WID_TE_SIGNS,
1876  WID_TE_HELP,
1877  };
1878  static const byte arrange_nopanel[] = {
1879  WID_TE_PAUSE,
1882  WID_TE_SAVE,
1890  WID_TE_ROADS,
1891  WID_TE_TRAMS,
1892  WID_TE_WATER,
1893  WID_TE_TREES,
1894  WID_TE_SIGNS,
1896  WID_TE_HELP,
1897  };
1898  static const byte arrange_switch[] = {
1904  WID_TE_ROADS,
1905  WID_TE_TRAMS,
1906  WID_TE_WATER,
1907  WID_TE_TREES,
1908  WID_TE_SIGNS,
1910  // lower toolbar
1911  WID_TE_PAUSE,
1914  WID_TE_SAVE,
1920  WID_TE_HELP,
1922  };
1923 
1924  /* If we can place all buttons *and* the panels, show them. */
1925  uint min_full_width = (lengthof(arrange_all) - lengthof(this->panel_widths)) * this->smallest_x + this->panel_widths[0] + this->panel_widths[1];
1926  if (width >= min_full_width) {
1927  width -= this->panel_widths[0] + this->panel_widths[1];
1928  arrangable_count = lengthof(arrange_all);
1929  button_count = arrangable_count - 2;
1930  spacer_count = this->spacers;
1931  return arrange_all;
1932  }
1933 
1934  /* 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 */
1935  uint min_small_width = (lengthof(arrange_switch) - lengthof(this->panel_widths)) * this->smallest_x / 2 + this->panel_widths[1];
1936  if (width > min_small_width) {
1937  width -= this->panel_widths[1];
1938  arrangable_count = lengthof(arrange_nopanel);
1939  button_count = arrangable_count - 1;
1940  spacer_count = this->spacers - 1;
1941  return arrange_nopanel;
1942  }
1943 
1944  /* Split toolbar */
1945  width -= this->panel_widths[1];
1946  arrangable_count = lengthof(arrange_switch) / 2;
1947  button_count = arrangable_count - 1;
1948  spacer_count = 0;
1949  return arrange_switch + ((_toolbar_mode == TB_LOWER) ? arrangable_count : 0);
1950  }
1951 };
1952 
1953 /* --- Toolbar handling for the 'normal' case */
1954 
1955 typedef CallBackFunction ToolbarButtonProc(Window *w);
1956 
1957 static ToolbarButtonProc * const _toolbar_button_procs[] = {
1958  ToolbarPauseClick,
1962  ToolbarMapClick,
1963  ToolbarTownClick,
1964  ToolbarSubsidiesClick,
1965  ToolbarStationsClick,
1966  ToolbarFinancesClick,
1967  ToolbarCompaniesClick,
1968  ToolbarStoryClick,
1969  ToolbarGoalClick,
1970  ToolbarGraphsClick,
1971  ToolbarLeagueClick,
1972  ToolbarIndustryClick,
1973  ToolbarTrainClick,
1974  ToolbarRoadClick,
1975  ToolbarShipClick,
1976  ToolbarAirClick,
1977  ToolbarZoomInClick,
1978  ToolbarZoomOutClick,
1979  ToolbarBuildRailClick,
1980  ToolbarBuildRoadClick,
1981  ToolbarBuildTramClick,
1982  ToolbarBuildWaterClick,
1983  ToolbarBuildAirClick,
1984  ToolbarForestClick,
1985  ToolbarMusicClick,
1986  ToolbarNewspaperClick,
1987  ToolbarHelpClick,
1988  ToolbarSwitchClick,
1989 };
1990 
1991 enum MainToolbarHotkeys {
1992  MTHK_PAUSE,
1993  MTHK_FASTFORWARD,
1994  MTHK_SETTINGS,
1995  MTHK_SAVEGAME,
1996  MTHK_LOADGAME,
1997  MTHK_SMALLMAP,
1998  MTHK_TOWNDIRECTORY,
1999  MTHK_SUBSIDIES,
2000  MTHK_STATIONS,
2001  MTHK_FINANCES,
2002  MTHK_COMPANIES,
2003  MTHK_STORY,
2004  MTHK_GOAL,
2005  MTHK_GRAPHS,
2006  MTHK_LEAGUE,
2007  MTHK_INDUSTRIES,
2008  MTHK_TRAIN_LIST,
2009  MTHK_ROADVEH_LIST,
2010  MTHK_SHIP_LIST,
2011  MTHK_AIRCRAFT_LIST,
2012  MTHK_ZOOM_IN,
2013  MTHK_ZOOM_OUT,
2014  MTHK_BUILD_RAIL,
2015  MTHK_BUILD_ROAD,
2016  MTHK_BUILD_TRAM,
2017  MTHK_BUILD_DOCKS,
2018  MTHK_BUILD_AIRPORT,
2019  MTHK_BUILD_TREES,
2020  MTHK_MUSIC,
2021  MTHK_AI_DEBUG,
2022  MTHK_SMALL_SCREENSHOT,
2023  MTHK_ZOOMEDIN_SCREENSHOT,
2024  MTHK_DEFAULTZOOM_SCREENSHOT,
2025  MTHK_GIANT_SCREENSHOT,
2026  MTHK_CHEATS,
2027  MTHK_TERRAFORM,
2028  MTHK_EXTRA_VIEWPORT,
2029  MTHK_CLIENT_LIST,
2030  MTHK_SIGN_LIST,
2031 };
2032 
2035  GUITimer timer;
2036 
2037  MainToolbarWindow(WindowDesc *desc) : Window(desc)
2038  {
2039  this->InitNested(0);
2040 
2041  _last_started_action = CBF_NONE;
2042  CLRBITS(this->flags, WF_WHITE_BORDER);
2043  this->SetWidgetDisabledState(WID_TN_PAUSE, _networking && !_network_server); // if not server, disable pause button
2044  this->SetWidgetDisabledState(WID_TN_FAST_FORWARD, _networking); // if networking, disable fast-forward button
2045  PositionMainToolbar(this);
2047 
2048  this->timer.SetInterval(MILLISECONDS_PER_TICK);
2049  }
2050 
2051  void FindWindowPlacementAndResize(int def_width, int def_height) override
2052  {
2054  }
2055 
2056  void OnPaint() override
2057  {
2058  /* If spectator, disable all construction buttons
2059  * ie : Build road, rail, ships, airports and landscaping
2060  * Since enabled state is the default, just disable when needed */
2062  /* disable company list drop downs, if there are no companies */
2064 
2065  this->SetWidgetDisabledState(WID_TN_GOAL, Goal::GetNumItems() == 0);
2066  this->SetWidgetDisabledState(WID_TN_STORY, StoryPage::GetNumItems() == 0);
2067 
2068  this->SetWidgetDisabledState(WID_TN_RAILS, !CanBuildVehicleInfrastructure(VEH_TRAIN));
2069  this->SetWidgetDisabledState(WID_TN_ROADS, !CanBuildVehicleInfrastructure(VEH_ROAD, RTT_ROAD));
2070  this->SetWidgetDisabledState(WID_TN_TRAMS, !CanBuildVehicleInfrastructure(VEH_ROAD, RTT_TRAM));
2071  this->SetWidgetDisabledState(WID_TN_AIR, !CanBuildVehicleInfrastructure(VEH_AIRCRAFT));
2072 
2073  this->DrawWidgets();
2074  }
2075 
2076  void OnClick(Point pt, int widget, int click_count) override
2077  {
2078  if (_game_mode != GM_MENU && !this->IsWidgetDisabled(widget)) _toolbar_button_procs[widget](this);
2079  }
2080 
2081  void OnDropdownSelect(int widget, int index) override
2082  {
2083  CallBackFunction cbf = _menu_clicked_procs[widget](index);
2084  if (cbf != CBF_NONE) _last_started_action = cbf;
2085  }
2086 
2087  EventState OnHotkey(int hotkey) override
2088  {
2089  switch (hotkey) {
2090  case MTHK_PAUSE: ToolbarPauseClick(this); break;
2091  case MTHK_FASTFORWARD: ToolbarFastForwardClick(this); break;
2092  case MTHK_SETTINGS: ShowGameOptions(); break;
2093  case MTHK_SAVEGAME: MenuClickSaveLoad(); break;
2094  case MTHK_LOADGAME: ShowSaveLoadDialog(FT_SAVEGAME, SLO_LOAD); break;
2095  case MTHK_SMALLMAP: ShowSmallMap(); break;
2096  case MTHK_TOWNDIRECTORY: ShowTownDirectory(); break;
2097  case MTHK_SUBSIDIES: ShowSubsidiesList(); break;
2098  case MTHK_STATIONS: ShowCompanyStations(_local_company); break;
2099  case MTHK_FINANCES: ShowCompanyFinances(_local_company); break;
2100  case MTHK_COMPANIES: ShowCompany(_local_company); break;
2101  case MTHK_STORY: ShowStoryBook(_local_company); break;
2102  case MTHK_GOAL: ShowGoalsList(_local_company); break;
2103  case MTHK_GRAPHS: ShowOperatingProfitGraph(); break;
2104  case MTHK_LEAGUE: ShowCompanyLeagueTable(); break;
2105  case MTHK_INDUSTRIES: ShowBuildIndustryWindow(); break;
2106  case MTHK_TRAIN_LIST: ShowVehicleListWindow(_local_company, VEH_TRAIN); break;
2107  case MTHK_ROADVEH_LIST: ShowVehicleListWindow(_local_company, VEH_ROAD); break;
2108  case MTHK_SHIP_LIST: ShowVehicleListWindow(_local_company, VEH_SHIP); break;
2109  case MTHK_AIRCRAFT_LIST: ShowVehicleListWindow(_local_company, VEH_AIRCRAFT); break;
2110  case MTHK_ZOOM_IN: ToolbarZoomInClick(this); break;
2111  case MTHK_ZOOM_OUT: ToolbarZoomOutClick(this); break;
2112  case MTHK_BUILD_RAIL: if (CanBuildVehicleInfrastructure(VEH_TRAIN)) ShowBuildRailToolbar(_last_built_railtype); break;
2113  case MTHK_BUILD_ROAD: ShowBuildRoadToolbar(_last_built_roadtype); break;
2114  case MTHK_BUILD_TRAM: if (CanBuildVehicleInfrastructure(VEH_ROAD, RTT_TRAM)) ShowBuildRoadToolbar(_last_built_tramtype); break;
2115  case MTHK_BUILD_DOCKS: ShowBuildDocksToolbar(); break;
2116  case MTHK_BUILD_AIRPORT: if (CanBuildVehicleInfrastructure(VEH_AIRCRAFT)) ShowBuildAirToolbar(); break;
2117  case MTHK_BUILD_TREES: ShowBuildTreesToolbar(); break;
2118  case MTHK_MUSIC: ShowMusicWindow(); break;
2119  case MTHK_AI_DEBUG: ShowAIDebugWindow(); break;
2120  case MTHK_SMALL_SCREENSHOT: MenuClickScreenshot(SC_VIEWPORT); break;
2121  case MTHK_ZOOMEDIN_SCREENSHOT: MenuClickScreenshot(SC_ZOOMEDIN); break;
2122  case MTHK_DEFAULTZOOM_SCREENSHOT: MenuClickScreenshot(SC_DEFAULTZOOM); break;
2123  case MTHK_GIANT_SCREENSHOT: MenuClickScreenshot(SC_WORLD); break;
2124  case MTHK_CHEATS: if (!_networking) ShowCheatWindow(); break;
2125  case MTHK_TERRAFORM: ShowTerraformToolbar(); break;
2126  case MTHK_EXTRA_VIEWPORT: ShowExtraViewPortWindowForTileUnderCursor(); break;
2127  case MTHK_CLIENT_LIST: if (_networking) ShowClientList(); break;
2128  case MTHK_SIGN_LIST: ShowSignList(); break;
2129  default: return ES_NOT_HANDLED;
2130  }
2131  return ES_HANDLED;
2132  }
2133 
2134  void OnPlaceObject(Point pt, TileIndex tile) override
2135  {
2136  switch (_last_started_action) {
2137  case CBF_PLACE_SIGN:
2138  PlaceProc_Sign(tile);
2139  break;
2140 
2141  case CBF_PLACE_LANDINFO:
2142  ShowLandInfo(tile);
2143  break;
2144 
2145  default: NOT_REACHED();
2146  }
2147  }
2148 
2149  void OnPlaceObjectAbort() override
2150  {
2151  _last_started_action = CBF_NONE;
2152  }
2153 
2154  void OnRealtimeTick(uint delta_ms) override
2155  {
2156  if (!this->timer.Elapsed(delta_ms)) return;
2157  this->timer.SetInterval(MILLISECONDS_PER_TICK);
2158 
2159  if (this->IsWidgetLowered(WID_TN_PAUSE) != !!_pause_mode) {
2160  this->ToggleWidgetLoweredState(WID_TN_PAUSE);
2161  this->SetWidgetDirty(WID_TN_PAUSE);
2162  }
2163 
2164  if (this->IsWidgetLowered(WID_TN_FAST_FORWARD) != !!_fast_forward) {
2165  this->ToggleWidgetLoweredState(WID_TN_FAST_FORWARD);
2166  this->SetWidgetDirty(WID_TN_FAST_FORWARD);
2167  }
2168  }
2169 
2170  void OnTimeout() override
2171  {
2172  /* We do not want to automatically raise the pause, fast forward and
2173  * switchbar buttons; they have to stay down when pressed etc. */
2174  for (uint i = WID_TN_SETTINGS; i < WID_TN_SWITCH_BAR; i++) {
2175  if (this->IsWidgetLowered(i)) {
2176  this->RaiseWidget(i);
2177  this->SetWidgetDirty(i);
2178  }
2179  }
2180  }
2181 
2187  void OnInvalidateData(int data = 0, bool gui_scope = true) override
2188  {
2189  if (!gui_scope) return;
2191  }
2192 
2193  static HotkeyList hotkeys;
2194 };
2195 
2196 const uint16 _maintoolbar_pause_keys[] = {WKC_F1, WKC_PAUSE, 0};
2197 const uint16 _maintoolbar_zoomin_keys[] = {WKC_NUM_PLUS, WKC_EQUALS, WKC_SHIFT | WKC_EQUALS, WKC_SHIFT | WKC_F5, 0};
2198 const uint16 _maintoolbar_zoomout_keys[] = {WKC_NUM_MINUS, WKC_MINUS, WKC_SHIFT | WKC_MINUS, WKC_SHIFT | WKC_F6, 0};
2199 const uint16 _maintoolbar_smallmap_keys[] = {WKC_F4, 'M', 0};
2200 
2201 static Hotkey maintoolbar_hotkeys[] = {
2202  Hotkey(_maintoolbar_pause_keys, "pause", MTHK_PAUSE),
2203  Hotkey((uint16)0, "fastforward", MTHK_FASTFORWARD),
2204  Hotkey(WKC_F2, "settings", MTHK_SETTINGS),
2205  Hotkey(WKC_F3, "saveload", MTHK_SAVEGAME),
2206  Hotkey((uint16)0, "load_game", MTHK_LOADGAME),
2207  Hotkey(_maintoolbar_smallmap_keys, "smallmap", MTHK_SMALLMAP),
2208  Hotkey(WKC_F5, "town_list", MTHK_TOWNDIRECTORY),
2209  Hotkey(WKC_F6, "subsidies", MTHK_SUBSIDIES),
2210  Hotkey(WKC_F7, "station_list", MTHK_STATIONS),
2211  Hotkey(WKC_F8, "finances", MTHK_FINANCES),
2212  Hotkey(WKC_F9, "companies", MTHK_COMPANIES),
2213  Hotkey((uint16)0, "story_book", MTHK_STORY),
2214  Hotkey((uint16)0, "goal_list", MTHK_GOAL),
2215  Hotkey(WKC_F10, "graphs", MTHK_GRAPHS),
2216  Hotkey(WKC_F11, "league", MTHK_LEAGUE),
2217  Hotkey(WKC_F12, "industry_list", MTHK_INDUSTRIES),
2218  Hotkey(WKC_SHIFT | WKC_F1, "train_list", MTHK_TRAIN_LIST),
2219  Hotkey(WKC_SHIFT | WKC_F2, "roadveh_list", MTHK_ROADVEH_LIST),
2220  Hotkey(WKC_SHIFT | WKC_F3, "ship_list", MTHK_SHIP_LIST),
2221  Hotkey(WKC_SHIFT | WKC_F4, "aircraft_list", MTHK_AIRCRAFT_LIST),
2222  Hotkey(_maintoolbar_zoomin_keys, "zoomin", MTHK_ZOOM_IN),
2223  Hotkey(_maintoolbar_zoomout_keys, "zoomout", MTHK_ZOOM_OUT),
2224  Hotkey(WKC_SHIFT | WKC_F7, "build_rail", MTHK_BUILD_RAIL),
2225  Hotkey(WKC_SHIFT | WKC_F8, "build_road", MTHK_BUILD_ROAD),
2226  Hotkey((uint16)0, "build_tram", MTHK_BUILD_TRAM),
2227  Hotkey(WKC_SHIFT | WKC_F9, "build_docks", MTHK_BUILD_DOCKS),
2228  Hotkey(WKC_SHIFT | WKC_F10, "build_airport", MTHK_BUILD_AIRPORT),
2229  Hotkey(WKC_SHIFT | WKC_F11, "build_trees", MTHK_BUILD_TREES),
2230  Hotkey(WKC_SHIFT | WKC_F12, "music", MTHK_MUSIC),
2231  Hotkey((uint16)0, "ai_debug", MTHK_AI_DEBUG),
2232  Hotkey(WKC_CTRL | 'S', "small_screenshot", MTHK_SMALL_SCREENSHOT),
2233  Hotkey(WKC_CTRL | 'P', "zoomedin_screenshot", MTHK_ZOOMEDIN_SCREENSHOT),
2234  Hotkey(WKC_CTRL | 'D', "defaultzoom_screenshot", MTHK_DEFAULTZOOM_SCREENSHOT),
2235  Hotkey((uint16)0, "giant_screenshot", MTHK_GIANT_SCREENSHOT),
2236  Hotkey(WKC_CTRL | WKC_ALT | 'C', "cheats", MTHK_CHEATS),
2237  Hotkey('L', "terraform", MTHK_TERRAFORM),
2238  Hotkey('V', "extra_viewport", MTHK_EXTRA_VIEWPORT),
2239  Hotkey((uint16)0, "client_list", MTHK_CLIENT_LIST),
2240  Hotkey((uint16)0, "sign_list", MTHK_SIGN_LIST),
2241  HOTKEY_LIST_END
2242 };
2243 HotkeyList MainToolbarWindow::hotkeys("maintoolbar", maintoolbar_hotkeys);
2244 
2245 static NWidgetBase *MakeMainToolbar(int *biggest_index)
2246 {
2248  static const SpriteID toolbar_button_sprites[] = {
2249  SPR_IMG_PAUSE, // WID_TN_PAUSE
2250  SPR_IMG_FASTFORWARD, // WID_TN_FAST_FORWARD
2251  SPR_IMG_SETTINGS, // WID_TN_SETTINGS
2252  SPR_IMG_SAVE, // WID_TN_SAVE
2253  SPR_IMG_SMALLMAP, // WID_TN_SMALL_MAP
2254  SPR_IMG_TOWN, // WID_TN_TOWNS
2255  SPR_IMG_SUBSIDIES, // WID_TN_SUBSIDIES
2256  SPR_IMG_COMPANY_LIST, // WID_TN_STATIONS
2257  SPR_IMG_COMPANY_FINANCE, // WID_TN_FINANCES
2258  SPR_IMG_COMPANY_GENERAL, // WID_TN_COMPANIES
2259  SPR_IMG_STORY_BOOK, // WID_TN_STORY
2260  SPR_IMG_GOAL, // WID_TN_GOAL
2261  SPR_IMG_GRAPHS, // WID_TN_GRAPHS
2262  SPR_IMG_COMPANY_LEAGUE, // WID_TN_LEAGUE
2263  SPR_IMG_INDUSTRY, // WID_TN_INDUSTRIES
2264  SPR_IMG_TRAINLIST, // WID_TN_TRAINS
2265  SPR_IMG_TRUCKLIST, // WID_TN_ROADVEHS
2266  SPR_IMG_SHIPLIST, // WID_TN_SHIPS
2267  SPR_IMG_AIRPLANESLIST, // WID_TN_AIRCRAFT
2268  SPR_IMG_ZOOMIN, // WID_TN_ZOOMIN
2269  SPR_IMG_ZOOMOUT, // WID_TN_ZOOMOUT
2270  SPR_IMG_BUILDRAIL, // WID_TN_RAILS
2271  SPR_IMG_BUILDROAD, // WID_TN_ROADS
2272  SPR_IMG_BUILDTRAMS, // WID_TN_TRAMS
2273  SPR_IMG_BUILDWATER, // WID_TN_WATER
2274  SPR_IMG_BUILDAIR, // WID_TN_AIR
2275  SPR_IMG_LANDSCAPING, // WID_TN_LANDSCAPE
2276  SPR_IMG_MUSIC, // WID_TN_MUSIC_SOUND
2277  SPR_IMG_MESSAGES, // WID_TN_MESSAGES
2278  SPR_IMG_QUERY, // WID_TN_HELP
2279  SPR_IMG_SWITCH_TOOLBAR, // WID_TN_SWITCH_BAR
2280  };
2281 
2283  for (uint i = 0; i < WID_TN_END; i++) {
2284  switch (i) {
2285  case WID_TN_SMALL_MAP:
2286  case WID_TN_FINANCES:
2287  case WID_TN_VEHICLE_START:
2288  case WID_TN_ZOOM_IN:
2290  case WID_TN_MUSIC_SOUND:
2291  hor->Add(new NWidgetSpacer(0, 0));
2292  break;
2293  }
2294  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));
2295  }
2296 
2297  *biggest_index = max<int>(*biggest_index, WID_TN_SWITCH_BAR);
2298  return hor;
2299 }
2300 
2301 static const NWidgetPart _nested_toolbar_normal_widgets[] = {
2303 };
2304 
2305 static WindowDesc _toolb_normal_desc(
2306  WDP_MANUAL, nullptr, 0, 0,
2308  WDF_NO_FOCUS,
2309  _nested_toolbar_normal_widgets, lengthof(_nested_toolbar_normal_widgets),
2310  &MainToolbarWindow::hotkeys
2311 );
2312 
2313 
2314 /* --- Toolbar handling for the scenario editor */
2315 
2316 static MenuClickedProc * const _scen_toolbar_dropdown_procs[] = {
2317  nullptr, // 0
2318  nullptr, // 1
2319  MenuClickSettings, // 2
2320  MenuClickSaveLoad, // 3
2321  nullptr, // 4
2322  nullptr, // 5
2323  nullptr, // 6
2324  nullptr, // 7
2325  MenuClickMap, // 8
2326  nullptr, // 9
2327  nullptr, // 10
2328  nullptr, // 11
2329  nullptr, // 12
2330  nullptr, // 13
2331  ToolbarScenBuildRoad, // 14
2332  ToolbarScenBuildTram, // 15
2333  nullptr, // 16
2334  nullptr, // 17
2335  nullptr, // 18
2336  nullptr, // 19
2337  MenuClickMusicWindow, // 20
2338  MenuClickHelp, // 21
2339  nullptr, // 22
2340 };
2341 
2342 static ToolbarButtonProc * const _scen_toolbar_button_procs[] = {
2343  ToolbarPauseClick,
2347  ToolbarBtn_NULL,
2349  ToolbarScenDateBackward,
2350  ToolbarScenDateForward,
2351  ToolbarScenMapTownDir,
2352  ToolbarZoomInClick,
2353  ToolbarZoomOutClick,
2354  ToolbarScenGenLand,
2355  ToolbarScenGenTown,
2356  ToolbarScenGenIndustry,
2357  ToolbarScenBuildRoadClick,
2358  ToolbarScenBuildTramClick,
2359  ToolbarScenBuildDocks,
2360  ToolbarScenPlantTrees,
2361  ToolbarScenPlaceSign,
2362  ToolbarBtn_NULL,
2363  ToolbarMusicClick,
2364  ToolbarHelpClick,
2365  ToolbarSwitchClick,
2366 };
2367 
2368 enum MainToolbarEditorHotkeys {
2369  MTEHK_PAUSE,
2370  MTEHK_FASTFORWARD,
2371  MTEHK_SETTINGS,
2372  MTEHK_SAVEGAME,
2373  MTEHK_GENLAND,
2374  MTEHK_GENTOWN,
2375  MTEHK_GENINDUSTRY,
2376  MTEHK_BUILD_ROAD,
2377  MTEHK_BUILD_TRAM,
2378  MTEHK_BUILD_DOCKS,
2379  MTEHK_BUILD_TREES,
2380  MTEHK_SIGN,
2381  MTEHK_MUSIC,
2382  MTEHK_LANDINFO,
2383  MTEHK_SMALL_SCREENSHOT,
2384  MTEHK_ZOOMEDIN_SCREENSHOT,
2385  MTEHK_DEFAULTZOOM_SCREENSHOT,
2386  MTEHK_GIANT_SCREENSHOT,
2387  MTEHK_ZOOM_IN,
2388  MTEHK_ZOOM_OUT,
2389  MTEHK_TERRAFORM,
2390  MTEHK_SMALLMAP,
2391  MTEHK_EXTRA_VIEWPORT,
2392 };
2393 
2395  GUITimer timer;
2396 
2398  {
2399  this->InitNested(0);
2400 
2401  _last_started_action = CBF_NONE;
2402  CLRBITS(this->flags, WF_WHITE_BORDER);
2403  PositionMainToolbar(this);
2405 
2406  this->timer.SetInterval(MILLISECONDS_PER_TICK);
2407  }
2408 
2409  void FindWindowPlacementAndResize(int def_width, int def_height) override
2410  {
2412  }
2413 
2414  void OnPaint() override
2415  {
2416  this->SetWidgetDisabledState(WID_TE_DATE_BACKWARD, _settings_game.game_creation.starting_year <= MIN_YEAR);
2417  this->SetWidgetDisabledState(WID_TE_DATE_FORWARD, _settings_game.game_creation.starting_year >= MAX_YEAR);
2418  this->SetWidgetDisabledState(WID_TE_ROADS, (GetRoadTypes(true) & ~_roadtypes_type) == ROADTYPES_NONE);
2419  this->SetWidgetDisabledState(WID_TE_TRAMS, (GetRoadTypes(true) & _roadtypes_type) == ROADTYPES_NONE);
2420 
2421  this->DrawWidgets();
2422  }
2423 
2424  void DrawWidget(const Rect &r, int widget) const override
2425  {
2426  switch (widget) {
2427  case WID_TE_DATE:
2429  DrawString(r.left, r.right, (this->height - FONT_HEIGHT_NORMAL) / 2, STR_WHITE_DATE_LONG, TC_FROMSTRING, SA_HOR_CENTER);
2430  break;
2431 
2432  case WID_TE_SPACER: {
2433  int height = r.bottom - r.top;
2434  if (height > 2 * FONT_HEIGHT_NORMAL) {
2435  DrawString(r.left, r.right, (height + 1) / 2 - FONT_HEIGHT_NORMAL, STR_SCENEDIT_TOOLBAR_OPENTTD, TC_FROMSTRING, SA_HOR_CENTER);
2436  DrawString(r.left, r.right, (height + 1) / 2, STR_SCENEDIT_TOOLBAR_SCENARIO_EDITOR, TC_FROMSTRING, SA_HOR_CENTER);
2437  } else {
2438  DrawString(r.left, r.right, (height - FONT_HEIGHT_NORMAL) / 2, STR_SCENEDIT_TOOLBAR_SCENARIO_EDITOR, TC_FROMSTRING, SA_HOR_CENTER);
2439  }
2440  break;
2441  }
2442  }
2443  }
2444 
2445  void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
2446  {
2447  switch (widget) {
2448  case WID_TE_SPACER:
2449  size->width = max(GetStringBoundingBox(STR_SCENEDIT_TOOLBAR_OPENTTD).width, GetStringBoundingBox(STR_SCENEDIT_TOOLBAR_SCENARIO_EDITOR).width) + WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT;
2450  break;
2451 
2452  case WID_TE_DATE:
2453  SetDParam(0, ConvertYMDToDate(MAX_YEAR, 0, 1));
2454  *size = GetStringBoundingBox(STR_WHITE_DATE_LONG);
2455  size->height = max(size->height, GetSpriteSize(SPR_IMG_SAVE).height + WD_IMGBTN_TOP + WD_IMGBTN_BOTTOM);
2456  break;
2457  }
2458  }
2459 
2460  void OnClick(Point pt, int widget, int click_count) override
2461  {
2462  if (_game_mode == GM_MENU) return;
2463  CallBackFunction cbf = _scen_toolbar_button_procs[widget](this);
2464  if (cbf != CBF_NONE) _last_started_action = cbf;
2465  }
2466 
2467  void OnDropdownSelect(int widget, int index) override
2468  {
2469  CallBackFunction cbf = _scen_toolbar_dropdown_procs[widget](index);
2470  if (cbf != CBF_NONE) _last_started_action = cbf;
2471  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
2472  }
2473 
2474  EventState OnHotkey(int hotkey) override
2475  {
2476  CallBackFunction cbf = CBF_NONE;
2477  switch (hotkey) {
2478  case MTEHK_PAUSE: ToolbarPauseClick(this); break;
2479  case MTEHK_FASTFORWARD: ToolbarFastForwardClick(this); break;
2480  case MTEHK_SETTINGS: ShowGameOptions(); break;
2481  case MTEHK_SAVEGAME: MenuClickSaveLoad(); break;
2482  case MTEHK_GENLAND: ToolbarScenGenLand(this); break;
2483  case MTEHK_GENTOWN: ToolbarScenGenTown(this); break;
2484  case MTEHK_GENINDUSTRY: ToolbarScenGenIndustry(this); break;
2485  case MTEHK_BUILD_ROAD: ToolbarScenBuildRoadClick(this); break;
2486  case MTEHK_BUILD_TRAM: ToolbarScenBuildTramClick(this); break;
2487  case MTEHK_BUILD_DOCKS: ToolbarScenBuildDocks(this); break;
2488  case MTEHK_BUILD_TREES: ToolbarScenPlantTrees(this); break;
2489  case MTEHK_SIGN: cbf = ToolbarScenPlaceSign(this); break;
2490  case MTEHK_MUSIC: ShowMusicWindow(); break;
2491  case MTEHK_LANDINFO: cbf = PlaceLandBlockInfo(); break;
2492  case MTEHK_SMALL_SCREENSHOT: MenuClickScreenshot(SC_VIEWPORT); break;
2493  case MTEHK_ZOOMEDIN_SCREENSHOT: MenuClickScreenshot(SC_ZOOMEDIN); break;
2494  case MTEHK_DEFAULTZOOM_SCREENSHOT: MenuClickScreenshot(SC_DEFAULTZOOM); break;
2495  case MTEHK_GIANT_SCREENSHOT: MenuClickScreenshot(SC_WORLD); break;
2496  case MTEHK_ZOOM_IN: ToolbarZoomInClick(this); break;
2497  case MTEHK_ZOOM_OUT: ToolbarZoomOutClick(this); break;
2498  case MTEHK_TERRAFORM: ShowEditorTerraformToolbar(); break;
2499  case MTEHK_SMALLMAP: ShowSmallMap(); break;
2500  case MTEHK_EXTRA_VIEWPORT: ShowExtraViewPortWindowForTileUnderCursor(); break;
2501  default: return ES_NOT_HANDLED;
2502  }
2503  if (cbf != CBF_NONE) _last_started_action = cbf;
2504  return ES_HANDLED;
2505  }
2506 
2507  void OnPlaceObject(Point pt, TileIndex tile) override
2508  {
2509  switch (_last_started_action) {
2510  case CBF_PLACE_SIGN:
2511  PlaceProc_Sign(tile);
2512  break;
2513 
2514  case CBF_PLACE_LANDINFO:
2515  ShowLandInfo(tile);
2516  break;
2517 
2518  default: NOT_REACHED();
2519  }
2520  }
2521 
2522  void OnPlaceObjectAbort() override
2523  {
2524  _last_started_action = CBF_NONE;
2525  }
2526 
2527  void OnTimeout() override
2528  {
2529  this->SetWidgetsLoweredState(false, WID_TE_DATE_BACKWARD, WID_TE_DATE_FORWARD, WIDGET_LIST_END);
2530  this->SetWidgetDirty(WID_TE_DATE_BACKWARD);
2531  this->SetWidgetDirty(WID_TE_DATE_FORWARD);
2532  }
2533 
2534  void OnRealtimeTick(uint delta_ms) override
2535  {
2536  if (!this->timer.Elapsed(delta_ms)) return;
2537  this->timer.SetInterval(MILLISECONDS_PER_TICK);
2538 
2539  if (this->IsWidgetLowered(WID_TE_PAUSE) != !!_pause_mode) {
2540  this->ToggleWidgetLoweredState(WID_TE_PAUSE);
2541  this->SetDirty();
2542  }
2543 
2544  if (this->IsWidgetLowered(WID_TE_FAST_FORWARD) != !!_fast_forward) {
2545  this->ToggleWidgetLoweredState(WID_TE_FAST_FORWARD);
2546  this->SetDirty();
2547  }
2548  }
2549 
2555  void OnInvalidateData(int data = 0, bool gui_scope = true) override
2556  {
2557  if (!gui_scope) return;
2559  }
2560 
2561  void OnQueryTextFinished(char *str) override
2562  {
2563  /* Was 'cancel' pressed? */
2564  if (str == nullptr) return;
2565 
2566  int32 value;
2567  if (!StrEmpty(str)) {
2568  value = atoi(str);
2569  } else {
2570  /* An empty string means revert to the default */
2571  value = DEF_START_YEAR;
2572  }
2573  SetStartingYear(value);
2574 
2575  this->SetDirty();
2576  }
2577 
2578  static HotkeyList hotkeys;
2579 };
2580 
2581 static Hotkey scenedit_maintoolbar_hotkeys[] = {
2582  Hotkey(_maintoolbar_pause_keys, "pause", MTEHK_PAUSE),
2583  Hotkey((uint16)0, "fastforward", MTEHK_FASTFORWARD),
2584  Hotkey(WKC_F2, "settings", MTEHK_SETTINGS),
2585  Hotkey(WKC_F3, "saveload", MTEHK_SAVEGAME),
2586  Hotkey(WKC_F4, "gen_land", MTEHK_GENLAND),
2587  Hotkey(WKC_F5, "gen_town", MTEHK_GENTOWN),
2588  Hotkey(WKC_F6, "gen_industry", MTEHK_GENINDUSTRY),
2589  Hotkey(WKC_F7, "build_road", MTEHK_BUILD_ROAD),
2590  Hotkey((uint16)0, "build_tram", MTEHK_BUILD_TRAM),
2591  Hotkey(WKC_F8, "build_docks", MTEHK_BUILD_DOCKS),
2592  Hotkey(WKC_F9, "build_trees", MTEHK_BUILD_TREES),
2593  Hotkey(WKC_F10, "build_sign", MTEHK_SIGN),
2594  Hotkey(WKC_F11, "music", MTEHK_MUSIC),
2595  Hotkey(WKC_F12, "land_info", MTEHK_LANDINFO),
2596  Hotkey(WKC_CTRL | 'S', "small_screenshot", MTEHK_SMALL_SCREENSHOT),
2597  Hotkey(WKC_CTRL | 'P', "zoomedin_screenshot", MTEHK_ZOOMEDIN_SCREENSHOT),
2598  Hotkey(WKC_CTRL | 'D', "defaultzoom_screenshot", MTEHK_DEFAULTZOOM_SCREENSHOT),
2599  Hotkey((uint16)0, "giant_screenshot", MTEHK_GIANT_SCREENSHOT),
2600  Hotkey(_maintoolbar_zoomin_keys, "zoomin", MTEHK_ZOOM_IN),
2601  Hotkey(_maintoolbar_zoomout_keys, "zoomout", MTEHK_ZOOM_OUT),
2602  Hotkey('L', "terraform", MTEHK_TERRAFORM),
2603  Hotkey('M', "smallmap", MTEHK_SMALLMAP),
2604  Hotkey('V', "extra_viewport", MTEHK_EXTRA_VIEWPORT),
2605  HOTKEY_LIST_END
2606 };
2607 HotkeyList ScenarioEditorToolbarWindow::hotkeys("scenedit_maintoolbar", scenedit_maintoolbar_hotkeys);
2608 
2609 static const NWidgetPart _nested_toolb_scen_inner_widgets[] = {
2610  NWidget(WWT_IMGBTN, COLOUR_GREY, WID_TE_PAUSE), SetDataTip(SPR_IMG_PAUSE, STR_TOOLBAR_TOOLTIP_PAUSE_GAME),
2611  NWidget(WWT_IMGBTN, COLOUR_GREY, WID_TE_FAST_FORWARD), SetDataTip(SPR_IMG_FASTFORWARD, STR_TOOLBAR_TOOLTIP_FORWARD),
2612  NWidget(WWT_IMGBTN, COLOUR_GREY, WID_TE_SETTINGS), SetDataTip(SPR_IMG_SETTINGS, STR_TOOLBAR_TOOLTIP_OPTIONS),
2613  NWidget(WWT_IMGBTN_2, COLOUR_GREY, WID_TE_SAVE), SetDataTip(SPR_IMG_SAVE, STR_SCENEDIT_TOOLBAR_TOOLTIP_SAVE_SCENARIO_LOAD_SCENARIO),
2615  NWidget(WWT_PANEL, COLOUR_GREY, WID_TE_SPACER), EndContainer(),
2617  NWidget(WWT_PANEL, COLOUR_GREY, WID_TE_DATE_PANEL),
2618  NWidget(NWID_HORIZONTAL), SetPIP(3, 2, 3),
2619  NWidget(WWT_IMGBTN, COLOUR_GREY, WID_TE_DATE_BACKWARD), SetDataTip(SPR_ARROW_DOWN, STR_SCENEDIT_TOOLBAR_TOOLTIP_MOVE_THE_STARTING_DATE_BACKWARD),
2620  NWidget(WWT_EMPTY, COLOUR_GREY, WID_TE_DATE), SetDataTip(STR_NULL, STR_SCENEDIT_TOOLBAR_TOOLTIP_SET_DATE),
2621  NWidget(WWT_IMGBTN, COLOUR_GREY, WID_TE_DATE_FORWARD), SetDataTip(SPR_ARROW_UP, STR_SCENEDIT_TOOLBAR_TOOLTIP_MOVE_THE_STARTING_DATE_FORWARD),
2622  EndContainer(),
2623  EndContainer(),
2625  NWidget(WWT_IMGBTN, COLOUR_GREY, WID_TE_SMALL_MAP), SetDataTip(SPR_IMG_SMALLMAP, STR_SCENEDIT_TOOLBAR_TOOLTIP_DISPLAY_MAP_TOWN_DIRECTORY),
2627  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_TE_ZOOM_IN), SetDataTip(SPR_IMG_ZOOMIN, STR_TOOLBAR_TOOLTIP_ZOOM_THE_VIEW_IN),
2628  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_TE_ZOOM_OUT), SetDataTip(SPR_IMG_ZOOMOUT, STR_TOOLBAR_TOOLTIP_ZOOM_THE_VIEW_OUT),
2630  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_TE_LAND_GENERATE), SetDataTip(SPR_IMG_LANDSCAPING, STR_SCENEDIT_TOOLBAR_LANDSCAPE_GENERATION),
2631  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_TE_TOWN_GENERATE), SetDataTip(SPR_IMG_TOWN, STR_SCENEDIT_TOOLBAR_TOWN_GENERATION),
2632  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_TE_INDUSTRY), SetDataTip(SPR_IMG_INDUSTRY, STR_SCENEDIT_TOOLBAR_INDUSTRY_GENERATION),
2633  NWidget(WWT_IMGBTN, COLOUR_GREY, WID_TE_ROADS), SetDataTip(SPR_IMG_BUILDROAD, STR_SCENEDIT_TOOLBAR_ROAD_CONSTRUCTION),
2634  NWidget(WWT_IMGBTN, COLOUR_GREY, WID_TE_TRAMS), SetDataTip(SPR_IMG_BUILDTRAMS, STR_SCENEDIT_TOOLBAR_TRAM_CONSTRUCTION),
2635  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_TE_WATER), SetDataTip(SPR_IMG_BUILDWATER, STR_TOOLBAR_TOOLTIP_BUILD_SHIP_DOCKS),
2636  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_TE_TREES), SetDataTip(SPR_IMG_PLANTTREES, STR_SCENEDIT_TOOLBAR_PLANT_TREES),
2637  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_TE_SIGNS), SetDataTip(SPR_IMG_SIGN, STR_SCENEDIT_TOOLBAR_PLACE_SIGN),
2639  NWidget(WWT_IMGBTN, COLOUR_GREY, WID_TE_MUSIC_SOUND), SetDataTip(SPR_IMG_MUSIC, STR_TOOLBAR_TOOLTIP_SHOW_SOUND_MUSIC_WINDOW),
2640  NWidget(WWT_IMGBTN, COLOUR_GREY, WID_TE_HELP), SetDataTip(SPR_IMG_QUERY, STR_TOOLBAR_TOOLTIP_LAND_BLOCK_INFORMATION),
2641  NWidget(WWT_IMGBTN, COLOUR_GREY, WID_TE_SWITCH_BAR), SetDataTip(SPR_IMG_SWITCH_TOOLBAR, STR_TOOLBAR_TOOLTIP_SWITCH_TOOLBAR),
2642 };
2643 
2644 static NWidgetBase *MakeScenarioToolbar(int *biggest_index)
2645 {
2646  return MakeNWidgets(_nested_toolb_scen_inner_widgets, lengthof(_nested_toolb_scen_inner_widgets), biggest_index, new NWidgetScenarioToolbarContainer());
2647 }
2648 
2649 static const NWidgetPart _nested_toolb_scen_widgets[] = {
2650  NWidgetFunction(MakeScenarioToolbar),
2651 };
2652 
2653 static WindowDesc _toolb_scen_desc(
2654  WDP_MANUAL, nullptr, 0, 0,
2656  WDF_NO_FOCUS,
2657  _nested_toolb_scen_widgets, lengthof(_nested_toolb_scen_widgets),
2658  &ScenarioEditorToolbarWindow::hotkeys
2659 );
2660 
2663 {
2664  /* Clean old GUI values; railtype is (re)set by rail_gui.cpp */
2665  _last_built_roadtype = ROADTYPE_ROAD;
2666  _last_built_tramtype = ROADTYPE_TRAM;
2667 
2668  if (_game_mode == GM_EDITOR) {
2669  new ScenarioEditorToolbarWindow(&_toolb_scen_desc);
2670  } else {
2671  new MainToolbarWindow(&_toolb_normal_desc);
2672  }
2673 }
EventState
State of handling an event.
Definition: window_type.h:717
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:80
used in multiplayer to create a new companies etc.
Definition: command_type.h:280
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:1133
The passed event is not handled.
Definition: window_type.h:719
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:3505
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
static void MenuClickScreenshot(ScreenshotType t)
Make a screenshot of the world.
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
GUI functions related to screenshots.
void ShowAIConfigWindow()
Open the AI config window.
Definition: ai_gui.cpp:972
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:3416
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:79
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:713
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:3337
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:38
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:85
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:177
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:79
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:91
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:636
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:536
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:1535
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:840
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:838
static const uint8 PC_VERY_DARK_RED
Almost-black red palette colour.
Definition: gfx_func.h:209
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:210
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:378
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:918
uint _toolbar_width
Width of the toolbar, shared by statusbar.
Definition: toolbar_gui.cpp:63
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:359
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:69
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:908
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:318
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:1525
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:72
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:718
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:150
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:27
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:94
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:973
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 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:1600
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:255