forked from OpenTTD/OpenTTD
/
toolbar_gui.cpp
2604 lines (2332 loc) · 78.8 KB
/
toolbar_gui.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* $Id$ */
/*
* This file is part of OpenTTD.
* 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.
* 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.
* 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/>.
*/
/** @file toolbar_gui.cpp Code related to the (main) toolbar. */
#include "stdafx.h"
#include "gui.h"
#include "window_gui.h"
#include "window_func.h"
#include "viewport_func.h"
#include "command_func.h"
#include "vehicle_gui.h"
#include "rail_gui.h"
#include "road_gui.h"
#include "date_func.h"
#include "vehicle_func.h"
#include "sound_func.h"
#include "terraform_gui.h"
#include "strings_func.h"
#include "company_func.h"
#include "company_gui.h"
#include "vehicle_base.h"
#include "cheat_func.h"
#include "transparency_gui.h"
#include "screenshot.h"
#include "signs_func.h"
#include "fios.h"
#include "console_gui.h"
#include "news_gui.h"
#include "ai/ai_gui.hpp"
#include "tilehighlight_func.h"
#include "smallmap_gui.h"
#include "graph_gui.h"
#include "textbuf_gui.h"
#include "linkgraph/linkgraph_gui.h"
#include "newgrf_debug.h"
#include "hotkeys.h"
#include "engine_base.h"
#include "highscore.h"
#include "game/game.hpp"
#include "goal_base.h"
#include "story_base.h"
#include "toolbar_gui.h"
#include "framerate_type.h"
#include "guitimer_func.h"
#include "widgets/toolbar_widget.h"
#include "network/network.h"
#include "network/network_gui.h"
#include "network/network_func.h"
#include "safeguards.h"
/** Width of the toolbar, shared by statusbar. */
uint _toolbar_width = 0;
RailType _last_built_railtype;
RoadType _last_built_roadtype;
static ScreenshotType _confirmed_screenshot_type; ///< Screenshot type the current query is about to confirm.
/** Toobar modes */
enum ToolbarMode {
TB_NORMAL,
TB_UPPER,
TB_LOWER
};
/** Callback functions. */
enum CallBackFunction {
CBF_NONE,
CBF_PLACE_SIGN,
CBF_PLACE_LANDINFO,
};
static CallBackFunction _last_started_action = CBF_NONE; ///< Last started user action.
/**
* Drop down list entry for showing a checked/unchecked toggle item.
*/
class DropDownListCheckedItem : public DropDownListStringItem {
uint checkmark_width;
public:
bool checked;
DropDownListCheckedItem(StringID string, int result, bool masked, bool checked) : DropDownListStringItem(string, result, masked), checked(checked)
{
this->checkmark_width = GetStringBoundingBox(STR_JUST_CHECKMARK).width + 3;
}
uint Width() const
{
return DropDownListStringItem::Width() + this->checkmark_width;
}
void Draw(int left, int right, int top, int bottom, bool sel, Colours bg_colour) const
{
bool rtl = _current_text_dir == TD_RTL;
if (this->checked) {
DrawString(left + WD_FRAMERECT_LEFT, right - WD_FRAMERECT_RIGHT, top, STR_JUST_CHECKMARK, sel ? TC_WHITE : TC_BLACK);
}
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);
}
};
/**
* Drop down list entry for showing a company entry, with companies 'blob'.
*/
class DropDownListCompanyItem : public DropDownListItem {
Dimension icon_size;
Dimension lock_size;
public:
bool greyed;
DropDownListCompanyItem(int result, bool masked, bool greyed) : DropDownListItem(result, masked), greyed(greyed)
{
this->icon_size = GetSpriteSize(SPR_COMPANY_ICON);
this->lock_size = GetSpriteSize(SPR_LOCK);
}
bool Selectable() const
{
return true;
}
uint Width() const
{
CompanyID company = (CompanyID)this->result;
SetDParam(0, company);
SetDParam(1, company);
return GetStringBoundingBox(STR_COMPANY_NAME_COMPANY_NUM).width + this->icon_size.width + this->lock_size.width + 6;
}
uint Height(uint width) const
{
return max(max(this->icon_size.height, this->lock_size.height) + 2U, (uint)FONT_HEIGHT_NORMAL);
}
void Draw(int left, int right, int top, int bottom, bool sel, Colours bg_colour) const
{
CompanyID company = (CompanyID)this->result;
bool rtl = _current_text_dir == TD_RTL;
/* It's possible the company is deleted while the dropdown is open */
if (!Company::IsValidID(company)) return;
int icon_offset = (bottom - top - icon_size.height) / 2;
int text_offset = (bottom - top - FONT_HEIGHT_NORMAL) / 2;
int lock_offset = (bottom - top - lock_size.height) / 2;
DrawCompanyIcon(company, rtl ? right - this->icon_size.width - WD_FRAMERECT_RIGHT : left + WD_FRAMERECT_LEFT, top + icon_offset);
#ifdef ENABLE_NETWORK
if (NetworkCompanyIsPassworded(company)) {
DrawSprite(SPR_LOCK, PAL_NONE, rtl ? left + WD_FRAMERECT_LEFT : right - this->lock_size.width - WD_FRAMERECT_RIGHT, top + lock_offset);
}
#endif
SetDParam(0, company);
SetDParam(1, company);
TextColour col;
if (this->greyed) {
col = (sel ? TC_SILVER : TC_GREY) | TC_NO_SHADE;
} else {
col = sel ? TC_WHITE : TC_BLACK;
}
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);
}
};
/**
* Pop up a generic text only menu.
* @param w Toolbar
* @param widget Toolbar button
* @param list List of items
* @param def Default item
*/
static void PopupMainToolbMenu(Window *w, int widget, DropDownList *list, int def)
{
ShowDropDownList(w, list, def, widget, 0, true, true);
if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
}
/**
* Pop up a generic text only menu.
* @param w Toolbar
* @param widget Toolbar button
* @param string String for the first item in the menu
* @param count Number of items in the menu
*/
static void PopupMainToolbMenu(Window *w, int widget, StringID string, int count)
{
DropDownList *list = new DropDownList();
for (int i = 0; i < count; i++) {
*list->Append() = new DropDownListStringItem(string + i, i, false);
}
PopupMainToolbMenu(w, widget, list, 0);
}
/** Enum for the Company Toolbar's network related buttons */
static const int CTMN_CLIENT_LIST = -1; ///< Show the client list
static const int CTMN_NEW_COMPANY = -2; ///< Create a new company
static const int CTMN_SPECTATE = -3; ///< Become spectator
static const int CTMN_SPECTATOR = -4; ///< Show a company window as spectator
/**
* Pop up a generic company list menu.
* @param w The toolbar window.
* @param widget The button widget id.
* @param grey A bitbask of which items to mark as disabled.
*/
static void PopupMainCompanyToolbMenu(Window *w, int widget, int grey = 0)
{
DropDownList *list = new DropDownList();
switch (widget) {
case WID_TN_COMPANIES:
#ifdef ENABLE_NETWORK
if (!_networking) break;
/* Add the client list button for the companies menu */
*list->Append() = new DropDownListStringItem(STR_NETWORK_COMPANY_LIST_CLIENT_LIST, CTMN_CLIENT_LIST, false);
if (_local_company == COMPANY_SPECTATOR) {
*list->Append() = new DropDownListStringItem(STR_NETWORK_COMPANY_LIST_NEW_COMPANY, CTMN_NEW_COMPANY, NetworkMaxCompaniesReached());
} else {
*list->Append() = new DropDownListStringItem(STR_NETWORK_COMPANY_LIST_SPECTATE, CTMN_SPECTATE, NetworkMaxSpectatorsReached());
}
#endif /* ENABLE_NETWORK */
break;
case WID_TN_STORY:
*list->Append() = new DropDownListStringItem(STR_STORY_BOOK_SPECTATOR, CTMN_SPECTATOR, false);
break;
case WID_TN_GOAL:
*list->Append() = new DropDownListStringItem(STR_GOALS_SPECTATOR, CTMN_SPECTATOR, false);
break;
}
for (CompanyID c = COMPANY_FIRST; c < MAX_COMPANIES; c++) {
if (!Company::IsValidID(c)) continue;
*list->Append() = new DropDownListCompanyItem(c, false, HasBit(grey, c));
}
PopupMainToolbMenu(w, widget, list, _local_company == COMPANY_SPECTATOR ? (widget == WID_TN_COMPANIES ? CTMN_CLIENT_LIST : CTMN_SPECTATOR) : (int)_local_company);
}
static ToolbarMode _toolbar_mode;
static CallBackFunction SelectSignTool()
{
if (_last_started_action == CBF_PLACE_SIGN) {
ResetObjectToPlace();
return CBF_NONE;
} else {
SetObjectToPlace(SPR_CURSOR_SIGN, PAL_NONE, HT_RECT, WC_MAIN_TOOLBAR, 0);
return CBF_PLACE_SIGN;
}
}
/* --- Pausing --- */
static CallBackFunction ToolbarPauseClick(Window *w)
{
if (_networking && !_network_server) return CBF_NONE; // only server can pause the game
if (DoCommandP(0, PM_PAUSED_NORMAL, _pause_mode == PM_UNPAUSED, CMD_PAUSE)) {
if (_settings_client.sound.confirm) SndPlayFx(SND_15_BEEP);
}
return CBF_NONE;
}
/**
* Toggle fast forward mode.
*
* @param w Unused.
* @return #CBF_NONE
*/
static CallBackFunction ToolbarFastForwardClick(Window *w)
{
_fast_forward ^= true;
if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
return CBF_NONE;
}
/**
* Game Option button menu entries.
*/
enum OptionMenuEntries {
OME_GAMEOPTIONS,
OME_SETTINGS,
OME_SCRIPT_SETTINGS,
OME_NEWGRFSETTINGS,
OME_TRANSPARENCIES,
OME_SHOW_TOWNNAMES,
OME_SHOW_STATIONNAMES,
OME_SHOW_WAYPOINTNAMES,
OME_SHOW_SIGNS,
OME_SHOW_COMPETITOR_SIGNS,
OME_FULL_ANIMATION,
OME_FULL_DETAILS,
OME_TRANSPARENTBUILDINGS,
OME_SHOW_STATIONSIGNS,
};
/**
* Handle click on Options button in toolbar.
*
* @param w parent window the shown Drop down list is attached to.
* @return #CBF_NONE
*/
static CallBackFunction ToolbarOptionsClick(Window *w)
{
DropDownList *list = new DropDownList();
*list->Append() = new DropDownListStringItem(STR_SETTINGS_MENU_GAME_OPTIONS, OME_GAMEOPTIONS, false);
*list->Append() = new DropDownListStringItem(STR_SETTINGS_MENU_CONFIG_SETTINGS_TREE, OME_SETTINGS, false);
/* Changes to the per-AI settings don't get send from the server to the clients. Clients get
* the settings once they join but never update it. As such don't show the window at all
* to network clients. */
if (!_networking || _network_server) *list->Append() = new DropDownListStringItem(STR_SETTINGS_MENU_SCRIPT_SETTINGS, OME_SCRIPT_SETTINGS, false);
*list->Append() = new DropDownListStringItem(STR_SETTINGS_MENU_NEWGRF_SETTINGS, OME_NEWGRFSETTINGS, false);
*list->Append() = new DropDownListStringItem(STR_SETTINGS_MENU_TRANSPARENCY_OPTIONS, OME_TRANSPARENCIES, false);
*list->Append() = new DropDownListItem(-1, false);
*list->Append() = new DropDownListCheckedItem(STR_SETTINGS_MENU_TOWN_NAMES_DISPLAYED, OME_SHOW_TOWNNAMES, false, HasBit(_display_opt, DO_SHOW_TOWN_NAMES));
*list->Append() = new DropDownListCheckedItem(STR_SETTINGS_MENU_STATION_NAMES_DISPLAYED, OME_SHOW_STATIONNAMES, false, HasBit(_display_opt, DO_SHOW_STATION_NAMES));
*list->Append() = new DropDownListCheckedItem(STR_SETTINGS_MENU_WAYPOINTS_DISPLAYED, OME_SHOW_WAYPOINTNAMES, false, HasBit(_display_opt, DO_SHOW_WAYPOINT_NAMES));
*list->Append() = new DropDownListCheckedItem(STR_SETTINGS_MENU_SIGNS_DISPLAYED, OME_SHOW_SIGNS, false, HasBit(_display_opt, DO_SHOW_SIGNS));
*list->Append() = new DropDownListCheckedItem(STR_SETTINGS_MENU_SHOW_COMPETITOR_SIGNS, OME_SHOW_COMPETITOR_SIGNS, false, HasBit(_display_opt, DO_SHOW_COMPETITOR_SIGNS));
*list->Append() = new DropDownListCheckedItem(STR_SETTINGS_MENU_FULL_ANIMATION, OME_FULL_ANIMATION, false, HasBit(_display_opt, DO_FULL_ANIMATION));
*list->Append() = new DropDownListCheckedItem(STR_SETTINGS_MENU_FULL_DETAIL, OME_FULL_DETAILS, false, HasBit(_display_opt, DO_FULL_DETAIL));
*list->Append() = new DropDownListCheckedItem(STR_SETTINGS_MENU_TRANSPARENT_BUILDINGS, OME_TRANSPARENTBUILDINGS, false, IsTransparencySet(TO_HOUSES));
*list->Append() = new DropDownListCheckedItem(STR_SETTINGS_MENU_TRANSPARENT_SIGNS, OME_SHOW_STATIONSIGNS, false, IsTransparencySet(TO_SIGNS));
ShowDropDownList(w, list, 0, WID_TN_SETTINGS, 140, true, true);
if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
return CBF_NONE;
}
/**
* Handle click on one of the entries in the Options button menu.
*
* @param index Index being clicked.
* @return #CBF_NONE
*/
static CallBackFunction MenuClickSettings(int index)
{
switch (index) {
case OME_GAMEOPTIONS: ShowGameOptions(); return CBF_NONE;
case OME_SETTINGS: ShowGameSettings(); return CBF_NONE;
case OME_SCRIPT_SETTINGS: ShowAIConfigWindow(); return CBF_NONE;
case OME_NEWGRFSETTINGS: ShowNewGRFSettings(!_networking && _settings_client.gui.UserIsAllowedToChangeNewGRFs(), true, true, &_grfconfig); return CBF_NONE;
case OME_TRANSPARENCIES: ShowTransparencyToolbar(); break;
case OME_SHOW_TOWNNAMES: ToggleBit(_display_opt, DO_SHOW_TOWN_NAMES); break;
case OME_SHOW_STATIONNAMES: ToggleBit(_display_opt, DO_SHOW_STATION_NAMES); break;
case OME_SHOW_WAYPOINTNAMES: ToggleBit(_display_opt, DO_SHOW_WAYPOINT_NAMES); break;
case OME_SHOW_SIGNS: ToggleBit(_display_opt, DO_SHOW_SIGNS); break;
case OME_SHOW_COMPETITOR_SIGNS:
ToggleBit(_display_opt, DO_SHOW_COMPETITOR_SIGNS);
InvalidateWindowClassesData(WC_SIGN_LIST, -1);
break;
case OME_FULL_ANIMATION: ToggleBit(_display_opt, DO_FULL_ANIMATION); CheckBlitter(); break;
case OME_FULL_DETAILS: ToggleBit(_display_opt, DO_FULL_DETAIL); break;
case OME_TRANSPARENTBUILDINGS: ToggleTransparency(TO_HOUSES); break;
case OME_SHOW_STATIONSIGNS: ToggleTransparency(TO_SIGNS); break;
}
MarkWholeScreenDirty();
return CBF_NONE;
}
/**
* SaveLoad entries in scenario editor mode.
*/
enum SaveLoadEditorMenuEntries {
SLEME_SAVE_SCENARIO = 0,
SLEME_LOAD_SCENARIO,
SLEME_SAVE_HEIGHTMAP,
SLEME_LOAD_HEIGHTMAP,
SLEME_EXIT_TOINTRO,
SLEME_EXIT_GAME = 6,
SLEME_MENUCOUNT,
};
/**
* SaveLoad entries in normal game mode.
*/
enum SaveLoadNormalMenuEntries {
SLNME_SAVE_GAME = 0,
SLNME_LOAD_GAME,
SLNME_EXIT_TOINTRO,
SLNME_EXIT_GAME = 4,
SLNME_MENUCOUNT,
};
/**
* Handle click on Save button in toolbar in normal game mode.
*
* @param w parent window the shown save dialogue is attached to.
* @return #CBF_NONE
*/
static CallBackFunction ToolbarSaveClick(Window *w)
{
PopupMainToolbMenu(w, WID_TN_SAVE, STR_FILE_MENU_SAVE_GAME, SLNME_MENUCOUNT);
return CBF_NONE;
}
/**
* Handle click on SaveLoad button in toolbar in the scenario editor.
*
* @param w parent window the shown save dialogue is attached to.
* @return #CBF_NONE
*/
static CallBackFunction ToolbarScenSaveOrLoad(Window *w)
{
PopupMainToolbMenu(w, WID_TE_SAVE, STR_SCENEDIT_FILE_MENU_SAVE_SCENARIO, SLEME_MENUCOUNT);
return CBF_NONE;
}
/**
* Handle click on one of the entries in the SaveLoad menu.
*
* @param index Index being clicked.
* @return #CBF_NONE
*/
static CallBackFunction MenuClickSaveLoad(int index = 0)
{
if (_game_mode == GM_EDITOR) {
switch (index) {
case SLEME_SAVE_SCENARIO: ShowSaveLoadDialog(FT_SCENARIO, SLO_SAVE); break;
case SLEME_LOAD_SCENARIO: ShowSaveLoadDialog(FT_SCENARIO, SLO_LOAD); break;
case SLEME_SAVE_HEIGHTMAP: ShowSaveLoadDialog(FT_HEIGHTMAP,SLO_SAVE); break;
case SLEME_LOAD_HEIGHTMAP: ShowSaveLoadDialog(FT_HEIGHTMAP,SLO_LOAD); break;
case SLEME_EXIT_TOINTRO: AskExitToGameMenu(); break;
case SLEME_EXIT_GAME: HandleExitGameRequest(); break;
}
} else {
switch (index) {
case SLNME_SAVE_GAME: ShowSaveLoadDialog(FT_SAVEGAME, SLO_SAVE); break;
case SLNME_LOAD_GAME: ShowSaveLoadDialog(FT_SAVEGAME, SLO_LOAD); break;
case SLNME_EXIT_TOINTRO: AskExitToGameMenu(); break;
case SLNME_EXIT_GAME: HandleExitGameRequest(); break;
}
}
return CBF_NONE;
}
/* --- Map button menu --- */
enum MapMenuEntries {
MME_SHOW_SMALLMAP = 0,
MME_SHOW_EXTRAVIEWPORTS,
MME_SHOW_LINKGRAPH,
MME_SHOW_SIGNLISTS,
MME_SHOW_TOWNDIRECTORY,
MME_SHOW_INDUSTRYDIRECTORY,
};
static CallBackFunction ToolbarMapClick(Window *w)
{
DropDownList *list = new DropDownList();
*list->Append() = new DropDownListStringItem(STR_MAP_MENU_MAP_OF_WORLD, MME_SHOW_SMALLMAP, false);
*list->Append() = new DropDownListStringItem(STR_MAP_MENU_EXTRA_VIEW_PORT, MME_SHOW_EXTRAVIEWPORTS, false);
*list->Append() = new DropDownListStringItem(STR_MAP_MENU_LINGRAPH_LEGEND, MME_SHOW_LINKGRAPH, false);
*list->Append() = new DropDownListStringItem(STR_MAP_MENU_SIGN_LIST, MME_SHOW_SIGNLISTS, false);
PopupMainToolbMenu(w, WID_TN_SMALL_MAP, list, 0);
return CBF_NONE;
}
static CallBackFunction ToolbarScenMapTownDir(Window *w)
{
DropDownList *list = new DropDownList();
*list->Append() = new DropDownListStringItem(STR_MAP_MENU_MAP_OF_WORLD, MME_SHOW_SMALLMAP, false);
*list->Append() = new DropDownListStringItem(STR_MAP_MENU_EXTRA_VIEW_PORT, MME_SHOW_EXTRAVIEWPORTS, false);
*list->Append() = new DropDownListStringItem(STR_MAP_MENU_SIGN_LIST, MME_SHOW_SIGNLISTS, false);
*list->Append() = new DropDownListStringItem(STR_TOWN_MENU_TOWN_DIRECTORY, MME_SHOW_TOWNDIRECTORY, false);
*list->Append() = new DropDownListStringItem(STR_INDUSTRY_MENU_INDUSTRY_DIRECTORY, MME_SHOW_INDUSTRYDIRECTORY, false);
PopupMainToolbMenu(w, WID_TE_SMALL_MAP, list, 0);
return CBF_NONE;
}
/**
* Handle click on one of the entries in the Map menu.
*
* @param index Index being clicked.
* @return #CBF_NONE
*/
static CallBackFunction MenuClickMap(int index)
{
switch (index) {
case MME_SHOW_SMALLMAP: ShowSmallMap(); break;
case MME_SHOW_EXTRAVIEWPORTS: ShowExtraViewPortWindow(); break;
case MME_SHOW_LINKGRAPH: ShowLinkGraphLegend(); break;
case MME_SHOW_SIGNLISTS: ShowSignList(); break;
case MME_SHOW_TOWNDIRECTORY: ShowTownDirectory(); break;
case MME_SHOW_INDUSTRYDIRECTORY: ShowIndustryDirectory(); break;
}
return CBF_NONE;
}
/* --- Town button menu --- */
static CallBackFunction ToolbarTownClick(Window *w)
{
PopupMainToolbMenu(w, WID_TN_TOWNS, STR_TOWN_MENU_TOWN_DIRECTORY, (_settings_game.economy.found_town == TF_FORBIDDEN) ? 1 : 2);
return CBF_NONE;
}
/**
* Handle click on one of the entries in the Town menu.
*
* @param index Index being clicked.
* @return #CBF_NONE
*/
static CallBackFunction MenuClickTown(int index)
{
switch (index) {
case 0: ShowTownDirectory(); break;
case 1: // setting could be changed when the dropdown was open
if (_settings_game.economy.found_town != TF_FORBIDDEN) ShowFoundTownWindow();
break;
}
return CBF_NONE;
}
/* --- Subidies button menu --- */
static CallBackFunction ToolbarSubsidiesClick(Window *w)
{
PopupMainToolbMenu(w, WID_TN_SUBSIDIES, STR_SUBSIDIES_MENU_SUBSIDIES, 1);
return CBF_NONE;
}
/**
* Handle click on the entry in the Subsidies menu.
*
* @param index Unused.
* @return #CBF_NONE
*/
static CallBackFunction MenuClickSubsidies(int index)
{
switch (index) {
case 0: ShowSubsidiesList(); break;
}
return CBF_NONE;
}
/* --- Stations button menu --- */
static CallBackFunction ToolbarStationsClick(Window *w)
{
PopupMainCompanyToolbMenu(w, WID_TN_STATIONS);
return CBF_NONE;
}
/**
* Handle click on the entry in the Stations menu
*
* @param index CompanyID to show station list for
* @return #CBF_NONE
*/
static CallBackFunction MenuClickStations(int index)
{
ShowCompanyStations((CompanyID)index);
return CBF_NONE;
}
/* --- Finances button menu --- */
static CallBackFunction ToolbarFinancesClick(Window *w)
{
PopupMainCompanyToolbMenu(w, WID_TN_FINANCES);
return CBF_NONE;
}
/**
* Handle click on the entry in the finances overview menu.
*
* @param index CompanyID to show finances for.
* @return #CBF_NONE
*/
static CallBackFunction MenuClickFinances(int index)
{
ShowCompanyFinances((CompanyID)index);
return CBF_NONE;
}
/* --- Company's button menu --- */
static CallBackFunction ToolbarCompaniesClick(Window *w)
{
PopupMainCompanyToolbMenu(w, WID_TN_COMPANIES, 0);
return CBF_NONE;
}
/**
* Handle click on the entry in the Company menu.
*
* @param index Menu entry to handle.
* @return #CBF_NONE
*/
static CallBackFunction MenuClickCompany(int index)
{
#ifdef ENABLE_NETWORK
if (_networking) {
switch (index) {
case CTMN_CLIENT_LIST:
ShowClientList();
return CBF_NONE;
case CTMN_NEW_COMPANY:
if (_network_server) {
DoCommandP(0, CCA_NEW, _network_own_client_id, CMD_COMPANY_CTRL);
} else {
NetworkSendCommand(0, CCA_NEW, 0, CMD_COMPANY_CTRL, NULL, NULL, _local_company);
}
return CBF_NONE;
case CTMN_SPECTATE:
if (_network_server) {
NetworkServerDoMove(CLIENT_ID_SERVER, COMPANY_SPECTATOR);
MarkWholeScreenDirty();
} else {
NetworkClientRequestMove(COMPANY_SPECTATOR);
}
return CBF_NONE;
}
}
#endif /* ENABLE_NETWORK */
ShowCompany((CompanyID)index);
return CBF_NONE;
}
/* --- Story button menu --- */
static CallBackFunction ToolbarStoryClick(Window *w)
{
PopupMainCompanyToolbMenu(w, WID_TN_STORY, 0);
return CBF_NONE;
}
/**
* Handle click on the entry in the Story menu
*
* @param index CompanyID to show story book for
* @return #CBF_NONE
*/
static CallBackFunction MenuClickStory(int index)
{
ShowStoryBook(index == CTMN_SPECTATOR ? INVALID_COMPANY : (CompanyID)index);
return CBF_NONE;
}
/* --- Goal button menu --- */
static CallBackFunction ToolbarGoalClick(Window *w)
{
PopupMainCompanyToolbMenu(w, WID_TN_GOAL, 0);
return CBF_NONE;
}
/**
* Handle click on the entry in the Goal menu
*
* @param index CompanyID to show story book for
* @return #CBF_NONE
*/
static CallBackFunction MenuClickGoal(int index)
{
ShowGoalsList(index == CTMN_SPECTATOR ? INVALID_COMPANY : (CompanyID)index);
return CBF_NONE;
}
/* --- Graphs button menu --- */
static CallBackFunction ToolbarGraphsClick(Window *w)
{
PopupMainToolbMenu(w, WID_TN_GRAPHS, STR_GRAPH_MENU_OPERATING_PROFIT_GRAPH, (_toolbar_mode == TB_NORMAL) ? 6 : 8);
return CBF_NONE;
}
/**
* Handle click on the entry in the Graphs menu.
*
* @param index Graph to show.
* @return #CBF_NONE
*/
static CallBackFunction MenuClickGraphs(int index)
{
switch (index) {
case 0: ShowOperatingProfitGraph(); break;
case 1: ShowIncomeGraph(); break;
case 2: ShowDeliveredCargoGraph(); break;
case 3: ShowPerformanceHistoryGraph(); break;
case 4: ShowCompanyValueGraph(); break;
case 5: ShowCargoPaymentRates(); break;
/* functions for combined graphs/league button */
case 6: ShowCompanyLeagueTable(); break;
case 7: ShowPerformanceRatingDetail(); break;
}
return CBF_NONE;
}
/* --- League button menu --- */
static CallBackFunction ToolbarLeagueClick(Window *w)
{
PopupMainToolbMenu(w, WID_TN_LEAGUE, STR_GRAPH_MENU_COMPANY_LEAGUE_TABLE, _networking ? 2 : 3);
return CBF_NONE;
}
/**
* Handle click on the entry in the CompanyLeague menu.
*
* @param index Menu entry number.
* @return #CBF_NONE
*/
static CallBackFunction MenuClickLeague(int index)
{
switch (index) {
case 0: ShowCompanyLeagueTable(); break;
case 1: ShowPerformanceRatingDetail(); break;
case 2: ShowHighscoreTable(); break;
}
return CBF_NONE;
}
/* --- Industries button menu --- */
static CallBackFunction ToolbarIndustryClick(Window *w)
{
/* Disable build-industry menu if we are a spectator */
PopupMainToolbMenu(w, WID_TN_INDUSTRIES, STR_INDUSTRY_MENU_INDUSTRY_DIRECTORY, (_local_company == COMPANY_SPECTATOR) ? 2 : 3);
return CBF_NONE;
}
/**
* Handle click on the entry in the Industry menu.
*
* @param index Menu entry number.
* @return #CBF_NONE
*/
static CallBackFunction MenuClickIndustry(int index)
{
switch (index) {
case 0: ShowIndustryDirectory(); break;
case 1: ShowIndustryCargoesWindow(); break;
case 2: ShowBuildIndustryWindow(); break;
}
return CBF_NONE;
}
/* --- Trains button menu + 1 helper function for all vehicles. --- */
static void ToolbarVehicleClick(Window *w, VehicleType veh)
{
const Vehicle *v;
int dis = ~0;
FOR_ALL_VEHICLES(v) {
if (v->type == veh && v->IsPrimaryVehicle()) ClrBit(dis, v->owner);
}
PopupMainCompanyToolbMenu(w, WID_TN_VEHICLE_START + veh, dis);
}
static CallBackFunction ToolbarTrainClick(Window *w)
{
ToolbarVehicleClick(w, VEH_TRAIN);
return CBF_NONE;
}
/**
* Handle click on the entry in the Train menu.
*
* @param index CompanyID to show train list for.
* @return #CBF_NONE
*/
static CallBackFunction MenuClickShowTrains(int index)
{
ShowVehicleListWindow((CompanyID)index, VEH_TRAIN);
return CBF_NONE;
}
/* --- Road vehicle button menu --- */
static CallBackFunction ToolbarRoadClick(Window *w)
{
ToolbarVehicleClick(w, VEH_ROAD);
return CBF_NONE;
}
/**
* Handle click on the entry in the Road Vehicles menu.
*
* @param index CompanyID to show road vehicles list for.
* @return #CBF_NONE
*/
static CallBackFunction MenuClickShowRoad(int index)
{
ShowVehicleListWindow((CompanyID)index, VEH_ROAD);
return CBF_NONE;
}
/* --- Ship button menu --- */
static CallBackFunction ToolbarShipClick(Window *w)
{
ToolbarVehicleClick(w, VEH_SHIP);
return CBF_NONE;
}
/**
* Handle click on the entry in the Ships menu.
*
* @param index CompanyID to show ship list for.
* @return #CBF_NONE
*/
static CallBackFunction MenuClickShowShips(int index)
{
ShowVehicleListWindow((CompanyID)index, VEH_SHIP);
return CBF_NONE;
}
/* --- Aircraft button menu --- */
static CallBackFunction ToolbarAirClick(Window *w)
{
ToolbarVehicleClick(w, VEH_AIRCRAFT);
return CBF_NONE;
}
/**
* Handle click on the entry in the Aircraft menu.
*
* @param index CompanyID to show aircraft list for.
* @return #CBF_NONE
*/
static CallBackFunction MenuClickShowAir(int index)
{
ShowVehicleListWindow((CompanyID)index, VEH_AIRCRAFT);
return CBF_NONE;
}
/* --- Zoom in button --- */
static CallBackFunction ToolbarZoomInClick(Window *w)
{
if (DoZoomInOutWindow(ZOOM_IN, FindWindowById(WC_MAIN_WINDOW, 0))) {
w->HandleButtonClick((_game_mode == GM_EDITOR) ? (byte)WID_TE_ZOOM_IN : (byte)WID_TN_ZOOM_IN);
if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
}
return CBF_NONE;
}
/* --- Zoom out button --- */
static CallBackFunction ToolbarZoomOutClick(Window *w)
{
if (DoZoomInOutWindow(ZOOM_OUT, FindWindowById(WC_MAIN_WINDOW, 0))) {
w->HandleButtonClick((_game_mode == GM_EDITOR) ? (byte)WID_TE_ZOOM_OUT : (byte)WID_TN_ZOOM_OUT);
if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
}
return CBF_NONE;
}
/* --- Rail button menu --- */
static CallBackFunction ToolbarBuildRailClick(Window *w)
{
ShowDropDownList(w, GetRailTypeDropDownList(), _last_built_railtype, WID_TN_RAILS, 140, true, true);
if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
return CBF_NONE;
}
/**
* Handle click on the entry in the Build Rail menu.
*
* @param index RailType to show the build toolbar for.
* @return #CBF_NONE
*/
static CallBackFunction MenuClickBuildRail(int index)
{
_last_built_railtype = (RailType)index;
ShowBuildRailToolbar(_last_built_railtype);
return CBF_NONE;
}
/* --- Road button menu --- */
static CallBackFunction ToolbarBuildRoadClick(Window *w)
{
const Company *c = Company::Get(_local_company);
DropDownList *list = new DropDownList();
/* Road is always visible and available. */
*list->Append() = new DropDownListStringItem(STR_ROAD_MENU_ROAD_CONSTRUCTION, ROADTYPE_ROAD, false);
/* Tram is only visible when there will be a tram, and available when that has been introduced. */
Engine *e;
FOR_ALL_ENGINES_OF_TYPE(e, VEH_ROAD) {
if (!HasBit(e->info.climates, _settings_game.game_creation.landscape)) continue;
if (!HasBit(e->info.misc_flags, EF_ROAD_TRAM)) continue;
*list->Append() = new DropDownListStringItem(STR_ROAD_MENU_TRAM_CONSTRUCTION, ROADTYPE_TRAM, !HasBit(c->avail_roadtypes, ROADTYPE_TRAM));
break;
}
ShowDropDownList(w, list, _last_built_roadtype, WID_TN_ROADS, 140, true, true);
if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
return CBF_NONE;
}
/**
* Handle click on the entry in the Build Road menu.
*
* @param index RoadType to show the build toolbar for.
* @return #CBF_NONE
*/
static CallBackFunction MenuClickBuildRoad(int index)
{
_last_built_roadtype = (RoadType)index;
ShowBuildRoadToolbar(_last_built_roadtype);
return CBF_NONE;
}
/* --- Water button menu --- */
static CallBackFunction ToolbarBuildWaterClick(Window *w)
{
PopupMainToolbMenu(w, WID_TN_WATER, STR_WATERWAYS_MENU_WATERWAYS_CONSTRUCTION, 1);
return CBF_NONE;
}
/**
* Handle click on the entry in the Build Waterways menu.
*
* @param index Unused.
* @return #CBF_NONE
*/
static CallBackFunction MenuClickBuildWater(int index)
{
ShowBuildDocksToolbar();
return CBF_NONE;
}
/* --- Airport button menu --- */
static CallBackFunction ToolbarBuildAirClick(Window *w)
{
PopupMainToolbMenu(w, WID_TN_AIR, STR_AIRCRAFT_MENU_AIRPORT_CONSTRUCTION, 1);
return CBF_NONE;
}
/**
* Handle click on the entry in the Build Air menu.
*
* @param index Unused.
* @return #CBF_NONE
*/
static CallBackFunction MenuClickBuildAir(int index)
{
ShowBuildAirToolbar();
return CBF_NONE;
}
/* --- Forest button menu --- */
static CallBackFunction ToolbarForestClick(Window *w)
{
PopupMainToolbMenu(w, WID_TN_LANDSCAPE, STR_LANDSCAPING_MENU_LANDSCAPING, 3);
return CBF_NONE;
}
/**
* Handle click on the entry in the landscaping menu.
*
* @param index Menu entry clicked.
* @return #CBF_NONE
*/
static CallBackFunction MenuClickForest(int index)
{
switch (index) {
case 0: ShowTerraformToolbar(); break;
case 1: ShowBuildTreesToolbar(); break;
case 2: return SelectSignTool();
}
return CBF_NONE;
}
/* --- Music button menu --- */