tron@2186: /* $Id$ */ tron@2186: truelight@0: #include "stdafx.h" Darkvater@1891: #include "openttd.h" tron@1299: #include "debug.h" tron@2163: #include "functions.h" tron@4041: #include "rail_map.h" hackykid@1922: #include "table/sprites.h" tron@507: #include "table/strings.h" tron@679: #include "map.h" truelight@0: #include "window.h" truelight@0: #include "gui.h" truelight@0: #include "gfx.h" truelight@0: #include "vehicle.h" truelight@0: #include "viewport.h" truelight@0: #include "station.h" truelight@0: #include "command.h" truelight@0: #include "player.h" truelight@0: #include "engine.h" tron@588: #include "vehicle_gui.h" truelight@1313: #include "depot.h" bjarni@2676: #include "train.h" peter1138@2962: #include "newgrf_engine.h" rubidium@4261: #include "date.h" darkvater@420: hackykid@1907: /** hackykid@1907: * Draw the purchase info details of train engine at a given location. hackykid@1907: * @param x,y location where to draw the info hackykid@1907: * @param engine_number the engine of which to draw the info of hackykid@1907: */ hackykid@1907: void DrawTrainEnginePurchaseInfo(int x, int y, EngineID engine_number) bjarni@842: { bjarni@842: const RailVehicleInfo *rvi = RailVehInfo(engine_number); belugas@4171: const Engine *e = GetEngine(engine_number); bjarni@842: int multihead = (rvi->flags&RVI_MULTIHEAD?1:0); bjarni@842: YearMonthDay ymd; rubidium@4288: ConvertDateToYMD(e->intro_date, &ymd); bjarni@842: hackykid@1907: /* Purchase Cost - Engine weight */ bjarni@842: SetDParam(0, rvi->base_cost * (_price.build_railvehicle >> 3) >> 5); bjarni@842: SetDParam(1, rvi->weight << multihead); hackykid@1907: DrawString(x,y, STR_PURCHASE_INFO_COST_WEIGHT, 0); hackykid@1907: y += 10; bjarni@842: hackykid@1907: /* Max speed - Engine power */ peter1138@3477: SetDParam(0, rvi->max_speed); hackykid@1907: SetDParam(1, rvi->power << multihead); hackykid@1907: DrawString(x,y, STR_PURCHASE_INFO_SPEED_POWER, 0); hackykid@1907: y += 10; hackykid@1907: hackykid@1907: /* Running cost */ peter1138@2840: SetDParam(0, (rvi->running_cost_base * _price.running_rail[rvi->running_cost_class] >> 8) << multihead); hackykid@1907: DrawString(x,y, STR_PURCHASE_INFO_RUNNINGCOST, 0); hackykid@1907: y += 10; hackykid@1907: hackykid@1908: /* Powered wagons power - Powered wagons extra weight */ hackykid@1908: if (rvi->pow_wag_power != 0) { hackykid@1908: SetDParam(0, rvi->pow_wag_power); hackykid@1908: SetDParam(1, rvi->pow_wag_weight); hackykid@1908: DrawString(x,y, STR_PURCHASE_INFO_PWAGPOWER_PWAGWEIGHT, 0); hackykid@1908: y += 10; hackykid@1908: }; hackykid@1908: hackykid@1907: /* Cargo type + capacity, or N/A */ hackykid@1907: SetDParam(0, STR_8838_N_A); hackykid@1907: SetDParam(2, STR_EMPTY); bjarni@842: if (rvi->capacity != 0) { ludde@2084: SetDParam(0, _cargoc.names_long[rvi->cargo_type]); hackykid@1907: SetDParam(1, rvi->capacity << multihead); hackykid@1907: SetDParam(2, STR_9842_REFITTABLE); bjarni@842: } hackykid@1907: DrawString(x,y, STR_PURCHASE_INFO_CAPACITY, 0); hackykid@1907: y += 10; bjarni@842: hackykid@1907: /* Design date - Life length */ rubidium@4293: SetDParam(0, ymd.year); hackykid@1907: SetDParam(1, e->lifelength); hackykid@1907: DrawString(x,y, STR_PURCHASE_INFO_DESIGNED_LIFE, 0); hackykid@1907: y += 10; bjarni@842: hackykid@1907: /* Reliability */ hackykid@1907: SetDParam(0, e->reliability * 100 >> 16); hackykid@1907: DrawString(x,y, STR_PURCHASE_INFO_RELIABILITY, 0); hackykid@1907: y += 10; peter1138@3651: peter1138@3651: /* Additional text from NewGRF */ peter1138@3651: // XXX 227 will become a calculated width... peter1138@3651: y += ShowAdditionalText(x, y, 227, engine_number); bjarni@842: } bjarni@842: hackykid@1907: /** hackykid@1907: * Draw the purchase info details of a train wagon at a given location. hackykid@1907: * @param x,y location where to draw the info hackykid@1907: * @param engine_number the engine of which to draw the info of hackykid@1907: */ hackykid@1907: void DrawTrainWagonPurchaseInfo(int x, int y, EngineID engine_number) bjarni@842: { bjarni@842: const RailVehicleInfo *rvi = RailVehInfo(engine_number); peter1138@3393: bool refittable = (EngInfo(engine_number)->refit_mask != 0); truelight@867: hackykid@1907: /* Purchase cost */ hackykid@1907: SetDParam(0, (rvi->base_cost * _price.build_railwagon) >> 8); hackykid@1907: DrawString(x, y, STR_PURCHASE_INFO_COST, 0); hackykid@1907: y += 10; hackykid@1907: hackykid@1907: /* Wagon weight - (including cargo) */ hackykid@1907: SetDParam(0, rvi->weight); hackykid@1907: SetDParam(1, (_cargoc.weights[rvi->cargo_type] * rvi->capacity >> 4) + rvi->weight); hackykid@1907: DrawString(x, y, STR_PURCHASE_INFO_WEIGHT_CWEIGHT, 0); hackykid@1907: y += 10; hackykid@1907: peter1138@3685: /* Cargo type + capacity, or N/A */ peter1138@3685: SetDParam(0, STR_8838_N_A); peter1138@3685: SetDParam(2, STR_EMPTY); peter1138@3685: if (rvi->capacity != 0) { peter1138@3685: SetDParam(0, _cargoc.names_long[rvi->cargo_type]); peter1138@3685: SetDParam(1, rvi->capacity); peter1138@3685: SetDParam(2, refittable ? STR_9842_REFITTABLE : STR_EMPTY); peter1138@3685: } hackykid@1907: DrawString(x, y, STR_PURCHASE_INFO_CAPACITY, 0); hackykid@1907: y += 10; peter1138@2443: peter1138@2443: /* Wagon speed limit, displayed if above zero */ peter1138@2456: if (rvi->max_speed > 0 && _patches.wagon_speed_limits) { peter1138@3477: SetDParam(0, rvi->max_speed); peter1138@2443: DrawString(x,y, STR_PURCHASE_INFO_SPEED, 0); peter1138@2443: y += 10; peter1138@2443: } peter1138@3651: peter1138@3651: /* Additional text from NewGRF */ peter1138@3651: y += ShowAdditionalText(x, y, 227, engine_number); bjarni@842: } truelight@0: tron@1977: void CcBuildWagon(bool success, TileIndex tile, uint32 p1, uint32 p2) truelight@0: { belugas@4171: Vehicle *v, *found; truelight@0: tron@4077: if (!success) return; truelight@0: truelight@0: // find a locomotive in the depot. truelight@0: found = NULL; truelight@0: FOR_ALL_VEHICLES(v) { bjarni@2676: if (v->type == VEH_Train && IsFrontEngine(v) && truelight@0: v->tile == tile && truelight@0: v->u.rail.track == 0x80) { tron@4077: if (found != NULL) return; // must be exactly one. truelight@0: found = v; truelight@0: } truelight@0: } truelight@0: truelight@0: // if we found a loco, truelight@0: if (found != NULL) { truelight@0: found = GetLastVehicleInChain(found); truelight@0: // put the new wagon at the end of the loco. tron@3948: DoCommandP(0, _new_vehicle_id | (found->index << 16), 0, NULL, CMD_MOVE_RAIL_VEHICLE); tron@588: RebuildVehicleLists(); truelight@0: } truelight@0: } truelight@0: tron@1977: void CcBuildLoco(bool success, TileIndex tile, uint32 p1, uint32 p2) truelight@0: { belugas@4171: const Vehicle *v; truelight@0: tron@2639: if (!success) return; truelight@193: tron@3948: v = GetVehicle(_new_vehicle_id); truelight@0: if (tile == _backup_orders_tile) { truelight@0: _backup_orders_tile = 0; truelight@0: RestoreVehicleOrders(v, _backup_orders_data); truelight@0: } truelight@0: ShowTrainViewWindow(v); truelight@0: } truelight@0: tron@3887: void CcCloneTrain(bool success, TileIndex tile, uint32 p1, uint32 p2) bjarni@2244: { tron@3948: if (success) ShowTrainViewWindow(GetVehicle(_new_vehicle_id)); bjarni@2244: } bjarni@2244: darkvater@524: static void engine_drawing_loop(int *x, int *y, int *pos, int *sel, belugas@4171: EngineID *selected_id, RailType railtype, byte show_max, bool is_engine) darkvater@524: { peter1138@2971: EngineID j; darkvater@524: peter1138@2971: for (j = 0; j < NUM_TRAIN_ENGINES; j++) { peter1138@2971: EngineID i = GetRailVehAtPosition(j); tron@1926: const Engine *e = GetEngine(i); tron@539: const RailVehicleInfo *rvi = RailVehInfo(i); darkvater@524: celestar@3355: if (!HasPowerOnRail(e->railtype, railtype) || !(rvi->flags & RVI_WAGON) != is_engine || darkvater@524: !HASBIT(e->player_avail, _local_player)) darkvater@524: continue; darkvater@524: tron@4077: if (*sel == 0) *selected_id = i; darkvater@524: truelight@867: if (IS_INT_INSIDE(--*pos, -show_max, 0)) { truelight@867: DrawString(*x + 59, *y + 2, GetCustomEngineName(i), *sel == 0 ? 0xC : 0x10); peter1138@3040: DrawTrainEngine(*x + 29, *y + 6, i, GetEnginePalette(i, _local_player)); darkvater@524: *y += 14; darkvater@524: } darkvater@524: --*sel; darkvater@524: } darkvater@524: } darkvater@524: truelight@0: static void NewRailVehicleWndProc(Window *w, WindowEvent *e) truelight@0: { tron@2952: switch (e->event) { truelight@0: case WE_PAINT: truelight@193: tron@4077: if (w->window_number == 0) SETBIT(w->disabled_state, 5); truelight@0: truelight@0: { truelight@0: int count = 0; tron@2520: RailType railtype = WP(w,buildtrain_d).railtype; tron@2477: EngineID i; darkvater@460: darkvater@460: for (i = 0; i < NUM_TRAIN_ENGINES; i++) { tron@1926: const Engine *e = GetEngine(i); tron@4077: if (HasPowerOnRail(e->railtype, railtype) && tron@4077: HASBIT(e->player_avail, _local_player)) { truelight@0: count++; tron@4077: } darkvater@460: } truelight@0: SetVScrollCount(w, count); truelight@0: } truelight@0: tron@534: SetDParam(0, WP(w,buildtrain_d).railtype + STR_881C_NEW_RAIL_VEHICLES); truelight@0: DrawWindowWidgets(w); truelight@193: truelight@0: { tron@2520: RailType railtype = WP(w,buildtrain_d).railtype; truelight@0: int sel = WP(w,buildtrain_d).sel_index; truelight@0: int pos = w->vscroll.pos; truelight@0: int x = 1; truelight@0: int y = 15; tron@2498: EngineID selected_id = INVALID_ENGINE; truelight@0: darkvater@460: /* Ensure that custom engines which substituted wagons darkvater@524: * are sorted correctly. darkvater@524: * XXX - DO NOT EVER DO THIS EVER AGAIN! GRRR hacking in wagons as darkvater@524: * engines to get more types.. Stays here until we have our own format darkvater@524: * then it is exit!!! */ truelight@867: engine_drawing_loop(&x, &y, &pos, &sel, &selected_id, railtype, w->vscroll.cap, true); // True engines truelight@867: engine_drawing_loop(&x, &y, &pos, &sel, &selected_id, railtype, w->vscroll.cap, false); // Feeble wagons truelight@0: truelight@0: WP(w,buildtrain_d).sel_engine = selected_id; truelight@0: tron@2498: if (selected_id != INVALID_ENGINE) { tron@539: const RailVehicleInfo *rvi = RailVehInfo(selected_id); truelight@0: truelight@0: if (!(rvi->flags & RVI_WAGON)) { truelight@0: /* it's an engine */ hackykid@1907: DrawTrainEnginePurchaseInfo(2, w->widget[4].top + 1,selected_id); truelight@0: } else { truelight@0: /* it's a wagon */ hackykid@1907: DrawTrainWagonPurchaseInfo(2, w->widget[4].top + 1, selected_id); truelight@0: } truelight@0: } truelight@0: } truelight@0: break; truelight@0: truelight@0: case WE_CLICK: { tron@2952: switch (e->click.widget) { truelight@0: case 2: { truelight@0: uint i = (e->click.pt.y - 14) / 14; truelight@867: if (i < w->vscroll.cap) { truelight@0: WP(w,buildtrain_d).sel_index = i + w->vscroll.pos; truelight@0: SetWindowDirty(w); truelight@0: } truelight@0: } break; truelight@0: case 5: { tron@2498: EngineID sel_eng = WP(w,buildtrain_d).sel_engine; tron@2498: if (sel_eng != INVALID_ENGINE) tron@540: DoCommandP(w->window_number, sel_eng, 0, (RailVehInfo(sel_eng)->flags & RVI_WAGON) ? CcBuildWagon : CcBuildLoco, CMD_BUILD_RAIL_VEHICLE | CMD_MSG(STR_882B_CAN_T_BUILD_RAILROAD_VEHICLE)); truelight@0: } break; darkvater@968: case 6: { /* rename */ tron@2498: EngineID sel_eng = WP(w,buildtrain_d).sel_engine; tron@2498: if (sel_eng != INVALID_ENGINE) { darkvater@968: WP(w,buildtrain_d).rename_engine = sel_eng; darkvater@968: ShowQueryString(GetCustomEngineName(sel_eng), truelight@4299: STR_886A_RENAME_TRAIN_VEHICLE_TYPE, 31, 160, w->window_class, w->window_number, CS_ALPHANUMERAL); darkvater@968: } darkvater@968: } break; truelight@0: } truelight@0: } break; truelight@0: truelight@0: case WE_ON_EDIT_TEXT: { tron@1820: if (e->edittext.str[0] != '\0') { tron@1820: _cmd_text = e->edittext.str; tron@1820: DoCommandP(0, WP(w,buildtrain_d).rename_engine, 0, NULL, tron@1820: CMD_RENAME_ENGINE | CMD_MSG(STR_886B_CAN_T_RENAME_TRAIN_VEHICLE)); tron@1820: } truelight@0: } break; truelight@867: truelight@867: case WE_RESIZE: { truelight@867: if (e->sizing.diff.y == 0) truelight@867: break; truelight@867: truelight@867: w->vscroll.cap += e->sizing.diff.y / 14; Darkvater@4547: w->widget[2].data = (w->vscroll.cap << 8) + 1; truelight@867: } break; truelight@0: } truelight@0: } truelight@193: truelight@0: static const Widget _new_rail_vehicle_widgets[] = { rubidium@4344: { WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, rubidium@4344: { WWT_CAPTION, RESIZE_NONE, 14, 11, 227, 0, 13, STR_JUST_STRING, STR_018C_WINDOW_TITLE_DRAG_THIS}, rubidium@4344: { WWT_MATRIX, RESIZE_BOTTOM, 14, 0, 215, 14, 125, 0x801, STR_8843_TRAIN_VEHICLE_SELECTION}, rubidium@4344: { WWT_SCROLLBAR, RESIZE_BOTTOM, 14, 216, 227, 14, 125, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, rubidium@4344: { WWT_PANEL, RESIZE_TB, 14, 0, 227, 126, 197, 0x0, STR_NULL}, rubidium@4344: { WWT_PUSHTXTBTN, RESIZE_TB, 14, 0, 107, 198, 209, STR_881F_BUILD_VEHICLE, STR_8844_BUILD_THE_HIGHLIGHTED_TRAIN}, rubidium@4344: { WWT_PUSHTXTBTN, RESIZE_TB, 14, 108, 215, 198, 209, STR_8820_RENAME, STR_8845_RENAME_TRAIN_VEHICLE_TYPE}, rubidium@4344: { WWT_RESIZEBOX, RESIZE_TB, 14, 216, 227, 198, 209, 0x0, STR_RESIZE_BUTTON}, darkvater@176: { WIDGETS_END}, truelight@0: }; truelight@0: truelight@0: static const WindowDesc _new_rail_vehicle_desc = { hackykid@1908: -1, -1, 228, 210, truelight@0: WC_BUILD_VEHICLE,0, truelight@867: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE, truelight@0: _new_rail_vehicle_widgets, truelight@0: NewRailVehicleWndProc truelight@0: }; truelight@0: bjarni@4442: void ShowBuildTrainWindow(TileIndex tile) truelight@0: { truelight@0: Window *w; truelight@0: truelight@0: DeleteWindowById(WC_BUILD_VEHICLE, tile); truelight@0: truelight@0: w = AllocateWindowDesc(&_new_rail_vehicle_desc); truelight@0: w->window_number = tile; truelight@0: w->vscroll.cap = 8; Darkvater@4547: w->widget[2].data = (w->vscroll.cap << 8) + 1; truelight@867: truelight@867: w->resize.step_height = 14; tron@4000: w->resize.height = w->height - 14 * 4; // Minimum of 4 vehicles in the display truelight@193: truelight@0: if (tile != 0) { tron@1901: w->caption_color = GetTileOwner(tile); tron@3242: WP(w,buildtrain_d).railtype = GetRailType(tile); truelight@0: } else { truelight@0: w->caption_color = _local_player; celestar@2147: WP(w,buildtrain_d).railtype = GetBestRailtype(GetPlayer(_local_player)); truelight@0: } truelight@0: } truelight@0: peter1138@2593: /** peter1138@2593: * Get the number of pixels for the given wagon length. peter1138@2593: * @param len Length measured in 1/8ths of a standard wagon. peter1138@2593: * @return Number of pixels across. peter1138@2593: */ peter1138@2593: static int WagonLengthToPixels(int len) { peter1138@3845: return (len * _traininfo_vehicle_width) / 8; peter1138@2593: } peter1138@2593: bjarni@4442: void DrawTrainImage(const Vehicle *v, int x, int y, int count, int skip, VehicleID selection) truelight@0: { peter1138@3919: DrawPixelInfo tmp_dpi, *old_dpi; peter1138@3919: int dx = -(skip * 8) / _traininfo_vehicle_width; peter1138@4049: /* Position of highlight box */ peter1138@4049: int highlight_l = 0; peter1138@4049: int highlight_r = 0; peter1138@3919: tron@4429: if (!FillDrawPixelInfo(&tmp_dpi, x - 2, y - 1, count + 1, 14)) return; peter1138@3919: peter1138@3919: count = (count * 8) / _traininfo_vehicle_width; peter1138@3919: peter1138@3919: old_dpi = _cur_dpi; peter1138@3919: _cur_dpi = &tmp_dpi; hackykid@1922: truelight@0: do { peter1138@3919: int width = v->u.rail.cached_veh_length; hackykid@1922: peter1138@3919: if (dx + width > 0) { peter1138@3919: if (dx <= count) { peter1138@3049: PalSpriteID pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v); peter1138@4049: DrawSprite(GetTrainImage(v, DIR_W) | pal, 16 + WagonLengthToPixels(dx), 7 + (is_custom_sprite(RailVehInfo(v->engine_type)->image_index) ? _traininfo_vehicle_pitch : 0)); peter1138@4049: if (v->index == selection) { peter1138@4049: /* Set the highlight position */ peter1138@4049: highlight_l = WagonLengthToPixels(dx) + 1; peter1138@4049: highlight_r = WagonLengthToPixels(dx + width) + 1; peter1138@4049: } hackykid@1922: } truelight@0: } peter1138@3919: dx += width; truelight@0: peter1138@2593: v = v->next; peter1138@3919: } while (dx < count && v != NULL); peter1138@3919: peter1138@4049: if (highlight_l != highlight_r) { peter1138@4049: /* Draw the highlight. Now done after drawing all the engines, as peter1138@4049: * the next engine after the highlight could overlap it. */ peter1138@4049: DrawFrameRect(highlight_l, 0, highlight_r, 13, 15, FR_BORDERONLY); peter1138@4049: } peter1138@4049: peter1138@3919: _cur_dpi = old_dpi; truelight@0: } truelight@0: truelight@0: static void DrawTrainDepotWindow(Window *w) truelight@0: { tron@1977: TileIndex tile; truelight@0: Vehicle *v, *u; truelight@0: int num,x,y,i, hnum; truelight@1313: Depot *depot; truelight@0: truelight@0: tile = w->window_number; truelight@0: truelight@0: /* setup disabled buttons */ tron@1901: w->disabled_state = bjarni@2244: IsTileOwner(tile, _local_player) ? 0 : ((1 << 4) | (1 << 5) | (1 << 8) | (1<<9)); truelight@0: truelight@0: /* determine amount of items for scroller */ truelight@867: num = 0; peter1138@2593: hnum = 8; truelight@0: FOR_ALL_VEHICLES(v) { truelight@0: if (v->type == VEH_Train && tron@4077: (IsFrontEngine(v) || IsFreeWagon(v)) && tron@1986: v->tile == tile && truelight@0: v->u.rail.track == 0x80) { tron@1986: num++; tron@1986: // determine number of items in the X direction. bjarni@2676: if (IsFrontEngine(v)) { peter1138@2593: hnum = max(hnum, v->u.rail.cached_total_length); tron@1986: } truelight@0: } truelight@0: } truelight@914: truelight@914: /* Always have 1 empty row, so people can change the setting of the train */ truelight@914: num++; truelight@914: truelight@0: SetVScrollCount(w, num); peter1138@3919: SetHScrollCount(w, WagonLengthToPixels(hnum)); truelight@193: truelight@0: /* locate the depot struct */ truelight@1313: depot = GetDepotByTile(tile); truelight@1313: assert(depot != NULL); truelight@0: truelight@1313: SetDParam(0, depot->town_index); truelight@0: DrawWindowWidgets(w); truelight@0: truelight@0: x = 2; truelight@0: y = 15; truelight@0: num = w->vscroll.pos; truelight@0: truelight@0: // draw all trains truelight@0: FOR_ALL_VEHICLES(v) { bjarni@2676: if (v->type == VEH_Train && IsFrontEngine(v) && tron@1986: v->tile == tile && v->u.rail.track == 0x80 && truelight@867: --num < 0 && num >= -w->vscroll.cap) { peter1138@3919: DrawTrainImage(v, x+21, y, w->hscroll.cap + 4, w->hscroll.pos, WP(w,traindepot_d).sel); darkvater@22: /* Draw the train number */ tron@534: SetDParam(0, v->unitnumber); truelight@0: DrawString(x, y, (v->max_age - 366 < v->age) ? STR_00E3 : STR_00E2, 0); tron@1019: peter1138@2593: // Number of wagons relative to a standard length wagon (rounded up) peter1138@2593: SetDParam(0, (v->u.rail.cached_total_length + 7) / 8); rubidium@4434: DrawStringRightAligned(w->widget[6].right - 1, y + 4, STR_TINY_BLACK, 0); // Draw the counter tron@1019: darkvater@22: /* Draw the pretty flag */ tron@2517: DrawSprite(v->vehstatus & VS_STOPPED ? SPR_FLAG_VEH_STOPPED : SPR_FLAG_VEH_RUNNING, x + 15, y); truelight@0: truelight@0: y += 14; truelight@0: } truelight@0: } truelight@0: truelight@0: // draw all remaining vehicles truelight@0: FOR_ALL_VEHICLES(v) { bjarni@2676: if (v->type == VEH_Train && IsFreeWagon(v) && tron@1986: v->tile == tile && v->u.rail.track == 0x80 && truelight@867: --num < 0 && num >= -w->vscroll.cap) { peter1138@3919: DrawTrainImage(v, x+50, y, w->hscroll.cap - 29, 0, WP(w,traindepot_d).sel); truelight@0: DrawString(x, y+2, STR_8816, 0); tron@1019: celestar@1002: /*Draw the train counter */ celestar@1002: i = 0; celestar@1002: u = v; rubidium@4434: do i++; while ( (u=u->next) != NULL); // Determine length of train rubidium@4434: SetDParam(0, i); // Set the counter rubidium@4434: DrawStringRightAligned(w->widget[6].right - 1, y + 4, STR_TINY_BLACK, 0); // Draw the counter truelight@0: y += 14; truelight@0: } truelight@0: } truelight@0: } truelight@0: truelight@0: typedef struct GetDepotVehiclePtData { truelight@0: Vehicle *head; truelight@0: Vehicle *wagon; truelight@0: } GetDepotVehiclePtData; truelight@0: Darkvater@2436: static int GetVehicleFromTrainDepotWndPt(const Window *w, int x, int y, GetDepotVehiclePtData *d) truelight@0: { truelight@0: int row; hackykid@1922: int skip = 0; truelight@0: Vehicle *v; truelight@0: truelight@0: x = x - 23; truelight@0: truelight@0: row = (y - 14) / 14; tron@2951: if ((uint)row >= w->vscroll.cap) return 1; /* means err */ truelight@0: truelight@0: row += w->vscroll.pos; truelight@0: truelight@0: /* go through all the locomotives */ truelight@0: FOR_ALL_VEHICLES(v) { truelight@0: if (v->type == VEH_Train && bjarni@2676: IsFrontEngine(v) && truelight@0: v->tile == w->window_number && truelight@0: v->u.rail.track == 0x80 && truelight@0: --row < 0) { tron@2951: skip = w->hscroll.pos; tron@2951: goto found_it; truelight@0: } truelight@0: } truelight@0: peter1138@3845: x -= _traininfo_vehicle_width; /* free wagons don't have an initial loco. */ truelight@0: truelight@0: /* and then the list of free wagons */ truelight@0: FOR_ALL_VEHICLES(v) { truelight@0: if (v->type == VEH_Train && bjarni@2676: IsFreeWagon(v) && truelight@0: v->tile == w->window_number && truelight@0: v->u.rail.track == 0x80 && tron@2951: --row < 0) { tron@2951: goto found_it; tron@2951: } truelight@0: } truelight@0: truelight@0: d->head = NULL; truelight@0: d->wagon = NULL; truelight@0: truelight@0: /* didn't find anything, get out */ truelight@0: return 0; truelight@0: truelight@193: found_it: truelight@0: d->head = d->wagon = v; truelight@0: truelight@0: /* either pressed the flag or the number, but only when it's a loco */ tron@2951: if (x < 0 && IsFrontEngine(v)) return (x >= -10) ? -2 : -1; hackykid@1922: peter1138@3919: skip = (skip * 8) / _traininfo_vehicle_width; peter1138@3919: x = (x * 8) / _traininfo_vehicle_width; peter1138@3919: peter1138@3919: /* Skip vehicles that are scrolled off the list */ peter1138@3919: x += skip; truelight@193: truelight@0: /* find the vehicle in this row that was clicked */ peter1138@3919: while (v != NULL && (x -= v->u.rail.cached_veh_length) >= 0) v = v->next; truelight@0: peter1138@2602: // if an articulated part was selected, find its parent bjarni@2676: while (v != NULL && IsArticulatedPart(v)) v = GetPrevVehicleInChain(v); peter1138@2602: truelight@193: d->wagon = v; truelight@0: truelight@0: return 0; truelight@0: } truelight@0: tron@2484: static void TrainDepotMoveVehicle(Vehicle *wagon, VehicleID sel, Vehicle *head) truelight@0: { truelight@0: Vehicle *v; truelight@0: truelight@919: v = GetVehicle(sel); truelight@0: tron@4077: if (v == wagon) return; truelight@0: truelight@0: if (wagon == NULL) { tron@4077: if (head != NULL) wagon = GetLastVehicleInChain(head); truelight@0: } else { truelight@0: wagon = GetPrevVehicleInChain(wagon); tron@4077: if (wagon == NULL) return; truelight@0: } truelight@0: tron@4077: if (wagon == v) return; truelight@0: tron@2484: 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)); truelight@0: } truelight@0: truelight@0: static void TrainDepotClickTrain(Window *w, int x, int y) truelight@0: { truelight@0: GetDepotVehiclePtData gdvp; tron@2484: int mode; truelight@0: Vehicle *v; truelight@0: truelight@0: mode = GetVehicleFromTrainDepotWndPt(w, x, y, &gdvp); dominik@10: dominik@10: // share / copy orders tron@4077: if (_thd.place_mode && mode <= 0) { tron@4077: _place_clicked_vehicle = gdvp.head; tron@4077: return; tron@4077: } truelight@193: truelight@0: v = gdvp.wagon; truelight@0: tron@2952: switch (mode) { tron@2484: case 0: { // start dragging of vehicle tron@2484: VehicleID sel = WP(w, traindepot_d).sel; tron@2484: tron@2484: if (sel != INVALID_VEHICLE) { truelight@0: WP(w,traindepot_d).sel = INVALID_VEHICLE; truelight@0: TrainDepotMoveVehicle(v, sel, gdvp.head); truelight@0: } else if (v != NULL) { truelight@0: WP(w,traindepot_d).sel = v->index; tron@3157: SetObjectToPlaceWnd(GetVehiclePalette(v) | GetTrainImage(v, DIR_W), 4, w); truelight@0: SetWindowDirty(w); truelight@0: } truelight@0: break; tron@2484: } truelight@0: dominik@10: case -1: // show info window truelight@0: ShowTrainViewWindow(v); truelight@0: break; truelight@0: dominik@10: case -2: // click start/stop flag truelight@0: DoCommandP(v->tile, v->index, 0, NULL, CMD_START_STOP_TRAIN | CMD_MSG(STR_883B_CAN_T_STOP_START_TRAIN)); truelight@0: break; truelight@0: } truelight@0: } truelight@0: bjarni@2244: /** bjarni@2244: * Clones a train bjarni@2244: * @param *v is the original vehicle to clone bjarni@2244: * @param *w is the window of the depot where the clone is build bjarni@2244: */ belugas@4171: static void HandleCloneVehClick(const Vehicle *v, const Window *w) bjarni@2244: { tron@2561: if (v == NULL || v->type != VEH_Train) return; bjarni@2244: bjarni@2244: // for train vehicles: subtype 0 for locs and not zero for others bjarni@2676: if (!IsFrontEngine(v)) { bjarni@2244: v = GetFirstVehicleInChain(v); tron@2561: // Do nothing when clicking on a train in depot with no loc attached bjarni@2676: if (!IsFrontEngine(v)) return; bjarni@2244: } bjarni@2244: tron@2561: DoCommandP(w->window_number, v->index, _ctrl_pressed ? 1 : 0, CcCloneTrain, tron@2561: CMD_CLONE_VEHICLE | CMD_MSG(STR_882B_CAN_T_BUILD_RAILROAD_VEHICLE) tron@2561: ); bjarni@2244: bjarni@2244: ResetObjectToPlace(); bjarni@2244: } bjarni@2244: belugas@4171: static void ClonePlaceObj(const Window *w) bjarni@2244: { belugas@4171: Vehicle *v = CheckMouseOverVehicle(); bjarni@2244: tron@2561: if (v != NULL) HandleCloneVehClick(v, w); bjarni@2244: } bjarni@2244: truelight@0: static void TrainDepotWndProc(Window *w, WindowEvent *e) truelight@0: { tron@2952: switch (e->event) { truelight@0: case WE_PAINT: truelight@0: DrawTrainDepotWindow(w); truelight@0: break; truelight@0: truelight@0: case WE_CLICK: { tron@2952: switch (e->click.widget) { truelight@867: case 8: bjarni@2244: ResetObjectToPlace(); truelight@0: ShowBuildTrainWindow(w->window_number); truelight@0: break; tron@4532: tron@4532: case 10: ScrollMainWindowToTile(w->window_number); break; tron@4532: darkvater@982: case 6: truelight@0: TrainDepotClickTrain(w, e->click.pt.x, e->click.pt.y); truelight@0: break; bjarni@2244: case 9: /* clone button */ bjarni@2244: InvalidateWidget(w, 9); bjarni@2244: TOGGLEBIT(w->click_state, 9); bjarni@2244: bjarni@2244: if (HASBIT(w->click_state, 9)) { bjarni@2244: _place_clicked_vehicle = NULL; bjarni@2244: SetObjectToPlaceWnd(SPR_CURSOR_CLONE, VHM_RECT, w); bjarni@2244: } else { bjarni@2244: ResetObjectToPlace(); bjarni@2244: } bjarni@2244: break; bjarni@2244: tron@4077: } bjarni@2244: } break; bjarni@2244: tron@4077: case WE_PLACE_OBJ: tron@4077: ClonePlaceObj(w); tron@4077: break; tron@4077: tron@4077: case WE_ABORT_PLACE_OBJ: bjarni@2244: CLRBIT(w->click_state, 9); bjarni@2244: InvalidateWidget(w, 9); tron@4077: break; ludde@2261: bjarni@2244: // check if a vehicle in a depot was clicked.. bjarni@2244: case WE_MOUSELOOP: { belugas@4171: const Vehicle *v = _place_clicked_vehicle; tron@2561: tron@2561: // since OTTD checks all open depot windows, we will make sure that it triggers the one with a clicked clone button bjarni@2244: if (v != NULL && HASBIT(w->click_state, 9)) { bjarni@2244: _place_clicked_vehicle = NULL; tron@2561: HandleCloneVehClick(v, w); truelight@0: } truelight@0: } break; truelight@0: bjarni@2244: truelight@0: case WE_DESTROY: truelight@0: DeleteWindowById(WC_BUILD_VEHICLE, w->window_number); truelight@0: break; truelight@0: truelight@0: case WE_DRAGDROP: { tron@2952: switch (e->click.widget) { darkvater@982: case 4: case 5: { truelight@0: Vehicle *v; truelight@0: int sell_cmd; truelight@0: truelight@0: /* sell vehicle */ truelight@0: if (w->disabled_state & (1 << e->click.widget)) truelight@0: return; truelight@0: truelight@0: if (WP(w,traindepot_d).sel == INVALID_VEHICLE) truelight@0: return; truelight@0: truelight@919: v = GetVehicle(WP(w,traindepot_d).sel); truelight@193: truelight@0: WP(w,traindepot_d).sel = INVALID_VEHICLE; truelight@0: SetWindowDirty(w); truelight@0: truelight@0: HandleButtonClick(w, e->click.widget); truelight@0: darkvater@982: sell_cmd = (e->click.widget == 5 || _ctrl_pressed) ? 1 : 0; truelight@0: bjarni@2676: if (!IsFrontEngine(v)) { truelight@0: DoCommandP(v->tile, v->index, sell_cmd, NULL, CMD_SELL_RAIL_WAGON | CMD_MSG(STR_8839_CAN_T_SELL_RAILROAD_VEHICLE)); truelight@0: } else { truelight@0: _backup_orders_tile = v->tile; truelight@0: BackupVehicleOrders(v, _backup_orders_data); truelight@0: if (!DoCommandP(v->tile, v->index, sell_cmd, NULL, CMD_SELL_RAIL_WAGON | CMD_MSG(STR_8839_CAN_T_SELL_RAILROAD_VEHICLE))) truelight@0: _backup_orders_tile = 0; truelight@0: } truelight@0: } break; truelight@0: darkvater@982: case 6: { truelight@0: GetDepotVehiclePtData gdvp; truelight@0: VehicleID sel = WP(w,traindepot_d).sel; truelight@0: truelight@0: WP(w,traindepot_d).sel = INVALID_VEHICLE; truelight@0: SetWindowDirty(w); truelight@0: truelight@193: if (GetVehicleFromTrainDepotWndPt(w, e->dragdrop.pt.x, e->dragdrop.pt.y, &gdvp) == 0 && truelight@0: sel != INVALID_VEHICLE) { bjarni@3256: if (gdvp.wagon != NULL && gdvp.wagon->index == sel && _ctrl_pressed) { bjarni@3256: DoCommandP(GetVehicle(sel)->tile, GetVehicle(sel)->index, true, NULL, CMD_REVERSE_TRAIN_DIRECTION | CMD_MSG(STR_9033_CAN_T_MAKE_VEHICLE_TURN)); bjarni@3256: } else if (gdvp.wagon == NULL || gdvp.wagon->index != sel) { truelight@0: TrainDepotMoveVehicle(gdvp.wagon, sel, gdvp.head); bjarni@2676: } else if (gdvp.head != NULL && IsFrontEngine(gdvp.head)) { truelight@0: ShowTrainViewWindow(gdvp.head); truelight@0: } truelight@193: } truelight@0: } break; truelight@0: truelight@0: default: truelight@0: WP(w,traindepot_d).sel = INVALID_VEHICLE; truelight@0: SetWindowDirty(w); truelight@0: break; truelight@0: } truelight@0: } break; truelight@867: case WE_RESIZE: { truelight@867: /* Update the scroll + matrix */ truelight@867: w->vscroll.cap += e->sizing.diff.y / 14; peter1138@3919: w->hscroll.cap += e->sizing.diff.x; Darkvater@4547: w->widget[6].data = (w->vscroll.cap << 8) + 1; truelight@867: } break; truelight@0: } truelight@0: } truelight@0: truelight@0: static const Widget _train_depot_widgets[] = { rubidium@4344: { WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, rubidium@4344: { WWT_CAPTION, RESIZE_RIGHT, 14, 11, 348, 0, 13, STR_8800_TRAIN_DEPOT, STR_018C_WINDOW_TITLE_DRAG_THIS}, rubidium@4344: { WWT_STICKYBOX, RESIZE_LR, 14, 349, 360, 0, 13, 0x0, STR_STICKY_BUTTON}, truelight@0: rubidium@4344: { WWT_PANEL, RESIZE_LRB, 14, 326, 348, 14, 13, 0x0, STR_NULL}, rubidium@4344: { WWT_PANEL, RESIZE_LRTB, 14, 326, 348, 14, 54, 0x2A9, STR_8841_DRAG_TRAIN_VEHICLE_TO_HERE}, rubidium@4344: { WWT_PANEL, RESIZE_LRTB, 14, 326, 348, 55, 109, 0x2BF, STR_DRAG_WHOLE_TRAIN_TO_SELL_TIP}, celestar@1002: rubidium@4344: { WWT_MATRIX, RESIZE_RB, 14, 0, 325, 14, 97, 0x601, STR_883F_TRAINS_CLICK_ON_TRAIN_FOR}, rubidium@4344: { WWT_SCROLLBAR, RESIZE_LRB, 14, 349, 360, 14, 109, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, rubidium@4344: { WWT_PUSHTXTBTN, RESIZE_TB, 14, 0, 116, 110, 121, STR_8815_NEW_VEHICLES, STR_8840_BUILD_NEW_TRAIN_VEHICLE}, rubidium@4344: {WWT_NODISTXTBTN, RESIZE_TB, 14, 117, 232, 110, 121, STR_CLONE_TRAIN, STR_CLONE_TRAIN_DEPOT_INFO}, rubidium@4344: { WWT_PUSHTXTBTN, RESIZE_TB, 14, 233, 348, 110, 121, STR_00E4_LOCATION, STR_8842_CENTER_MAIN_VIEW_ON_TRAIN}, bjarni@2244: bjarni@2244: rubidium@4344: { WWT_HSCROLLBAR, RESIZE_RTB, 14, 0, 325, 98, 109, 0x0, STR_HSCROLL_BAR_SCROLLS_LIST}, rubidium@4344: { WWT_PANEL, RESIZE_RTB, 14, 349, 348, 110, 121, 0x0, STR_NULL}, bjarni@2244: rubidium@4344: { WWT_RESIZEBOX, RESIZE_LRTB, 14, 349, 360, 110, 121, 0x0, STR_RESIZE_BUTTON}, darkvater@176: { WIDGETS_END}, truelight@0: }; truelight@0: truelight@0: static const WindowDesc _train_depot_desc = { celestar@1002: -1, -1, 361, 122, truelight@0: WC_VEHICLE_DEPOT,0, truelight@867: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE, truelight@0: _train_depot_widgets, truelight@0: TrainDepotWndProc truelight@0: }; truelight@0: truelight@0: tron@1977: void ShowTrainDepotWindow(TileIndex tile) truelight@0: { truelight@0: Window *w; truelight@0: truelight@0: w = AllocateWindowDescFront(&_train_depot_desc, tile); truelight@0: if (w) { tron@1901: w->caption_color = GetTileOwner(w->window_number); truelight@0: w->vscroll.cap = 6; peter1138@3919: w->hscroll.cap = 10 * 29; peter1138@3919: w->resize.step_width = 1; truelight@867: w->resize.step_height = 14; truelight@0: WP(w,traindepot_d).sel = INVALID_VEHICLE; truelight@0: _backup_orders_tile = 0; truelight@0: } truelight@0: } truelight@0: truelight@0: static void RailVehicleRefitWndProc(Window *w, WindowEvent *e) truelight@0: { Darkvater@1802: switch (e->event) { truelight@0: case WE_PAINT: { Darkvater@1802: const Vehicle *v = GetVehicle(w->window_number); truelight@0: tron@534: SetDParam(0, v->string_id); tron@534: SetDParam(1, v->unitnumber); truelight@0: DrawWindowWidgets(w); truelight@0: truelight@0: Darkvater@1802: /* TODO: Support for custom GRFSpecial-specified refitting! --pasky */ Darkvater@1802: WP(w,refit_d).cargo = DrawVehicleRefitWindow(v, WP(w, refit_d).sel); darkvater@382: Darkvater@1802: if (WP(w,refit_d).cargo != CT_INVALID) { tron@3491: int32 cost = DoCommand(v->tile, v->index, WP(w,refit_d).cargo, DC_QUERY_COST, CMD_REFIT_RAIL_VEHICLE); Darkvater@1802: if (!CmdFailed(cost)) { tron@534: SetDParam(2, cost); ludde@2084: SetDParam(0, _cargoc.names_long[WP(w,refit_d).cargo]); peter1138@3008: SetDParam(1, _returned_refit_capacity); truelight@0: DrawString(1, 137, STR_9840_NEW_CAPACITY_COST_OF_REFIT, 0); truelight@0: } truelight@0: } Darkvater@1802: } break; truelight@0: truelight@0: case WE_CLICK: tron@2952: switch (e->click.widget) { truelight@0: case 2: { /* listbox */ truelight@0: int y = e->click.pt.y - 25; truelight@0: if (y >= 0) { truelight@0: WP(w,refit_d).sel = y / 10; truelight@0: SetWindowDirty(w); truelight@0: } truelight@0: } break; truelight@0: case 4: /* refit button */ Darkvater@1802: if (WP(w,refit_d).cargo != CT_INVALID) { Darkvater@1802: const Vehicle *v = GetVehicle(w->window_number); truelight@0: if (DoCommandP(v->tile, v->index, WP(w,refit_d).cargo, NULL, CMD_REFIT_RAIL_VEHICLE | CMD_MSG(STR_RAIL_CAN_T_REFIT_VEHICLE))) truelight@0: DeleteWindow(w); truelight@0: } truelight@0: break; truelight@0: } truelight@0: break; truelight@0: } truelight@0: } truelight@0: truelight@0: truelight@0: static const Widget _rail_vehicle_refit_widgets[] = { belugas@4345: { WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, belugas@4345: { WWT_CAPTION, RESIZE_NONE, 14, 11, 239, 0, 13, STR_983B_REFIT, STR_018C_WINDOW_TITLE_DRAG_THIS}, belugas@4345: { WWT_IMGBTN, RESIZE_NONE, 14, 0, 239, 14, 135, 0x0, STR_RAIL_SELECT_TYPE_OF_CARGO_FOR}, belugas@4345: { WWT_IMGBTN, RESIZE_NONE, 14, 0, 239, 136, 157, 0x0, STR_NULL}, belugas@4345: { WWT_PUSHTXTBTN, RESIZE_NONE, 14, 0, 239, 158, 169, STR_RAIL_REFIT_VEHICLE, STR_RAIL_REFIT_TO_CARRY_HIGHLIGHTED}, belugas@4345: { WWT_LABEL, RESIZE_NONE, 0, 0, 239, 13, 26, STR_983F_SELECT_CARGO_TYPE_TO_CARRY, STR_NULL}, darkvater@176: { WIDGETS_END}, truelight@0: }; truelight@0: truelight@0: static const WindowDesc _rail_vehicle_refit_desc = { truelight@0: -1,-1, 240, 170, truelight@0: WC_VEHICLE_REFIT,WC_VEHICLE_VIEW, truelight@0: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS, truelight@0: _rail_vehicle_refit_widgets, truelight@0: RailVehicleRefitWndProc, truelight@0: }; truelight@0: truelight@0: static void ShowRailVehicleRefitWindow(Vehicle *v) truelight@0: { truelight@0: Window *w; truelight@0: DeleteWindowById(WC_VEHICLE_REFIT, v->index); truelight@0: _alloc_wnd_parent_num = v->index; truelight@0: w = AllocateWindowDesc(&_rail_vehicle_refit_desc); truelight@0: w->window_number = v->index; truelight@0: w->caption_color = v->owner; truelight@0: WP(w,refit_d).sel = -1; truelight@0: } truelight@0: tron@2275: static const Widget _train_view_widgets[] = { rubidium@4344: { WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW }, rubidium@4344: { WWT_CAPTION, RESIZE_RIGHT, 14, 11, 237, 0, 13, STR_882E, STR_018C_WINDOW_TITLE_DRAG_THIS }, rubidium@4344: { WWT_STICKYBOX, RESIZE_LR, 14, 238, 249, 0, 13, 0x0, STR_STICKY_BUTTON }, rubidium@4344: { WWT_PANEL, RESIZE_RB, 14, 0, 231, 14, 121, 0x0, STR_NULL }, rubidium@4344: { WWT_6, RESIZE_RB, 14, 2, 229, 16, 119, 0x0, STR_NULL }, rubidium@4344: { WWT_PUSHIMGBTN, RESIZE_RTB, 14, 0, 237, 122, 133, 0x0, STR_8846_CURRENT_TRAIN_ACTION_CLICK }, rubidium@4344: { WWT_PUSHIMGBTN, RESIZE_LR, 14, 232, 249, 14, 31, 0x2AB, STR_8848_CENTER_MAIN_VIEW_ON_TRAIN }, rubidium@4344: { WWT_PUSHIMGBTN, RESIZE_LR, 14, 232, 249, 32, 49, 0x2AD, STR_8849_SEND_TRAIN_TO_DEPOT }, rubidium@4344: { WWT_PUSHIMGBTN, RESIZE_LR, 14, 232, 249, 50, 67, 0x2B1, STR_884A_FORCE_TRAIN_TO_PROCEED }, rubidium@4344: { WWT_PUSHIMGBTN, RESIZE_LR, 14, 232, 249, 68, 85, 0x2CB, STR_884B_REVERSE_DIRECTION_OF_TRAIN }, rubidium@4344: { WWT_PUSHIMGBTN, RESIZE_LR, 14, 232, 249, 86, 103, 0x2B2, STR_8847_SHOW_TRAIN_S_ORDERS }, rubidium@4344: { WWT_PUSHIMGBTN, RESIZE_LR, 14, 232, 249, 104, 121, 0x2B3, STR_884C_SHOW_TRAIN_DETAILS }, rubidium@4344: { WWT_PUSHIMGBTN, RESIZE_LR, 14, 232, 249, 68, 85, 0x2B4, STR_RAIL_REFIT_VEHICLE_TO_CARRY }, rubidium@4344: { WWT_PUSHIMGBTN, RESIZE_LR, 14, 232, 249, 32, 49, SPR_CLONE_TRAIN, STR_CLONE_TRAIN_INFO }, rubidium@4344: { WWT_PANEL, RESIZE_LRB, 14, 232, 249, 122, 121, 0x0, STR_NULL }, rubidium@4344: { WWT_RESIZEBOX, RESIZE_LRTB, 14, 238, 249, 122, 133, 0x0, STR_NULL }, tron@1485: { WIDGETS_END } truelight@0: }; truelight@0: belugas@4171: static void ShowTrainDetailsWindow(const Vehicle *v); tron@2561: truelight@0: static void TrainViewWndProc(Window *w, WindowEvent *e) truelight@0: { Darkvater@1802: switch (e->event) { truelight@0: case WE_PAINT: { Darkvater@1802: const Vehicle *v, *u; truelight@0: StringID str; truelight@0: truelight@919: v = GetVehicle(w->window_number); truelight@193: peter1138@2867: if (v->owner != _local_player) { peter1138@2867: w->disabled_state = 0x3380; peter1138@2867: } else { peter1138@2867: w->disabled_state = 0; celestar@1387: peter1138@2867: SETBIT(w->disabled_state, 12); peter1138@2867: peter1138@2867: /* See if any vehicle can be refitted */ peter1138@2867: for (u = v; u != NULL; u = u->next) { peter1138@3393: if (EngInfo(u->engine_type)->refit_mask != 0 || peter1138@2867: (!(RailVehInfo(v->engine_type)->flags & RVI_WAGON) && v->cargo_cap != 0)) { peter1138@2867: CLRBIT(w->disabled_state, 12); peter1138@2867: /* We have a refittable carriage, bail out */ peter1138@2867: break; peter1138@2867: } celestar@1387: } celestar@1387: } celestar@1387: truelight@0: /* draw widgets & caption */ tron@534: SetDParam(0, v->string_id); ludde@2261: SetDParam(1, v->unitnumber); truelight@0: DrawWindowWidgets(w); truelight@0: truelight@0: if (v->u.rail.crash_anim_pos != 0) { truelight@0: str = STR_8863_CRASHED; truelight@0: } else if (v->breakdown_ctr == 1) { truelight@0: str = STR_885C_BROKEN_DOWN; truelight@0: } else if (v->vehstatus & VS_STOPPED) { truelight@0: if (v->u.rail.last_speed == 0) { bjarni@4251: if (v->u.rail.cached_power == 0) { bjarni@4251: str = STR_TRAIN_NO_POWER; bjarni@4251: } else { bjarni@4251: str = STR_8861_STOPPED; bjarni@4251: } truelight@0: } else { peter1138@3477: SetDParam(0, v->u.rail.last_speed); truelight@0: str = STR_TRAIN_STOPPING + _patches.vehicle_speed; truelight@0: } truelight@0: } else { tron@555: switch (v->current_order.type) { truelight@0: case OT_GOTO_STATION: { truelight@0: str = STR_HEADING_FOR_STATION + _patches.vehicle_speed; tron@4527: SetDParam(0, v->current_order.dest); peter1138@3477: SetDParam(1, v->u.rail.last_speed); truelight@0: } break; truelight@0: truelight@0: case OT_GOTO_DEPOT: { tron@4527: Depot *dep = GetDepot(v->current_order.dest); tron@534: SetDParam(0, dep->town_index); bjarni@4412: if (HASBIT(v->current_order.flags, OFB_HALT_IN_DEPOT)) { bjarni@4412: str = STR_HEADING_FOR_TRAIN_DEPOT + _patches.vehicle_speed; bjarni@4412: } else { bjarni@4412: str = STR_HEADING_FOR_TRAIN_DEPOT_SERVICE + _patches.vehicle_speed; bjarni@4412: } peter1138@3477: SetDParam(1, v->u.rail.last_speed); truelight@0: } break; truelight@0: truelight@0: case OT_LOADING: truelight@0: case OT_LEAVESTATION: truelight@0: str = STR_882F_LOADING_UNLOADING; truelight@0: break; truelight@0: darkvater@395: case OT_GOTO_WAYPOINT: { tron@4527: SetDParam(0, v->current_order.dest); darkvater@395: str = STR_HEADING_FOR_WAYPOINT + _patches.vehicle_speed; peter1138@3477: SetDParam(1, v->u.rail.last_speed); truelight@0: break; truelight@0: } truelight@193: truelight@0: default: truelight@0: if (v->num_orders == 0) { truelight@0: str = STR_NO_ORDERS + _patches.vehicle_speed; peter1138@3477: SetDParam(0, v->u.rail.last_speed); tron@4077: } else { truelight@0: str = STR_EMPTY; tron@4077: } truelight@0: break; truelight@0: } truelight@0: } truelight@0: Darkvater@2103: /* draw the flag plus orders */ tron@2517: DrawSprite(v->vehstatus & VS_STOPPED ? SPR_FLAG_VEH_STOPPED : SPR_FLAG_VEH_RUNNING, 2, w->widget[5].top + 1); Darkvater@2113: DrawStringCenteredTruncated(w->widget[5].left + 8, w->widget[5].right, w->widget[5].top + 1, str, 0); truelight@0: DrawWindowViewport(w); truelight@0: } break; truelight@0: truelight@0: case WE_CLICK: { truelight@0: int wid = e->click.widget; truelight@919: Vehicle *v = GetVehicle(w->window_number); truelight@0: tron@2952: switch (wid) { darkvater@755: case 5: /* start/stop train */ truelight@193: DoCommandP(v->tile, v->index, 0, NULL, CMD_START_STOP_TRAIN | CMD_MSG(STR_883B_CAN_T_STOP_START_TRAIN)); truelight@0: break; rubidium@4434: case 6: /* center main view */ truelight@0: ScrollMainWindowTo(v->x_pos, v->y_pos); truelight@0: break; rubidium@4434: case 7: /* goto depot */ truelight@601: /* TrainGotoDepot has a nice randomizer in the pathfinder, which causes desyncs... */ bjarni@4506: DoCommandP(v->tile, v->index, _ctrl_pressed ? DEPOT_SERVICE : 0, NULL, CMD_SEND_TRAIN_TO_DEPOT | CMD_NO_TEST_IF_IN_NETWORK | CMD_MSG(STR_8830_CAN_T_SEND_TRAIN_TO_DEPOT)); truelight@0: break; darkvater@755: case 8: /* force proceed */ truelight@193: DoCommandP(v->tile, v->index, 0, NULL, CMD_FORCE_TRAIN_PROCEED | CMD_MSG(STR_8862_CAN_T_MAKE_TRAIN_PASS_SIGNAL)); truelight@0: break; darkvater@755: case 9: /* reverse direction */ truelight@193: DoCommandP(v->tile, v->index, 0, NULL, CMD_REVERSE_TRAIN_DIRECTION | CMD_MSG(STR_8869_CAN_T_REVERSE_DIRECTION)); truelight@0: break; darkvater@755: case 10: /* show train orders */ truelight@0: ShowOrdersWindow(v); truelight@0: break; darkvater@755: case 11: /* show train details */ truelight@0: ShowTrainDetailsWindow(v); truelight@0: break; darkvater@755: case 12: truelight@0: ShowRailVehicleRefitWindow(v); truelight@0: break; bjarni@2244: case 13: bjarni@2244: DoCommandP(v->tile, v->index, _ctrl_pressed ? 1 : 0, NULL, CMD_CLONE_VEHICLE | CMD_MSG(STR_882B_CAN_T_BUILD_RAILROAD_VEHICLE)); bjarni@2244: break; truelight@0: } truelight@0: } break; truelight@0: tron@1485: case WE_RESIZE: tron@1485: w->viewport->width += e->sizing.diff.x; tron@1485: w->viewport->height += e->sizing.diff.y; tron@1485: w->viewport->virtual_width += e->sizing.diff.x; tron@1485: w->viewport->virtual_height += e->sizing.diff.y; tron@1485: break; tron@1485: truelight@0: case WE_DESTROY: tron@338: DeleteWindowById(WC_VEHICLE_REFIT, w->window_number); truelight@0: DeleteWindowById(WC_VEHICLE_ORDERS, w->window_number); truelight@0: DeleteWindowById(WC_VEHICLE_DETAILS, w->window_number); truelight@0: break; truelight@0: truelight@0: case WE_MOUSELOOP: { belugas@4171: const Vehicle *v = GetVehicle(w->window_number); truelight@0: uint32 h; truelight@0: truelight@0: assert(v->type == VEH_Train); bjarni@2244: h = CheckTrainStoppedInDepot(v) >= 0 ? (1 << 9)| (1 << 7) : (1 << 12) | (1 << 13); truelight@0: if (h != w->hidden_state) { truelight@0: w->hidden_state = h; truelight@0: SetWindowDirty(w); truelight@0: } truelight@0: break; truelight@0: } truelight@0: truelight@0: } truelight@0: } truelight@0: truelight@0: static const WindowDesc _train_view_desc = { truelight@0: -1,-1, 250, 134, truelight@0: WC_VEHICLE_VIEW,0, tron@1485: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE, truelight@0: _train_view_widgets, truelight@0: TrainViewWndProc truelight@0: }; truelight@0: belugas@4171: void ShowTrainViewWindow(const Vehicle *v) truelight@0: { belugas@4171: Window *w = AllocateWindowDescFront(&_train_view_desc,v->index); truelight@0: tron@2561: if (w != NULL) { truelight@0: w->caption_color = v->owner; truelight@0: AssignWindowViewport(w, 3, 17, 0xE2, 0x66, w->window_number | (1 << 31), 0); truelight@0: } truelight@0: } truelight@0: Darkvater@1790: static void TrainDetailsCargoTab(const Vehicle *v, int x, int y) truelight@0: { tron@4492: if (v->cargo_cap != 0) { tron@4492: uint num = v->cargo_count; tron@4492: StringID str = STR_8812_EMPTY; truelight@0: truelight@0: if (num != 0) { tron@534: SetDParam(0, v->cargo_type); tron@534: SetDParam(1, num); tron@534: SetDParam(2, v->cargo_source); truelight@0: str = STR_8813_FROM; truelight@0: } truelight@0: DrawString(x, y, str, 0); truelight@0: } truelight@0: } truelight@0: Darkvater@1790: static void TrainDetailsInfoTab(const Vehicle *v, int x, int y) truelight@0: { tron@4492: if (RailVehInfo(v->engine_type)->flags & RVI_WAGON) { tron@4492: SetDParam(0, GetCustomEngineName(v->engine_type)); tron@4492: SetDParam(1, v->value); tron@4492: DrawString(x, y, STR_882D_VALUE, 0x10); tron@4492: } else { tron@534: SetDParam(0, GetCustomEngineName(v->engine_type)); rubidium@4329: SetDParam(1, v->build_year); tron@534: SetDParam(2, v->value); truelight@0: DrawString(x, y, STR_882C_BUILT_VALUE, 0x10); truelight@193: } truelight@0: } truelight@0: Darkvater@1790: static void TrainDetailsCapacityTab(const Vehicle *v, int x, int y) truelight@0: { truelight@0: if (v->cargo_cap != 0) { ludde@2084: SetDParam(0, _cargoc.names_long[v->cargo_type]); tron@534: SetDParam(1, v->cargo_cap); truelight@0: DrawString(x, y, STR_013F_CAPACITY, 0); truelight@0: } truelight@0: } truelight@0: truelight@0: truelight@0: static void DrawTrainDetailsWindow(Window *w) truelight@0: { truelight@0: byte det_tab = WP(w, traindetails_d).tab; tron@4492: const Vehicle* v; tron@4492: const Vehicle* u; tron@4492: AcceptedCargo act_cargo; tron@4492: AcceptedCargo max_cargo; tron@4492: uint i; tron@4492: int num; tron@4492: int x; tron@4492: int y; tron@4492: int sel; truelight@0: truelight@0: num = 0; truelight@919: u = v = GetVehicle(w->window_number); tron@4492: if (det_tab == 3) { // Total cargo tab tron@4492: for (i = 0; i < lengthof(act_cargo); i++) { tron@4492: act_cargo[i] = 0; tron@4492: max_cargo[i] = 0; truelight@0: } truelight@0: tron@4492: do { tron@4492: act_cargo[u->cargo_type] += u->cargo_count; tron@4492: max_cargo[u->cargo_type] += u->cargo_cap; tron@4492: } while ((u = GetNextVehicle(u)) != NULL); tron@4492: tron@4492: /* Set scroll-amount seperately from counting, as to not compute num double tron@4492: * for more carriages of the same type tron@4492: */ truelight@0: for (i = 0; i != NUM_CARGO; i++) { tron@4492: if (max_cargo[i] > 0) num++; // only count carriages that the train has truelight@0: } rubidium@4434: num++; // needs one more because first line is description string tron@4492: } else { tron@4492: do { tron@4492: num++; tron@4492: } while ((u = GetNextVehicle(u)) != NULL); truelight@0: } truelight@0: truelight@0: SetVScrollCount(w, num); truelight@0: truelight@0: w->disabled_state = 1 << (det_tab + 9); tron@4492: if (v->owner != _local_player) w->disabled_state |= (1 << 2); truelight@0: tron@4492: // disable service-scroller when interval is set to disabled tron@4492: if (!_patches.servint_trains) w->disabled_state |= (1 << 6) | (1 << 7); darkvater@156: tron@534: SetDParam(0, v->string_id); tron@534: SetDParam(1, v->unitnumber); truelight@0: DrawWindowWidgets(w); truelight@0: tron@4492: SetDParam(1, v->age / 366); truelight@193: truelight@0: x = 2; truelight@193: tron@2252: SetDParam(0, (v->age + 365 < v->max_age) ? STR_AGE : STR_AGE_RED); tron@534: SetDParam(2, v->max_age / 366); tron@534: SetDParam(3, GetTrainRunningCost(v) >> 8); truelight@0: DrawString(x, 15, STR_885D_AGE_RUNNING_COST_YR, 0); truelight@0: peter1138@3477: SetDParam(2, v->u.rail.cached_max_speed); tron@534: SetDParam(1, v->u.rail.cached_power); tron@534: SetDParam(0, v->u.rail.cached_weight); peter1138@3401: DrawString(x, 25, STR_VEHICLE_INFO_WEIGHT_POWER_MAX_SPEED, 0); truelight@0: tron@534: SetDParam(0, v->profit_this_year); tron@534: SetDParam(1, v->profit_last_year); truelight@0: DrawString(x, 35, STR_885F_PROFIT_THIS_YEAR_LAST_YEAR, 0); truelight@0: tron@534: SetDParam(0, 100 * (v->reliability>>8) >> 8); tron@534: SetDParam(1, v->breakdowns_since_last_service); truelight@0: DrawString(x, 45, STR_8860_RELIABILITY_BREAKDOWNS, 0); truelight@0: tron@534: SetDParam(0, v->service_interval); tron@534: SetDParam(1, v->date_of_last_service); peter1138@2959: DrawString(x + 11, 57 + (w->vscroll.cap * 14), _patches.servint_ispercent ? STR_SERVICING_INTERVAL_PERCENT : STR_883C_SERVICING_INTERVAL_DAYS, 0); truelight@0: truelight@0: y = 57; truelight@0: sel = w->vscroll.pos; truelight@193: truelight@0: // draw the first 3 details tabs truelight@0: if (det_tab != 3) { peter1138@2822: x = 1; tron@2952: for (;;) { peter1138@2959: if (--sel < 0 && sel >= -w->vscroll.cap) { peter1138@2602: int dx = 0; tron@4492: int px; tron@4492: int py; tron@4492: peter1138@2602: u = v; peter1138@2602: do { peter1138@3844: PalSpriteID pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v); peter1138@3844: DrawSprite(GetTrainImage(u, DIR_W) | pal, x + 14 + WagonLengthToPixels(dx), y + 6 + (is_custom_sprite(RailVehInfo(u->engine_type)->image_index) ? _traininfo_vehicle_pitch : 0)); peter1138@2602: dx += u->u.rail.cached_veh_length; peter1138@2602: u = u->next; bjarni@2676: } while (u != NULL && IsArticulatedPart(u)); tron@4492: tron@4492: px = x + WagonLengthToPixels(dx) + 2; tron@4492: py = y + 2; tron@4492: switch (det_tab) { tron@4492: default: NOT_REACHED(); tron@4492: case 0: TrainDetailsCargoTab( v, px, py); break; tron@4492: case 1: TrainDetailsInfoTab( v, px, py); break; tron@4492: case 2: TrainDetailsCapacityTab(v, px, py); break; tron@4492: } truelight@0: y += 14; truelight@0: } tron@4492: v = GetNextVehicle(v); tron@4492: if (v == NULL) return; truelight@0: } peter1138@2959: } else { peter1138@2959: // draw total cargo tab truelight@0: DrawString(x, y + 2, STR_013F_TOTAL_CAPACITY_TEXT, 0); peter1138@2959: for (i = 0; i != NUM_CARGO; i++) { tron@4492: if (max_cargo[i] > 0 && --sel < 0 && sel > -w->vscroll.cap) { truelight@0: y += 14; tron@4492: SetDParam(0, i); // {CARGO} #1 tron@4492: SetDParam(1, act_cargo[i]); // {CARGO} #2 tron@4492: SetDParam(2, i); // {SHORTCARGO} #1 tron@4492: SetDParam(3, max_cargo[i]); // {SHORTCARGO} #2 peter1138@2822: DrawString(x, y + 2, STR_013F_TOTAL_CAPACITY, 0); truelight@0: } peter1138@2959: } truelight@0: } truelight@0: } truelight@0: truelight@0: static void TrainDetailsWndProc(Window *w, WindowEvent *e) truelight@0: { Darkvater@1790: switch (e->event) { truelight@0: case WE_PAINT: truelight@0: DrawTrainDetailsWindow(w); truelight@0: break; truelight@0: case WE_CLICK: { truelight@0: int mod; Darkvater@1790: const Vehicle *v; Darkvater@1790: switch (e->click.widget) { truelight@0: case 2: /* name train */ truelight@919: v = GetVehicle(w->window_number); tron@534: SetDParam(0, v->unitnumber); truelight@4299: ShowQueryString(v->string_id, STR_8865_NAME_TRAIN, 31, 150, w->window_class, w->window_number, CS_ALPHANUMERAL); truelight@0: break; rubidium@4434: case 6: /* inc serv interval */ darkvater@156: mod = _ctrl_pressed? 5 : 10; truelight@0: goto do_change_service_int; truelight@0: truelight@0: case 7: /* dec serv interval */ darkvater@156: mod = _ctrl_pressed? -5 : -10; truelight@0: do_change_service_int: truelight@919: v = GetVehicle(w->window_number); darkvater@156: Darkvater@1790: mod = GetServiceIntervalClamped(mod + v->service_interval); Darkvater@1790: if (mod == v->service_interval) return; truelight@193: tron@2819: DoCommandP(v->tile, v->index, mod, NULL, CMD_CHANGE_SERVICE_INT | CMD_MSG(STR_018A_CAN_T_CHANGE_SERVICING)); truelight@0: break; truelight@0: /* details buttons*/ rubidium@4434: case 9: // Cargo rubidium@4434: case 10: // Information rubidium@4434: case 11: // Capacities rubidium@4434: case 12: // Total cargo truelight@0: CLRBIT(w->disabled_state, 9); truelight@0: CLRBIT(w->disabled_state, 10); truelight@0: CLRBIT(w->disabled_state, 11); truelight@0: CLRBIT(w->disabled_state, 12); truelight@0: SETBIT(w->disabled_state, e->click.widget); truelight@0: WP(w,traindetails_d).tab = e->click.widget - 9; truelight@0: SetWindowDirty(w); truelight@0: break; truelight@0: } truelight@0: } break; truelight@0: tron@2548: case WE_ON_EDIT_TEXT: tron@1820: if (e->edittext.str[0] != '\0') { tron@1820: _cmd_text = e->edittext.str; tron@1820: DoCommandP(0, w->window_number, 0, NULL, tron@1820: CMD_NAME_VEHICLE | CMD_MSG(STR_8866_CAN_T_NAME_TRAIN)); tron@1820: } tron@2548: break; peter1138@2959: peter1138@2959: case WE_RESIZE: tron@4077: if (e->sizing.diff.y == 0) break; peter1138@2959: peter1138@2959: w->vscroll.cap += e->sizing.diff.y / 14; Darkvater@4547: w->widget[4].data = (w->vscroll.cap << 8) + 1; peter1138@2959: break; truelight@0: } truelight@0: } truelight@0: truelight@0: static const Widget _train_details_widgets[] = { peter1138@2959: { WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, peter1138@2959: { WWT_CAPTION, RESIZE_NONE, 14, 11, 329, 0, 13, STR_8802_DETAILS, STR_018C_WINDOW_TITLE_DRAG_THIS}, peter1138@2959: { WWT_PUSHTXTBTN, RESIZE_NONE, 14, 330, 369, 0, 13, STR_01AA_NAME, STR_8867_NAME_TRAIN}, peter1138@2959: { WWT_PANEL, RESIZE_NONE, 14, 0, 369, 14, 55, 0x0, STR_NULL}, peter1138@2959: { WWT_MATRIX, RESIZE_BOTTOM, 14, 0, 357, 56, 139, 0x601, STR_NULL}, peter1138@2959: { WWT_SCROLLBAR, RESIZE_BOTTOM, 14, 358, 369, 56, 139, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, peter1138@2959: { WWT_PUSHTXTBTN, RESIZE_TB, 14, 0, 10, 140, 145, STR_0188, STR_884D_INCREASE_SERVICING_INTERVAL}, peter1138@2959: { WWT_PUSHTXTBTN, RESIZE_TB, 14, 0, 10, 146, 151, STR_0189, STR_884E_DECREASE_SERVICING_INTERVAL}, peter1138@2959: { WWT_PANEL, RESIZE_TB, 14, 11, 369, 140, 151, 0x0, STR_NULL}, peter1138@2959: { WWT_PUSHTXTBTN, RESIZE_TB, 14, 0, 89, 152, 163, STR_013C_CARGO, STR_884F_SHOW_DETAILS_OF_CARGO_CARRIED}, peter1138@2959: { WWT_PUSHTXTBTN, RESIZE_TB, 14, 90, 178, 152, 163, STR_013D_INFORMATION, STR_8850_SHOW_DETAILS_OF_TRAIN_VEHICLES}, peter1138@2959: { WWT_PUSHTXTBTN, RESIZE_TB, 14, 179, 268, 152, 163, STR_013E_CAPACITIES, STR_8851_SHOW_CAPACITIES_OF_EACH}, peter1138@2959: { WWT_PUSHTXTBTN, RESIZE_TB, 14, 269, 357, 152, 163, STR_013E_TOTAL_CARGO, STR_8852_SHOW_TOTAL_CARGO}, peter1138@2959: { WWT_RESIZEBOX, RESIZE_TB, 14, 358, 369, 152, 163, 0x0, STR_RESIZE_BUTTON}, darkvater@176: { WIDGETS_END}, truelight@0: }; truelight@0: truelight@0: truelight@0: static const WindowDesc _train_details_desc = { truelight@0: -1,-1, 370, 164, truelight@0: WC_VEHICLE_DETAILS,WC_VEHICLE_VIEW, peter1138@2959: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE, truelight@0: _train_details_widgets, truelight@0: TrainDetailsWndProc truelight@0: }; truelight@0: truelight@0: belugas@4171: static void ShowTrainDetailsWindow(const Vehicle *v) truelight@0: { truelight@0: Window *w; truelight@0: VehicleID veh = v->index; truelight@0: truelight@0: DeleteWindowById(WC_VEHICLE_ORDERS, veh); truelight@0: DeleteWindowById(WC_VEHICLE_DETAILS, veh); truelight@0: truelight@193: _alloc_wnd_parent_num = veh; truelight@0: w = AllocateWindowDesc(&_train_details_desc); truelight@0: truelight@0: w->window_number = veh; truelight@0: w->caption_color = v->owner; truelight@0: w->vscroll.cap = 6; Darkvater@4547: w->widget[4].data = (w->vscroll.cap << 8) + 1; peter1138@2959: peter1138@2959: w->resize.step_height = 14; peter1138@2959: w->resize.height = w->height - 14 * 2; /* Minimum of 4 wagons in the display */ peter1138@2959: truelight@0: WP(w,traindetails_d).tab = 0; truelight@0: } truelight@0: bjarni@4456: static const Widget _player_trains_widgets[] = { rubidium@4344: { WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, rubidium@4344: { WWT_CAPTION, RESIZE_RIGHT, 14, 11, 312, 0, 13, STR_881B_TRAINS, STR_018C_WINDOW_TITLE_DRAG_THIS}, rubidium@4344: { WWT_STICKYBOX, RESIZE_LR, 14, 313, 324, 0, 13, 0x0, STR_STICKY_BUTTON}, rubidium@4344: { WWT_PUSHTXTBTN, RESIZE_NONE, 14, 0, 80, 14, 25, STR_SORT_BY, STR_SORT_ORDER_TIP}, rubidium@4344: { WWT_PANEL, RESIZE_NONE, 14, 81, 235, 14, 25, 0x0, STR_SORT_CRITERIA_TIP}, rubidium@4344: { WWT_TEXTBTN, RESIZE_NONE, 14, 236, 247, 14, 25, STR_0225, STR_SORT_CRITERIA_TIP}, rubidium@4344: { WWT_PANEL, RESIZE_RIGHT, 14, 248, 324, 14, 25, 0x0, STR_NULL}, rubidium@4344: { WWT_MATRIX, RESIZE_RB, 14, 0, 312, 26, 207, 0x701, STR_883D_TRAINS_CLICK_ON_TRAIN_FOR}, rubidium@4344: { WWT_SCROLLBAR, RESIZE_LRB, 14, 313, 324, 26, 207, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, bjarni@4506: { WWT_PUSHTXTBTN, RESIZE_TB, 14, 0, 156, 208, 219, STR_SEND_TO_DEPOTS, STR_SEND_TO_DEPOTS_TIP}, rubidium@4344: { WWT_PUSHTXTBTN, RESIZE_TB, 14, 157, 312, 208, 219, STR_REPLACE_VEHICLES, STR_REPLACE_HELP}, rubidium@4344: { WWT_PANEL, RESIZE_RTB, 14, 313, 312, 208, 219, 0x0, STR_NULL}, rubidium@4344: { WWT_RESIZEBOX, RESIZE_LRTB, 14, 313, 324, 208, 219, 0x0, STR_RESIZE_BUTTON}, tron@588: { WIDGETS_END}, tron@588: }; darkvater@164: truelight@867: static const Widget _other_player_trains_widgets[] = { rubidium@4344: { WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, rubidium@4344: { WWT_CAPTION, RESIZE_RIGHT, 14, 11, 312, 0, 13, STR_881B_TRAINS, STR_018C_WINDOW_TITLE_DRAG_THIS}, rubidium@4344: { WWT_STICKYBOX, RESIZE_LR, 14, 313, 324, 0, 13, 0x0, STR_STICKY_BUTTON}, rubidium@4344: { WWT_PUSHTXTBTN, RESIZE_NONE, 14, 0, 80, 14, 25, STR_SORT_BY, STR_SORT_ORDER_TIP}, rubidium@4344: { WWT_PANEL, RESIZE_NONE, 14, 81, 235, 14, 25, 0x0, STR_SORT_CRITERIA_TIP}, rubidium@4344: { WWT_TEXTBTN, RESIZE_NONE, 14, 236, 247, 14, 25, STR_0225, STR_SORT_CRITERIA_TIP}, rubidium@4344: { WWT_PANEL, RESIZE_RIGHT, 14, 248, 324, 14, 25, 0x0, STR_NULL}, rubidium@4344: { WWT_MATRIX, RESIZE_RB, 14, 0, 312, 26, 207, 0x701, STR_883D_TRAINS_CLICK_ON_TRAIN_FOR}, rubidium@4344: { WWT_SCROLLBAR, RESIZE_LRB, 14, 313, 324, 26, 207, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, rubidium@4344: { WWT_PANEL, RESIZE_RTB, 14, 0, 312, 208, 219, 0x0, STR_NULL}, rubidium@4344: { WWT_RESIZEBOX, RESIZE_LRTB, 14, 313, 324, 208, 219, 0x0, STR_RESIZE_BUTTON}, tron@588: { WIDGETS_END}, tron@588: }; truelight@0: truelight@0: static const WindowDesc _player_trains_desc = { darkvater@164: -1, -1, 325, 220, truelight@0: WC_TRAINS_LIST,0, truelight@867: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE, truelight@0: _player_trains_widgets, bjarni@4442: PlayerVehWndProc truelight@0: }; truelight@0: truelight@0: static const WindowDesc _other_player_trains_desc = { truelight@867: -1, -1, 325, 220, truelight@0: WC_TRAINS_LIST,0, truelight@867: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE, truelight@0: _other_player_trains_widgets, bjarni@4442: PlayerVehWndProc truelight@0: }; truelight@0: bjarni@4414: static void ShowPlayerTrainsLocal(PlayerID player, StationID station, OrderID order, bool show_shared) truelight@0: { truelight@0: Window *w; truelight@0: bjarni@4408: if (show_shared) { bjarni@4456: w = AllocateWindowDescFront(&_player_trains_desc, (order << 16) | (VEH_Train << 11) | VLW_SHARED_ORDERS | player); darkvater@164: } else { bjarni@4449: uint16 VLW_flag = (station == INVALID_STATION) ? VLW_STANDARD : VLW_STATION_LIST; bjarni@4408: if (player == _local_player) { bjarni@4449: w = AllocateWindowDescFront(&_player_trains_desc, (station << 16) | (VEH_Train << 11) | VLW_flag | player); bjarni@4449: } else { bjarni@4449: w = AllocateWindowDescFront(&_other_player_trains_desc, (station << 16) | (VEH_Train << 11) | VLW_flag | player); bjarni@4408: } truelight@0: } truelight@0: } bjarni@4408: bjarni@4408: void ShowPlayerTrains(PlayerID player, StationID station) bjarni@4408: { bjarni@4408: ShowPlayerTrainsLocal(player, station, INVALID_ORDER, false); bjarni@4408: } bjarni@4408: bjarni@4408: void ShowVehWithSharedOrdersTrains(Vehicle *v) bjarni@4408: { rubidium@4434: if (v->orders == NULL) return; // no shared list to show bjarni@4408: ShowPlayerTrainsLocal(v->owner, INVALID_STATION, v->orders->index, true); bjarni@4408: }