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_gui.h"
21 #include "date_func.h"
22 #include "vehicle_func.h"
23 #include "sound_func.h"
24 #include "terraform_gui.h"
25 #include "strings_func.h"
26 #include "company_func.h"
27 #include "company_gui.h"
28 #include "vehicle_base.h"
29 #include "cheat_func.h"
30 #include "transparency_gui.h"
31 #include "screenshot.h"
32 #include "signs_func.h"
33 #include "fios.h"
34 #include "console_gui.h"
35 #include "news_gui.h"
36 #include "ai/ai_gui.hpp"
37 #include "tilehighlight_func.h"
38 #include "smallmap_gui.h"
39 #include "graph_gui.h"
40 #include "textbuf_gui.h"
42 #include "newgrf_debug.h"
43 #include "hotkeys.h"
44 #include "engine_base.h"
45 #include "highscore.h"
46 #include "game/game.hpp"
47 #include "goal_base.h"
48 #include "story_base.h"
49 #include "toolbar_gui.h"
50 #include "framerate_type.h"
51 #include "guitimer_func.h"
52 
53 #include "widgets/toolbar_widget.h"
54 
55 #include "network/network.h"
56 #include "network/network_gui.h"
57 #include "network/network_func.h"
58 
59 #include "safeguards.h"
60 
61 
63 uint _toolbar_width = 0;
64 
65 RailType _last_built_railtype;
66 RoadType _last_built_roadtype;
67 
69 
72  TB_NORMAL,
73  TB_UPPER,
74  TB_LOWER
75 };
76 
79  CBF_NONE,
80  CBF_PLACE_SIGN,
81  CBF_PLACE_LANDINFO,
82 };
83 
85 
86 
91  uint checkmark_width;
92 public:
93  bool checked;
94 
95  DropDownListCheckedItem(StringID string, int result, bool masked, bool checked) : DropDownListStringItem(string, result, masked), checked(checked)
96  {
97  this->checkmark_width = GetStringBoundingBox(STR_JUST_CHECKMARK).width + 3;
98  }
99 
100  virtual ~DropDownListCheckedItem() {}
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, int 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  virtual ~DropDownListCompanyItem() {}
133 
134  bool Selectable() const
135  {
136  return true;
137  }
138 
139  uint Width() const
140  {
141  CompanyID company = (CompanyID)this->result;
142  SetDParam(0, company);
143  SetDParam(1, company);
144  return GetStringBoundingBox(STR_COMPANY_NAME_COMPANY_NUM).width + this->icon_size.width + this->lock_size.width + 6;
145  }
146 
147  uint Height(uint width) const
148  {
149  return max(max(this->icon_size.height, this->lock_size.height) + 2U, (uint)FONT_HEIGHT_NORMAL);
150  }
151 
152  void Draw(int left, int right, int top, int bottom, bool sel, int bg_colour) const
153  {
154  CompanyID company = (CompanyID)this->result;
155  bool rtl = _current_text_dir == TD_RTL;
156 
157  /* It's possible the company is deleted while the dropdown is open */
158  if (!Company::IsValidID(company)) return;
159 
160  int icon_offset = (bottom - top - icon_size.height) / 2;
161  int text_offset = (bottom - top - FONT_HEIGHT_NORMAL) / 2;
162  int lock_offset = (bottom - top - lock_size.height) / 2;
163 
164  DrawCompanyIcon(company, rtl ? right - this->icon_size.width - WD_FRAMERECT_RIGHT : left + WD_FRAMERECT_LEFT, top + icon_offset);
165  if (NetworkCompanyIsPassworded(company)) {
166  DrawSprite(SPR_LOCK, PAL_NONE, rtl ? left + WD_FRAMERECT_LEFT : right - this->lock_size.width - WD_FRAMERECT_RIGHT, top + lock_offset);
167  }
168 
169  SetDParam(0, company);
170  SetDParam(1, company);
171  TextColour col;
172  if (this->greyed) {
173  col = (sel ? TC_SILVER : TC_GREY) | TC_NO_SHADE;
174  } else {
175  col = sel ? TC_WHITE : TC_BLACK;
176  }
177  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);
178  }
179 };
180 
188 static void PopupMainToolbMenu(Window *w, int widget, DropDownList *list, int def)
189 {
190  ShowDropDownList(w, list, def, widget, 0, true, true);
191  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
192 }
193 
201 static void PopupMainToolbMenu(Window *w, int widget, StringID string, int count)
202 {
203  DropDownList *list = new DropDownList();
204  for (int i = 0; i < count; i++) {
205  *list->Append() = new DropDownListStringItem(string + i, i, false);
206  }
207  PopupMainToolbMenu(w, widget, list, 0);
208 }
209 
211 static const int CTMN_CLIENT_LIST = -1;
212 static const int CTMN_NEW_COMPANY = -2;
213 static const int CTMN_SPECTATE = -3;
214 static const int CTMN_SPECTATOR = -4;
215 
223 static void PopupMainCompanyToolbMenu(Window *w, int widget, int grey = 0, bool include_spectator = false)
224 {
225  DropDownList *list = new DropDownList();
226 
227 #ifdef ENABLE_NETWORK
228  if (_networking) {
229  if (widget == WID_TN_COMPANIES) {
230  /* Add the client list button for the companies menu */
231  *list->Append() = new DropDownListStringItem(STR_NETWORK_COMPANY_LIST_CLIENT_LIST, CTMN_CLIENT_LIST, false);
232  }
233 
234  if (include_spectator) {
235  if (widget == WID_TN_COMPANIES) {
237  *list->Append() = new DropDownListStringItem(STR_NETWORK_COMPANY_LIST_NEW_COMPANY, CTMN_NEW_COMPANY, NetworkMaxCompaniesReached());
238  } else {
239  *list->Append() = new DropDownListStringItem(STR_NETWORK_COMPANY_LIST_SPECTATE, CTMN_SPECTATE, NetworkMaxSpectatorsReached());
240  }
241  } else {
242  *list->Append() = new DropDownListStringItem(STR_NETWORK_TOOLBAR_LIST_SPECTATOR, CTMN_SPECTATOR, false);
243  }
244  }
245  }
246 #endif /* ENABLE_NETWORK */
247 
248  for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) {
249  if (!Company::IsValidID(c)) continue;
250  *list->Append() = new DropDownListCompanyItem(c, false, HasBit(grey, c));
251  }
252 
254 }
255 
256 
257 static ToolbarMode _toolbar_mode;
258 
259 static CallBackFunction SelectSignTool()
260 {
261  if (_last_started_action == CBF_PLACE_SIGN) {
263  return CBF_NONE;
264  } else {
265  SetObjectToPlace(SPR_CURSOR_SIGN, PAL_NONE, HT_RECT, WC_MAIN_TOOLBAR, 0);
266  return CBF_PLACE_SIGN;
267  }
268 }
269 
270 /* --- Pausing --- */
271 
272 static CallBackFunction ToolbarPauseClick(Window *w)
273 {
274  if (_networking && !_network_server) return CBF_NONE; // only server can pause the game
275 
277  if (_settings_client.sound.confirm) SndPlayFx(SND_15_BEEP);
278  }
279  return CBF_NONE;
280 }
281 
289 {
290  _fast_forward ^= true;
291  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
292  return CBF_NONE;
293 }
294 
299  OME_GAMEOPTIONS,
300  OME_SETTINGS,
301  OME_SCRIPT_SETTINGS,
302  OME_NEWGRFSETTINGS,
303  OME_TRANSPARENCIES,
304  OME_SHOW_TOWNNAMES,
305  OME_SHOW_STATIONNAMES,
306  OME_SHOW_WAYPOINTNAMES,
307  OME_SHOW_SIGNS,
308  OME_SHOW_COMPETITOR_SIGNS,
309  OME_FULL_ANIMATION,
310  OME_FULL_DETAILS,
311  OME_TRANSPARENTBUILDINGS,
312  OME_SHOW_STATIONSIGNS,
313 };
314 
322 {
323  DropDownList *list = new DropDownList();
324  *list->Append() = new DropDownListStringItem(STR_SETTINGS_MENU_GAME_OPTIONS, OME_GAMEOPTIONS, false);
325  *list->Append() = new DropDownListStringItem(STR_SETTINGS_MENU_CONFIG_SETTINGS_TREE, OME_SETTINGS, false);
326  /* Changes to the per-AI settings don't get send from the server to the clients. Clients get
327  * the settings once they join but never update it. As such don't show the window at all
328  * to network clients. */
329  if (!_networking || _network_server) *list->Append() = new DropDownListStringItem(STR_SETTINGS_MENU_SCRIPT_SETTINGS, OME_SCRIPT_SETTINGS, false);
330  *list->Append() = new DropDownListStringItem(STR_SETTINGS_MENU_NEWGRF_SETTINGS, OME_NEWGRFSETTINGS, false);
331  *list->Append() = new DropDownListStringItem(STR_SETTINGS_MENU_TRANSPARENCY_OPTIONS, OME_TRANSPARENCIES, false);
332  *list->Append() = new DropDownListItem(-1, false);
333  *list->Append() = new DropDownListCheckedItem(STR_SETTINGS_MENU_TOWN_NAMES_DISPLAYED, OME_SHOW_TOWNNAMES, false, HasBit(_display_opt, DO_SHOW_TOWN_NAMES));
334  *list->Append() = new DropDownListCheckedItem(STR_SETTINGS_MENU_STATION_NAMES_DISPLAYED, OME_SHOW_STATIONNAMES, false, HasBit(_display_opt, DO_SHOW_STATION_NAMES));
335  *list->Append() = new DropDownListCheckedItem(STR_SETTINGS_MENU_WAYPOINTS_DISPLAYED, OME_SHOW_WAYPOINTNAMES, false, HasBit(_display_opt, DO_SHOW_WAYPOINT_NAMES));
336  *list->Append() = new DropDownListCheckedItem(STR_SETTINGS_MENU_SIGNS_DISPLAYED, OME_SHOW_SIGNS, false, HasBit(_display_opt, DO_SHOW_SIGNS));
337  *list->Append() = new DropDownListCheckedItem(STR_SETTINGS_MENU_SHOW_COMPETITOR_SIGNS, OME_SHOW_COMPETITOR_SIGNS, false, HasBit(_display_opt, DO_SHOW_COMPETITOR_SIGNS));
338  *list->Append() = new DropDownListCheckedItem(STR_SETTINGS_MENU_FULL_ANIMATION, OME_FULL_ANIMATION, false, HasBit(_display_opt, DO_FULL_ANIMATION));
339  *list->Append() = new DropDownListCheckedItem(STR_SETTINGS_MENU_FULL_DETAIL, OME_FULL_DETAILS, false, HasBit(_display_opt, DO_FULL_DETAIL));
340  *list->Append() = new DropDownListCheckedItem(STR_SETTINGS_MENU_TRANSPARENT_BUILDINGS, OME_TRANSPARENTBUILDINGS, false, IsTransparencySet(TO_HOUSES));
341  *list->Append() = new DropDownListCheckedItem(STR_SETTINGS_MENU_TRANSPARENT_SIGNS, OME_SHOW_STATIONSIGNS, false, IsTransparencySet(TO_SIGNS));
342 
343  ShowDropDownList(w, list, 0, WID_TN_SETTINGS, 140, true, true);
344  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
345  return CBF_NONE;
346 }
347 
355 {
356  switch (index) {
357  case OME_GAMEOPTIONS: ShowGameOptions(); return CBF_NONE;
358  case OME_SETTINGS: ShowGameSettings(); return CBF_NONE;
359  case OME_SCRIPT_SETTINGS: ShowAIConfigWindow(); return CBF_NONE;
360  case OME_NEWGRFSETTINGS: ShowNewGRFSettings(!_networking && _settings_client.gui.UserIsAllowedToChangeNewGRFs(), true, true, &_grfconfig); return CBF_NONE;
361  case OME_TRANSPARENCIES: ShowTransparencyToolbar(); break;
362 
363  case OME_SHOW_TOWNNAMES: ToggleBit(_display_opt, DO_SHOW_TOWN_NAMES); break;
364  case OME_SHOW_STATIONNAMES: ToggleBit(_display_opt, DO_SHOW_STATION_NAMES); break;
365  case OME_SHOW_WAYPOINTNAMES: ToggleBit(_display_opt, DO_SHOW_WAYPOINT_NAMES); break;
366  case OME_SHOW_SIGNS: ToggleBit(_display_opt, DO_SHOW_SIGNS); break;
367  case OME_SHOW_COMPETITOR_SIGNS:
370  break;
371  case OME_FULL_ANIMATION: ToggleBit(_display_opt, DO_FULL_ANIMATION); CheckBlitter(); break;
372  case OME_FULL_DETAILS: ToggleBit(_display_opt, DO_FULL_DETAIL); break;
373  case OME_TRANSPARENTBUILDINGS: ToggleTransparency(TO_HOUSES); break;
374  case OME_SHOW_STATIONSIGNS: ToggleTransparency(TO_SIGNS); break;
375  }
377  return CBF_NONE;
378 }
379 
384  SLEME_SAVE_SCENARIO = 0,
385  SLEME_LOAD_SCENARIO,
386  SLEME_SAVE_HEIGHTMAP,
387  SLEME_LOAD_HEIGHTMAP,
388  SLEME_EXIT_TOINTRO,
389  SLEME_EXIT_GAME = 6,
390  SLEME_MENUCOUNT,
391 };
392 
397  SLNME_SAVE_GAME = 0,
398  SLNME_LOAD_GAME,
399  SLNME_EXIT_TOINTRO,
400  SLNME_EXIT_GAME = 4,
401  SLNME_MENUCOUNT,
402 };
403 
411 {
412  PopupMainToolbMenu(w, WID_TN_SAVE, STR_FILE_MENU_SAVE_GAME, SLNME_MENUCOUNT);
413  return CBF_NONE;
414 }
415 
423 {
424  PopupMainToolbMenu(w, WID_TE_SAVE, STR_SCENEDIT_FILE_MENU_SAVE_SCENARIO, SLEME_MENUCOUNT);
425  return CBF_NONE;
426 }
427 
434 static CallBackFunction MenuClickSaveLoad(int index = 0)
435 {
436  if (_game_mode == GM_EDITOR) {
437  switch (index) {
438  case SLEME_SAVE_SCENARIO: ShowSaveLoadDialog(FT_SCENARIO, SLO_SAVE); break;
439  case SLEME_LOAD_SCENARIO: ShowSaveLoadDialog(FT_SCENARIO, SLO_LOAD); break;
440  case SLEME_SAVE_HEIGHTMAP: ShowSaveLoadDialog(FT_HEIGHTMAP,SLO_SAVE); break;
441  case SLEME_LOAD_HEIGHTMAP: ShowSaveLoadDialog(FT_HEIGHTMAP,SLO_LOAD); break;
442  case SLEME_EXIT_TOINTRO: AskExitToGameMenu(); break;
443  case SLEME_EXIT_GAME: HandleExitGameRequest(); break;
444  }
445  } else {
446  switch (index) {
447  case SLNME_SAVE_GAME: ShowSaveLoadDialog(FT_SAVEGAME, SLO_SAVE); break;
448  case SLNME_LOAD_GAME: ShowSaveLoadDialog(FT_SAVEGAME, SLO_LOAD); break;
449  case SLNME_EXIT_TOINTRO: AskExitToGameMenu(); break;
450  case SLNME_EXIT_GAME: HandleExitGameRequest(); break;
451  }
452  }
453  return CBF_NONE;
454 }
455 
456 /* --- Map button menu --- */
457 
458 enum MapMenuEntries {
459  MME_SHOW_SMALLMAP = 0,
460  MME_SHOW_EXTRAVIEWPORTS,
461  MME_SHOW_LINKGRAPH,
462  MME_SHOW_SIGNLISTS,
463  MME_SHOW_TOWNDIRECTORY,
464  MME_SHOW_INDUSTRYDIRECTORY,
465 };
466 
467 static CallBackFunction ToolbarMapClick(Window *w)
468 {
469  DropDownList *list = new DropDownList();
470  *list->Append() = new DropDownListStringItem(STR_MAP_MENU_MAP_OF_WORLD, MME_SHOW_SMALLMAP, false);
471  *list->Append() = new DropDownListStringItem(STR_MAP_MENU_EXTRA_VIEW_PORT, MME_SHOW_EXTRAVIEWPORTS, false);
472  *list->Append() = new DropDownListStringItem(STR_MAP_MENU_LINGRAPH_LEGEND, MME_SHOW_LINKGRAPH, false);
473  *list->Append() = new DropDownListStringItem(STR_MAP_MENU_SIGN_LIST, MME_SHOW_SIGNLISTS, false);
475  return CBF_NONE;
476 }
477 
478 static CallBackFunction ToolbarScenMapTownDir(Window *w)
479 {
480  DropDownList *list = new DropDownList();
481  *list->Append() = new DropDownListStringItem(STR_MAP_MENU_MAP_OF_WORLD, MME_SHOW_SMALLMAP, false);
482  *list->Append() = new DropDownListStringItem(STR_MAP_MENU_EXTRA_VIEW_PORT, MME_SHOW_EXTRAVIEWPORTS, false);
483  *list->Append() = new DropDownListStringItem(STR_MAP_MENU_SIGN_LIST, MME_SHOW_SIGNLISTS, false);
484  *list->Append() = new DropDownListStringItem(STR_TOWN_MENU_TOWN_DIRECTORY, MME_SHOW_TOWNDIRECTORY, false);
485  *list->Append() = new DropDownListStringItem(STR_INDUSTRY_MENU_INDUSTRY_DIRECTORY, MME_SHOW_INDUSTRYDIRECTORY, false);
487  return CBF_NONE;
488 }
489 
497 {
498  switch (index) {
499  case MME_SHOW_SMALLMAP: ShowSmallMap(); break;
500  case MME_SHOW_EXTRAVIEWPORTS: ShowExtraViewPortWindow(); break;
501  case MME_SHOW_LINKGRAPH: ShowLinkGraphLegend(); break;
502  case MME_SHOW_SIGNLISTS: ShowSignList(); break;
503  case MME_SHOW_TOWNDIRECTORY: ShowTownDirectory(); break;
504  case MME_SHOW_INDUSTRYDIRECTORY: ShowIndustryDirectory(); break;
505  }
506  return CBF_NONE;
507 }
508 
509 /* --- Town button menu --- */
510 
511 static CallBackFunction ToolbarTownClick(Window *w)
512 {
513  PopupMainToolbMenu(w, WID_TN_TOWNS, STR_TOWN_MENU_TOWN_DIRECTORY, (_settings_game.economy.found_town == TF_FORBIDDEN) ? 1 : 2);
514  return CBF_NONE;
515 }
516 
524 {
525  switch (index) {
526  case 0: ShowTownDirectory(); break;
527  case 1: // setting could be changed when the dropdown was open
528  if (_settings_game.economy.found_town != TF_FORBIDDEN) ShowFoundTownWindow();
529  break;
530  }
531  return CBF_NONE;
532 }
533 
534 /* --- Subidies button menu --- */
535 
536 static CallBackFunction ToolbarSubsidiesClick(Window *w)
537 {
538  PopupMainToolbMenu(w, WID_TN_SUBSIDIES, STR_SUBSIDIES_MENU_SUBSIDIES, 1);
539  return CBF_NONE;
540 }
541 
549 {
550  switch (index) {
551  case 0: ShowSubsidiesList(); break;
552  }
553  return CBF_NONE;
554 }
555 
556 /* --- Stations button menu --- */
557 
558 static CallBackFunction ToolbarStationsClick(Window *w)
559 {
561  return CBF_NONE;
562 }
563 
571 {
573  return CBF_NONE;
574 }
575 
576 /* --- Finances button menu --- */
577 
578 static CallBackFunction ToolbarFinancesClick(Window *w)
579 {
581  return CBF_NONE;
582 }
583 
591 {
593  return CBF_NONE;
594 }
595 
596 /* --- Company's button menu --- */
597 
598 static CallBackFunction ToolbarCompaniesClick(Window *w)
599 {
601  return CBF_NONE;
602 }
603 
611 {
612 #ifdef ENABLE_NETWORK
613  if (_networking) {
614  switch (index) {
615  case CTMN_CLIENT_LIST:
616  ShowClientList();
617  return CBF_NONE;
618 
619  case CTMN_NEW_COMPANY:
620  if (_network_server) {
622  } else {
624  }
625  return CBF_NONE;
626 
627  case CTMN_SPECTATE:
628  if (_network_server) {
631  } else {
633  }
634  return CBF_NONE;
635  }
636  }
637 #endif /* ENABLE_NETWORK */
638  ShowCompany((CompanyID)index);
639  return CBF_NONE;
640 }
641 
642 /* --- Story button menu --- */
643 
644 static CallBackFunction ToolbarStoryClick(Window *w)
645 {
647  return CBF_NONE;
648 }
649 
657 {
659  return CBF_NONE;
660 }
661 
662 /* --- Goal button menu --- */
663 
664 static CallBackFunction ToolbarGoalClick(Window *w)
665 {
667  return CBF_NONE;
668 }
669 
677 {
679  return CBF_NONE;
680 }
681 
682 /* --- Graphs button menu --- */
683 
684 static CallBackFunction ToolbarGraphsClick(Window *w)
685 {
686  PopupMainToolbMenu(w, WID_TN_GRAPHS, STR_GRAPH_MENU_OPERATING_PROFIT_GRAPH, (_toolbar_mode == TB_NORMAL) ? 6 : 8);
687  return CBF_NONE;
688 }
689 
697 {
698  switch (index) {
699  case 0: ShowOperatingProfitGraph(); break;
700  case 1: ShowIncomeGraph(); break;
701  case 2: ShowDeliveredCargoGraph(); break;
702  case 3: ShowPerformanceHistoryGraph(); break;
703  case 4: ShowCompanyValueGraph(); break;
704  case 5: ShowCargoPaymentRates(); break;
705  /* functions for combined graphs/league button */
706  case 6: ShowCompanyLeagueTable(); break;
707  case 7: ShowPerformanceRatingDetail(); break;
708  }
709  return CBF_NONE;
710 }
711 
712 /* --- League button menu --- */
713 
714 static CallBackFunction ToolbarLeagueClick(Window *w)
715 {
716  PopupMainToolbMenu(w, WID_TN_LEAGUE, STR_GRAPH_MENU_COMPANY_LEAGUE_TABLE, _networking ? 2 : 3);
717  return CBF_NONE;
718 }
719 
727 {
728  switch (index) {
729  case 0: ShowCompanyLeagueTable(); break;
730  case 1: ShowPerformanceRatingDetail(); break;
731  case 2: ShowHighscoreTable(); break;
732  }
733  return CBF_NONE;
734 }
735 
736 /* --- Industries button menu --- */
737 
738 static CallBackFunction ToolbarIndustryClick(Window *w)
739 {
740  /* Disable build-industry menu if we are a spectator */
741  PopupMainToolbMenu(w, WID_TN_INDUSTRIES, STR_INDUSTRY_MENU_INDUSTRY_DIRECTORY, (_local_company == COMPANY_SPECTATOR) ? 2 : 3);
742  return CBF_NONE;
743 }
744 
752 {
753  switch (index) {
754  case 0: ShowIndustryDirectory(); break;
755  case 1: ShowIndustryCargoesWindow(); break;
756  case 2: ShowBuildIndustryWindow(); break;
757  }
758  return CBF_NONE;
759 }
760 
761 /* --- Trains button menu + 1 helper function for all vehicles. --- */
762 
763 static void ToolbarVehicleClick(Window *w, VehicleType veh)
764 {
765  const Vehicle *v;
766  int dis = ~0;
767 
768  FOR_ALL_VEHICLES(v) {
769  if (v->type == veh && v->IsPrimaryVehicle()) ClrBit(dis, v->owner);
770  }
772 }
773 
774 
775 static CallBackFunction ToolbarTrainClick(Window *w)
776 {
777  ToolbarVehicleClick(w, VEH_TRAIN);
778  return CBF_NONE;
779 }
780 
788 {
789  ShowVehicleListWindow((CompanyID)index, VEH_TRAIN);
790  return CBF_NONE;
791 }
792 
793 /* --- Road vehicle button menu --- */
794 
795 static CallBackFunction ToolbarRoadClick(Window *w)
796 {
797  ToolbarVehicleClick(w, VEH_ROAD);
798  return CBF_NONE;
799 }
800 
808 {
809  ShowVehicleListWindow((CompanyID)index, VEH_ROAD);
810  return CBF_NONE;
811 }
812 
813 /* --- Ship button menu --- */
814 
815 static CallBackFunction ToolbarShipClick(Window *w)
816 {
817  ToolbarVehicleClick(w, VEH_SHIP);
818  return CBF_NONE;
819 }
820 
828 {
829  ShowVehicleListWindow((CompanyID)index, VEH_SHIP);
830  return CBF_NONE;
831 }
832 
833 /* --- Aircraft button menu --- */
834 
835 static CallBackFunction ToolbarAirClick(Window *w)
836 {
837  ToolbarVehicleClick(w, VEH_AIRCRAFT);
838  return CBF_NONE;
839 }
840 
848 {
849  ShowVehicleListWindow((CompanyID)index, VEH_AIRCRAFT);
850  return CBF_NONE;
851 }
852 
853 /* --- Zoom in button --- */
854 
855 static CallBackFunction ToolbarZoomInClick(Window *w)
856 {
858  w->HandleButtonClick((_game_mode == GM_EDITOR) ? (byte)WID_TE_ZOOM_IN : (byte)WID_TN_ZOOM_IN);
859  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
860  }
861  return CBF_NONE;
862 }
863 
864 /* --- Zoom out button --- */
865 
866 static CallBackFunction ToolbarZoomOutClick(Window *w)
867 {
869  w->HandleButtonClick((_game_mode == GM_EDITOR) ? (byte)WID_TE_ZOOM_OUT : (byte)WID_TN_ZOOM_OUT);
870  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
871  }
872  return CBF_NONE;
873 }
874 
875 /* --- Rail button menu --- */
876 
877 static CallBackFunction ToolbarBuildRailClick(Window *w)
878 {
879  ShowDropDownList(w, GetRailTypeDropDownList(), _last_built_railtype, WID_TN_RAILS, 140, true, true);
880  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
881  return CBF_NONE;
882 }
883 
891 {
892  _last_built_railtype = (RailType)index;
893  ShowBuildRailToolbar(_last_built_railtype);
894  return CBF_NONE;
895 }
896 
897 /* --- Road button menu --- */
898 
899 static CallBackFunction ToolbarBuildRoadClick(Window *w)
900 {
901  const Company *c = Company::Get(_local_company);
902  DropDownList *list = new DropDownList();
903 
904  /* Road is always visible and available. */
905  *list->Append() = new DropDownListStringItem(STR_ROAD_MENU_ROAD_CONSTRUCTION, ROADTYPE_ROAD, false);
906 
907  /* Tram is only visible when there will be a tram, and available when that has been introduced. */
908  Engine *e;
909  FOR_ALL_ENGINES_OF_TYPE(e, VEH_ROAD) {
910  if (!HasBit(e->info.climates, _settings_game.game_creation.landscape)) continue;
911  if (!HasBit(e->info.misc_flags, EF_ROAD_TRAM)) continue;
912 
913  *list->Append() = new DropDownListStringItem(STR_ROAD_MENU_TRAM_CONSTRUCTION, ROADTYPE_TRAM, !HasBit(c->avail_roadtypes, ROADTYPE_TRAM));
914  break;
915  }
916  ShowDropDownList(w, list, _last_built_roadtype, WID_TN_ROADS, 140, true, true);
917  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
918  return CBF_NONE;
919 }
920 
928 {
929  _last_built_roadtype = (RoadType)index;
930  ShowBuildRoadToolbar(_last_built_roadtype);
931  return CBF_NONE;
932 }
933 
934 /* --- Water button menu --- */
935 
936 static CallBackFunction ToolbarBuildWaterClick(Window *w)
937 {
938  PopupMainToolbMenu(w, WID_TN_WATER, STR_WATERWAYS_MENU_WATERWAYS_CONSTRUCTION, 1);
939  return CBF_NONE;
940 }
941 
949 {
951  return CBF_NONE;
952 }
953 
954 /* --- Airport button menu --- */
955 
956 static CallBackFunction ToolbarBuildAirClick(Window *w)
957 {
958  PopupMainToolbMenu(w, WID_TN_AIR, STR_AIRCRAFT_MENU_AIRPORT_CONSTRUCTION, 1);
959  return CBF_NONE;
960 }
961 
969 {
971  return CBF_NONE;
972 }
973 
974 /* --- Forest button menu --- */
975 
976 static CallBackFunction ToolbarForestClick(Window *w)
977 {
978  PopupMainToolbMenu(w, WID_TN_LANDSCAPE, STR_LANDSCAPING_MENU_LANDSCAPING, 3);
979  return CBF_NONE;
980 }
981 
989 {
990  switch (index) {
991  case 0: ShowTerraformToolbar(); break;
992  case 1: ShowBuildTreesToolbar(); break;
993  case 2: return SelectSignTool();
994  }
995  return CBF_NONE;
996 }
997 
998 /* --- Music button menu --- */
999 
1000 static CallBackFunction ToolbarMusicClick(Window *w)
1001 {
1002  PopupMainToolbMenu(w, WID_TN_MUSIC_SOUND, STR_TOOLBAR_SOUND_MUSIC, 1);
1003  return CBF_NONE;
1004 }
1005 
1013 {
1014  ShowMusicWindow();
1015  return CBF_NONE;
1016 }
1017 
1018 /* --- Newspaper button menu --- */
1019 
1020 static CallBackFunction ToolbarNewspaperClick(Window *w)
1021 {
1022  PopupMainToolbMenu(w, WID_TN_MESSAGES, STR_NEWS_MENU_LAST_MESSAGE_NEWS_REPORT, 2);
1023  return CBF_NONE;
1024 }
1025 
1033 {
1034  switch (index) {
1035  case 0: ShowLastNewsMessage(); break;
1036  case 1: ShowMessageHistory(); break;
1037  }
1038  return CBF_NONE;
1039 }
1040 
1041 /* --- Help button menu --- */
1042 
1043 static CallBackFunction PlaceLandBlockInfo()
1044 {
1045  if (_last_started_action == CBF_PLACE_LANDINFO) {
1047  return CBF_NONE;
1048  } else {
1049  SetObjectToPlace(SPR_CURSOR_QUERY, PAL_NONE, HT_RECT, WC_MAIN_TOOLBAR, 0);
1050  return CBF_PLACE_LANDINFO;
1051  }
1052 }
1053 
1054 static CallBackFunction ToolbarHelpClick(Window *w)
1055 {
1056  PopupMainToolbMenu(w, WID_TN_HELP, STR_ABOUT_MENU_LAND_BLOCK_INFO, _settings_client.gui.newgrf_developer_tools ? 13 : 10);
1057  return CBF_NONE;
1058 }
1059 
1060 static void MenuClickSmallScreenshot()
1061 {
1062  MakeScreenshot(SC_VIEWPORT, NULL);
1063 }
1064 
1070 static void ScreenshotConfirmCallback(Window *w, bool confirmed)
1071 {
1072  if (confirmed) MakeScreenshot(_confirmed_screenshot_type, NULL);
1073 }
1074 
1081 {
1082  ViewPort vp;
1083  SetupScreenshotViewport(t, &vp);
1084  if ((uint64)vp.width * (uint64)vp.height > 8192 * 8192) {
1085  /* Ask for confirmation */
1086  SetDParam(0, vp.width);
1087  SetDParam(1, vp.height);
1089  ShowQuery(STR_WARNING_SCREENSHOT_SIZE_CAPTION, STR_WARNING_SCREENSHOT_SIZE_MESSAGE, NULL, ScreenshotConfirmCallback);
1090  } else {
1091  /* Less than 64M pixels, just do it */
1092  MakeScreenshot(t, NULL);
1093  }
1094 }
1095 
1104 {
1105  extern bool _draw_bounding_boxes;
1106  /* Always allow to toggle them off */
1107  if (_settings_client.gui.newgrf_developer_tools || _draw_bounding_boxes) {
1108  _draw_bounding_boxes = !_draw_bounding_boxes;
1110  }
1111 }
1112 
1121 {
1122  extern bool _draw_dirty_blocks;
1123  /* Always allow to toggle them off */
1124  if (_settings_client.gui.newgrf_developer_tools || _draw_dirty_blocks) {
1125  _draw_dirty_blocks = !_draw_dirty_blocks;
1127  }
1128 }
1129 
1135 {
1138  /* If you open a savegame as scenario there may already be link graphs.*/
1140  SetDate(new_date, 0);
1141 }
1142 
1149 {
1150  switch (index) {
1151  case 0: return PlaceLandBlockInfo();
1152  case 2: IConsoleSwitch(); break;
1153  case 3: ShowAIDebugWindow(); break;
1154  case 4: MenuClickSmallScreenshot(); break;
1157  case 7: MenuClickLargeWorldScreenshot(SC_WORLD); break;
1158  case 8: ShowFramerateWindow(); break;
1159  case 9: ShowAboutWindow(); break;
1160  case 10: ShowSpriteAlignerWindow(); break;
1161  case 11: ToggleBoundingBoxes(); break;
1162  case 12: ToggleDirtyBlocks(); break;
1163  }
1164  return CBF_NONE;
1165 }
1166 
1167 /* --- Switch toolbar button --- */
1168 
1169 static CallBackFunction ToolbarSwitchClick(Window *w)
1170 {
1171  if (_toolbar_mode != TB_LOWER) {
1172  _toolbar_mode = TB_LOWER;
1173  } else {
1174  _toolbar_mode = TB_UPPER;
1175  }
1176 
1177  w->ReInit();
1178  w->SetWidgetLoweredState(WID_TN_SWITCH_BAR, _toolbar_mode == TB_LOWER);
1179  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
1180  return CBF_NONE;
1181 }
1182 
1183 /* --- Scenario editor specific handlers. */
1184 
1189 {
1191  ShowQueryString(STR_JUST_INT, STR_MAPGEN_START_DATE_QUERY_CAPT, 8, w, CS_NUMERAL, QSF_ENABLE_DEFAULT);
1192  _left_button_clicked = false;
1193  return CBF_NONE;
1194 }
1195 
1196 static CallBackFunction ToolbarScenDateBackward(Window *w)
1197 {
1198  /* don't allow too fast scrolling */
1199  if (!(w->flags & WF_TIMEOUT) || w->timeout_timer <= 1) {
1201  w->SetDirty();
1202 
1204  }
1205  _left_button_clicked = false;
1206  return CBF_NONE;
1207 }
1208 
1209 static CallBackFunction ToolbarScenDateForward(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 ToolbarScenGenLand(Window *w)
1223 {
1225  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
1226 
1228  return CBF_NONE;
1229 }
1230 
1231 
1232 static CallBackFunction ToolbarScenGenTown(Window *w)
1233 {
1235  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
1236  ShowFoundTownWindow();
1237  return CBF_NONE;
1238 }
1239 
1240 static CallBackFunction ToolbarScenGenIndustry(Window *w)
1241 {
1243  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
1244  ShowBuildIndustryWindow();
1245  return CBF_NONE;
1246 }
1247 
1248 static CallBackFunction ToolbarScenBuildRoad(Window *w)
1249 {
1251  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
1253  return CBF_NONE;
1254 }
1255 
1256 static CallBackFunction ToolbarScenBuildDocks(Window *w)
1257 {
1259  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
1261  return CBF_NONE;
1262 }
1263 
1264 static CallBackFunction ToolbarScenPlantTrees(Window *w)
1265 {
1267  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
1268  ShowBuildTreesToolbar();
1269  return CBF_NONE;
1270 }
1271 
1272 static CallBackFunction ToolbarScenPlaceSign(Window *w)
1273 {
1275  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
1276  return SelectSignTool();
1277 }
1278 
1279 static CallBackFunction ToolbarBtn_NULL(Window *w)
1280 {
1281  return CBF_NONE;
1282 }
1283 
1284 typedef CallBackFunction MenuClickedProc(int index);
1285 
1286 static MenuClickedProc * const _menu_clicked_procs[] = {
1287  NULL, // 0
1288  NULL, // 1
1289  MenuClickSettings, // 2
1290  MenuClickSaveLoad, // 3
1291  MenuClickMap, // 4
1292  MenuClickTown, // 5
1293  MenuClickSubsidies, // 6
1294  MenuClickStations, // 7
1295  MenuClickFinances, // 8
1296  MenuClickCompany, // 9
1297  MenuClickStory, // 10
1298  MenuClickGoal, // 11
1299  MenuClickGraphs, // 12
1300  MenuClickLeague, // 13
1301  MenuClickIndustry, // 14
1302  MenuClickShowTrains, // 15
1303  MenuClickShowRoad, // 16
1304  MenuClickShowShips, // 17
1305  MenuClickShowAir, // 18
1306  MenuClickMap, // 19
1307  NULL, // 20
1308  MenuClickBuildRail, // 21
1309  MenuClickBuildRoad, // 22
1310  MenuClickBuildWater, // 23
1311  MenuClickBuildAir, // 24
1312  MenuClickForest, // 25
1313  MenuClickMusicWindow, // 26
1314  MenuClickNewspaper, // 27
1315  MenuClickHelp, // 28
1316 };
1317 
1320  bool visible[WID_TN_END];
1321 protected:
1322  uint spacers;
1323 
1324 public:
1326  {
1327  }
1328 
1334  bool IsButton(WidgetType type) const
1335  {
1336  return type == WWT_IMGBTN || type == WWT_IMGBTN_2 || type == WWT_PUSHIMGBTN;
1337  }
1338 
1339  void SetupSmallestSize(Window *w, bool init_array)
1340  {
1341  this->smallest_x = 0; // Biggest child
1342  this->smallest_y = 0; // Biggest child
1343  this->fill_x = 1;
1344  this->fill_y = 0;
1345  this->resize_x = 1; // We only resize in this direction
1346  this->resize_y = 0; // We never resize in this direction
1347  this->spacers = 0;
1348 
1349  uint nbuttons = 0;
1350  /* First initialise some variables... */
1351  for (NWidgetBase *child_wid = this->head; child_wid != NULL; child_wid = child_wid->next) {
1352  child_wid->SetupSmallestSize(w, init_array);
1353  this->smallest_y = max(this->smallest_y, child_wid->smallest_y + child_wid->padding_top + child_wid->padding_bottom);
1354  if (this->IsButton(child_wid->type)) {
1355  nbuttons++;
1356  this->smallest_x = max(this->smallest_x, child_wid->smallest_x + child_wid->padding_left + child_wid->padding_right);
1357  } else if (child_wid->type == NWID_SPACER) {
1358  this->spacers++;
1359  }
1360  }
1361 
1362  /* ... then in a second pass make sure the 'current' heights are set. Won't change ever. */
1363  for (NWidgetBase *child_wid = this->head; child_wid != NULL; child_wid = child_wid->next) {
1364  child_wid->current_y = this->smallest_y;
1365  if (!this->IsButton(child_wid->type)) {
1366  child_wid->current_x = child_wid->smallest_x;
1367  }
1368  }
1369  _toolbar_width = nbuttons * this->smallest_x;
1370  }
1371 
1372  void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl)
1373  {
1374  assert(given_width >= this->smallest_x && given_height >= this->smallest_y);
1375 
1376  this->pos_x = x;
1377  this->pos_y = y;
1378  this->current_x = given_width;
1379  this->current_y = given_height;
1380 
1381  /* Figure out what are the visible buttons */
1382  memset(this->visible, 0, sizeof(this->visible));
1383  uint arrangable_count, button_count, spacer_count;
1384  const byte *arrangement = GetButtonArrangement(given_width, arrangable_count, button_count, spacer_count);
1385  for (uint i = 0; i < arrangable_count; i++) {
1386  this->visible[arrangement[i]] = true;
1387  }
1388 
1389  /* Create us ourselves a quick lookup table */
1390  NWidgetBase *widgets[WID_TN_END];
1391  for (NWidgetBase *child_wid = this->head; child_wid != NULL; child_wid = child_wid->next) {
1392  if (child_wid->type == NWID_SPACER) continue;
1393  widgets[((NWidgetCore*)child_wid)->index] = child_wid;
1394  }
1395 
1396  /* Now assign the widgets to their rightful place */
1397  uint position = 0; // Place to put next child relative to origin of the container.
1398  uint spacer_space = max(0, (int)given_width - (int)(button_count * this->smallest_x)); // Remaining spacing for 'spacer' widgets
1399  uint button_space = given_width - spacer_space; // Remaining spacing for the buttons
1400  uint spacer_i = 0;
1401  uint button_i = 0;
1402 
1403  /* Index into the arrangement indices. The macro lastof cannot be used here! */
1404  const byte *cur_wid = rtl ? &arrangement[arrangable_count - 1] : arrangement;
1405  for (uint i = 0; i < arrangable_count; i++) {
1406  NWidgetBase *child_wid = widgets[*cur_wid];
1407  /* If we have to give space to the spacers, do that */
1408  if (spacer_space != 0) {
1409  NWidgetBase *possible_spacer = rtl ? child_wid->next : child_wid->prev;
1410  if (possible_spacer != NULL && possible_spacer->type == NWID_SPACER) {
1411  uint add = spacer_space / (spacer_count - spacer_i);
1412  position += add;
1413  spacer_space -= add;
1414  spacer_i++;
1415  }
1416  }
1417 
1418  /* Buttons can be scaled, the others not. */
1419  if (this->IsButton(child_wid->type)) {
1420  child_wid->current_x = button_space / (button_count - button_i);
1421  button_space -= child_wid->current_x;
1422  button_i++;
1423  }
1424  child_wid->AssignSizePosition(sizing, x + position, y, child_wid->current_x, this->current_y, rtl);
1425  position += child_wid->current_x;
1426 
1427  if (rtl) {
1428  cur_wid--;
1429  } else {
1430  cur_wid++;
1431  }
1432  }
1433  }
1434 
1435  /* virtual */ void Draw(const Window *w)
1436  {
1437  /* Draw brown-red toolbar bg. */
1438  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);
1439  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);
1440 
1441  bool rtl = _current_text_dir == TD_RTL;
1442  for (NWidgetBase *child_wid = rtl ? this->tail : this->head; child_wid != NULL; child_wid = rtl ? child_wid->prev : child_wid->next) {
1443  if (child_wid->type == NWID_SPACER) continue;
1444  if (!this->visible[((NWidgetCore*)child_wid)->index]) continue;
1445 
1446  child_wid->Draw(w);
1447  }
1448  }
1449 
1450  /* virtual */ NWidgetCore *GetWidgetFromPos(int x, int y)
1451  {
1452  if (!IsInsideBS(x, this->pos_x, this->current_x) || !IsInsideBS(y, this->pos_y, this->current_y)) return NULL;
1453 
1454  for (NWidgetBase *child_wid = this->head; child_wid != NULL; child_wid = child_wid->next) {
1455  if (child_wid->type == NWID_SPACER) continue;
1456  if (!this->visible[((NWidgetCore*)child_wid)->index]) continue;
1457 
1458  NWidgetCore *nwid = child_wid->GetWidgetFromPos(x, y);
1459  if (nwid != NULL) return nwid;
1460  }
1461  return NULL;
1462  }
1463 
1472  virtual const byte *GetButtonArrangement(uint &width, uint &arrangable_count, uint &button_count, uint &spacer_count) const = 0;
1473 };
1474 
1477  /* virtual */ const byte *GetButtonArrangement(uint &width, uint &arrangable_count, uint &button_count, uint &spacer_count) const
1478  {
1479  static const uint SMALLEST_ARRANGEMENT = 14;
1480  static const uint BIGGEST_ARRANGEMENT = 20;
1481 
1482  /* The number of buttons of each row of the toolbar should match the number of items which we want to be visible.
1483  * The total number of buttons should be equal to arrangable_count * 2.
1484  * No bad things happen, but we could see strange behaviours if we have buttons < (arrangable_count * 2) like a
1485  * pause button appearing on the right of the lower toolbar and weird resizing of the widgets even if there is
1486  * enough space.
1487  */
1488  static const byte arrange14[] = {
1489  WID_TN_PAUSE,
1491  WID_TN_TRAINS,
1493  WID_TN_SHIPS,
1497  WID_TN_RAILS,
1498  WID_TN_ROADS,
1499  WID_TN_WATER,
1500  WID_TN_AIR,
1503  // lower toolbar
1505  WID_TN_SAVE,
1507  WID_TN_TOWNS,
1512  WID_TN_GRAPHS,
1516  WID_TN_HELP,
1518  };
1519  static const byte arrange15[] = {
1520  WID_TN_PAUSE,
1523  WID_TN_TRAINS,
1525  WID_TN_SHIPS,
1527  WID_TN_RAILS,
1528  WID_TN_ROADS,
1529  WID_TN_WATER,
1530  WID_TN_AIR,
1535  // lower toolbar
1536  WID_TN_PAUSE,
1539  WID_TN_SAVE,
1540  WID_TN_TOWNS,
1545  WID_TN_GRAPHS,
1549  WID_TN_HELP,
1551  };
1552  static const byte arrange16[] = {
1553  WID_TN_PAUSE,
1557  WID_TN_TRAINS,
1559  WID_TN_SHIPS,
1561  WID_TN_RAILS,
1562  WID_TN_ROADS,
1563  WID_TN_WATER,
1564  WID_TN_AIR,
1569  // lower toolbar
1570  WID_TN_PAUSE,
1572  WID_TN_SAVE,
1573  WID_TN_TOWNS,
1578  WID_TN_GRAPHS,
1582  WID_TN_HELP,
1586  };
1587  static const byte arrange17[] = {
1588  WID_TN_PAUSE,
1593  WID_TN_TRAINS,
1595  WID_TN_SHIPS,
1597  WID_TN_RAILS,
1598  WID_TN_ROADS,
1599  WID_TN_WATER,
1600  WID_TN_AIR,
1605  // lower toolbar
1606  WID_TN_PAUSE,
1608  WID_TN_SAVE,
1611  WID_TN_TOWNS,
1615  WID_TN_GRAPHS,
1619  WID_TN_HELP,
1623  };
1624  static const byte arrange18[] = {
1625  WID_TN_PAUSE,
1629  WID_TN_TOWNS,
1635  WID_TN_RAILS,
1636  WID_TN_ROADS,
1637  WID_TN_WATER,
1638  WID_TN_AIR,
1643  // lower toolbar
1644  WID_TN_PAUSE,
1646  WID_TN_SAVE,
1648  WID_TN_TOWNS,
1651  WID_TN_GRAPHS,
1652  WID_TN_TRAINS,
1654  WID_TN_SHIPS,
1658  WID_TN_HELP,
1662  };
1663  static const byte arrange19[] = {
1664  WID_TN_PAUSE,
1668  WID_TN_TOWNS,
1670  WID_TN_TRAINS,
1672  WID_TN_SHIPS,
1674  WID_TN_RAILS,
1675  WID_TN_ROADS,
1676  WID_TN_WATER,
1677  WID_TN_AIR,
1683  // lower toolbar
1684  WID_TN_PAUSE,
1686  WID_TN_SAVE,
1691  WID_TN_GRAPHS,
1694  WID_TN_RAILS,
1695  WID_TN_ROADS,
1696  WID_TN_WATER,
1697  WID_TN_AIR,
1699  WID_TN_HELP,
1703  };
1704  static const byte arrange20[] = {
1705  WID_TN_PAUSE,
1709  WID_TN_TOWNS,
1711  WID_TN_TRAINS,
1713  WID_TN_SHIPS,
1715  WID_TN_RAILS,
1716  WID_TN_ROADS,
1717  WID_TN_WATER,
1718  WID_TN_AIR,
1721  WID_TN_GOAL,
1725  // lower toolbar
1726  WID_TN_PAUSE,
1728  WID_TN_SAVE,
1733  WID_TN_GRAPHS,
1736  WID_TN_RAILS,
1737  WID_TN_ROADS,
1738  WID_TN_WATER,
1739  WID_TN_AIR,
1741  WID_TN_STORY,
1742  WID_TN_HELP,
1746  };
1747  static const byte arrange_all[] = {
1748  WID_TN_PAUSE,
1751  WID_TN_SAVE,
1753  WID_TN_TOWNS,
1758  WID_TN_STORY,
1759  WID_TN_GOAL,
1760  WID_TN_GRAPHS,
1761  WID_TN_LEAGUE,
1763  WID_TN_TRAINS,
1765  WID_TN_SHIPS,
1769  WID_TN_RAILS,
1770  WID_TN_ROADS,
1771  WID_TN_WATER,
1772  WID_TN_AIR,
1776  WID_TN_HELP
1777  };
1778 
1779  /* If at least BIGGEST_ARRANGEMENT fit, just spread all the buttons nicely */
1780  uint full_buttons = max(CeilDiv(width, this->smallest_x), SMALLEST_ARRANGEMENT);
1781  if (full_buttons > BIGGEST_ARRANGEMENT) {
1782  button_count = arrangable_count = lengthof(arrange_all);
1783  spacer_count = this->spacers;
1784  return arrange_all;
1785  }
1786 
1787  /* Introduce the split toolbar */
1788  static const byte * const arrangements[] = { arrange14, arrange15, arrange16, arrange17, arrange18, arrange19, arrange20 };
1789 
1790  button_count = arrangable_count = full_buttons;
1791  spacer_count = this->spacers;
1792  return arrangements[full_buttons - SMALLEST_ARRANGEMENT] + ((_toolbar_mode == TB_LOWER) ? full_buttons : 0);
1793  }
1794 };
1795 
1798  uint panel_widths[2];
1799 
1800  void SetupSmallestSize(Window *w, bool init_array)
1801  {
1802  this->NWidgetToolbarContainer::SetupSmallestSize(w, init_array);
1803 
1804  /* Find the size of panel_widths */
1805  uint i = 0;
1806  for (NWidgetBase *child_wid = this->head; child_wid != NULL; child_wid = child_wid->next) {
1807  if (child_wid->type == NWID_SPACER || this->IsButton(child_wid->type)) continue;
1808 
1809  assert(i < lengthof(this->panel_widths));
1810  this->panel_widths[i++] = child_wid->current_x;
1811  _toolbar_width += child_wid->current_x;
1812  }
1813  }
1814 
1815  /* virtual */ const byte *GetButtonArrangement(uint &width, uint &arrangable_count, uint &button_count, uint &spacer_count) const
1816  {
1817  static const byte arrange_all[] = {
1818  WID_TE_PAUSE,
1821  WID_TE_SAVE,
1822  WID_TE_SPACER,
1830  WID_TE_ROADS,
1831  WID_TE_WATER,
1832  WID_TE_TREES,
1833  WID_TE_SIGNS,
1835  WID_TE_HELP,
1836  };
1837  static const byte arrange_nopanel[] = {
1838  WID_TE_PAUSE,
1841  WID_TE_SAVE,
1849  WID_TE_ROADS,
1850  WID_TE_WATER,
1851  WID_TE_TREES,
1852  WID_TE_SIGNS,
1854  WID_TE_HELP,
1855  };
1856  static const byte arrange_switch[] = {
1862  WID_TE_ROADS,
1863  WID_TE_WATER,
1864  WID_TE_TREES,
1865  WID_TE_SIGNS,
1867  // lower toolbar
1868  WID_TE_PAUSE,
1871  WID_TE_SAVE,
1877  };
1878 
1879  /* If we can place all buttons *and* the panels, show them. */
1880  uint min_full_width = (lengthof(arrange_all) - lengthof(this->panel_widths)) * this->smallest_x + this->panel_widths[0] + this->panel_widths[1];
1881  if (width >= min_full_width) {
1882  width -= this->panel_widths[0] + this->panel_widths[1];
1883  arrangable_count = lengthof(arrange_all);
1884  button_count = arrangable_count - 2;
1885  spacer_count = this->spacers;
1886  return arrange_all;
1887  }
1888 
1889  /* 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 */
1890  uint min_small_width = (lengthof(arrange_switch) - lengthof(this->panel_widths)) * this->smallest_x / 2 + this->panel_widths[1];
1891  if (width > min_small_width) {
1892  width -= this->panel_widths[1];
1893  arrangable_count = lengthof(arrange_nopanel);
1894  button_count = arrangable_count - 1;
1895  spacer_count = this->spacers - 1;
1896  return arrange_nopanel;
1897  }
1898 
1899  /* Split toolbar */
1900  width -= this->panel_widths[1];
1901  arrangable_count = lengthof(arrange_switch) / 2;
1902  button_count = arrangable_count - 1;
1903  spacer_count = 0;
1904  return arrange_switch + ((_toolbar_mode == TB_LOWER) ? arrangable_count : 0);
1905  }
1906 };
1907 
1908 /* --- Toolbar handling for the 'normal' case */
1909 
1910 typedef CallBackFunction ToolbarButtonProc(Window *w);
1911 
1912 static ToolbarButtonProc * const _toolbar_button_procs[] = {
1913  ToolbarPauseClick,
1917  ToolbarMapClick,
1918  ToolbarTownClick,
1919  ToolbarSubsidiesClick,
1920  ToolbarStationsClick,
1921  ToolbarFinancesClick,
1922  ToolbarCompaniesClick,
1923  ToolbarStoryClick,
1924  ToolbarGoalClick,
1925  ToolbarGraphsClick,
1926  ToolbarLeagueClick,
1927  ToolbarIndustryClick,
1928  ToolbarTrainClick,
1929  ToolbarRoadClick,
1930  ToolbarShipClick,
1931  ToolbarAirClick,
1932  ToolbarZoomInClick,
1933  ToolbarZoomOutClick,
1934  ToolbarBuildRailClick,
1935  ToolbarBuildRoadClick,
1936  ToolbarBuildWaterClick,
1937  ToolbarBuildAirClick,
1938  ToolbarForestClick,
1939  ToolbarMusicClick,
1940  ToolbarNewspaperClick,
1941  ToolbarHelpClick,
1942  ToolbarSwitchClick,
1943 };
1944 
1945 enum MainToolbarHotkeys {
1946  MTHK_PAUSE,
1947  MTHK_FASTFORWARD,
1948  MTHK_SETTINGS,
1949  MTHK_SAVEGAME,
1950  MTHK_LOADGAME,
1951  MTHK_SMALLMAP,
1952  MTHK_TOWNDIRECTORY,
1953  MTHK_SUBSIDIES,
1954  MTHK_STATIONS,
1955  MTHK_FINANCES,
1956  MTHK_COMPANIES,
1957  MTHK_STORY,
1958  MTHK_GOAL,
1959  MTHK_GRAPHS,
1960  MTHK_LEAGUE,
1961  MTHK_INDUSTRIES,
1962  MTHK_TRAIN_LIST,
1963  MTHK_ROADVEH_LIST,
1964  MTHK_SHIP_LIST,
1965  MTHK_AIRCRAFT_LIST,
1966  MTHK_ZOOM_IN,
1967  MTHK_ZOOM_OUT,
1968  MTHK_BUILD_RAIL,
1969  MTHK_BUILD_ROAD,
1970  MTHK_BUILD_DOCKS,
1971  MTHK_BUILD_AIRPORT,
1972  MTHK_BUILD_TREES,
1973  MTHK_MUSIC,
1974  MTHK_AI_DEBUG,
1975  MTHK_SMALL_SCREENSHOT,
1976  MTHK_ZOOMEDIN_SCREENSHOT,
1977  MTHK_DEFAULTZOOM_SCREENSHOT,
1978  MTHK_GIANT_SCREENSHOT,
1979  MTHK_CHEATS,
1980  MTHK_TERRAFORM,
1981  MTHK_EXTRA_VIEWPORT,
1982  MTHK_CLIENT_LIST,
1983  MTHK_SIGN_LIST,
1984 };
1985 
1988  GUITimer timer;
1989 
1990  MainToolbarWindow(WindowDesc *desc) : Window(desc)
1991  {
1992  this->InitNested(0);
1993 
1994  _last_started_action = CBF_NONE;
1995  CLRBITS(this->flags, WF_WHITE_BORDER);
1996  this->SetWidgetDisabledState(WID_TN_PAUSE, _networking && !_network_server); // if not server, disable pause button
1997  this->SetWidgetDisabledState(WID_TN_FAST_FORWARD, _networking); // if networking, disable fast-forward button
1998  PositionMainToolbar(this);
2000 
2001  this->timer.SetInterval(MILLISECONDS_PER_TICK);
2002  }
2003 
2004  virtual void FindWindowPlacementAndResize(int def_width, int def_height)
2005  {
2007  }
2008 
2009  virtual void OnPaint()
2010  {
2011  /* If spectator, disable all construction buttons
2012  * ie : Build road, rail, ships, airports and landscaping
2013  * Since enabled state is the default, just disable when needed */
2015  /* disable company list drop downs, if there are no companies */
2017 
2018  this->SetWidgetDisabledState(WID_TN_GOAL, Goal::GetNumItems() == 0);
2019  this->SetWidgetDisabledState(WID_TN_STORY, StoryPage::GetNumItems() == 0);
2020 
2021  this->SetWidgetDisabledState(WID_TN_RAILS, !CanBuildVehicleInfrastructure(VEH_TRAIN));
2022  this->SetWidgetDisabledState(WID_TN_AIR, !CanBuildVehicleInfrastructure(VEH_AIRCRAFT));
2023 
2024  this->DrawWidgets();
2025  }
2026 
2027  virtual void OnClick(Point pt, int widget, int click_count)
2028  {
2029  if (_game_mode != GM_MENU && !this->IsWidgetDisabled(widget)) _toolbar_button_procs[widget](this);
2030  }
2031 
2032  virtual void OnDropdownSelect(int widget, int index)
2033  {
2034  CallBackFunction cbf = _menu_clicked_procs[widget](index);
2035  if (cbf != CBF_NONE) _last_started_action = cbf;
2036  }
2037 
2038  virtual EventState OnHotkey(int hotkey)
2039  {
2040  switch (hotkey) {
2041  case MTHK_PAUSE: ToolbarPauseClick(this); break;
2042  case MTHK_FASTFORWARD: ToolbarFastForwardClick(this); break;
2043  case MTHK_SETTINGS: ShowGameOptions(); break;
2044  case MTHK_SAVEGAME: MenuClickSaveLoad(); break;
2045  case MTHK_LOADGAME: ShowSaveLoadDialog(FT_SAVEGAME, SLO_LOAD); break;
2046  case MTHK_SMALLMAP: ShowSmallMap(); break;
2047  case MTHK_TOWNDIRECTORY: ShowTownDirectory(); break;
2048  case MTHK_SUBSIDIES: ShowSubsidiesList(); break;
2049  case MTHK_STATIONS: ShowCompanyStations(_local_company); break;
2050  case MTHK_FINANCES: ShowCompanyFinances(_local_company); break;
2051  case MTHK_COMPANIES: ShowCompany(_local_company); break;
2052  case MTHK_STORY: ShowStoryBook(_local_company); break;
2053  case MTHK_GOAL: ShowGoalsList(_local_company); break;
2054  case MTHK_GRAPHS: ShowOperatingProfitGraph(); break;
2055  case MTHK_LEAGUE: ShowCompanyLeagueTable(); break;
2056  case MTHK_INDUSTRIES: ShowBuildIndustryWindow(); break;
2057  case MTHK_TRAIN_LIST: ShowVehicleListWindow(_local_company, VEH_TRAIN); break;
2058  case MTHK_ROADVEH_LIST: ShowVehicleListWindow(_local_company, VEH_ROAD); break;
2059  case MTHK_SHIP_LIST: ShowVehicleListWindow(_local_company, VEH_SHIP); break;
2060  case MTHK_AIRCRAFT_LIST: ShowVehicleListWindow(_local_company, VEH_AIRCRAFT); break;
2061  case MTHK_ZOOM_IN: ToolbarZoomInClick(this); break;
2062  case MTHK_ZOOM_OUT: ToolbarZoomOutClick(this); break;
2063  case MTHK_BUILD_RAIL: if (CanBuildVehicleInfrastructure(VEH_TRAIN)) ShowBuildRailToolbar(_last_built_railtype); break;
2064  case MTHK_BUILD_ROAD: ShowBuildRoadToolbar(_last_built_roadtype); break;
2065  case MTHK_BUILD_DOCKS: ShowBuildDocksToolbar(); break;
2066  case MTHK_BUILD_AIRPORT: if (CanBuildVehicleInfrastructure(VEH_AIRCRAFT)) ShowBuildAirToolbar(); break;
2067  case MTHK_BUILD_TREES: ShowBuildTreesToolbar(); break;
2068  case MTHK_MUSIC: ShowMusicWindow(); break;
2069  case MTHK_AI_DEBUG: ShowAIDebugWindow(); break;
2070  case MTHK_SMALL_SCREENSHOT: MenuClickSmallScreenshot(); break;
2071  case MTHK_ZOOMEDIN_SCREENSHOT: MenuClickLargeWorldScreenshot(SC_ZOOMEDIN); break;
2072  case MTHK_DEFAULTZOOM_SCREENSHOT: MenuClickLargeWorldScreenshot(SC_DEFAULTZOOM); break;
2073  case MTHK_GIANT_SCREENSHOT: MenuClickLargeWorldScreenshot(SC_WORLD); break;
2074  case MTHK_CHEATS: if (!_networking) ShowCheatWindow(); break;
2075  case MTHK_TERRAFORM: ShowTerraformToolbar(); break;
2076  case MTHK_EXTRA_VIEWPORT: ShowExtraViewPortWindowForTileUnderCursor(); break;
2077 #ifdef ENABLE_NETWORK
2078  case MTHK_CLIENT_LIST: if (_networking) ShowClientList(); break;
2079 #endif
2080  case MTHK_SIGN_LIST: ShowSignList(); break;
2081  default: return ES_NOT_HANDLED;
2082  }
2083  return ES_HANDLED;
2084  }
2085 
2086  virtual void OnPlaceObject(Point pt, TileIndex tile)
2087  {
2088  switch (_last_started_action) {
2089  case CBF_PLACE_SIGN:
2090  PlaceProc_Sign(tile);
2091  break;
2092 
2093  case CBF_PLACE_LANDINFO:
2094  ShowLandInfo(tile);
2095  break;
2096 
2097  default: NOT_REACHED();
2098  }
2099  }
2100 
2101  virtual void OnPlaceObjectAbort()
2102  {
2103  _last_started_action = CBF_NONE;
2104  }
2105 
2106  virtual void OnRealtimeTick(uint delta_ms)
2107  {
2108  if (!this->timer.Elapsed(delta_ms)) return;
2109  this->timer.SetInterval(MILLISECONDS_PER_TICK);
2110 
2111  if (this->IsWidgetLowered(WID_TN_PAUSE) != !!_pause_mode) {
2112  this->ToggleWidgetLoweredState(WID_TN_PAUSE);
2113  this->SetWidgetDirty(WID_TN_PAUSE);
2114  }
2115 
2116  if (this->IsWidgetLowered(WID_TN_FAST_FORWARD) != !!_fast_forward) {
2117  this->ToggleWidgetLoweredState(WID_TN_FAST_FORWARD);
2118  this->SetWidgetDirty(WID_TN_FAST_FORWARD);
2119  }
2120  }
2121 
2122  virtual void OnTimeout()
2123  {
2124  /* We do not want to automatically raise the pause, fast forward and
2125  * switchbar buttons; they have to stay down when pressed etc. */
2126  for (uint i = WID_TN_SETTINGS; i < WID_TN_SWITCH_BAR; i++) {
2127  if (this->IsWidgetLowered(i)) {
2128  this->RaiseWidget(i);
2129  this->SetWidgetDirty(i);
2130  }
2131  }
2132  }
2133 
2139  virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
2140  {
2141  if (!gui_scope) return;
2143  }
2144 
2145  static HotkeyList hotkeys;
2146 };
2147 
2148 const uint16 _maintoolbar_pause_keys[] = {WKC_F1, WKC_PAUSE, 0};
2149 const uint16 _maintoolbar_zoomin_keys[] = {WKC_NUM_PLUS, WKC_EQUALS, WKC_SHIFT | WKC_EQUALS, WKC_SHIFT | WKC_F5, 0};
2150 const uint16 _maintoolbar_zoomout_keys[] = {WKC_NUM_MINUS, WKC_MINUS, WKC_SHIFT | WKC_MINUS, WKC_SHIFT | WKC_F6, 0};
2151 const uint16 _maintoolbar_smallmap_keys[] = {WKC_F4, 'M', 0};
2152 
2153 static Hotkey maintoolbar_hotkeys[] = {
2154  Hotkey(_maintoolbar_pause_keys, "pause", MTHK_PAUSE),
2155  Hotkey((uint16)0, "fastforward", MTHK_FASTFORWARD),
2156  Hotkey(WKC_F2, "settings", MTHK_SETTINGS),
2157  Hotkey(WKC_F3, "saveload", MTHK_SAVEGAME),
2158  Hotkey((uint16)0, "load_game", MTHK_LOADGAME),
2159  Hotkey(_maintoolbar_smallmap_keys, "smallmap", MTHK_SMALLMAP),
2160  Hotkey(WKC_F5, "town_list", MTHK_TOWNDIRECTORY),
2161  Hotkey(WKC_F6, "subsidies", MTHK_SUBSIDIES),
2162  Hotkey(WKC_F7, "station_list", MTHK_STATIONS),
2163  Hotkey(WKC_F8, "finances", MTHK_FINANCES),
2164  Hotkey(WKC_F9, "companies", MTHK_COMPANIES),
2165  Hotkey((uint16)0, "story_book", MTHK_STORY),
2166  Hotkey((uint16)0, "goal_list", MTHK_GOAL),
2167  Hotkey(WKC_F10, "graphs", MTHK_GRAPHS),
2168  Hotkey(WKC_F11, "league", MTHK_LEAGUE),
2169  Hotkey(WKC_F12, "industry_list", MTHK_INDUSTRIES),
2170  Hotkey(WKC_SHIFT | WKC_F1, "train_list", MTHK_TRAIN_LIST),
2171  Hotkey(WKC_SHIFT | WKC_F2, "roadveh_list", MTHK_ROADVEH_LIST),
2172  Hotkey(WKC_SHIFT | WKC_F3, "ship_list", MTHK_SHIP_LIST),
2173  Hotkey(WKC_SHIFT | WKC_F4, "aircraft_list", MTHK_AIRCRAFT_LIST),
2174  Hotkey(_maintoolbar_zoomin_keys, "zoomin", MTHK_ZOOM_IN),
2175  Hotkey(_maintoolbar_zoomout_keys, "zoomout", MTHK_ZOOM_OUT),
2176  Hotkey(WKC_SHIFT | WKC_F7, "build_rail", MTHK_BUILD_RAIL),
2177  Hotkey(WKC_SHIFT | WKC_F8, "build_road", MTHK_BUILD_ROAD),
2178  Hotkey(WKC_SHIFT | WKC_F9, "build_docks", MTHK_BUILD_DOCKS),
2179  Hotkey(WKC_SHIFT | WKC_F10, "build_airport", MTHK_BUILD_AIRPORT),
2180  Hotkey(WKC_SHIFT | WKC_F11, "build_trees", MTHK_BUILD_TREES),
2181  Hotkey(WKC_SHIFT | WKC_F12, "music", MTHK_MUSIC),
2182  Hotkey((uint16)0, "ai_debug", MTHK_AI_DEBUG),
2183  Hotkey(WKC_CTRL | 'S', "small_screenshot", MTHK_SMALL_SCREENSHOT),
2184  Hotkey(WKC_CTRL | 'P', "zoomedin_screenshot", MTHK_ZOOMEDIN_SCREENSHOT),
2185  Hotkey(WKC_CTRL | 'D', "defaultzoom_screenshot", MTHK_DEFAULTZOOM_SCREENSHOT),
2186  Hotkey((uint16)0, "giant_screenshot", MTHK_GIANT_SCREENSHOT),
2187  Hotkey(WKC_CTRL | WKC_ALT | 'C', "cheats", MTHK_CHEATS),
2188  Hotkey('L', "terraform", MTHK_TERRAFORM),
2189  Hotkey('V', "extra_viewport", MTHK_EXTRA_VIEWPORT),
2190 #ifdef ENABLE_NETWORK
2191  Hotkey((uint16)0, "client_list", MTHK_CLIENT_LIST),
2192 #endif
2193  Hotkey((uint16)0, "sign_list", MTHK_SIGN_LIST),
2194  HOTKEY_LIST_END
2195 };
2196 HotkeyList MainToolbarWindow::hotkeys("maintoolbar", maintoolbar_hotkeys);
2197 
2198 static NWidgetBase *MakeMainToolbar(int *biggest_index)
2199 {
2201  static const SpriteID toolbar_button_sprites[] = {
2202  SPR_IMG_PAUSE, // WID_TN_PAUSE
2203  SPR_IMG_FASTFORWARD, // WID_TN_FAST_FORWARD
2204  SPR_IMG_SETTINGS, // WID_TN_SETTINGS
2205  SPR_IMG_SAVE, // WID_TN_SAVE
2206  SPR_IMG_SMALLMAP, // WID_TN_SMALL_MAP
2207  SPR_IMG_TOWN, // WID_TN_TOWNS
2208  SPR_IMG_SUBSIDIES, // WID_TN_SUBSIDIES
2209  SPR_IMG_COMPANY_LIST, // WID_TN_STATIONS
2210  SPR_IMG_COMPANY_FINANCE, // WID_TN_FINANCES
2211  SPR_IMG_COMPANY_GENERAL, // WID_TN_COMPANIES
2212  SPR_IMG_STORY_BOOK, // WID_TN_STORY
2213  SPR_IMG_GOAL, // WID_TN_GOAL
2214  SPR_IMG_GRAPHS, // WID_TN_GRAPHS
2215  SPR_IMG_COMPANY_LEAGUE, // WID_TN_LEAGUE
2216  SPR_IMG_INDUSTRY, // WID_TN_INDUSTRIES
2217  SPR_IMG_TRAINLIST, // WID_TN_TRAINS
2218  SPR_IMG_TRUCKLIST, // WID_TN_ROADVEHS
2219  SPR_IMG_SHIPLIST, // WID_TN_SHIPS
2220  SPR_IMG_AIRPLANESLIST, // WID_TN_AIRCRAFT
2221  SPR_IMG_ZOOMIN, // WID_TN_ZOOMIN
2222  SPR_IMG_ZOOMOUT, // WID_TN_ZOOMOUT
2223  SPR_IMG_BUILDRAIL, // WID_TN_RAILS
2224  SPR_IMG_BUILDROAD, // WID_TN_ROADS
2225  SPR_IMG_BUILDWATER, // WID_TN_WATER
2226  SPR_IMG_BUILDAIR, // WID_TN_AIR
2227  SPR_IMG_LANDSCAPING, // WID_TN_LANDSCAPE
2228  SPR_IMG_MUSIC, // WID_TN_MUSIC_SOUND
2229  SPR_IMG_MESSAGES, // WID_TN_MESSAGES
2230  SPR_IMG_QUERY, // WID_TN_HELP
2231  SPR_IMG_SWITCH_TOOLBAR, // WID_TN_SWITCH_BAR
2232  };
2233 
2235  for (uint i = 0; i < WID_TN_END; i++) {
2236  switch (i) {
2237  case WID_TN_SMALL_MAP:
2238  case WID_TN_FINANCES:
2239  case WID_TN_VEHICLE_START:
2240  case WID_TN_ZOOM_IN:
2242  case WID_TN_MUSIC_SOUND:
2243  hor->Add(new NWidgetSpacer(0, 0));
2244  break;
2245  }
2246  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));
2247  }
2248 
2249  *biggest_index = max<int>(*biggest_index, WID_TN_SWITCH_BAR);
2250  return hor;
2251 }
2252 
2253 static const NWidgetPart _nested_toolbar_normal_widgets[] = {
2255 };
2256 
2257 static WindowDesc _toolb_normal_desc(
2258  WDP_MANUAL, NULL, 0, 0,
2260  WDF_NO_FOCUS,
2261  _nested_toolbar_normal_widgets, lengthof(_nested_toolbar_normal_widgets),
2262  &MainToolbarWindow::hotkeys
2263 );
2264 
2265 
2266 /* --- Toolbar handling for the scenario editor */
2267 
2268 static ToolbarButtonProc * const _scen_toolbar_button_procs[] = {
2269  ToolbarPauseClick,
2273  ToolbarBtn_NULL,
2275  ToolbarScenDateBackward,
2276  ToolbarScenDateForward,
2277  ToolbarScenMapTownDir,
2278  ToolbarZoomInClick,
2279  ToolbarZoomOutClick,
2280  ToolbarScenGenLand,
2281  ToolbarScenGenTown,
2282  ToolbarScenGenIndustry,
2283  ToolbarScenBuildRoad,
2284  ToolbarScenBuildDocks,
2285  ToolbarScenPlantTrees,
2286  ToolbarScenPlaceSign,
2287  ToolbarBtn_NULL,
2288  NULL,
2289  NULL,
2290  NULL,
2291  NULL,
2292  NULL,
2293  NULL,
2294  NULL,
2295  ToolbarMusicClick,
2296  NULL,
2297  ToolbarHelpClick,
2298  ToolbarSwitchClick,
2299 };
2300 
2301 enum MainToolbarEditorHotkeys {
2302  MTEHK_PAUSE,
2303  MTEHK_FASTFORWARD,
2304  MTEHK_SETTINGS,
2305  MTEHK_SAVEGAME,
2306  MTEHK_GENLAND,
2307  MTEHK_GENTOWN,
2308  MTEHK_GENINDUSTRY,
2309  MTEHK_BUILD_ROAD,
2310  MTEHK_BUILD_DOCKS,
2311  MTEHK_BUILD_TREES,
2312  MTEHK_SIGN,
2313  MTEHK_MUSIC,
2314  MTEHK_LANDINFO,
2315  MTEHK_SMALL_SCREENSHOT,
2316  MTEHK_ZOOMEDIN_SCREENSHOT,
2317  MTEHK_DEFAULTZOOM_SCREENSHOT,
2318  MTEHK_GIANT_SCREENSHOT,
2319  MTEHK_ZOOM_IN,
2320  MTEHK_ZOOM_OUT,
2321  MTEHK_TERRAFORM,
2322  MTEHK_SMALLMAP,
2323  MTEHK_EXTRA_VIEWPORT,
2324 };
2325 
2327  GUITimer timer;
2328 
2330  {
2331  this->InitNested(0);
2332 
2333  _last_started_action = CBF_NONE;
2334  CLRBITS(this->flags, WF_WHITE_BORDER);
2335  PositionMainToolbar(this);
2337 
2338  this->timer.SetInterval(MILLISECONDS_PER_TICK);
2339  }
2340 
2341  virtual void FindWindowPlacementAndResize(int def_width, int def_height)
2342  {
2344  }
2345 
2346  virtual void OnPaint()
2347  {
2348  this->SetWidgetDisabledState(WID_TE_DATE_BACKWARD, _settings_game.game_creation.starting_year <= MIN_YEAR);
2349  this->SetWidgetDisabledState(WID_TE_DATE_FORWARD, _settings_game.game_creation.starting_year >= MAX_YEAR);
2350 
2351  this->DrawWidgets();
2352  }
2353 
2354  virtual void DrawWidget(const Rect &r, int widget) const
2355  {
2356  switch (widget) {
2357  case WID_TE_DATE:
2359  DrawString(r.left, r.right, (this->height - FONT_HEIGHT_NORMAL) / 2, STR_WHITE_DATE_LONG, TC_FROMSTRING, SA_HOR_CENTER);
2360  break;
2361 
2362  case WID_TE_SPACER: {
2363  int height = r.bottom - r.top;
2364  if (height > 2 * FONT_HEIGHT_NORMAL) {
2365  DrawString(r.left, r.right, (height + 1) / 2 - FONT_HEIGHT_NORMAL, STR_SCENEDIT_TOOLBAR_OPENTTD, TC_FROMSTRING, SA_HOR_CENTER);
2366  DrawString(r.left, r.right, (height + 1) / 2, STR_SCENEDIT_TOOLBAR_SCENARIO_EDITOR, TC_FROMSTRING, SA_HOR_CENTER);
2367  } else {
2368  DrawString(r.left, r.right, (height - FONT_HEIGHT_NORMAL) / 2, STR_SCENEDIT_TOOLBAR_SCENARIO_EDITOR, TC_FROMSTRING, SA_HOR_CENTER);
2369  }
2370  break;
2371  }
2372  }
2373  }
2374 
2375  virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
2376  {
2377  switch (widget) {
2378  case WID_TE_SPACER:
2379  size->width = max(GetStringBoundingBox(STR_SCENEDIT_TOOLBAR_OPENTTD).width, GetStringBoundingBox(STR_SCENEDIT_TOOLBAR_SCENARIO_EDITOR).width) + WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT;
2380  break;
2381 
2382  case WID_TE_DATE:
2383  SetDParam(0, ConvertYMDToDate(MAX_YEAR, 0, 1));
2384  *size = GetStringBoundingBox(STR_WHITE_DATE_LONG);
2385  size->height = max(size->height, GetSpriteSize(SPR_IMG_SAVE).height + WD_IMGBTN_TOP + WD_IMGBTN_BOTTOM);
2386  break;
2387  }
2388  }
2389 
2390  virtual void OnClick(Point pt, int widget, int click_count)
2391  {
2392  if (_game_mode == GM_MENU) return;
2393  CallBackFunction cbf = _scen_toolbar_button_procs[widget](this);
2394  if (cbf != CBF_NONE) _last_started_action = cbf;
2395  }
2396 
2397  virtual void OnDropdownSelect(int widget, int index)
2398  {
2399  /* The map button is in a different location on the scenario
2400  * editor toolbar, so we need to adjust for it. */
2401  if (widget == WID_TE_SMALL_MAP) widget = WID_TN_SMALL_MAP;
2402  CallBackFunction cbf = _menu_clicked_procs[widget](index);
2403  if (cbf != CBF_NONE) _last_started_action = cbf;
2404  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
2405  }
2406 
2407  virtual EventState OnHotkey(int hotkey)
2408  {
2409  CallBackFunction cbf = CBF_NONE;
2410  switch (hotkey) {
2411  case MTEHK_PAUSE: ToolbarPauseClick(this); break;
2412  case MTEHK_FASTFORWARD: ToolbarFastForwardClick(this); break;
2413  case MTEHK_SETTINGS: ShowGameOptions(); break;
2414  case MTEHK_SAVEGAME: MenuClickSaveLoad(); break;
2415  case MTEHK_GENLAND: ToolbarScenGenLand(this); break;
2416  case MTEHK_GENTOWN: ToolbarScenGenTown(this); break;
2417  case MTEHK_GENINDUSTRY: ToolbarScenGenIndustry(this); break;
2418  case MTEHK_BUILD_ROAD: ToolbarScenBuildRoad(this); break;
2419  case MTEHK_BUILD_DOCKS: ToolbarScenBuildDocks(this); break;
2420  case MTEHK_BUILD_TREES: ToolbarScenPlantTrees(this); break;
2421  case MTEHK_SIGN: cbf = ToolbarScenPlaceSign(this); break;
2422  case MTEHK_MUSIC: ShowMusicWindow(); break;
2423  case MTEHK_LANDINFO: cbf = PlaceLandBlockInfo(); break;
2424  case MTEHK_SMALL_SCREENSHOT: MenuClickSmallScreenshot(); break;
2425  case MTEHK_ZOOMEDIN_SCREENSHOT: MenuClickLargeWorldScreenshot(SC_ZOOMEDIN); break;
2426  case MTEHK_DEFAULTZOOM_SCREENSHOT: MenuClickLargeWorldScreenshot(SC_DEFAULTZOOM); break;
2427  case MTEHK_GIANT_SCREENSHOT: MenuClickLargeWorldScreenshot(SC_WORLD); break;
2428  case MTEHK_ZOOM_IN: ToolbarZoomInClick(this); break;
2429  case MTEHK_ZOOM_OUT: ToolbarZoomOutClick(this); break;
2430  case MTEHK_TERRAFORM: ShowEditorTerraformToolbar(); break;
2431  case MTEHK_SMALLMAP: ShowSmallMap(); break;
2432  case MTEHK_EXTRA_VIEWPORT: ShowExtraViewPortWindowForTileUnderCursor(); break;
2433  default: return ES_NOT_HANDLED;
2434  }
2435  if (cbf != CBF_NONE) _last_started_action = cbf;
2436  return ES_HANDLED;
2437  }
2438 
2439  virtual void OnPlaceObject(Point pt, TileIndex tile)
2440  {
2441  switch (_last_started_action) {
2442  case CBF_PLACE_SIGN:
2443  PlaceProc_Sign(tile);
2444  break;
2445 
2446  case CBF_PLACE_LANDINFO:
2447  ShowLandInfo(tile);
2448  break;
2449 
2450  default: NOT_REACHED();
2451  }
2452  }
2453 
2454  virtual void OnPlaceObjectAbort()
2455  {
2456  _last_started_action = CBF_NONE;
2457  }
2458 
2459  virtual void OnTimeout()
2460  {
2461  this->SetWidgetsLoweredState(false, WID_TE_DATE_BACKWARD, WID_TE_DATE_FORWARD, WIDGET_LIST_END);
2462  this->SetWidgetDirty(WID_TE_DATE_BACKWARD);
2463  this->SetWidgetDirty(WID_TE_DATE_FORWARD);
2464  }
2465 
2466  virtual void OnRealtimeTick(uint delta_ms)
2467  {
2468  if (!this->timer.Elapsed(delta_ms)) return;
2469  this->timer.SetInterval(MILLISECONDS_PER_TICK);
2470 
2471  if (this->IsWidgetLowered(WID_TE_PAUSE) != !!_pause_mode) {
2472  this->ToggleWidgetLoweredState(WID_TE_PAUSE);
2473  this->SetDirty();
2474  }
2475 
2476  if (this->IsWidgetLowered(WID_TE_FAST_FORWARD) != !!_fast_forward) {
2477  this->ToggleWidgetLoweredState(WID_TE_FAST_FORWARD);
2478  this->SetDirty();
2479  }
2480  }
2481 
2487  virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
2488  {
2489  if (!gui_scope) return;
2491  }
2492 
2493  virtual void OnQueryTextFinished(char *str)
2494  {
2495  /* Was 'cancel' pressed? */
2496  if (str == NULL) return;
2497 
2498  int32 value;
2499  if (!StrEmpty(str)) {
2500  value = atoi(str);
2501  } else {
2502  /* An empty string means revert to the default */
2503  value = DEF_START_YEAR;
2504  }
2505  SetStartingYear(value);
2506 
2507  this->SetDirty();
2508  }
2509 
2510  static HotkeyList hotkeys;
2511 };
2512 
2513 static Hotkey scenedit_maintoolbar_hotkeys[] = {
2514  Hotkey(_maintoolbar_pause_keys, "pause", MTEHK_PAUSE),
2515  Hotkey((uint16)0, "fastforward", MTEHK_FASTFORWARD),
2516  Hotkey(WKC_F2, "settings", MTEHK_SETTINGS),
2517  Hotkey(WKC_F3, "saveload", MTEHK_SAVEGAME),
2518  Hotkey(WKC_F4, "gen_land", MTEHK_GENLAND),
2519  Hotkey(WKC_F5, "gen_town", MTEHK_GENTOWN),
2520  Hotkey(WKC_F6, "gen_industry", MTEHK_GENINDUSTRY),
2521  Hotkey(WKC_F7, "build_road", MTEHK_BUILD_ROAD),
2522  Hotkey(WKC_F8, "build_docks", MTEHK_BUILD_DOCKS),
2523  Hotkey(WKC_F9, "build_trees", MTEHK_BUILD_TREES),
2524  Hotkey(WKC_F10, "build_sign", MTEHK_SIGN),
2525  Hotkey(WKC_F11, "music", MTEHK_MUSIC),
2526  Hotkey(WKC_F12, "land_info", MTEHK_LANDINFO),
2527  Hotkey(WKC_CTRL | 'S', "small_screenshot", MTEHK_SMALL_SCREENSHOT),
2528  Hotkey(WKC_CTRL | 'P', "zoomedin_screenshot", MTEHK_ZOOMEDIN_SCREENSHOT),
2529  Hotkey(WKC_CTRL | 'D', "defaultzoom_screenshot", MTEHK_DEFAULTZOOM_SCREENSHOT),
2530  Hotkey((uint16)0, "giant_screenshot", MTEHK_GIANT_SCREENSHOT),
2531  Hotkey(_maintoolbar_zoomin_keys, "zoomin", MTEHK_ZOOM_IN),
2532  Hotkey(_maintoolbar_zoomout_keys, "zoomout", MTEHK_ZOOM_OUT),
2533  Hotkey('L', "terraform", MTEHK_TERRAFORM),
2534  Hotkey('M', "smallmap", MTEHK_SMALLMAP),
2535  Hotkey('V', "extra_viewport", MTEHK_EXTRA_VIEWPORT),
2536  HOTKEY_LIST_END
2537 };
2538 HotkeyList ScenarioEditorToolbarWindow::hotkeys("scenedit_maintoolbar", scenedit_maintoolbar_hotkeys);
2539 
2540 static const NWidgetPart _nested_toolb_scen_inner_widgets[] = {
2541  NWidget(WWT_IMGBTN, COLOUR_GREY, WID_TE_PAUSE), SetDataTip(SPR_IMG_PAUSE, STR_TOOLBAR_TOOLTIP_PAUSE_GAME),
2542  NWidget(WWT_IMGBTN, COLOUR_GREY, WID_TE_FAST_FORWARD), SetDataTip(SPR_IMG_FASTFORWARD, STR_TOOLBAR_TOOLTIP_FORWARD),
2543  NWidget(WWT_IMGBTN, COLOUR_GREY, WID_TE_SETTINGS), SetDataTip(SPR_IMG_SETTINGS, STR_TOOLBAR_TOOLTIP_OPTIONS),
2544  NWidget(WWT_IMGBTN_2, COLOUR_GREY, WID_TE_SAVE), SetDataTip(SPR_IMG_SAVE, STR_SCENEDIT_TOOLBAR_TOOLTIP_SAVE_SCENARIO_LOAD_SCENARIO),
2546  NWidget(WWT_PANEL, COLOUR_GREY, WID_TE_SPACER), EndContainer(),
2548  NWidget(WWT_PANEL, COLOUR_GREY, WID_TE_DATE_PANEL),
2549  NWidget(NWID_HORIZONTAL), SetPIP(3, 2, 3),
2550  NWidget(WWT_IMGBTN, COLOUR_GREY, WID_TE_DATE_BACKWARD), SetDataTip(SPR_ARROW_DOWN, STR_SCENEDIT_TOOLBAR_TOOLTIP_MOVE_THE_STARTING_DATE_BACKWARD),
2551  NWidget(WWT_EMPTY, COLOUR_GREY, WID_TE_DATE), SetDataTip(STR_NULL, STR_SCENEDIT_TOOLBAR_TOOLTIP_SET_DATE),
2552  NWidget(WWT_IMGBTN, COLOUR_GREY, WID_TE_DATE_FORWARD), SetDataTip(SPR_ARROW_UP, STR_SCENEDIT_TOOLBAR_TOOLTIP_MOVE_THE_STARTING_DATE_FORWARD),
2553  EndContainer(),
2554  EndContainer(),
2556  NWidget(WWT_IMGBTN, COLOUR_GREY, WID_TE_SMALL_MAP), SetDataTip(SPR_IMG_SMALLMAP, STR_SCENEDIT_TOOLBAR_TOOLTIP_DISPLAY_MAP_TOWN_DIRECTORY),
2558  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_TE_ZOOM_IN), SetDataTip(SPR_IMG_ZOOMIN, STR_TOOLBAR_TOOLTIP_ZOOM_THE_VIEW_IN),
2559  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_TE_ZOOM_OUT), SetDataTip(SPR_IMG_ZOOMOUT, STR_TOOLBAR_TOOLTIP_ZOOM_THE_VIEW_OUT),
2561  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_TE_LAND_GENERATE), SetDataTip(SPR_IMG_LANDSCAPING, STR_SCENEDIT_TOOLBAR_LANDSCAPE_GENERATION),
2562  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_TE_TOWN_GENERATE), SetDataTip(SPR_IMG_TOWN, STR_SCENEDIT_TOOLBAR_TOWN_GENERATION),
2563  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_TE_INDUSTRY), SetDataTip(SPR_IMG_INDUSTRY, STR_SCENEDIT_TOOLBAR_INDUSTRY_GENERATION),
2564  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_TE_ROADS), SetDataTip(SPR_IMG_BUILDROAD, STR_SCENEDIT_TOOLBAR_ROAD_CONSTRUCTION),
2565  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_TE_WATER), SetDataTip(SPR_IMG_BUILDWATER, STR_TOOLBAR_TOOLTIP_BUILD_SHIP_DOCKS),
2566  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_TE_TREES), SetDataTip(SPR_IMG_PLANTTREES, STR_SCENEDIT_TOOLBAR_PLANT_TREES),
2567  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_TE_SIGNS), SetDataTip(SPR_IMG_SIGN, STR_SCENEDIT_TOOLBAR_PLACE_SIGN),
2569  NWidget(WWT_IMGBTN, COLOUR_GREY, WID_TE_MUSIC_SOUND), SetDataTip(SPR_IMG_MUSIC, STR_TOOLBAR_TOOLTIP_SHOW_SOUND_MUSIC_WINDOW),
2570  NWidget(WWT_IMGBTN, COLOUR_GREY, WID_TE_HELP), SetDataTip(SPR_IMG_QUERY, STR_TOOLBAR_TOOLTIP_LAND_BLOCK_INFORMATION),
2571  NWidget(WWT_IMGBTN, COLOUR_GREY, WID_TE_SWITCH_BAR), SetDataTip(SPR_IMG_SWITCH_TOOLBAR, STR_TOOLBAR_TOOLTIP_SWITCH_TOOLBAR),
2572 };
2573 
2574 static NWidgetBase *MakeScenarioToolbar(int *biggest_index)
2575 {
2576  return MakeNWidgets(_nested_toolb_scen_inner_widgets, lengthof(_nested_toolb_scen_inner_widgets), biggest_index, new NWidgetScenarioToolbarContainer());
2577 }
2578 
2579 static const NWidgetPart _nested_toolb_scen_widgets[] = {
2580  NWidgetFunction(MakeScenarioToolbar),
2581 };
2582 
2583 static WindowDesc _toolb_scen_desc(
2584  WDP_MANUAL, NULL, 0, 0,
2586  WDF_NO_FOCUS,
2587  _nested_toolb_scen_widgets, lengthof(_nested_toolb_scen_widgets),
2588  &ScenarioEditorToolbarWindow::hotkeys
2589 );
2590 
2593 {
2594  /* Clean old GUI values; railtype is (re)set by rail_gui.cpp */
2595  _last_built_roadtype = ROADTYPE_ROAD;
2596 
2597  if (_game_mode == GM_EDITOR) {
2598  new ScenarioEditorToolbarWindow(&_toolb_scen_desc);
2599  } else {
2600  new MainToolbarWindow(&_toolb_normal_desc);
2601  }
2602 }
virtual void OnPlaceObjectAbort()
The user cancelled a tile highlight mode that has been set.
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:144
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:867
Empty widget, place holder to reserve space in widget array.
Definition: widget_type.h:48
Functions/types related to NewGRF debugging.
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.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:77
used in multiplayer to create a new companies etc.
Definition: command_type.h:279
void Draw(const Window *w)
Draw the widgets of the tree.
static void PopupMainToolbMenu(Window *w, int widget, DropDownList *list, int def)
Pop up a generic text only menu.
bool _networking
are we in networking mode?
Definition: network.cpp:56
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.
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:99
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
A game normally paused.
Definition: openttd.h:59
A normal unpaused game.
Definition: openttd.h:58
Sign building.
GRFConfig * _grfconfig
First item in list of current GRF set up.
byte landscape
the landscape we&#39;re currently in
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:448
RailType
Enumeration for all possible railtypes.
Definition: rail_type.h:29
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.
TownFoundingByte found_town
town founding,
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:305
virtual void OnQueryTextFinished(char *str)
The query window opened from this window has closed.
Help menu.
Zoom out (get helicopter view).
Definition: viewport_type.h:64
int height
Screen height of the viewport.
Definition: viewport_type.h:28
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:246
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:472
Hotkey related functions.
Functions related to dates.
virtual void OnPlaceObjectAbort()
The user cancelled a tile highlight mode that has been set.
GUIs related to networking.
Tree building toolbar.
static T ToggleBit(T &x, const uint8 y)
Toggles a bit in a variable.
Road vehicle menu.
Basic road type.
Definition: road_type.h:24
Window for configuring the AIs
static const int CTMN_SPECTATOR
Show a company window as spectator.
uint spacers
Number of spacer widgets in this toolbar.
Window * ShowTerraformToolbar(Window *link)
Show the toolbar for terraforming in the game.
virtual void OnRealtimeTick(uint delta_ms)
Called periodically.
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:1111
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:3455
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:1064
WidgetType type
Type of the widget / nested widget.
Definition: widget_type.h:163
Settings menu.
Aircraft menu.
Types for recording game performance data.
Small map menu.
Window * ShowSignList()
Open the sign list window.
Definition: signs_gui.cpp:403
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:809
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
virtual void OnDropdownSelect(int widget, int index)
A dropdown option associated to this window has been selected.
Window * ShowBuildDocksToolbar()
Open the build water toolbar window.
Definition: dock_gui.cpp:346
Vehicle data structure.
Definition: vehicle_base.h:212
static CallBackFunction MenuClickStory(int index)
Handle click on the entry in the Story menu.
static bool IsInsideBS(const T x, const uint base, const uint size)
Checks if a value is between a window started at some base point.
Definition: math_func.hpp:250
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
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.
const byte * GetButtonArrangement(uint &width, uint &arrangable_count, uint &button_count, uint &spacer_count) const
Get the arrangement of the buttons for the toolbar.
The client is spectating.
Definition: company_type.h:37
bool CanBuildVehicleInfrastructure(VehicleType type)
Check whether we can build infrastructure for the given vehicle type.
Definition: vehicle.cpp:1751
void ReInit(int rx=0, int ry=0)
Re-initialize a window, and optionally change its size.
Definition: window.cpp:976
bool NetworkCompanyIsPassworded(CompanyID company_id)
Check if the company we want to join requires a password.
Definition: network.cpp:225
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.
virtual void OnRealtimeTick(uint delta_ms)
Called periodically.
virtual void OnPlaceObject(Point pt, TileIndex tile)
The user clicked some place on the map when a tile highlight mode has been set.
Spacer widget.
Definition: widget_type.h:529
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:22
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.
Fully zoomed in screenshot of the visible area.
Definition: screenshot.h:23
Town menu.
Common string list item.
Definition: dropdown_type.h:41
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:78
File is being saved.
Definition: fileio_type.h:52
Small map menu.
Functions/types etc.
Functions, definitions and such used only by the GUI.
Servers always have this ID.
Definition: network_type.h:45
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:40
Display signs.
Definition: openttd.h:45
Industry menu.
static const Year DEF_START_YEAR
The default starting year.
Definition: date_type.h:88
T * Append(uint to_add=1)
Append an item and return it.
Leaf widget.
Definition: widget_type.h:770
CompanyByte _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:46
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:362
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:271
Fast forward the game.
virtual void OnInvalidateData(int data=0, bool gui_scope=true)
Some data on this window has become invalid.
virtual void OnInvalidateData(int data=0, bool gui_scope=true)
Some data on this window has become invalid.
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:3297
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
virtual EventState OnHotkey(int hotkey)
A hotkey has been pressed.
Aircraft vehicle type.
Definition: vehicle_type.h:29
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:28
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 ShowCompany(CompanyID company)
Show the window with the overview of the company.
void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl)
Assign size and position to the widget.
const byte * GetButtonArrangement(uint &width, uint &arrangable_count, uint &button_count, uint &spacer_count) const
Get the arrangement of the buttons for the toolbar.
Only available when toolbar has been split to switch between different subsets.
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:1205
GUI functions related to the news.
static CallBackFunction _last_started_action
Last started user action.
Definition: toolbar_gui.cpp:84
static LinkGraphSchedule instance
Static instance of LinkGraphSchedule.
VehicleType
Available vehicle types.
Definition: vehicle_type.h:23
void ShowMessageHistory()
Display window with news messages history.
Definition: news_gui.cpp:1141
static CallBackFunction MenuClickLeague(int index)
Handle click on the entry in the CompanyLeague menu.
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
Definition: gfx_func.h:180
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.
Simple vector template class, with automatic delete.
ClientID _network_own_client_id
Our client identifier.
Definition: network.cpp:63
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:76
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.
OptionMenuEntries
Game Option button menu entries.
A number of safeguards to prevent using unsafe methods.
Trams.
Definition: road_type.h:25
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition: gfx_type.h:247
List of hotkeys for a window.
Definition: hotkeys.h:42
rectangle (stations, depots, ...)
First company, same as owner.
Definition: company_type.h:24
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:90
Window timeout counter.
Definition: window_gui.h:234
virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
Update size and resize step of a widget in the window.
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:925
Road building menu.
byte misc_flags
Miscellaneous flags.
Definition: engine_type.h:142
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
Baseclass for nested widgets.
Definition: widget_type.h:126
Graph menu.
virtual void OnClick(Point pt, int widget, int click_count)
A click with the left mouse button has been made on the window.
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.
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:531
Rail building menu.
virtual void OnPlaceObject(Point pt, TileIndex tile)
The user clicked some place on the map when a tile highlight mode has been set.
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.
PauseModeByte _pause_mode
The current pause mode.
Definition: gfx.cpp:48
Road vehicle type.
Definition: vehicle_type.h:27
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.
Airport building toolbar.
static CallBackFunction MenuClickTown(int index)
Handle click on one of the entries in the Town menu.
Functions related to sound.
Finance menu.
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:18
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.
Maximum number of companies.
Definition: company_type.h:25
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
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:1988
Ship vehicle type.
Definition: vehicle_type.h:28
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:965
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
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:699
virtual void OnPaint()
The window must be repainted.
static const uint8 PC_VERY_DARK_RED
Almost-black red palette colour.
Definition: gfx_func.h:212
static CallBackFunction ToolbarSaveClick(Window *w)
Handle click on Save button in toolbar in normal game mode.
NWidgetCore * GetWidgetFromPos(int x, int y)
Retrieve a widget by its position.
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:213
Smallmap GUI functions.
virtual void DrawWidget(const Rect &r, int widget) const
Draw the contents of a nested widget.
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
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.
Declaration of functions and types defined in highscore.h and highscore_gui.h.
Zoom in the main viewport.
virtual void OnClick(Point pt, int widget, int click_count)
A click with the left mouse button has been made on the window.
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.
virtual void OnTimeout()
Called when this window&#39;s timeout has been reached.
Zoomed to default zoom level screenshot of the visible area.
Definition: screenshot.h:24
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:892
uint _toolbar_width
Width of the toolbar, shared by statusbar.
Definition: toolbar_gui.cpp:63
static size_t GetNumItems()
Returns number of valid items in the pool.
Definition: pool_type.hpp:276
Water building toolbar.
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition: strings.cpp:52
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:68
This window won&#39;t get focus/make any other window lose focus when click.
Definition: window_gui.h:212
Station 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
OwnerByte owner
Which company owns the vehicle?
Definition: vehicle_base.h:273
RoadTypes avail_roadtypes
Road types available to this company.
Definition: company_base.h:120
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.
NWidgetCore * GetWidgetFromPos(int x, int y)
Retrieve a widget by its position.
Definition: widget.cpp:905
Main toolbar.
uint current_x
Current horizontal size (after resizing).
Definition: widget_type.h:174
Goal base class.
Forbidden.
Definition: town_type.h:100
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.
virtual void OnPaint()
The window must be repainted.
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 succesful constructions or other actions.
Music/sound configuration menu.
virtual void OnTimeout()
Called when this window&#39;s timeout has been reached.
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).
Network functions used by other parts of OpenTTD.
Helper for knowing the amount of widgets.
bool _network_server
network-server is active
Definition: network.cpp:57
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:766
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:768
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-NULL) 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:3030
virtual void FindWindowPlacementAndResize(int def_width, int def_height)
Resize window towards the default size.
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
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:618
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:1503
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.
ToolbarMode
Toobar modes.
Definition: toolbar_gui.cpp:71
static void PopupMainCompanyToolbMenu(Window *w, int widget, int grey=0, bool include_spectator=false)
Pop up a generic company list menu.
SaveLoadEditorMenuEntries
SaveLoad entries in scenario editor mode.
Window * ShowBuildRoadScenToolbar()
Show the road building toolbar in the scenario editor.
Definition: road_gui.cpp:857
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:69
#define FOR_ALL_VEHICLES(var)
Iterate over all vehicles.
Definition: vehicle_base.h:987
void SetupSmallestSize(Window *w, bool init_array)
Compute smallest size needed by the widget.
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:3075
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
Road vehicle is a tram/light rail vehicle.
Definition: engine_type.h:154
Functions related to tile highlights.
static CallBackFunction MenuClickNewspaper(int index)
Handle click on the entry in the Newspaper menu.
Owner
Enum for all companies/owners.
Definition: company_type.h:20
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.
(Toggle) Button with image
Definition: widget_type.h:52
Manually align the window (so no automatic location finding)
Definition: window_gui.h:155
void SetupSmallestSize(Window *w, bool init_array)
Compute smallest size needed by the widget.
Help menu.
virtual void FindWindowPlacementAndResize(int def_width, int def_height)
Resize window towards the default size.
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:387
void PlaceProc_Sign(TileIndex tile)
PlaceProc function, called when someone pressed the button if the sign-tool is selected.
Definition: signs_cmd.cpp:132
uint8 timeout_timer
Timer value of the WF_TIMEOUT for flags.
Definition: window_gui.h:309
byte climates
Climates supported by the engine.
Definition: engine_type.h:138
Date _date
Current date in days (day counter)
Definition: date.cpp:28
An invalid company.
Definition: company_type.h:32
Window white border counter bit mask.
Definition: window_gui.h:242
Hack, used to update the button status.
Definition: viewport_type.h:65
Base list item class from which others are derived.
Definition: dropdown_type.h:24
VehicleTypeByte type
Type of vehicle.
Definition: vehicle_type.h:56
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.
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
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:833
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.
Settings menu.
Landscaping toolbar.
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
Definition: gfx.cpp:1461
virtual EventState OnHotkey(int hotkey)
A hotkey has been pressed.
ScreenshotType
Type of requested screenshot.
Definition: screenshot.h:20
Stuff related to the (main) toolbar.
Train vehicle type.
Definition: vehicle_type.h:26
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
virtual void OnDropdownSelect(int widget, int index)
A dropdown option associated to this window has been selected.
pause the game
Definition: command_type.h:255