truelight@0: #include "stdafx.h" Darkvater@1891: #include "openttd.h" tron@1299: #include "debug.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" darkvater@420: darkvater@420: int _traininfo_vehicle_pitch = 0; 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); tron@1926: const Engine* e = GetEngine(engine_number); bjarni@842: int multihead = (rvi->flags&RVI_MULTIHEAD?1:0); bjarni@842: YearMonthDay ymd; hackykid@1907: ConvertDayToYMD(&ymd, e->intro_date); 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 */ hackykid@1907: SetDParam(0, rvi->max_speed * 10 >> 4); 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 */ hackykid@1907: SetDParam(0, (rvi->running_cost_base * _price.running_rail[rvi->engclass] >> 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) { hackykid@1907: SetDParam(0, _cargoc.names_long_p[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 */ hackykid@1907: SetDParam(0, ymd.year + 1920); 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; 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); hackykid@1907: bool refittable = (_engine_refit_masks[engine_number] != 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: hackykid@1907: /* Cargo type + capacity */ hackykid@1907: SetDParam(0, _cargoc.names_long_p[rvi->cargo_type]); hackykid@1907: SetDParam(1, rvi->capacity); hackykid@1907: SetDParam(2, refittable ? STR_9842_REFITTABLE : STR_EMPTY); hackykid@1907: DrawString(x, y, STR_PURCHASE_INFO_CAPACITY, 0); hackykid@1907: y += 10; bjarni@842: } truelight@0: tron@1977: void CcBuildWagon(bool success, TileIndex tile, uint32 p1, uint32 p2) truelight@0: { truelight@0: Vehicle *v,*found; truelight@0: truelight@0: if (!success) truelight@0: return; truelight@0: truelight@0: // find a locomotive in the depot. truelight@0: found = NULL; truelight@0: FOR_ALL_VEHICLES(v) { bjarni@1067: if (v->type == VEH_Train && v->subtype == TS_Front_Engine && truelight@0: v->tile == tile && truelight@0: v->u.rail.track == 0x80) { truelight@0: if (found != NULL) // must be exactly one. truelight@0: return; 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. truelight@0: DoCommandP(0, _new_wagon_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: { truelight@0: Vehicle *v; truelight@0: truelight@0: if (!success) truelight@0: return; truelight@193: truelight@919: v = GetVehicle(_new_train_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: darkvater@524: static void engine_drawing_loop(int *x, int *y, int *pos, int *sel, truelight@867: int *selected_id, byte railtype, byte show_max, bool is_engine) darkvater@524: { darkvater@524: int i; darkvater@524: darkvater@524: for (i = 0; i < NUM_TRAIN_ENGINES; i++) { tron@1926: const Engine *e = GetEngine(i); tron@539: const RailVehicleInfo *rvi = RailVehInfo(i); darkvater@524: celestar@2032: if (!IsCompatibleRail(railtype, e->railtype) || !(rvi->flags & RVI_WAGON) != is_engine || darkvater@524: !HASBIT(e->player_avail, _local_player)) darkvater@524: continue; darkvater@524: truelight@867: if (*sel == 0) truelight@867: *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); darkvater@524: DrawTrainEngine(*x + 29, *y + 6 + _traininfo_vehicle_pitch, i, darkvater@524: SPRITE_PALETTE(PLAYER_SPRITE_COLOR(_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: { truelight@0: switch(e->event) { truelight@0: case WE_PAINT: truelight@193: truelight@0: if (w->window_number == 0) truelight@0: SETBIT(w->disabled_state, 5); truelight@0: truelight@0: { truelight@0: int count = 0; darkvater@460: byte railtype = WP(w,buildtrain_d).railtype; darkvater@460: int i; darkvater@460: darkvater@460: for (i = 0; i < NUM_TRAIN_ENGINES; i++) { tron@1926: const Engine *e = GetEngine(i); celestar@2032: if (IsCompatibleRail(railtype, e->railtype) darkvater@460: && HASBIT(e->player_avail, _local_player)) truelight@0: count++; 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: { darkvater@460: byte 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; truelight@0: int selected_id = -1; 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: truelight@0: if (selected_id != -1) { 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: { truelight@0: 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: { truelight@0: int sel_eng; truelight@0: sel_eng = WP(w,buildtrain_d).sel_engine; truelight@0: if (sel_eng != -1) 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 */ darkvater@968: int sel_eng = WP(w,buildtrain_d).sel_engine; darkvater@968: if (sel_eng != -1) { darkvater@968: WP(w,buildtrain_d).rename_engine = sel_eng; darkvater@968: ShowQueryString(GetCustomEngineName(sel_eng), darkvater@968: STR_886A_RENAME_TRAIN_VEHICLE_TYPE, 31, 160, w->window_class, w->window_number); darkvater@968: } darkvater@968: } break; truelight@0: } truelight@0: } break; truelight@0: truelight@0: case WE_4: truelight@0: if (w->window_number != 0 && !FindWindowById(WC_VEHICLE_DEPOT, w->window_number)) { truelight@0: DeleteWindow(w); 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; truelight@867: w->widget[2].unkA = (w->vscroll.cap << 8) + 1; truelight@867: } break; truelight@0: } truelight@0: } truelight@193: truelight@0: static const Widget _new_rail_vehicle_widgets[] = { truelight@867: { WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, darkvater@1017: { WWT_CAPTION, RESIZE_NONE, 14, 11, 227, 0, 13, STR_JUST_STRING, STR_018C_WINDOW_TITLE_DRAG_THIS}, darkvater@893: { WWT_MATRIX, RESIZE_BOTTOM, 14, 0, 215, 14, 125, 0x801, STR_8843_TRAIN_VEHICLE_SELECTION}, darkvater@893: { WWT_SCROLLBAR, RESIZE_BOTTOM, 14, 216, 227, 14, 125, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, hackykid@1908: { WWT_PANEL, RESIZE_TB, 14, 0, 227, 126, 197, 0x0, STR_NULL}, hackykid@1908: { WWT_PUSHTXTBTN, RESIZE_TB, 14, 0, 107, 198, 209, STR_881F_BUILD_VEHICLE, STR_8844_BUILD_THE_HIGHLIGHTED_TRAIN}, hackykid@1908: { WWT_PUSHTXTBTN, RESIZE_TB, 14, 108, 215, 198, 209, STR_8820_RENAME, STR_8845_RENAME_TRAIN_VEHICLE_TYPE}, hackykid@1908: { 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: tron@1977: static 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; truelight@867: w->widget[2].unkA = (w->vscroll.cap << 8) + 1; truelight@867: truelight@867: w->resize.step_height = 14; truelight@867: 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@2049: WP(w,buildtrain_d).railtype = _m[tile].m3 & 0xF; truelight@0: } else { truelight@0: w->caption_color = _local_player; celestar@1962: WP(w,buildtrain_d).railtype = GetPlayer(_local_player)->max_railtype - 1; truelight@0: } truelight@0: } truelight@0: Darkvater@1790: static void DrawTrainImage(const Vehicle *v, int x, int y, int count, int skip, VehicleID selection) truelight@0: { hackykid@1922: int max_x = x + count * 29; hackykid@1922: truelight@0: do { truelight@0: if (--skip < 0) { truelight@0: int image = GetTrainImage(v, 6); truelight@0: uint32 ormod = SPRITE_PALETTE(PLAYER_SPRITE_COLOR(v->owner)); hackykid@1922: int width = v->u.rail.cached_veh_length * 3; hackykid@1922: hackykid@1922: if (x + width + 4 <= max_x) { hackykid@1922: if (v->vehstatus & VS_CRASHED) hackykid@1922: ormod = PALETTE_CRASH; hackykid@1922: DrawSprite(image | ormod, x + 14, y + 6 + _traininfo_vehicle_pitch); hackykid@1922: if (v->index == selection) hackykid@1938: DrawFrameRect(x - 1, y - 1, x + width + 4, y + 12, 15, FR_BORDERONLY); hackykid@1922: } hackykid@1922: x += width + 5; truelight@0: } truelight@0: truelight@0: if (!(v = v->next)) truelight@0: break; hackykid@1922: } while (x < max_x); 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 = tron@1901: IsTileOwner(tile, _local_player) ? 0 : ((1 << 4) | (1 << 5) | (1 << 8)); truelight@0: truelight@0: /* determine amount of items for scroller */ truelight@867: num = 0; truelight@867: hnum = 1; truelight@0: FOR_ALL_VEHICLES(v) { truelight@0: if (v->type == VEH_Train && tron@1986: (v->subtype == TS_Front_Engine || v->subtype == TS_Free_Car) && 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. tron@1986: if (v->subtype == TS_Front_Engine) { tron@1986: i = 0; tron@1986: u = v; tron@1986: do i++; while ((u = u->next) != NULL); tron@1986: if (i > hnum) hnum = i; 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); truelight@0: SetHScrollCount(w, 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) { tron@1986: if (v->type == VEH_Train && v->subtype == TS_Front_Engine && tron@1986: v->tile == tile && v->u.rail.track == 0x80 && truelight@867: --num < 0 && num >= -w->vscroll.cap) { truelight@867: DrawTrainImage(v, x+21, y, w->hscroll.cap, 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: celestar@1002: /*Draw the train counter */ celestar@1002: i = 0; celestar@1002: u = v; hackykid@1922: do { hackykid@1922: i += u->u.rail.cached_veh_length + 1; hackykid@1922: } while ( (u=u->next) != NULL); //Determine length of train hackykid@1922: SetDParam(0, (i+8) / 9); //Set the counter celestar@1002: i = (w->hscroll.cap * 29) + (x + 26); //Calculate position of text according to window size celestar@1002: DrawStringCentered(i, y+5, STR_TINY_BLACK, 0); //Draw the counter tron@1019: darkvater@22: /* Draw the pretty flag */ truelight@0: DrawSprite(v->vehstatus&VS_STOPPED ? 0xC12 : 0xC13, 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) { tron@1986: if (v->type == VEH_Train && v->subtype == TS_Free_Car && tron@1986: v->tile == tile && v->u.rail.track == 0x80 && truelight@867: --num < 0 && num >= -w->vscroll.cap) { truelight@867: DrawTrainImage(v, x+50, y, w->hscroll.cap - 1, 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; celestar@1002: do i++; while ( (u=u->next) != NULL); //Determine length of train celestar@1002: SetDParam(0, i); //Set the counter celestar@1002: i = (w->hscroll.cap * 29) + (x + 26); //Calculate position of text according to window size celestar@1002: DrawStringCentered(i, y+5, 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: truelight@0: static int GetVehicleFromTrainDepotWndPt(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; truelight@914: if ( (uint) row >= w->vscroll.cap) truelight@0: 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@1067: v->subtype == TS_Front_Engine && truelight@0: v->tile == w->window_number && truelight@0: v->u.rail.track == 0x80 && truelight@0: --row < 0) { hackykid@1922: skip = w->hscroll.pos; truelight@0: goto found_it; truelight@0: } truelight@0: } truelight@0: hackykid@1922: x -= 29; /* 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@1067: v->subtype == TS_Free_Car && truelight@0: v->tile == w->window_number && truelight@0: v->u.rail.track == 0x80 && truelight@0: --row < 0) truelight@0: goto found_it; 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 */ hackykid@1922: if (x < 0 && v->subtype == TS_Front_Engine) hackykid@1922: return (x >= -10) ? -2 : -1; hackykid@1922: hackykid@1922: // skip vehicles that are scrolled off the left side hackykid@1922: while (skip--) v = v->next; truelight@193: truelight@0: /* find the vehicle in this row that was clicked */ hackykid@1922: while ((x -= v->u.rail.cached_veh_length * 3 + 5) >= 0) { truelight@0: v = v->next; truelight@0: if (v == NULL) break; truelight@0: } truelight@0: truelight@193: d->wagon = v; truelight@0: truelight@0: return 0; truelight@0: } truelight@0: truelight@0: static void TrainDepotMoveVehicle(Vehicle *wagon, int sel, Vehicle *head) truelight@0: { truelight@0: Vehicle *v; truelight@0: truelight@919: v = GetVehicle(sel); truelight@0: bjarni@1067: if (/*v->subtype == TS_Front_Engine ||*/ v == wagon) truelight@0: return; truelight@0: truelight@0: if (wagon == NULL) { truelight@0: if (head != NULL) truelight@0: wagon = GetLastVehicleInChain(head); truelight@0: } else { truelight@0: wagon = GetPrevVehicleInChain(wagon); truelight@0: if (wagon == NULL) truelight@0: return; truelight@0: } truelight@0: truelight@0: if (wagon == v) truelight@0: return; truelight@0: truelight@0: DoCommandP(v->tile, v->index + ((wagon==NULL ? (uint32)-1 : 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; truelight@0: int mode, sel; truelight@0: Vehicle *v; truelight@0: truelight@0: mode = GetVehicleFromTrainDepotWndPt(w, x, y, &gdvp); dominik@10: dominik@10: // share / copy orders truelight@0: if (_thd.place_mode && mode <= 0) { _place_clicked_vehicle = gdvp.head; return; } truelight@193: truelight@0: v = gdvp.wagon; truelight@0: truelight@0: switch(mode) { dominik@10: case 0: // start dragging of vehicle truelight@0: sel = (int16)WP(w,traindepot_d).sel; truelight@0: if (sel != -1) { 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; truelight@0: SetObjectToPlaceWnd( SPRITE_PALETTE(PLAYER_SPRITE_COLOR(v->owner)) + GetTrainImage(v, 6), 4, w); truelight@0: SetWindowDirty(w); truelight@0: } truelight@0: break; 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: truelight@0: static void TrainDepotWndProc(Window *w, WindowEvent *e) truelight@0: { truelight@0: switch(e->event) { truelight@0: case WE_PAINT: truelight@0: DrawTrainDepotWindow(w); truelight@0: break; truelight@0: truelight@0: case WE_CLICK: { truelight@0: switch(e->click.widget) { truelight@867: case 8: truelight@0: ShowBuildTrainWindow(w->window_number); truelight@0: break; truelight@867: case 9: truelight@0: ScrollMainWindowToTile(w->window_number); truelight@0: break; darkvater@982: case 6: truelight@0: TrainDepotClickTrain(w, e->click.pt.x, e->click.pt.y); truelight@0: break; truelight@0: } truelight@0: } break; truelight@0: truelight@0: case WE_DESTROY: truelight@0: DeleteWindowById(WC_BUILD_VEHICLE, w->window_number); truelight@0: break; truelight@0: truelight@0: case WE_DRAGDROP: { truelight@0: 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@1067: if (v->subtype != TS_Front_Engine) { 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) { truelight@0: if (gdvp.wagon == NULL || gdvp.wagon->index != sel) { truelight@0: TrainDepotMoveVehicle(gdvp.wagon, sel, gdvp.head); bjarni@1067: } else if (gdvp.head != NULL && gdvp.head->subtype == TS_Front_Engine) { 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; truelight@867: w->hscroll.cap += e->sizing.diff.x / 29; darkvater@982: w->widget[6].unkA = (w->vscroll.cap << 8) + 1; truelight@867: } break; truelight@0: } truelight@0: } truelight@0: truelight@0: static const Widget _train_depot_widgets[] = { darkvater@982: { WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, celestar@1002: { WWT_CAPTION, RESIZE_RIGHT, 14, 11, 348, 0, 13, STR_8800_TRAIN_DEPOT, STR_018C_WINDOW_TITLE_DRAG_THIS}, celestar@1002: { WWT_STICKYBOX, RESIZE_LR, 14, 349, 360, 0, 13, 0x0, STR_STICKY_BUTTON}, truelight@0: celestar@1002: { WWT_PANEL, RESIZE_LRB, 14, 326, 348, 14, 13, 0x0, STR_NULL}, celestar@1002: { WWT_PANEL, RESIZE_LRTB, 14, 326, 348, 14, 54, 0x2A9, STR_8841_DRAG_TRAIN_VEHICLE_TO_HERE}, celestar@1002: { WWT_PANEL, RESIZE_LRTB, 14, 326, 348, 55, 109, 0x2BF, STR_DRAG_WHOLE_TRAIN_TO_SELL_TIP}, celestar@1002: celestar@1002: { WWT_MATRIX, RESIZE_RB, 14, 0, 325, 14, 97, 0x601, STR_883F_TRAINS_CLICK_ON_TRAIN_FOR}, celestar@1002: { WWT_SCROLLBAR, RESIZE_LRB, 14, 349, 360, 14, 109, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, truelight@914: { WWT_PUSHTXTBTN, RESIZE_TB, 14, 0, 167, 110, 121, STR_8815_NEW_VEHICLES, STR_8840_BUILD_NEW_TRAIN_VEHICLE}, celestar@1002: { WWT_PUSHTXTBTN, RESIZE_TB, 14, 168, 348, 110, 121, STR_00E4_LOCATION, STR_8842_CENTER_MAIN_VIEW_ON_TRAIN}, Darkvater@1658: { WWT_HSCROLLBAR, RESIZE_RTB, 14, 0, 325, 98, 109, 0x0, STR_HSCROLL_BAR_SCROLLS_LIST}, celestar@1002: { WWT_PANEL, RESIZE_RTB, 14, 349, 348, 110, 121, 0x0, STR_NULL}, celestar@1002: { 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; truelight@867: w->hscroll.cap = 10; truelight@867: w->resize.step_width = 29; 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: DrawString(1, 15, STR_983F_SELECT_CARGO_TYPE_TO_CARRY, 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) { Darkvater@1802: int32 cost = DoCommandByTile(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); Darkvater@1802: SetDParam(0, _cargoc.names_long_p[WP(w,refit_d).cargo]); tron@534: SetDParam(1, _returned_refit_amount); 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: truelight@0: 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[] = { truelight@867: { WWT_TEXTBTN, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, truelight@867: { WWT_CAPTION, RESIZE_NONE, 14, 11, 239, 0, 13, STR_983B_REFIT, STR_018C_WINDOW_TITLE_DRAG_THIS}, truelight@867: { WWT_IMGBTN, RESIZE_NONE, 14, 0, 239, 14, 135, 0x0, STR_RAIL_SELECT_TYPE_OF_CARGO_FOR}, truelight@867: { WWT_IMGBTN, RESIZE_NONE, 14, 0, 239, 136, 157, 0x0, STR_NULL}, truelight@867: { WWT_PUSHTXTBTN, RESIZE_NONE, 14, 0, 239, 158, 169, STR_RAIL_REFIT_VEHICLE,STR_RAIL_REFIT_TO_CARRY_HIGHLIGHTED}, 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: truelight@0: static Widget _train_view_widgets[] = { tron@1485: { WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW }, tron@1485: { WWT_CAPTION, RESIZE_RIGHT, 14, 11, 237, 0, 13, STR_882E, STR_018C_WINDOW_TITLE_DRAG_THIS }, tron@1485: { WWT_STICKYBOX, RESIZE_LR, 14, 238, 249, 0, 13, 0x0, STR_STICKY_BUTTON }, tron@1485: { WWT_PANEL, RESIZE_RB, 14, 0, 231, 14, 121, 0x0, STR_NULL }, tron@1485: { WWT_6, RESIZE_RB, 14, 2, 229, 16, 119, 0x0, STR_NULL }, tron@1485: { WWT_PUSHIMGBTN, RESIZE_RTB, 14, 0, 237, 122, 133, 0x0, STR_8846_CURRENT_TRAIN_ACTION_CLICK }, tron@1485: { WWT_PUSHIMGBTN, RESIZE_LR, 14, 232, 249, 14, 31, 0x2AB, STR_8848_CENTER_MAIN_VIEW_ON_TRAIN }, tron@1485: { WWT_PUSHIMGBTN, RESIZE_LR, 14, 232, 249, 32, 49, 0x2AD, STR_8849_SEND_TRAIN_TO_DEPOT }, tron@1485: { WWT_PUSHIMGBTN, RESIZE_LR, 14, 232, 249, 50, 67, 0x2B1, STR_884A_FORCE_TRAIN_TO_PROCEED }, tron@1485: { WWT_PUSHIMGBTN, RESIZE_LR, 14, 232, 249, 68, 85, 0x2CB, STR_884B_REVERSE_DIRECTION_OF_TRAIN }, tron@1485: { WWT_PUSHIMGBTN, RESIZE_LR, 14, 232, 249, 86, 103, 0x2B2, STR_8847_SHOW_TRAIN_S_ORDERS }, tron@1485: { WWT_PUSHIMGBTN, RESIZE_LR, 14, 232, 249, 104, 121, 0x2B3, STR_884C_SHOW_TRAIN_DETAILS }, tron@1485: { WWT_PUSHIMGBTN, RESIZE_LR, 14, 232, 249, 68, 85, 0x2B4, STR_RAIL_REFIT_VEHICLE_TO_CARRY }, tron@1485: { WWT_PANEL, RESIZE_LRB, 14, 232, 249, 122, 121, 0x0, STR_NULL }, tron@1485: { WWT_RESIZEBOX, RESIZE_LRTB, 14, 238, 249, 122, 133, 0x0, STR_NULL }, tron@1485: { WIDGETS_END } truelight@0: }; truelight@0: 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: darkvater@755: w->disabled_state = (v->owner == _local_player) ? 0 : 0x380; truelight@193: celestar@1387: SETBIT(w->disabled_state, 12); celestar@1387: Darkvater@1802: /* See if any vehicle can be refitted */ celestar@1387: for ( u = v; u != NULL; u = u->next) { Darkvater@1802: if (_engine_refit_masks[u->engine_type] != 0 || Darkvater@1802: (!(RailVehInfo(v->engine_type)->flags & RVI_WAGON) && v->cargo_cap != 0)) { celestar@1387: CLRBIT(w->disabled_state, 12); celestar@1387: /* We have a refittable carriage, bail out */ celestar@1387: break; celestar@1387: } celestar@1387: } celestar@1387: truelight@0: /* draw widgets & caption */ tron@534: SetDParam(0, v->string_id); tron@534: SetDParam(1, v->unitnumber); truelight@0: DrawWindowWidgets(w); truelight@0: truelight@0: /* draw the flag */ tron@1485: DrawSprite(v->vehstatus & VS_STOPPED ? 0xC12 : 0xC13, 2, tron@1485: w->widget[5].top + 1); truelight@193: 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) { truelight@0: str = STR_8861_STOPPED; truelight@0: } else { tron@534: SetDParam(0, v->u.rail.last_speed * 10 >> 4); 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@555: SetDParam(0, v->current_order.station); tron@534: SetDParam(1, v->u.rail.last_speed * 10 >> 4); truelight@0: } break; truelight@0: truelight@0: case OT_GOTO_DEPOT: { truelight@1313: Depot *dep = GetDepot(v->current_order.station); tron@534: SetDParam(0, dep->town_index); truelight@0: str = STR_HEADING_FOR_TRAIN_DEPOT + _patches.vehicle_speed; tron@534: SetDParam(1, v->u.rail.last_speed * 10 >> 4); 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@555: SetDParam(0, v->current_order.station); darkvater@395: str = STR_HEADING_FOR_WAYPOINT + _patches.vehicle_speed; tron@534: SetDParam(1, v->u.rail.last_speed * 10 >> 4); 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; tron@534: SetDParam(0, v->u.rail.last_speed * 10 >> 4); truelight@0: } else truelight@0: str = STR_EMPTY; truelight@0: break; truelight@0: } truelight@0: } truelight@0: tron@1485: DrawStringCentered((w->widget[5].right - w->widget[5].left) / 2, tron@1485: 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: truelight@0: 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; darkvater@755: case 6: /* center main view */ truelight@0: ScrollMainWindowTo(v->x_pos, v->y_pos); truelight@0: break; darkvater@755: case 7: /* goto depot */ truelight@601: /* TrainGotoDepot has a nice randomizer in the pathfinder, which causes desyncs... */ truelight@601: DoCommandP(v->tile, v->index, 0, NULL, CMD_TRAIN_GOTO_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; 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: { truelight@0: Vehicle *v; truelight@0: uint32 h; truelight@0: truelight@919: v = GetVehicle(w->window_number); truelight@0: assert(v->type == VEH_Train); truelight@1313: h = CheckTrainStoppedInDepot(v) >= 0 ? (1 << 9) : (1 << 12); 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: truelight@0: void ShowTrainViewWindow(Vehicle *v) truelight@0: { truelight@0: Window *w; truelight@0: truelight@0: w = AllocateWindowDescFront(&_train_view_desc,v->index); truelight@0: if (w) { 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: { truelight@0: int num; truelight@0: StringID str; truelight@0: truelight@0: if (v->cargo_cap != 0) { truelight@0: num = v->cargo_count; truelight@0: str = STR_8812_EMPTY; 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@540: const RailVehicleInfo *rvi = RailVehInfo(v->engine_type); truelight@0: truelight@0: if (!(rvi->flags & RVI_WAGON)) { tron@534: SetDParam(0, GetCustomEngineName(v->engine_type)); tron@534: SetDParam(1, v->build_year + 1920); tron@534: SetDParam(2, v->value); truelight@0: DrawString(x, y, STR_882C_BUILT_VALUE, 0x10); truelight@0: } else { tron@534: SetDParam(0, GetCustomEngineName(v->engine_type)); tron@534: SetDParam(1, v->value); truelight@0: DrawString(x, y, STR_882D_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) { tron@534: SetDParam(1, v->cargo_cap); tron@534: SetDParam(0, _cargoc.names_long_p[v->cargo_type]); truelight@0: DrawString(x, y, STR_013F_CAPACITY, 0); truelight@0: } truelight@0: } truelight@0: Darkvater@1790: typedef void TrainDetailsDrawerProc(const Vehicle *v, int x, int y); truelight@0: truelight@0: static TrainDetailsDrawerProc * const _train_details_drawer_proc[3] = { truelight@0: TrainDetailsCargoTab, truelight@0: TrainDetailsInfoTab, truelight@0: TrainDetailsCapacityTab, truelight@0: }; truelight@0: truelight@0: static void DrawTrainDetailsWindow(Window *w) truelight@0: { Darkvater@1790: const Vehicle *v, *u; truelight@0: uint16 tot_cargo[NUM_CARGO][2]; // count total cargo ([0]-actual cargo, [1]-total cargo) truelight@0: int i,num,x,y,sel; truelight@0: StringID str; truelight@0: byte det_tab = WP(w, traindetails_d).tab; truelight@0: truelight@0: /* Count number of vehicles */ truelight@0: num = 0; truelight@0: truelight@0: // det_tab == 3 <-- Total Cargo tab truelight@0: if (det_tab == 3) // reset tot_cargo array to 0 values truelight@0: memset(tot_cargo, 0, sizeof(tot_cargo)); truelight@193: truelight@919: u = v = GetVehicle(w->window_number); truelight@0: do { truelight@0: if (det_tab != 3) truelight@0: num++; truelight@0: else { truelight@0: tot_cargo[u->cargo_type][0] += u->cargo_count; truelight@0: tot_cargo[u->cargo_type][1] += u->cargo_cap; truelight@0: } truelight@0: } while ( (u = u->next) != NULL); truelight@0: truelight@0: /* set scroll-amount seperately from counting, as to not truelight@0: compute num double for more carriages of the same type truelight@0: */ truelight@0: if (det_tab == 3) { truelight@0: for (i = 0; i != NUM_CARGO; i++) { truelight@0: if (tot_cargo[i][1] > 0) // only count carriages that the train has truelight@0: num++; truelight@0: } truelight@0: num++; // needs one more because first line is description string truelight@0: } truelight@0: truelight@0: SetVScrollCount(w, num); truelight@0: truelight@0: w->disabled_state = 1 << (det_tab + 9); truelight@0: if (v->owner != _local_player) truelight@0: w->disabled_state |= (1 << 2); truelight@0: darkvater@156: if (!_patches.servint_trains) // disable service-scroller when interval is set to disabled darkvater@156: 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: truelight@0: num = v->age / 366; tron@534: SetDParam(1, num); truelight@193: truelight@0: x = 2; truelight@193: truelight@0: str = STR_0199_YEAR; truelight@0: if (num != 1) { truelight@0: str += STR_019A_YEARS - STR_0199_YEAR; truelight@0: if ((uint16)(v->max_age - 366) < v->age) truelight@0: str += STR_019B_YEARS - STR_019A_YEARS; truelight@0: } tron@534: SetDParam(0, str); 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: hackykid@1905: SetDParam(2, v->u.rail.cached_max_speed * 10 >> 4); tron@534: SetDParam(1, v->u.rail.cached_power); tron@534: SetDParam(0, v->u.rail.cached_weight); truelight@0: DrawString(x, 25, STR_885E_WEIGHT_T_POWER_HP_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); darkvater@156: DrawString(x + 11, 141, _patches.servint_ispercent?STR_SERVICING_INTERVAL_PERCENT:STR_883C_SERVICING_INTERVAL_DAYS, 0); truelight@0: truelight@0: x = 1; 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) { truelight@0: for(;;) { truelight@0: if (--sel < 0 && sel >= -6) { truelight@0: DrawTrainImage(v, x, y, 1, 0, INVALID_VEHICLE); truelight@0: _train_details_drawer_proc[WP(w,traindetails_d).tab](v, x + 30, y + 2); truelight@0: y += 14; truelight@0: } truelight@0: if ( (v=v->next) == NULL) truelight@0: return; truelight@0: } truelight@0: } truelight@0: else { // draw total cargo tab truelight@0: i = 0; truelight@0: DrawString(x, y + 2, STR_013F_TOTAL_CAPACITY_TEXT, 0); truelight@0: do { truelight@0: if (tot_cargo[i][1] > 0 && --sel < 0 && sel >= -5) { truelight@0: y += 14; truelight@0: // STR_013F_TOTAL_CAPACITY :{LTBLUE}- {CARGO} ({SHORTCARGO}) tron@534: SetDParam(0, i); // {CARGO} #1 tron@534: SetDParam(1, tot_cargo[i][0]); // {CARGO} #2 tron@534: SetDParam(2, i); // {SHORTCARGO} #1 tron@534: SetDParam(3, tot_cargo[i][1]); // {SHORTCARGO} #2 truelight@0: DrawString(x, y, STR_013F_TOTAL_CAPACITY, 0); truelight@0: } truelight@0: } while (++i != NUM_CARGO); 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@0: ShowQueryString(v->string_id, STR_8865_NAME_TRAIN, 31, 150, w->window_class, w->window_number); truelight@0: break; truelight@0: 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: truelight@0: DoCommandP(v->tile, v->index, mod, NULL, CMD_CHANGE_TRAIN_SERVICE_INT | CMD_MSG(STR_018A_CAN_T_CHANGE_SERVICING)); truelight@0: break; truelight@0: /* details buttons*/ truelight@0: case 9: // Cargo truelight@0: case 10: // Information truelight@0: case 11: // Capacities truelight@0: 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: truelight@0: case WE_4: truelight@0: if (FindWindowById(WC_VEHICLE_VIEW, w->window_number) == NULL) truelight@0: DeleteWindow(w); 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, w->window_number, 0, NULL, tron@1820: CMD_NAME_VEHICLE | CMD_MSG(STR_8866_CAN_T_NAME_TRAIN)); tron@1820: } truelight@0: } break; truelight@0: } truelight@0: } truelight@0: truelight@0: static const Widget _train_details_widgets[] = { truelight@867: { WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, truelight@867: { WWT_CAPTION, RESIZE_NONE, 14, 11, 329, 0, 13, STR_8802_DETAILS,STR_018C_WINDOW_TITLE_DRAG_THIS}, truelight@867: { WWT_PUSHTXTBTN, RESIZE_NONE, 14, 330, 369, 0, 13, STR_01AA_NAME, STR_8867_NAME_TRAIN}, truelight@867: { WWT_PANEL, RESIZE_NONE, 14, 0, 369, 14, 55, 0x0, STR_NULL}, darkvater@893: { WWT_MATRIX, RESIZE_NONE, 14, 0, 357, 56, 139, 0x601, STR_NULL}, darkvater@893: { WWT_SCROLLBAR, RESIZE_NONE, 14, 358, 369, 56, 139, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, truelight@867: { WWT_PUSHTXTBTN, RESIZE_NONE, 14, 0, 10, 140, 145, STR_0188, STR_884D_INCREASE_SERVICING_INTERVAL}, truelight@867: { WWT_PUSHTXTBTN, RESIZE_NONE, 14, 0, 10, 146, 151, STR_0189, STR_884E_DECREASE_SERVICING_INTERVAL}, truelight@867: { WWT_PANEL, RESIZE_NONE, 14, 11, 369, 140, 151, 0x0, STR_NULL}, truelight@867: { WWT_PUSHTXTBTN, RESIZE_NONE, 14, 0, 92, 152, 163, STR_013C_CARGO, STR_884F_SHOW_DETAILS_OF_CARGO_CARRIED}, truelight@867: { WWT_PUSHTXTBTN, RESIZE_NONE, 14, 93, 184, 152, 163, STR_013D_INFORMATION, STR_8850_SHOW_DETAILS_OF_TRAIN_VEHICLES}, truelight@867: { WWT_PUSHTXTBTN, RESIZE_NONE, 14, 185, 277, 152, 163, STR_013E_CAPACITIES, STR_8851_SHOW_CAPACITIES_OF_EACH}, truelight@867: { WWT_PUSHTXTBTN, RESIZE_NONE, 14, 278, 369, 152, 163, STR_013E_TOTAL_CARGO, STR_8852_SHOW_TOTAL_CARGO}, 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, truelight@0: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS, truelight@0: _train_details_widgets, truelight@0: TrainDetailsWndProc truelight@0: }; truelight@0: truelight@0: truelight@0: void ShowTrainDetailsWindow(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; truelight@0: WP(w,traindetails_d).tab = 0; truelight@0: } truelight@0: truelight@867: static const Widget _player_trains_widgets[] = { truelight@867: { WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, truelight@867: { WWT_CAPTION, RESIZE_RIGHT, 14, 11, 312, 0, 13, STR_881B_TRAINS, STR_018C_WINDOW_TITLE_DRAG_THIS}, truelight@867: { WWT_STICKYBOX, RESIZE_LR, 14, 313, 324, 0, 13, 0x0, STR_STICKY_BUTTON}, truelight@867: { WWT_PUSHTXTBTN, RESIZE_NONE, 14, 0, 80, 14, 25, SRT_SORT_BY, STR_SORT_ORDER_TIP}, truelight@867: { WWT_PANEL, RESIZE_NONE, 14, 81, 232, 14, 25, 0x0, STR_SORT_CRITERIA_TIP}, truelight@867: { WWT_CLOSEBOX, RESIZE_NONE, 14, 233, 243, 14, 25, STR_0225, STR_SORT_CRITERIA_TIP}, truelight@867: { WWT_PANEL, RESIZE_RIGHT, 14, 244, 324, 14, 25, 0x0, STR_NULL}, darkvater@893: { WWT_MATRIX, RESIZE_RB, 14, 0, 312, 26, 207, 0x701, STR_883D_TRAINS_CLICK_ON_TRAIN_FOR}, darkvater@893: { WWT_SCROLLBAR, RESIZE_LRB, 14, 313, 324, 26, 207, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, truelight@867: { WWT_PUSHTXTBTN, RESIZE_TB, 14, 0, 156, 208, 219, STR_8815_NEW_VEHICLES, STR_883E_BUILD_NEW_TRAINS_REQUIRES}, darkvater@893: { WWT_PUSHTXTBTN, RESIZE_TB, 14, 157, 312, 208, 219, STR_REPLACE_VEHICLES, STR_REPLACE_HELP}, darkvater@893: { WWT_PANEL, RESIZE_RTB, 14, 313, 312, 208, 219, 0x0, STR_NULL}, darkvater@893: { 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[] = { truelight@867: { WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, truelight@867: { WWT_CAPTION, RESIZE_RIGHT, 14, 11, 312, 0, 13, STR_881B_TRAINS, STR_018C_WINDOW_TITLE_DRAG_THIS}, truelight@867: { WWT_STICKYBOX, RESIZE_LR, 14, 313, 324, 0, 13, 0x0, STR_STICKY_BUTTON}, truelight@867: { WWT_PUSHTXTBTN, RESIZE_NONE, 14, 0, 80, 14, 25, SRT_SORT_BY, STR_SORT_ORDER_TIP}, truelight@867: { WWT_PANEL, RESIZE_NONE, 14, 81, 232, 14, 25, 0x0, STR_SORT_CRITERIA_TIP}, truelight@867: { WWT_CLOSEBOX, RESIZE_NONE, 14, 233, 243, 14, 25, STR_0225, STR_SORT_CRITERIA_TIP}, truelight@867: { WWT_PANEL, RESIZE_RIGHT, 14, 244, 324, 14, 25, 0x0, STR_NULL}, darkvater@893: { WWT_MATRIX, RESIZE_RB, 14, 0, 312, 26, 207, 0x701, STR_883D_TRAINS_CLICK_ON_TRAIN_FOR}, darkvater@893: { WWT_SCROLLBAR, RESIZE_LRB, 14, 313, 324, 26, 207, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, darkvater@893: { WWT_PANEL, RESIZE_RTB, 14, 0, 312, 208, 219, 0x0, STR_NULL}, darkvater@893: { WWT_RESIZEBOX, RESIZE_LRTB, 14, 313, 324, 208, 219, 0x0, STR_RESIZE_BUTTON}, tron@588: { WIDGETS_END}, tron@588: }; truelight@0: truelight@0: static void PlayerTrainsWndProc(Window *w, WindowEvent *e) truelight@0: { tron@588: int station = (int)w->window_number >> 16; tron@588: int owner = w->window_number & 0xff; tron@588: vehiclelist_d *vl = &WP(w, vehiclelist_d); tron@588: truelight@0: switch(e->event) { darkvater@164: case WE_PAINT: { tron@588: int x = 2; tron@588: int y = PLY_WND_PRC__OFFSET_TOP_WIDGET; tron@588: int max; tron@588: int i; darkvater@243: tron@588: BuildVehicleList(vl, VEH_Train, owner, station); tron@588: SortVehicleList(vl); darkvater@164: tron@588: SetVScrollCount(w, vl->list_length); tron@588: tron@588: // disable 'Sort By' tooltip on Unsorted sorting criteria tron@588: if (vl->sort_type == SORT_BY_UNSORTED) darkvater@757: w->disabled_state |= (1 << 3); truelight@193: truelight@0: /* draw the widgets */ truelight@0: { celestar@1962: const Player *p = GetPlayer(owner); tron@588: if (station == -1) { tron@588: /* Company Name -- (###) Trains */ tron@588: SetDParam(0, p->name_1); tron@588: SetDParam(1, p->name_2); tron@588: SetDParam(2, w->vscroll.count); truelight@867: w->widget[1].unkA = STR_881B_TRAINS; tron@588: } else { tron@588: /* Station Name -- (###) Trains */ tron@1294: SetDParam(0, station); tron@588: SetDParam(1, w->vscroll.count); truelight@867: w->widget[1].unkA = STR_SCHEDULED_TRAINS; tron@588: } truelight@0: DrawWindowWidgets(w); truelight@0: } darkvater@168: /* draw sorting criteria string */ tron@588: DrawString(85, 15, _vehicle_sort_listing[vl->sort_type], 0x10); tron@588: /* draw arrow pointing up/down for ascending/descending sorting */ darkvater@1246: DoDrawString(vl->flags & VL_DESC ? "\xAA" : "\xA0", 69, 15, 0x10); darkvater@164: tron@588: max = min(w->vscroll.pos + w->vscroll.cap, vl->list_length); tron@588: for (i = w->vscroll.pos; i < max; ++i) { truelight@919: Vehicle *v = GetVehicle(vl->sort_list[i].index); tron@588: StringID str; darkvater@164: tron@588: assert(v->type == VEH_Train && v->owner == owner); truelight@193: tron@588: DrawTrainImage( truelight@867: v, x + 21, y + 6 + _traininfo_vehicle_pitch, w->hscroll.cap, 0, INVALID_VEHICLE); tron@588: DrawVehicleProfitButton(v, x, y + 13); darkvater@164: tron@588: SetDParam(0, v->unitnumber); matthijs@1330: if (IsTileDepotType(v->tile, TRANSPORT_RAIL) && (v->vehstatus & VS_HIDDEN)) tron@588: str = STR_021F; tron@588: else tron@588: str = v->age > v->max_age - 366 ? STR_00E3 : STR_00E2; tron@588: DrawString(x, y + 2, str, 0); tron@588: tron@588: SetDParam(0, v->profit_this_year); tron@588: SetDParam(1, v->profit_last_year); tron@588: DrawString(x + 21, y + 18, STR_0198_PROFIT_THIS_YEAR_LAST_YEAR, 0); tron@588: tron@588: if (v->string_id != STR_SV_TRAIN_NAME) { tron@588: SetDParam(0, v->string_id); tron@588: DrawString(x + 21, y, STR_01AB, 0); truelight@0: } tron@588: tron@588: y += PLY_WND_PRC__SIZE_OF_ROW_SMALL; truelight@0: } tron@588: break; tron@588: } truelight@0: truelight@0: case WE_CLICK: { truelight@0: switch(e->click.widget) { darkvater@757: case 3: /* Flip sorting method ascending/descending */ tron@588: vl->flags ^= VL_DESC; tron@588: vl->flags |= VL_RESORT; darkvater@1246: _sorting.train.order = !!(vl->flags & VL_DESC); darkvater@164: SetWindowDirty(w); darkvater@164: break; tron@588: darkvater@757: case 4: case 5:/* Select sorting criteria dropdown menu */ bjarni@842: ShowDropDownMenu(w, _vehicle_sort_listing, vl->sort_type, 5, 0, 0); darkvater@164: return; tron@588: darkvater@757: case 7: { /* Matrix to show vehicles */ darkvater@174: uint32 id_v = (e->click.pt.y - PLY_WND_PRC__OFFSET_TOP_WIDGET) / PLY_WND_PRC__SIZE_OF_ROW_SMALL; truelight@193: darkvater@174: if (id_v >= w->vscroll.cap) { return;} // click out of bounds truelight@0: darkvater@164: id_v += w->vscroll.pos; truelight@0: darkvater@164: { darkvater@164: Vehicle *v; darkvater@164: tron@588: if (id_v >= vl->list_length) return; // click out of list bound darkvater@164: truelight@919: v = GetVehicle(vl->sort_list[id_v].index); darkvater@164: bjarni@1067: assert(v->type == VEH_Train && v->subtype == TS_Front_Engine && v->owner == owner); darkvater@164: darkvater@164: ShowTrainViewWindow(v); truelight@0: } truelight@0: } break; truelight@0: darkvater@757: case 9: { /* Build new Vehicle */ tron@1977: TileIndex tile; truelight@0: truelight@867: if (!IsWindowOfPrototype(w, _player_trains_widgets)) truelight@867: break; truelight@867: truelight@0: tile = _last_built_train_depot_tile; truelight@0: do { hackykid@1906: if (IsTileDepotType(tile, TRANSPORT_RAIL) && IsTileOwner(tile, _local_player)) { truelight@0: ShowTrainDepotWindow(tile); truelight@0: ShowBuildTrainWindow(tile); truelight@0: return; truelight@0: } truelight@193: truelight@0: tile = TILE_MASK(tile + 1); truelight@0: } while(tile != _last_built_train_depot_tile); truelight@193: truelight@0: ShowBuildTrainWindow(0); truelight@0: } break; bjarni@842: case 10: { truelight@886: if (!IsWindowOfPrototype(w, _player_trains_widgets)) truelight@886: break; truelight@886: bjarni@842: ShowReplaceVehicleWindow(VEH_Train); bjarni@842: break; bjarni@842: } bjarni@842: truelight@0: } truelight@0: } break; truelight@0: darkvater@164: case WE_DROPDOWN_SELECT: /* we have selected a dropdown item in the list */ tron@588: if (vl->sort_type != e->dropdown.index) { tron@588: // value has changed -> resort tron@588: vl->flags |= VL_RESORT; tron@588: vl->sort_type = e->dropdown.index; darkvater@1246: _sorting.train.criteria = vl->sort_type; darkvater@164: tron@588: // enable 'Sort By' if a sorter criteria is chosen tron@588: if (vl->sort_type != SORT_BY_UNSORTED) darkvater@1246: CLRBIT(w->disabled_state, 3); tron@588: } darkvater@164: SetWindowDirty(w); darkvater@164: break; tron@588: darkvater@164: case WE_CREATE: /* set up resort timer */ tron@588: vl->sort_list = NULL; darkvater@1246: vl->flags = VL_REBUILD | (_sorting.train.order << (VL_DESC - 1)); darkvater@1246: vl->sort_type = _sorting.train.criteria; tron@588: vl->resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS; darkvater@164: break; tron@588: tron@767: case WE_DESTROY: tron@767: free(vl->sort_list); tron@767: break; tron@767: darkvater@164: case WE_TICK: /* resort the list every 20 seconds orso (10 days) */ tron@588: if (--vl->resort_timer == 0) { tron@588: DEBUG(misc, 1) ("Periodic resort trains list player %d station %d", tron@588: owner, station); tron@588: vl->resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS; tron@588: vl->flags |= VL_RESORT; tron@588: SetWindowDirty(w); darkvater@164: } darkvater@164: break; truelight@867: truelight@867: case WE_RESIZE: truelight@867: /* Update the scroll + matrix */ truelight@867: w->hscroll.cap += e->sizing.diff.x / 29; truelight@867: w->vscroll.cap += e->sizing.diff.y / PLY_WND_PRC__SIZE_OF_ROW_SMALL; truelight@867: w->widget[7].unkA = (w->vscroll.cap << 8) + 1; truelight@867: break; truelight@0: } truelight@0: } 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, truelight@0: PlayerTrainsWndProc 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, truelight@0: PlayerTrainsWndProc truelight@0: }; truelight@0: tron@588: void ShowPlayerTrains(int player, int station) truelight@0: { truelight@0: Window *w; truelight@0: darkvater@164: if (player == _local_player) { tron@588: w = AllocateWindowDescFront(&_player_trains_desc, (station << 16) | player); darkvater@164: } else { tron@588: w = AllocateWindowDescFront(&_other_player_trains_desc, (station << 16) | player); truelight@0: } truelight@0: if (w) { Darkvater@1402: w->caption_color = player; truelight@867: w->hscroll.cap = 10; darkvater@164: w->vscroll.cap = 7; // maximum number of vehicles shown truelight@867: w->widget[7].unkA = (w->vscroll.cap << 8) + 1; truelight@867: w->resize.step_height = PLY_WND_PRC__SIZE_OF_ROW_SMALL; truelight@867: w->resize.step_width = 29; truelight@867: w->resize.height = 220 - (PLY_WND_PRC__SIZE_OF_ROW_SMALL * 3); /* Minimum of 4 vehicles */ truelight@0: } truelight@0: }