34 #include "table/strings.h"
88 _nested_train_depot_widgets,
lengthof(_nested_train_depot_widgets)
95 _nested_train_depot_widgets,
lengthof(_nested_train_depot_widgets)
102 _nested_train_depot_widgets,
lengthof(_nested_train_depot_widgets)
106 WDP_AUTO,
"depot_aircraft", 332, 99,
109 _nested_train_depot_widgets,
lengthof(_nested_train_depot_widgets)
123 if (result.
Failed())
return;
134 if (v == wagon)
return;
137 if (head != NULL) wagon = head->
Last();
140 if (wagon == NULL)
return;
143 if (wagon == v)
return;
161 switch (image_type) {
162 case EIT_IN_DEPOT:
return _base_block_sizes_depot[type];
163 case EIT_PURCHASE:
return _base_block_sizes_purchase[type];
164 default: NOT_REACHED();
170 int max_extend_left = 0;
171 int max_extend_right = 0;
175 FOR_ALL_ENGINES_OF_TYPE(e, type) {
183 default: NOT_REACHED();
189 if (y > max_height) max_height = y;
190 if (-x_offs > max_extend_left) max_extend_left = -x_offs;
191 if ((
int)x + x_offs > max_extend_right) max_extend_right = x + x_offs;
197 switch (image_type) {
200 _base_block_sizes_depot[type].
extend_left =
Clamp(max_extend_left, min_extend, max_extend);
201 _base_block_sizes_depot[type].
extend_right =
Clamp(max_extend_right, min_extend, max_extend);
205 _base_block_sizes_purchase[type].
extend_left =
Clamp(max_extend_left, min_extend, max_extend);
206 _base_block_sizes_purchase[type].
extend_right =
Clamp(max_extend_right, min_extend, max_extend);
209 default: NOT_REACHED();
224 _consistent_train_width = TRAININFO_DEFAULT_VEHICLE_WIDTH;
230 uint w = TRAININFO_DEFAULT_VEHICLE_WIDTH;
231 if (e->
GetGRF() != NULL && is_custom_sprite(e->u.rail.image_index)) {
233 if (w != VEHICLEINFO_FULL_VEHICLE_WIDTH) {
238 _consistent_train_width = 0;
244 _consistent_train_width = w;
246 }
else if (w != _consistent_train_width) {
247 _consistent_train_width = 0;
253 static void DepotSellAllConfirmationCallback(
Window *w,
bool confirmed);
264 uint unitnumber_digits;
275 this->generate_list =
true;
279 this->unitnumber_digits = 2;
312 bool free_wagon =
false;
316 int image_left = rtl ? left + this->count_width : left + this->header_width;
317 int image_right = rtl ? right - this->header_width : right - this->count_width;
324 uint x_space = free_wagon ?
325 ScaleGUITrad(_consistent_train_width != 0 ? _consistent_train_width : TRAININFO_DEFAULT_VEHICLE_WIDTH) :
328 DrawTrainImage(u, image_left + (rtl ? 0 : x_space), image_right - (rtl ? x_space : 0), sprite_y - 1,
341 default: NOT_REACHED();
354 int text_left = rtl ? right - this->header_width - 1 : left + diff_x;
355 int text_right = rtl ? right - diff_x : left + this->header_width - 1;
358 DrawString(text_left, text_right, y + 2, STR_DEPOT_NO_ENGINE);
381 if (this->type ==
VEH_TRAIN && _consistent_train_width != 0) {
384 int image_left = rtl ? r.left + this->count_width : r.left + this->header_width;
385 int image_right = rtl ? r.right - this->header_width : r.right - this->count_width;
388 for (
int x = image_right - first_line; x >= image_left; x -= w) {
389 GfxDrawLine(x, r.top, x, r.bottom, col, 1, 3);
392 for (
int x = image_left + first_line; x <= image_right; x += w) {
393 GfxDrawLine(x, r.top, x, r.bottom, col, 1, 3);
404 for (byte i = 0; i < this->
num_columns && num < maxval; i++, num++) {
406 const Vehicle *v = this->vehicle_list[num];
420 const Vehicle *v = this->wagon_list[num - this->vehicle_list.
Length()];
440 enum DepotGUIAction {
447 DepotGUIAction GetVehicleFromDepotWndPt(
int x,
int y,
const Vehicle **veh, GetDepotVehiclePtData *d)
const
453 uint xt = 0, xm = 0, ym = 0;
464 if (row >= this->vscroll->
GetCapacity())
return MODE_ERROR;
468 if (this->vehicle_list.
Length() + this->wagon_list.
Length() <= pos) {
474 return MODE_DRAG_VEHICLE;
481 if (this->vehicle_list.
Length() > pos) {
482 *veh = this->vehicle_list[pos];
486 pos -= this->vehicle_list.
Length();
487 *veh = this->wagon_list[pos];
493 const Train *v = NULL;
496 d->head = d->wagon = v;
499 if (xm <= this->header_width) {
500 switch (this->type) {
502 if (wagon)
return MODE_ERROR;
506 if (xm <= this->flag_width)
return MODE_START_STOP;
514 default: NOT_REACHED();
516 return MODE_SHOW_VEHICLE;
519 if (this->type !=
VEH_TRAIN)
return MODE_DRAG_VEHICLE;
522 if (xm >= matrix_widget->
current_x - this->count_width)
return wagon ? MODE_ERROR : MODE_SHOW_VEHICLE;
525 x -= this->header_width;
528 for (; v != NULL; v = v->
Next()) {
535 return MODE_DRAG_VEHICLE;
547 DepotGUIAction mode = this->GetVehicleFromDepotWndPt(x, y, &v, &gdvp);
549 if (this->type ==
VEH_TRAIN) v = gdvp.wagon;
555 case MODE_DRAG_VEHICLE: {
562 TrainDepotMoveVehicle(v, sel, gdvp.head);
563 }
else if (v != NULL) {
568 this->sel = v->
index;
574 case MODE_SHOW_VEHICLE:
578 case MODE_START_STOP:
582 default: NOT_REACHED();
594 this->GetWidget<NWidgetCore>(
WID_D_STOP_ALL)->tool_tip = STR_DEPOT_MASS_STOP_DEPOT_TRAIN_TOOLTIP + type;
595 this->GetWidget<NWidgetCore>(
WID_D_START_ALL)->tool_tip = STR_DEPOT_MASS_START_DEPOT_TRAIN_TOOLTIP + type;
596 this->GetWidget<NWidgetCore>(
WID_D_SELL)->tool_tip = STR_DEPOT_TRAIN_SELL_TOOLTIP + type;
597 this->GetWidget<NWidgetCore>(
WID_D_SELL_ALL)->tool_tip = STR_DEPOT_SELL_ALL_BUTTON_TRAIN_TOOLTIP + type;
599 this->GetWidget<NWidgetCore>(
WID_D_BUILD)->
SetDataTip(STR_DEPOT_TRAIN_NEW_VEHICLES_BUTTON + type, STR_DEPOT_TRAIN_NEW_VEHICLES_TOOLTIP + type);
600 this->GetWidget<NWidgetCore>(
WID_D_CLONE)->
SetDataTip(STR_DEPOT_CLONE_TRAIN + type, STR_DEPOT_CLONE_TRAIN_DEPOT_INFO + type);
602 this->GetWidget<NWidgetCore>(
WID_D_LOCATION)->tool_tip = STR_DEPOT_TRAIN_LOCATION_TOOLTIP + type;
603 this->GetWidget<NWidgetCore>(
WID_D_VEHICLE_LIST)->tool_tip = STR_DEPOT_VEHICLE_ORDER_LIST_TRAIN_TOOLTIP + type;
604 this->GetWidget<NWidgetCore>(
WID_D_AUTOREPLACE)->tool_tip = STR_DEPOT_AUTOREPLACE_TRAIN_TOOLTIP + type;
605 this->GetWidget<NWidgetCore>(
WID_D_MATRIX)->tool_tip = STR_DEPOT_TRAIN_LIST_TOOLTIP + this->type;
608 default: NOT_REACHED();
614 this->GetWidget<NWidgetCore>(
WID_D_SELL)->widget_data = SPR_SELL_TRAIN;
615 this->GetWidget<NWidgetCore>(
WID_D_SELL_ALL)->widget_data = SPR_SELL_ALL_TRAIN;
616 this->GetWidget<NWidgetCore>(
WID_D_AUTOREPLACE)->widget_data = SPR_REPLACE_TRAIN;
623 this->GetWidget<NWidgetCore>(
WID_D_SELL)->widget_data = SPR_SELL_ROADVEH;
624 this->GetWidget<NWidgetCore>(
WID_D_SELL_ALL)->widget_data = SPR_SELL_ALL_ROADVEH;
625 this->GetWidget<NWidgetCore>(
WID_D_AUTOREPLACE)->widget_data = SPR_REPLACE_ROADVEH;
632 this->GetWidget<NWidgetCore>(
WID_D_SELL)->widget_data = SPR_SELL_SHIP;
633 this->GetWidget<NWidgetCore>(
WID_D_SELL_ALL)->widget_data = SPR_SELL_ALL_SHIP;
641 this->GetWidget<NWidgetCore>(
WID_D_SELL)->widget_data = SPR_SELL_AIRCRAFT;
642 this->GetWidget<NWidgetCore>(
WID_D_SELL_ALL)->widget_data = SPR_SELL_ALL_AIRCRAFT;
643 this->GetWidget<NWidgetCore>(
WID_D_AUTOREPLACE)->widget_data = SPR_REPLACE_AIRCRAFT;
664 this->count_width = 0;
680 int base_width = this->count_width + this->header_width;
686 size->height = resize->height * 6;
689 size->width = resize->width * (this->type ==
VEH_ROAD ? 5 : 3);
690 size->height = resize->height * (this->type ==
VEH_ROAD ? 5 : 3);
692 fill->width = resize->width;
693 fill->height = resize->height;
706 this->generate_list =
true;
711 if (this->generate_list) {
715 this->generate_list =
false;
716 DepotSortList(&this->vehicle_list);
720 if (this->unitnumber_digits < new_unitnumber_digits) {
721 this->unitnumber_digits = new_unitnumber_digits;
728 uint max_width =
ScaleGUITrad(VEHICLEINFO_FULL_VEHICLE_WIDTH);
729 for (uint num = 0; num < this->vehicle_list.
Length(); num++) {
734 max_width =
max(max_width, width);
780 static const CursorID clone_icons[] = {
781 SPR_CURSOR_CLONE_TRAIN, SPR_CURSOR_CLONE_ROADVEH,
782 SPR_CURSOR_CLONE_SHIP, SPR_CURSOR_CLONE_AIRPLANE
814 if (this->vehicle_list.
Length() != 0 || this->wagon_list.
Length() != 0) {
816 byte vehtype = this->type;
822 STR_DEPOT_SELL_CONFIRMATION_TEXT,
824 DepotSellAllConfirmationCallback
830 ShowVehicleListWindow(
GetTileOwner(this->window_number), this->type, (
TileIndex)this->window_number);
842 if (str == NULL)
return;
855 DepotGUIAction mode = this->GetVehicleFromDepotWndPt(pt.x - nwi->
pos_x, pt.y - nwi->
pos_y, &v, &gdvp);
857 if (this->type ==
VEH_TRAIN) v = gdvp.wagon;
859 if (v == NULL || mode != MODE_DRAG_VEHICLE)
return false;
868 for (
const Vehicle *w = v; w != NULL; w = w->
Next()) {
869 if (w->cargo_cap > 0 && w->cargo_type <
NUM_CARGO) {
870 capacity[w->cargo_type] += w->cargo_cap;
871 loaded [w->cargo_type] += w->cargo.StoredCount();
874 if (w->type ==
VEH_TRAIN && !w->HasArticulatedPart()) {
876 if (!whole_chain)
break;
881 static char details[1024];
886 if (capacity[cargo_type] == 0)
continue;
892 pos = GetString(pos, STR_DEPOT_VEHICLE_TOOLTIP_CARGO,
lastof(details));
898 args[1] = (uint64)(
size_t)details;
899 GuiShowTooltips(
this, whole_chain ? STR_DEPOT_VEHICLE_TOOLTIP_CHAIN : STR_DEPOT_VEHICLE_TOOLTIP, 2, args, TCC_RIGHT_CLICK);
960 NWidgetBase *matrix = this->GetWidget<NWidgetBase>(widget);
964 if (this->GetVehicleFromDepotWndPt(pt.x - matrix->
pos_x, pt.y - matrix->
pos_y, &v, &gdvp) != MODE_DRAG_VEHICLE)
return;
967 if (gdvp.head != NULL) {
968 if (gdvp.wagon == NULL && gdvp.head->
Last()->
index != this->sel) {
973 new_vehicle_over = gdvp.head->
index;
974 }
else if (gdvp.wagon != NULL && gdvp.head != gdvp.wagon &&
975 gdvp.wagon->
index != this->sel &&
977 new_vehicle_over = gdvp.wagon->
index;
1001 if (this->GetVehicleFromDepotWndPt(pt.x - nwi->
pos_x, pt.y - nwi->
pos_y, &v, &gdvp) == MODE_DRAG_VEHICLE && sel !=
INVALID_VEHICLE) {
1005 }
else if (gdvp.wagon == NULL || gdvp.wagon->
index != sel) {
1007 TrainDepotMoveVehicle(gdvp.wagon, sel, gdvp.head);
1008 }
else if (gdvp.head != NULL && gdvp.head->
IsFrontEngine()) {
1012 }
else if (this->GetVehicleFromDepotWndPt(pt.x - nwi->
pos_x, pt.y - nwi->
pos_y, &v, NULL) == MODE_DRAG_VEHICLE && v != NULL && sel == v->
index) {
1077 static void DepotSellAllConfirmationCallback(
Window *win,
bool confirmed)
1082 byte vehtype = w->type;
1098 default: NOT_REACHED();
1099 case VEH_TRAIN: desc = &_train_depot_desc;
break;
1100 case VEH_ROAD: desc = &_road_depot_desc;
break;
1101 case VEH_SHIP: desc = &_ship_depot_desc;
break;
1102 case VEH_AIRCRAFT: desc = &_aircraft_depot_desc;
break;