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 #ifdef ENABLE_NETWORK
166  if (NetworkCompanyIsPassworded(company)) {
167  DrawSprite(SPR_LOCK, PAL_NONE, rtl ? left + WD_FRAMERECT_LEFT : right - this->lock_size.width - WD_FRAMERECT_RIGHT, top + lock_offset);
168  }
169 #endif
170 
171  SetDParam(0, company);
172  SetDParam(1, company);
173  TextColour col;
174  if (this->greyed) {
175  col = (sel ? TC_SILVER : TC_GREY) | TC_NO_SHADE;
176  } else {
177  col = sel ? TC_WHITE : TC_BLACK;
178  }
179  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);
180  }
181 };
182 
190 static void PopupMainToolbMenu(Window *w, int widget, DropDownList *list, int def)
191 {
192  ShowDropDownList(w, list, def, widget, 0, true, true);
193  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
194 }
195 
203 static void PopupMainToolbMenu(Window *w, int widget, StringID string, int count)
204 {
205  DropDownList *list = new DropDownList();
206  for (int i = 0; i < count; i++) {
207  *list->Append() = new DropDownListStringItem(string + i, i, false);
208  }
209  PopupMainToolbMenu(w, widget, list, 0);
210 }
211 
213 static const int CTMN_CLIENT_LIST = -1;
214 static const int CTMN_NEW_COMPANY = -2;
215 static const int CTMN_SPECTATE = -3;
216 static const int CTMN_SPECTATOR = -4;
217 
224 static void PopupMainCompanyToolbMenu(Window *w, int widget, int grey = 0)
225 {
226  DropDownList *list = new DropDownList();
227 
228  switch (widget) {
229  case WID_TN_COMPANIES:
230 #ifdef ENABLE_NETWORK
231  if (!_networking) break;
232 
233  /* Add the client list button for the companies menu */
234  *list->Append() = new DropDownListStringItem(STR_NETWORK_COMPANY_LIST_CLIENT_LIST, CTMN_CLIENT_LIST, false);
235 
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 #endif /* ENABLE_NETWORK */
242  break;
243 
244  case WID_TN_STORY:
245  *list->Append() = new DropDownListStringItem(STR_STORY_BOOK_SPECTATOR, CTMN_SPECTATOR, false);
246  break;
247 
248  case WID_TN_GOAL:
249  *list->Append() = new DropDownListStringItem(STR_GOALS_SPECTATOR, CTMN_SPECTATOR, false);
250  break;
251  }
252 
253  for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) {
254  if (!Company::IsValidID(c)) continue;
255  *list->Append() = new DropDownListCompanyItem(c, false, HasBit(grey, c));
256  }
257 
259 }
260 
261 
262 static ToolbarMode _toolbar_mode;
263 
264 static CallBackFunction SelectSignTool()
265 {
266  if (_last_started_action == CBF_PLACE_SIGN) {
268  return CBF_NONE;
269  } else {
270  SetObjectToPlace(SPR_CURSOR_SIGN, PAL_NONE, HT_RECT, WC_MAIN_TOOLBAR, 0);
271  return CBF_PLACE_SIGN;
272  }
273 }
274 
275 /* --- Pausing --- */
276 
277 static CallBackFunction ToolbarPauseClick(Window *w)
278 {
279  if (_networking && !_network_server) return CBF_NONE; // only server can pause the game
280 
282  if (_settings_client.sound.confirm) SndPlayFx(SND_15_BEEP);
283  }
284  return CBF_NONE;
285 }
286 
294 {
295  _fast_forward ^= true;
296  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
297  return CBF_NONE;
298 }
299 
304  OME_GAMEOPTIONS,
305  OME_SETTINGS,
306  OME_SCRIPT_SETTINGS,
307  OME_NEWGRFSETTINGS,
308  OME_TRANSPARENCIES,
309  OME_SHOW_TOWNNAMES,
310  OME_SHOW_STATIONNAMES,
311  OME_SHOW_WAYPOINTNAMES,
312  OME_SHOW_SIGNS,
313  OME_SHOW_COMPETITOR_SIGNS,
314  OME_FULL_ANIMATION,
315  OME_FULL_DETAILS,
316  OME_TRANSPARENTBUILDINGS,
317  OME_SHOW_STATIONSIGNS,
318 };
319 
327 {
328  DropDownList *list = new DropDownList();
329  *list->Append() = new DropDownListStringItem(STR_SETTINGS_MENU_GAME_OPTIONS, OME_GAMEOPTIONS, false);
330  *list->Append() = new DropDownListStringItem(STR_SETTINGS_MENU_CONFIG_SETTINGS_TREE, OME_SETTINGS, false);
331  /* Changes to the per-AI settings don't get send from the server to the clients. Clients get
332  * the settings once they join but never update it. As such don't show the window at all
333  * to network clients. */
334  if (!_networking || _network_server) *list->Append() = new DropDownListStringItem(STR_SETTINGS_MENU_SCRIPT_SETTINGS, OME_SCRIPT_SETTINGS, false);
335  *list->Append() = new DropDownListStringItem(STR_SETTINGS_MENU_NEWGRF_SETTINGS, OME_NEWGRFSETTINGS, false);
336  *list->Append() = new DropDownListStringItem(STR_SETTINGS_MENU_TRANSPARENCY_OPTIONS, OME_TRANSPARENCIES, false);
337  *list->Append() = new DropDownListItem(-1, false);
338  *list->Append() = new DropDownListCheckedItem(STR_SETTINGS_MENU_TOWN_NAMES_DISPLAYED, OME_SHOW_TOWNNAMES, false, HasBit(_display_opt, DO_SHOW_TOWN_NAMES));
339  *list->Append() = new DropDownListCheckedItem(STR_SETTINGS_MENU_STATION_NAMES_DISPLAYED, OME_SHOW_STATIONNAMES, false, HasBit(_display_opt, DO_SHOW_STATION_NAMES));
340  *list->Append() = new DropDownListCheckedItem(STR_SETTINGS_MENU_WAYPOINTS_DISPLAYED, OME_SHOW_WAYPOINTNAMES, false, HasBit(_display_opt, DO_SHOW_WAYPOINT_NAMES));
341  *list->Append() = new DropDownListCheckedItem(STR_SETTINGS_MENU_SIGNS_DISPLAYED, OME_SHOW_SIGNS, false, HasBit(_display_opt, DO_SHOW_SIGNS));
342  *list->Append() = new DropDownListCheckedItem(STR_SETTINGS_MENU_SHOW_COMPETITOR_SIGNS, OME_SHOW_COMPETITOR_SIGNS, false, HasBit(_display_opt, DO_SHOW_COMPETITOR_SIGNS));
343  *list->Append() = new DropDownListCheckedItem(STR_SETTINGS_MENU_FULL_ANIMATION, OME_FULL_ANIMATION, false, HasBit(_display_opt, DO_FULL_ANIMATION));
344  *list->Append() = new DropDownListCheckedItem(STR_SETTINGS_MENU_FULL_DETAIL, OME_FULL_DETAILS, false, HasBit(_display_opt, DO_FULL_DETAIL));
345  *list->Append() = new DropDownListCheckedItem(STR_SETTINGS_MENU_TRANSPARENT_BUILDINGS, OME_TRANSPARENTBUILDINGS, false, IsTransparencySet(TO_HOUSES));
346  *list->Append() = new DropDownListCheckedItem(STR_SETTINGS_MENU_TRANSPARENT_SIGNS, OME_SHOW_STATIONSIGNS, false, IsTransparencySet(TO_SIGNS));
347 
348  ShowDropDownList(w, list, 0, WID_TN_SETTINGS, 140, true, true);
349  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
350  return CBF_NONE;
351 }
352 
360 {
361  switch (index) {
362  case OME_GAMEOPTIONS: ShowGameOptions(); return CBF_NONE;
363  case OME_SETTINGS: ShowGameSettings(); return CBF_NONE;
364  case OME_SCRIPT_SETTINGS: ShowAIConfigWindow(); return CBF_NONE;
365  case OME_NEWGRFSETTINGS: ShowNewGRFSettings(!_networking && _settings_client.gui.UserIsAllowedToChangeNewGRFs(), true, true, &_grfconfig); return CBF_NONE;
366  case OME_TRANSPARENCIES: ShowTransparencyToolbar(); break;
367 
368  case OME_SHOW_TOWNNAMES: ToggleBit(_display_opt, DO_SHOW_TOWN_NAMES); break;
369  case OME_SHOW_STATIONNAMES: ToggleBit(_display_opt, DO_SHOW_STATION_NAMES); break;
370  case OME_SHOW_WAYPOINTNAMES: ToggleBit(_display_opt, DO_SHOW_WAYPOINT_NAMES); break;
371  case OME_SHOW_SIGNS: ToggleBit(_display_opt, DO_SHOW_SIGNS); break;
372  case OME_SHOW_COMPETITOR_SIGNS:
375  break;
376  case OME_FULL_ANIMATION: ToggleBit(_display_opt, DO_FULL_ANIMATION); CheckBlitter(); break;
377  case OME_FULL_DETAILS: ToggleBit(_display_opt, DO_FULL_DETAIL); break;
378  case OME_TRANSPARENTBUILDINGS: ToggleTransparency(TO_HOUSES); break;
379  case OME_SHOW_STATIONSIGNS: ToggleTransparency(TO_SIGNS); break;
380  }
382  return CBF_NONE;
383 }
384 
389  SLEME_SAVE_SCENARIO = 0,
390  SLEME_LOAD_SCENARIO,
391  SLEME_SAVE_HEIGHTMAP,
392  SLEME_LOAD_HEIGHTMAP,
393  SLEME_EXIT_TOINTRO,
394  SLEME_EXIT_GAME = 6,
395  SLEME_MENUCOUNT,
396 };
397 
402  SLNME_SAVE_GAME = 0,
403  SLNME_LOAD_GAME,
404  SLNME_EXIT_TOINTRO,
405  SLNME_EXIT_GAME = 4,
406  SLNME_MENUCOUNT,
407 };
408 
416 {
417  PopupMainToolbMenu(w, WID_TN_SAVE, STR_FILE_MENU_SAVE_GAME, SLNME_MENUCOUNT);
418  return CBF_NONE;
419 }
420 
428 {
429  PopupMainToolbMenu(w, WID_TE_SAVE, STR_SCENEDIT_FILE_MENU_SAVE_SCENARIO, SLEME_MENUCOUNT);
430  return CBF_NONE;
431 }
432 
439 static CallBackFunction MenuClickSaveLoad(int index = 0)
440 {
441  if (_game_mode == GM_EDITOR) {
442  switch (index) {
443  case SLEME_SAVE_SCENARIO: ShowSaveLoadDialog(FT_SCENARIO, SLO_SAVE); break;
444  case SLEME_LOAD_SCENARIO: ShowSaveLoadDialog(FT_SCENARIO, SLO_LOAD); break;
445  case SLEME_SAVE_HEIGHTMAP: ShowSaveLoadDialog(FT_HEIGHTMAP,SLO_SAVE); break;
446  case SLEME_LOAD_HEIGHTMAP: ShowSaveLoadDialog(FT_HEIGHTMAP,SLO_LOAD); break;
447  case SLEME_EXIT_TOINTRO: AskExitToGameMenu(); break;
448  case SLEME_EXIT_GAME: HandleExitGameRequest(); break;
449  }
450  } else {
451  switch (index) {
452  case SLNME_SAVE_GAME: ShowSaveLoadDialog(FT_SAVEGAME, SLO_SAVE); break;
453  case SLNME_LOAD_GAME: ShowSaveLoadDialog(FT_SAVEGAME, SLO_LOAD); break;
454  case SLNME_EXIT_TOINTRO: AskExitToGameMenu(); break;
455  case SLNME_EXIT_GAME: HandleExitGameRequest(); break;
456  }
457  }
458  return CBF_NONE;
459 }
460 
461 /* --- Map button menu --- */
462 
463 enum MapMenuEntries {
464  MME_SHOW_SMALLMAP = 0,
465  MME_SHOW_EXTRAVIEWPORTS,
466  MME_SHOW_LINKGRAPH,
467  MME_SHOW_SIGNLISTS,
468  MME_SHOW_TOWNDIRECTORY,
469  MME_SHOW_INDUSTRYDIRECTORY,
470 };
471 
472 static CallBackFunction ToolbarMapClick(Window *w)
473 {
474  DropDownList *list = new DropDownList();
475  *list->Append() = new DropDownListStringItem(STR_MAP_MENU_MAP_OF_WORLD, MME_SHOW_SMALLMAP, false);
476  *list->Append() = new DropDownListStringItem(STR_MAP_MENU_EXTRA_VIEW_PORT, MME_SHOW_EXTRAVIEWPORTS, false);
477  *list->Append() = new DropDownListStringItem(STR_MAP_MENU_LINGRAPH_LEGEND, MME_SHOW_LINKGRAPH, false);
478  *list->Append() = new DropDownListStringItem(STR_MAP_MENU_SIGN_LIST, MME_SHOW_SIGNLISTS, false);
480  return CBF_NONE;
481 }
482 
483 static CallBackFunction ToolbarScenMapTownDir(Window *w)
484 {
485  DropDownList *list = new DropDownList();
486  *list->Append() = new DropDownListStringItem(STR_MAP_MENU_MAP_OF_WORLD, MME_SHOW_SMALLMAP, false);
487  *list->Append() = new DropDownListStringItem(STR_MAP_MENU_EXTRA_VIEW_PORT, MME_SHOW_EXTRAVIEWPORTS, false);
488  *list->Append() = new DropDownListStringItem(STR_MAP_MENU_SIGN_LIST, MME_SHOW_SIGNLISTS, false);
489  *list->Append() = new DropDownListStringItem(STR_TOWN_MENU_TOWN_DIRECTORY, MME_SHOW_TOWNDIRECTORY, false);
490  *list->Append() = new DropDownListStringItem(STR_INDUSTRY_MENU_INDUSTRY_DIRECTORY, MME_SHOW_INDUSTRYDIRECTORY, false);
492  return CBF_NONE;
493 }
494 
502 {
503  switch (index) {
504  case MME_SHOW_SMALLMAP: ShowSmallMap(); break;
505  case MME_SHOW_EXTRAVIEWPORTS: ShowExtraViewPortWindow(); break;
506  case MME_SHOW_LINKGRAPH: ShowLinkGraphLegend(); break;
507  case MME_SHOW_SIGNLISTS: ShowSignList(); break;
508  case MME_SHOW_TOWNDIRECTORY: ShowTownDirectory(); break;
509  case MME_SHOW_INDUSTRYDIRECTORY: ShowIndustryDirectory(); break;
510  }
511  return CBF_NONE;
512 }
513 
514 /* --- Town button menu --- */
515 
516 static CallBackFunction ToolbarTownClick(Window *w)
517 {
518  PopupMainToolbMenu(w, WID_TN_TOWNS, STR_TOWN_MENU_TOWN_DIRECTORY, (_settings_game.economy.found_town == TF_FORBIDDEN) ? 1 : 2);
519  return CBF_NONE;
520 }
521 
529 {
530  switch (index) {
531  case 0: ShowTownDirectory(); break;
532  case 1: // setting could be changed when the dropdown was open
533  if (_settings_game.economy.found_town != TF_FORBIDDEN) ShowFoundTownWindow();
534  break;
535  }
536  return CBF_NONE;
537 }
538 
539 /* --- Subidies button menu --- */
540 
541 static CallBackFunction ToolbarSubsidiesClick(Window *w)
542 {
543  PopupMainToolbMenu(w, WID_TN_SUBSIDIES, STR_SUBSIDIES_MENU_SUBSIDIES, 1);
544  return CBF_NONE;
545 }
546 
554 {
555  switch (index) {
556  case 0: ShowSubsidiesList(); break;
557  }
558  return CBF_NONE;
559 }
560 
561 /* --- Stations button menu --- */
562 
563 static CallBackFunction ToolbarStationsClick(Window *w)
564 {
566  return CBF_NONE;
567 }
568 
576 {
578  return CBF_NONE;
579 }
580 
581 /* --- Finances button menu --- */
582 
583 static CallBackFunction ToolbarFinancesClick(Window *w)
584 {
586  return CBF_NONE;
587 }
588 
596 {
598  return CBF_NONE;
599 }
600 
601 /* --- Company's button menu --- */
602 
603 static CallBackFunction ToolbarCompaniesClick(Window *w)
604 {
606  return CBF_NONE;
607 }
608 
616 {
617 #ifdef ENABLE_NETWORK
618  if (_networking) {
619  switch (index) {
620  case CTMN_CLIENT_LIST:
621  ShowClientList();
622  return CBF_NONE;
623 
624  case CTMN_NEW_COMPANY:
625  if (_network_server) {
627  } else {
629  }
630  return CBF_NONE;
631 
632  case CTMN_SPECTATE:
633  if (_network_server) {
636  } else {
638  }
639  return CBF_NONE;
640  }
641  }
642 #endif /* ENABLE_NETWORK */
643  ShowCompany((CompanyID)index);
644  return CBF_NONE;
645 }
646 
647 /* --- Story button menu --- */
648 
649 static CallBackFunction ToolbarStoryClick(Window *w)
650 {
652  return CBF_NONE;
653 }
654 
662 {
664  return CBF_NONE;
665 }
666 
667 /* --- Goal button menu --- */
668 
669 static CallBackFunction ToolbarGoalClick(Window *w)
670 {
672  return CBF_NONE;
673 }
674 
682 {
684  return CBF_NONE;
685 }
686 
687 /* --- Graphs button menu --- */
688 
689 static CallBackFunction ToolbarGraphsClick(Window *w)
690 {
691  PopupMainToolbMenu(w, WID_TN_GRAPHS, STR_GRAPH_MENU_OPERATING_PROFIT_GRAPH, (_toolbar_mode == TB_NORMAL) ? 6 : 8);
692  return CBF_NONE;
693 }
694 
702 {
703  switch (index) {
704  case 0: ShowOperatingProfitGraph(); break;
705  case 1: ShowIncomeGraph(); break;
706  case 2: ShowDeliveredCargoGraph(); break;
707  case 3: ShowPerformanceHistoryGraph(); break;
708  case 4: ShowCompanyValueGraph(); break;
709  case 5: ShowCargoPaymentRates(); break;
710  /* functions for combined graphs/league button */
711  case 6: ShowCompanyLeagueTable(); break;
712  case 7: ShowPerformanceRatingDetail(); break;
713  }
714  return CBF_NONE;
715 }
716 
717 /* --- League button menu --- */
718 
719 static CallBackFunction ToolbarLeagueClick(Window *w)
720 {
721  PopupMainToolbMenu(w, WID_TN_LEAGUE, STR_GRAPH_MENU_COMPANY_LEAGUE_TABLE, _networking ? 2 : 3);
722  return CBF_NONE;
723 }
724 
732 {
733  switch (index) {
734  case 0: ShowCompanyLeagueTable(); break;
735  case 1: ShowPerformanceRatingDetail(); break;
736  case 2: ShowHighscoreTable(); break;
737  }
738  return CBF_NONE;
739 }
740 
741 /* --- Industries button menu --- */
742 
743 static CallBackFunction ToolbarIndustryClick(Window *w)
744 {
745  /* Disable build-industry menu if we are a spectator */
746  PopupMainToolbMenu(w, WID_TN_INDUSTRIES, STR_INDUSTRY_MENU_INDUSTRY_DIRECTORY, (_local_company == COMPANY_SPECTATOR) ? 2 : 3);
747  return CBF_NONE;
748 }
749 
757 {
758  switch (index) {
759  case 0: ShowIndustryDirectory(); break;
760  case 1: ShowIndustryCargoesWindow(); break;
761  case 2: ShowBuildIndustryWindow(); break;
762  }
763  return CBF_NONE;
764 }
765 
766 /* --- Trains button menu + 1 helper function for all vehicles. --- */
767 
768 static void ToolbarVehicleClick(Window *w, VehicleType veh)
769 {
770  const Vehicle *v;
771  int dis = ~0;
772 
773  FOR_ALL_VEHICLES(v) {
774  if (v->type == veh && v->IsPrimaryVehicle()) ClrBit(dis, v->owner);
775  }
777 }
778 
779 
780 static CallBackFunction ToolbarTrainClick(Window *w)
781 {
782  ToolbarVehicleClick(w, VEH_TRAIN);
783  return CBF_NONE;
784 }
785 
793 {
794  ShowVehicleListWindow((CompanyID)index, VEH_TRAIN);
795  return CBF_NONE;
796 }
797 
798 /* --- Road vehicle button menu --- */
799 
800 static CallBackFunction ToolbarRoadClick(Window *w)
801 {
802  ToolbarVehicleClick(w, VEH_ROAD);
803  return CBF_NONE;
804 }
805 
813 {
814  ShowVehicleListWindow((CompanyID)index, VEH_ROAD);
815  return CBF_NONE;
816 }
817 
818 /* --- Ship button menu --- */
819 
820 static CallBackFunction ToolbarShipClick(Window *w)
821 {
822  ToolbarVehicleClick(w, VEH_SHIP);
823  return CBF_NONE;
824 }
825 
833 {
834  ShowVehicleListWindow((CompanyID)index, VEH_SHIP);
835  return CBF_NONE;
836 }
837 
838 /* --- Aircraft button menu --- */
839 
840 static CallBackFunction ToolbarAirClick(Window *w)
841 {
842  ToolbarVehicleClick(w, VEH_AIRCRAFT);
843  return CBF_NONE;
844 }
845 
853 {
854  ShowVehicleListWindow((CompanyID)index, VEH_AIRCRAFT);
855  return CBF_NONE;
856 }
857 
858 /* --- Zoom in button --- */
859 
860 static CallBackFunction ToolbarZoomInClick(Window *w)
861 {
863  w->HandleButtonClick((_game_mode == GM_EDITOR) ? (byte)WID_TE_ZOOM_IN : (byte)WID_TN_ZOOM_IN);
864  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
865  }
866  return CBF_NONE;
867 }
868 
869 /* --- Zoom out button --- */
870 
871 static CallBackFunction ToolbarZoomOutClick(Window *w)
872 {
874  w->HandleButtonClick((_game_mode == GM_EDITOR) ? (byte)WID_TE_ZOOM_OUT : (byte)WID_TN_ZOOM_OUT);
875  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
876  }
877  return CBF_NONE;
878 }
879 
880 /* --- Rail button menu --- */
881 
882 static CallBackFunction ToolbarBuildRailClick(Window *w)
883 {
884  ShowDropDownList(w, GetRailTypeDropDownList(), _last_built_railtype, WID_TN_RAILS, 140, true, true);
885  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
886  return CBF_NONE;
887 }
888 
896 {
897  _last_built_railtype = (RailType)index;
898  ShowBuildRailToolbar(_last_built_railtype);
899  return CBF_NONE;
900 }
901 
902 /* --- Road button menu --- */
903 
904 static CallBackFunction ToolbarBuildRoadClick(Window *w)
905 {
906  const Company *c = Company::Get(_local_company);
907  DropDownList *list = new DropDownList();
908 
909  /* Road is always visible and available. */
910  *list->Append() = new DropDownListStringItem(STR_ROAD_MENU_ROAD_CONSTRUCTION, ROADTYPE_ROAD, false);
911 
912  /* Tram is only visible when there will be a tram, and available when that has been introduced. */
913  Engine *e;
914  FOR_ALL_ENGINES_OF_TYPE(e, VEH_ROAD) {
915  if (!HasBit(e->info.climates, _settings_game.game_creation.landscape)) continue;
916  if (!HasBit(e->info.misc_flags, EF_ROAD_TRAM)) continue;
917 
918  *list->Append() = new DropDownListStringItem(STR_ROAD_MENU_TRAM_CONSTRUCTION, ROADTYPE_TRAM, !HasBit(c->avail_roadtypes, ROADTYPE_TRAM));
919  break;
920  }
921  ShowDropDownList(w, list, _last_built_roadtype, WID_TN_ROADS, 140, true, true);
922  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
923  return CBF_NONE;
924 }
925 
933 {
934  _last_built_roadtype = (RoadType)index;
935  ShowBuildRoadToolbar(_last_built_roadtype);
936  return CBF_NONE;
937 }
938 
939 /* --- Water button menu --- */
940 
941 static CallBackFunction ToolbarBuildWaterClick(Window *w)
942 {
943  PopupMainToolbMenu(w, WID_TN_WATER, STR_WATERWAYS_MENU_WATERWAYS_CONSTRUCTION, 1);
944  return CBF_NONE;
945 }
946 
954 {
956  return CBF_NONE;
957 }
958 
959 /* --- Airport button menu --- */
960 
961 static CallBackFunction ToolbarBuildAirClick(Window *w)
962 {
963  PopupMainToolbMenu(w, WID_TN_AIR, STR_AIRCRAFT_MENU_AIRPORT_CONSTRUCTION, 1);
964  return CBF_NONE;
965 }
966 
974 {
976  return CBF_NONE;
977 }
978 
979 /* --- Forest button menu --- */
980 
981 static CallBackFunction ToolbarForestClick(Window *w)
982 {
983  PopupMainToolbMenu(w, WID_TN_LANDSCAPE, STR_LANDSCAPING_MENU_LANDSCAPING, 3);
984  return CBF_NONE;
985 }
986 
994 {
995  switch (index) {
996  case 0: ShowTerraformToolbar(); break;
997  case 1: ShowBuildTreesToolbar(); break;
998  case 2: return SelectSignTool();
999  }
1000  return CBF_NONE;
1001 }
1002 
1003 /* --- Music button menu --- */
1004 
1005 static CallBackFunction ToolbarMusicClick(Window *w)
1006 {
1007  PopupMainToolbMenu(w, WID_TN_MUSIC_SOUND, STR_TOOLBAR_SOUND_MUSIC, 1);
1008  return CBF_NONE;
1009 }
1010 
1018 {
1019  ShowMusicWindow();
1020  return CBF_NONE;
1021 }
1022 
1023 /* --- Newspaper button menu --- */
1024 
1025 static CallBackFunction ToolbarNewspaperClick(Window *w)
1026 {
1027  PopupMainToolbMenu(w, WID_TN_MESSAGES, STR_NEWS_MENU_LAST_MESSAGE_NEWS_REPORT, 3);
1028  return CBF_NONE;
1029 }
1030 
1038 {
1039  switch (index) {
1040  case 0: ShowLastNewsMessage(); break;
1041  case 1: ShowMessageHistory(); break;
1042  case 2: DeleteAllMessages(); break;
1043  }
1044  return CBF_NONE;
1045 }
1046 
1047 /* --- Help button menu --- */
1048 
1049 static CallBackFunction PlaceLandBlockInfo()
1050 {
1051  if (_last_started_action == CBF_PLACE_LANDINFO) {
1053  return CBF_NONE;
1054  } else {
1055  SetObjectToPlace(SPR_CURSOR_QUERY, PAL_NONE, HT_RECT, WC_MAIN_TOOLBAR, 0);
1056  return CBF_PLACE_LANDINFO;
1057  }
1058 }
1059 
1060 static CallBackFunction ToolbarHelpClick(Window *w)
1061 {
1062  PopupMainToolbMenu(w, WID_TN_HELP, STR_ABOUT_MENU_LAND_BLOCK_INFO, _settings_client.gui.newgrf_developer_tools ? 13 : 10);
1063  return CBF_NONE;
1064 }
1065 
1066 static void MenuClickSmallScreenshot()
1067 {
1068  MakeScreenshot(SC_VIEWPORT, NULL);
1069 }
1070 
1076 static void ScreenshotConfirmCallback(Window *w, bool confirmed)
1077 {
1078  if (confirmed) MakeScreenshot(_confirmed_screenshot_type, NULL);
1079 }
1080 
1087 {
1088  ViewPort vp;
1089  SetupScreenshotViewport(t, &vp);
1090  if ((uint64)vp.width * (uint64)vp.height > 8192 * 8192) {
1091  /* Ask for confirmation */
1092  SetDParam(0, vp.width);
1093  SetDParam(1, vp.height);
1095  ShowQuery(STR_WARNING_SCREENSHOT_SIZE_CAPTION, STR_WARNING_SCREENSHOT_SIZE_MESSAGE, NULL, ScreenshotConfirmCallback);
1096  } else {
1097  /* Less than 64M pixels, just do it */
1098  MakeScreenshot(t, NULL);
1099  }
1100 }
1101 
1110 {
1111  extern bool _draw_bounding_boxes;
1112  /* Always allow to toggle them off */
1113  if (_settings_client.gui.newgrf_developer_tools || _draw_bounding_boxes) {
1114  _draw_bounding_boxes = !_draw_bounding_boxes;
1116  }
1117 }
1118 
1127 {
1128  extern bool _draw_dirty_blocks;
1129  /* Always allow to toggle them off */
1130  if (_settings_client.gui.newgrf_developer_tools || _draw_dirty_blocks) {
1131  _draw_dirty_blocks = !_draw_dirty_blocks;
1133  }
1134 }
1135 
1141 {
1144  /* If you open a savegame as scenario there may already be link graphs.*/
1146  SetDate(new_date, 0);
1147 }
1148 
1155 {
1156  switch (index) {
1157  case 0: return PlaceLandBlockInfo();
1158  case 2: IConsoleSwitch(); break;
1159  case 3: ShowAIDebugWindow(); break;
1160  case 4: MenuClickSmallScreenshot(); break;
1163  case 7: MenuClickLargeWorldScreenshot(SC_WORLD); break;
1164  case 8: ShowFramerateWindow(); break;
1165  case 9: ShowAboutWindow(); break;
1166  case 10: ShowSpriteAlignerWindow(); break;
1167  case 11: ToggleBoundingBoxes(); break;
1168  case 12: ToggleDirtyBlocks(); break;
1169  }
1170  return CBF_NONE;
1171 }
1172 
1173 /* --- Switch toolbar button --- */
1174 
1175 static CallBackFunction ToolbarSwitchClick(Window *w)
1176 {
1177  if (_toolbar_mode != TB_LOWER) {
1178  _toolbar_mode = TB_LOWER;
1179  } else {
1180  _toolbar_mode = TB_UPPER;
1181  }
1182 
1183  w->ReInit();
1184  w->SetWidgetLoweredState(WID_TN_SWITCH_BAR, _toolbar_mode == TB_LOWER);
1185  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
1186  return CBF_NONE;
1187 }
1188 
1189 /* --- Scenario editor specific handlers. */
1190 
1195 {
1197  ShowQueryString(STR_JUST_INT, STR_MAPGEN_START_DATE_QUERY_CAPT, 8, w, CS_NUMERAL, QSF_ENABLE_DEFAULT);
1198  _left_button_clicked = false;
1199  return CBF_NONE;
1200 }
1201 
1202 static CallBackFunction ToolbarScenDateBackward(Window *w)
1203 {
1204  /* don't allow too fast scrolling */
1205  if (!(w->flags & WF_TIMEOUT) || w->timeout_timer <= 1) {
1207  w->SetDirty();
1208 
1210  }
1211  _left_button_clicked = false;
1212  return CBF_NONE;
1213 }
1214 
1215 static CallBackFunction ToolbarScenDateForward(Window *w)
1216 {
1217  /* don't allow too fast scrolling */
1218  if (!(w->flags & WF_TIMEOUT) || w->timeout_timer <= 1) {
1220  w->SetDirty();
1221 
1223  }
1224  _left_button_clicked = false;
1225  return CBF_NONE;
1226 }
1227 
1228 static CallBackFunction ToolbarScenGenLand(Window *w)
1229 {
1231  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
1232 
1234  return CBF_NONE;
1235 }
1236 
1237 
1238 static CallBackFunction ToolbarScenGenTown(Window *w)
1239 {
1241  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
1242  ShowFoundTownWindow();
1243  return CBF_NONE;
1244 }
1245 
1246 static CallBackFunction ToolbarScenGenIndustry(Window *w)
1247 {
1249  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
1250  ShowBuildIndustryWindow();
1251  return CBF_NONE;
1252 }
1253 
1254 static CallBackFunction ToolbarScenBuildRoad(Window *w)
1255 {
1257  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
1259  return CBF_NONE;
1260 }
1261 
1262 static CallBackFunction ToolbarScenBuildDocks(Window *w)
1263 {
1265  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
1267  return CBF_NONE;
1268 }
1269 
1270 static CallBackFunction ToolbarScenPlantTrees(Window *w)
1271 {
1273  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
1274  ShowBuildTreesToolbar();
1275  return CBF_NONE;
1276 }
1277 
1278 static CallBackFunction ToolbarScenPlaceSign(Window *w)
1279 {
1281  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
1282  return SelectSignTool();
1283 }
1284 
1285 static CallBackFunction ToolbarBtn_NULL(Window *w)
1286 {
1287  return CBF_NONE;
1288 }
1289 
1290 typedef CallBackFunction MenuClickedProc(int index);
1291 
1292 static MenuClickedProc * const _menu_clicked_procs[] = {
1293  NULL, // 0
1294  NULL, // 1
1295  MenuClickSettings, // 2
1296  MenuClickSaveLoad, // 3
1297  MenuClickMap, // 4
1298  MenuClickTown, // 5
1299  MenuClickSubsidies, // 6
1300  MenuClickStations, // 7
1301  MenuClickFinances, // 8
1302  MenuClickCompany, // 9
1303  MenuClickStory, // 10
1304  MenuClickGoal, // 11
1305  MenuClickGraphs, // 12
1306  MenuClickLeague, // 13
1307  MenuClickIndustry, // 14
1308  MenuClickShowTrains, // 15
1309  MenuClickShowRoad, // 16
1310  MenuClickShowShips, // 17
1311  MenuClickShowAir, // 18
1312  MenuClickMap, // 19
1313  NULL, // 20
1314  MenuClickBuildRail, // 21
1315  MenuClickBuildRoad, // 22
1316  MenuClickBuildWater, // 23
1317  MenuClickBuildAir, // 24
1318  MenuClickForest, // 25
1319  MenuClickMusicWindow, // 26
1320  MenuClickNewspaper, // 27
1321  MenuClickHelp, // 28
1322 };
1323 
1326  bool visible[WID_TN_END];
1327 protected:
1328  uint spacers;
1329 
1330 public:
1332  {
1333  }
1334 
1340  bool IsButton(WidgetType type) const
1341  {
1342  return type == WWT_IMGBTN || type == WWT_IMGBTN_2 || type == WWT_PUSHIMGBTN;
1343  }
1344 
1345  void SetupSmallestSize(Window *w, bool init_array)
1346  {
1347  this->smallest_x = 0; // Biggest child
1348  this->smallest_y = 0; // Biggest child
1349  this->fill_x = 1;
1350  this->fill_y = 0;
1351  this->resize_x = 1; // We only resize in this direction
1352  this->resize_y = 0; // We never resize in this direction
1353  this->spacers = 0;
1354 
1355  uint nbuttons = 0;
1356  /* First initialise some variables... */
1357  for (NWidgetBase *child_wid = this->head; child_wid != NULL; child_wid = child_wid->next) {
1358  child_wid->SetupSmallestSize(w, init_array);
1359  this->smallest_y = max(this->smallest_y, child_wid->smallest_y + child_wid->padding_top + child_wid->padding_bottom);
1360  if (this->IsButton(child_wid->type)) {
1361  nbuttons++;
1362  this->smallest_x = max(this->smallest_x, child_wid->smallest_x + child_wid->padding_left + child_wid->padding_right);
1363  } else if (child_wid->type == NWID_SPACER) {
1364  this->spacers++;
1365  }
1366  }
1367 
1368  /* ... then in a second pass make sure the 'current' heights are set. Won't change ever. */
1369  for (NWidgetBase *child_wid = this->head; child_wid != NULL; child_wid = child_wid->next) {
1370  child_wid->current_y = this->smallest_y;
1371  if (!this->IsButton(child_wid->type)) {
1372  child_wid->current_x = child_wid->smallest_x;
1373  }
1374  }
1375  _toolbar_width = nbuttons * this->smallest_x;
1376  }
1377 
1378  void AssignSizePosition(SizingType sizing, uint x, uint y, uint given_width, uint given_height, bool rtl)
1379  {
1380  assert(given_width >= this->smallest_x && given_height >= this->smallest_y);
1381 
1382  this->pos_x = x;
1383  this->pos_y = y;
1384  this->current_x = given_width;
1385  this->current_y = given_height;
1386 
1387  /* Figure out what are the visible buttons */
1388  memset(this->visible, 0, sizeof(this->visible));
1389  uint arrangable_count, button_count, spacer_count;
1390  const byte *arrangement = GetButtonArrangement(given_width, arrangable_count, button_count, spacer_count);
1391  for (uint i = 0; i < arrangable_count; i++) {
1392  this->visible[arrangement[i]] = true;
1393  }
1394 
1395  /* Create us ourselves a quick lookup table */
1396  NWidgetBase *widgets[WID_TN_END];
1397  for (NWidgetBase *child_wid = this->head; child_wid != NULL; child_wid = child_wid->next) {
1398  if (child_wid->type == NWID_SPACER) continue;
1399  widgets[((NWidgetCore*)child_wid)->index] = child_wid;
1400  }
1401 
1402  /* Now assign the widgets to their rightful place */
1403  uint position = 0; // Place to put next child relative to origin of the container.
1404  uint spacer_space = max(0, (int)given_width - (int)(button_count * this->smallest_x)); // Remaining spacing for 'spacer' widgets
1405  uint button_space = given_width - spacer_space; // Remaining spacing for the buttons
1406  uint spacer_i = 0;
1407  uint button_i = 0;
1408 
1409  /* Index into the arrangement indices. The macro lastof cannot be used here! */
1410  const byte *cur_wid = rtl ? &arrangement[arrangable_count - 1] : arrangement;
1411  for (uint i = 0; i < arrangable_count; i++) {
1412  NWidgetBase *child_wid = widgets[*cur_wid];
1413  /* If we have to give space to the spacers, do that */
1414  if (spacer_space != 0) {
1415  NWidgetBase *possible_spacer = rtl ? child_wid->next : child_wid->prev;
1416  if (possible_spacer != NULL && possible_spacer->type == NWID_SPACER) {
1417  uint add = spacer_space / (spacer_count - spacer_i);
1418  position += add;
1419  spacer_space -= add;
1420  spacer_i++;
1421  }
1422  }
1423 
1424  /* Buttons can be scaled, the others not. */
1425  if (this->IsButton(child_wid->type)) {
1426  child_wid->current_x = button_space / (button_count - button_i);
1427  button_space -= child_wid->current_x;
1428  button_i++;
1429  }
1430  child_wid->AssignSizePosition(sizing, x + position, y, child_wid->current_x, this->current_y, rtl);
1431  position += child_wid->current_x;
1432 
1433  if (rtl) {
1434  cur_wid--;
1435  } else {
1436  cur_wid++;
1437  }
1438  }
1439  }
1440 
1441  /* virtual */ void Draw(const Window *w)
1442  {
1443  /* Draw brown-red toolbar bg. */
1444  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);
1445  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);
1446 
1447  bool rtl = _current_text_dir == TD_RTL;
1448  for (NWidgetBase *child_wid = rtl ? this->tail : this->head; child_wid != NULL; child_wid = rtl ? child_wid->prev : child_wid->next) {
1449  if (child_wid->type == NWID_SPACER) continue;
1450  if (!this->visible[((NWidgetCore*)child_wid)->index]) continue;
1451 
1452  child_wid->Draw(w);
1453  }
1454  }
1455 
1456  /* virtual */ NWidgetCore *GetWidgetFromPos(int x, int y)
1457  {
1458  if (!IsInsideBS(x, this->pos_x, this->current_x) || !IsInsideBS(y, this->pos_y, this->current_y)) return NULL;
1459 
1460  for (NWidgetBase *child_wid = this->head; child_wid != NULL; child_wid = child_wid->next) {
1461  if (child_wid->type == NWID_SPACER) continue;
1462  if (!this->visible[((NWidgetCore*)child_wid)->index]) continue;
1463 
1464  NWidgetCore *nwid = child_wid->GetWidgetFromPos(x, y);
1465  if (nwid != NULL) return nwid;
1466  }
1467  return NULL;
1468  }
1469 
1478  virtual const byte *GetButtonArrangement(uint &width, uint &arrangable_count, uint &button_count, uint &spacer_count) const = 0;
1479 };
1480 
1483  /* virtual */ const byte *GetButtonArrangement(uint &width, uint &arrangable_count, uint &button_count, uint &spacer_count) const
1484  {
1485  static const uint SMALLEST_ARRANGEMENT = 14;
1486  static const uint BIGGEST_ARRANGEMENT = 20;
1487 
1488  /* The number of buttons of each row of the toolbar should match the number of items which we want to be visible.
1489  * The total number of buttons should be equal to arrangable_count * 2.
1490  * No bad things happen, but we could see strange behaviours if we have buttons < (arrangable_count * 2) like a
1491  * pause button appearing on the right of the lower toolbar and weird resizing of the widgets even if there is
1492  * enough space.
1493  */
1494  static const byte arrange14[] = {
1495  WID_TN_PAUSE,
1497  WID_TN_TRAINS,
1499  WID_TN_SHIPS,
1503  WID_TN_RAILS,
1504  WID_TN_ROADS,
1505  WID_TN_WATER,
1506  WID_TN_AIR,
1509  // lower toolbar
1511  WID_TN_SAVE,
1513  WID_TN_TOWNS,
1518  WID_TN_GRAPHS,
1522  WID_TN_HELP,
1524  };
1525  static const byte arrange15[] = {
1526  WID_TN_PAUSE,
1529  WID_TN_TRAINS,
1531  WID_TN_SHIPS,
1533  WID_TN_RAILS,
1534  WID_TN_ROADS,
1535  WID_TN_WATER,
1536  WID_TN_AIR,
1541  // lower toolbar
1542  WID_TN_PAUSE,
1545  WID_TN_SAVE,
1546  WID_TN_TOWNS,
1551  WID_TN_GRAPHS,
1555  WID_TN_HELP,
1557  };
1558  static const byte arrange16[] = {
1559  WID_TN_PAUSE,
1563  WID_TN_TRAINS,
1565  WID_TN_SHIPS,
1567  WID_TN_RAILS,
1568  WID_TN_ROADS,
1569  WID_TN_WATER,
1570  WID_TN_AIR,
1575  // lower toolbar
1576  WID_TN_PAUSE,
1578  WID_TN_SAVE,
1579  WID_TN_TOWNS,
1584  WID_TN_GRAPHS,
1588  WID_TN_HELP,
1592  };
1593  static const byte arrange17[] = {
1594  WID_TN_PAUSE,
1599  WID_TN_TRAINS,
1601  WID_TN_SHIPS,
1603  WID_TN_RAILS,
1604  WID_TN_ROADS,
1605  WID_TN_WATER,
1606  WID_TN_AIR,
1611  // lower toolbar
1612  WID_TN_PAUSE,
1614  WID_TN_SAVE,
1617  WID_TN_TOWNS,
1621  WID_TN_GRAPHS,
1625  WID_TN_HELP,
1629  };
1630  static const byte arrange18[] = {
1631  WID_TN_PAUSE,
1635  WID_TN_TOWNS,
1641  WID_TN_RAILS,
1642  WID_TN_ROADS,
1643  WID_TN_WATER,
1644  WID_TN_AIR,
1649  // lower toolbar
1650  WID_TN_PAUSE,
1652  WID_TN_SAVE,
1654  WID_TN_TOWNS,
1657  WID_TN_GRAPHS,
1658  WID_TN_TRAINS,
1660  WID_TN_SHIPS,
1664  WID_TN_HELP,
1668  };
1669  static const byte arrange19[] = {
1670  WID_TN_PAUSE,
1674  WID_TN_TOWNS,
1676  WID_TN_TRAINS,
1678  WID_TN_SHIPS,
1680  WID_TN_RAILS,
1681  WID_TN_ROADS,
1682  WID_TN_WATER,
1683  WID_TN_AIR,
1689  // lower toolbar
1690  WID_TN_PAUSE,
1692  WID_TN_SAVE,
1697  WID_TN_GRAPHS,
1700  WID_TN_RAILS,
1701  WID_TN_ROADS,
1702  WID_TN_WATER,
1703  WID_TN_AIR,
1705  WID_TN_HELP,
1709  };
1710  static const byte arrange20[] = {
1711  WID_TN_PAUSE,
1715  WID_TN_TOWNS,
1717  WID_TN_TRAINS,
1719  WID_TN_SHIPS,
1721  WID_TN_RAILS,
1722  WID_TN_ROADS,
1723  WID_TN_WATER,
1724  WID_TN_AIR,
1727  WID_TN_GOAL,
1731  // lower toolbar
1732  WID_TN_PAUSE,
1734  WID_TN_SAVE,
1739  WID_TN_GRAPHS,
1742  WID_TN_RAILS,
1743  WID_TN_ROADS,
1744  WID_TN_WATER,
1745  WID_TN_AIR,
1747  WID_TN_STORY,
1748  WID_TN_HELP,
1752  };
1753  static const byte arrange_all[] = {
1754  WID_TN_PAUSE,
1757  WID_TN_SAVE,
1759  WID_TN_TOWNS,
1764  WID_TN_STORY,
1765  WID_TN_GOAL,
1766  WID_TN_GRAPHS,
1767  WID_TN_LEAGUE,
1769  WID_TN_TRAINS,
1771  WID_TN_SHIPS,
1775  WID_TN_RAILS,
1776  WID_TN_ROADS,
1777  WID_TN_WATER,
1778  WID_TN_AIR,
1782  WID_TN_HELP
1783  };
1784 
1785  /* If at least BIGGEST_ARRANGEMENT fit, just spread all the buttons nicely */
1786  uint full_buttons = max(CeilDiv(width, this->smallest_x), SMALLEST_ARRANGEMENT);
1787  if (full_buttons > BIGGEST_ARRANGEMENT) {
1788  button_count = arrangable_count = lengthof(arrange_all);
1789  spacer_count = this->spacers;
1790  return arrange_all;
1791  }
1792 
1793  /* Introduce the split toolbar */
1794  static const byte * const arrangements[] = { arrange14, arrange15, arrange16, arrange17, arrange18, arrange19, arrange20 };
1795 
1796  button_count = arrangable_count = full_buttons;
1797  spacer_count = this->spacers;
1798  return arrangements[full_buttons - SMALLEST_ARRANGEMENT] + ((_toolbar_mode == TB_LOWER) ? full_buttons : 0);
1799  }
1800 };
1801 
1804  uint panel_widths[2];
1805 
1806  void SetupSmallestSize(Window *w, bool init_array)
1807  {
1808  this->NWidgetToolbarContainer::SetupSmallestSize(w, init_array);
1809 
1810  /* Find the size of panel_widths */
1811  uint i = 0;
1812  for (NWidgetBase *child_wid = this->head; child_wid != NULL; child_wid = child_wid->next) {
1813  if (child_wid->type == NWID_SPACER || this->IsButton(child_wid->type)) continue;
1814 
1815  assert(i < lengthof(this->panel_widths));
1816  this->panel_widths[i++] = child_wid->current_x;
1817  _toolbar_width += child_wid->current_x;
1818  }
1819  }
1820 
1821  /* virtual */ const byte *GetButtonArrangement(uint &width, uint &arrangable_count, uint &button_count, uint &spacer_count) const
1822  {
1823  static const byte arrange_all[] = {
1824  WID_TE_PAUSE,
1827  WID_TE_SAVE,
1828  WID_TE_SPACER,
1836  WID_TE_ROADS,
1837  WID_TE_WATER,
1838  WID_TE_TREES,
1839  WID_TE_SIGNS,
1841  WID_TE_HELP,
1842  };
1843  static const byte arrange_nopanel[] = {
1844  WID_TE_PAUSE,
1847  WID_TE_SAVE,
1855  WID_TE_ROADS,
1856  WID_TE_WATER,
1857  WID_TE_TREES,
1858  WID_TE_SIGNS,
1860  WID_TE_HELP,
1861  };
1862  static const byte arrange_switch[] = {
1868  WID_TE_ROADS,
1869  WID_TE_WATER,
1870  WID_TE_TREES,
1871  WID_TE_SIGNS,
1873  // lower toolbar
1874  WID_TE_PAUSE,
1877  WID_TE_SAVE,
1883  };
1884 
1885  /* If we can place all buttons *and* the panels, show them. */
1886  uint min_full_width = (lengthof(arrange_all) - lengthof(this->panel_widths)) * this->smallest_x + this->panel_widths[0] + this->panel_widths[1];
1887  if (width >= min_full_width) {
1888  width -= this->panel_widths[0] + this->panel_widths[1];
1889  arrangable_count = lengthof(arrange_all);
1890  button_count = arrangable_count - 2;
1891  spacer_count = this->spacers;
1892  return arrange_all;
1893  }
1894 
1895  /* 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 */
1896  uint min_small_width = (lengthof(arrange_switch) - lengthof(this->panel_widths)) * this->smallest_x / 2 + this->panel_widths[1];
1897  if (width > min_small_width) {
1898  width -= this->panel_widths[1];
1899  arrangable_count = lengthof(arrange_nopanel);
1900  button_count = arrangable_count - 1;
1901  spacer_count = this->spacers - 1;
1902  return arrange_nopanel;
1903  }
1904 
1905  /* Split toolbar */
1906  width -= this->panel_widths[1];
1907  arrangable_count = lengthof(arrange_switch) / 2;
1908  button_count = arrangable_count - 1;
1909  spacer_count = 0;
1910  return arrange_switch + ((_toolbar_mode == TB_LOWER) ? arrangable_count : 0);
1911  }
1912 };
1913 
1914 /* --- Toolbar handling for the 'normal' case */
1915 
1916 typedef CallBackFunction ToolbarButtonProc(Window *w);
1917 
1918 static ToolbarButtonProc * const _toolbar_button_procs[] = {
1919  ToolbarPauseClick,
1923  ToolbarMapClick,
1924  ToolbarTownClick,
1925  ToolbarSubsidiesClick,
1926  ToolbarStationsClick,
1927  ToolbarFinancesClick,
1928  ToolbarCompaniesClick,
1929  ToolbarStoryClick,
1930  ToolbarGoalClick,
1931  ToolbarGraphsClick,
1932  ToolbarLeagueClick,
1933  ToolbarIndustryClick,
1934  ToolbarTrainClick,
1935  ToolbarRoadClick,
1936  ToolbarShipClick,
1937  ToolbarAirClick,
1938  ToolbarZoomInClick,
1939  ToolbarZoomOutClick,
1940  ToolbarBuildRailClick,
1941  ToolbarBuildRoadClick,
1942  ToolbarBuildWaterClick,
1943  ToolbarBuildAirClick,
1944  ToolbarForestClick,
1945  ToolbarMusicClick,
1946  ToolbarNewspaperClick,
1947  ToolbarHelpClick,
1948  ToolbarSwitchClick,
1949 };
1950 
1951 enum MainToolbarHotkeys {
1952  MTHK_PAUSE,
1953  MTHK_FASTFORWARD,
1954  MTHK_SETTINGS,
1955  MTHK_SAVEGAME,
1956  MTHK_LOADGAME,
1957  MTHK_SMALLMAP,
1958  MTHK_TOWNDIRECTORY,
1959  MTHK_SUBSIDIES,
1960  MTHK_STATIONS,
1961  MTHK_FINANCES,
1962  MTHK_COMPANIES,
1963  MTHK_STORY,
1964  MTHK_GOAL,
1965  MTHK_GRAPHS,
1966  MTHK_LEAGUE,
1967  MTHK_INDUSTRIES,
1968  MTHK_TRAIN_LIST,
1969  MTHK_ROADVEH_LIST,
1970  MTHK_SHIP_LIST,
1971  MTHK_AIRCRAFT_LIST,
1972  MTHK_ZOOM_IN,
1973  MTHK_ZOOM_OUT,
1974  MTHK_BUILD_RAIL,
1975  MTHK_BUILD_ROAD,
1976  MTHK_BUILD_DOCKS,
1977  MTHK_BUILD_AIRPORT,
1978  MTHK_BUILD_TREES,
1979  MTHK_MUSIC,
1980  MTHK_AI_DEBUG,
1981  MTHK_SMALL_SCREENSHOT,
1982  MTHK_ZOOMEDIN_SCREENSHOT,
1983  MTHK_DEFAULTZOOM_SCREENSHOT,
1984  MTHK_GIANT_SCREENSHOT,
1985  MTHK_CHEATS,
1986  MTHK_TERRAFORM,
1987  MTHK_EXTRA_VIEWPORT,
1988  MTHK_CLIENT_LIST,
1989  MTHK_SIGN_LIST,
1990 };
1991 
1994  GUITimer timer;
1995 
1996  MainToolbarWindow(WindowDesc *desc) : Window(desc)
1997  {
1998  this->InitNested(0);
1999 
2000  _last_started_action = CBF_NONE;
2001  CLRBITS(this->flags, WF_WHITE_BORDER);
2002  this->SetWidgetDisabledState(WID_TN_PAUSE, _networking && !_network_server); // if not server, disable pause button
2003  this->SetWidgetDisabledState(WID_TN_FAST_FORWARD, _networking); // if networking, disable fast-forward button
2004  PositionMainToolbar(this);
2006 
2007  this->timer.SetInterval(MILLISECONDS_PER_TICK);
2008  }
2009 
2010  virtual void FindWindowPlacementAndResize(int def_width, int def_height)
2011  {
2013  }
2014 
2015  virtual void OnPaint()
2016  {
2017  /* If spectator, disable all construction buttons
2018  * ie : Build road, rail, ships, airports and landscaping
2019  * Since enabled state is the default, just disable when needed */
2021  /* disable company list drop downs, if there are no companies */
2023 
2024  this->SetWidgetDisabledState(WID_TN_GOAL, Goal::GetNumItems() == 0);
2025  this->SetWidgetDisabledState(WID_TN_STORY, StoryPage::GetNumItems() == 0);
2026 
2027  this->SetWidgetDisabledState(WID_TN_RAILS, !CanBuildVehicleInfrastructure(VEH_TRAIN));
2028  this->SetWidgetDisabledState(WID_TN_AIR, !CanBuildVehicleInfrastructure(VEH_AIRCRAFT));
2029 
2030  this->DrawWidgets();
2031  }
2032 
2033  virtual void OnClick(Point pt, int widget, int click_count)
2034  {
2035  if (_game_mode != GM_MENU && !this->IsWidgetDisabled(widget)) _toolbar_button_procs[widget](this);
2036  }
2037 
2038  virtual void OnDropdownSelect(int widget, int index)
2039  {
2040  CallBackFunction cbf = _menu_clicked_procs[widget](index);
2041  if (cbf != CBF_NONE) _last_started_action = cbf;
2042  }
2043 
2044  virtual EventState OnHotkey(int hotkey)
2045  {
2046  switch (hotkey) {
2047  case MTHK_PAUSE: ToolbarPauseClick(this); break;
2048  case MTHK_FASTFORWARD: ToolbarFastForwardClick(this); break;
2049  case MTHK_SETTINGS: ShowGameOptions(); break;
2050  case MTHK_SAVEGAME: MenuClickSaveLoad(); break;
2051  case MTHK_LOADGAME: ShowSaveLoadDialog(FT_SAVEGAME, SLO_LOAD); break;
2052  case MTHK_SMALLMAP: ShowSmallMap(); break;
2053  case MTHK_TOWNDIRECTORY: ShowTownDirectory(); break;
2054  case MTHK_SUBSIDIES: ShowSubsidiesList(); break;
2055  case MTHK_STATIONS: ShowCompanyStations(_local_company); break;
2056  case MTHK_FINANCES: ShowCompanyFinances(_local_company); break;
2057  case MTHK_COMPANIES: ShowCompany(_local_company); break;
2058  case MTHK_STORY: ShowStoryBook(_local_company); break;
2059  case MTHK_GOAL: ShowGoalsList(_local_company); break;
2060  case MTHK_GRAPHS: ShowOperatingProfitGraph(); break;
2061  case MTHK_LEAGUE: ShowCompanyLeagueTable(); break;
2062  case MTHK_INDUSTRIES: ShowBuildIndustryWindow(); break;
2063  case MTHK_TRAIN_LIST: ShowVehicleListWindow(_local_company, VEH_TRAIN); break;
2064  case MTHK_ROADVEH_LIST: ShowVehicleListWindow(_local_company, VEH_ROAD); break;
2065  case MTHK_SHIP_LIST: ShowVehicleListWindow(_local_company, VEH_SHIP); break;
2066  case MTHK_AIRCRAFT_LIST: ShowVehicleListWindow(_local_company, VEH_AIRCRAFT); break;
2067  case MTHK_ZOOM_IN: ToolbarZoomInClick(this); break;
2068  case MTHK_ZOOM_OUT: ToolbarZoomOutClick(this); break;
2069  case MTHK_BUILD_RAIL: if (CanBuildVehicleInfrastructure(VEH_TRAIN)) ShowBuildRailToolbar(_last_built_railtype); break;
2070  case MTHK_BUILD_ROAD: ShowBuildRoadToolbar(_last_built_roadtype); break;
2071  case MTHK_BUILD_DOCKS: ShowBuildDocksToolbar(); break;
2072  case MTHK_BUILD_AIRPORT: if (CanBuildVehicleInfrastructure(VEH_AIRCRAFT)) ShowBuildAirToolbar(); break;
2073  case MTHK_BUILD_TREES: ShowBuildTreesToolbar(); break;
2074  case MTHK_MUSIC: ShowMusicWindow(); break;
2075  case MTHK_AI_DEBUG: ShowAIDebugWindow(); break;
2076  case MTHK_SMALL_SCREENSHOT: MenuClickSmallScreenshot(); break;
2077  case MTHK_ZOOMEDIN_SCREENSHOT: MenuClickLargeWorldScreenshot(SC_ZOOMEDIN); break;
2078  case MTHK_DEFAULTZOOM_SCREENSHOT: MenuClickLargeWorldScreenshot(SC_DEFAULTZOOM); break;
2079  case MTHK_GIANT_SCREENSHOT: MenuClickLargeWorldScreenshot(SC_WORLD); break;
2080  case MTHK_CHEATS: if (!_networking) ShowCheatWindow(); break;
2081  case MTHK_TERRAFORM: ShowTerraformToolbar(); break;
2082  case MTHK_EXTRA_VIEWPORT: ShowExtraViewPortWindowForTileUnderCursor(); break;
2083 #ifdef ENABLE_NETWORK
2084  case MTHK_CLIENT_LIST: if (_networking) ShowClientList(); break;
2085 #endif
2086  case MTHK_SIGN_LIST: ShowSignList(); break;
2087  default: return ES_NOT_HANDLED;
2088  }
2089  return ES_HANDLED;
2090  }
2091 
2092  virtual void OnPlaceObject(Point pt, TileIndex tile)
2093  {
2094  switch (_last_started_action) {
2095  case CBF_PLACE_SIGN:
2096  PlaceProc_Sign(tile);
2097  break;
2098 
2099  case CBF_PLACE_LANDINFO:
2100  ShowLandInfo(tile);
2101  break;
2102 
2103  default: NOT_REACHED();
2104  }
2105  }
2106 
2107  virtual void OnPlaceObjectAbort()
2108  {
2109  _last_started_action = CBF_NONE;
2110  }
2111 
2112  virtual void OnRealtimeTick(uint delta_ms)
2113  {
2114  if (!this->timer.Elapsed(delta_ms)) return;
2115  this->timer.SetInterval(MILLISECONDS_PER_TICK);
2116 
2117  if (this->IsWidgetLowered(WID_TN_PAUSE) != !!_pause_mode) {
2118  this->ToggleWidgetLoweredState(WID_TN_PAUSE);
2119  this->SetWidgetDirty(WID_TN_PAUSE);
2120  }
2121 
2122  if (this->IsWidgetLowered(WID_TN_FAST_FORWARD) != !!_fast_forward) {
2123  this->ToggleWidgetLoweredState(WID_TN_FAST_FORWARD);
2124  this->SetWidgetDirty(WID_TN_FAST_FORWARD);
2125  }
2126  }
2127 
2128  virtual void OnTimeout()
2129  {
2130  /* We do not want to automatically raise the pause, fast forward and
2131  * switchbar buttons; they have to stay down when pressed etc. */
2132  for (uint i = WID_TN_SETTINGS; i < WID_TN_SWITCH_BAR; i++) {
2133  if (this->IsWidgetLowered(i)) {
2134  this->RaiseWidget(i);
2135  this->SetWidgetDirty(i);
2136  }
2137  }
2138  }
2139 
2145  virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
2146  {
2147  if (!gui_scope) return;
2149  }
2150 
2151  static HotkeyList hotkeys;
2152 };
2153 
2154 const uint16 _maintoolbar_pause_keys[] = {WKC_F1, WKC_PAUSE, 0};
2155 const uint16 _maintoolbar_zoomin_keys[] = {WKC_NUM_PLUS, WKC_EQUALS, WKC_SHIFT | WKC_EQUALS, WKC_SHIFT | WKC_F5, 0};
2156 const uint16 _maintoolbar_zoomout_keys[] = {WKC_NUM_MINUS, WKC_MINUS, WKC_SHIFT | WKC_MINUS, WKC_SHIFT | WKC_F6, 0};
2157 const uint16 _maintoolbar_smallmap_keys[] = {WKC_F4, 'M', 0};
2158 
2159 static Hotkey maintoolbar_hotkeys[] = {
2160  Hotkey(_maintoolbar_pause_keys, "pause", MTHK_PAUSE),
2161  Hotkey((uint16)0, "fastforward", MTHK_FASTFORWARD),
2162  Hotkey(WKC_F2, "settings", MTHK_SETTINGS),
2163  Hotkey(WKC_F3, "saveload", MTHK_SAVEGAME),
2164  Hotkey((uint16)0, "load_game", MTHK_LOADGAME),
2165  Hotkey(_maintoolbar_smallmap_keys, "smallmap", MTHK_SMALLMAP),
2166  Hotkey(WKC_F5, "town_list", MTHK_TOWNDIRECTORY),
2167  Hotkey(WKC_F6, "subsidies", MTHK_SUBSIDIES),
2168  Hotkey(WKC_F7, "station_list", MTHK_STATIONS),
2169  Hotkey(WKC_F8, "finances", MTHK_FINANCES),
2170  Hotkey(WKC_F9, "companies", MTHK_COMPANIES),
2171  Hotkey((uint16)0, "story_book", MTHK_STORY),
2172  Hotkey((uint16)0, "goal_list", MTHK_GOAL),
2173  Hotkey(WKC_F10, "graphs", MTHK_GRAPHS),
2174  Hotkey(WKC_F11, "league", MTHK_LEAGUE),
2175  Hotkey(WKC_F12, "industry_list", MTHK_INDUSTRIES),
2176  Hotkey(WKC_SHIFT | WKC_F1, "train_list", MTHK_TRAIN_LIST),
2177  Hotkey(WKC_SHIFT | WKC_F2, "roadveh_list", MTHK_ROADVEH_LIST),
2178  Hotkey(WKC_SHIFT | WKC_F3, "ship_list", MTHK_SHIP_LIST),
2179  Hotkey(WKC_SHIFT | WKC_F4, "aircraft_list", MTHK_AIRCRAFT_LIST),
2180  Hotkey(_maintoolbar_zoomin_keys, "zoomin", MTHK_ZOOM_IN),
2181  Hotkey(_maintoolbar_zoomout_keys, "zoomout", MTHK_ZOOM_OUT),
2182  Hotkey(WKC_SHIFT | WKC_F7, "build_rail", MTHK_BUILD_RAIL),
2183  Hotkey(WKC_SHIFT | WKC_F8, "build_road", MTHK_BUILD_ROAD),
2184  Hotkey(WKC_SHIFT | WKC_F9, "build_docks", MTHK_BUILD_DOCKS),
2185  Hotkey(WKC_SHIFT | WKC_F10, "build_airport", MTHK_BUILD_AIRPORT),
2186  Hotkey(WKC_SHIFT | WKC_F11, "build_trees", MTHK_BUILD_TREES),
2187  Hotkey(WKC_SHIFT | WKC_F12, "music", MTHK_MUSIC),
2188  Hotkey((uint16)0, "ai_debug", MTHK_AI_DEBUG),
2189  Hotkey(WKC_CTRL | 'S', "small_screenshot", MTHK_SMALL_SCREENSHOT),
2190  Hotkey(WKC_CTRL | 'P', "zoomedin_screenshot", MTHK_ZOOMEDIN_SCREENSHOT),
2191  Hotkey(WKC_CTRL | 'D', "defaultzoom_screenshot", MTHK_DEFAULTZOOM_SCREENSHOT),
2192  Hotkey((uint16)0, "giant_screenshot", MTHK_GIANT_SCREENSHOT),
2193  Hotkey(WKC_CTRL | WKC_ALT | 'C', "cheats", MTHK_CHEATS),
2194  Hotkey('L', "terraform", MTHK_TERRAFORM),
2195  Hotkey('V', "extra_viewport", MTHK_EXTRA_VIEWPORT),
2196 #ifdef ENABLE_NETWORK
2197  Hotkey((uint16)0, "client_list", MTHK_CLIENT_LIST),
2198 #endif
2199  Hotkey((uint16)0, "sign_list", MTHK_SIGN_LIST),
2200  HOTKEY_LIST_END
2201 };
2202 HotkeyList MainToolbarWindow::hotkeys("maintoolbar", maintoolbar_hotkeys);
2203 
2204 static NWidgetBase *MakeMainToolbar(int *biggest_index)
2205 {
2207  static const SpriteID toolbar_button_sprites[] = {
2208  SPR_IMG_PAUSE, // WID_TN_PAUSE
2209  SPR_IMG_FASTFORWARD, // WID_TN_FAST_FORWARD
2210  SPR_IMG_SETTINGS, // WID_TN_SETTINGS
2211  SPR_IMG_SAVE, // WID_TN_SAVE
2212  SPR_IMG_SMALLMAP, // WID_TN_SMALL_MAP
2213  SPR_IMG_TOWN, // WID_TN_TOWNS
2214  SPR_IMG_SUBSIDIES, // WID_TN_SUBSIDIES
2215  SPR_IMG_COMPANY_LIST, // WID_TN_STATIONS
2216  SPR_IMG_COMPANY_FINANCE, // WID_TN_FINANCES
2217  SPR_IMG_COMPANY_GENERAL, // WID_TN_COMPANIES
2218  SPR_IMG_STORY_BOOK, // WID_TN_STORY
2219  SPR_IMG_GOAL, // WID_TN_GOAL
2220  SPR_IMG_GRAPHS, // WID_TN_GRAPHS
2221  SPR_IMG_COMPANY_LEAGUE, // WID_TN_LEAGUE
2222  SPR_IMG_INDUSTRY, // WID_TN_INDUSTRIES
2223  SPR_IMG_TRAINLIST, // WID_TN_TRAINS
2224  SPR_IMG_TRUCKLIST, // WID_TN_ROADVEHS
2225  SPR_IMG_SHIPLIST, // WID_TN_SHIPS
2226  SPR_IMG_AIRPLANESLIST, // WID_TN_AIRCRAFT
2227  SPR_IMG_ZOOMIN, // WID_TN_ZOOMIN
2228  SPR_IMG_ZOOMOUT, // WID_TN_ZOOMOUT
2229  SPR_IMG_BUILDRAIL, // WID_TN_RAILS
2230  SPR_IMG_BUILDROAD, // WID_TN_ROADS
2231  SPR_IMG_BUILDWATER, // WID_TN_WATER
2232  SPR_IMG_BUILDAIR, // WID_TN_AIR
2233  SPR_IMG_LANDSCAPING, // WID_TN_LANDSCAPE
2234  SPR_IMG_MUSIC, // WID_TN_MUSIC_SOUND
2235  SPR_IMG_MESSAGES, // WID_TN_MESSAGES
2236  SPR_IMG_QUERY, // WID_TN_HELP
2237  SPR_IMG_SWITCH_TOOLBAR, // WID_TN_SWITCH_BAR
2238  };
2239 
2241  for (uint i = 0; i < WID_TN_END; i++) {
2242  switch (i) {
2243  case WID_TN_SMALL_MAP:
2244  case WID_TN_FINANCES:
2245  case WID_TN_VEHICLE_START:
2246  case WID_TN_ZOOM_IN:
2248  case WID_TN_MUSIC_SOUND:
2249  hor->Add(new NWidgetSpacer(0, 0));
2250  break;
2251  }
2252  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));
2253  }
2254 
2255  *biggest_index = max<int>(*biggest_index, WID_TN_SWITCH_BAR);
2256  return hor;
2257 }
2258 
2259 static const NWidgetPart _nested_toolbar_normal_widgets[] = {
2261 };
2262 
2263 static WindowDesc _toolb_normal_desc(
2264  WDP_MANUAL, NULL, 0, 0,
2266  WDF_NO_FOCUS,
2267  _nested_toolbar_normal_widgets, lengthof(_nested_toolbar_normal_widgets),
2268  &MainToolbarWindow::hotkeys
2269 );
2270 
2271 
2272 /* --- Toolbar handling for the scenario editor */
2273 
2274 static ToolbarButtonProc * const _scen_toolbar_button_procs[] = {
2275  ToolbarPauseClick,
2279  ToolbarBtn_NULL,
2281  ToolbarScenDateBackward,
2282  ToolbarScenDateForward,
2283  ToolbarScenMapTownDir,
2284  ToolbarZoomInClick,
2285  ToolbarZoomOutClick,
2286  ToolbarScenGenLand,
2287  ToolbarScenGenTown,
2288  ToolbarScenGenIndustry,
2289  ToolbarScenBuildRoad,
2290  ToolbarScenBuildDocks,
2291  ToolbarScenPlantTrees,
2292  ToolbarScenPlaceSign,
2293  ToolbarBtn_NULL,
2294  NULL,
2295  NULL,
2296  NULL,
2297  NULL,
2298  NULL,
2299  NULL,
2300  NULL,
2301  ToolbarMusicClick,
2302  NULL,
2303  ToolbarHelpClick,
2304  ToolbarSwitchClick,
2305 };
2306 
2307 enum MainToolbarEditorHotkeys {
2308  MTEHK_PAUSE,
2309  MTEHK_FASTFORWARD,
2310  MTEHK_SETTINGS,
2311  MTEHK_SAVEGAME,
2312  MTEHK_GENLAND,
2313  MTEHK_GENTOWN,
2314  MTEHK_GENINDUSTRY,
2315  MTEHK_BUILD_ROAD,
2316  MTEHK_BUILD_DOCKS,
2317  MTEHK_BUILD_TREES,
2318  MTEHK_SIGN,
2319  MTEHK_MUSIC,
2320  MTEHK_LANDINFO,
2321  MTEHK_SMALL_SCREENSHOT,
2322  MTEHK_ZOOMEDIN_SCREENSHOT,
2323  MTEHK_DEFAULTZOOM_SCREENSHOT,
2324  MTEHK_GIANT_SCREENSHOT,
2325  MTEHK_ZOOM_IN,
2326  MTEHK_ZOOM_OUT,
2327  MTEHK_TERRAFORM,
2328  MTEHK_SMALLMAP,
2329  MTEHK_EXTRA_VIEWPORT,
2330 };
2331 
2333  GUITimer timer;
2334 
2336  {
2337  this->InitNested(0);
2338 
2339  _last_started_action = CBF_NONE;
2340  CLRBITS(this->flags, WF_WHITE_BORDER);
2341  PositionMainToolbar(this);
2343 
2344  this->timer.SetInterval(MILLISECONDS_PER_TICK);
2345  }
2346 
2347  virtual void FindWindowPlacementAndResize(int def_width, int def_height)
2348  {
2350  }
2351 
2352  virtual void OnPaint()
2353  {
2354  this->SetWidgetDisabledState(WID_TE_DATE_BACKWARD, _settings_game.game_creation.starting_year <= MIN_YEAR);
2355  this->SetWidgetDisabledState(WID_TE_DATE_FORWARD, _settings_game.game_creation.starting_year >= MAX_YEAR);
2356 
2357  this->DrawWidgets();
2358  }
2359 
2360  virtual void DrawWidget(const Rect &r, int widget) const
2361  {
2362  switch (widget) {
2363  case WID_TE_DATE:
2365  DrawString(r.left, r.right, (this->height - FONT_HEIGHT_NORMAL) / 2, STR_WHITE_DATE_LONG, TC_FROMSTRING, SA_HOR_CENTER);
2366  break;
2367 
2368  case WID_TE_SPACER: {
2369  int height = r.bottom - r.top;
2370  if (height > 2 * FONT_HEIGHT_NORMAL) {
2371  DrawString(r.left, r.right, (height + 1) / 2 - FONT_HEIGHT_NORMAL, STR_SCENEDIT_TOOLBAR_OPENTTD, TC_FROMSTRING, SA_HOR_CENTER);
2372  DrawString(r.left, r.right, (height + 1) / 2, STR_SCENEDIT_TOOLBAR_SCENARIO_EDITOR, TC_FROMSTRING, SA_HOR_CENTER);
2373  } else {
2374  DrawString(r.left, r.right, (height - FONT_HEIGHT_NORMAL) / 2, STR_SCENEDIT_TOOLBAR_SCENARIO_EDITOR, TC_FROMSTRING, SA_HOR_CENTER);
2375  }
2376  break;
2377  }
2378  }
2379  }
2380 
2381  virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
2382  {
2383  switch (widget) {
2384  case WID_TE_SPACER:
2385  size->width = max(GetStringBoundingBox(STR_SCENEDIT_TOOLBAR_OPENTTD).width, GetStringBoundingBox(STR_SCENEDIT_TOOLBAR_SCENARIO_EDITOR).width) + WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT;
2386  break;
2387 
2388  case WID_TE_DATE:
2389  SetDParam(0, ConvertYMDToDate(MAX_YEAR, 0, 1));
2390  *size = GetStringBoundingBox(STR_WHITE_DATE_LONG);
2391  size->height = max(size->height, GetSpriteSize(SPR_IMG_SAVE).height + WD_IMGBTN_TOP + WD_IMGBTN_BOTTOM);
2392  break;
2393  }
2394  }
2395 
2396  virtual void OnClick(Point pt, int widget, int click_count)
2397  {
2398  if (_game_mode == GM_MENU) return;
2399  CallBackFunction cbf = _scen_toolbar_button_procs[widget](this);
2400  if (cbf != CBF_NONE) _last_started_action = cbf;
2401  }
2402 
2403  virtual void OnDropdownSelect(int widget, int index)
2404  {
2405  /* The map button is in a different location on the scenario
2406  * editor toolbar, so we need to adjust for it. */
2407  if (widget == WID_TE_SMALL_MAP) widget = WID_TN_SMALL_MAP;
2408  CallBackFunction cbf = _menu_clicked_procs[widget](index);
2409  if (cbf != CBF_NONE) _last_started_action = cbf;
2410  if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
2411  }
2412 
2413  virtual EventState OnHotkey(int hotkey)
2414  {
2415  CallBackFunction cbf = CBF_NONE;
2416  switch (hotkey) {
2417  case MTEHK_PAUSE: ToolbarPauseClick(this); break;
2418  case MTEHK_FASTFORWARD: ToolbarFastForwardClick(this); break;
2419  case MTEHK_SETTINGS: ShowGameOptions(); break;
2420  case MTEHK_SAVEGAME: MenuClickSaveLoad(); break;
2421  case MTEHK_GENLAND: ToolbarScenGenLand(this); break;
2422  case MTEHK_GENTOWN: ToolbarScenGenTown(this); break;
2423  case MTEHK_GENINDUSTRY: ToolbarScenGenIndustry(this); break;
2424  case MTEHK_BUILD_ROAD: ToolbarScenBuildRoad(this); break;
2425  case MTEHK_BUILD_DOCKS: ToolbarScenBuildDocks(this); break;
2426  case MTEHK_BUILD_TREES: ToolbarScenPlantTrees(this); break;
2427  case MTEHK_SIGN: cbf = ToolbarScenPlaceSign(this); break;
2428  case MTEHK_MUSIC: ShowMusicWindow(); break;
2429  case MTEHK_LANDINFO: cbf = PlaceLandBlockInfo(); break;
2430  case MTEHK_SMALL_SCREENSHOT: MenuClickSmallScreenshot(); break;
2431  case MTEHK_ZOOMEDIN_SCREENSHOT: MenuClickLargeWorldScreenshot(SC_ZOOMEDIN); break;
2432  case MTEHK_DEFAULTZOOM_SCREENSHOT: MenuClickLargeWorldScreenshot(SC_DEFAULTZOOM); break;
2433  case MTEHK_GIANT_SCREENSHOT: MenuClickLargeWorldScreenshot(SC_WORLD); break;
2434  case MTEHK_ZOOM_IN: ToolbarZoomInClick(this); break;
2435  case MTEHK_ZOOM_OUT: ToolbarZoomOutClick(this); break;
2436  case MTEHK_TERRAFORM: ShowEditorTerraformToolbar(); break;
2437  case MTEHK_SMALLMAP: ShowSmallMap(); break;
2438  case MTEHK_EXTRA_VIEWPORT: ShowExtraViewPortWindowForTileUnderCursor(); break;
2439  default: return ES_NOT_HANDLED;
2440  }
2441  if (cbf != CBF_NONE) _last_started_action = cbf;
2442  return ES_HANDLED;
2443  }
2444 
2445  virtual void OnPlaceObject(Point pt, TileIndex tile)
2446  {
2447  switch (_last_started_action) {
2448  case CBF_PLACE_SIGN:
2449  PlaceProc_Sign(tile);
2450  break;
2451 
2452  case CBF_PLACE_LANDINFO:
2453  ShowLandInfo(tile);
2454  break;
2455 
2456  default: NOT_REACHED();
2457  }
2458  }
2459 
2460  virtual void OnPlaceObjectAbort()
2461  {
2462  _last_started_action = CBF_NONE;
2463  }
2464 
2465  virtual void OnTimeout()
2466  {
2467  this->SetWidgetsLoweredState(false, WID_TE_DATE_BACKWARD, WID_TE_DATE_FORWARD, WIDGET_LIST_END);
2468  this->SetWidgetDirty(WID_TE_DATE_BACKWARD);
2469  this->SetWidgetDirty(WID_TE_DATE_FORWARD);
2470  }
2471 
2472  virtual void OnRealtimeTick(uint delta_ms)
2473  {
2474  if (!this->timer.Elapsed(delta_ms)) return;
2475  this->timer.SetInterval(MILLISECONDS_PER_TICK);
2476 
2477  if (this->IsWidgetLowered(WID_TE_PAUSE) != !!_pause_mode) {
2478  this->ToggleWidgetLoweredState(WID_TE_PAUSE);
2479  this->SetDirty();
2480  }
2481 
2482  if (this->IsWidgetLowered(WID_TE_FAST_FORWARD) != !!_fast_forward) {
2483  this->ToggleWidgetLoweredState(WID_TE_FAST_FORWARD);
2484  this->SetDirty();
2485  }
2486  }
2487 
2493  virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
2494  {
2495  if (!gui_scope) return;
2497  }
2498 
2499  virtual void OnQueryTextFinished(char *str)
2500  {
2501  /* Was 'cancel' pressed? */
2502  if (str == NULL) return;
2503 
2504  int32 value;
2505  if (!StrEmpty(str)) {
2506  value = atoi(str);
2507  } else {
2508  /* An empty string means revert to the default */
2509  value = DEF_START_YEAR;
2510  }
2511  SetStartingYear(value);
2512 
2513  this->SetDirty();
2514  }
2515 
2516  static HotkeyList hotkeys;
2517 };
2518 
2519 static Hotkey scenedit_maintoolbar_hotkeys[] = {
2520  Hotkey(_maintoolbar_pause_keys, "pause", MTEHK_PAUSE),
2521  Hotkey((uint16)0, "fastforward", MTEHK_FASTFORWARD),
2522  Hotkey(WKC_F2, "settings", MTEHK_SETTINGS),
2523  Hotkey(WKC_F3, "saveload", MTEHK_SAVEGAME),
2524  Hotkey(WKC_F4, "gen_land", MTEHK_GENLAND),
2525  Hotkey(WKC_F5, "gen_town", MTEHK_GENTOWN),
2526  Hotkey(WKC_F6, "gen_industry", MTEHK_GENINDUSTRY),
2527  Hotkey(WKC_F7, "build_road", MTEHK_BUILD_ROAD),
2528  Hotkey(WKC_F8, "build_docks", MTEHK_BUILD_DOCKS),
2529  Hotkey(WKC_F9, "build_trees", MTEHK_BUILD_TREES),
2530  Hotkey(WKC_F10, "build_sign", MTEHK_SIGN),
2531  Hotkey(WKC_F11, "music", MTEHK_MUSIC),
2532  Hotkey(WKC_F12, "land_info", MTEHK_LANDINFO),
2533  Hotkey(WKC_CTRL | 'S', "small_screenshot", MTEHK_SMALL_SCREENSHOT),
2534  Hotkey(WKC_CTRL | 'P', "zoomedin_screenshot", MTEHK_ZOOMEDIN_SCREENSHOT),
2535  Hotkey(WKC_CTRL | 'D', "defaultzoom_screenshot", MTEHK_DEFAULTZOOM_SCREENSHOT),
2536  Hotkey((uint16)0, "giant_screenshot", MTEHK_GIANT_SCREENSHOT),
2537  Hotkey(_maintoolbar_zoomin_keys, "zoomin", MTEHK_ZOOM_IN),
2538  Hotkey(_maintoolbar_zoomout_keys, "zoomout", MTEHK_ZOOM_OUT),
2539  Hotkey('L', "terraform", MTEHK_TERRAFORM),
2540  Hotkey('M', "smallmap", MTEHK_SMALLMAP),
2541  Hotkey('V', "extra_viewport", MTEHK_EXTRA_VIEWPORT),
2542  HOTKEY_LIST_END
2543 };
2544 HotkeyList ScenarioEditorToolbarWindow::hotkeys("scenedit_maintoolbar", scenedit_maintoolbar_hotkeys);
2545 
2546 static const NWidgetPart _nested_toolb_scen_inner_widgets[] = {
2547  NWidget(WWT_IMGBTN, COLOUR_GREY, WID_TE_PAUSE), SetDataTip(SPR_IMG_PAUSE, STR_TOOLBAR_TOOLTIP_PAUSE_GAME),
2548  NWidget(WWT_IMGBTN, COLOUR_GREY, WID_TE_FAST_FORWARD), SetDataTip(SPR_IMG_FASTFORWARD, STR_TOOLBAR_TOOLTIP_FORWARD),
2549  NWidget(WWT_IMGBTN, COLOUR_GREY, WID_TE_SETTINGS), SetDataTip(SPR_IMG_SETTINGS, STR_TOOLBAR_TOOLTIP_OPTIONS),
2550  NWidget(WWT_IMGBTN_2, COLOUR_GREY, WID_TE_SAVE), SetDataTip(SPR_IMG_SAVE, STR_SCENEDIT_TOOLBAR_TOOLTIP_SAVE_SCENARIO_LOAD_SCENARIO),
2552  NWidget(WWT_PANEL, COLOUR_GREY, WID_TE_SPACER), EndContainer(),
2554  NWidget(WWT_PANEL, COLOUR_GREY, WID_TE_DATE_PANEL),
2555  NWidget(NWID_HORIZONTAL), SetPIP(3, 2, 3),
2556  NWidget(WWT_IMGBTN, COLOUR_GREY, WID_TE_DATE_BACKWARD), SetDataTip(SPR_ARROW_DOWN, STR_SCENEDIT_TOOLBAR_TOOLTIP_MOVE_THE_STARTING_DATE_BACKWARD),
2557  NWidget(WWT_EMPTY, COLOUR_GREY, WID_TE_DATE), SetDataTip(STR_NULL, STR_SCENEDIT_TOOLBAR_TOOLTIP_SET_DATE),
2558  NWidget(WWT_IMGBTN, COLOUR_GREY, WID_TE_DATE_FORWARD), SetDataTip(SPR_ARROW_UP, STR_SCENEDIT_TOOLBAR_TOOLTIP_MOVE_THE_STARTING_DATE_FORWARD),
2559  EndContainer(),
2560  EndContainer(),
2562  NWidget(WWT_IMGBTN, COLOUR_GREY, WID_TE_SMALL_MAP), SetDataTip(SPR_IMG_SMALLMAP, STR_SCENEDIT_TOOLBAR_TOOLTIP_DISPLAY_MAP_TOWN_DIRECTORY),
2564  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_TE_ZOOM_IN), SetDataTip(SPR_IMG_ZOOMIN, STR_TOOLBAR_TOOLTIP_ZOOM_THE_VIEW_IN),
2565  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_TE_ZOOM_OUT), SetDataTip(SPR_IMG_ZOOMOUT, STR_TOOLBAR_TOOLTIP_ZOOM_THE_VIEW_OUT),
2567  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_TE_LAND_GENERATE), SetDataTip(SPR_IMG_LANDSCAPING, STR_SCENEDIT_TOOLBAR_LANDSCAPE_GENERATION),
2568  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_TE_TOWN_GENERATE), SetDataTip(SPR_IMG_TOWN, STR_SCENEDIT_TOOLBAR_TOWN_GENERATION),
2569  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_TE_INDUSTRY), SetDataTip(SPR_IMG_INDUSTRY, STR_SCENEDIT_TOOLBAR_INDUSTRY_GENERATION),
2570  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_TE_ROADS), SetDataTip(SPR_IMG_BUILDROAD, STR_SCENEDIT_TOOLBAR_ROAD_CONSTRUCTION),
2571  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_TE_WATER), SetDataTip(SPR_IMG_BUILDWATER, STR_TOOLBAR_TOOLTIP_BUILD_SHIP_DOCKS),
2572  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_TE_TREES), SetDataTip(SPR_IMG_PLANTTREES, STR_SCENEDIT_TOOLBAR_PLANT_TREES),
2573  NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_TE_SIGNS), SetDataTip(SPR_IMG_SIGN, STR_SCENEDIT_TOOLBAR_PLACE_SIGN),
2575  NWidget(WWT_IMGBTN, COLOUR_GREY, WID_TE_MUSIC_SOUND), SetDataTip(SPR_IMG_MUSIC, STR_TOOLBAR_TOOLTIP_SHOW_SOUND_MUSIC_WINDOW),
2576  NWidget(WWT_IMGBTN, COLOUR_GREY, WID_TE_HELP), SetDataTip(SPR_IMG_QUERY, STR_TOOLBAR_TOOLTIP_LAND_BLOCK_INFORMATION),
2577  NWidget(WWT_IMGBTN, COLOUR_GREY, WID_TE_SWITCH_BAR), SetDataTip(SPR_IMG_SWITCH_TOOLBAR, STR_TOOLBAR_TOOLTIP_SWITCH_TOOLBAR),
2578 };
2579 
2580 static NWidgetBase *MakeScenarioToolbar(int *biggest_index)
2581 {
2582  return MakeNWidgets(_nested_toolb_scen_inner_widgets, lengthof(_nested_toolb_scen_inner_widgets), biggest_index, new NWidgetScenarioToolbarContainer());
2583 }
2584 
2585 static const NWidgetPart _nested_toolb_scen_widgets[] = {
2586  NWidgetFunction(MakeScenarioToolbar),
2587 };
2588 
2589 static WindowDesc _toolb_scen_desc(
2590  WDP_MANUAL, NULL, 0, 0,
2592  WDF_NO_FOCUS,
2593  _nested_toolb_scen_widgets, lengthof(_nested_toolb_scen_widgets),
2594  &ScenarioEditorToolbarWindow::hotkeys
2595 );
2596 
2599 {
2600  /* Clean old GUI values; railtype is (re)set by rail_gui.cpp */
2601  _last_built_roadtype = ROADTYPE_ROAD;
2602 
2603  if (_game_mode == GM_EDITOR) {
2604  new ScenarioEditorToolbarWindow(&_toolb_scen_desc);
2605  } else {
2606  new MainToolbarWindow(&_toolb_normal_desc);
2607  }
2608 }
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:113
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:455
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:312
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:1114
The passed event is not handled.
Definition: window_type.h:715
Display station names.
Definition: openttd.h:44
bool Elapsed(uint delta)
Test if a timer has elapsed.
Definition: guitimer_func.h:57
int PositionMainToolbar(Window *w)
(Re)position main toolbar window at the screen.
Definition: window.cpp:3488
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:407
Sign list; Window numbers:
Definition: window_type.h:273
Screenshot of viewport.
Definition: screenshot.h:21
Window * ShowBuildRoadToolbar(RoadType roadtype)
Open the build road toolbar window.
Definition: road_gui.cpp:811
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:966
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:1756
void ReInit(int rx=0, int ry=0)
Re-initialize a window, and optionally change its size.
Definition: window.cpp:979
bool NetworkCompanyIsPassworded(CompanyID company_id)
Check if the company we want to join requires a password.
Definition: network.cpp: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.
void DeleteAllMessages()
Delete all messages and their corresponding window (if any).
Definition: window.cpp:3398
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:278
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:3319
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:1146
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:930
Road building menu.
static void PopupMainCompanyToolbMenu(Window *w, int widget, int grey=0)
Pop up a generic company list 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:500
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:1531
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:968
Pause the game.
void ShowExtraViewPortWindow(TileIndex tile=INVALID_TILE)
Show a new Extra Viewport window.
bool MakeScreenshot(ScreenshotType t, const char *name)
Make an actual screenshot.
Definition: screenshot.cpp:812
bool newgrf_developer_tools
activate NewGRF developer tools and allow modifying NewGRFs in an existing game
void ShowHighscoreTable(int difficulty=SP_CUSTOM, int8 rank=-1)
Show the highscore table for a given difficulty.
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:700
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:896
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:769
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:3040
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:619
static const int CTMN_NEW_COMPANY
Create a new company.
virtual void FindWindowPlacementAndResize(int def_width, int def_height)
Resize window towards the default size.
Definition: window.cpp:1506
static const int CTMN_CLIENT_LIST
Enum for the Company Toolbar&#39;s network related buttons.
Reduce the date of the scenario.
void ShowGameSettings()
Open advanced settings window.
Offset at right to draw the frame rectangular area.
Definition: window_gui.h:63
Zoom out the main viewport.
ToolbarMode
Toobar modes.
Definition: toolbar_gui.cpp:71
SaveLoadEditorMenuEntries
SaveLoad entries in scenario editor mode.
Window * ShowBuildRoadScenToolbar()
Show the road building toolbar in the scenario editor.
Definition: road_gui.cpp:859
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:3088
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:133
uint8 timeout_timer
Timer value of the WF_TIMEOUT for flags.
Definition: window_gui.h:316
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:834
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:1463
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