56 TB_NORMAL, |
56 TB_NORMAL, |
57 TB_UPPER, |
57 TB_UPPER, |
58 TB_LOWER |
58 TB_LOWER |
59 }; |
59 }; |
60 |
60 |
|
61 enum ToolbarNormalWidgets { |
|
62 TBN_PAUSE = 0, |
|
63 TBN_FASTFORWARD, |
|
64 TBN_SETTINGS, |
|
65 TBN_SAVEGAME, |
|
66 TBN_SMALLMAP, |
|
67 TBN_TOWNDIRECTORY, |
|
68 TBN_SUBSIDIES, |
|
69 TBN_STATIONS, |
|
70 TBN_FINANCES, |
|
71 TBN_PLAYERS, |
|
72 TBN_GRAPHICS, |
|
73 TBN_LEAGUE, |
|
74 TBN_INDUSTRIES, |
|
75 TBN_VEHICLESTART, ///< trains, actually. So following are trucks, boats and planes |
|
76 TBN_TRAINS = TBN_VEHICLESTART, |
|
77 TBN_ROADVEHS, |
|
78 TBN_SHIPS, |
|
79 TBN_AIRCRAFTS, |
|
80 TBN_ZOOMIN, |
|
81 TBN_ZOOMOUT, |
|
82 TBN_RAILS, |
|
83 TBN_ROADS, |
|
84 TBN_WATER, |
|
85 TBN_AIR, |
|
86 TBN_LANDSCAPE, |
|
87 TBN_MUSICSOUND, |
|
88 TBN_NEWSREPORT, |
|
89 TBN_HELP, |
|
90 TBN_SWITCHBAR, ///< only available when toolbar has been split |
|
91 }; |
|
92 |
|
93 enum ToolbarScenEditorWidgets { |
|
94 TBSE_PAUSE = 0, |
|
95 TBSE_FASTFORWARD, |
|
96 TBSE_SAVESCENARIO = 3, |
|
97 TBSE_SPACERPANEL, |
|
98 TBSE_DATEBACKWARD = 6, |
|
99 TBSE_DATEFORWARD, |
|
100 TBSE_ZOOMIN = 9, |
|
101 TBSE_ZOOMOUT, |
|
102 TBSE_LANDGENERATE, |
|
103 TBSE_TOWNGENERATE, |
|
104 TBSE_INDUSTRYGENERATE, |
|
105 TBSE_BUILDROAD, |
|
106 TBSE_PLANTTREES, |
|
107 TBSE_PLACESIGNS, |
|
108 }; |
|
109 |
61 static ToolbarMode _toolbar_mode; |
110 static ToolbarMode _toolbar_mode; |
62 |
111 |
63 static void SelectSignTool() |
112 static void SelectSignTool() |
64 { |
113 { |
65 if (_cursor.sprite == SPR_CURSOR_SIGN) { |
114 if (_cursor.sprite == SPR_CURSOR_SIGN) { |
138 if (HasBit(_display_opt, DO_FULL_ANIMATION)) SetBit(x, 10); |
187 if (HasBit(_display_opt, DO_FULL_ANIMATION)) SetBit(x, 10); |
139 if (HasBit(_display_opt, DO_FULL_DETAIL)) SetBit(x, 11); |
188 if (HasBit(_display_opt, DO_FULL_DETAIL)) SetBit(x, 11); |
140 if (IsTransparencySet(TO_HOUSES)) SetBit(x, 12); |
189 if (IsTransparencySet(TO_HOUSES)) SetBit(x, 12); |
141 if (IsTransparencySet(TO_SIGNS)) SetBit(x, 13); |
190 if (IsTransparencySet(TO_SIGNS)) SetBit(x, 13); |
142 |
191 |
143 PopupMainToolbMenu(w, 2, STR_02C4_GAME_OPTIONS, 14, 0, 0, x); |
192 PopupMainToolbMenu(w, TBN_SETTINGS, STR_02C4_GAME_OPTIONS, 14, 0, 0, x); |
144 } |
193 } |
145 |
194 |
146 static void MenuClickSettings(int index) |
195 static void MenuClickSettings(int index) |
147 { |
196 { |
148 switch (index) { |
197 switch (index) { |
149 case 0: ShowGameOptions(); return; |
198 case 0: ShowGameOptions(); return; |
150 case 1: ShowGameDifficulty(); return; |
199 case 1: ShowGameDifficulty(); return; |
151 case 2: ShowPatchesSelection(); return; |
200 case 2: ShowPatchesSelection(); return; |
152 case 3: ShowNewGRFSettings(!_networking, true, true, &_grfconfig); return; |
201 case 3: ShowNewGRFSettings(!_networking, true, true, &_grfconfig); return; |
153 case 4: ShowTransparencyToolbar(); break; |
202 case 4: ShowTransparencyToolbar(); break; |
154 |
203 |
155 case 6: ToggleBit(_display_opt, DO_SHOW_TOWN_NAMES); break; |
204 case 6: ToggleBit(_display_opt, DO_SHOW_TOWN_NAMES); break; |
156 case 7: ToggleBit(_display_opt, DO_SHOW_STATION_NAMES); break; |
205 case 7: ToggleBit(_display_opt, DO_SHOW_STATION_NAMES); break; |
157 case 8: ToggleBit(_display_opt, DO_SHOW_SIGNS); break; |
206 case 8: ToggleBit(_display_opt, DO_SHOW_SIGNS); break; |
158 case 9: ToggleBit(_display_opt, DO_WAYPOINTS); break; |
207 case 9: ToggleBit(_display_opt, DO_WAYPOINTS); break; |
166 |
215 |
167 /* --- Saving/loading button menu --- */ |
216 /* --- Saving/loading button menu --- */ |
168 |
217 |
169 static void ToolbarSaveClick(Window *w) |
218 static void ToolbarSaveClick(Window *w) |
170 { |
219 { |
171 PopupMainToolbMenu(w, 3, STR_015C_SAVE_GAME, 4); |
220 PopupMainToolbMenu(w, TBN_SAVEGAME, STR_015C_SAVE_GAME, 4); |
172 } |
221 } |
173 |
222 |
174 static void ToolbarScenSaveOrLoad(Window *w) |
223 static void ToolbarScenSaveOrLoad(Window *w) |
175 { |
224 { |
176 PopupMainToolbMenu(w, 3, STR_0292_SAVE_SCENARIO, 6); |
225 PopupMainToolbMenu(w, TBSE_SAVESCENARIO, STR_0292_SAVE_SCENARIO, 6); |
177 } |
226 } |
178 |
227 |
179 static void MenuClickSaveLoad(int index) |
228 static void MenuClickSaveLoad(int index) |
180 { |
229 { |
181 if (_game_mode == GM_EDITOR) { |
230 if (_game_mode == GM_EDITOR) { |
327 /* --- Industries button menu --- */ |
376 /* --- Industries button menu --- */ |
328 |
377 |
329 static void ToolbarIndustryClick(Window *w) |
378 static void ToolbarIndustryClick(Window *w) |
330 { |
379 { |
331 /* Disable build-industry menu if we are a spectator */ |
380 /* Disable build-industry menu if we are a spectator */ |
332 PopupMainToolbMenu(w, 12, STR_INDUSTRY_DIR, 2, (_current_player == PLAYER_SPECTATOR) ? (1 << 1) : 0); |
381 PopupMainToolbMenu(w, TBN_INDUSTRIES, STR_INDUSTRY_DIR, 2, (_current_player == PLAYER_SPECTATOR) ? 2 : 0); |
333 } |
382 } |
334 |
383 |
335 static void MenuClickIndustry(int index) |
384 static void MenuClickIndustry(int index) |
336 { |
385 { |
337 switch (index) { |
386 switch (index) { |
403 /* --- Zoom in button --- */ |
452 /* --- Zoom in button --- */ |
404 |
453 |
405 static void ToolbarZoomInClick(Window *w) |
454 static void ToolbarZoomInClick(Window *w) |
406 { |
455 { |
407 if (DoZoomInOutWindow(ZOOM_IN, FindWindowById(WC_MAIN_WINDOW, 0))) { |
456 if (DoZoomInOutWindow(ZOOM_IN, FindWindowById(WC_MAIN_WINDOW, 0))) { |
408 w->HandleButtonClick(17); |
457 w->HandleButtonClick(TBN_ZOOMIN); |
409 SndPlayFx(SND_15_BEEP); |
458 SndPlayFx(SND_15_BEEP); |
410 } |
459 } |
411 } |
460 } |
412 |
461 |
413 /* --- Zoom out button --- */ |
462 /* --- Zoom out button --- */ |
414 |
463 |
415 static void ToolbarZoomOutClick(Window *w) |
464 static void ToolbarZoomOutClick(Window *w) |
416 { |
465 { |
417 if (DoZoomInOutWindow(ZOOM_OUT, FindWindowById(WC_MAIN_WINDOW, 0))) { |
466 if (DoZoomInOutWindow(ZOOM_OUT, FindWindowById(WC_MAIN_WINDOW, 0))) { |
418 w->HandleButtonClick(18); |
467 w->HandleButtonClick(TBN_ZOOMOUT); |
419 SndPlayFx(SND_15_BEEP); |
468 SndPlayFx(SND_15_BEEP); |
420 } |
469 } |
421 } |
470 } |
422 |
471 |
423 /* --- Rail button menu --- */ |
472 /* --- Rail button menu --- */ |
424 |
473 |
425 static void ToolbarBuildRailClick(Window *w) |
474 static void ToolbarBuildRailClick(Window *w) |
426 { |
475 { |
427 const Player *p = GetPlayer(_local_player); |
476 const Player *p = GetPlayer(_local_player); |
428 PopupMainToolbMenu(w, 19, STR_1015_RAILROAD_CONSTRUCTION, RAILTYPE_END, ~p->avail_railtypes, _last_built_railtype); |
477 PopupMainToolbMenu(w, TBN_RAILS, STR_1015_RAILROAD_CONSTRUCTION, RAILTYPE_END, ~p->avail_railtypes, _last_built_railtype); |
429 } |
478 } |
430 |
479 |
431 static void MenuClickBuildRail(int index) |
480 static void MenuClickBuildRail(int index) |
432 { |
481 { |
433 _last_built_railtype = (RailType)index; |
482 _last_built_railtype = (RailType)index; |
438 |
487 |
439 static void ToolbarBuildRoadClick(Window *w) |
488 static void ToolbarBuildRoadClick(Window *w) |
440 { |
489 { |
441 const Player *p = GetPlayer(_local_player); |
490 const Player *p = GetPlayer(_local_player); |
442 /* The standard road button is *always* available */ |
491 /* The standard road button is *always* available */ |
443 PopupMainToolbMenu(w, 20, STR_180A_ROAD_CONSTRUCTION, 2, ~(p->avail_roadtypes | ROADTYPES_ROAD), _last_built_roadtype); |
492 PopupMainToolbMenu(w, TBN_ROADS, STR_180A_ROAD_CONSTRUCTION, 2, ~(p->avail_roadtypes | ROADTYPES_ROAD), _last_built_roadtype); |
444 } |
493 } |
445 |
494 |
446 static void MenuClickBuildRoad(int index) |
495 static void MenuClickBuildRoad(int index) |
447 { |
496 { |
448 _last_built_roadtype = (RoadType)index; |
497 _last_built_roadtype = (RoadType)index; |
554 } else { |
603 } else { |
555 _toolbar_mode = TB_UPPER; |
604 _toolbar_mode = TB_UPPER; |
556 } |
605 } |
557 |
606 |
558 SplitToolbar(w); |
607 SplitToolbar(w); |
559 w->HandleButtonClick(27); |
608 w->HandleButtonClick(TBN_SWITCHBAR); |
560 SetWindowDirty(w); |
609 SetWindowDirty(w); |
561 SndPlayFx(SND_15_BEEP); |
610 SndPlayFx(SND_15_BEEP); |
562 } |
611 } |
563 |
612 |
564 /* --- Scenario editor specific handlers. */ |
613 /* --- Scenario editor specific handlers. */ |
565 |
614 |
566 static void ToolbarScenDateBackward(Window *w) |
615 static void ToolbarScenDateBackward(Window *w) |
567 { |
616 { |
568 /* don't allow too fast scrolling */ |
617 /* don't allow too fast scrolling */ |
569 if ((w->flags4 & WF_TIMEOUT_MASK) <= 2 << WF_TIMEOUT_SHL) { |
618 if ((w->flags4 & WF_TIMEOUT_MASK) <= 2 << WF_TIMEOUT_SHL) { |
570 w->HandleButtonClick(6); |
619 w->HandleButtonClick(TBSE_DATEBACKWARD); |
571 w->SetDirty(); |
620 w->SetDirty(); |
572 |
621 |
573 _settings_newgame.game_creation.starting_year = Clamp(_settings_newgame.game_creation.starting_year - 1, MIN_YEAR, MAX_YEAR); |
622 _settings_newgame.game_creation.starting_year = Clamp(_settings_newgame.game_creation.starting_year - 1, MIN_YEAR, MAX_YEAR); |
574 SetDate(ConvertYMDToDate(_settings_newgame.game_creation.starting_year, 0, 1)); |
623 SetDate(ConvertYMDToDate(_settings_newgame.game_creation.starting_year, 0, 1)); |
575 } |
624 } |
578 |
627 |
579 static void ToolbarScenDateForward(Window *w) |
628 static void ToolbarScenDateForward(Window *w) |
580 { |
629 { |
581 /* don't allow too fast scrolling */ |
630 /* don't allow too fast scrolling */ |
582 if ((w->flags4 & WF_TIMEOUT_MASK) <= 2 << WF_TIMEOUT_SHL) { |
631 if ((w->flags4 & WF_TIMEOUT_MASK) <= 2 << WF_TIMEOUT_SHL) { |
583 w->HandleButtonClick(7); |
632 w->HandleButtonClick(TBSE_DATEFORWARD); |
584 w->SetDirty(); |
633 w->SetDirty(); |
585 |
634 |
586 _settings_newgame.game_creation.starting_year = Clamp(_settings_newgame.game_creation.starting_year + 1, MIN_YEAR, MAX_YEAR); |
635 _settings_newgame.game_creation.starting_year = Clamp(_settings_newgame.game_creation.starting_year + 1, MIN_YEAR, MAX_YEAR); |
587 SetDate(ConvertYMDToDate(_settings_newgame.game_creation.starting_year, 0, 1)); |
636 SetDate(ConvertYMDToDate(_settings_newgame.game_creation.starting_year, 0, 1)); |
588 } |
637 } |
596 } |
645 } |
597 |
646 |
598 static void ToolbarScenZoomIn(Window *w) |
647 static void ToolbarScenZoomIn(Window *w) |
599 { |
648 { |
600 if (DoZoomInOutWindow(ZOOM_IN, FindWindowById(WC_MAIN_WINDOW, 0))) { |
649 if (DoZoomInOutWindow(ZOOM_IN, FindWindowById(WC_MAIN_WINDOW, 0))) { |
601 w->HandleButtonClick(9); |
650 w->HandleButtonClick(TBSE_ZOOMIN); |
602 SndPlayFx(SND_15_BEEP); |
651 SndPlayFx(SND_15_BEEP); |
603 } |
652 } |
604 } |
653 } |
605 |
654 |
606 static void ToolbarScenZoomOut(Window *w) |
655 static void ToolbarScenZoomOut(Window *w) |
607 { |
656 { |
608 if (DoZoomInOutWindow(ZOOM_OUT, FindWindowById(WC_MAIN_WINDOW, 0))) { |
657 if (DoZoomInOutWindow(ZOOM_OUT, FindWindowById(WC_MAIN_WINDOW, 0))) { |
609 w->HandleButtonClick(10); |
658 w->HandleButtonClick(TBSE_ZOOMOUT); |
610 SndPlayFx(SND_15_BEEP); |
659 SndPlayFx(SND_15_BEEP); |
611 } |
660 } |
612 } |
661 } |
613 |
662 |
614 static void ToolbarScenGenLand(Window *w) |
663 static void ToolbarScenGenLand(Window *w) |
615 { |
664 { |
616 w->HandleButtonClick(11); |
665 w->HandleButtonClick(TBSE_LANDGENERATE); |
617 SndPlayFx(SND_15_BEEP); |
666 SndPlayFx(SND_15_BEEP); |
618 |
667 |
619 ShowEditorTerraformToolbar(); |
668 ShowEditorTerraformToolbar(); |
620 } |
669 } |
621 |
670 |
622 |
671 |
623 static void ToolbarScenGenTown(Window *w) |
672 static void ToolbarScenGenTown(Window *w) |
624 { |
673 { |
625 w->HandleButtonClick(12); |
674 w->HandleButtonClick(TBSE_TOWNGENERATE); |
626 SndPlayFx(SND_15_BEEP); |
675 SndPlayFx(SND_15_BEEP); |
627 ShowBuildTownWindow(); |
676 ShowBuildTownWindow(); |
628 } |
677 } |
629 |
678 |
630 static void ToolbarScenGenIndustry(Window *w) |
679 static void ToolbarScenGenIndustry(Window *w) |
631 { |
680 { |
632 w->HandleButtonClick(13); |
681 w->HandleButtonClick(TBSE_INDUSTRYGENERATE); |
633 SndPlayFx(SND_15_BEEP); |
682 SndPlayFx(SND_15_BEEP); |
634 ShowBuildIndustryWindow(); |
683 ShowBuildIndustryWindow(); |
635 } |
684 } |
636 |
685 |
637 static void ToolbarScenBuildRoad(Window *w) |
686 static void ToolbarScenBuildRoad(Window *w) |
638 { |
687 { |
639 w->HandleButtonClick(14); |
688 w->HandleButtonClick(TBSE_BUILDROAD); |
640 SndPlayFx(SND_15_BEEP); |
689 SndPlayFx(SND_15_BEEP); |
641 ShowBuildRoadScenToolbar(); |
690 ShowBuildRoadScenToolbar(); |
642 } |
691 } |
643 |
692 |
644 static void ToolbarScenPlantTrees(Window *w) |
693 static void ToolbarScenPlantTrees(Window *w) |
645 { |
694 { |
646 w->HandleButtonClick(15); |
695 w->HandleButtonClick(TBSE_PLANTTREES); |
647 SndPlayFx(SND_15_BEEP); |
696 SndPlayFx(SND_15_BEEP); |
648 ShowBuildTreesToolbar(); |
697 ShowBuildTreesToolbar(); |
649 } |
698 } |
650 |
699 |
651 static void ToolbarScenPlaceSign(Window *w) |
700 static void ToolbarScenPlaceSign(Window *w) |
652 { |
701 { |
653 w->HandleButtonClick(16); |
702 w->HandleButtonClick(TBSE_PLACESIGNS); |
654 SndPlayFx(SND_15_BEEP); |
703 SndPlayFx(SND_15_BEEP); |
655 SelectSignTool(); |
704 SelectSignTool(); |
656 } |
705 } |
657 |
706 |
658 static void ToolbarBtn_NULL(Window *w) |
707 static void ToolbarBtn_NULL(Window *w) |
664 static void ResizeToolbar(Window *w) |
713 static void ResizeToolbar(Window *w) |
665 { |
714 { |
666 /* There are 27 buttons plus some spacings if the space allows it */ |
715 /* There are 27 buttons plus some spacings if the space allows it */ |
667 uint button_width; |
716 uint button_width; |
668 uint spacing; |
717 uint spacing; |
669 if (w->width >= 27 * 22) { |
718 if (w->width >= (int)w->widget_count * 22) { |
670 button_width = 22; |
719 button_width = 22; |
671 spacing = w->width - (27 * button_width); |
720 spacing = w->width - (w->widget_count * button_width); |
672 } else { |
721 } else { |
673 button_width = w->width / 27; |
722 button_width = w->width / w->widget_count; |
674 spacing = 0; |
723 spacing = 0; |
675 } |
724 } |
|
725 |
676 uint extra_spacing_at[] = { 4, 8, 13, 17, 19, 24, 0 }; |
726 uint extra_spacing_at[] = { 4, 8, 13, 17, 19, 24, 0 }; |
677 |
727 uint i = 0; |
678 for (uint i = 0, x = 0, j = 0; i < 27; i++) { |
728 for (uint x = 0, j = 0; i < w->widget_count; i++) { |
679 if (extra_spacing_at[j] == i) { |
729 if (extra_spacing_at[j] == i) { |
680 j++; |
730 j++; |
681 uint add = spacing / (lengthof(extra_spacing_at) - j); |
731 uint add = spacing / (lengthof(extra_spacing_at) - j); |
682 spacing -= add; |
732 spacing -= add; |
683 x += add; |
733 x += add; |
684 } |
734 } |
685 |
735 |
686 w->widget[i].type = WWT_IMGBTN; |
736 w->widget[i].type = WWT_IMGBTN; |
687 w->widget[i].left = x; |
737 w->widget[i].left = x; |
688 x += (spacing != 0) ? button_width : (w->width - x) / (27 - i); |
738 x += (spacing != 0) ? button_width : (w->width - x) / (w->widget_count - i); |
689 w->widget[i].right = x - 1; |
739 w->widget[i].right = x - 1; |
690 } |
740 } |
691 |
741 |
692 w->widget[27].type = WWT_EMPTY; |
742 w->widget[i].type = WWT_EMPTY; // i now points to the last item |
693 _toolbar_mode = TB_NORMAL; |
743 _toolbar_mode = TB_NORMAL; |
694 } |
744 } |
695 |
745 |
696 /* --- Split the toolbar */ |
746 /* --- Split the toolbar */ |
697 |
747 |
728 uint max_icons = max(14U, (w->width + icon_size / 2) / icon_size); |
778 uint max_icons = max(14U, (w->width + icon_size / 2) / icon_size); |
729 |
779 |
730 assert(max_icons >= 14 && max_icons <= 19); |
780 assert(max_icons >= 14 && max_icons <= 19); |
731 |
781 |
732 /* first hide all icons */ |
782 /* first hide all icons */ |
733 for (uint i = 0; i < 27; i++) { |
783 for (uint i = 0; i < w->widget_count; i++) { |
734 w->widget[i].type = WWT_EMPTY; |
784 w->widget[i].type = WWT_EMPTY; |
735 } |
785 } |
736 |
786 |
737 /* now activate them all on their proper positions */ |
787 /* now activate them all on their proper positions */ |
738 for (uint i = 0, x = 0, n = max_icons - 14; i < max_icons; i++) { |
788 for (uint i = 0, x = 0, n = max_icons - 14; i < max_icons; i++) { |
780 }; |
830 }; |
781 |
831 |
782 struct MainToolbarWindow : Window { |
832 struct MainToolbarWindow : Window { |
783 MainToolbarWindow(const WindowDesc *desc) : Window(desc) |
833 MainToolbarWindow(const WindowDesc *desc) : Window(desc) |
784 { |
834 { |
785 this->SetWidgetDisabledState(0, _networking && !_network_server); // if not server, disable pause button |
835 this->SetWidgetDisabledState(TBN_PAUSE, _networking && !_network_server); // if not server, disable pause button |
786 this->SetWidgetDisabledState(1, _networking); // if networking, disable fast-forward button |
836 this->SetWidgetDisabledState(TBN_FASTFORWARD, _networking); // if networking, disable fast-forward button |
787 |
837 |
788 CLRBITS(this->flags4, WF_WHITE_BORDER_MASK); |
838 CLRBITS(this->flags4, WF_WHITE_BORDER_MASK); |
789 |
839 |
790 this->FindWindowPlacementAndResize(desc); |
840 this->FindWindowPlacementAndResize(desc); |
791 PositionMainToolbar(this); |
841 PositionMainToolbar(this); |
799 GfxFillRect(0, 0, this->width - 1, this->height - 1, 0xB4 | (1 << PALETTE_MODIFIER_GREYOUT)); |
849 GfxFillRect(0, 0, this->width - 1, this->height - 1, 0xB4 | (1 << PALETTE_MODIFIER_GREYOUT)); |
800 |
850 |
801 /* If spectator, disable all construction buttons |
851 /* If spectator, disable all construction buttons |
802 * ie : Build road, rail, ships, airports and landscaping |
852 * ie : Build road, rail, ships, airports and landscaping |
803 * Since enabled state is the default, just disable when needed */ |
853 * Since enabled state is the default, just disable when needed */ |
804 this->SetWidgetsDisabledState(_current_player == PLAYER_SPECTATOR, 19, 20, 21, 22, 23, WIDGET_LIST_END); |
854 this->SetWidgetsDisabledState(_current_player == PLAYER_SPECTATOR, TBN_RAILS, TBN_ROADS, TBN_WATER, TBN_AIR, TBN_LANDSCAPE, WIDGET_LIST_END); |
805 /* disable company list drop downs, if there are no companies */ |
855 /* disable company list drop downs, if there are no companies */ |
806 this->SetWidgetsDisabledState(ActivePlayerCount() == 0, 7, 8, 13, 14, 15, 16, WIDGET_LIST_END); |
856 this->SetWidgetsDisabledState(ActivePlayerCount() == TBN_PAUSE, TBN_STATIONS, TBN_FINANCES, TBN_TRAINS, TBN_ROADVEHS, TBN_SHIPS, TBN_AIRCRAFTS, WIDGET_LIST_END); |
807 |
857 |
808 this->SetWidgetDisabledState(19, !CanBuildVehicleInfrastructure(VEH_TRAIN)); |
858 this->SetWidgetDisabledState(TBN_RAILS, !CanBuildVehicleInfrastructure(VEH_TRAIN)); |
809 this->SetWidgetDisabledState(22, !CanBuildVehicleInfrastructure(VEH_AIRCRAFT)); |
859 this->SetWidgetDisabledState(TBN_AIR, !CanBuildVehicleInfrastructure(VEH_AIRCRAFT)); |
810 |
860 |
811 this->DrawWidgets(); |
861 this->DrawWidgets(); |
812 } |
862 } |
813 |
863 |
814 virtual void OnClick(Point pt, int widget) |
864 virtual void OnClick(Point pt, int widget) |
864 virtual void OnPlaceObject(Point pt, TileIndex tile) |
914 virtual void OnPlaceObject(Point pt, TileIndex tile) |
865 { |
915 { |
866 _place_proc(tile); |
916 _place_proc(tile); |
867 } |
917 } |
868 |
918 |
869 virtual void OnPlaceObjectAbort() |
|
870 { |
|
871 this->RaiseWidget(25); |
|
872 this->SetDirty(); |
|
873 } |
|
874 |
|
875 virtual void OnTick() |
919 virtual void OnTick() |
876 { |
920 { |
877 if (this->IsWidgetLowered(0) != !!_pause_game) { |
921 if (this->IsWidgetLowered(TBN_PAUSE) != !!_pause_game) { |
878 this->ToggleWidgetLoweredState(0); |
922 this->ToggleWidgetLoweredState(TBN_PAUSE); |
879 this->InvalidateWidget(0); |
923 this->InvalidateWidget(TBN_PAUSE); |
880 } |
924 } |
881 |
925 |
882 if (this->IsWidgetLowered(1) != !!_fast_forward) { |
926 if (this->IsWidgetLowered(TBN_FASTFORWARD) != !!_fast_forward) { |
883 this->ToggleWidgetLoweredState(1); |
927 this->ToggleWidgetLoweredState(TBN_FASTFORWARD); |
884 this->InvalidateWidget(1); |
928 this->InvalidateWidget(TBN_FASTFORWARD); |
885 } |
929 } |
886 } |
930 } |
887 |
931 |
888 virtual void OnResize(Point new_size, Point delta) |
932 virtual void OnResize(Point new_size, Point delta) |
889 { |
933 { |
894 } |
938 } |
895 } |
939 } |
896 |
940 |
897 virtual void OnTimeout() |
941 virtual void OnTimeout() |
898 { |
942 { |
899 for (uint i = 2; i < this->widget_count; i++) { |
943 for (uint i = TBN_SETTINGS; i < this->widget_count; i++) { |
900 if (this->IsWidgetLowered(i)) { |
944 if (this->IsWidgetLowered(i)) { |
901 this->RaiseWidget(i); |
945 this->RaiseWidget(i); |
902 this->InvalidateWidget(i); |
946 this->InvalidateWidget(i); |
903 } |
947 } |
904 } |
948 } |
905 } |
949 } |
906 |
950 |
907 virtual void OnInvalidateData(int data) |
951 virtual void OnInvalidateData(int data) |
908 { |
952 { |
909 if (FindWindowById(WC_MAIN_WINDOW, 0) != NULL) HandleZoomMessage(this, FindWindowById(WC_MAIN_WINDOW, 0)->viewport, 17, 18); |
953 if (FindWindowById(WC_MAIN_WINDOW, 0) != NULL) HandleZoomMessage(this, FindWindowById(WC_MAIN_WINDOW, 0)->viewport, TBN_ZOOMIN, TBN_ZOOMOUT); |
910 } |
954 } |
911 }; |
955 }; |
912 |
956 |
913 static const Widget _toolb_normal_widgets[] = { |
957 static const Widget _toolb_normal_widgets[] = { |
914 { WWT_IMGBTN, RESIZE_LEFT, 14, 0, 0, 0, 21, SPR_IMG_PAUSE, STR_0171_PAUSE_GAME}, |
958 { WWT_IMGBTN, RESIZE_LEFT, 14, 0, 0, 0, 21, SPR_IMG_PAUSE, STR_0171_PAUSE_GAME}, |
998 DoZoomInOutWindow(ZOOM_NONE, this); |
1043 DoZoomInOutWindow(ZOOM_NONE, this); |
999 } |
1044 } |
1000 |
1045 |
1001 virtual void OnPaint() |
1046 virtual void OnPaint() |
1002 { |
1047 { |
1003 this->SetWidgetDisabledState(6, _settings_newgame.game_creation.starting_year <= MIN_YEAR); |
1048 this->SetWidgetDisabledState(TBSE_DATEBACKWARD, _settings_newgame.game_creation.starting_year <= MIN_YEAR); |
1004 this->SetWidgetDisabledState(7, _settings_newgame.game_creation.starting_year >= MAX_YEAR); |
1049 this->SetWidgetDisabledState(TBSE_DATEFORWARD, _settings_newgame.game_creation.starting_year >= MAX_YEAR); |
1005 |
1050 |
1006 /* Draw brown-red toolbar bg. */ |
1051 /* Draw brown-red toolbar bg. */ |
1007 GfxFillRect(0, 0, this->width - 1, this->height - 1, 0xB2); |
1052 GfxFillRect(0, 0, this->width - 1, this->height - 1, 0xB2); |
1008 GfxFillRect(0, 0, this->width - 1, this->height - 1, 0xB4 | (1 << PALETTE_MODIFIER_GREYOUT)); |
1053 GfxFillRect(0, 0, this->width - 1, this->height - 1, 0xB4 | (1 << PALETTE_MODIFIER_GREYOUT)); |
1009 |
1054 |
1010 this->DrawWidgets(); |
1055 this->DrawWidgets(); |
1011 |
1056 |
1012 SetDParam(0, ConvertYMDToDate(_settings_newgame.game_creation.starting_year, 0, 1)); |
1057 SetDParam(0, ConvertYMDToDate(_settings_newgame.game_creation.starting_year, 0, 1)); |
1013 DrawStringCenteredTruncated(this->widget[6].right, this->widget[7].left, 6, STR_00AF, TC_FROMSTRING); |
1058 DrawStringCenteredTruncated(this->widget[TBSE_DATEBACKWARD].right, this->widget[TBSE_DATEFORWARD].left, 6, STR_00AF, TC_FROMSTRING); |
1014 |
1059 |
1015 /* We hide this panel when the toolbar space gets too small */ |
1060 /* We hide this panel when the toolbar space gets too small */ |
1016 if (this->widget[4].left != this->widget[4].right) { |
1061 const Widget *panel = &this->widget[TBSE_SPACERPANEL]; |
1017 DrawStringCenteredTruncated(this->widget[4].left + 1, this->widget[4].right - 1, 1, STR_0221_OPENTTD, TC_FROMSTRING); |
1062 if (panel->left != panel->right) { |
1018 DrawStringCenteredTruncated(this->widget[4].left + 1, this->widget[4].right - 1, 11, STR_0222_SCENARIO_EDITOR, TC_FROMSTRING); |
1063 DrawStringCenteredTruncated(panel->left + 1, panel->right - 1, 1, STR_0221_OPENTTD, TC_FROMSTRING); |
|
1064 DrawStringCenteredTruncated(panel->left + 1, panel->right - 1, 11, STR_0222_SCENARIO_EDITOR, TC_FROMSTRING); |
1019 } |
1065 } |
1020 } |
1066 } |
1021 |
1067 |
1022 virtual void OnClick(Point pt, int widget) |
1068 virtual void OnClick(Point pt, int widget) |
1023 { |
1069 { |
1044 |
1090 |
1045 /* those following are all fall through */ |
1091 /* those following are all fall through */ |
1046 case WKC_NUM_PLUS: |
1092 case WKC_NUM_PLUS: |
1047 case WKC_EQUALS: |
1093 case WKC_EQUALS: |
1048 case WKC_SHIFT | WKC_EQUALS: |
1094 case WKC_SHIFT | WKC_EQUALS: |
1049 case WKC_SHIFT | WKC_F5: ToolbarZoomInClick(this); break; |
1095 case WKC_SHIFT | WKC_F5: ToolbarScenZoomIn(this); break; |
1050 |
1096 |
1051 /* those following are all fall through */ |
1097 /* those following are all fall through */ |
1052 case WKC_NUM_MINUS: |
1098 case WKC_NUM_MINUS: |
1053 case WKC_MINUS: |
1099 case WKC_MINUS: |
1054 case WKC_SHIFT | WKC_MINUS: |
1100 case WKC_SHIFT | WKC_MINUS: |
1055 case WKC_SHIFT | WKC_F6: ToolbarZoomOutClick(this); break; |
1101 case WKC_SHIFT | WKC_F6: ToolbarScenZoomOut(this); break; |
1056 |
1102 |
1057 case 'L': ShowEditorTerraformToolbar(); break; |
1103 case 'L': ShowEditorTerraformToolbar(); break; |
1058 case 'M': ShowSmallMap(); break; |
1104 case 'M': ShowSmallMap(); break; |
1059 case 'V': ShowExtraViewPortWindow(); break; |
1105 case 'V': ShowExtraViewPortWindow(); break; |
1060 default: return ES_NOT_HANDLED; |
1106 default: return ES_NOT_HANDLED; |
1091 buttons_width = this->width - 130; |
1131 buttons_width = this->width - 130; |
1092 spacing = 0; |
1132 spacing = 0; |
1093 } |
1133 } |
1094 uint extra_spacing_at[] = { 3, 4, 7, 8, 10, 16, 0 }; |
1134 uint extra_spacing_at[] = { 3, 4, 7, 8, 10, 16, 0 }; |
1095 |
1135 |
1096 /* Yes, it defines about 27 widgets for this toolbar */ |
1136 for (uint i = 0, x = 0, j = 0, b = 0; i < this->widget_count; i++) { |
1097 for (uint i = 0, x = 0, j = 0, b = 0; i < 27; i++) { |
|
1098 switch (i) { |
1137 switch (i) { |
1099 case 4: |
1138 case 4: |
1100 this->widget[i].left = x; |
1139 this->widget[i].left = x; |
1101 if (this->width < normal_min_width) { |
1140 if (this->width < normal_min_width) { |
1102 this->widget[i].right = x; |
1141 this->widget[i].right = x; |
1140 } |
1179 } |
1141 } |
1180 } |
1142 |
1181 |
1143 virtual void OnTick() |
1182 virtual void OnTick() |
1144 { |
1183 { |
1145 if (this->IsWidgetLowered(0) != !!_pause_game) { |
1184 if (this->IsWidgetLowered(TBSE_PAUSE) != !!_pause_game) { |
1146 this->ToggleWidgetLoweredState(0); |
1185 this->ToggleWidgetLoweredState(TBSE_PAUSE); |
1147 this->SetDirty(); |
1186 this->SetDirty(); |
1148 } |
1187 } |
1149 |
1188 |
1150 if (this->IsWidgetLowered(1) != !!_fast_forward) { |
1189 if (this->IsWidgetLowered(TBSE_FASTFORWARD) != !!_fast_forward) { |
1151 this->ToggleWidgetLoweredState(1); |
1190 this->ToggleWidgetLoweredState(TBSE_FASTFORWARD); |
1152 this->SetDirty(); |
1191 this->SetDirty(); |
1153 } |
1192 } |
1154 } |
1193 } |
1155 |
1194 |
1156 virtual void OnInvalidateData(int data) |
1195 virtual void OnInvalidateData(int data) |
1157 { |
1196 { |
1158 if (FindWindowById(WC_MAIN_WINDOW, 0) != NULL) HandleZoomMessage(this, FindWindowById(WC_MAIN_WINDOW, 0)->viewport, 17, 18); |
1197 if (FindWindowById(WC_MAIN_WINDOW, 0) != NULL) HandleZoomMessage(this, FindWindowById(WC_MAIN_WINDOW, 0)->viewport, TBSE_ZOOMIN, TBSE_ZOOMOUT); |
1159 } |
1198 } |
1160 }; |
1199 }; |
1161 |
1200 |
1162 static const Widget _toolb_scen_widgets[] = { |
1201 static const Widget _toolb_scen_widgets[] = { |
1163 { WWT_IMGBTN, RESIZE_LEFT, 14, 0, 0, 0, 21, SPR_IMG_PAUSE, STR_0171_PAUSE_GAME}, |
1202 { WWT_IMGBTN, RESIZE_LEFT, 14, 0, 0, 0, 21, SPR_IMG_PAUSE, STR_0171_PAUSE_GAME}, |
1407 Window(x, y, width, height, WC_TOOLBAR_MENU, widgets), |
1446 Window(x, y, width, height, WC_TOOLBAR_MENU, widgets), |
1408 item_count(0), main_button(main_button), action_id(main_button), gray_items(gray) |
1447 item_count(0), main_button(main_button), action_id(main_button), gray_items(gray) |
1409 { |
1448 { |
1410 this->flags4 &= ~WF_WHITE_BORDER_MASK; |
1449 this->flags4 &= ~WF_WHITE_BORDER_MASK; |
1411 this->sel_index = (_local_player != PLAYER_SPECTATOR) ? _local_player : GetPlayerIndexFromMenu(0); |
1450 this->sel_index = (_local_player != PLAYER_SPECTATOR) ? _local_player : GetPlayerIndexFromMenu(0); |
1412 if (_networking && main_button == 9) { |
1451 if (_networking && main_button == TBN_PLAYERS) { |
1413 if (_local_player != PLAYER_SPECTATOR) { |
1452 if (_local_player != PLAYER_SPECTATOR) { |
1414 this->sel_index++; |
1453 this->sel_index++; |
1415 } else { |
1454 } else { |
1416 /* Select client list by default for spectators */ |
1455 /* Select client list by default for spectators */ |
1417 this->sel_index = 0; |
1456 this->sel_index = 0; |
1455 int y = 1; |
1494 int y = 1; |
1456 int sel = this->sel_index; |
1495 int sel = this->sel_index; |
1457 int gray = this->gray_items; |
1496 int gray = this->gray_items; |
1458 |
1497 |
1459 /* 9 = playerlist */ |
1498 /* 9 = playerlist */ |
1460 if (_networking && this->main_button == 9) { |
1499 if (_networking && this->main_button == TBN_PLAYERS) { |
1461 if (sel == 0) { |
1500 if (sel == 0) { |
1462 GfxFillRect(x, y, x + 238, y + 9, 0); |
1501 GfxFillRect(x, y, x + 238, y + 9, 0); |
1463 } |
1502 } |
1464 DrawString(x + 19, y, STR_NETWORK_CLIENT_LIST, TC_FROMSTRING); |
1503 DrawString(x + 19, y, STR_NETWORK_CLIENT_LIST, TC_FROMSTRING); |
1465 y += 10; |
1504 y += 10; |
1494 |
1533 |
1495 if (_left_button_down) { |
1534 if (_left_button_down) { |
1496 this->UpdatePlayerMenuHeight(); |
1535 this->UpdatePlayerMenuHeight(); |
1497 /* We have a new entry at the top of the list of menu 9 when networking |
1536 /* We have a new entry at the top of the list of menu 9 when networking |
1498 * so keep that in count */ |
1537 * so keep that in count */ |
1499 if (_networking && this->main_button == 9) { |
1538 if (_networking && this->main_button == TBN_PLAYERS) { |
1500 if (index > 0) index = GetPlayerIndexFromMenu(index - 1) + 1; |
1539 if (index > 0) index = GetPlayerIndexFromMenu(index - 1) + 1; |
1501 } else { |
1540 } else { |
1502 index = GetPlayerIndexFromMenu(index); |
1541 index = GetPlayerIndexFromMenu(index); |
1503 } |
1542 } |
1504 |
1543 |