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;
160 switch (image_type) {
161 case EIT_IN_DEPOT:
return _base_block_sizes_depot[type];
162 case EIT_PURCHASE:
return _base_block_sizes_purchase[type];
163 default: NOT_REACHED();
169 int max_extend_left = 0;
170 int max_extend_right = 0;
174 FOR_ALL_ENGINES_OF_TYPE(e, type) {
182 default: NOT_REACHED();
188 if (y > max_height) max_height = y;
189 if (-x_offs > max_extend_left) max_extend_left = -x_offs;
190 if ((
int)x + x_offs > max_extend_right) max_extend_right = x + x_offs;
196 switch (image_type) {
199 _base_block_sizes_depot[type].
extend_left =
Clamp(max_extend_left, min_extend, max_extend);
200 _base_block_sizes_depot[type].
extend_right =
Clamp(max_extend_right, min_extend, max_extend);
204 _base_block_sizes_purchase[type].
extend_left =
Clamp(max_extend_left, min_extend, max_extend);
205 _base_block_sizes_purchase[type].
extend_right =
Clamp(max_extend_right, min_extend, max_extend);
208 default: NOT_REACHED();
224 static void DepotSellAllConfirmationCallback(
Window *w,
bool confirmed);
235 uint unitnumber_digits;
246 this->generate_list =
true;
250 this->unitnumber_digits = 2;
283 bool free_wagon =
false;
287 int image_left = rtl ? left + this->count_width : left + this->header_width;
288 int image_right = rtl ? right - this->header_width : right - this->count_width;
295 uint x_space = free_wagon ?
ScaleGUITrad(TRAININFO_DEFAULT_VEHICLE_WIDTH) : 0;
296 DrawTrainImage(u, image_left + (rtl ? 0 : x_space), image_right - (rtl ? x_space : 0), sprite_y - 1,
309 default: NOT_REACHED();
322 int text_left = rtl ? right - this->header_width - 1 : left + diff_x;
323 int text_right = rtl ? right - diff_x : left + this->header_width - 1;
326 DrawString(text_left, text_right, y + 2, STR_DEPOT_NO_ENGINE);
349 for (byte i = 0; i < this->
num_columns && num < maxval; i++, num++) {
351 const Vehicle *v = this->vehicle_list[num];
365 const Vehicle *v = this->wagon_list[num - this->vehicle_list.
Length()];
385 enum DepotGUIAction {
392 DepotGUIAction GetVehicleFromDepotWndPt(
int x,
int y,
const Vehicle **veh, GetDepotVehiclePtData *d)
const
398 uint xt = 0, xm = 0, ym = 0;
409 if (row >= this->vscroll->
GetCapacity())
return MODE_ERROR;
413 if (this->vehicle_list.
Length() + this->wagon_list.
Length() <= pos) {
419 return MODE_DRAG_VEHICLE;
426 if (this->vehicle_list.
Length() > pos) {
427 *veh = this->vehicle_list[pos];
431 pos -= this->vehicle_list.
Length();
432 *veh = this->wagon_list[pos];
438 const Train *v = NULL;
441 d->head = d->wagon = v;
444 if (xm <= this->header_width) {
445 switch (this->type) {
447 if (wagon)
return MODE_ERROR;
450 if (xm <= this->flag_width)
return MODE_START_STOP;
458 default: NOT_REACHED();
460 return MODE_SHOW_VEHICLE;
463 if (this->type !=
VEH_TRAIN)
return MODE_DRAG_VEHICLE;
466 if (xm >= matrix_widget->
current_x - this->count_width)
return wagon ? MODE_ERROR : MODE_SHOW_VEHICLE;
469 x -= this->header_width;
472 for (; v != NULL; v = v->
Next()) {
479 return MODE_DRAG_VEHICLE;
491 DepotGUIAction mode = this->GetVehicleFromDepotWndPt(x, y, &v, &gdvp);
493 if (this->type ==
VEH_TRAIN) v = gdvp.wagon;
499 case MODE_DRAG_VEHICLE: {
506 TrainDepotMoveVehicle(v, sel, gdvp.head);
507 }
else if (v != NULL) {
512 this->sel = v->
index;
518 case MODE_SHOW_VEHICLE:
522 case MODE_START_STOP:
526 default: NOT_REACHED();
538 this->GetWidget<NWidgetCore>(
WID_D_STOP_ALL)->tool_tip = STR_DEPOT_MASS_STOP_DEPOT_TRAIN_TOOLTIP + type;
539 this->GetWidget<NWidgetCore>(
WID_D_START_ALL)->tool_tip = STR_DEPOT_MASS_START_DEPOT_TRAIN_TOOLTIP + type;
540 this->GetWidget<NWidgetCore>(
WID_D_SELL)->tool_tip = STR_DEPOT_TRAIN_SELL_TOOLTIP + type;
541 this->GetWidget<NWidgetCore>(
WID_D_SELL_ALL)->tool_tip = STR_DEPOT_SELL_ALL_BUTTON_TRAIN_TOOLTIP + type;
543 this->GetWidget<NWidgetCore>(
WID_D_BUILD)->
SetDataTip(STR_DEPOT_TRAIN_NEW_VEHICLES_BUTTON + type, STR_DEPOT_TRAIN_NEW_VEHICLES_TOOLTIP + type);
544 this->GetWidget<NWidgetCore>(
WID_D_CLONE)->
SetDataTip(STR_DEPOT_CLONE_TRAIN + type, STR_DEPOT_CLONE_TRAIN_DEPOT_INFO + type);
546 this->GetWidget<NWidgetCore>(
WID_D_LOCATION)->tool_tip = STR_DEPOT_TRAIN_LOCATION_TOOLTIP + type;
547 this->GetWidget<NWidgetCore>(
WID_D_VEHICLE_LIST)->tool_tip = STR_DEPOT_VEHICLE_ORDER_LIST_TRAIN_TOOLTIP + type;
548 this->GetWidget<NWidgetCore>(
WID_D_AUTOREPLACE)->tool_tip = STR_DEPOT_AUTOREPLACE_TRAIN_TOOLTIP + type;
549 this->GetWidget<NWidgetCore>(
WID_D_MATRIX)->tool_tip = STR_DEPOT_TRAIN_LIST_TOOLTIP + this->type;
552 default: NOT_REACHED();
558 this->GetWidget<NWidgetCore>(
WID_D_SELL)->widget_data = SPR_SELL_TRAIN;
559 this->GetWidget<NWidgetCore>(
WID_D_SELL_ALL)->widget_data = SPR_SELL_ALL_TRAIN;
560 this->GetWidget<NWidgetCore>(
WID_D_AUTOREPLACE)->widget_data = SPR_REPLACE_TRAIN;
567 this->GetWidget<NWidgetCore>(
WID_D_SELL)->widget_data = SPR_SELL_ROADVEH;
568 this->GetWidget<NWidgetCore>(
WID_D_SELL_ALL)->widget_data = SPR_SELL_ALL_ROADVEH;
569 this->GetWidget<NWidgetCore>(
WID_D_AUTOREPLACE)->widget_data = SPR_REPLACE_ROADVEH;
576 this->GetWidget<NWidgetCore>(
WID_D_SELL)->widget_data = SPR_SELL_SHIP;
577 this->GetWidget<NWidgetCore>(
WID_D_SELL_ALL)->widget_data = SPR_SELL_ALL_SHIP;
585 this->GetWidget<NWidgetCore>(
WID_D_SELL)->widget_data = SPR_SELL_AIRCRAFT;
586 this->GetWidget<NWidgetCore>(
WID_D_SELL_ALL)->widget_data = SPR_SELL_ALL_AIRCRAFT;
587 this->GetWidget<NWidgetCore>(
WID_D_AUTOREPLACE)->widget_data = SPR_REPLACE_AIRCRAFT;
608 this->count_width = 0;
624 int base_width = this->count_width + this->header_width;
630 size->height = resize->height * 6;
633 size->width = resize->width * (this->type ==
VEH_ROAD ? 5 : 3);
634 size->height = resize->height * (this->type ==
VEH_ROAD ? 5 : 3);
636 fill->width = resize->width;
637 fill->height = resize->height;
650 this->generate_list =
true;
655 if (this->generate_list) {
659 this->generate_list =
false;
660 DepotSortList(&this->vehicle_list);
664 if (this->unitnumber_digits < new_unitnumber_digits) {
665 this->unitnumber_digits = new_unitnumber_digits;
672 uint max_width =
ScaleGUITrad(VEHICLEINFO_FULL_VEHICLE_WIDTH);
673 for (uint num = 0; num < this->vehicle_list.
Length(); num++) {
678 max_width =
max(max_width, width);
723 static const CursorID clone_icons[] = {
724 SPR_CURSOR_CLONE_TRAIN, SPR_CURSOR_CLONE_ROADVEH,
725 SPR_CURSOR_CLONE_SHIP, SPR_CURSOR_CLONE_AIRPLANE
757 if (this->vehicle_list.
Length() != 0 || this->wagon_list.
Length() != 0) {
759 byte vehtype = this->type;
765 STR_DEPOT_SELL_CONFIRMATION_TEXT,
767 DepotSellAllConfirmationCallback
773 ShowVehicleListWindow(
GetTileOwner(this->window_number), this->type, (
TileIndex)this->window_number);
785 if (str == NULL)
return;
798 DepotGUIAction mode = this->GetVehicleFromDepotWndPt(pt.x - nwi->
pos_x, pt.y - nwi->
pos_y, &v, &gdvp);
800 if (this->type ==
VEH_TRAIN) v = gdvp.wagon;
802 if (v == NULL || mode != MODE_DRAG_VEHICLE)
return false;
811 for (
const Vehicle *w = v; w != NULL; w = w->
Next()) {
812 if (w->cargo_cap > 0 && w->cargo_type <
NUM_CARGO) {
813 capacity[w->cargo_type] += w->cargo_cap;
814 loaded [w->cargo_type] += w->cargo.StoredCount();
817 if (w->type ==
VEH_TRAIN && !w->HasArticulatedPart()) {
819 if (!whole_chain)
break;
824 static char details[1024];
829 if (capacity[cargo_type] == 0)
continue;
835 pos = GetString(pos, STR_DEPOT_VEHICLE_TOOLTIP_CARGO,
lastof(details));
841 args[1] = (uint64)(
size_t)details;
842 GuiShowTooltips(
this, whole_chain ? STR_DEPOT_VEHICLE_TOOLTIP_CHAIN : STR_DEPOT_VEHICLE_TOOLTIP, 2, args, TCC_RIGHT_CLICK);
903 NWidgetBase *matrix = this->GetWidget<NWidgetBase>(widget);
907 if (this->GetVehicleFromDepotWndPt(pt.x - matrix->
pos_x, pt.y - matrix->
pos_y, &v, &gdvp) != MODE_DRAG_VEHICLE)
return;
910 if (gdvp.head != NULL) {
911 if (gdvp.wagon == NULL && gdvp.head->
Last()->
index != this->sel) {
916 new_vehicle_over = gdvp.head->
index;
917 }
else if (gdvp.wagon != NULL && gdvp.head != gdvp.wagon &&
918 gdvp.wagon->
index != this->sel &&
920 new_vehicle_over = gdvp.wagon->
index;
944 if (this->GetVehicleFromDepotWndPt(pt.x - nwi->
pos_x, pt.y - nwi->
pos_y, &v, &gdvp) == MODE_DRAG_VEHICLE && sel !=
INVALID_VEHICLE) {
948 }
else if (gdvp.wagon == NULL || gdvp.wagon->
index != sel) {
950 TrainDepotMoveVehicle(gdvp.wagon, sel, gdvp.head);
951 }
else if (gdvp.head != NULL && gdvp.head->
IsFrontEngine()) {
955 }
else if (this->GetVehicleFromDepotWndPt(pt.x - nwi->
pos_x, pt.y - nwi->
pos_y, &v, NULL) == MODE_DRAG_VEHICLE && v != NULL && sel == v->
index) {
1020 static void DepotSellAllConfirmationCallback(
Window *win,
bool confirmed)
1025 byte vehtype = w->type;
1041 default: NOT_REACHED();
1042 case VEH_TRAIN: desc = &_train_depot_desc;
break;
1043 case VEH_ROAD: desc = &_road_depot_desc;
break;
1044 case VEH_SHIP: desc = &_ship_depot_desc;
break;
1045 case VEH_AIRCRAFT: desc = &_aircraft_depot_desc;
break;