OpenTTD
toolbar_gui.cpp
Go to the documentation of this file.
1 /* $Id$ */
2 
3 /*
4  * This file is part of OpenTTD.
5  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
6  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
8  */
9 
12 #include "stdafx.h"
13 #include "gui.h"
14 #include "window_gui.h"
15 #include "window_func.h"
16 #include "viewport_func.h"
17 #include "command_func.h"
18 #include "vehicle_gui.h"
19 #include "rail_gui.h"
20 #include "road.h"
21 #include "road_gui.h"
22 #include "date_func.h"
23 #include "vehicle_func.h"
24 #include "sound_func.h"
25 #include "terraform_gui.h"
26 #include "strings_func.h"
27 #include "company_func.h"
28 #include "company_gui.h"
29 #include "vehicle_base.h"
30 #include "cheat_func.h"
31 #include "transparency_gui.h"
32 #include "screenshot.h"
33 #include "signs_func.h"
34 #include "fios.h"
35 #include "console_gui.h"
36 #include "news_gui.h"
37 #include "ai/ai_gui.hpp"
38 #include "tilehighlight_func.h"
39 #include "smallmap_gui.h"
40 #include "graph_gui.h"
41 #include "textbuf_gui.h"
43 #include "newgrf_debug.h"
44 #include "hotkeys.h"
45 #include "engine_base.h"
46 #include "highscore.h"
47 #include "game/game.hpp"
48 #include "goal_base.h"
49 #include "story_base.h"
50 #include "toolbar_gui.h"
51 #include "framerate_type.h"
52 #include "guitimer_func.h"
53 
54 #include "widgets/toolbar_widget.h"
55 
56 #include "network/network.h"
57 #include "network/network_gui.h"
58 #include "network/network_func.h"
59 
60 #include "safeguards.h"
61 
62 
64 uint _toolbar_width = 0;
65 
66 RailType _last_built_railtype;
67 RoadType _last_built_roadtype;
68 RoadType _last_built_tramtype;
69 
71 
74  TB_NORMAL,
75  TB_UPPER,
76  TB_LOWER
77 };
78 
81  CBF_NONE,
82  CBF_PLACE_SIGN,
83  CBF_PLACE_LANDINFO,
84 };
85 
87 
88 
93  uint checkmark_width;
94 public:
95  bool checked;
96 
97  DropDownListCheckedItem(StringID string, int result, bool masked, bool checked) : DropDownListStringItem(string, result, masked), checked(checked)
98  {
99  this->checkmark_width = GetStringBoundingBox(STR_JUST_CHECKMARK).width + 3;
100  }
101 
102  uint Width() const
103  {
104  return DropDownListStringItem::Width() + this->checkmark_width;
105  }
106 
107  void Draw(int left, int right, int top, int bottom, bool sel, Colours bg_colour) const
108  {
109  bool rtl = _current_text_dir == TD_RTL;
110  if (this->checked) {
111  DrawString(left + WD_FRAMERECT_LEFT, right - WD_FRAMERECT_RIGHT, top, STR_JUST_CHECKMARK, sel ? TC_WHITE : TC_BLACK);
112  }
113  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);
114  }
115 };
116 
121  Dimension icon_size;
122  Dimension lock_size;
123 public:
124  bool greyed;
125 
126  DropDownListCompanyItem(int result, bool masked, bool greyed) : DropDownListItem(result, masked), greyed(greyed)
127  {
128  this->icon_size = GetSpriteSize(SPR_COMPANY_ICON);
129  this->lock_size = GetSpriteSize(SPR_LOCK);
130  }
131 
132  bool Selectable() const override
133  {
134  return true;
135  }
136 
137  uint Width() const override
138  {
139  CompanyID company = (CompanyID)this->result;
140  SetDParam(0, company);
141  SetDParam(1, company);
142  return GetStringBoundingBox(STR_COMPANY_NAME_COMPANY_NUM).width + this->icon_size.width + this->lock_size.width + 6;
143  }
144 
145  uint Height(uint width) const override
146  {
147  return max(max(this->icon_size.height, this->lock_size.height) + 2U, (uint)FONT_HEIGHT_NORMAL);
148  }
149 
150  void Draw(int left, int right, int top, int bottom, bool sel, Colours bg_colour) const override
151  {
152  CompanyID company = (CompanyID)this->result;
153  bool rtl = _current_text_dir == TD_RTL;
154 
155  /* It's possible the company is deleted while the dropdown is open */
156  if (!Company::IsValidID(company)) return;
157 
158  int icon_offset = (bottom - top - icon_size.height) / 2;
159  int text_offset = (bottom - top - FONT_HEIGHT_NORMAL) / 2;
160  int lock_offset = (bottom - top - lock_size.height) / 2;
161 
162  DrawCompanyIcon(company, rtl ? right - this->icon_size.width - WD_FRAMERECT_RIGHT : left + WD_FRAMERECT_LEFT, top + icon_offset);
163  if (NetworkCompanyIsPassworded(company)) {
164  DrawSprite(SPR_LOCK, PAL_NONE, rtl ? left + WD_FRAMERECT_LEFT : right - this->lock_size.width - WD_FRAMERECT_RIGHT, top + lock_offset);
165  }
166 
167  SetDParam(0, company);
168  SetDParam(1, company);
169  TextColour col;
170  if (this->greyed) {
171  col = (sel ? TC_SILVER : TC_GREY) | TC_NO_SHADE;
172  } else {
173  col = sel ? TC_WHITE : TC_BLACK;
174  }
175  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);
176  }
177 };
178 
186 static void PopupMainToolbMenu(Window *w, int widget, DropDownList &&list, int def)
187 {
188  ShowDropDownList(w, std::move(list), def, widget, 0, true, true);
189  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
190 }
191 
199 static void PopupMainToolbMenu(Window *w, int widget, StringID string, int count)
200 {
201  DropDownList list;
202  for (int i = 0; i < count; i++) {
203  list.emplace_back(new DropDownListStringItem(string + i, i, false));
204  }
205  PopupMainToolbMenu(w, widget, std::move(list), 0);
206 }
207 
209 static const int CTMN_CLIENT_LIST = -1;
210 static const int CTMN_NEW_COMPANY = -2;
211 static const int CTMN_SPECTATE = -3;
212 static const int CTMN_SPECTATOR = -4;
213 
220 static void PopupMainCompanyToolbMenu(Window *w, int widget, int grey = 0)
221 {
222  DropDownList list;
223 
224  switch (widget) {
225  case WID_TN_COMPANIES:
226  if (!_networking) break;
227 
228  /* Add the client list button for the companies menu */
229  list.emplace_back(new DropDownListStringItem(STR_NETWORK_COMPANY_LIST_CLIENT_LIST, CTMN_CLIENT_LIST, false));
230 
232  list.emplace_back(new DropDownListStringItem(STR_NETWORK_COMPANY_LIST_NEW_COMPANY, CTMN_NEW_COMPANY, NetworkMaxCompaniesReached()));
233  } else {
234  list.emplace_back(new DropDownListStringItem(STR_NETWORK_COMPANY_LIST_SPECTATE, CTMN_SPECTATE, NetworkMaxSpectatorsReached()));
235  }
236  break;
237 
238  case WID_TN_STORY:
239  list.emplace_back(new DropDownListStringItem(STR_STORY_BOOK_SPECTATOR, CTMN_SPECTATOR, false));
240  break;
241 
242  case WID_TN_GOAL:
243  list.emplace_back(new DropDownListStringItem(STR_GOALS_SPECTATOR, CTMN_SPECTATOR, false));
244  break;
245  }
246 
247  for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) {
248  if (!Company::IsValidID(c)) continue;
249  list.emplace_back(new DropDownListCompanyItem(c, false, HasBit(grey, c)));
250  }
251 
253 }
254 
255 
256 static ToolbarMode _toolbar_mode;
257 
258 static CallBackFunction SelectSignTool()
259 {
260  if (_last_started_action == CBF_PLACE_SIGN) {
262  return CBF_NONE;
263  } else {
264  SetObjectToPlace(SPR_CURSOR_SIGN, PAL_NONE, HT_RECT, WC_MAIN_TOOLBAR, 0);
265  return CBF_PLACE_SIGN;
266  }
267 }
268 
269 /* --- Pausing --- */
270 
271 static CallBackFunction ToolbarPauseClick(Window *w)
272 {
273  if (_networking && !_network_server) return CBF_NONE; // only server can pause the game
274 
276  if (_settings_client.sound.confirm) SndPlayFx(SND_15_BEEP);
277  }
278  return CBF_NONE;
279 }
280 
288 {
289  _fast_forward ^= true;
290  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
291  return CBF_NONE;
292 }
293 
298  OME_GAMEOPTIONS,
299  OME_SETTINGS,
300  OME_SCRIPT_SETTINGS,
301  OME_NEWGRFSETTINGS,
302  OME_TRANSPARENCIES,
303  OME_SHOW_TOWNNAMES,
304  OME_SHOW_STATIONNAMES,
305  OME_SHOW_WAYPOINTNAMES,
306  OME_SHOW_SIGNS,
307  OME_SHOW_COMPETITOR_SIGNS,
308  OME_FULL_ANIMATION,
309  OME_FULL_DETAILS,
310  OME_TRANSPARENTBUILDINGS,
311  OME_SHOW_STATIONSIGNS,
312 };
313 
321 {
322  DropDownList list;
323  list.emplace_back(new DropDownListStringItem(STR_SETTINGS_MENU_GAME_OPTIONS, OME_GAMEOPTIONS, false));
324  list.emplace_back(new DropDownListStringItem(STR_SETTINGS_MENU_CONFIG_SETTINGS_TREE, OME_SETTINGS, false));
325  /* Changes to the per-AI settings don't get send from the server to the clients. Clients get
326  * the settings once they join but never update it. As such don't show the window at all
327  * to network clients. */
328  if (!_networking || _network_server) list.emplace_back(new DropDownListStringItem(STR_SETTINGS_MENU_SCRIPT_SETTINGS, OME_SCRIPT_SETTINGS, false));
329  list.emplace_back(new DropDownListStringItem(STR_SETTINGS_MENU_NEWGRF_SETTINGS, OME_NEWGRFSETTINGS, false));
330  list.emplace_back(new DropDownListStringItem(STR_SETTINGS_MENU_TRANSPARENCY_OPTIONS, OME_TRANSPARENCIES, false));
331  list.emplace_back(new DropDownListItem(-1, false));
332  list.emplace_back(new DropDownListCheckedItem(STR_SETTINGS_MENU_TOWN_NAMES_DISPLAYED, OME_SHOW_TOWNNAMES, false, HasBit(_display_opt, DO_SHOW_TOWN_NAMES)));
333  list.emplace_back(new DropDownListCheckedItem(STR_SETTINGS_MENU_STATION_NAMES_DISPLAYED, OME_SHOW_STATIONNAMES, false, HasBit(_display_opt, DO_SHOW_STATION_NAMES)));
334  list.emplace_back(new DropDownListCheckedItem(STR_SETTINGS_MENU_WAYPOINTS_DISPLAYED, OME_SHOW_WAYPOINTNAMES, false, HasBit(_display_opt, DO_SHOW_WAYPOINT_NAMES)));
335  list.emplace_back(new DropDownListCheckedItem(STR_SETTINGS_MENU_SIGNS_DISPLAYED, OME_SHOW_SIGNS, false, HasBit(_display_opt, DO_SHOW_SIGNS)));
336  list.emplace_back(new DropDownListCheckedItem(STR_SETTINGS_MENU_SHOW_COMPETITOR_SIGNS, OME_SHOW_COMPETITOR_SIGNS, false, HasBit(_display_opt, DO_SHOW_COMPETITOR_SIGNS)));
337  list.emplace_back(new DropDownListCheckedItem(STR_SETTINGS_MENU_FULL_ANIMATION, OME_FULL_ANIMATION, false, HasBit(_display_opt, DO_FULL_ANIMATION)));
338  list.emplace_back(new DropDownListCheckedItem(STR_SETTINGS_MENU_FULL_DETAIL, OME_FULL_DETAILS, false, HasBit(_display_opt, DO_FULL_DETAIL)));
339  list.emplace_back(new DropDownListCheckedItem(STR_SETTINGS_MENU_TRANSPARENT_BUILDINGS, OME_TRANSPARENTBUILDINGS, false, IsTransparencySet(TO_HOUSES)));
340  list.emplace_back(new DropDownListCheckedItem(STR_SETTINGS_MENU_TRANSPARENT_SIGNS, OME_SHOW_STATIONSIGNS, false, IsTransparencySet(TO_SIGNS)));
341 
342  ShowDropDownList(w, std::move(list), 0, WID_TN_SETTINGS, 140, true, true);
343  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
344  return CBF_NONE;
345 }
346 
354 {
355  switch (index) {
356  case OME_GAMEOPTIONS: ShowGameOptions(); return CBF_NONE;
357  case OME_SETTINGS: ShowGameSettings(); return CBF_NONE;
358  case OME_SCRIPT_SETTINGS: ShowAIConfigWindow(); return CBF_NONE;
359  case OME_NEWGRFSETTINGS: ShowNewGRFSettings(!_networking && _settings_client.gui.UserIsAllowedToChangeNewGRFs(), true, true, &_grfconfig); return CBF_NONE;
360  case OME_TRANSPARENCIES: ShowTransparencyToolbar(); break;
361 
362  case OME_SHOW_TOWNNAMES: ToggleBit(_display_opt, DO_SHOW_TOWN_NAMES); break;
363  case OME_SHOW_STATIONNAMES: ToggleBit(_display_opt, DO_SHOW_STATION_NAMES); break;
364  case OME_SHOW_WAYPOINTNAMES: ToggleBit(_display_opt, DO_SHOW_WAYPOINT_NAMES); break;
365  case OME_SHOW_SIGNS: ToggleBit(_display_opt, DO_SHOW_SIGNS); break;
366  case OME_SHOW_COMPETITOR_SIGNS:
369  break;
370  case OME_FULL_ANIMATION: ToggleBit(_display_opt, DO_FULL_ANIMATION); CheckBlitter(); break;
371  case OME_FULL_DETAILS: ToggleBit(_display_opt, DO_FULL_DETAIL); break;
372  case OME_TRANSPARENTBUILDINGS: ToggleTransparency(TO_HOUSES); break;
373  case OME_SHOW_STATIONSIGNS: ToggleTransparency(TO_SIGNS); break;
374  }
376  return CBF_NONE;
377 }
378 
383  SLEME_SAVE_SCENARIO = 0,
384  SLEME_LOAD_SCENARIO,
385  SLEME_SAVE_HEIGHTMAP,
386  SLEME_LOAD_HEIGHTMAP,
387  SLEME_EXIT_TOINTRO,
388  SLEME_EXIT_GAME = 6,
389  SLEME_MENUCOUNT,
390 };
391 
396  SLNME_SAVE_GAME = 0,
397  SLNME_LOAD_GAME,
398  SLNME_EXIT_TOINTRO,
399  SLNME_EXIT_GAME = 4,
400  SLNME_MENUCOUNT,
401 };
402 
410 {
411  PopupMainToolbMenu(w, WID_TN_SAVE, STR_FILE_MENU_SAVE_GAME, SLNME_MENUCOUNT);
412  return CBF_NONE;
413 }
414 
422 {
423  PopupMainToolbMenu(w, WID_TE_SAVE, STR_SCENEDIT_FILE_MENU_SAVE_SCENARIO, SLEME_MENUCOUNT);
424  return CBF_NONE;
425 }
426 
433 static CallBackFunction MenuClickSaveLoad(int index = 0)
434 {
435  if (_game_mode == GM_EDITOR) {
436  switch (index) {
437  case SLEME_SAVE_SCENARIO: ShowSaveLoadDialog(FT_SCENARIO, SLO_SAVE); break;
438  case SLEME_LOAD_SCENARIO: ShowSaveLoadDialog(FT_SCENARIO, SLO_LOAD); break;
439  case SLEME_SAVE_HEIGHTMAP: ShowSaveLoadDialog(FT_HEIGHTMAP,SLO_SAVE); break;
440  case SLEME_LOAD_HEIGHTMAP: ShowSaveLoadDialog(FT_HEIGHTMAP,SLO_LOAD); break;
441  case SLEME_EXIT_TOINTRO: AskExitToGameMenu(); break;
442  case SLEME_EXIT_GAME: HandleExitGameRequest(); break;
443  }
444  } else {
445  switch (index) {
446  case SLNME_SAVE_GAME: ShowSaveLoadDialog(FT_SAVEGAME, SLO_SAVE); break;
447  case SLNME_LOAD_GAME: ShowSaveLoadDialog(FT_SAVEGAME, SLO_LOAD); break;
448  case SLNME_EXIT_TOINTRO: AskExitToGameMenu(); break;
449  case SLNME_EXIT_GAME: HandleExitGameRequest(); break;
450  }
451  }
452  return CBF_NONE;
453 }
454 
455 /* --- Map button menu --- */
456 
457 enum MapMenuEntries {
458  MME_SHOW_SMALLMAP = 0,
459  MME_SHOW_EXTRAVIEWPORTS,
460  MME_SHOW_LINKGRAPH,
461  MME_SHOW_SIGNLISTS,
462  MME_SHOW_TOWNDIRECTORY,
463  MME_SHOW_INDUSTRYDIRECTORY,
464 };
465 
466 static CallBackFunction ToolbarMapClick(Window *w)
467 {
468  DropDownList list;
469  list.emplace_back(new DropDownListStringItem(STR_MAP_MENU_MAP_OF_WORLD, MME_SHOW_SMALLMAP, false));
470  list.emplace_back(new DropDownListStringItem(STR_MAP_MENU_EXTRA_VIEW_PORT, MME_SHOW_EXTRAVIEWPORTS, false));
471  list.emplace_back(new DropDownListStringItem(STR_MAP_MENU_LINGRAPH_LEGEND, MME_SHOW_LINKGRAPH, false));
472  list.emplace_back(new DropDownListStringItem(STR_MAP_MENU_SIGN_LIST, MME_SHOW_SIGNLISTS, false));
473  PopupMainToolbMenu(w, WID_TN_SMALL_MAP, std::move(list), 0);
474  return CBF_NONE;
475 }
476 
477 static CallBackFunction ToolbarScenMapTownDir(Window *w)
478 {
479  DropDownList list;
480  list.emplace_back(new DropDownListStringItem(STR_MAP_MENU_MAP_OF_WORLD, MME_SHOW_SMALLMAP, false));
481  list.emplace_back(new DropDownListStringItem(STR_MAP_MENU_EXTRA_VIEW_PORT, MME_SHOW_EXTRAVIEWPORTS, false));
482  list.emplace_back(new DropDownListStringItem(STR_MAP_MENU_SIGN_LIST, MME_SHOW_SIGNLISTS, false));
483  list.emplace_back(new DropDownListStringItem(STR_TOWN_MENU_TOWN_DIRECTORY, MME_SHOW_TOWNDIRECTORY, false));
484  list.emplace_back(new DropDownListStringItem(STR_INDUSTRY_MENU_INDUSTRY_DIRECTORY, MME_SHOW_INDUSTRYDIRECTORY, false));
485  PopupMainToolbMenu(w, WID_TE_SMALL_MAP, std::move(list), 0);
486  return CBF_NONE;
487 }
488 
496 {
497  switch (index) {
498  case MME_SHOW_SMALLMAP: ShowSmallMap(); break;
499  case MME_SHOW_EXTRAVIEWPORTS: ShowExtraViewPortWindow(); break;
500  case MME_SHOW_LINKGRAPH: ShowLinkGraphLegend(); break;
501  case MME_SHOW_SIGNLISTS: ShowSignList(); break;
502  case MME_SHOW_TOWNDIRECTORY: ShowTownDirectory(); break;
503  case MME_SHOW_INDUSTRYDIRECTORY: ShowIndustryDirectory(); break;
504  }
505  return CBF_NONE;
506 }
507 
508 /* --- Town button menu --- */
509 
510 static CallBackFunction ToolbarTownClick(Window *w)
511 {
512  PopupMainToolbMenu(w, WID_TN_TOWNS, STR_TOWN_MENU_TOWN_DIRECTORY, (_settings_game.economy.found_town == TF_FORBIDDEN) ? 1 : 2);
513  return CBF_NONE;
514 }
515 
523 {
524  switch (index) {
525  case 0: ShowTownDirectory(); break;
526  case 1: // setting could be changed when the dropdown was open
527  if (_settings_game.economy.found_town != TF_FORBIDDEN) ShowFoundTownWindow();
528  break;
529  }
530  return CBF_NONE;
531 }
532 
533 /* --- Subidies button menu --- */
534 
535 static CallBackFunction ToolbarSubsidiesClick(Window *w)
536 {
537  PopupMainToolbMenu(w, WID_TN_SUBSIDIES, STR_SUBSIDIES_MENU_SUBSIDIES, 1);
538  return CBF_NONE;
539 }
540 
548 {
549  switch (index) {
550  case 0: ShowSubsidiesList(); break;
551  }
552  return CBF_NONE;
553 }
554 
555 /* --- Stations button menu --- */
556 
557 static CallBackFunction ToolbarStationsClick(Window *w)
558 {
560  return CBF_NONE;
561 }
562 
570 {
572  return CBF_NONE;
573 }
574 
575 /* --- Finances button menu --- */
576 
577 static CallBackFunction ToolbarFinancesClick(Window *w)
578 {
580  return CBF_NONE;
581 }
582 
590 {
592  return CBF_NONE;
593 }
594 
595 /* --- Company's button menu --- */
596 
597 static CallBackFunction ToolbarCompaniesClick(Window *w)
598 {
600  return CBF_NONE;
601 }
602 
610 {
611  if (_networking) {
612  switch (index) {
613  case CTMN_CLIENT_LIST:
614  ShowClientList();
615  return CBF_NONE;
616 
617  case CTMN_NEW_COMPANY:
618  if (_network_server) {
620  } else {
621  NetworkSendCommand(0, CCA_NEW, 0, CMD_COMPANY_CTRL, nullptr, nullptr, _local_company);
622  }
623  return CBF_NONE;
624 
625  case CTMN_SPECTATE:
626  if (_network_server) {
629  } else {
631  }
632  return CBF_NONE;
633  }
634  }
635  ShowCompany((CompanyID)index);
636  return CBF_NONE;
637 }
638 
639 /* --- Story button menu --- */
640 
641 static CallBackFunction ToolbarStoryClick(Window *w)
642 {
644  return CBF_NONE;
645 }
646 
654 {
656  return CBF_NONE;
657 }
658 
659 /* --- Goal button menu --- */
660 
661 static CallBackFunction ToolbarGoalClick(Window *w)
662 {
664  return CBF_NONE;
665 }
666 
674 {
676  return CBF_NONE;
677 }
678 
679 /* --- Graphs button menu --- */
680 
681 static CallBackFunction ToolbarGraphsClick(Window *w)
682 {
683  PopupMainToolbMenu(w, WID_TN_GRAPHS, STR_GRAPH_MENU_OPERATING_PROFIT_GRAPH, (_toolbar_mode == TB_NORMAL) ? 6 : 8);
684  return CBF_NONE;
685 }
686 
694 {
695  switch (index) {
696  case 0: ShowOperatingProfitGraph(); break;
697  case 1: ShowIncomeGraph(); break;
698  case 2: ShowDeliveredCargoGraph(); break;
699  case 3: ShowPerformanceHistoryGraph(); break;
700  case 4: ShowCompanyValueGraph(); break;
701  case 5: ShowCargoPaymentRates(); break;
702  /* functions for combined graphs/league button */
703  case 6: ShowCompanyLeagueTable(); break;
704  case 7: ShowPerformanceRatingDetail(); break;
705  }
706  return CBF_NONE;
707 }
708 
709 /* --- League button menu --- */
710 
711 static CallBackFunction ToolbarLeagueClick(Window *w)
712 {
713  PopupMainToolbMenu(w, WID_TN_LEAGUE, STR_GRAPH_MENU_COMPANY_LEAGUE_TABLE, _networking ? 2 : 3);
714  return CBF_NONE;
715 }
716 
724 {
725  switch (index) {
726  case 0: ShowCompanyLeagueTable(); break;
727  case 1: ShowPerformanceRatingDetail(); break;
728  case 2: ShowHighscoreTable(); break;
729  }
730  return CBF_NONE;
731 }
732 
733 /* --- Industries button menu --- */
734 
735 static CallBackFunction ToolbarIndustryClick(Window *w)
736 {
737  /* Disable build-industry menu if we are a spectator */
738  PopupMainToolbMenu(w, WID_TN_INDUSTRIES, STR_INDUSTRY_MENU_INDUSTRY_DIRECTORY, (_local_company == COMPANY_SPECTATOR) ? 2 : 3);
739  return CBF_NONE;
740 }
741 
749 {
750  switch (index) {
751  case 0: ShowIndustryDirectory(); break;
752  case 1: ShowIndustryCargoesWindow(); break;
753  case 2: ShowBuildIndustryWindow(); break;
754  }
755  return CBF_NONE;
756 }
757 
758 /* --- Trains button menu + 1 helper function for all vehicles. --- */
759 
760 static void ToolbarVehicleClick(Window *w, VehicleType veh)
761 {
762  const Vehicle *v;
763  int dis = ~0;
764 
765  FOR_ALL_VEHICLES(v) {
766  if (v->type == veh && v->IsPrimaryVehicle()) ClrBit(dis, v->owner);
767  }
769 }
770 
771 
772 static CallBackFunction ToolbarTrainClick(Window *w)
773 {
774  ToolbarVehicleClick(w, VEH_TRAIN);
775  return CBF_NONE;
776 }
777 
785 {
786  ShowVehicleListWindow((CompanyID)index, VEH_TRAIN);
787  return CBF_NONE;
788 }
789 
790 /* --- Road vehicle button menu --- */
791 
792 static CallBackFunction ToolbarRoadClick(Window *w)
793 {
794  ToolbarVehicleClick(w, VEH_ROAD);
795  return CBF_NONE;
796 }
797 
805 {
806  ShowVehicleListWindow((CompanyID)index, VEH_ROAD);
807  return CBF_NONE;
808 }
809 
810 /* --- Ship button menu --- */
811 
812 static CallBackFunction ToolbarShipClick(Window *w)
813 {
814  ToolbarVehicleClick(w, VEH_SHIP);
815  return CBF_NONE;
816 }
817 
825 {
826  ShowVehicleListWindow((CompanyID)index, VEH_SHIP);
827  return CBF_NONE;
828 }
829 
830 /* --- Aircraft button menu --- */
831 
832 static CallBackFunction ToolbarAirClick(Window *w)
833 {
834  ToolbarVehicleClick(w, VEH_AIRCRAFT);
835  return CBF_NONE;
836 }
837 
845 {
846  ShowVehicleListWindow((CompanyID)index, VEH_AIRCRAFT);
847  return CBF_NONE;
848 }
849 
850 /* --- Zoom in button --- */
851 
852 static CallBackFunction ToolbarZoomInClick(Window *w)
853 {
855  w->HandleButtonClick((_game_mode == GM_EDITOR) ? (byte)WID_TE_ZOOM_IN : (byte)WID_TN_ZOOM_IN);
856  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
857  }
858  return CBF_NONE;
859 }
860 
861 /* --- Zoom out button --- */
862 
863 static CallBackFunction ToolbarZoomOutClick(Window *w)
864 {
866  w->HandleButtonClick((_game_mode == GM_EDITOR) ? (byte)WID_TE_ZOOM_OUT : (byte)WID_TN_ZOOM_OUT);
867  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
868  }
869  return CBF_NONE;
870 }
871 
872 /* --- Rail button menu --- */
873 
874 static CallBackFunction ToolbarBuildRailClick(Window *w)
875 {
876  ShowDropDownList(w, GetRailTypeDropDownList(), _last_built_railtype, WID_TN_RAILS, 140, true, true);
877  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
878  return CBF_NONE;
879 }
880 
888 {
889  _last_built_railtype = (RailType)index;
890  ShowBuildRailToolbar(_last_built_railtype);
891  return CBF_NONE;
892 }
893 
894 /* --- Road button menu --- */
895 
896 static CallBackFunction ToolbarBuildRoadClick(Window *w)
897 {
898  ShowDropDownList(w, GetRoadTypeDropDownList(RTTB_ROAD), _last_built_roadtype, WID_TN_ROADS, 140, true, true);
899  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
900  return CBF_NONE;
901 }
902 
910 {
911  _last_built_roadtype = (RoadType)index;
912  ShowBuildRoadToolbar(_last_built_roadtype);
913  return CBF_NONE;
914 }
915 
916 /* --- Tram button menu --- */
917 
918 static CallBackFunction ToolbarBuildTramClick(Window *w)
919 {
920  ShowDropDownList(w, GetRoadTypeDropDownList(RTTB_TRAM), _last_built_tramtype, WID_TN_TRAMS, 140, true, true);
921  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
922  return CBF_NONE;
923 }
924 
932 {
933  _last_built_tramtype = (RoadType)index;
934  ShowBuildRoadToolbar(_last_built_tramtype);
935  return CBF_NONE;
936 }
937 
938 /* --- Water button menu --- */
939 
940 static CallBackFunction ToolbarBuildWaterClick(Window *w)
941 {
942  DropDownList list;
943  list.emplace_back(new DropDownListIconItem(SPR_IMG_BUILD_CANAL, PAL_NONE, STR_WATERWAYS_MENU_WATERWAYS_CONSTRUCTION, 0, false));
944  ShowDropDownList(w, std::move(list), 0, WID_TN_WATER, 140, true, true);
945  return CBF_NONE;
946 }
947 
955 {
957  return CBF_NONE;
958 }
959 
960 /* --- Airport button menu --- */
961 
962 static CallBackFunction ToolbarBuildAirClick(Window *w)
963 {
964  DropDownList list;
965  list.emplace_back(new DropDownListIconItem(SPR_IMG_AIRPORT, PAL_NONE, STR_AIRCRAFT_MENU_AIRPORT_CONSTRUCTION, 0, false));
966  ShowDropDownList(w, std::move(list), 0, WID_TN_AIR, 140, true, true);
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  return CBF_NONE;
992 }
993 
1001 {
1002  switch (index) {
1003  case 0: ShowTerraformToolbar(); break;
1004  case 1: ShowBuildTreesToolbar(); break;
1005  case 2: return SelectSignTool();
1006  }
1007  return CBF_NONE;
1008 }
1009 
1010 /* --- Music button menu --- */
1011 
1012 static CallBackFunction ToolbarMusicClick(Window *w)
1013 {
1014  PopupMainToolbMenu(w, _game_mode == GM_EDITOR ? (int)WID_TE_MUSIC_SOUND : (int)WID_TN_MUSIC_SOUND, STR_TOOLBAR_SOUND_MUSIC, 1);
1015  return CBF_NONE;
1016 }
1017 
1025 {
1026  ShowMusicWindow();
1027  return CBF_NONE;
1028 }
1029 
1030 /* --- Newspaper button menu --- */
1031 
1032 static CallBackFunction ToolbarNewspaperClick(Window *w)
1033 {
1034  PopupMainToolbMenu(w, WID_TN_MESSAGES, STR_NEWS_MENU_LAST_MESSAGE_NEWS_REPORT, 3);
1035  return CBF_NONE;
1036 }
1037 
1045 {
1046  switch (index) {
1047  case 0: ShowLastNewsMessage(); break;
1048  case 1: ShowMessageHistory(); break;
1049  case 2: DeleteAllMessages(); break;
1050  }
1051  return CBF_NONE;
1052 }
1053 
1054 /* --- Help button menu --- */
1055 
1056 static CallBackFunction PlaceLandBlockInfo()
1057 {
1058  if (_last_started_action == CBF_PLACE_LANDINFO) {
1060  return CBF_NONE;
1061  } else {
1062  SetObjectToPlace(SPR_CURSOR_QUERY, PAL_NONE, HT_RECT, WC_MAIN_TOOLBAR, 0);
1063  return CBF_PLACE_LANDINFO;
1064  }
1065 }
1066 
1067 static CallBackFunction ToolbarHelpClick(Window *w)
1068 {
1069  PopupMainToolbMenu(w, _game_mode == GM_EDITOR ? (int)WID_TE_HELP : (int)WID_TN_HELP, STR_ABOUT_MENU_LAND_BLOCK_INFO, _settings_client.gui.newgrf_developer_tools ? 13 : 10);
1070  return CBF_NONE;
1071 }
1072 
1073 static void MenuClickSmallScreenshot()
1074 {
1075  MakeScreenshot(SC_VIEWPORT, nullptr);
1076 }
1077 
1083 static void ScreenshotConfirmCallback(Window *w, bool confirmed)
1084 {
1085  if (confirmed) MakeScreenshot(_confirmed_screenshot_type, nullptr);
1086 }
1087 
1094 {
1095  ViewPort vp;
1096  SetupScreenshotViewport(t, &vp);
1097  if ((uint64)vp.width * (uint64)vp.height > 8192 * 8192) {
1098  /* Ask for confirmation */
1099  SetDParam(0, vp.width);
1100  SetDParam(1, vp.height);
1102  ShowQuery(STR_WARNING_SCREENSHOT_SIZE_CAPTION, STR_WARNING_SCREENSHOT_SIZE_MESSAGE, nullptr, ScreenshotConfirmCallback);
1103  } else {
1104  /* Less than 64M pixels, just do it */
1105  MakeScreenshot(t, nullptr);
1106  }
1107 }
1108 
1117 {
1118  extern bool _draw_bounding_boxes;
1119  /* Always allow to toggle them off */
1120  if (_settings_client.gui.newgrf_developer_tools || _draw_bounding_boxes) {
1121  _draw_bounding_boxes = !_draw_bounding_boxes;
1123  }
1124 }
1125 
1134 {
1135  extern bool _draw_dirty_blocks;
1136  /* Always allow to toggle them off */
1137  if (_settings_client.gui.newgrf_developer_tools || _draw_dirty_blocks) {
1138  _draw_dirty_blocks = !_draw_dirty_blocks;
1140  }
1141 }
1142 
1148 {
1151  /* If you open a savegame as scenario there may already be link graphs.*/
1153  SetDate(new_date, 0);
1154 }
1155 
1162 {
1163  switch (index) {
1164  case 0: return PlaceLandBlockInfo();
1165  case 2: IConsoleSwitch(); break;
1166  case 3: ShowAIDebugWindow(); break;
1167  case 4: MenuClickSmallScreenshot(); break;
1170  case 7: MenuClickLargeWorldScreenshot(SC_WORLD); break;
1171  case 8: ShowFramerateWindow(); break;
1172  case 9: ShowAboutWindow(); break;
1173  case 10: ShowSpriteAlignerWindow(); break;
1174  case 11: ToggleBoundingBoxes(); break;
1175  case 12: ToggleDirtyBlocks(); break;
1176  }
1177  return CBF_NONE;
1178 }
1179 
1180 /* --- Switch toolbar button --- */
1181 
1182 static CallBackFunction ToolbarSwitchClick(Window *w)
1183 {
1184  if (_toolbar_mode != TB_LOWER) {
1185  _toolbar_mode = TB_LOWER;
1186  } else {
1187  _toolbar_mode = TB_UPPER;
1188  }
1189 
1190  w->ReInit();
1191  w->SetWidgetLoweredState(_game_mode == GM_EDITOR ? (uint)WID_TE_SWITCH_BAR : (uint)WID_TN_SWITCH_BAR, _toolbar_mode == TB_LOWER);
1192  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
1193  return CBF_NONE;
1194 }
1195 
1196 /* --- Scenario editor specific handlers. */
1197 
1202 {
1204  ShowQueryString(STR_JUST_INT, STR_MAPGEN_START_DATE_QUERY_CAPT, 8, w, CS_NUMERAL, QSF_ENABLE_DEFAULT);
1205  _left_button_clicked = false;
1206  return CBF_NONE;
1207 }
1208 
1209 static CallBackFunction ToolbarScenDateBackward(Window *w)
1210 {
1211  /* don't allow too fast scrolling */
1212  if (!(w->flags & WF_TIMEOUT) || w->timeout_timer <= 1) {
1214  w->SetDirty();
1215 
1217  }
1218  _left_button_clicked = false;
1219  return CBF_NONE;
1220 }
1221 
1222 static CallBackFunction ToolbarScenDateForward(Window *w)
1223 {
1224  /* don't allow too fast scrolling */
1225  if (!(w->flags & WF_TIMEOUT) || w->timeout_timer <= 1) {
1227  w->SetDirty();
1228 
1230  }
1231  _left_button_clicked = false;
1232  return CBF_NONE;
1233 }
1234 
1235 static CallBackFunction ToolbarScenGenLand(Window *w)
1236 {
1238  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
1239 
1241  return CBF_NONE;
1242 }
1243 
1244 
1245 static CallBackFunction ToolbarScenGenTown(Window *w)
1246 {
1248  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
1249  ShowFoundTownWindow();
1250  return CBF_NONE;
1251 }
1252 
1253 static CallBackFunction ToolbarScenGenIndustry(Window *w)
1254 {
1256  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
1257  ShowBuildIndustryWindow();
1258  return CBF_NONE;
1259 }
1260 
1261 static CallBackFunction ToolbarScenBuildRoadClick(Window *w)
1262 {
1263  ShowDropDownList(w, GetScenRoadTypeDropDownList(RTTB_ROAD), _last_built_roadtype, WID_TE_ROADS, 140, true, true);
1264  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
1265  return CBF_NONE;
1266 }
1267 
1275 {
1276  _last_built_roadtype = (RoadType)index;
1277  ShowBuildRoadScenToolbar(_last_built_roadtype);
1278  return CBF_NONE;
1279 }
1280 
1281 static CallBackFunction ToolbarScenBuildTramClick(Window *w)
1282 {
1283  ShowDropDownList(w, GetScenRoadTypeDropDownList(RTTB_TRAM), _last_built_tramtype, WID_TE_TRAMS, 140, true, true);
1284  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
1285  return CBF_NONE;
1286 }
1287 
1295 {
1296  _last_built_tramtype = (RoadType)index;
1297  ShowBuildRoadScenToolbar(_last_built_tramtype);
1298  return CBF_NONE;
1299 }
1300 
1301 static CallBackFunction ToolbarScenBuildDocks(Window *w)
1302 {
1304  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
1306  return CBF_NONE;
1307 }
1308 
1309 static CallBackFunction ToolbarScenPlantTrees(Window *w)
1310 {
1312  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
1313  ShowBuildTreesToolbar();
1314  return CBF_NONE;
1315 }
1316 
1317 static CallBackFunction ToolbarScenPlaceSign(Window *w)
1318 {
1320  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
1321  return SelectSignTool();
1322 }
1323 
1324 static CallBackFunction ToolbarBtn_NULL(Window *w)
1325 {
1326  return CBF_NONE;
1327 }
1328 
1329 typedef CallBackFunction MenuClickedProc(int index);
1330 
1331 static MenuClickedProc * const _menu_clicked_procs[] = {
1332  nullptr, // 0
1333  nullptr, // 1
1334  MenuClickSettings, // 2
1335  MenuClickSaveLoad, // 3
1336  MenuClickMap, // 4
1337  MenuClickTown, // 5
1338  MenuClickSubsidies, // 6
1339  MenuClickStations, // 7
1340  MenuClickFinances, // 8
1341  MenuClickCompany, // 9
1342  MenuClickStory, // 10
1343  MenuClickGoal, // 11
1344  MenuClickGraphs, // 12
1345  MenuClickLeague, // 13
1346  MenuClickIndustry, // 14
1347  MenuClickShowTrains, // 15
1348  MenuClickShowRoad, // 16
1349  MenuClickShowShips, // 17
1350  MenuClickShowAir, // 18
1351  MenuClickMap, // 19
1352  nullptr, // 20
1353  MenuClickBuildRail, // 21
1354  MenuClickBuildRoad, // 22
1355  MenuClickBuildTram, // 23
1356  MenuClickBuildWater, // 24
1357  MenuClickBuildAir, // 25
1358  MenuClickForest, // 26
1359  MenuClickMusicWindow, // 27
1360  MenuClickNewspaper, // 28
1361  MenuClickHelp, // 29
1362 };
1363 
1366  bool visible[WID_TN_END];
1367 protected:
1368  uint spacers;
1369 
1370 public:
1372  {
1373  }
1374 
1380  bool IsButton(WidgetType type) const
1381  {
1382  return type == WWT_IMGBTN || type == WWT_IMGBTN_2 || type == WWT_PUSHIMGBTN;
1383  }
1384 
1385  void SetupSmallestSize(Window *w, bool init_array) override
1386  {
1387  this->smallest_x = 0; // Biggest child
1388  this->smallest_y = 0; // Biggest child
1389  this->fill_x = 1;
1390  this->fill_y = 0;
1391  this->resize_x = 1; // We only resize in this direction
1392  this->resize_y = 0; // We never resize in this direction
1393  this->spacers = 0;
1394 
1395  uint nbuttons = 0;
1396  /* First initialise some variables... */
1397  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1398  child_wid->SetupSmallestSize(w, init_array);
1399  this->smallest_y = max(this->smallest_y, child_wid->smallest_y + child_wid->padding_top + child_wid->padding_bottom);
1400  if (this->IsButton(child_wid->type)) {
1401  nbuttons++;
1402  this->smallest_x = max(this->smallest_x, child_wid->smallest_x + child_wid->padding_left + child_wid->padding_right);
1403  } else if (child_wid->type == NWID_SPACER) {
1404  this->spacers++;
1405  }
1406  }
1407 
1408  /* ... then in a second pass make sure the 'current' heights are set. Won't change ever. */
1409  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1410  child_wid->current_y = this->smallest_y;
1411  if (!this->IsButton(child_wid->type)) {
1412  child_wid->current_x = child_wid->smallest_x;
1413  }
1414  }
1415  _toolbar_width = nbuttons * this->smallest_x;
1416  }
1417 
1418  void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl) override
1419  {
1420  assert(given_width >= this->smallest_x && given_height >= this->smallest_y);
1421 
1422  this->pos_x = x;
1423  this->pos_y = y;
1424  this->current_x = given_width;
1425  this->current_y = given_height;
1426 
1427  /* Figure out what are the visible buttons */
1428  memset(this->visible, 0, sizeof(this->visible));
1429  uint arrangable_count, button_count, spacer_count;
1430  const byte *arrangement = GetButtonArrangement(given_width, arrangable_count, button_count, spacer_count);
1431  for (uint i = 0; i < arrangable_count; i++) {
1432  this->visible[arrangement[i]] = true;
1433  }
1434 
1435  /* Create us ourselves a quick lookup table */
1436  NWidgetBase *widgets[WID_TN_END];
1437  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1438  if (child_wid->type == NWID_SPACER) continue;
1439  widgets[((NWidgetCore*)child_wid)->index] = child_wid;
1440  }
1441 
1442  /* Now assign the widgets to their rightful place */
1443  uint position = 0; // Place to put next child relative to origin of the container.
1444  uint spacer_space = max(0, (int)given_width - (int)(button_count * this->smallest_x)); // Remaining spacing for 'spacer' widgets
1445  uint button_space = given_width - spacer_space; // Remaining spacing for the buttons
1446  uint spacer_i = 0;
1447  uint button_i = 0;
1448 
1449  /* Index into the arrangement indices. The macro lastof cannot be used here! */
1450  const byte *cur_wid = rtl ? &arrangement[arrangable_count - 1] : arrangement;
1451  for (uint i = 0; i < arrangable_count; i++) {
1452  NWidgetBase *child_wid = widgets[*cur_wid];
1453  /* If we have to give space to the spacers, do that */
1454  if (spacer_space != 0) {
1455  NWidgetBase *possible_spacer = rtl ? child_wid->next : child_wid->prev;
1456  if (possible_spacer != nullptr && possible_spacer->type == NWID_SPACER) {
1457  uint add = spacer_space / (spacer_count - spacer_i);
1458  position += add;
1459  spacer_space -= add;
1460  spacer_i++;
1461  }
1462  }
1463 
1464  /* Buttons can be scaled, the others not. */
1465  if (this->IsButton(child_wid->type)) {
1466  child_wid->current_x = button_space / (button_count - button_i);
1467  button_space -= child_wid->current_x;
1468  button_i++;
1469  }
1470  child_wid->AssignSizePosition(sizing, x + position, y, child_wid->current_x, this->current_y, rtl);
1471  position += child_wid->current_x;
1472 
1473  if (rtl) {
1474  cur_wid--;
1475  } else {
1476  cur_wid++;
1477  }
1478  }
1479  }
1480 
1481  void Draw(const Window *w) override
1482  {
1483  /* Draw brown-red toolbar bg. */
1484  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);
1485  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);
1486 
1487  bool rtl = _current_text_dir == TD_RTL;
1488  for (NWidgetBase *child_wid = rtl ? this->tail : this->head; child_wid != nullptr; child_wid = rtl ? child_wid->prev : child_wid->next) {
1489  if (child_wid->type == NWID_SPACER) continue;
1490  if (!this->visible[((NWidgetCore*)child_wid)->index]) continue;
1491 
1492  child_wid->Draw(w);
1493  }
1494  }
1495 
1496  NWidgetCore *GetWidgetFromPos(int x, int y) override
1497  {
1498  if (!IsInsideBS(x, this->pos_x, this->current_x) || !IsInsideBS(y, this->pos_y, this->current_y)) return nullptr;
1499 
1500  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1501  if (child_wid->type == NWID_SPACER) continue;
1502  if (!this->visible[((NWidgetCore*)child_wid)->index]) continue;
1503 
1504  NWidgetCore *nwid = child_wid->GetWidgetFromPos(x, y);
1505  if (nwid != nullptr) return nwid;
1506  }
1507  return nullptr;
1508  }
1509 
1518  virtual const byte *GetButtonArrangement(uint &width, uint &arrangable_count, uint &button_count, uint &spacer_count) const = 0;
1519 };
1520 
1523  const byte *GetButtonArrangement(uint &width, uint &arrangable_count, uint &button_count, uint &spacer_count) const override
1524  {
1525  static const uint SMALLEST_ARRANGEMENT = 14;
1526  static const uint BIGGEST_ARRANGEMENT = 20;
1527 
1528  /* The number of buttons of each row of the toolbar should match the number of items which we want to be visible.
1529  * The total number of buttons should be equal to arrangable_count * 2.
1530  * No bad things happen, but we could see strange behaviours if we have buttons < (arrangable_count * 2) like a
1531  * pause button appearing on the right of the lower toolbar and weird resizing of the widgets even if there is
1532  * enough space.
1533  */
1534  static const byte arrange14[] = {
1535  WID_TN_PAUSE,
1537  WID_TN_TRAINS,
1539  WID_TN_SHIPS,
1543  WID_TN_RAILS,
1544  WID_TN_ROADS,
1545  WID_TN_WATER,
1546  WID_TN_AIR,
1549  // lower toolbar
1551  WID_TN_SAVE,
1553  WID_TN_TOWNS,
1558  WID_TN_GRAPHS,
1562  WID_TN_HELP,
1564  };
1565  static const byte arrange15[] = {
1566  WID_TN_PAUSE,
1569  WID_TN_TRAINS,
1571  WID_TN_SHIPS,
1573  WID_TN_RAILS,
1574  WID_TN_ROADS,
1575  WID_TN_WATER,
1576  WID_TN_AIR,
1581  // lower toolbar
1582  WID_TN_PAUSE,
1585  WID_TN_SAVE,
1586  WID_TN_TOWNS,
1591  WID_TN_GRAPHS,
1595  WID_TN_HELP,
1597  };
1598  static const byte arrange16[] = {
1599  WID_TN_PAUSE,
1603  WID_TN_TRAINS,
1605  WID_TN_SHIPS,
1607  WID_TN_RAILS,
1608  WID_TN_ROADS,
1609  WID_TN_WATER,
1610  WID_TN_AIR,
1615  // lower toolbar
1616  WID_TN_PAUSE,
1618  WID_TN_SAVE,
1619  WID_TN_TOWNS,
1624  WID_TN_GRAPHS,
1628  WID_TN_HELP,
1632  };
1633  static const byte arrange17[] = {
1634  WID_TN_PAUSE,
1639  WID_TN_TRAINS,
1641  WID_TN_SHIPS,
1643  WID_TN_RAILS,
1644  WID_TN_ROADS,
1645  WID_TN_WATER,
1646  WID_TN_AIR,
1651  // lower toolbar
1652  WID_TN_PAUSE,
1654  WID_TN_SAVE,
1657  WID_TN_TOWNS,
1661  WID_TN_GRAPHS,
1665  WID_TN_HELP,
1669  };
1670  static const byte arrange18[] = {
1671  WID_TN_PAUSE,
1675  WID_TN_TOWNS,
1681  WID_TN_RAILS,
1682  WID_TN_ROADS,
1683  WID_TN_WATER,
1684  WID_TN_AIR,
1689  // lower toolbar
1690  WID_TN_PAUSE,
1692  WID_TN_SAVE,
1694  WID_TN_TOWNS,
1697  WID_TN_GRAPHS,
1698  WID_TN_TRAINS,
1700  WID_TN_SHIPS,
1704  WID_TN_HELP,
1708  };
1709  static const byte arrange19[] = {
1710  WID_TN_PAUSE,
1714  WID_TN_TOWNS,
1716  WID_TN_TRAINS,
1718  WID_TN_SHIPS,
1720  WID_TN_RAILS,
1721  WID_TN_ROADS,
1722  WID_TN_WATER,
1723  WID_TN_AIR,
1729  // lower toolbar
1730  WID_TN_PAUSE,
1732  WID_TN_SAVE,
1737  WID_TN_GRAPHS,
1740  WID_TN_RAILS,
1741  WID_TN_ROADS,
1742  WID_TN_WATER,
1743  WID_TN_AIR,
1745  WID_TN_HELP,
1749  };
1750  static const byte arrange20[] = {
1751  WID_TN_PAUSE,
1755  WID_TN_TOWNS,
1757  WID_TN_TRAINS,
1759  WID_TN_SHIPS,
1761  WID_TN_RAILS,
1762  WID_TN_ROADS,
1763  WID_TN_WATER,
1764  WID_TN_AIR,
1767  WID_TN_GOAL,
1771  // lower toolbar
1772  WID_TN_PAUSE,
1774  WID_TN_SAVE,
1779  WID_TN_GRAPHS,
1782  WID_TN_RAILS,
1783  WID_TN_ROADS,
1784  WID_TN_WATER,
1785  WID_TN_AIR,
1787  WID_TN_STORY,
1788  WID_TN_HELP,
1792  };
1793  static const byte arrange_all[] = {
1794  WID_TN_PAUSE,
1797  WID_TN_SAVE,
1799  WID_TN_TOWNS,
1804  WID_TN_STORY,
1805  WID_TN_GOAL,
1806  WID_TN_GRAPHS,
1807  WID_TN_LEAGUE,
1809  WID_TN_TRAINS,
1811  WID_TN_SHIPS,
1815  WID_TN_RAILS,
1816  WID_TN_ROADS,
1817  WID_TN_TRAMS,
1818  WID_TN_WATER,
1819  WID_TN_AIR,
1823  WID_TN_HELP
1824  };
1825 
1826  /* If at least BIGGEST_ARRANGEMENT fit, just spread all the buttons nicely */
1827  uint full_buttons = max(CeilDiv(width, this->smallest_x), SMALLEST_ARRANGEMENT);
1828  if (full_buttons > BIGGEST_ARRANGEMENT) {
1829  button_count = arrangable_count = lengthof(arrange_all);
1830  spacer_count = this->spacers;
1831  return arrange_all;
1832  }
1833 
1834  /* Introduce the split toolbar */
1835  static const byte * const arrangements[] = { arrange14, arrange15, arrange16, arrange17, arrange18, arrange19, arrange20 };
1836 
1837  button_count = arrangable_count = full_buttons;
1838  spacer_count = this->spacers;
1839  return arrangements[full_buttons - SMALLEST_ARRANGEMENT] + ((_toolbar_mode == TB_LOWER) ? full_buttons : 0);
1840  }
1841 };
1842 
1845  uint panel_widths[2];
1846 
1847  void SetupSmallestSize(Window *w, bool init_array) override
1848  {
1849  this->NWidgetToolbarContainer::SetupSmallestSize(w, init_array);
1850 
1851  /* Find the size of panel_widths */
1852  uint i = 0;
1853  for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
1854  if (child_wid->type == NWID_SPACER || this->IsButton(child_wid->type)) continue;
1855 
1856  assert(i < lengthof(this->panel_widths));
1857  this->panel_widths[i++] = child_wid->current_x;
1858  _toolbar_width += child_wid->current_x;
1859  }
1860  }
1861 
1862  const byte *GetButtonArrangement(uint &width, uint &arrangable_count, uint &button_count, uint &spacer_count) const override
1863  {
1864  static const byte arrange_all[] = {
1865  WID_TE_PAUSE,
1868  WID_TE_SAVE,
1869  WID_TE_SPACER,
1877  WID_TE_ROADS,
1878  WID_TE_TRAMS,
1879  WID_TE_WATER,
1880  WID_TE_TREES,
1881  WID_TE_SIGNS,
1883  WID_TE_HELP,
1884  };
1885  static const byte arrange_nopanel[] = {
1886  WID_TE_PAUSE,
1889  WID_TE_SAVE,
1897  WID_TE_ROADS,
1898  WID_TE_TRAMS,
1899  WID_TE_WATER,
1900  WID_TE_TREES,
1901  WID_TE_SIGNS,
1903  WID_TE_HELP,
1904  };
1905  static const byte arrange_switch[] = {
1911  WID_TE_ROADS,
1912  WID_TE_TRAMS,
1913  WID_TE_WATER,
1914  WID_TE_TREES,
1915  WID_TE_SIGNS,
1917  // lower toolbar
1918  WID_TE_PAUSE,
1921  WID_TE_SAVE,
1927  WID_TE_HELP,
1929  };
1930 
1931  /* If we can place all buttons *and* the panels, show them. */
1932  uint min_full_width = (lengthof(arrange_all) - lengthof(this->panel_widths)) * this->smallest_x + this->panel_widths[0] + this->panel_widths[1];
1933  if (width >= min_full_width) {
1934  width -= this->panel_widths[0] + this->panel_widths[1];
1935  arrangable_count = lengthof(arrange_all);
1936  button_count = arrangable_count - 2;
1937  spacer_count = this->spacers;
1938  return arrange_all;
1939  }
1940 
1941  /* 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 */
1942  uint min_small_width = (lengthof(arrange_switch) - lengthof(this->panel_widths)) * this->smallest_x / 2 + this->panel_widths[1];
1943  if (width > min_small_width) {
1944  width -= this->panel_widths[1];
1945  arrangable_count = lengthof(arrange_nopanel);
1946  button_count = arrangable_count - 1;
1947  spacer_count = this->spacers - 1;
1948  return arrange_nopanel;
1949  }
1950 
1951  /* Split toolbar */
1952  width -= this->panel_widths[1];
1953  arrangable_count = lengthof(arrange_switch) / 2;
1954  button_count = arrangable_count - 1;
1955  spacer_count = 0;
1956  return arrange_switch + ((_toolbar_mode == TB_LOWER) ? arrangable_count : 0);
1957  }
1958 };
1959 
1960 /* --- Toolbar handling for the 'normal' case */
1961 
1962 typedef CallBackFunction ToolbarButtonProc(Window *w);
1963 
1964 static ToolbarButtonProc * const _toolbar_button_procs[] = {
1965  ToolbarPauseClick,
1969  ToolbarMapClick,
1970  ToolbarTownClick,
1971  ToolbarSubsidiesClick,
1972  ToolbarStationsClick,
1973  ToolbarFinancesClick,
1974  ToolbarCompaniesClick,
1975  ToolbarStoryClick,
1976  ToolbarGoalClick,
1977  ToolbarGraphsClick,
1978  ToolbarLeagueClick,
1979  ToolbarIndustryClick,
1980  ToolbarTrainClick,
1981  ToolbarRoadClick,
1982  ToolbarShipClick,
1983  ToolbarAirClick,
1984  ToolbarZoomInClick,
1985  ToolbarZoomOutClick,
1986  ToolbarBuildRailClick,
1987  ToolbarBuildRoadClick,
1988  ToolbarBuildTramClick,
1989  ToolbarBuildWaterClick,
1990  ToolbarBuildAirClick,
1991  ToolbarForestClick,
1992  ToolbarMusicClick,
1993  ToolbarNewspaperClick,
1994  ToolbarHelpClick,
1995  ToolbarSwitchClick,
1996 };
1997 
1998 enum MainToolbarHotkeys {
1999  MTHK_PAUSE,
2000  MTHK_FASTFORWARD,
2001  MTHK_SETTINGS,
2002  MTHK_SAVEGAME,
2003  MTHK_LOADGAME,
2004  MTHK_SMALLMAP,
2005  MTHK_TOWNDIRECTORY,
2006  MTHK_SUBSIDIES,
2007  MTHK_STATIONS,
2008  MTHK_FINANCES,
2009  MTHK_COMPANIES,
2010  MTHK_STORY,
2011  MTHK_GOAL,
2012  MTHK_GRAPHS,
2013  MTHK_LEAGUE,
2014  MTHK_INDUSTRIES,
2015  MTHK_TRAIN_LIST,
2016  MTHK_ROADVEH_LIST,
2017  MTHK_SHIP_LIST,
2018  MTHK_AIRCRAFT_LIST,
2019  MTHK_ZOOM_IN,
2020  MTHK_ZOOM_OUT,
2021  MTHK_BUILD_RAIL,
2022  MTHK_BUILD_ROAD,
2023  MTHK_BUILD_TRAM,
2024  MTHK_BUILD_DOCKS,
2025  MTHK_BUILD_AIRPORT,
2026  MTHK_BUILD_TREES,
2027  MTHK_MUSIC,
2028  MTHK_AI_DEBUG,
2029  MTHK_SMALL_SCREENSHOT,
2030  MTHK_ZOOMEDIN_SCREENSHOT,
2031  MTHK_DEFAULTZOOM_SCREENSHOT,
2032  MTHK_GIANT_SCREENSHOT,
2033  MTHK_CHEATS,
2034  MTHK_TERRAFORM,
2035  MTHK_EXTRA_VIEWPORT,
2036  MTHK_CLIENT_LIST,
2037  MTHK_SIGN_LIST,
2038 };
2039 
2042  GUITimer timer;
2043 
2044  MainToolbarWindow(WindowDesc *desc) : Window(desc)
2045  {
2046  this->InitNested(0);
2047 
2048  _last_started_action = CBF_NONE;
2049  CLRBITS(this->flags, WF_WHITE_BORDER);
2050  this->SetWidgetDisabledState(WID_TN_PAUSE, _networking && !_network_server); // if not server, disable pause button
2051  this->SetWidgetDisabledState(WID_TN_FAST_FORWARD, _networking); // if networking, disable fast-forward button
2052  PositionMainToolbar(this);
2054 
2055  this->timer.SetInterval(MILLISECONDS_PER_TICK);
2056  }
2057 
2058  void FindWindowPlacementAndResize(int def_width, int def_height) override
2059  {
2061  }
2062 
2063  void OnPaint() override
2064  {
2065  /* If spectator, disable all construction buttons
2066  * ie : Build road, rail, ships, airports and landscaping
2067  * Since enabled state is the default, just disable when needed */
2069  /* disable company list drop downs, if there are no companies */
2071 
2072  this->SetWidgetDisabledState(WID_TN_GOAL, Goal::GetNumItems() == 0);
2073  this->SetWidgetDisabledState(WID_TN_STORY, StoryPage::GetNumItems() == 0);
2074 
2075  this->SetWidgetDisabledState(WID_TN_RAILS, !CanBuildVehicleInfrastructure(VEH_TRAIN));
2076  this->SetWidgetDisabledState(WID_TN_ROADS, !CanBuildVehicleInfrastructure(VEH_ROAD, RTT_ROAD));
2077  this->SetWidgetDisabledState(WID_TN_TRAMS, !CanBuildVehicleInfrastructure(VEH_ROAD, RTT_TRAM));
2078  this->SetWidgetDisabledState(WID_TN_AIR, !CanBuildVehicleInfrastructure(VEH_AIRCRAFT));
2079 
2080  this->DrawWidgets();
2081  }
2082 
2083  void OnClick(Point pt, int widget, int click_count) override
2084  {
2085  if (_game_mode != GM_MENU && !this->IsWidgetDisabled(widget)) _toolbar_button_procs[widget](this);
2086  }
2087 
2088  void OnDropdownSelect(int widget, int index) override
2089  {
2090  CallBackFunction cbf = _menu_clicked_procs[widget](index);
2091  if (cbf != CBF_NONE) _last_started_action = cbf;
2092  }
2093 
2094  EventState OnHotkey(int hotkey) override
2095  {
2096  switch (hotkey) {
2097  case MTHK_PAUSE: ToolbarPauseClick(this); break;
2098  case MTHK_FASTFORWARD: ToolbarFastForwardClick(this); break;
2099  case MTHK_SETTINGS: ShowGameOptions(); break;
2100  case MTHK_SAVEGAME: MenuClickSaveLoad(); break;
2101  case MTHK_LOADGAME: ShowSaveLoadDialog(FT_SAVEGAME, SLO_LOAD); break;
2102  case MTHK_SMALLMAP: ShowSmallMap(); break;
2103  case MTHK_TOWNDIRECTORY: ShowTownDirectory(); break;
2104  case MTHK_SUBSIDIES: ShowSubsidiesList(); break;
2105  case MTHK_STATIONS: ShowCompanyStations(_local_company); break;
2106  case MTHK_FINANCES: ShowCompanyFinances(_local_company); break;
2107  case MTHK_COMPANIES: ShowCompany(_local_company); break;
2108  case MTHK_STORY: ShowStoryBook(_local_company); break;
2109  case MTHK_GOAL: ShowGoalsList(_local_company); break;
2110  case MTHK_GRAPHS: ShowOperatingProfitGraph(); break;
2111  case MTHK_LEAGUE: ShowCompanyLeagueTable(); break;
2112  case MTHK_INDUSTRIES: ShowBuildIndustryWindow(); break;
2113  case MTHK_TRAIN_LIST: ShowVehicleListWindow(_local_company, VEH_TRAIN); break;
2114  case MTHK_ROADVEH_LIST: ShowVehicleListWindow(_local_company, VEH_ROAD); break;
2115  case MTHK_SHIP_LIST: ShowVehicleListWindow(_local_company, VEH_SHIP); break;
2116  case MTHK_AIRCRAFT_LIST: ShowVehicleListWindow(_local_company, VEH_AIRCRAFT); break;
2117  case MTHK_ZOOM_IN: ToolbarZoomInClick(this); break;
2118  case MTHK_ZOOM_OUT: ToolbarZoomOutClick(this); break;
2119  case MTHK_BUILD_RAIL: if (CanBuildVehicleInfrastructure(VEH_TRAIN)) ShowBuildRailToolbar(_last_built_railtype); break;
2120  case MTHK_BUILD_ROAD: ShowBuildRoadToolbar(_last_built_roadtype); break;
2121  case MTHK_BUILD_TRAM: if (CanBuildVehicleInfrastructure(VEH_ROAD, RTT_TRAM)) ShowBuildRoadToolbar(_last_built_tramtype); break;
2122  case MTHK_BUILD_DOCKS: ShowBuildDocksToolbar(); break;
2123  case MTHK_BUILD_AIRPORT: if (CanBuildVehicleInfrastructure(VEH_AIRCRAFT)) ShowBuildAirToolbar(); break;
2124  case MTHK_BUILD_TREES: ShowBuildTreesToolbar(); break;
2125  case MTHK_MUSIC: ShowMusicWindow(); break;
2126  case MTHK_AI_DEBUG: ShowAIDebugWindow(); break;
2127  case MTHK_SMALL_SCREENSHOT: MenuClickSmallScreenshot(); break;
2128  case MTHK_ZOOMEDIN_SCREENSHOT: MenuClickLargeWorldScreenshot(SC_ZOOMEDIN); break;
2129  case MTHK_DEFAULTZOOM_SCREENSHOT: MenuClickLargeWorldScreenshot(SC_DEFAULTZOOM); break;
2130  case MTHK_GIANT_SCREENSHOT: MenuClickLargeWorldScreenshot(SC_WORLD); break;
2131  case MTHK_CHEATS: if (!_networking) ShowCheatWindow(); break;
2132  case MTHK_TERRAFORM: ShowTerraformToolbar(); break;
2133  case MTHK_EXTRA_VIEWPORT: ShowExtraViewPortWindowForTileUnderCursor(); break;
2134  case MTHK_CLIENT_LIST: if (_networking) ShowClientList(); break;
2135  case MTHK_SIGN_LIST: ShowSignList(); break;
2136  default: return ES_NOT_HANDLED;
2137  }
2138  return ES_HANDLED;
2139  }
2140 
2141  void OnPlaceObject(Point pt, TileIndex tile) override
2142  {
2143  switch (_last_started_action) {
2144  case CBF_PLACE_SIGN:
2145  PlaceProc_Sign(tile);
2146  break;
2147 
2148  case CBF_PLACE_LANDINFO:
2149  ShowLandInfo(tile);
2150  break;
2151 
2152  default: NOT_REACHED();
2153  }
2154  }
2155 
2156  void OnPlaceObjectAbort() override
2157  {
2158  _last_started_action = CBF_NONE;
2159  }
2160 
2161  void OnRealtimeTick(uint delta_ms) override
2162  {
2163  if (!this->timer.Elapsed(delta_ms)) return;
2164  this->timer.SetInterval(MILLISECONDS_PER_TICK);
2165 
2166  if (this->IsWidgetLowered(WID_TN_PAUSE) != !!_pause_mode) {
2167  this->ToggleWidgetLoweredState(WID_TN_PAUSE);
2168  this->SetWidgetDirty(WID_TN_PAUSE);
2169  }
2170 
2171  if (this->IsWidgetLowered(WID_TN_FAST_FORWARD) != !!_fast_forward) {
2172  this->ToggleWidgetLoweredState(WID_TN_FAST_FORWARD);
2173  this->SetWidgetDirty(WID_TN_FAST_FORWARD);
2174  }
2175  }
2176 
2177  void OnTimeout() override
2178  {
2179  /* We do not want to automatically raise the pause, fast forward and
2180  * switchbar buttons; they have to stay down when pressed etc. */
2181  for (uint i = WID_TN_SETTINGS; i < WID_TN_SWITCH_BAR; i++) {
2182  if (this->IsWidgetLowered(i)) {
2183  this->RaiseWidget(i);
2184  this->SetWidgetDirty(i);
2185  }
2186  }
2187  }
2188 
2194  void OnInvalidateData(int data = 0, bool gui_scope = true) override
2195  {
2196  if (!gui_scope) return;
2198  }
2199 
2200  static HotkeyList hotkeys;
2201 };
2202 
2203 const uint16 _maintoolbar_pause_keys[] = {WKC_F1, WKC_PAUSE, 0};
2204 const uint16 _maintoolbar_zoomin_keys[] = {WKC_NUM_PLUS, WKC_EQUALS, WKC_SHIFT | WKC_EQUALS, WKC_SHIFT | WKC_F5, 0};
2205 const uint16 _maintoolbar_zoomout_keys[] = {WKC_NUM_MINUS, WKC_MINUS, WKC_SHIFT | WKC_MINUS, WKC_SHIFT | WKC_F6, 0};
2206 const uint16 _maintoolbar_smallmap_keys[] = {WKC_F4, 'M', 0};
2207 
2208 static Hotkey maintoolbar_hotkeys[] = {
2209  Hotkey(_maintoolbar_pause_keys, "pause", MTHK_PAUSE),
2210  Hotkey((uint16)0, "fastforward", MTHK_FASTFORWARD),
2211  Hotkey(WKC_F2, "settings", MTHK_SETTINGS),
2212  Hotkey(WKC_F3, "saveload", MTHK_SAVEGAME),
2213  Hotkey((uint16)0, "load_game", MTHK_LOADGAME),
2214  Hotkey(_maintoolbar_smallmap_keys, "smallmap", MTHK_SMALLMAP),
2215  Hotkey(WKC_F5, "town_list", MTHK_TOWNDIRECTORY),
2216  Hotkey(WKC_F6, "subsidies", MTHK_SUBSIDIES),
2217  Hotkey(WKC_F7, "station_list", MTHK_STATIONS),
2218  Hotkey(WKC_F8, "finances", MTHK_FINANCES),
2219  Hotkey(WKC_F9, "companies", MTHK_COMPANIES),
2220  Hotkey((uint16)0, "story_book", MTHK_STORY),
2221  Hotkey((uint16)0, "goal_list", MTHK_GOAL),
2222  Hotkey(WKC_F10, "graphs", MTHK_GRAPHS),
2223  Hotkey(WKC_F11, "league", MTHK_LEAGUE),
2224  Hotkey(WKC_F12, "industry_list", MTHK_INDUSTRIES),
2225  Hotkey(WKC_SHIFT | WKC_F1, "train_list", MTHK_TRAIN_LIST),
2226  Hotkey(WKC_SHIFT | WKC_F2, "roadveh_list", MTHK_ROADVEH_LIST),
2227  Hotkey(WKC_SHIFT | WKC_F3, "ship_list", MTHK_SHIP_LIST),
2228  Hotkey(WKC_SHIFT | WKC_F4, "aircraft_list", MTHK_AIRCRAFT_LIST),
2229  Hotkey(_maintoolbar_zoomin_keys, "zoomin", MTHK_ZOOM_IN),
2230  Hotkey(_maintoolbar_zoomout_keys, "zoomout", MTHK_ZOOM_OUT),
2231  Hotkey(WKC_SHIFT | WKC_F7, "build_rail", MTHK_BUILD_RAIL),
2232  Hotkey(WKC_SHIFT | WKC_F8, "build_road", MTHK_BUILD_ROAD),
2233  Hotkey((uint16)0, "build_tram", MTHK_BUILD_TRAM),
2234  Hotkey(WKC_SHIFT | WKC_F9, "build_docks", MTHK_BUILD_DOCKS),
2235  Hotkey(WKC_SHIFT | WKC_F10, "build_airport", MTHK_BUILD_AIRPORT),
2236  Hotkey(WKC_SHIFT | WKC_F11, "build_trees", MTHK_BUILD_TREES),
2237  Hotkey(WKC_SHIFT | WKC_F12, "music", MTHK_MUSIC),
2238  Hotkey((uint16)0, "ai_debug", MTHK_AI_DEBUG),
2239  Hotkey(WKC_CTRL | 'S', "small_screenshot", MTHK_SMALL_SCREENSHOT),
2240  Hotkey(WKC_CTRL | 'P', "zoomedin_screenshot", MTHK_ZOOMEDIN_SCREENSHOT),
2241  Hotkey(WKC_CTRL | 'D', "defaultzoom_screenshot", MTHK_DEFAULTZOOM_SCREENSHOT),
2242  Hotkey((uint16)0, "giant_screenshot", MTHK_GIANT_SCREENSHOT),
2243  Hotkey(WKC_CTRL | WKC_ALT | 'C', "cheats", MTHK_CHEATS),
2244  Hotkey('L', "terraform", MTHK_TERRAFORM),
2245  Hotkey('V', "extra_viewport", MTHK_EXTRA_VIEWPORT),
2246  Hotkey((uint16)0, "client_list", MTHK_CLIENT_LIST),
2247  Hotkey((uint16)0, "sign_list", MTHK_SIGN_LIST),
2248  HOTKEY_LIST_END
2249 };
2250 HotkeyList MainToolbarWindow::hotkeys("maintoolbar", maintoolbar_hotkeys);
2251 
2252 static NWidgetBase *MakeMainToolbar(int *biggest_index)
2253 {
2255  static const SpriteID toolbar_button_sprites[] = {
2256  SPR_IMG_PAUSE, // WID_TN_PAUSE
2257  SPR_IMG_FASTFORWARD, // WID_TN_FAST_FORWARD
2258  SPR_IMG_SETTINGS, // WID_TN_SETTINGS
2259  SPR_IMG_SAVE, // WID_TN_SAVE
2260  SPR_IMG_SMALLMAP, // WID_TN_SMALL_MAP
2261  SPR_IMG_TOWN, // WID_TN_TOWNS
2262  SPR_IMG_SUBSIDIES, // WID_TN_SUBSIDIES
2263  SPR_IMG_COMPANY_LIST, // WID_TN_STATIONS
2264  SPR_IMG_COMPANY_FINANCE, // WID_TN_FINANCES
2265  SPR_IMG_COMPANY_GENERAL, // WID_TN_COMPANIES
2266  SPR_IMG_STORY_BOOK, // WID_TN_STORY
2267  SPR_IMG_GOAL, // WID_TN_GOAL
2268  SPR_IMG_GRAPHS, // WID_TN_GRAPHS
2269  SPR_IMG_COMPANY_LEAGUE, // WID_TN_LEAGUE
2270  SPR_IMG_INDUSTRY, // WID_TN_INDUSTRIES
2271  SPR_IMG_TRAINLIST, // WID_TN_TRAINS
2272  SPR_IMG_TRUCKLIST, // WID_TN_ROADVEHS
2273  SPR_IMG_SHIPLIST, // WID_TN_SHIPS
2274  SPR_IMG_AIRPLANESLIST, // WID_TN_AIRCRAFT
2275  SPR_IMG_ZOOMIN, // WID_TN_ZOOMIN
2276  SPR_IMG_ZOOMOUT, // WID_TN_ZOOMOUT
2277  SPR_IMG_BUILDRAIL, // WID_TN_RAILS
2278  SPR_IMG_BUILDROAD, // WID_TN_ROADS
2279  SPR_IMG_BUILDTRAMS, // WID_TN_TRAMS
2280  SPR_IMG_BUILDWATER, // WID_TN_WATER
2281  SPR_IMG_BUILDAIR, // WID_TN_AIR
2282  SPR_IMG_LANDSCAPING, // WID_TN_LANDSCAPE
2283  SPR_IMG_MUSIC, // WID_TN_MUSIC_SOUND
2284  SPR_IMG_MESSAGES, // WID_TN_MESSAGES
2285  SPR_IMG_QUERY, // WID_TN_HELP
2286  SPR_IMG_SWITCH_TOOLBAR, // WID_TN_SWITCH_BAR
2287  };
2288 
2290  for (uint i = 0; i < WID_TN_END; i++) {
2291  switch (i) {
2292  case WID_TN_SMALL_MAP:
2293  case WID_TN_FINANCES:
2294  case WID_TN_VEHICLE_START:
2295  case WID_TN_ZOOM_IN:
2297  case WID_TN_MUSIC_SOUND:
2298  hor->Add(new NWidgetSpacer(0, 0));
2299  break;
2300  }
2301  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));
2302  }
2303 
2304  *biggest_index = max<int>(*biggest_index, WID_TN_SWITCH_BAR);
2305  return hor;
2306 }
2307 
2308 static const NWidgetPart _nested_toolbar_normal_widgets[] = {
2310 };
2311 
2312 static WindowDesc _toolb_normal_desc(
2313  WDP_MANUAL, nullptr, 0, 0,
2315  WDF_NO_FOCUS,
2316  _nested_toolbar_normal_widgets, lengthof(_nested_toolbar_normal_widgets),
2317  &MainToolbarWindow::hotkeys
2318 );
2319 
2320 
2321 /* --- Toolbar handling for the scenario editor */
2322 
2323 static MenuClickedProc * const _scen_toolbar_dropdown_procs[] = {
2324  nullptr, // 0
2325  nullptr, // 1
2326  MenuClickSettings, // 2
2327  MenuClickSaveLoad, // 3
2328  nullptr, // 4
2329  nullptr, // 5
2330  nullptr, // 6
2331  nullptr, // 7
2332  MenuClickMap, // 8
2333  nullptr, // 9
2334  nullptr, // 10
2335  nullptr, // 11
2336  nullptr, // 12
2337  nullptr, // 13
2338  ToolbarScenBuildRoad, // 14
2339  ToolbarScenBuildTram, // 15
2340  nullptr, // 16
2341  nullptr, // 17
2342  nullptr, // 18
2343  nullptr, // 19
2344  MenuClickMusicWindow, // 20
2345  MenuClickHelp, // 21
2346  nullptr, // 22
2347 };
2348 
2349 static ToolbarButtonProc * const _scen_toolbar_button_procs[] = {
2350  ToolbarPauseClick,
2354  ToolbarBtn_NULL,
2356  ToolbarScenDateBackward,
2357  ToolbarScenDateForward,
2358  ToolbarScenMapTownDir,
2359  ToolbarZoomInClick,
2360  ToolbarZoomOutClick,
2361  ToolbarScenGenLand,
2362  ToolbarScenGenTown,
2363  ToolbarScenGenIndustry,
2364  ToolbarScenBuildRoadClick,
2365  ToolbarScenBuildTramClick,
2366  ToolbarScenBuildDocks,
2367  ToolbarScenPlantTrees,
2368  ToolbarScenPlaceSign,
2369  ToolbarBtn_NULL,
2370  ToolbarMusicClick,
2371  ToolbarHelpClick,
2372  ToolbarSwitchClick,
2373 };
2374 
2375 enum MainToolbarEditorHotkeys {
2376  MTEHK_PAUSE,
2377  MTEHK_FASTFORWARD,
2378  MTEHK_SETTINGS,
2379  MTEHK_SAVEGAME,
2380  MTEHK_GENLAND,
2381  MTEHK_GENTOWN,
2382  MTEHK_GENINDUSTRY,
2383  MTEHK_BUILD_ROAD,
2384  MTEHK_BUILD_TRAM,
2385  MTEHK_BUILD_DOCKS,
2386  MTEHK_BUILD_TREES,
2387  MTEHK_SIGN,
2388  MTEHK_MUSIC,
2389  MTEHK_LANDINFO,
2390  MTEHK_SMALL_SCREENSHOT,
2391  MTEHK_ZOOMEDIN_SCREENSHOT,
2392  MTEHK_DEFAULTZOOM_SCREENSHOT,
2393  MTEHK_GIANT_SCREENSHOT,
2394  MTEHK_ZOOM_IN,
2395  MTEHK_ZOOM_OUT,
2396  MTEHK_TERRAFORM,
2397  MTEHK_SMALLMAP,
2398  MTEHK_EXTRA_VIEWPORT,
2399 };
2400 
2402  GUITimer timer;
2403 
2405  {
2406  this->InitNested(0);
2407 
2408  _last_started_action = CBF_NONE;
2409  CLRBITS(this->flags, WF_WHITE_BORDER);
2410  PositionMainToolbar(this);
2412 
2413  this->timer.SetInterval(MILLISECONDS_PER_TICK);
2414  }
2415 
2416  void FindWindowPlacementAndResize(int def_width, int def_height) override
2417  {
2419  }
2420 
2421  void OnPaint() override
2422  {
2423  this->SetWidgetDisabledState(WID_TE_DATE_BACKWARD, _settings_game.game_creation.starting_year <= MIN_YEAR);
2424  this->SetWidgetDisabledState(WID_TE_DATE_FORWARD, _settings_game.game_creation.starting_year >= MAX_YEAR);
2425  this->SetWidgetDisabledState(WID_TE_ROADS, (GetRoadTypes(true) & ~_roadtypes_type) == ROADTYPES_NONE);
2426  this->SetWidgetDisabledState(WID_TE_TRAMS, (GetRoadTypes(true) & _roadtypes_type) == ROADTYPES_NONE);
2427 
2428  this->DrawWidgets();
2429  }
2430 
2431  void DrawWidget(const Rect &r, int widget) const override
2432  {
2433  switch (widget) {
2434  case WID_TE_DATE:
2436  DrawString(r.left, r.right, (this->height - FONT_HEIGHT_NORMAL) / 2, STR_WHITE_DATE_LONG, TC_FROMSTRING, SA_HOR_CENTER);
2437  break;
2438 
2439  case WID_TE_SPACER: {
2440  int height = r.bottom - r.top;
2441  if (height > 2 * FONT_HEIGHT_NORMAL) {
2442  DrawString(r.left, r.right, (height + 1) / 2 - FONT_HEIGHT_NORMAL, STR_SCENEDIT_TOOLBAR_OPENTTD, TC_FROMSTRING, SA_HOR_CENTER);
2443  DrawString(r.left, r.right, (height + 1) / 2, STR_SCENEDIT_TOOLBAR_SCENARIO_EDITOR, TC_FROMSTRING, SA_HOR_CENTER);
2444  } else {
2445  DrawString(r.left, r.right, (height - FONT_HEIGHT_NORMAL) / 2, STR_SCENEDIT_TOOLBAR_SCENARIO_EDITOR, TC_FROMSTRING, SA_HOR_CENTER);
2446  }
2447  break;
2448  }
2449  }
2450  }
2451 
2452  void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
2453  {
2454  switch (widget) {
2455  case WID_TE_SPACER:
2456  size->width = max(GetStringBoundingBox(STR_SCENEDIT_TOOLBAR_OPENTTD).width, GetStringBoundingBox(STR_SCENEDIT_TOOLBAR_SCENARIO_EDITOR).width) + WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT;
2457  break;
2458 
2459  case WID_TE_DATE:
2460  SetDParam(0, ConvertYMDToDate(MAX_YEAR, 0, 1));
2461  *size = GetStringBoundingBox(STR_WHITE_DATE_LONG);
2462  size->height = max(size->height, GetSpriteSize(SPR_IMG_SAVE).height + WD_IMGBTN_TOP + WD_IMGBTN_BOTTOM);
2463  break;
2464  }
2465  }
2466 
2467  void OnClick(Point pt, int widget, int click_count) override
2468  {
2469  if (_game_mode == GM_MENU) return;
2470  CallBackFunction cbf = _scen_toolbar_button_procs[widget](this);
2471  if (cbf != CBF_NONE) _last_started_action = cbf;
2472  }
2473 
2474  void OnDropdownSelect(int widget, int index) override
2475  {
2476  CallBackFunction cbf = _scen_toolbar_dropdown_procs[widget](index);
2477  if (cbf != CBF_NONE) _last_started_action = cbf;
2478  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
2479  }
2480 
2481  EventState OnHotkey(int hotkey) override
2482  {
2483  CallBackFunction cbf = CBF_NONE;
2484  switch (hotkey) {
2485  case MTEHK_PAUSE: ToolbarPauseClick(this); break;
2486  case MTEHK_FASTFORWARD: ToolbarFastForwardClick(this); break;
2487  case MTEHK_SETTINGS: ShowGameOptions(); break;
2488  case MTEHK_SAVEGAME: MenuClickSaveLoad(); break;
2489  case MTEHK_GENLAND: ToolbarScenGenLand(this); break;
2490  case MTEHK_GENTOWN: ToolbarScenGenTown(this); break;
2491  case MTEHK_GENINDUSTRY: ToolbarScenGenIndustry(this); break;
2492  case MTEHK_BUILD_ROAD: ToolbarScenBuildRoadClick(this); break;
2493  case MTEHK_BUILD_TRAM: ToolbarScenBuildTramClick(this); break;
2494  case MTEHK_BUILD_DOCKS: ToolbarScenBuildDocks(this); break;
2495  case MTEHK_BUILD_TREES: ToolbarScenPlantTrees(this); break;
2496  case MTEHK_SIGN: cbf = ToolbarScenPlaceSign(this); break;
2497  case MTEHK_MUSIC: ShowMusicWindow(); break;
2498  case MTEHK_LANDINFO: cbf = PlaceLandBlockInfo(); break;
2499  case MTEHK_SMALL_SCREENSHOT: MenuClickSmallScreenshot(); break;
2500  case MTEHK_ZOOMEDIN_SCREENSHOT: MenuClickLargeWorldScreenshot(SC_ZOOMEDIN); break;
2501  case MTEHK_DEFAULTZOOM_SCREENSHOT: MenuClickLargeWorldScreenshot(SC_DEFAULTZOOM); break;
2502  case MTEHK_GIANT_SCREENSHOT: MenuClickLargeWorldScreenshot(SC_WORLD); break;
2503  case MTEHK_ZOOM_IN: ToolbarZoomInClick(this); break;
2504  case MTEHK_ZOOM_OUT: ToolbarZoomOutClick(this); break;
2505  case MTEHK_TERRAFORM: ShowEditorTerraformToolbar(); break;
2506  case MTEHK_SMALLMAP: ShowSmallMap(); break;
2507  case MTEHK_EXTRA_VIEWPORT: ShowExtraViewPortWindowForTileUnderCursor(); break;
2508  default: return ES_NOT_HANDLED;
2509  }
2510  if (cbf != CBF_NONE) _last_started_action = cbf;
2511  return ES_HANDLED;
2512  }
2513 
2514  void OnPlaceObject(Point pt, TileIndex tile) override
2515  {
2516  switch (_last_started_action) {
2517  case CBF_PLACE_SIGN:
2518  PlaceProc_Sign(tile);
2519  break;
2520 
2521  case CBF_PLACE_LANDINFO:
2522  ShowLandInfo(tile);
2523  break;
2524 
2525  default: NOT_REACHED();
2526  }
2527  }
2528 
2529  void OnPlaceObjectAbort() override
2530  {
2531  _last_started_action = CBF_NONE;
2532  }
2533 
2534  void OnTimeout() override
2535  {
2536  this->SetWidgetsLoweredState(false, WID_TE_DATE_BACKWARD, WID_TE_DATE_FORWARD, WIDGET_LIST_END);
2537  this->SetWidgetDirty(WID_TE_DATE_BACKWARD);
2538  this->SetWidgetDirty(WID_TE_DATE_FORWARD);
2539  }
2540 
2541  void OnRealtimeTick(uint delta_ms) override
2542  {
2543  if (!this->timer.Elapsed(delta_ms)) return;
2544  this->timer.SetInterval(MILLISECONDS_PER_TICK);
2545 
2546  if (this->IsWidgetLowered(WID_TE_PAUSE) != !!_pause_mode) {
2547  this->ToggleWidgetLoweredState(WID_TE_PAUSE);
2548  this->SetDirty();
2549  }
2550 
2551  if (this->IsWidgetLowered(WID_TE_FAST_FORWARD) != !!_fast_forward) {
2552  this->ToggleWidgetLoweredState(WID_TE_FAST_FORWARD);
2553  this->SetDirty();
2554  }
2555  }
2556 
2562  void OnInvalidateData(int data = 0, bool gui_scope = true) override
2563  {
2564  if (!gui_scope) return;
2566  }
2567 
2568  void OnQueryTextFinished(char *str) override
2569  {
2570  /* Was 'cancel' pressed? */
2571  if (str == nullptr) return;
2572 
2573  int32 value;
2574  if (!StrEmpty(str)) {
2575  value = atoi(str);
2576  } else {
2577  /* An empty string means revert to the default */
2578  value = DEF_START_YEAR;
2579  }
2580  SetStartingYear(value);
2581 
2582  this->SetDirty();
2583  }
2584 
2585  static HotkeyList hotkeys;
2586 };
2587 
2588 static Hotkey scenedit_maintoolbar_hotkeys[] = {
2589  Hotkey(_maintoolbar_pause_keys, "pause", MTEHK_PAUSE),
2590  Hotkey((uint16)0, "fastforward", MTEHK_FASTFORWARD),
2591  Hotkey(WKC_F2, "settings", MTEHK_SETTINGS),
2592  Hotkey(WKC_F3, "saveload", MTEHK_SAVEGAME),
2593  Hotkey(WKC_F4, "gen_land", MTEHK_GENLAND),
2594  Hotkey(WKC_F5, "gen_town", MTEHK_GENTOWN),
2595  Hotkey(WKC_F6, "gen_industry", MTEHK_GENINDUSTRY),
2596  Hotkey(WKC_F7, "build_road", MTEHK_BUILD_ROAD),
2597  Hotkey((uint16)0, "build_tram", MTEHK_BUILD_TRAM),
2598  Hotkey(WKC_F8, "build_docks", MTEHK_BUILD_DOCKS),
2599  Hotkey(WKC_F9, "build_trees", MTEHK_BUILD_TREES),
2600  Hotkey(WKC_F10, "build_sign", MTEHK_SIGN),
2601  Hotkey(WKC_F11, "music", MTEHK_MUSIC),
2602  Hotkey(WKC_F12, "land_info", MTEHK_LANDINFO),
2603  Hotkey(WKC_CTRL | 'S', "small_screenshot", MTEHK_SMALL_SCREENSHOT),
2604  Hotkey(WKC_CTRL | 'P', "zoomedin_screenshot", MTEHK_ZOOMEDIN_SCREENSHOT),
2605  Hotkey(WKC_CTRL | 'D', "defaultzoom_screenshot", MTEHK_DEFAULTZOOM_SCREENSHOT),
2606  Hotkey((uint16)0, "giant_screenshot", MTEHK_GIANT_SCREENSHOT),
2607  Hotkey(_maintoolbar_zoomin_keys, "zoomin", MTEHK_ZOOM_IN),
2608  Hotkey(_maintoolbar_zoomout_keys, "zoomout", MTEHK_ZOOM_OUT),
2609  Hotkey('L', "terraform", MTEHK_TERRAFORM),
2610  Hotkey('M', "smallmap", MTEHK_SMALLMAP),
2611  Hotkey('V', "extra_viewport", MTEHK_EXTRA_VIEWPORT),
2612  HOTKEY_LIST_END
2613 };
2614 HotkeyList ScenarioEditorToolbarWindow::hotkeys("scenedit_maintoolbar", scenedit_maintoolbar_hotkeys);
2615 
2616 static const NWidgetPart _nested_toolb_scen_inner_widgets[] = {
2617  NWidget(WWT_IMGBTN, COLOUR_GREY, WID_TE_PAUSE), SetDataTip(SPR_IMG_PAUSE, STR_TOOLBAR_TOOLTIP_PAUSE_GAME),
2618  NWidget(WWT_IMGBTN, COLOUR_GREY, WID_TE_FAST_FORWARD), SetDataTip(SPR_IMG_FASTFORWARD, STR_TOOLBAR_TOOLTIP_FORWARD),
2619  NWidget(WWT_IMGBTN, COLOUR_GREY, WID_TE_SETTINGS), SetDataTip(SPR_IMG_SETTINGS, STR_TOOLBAR_TOOLTIP_OPTIONS),
2620  NWidget(WWT_IMGBTN_2, COLOUR_GREY, WID_TE_SAVE), SetDataTip(SPR_IMG_SAVE, STR_SCENEDIT_TOOLBAR_TOOLTIP_SAVE_SCENARIO_LOAD_SCENARIO),
2622  NWidget(WWT_PANEL, COLOUR_GREY, WID_TE_SPACER), EndContainer(),
2624  NWidget(WWT_PANEL, COLOUR_GREY, WID_TE_DATE_PANEL),
2625  NWidget(NWID_HORIZONTAL), SetPIP(3, 2, 3),
2626  NWidget(WWT_IMGBTN, COLOUR_GREY, WID_TE_DATE_BACKWARD), SetDataTip(SPR_ARROW_DOWN, STR_SCENEDIT_TOOLBAR_TOOLTIP_MOVE_THE_STARTING_DATE_BACKWARD),
2627  NWidget(WWT_EMPTY, COLOUR_GREY, WID_TE_DATE), SetDataTip(STR_NULL, STR_SCENEDIT_TOOLBAR_TOOLTIP_SET_DATE),
2628  NWidget(WWT_IMGBTN, COLOUR_GREY, WID_TE_DATE_FORWARD), SetDataTip(SPR_ARROW_UP, STR_SCENEDIT_TOOLBAR_TOOLTIP_MOVE_THE_STARTING_DATE_FORWARD),
2629  EndContainer(),
2630  EndContainer(),
2632  NWidget(WWT_IMGBTN, COLOUR_GREY, WID_TE_SMALL_MAP), SetDataTip(SPR_IMG_SMALLMAP, STR_SCENEDIT_TOOLBAR_TOOLTIP_DISPLAY_MAP_TOWN_DIRECTORY),
2634  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_TE_ZOOM_IN), SetDataTip(SPR_IMG_ZOOMIN, STR_TOOLBAR_TOOLTIP_ZOOM_THE_VIEW_IN),
2635  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_TE_ZOOM_OUT), SetDataTip(SPR_IMG_ZOOMOUT, STR_TOOLBAR_TOOLTIP_ZOOM_THE_VIEW_OUT),
2637  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_TE_LAND_GENERATE), SetDataTip(SPR_IMG_LANDSCAPING, STR_SCENEDIT_TOOLBAR_LANDSCAPE_GENERATION),
2638  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_TE_TOWN_GENERATE), SetDataTip(SPR_IMG_TOWN, STR_SCENEDIT_TOOLBAR_TOWN_GENERATION),
2639  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_TE_INDUSTRY), SetDataTip(SPR_IMG_INDUSTRY, STR_SCENEDIT_TOOLBAR_INDUSTRY_GENERATION),
2640  NWidget(WWT_IMGBTN, COLOUR_GREY, WID_TE_ROADS), SetDataTip(SPR_IMG_BUILDROAD, STR_SCENEDIT_TOOLBAR_ROAD_CONSTRUCTION),
2641  NWidget(WWT_IMGBTN, COLOUR_GREY, WID_TE_TRAMS), SetDataTip(SPR_IMG_BUILDTRAMS, STR_SCENEDIT_TOOLBAR_TRAM_CONSTRUCTION),
2642  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_TE_WATER), SetDataTip(SPR_IMG_BUILDWATER, STR_TOOLBAR_TOOLTIP_BUILD_SHIP_DOCKS),
2643  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_TE_TREES), SetDataTip(SPR_IMG_PLANTTREES, STR_SCENEDIT_TOOLBAR_PLANT_TREES),
2644  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_TE_SIGNS), SetDataTip(SPR_IMG_SIGN, STR_SCENEDIT_TOOLBAR_PLACE_SIGN),
2646  NWidget(WWT_IMGBTN, COLOUR_GREY, WID_TE_MUSIC_SOUND), SetDataTip(SPR_IMG_MUSIC, STR_TOOLBAR_TOOLTIP_SHOW_SOUND_MUSIC_WINDOW),
2647  NWidget(WWT_IMGBTN, COLOUR_GREY, WID_TE_HELP), SetDataTip(SPR_IMG_QUERY, STR_TOOLBAR_TOOLTIP_LAND_BLOCK_INFORMATION),
2648  NWidget(WWT_IMGBTN, COLOUR_GREY, WID_TE_SWITCH_BAR), SetDataTip(SPR_IMG_SWITCH_TOOLBAR, STR_TOOLBAR_TOOLTIP_SWITCH_TOOLBAR),
2649 };
2650 
2651 static NWidgetBase *MakeScenarioToolbar(int *biggest_index)
2652 {
2653  return MakeNWidgets(_nested_toolb_scen_inner_widgets, lengthof(_nested_toolb_scen_inner_widgets), biggest_index, new NWidgetScenarioToolbarContainer());
2654 }
2655 
2656 static const NWidgetPart _nested_toolb_scen_widgets[] = {
2657  NWidgetFunction(MakeScenarioToolbar),
2658 };
2659 
2660 static WindowDesc _toolb_scen_desc(
2661  WDP_MANUAL, nullptr, 0, 0,
2663  WDF_NO_FOCUS,
2664  _nested_toolb_scen_widgets, lengthof(_nested_toolb_scen_widgets),
2665  &ScenarioEditorToolbarWindow::hotkeys
2666 );
2667 
2670 {
2671  /* Clean old GUI values; railtype is (re)set by rail_gui.cpp */
2672  _last_built_roadtype = ROADTYPE_ROAD;
2673  _last_built_tramtype = ROADTYPE_TRAM;
2674 
2675  if (_game_mode == GM_EDITOR) {
2676  new ScenarioEditorToolbarWindow(&_toolb_scen_desc);
2677  } else {
2678  new MainToolbarWindow(&_toolb_normal_desc);
2679  }
2680 }
EventState
State of handling an event.
Definition: window_type.h:713
World screenshot.
Definition: screenshot.h:25
bool DoZoomInOutWindow(ZoomStateChange how, Window *w)
Zooms a viewport in a window in or out.
Definition: main_gui.cpp:138
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:870
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:20
Empty widget, place holder to reserve space in widget array.
Definition: widget_type.h:48
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:111
Full blown container to make it behave exactly as we want :)
Normal push-button (no toggle button) with image caption.
Definition: widget_type.h:105
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:956
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:81
used in multiplayer to create a new companies etc.
Definition: command_type.h:280
bool _networking
are we in networking mode?
Definition: network.cpp:54
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:97
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:112
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:1146
void SetWidgetLoweredState(byte widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
Definition: window_gui.h:455
RoadTypes _roadtypes_type
Bitmap of road/tram types.
Definition: road_cmd.cpp:59
Subsidy menu.
All data for a single hotkey.
Definition: hotkeys.h:24
High level window description.
Definition: window_gui.h:168
(Toggle) Button with diff image when clicked
Definition: widget_type.h:53
signs
Definition: transparency.h:25
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:312
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:905
Train vehicle type.
Definition: vehicle_type.h:26
Help menu.
Zoom out (get helicopter view).
Definition: viewport_type.h:64
int height
Screen height of the viewport.
Definition: viewport_type.h:28
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:48
static CallBackFunction MenuClickShowTrains(int index)
Handle click on the entry in the Train menu.
Baseclass for container widgets.
Definition: widget_type.h:368
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:478
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:29
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:75
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:1114
The passed event is not handled.
Definition: window_type.h:715
Display station names.
Definition: openttd.h:44
bool Elapsed(uint delta)
Test if a timer has elapsed.
Definition: guitimer_func.h:57
int PositionMainToolbar(Window *w)
(Re)position main toolbar window at the screen.
Definition: window.cpp:3486
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:1121
Ship vehicle type.
Definition: vehicle_type.h:28
WidgetType type
Type of the widget / nested widget.
Definition: widget_type.h:163
Settings menu.
Aircraft menu.
Types for recording game performance data.
VehicleType
Available vehicle types.
Definition: vehicle_type.h:23
Small map menu.
Road specific functions.
Window * ShowSignList()
Open the sign list window.
Definition: signs_gui.cpp:407
Sign list; Window numbers:
Definition: window_type.h:273
Screenshot of viewport.
Definition: screenshot.h:21
Window * ShowBuildRoadToolbar(RoadType roadtype)
Open the build road toolbar window.
Definition: road_gui.cpp:869
Functions related to vehicles.
void DrawCompanyIcon(CompanyID c, int x, int y)
Draw the icon of a company.
= Equals
Definition: gfx_type.h:99
void ShowGoalsList(CompanyID company)
Open a goal list window.
Definition: goal_gui.cpp:351
Window * ShowBuildDocksToolbar()
Open the build water toolbar window.
Definition: dock_gui.cpp:349
Vehicle data structure.
Definition: vehicle_base.h:212
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:43
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:49
EventState OnHotkey(int hotkey) override
A hotkey has been pressed.
Also draw details of track and roads.
Definition: openttd.h:47
void ShowAIConfigWindow()
Open the AI config window.
Definition: ai_gui.cpp:964
Zoom in (get more detailed view).
Definition: viewport_type.h:63
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:979
bool NetworkCompanyIsPassworded(CompanyID company_id)
Check if the company we want to join requires a password.
Definition: network.cpp:223
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:3397
Spacer widget.
Definition: widget_type.h:529
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:1993
int32 Year
Type for the year, note: 0 based, i.e. starts at the year 0.
Definition: date_type.h:20
Functions related to signs.
RoadType
The different roadtypes we support.
Definition: road_type.h:27
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:26
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:23
Town menu.
Common string list item.
Definition: dropdown_type.h:41
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:2792
Functions related to the vehicle&#39;s GUIs.
CallBackFunction
Callback functions.
Definition: toolbar_gui.cpp:80
File is being saved.
Definition: fileio_type.h:52
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:96
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:41
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:250
Display signs.
Definition: openttd.h:45
Industry menu.
static const Year DEF_START_YEAR
The default starting year.
Definition: date_type.h:88
Leaf widget.
Definition: widget_type.h:770
void AllocateToolbar()
Allocate the toolbar.
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:910
void ShowLandInfo(TileIndex tile)
Show land information window.
Definition: misc_gui.cpp:386
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:278
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:180
old or new savegame
Definition: fileio_type.h:20
old or new scenario
Definition: fileio_type.h:21
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:3318
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:43
town buildings
Definition: transparency.h:27
Main window; Window numbers:
Definition: window_type.h:46
void SetDate(Date date, DateFract fract)
Set the date.
Definition: date.cpp:37
enable the &#39;Default&#39; button ("\0" is returned)
Definition: textbuf_gui.h:23
void Add(NWidgetBase *wid)
Append widget wid to container.
Definition: widget.cpp:944
SaveLoadNormalMenuEntries
SaveLoad entries in normal game mode.
Only numeric ones.
Definition: string_type.h:30
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:79
virtual bool IsPrimaryVehicle() const
Whether this is the primary vehicle in the chain.
Definition: vehicle_base.h:433
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:58
The client is spectating.
Definition: company_type.h:37
Only available when toolbar has been split to switch between different subsets.
List item with icon and string.
Definition: dropdown_type.h:83
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:1262
GUI functions related to the news.
static CallBackFunction _last_started_action
Last started user action.
Definition: toolbar_gui.cpp:86
static LinkGraphSchedule instance
Static instance of LinkGraphSchedule.
void ShowMessageHistory()
Display window with news messages history.
Definition: news_gui.cpp:1195
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:178
static NWidgetPart SetDataTip(uint32 data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1014
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:61
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:80
bool masked
Masked and unselectable item.
Definition: dropdown_type.h:27
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:30
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition: gfx_type.h:247
List of hotkeys for a window.
Definition: hotkeys.h:42
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:50
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:316
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:306
Drop down list entry for showing a checked/unchecked toggle item.
Definition: toolbar_gui.cpp:92
Window timeout counter.
Definition: window_gui.h:234
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:979
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:418
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:1114
A game normally paused.
Definition: openttd.h:59
Baseclass for nested widgets.
Definition: widget_type.h:126
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:499
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.
Owner owner
Which company owns the vehicle?
Definition: vehicle_base.h:273
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:534
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:71
#define lengthof(x)
Return the length of an fixed size array.
Definition: depend.cpp:42
static CallBackFunction MenuClickBuildWater(int index)
Handle click on the entry in the Build Waterways menu.
File is being loaded.
Definition: fileio_type.h:51
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:181
Window * ShowBuildAirToolbar()
Open the build airport toolbar window.
PauseMode _pause_mode
The current pause mode.
Definition: gfx.cpp:49
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:18
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:1529
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:22
bool CanBuildVehicleInfrastructure(VehicleType type, byte subtype)
Check whether we can build infrastructure for the given vehicle type.
Definition: vehicle.cpp:1760
static T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Definition: math_func.hpp:139
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:968
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:812
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:698
static const uint8 PC_VERY_DARK_RED
Almost-black red palette colour.
Definition: gfx_func.h:210
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:284
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:40
Zoom out the main viewport.
Save menu.
static const uint8 PC_DARK_RED
Dark red palette colour.
Definition: gfx_func.h:211
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:46
An invalid company.
Definition: company_type.h:32
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:29
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
Story menu.
Base class for all vehicles.
Data structure for viewport, display of a part of the world.
Definition: viewport_type.h:24
uint32 SpriteID
The number of a sprite, without mapping bits and colourtables.
Definition: gfx_type.h:19
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
Definition: string_func.h:59
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:24
void OnPaint() override
The window must be repainted.
uint32 TileIndex
The index/ID of a Tile.
Definition: tile_type.h:80
void ShowSaveLoadDialog(AbstractFileType abstract_filetype, SaveLoadOperation fop)
Launch save/load dialog in the given mode.
Definition: fios_gui.cpp:890
uint _toolbar_width
Width of the toolbar, shared by statusbar.
Definition: toolbar_gui.cpp:64
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:276
Water building toolbar.
First company, same as owner.
Definition: company_type.h:24
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:50
int result
Result code to return to window on selection.
Definition: dropdown_type.h:26
static ScreenshotType _confirmed_screenshot_type
Screenshot type the current query is about to confirm.
Definition: toolbar_gui.cpp:70
This window won&#39;t get focus/make any other window lose focus when click.
Definition: window_gui.h:212
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:42
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:999
Do not add shading to this text colour.
Definition: gfx_type.h:271
Container for the &#39;normal&#39; main toolbar.
void OnPaint() override
The window must be repainted.
Main toolbar.
VehicleType type
Type of vehicle.
Definition: vehicle_type.h:54
uint current_x
Current horizontal size (after resizing).
Definition: widget_type.h:174
Goal base class.
Maximum number of companies.
Definition: company_type.h:25
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:55
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:754
Main toolbar (the long bar at the top); Window numbers:
Definition: window_type.h:53
Coordinates of a point in 2D.
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition: gfx.cpp:767
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:46
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:235
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:3326
heightmap file
Definition: fileio_type.h:22
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:85
StoryPage base class.
Container for the date widgets.
int32 Date
The type to store our dates in.
Definition: date_type.h:16
Aircraft vehicle type.
Definition: vehicle_type.h:29
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:619
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:1506
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:63
Zoom out the main viewport.
Tram building menu.
ToolbarMode
Toobar modes.
Definition: toolbar_gui.cpp:73
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:67
#define FOR_ALL_VEHICLES(var)
Iterate over all vehicles.
Definition: vehicle_base.h:987
Servers always have this ID.
Definition: network_type.h:43
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:3374
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:714
Text is written right-to-left by default.
Definition: strings_type.h:26
Date ConvertYMDToDate(Year year, Month month, Day day)
Converts a tuple of Year, Month and Day to a Date.
Definition: date.cpp:149
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:52
Manually align the window (so no automatic location finding)
Definition: window_gui.h:155
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:390
void PlaceProc_Sign(TileIndex tile)
PlaceProc function, called when someone pressed the button if the sign-tool is selected.
Definition: signs_cmd.cpp:136
uint8 timeout_timer
Timer value of the WF_TIMEOUT for flags.
Definition: window_gui.h:316
RoadTypes GetRoadTypes(bool introduces)
Get list of road types, regardless of company availability.
Definition: road.cpp:219
Date _date
Current date in days (day counter)
Definition: date.cpp:28
Window white border counter bit mask.
Definition: window_gui.h:242
Hack, used to update the button status.
Definition: viewport_type.h:65
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:46
Base list item class from which others are derived.
Definition: dropdown_type.h:24
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:62
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:330
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:50
Road vehicle type.
Definition: vehicle_type.h:27
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:832
static NWidgetPart SetPIP(uint8 pre, uint8 inter, uint8 post)
Widget part function for setting a pre/inter/post spaces.
Definition: widget_type.h:1076
static void MenuClickLargeWorldScreenshot(ScreenshotType t)
Make a screenshot of the world.
static CallBackFunction MenuClickShowShips(int index)
Handle click on the entry in the Ships menu.
No roadtypes.
Definition: road_type.h:42
Settings menu.
Landscaping toolbar.
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
Definition: gfx.cpp:1459
void OnTimeout() override
Called when this window&#39;s timeout has been reached.
ScreenshotType
Type of requested screenshot.
Definition: screenshot.h:20
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:201
Base class for a &#39;real&#39; widget.
Definition: widget_type.h:284
int width
Screen width of the viewport.
Definition: viewport_type.h:27
pause the game
Definition: command_type.h:256