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;
387 for (
int x = image_right - w; x > image_left; x -= w) {
388 GfxDrawLine(x, r.top, x, r.bottom, col, 1, 3);
391 for (
int x = image_left + w; x < image_right; x += w) {
392 GfxDrawLine(x, r.top, x, r.bottom, col, 1, 3);
403 for (byte i = 0; i < this->
num_columns && num < maxval; i++, num++) {
405 const Vehicle *v = this->vehicle_list[num];
419 const Vehicle *v = this->wagon_list[num - this->vehicle_list.
Length()];
439 enum DepotGUIAction {
446 DepotGUIAction GetVehicleFromDepotWndPt(
int x,
int y,
const Vehicle **veh, GetDepotVehiclePtData *d)
const
452 uint xt = 0, xm = 0, ym = 0;
463 if (row >= this->vscroll->
GetCapacity())
return MODE_ERROR;
467 if (this->vehicle_list.
Length() + this->wagon_list.
Length() <= pos) {
473 return MODE_DRAG_VEHICLE;
480 if (this->vehicle_list.
Length() > pos) {
481 *veh = this->vehicle_list[pos];
485 pos -= this->vehicle_list.
Length();
486 *veh = this->wagon_list[pos];
492 const Train *v = NULL;
495 d->head = d->wagon = v;
498 if (xm <= this->header_width) {
499 switch (this->type) {
501 if (wagon)
return MODE_ERROR;
505 if (xm <= this->flag_width)
return MODE_START_STOP;
513 default: NOT_REACHED();
515 return MODE_SHOW_VEHICLE;
518 if (this->type !=
VEH_TRAIN)
return MODE_DRAG_VEHICLE;
521 if (xm >= matrix_widget->
current_x - this->count_width)
return wagon ? MODE_ERROR : MODE_SHOW_VEHICLE;
524 x -= this->header_width;
527 for (; v != NULL; v = v->
Next()) {
534 return MODE_DRAG_VEHICLE;
546 DepotGUIAction mode = this->GetVehicleFromDepotWndPt(x, y, &v, &gdvp);
548 if (this->type ==
VEH_TRAIN) v = gdvp.wagon;
554 case MODE_DRAG_VEHICLE: {
561 TrainDepotMoveVehicle(v, sel, gdvp.head);
562 }
else if (v != NULL) {
567 this->sel = v->
index;
573 case MODE_SHOW_VEHICLE:
577 case MODE_START_STOP:
581 default: NOT_REACHED();
593 this->GetWidget<NWidgetCore>(
WID_D_STOP_ALL)->tool_tip = STR_DEPOT_MASS_STOP_DEPOT_TRAIN_TOOLTIP + type;
594 this->GetWidget<NWidgetCore>(
WID_D_START_ALL)->tool_tip = STR_DEPOT_MASS_START_DEPOT_TRAIN_TOOLTIP + type;
595 this->GetWidget<NWidgetCore>(
WID_D_SELL)->tool_tip = STR_DEPOT_TRAIN_SELL_TOOLTIP + type;
596 this->GetWidget<NWidgetCore>(
WID_D_SELL_ALL)->tool_tip = STR_DEPOT_SELL_ALL_BUTTON_TRAIN_TOOLTIP + type;
598 this->GetWidget<NWidgetCore>(
WID_D_BUILD)->
SetDataTip(STR_DEPOT_TRAIN_NEW_VEHICLES_BUTTON + type, STR_DEPOT_TRAIN_NEW_VEHICLES_TOOLTIP + type);
599 this->GetWidget<NWidgetCore>(
WID_D_CLONE)->
SetDataTip(STR_DEPOT_CLONE_TRAIN + type, STR_DEPOT_CLONE_TRAIN_DEPOT_INFO + type);
601 this->GetWidget<NWidgetCore>(
WID_D_LOCATION)->tool_tip = STR_DEPOT_TRAIN_LOCATION_TOOLTIP + type;
602 this->GetWidget<NWidgetCore>(
WID_D_VEHICLE_LIST)->tool_tip = STR_DEPOT_VEHICLE_ORDER_LIST_TRAIN_TOOLTIP + type;
603 this->GetWidget<NWidgetCore>(
WID_D_AUTOREPLACE)->tool_tip = STR_DEPOT_AUTOREPLACE_TRAIN_TOOLTIP + type;
604 this->GetWidget<NWidgetCore>(
WID_D_MATRIX)->tool_tip = STR_DEPOT_TRAIN_LIST_TOOLTIP + this->type;
607 default: NOT_REACHED();
613 this->GetWidget<NWidgetCore>(
WID_D_SELL)->widget_data = SPR_SELL_TRAIN;
614 this->GetWidget<NWidgetCore>(
WID_D_SELL_ALL)->widget_data = SPR_SELL_ALL_TRAIN;
615 this->GetWidget<NWidgetCore>(
WID_D_AUTOREPLACE)->widget_data = SPR_REPLACE_TRAIN;
622 this->GetWidget<NWidgetCore>(
WID_D_SELL)->widget_data = SPR_SELL_ROADVEH;
623 this->GetWidget<NWidgetCore>(
WID_D_SELL_ALL)->widget_data = SPR_SELL_ALL_ROADVEH;
624 this->GetWidget<NWidgetCore>(
WID_D_AUTOREPLACE)->widget_data = SPR_REPLACE_ROADVEH;
631 this->GetWidget<NWidgetCore>(
WID_D_SELL)->widget_data = SPR_SELL_SHIP;
632 this->GetWidget<NWidgetCore>(
WID_D_SELL_ALL)->widget_data = SPR_SELL_ALL_SHIP;
640 this->GetWidget<NWidgetCore>(
WID_D_SELL)->widget_data = SPR_SELL_AIRCRAFT;
641 this->GetWidget<NWidgetCore>(
WID_D_SELL_ALL)->widget_data = SPR_SELL_ALL_AIRCRAFT;
642 this->GetWidget<NWidgetCore>(
WID_D_AUTOREPLACE)->widget_data = SPR_REPLACE_AIRCRAFT;
663 this->count_width = 0;
679 int base_width = this->count_width + this->header_width;
685 size->height = resize->height * 6;
688 size->width = resize->width * (this->type ==
VEH_ROAD ? 5 : 3);
689 size->height = resize->height * (this->type ==
VEH_ROAD ? 5 : 3);
691 fill->width = resize->width;
692 fill->height = resize->height;
705 this->generate_list =
true;
710 if (this->generate_list) {
714 this->generate_list =
false;
715 DepotSortList(&this->vehicle_list);
719 if (this->unitnumber_digits < new_unitnumber_digits) {
720 this->unitnumber_digits = new_unitnumber_digits;
727 uint max_width =
ScaleGUITrad(VEHICLEINFO_FULL_VEHICLE_WIDTH);
728 for (uint num = 0; num < this->vehicle_list.
Length(); num++) {
733 max_width =
max(max_width, width);
778 static const CursorID clone_icons[] = {
779 SPR_CURSOR_CLONE_TRAIN, SPR_CURSOR_CLONE_ROADVEH,
780 SPR_CURSOR_CLONE_SHIP, SPR_CURSOR_CLONE_AIRPLANE
812 if (this->vehicle_list.
Length() != 0 || this->wagon_list.
Length() != 0) {
814 byte vehtype = this->type;
820 STR_DEPOT_SELL_CONFIRMATION_TEXT,
822 DepotSellAllConfirmationCallback
828 ShowVehicleListWindow(
GetTileOwner(this->window_number), this->type, (
TileIndex)this->window_number);
840 if (str == NULL)
return;
853 DepotGUIAction mode = this->GetVehicleFromDepotWndPt(pt.x - nwi->
pos_x, pt.y - nwi->
pos_y, &v, &gdvp);
855 if (this->type ==
VEH_TRAIN) v = gdvp.wagon;
857 if (v == NULL || mode != MODE_DRAG_VEHICLE)
return false;
866 for (
const Vehicle *w = v; w != NULL; w = w->
Next()) {
867 if (w->cargo_cap > 0 && w->cargo_type <
NUM_CARGO) {
868 capacity[w->cargo_type] += w->cargo_cap;
869 loaded [w->cargo_type] += w->cargo.StoredCount();
872 if (w->type ==
VEH_TRAIN && !w->HasArticulatedPart()) {
874 if (!whole_chain)
break;
879 static char details[1024];
884 if (capacity[cargo_type] == 0)
continue;
890 pos = GetString(pos, STR_DEPOT_VEHICLE_TOOLTIP_CARGO,
lastof(details));
896 args[1] = (uint64)(
size_t)details;
897 GuiShowTooltips(
this, whole_chain ? STR_DEPOT_VEHICLE_TOOLTIP_CHAIN : STR_DEPOT_VEHICLE_TOOLTIP, 2, args, TCC_RIGHT_CLICK);
958 NWidgetBase *matrix = this->GetWidget<NWidgetBase>(widget);
962 if (this->GetVehicleFromDepotWndPt(pt.x - matrix->
pos_x, pt.y - matrix->
pos_y, &v, &gdvp) != MODE_DRAG_VEHICLE)
return;
965 if (gdvp.head != NULL) {
966 if (gdvp.wagon == NULL && gdvp.head->
Last()->
index != this->sel) {
971 new_vehicle_over = gdvp.head->
index;
972 }
else if (gdvp.wagon != NULL && gdvp.head != gdvp.wagon &&
973 gdvp.wagon->
index != this->sel &&
975 new_vehicle_over = gdvp.wagon->
index;
999 if (this->GetVehicleFromDepotWndPt(pt.x - nwi->
pos_x, pt.y - nwi->
pos_y, &v, &gdvp) == MODE_DRAG_VEHICLE && sel !=
INVALID_VEHICLE) {
1003 }
else if (gdvp.wagon == NULL || gdvp.wagon->
index != sel) {
1005 TrainDepotMoveVehicle(gdvp.wagon, sel, gdvp.head);
1006 }
else if (gdvp.head != NULL && gdvp.head->
IsFrontEngine()) {
1010 }
else if (this->GetVehicleFromDepotWndPt(pt.x - nwi->
pos_x, pt.y - nwi->
pos_y, &v, NULL) == MODE_DRAG_VEHICLE && v != NULL && sel == v->
index) {
1075 static void DepotSellAllConfirmationCallback(
Window *win,
bool confirmed)
1080 byte vehtype = w->type;
1096 default: NOT_REACHED();
1097 case VEH_TRAIN: desc = &_train_depot_desc;
break;
1098 case VEH_ROAD: desc = &_road_depot_desc;
break;
1099 case VEH_SHIP: desc = &_ship_depot_desc;
break;
1100 case VEH_AIRCRAFT: desc = &_aircraft_depot_desc;
break;