54 /* When adding widgets, place them as you would place them for the ship depot and define how you want it to move in widget_moves[] |
55 /* When adding widgets, place them as you would place them for the ship depot and define how you want it to move in widget_moves[] |
55 * If you want a widget for one window only, set it to be hidden in ShowDepotWindow() for the windows where you don't want it |
56 * If you want a widget for one window only, set it to be hidden in ShowDepotWindow() for the windows where you don't want it |
56 * NOTE: the train only widgets are moved/resized in ShowDepotWindow() so they follow certain other widgets if they are moved to ensure that they stick together. |
57 * NOTE: the train only widgets are moved/resized in ShowDepotWindow() so they follow certain other widgets if they are moved to ensure that they stick together. |
57 * Changing the size of those here will not have an effect at all. It should be done in ShowDepotWindow() |
58 * Changing the size of those here will not have an effect at all. It should be done in ShowDepotWindow() |
58 */ |
59 */ |
|
60 |
|
61 /* |
|
62 * Some of the widgets are placed outside the window (negative coordinates). |
|
63 * The reason is that they are placed relatively to the matrix and the matrix is just one pixel (in 0, 14). |
|
64 * The matrix and the rest of the window will be resized when the size of the boxes is set and then all the widgets will be inside the window. |
|
65 */ |
59 static const Widget _depot_widgets[] = { |
66 static const Widget _depot_widgets[] = { |
60 { WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, // DEPOT_WIDGET_CLOSEBOX |
67 { WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, // DEPOT_WIDGET_CLOSEBOX |
61 { WWT_CAPTION, RESIZE_RIGHT, 14, 11, 292, 0, 13, 0x0, STR_018C_WINDOW_TITLE_DRAG_THIS}, // DEPOT_WIDGET_CAPTION |
68 { WWT_CAPTION, RESIZE_RIGHT, 14, 11, 23, 0, 13, 0x0, STR_018C_WINDOW_TITLE_DRAG_THIS}, // DEPOT_WIDGET_CAPTION |
62 { WWT_STICKYBOX, RESIZE_LR, 14, 293, 304, 0, 13, 0x0, STR_STICKY_BUTTON}, // DEPOT_WIDGET_STICKY |
69 { WWT_STICKYBOX, RESIZE_LR, 14, 24, 35, 0, 13, 0x0, STR_STICKY_BUTTON}, // DEPOT_WIDGET_STICKY |
63 |
70 |
64 /* Widgets are set up run-time */ |
71 /* Widgets are set up run-time */ |
65 { WWT_IMGBTN, RESIZE_LRB, 14, 270, 292, 14, 37, 0x0, STR_NULL}, // DEPOT_WIDGET_SELL |
72 { WWT_IMGBTN, RESIZE_LRB, 14, 1, 23, 14, -32, 0x0, STR_NULL}, // DEPOT_WIDGET_SELL |
66 { WWT_IMGBTN, RESIZE_LRTB, 14, 270, 292, 14, 37, SPR_SELL_CHAIN_TRAIN,STR_DRAG_WHOLE_TRAIN_TO_SELL_TIP}, // DEPOT_WIDGET_SELL_CHAIN, trains only |
73 { WWT_IMGBTN, RESIZE_LRTB, 14, 1, 23, -55, -32, SPR_SELL_CHAIN_TRAIN,STR_DRAG_WHOLE_TRAIN_TO_SELL_TIP}, // DEPOT_WIDGET_SELL_CHAIN, trains only |
67 { WWT_PUSHIMGBTN, RESIZE_LRTB, 14, 270, 292, 38, 60, 0x0, STR_NULL}, // DEPOT_WIDGET_SELL_ALL |
74 { WWT_PUSHIMGBTN, RESIZE_LRTB, 14, 1, 23, -31, -9, 0x0, STR_NULL}, // DEPOT_WIDGET_SELL_ALL |
68 { WWT_PUSHIMGBTN, RESIZE_LRTB, 14, 270, 292, 61, 83, 0x0, STR_NULL}, // DEPOT_WIDGET_AUTOREPLACE |
75 { WWT_PUSHIMGBTN, RESIZE_LRTB, 14, 1, 23, -8, 14, 0x0, STR_NULL}, // DEPOT_WIDGET_AUTOREPLACE |
69 |
76 |
70 { WWT_MATRIX, RESIZE_RB, 14, 0, 269, 14, 83, 0x0, STR_NULL}, // DEPOT_WIDGET_MATRIX |
77 { WWT_MATRIX, RESIZE_RB, 14, 0, 0, 14, 14, 0x0, STR_NULL}, // DEPOT_WIDGET_MATRIX |
71 { WWT_SCROLLBAR, RESIZE_LRB, 14, 293, 304, 14, 83, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, // DEPOT_WIDGET_V_SCROLL |
78 { WWT_SCROLLBAR, RESIZE_LRB, 14, 24, 35, 14, 14, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, // DEPOT_WIDGET_V_SCROLL |
72 |
79 |
73 { WWT_HSCROLLBAR, RESIZE_RTB, 14, 0, 269, 72, 83, 0x0, STR_HSCROLL_BAR_SCROLLS_LIST}, // DEPOT_WIDGET_H_SCROLL, trains only |
80 { WWT_HSCROLLBAR, RESIZE_RTB, 14, 0, 0, 3, 14, 0x0, STR_HSCROLL_BAR_SCROLLS_LIST}, // DEPOT_WIDGET_H_SCROLL, trains only |
74 |
81 |
75 /* The buttons in the bottom of the window. left and right is not important as they are later resized to be equal in size |
82 /* The buttons in the bottom of the window. left and right is not important as they are later resized to be equal in size |
76 * This calculation is based on right in DEPOT_WIDGET_LOCATION and it presumes left of DEPOT_WIDGET_BUILD is 0 */ |
83 * This calculation is based on right in DEPOT_WIDGET_LOCATION and it presumes left of DEPOT_WIDGET_BUILD is 0 */ |
77 { WWT_PUSHTXTBTN, RESIZE_TB, 14, 0, 85, 84, 95, 0x0, STR_NULL}, // DEPOT_WIDGET_BUILD |
84 { WWT_PUSHTXTBTN, RESIZE_TB, 14, 0, 0, 15, 26, 0x0, STR_NULL}, // DEPOT_WIDGET_BUILD |
78 { WWT_TEXTBTN, RESIZE_TB, 14, 86, 170, 84, 95, 0x0, STR_NULL}, // DEPOT_WIDGET_CLONE |
85 { WWT_TEXTBTN, RESIZE_TB, 14, 0, 0, 15, 26, 0x0, STR_NULL}, // DEPOT_WIDGET_CLONE |
79 { WWT_PUSHTXTBTN, RESIZE_RTB, 14, 171, 257, 84, 95, STR_00E4_LOCATION, STR_NULL}, // DEPOT_WIDGET_LOCATION |
86 { WWT_PUSHTXTBTN, RESIZE_RTB, 14, 0, -12, 15, 26, STR_00E4_LOCATION, STR_NULL}, // DEPOT_WIDGET_LOCATION |
80 { WWT_PUSHTXTBTN, RESIZE_LRTB, 14, 258, 269, 84, 95, 0x0, STR_NULL}, // DEPOT_WIDGET_VEHICLE_LIST |
87 { WWT_PUSHTXTBTN, RESIZE_LRTB, 14, -11, 0, 15, 26, 0x0, STR_NULL}, // DEPOT_WIDGET_VEHICLE_LIST |
81 { WWT_PUSHIMGBTN, RESIZE_LRTB, 14, 270, 280, 84, 95, SPR_FLAG_VEH_STOPPED,STR_NULL}, // DEPOT_WIDGET_STOP_ALL |
88 { WWT_PUSHIMGBTN, RESIZE_LRTB, 14, 1, 11, 15, 26, SPR_FLAG_VEH_STOPPED,STR_NULL}, // DEPOT_WIDGET_STOP_ALL |
82 { WWT_PUSHIMGBTN, RESIZE_LRTB, 14, 281, 292, 84, 95, SPR_FLAG_VEH_RUNNING,STR_NULL}, // DEPOT_WIDGET_START_ALL |
89 { WWT_PUSHIMGBTN, RESIZE_LRTB, 14, 12, 23, 15, 26, SPR_FLAG_VEH_RUNNING,STR_NULL}, // DEPOT_WIDGET_START_ALL |
83 { WWT_RESIZEBOX, RESIZE_LRTB, 14, 293, 304, 84, 95, 0x0, STR_RESIZE_BUTTON}, // DEPOT_WIDGET_RESIZE |
90 { WWT_RESIZEBOX, RESIZE_LRTB, 14, 24, 35, 15, 26, 0x0, STR_RESIZE_BUTTON}, // DEPOT_WIDGET_RESIZE |
84 { WIDGETS_END}, |
91 { WIDGETS_END}, |
85 }; |
92 }; |
86 |
93 |
87 static void DepotWndProc(Window *w, WindowEvent *e); |
94 static void DepotWndProc(Window *w, WindowEvent *e); |
88 |
95 |
89 static const WindowDesc _train_depot_desc = { |
96 static const WindowDesc _train_depot_desc = { |
90 WDP_AUTO, WDP_AUTO, 305, 96, |
97 WDP_AUTO, WDP_AUTO, 36, 27, |
91 WC_VEHICLE_DEPOT, WC_NONE, |
98 WC_VEHICLE_DEPOT, WC_NONE, |
92 WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE, |
99 WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE, |
93 _depot_widgets, |
100 _depot_widgets, |
94 DepotWndProc |
101 DepotWndProc |
95 }; |
102 }; |
96 |
103 |
97 static const WindowDesc _road_depot_desc = { |
104 static const WindowDesc _road_depot_desc = { |
98 WDP_AUTO, WDP_AUTO, 305, 96, |
105 WDP_AUTO, WDP_AUTO, 36, 27, |
99 WC_VEHICLE_DEPOT, WC_NONE, |
106 WC_VEHICLE_DEPOT, WC_NONE, |
100 WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE, |
107 WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE, |
101 _depot_widgets, |
108 _depot_widgets, |
102 DepotWndProc |
109 DepotWndProc |
103 }; |
110 }; |
104 |
111 |
105 static const WindowDesc _ship_depot_desc = { |
112 static const WindowDesc _ship_depot_desc = { |
106 WDP_AUTO, WDP_AUTO, 305, 96, |
113 WDP_AUTO, WDP_AUTO, 36, 27, |
107 WC_VEHICLE_DEPOT, WC_NONE, |
114 WC_VEHICLE_DEPOT, WC_NONE, |
108 WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE, |
115 WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE, |
109 _depot_widgets, |
116 _depot_widgets, |
110 DepotWndProc |
117 DepotWndProc |
111 }; |
118 }; |
112 |
119 |
113 static const WindowDesc _aircraft_depot_desc = { |
120 static const WindowDesc _aircraft_depot_desc = { |
114 WDP_AUTO, WDP_AUTO, 305, 96, |
121 WDP_AUTO, WDP_AUTO, 36, 27, |
115 WC_VEHICLE_DEPOT, WC_NONE, |
122 WC_VEHICLE_DEPOT, WC_NONE, |
116 WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE, |
123 WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE, |
117 _depot_widgets, |
124 _depot_widgets, |
118 DepotWndProc |
125 DepotWndProc |
119 }; |
126 }; |
610 w->widget[DEPOT_WIDGET_AUTOREPLACE].data = SPR_REPLACE_AIRCRAFT; |
625 w->widget[DEPOT_WIDGET_AUTOREPLACE].data = SPR_REPLACE_AIRCRAFT; |
611 break; |
626 break; |
612 } |
627 } |
613 } |
628 } |
614 |
629 |
|
630 |
|
631 /* Array to hold the block sizes |
|
632 * First part is the vehicle type, while the last is 0 = x, 1 = y */ |
|
633 uint _block_sizes[4][2]; |
|
634 |
|
635 /* Array to hold the default resize capacities |
|
636 * First part is the vehicle type, while the last is 0 = x, 1 = y */ |
|
637 const uint _resize_cap[][2] = { |
|
638 /* VEH_Train */ {6, 10 * 29 + 36}, // flags, unitnumber and unit count uses a total of 36 pixels and we set default to 10 units |
|
639 /* VEH_Road */ {5, 5}, |
|
640 /* VEH_Ship */ {3, 3}, |
|
641 /* VEH_Aircraft */ {3, 4}, |
|
642 }; |
|
643 |
|
644 static void ResizeDefaultWindowSizeForTrains() |
|
645 { |
|
646 _block_sizes[VEH_Train][0] = 1; |
|
647 _block_sizes[VEH_Train][1] = GetVehicleListHeight(VEH_Train); |
|
648 } |
|
649 |
|
650 static void ResizeDefaultWindowSizeForRoadVehicles() |
|
651 { |
|
652 _block_sizes[VEH_Road][0] = 56; |
|
653 _block_sizes[VEH_Road][1] = GetVehicleListHeight(VEH_Road); |
|
654 } |
|
655 |
|
656 static void ResizeDefaultWindowSize(byte type) |
|
657 { |
|
658 EngineID engine; |
|
659 uint max_width = 0; |
|
660 uint max_height = 0; |
|
661 |
|
662 FOR_ALL_ENGINEIDS_OF_TYPE(engine, type) { |
|
663 uint x, y; |
|
664 |
|
665 switch (type) { |
|
666 default: NOT_REACHED(); |
|
667 case VEH_Ship: GetShipSpriteSize( engine, x, y); break; |
|
668 case VEH_Aircraft: GetAircraftSpriteSize(engine, x, y); break; |
|
669 } |
|
670 if (x > max_width) max_width = x; |
|
671 if (y > max_height) max_height = y; |
|
672 } |
|
673 |
|
674 switch (type) { |
|
675 default: NOT_REACHED(); |
|
676 case VEH_Ship: |
|
677 _block_sizes[VEH_Ship][0] = max(90U, max_width + 20); // we need 20 pixels from the right edge to the sprite |
|
678 break; |
|
679 case VEH_Aircraft: |
|
680 _block_sizes[VEH_Aircraft][0] = max(74U, max_width); |
|
681 break; |
|
682 } |
|
683 _block_sizes[type][1] = max(GetVehicleListHeight(type), max_height); |
|
684 } |
|
685 |
|
686 /* Set the size of the blocks in the window so we can be sure that they are big enough for the vehicle sprites in the current game |
|
687 * We will only need to call this once for each game */ |
|
688 void InitDepotWindowBlockSizes() |
|
689 { |
|
690 ResizeDefaultWindowSizeForTrains(); |
|
691 ResizeDefaultWindowSizeForRoadVehicles(); |
|
692 ResizeDefaultWindowSize(VEH_Ship); |
|
693 ResizeDefaultWindowSize(VEH_Aircraft); |
|
694 } |
|
695 |
615 static void CreateDepotListWindow(Window *w, byte type) |
696 static void CreateDepotListWindow(Window *w, byte type) |
616 { |
697 { |
617 WP(w, depot_d).type = type; |
698 WP(w, depot_d).type = type; |
618 _backup_orders_tile = 0; |
699 _backup_orders_tile = 0; |
619 |
700 |
|
701 assert(IsPlayerBuildableVehicleType(type)); // ensure that we make the call with a valid type |
|
702 |
620 /* Resize the window according to the vehicle type */ |
703 /* Resize the window according to the vehicle type */ |
621 switch (type) { |
704 |
622 default: NOT_REACHED(); |
705 /* Set the number of blocks in each direction */ |
623 case VEH_Train: |
706 w->vscroll.cap = _resize_cap[type][0]; |
624 w->vscroll.cap = 6; |
707 w->hscroll.cap = _resize_cap[type][1]; |
625 w->hscroll.cap = 10 * 29; |
708 |
626 w->resize.step_width = 1; |
709 /* Set the block size */ |
627 ResizeWindow(w, 56, 26); |
710 w->resize.step_width = _block_sizes[type][0]; |
628 break; |
711 w->resize.step_height = _block_sizes[type][1]; |
629 |
712 |
630 case VEH_Road: |
713 /* Enlarge the window to fit with the selected number of blocks of the selected size */ |
631 w->vscroll.cap = 5; |
714 ResizeWindow(w, |
632 w->hscroll.cap = 5; |
715 _block_sizes[type][0] * w->hscroll.cap, |
633 w->resize.step_width = 56; |
716 _block_sizes[type][1] * w->vscroll.cap); |
634 ResizeWindow(w, 10, 0); |
717 |
635 break; |
718 if (type == VEH_Train) { |
636 |
719 /* The train depot has a horizontal scroller so we should make room for it */ |
637 case VEH_Ship: |
720 ResizeWindow(w, 0, 12); |
638 w->vscroll.cap = 3; |
721 /* substract the newly added space from the matrix since it was meant for the scrollbar */ |
639 w->hscroll.cap = 3; |
722 w->widget[DEPOT_WIDGET_MATRIX].bottom -= 12; |
640 w->resize.step_width = 90; |
|
641 ResizeWindow(w, 0, 2); |
|
642 break; |
|
643 |
|
644 case VEH_Aircraft: |
|
645 w->vscroll.cap = 3; |
|
646 w->hscroll.cap = 4; |
|
647 w->resize.step_width = 74; |
|
648 ResizeWindow(w, 26, 2); |
|
649 break; |
|
650 } |
723 } |
651 |
724 |
652 /* Set the minimum window size to the current window size */ |
725 /* Set the minimum window size to the current window size */ |
653 w->resize.width = w->width; |
726 w->resize.width = w->width; |
654 w->resize.height = w->height; |
727 w->resize.height = w->height; |
655 w->resize.step_height = GetVehicleListHeight(type); |
|
656 |
728 |
657 SetupStringsForDepotWindow(w, type); |
729 SetupStringsForDepotWindow(w, type); |
658 |
730 |
659 w->widget[DEPOT_WIDGET_MATRIX].data = |
731 w->widget[DEPOT_WIDGET_MATRIX].data = |
660 (w->vscroll.cap * 0x100) // number of rows to draw on the background |
732 (w->vscroll.cap * 0x100) // number of rows to draw on the background |