bjarni@4638: /* $Id$ */ bjarni@4638: rubidium@9111: /** @file depot_gui.cpp The GUI for depots. */ belugas@6125: bjarni@4638: #include "stdafx.h" bjarni@4638: #include "openttd.h" bjarni@4654: #include "train.h" bjarni@4654: #include "roadveh.h" bjarni@4638: #include "ship.h" bjarni@4653: #include "aircraft.h" bjarni@4638: #include "gui.h" rubidium@8107: #include "textbuf_gui.h" rubidium@8224: #include "viewport_func.h" rubidium@8224: #include "gfx_func.h" rubidium@8116: #include "command_func.h" rubidium@8962: #include "depot_base.h" bjarni@4638: #include "vehicle_gui.h" bjarni@4638: #include "station_map.h" bjarni@4638: #include "newgrf_engine.h" bjarni@5972: #include "spritecache.h" rubidium@8114: #include "strings_func.h" rubidium@8131: #include "window_func.h" rubidium@8144: #include "vehicle_func.h" rubidium@10208: #include "company_func.h" rubidium@8784: #include "order_func.h" rubidium@8962: #include "depot_base.h" rubidium@9127: #include "tilehighlight_func.h" rubidium@9274: #include "window_gui.h" peter1138@9396: #include "vehiclelist.h" bjarni@4649: rubidium@8264: #include "table/strings.h" rubidium@8264: #include "table/sprites.h" rubidium@8264: bjarni@4649: /* bjarni@4649: * Since all depot window sizes aren't the same, we need to modify sizes a little. bjarni@4649: * It's done with the following arrays of widget indexes. Each of them tells if a widget side should be moved and in what direction. bjarni@4649: * How long they should be moved and for what window types are controlled in ShowDepotWindow() bjarni@4649: */ bjarni@4649: bjarni@4646: /* Names of the widgets. Keep them in the same order as in the widget array */ Darkvater@5269: enum DepotWindowWidgets { bjarni@4646: DEPOT_WIDGET_CLOSEBOX = 0, bjarni@4646: DEPOT_WIDGET_CAPTION, bjarni@4646: DEPOT_WIDGET_STICKY, bjarni@4646: DEPOT_WIDGET_SELL, bjarni@4659: DEPOT_WIDGET_SELL_CHAIN, bjarni@4646: DEPOT_WIDGET_SELL_ALL, peter1138@4699: DEPOT_WIDGET_AUTOREPLACE, bjarni@4646: DEPOT_WIDGET_MATRIX, belugas@6125: DEPOT_WIDGET_V_SCROLL, ///< Vertical scrollbar belugas@6125: DEPOT_WIDGET_H_SCROLL, ///< Horizontal scrollbar bjarni@4646: DEPOT_WIDGET_BUILD, bjarni@4646: DEPOT_WIDGET_CLONE, bjarni@4646: DEPOT_WIDGET_LOCATION, bjarni@4681: DEPOT_WIDGET_VEHICLE_LIST, peter1138@4699: DEPOT_WIDGET_STOP_ALL, peter1138@4699: DEPOT_WIDGET_START_ALL, bjarni@4646: DEPOT_WIDGET_RESIZE, bjarni@4649: }; bjarni@4649: bjarni@4638: /* Widget array for all depot windows. bjarni@4638: * If a widget is needed in some windows only (like train specific), add it for all windows belugas@4702: * and use HideWindowWidget in ShowDepotWindow() to remove it in the windows where it should not be bjarni@4638: * Keep the widget numbers in sync with the enum or really bad stuff will happen!!! */ bjarni@4649: bjarni@4649: /* 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[] bjarni@4650: * 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 bjarni@4650: * 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. bjarni@4650: * Changing the size of those here will not have an effect at all. It should be done in ShowDepotWindow() bjarni@4650: */ bjarni@5972: bjarni@5972: /* bjarni@5972: * Some of the widgets are placed outside the window (negative coordinates). bjarni@5972: * The reason is that they are placed relatively to the matrix and the matrix is just one pixel (in 0, 14). bjarni@5972: * 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. bjarni@5972: */ bjarni@4638: static const Widget _depot_widgets[] = { belugas@9751: { WWT_CLOSEBOX, RESIZE_NONE, COLOUR_GREY, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, // DEPOT_WIDGET_CLOSEBOX belugas@9751: { WWT_CAPTION, RESIZE_RIGHT, COLOUR_GREY, 11, 23, 0, 13, 0x0, STR_018C_WINDOW_TITLE_DRAG_THIS}, // DEPOT_WIDGET_CAPTION belugas@9751: { WWT_STICKYBOX, RESIZE_LR, COLOUR_GREY, 24, 35, 0, 13, 0x0, STR_STICKY_BUTTON}, // DEPOT_WIDGET_STICKY bjarni@4640: Darkvater@4938: /* Widgets are set up run-time */ belugas@9751: { WWT_IMGBTN, RESIZE_LRB, COLOUR_GREY, 1, 23, 14, -32, 0x0, STR_NULL}, // DEPOT_WIDGET_SELL belugas@9751: { WWT_IMGBTN, RESIZE_LRTB, COLOUR_GREY, 1, 23, -55, -32, SPR_SELL_CHAIN_TRAIN,STR_DRAG_WHOLE_TRAIN_TO_SELL_TIP}, // DEPOT_WIDGET_SELL_CHAIN, trains only belugas@9751: { WWT_PUSHIMGBTN, RESIZE_LRTB, COLOUR_GREY, 1, 23, -31, -9, 0x0, STR_NULL}, // DEPOT_WIDGET_SELL_ALL belugas@9751: { WWT_PUSHIMGBTN, RESIZE_LRTB, COLOUR_GREY, 1, 23, -8, 14, 0x0, STR_NULL}, // DEPOT_WIDGET_AUTOREPLACE bjarni@4638: belugas@9751: { WWT_MATRIX, RESIZE_RB, COLOUR_GREY, 0, 0, 14, 14, 0x0, STR_NULL}, // DEPOT_WIDGET_MATRIX belugas@9751: { WWT_SCROLLBAR, RESIZE_LRB, COLOUR_GREY, 24, 35, 14, 14, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, // DEPOT_WIDGET_V_SCROLL bjarni@4638: belugas@9751: { WWT_HSCROLLBAR, RESIZE_RTB, COLOUR_GREY, 0, 0, 3, 14, 0x0, STR_HSCROLL_BAR_SCROLLS_LIST}, // DEPOT_WIDGET_H_SCROLL, trains only bjarni@4638: bjarni@4638: /* The buttons in the bottom of the window. left and right is not important as they are later resized to be equal in size bjarni@4638: * This calculation is based on right in DEPOT_WIDGET_LOCATION and it presumes left of DEPOT_WIDGET_BUILD is 0 */ belugas@9751: { WWT_PUSHTXTBTN, RESIZE_TB, COLOUR_GREY, 0, 0, 15, 26, 0x0, STR_NULL}, // DEPOT_WIDGET_BUILD belugas@9751: { WWT_TEXTBTN, RESIZE_TB, COLOUR_GREY, 0, 0, 15, 26, 0x0, STR_NULL}, // DEPOT_WIDGET_CLONE belugas@9751: { WWT_PUSHTXTBTN, RESIZE_RTB, COLOUR_GREY, 0, -12, 15, 26, STR_00E4_LOCATION, STR_NULL}, // DEPOT_WIDGET_LOCATION belugas@9751: { WWT_PUSHTXTBTN, RESIZE_LRTB, COLOUR_GREY, -11, 0, 15, 26, 0x0, STR_NULL}, // DEPOT_WIDGET_VEHICLE_LIST belugas@9751: { WWT_PUSHIMGBTN, RESIZE_LRTB, COLOUR_GREY, 1, 11, 15, 26, SPR_FLAG_VEH_STOPPED,STR_NULL}, // DEPOT_WIDGET_STOP_ALL belugas@9751: { WWT_PUSHIMGBTN, RESIZE_LRTB, COLOUR_GREY, 12, 23, 15, 26, SPR_FLAG_VEH_RUNNING,STR_NULL}, // DEPOT_WIDGET_START_ALL belugas@9751: { WWT_RESIZEBOX, RESIZE_LRTB, COLOUR_GREY, 24, 35, 15, 26, 0x0, STR_RESIZE_BUTTON}, // DEPOT_WIDGET_RESIZE bjarni@4638: { WIDGETS_END}, bjarni@4638: }; bjarni@4638: rubidium@9188: bjarni@4638: static const WindowDesc _train_depot_desc = { rubidium@7341: WDP_AUTO, WDP_AUTO, 36, 27, 36, 27, rubidium@5893: WC_VEHICLE_DEPOT, WC_NONE, bjarni@4638: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE, bjarni@4638: _depot_widgets, bjarni@4638: }; bjarni@4638: bjarni@4638: static const WindowDesc _road_depot_desc = { rubidium@7341: WDP_AUTO, WDP_AUTO, 36, 27, 36, 27, rubidium@5893: WC_VEHICLE_DEPOT, WC_NONE, bjarni@4638: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE, bjarni@4638: _depot_widgets, bjarni@4638: }; bjarni@4638: bjarni@4638: static const WindowDesc _ship_depot_desc = { rubidium@7341: WDP_AUTO, WDP_AUTO, 36, 27, 36, 27, rubidium@5893: WC_VEHICLE_DEPOT, WC_NONE, bjarni@4638: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE, bjarni@4638: _depot_widgets, bjarni@4638: }; bjarni@4638: bjarni@4638: static const WindowDesc _aircraft_depot_desc = { rubidium@7341: WDP_AUTO, WDP_AUTO, 36, 27, 36, 27, rubidium@5893: WC_VEHICLE_DEPOT, WC_NONE, bjarni@4638: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE, bjarni@4638: _depot_widgets, bjarni@4638: }; bjarni@4638: bjarni@4638: extern int WagonLengthToPixels(int len); peter1138@9351: extern void DepotSortList(VehicleList *list); bjarni@4638: rubidium@7478: /** rubidium@7478: * This is the Callback method after the cloning attempt of a vehicle rubidium@7478: * @param success indicates completion (or not) of the operation rubidium@7478: * @param tile unused rubidium@7478: * @param p1 unused rubidium@7478: * @param p2 unused rubidium@7478: */ bjarni@4638: void CcCloneVehicle(bool success, TileIndex tile, uint32 p1, uint32 p2) bjarni@4638: { bjarni@4638: if (!success) return; rubidium@7478: peter1138@9344: const Vehicle *v = GetVehicle(_new_vehicle_id); rubidium@7478: rubidium@7486: ShowVehicleViewWindow(v); bjarni@4638: } bjarni@4638: peter1138@9344: static void TrainDepotMoveVehicle(const Vehicle *wagon, VehicleID sel, const Vehicle *head) bjarni@4638: { peter1138@9344: const Vehicle *v = GetVehicle(sel); bjarni@4638: bjarni@4638: if (v == wagon) return; bjarni@4638: bjarni@4638: if (wagon == NULL) { bjarni@4638: if (head != NULL) wagon = GetLastVehicleInChain(head); bjarni@4638: } else { rubidium@7497: wagon = wagon->Previous(); bjarni@4638: if (wagon == NULL) return; bjarni@4638: } bjarni@4638: bjarni@4638: if (wagon == v) return; bjarni@4638: bjarni@4638: DoCommandP(v->tile, v->index + ((wagon == NULL ? INVALID_VEHICLE : wagon->index) << 16), _ctrl_pressed ? 1 : 0, NULL, CMD_MOVE_RAIL_VEHICLE | CMD_MSG(STR_8837_CAN_T_MOVE_VEHICLE)); bjarni@4638: } bjarni@4638: bjarni@5972: /* Array to hold the block sizes bjarni@5972: * First part is the vehicle type, while the last is 0 = x, 1 = y */ bjarni@5972: uint _block_sizes[4][2]; bjarni@5972: bjarni@5972: /* Array to hold the default resize capacities bjarni@5972: * First part is the vehicle type, while the last is 0 = x, 1 = y */ bjarni@5972: const uint _resize_cap[][2] = { maedhros@6401: /* VEH_TRAIN */ {6, 10 * 29}, rubidium@6259: /* VEH_ROAD */ {5, 5}, rubidium@6259: /* VEH_SHIP */ {3, 3}, rubidium@6259: /* VEH_AIRCRAFT */ {3, 4}, bjarni@5972: }; bjarni@5972: bjarni@5972: static void ResizeDefaultWindowSizeForTrains() bjarni@5972: { rubidium@6259: _block_sizes[VEH_TRAIN][0] = 1; rubidium@6259: _block_sizes[VEH_TRAIN][1] = GetVehicleListHeight(VEH_TRAIN); bjarni@5972: } bjarni@5972: bjarni@5972: static void ResizeDefaultWindowSizeForRoadVehicles() bjarni@5972: { rubidium@6259: _block_sizes[VEH_ROAD][0] = 56; rubidium@6259: _block_sizes[VEH_ROAD][1] = GetVehicleListHeight(VEH_ROAD); bjarni@5972: } bjarni@5972: rubidium@6638: static void ResizeDefaultWindowSize(VehicleType type) bjarni@5972: { bjarni@5972: uint max_width = 0; bjarni@5972: uint max_height = 0; bjarni@5972: peter1138@9070: const Engine *e; peter1138@9070: FOR_ALL_ENGINES_OF_TYPE(e, type) { peter1138@9070: EngineID eid = e->index; bjarni@5972: uint x, y; bjarni@5972: bjarni@5972: switch (type) { bjarni@5972: default: NOT_REACHED(); peter1138@9065: case VEH_SHIP: GetShipSpriteSize( eid, x, y); break; peter1138@9065: case VEH_AIRCRAFT: GetAircraftSpriteSize(eid, x, y); break; bjarni@5972: } bjarni@5972: if (x > max_width) max_width = x; bjarni@5972: if (y > max_height) max_height = y; bjarni@5972: } bjarni@5972: bjarni@5972: switch (type) { bjarni@5972: default: NOT_REACHED(); rubidium@6259: case VEH_SHIP: rubidium@6259: _block_sizes[VEH_SHIP][0] = max(90U, max_width + 20); // we need 20 pixels from the right edge to the sprite bjarni@5972: break; rubidium@6259: case VEH_AIRCRAFT: rubidium@6259: _block_sizes[VEH_AIRCRAFT][0] = max(74U, max_width); bjarni@5972: break; bjarni@5972: } bjarni@5972: _block_sizes[type][1] = max(GetVehicleListHeight(type), max_height); bjarni@5972: } bjarni@5972: bjarni@5972: /* 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 bjarni@5972: * We will only need to call this once for each game */ bjarni@5972: void InitDepotWindowBlockSizes() bjarni@5972: { bjarni@5972: ResizeDefaultWindowSizeForTrains(); bjarni@5972: ResizeDefaultWindowSizeForRoadVehicles(); rubidium@6259: ResizeDefaultWindowSize(VEH_SHIP); rubidium@6259: ResizeDefaultWindowSize(VEH_AIRCRAFT); bjarni@5972: } bjarni@5972: rubidium@9201: static void DepotSellAllConfirmationCallback(Window *w, bool confirmed); rubidium@9201: const Sprite *GetAircraftSprite(EngineID engine); Darkvater@5269: rubidium@9201: struct DepotWindow : Window { rubidium@9201: VehicleID sel; rubidium@9201: VehicleType type; rubidium@9201: bool generate_list; peter1138@9351: VehicleList vehicle_list; peter1138@9351: VehicleList wagon_list; bjarni@5972: rubidium@9203: DepotWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number) rubidium@9201: { rubidium@9201: this->sel = INVALID_VEHICLE; rubidium@9201: this->generate_list = true; bjarni@5972: rubidium@9201: this->FindWindowPlacementAndResize(desc); Darkvater@5269: } Darkvater@5269: rubidium@9201: ~DepotWindow() rubidium@9201: { rubidium@9201: DeleteWindowById(WC_BUILD_VEHICLE, this->window_number); rubidium@9201: } Darkvater@5269: rubidium@9201: /** Draw a vehicle in the depot window in the box with the top left corner at x,y rubidium@9201: * @param *w Window to draw in rubidium@9201: * @param *v Vehicle to draw rubidium@9201: * @param x Left side of the box to draw in rubidium@9201: * @param y Top of the box to draw in rubidium@9201: */ rubidium@9201: void DrawVehicleInDepot(Window *w, const Vehicle *v, int x, int y) rubidium@9201: { rubidium@9201: byte diff_x = 0, diff_y = 0; Darkvater@5269: rubidium@9201: int sprite_y = y + this->resize.step_height - GetVehicleListHeight(v->type); rubidium@9201: rubidium@9201: switch (v->type) { rubidium@9201: case VEH_TRAIN: rubidium@9201: DrawTrainImage(v, x + 21, sprite_y, this->sel, this->hscroll.cap + 4, this->hscroll.pos); rubidium@9201: rubidium@9201: /* Number of wagons relative to a standard length wagon (rounded up) */ rubidium@9201: SetDParam(0, (v->u.rail.cached_total_length + 7) / 8); rubidium@9201: DrawStringRightAligned(this->widget[DEPOT_WIDGET_MATRIX].right - 1, y + 4, STR_TINY_BLACK, TC_FROMSTRING); // Draw the counter rubidium@9201: break; rubidium@9201: rubidium@9201: case VEH_ROAD: DrawRoadVehImage( v, x + 24, sprite_y, this->sel, 1); break; rubidium@9201: case VEH_SHIP: DrawShipImage( v, x + 19, sprite_y - 1, this->sel); break; rubidium@9201: case VEH_AIRCRAFT: { rubidium@10056: const Sprite *spr = GetSprite(v->GetImage(DIR_W), ST_NORMAL); rubidium@9201: DrawAircraftImage(v, x + 12, rubidium@9201: y + max(spr->height + spr->y_offs - 14, 0), // tall sprites needs an y offset rubidium@9201: this->sel); rubidium@9201: } break; rubidium@9201: default: NOT_REACHED(); rubidium@9201: } rubidium@9201: rubidium@9201: if (this->resize.step_height == 14) { rubidium@9201: /* VEH_TRAIN and VEH_ROAD, which are low */ rubidium@9201: diff_x = 15; rubidium@9201: } else { rubidium@9201: /* VEH_SHIP and VEH_AIRCRAFT, which are tall */ rubidium@9201: diff_y = 12; rubidium@9201: } rubidium@9201: rubidium@9201: DrawSprite((v->vehstatus & VS_STOPPED) ? SPR_FLAG_VEH_STOPPED : SPR_FLAG_VEH_RUNNING, PAL_NONE, x + diff_x, y + diff_y); rubidium@9201: rubidium@9201: SetDParam(0, v->unitnumber); rubidium@9201: DrawString(x, y + 2, (uint16)(v->max_age - 366) >= v->age ? STR_00E2 : STR_00E3, TC_FROMSTRING); rubidium@9201: } rubidium@9201: rubidium@9201: void DrawDepotWindow(Window *w) rubidium@9201: { rubidium@9201: TileIndex tile = this->window_number; rubidium@9201: int x, y, i, maxval; rubidium@9201: uint16 hnum; rubidium@9201: rubidium@9201: /* Set the row and number of boxes in each row based on the number of boxes drawn in the matrix */ rubidium@9201: uint16 rows_in_display = this->widget[DEPOT_WIDGET_MATRIX].data >> 8; rubidium@9201: uint16 boxes_in_each_row = this->widget[DEPOT_WIDGET_MATRIX].data & 0xFF; rubidium@9201: rubidium@9201: /* setup disabled buttons */ rubidium@10207: this->SetWidgetsDisabledState(!IsTileOwner(tile, _local_company), rubidium@9201: DEPOT_WIDGET_STOP_ALL, rubidium@9201: DEPOT_WIDGET_START_ALL, rubidium@9201: DEPOT_WIDGET_SELL, rubidium@9201: DEPOT_WIDGET_SELL_CHAIN, rubidium@9201: DEPOT_WIDGET_SELL_ALL, rubidium@9201: DEPOT_WIDGET_BUILD, rubidium@9201: DEPOT_WIDGET_CLONE, rubidium@9201: DEPOT_WIDGET_AUTOREPLACE, rubidium@9201: WIDGET_LIST_END); rubidium@9201: rubidium@9201: /* determine amount of items for scroller */ rubidium@9201: if (this->type == VEH_TRAIN) { rubidium@9201: hnum = 8; peter1138@9351: for (uint num = 0; num < this->vehicle_list.Length(); num++) { peter1138@9351: const Vehicle *v = this->vehicle_list[num]; rubidium@9201: hnum = max(hnum, v->u.rail.cached_total_length); rubidium@9201: } rubidium@9201: /* Always have 1 empty row, so people can change the setting of the train */ peter1138@9351: SetVScrollCount(w, this->vehicle_list.Length() + this->wagon_list.Length() + 1); rubidium@9201: SetHScrollCount(w, WagonLengthToPixels(hnum)); rubidium@9201: } else { peter1138@9351: SetVScrollCount(w, (this->vehicle_list.Length() + this->hscroll.cap - 1) / this->hscroll.cap); rubidium@9201: } rubidium@9201: rubidium@9201: /* locate the depot struct */ rubidium@9201: if (this->type == VEH_AIRCRAFT) { rubidium@9201: SetDParam(0, GetStationIndex(tile)); // Airport name rubidium@9201: } else { rubidium@9201: Depot *depot = GetDepotByTile(tile); rubidium@9201: assert(depot != NULL); rubidium@9201: rubidium@9201: SetDParam(0, depot->town_index); rubidium@9201: } rubidium@9201: rubidium@9273: w->DrawWidgets(); rubidium@9201: peter1138@9351: uint16 num = this->vscroll.pos * boxes_in_each_row; peter1138@9351: maxval = min(this->vehicle_list.Length(), num + (rows_in_display * boxes_in_each_row)); rubidium@9201: rubidium@9201: for (x = 2, y = 15; num < maxval; y += this->resize.step_height, x = 2) { // Draw the rows rubidium@9201: byte i; rubidium@9201: rubidium@9201: for (i = 0; i < boxes_in_each_row && num < maxval; i++, num++, x += this->resize.step_width) { rubidium@9201: /* Draw all vehicles in the current row */ peter1138@9351: const Vehicle *v = this->vehicle_list[num]; rubidium@9201: DrawVehicleInDepot(w, v, x, y); rubidium@9201: } rubidium@9201: } rubidium@9201: peter1138@9351: maxval = min(this->vehicle_list.Length() + this->wagon_list.Length(), (this->vscroll.pos * boxes_in_each_row) + (rows_in_display * boxes_in_each_row)); rubidium@9201: rubidium@9201: /* draw the train wagons, that do not have an engine in front */ rubidium@9201: for (; num < maxval; num++, y += 14) { peter1138@9351: const Vehicle *v = this->wagon_list[num - this->vehicle_list.Length()]; rubidium@9201: const Vehicle *u; rubidium@9201: rubidium@9201: DrawTrainImage(v, x + 50, y, this->sel, this->hscroll.cap - 29, 0); rubidium@9201: DrawString(x, y + 2, STR_8816, TC_FROMSTRING); rubidium@9201: rubidium@9201: /*Draw the train counter */ rubidium@9201: i = 0; rubidium@9201: u = v; rubidium@9201: do i++; while ((u = u->Next()) != NULL); // Determine length of train rubidium@9201: SetDParam(0, i); // Set the counter rubidium@9201: DrawStringRightAligned(this->widget[DEPOT_WIDGET_MATRIX].right - 1, y + 4, STR_TINY_BLACK, TC_FROMSTRING); // Draw the counter rubidium@9201: } rubidium@9201: } rubidium@9201: rubidium@9201: struct GetDepotVehiclePtData { peter1138@9344: const Vehicle *head; peter1138@9344: const Vehicle *wagon; rubidium@9201: }; rubidium@9201: rubidium@9201: enum DepotGUIAction { rubidium@9201: MODE_ERROR, rubidium@9201: MODE_DRAG_VEHICLE, rubidium@9201: MODE_SHOW_VEHICLE, rubidium@9201: MODE_START_STOP, rubidium@9201: }; rubidium@9201: peter1138@9344: DepotGUIAction GetVehicleFromDepotWndPt(int x, int y, const Vehicle **veh, GetDepotVehiclePtData *d) const rubidium@9201: { rubidium@9201: uint xt, row, xm = 0, ym = 0; rubidium@9201: int pos, skip = 0; rubidium@9201: uint16 boxes_in_each_row = this->widget[DEPOT_WIDGET_MATRIX].data & 0xFF; rubidium@9201: rubidium@9201: if (this->type == VEH_TRAIN) { rubidium@9201: xt = 0; rubidium@9201: x -= 23; rubidium@9201: } else { rubidium@9201: xt = x / this->resize.step_width; rubidium@9201: xm = x % this->resize.step_width; rubidium@9201: if (xt >= this->hscroll.cap) return MODE_ERROR; rubidium@9201: rubidium@9201: ym = (y - 14) % this->resize.step_height; rubidium@9201: } rubidium@9201: rubidium@9201: row = (y - 14) / this->resize.step_height; rubidium@9201: if (row >= this->vscroll.cap) return MODE_ERROR; rubidium@9201: rubidium@9201: pos = ((row + this->vscroll.pos) * boxes_in_each_row) + xt; rubidium@9201: peter1138@9351: if ((int)(this->vehicle_list.Length() + this->wagon_list.Length()) <= pos) { rubidium@9201: if (this->type == VEH_TRAIN) { rubidium@9201: d->head = NULL; rubidium@9201: d->wagon = NULL; rubidium@9201: return MODE_DRAG_VEHICLE; rubidium@9201: } else { rubidium@9201: return MODE_ERROR; // empty block, so no vehicle is selected rubidium@9201: } rubidium@9201: } rubidium@9201: peter1138@9351: if ((int)this->vehicle_list.Length() > pos) { peter1138@9351: *veh = this->vehicle_list[pos]; rubidium@9201: skip = this->hscroll.pos; rubidium@9201: } else { peter1138@9351: pos -= this->vehicle_list.Length(); peter1138@9351: *veh = this->wagon_list[pos]; rubidium@9201: /* free wagons don't have an initial loco. */ rubidium@9201: x -= _traininfo_vehicle_width; rubidium@9201: } rubidium@9201: rubidium@9201: switch (this->type) { rubidium@9201: case VEH_TRAIN: { peter1138@9344: const Vehicle *v = *veh; rubidium@9201: d->head = d->wagon = v; rubidium@9201: rubidium@9201: /* either pressed the flag or the number, but only when it's a loco */ rubidium@9201: if (x < 0 && IsFrontEngine(v)) return (x >= -10) ? MODE_START_STOP : MODE_SHOW_VEHICLE; rubidium@9201: rubidium@9201: skip = (skip * 8) / _traininfo_vehicle_width; rubidium@9201: x = (x * 8) / _traininfo_vehicle_width; rubidium@9201: rubidium@9201: /* Skip vehicles that are scrolled off the list */ rubidium@9201: x += skip; rubidium@9201: rubidium@9201: /* find the vehicle in this row that was clicked */ rubidium@9201: while (v != NULL && (x -= v->u.rail.cached_veh_length) >= 0) v = v->Next(); rubidium@9201: rubidium@9201: /* if an articulated part was selected, find its parent */ rubidium@9201: while (v != NULL && IsArticulatedPart(v)) v = v->Previous(); rubidium@9201: rubidium@9201: d->wagon = v; rubidium@9201: rubidium@9201: return MODE_DRAG_VEHICLE; rubidium@9201: } rubidium@9201: break; rubidium@9201: rubidium@9201: case VEH_ROAD: rubidium@9201: if (xm >= 24) return MODE_DRAG_VEHICLE; rubidium@9201: if (xm <= 16) return MODE_SHOW_VEHICLE; rubidium@9201: break; rubidium@9201: rubidium@9201: case VEH_SHIP: rubidium@9201: if (xm >= 19) return MODE_DRAG_VEHICLE; rubidium@9201: if (ym <= 10) return MODE_SHOW_VEHICLE; rubidium@9201: break; rubidium@9201: rubidium@9201: case VEH_AIRCRAFT: rubidium@9201: if (xm >= 12) return MODE_DRAG_VEHICLE; rubidium@9201: if (ym <= 12) return MODE_SHOW_VEHICLE; rubidium@9201: break; rubidium@9201: rubidium@9201: default: NOT_REACHED(); rubidium@9201: } rubidium@9201: return MODE_START_STOP; rubidium@9201: } rubidium@9201: rubidium@9201: void DepotClick(int x, int y) rubidium@9201: { smatz@9213: GetDepotVehiclePtData gdvp = { NULL, NULL }; peter1138@9344: const Vehicle *v = NULL; rubidium@9201: DepotGUIAction mode = this->GetVehicleFromDepotWndPt(x, y, &v, &gdvp); rubidium@9201: rubidium@9201: /* share / copy orders */ rubidium@9201: if (_thd.place_mode != VHM_NONE && mode != MODE_ERROR) { rubidium@9201: _place_clicked_vehicle = (this->type == VEH_TRAIN ? gdvp.head : v); rubidium@9201: return; rubidium@9201: } rubidium@9201: rubidium@9201: if (this->type == VEH_TRAIN) v = gdvp.wagon; rubidium@9201: rubidium@9201: switch (mode) { rubidium@9201: case MODE_ERROR: // invalid rubidium@9201: return; rubidium@9201: rubidium@9201: case MODE_DRAG_VEHICLE: { // start dragging of vehicle rubidium@9201: VehicleID sel = this->sel; rubidium@9201: rubidium@9201: if (this->type == VEH_TRAIN && sel != INVALID_VEHICLE) { rubidium@9201: this->sel = INVALID_VEHICLE; rubidium@9201: TrainDepotMoveVehicle(v, sel, gdvp.head); rubidium@9201: } else if (v != NULL) { rubidium@9201: int image = v->GetImage(DIR_W); rubidium@9201: rubidium@9201: this->sel = v->index; rubidium@9201: this->SetDirty(); rubidium@9201: SetObjectToPlaceWnd(image, GetVehiclePalette(v), VHM_DRAG, this); rubidium@9670: rubidium@9670: switch (v->type) { rubidium@9670: case VEH_TRAIN: rubidium@9670: _cursor.short_vehicle_offset = 16 - v->u.rail.cached_veh_length * 2; rubidium@9670: break; rubidium@9670: rubidium@9670: case VEH_ROAD: rubidium@9670: _cursor.short_vehicle_offset = 16 - v->u.road.cached_veh_length * 2; rubidium@9670: break; rubidium@9670: rubidium@9670: default: rubidium@9670: _cursor.short_vehicle_offset = 0; rubidium@9670: break; rubidium@9670: } rubidium@9201: _cursor.vehchain = _ctrl_pressed; rubidium@9201: } rubidium@9201: } break; rubidium@9201: rubidium@9201: case MODE_SHOW_VEHICLE: // show info window rubidium@9201: ShowVehicleViewWindow(v); rubidium@9201: break; rubidium@9201: rubidium@9201: case MODE_START_STOP: { // click start/stop flag rubidium@9201: uint command; rubidium@9201: rubidium@9201: switch (this->type) { frosch@9921: case VEH_TRAIN: command = CMD_START_STOP_VEHICLE | CMD_MSG(STR_883B_CAN_T_STOP_START_TRAIN); break; frosch@9921: case VEH_ROAD: command = CMD_START_STOP_VEHICLE | CMD_MSG(STR_9015_CAN_T_STOP_START_ROAD_VEHICLE); break; frosch@9921: case VEH_SHIP: command = CMD_START_STOP_VEHICLE | CMD_MSG(STR_9818_CAN_T_STOP_START_SHIP); break; frosch@9921: case VEH_AIRCRAFT: command = CMD_START_STOP_VEHICLE | CMD_MSG(STR_A016_CAN_T_STOP_START_AIRCRAFT); break; rubidium@9201: default: NOT_REACHED(); command = 0; rubidium@9201: } rubidium@9201: DoCommandP(v->tile, v->index, 0, NULL, command); rubidium@9201: } break; rubidium@9201: rubidium@9201: default: NOT_REACHED(); rubidium@9201: } rubidium@9201: } rubidium@9201: rubidium@9201: /** rubidium@9201: * Clones a vehicle rubidium@9201: * @param *v is the original vehicle to clone rubidium@9201: * @param *w is the window of the depot where the clone is build rubidium@9201: */ rubidium@9201: void HandleCloneVehClick(const Vehicle *v, const Window *w) rubidium@9201: { rubidium@9201: uint error_str; rubidium@9201: rubidium@9201: if (v == NULL) return; rubidium@9201: rubidium@9201: if (!v->IsPrimaryVehicle()) { rubidium@9201: v = v->First(); rubidium@9201: /* Do nothing when clicking on a train in depot with no loc attached */ rubidium@9201: if (v->type == VEH_TRAIN && !IsFrontEngine(v)) return; rubidium@9201: } rubidium@9201: rubidium@9201: switch (v->type) { rubidium@9201: case VEH_TRAIN: error_str = CMD_MSG(STR_882B_CAN_T_BUILD_RAILROAD_VEHICLE); break; rubidium@9201: case VEH_ROAD: error_str = CMD_MSG(STR_9009_CAN_T_BUILD_ROAD_VEHICLE); break; rubidium@9201: case VEH_SHIP: error_str = CMD_MSG(STR_980D_CAN_T_BUILD_SHIP); break; rubidium@9201: case VEH_AIRCRAFT: error_str = CMD_MSG(STR_A008_CAN_T_BUILD_AIRCRAFT); break; rubidium@9201: default: return; rubidium@9201: } rubidium@9201: rubidium@9201: DoCommandP(this->window_number, v->index, _ctrl_pressed ? 1 : 0, CcCloneVehicle, CMD_CLONE_VEHICLE | error_str); rubidium@9201: rubidium@9201: ResetObjectToPlace(); rubidium@9201: } rubidium@9201: rubidium@9201: void ResizeDepotButtons(Window *w) rubidium@9201: { rubidium@9201: ResizeButtons(w, DEPOT_WIDGET_BUILD, DEPOT_WIDGET_LOCATION); rubidium@9201: rubidium@9201: if (this->type == VEH_TRAIN) { rubidium@9201: /* Divide the size of DEPOT_WIDGET_SELL into two equally big buttons so DEPOT_WIDGET_SELL and DEPOT_WIDGET_SELL_CHAIN will get the same size. rubidium@9201: * This way it will stay the same even if DEPOT_WIDGET_SELL_CHAIN is resized for some reason */ rubidium@9201: this->widget[DEPOT_WIDGET_SELL_CHAIN].top = ((this->widget[DEPOT_WIDGET_SELL_CHAIN].bottom - this->widget[DEPOT_WIDGET_SELL].top) / 2) + this->widget[DEPOT_WIDGET_SELL].top; rubidium@9201: this->widget[DEPOT_WIDGET_SELL].bottom = this->widget[DEPOT_WIDGET_SELL_CHAIN].top - 1; rubidium@9201: } rubidium@9201: } rubidium@9201: rubidium@9201: /* Function to set up vehicle specific sprites and strings rubidium@9201: * Only use this if it's the same widget, that's used for more than one vehicle type and it needs different text/sprites rubidium@9201: * Vehicle specific text/sprites, that's in a widget, that's only shown for one vehicle type (like sell whole train) is set in the widget array rubidium@9201: */ rubidium@9201: void SetupStringsForDepotWindow(VehicleType type) rubidium@9201: { rubidium@9201: switch (type) { rubidium@9201: default: NOT_REACHED(); rubidium@9201: rubidium@9201: case VEH_TRAIN: rubidium@9201: this->widget[DEPOT_WIDGET_CAPTION].data = STR_8800_TRAIN_DEPOT; rubidium@9201: this->widget[DEPOT_WIDGET_STOP_ALL].tooltips = STR_MASS_STOP_DEPOT_TRAIN_TIP; rubidium@9201: this->widget[DEPOT_WIDGET_START_ALL].tooltips= STR_MASS_START_DEPOT_TRAIN_TIP; rubidium@9201: this->widget[DEPOT_WIDGET_SELL].tooltips = STR_8841_DRAG_TRAIN_VEHICLE_TO_HERE; rubidium@9201: this->widget[DEPOT_WIDGET_SELL_ALL].tooltips = STR_DEPOT_SELL_ALL_BUTTON_TRAIN_TIP; rubidium@9201: rubidium@9201: this->widget[DEPOT_WIDGET_BUILD].data = STR_8815_NEW_VEHICLES; rubidium@9201: this->widget[DEPOT_WIDGET_BUILD].tooltips = STR_8840_BUILD_NEW_TRAIN_VEHICLE; rubidium@9201: this->widget[DEPOT_WIDGET_CLONE].data = STR_CLONE_TRAIN; rubidium@9201: this->widget[DEPOT_WIDGET_CLONE].tooltips = STR_CLONE_TRAIN_DEPOT_INFO; rubidium@9201: rubidium@9201: this->widget[DEPOT_WIDGET_LOCATION].tooltips = STR_8842_CENTER_MAIN_VIEW_ON_TRAIN; rubidium@9201: this->widget[DEPOT_WIDGET_VEHICLE_LIST].data = STR_TRAIN; rubidium@9201: this->widget[DEPOT_WIDGET_VEHICLE_LIST].tooltips = STR_DEPOT_VEHICLE_ORDER_LIST_TRAIN_TIP; rubidium@9201: this->widget[DEPOT_WIDGET_AUTOREPLACE].tooltips = STR_DEPOT_AUTOREPLACE_TRAIN_TIP; rubidium@9201: rubidium@9201: /* Sprites */ rubidium@9201: this->widget[DEPOT_WIDGET_SELL].data = SPR_SELL_TRAIN; rubidium@9201: this->widget[DEPOT_WIDGET_SELL_ALL].data = SPR_SELL_ALL_TRAIN; rubidium@9201: this->widget[DEPOT_WIDGET_AUTOREPLACE].data = SPR_REPLACE_TRAIN; rubidium@9201: break; rubidium@9201: rubidium@9201: case VEH_ROAD: rubidium@9201: this->widget[DEPOT_WIDGET_CAPTION].data = STR_9003_ROAD_VEHICLE_DEPOT; rubidium@9201: this->widget[DEPOT_WIDGET_STOP_ALL].tooltips = STR_MASS_STOP_DEPOT_ROADVEH_TIP; rubidium@9201: this->widget[DEPOT_WIDGET_START_ALL].tooltips= STR_MASS_START_DEPOT_ROADVEH_TIP; rubidium@9201: this->widget[DEPOT_WIDGET_SELL].tooltips = STR_9024_DRAG_ROAD_VEHICLE_TO_HERE; rubidium@9201: this->widget[DEPOT_WIDGET_SELL_ALL].tooltips = STR_DEPOT_SELL_ALL_BUTTON_ROADVEH_TIP; rubidium@9201: rubidium@9201: this->widget[DEPOT_WIDGET_BUILD].data = STR_9004_NEW_VEHICLES; rubidium@9201: this->widget[DEPOT_WIDGET_BUILD].tooltips = STR_9023_BUILD_NEW_ROAD_VEHICLE; rubidium@9201: this->widget[DEPOT_WIDGET_CLONE].data = STR_CLONE_ROAD_VEHICLE; rubidium@9201: this->widget[DEPOT_WIDGET_CLONE].tooltips = STR_CLONE_ROAD_VEHICLE_DEPOT_INFO; rubidium@9201: rubidium@9201: this->widget[DEPOT_WIDGET_LOCATION].tooltips = STR_9025_CENTER_MAIN_VIEW_ON_ROAD; rubidium@9201: this->widget[DEPOT_WIDGET_VEHICLE_LIST].data = STR_LORRY; rubidium@9201: this->widget[DEPOT_WIDGET_VEHICLE_LIST].tooltips = STR_DEPOT_VEHICLE_ORDER_LIST_ROADVEH_TIP; rubidium@9201: this->widget[DEPOT_WIDGET_AUTOREPLACE].tooltips = STR_DEPOT_AUTOREPLACE_ROADVEH_TIP; rubidium@9201: rubidium@9201: /* Sprites */ rubidium@9201: this->widget[DEPOT_WIDGET_SELL].data = SPR_SELL_ROADVEH; rubidium@9201: this->widget[DEPOT_WIDGET_SELL_ALL].data = SPR_SELL_ALL_ROADVEH; rubidium@9201: this->widget[DEPOT_WIDGET_AUTOREPLACE].data = SPR_REPLACE_ROADVEH; rubidium@9201: break; rubidium@9201: rubidium@9201: case VEH_SHIP: rubidium@9201: this->widget[DEPOT_WIDGET_CAPTION].data = STR_9803_SHIP_DEPOT; rubidium@9201: this->widget[DEPOT_WIDGET_STOP_ALL].tooltips = STR_MASS_STOP_DEPOT_SHIP_TIP; rubidium@9201: this->widget[DEPOT_WIDGET_START_ALL].tooltips= STR_MASS_START_DEPOT_SHIP_TIP; rubidium@9201: this->widget[DEPOT_WIDGET_SELL].tooltips = STR_9821_DRAG_SHIP_TO_HERE_TO_SELL; rubidium@9201: this->widget[DEPOT_WIDGET_SELL_ALL].tooltips = STR_DEPOT_SELL_ALL_BUTTON_SHIP_TIP; rubidium@9201: rubidium@9201: this->widget[DEPOT_WIDGET_BUILD].data = STR_9804_NEW_SHIPS; rubidium@9201: this->widget[DEPOT_WIDGET_BUILD].tooltips = STR_9820_BUILD_NEW_SHIP; rubidium@9201: this->widget[DEPOT_WIDGET_CLONE].data = STR_CLONE_SHIP; rubidium@9201: this->widget[DEPOT_WIDGET_CLONE].tooltips = STR_CLONE_SHIP_DEPOT_INFO; rubidium@9201: rubidium@9201: this->widget[DEPOT_WIDGET_LOCATION].tooltips = STR_9822_CENTER_MAIN_VIEW_ON_SHIP; rubidium@9201: this->widget[DEPOT_WIDGET_VEHICLE_LIST].data = STR_SHIP; rubidium@9201: this->widget[DEPOT_WIDGET_VEHICLE_LIST].tooltips = STR_DEPOT_VEHICLE_ORDER_LIST_SHIP_TIP; rubidium@9201: this->widget[DEPOT_WIDGET_AUTOREPLACE].tooltips = STR_DEPOT_AUTOREPLACE_SHIP_TIP; rubidium@9201: rubidium@9201: /* Sprites */ rubidium@9201: this->widget[DEPOT_WIDGET_SELL].data = SPR_SELL_SHIP; rubidium@9201: this->widget[DEPOT_WIDGET_SELL_ALL].data = SPR_SELL_ALL_SHIP; rubidium@9201: this->widget[DEPOT_WIDGET_AUTOREPLACE].data = SPR_REPLACE_SHIP; rubidium@9201: break; rubidium@9201: rubidium@9201: case VEH_AIRCRAFT: rubidium@9201: this->widget[DEPOT_WIDGET_CAPTION].data = STR_A002_AIRCRAFT_HANGAR; rubidium@9201: this->widget[DEPOT_WIDGET_STOP_ALL].tooltips = STR_MASS_STOP_HANGAR_TIP; rubidium@9201: this->widget[DEPOT_WIDGET_START_ALL].tooltips= STR_MASS_START_HANGAR_TIP; rubidium@9201: this->widget[DEPOT_WIDGET_SELL].tooltips = STR_A023_DRAG_AIRCRAFT_TO_HERE_TO; rubidium@9201: this->widget[DEPOT_WIDGET_SELL_ALL].tooltips = STR_DEPOT_SELL_ALL_BUTTON_AIRCRAFT_TIP; rubidium@9201: rubidium@9201: this->widget[DEPOT_WIDGET_BUILD].data = STR_A003_NEW_AIRCRAFT; rubidium@9201: this->widget[DEPOT_WIDGET_BUILD].tooltips = STR_A022_BUILD_NEW_AIRCRAFT; rubidium@9201: this->widget[DEPOT_WIDGET_CLONE].data = STR_CLONE_AIRCRAFT; rubidium@9201: this->widget[DEPOT_WIDGET_CLONE].tooltips = STR_CLONE_AIRCRAFT_INFO_HANGAR_WINDOW; rubidium@9201: rubidium@9201: this->widget[DEPOT_WIDGET_LOCATION].tooltips = STR_A024_CENTER_MAIN_VIEW_ON_HANGAR; rubidium@9201: this->widget[DEPOT_WIDGET_VEHICLE_LIST].data = STR_PLANE; rubidium@9201: this->widget[DEPOT_WIDGET_VEHICLE_LIST].tooltips = STR_DEPOT_VEHICLE_ORDER_LIST_AIRCRAFT_TIP; rubidium@9201: this->widget[DEPOT_WIDGET_AUTOREPLACE].tooltips = STR_DEPOT_AUTOREPLACE_AIRCRAFT_TIP; rubidium@9201: rubidium@9201: /* Sprites */ rubidium@9201: this->widget[DEPOT_WIDGET_SELL].data = SPR_SELL_AIRCRAFT; rubidium@9201: this->widget[DEPOT_WIDGET_SELL_ALL].data = SPR_SELL_ALL_AIRCRAFT; rubidium@9201: this->widget[DEPOT_WIDGET_AUTOREPLACE].data = SPR_REPLACE_AIRCRAFT; rubidium@9201: break; rubidium@9201: } rubidium@9201: } rubidium@9201: rubidium@9201: void CreateDepotListWindow(VehicleType type) rubidium@9201: { rubidium@9201: this->type = type; rubidium@9201: _backup_orders_tile = 0; rubidium@9201: rubidium@10207: assert(IsCompanyBuildableVehicleType(type)); // ensure that we make the call with a valid type rubidium@9201: rubidium@9201: /* Resize the window according to the vehicle type */ rubidium@9201: rubidium@9201: /* Set the number of blocks in each direction */ rubidium@9201: this->vscroll.cap = _resize_cap[type][0]; rubidium@9201: this->hscroll.cap = _resize_cap[type][1]; rubidium@9201: rubidium@9201: /* Set the block size */ rubidium@9201: this->resize.step_width = _block_sizes[type][0]; rubidium@9201: this->resize.step_height = _block_sizes[type][1]; rubidium@9201: rubidium@9201: /* Enlarge the window to fit with the selected number of blocks of the selected size */ rubidium@9201: ResizeWindow(this, rubidium@9201: _block_sizes[type][0] * this->hscroll.cap, rubidium@9201: _block_sizes[type][1] * this->vscroll.cap); rubidium@9201: rubidium@9201: if (type == VEH_TRAIN) { rubidium@9201: /* Make space for the horizontal scrollbar vertically, and the unit rubidium@9201: * number, flag, and length counter horizontally. */ rubidium@9201: ResizeWindow(this, 36, 12); rubidium@9201: /* substract the newly added space from the matrix since it was meant for the scrollbar */ rubidium@9201: this->widget[DEPOT_WIDGET_MATRIX].bottom -= 12; rubidium@9201: } rubidium@9201: rubidium@9201: /* Set the minimum window size to the current window size */ rubidium@9201: this->resize.width = this->width; rubidium@9201: this->resize.height = this->height; rubidium@9201: rubidium@9201: this->SetupStringsForDepotWindow(type); rubidium@9201: rubidium@9201: this->widget[DEPOT_WIDGET_MATRIX].data = rubidium@9201: (this->vscroll.cap * 0x100) // number of rows to draw on the background rubidium@9201: + (type == VEH_TRAIN ? 1 : this->hscroll.cap); // number of boxes in each row. Trains always have just one Darkvater@5269: Darkvater@5269: rubidium@9201: this->SetWidgetsHiddenState(type != VEH_TRAIN, rubidium@9201: DEPOT_WIDGET_H_SCROLL, rubidium@9201: DEPOT_WIDGET_SELL_CHAIN, rubidium@9201: WIDGET_LIST_END); bjarni@4638: rubidium@9201: ResizeDepotButtons(this); rubidium@9201: } bjarni@4638: rubidium@9201: virtual void OnInvalidateData(int data) rubidium@9201: { rubidium@9201: this->generate_list = true; rubidium@9201: } bjarni@4638: rubidium@9201: virtual void OnPaint() rubidium@9201: { rubidium@9201: if (this->generate_list) { rubidium@9201: /* Generate the vehicle list rubidium@9201: * It's ok to use the wagon pointers for non-trains as they will be ignored */ peter1138@9351: BuildDepotVehicleList(this->type, this->window_number, &this->vehicle_list, &this->wagon_list); rubidium@9201: this->generate_list = false; peter1138@9351: DepotSortList(&this->vehicle_list); rubidium@9201: } rubidium@9201: DrawDepotWindow(this); rubidium@9201: } Darkvater@4935: rubidium@9201: virtual void OnClick(Point pt, int widget) rubidium@9201: { rubidium@9201: switch (widget) { rubidium@9201: case DEPOT_WIDGET_MATRIX: // List rubidium@9201: this->DepotClick(pt.x, pt.y); rubidium@9201: break; bjarni@4638: rubidium@9201: case DEPOT_WIDGET_BUILD: // Build vehicle rubidium@9201: ResetObjectToPlace(); rubidium@9201: ShowBuildVehicleWindow(this->window_number, this->type); rubidium@9201: break; bjarni@4640: rubidium@9201: case DEPOT_WIDGET_CLONE: // Clone button rubidium@9201: this->InvalidateWidget(DEPOT_WIDGET_CLONE); rubidium@9201: this->ToggleWidgetLoweredState(DEPOT_WIDGET_CLONE); rubidium@9201: rubidium@9201: if (this->IsWidgetLowered(DEPOT_WIDGET_CLONE)) { rubidium@9201: static const CursorID clone_icons[] = { rubidium@9201: SPR_CURSOR_CLONE_TRAIN, SPR_CURSOR_CLONE_ROADVEH, rubidium@9201: SPR_CURSOR_CLONE_SHIP, SPR_CURSOR_CLONE_AIRPLANE rubidium@9201: }; rubidium@9201: rubidium@9201: _place_clicked_vehicle = NULL; rubidium@9201: SetObjectToPlaceWnd(clone_icons[this->type], PAL_NONE, VHM_RECT, this); rubidium@9201: } else { rubidium@9201: ResetObjectToPlace(); rubidium@9201: } bjarni@4640: break; bjarni@4640: rubidium@9201: case DEPOT_WIDGET_LOCATION: rubidium@9201: if (_ctrl_pressed) { rubidium@9201: ShowExtraViewPortWindow(this->window_number); rubidium@9201: } else { rubidium@9201: ScrollMainWindowToTile(this->window_number); rubidium@9201: } rubidium@9201: break; bjarni@4638: rubidium@9201: case DEPOT_WIDGET_STOP_ALL: rubidium@9201: case DEPOT_WIDGET_START_ALL: rubidium@9201: DoCommandP(this->window_number, 0, this->type | (widget == DEPOT_WIDGET_START_ALL ? (1 << 5) : 0), NULL, CMD_MASS_START_STOP); rubidium@9201: break; bjarni@4638: rubidium@9201: case DEPOT_WIDGET_SELL_ALL: rubidium@9201: /* Only open the confimation window if there are anything to sell */ peter1138@9351: if (this->vehicle_list.Length() != 0 || this->wagon_list.Length() != 0) { rubidium@9201: static const StringID confirm_captions[] = { rubidium@9201: STR_8800_TRAIN_DEPOT, rubidium@9201: STR_9003_ROAD_VEHICLE_DEPOT, rubidium@9201: STR_9803_SHIP_DEPOT, rubidium@9201: STR_A002_AIRCRAFT_HANGAR rubidium@9201: }; rubidium@9201: TileIndex tile = this->window_number; rubidium@9201: byte vehtype = this->type; bjarni@4638: rubidium@9201: SetDParam(0, (vehtype == VEH_AIRCRAFT) ? GetStationIndex(tile) : GetDepotByTile(tile)->town_index); rubidium@9201: ShowQuery( rubidium@9201: confirm_captions[vehtype], rubidium@9201: STR_DEPOT_SELL_CONFIRMATION_TEXT, rubidium@9201: this, rubidium@9201: DepotSellAllConfirmationCallback rubidium@9201: ); rubidium@9201: } rubidium@9201: break; rubidium@9201: rubidium@9201: case DEPOT_WIDGET_VEHICLE_LIST: rubidium@9201: ShowVehicleListWindow(GetTileOwner(this->window_number), this->type, (TileIndex)this->window_number); rubidium@9201: break; rubidium@9201: rubidium@9201: case DEPOT_WIDGET_AUTOREPLACE: rubidium@9201: DoCommandP(this->window_number, this->type, 0, NULL, CMD_DEPOT_MASS_AUTOREPLACE); rubidium@9201: break; rubidium@9201: rubidium@9201: } rubidium@9201: } rubidium@9201: frosch@9782: virtual void OnRightClick(Point pt, int widget) frosch@9782: { frosch@9782: if (widget != DEPOT_WIDGET_MATRIX) return; frosch@9782: frosch@9782: GetDepotVehiclePtData gdvp = { NULL, NULL }; frosch@9782: const Vehicle *v = NULL; frosch@9782: DepotGUIAction mode = this->GetVehicleFromDepotWndPt(pt.x, pt.y, &v, &gdvp); frosch@9782: frosch@9782: if (this->type == VEH_TRAIN) v = gdvp.wagon; frosch@9782: frosch@9782: if (v != NULL && mode == MODE_DRAG_VEHICLE) { frosch@9782: AcceptedCargo capacity, loaded; frosch@9782: memset(capacity, 0, sizeof(capacity)); frosch@9782: memset(loaded, 0, sizeof(loaded)); frosch@9782: frosch@9782: /* Display info for single (articulated) vehicle, or for whole chain starting with selected vehicle */ frosch@9782: bool whole_chain = (this->type == VEH_TRAIN && _ctrl_pressed); frosch@9782: frosch@9782: /* loop through vehicle chain and collect cargos */ frosch@9782: uint num = 0; frosch@9782: for (const Vehicle *w = v; w != NULL; w = w->Next()) { frosch@9782: if (w->cargo_cap > 0 && w->cargo_type < NUM_CARGO) { frosch@9782: capacity[w->cargo_type] += w->cargo_cap; frosch@9782: loaded [w->cargo_type] += w->cargo.Count(); frosch@9782: } frosch@9782: frosch@9782: if (w->type == VEH_TRAIN && !EngineHasArticPart(w)) { frosch@9782: num++; frosch@9782: if (!whole_chain) break; frosch@9782: } frosch@9782: } frosch@9782: frosch@9782: /* Build tooltipstring */ frosch@9782: static char details[1024]; frosch@9782: details[0] = '\0'; frosch@9782: char *pos = details; frosch@9782: frosch@9782: for (CargoID cargo_type = 0; cargo_type < NUM_CARGO; cargo_type++) { frosch@9782: if (capacity[cargo_type] == 0) continue; frosch@9782: frosch@9782: SetDParam(0, cargo_type); // {CARGO} #1 frosch@9782: SetDParam(1, loaded[cargo_type]); // {CARGO} #2 frosch@9782: SetDParam(2, cargo_type); // {SHORTCARGO} #1 frosch@9782: SetDParam(3, capacity[cargo_type]); // {SHORTCARGO} #2 frosch@9782: pos = GetString(pos, STR_DEPOT_VEHICLE_TOOLTIP_CARGO, lastof(details)); frosch@9782: } frosch@9782: frosch@9782: /* Show tooltip window */ frosch@9782: uint64 args[2]; frosch@9782: args[0] = (whole_chain ? num : v->engine_type); glx@9826: args[1] = (uint64)(size_t)details; frosch@9782: GuiShowTooltips(whole_chain ? STR_DEPOT_VEHICLE_TOOLTIP_CHAIN : STR_DEPOT_VEHICLE_TOOLTIP, 2, args); frosch@9782: } else { frosch@9782: /* Show tooltip help */ frosch@9782: StringID tooltip = INVALID_STRING_ID; frosch@9782: switch (this->type) { frosch@9782: case VEH_TRAIN: tooltip = STR_883F_TRAINS_CLICK_ON_TRAIN_FOR; break; frosch@9782: case VEH_ROAD: tooltip = STR_9022_VEHICLES_CLICK_ON_VEHICLE; break; frosch@9782: case VEH_SHIP: tooltip = STR_981F_SHIPS_CLICK_ON_SHIP_FOR; break; frosch@9782: case VEH_AIRCRAFT: tooltip = STR_A021_AIRCRAFT_CLICK_ON_AIRCRAFT;break; frosch@9782: default: NOT_REACHED(); frosch@9782: } frosch@9782: GuiShowTooltips(tooltip); frosch@9782: } frosch@9782: } frosch@9782: frosch@9782: rubidium@9201: virtual void OnPlaceObject(Point pt, TileIndex tile) rubidium@9201: { rubidium@9201: const Vehicle *v = CheckMouseOverVehicle(); rubidium@9201: rubidium@9201: if (v != NULL) HandleCloneVehClick(v, this); rubidium@9201: } rubidium@9201: rubidium@9201: virtual void OnPlaceObjectAbort() rubidium@9201: { rubidium@9201: /* abort clone */ rubidium@9201: this->RaiseWidget(DEPOT_WIDGET_CLONE); rubidium@9201: this->InvalidateWidget(DEPOT_WIDGET_CLONE); rubidium@9201: rubidium@9201: /* abort drag & drop */ rubidium@9201: this->sel = INVALID_VEHICLE; rubidium@9201: this->InvalidateWidget(DEPOT_WIDGET_MATRIX); rubidium@9201: }; rubidium@9201: rubidium@9201: /* check if a vehicle in a depot was clicked.. */ rubidium@9201: virtual void OnMouseLoop() rubidium@9201: { rubidium@9201: const Vehicle *v = _place_clicked_vehicle; rubidium@9201: rubidium@9201: /* since OTTD checks all open depot windows, we will make sure that it triggers the one with a clicked clone button */ rubidium@9201: if (v != NULL && this->IsWidgetLowered(DEPOT_WIDGET_CLONE)) { rubidium@9201: _place_clicked_vehicle = NULL; rubidium@9201: HandleCloneVehClick(v, this); rubidium@9201: } rubidium@9201: } rubidium@9201: rubidium@9201: virtual void OnDragDrop(Point pt, int widget) rubidium@9201: { rubidium@9201: switch (widget) { rubidium@9201: case DEPOT_WIDGET_MATRIX: { peter1138@9344: const Vehicle *v = NULL; rubidium@9201: VehicleID sel = this->sel; rubidium@9201: rubidium@9201: this->sel = INVALID_VEHICLE; rubidium@9201: this->SetDirty(); rubidium@9201: rubidium@9201: if (this->type == VEH_TRAIN) { smatz@9225: GetDepotVehiclePtData gdvp = { NULL, NULL }; rubidium@9201: rubidium@9201: if (this->GetVehicleFromDepotWndPt(pt.x, pt.y, &v, &gdvp) == MODE_DRAG_VEHICLE && rubidium@9201: sel != INVALID_VEHICLE) { rubidium@9201: if (gdvp.wagon != NULL && gdvp.wagon->index == sel && _ctrl_pressed) { rubidium@9201: DoCommandP(GetVehicle(sel)->tile, GetVehicle(sel)->index, true, NULL, CMD_REVERSE_TRAIN_DIRECTION | CMD_MSG(STR_9033_CAN_T_MAKE_VEHICLE_TURN)); rubidium@9201: } else if (gdvp.wagon == NULL || gdvp.wagon->index != sel) { rubidium@9201: TrainDepotMoveVehicle(gdvp.wagon, sel, gdvp.head); rubidium@9201: } else if (gdvp.head != NULL && IsFrontEngine(gdvp.head)) { rubidium@9201: ShowVehicleViewWindow(gdvp.head); bjarni@4638: } bjarni@4638: } rubidium@9201: } else if (this->GetVehicleFromDepotWndPt(pt.x, pt.y, &v, NULL) == MODE_DRAG_VEHICLE && rubidium@9201: v != NULL && rubidium@9201: sel == v->index) { rubidium@9201: ShowVehicleViewWindow(v); rubidium@9201: } rubidium@9201: } break; bjarni@4638: rubidium@9201: case DEPOT_WIDGET_SELL: case DEPOT_WIDGET_SELL_CHAIN: rubidium@9201: if (!this->IsWidgetDisabled(DEPOT_WIDGET_SELL) && rubidium@9201: this->sel != INVALID_VEHICLE) { rubidium@9201: uint command; smatz@8828: rubidium@9201: if (this->IsWidgetDisabled(widget)) return; rubidium@9201: if (this->sel == INVALID_VEHICLE) return; rubidium@9201: rubidium@9201: this->HandleButtonClick(widget); rubidium@9201: peter1138@9344: const Vehicle *v = GetVehicle(this->sel); rubidium@9201: this->sel = INVALID_VEHICLE; rubidium@9201: this->SetDirty(); rubidium@9201: peter1138@9344: int sell_cmd = (v->type == VEH_TRAIN && (widget == DEPOT_WIDGET_SELL_CHAIN || _ctrl_pressed)) ? 1 : 0; rubidium@9201: peter1138@9344: bool is_engine = (!(v->type == VEH_TRAIN && !IsFrontEngine(v))); rubidium@9201: rubidium@9201: if (is_engine) { rubidium@9201: _backup_orders_tile = v->tile; rubidium@9201: BackupVehicleOrders(v); rubidium@9201: } rubidium@9201: rubidium@9201: switch (v->type) { rubidium@9201: case VEH_TRAIN: command = CMD_SELL_RAIL_WAGON | CMD_MSG(STR_8839_CAN_T_SELL_RAILROAD_VEHICLE); break; rubidium@9201: case VEH_ROAD: command = CMD_SELL_ROAD_VEH | CMD_MSG(STR_9014_CAN_T_SELL_ROAD_VEHICLE); break; rubidium@9201: case VEH_SHIP: command = CMD_SELL_SHIP | CMD_MSG(STR_980C_CAN_T_SELL_SHIP); break; rubidium@9201: case VEH_AIRCRAFT: command = CMD_SELL_AIRCRAFT | CMD_MSG(STR_A01C_CAN_T_SELL_AIRCRAFT); break; rubidium@9201: default: NOT_REACHED(); command = 0; rubidium@9201: } rubidium@9201: rubidium@9201: if (!DoCommandP(v->tile, v->index, sell_cmd, NULL, command) && is_engine) _backup_orders_tile = 0; rubidium@9201: } rubidium@9201: break; rubidium@9201: default: rubidium@9201: this->sel = INVALID_VEHICLE; rubidium@9201: this->SetDirty(); rubidium@9201: } rubidium@9201: _cursor.vehchain = false; rubidium@9201: } rubidium@9201: rubidium@9201: virtual void OnResize(Point new_size, Point delta) rubidium@9201: { rubidium@9201: this->vscroll.cap += delta.y / (int)this->resize.step_height; rubidium@9201: this->hscroll.cap += delta.x / (int)this->resize.step_width; rubidium@9201: this->widget[DEPOT_WIDGET_MATRIX].data = (this->vscroll.cap << 8) + (this->type == VEH_TRAIN ? 1 : this->hscroll.cap); rubidium@9201: ResizeDepotButtons(this); rubidium@9201: } rubidium@9201: rubidium@9285: virtual EventState OnCTRLStateChange() rubidium@9201: { rubidium@9201: if (this->sel != INVALID_VEHICLE) { rubidium@9201: _cursor.vehchain = _ctrl_pressed; rubidium@9201: this->InvalidateWidget(DEPOT_WIDGET_MATRIX); smatz@9931: return ES_HANDLED; rubidium@9201: } rubidium@9201: smatz@9931: return ES_NOT_HANDLED; rubidium@9201: } rubidium@9201: }; rubidium@9201: rubidium@9201: static void DepotSellAllConfirmationCallback(Window *win, bool confirmed) rubidium@9201: { rubidium@9201: if (confirmed) { rubidium@9201: DepotWindow *w = (DepotWindow*)win; rubidium@9201: TileIndex tile = w->window_number; rubidium@9201: byte vehtype = w->type; rubidium@9201: DoCommandP(tile, vehtype, 0, NULL, CMD_DEPOT_SELL_ALL_VEHICLES); bjarni@4638: } bjarni@4638: } bjarni@4638: bjarni@4638: /** Opens a depot window bjarni@4638: * @param tile The tile where the depot/hangar is located bjarni@4638: * @param type The type of vehicles in the depot bjarni@4638: */ rubidium@6638: void ShowDepotWindow(TileIndex tile, VehicleType type) bjarni@4638: { rubidium@9201: DepotWindow *w; bjarni@4638: bjarni@4638: switch (type) { Darkvater@5269: default: NOT_REACHED(); rubidium@6259: case VEH_TRAIN: rubidium@9201: w = AllocateWindowDescFront(&_train_depot_desc, tile); break; rubidium@6259: case VEH_ROAD: rubidium@9201: w = AllocateWindowDescFront(&_road_depot_desc, tile); break; rubidium@6259: case VEH_SHIP: rubidium@9201: w = AllocateWindowDescFront(&_ship_depot_desc, tile); break; rubidium@6259: case VEH_AIRCRAFT: rubidium@9201: w = AllocateWindowDescFront(&_aircraft_depot_desc, tile); break; bjarni@4638: } bjarni@4638: rubidium@9232: if (w == NULL) return; rubidium@9232: rubidium@9201: w->caption_color = GetTileOwner(tile); rubidium@9201: w->CreateDepotListWindow(type); bjarni@4638: } bjarni@5255: bjarni@5255: /** Removes the highlight of a vehicle in a depot window bjarni@5255: * @param *v Vehicle to remove all highlights from bjarni@5255: */ bjarni@5255: void DeleteDepotHighlightOfVehicle(const Vehicle *v) bjarni@5255: { rubidium@9201: DepotWindow *w; bjarni@5255: bjarni@5260: /* If we haven't got any vehicles on the mouse pointer, we haven't got any highlighted in any depots either rubidium@9201: * If that is the case, we can skip looping though the windows and save time rubidium@9201: */ bjarni@5260: if (_special_mouse_mode != WSM_DRAGDROP) return; bjarni@5260: rubidium@9201: w = dynamic_cast(FindWindowById(WC_VEHICLE_DEPOT, v->tile)); Darkvater@5265: if (w != NULL) { rubidium@9201: w->sel = INVALID_VEHICLE; Darkvater@5265: ResetObjectToPlace(); bjarni@5255: } bjarni@5255: }