2004-08-09 17:04:08 +00:00
|
|
|
#include "stdafx.h"
|
|
|
|
#include "ttd.h"
|
2005-02-05 15:58:59 +00:00
|
|
|
#include "debug.h"
|
2004-11-25 10:47:30 +00:00
|
|
|
#include "table/strings.h"
|
2004-12-15 22:18:54 +00:00
|
|
|
#include "map.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "window.h"
|
|
|
|
#include "gui.h"
|
|
|
|
#include "gfx.h"
|
|
|
|
#include "vehicle.h"
|
|
|
|
#include "viewport.h"
|
|
|
|
#include "station.h"
|
|
|
|
#include "command.h"
|
|
|
|
#include "player.h"
|
|
|
|
#include "engine.h"
|
2004-12-10 18:16:08 +00:00
|
|
|
#include "vehicle_gui.h"
|
2005-02-06 10:18:47 +00:00
|
|
|
#include "depot.h"
|
2004-11-14 23:36:19 +00:00
|
|
|
|
|
|
|
int _traininfo_vehicle_pitch = 0;
|
|
|
|
|
2005-01-02 17:23:04 +00:00
|
|
|
void Set_DPARAM_Train_Engine_Build_Window(uint16 engine_number)
|
|
|
|
{
|
|
|
|
const RailVehicleInfo *rvi = RailVehInfo(engine_number);
|
|
|
|
Engine *e;
|
|
|
|
int multihead = (rvi->flags&RVI_MULTIHEAD?1:0);
|
|
|
|
YearMonthDay ymd;
|
|
|
|
|
|
|
|
|
|
|
|
SetDParam(0, rvi->base_cost * (_price.build_railvehicle >> 3) >> 5);
|
|
|
|
SetDParam(2, rvi->max_speed * 10 >> 4);
|
|
|
|
SetDParam(3, rvi->power << multihead);
|
|
|
|
SetDParam(1, rvi->weight << multihead);
|
|
|
|
SetDParam(4, (rvi->running_cost_base * _price.running_rail[rvi->engclass] >> 8) << multihead);
|
|
|
|
|
|
|
|
SetDParam(5, STR_8838_N_A);
|
|
|
|
if (rvi->capacity != 0) {
|
|
|
|
SetDParam(6, rvi->capacity << multihead);
|
|
|
|
SetDParam(5, _cargoc.names_long_p[rvi->cargo_type]);
|
|
|
|
}
|
|
|
|
|
|
|
|
e = &_engines[engine_number];
|
|
|
|
|
|
|
|
SetDParam(8, e->lifelength);
|
|
|
|
SetDParam(9, e->reliability * 100 >> 16);
|
|
|
|
ConvertDayToYMD(&ymd, e->intro_date);
|
|
|
|
SetDParam(7, ymd.year + 1920);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Set_DPARAM_Train_Car_Build_Window(Window *w, uint16 engine_number)
|
|
|
|
{
|
|
|
|
const RailVehicleInfo *rvi = RailVehInfo(engine_number);
|
2005-01-03 19:45:18 +00:00
|
|
|
|
2005-01-02 17:23:04 +00:00
|
|
|
SetDParam(0, DoCommandByTile(w->window_number, engine_number, 0, DC_QUERY_COST, CMD_BUILD_RAIL_VEHICLE) );
|
|
|
|
SetDParam(4, rvi->capacity);
|
|
|
|
SetDParam(1, rvi->weight);
|
|
|
|
SetDParam(3, _cargoc.names_long_p[rvi->cargo_type]);
|
|
|
|
SetDParam(2, (_cargoc.weights[rvi->cargo_type] * rvi->capacity >> 4) + rvi->weight);
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2004-12-04 17:54:56 +00:00
|
|
|
void CcBuildWagon(bool success, uint tile, uint32 p1, uint32 p2)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
Vehicle *v,*found;
|
|
|
|
|
|
|
|
if (!success)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// find a locomotive in the depot.
|
|
|
|
found = NULL;
|
|
|
|
FOR_ALL_VEHICLES(v) {
|
2005-01-19 19:15:03 +00:00
|
|
|
if (v->type == VEH_Train && v->subtype == TS_Front_Engine &&
|
2004-08-09 17:04:08 +00:00
|
|
|
v->tile == tile &&
|
|
|
|
v->u.rail.track == 0x80) {
|
|
|
|
if (found != NULL) // must be exactly one.
|
|
|
|
return;
|
|
|
|
found = v;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// if we found a loco,
|
|
|
|
if (found != NULL) {
|
|
|
|
found = GetLastVehicleInChain(found);
|
|
|
|
// put the new wagon at the end of the loco.
|
|
|
|
DoCommandP(0, _new_wagon_id | (found->index<<16), 0, NULL, CMD_MOVE_RAIL_VEHICLE);
|
2004-12-10 18:16:08 +00:00
|
|
|
RebuildVehicleLists();
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-12-04 17:54:56 +00:00
|
|
|
void CcBuildLoco(bool success, uint tile, uint32 p1, uint32 p2)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
Vehicle *v;
|
|
|
|
|
|
|
|
if (!success)
|
|
|
|
return;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2005-01-06 22:31:58 +00:00
|
|
|
v = GetVehicle(_new_train_id);
|
2004-08-09 17:04:08 +00:00
|
|
|
if (tile == _backup_orders_tile) {
|
|
|
|
_backup_orders_tile = 0;
|
|
|
|
RestoreVehicleOrders(v, _backup_orders_data);
|
|
|
|
}
|
|
|
|
ShowTrainViewWindow(v);
|
|
|
|
}
|
|
|
|
|
2004-11-29 19:26:24 +00:00
|
|
|
static void engine_drawing_loop(int *x, int *y, int *pos, int *sel,
|
2005-01-03 19:45:18 +00:00
|
|
|
int *selected_id, byte railtype, byte show_max, bool is_engine)
|
2004-11-29 19:26:24 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < NUM_TRAIN_ENGINES; i++) {
|
|
|
|
const Engine *e = DEREF_ENGINE(i);
|
2004-12-04 00:34:20 +00:00
|
|
|
const RailVehicleInfo *rvi = RailVehInfo(i);
|
2004-11-29 19:26:24 +00:00
|
|
|
|
|
|
|
if (e->railtype != railtype || !(rvi->flags & RVI_WAGON) != is_engine ||
|
|
|
|
!HASBIT(e->player_avail, _local_player))
|
|
|
|
continue;
|
|
|
|
|
2005-01-03 19:45:18 +00:00
|
|
|
if (*sel == 0)
|
|
|
|
*selected_id = i;
|
2004-11-29 19:26:24 +00:00
|
|
|
|
2005-01-03 19:45:18 +00:00
|
|
|
if (IS_INT_INSIDE(--*pos, -show_max, 0)) {
|
|
|
|
DrawString(*x + 59, *y + 2, GetCustomEngineName(i), *sel == 0 ? 0xC : 0x10);
|
2004-11-29 19:26:24 +00:00
|
|
|
DrawTrainEngine(*x + 29, *y + 6 + _traininfo_vehicle_pitch, i,
|
|
|
|
SPRITE_PALETTE(PLAYER_SPRITE_COLOR(_local_player)));
|
|
|
|
*y += 14;
|
|
|
|
}
|
|
|
|
--*sel;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
static void NewRailVehicleWndProc(Window *w, WindowEvent *e)
|
|
|
|
{
|
|
|
|
switch(e->event) {
|
|
|
|
case WE_PAINT:
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
if (w->window_number == 0)
|
|
|
|
SETBIT(w->disabled_state, 5);
|
|
|
|
|
|
|
|
{
|
|
|
|
int count = 0;
|
2004-11-19 19:13:32 +00:00
|
|
|
byte railtype = WP(w,buildtrain_d).railtype;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < NUM_TRAIN_ENGINES; i++) {
|
2004-11-29 19:26:24 +00:00
|
|
|
const Engine *e = DEREF_ENGINE(i);
|
2004-11-19 19:13:32 +00:00
|
|
|
if (e->railtype == railtype
|
|
|
|
&& HASBIT(e->player_avail, _local_player))
|
2004-08-09 17:04:08 +00:00
|
|
|
count++;
|
2004-11-19 19:13:32 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
SetVScrollCount(w, count);
|
|
|
|
}
|
|
|
|
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, WP(w,buildtrain_d).railtype + STR_881C_NEW_RAIL_VEHICLES);
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawWindowWidgets(w);
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2004-11-19 19:13:32 +00:00
|
|
|
byte railtype = WP(w,buildtrain_d).railtype;
|
2004-08-09 17:04:08 +00:00
|
|
|
int sel = WP(w,buildtrain_d).sel_index;
|
|
|
|
int pos = w->vscroll.pos;
|
|
|
|
int x = 1;
|
|
|
|
int y = 15;
|
|
|
|
int selected_id = -1;
|
2004-11-19 19:13:32 +00:00
|
|
|
|
|
|
|
/* Ensure that custom engines which substituted wagons
|
2004-11-29 19:26:24 +00:00
|
|
|
* are sorted correctly.
|
|
|
|
* XXX - DO NOT EVER DO THIS EVER AGAIN! GRRR hacking in wagons as
|
|
|
|
* engines to get more types.. Stays here until we have our own format
|
|
|
|
* then it is exit!!! */
|
2005-01-03 19:45:18 +00:00
|
|
|
engine_drawing_loop(&x, &y, &pos, &sel, &selected_id, railtype, w->vscroll.cap, true); // True engines
|
|
|
|
engine_drawing_loop(&x, &y, &pos, &sel, &selected_id, railtype, w->vscroll.cap, false); // Feeble wagons
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
WP(w,buildtrain_d).sel_engine = selected_id;
|
|
|
|
|
|
|
|
if (selected_id != -1) {
|
2004-12-04 00:34:20 +00:00
|
|
|
const RailVehicleInfo *rvi = RailVehInfo(selected_id);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
if (!(rvi->flags & RVI_WAGON)) {
|
|
|
|
/* it's an engine */
|
2005-01-02 17:23:04 +00:00
|
|
|
Set_DPARAM_Train_Engine_Build_Window(selected_id);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-01-03 19:45:18 +00:00
|
|
|
DrawString(2, w->widget[4].top + 1, STR_8817_COST_WEIGHT_T_SPEED_POWER, 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
} else {
|
|
|
|
/* it's a wagon */
|
2005-01-02 17:23:04 +00:00
|
|
|
Set_DPARAM_Train_Car_Build_Window(w, selected_id);
|
2005-01-03 19:45:18 +00:00
|
|
|
|
|
|
|
DrawString(2, w->widget[4].top + 1, STR_8821_COST_WEIGHT_T_T_CAPACITY, 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WE_CLICK: {
|
|
|
|
switch(e->click.widget) {
|
|
|
|
case 2: {
|
|
|
|
uint i = (e->click.pt.y - 14) / 14;
|
2005-01-03 19:45:18 +00:00
|
|
|
if (i < w->vscroll.cap) {
|
2004-08-09 17:04:08 +00:00
|
|
|
WP(w,buildtrain_d).sel_index = i + w->vscroll.pos;
|
|
|
|
SetWindowDirty(w);
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case 5: {
|
|
|
|
int sel_eng;
|
|
|
|
sel_eng = WP(w,buildtrain_d).sel_engine;
|
|
|
|
if (sel_eng != -1)
|
2004-12-04 07:41:37 +00:00
|
|
|
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));
|
2004-08-09 17:04:08 +00:00
|
|
|
} break;
|
2005-01-10 14:24:40 +00:00
|
|
|
case 6: { /* rename */
|
|
|
|
int sel_eng = WP(w,buildtrain_d).sel_engine;
|
|
|
|
if (sel_eng != -1) {
|
|
|
|
WP(w,buildtrain_d).rename_engine = sel_eng;
|
|
|
|
ShowQueryString(GetCustomEngineName(sel_eng),
|
|
|
|
STR_886A_RENAME_TRAIN_VEHICLE_TYPE, 31, 160, w->window_class, w->window_number);
|
|
|
|
}
|
|
|
|
} break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case WE_4:
|
|
|
|
if (w->window_number != 0 && !FindWindowById(WC_VEHICLE_DEPOT, w->window_number)) {
|
|
|
|
DeleteWindow(w);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WE_ON_EDIT_TEXT: {
|
2005-05-15 18:50:55 +00:00
|
|
|
if (e->edittext.str[0] != '\0') {
|
|
|
|
_cmd_text = e->edittext.str;
|
|
|
|
DoCommandP(0, WP(w,buildtrain_d).rename_engine, 0, NULL,
|
|
|
|
CMD_RENAME_ENGINE | CMD_MSG(STR_886B_CAN_T_RENAME_TRAIN_VEHICLE));
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
} break;
|
2005-01-03 19:45:18 +00:00
|
|
|
|
|
|
|
case WE_RESIZE: {
|
|
|
|
if (e->sizing.diff.y == 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
w->vscroll.cap += e->sizing.diff.y / 14;
|
|
|
|
w->widget[2].unkA = (w->vscroll.cap << 8) + 1;
|
|
|
|
} break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
static const Widget _new_rail_vehicle_widgets[] = {
|
2005-01-03 19:45:18 +00:00
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
2005-01-15 01:52:23 +00:00
|
|
|
{ WWT_CAPTION, RESIZE_NONE, 14, 11, 227, 0, 13, STR_JUST_STRING, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
2005-01-04 21:28:09 +00:00
|
|
|
{ WWT_MATRIX, RESIZE_BOTTOM, 14, 0, 215, 14, 125, 0x801, STR_8843_TRAIN_VEHICLE_SELECTION},
|
|
|
|
{ WWT_SCROLLBAR, RESIZE_BOTTOM, 14, 216, 227, 14, 125, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST},
|
2005-01-03 19:45:18 +00:00
|
|
|
{ WWT_PANEL, RESIZE_TB, 14, 0, 227, 126, 187, 0x0, STR_NULL},
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 0, 107, 188, 199, STR_881F_BUILD_VEHICLE, STR_8844_BUILD_THE_HIGHLIGHTED_TRAIN},
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 108, 215, 188, 199, STR_8820_RENAME, STR_8845_RENAME_TRAIN_VEHICLE_TYPE},
|
2005-01-04 21:28:09 +00:00
|
|
|
{ WWT_RESIZEBOX, RESIZE_TB, 14, 216, 227, 188, 199, 0x0, STR_RESIZE_BUTTON},
|
2004-09-07 21:48:09 +00:00
|
|
|
{ WIDGETS_END},
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const WindowDesc _new_rail_vehicle_desc = {
|
|
|
|
-1, -1, 228, 200,
|
|
|
|
WC_BUILD_VEHICLE,0,
|
2005-01-03 19:45:18 +00:00
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE,
|
2004-08-09 17:04:08 +00:00
|
|
|
_new_rail_vehicle_widgets,
|
|
|
|
NewRailVehicleWndProc
|
|
|
|
};
|
|
|
|
|
|
|
|
static void ShowBuildTrainWindow(uint tile)
|
|
|
|
{
|
|
|
|
Window *w;
|
|
|
|
|
|
|
|
DeleteWindowById(WC_BUILD_VEHICLE, tile);
|
|
|
|
|
|
|
|
w = AllocateWindowDesc(&_new_rail_vehicle_desc);
|
|
|
|
w->window_number = tile;
|
|
|
|
w->vscroll.cap = 8;
|
2005-01-03 19:45:18 +00:00
|
|
|
w->widget[2].unkA = (w->vscroll.cap << 8) + 1;
|
|
|
|
|
|
|
|
w->resize.step_height = 14;
|
|
|
|
w->resize.height = w->height - 14 * 4; /* Minimum of 4 vehicles in the display */
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
if (tile != 0) {
|
|
|
|
w->caption_color = _map_owner[tile];
|
|
|
|
WP(w,buildtrain_d).railtype = _map3_lo[tile] & 0xF;
|
|
|
|
} else {
|
|
|
|
w->caption_color = _local_player;
|
|
|
|
WP(w,buildtrain_d).railtype = DEREF_PLAYER(_local_player)->max_railtype - 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-05-11 16:17:03 +00:00
|
|
|
static void DrawTrainImage(const Vehicle *v, int x, int y, int count, int skip, VehicleID selection)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
do {
|
|
|
|
if (--skip < 0) {
|
|
|
|
int image = GetTrainImage(v, 6);
|
|
|
|
uint32 ormod = SPRITE_PALETTE(PLAYER_SPRITE_COLOR(v->owner));
|
|
|
|
if (v->vehstatus & VS_CRASHED) ormod = 0x3248000;
|
2004-11-14 23:36:19 +00:00
|
|
|
DrawSprite(image | ormod, x+14, y+6+_traininfo_vehicle_pitch);
|
2004-08-09 17:04:08 +00:00
|
|
|
if (v->index == selection) DrawFrameRect(x-1, y-1, x+28, y+12, 15, 0x10);
|
|
|
|
x += 29;
|
|
|
|
count--;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(v = v->next))
|
|
|
|
break;
|
|
|
|
} while (count);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void DrawTrainDepotWindow(Window *w)
|
|
|
|
{
|
|
|
|
uint tile;
|
|
|
|
Vehicle *v, *u;
|
|
|
|
int num,x,y,i, hnum;
|
2005-02-06 10:18:47 +00:00
|
|
|
Depot *depot;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
tile = w->window_number;
|
|
|
|
|
|
|
|
/* setup disabled buttons */
|
2005-01-11 00:24:27 +00:00
|
|
|
w->disabled_state = (_map_owner[tile]==_local_player) ? 0 : ((1<<4)|(1<<5)|(1<<8));
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
/* determine amount of items for scroller */
|
2005-01-03 19:45:18 +00:00
|
|
|
num = 0;
|
|
|
|
hnum = 1;
|
2004-08-09 17:04:08 +00:00
|
|
|
FOR_ALL_VEHICLES(v) {
|
|
|
|
if (v->type == VEH_Train &&
|
2005-01-19 19:15:03 +00:00
|
|
|
(v->subtype == TS_Front_Engine || v->subtype == TS_Free_Car) &&
|
2004-08-09 17:04:08 +00:00
|
|
|
v->tile == (TileIndex)tile &&
|
|
|
|
v->u.rail.track == 0x80) {
|
|
|
|
num++;
|
|
|
|
// determine number of items in the X direction.
|
2005-01-19 19:15:03 +00:00
|
|
|
if (v->subtype == TS_Front_Engine) {
|
2005-01-03 19:45:18 +00:00
|
|
|
i = 0;
|
2004-08-09 17:04:08 +00:00
|
|
|
u = v;
|
|
|
|
do i++; while ( (u=u->next) != NULL);
|
|
|
|
if (i > hnum) hnum = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-01-06 17:40:57 +00:00
|
|
|
|
|
|
|
/* Always have 1 empty row, so people can change the setting of the train */
|
|
|
|
num++;
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
SetVScrollCount(w, num);
|
|
|
|
SetHScrollCount(w, hnum);
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
/* locate the depot struct */
|
2005-02-06 10:18:47 +00:00
|
|
|
depot = GetDepotByTile(tile);
|
|
|
|
assert(depot != NULL);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-02-06 10:18:47 +00:00
|
|
|
SetDParam(0, depot->town_index);
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawWindowWidgets(w);
|
|
|
|
|
|
|
|
x = 2;
|
|
|
|
y = 15;
|
|
|
|
num = w->vscroll.pos;
|
|
|
|
|
|
|
|
// draw all trains
|
|
|
|
FOR_ALL_VEHICLES(v) {
|
|
|
|
if (v->type == VEH_Train &&
|
2005-01-19 19:15:03 +00:00
|
|
|
v->subtype == TS_Front_Engine &&
|
2004-08-09 17:04:08 +00:00
|
|
|
v->tile == (TileIndex)tile &&
|
2004-09-10 19:02:27 +00:00
|
|
|
v->u.rail.track == 0x80 &&
|
2005-01-03 19:45:18 +00:00
|
|
|
--num < 0 && num >= -w->vscroll.cap) {
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-01-03 19:45:18 +00:00
|
|
|
DrawTrainImage(v, x+21, y, w->hscroll.cap, w->hscroll.pos, WP(w,traindepot_d).sel);
|
2004-08-11 22:07:08 +00:00
|
|
|
/* Draw the train number */
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, v->unitnumber);
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawString(x, y, (v->max_age - 366 < v->age) ? STR_00E3 : STR_00E2, 0);
|
2005-01-15 08:58:31 +00:00
|
|
|
|
2005-01-13 17:23:24 +00:00
|
|
|
/*Draw the train counter */
|
|
|
|
i = 0;
|
|
|
|
u = v;
|
|
|
|
do i++; while ( (u=u->next) != NULL); //Determine length of train
|
|
|
|
SetDParam(0, i); //Set the counter
|
|
|
|
i = (w->hscroll.cap * 29) + (x + 26); //Calculate position of text according to window size
|
|
|
|
DrawStringCentered(i, y+5, STR_TINY_BLACK, 0); //Draw the counter
|
2005-01-15 08:58:31 +00:00
|
|
|
|
2004-08-11 22:07:08 +00:00
|
|
|
/* Draw the pretty flag */
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawSprite(v->vehstatus&VS_STOPPED ? 0xC12 : 0xC13, x+15, y);
|
|
|
|
|
|
|
|
y += 14;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// draw all remaining vehicles
|
|
|
|
FOR_ALL_VEHICLES(v) {
|
|
|
|
if (v->type == VEH_Train &&
|
2005-01-19 19:15:03 +00:00
|
|
|
v->subtype == TS_Free_Car &&
|
2004-08-09 17:04:08 +00:00
|
|
|
v->tile == (TileIndex)tile &&
|
2004-09-10 19:02:27 +00:00
|
|
|
v->u.rail.track == 0x80 &&
|
2005-01-03 19:45:18 +00:00
|
|
|
--num < 0 && num >= -w->vscroll.cap) {
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-01-03 19:45:18 +00:00
|
|
|
DrawTrainImage(v, x+50, y, w->hscroll.cap - 1, 0, WP(w,traindepot_d).sel);
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawString(x, y+2, STR_8816, 0);
|
2005-01-15 08:58:31 +00:00
|
|
|
|
2005-01-13 17:23:24 +00:00
|
|
|
/*Draw the train counter */
|
|
|
|
i = 0;
|
|
|
|
u = v;
|
|
|
|
do i++; while ( (u=u->next) != NULL); //Determine length of train
|
|
|
|
SetDParam(0, i); //Set the counter
|
|
|
|
i = (w->hscroll.cap * 29) + (x + 26); //Calculate position of text according to window size
|
|
|
|
DrawStringCentered(i, y+5, STR_TINY_BLACK, 0); //Draw the counter
|
2004-08-09 17:04:08 +00:00
|
|
|
y += 14;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct GetDepotVehiclePtData {
|
|
|
|
Vehicle *head;
|
|
|
|
Vehicle *wagon;
|
|
|
|
} GetDepotVehiclePtData;
|
|
|
|
|
|
|
|
static int GetVehicleFromTrainDepotWndPt(Window *w, int x, int y, GetDepotVehiclePtData *d)
|
|
|
|
{
|
|
|
|
int area_x;
|
|
|
|
int row;
|
|
|
|
Vehicle *v;
|
|
|
|
|
|
|
|
x = x - 23;
|
|
|
|
if (x < 0) {
|
|
|
|
area_x = (x >= -10) ? -2 : -1;
|
|
|
|
} else {
|
|
|
|
area_x = x / 29;
|
|
|
|
}
|
|
|
|
|
|
|
|
row = (y - 14) / 14;
|
2005-01-06 17:40:57 +00:00
|
|
|
if ( (uint) row >= w->vscroll.cap)
|
2004-08-09 17:04:08 +00:00
|
|
|
return 1; /* means err */
|
|
|
|
|
|
|
|
row += w->vscroll.pos;
|
|
|
|
|
|
|
|
/* go through all the locomotives */
|
|
|
|
FOR_ALL_VEHICLES(v) {
|
|
|
|
if (v->type == VEH_Train &&
|
2005-01-19 19:15:03 +00:00
|
|
|
v->subtype == TS_Front_Engine &&
|
2004-08-09 17:04:08 +00:00
|
|
|
v->tile == w->window_number &&
|
|
|
|
v->u.rail.track == 0x80 &&
|
|
|
|
--row < 0) {
|
2004-11-27 19:53:53 +00:00
|
|
|
if (area_x >= 0) area_x += w->hscroll.pos;
|
2004-08-09 17:04:08 +00:00
|
|
|
goto found_it;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
area_x--; /* free wagons don't have an initial loco. */
|
|
|
|
|
|
|
|
/* and then the list of free wagons */
|
|
|
|
FOR_ALL_VEHICLES(v) {
|
|
|
|
if (v->type == VEH_Train &&
|
2005-01-19 19:15:03 +00:00
|
|
|
v->subtype == TS_Free_Car &&
|
2004-08-09 17:04:08 +00:00
|
|
|
v->tile == w->window_number &&
|
|
|
|
v->u.rail.track == 0x80 &&
|
|
|
|
--row < 0)
|
|
|
|
goto found_it;
|
|
|
|
}
|
|
|
|
|
|
|
|
d->head = NULL;
|
|
|
|
d->wagon = NULL;
|
|
|
|
|
|
|
|
/* didn't find anything, get out */
|
|
|
|
return 0;
|
|
|
|
|
2004-09-10 19:02:27 +00:00
|
|
|
found_it:
|
2004-08-09 17:04:08 +00:00
|
|
|
d->head = d->wagon = v;
|
|
|
|
|
|
|
|
/* either pressed the flag or the number, but only when it's a loco */
|
2005-01-19 19:15:03 +00:00
|
|
|
if (area_x < 0 && v->subtype == TS_Front_Engine)
|
2004-08-09 17:04:08 +00:00
|
|
|
return area_x;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
/* find the vehicle in this row that was clicked */
|
|
|
|
while (--area_x >= 0) {
|
|
|
|
v = v->next;
|
|
|
|
if (v == NULL) break;
|
|
|
|
}
|
|
|
|
|
2004-09-10 19:02:27 +00:00
|
|
|
d->wagon = v;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void TrainDepotMoveVehicle(Vehicle *wagon, int sel, Vehicle *head)
|
|
|
|
{
|
|
|
|
Vehicle *v;
|
|
|
|
|
2005-01-06 22:31:58 +00:00
|
|
|
v = GetVehicle(sel);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-01-19 19:15:03 +00:00
|
|
|
if (/*v->subtype == TS_Front_Engine ||*/ v == wagon)
|
2004-08-09 17:04:08 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (wagon == NULL) {
|
|
|
|
if (head != NULL)
|
|
|
|
wagon = GetLastVehicleInChain(head);
|
|
|
|
} else {
|
|
|
|
wagon = GetPrevVehicleInChain(wagon);
|
|
|
|
if (wagon == NULL)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wagon == v)
|
|
|
|
return;
|
|
|
|
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void TrainDepotClickTrain(Window *w, int x, int y)
|
|
|
|
{
|
|
|
|
GetDepotVehiclePtData gdvp;
|
|
|
|
int mode, sel;
|
|
|
|
Vehicle *v;
|
|
|
|
|
|
|
|
mode = GetVehicleFromTrainDepotWndPt(w, x, y, &gdvp);
|
2004-08-10 16:54:34 +00:00
|
|
|
|
|
|
|
// share / copy orders
|
2004-08-09 17:04:08 +00:00
|
|
|
if (_thd.place_mode && mode <= 0) { _place_clicked_vehicle = gdvp.head; return; }
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
v = gdvp.wagon;
|
|
|
|
|
|
|
|
switch(mode) {
|
2004-08-10 16:54:34 +00:00
|
|
|
case 0: // start dragging of vehicle
|
2004-08-09 17:04:08 +00:00
|
|
|
sel = (int16)WP(w,traindepot_d).sel;
|
|
|
|
if (sel != -1) {
|
|
|
|
WP(w,traindepot_d).sel = INVALID_VEHICLE;
|
|
|
|
TrainDepotMoveVehicle(v, sel, gdvp.head);
|
|
|
|
} else if (v != NULL) {
|
|
|
|
WP(w,traindepot_d).sel = v->index;
|
|
|
|
SetObjectToPlaceWnd( SPRITE_PALETTE(PLAYER_SPRITE_COLOR(v->owner)) + GetTrainImage(v, 6), 4, w);
|
|
|
|
SetWindowDirty(w);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2004-08-10 16:54:34 +00:00
|
|
|
case -1: // show info window
|
2004-08-09 17:04:08 +00:00
|
|
|
ShowTrainViewWindow(v);
|
|
|
|
break;
|
|
|
|
|
2004-08-10 16:54:34 +00:00
|
|
|
case -2: // click start/stop flag
|
2004-08-09 17:04:08 +00:00
|
|
|
DoCommandP(v->tile, v->index, 0, NULL, CMD_START_STOP_TRAIN | CMD_MSG(STR_883B_CAN_T_STOP_START_TRAIN));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void TrainDepotWndProc(Window *w, WindowEvent *e)
|
|
|
|
{
|
|
|
|
switch(e->event) {
|
|
|
|
case WE_PAINT:
|
|
|
|
DrawTrainDepotWindow(w);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WE_CLICK: {
|
|
|
|
switch(e->click.widget) {
|
2005-01-03 19:45:18 +00:00
|
|
|
case 8:
|
2004-08-09 17:04:08 +00:00
|
|
|
ShowBuildTrainWindow(w->window_number);
|
|
|
|
break;
|
2005-01-03 19:45:18 +00:00
|
|
|
case 9:
|
2004-08-09 17:04:08 +00:00
|
|
|
ScrollMainWindowToTile(w->window_number);
|
|
|
|
break;
|
2005-01-11 00:24:27 +00:00
|
|
|
case 6:
|
2004-08-09 17:04:08 +00:00
|
|
|
TrainDepotClickTrain(w, e->click.pt.x, e->click.pt.y);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case WE_DESTROY:
|
|
|
|
DeleteWindowById(WC_BUILD_VEHICLE, w->window_number);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WE_DRAGDROP: {
|
|
|
|
switch(e->click.widget) {
|
2005-01-11 00:24:27 +00:00
|
|
|
case 4: case 5: {
|
2004-08-09 17:04:08 +00:00
|
|
|
Vehicle *v;
|
|
|
|
int sell_cmd;
|
|
|
|
|
|
|
|
/* sell vehicle */
|
|
|
|
if (w->disabled_state & (1 << e->click.widget))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (WP(w,traindepot_d).sel == INVALID_VEHICLE)
|
|
|
|
return;
|
|
|
|
|
2005-01-06 22:31:58 +00:00
|
|
|
v = GetVehicle(WP(w,traindepot_d).sel);
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
WP(w,traindepot_d).sel = INVALID_VEHICLE;
|
|
|
|
SetWindowDirty(w);
|
|
|
|
|
|
|
|
HandleButtonClick(w, e->click.widget);
|
|
|
|
|
2005-01-11 00:24:27 +00:00
|
|
|
sell_cmd = (e->click.widget == 5 || _ctrl_pressed) ? 1 : 0;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-01-19 19:15:03 +00:00
|
|
|
if (v->subtype != TS_Front_Engine) {
|
2004-08-09 17:04:08 +00:00
|
|
|
DoCommandP(v->tile, v->index, sell_cmd, NULL, CMD_SELL_RAIL_WAGON | CMD_MSG(STR_8839_CAN_T_SELL_RAILROAD_VEHICLE));
|
|
|
|
} else {
|
|
|
|
_backup_orders_tile = v->tile;
|
|
|
|
BackupVehicleOrders(v, _backup_orders_data);
|
|
|
|
if (!DoCommandP(v->tile, v->index, sell_cmd, NULL, CMD_SELL_RAIL_WAGON | CMD_MSG(STR_8839_CAN_T_SELL_RAILROAD_VEHICLE)))
|
|
|
|
_backup_orders_tile = 0;
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
|
2005-01-11 00:24:27 +00:00
|
|
|
case 6: {
|
2004-08-09 17:04:08 +00:00
|
|
|
GetDepotVehiclePtData gdvp;
|
|
|
|
VehicleID sel = WP(w,traindepot_d).sel;
|
|
|
|
|
|
|
|
WP(w,traindepot_d).sel = INVALID_VEHICLE;
|
|
|
|
SetWindowDirty(w);
|
|
|
|
|
2004-09-10 19:02:27 +00:00
|
|
|
if (GetVehicleFromTrainDepotWndPt(w, e->dragdrop.pt.x, e->dragdrop.pt.y, &gdvp) == 0 &&
|
2004-08-09 17:04:08 +00:00
|
|
|
sel != INVALID_VEHICLE) {
|
|
|
|
if (gdvp.wagon == NULL || gdvp.wagon->index != sel) {
|
|
|
|
TrainDepotMoveVehicle(gdvp.wagon, sel, gdvp.head);
|
2005-01-19 19:15:03 +00:00
|
|
|
} else if (gdvp.head != NULL && gdvp.head->subtype == TS_Front_Engine) {
|
2004-08-09 17:04:08 +00:00
|
|
|
ShowTrainViewWindow(gdvp.head);
|
|
|
|
}
|
2004-09-10 19:02:27 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
} break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
WP(w,traindepot_d).sel = INVALID_VEHICLE;
|
|
|
|
SetWindowDirty(w);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} break;
|
2005-01-03 19:45:18 +00:00
|
|
|
case WE_RESIZE: {
|
|
|
|
/* Update the scroll + matrix */
|
|
|
|
w->vscroll.cap += e->sizing.diff.y / 14;
|
|
|
|
w->hscroll.cap += e->sizing.diff.x / 29;
|
2005-01-11 00:24:27 +00:00
|
|
|
w->widget[6].unkA = (w->vscroll.cap << 8) + 1;
|
2005-01-03 19:45:18 +00:00
|
|
|
} break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const Widget _train_depot_widgets[] = {
|
2005-01-11 00:24:27 +00:00
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
2005-01-13 17:23:24 +00:00
|
|
|
{ WWT_CAPTION, RESIZE_RIGHT, 14, 11, 348, 0, 13, STR_8800_TRAIN_DEPOT, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
|
|
|
{ WWT_STICKYBOX, RESIZE_LR, 14, 349, 360, 0, 13, 0x0, STR_STICKY_BUTTON},
|
2005-01-11 00:24:27 +00:00
|
|
|
|
2005-01-13 17:23:24 +00:00
|
|
|
{ WWT_PANEL, RESIZE_LRB, 14, 326, 348, 14, 13, 0x0, STR_NULL},
|
|
|
|
{ WWT_PANEL, RESIZE_LRTB, 14, 326, 348, 14, 54, 0x2A9, STR_8841_DRAG_TRAIN_VEHICLE_TO_HERE},
|
|
|
|
{ WWT_PANEL, RESIZE_LRTB, 14, 326, 348, 55, 109, 0x2BF, STR_DRAG_WHOLE_TRAIN_TO_SELL_TIP},
|
2005-01-06 17:40:57 +00:00
|
|
|
|
2005-01-13 17:23:24 +00:00
|
|
|
{ WWT_MATRIX, RESIZE_RB, 14, 0, 325, 14, 97, 0x601, STR_883F_TRAINS_CLICK_ON_TRAIN_FOR},
|
|
|
|
{ WWT_SCROLLBAR, RESIZE_LRB, 14, 349, 360, 14, 109, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST},
|
2005-01-06 17:40:57 +00:00
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 0, 167, 110, 121, STR_8815_NEW_VEHICLES, STR_8840_BUILD_NEW_TRAIN_VEHICLE},
|
2005-01-13 17:23:24 +00:00
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 168, 348, 110, 121, STR_00E4_LOCATION, STR_8842_CENTER_MAIN_VIEW_ON_TRAIN},
|
2005-04-07 01:02:15 +00:00
|
|
|
{ WWT_HSCROLLBAR, RESIZE_RTB, 14, 0, 325, 98, 109, 0x0, STR_HSCROLL_BAR_SCROLLS_LIST},
|
2005-01-13 17:23:24 +00:00
|
|
|
{ WWT_PANEL, RESIZE_RTB, 14, 349, 348, 110, 121, 0x0, STR_NULL},
|
|
|
|
{ WWT_RESIZEBOX, RESIZE_LRTB, 14, 349, 360, 110, 121, 0x0, STR_RESIZE_BUTTON},
|
2004-09-07 21:48:09 +00:00
|
|
|
{ WIDGETS_END},
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const WindowDesc _train_depot_desc = {
|
2005-01-13 17:23:24 +00:00
|
|
|
-1, -1, 361, 122,
|
2004-08-09 17:04:08 +00:00
|
|
|
WC_VEHICLE_DEPOT,0,
|
2005-01-03 19:45:18 +00:00
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
|
2004-08-09 17:04:08 +00:00
|
|
|
_train_depot_widgets,
|
|
|
|
TrainDepotWndProc
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void ShowTrainDepotWindow(uint tile)
|
|
|
|
{
|
|
|
|
Window *w;
|
|
|
|
|
|
|
|
w = AllocateWindowDescFront(&_train_depot_desc, tile);
|
|
|
|
if (w) {
|
|
|
|
w->caption_color = _map_owner[w->window_number];
|
|
|
|
w->vscroll.cap = 6;
|
2005-01-03 19:45:18 +00:00
|
|
|
w->hscroll.cap = 10;
|
|
|
|
w->resize.step_width = 29;
|
|
|
|
w->resize.step_height = 14;
|
2004-08-09 17:04:08 +00:00
|
|
|
WP(w,traindepot_d).sel = INVALID_VEHICLE;
|
|
|
|
_backup_orders_tile = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void RailVehicleRefitWndProc(Window *w, WindowEvent *e)
|
|
|
|
{
|
2005-05-14 12:36:16 +00:00
|
|
|
switch (e->event) {
|
2004-08-09 17:04:08 +00:00
|
|
|
case WE_PAINT: {
|
2005-05-14 12:36:16 +00:00
|
|
|
const Vehicle *v = GetVehicle(w->window_number);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, v->string_id);
|
|
|
|
SetDParam(1, v->unitnumber);
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawWindowWidgets(w);
|
|
|
|
|
|
|
|
DrawString(1, 15, STR_983F_SELECT_CARGO_TYPE_TO_CARRY, 0);
|
|
|
|
|
2005-05-14 12:36:16 +00:00
|
|
|
/* TODO: Support for custom GRFSpecial-specified refitting! --pasky */
|
|
|
|
WP(w,refit_d).cargo = DrawVehicleRefitWindow(v, WP(w, refit_d).sel);
|
2004-11-13 21:42:35 +00:00
|
|
|
|
2005-05-14 12:36:16 +00:00
|
|
|
if (WP(w,refit_d).cargo != CT_INVALID) {
|
|
|
|
int32 cost = DoCommandByTile(v->tile, v->index, WP(w,refit_d).cargo, DC_QUERY_COST, CMD_REFIT_RAIL_VEHICLE);
|
|
|
|
if (!CmdFailed(cost)) {
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(2, cost);
|
2005-05-14 12:36:16 +00:00
|
|
|
SetDParam(0, _cargoc.names_long_p[WP(w,refit_d).cargo]);
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(1, _returned_refit_amount);
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawString(1, 137, STR_9840_NEW_CAPACITY_COST_OF_REFIT, 0);
|
|
|
|
}
|
|
|
|
}
|
2005-05-14 12:36:16 +00:00
|
|
|
} break;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
case WE_CLICK:
|
|
|
|
switch(e->click.widget) {
|
|
|
|
case 2: { /* listbox */
|
|
|
|
int y = e->click.pt.y - 25;
|
|
|
|
if (y >= 0) {
|
|
|
|
WP(w,refit_d).sel = y / 10;
|
|
|
|
SetWindowDirty(w);
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case 4: /* refit button */
|
2005-05-14 12:36:16 +00:00
|
|
|
if (WP(w,refit_d).cargo != CT_INVALID) {
|
|
|
|
const Vehicle *v = GetVehicle(w->window_number);
|
2004-08-09 17:04:08 +00:00
|
|
|
if (DoCommandP(v->tile, v->index, WP(w,refit_d).cargo, NULL, CMD_REFIT_RAIL_VEHICLE | CMD_MSG(STR_RAIL_CAN_T_REFIT_VEHICLE)))
|
|
|
|
DeleteWindow(w);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static const Widget _rail_vehicle_refit_widgets[] = {
|
2005-01-03 19:45:18 +00:00
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
|
|
|
{ WWT_CAPTION, RESIZE_NONE, 14, 11, 239, 0, 13, STR_983B_REFIT, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
|
|
|
{ WWT_IMGBTN, RESIZE_NONE, 14, 0, 239, 14, 135, 0x0, STR_RAIL_SELECT_TYPE_OF_CARGO_FOR},
|
|
|
|
{ WWT_IMGBTN, RESIZE_NONE, 14, 0, 239, 136, 157, 0x0, STR_NULL},
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 0, 239, 158, 169, STR_RAIL_REFIT_VEHICLE,STR_RAIL_REFIT_TO_CARRY_HIGHLIGHTED},
|
2004-09-07 21:48:09 +00:00
|
|
|
{ WIDGETS_END},
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const WindowDesc _rail_vehicle_refit_desc = {
|
|
|
|
-1,-1, 240, 170,
|
|
|
|
WC_VEHICLE_REFIT,WC_VEHICLE_VIEW,
|
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
|
|
|
|
_rail_vehicle_refit_widgets,
|
|
|
|
RailVehicleRefitWndProc,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void ShowRailVehicleRefitWindow(Vehicle *v)
|
|
|
|
{
|
|
|
|
Window *w;
|
|
|
|
DeleteWindowById(WC_VEHICLE_REFIT, v->index);
|
|
|
|
_alloc_wnd_parent_num = v->index;
|
|
|
|
w = AllocateWindowDesc(&_rail_vehicle_refit_desc);
|
|
|
|
w->window_number = v->index;
|
|
|
|
w->caption_color = v->owner;
|
|
|
|
WP(w,refit_d).sel = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Widget _train_view_widgets[] = {
|
2005-03-11 13:17:39 +00:00
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW },
|
|
|
|
{ WWT_CAPTION, RESIZE_RIGHT, 14, 11, 237, 0, 13, STR_882E, STR_018C_WINDOW_TITLE_DRAG_THIS },
|
|
|
|
{ WWT_STICKYBOX, RESIZE_LR, 14, 238, 249, 0, 13, 0x0, STR_STICKY_BUTTON },
|
|
|
|
{ WWT_PANEL, RESIZE_RB, 14, 0, 231, 14, 121, 0x0, STR_NULL },
|
|
|
|
{ WWT_6, RESIZE_RB, 14, 2, 229, 16, 119, 0x0, STR_NULL },
|
|
|
|
{ WWT_PUSHIMGBTN, RESIZE_RTB, 14, 0, 237, 122, 133, 0x0, STR_8846_CURRENT_TRAIN_ACTION_CLICK },
|
|
|
|
{ WWT_PUSHIMGBTN, RESIZE_LR, 14, 232, 249, 14, 31, 0x2AB, STR_8848_CENTER_MAIN_VIEW_ON_TRAIN },
|
|
|
|
{ WWT_PUSHIMGBTN, RESIZE_LR, 14, 232, 249, 32, 49, 0x2AD, STR_8849_SEND_TRAIN_TO_DEPOT },
|
|
|
|
{ WWT_PUSHIMGBTN, RESIZE_LR, 14, 232, 249, 50, 67, 0x2B1, STR_884A_FORCE_TRAIN_TO_PROCEED },
|
|
|
|
{ WWT_PUSHIMGBTN, RESIZE_LR, 14, 232, 249, 68, 85, 0x2CB, STR_884B_REVERSE_DIRECTION_OF_TRAIN },
|
|
|
|
{ WWT_PUSHIMGBTN, RESIZE_LR, 14, 232, 249, 86, 103, 0x2B2, STR_8847_SHOW_TRAIN_S_ORDERS },
|
|
|
|
{ WWT_PUSHIMGBTN, RESIZE_LR, 14, 232, 249, 104, 121, 0x2B3, STR_884C_SHOW_TRAIN_DETAILS },
|
|
|
|
{ WWT_PUSHIMGBTN, RESIZE_LR, 14, 232, 249, 68, 85, 0x2B4, STR_RAIL_REFIT_VEHICLE_TO_CARRY },
|
|
|
|
{ WWT_PANEL, RESIZE_LRB, 14, 232, 249, 122, 121, 0x0, STR_NULL },
|
|
|
|
{ WWT_RESIZEBOX, RESIZE_LRTB, 14, 238, 249, 122, 133, 0x0, STR_NULL },
|
|
|
|
{ WIDGETS_END }
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void TrainViewWndProc(Window *w, WindowEvent *e)
|
|
|
|
{
|
2005-05-14 12:36:16 +00:00
|
|
|
switch (e->event) {
|
2004-08-09 17:04:08 +00:00
|
|
|
case WE_PAINT: {
|
2005-05-14 12:36:16 +00:00
|
|
|
const Vehicle *v, *u;
|
2004-08-09 17:04:08 +00:00
|
|
|
StringID str;
|
|
|
|
|
2005-01-06 22:31:58 +00:00
|
|
|
v = GetVehicle(w->window_number);
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-12-21 23:27:58 +00:00
|
|
|
w->disabled_state = (v->owner == _local_player) ? 0 : 0x380;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2005-02-20 07:47:42 +00:00
|
|
|
SETBIT(w->disabled_state, 12);
|
|
|
|
|
2005-05-14 12:36:16 +00:00
|
|
|
/* See if any vehicle can be refitted */
|
2005-02-20 07:47:42 +00:00
|
|
|
for ( u = v; u != NULL; u = u->next) {
|
2005-05-14 12:36:16 +00:00
|
|
|
if (_engine_refit_masks[u->engine_type] != 0 ||
|
|
|
|
(!(RailVehInfo(v->engine_type)->flags & RVI_WAGON) && v->cargo_cap != 0)) {
|
2005-02-20 07:47:42 +00:00
|
|
|
CLRBIT(w->disabled_state, 12);
|
|
|
|
/* We have a refittable carriage, bail out */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
/* draw widgets & caption */
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, v->string_id);
|
|
|
|
SetDParam(1, v->unitnumber);
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawWindowWidgets(w);
|
|
|
|
|
|
|
|
/* draw the flag */
|
2005-03-11 13:17:39 +00:00
|
|
|
DrawSprite(v->vehstatus & VS_STOPPED ? 0xC12 : 0xC13, 2,
|
|
|
|
w->widget[5].top + 1);
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
if (v->u.rail.crash_anim_pos != 0) {
|
|
|
|
str = STR_8863_CRASHED;
|
|
|
|
} else if (v->breakdown_ctr == 1) {
|
|
|
|
str = STR_885C_BROKEN_DOWN;
|
|
|
|
} else if (v->vehstatus & VS_STOPPED) {
|
|
|
|
if (v->u.rail.last_speed == 0) {
|
|
|
|
str = STR_8861_STOPPED;
|
|
|
|
} else {
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, v->u.rail.last_speed * 10 >> 4);
|
2004-08-09 17:04:08 +00:00
|
|
|
str = STR_TRAIN_STOPPING + _patches.vehicle_speed;
|
|
|
|
}
|
|
|
|
} else {
|
2004-12-05 12:43:04 +00:00
|
|
|
switch (v->current_order.type) {
|
2004-08-09 17:04:08 +00:00
|
|
|
case OT_GOTO_STATION: {
|
|
|
|
str = STR_HEADING_FOR_STATION + _patches.vehicle_speed;
|
2004-12-05 12:43:04 +00:00
|
|
|
SetDParam(0, v->current_order.station);
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(1, v->u.rail.last_speed * 10 >> 4);
|
2004-08-09 17:04:08 +00:00
|
|
|
} break;
|
|
|
|
|
|
|
|
case OT_GOTO_DEPOT: {
|
2005-02-06 10:18:47 +00:00
|
|
|
Depot *dep = GetDepot(v->current_order.station);
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, dep->town_index);
|
2004-08-09 17:04:08 +00:00
|
|
|
str = STR_HEADING_FOR_TRAIN_DEPOT + _patches.vehicle_speed;
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(1, v->u.rail.last_speed * 10 >> 4);
|
2004-08-09 17:04:08 +00:00
|
|
|
} break;
|
|
|
|
|
|
|
|
case OT_LOADING:
|
|
|
|
case OT_LEAVESTATION:
|
|
|
|
str = STR_882F_LOADING_UNLOADING;
|
|
|
|
break;
|
|
|
|
|
2004-11-14 13:07:07 +00:00
|
|
|
case OT_GOTO_WAYPOINT: {
|
2004-12-05 12:43:04 +00:00
|
|
|
SetDParam(0, v->current_order.station);
|
2004-11-14 13:07:07 +00:00
|
|
|
str = STR_HEADING_FOR_WAYPOINT + _patches.vehicle_speed;
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(1, v->u.rail.last_speed * 10 >> 4);
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
|
|
|
}
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
default:
|
|
|
|
if (v->num_orders == 0) {
|
|
|
|
str = STR_NO_ORDERS + _patches.vehicle_speed;
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, v->u.rail.last_speed * 10 >> 4);
|
2004-08-09 17:04:08 +00:00
|
|
|
} else
|
|
|
|
str = STR_EMPTY;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-03-11 13:17:39 +00:00
|
|
|
DrawStringCentered((w->widget[5].right - w->widget[5].left) / 2,
|
|
|
|
w->widget[5].top + 1, str, 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawWindowViewport(w);
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case WE_CLICK: {
|
|
|
|
int wid = e->click.widget;
|
2005-01-06 22:31:58 +00:00
|
|
|
Vehicle *v = GetVehicle(w->window_number);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
switch(wid) {
|
2004-12-21 23:27:58 +00:00
|
|
|
case 5: /* start/stop train */
|
2004-09-10 19:02:27 +00:00
|
|
|
DoCommandP(v->tile, v->index, 0, NULL, CMD_START_STOP_TRAIN | CMD_MSG(STR_883B_CAN_T_STOP_START_TRAIN));
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
2004-12-21 23:27:58 +00:00
|
|
|
case 6: /* center main view */
|
2004-08-09 17:04:08 +00:00
|
|
|
ScrollMainWindowTo(v->x_pos, v->y_pos);
|
|
|
|
break;
|
2004-12-21 23:27:58 +00:00
|
|
|
case 7: /* goto depot */
|
2004-12-12 15:43:55 +00:00
|
|
|
/* TrainGotoDepot has a nice randomizer in the pathfinder, which causes desyncs... */
|
|
|
|
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));
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
2004-12-21 23:27:58 +00:00
|
|
|
case 8: /* force proceed */
|
2004-09-10 19:02:27 +00:00
|
|
|
DoCommandP(v->tile, v->index, 0, NULL, CMD_FORCE_TRAIN_PROCEED | CMD_MSG(STR_8862_CAN_T_MAKE_TRAIN_PASS_SIGNAL));
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
2004-12-21 23:27:58 +00:00
|
|
|
case 9: /* reverse direction */
|
2004-09-10 19:02:27 +00:00
|
|
|
DoCommandP(v->tile, v->index, 0, NULL, CMD_REVERSE_TRAIN_DIRECTION | CMD_MSG(STR_8869_CAN_T_REVERSE_DIRECTION));
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
2004-12-21 23:27:58 +00:00
|
|
|
case 10: /* show train orders */
|
2004-08-09 17:04:08 +00:00
|
|
|
ShowOrdersWindow(v);
|
|
|
|
break;
|
2004-12-21 23:27:58 +00:00
|
|
|
case 11: /* show train details */
|
2004-08-09 17:04:08 +00:00
|
|
|
ShowTrainDetailsWindow(v);
|
|
|
|
break;
|
2004-12-21 23:27:58 +00:00
|
|
|
case 12:
|
2004-08-09 17:04:08 +00:00
|
|
|
ShowRailVehicleRefitWindow(v);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
|
2005-03-11 13:17:39 +00:00
|
|
|
case WE_RESIZE:
|
|
|
|
w->viewport->width += e->sizing.diff.x;
|
|
|
|
w->viewport->height += e->sizing.diff.y;
|
|
|
|
w->viewport->virtual_width += e->sizing.diff.x;
|
|
|
|
w->viewport->virtual_height += e->sizing.diff.y;
|
|
|
|
break;
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
case WE_DESTROY:
|
2004-11-06 09:24:28 +00:00
|
|
|
DeleteWindowById(WC_VEHICLE_REFIT, w->window_number);
|
2004-08-09 17:04:08 +00:00
|
|
|
DeleteWindowById(WC_VEHICLE_ORDERS, w->window_number);
|
|
|
|
DeleteWindowById(WC_VEHICLE_DETAILS, w->window_number);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WE_MOUSELOOP: {
|
|
|
|
Vehicle *v;
|
|
|
|
uint32 h;
|
|
|
|
|
2005-01-06 22:31:58 +00:00
|
|
|
v = GetVehicle(w->window_number);
|
2004-08-09 17:04:08 +00:00
|
|
|
assert(v->type == VEH_Train);
|
2005-02-06 10:18:47 +00:00
|
|
|
h = CheckTrainStoppedInDepot(v) >= 0 ? (1 << 9) : (1 << 12);
|
2004-08-09 17:04:08 +00:00
|
|
|
if (h != w->hidden_state) {
|
|
|
|
w->hidden_state = h;
|
|
|
|
SetWindowDirty(w);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const WindowDesc _train_view_desc = {
|
|
|
|
-1,-1, 250, 134,
|
|
|
|
WC_VEHICLE_VIEW,0,
|
2005-03-11 13:17:39 +00:00
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
|
2004-08-09 17:04:08 +00:00
|
|
|
_train_view_widgets,
|
|
|
|
TrainViewWndProc
|
|
|
|
};
|
|
|
|
|
|
|
|
void ShowTrainViewWindow(Vehicle *v)
|
|
|
|
{
|
|
|
|
Window *w;
|
|
|
|
|
|
|
|
w = AllocateWindowDescFront(&_train_view_desc,v->index);
|
|
|
|
if (w) {
|
|
|
|
w->caption_color = v->owner;
|
|
|
|
AssignWindowViewport(w, 3, 17, 0xE2, 0x66, w->window_number | (1 << 31), 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-05-11 16:17:03 +00:00
|
|
|
static void TrainDetailsCargoTab(const Vehicle *v, int x, int y)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
int num;
|
|
|
|
StringID str;
|
|
|
|
|
|
|
|
if (v->cargo_cap != 0) {
|
|
|
|
num = v->cargo_count;
|
|
|
|
str = STR_8812_EMPTY;
|
|
|
|
if (num != 0) {
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, v->cargo_type);
|
|
|
|
SetDParam(1, num);
|
|
|
|
SetDParam(2, v->cargo_source);
|
2004-08-09 17:04:08 +00:00
|
|
|
str = STR_8813_FROM;
|
|
|
|
}
|
|
|
|
DrawString(x, y, str, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-05-11 16:17:03 +00:00
|
|
|
static void TrainDetailsInfoTab(const Vehicle *v, int x, int y)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2004-12-04 07:41:37 +00:00
|
|
|
const RailVehicleInfo *rvi = RailVehInfo(v->engine_type);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
if (!(rvi->flags & RVI_WAGON)) {
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, GetCustomEngineName(v->engine_type));
|
|
|
|
SetDParam(1, v->build_year + 1920);
|
|
|
|
SetDParam(2, v->value);
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawString(x, y, STR_882C_BUILT_VALUE, 0x10);
|
|
|
|
} else {
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, GetCustomEngineName(v->engine_type));
|
|
|
|
SetDParam(1, v->value);
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawString(x, y, STR_882D_VALUE, 0x10);
|
2004-09-10 19:02:27 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-05-11 16:17:03 +00:00
|
|
|
static void TrainDetailsCapacityTab(const Vehicle *v, int x, int y)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
if (v->cargo_cap != 0) {
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(1, v->cargo_cap);
|
|
|
|
SetDParam(0, _cargoc.names_long_p[v->cargo_type]);
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawString(x, y, STR_013F_CAPACITY, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-05-11 16:17:03 +00:00
|
|
|
typedef void TrainDetailsDrawerProc(const Vehicle *v, int x, int y);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
static TrainDetailsDrawerProc * const _train_details_drawer_proc[3] = {
|
|
|
|
TrainDetailsCargoTab,
|
|
|
|
TrainDetailsInfoTab,
|
|
|
|
TrainDetailsCapacityTab,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void DrawTrainDetailsWindow(Window *w)
|
|
|
|
{
|
2005-05-11 16:17:03 +00:00
|
|
|
const Vehicle *v, *u;
|
2004-08-09 17:04:08 +00:00
|
|
|
uint16 tot_cargo[NUM_CARGO][2]; // count total cargo ([0]-actual cargo, [1]-total cargo)
|
2005-01-26 12:51:04 +00:00
|
|
|
int max_speed = 0xFFFF;
|
2004-08-09 17:04:08 +00:00
|
|
|
int i,num,x,y,sel;
|
|
|
|
StringID str;
|
|
|
|
byte det_tab = WP(w, traindetails_d).tab;
|
|
|
|
|
|
|
|
/* Count number of vehicles */
|
|
|
|
num = 0;
|
|
|
|
|
|
|
|
// det_tab == 3 <-- Total Cargo tab
|
|
|
|
if (det_tab == 3) // reset tot_cargo array to 0 values
|
|
|
|
memset(tot_cargo, 0, sizeof(tot_cargo));
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2005-01-06 22:31:58 +00:00
|
|
|
u = v = GetVehicle(w->window_number);
|
2004-08-09 17:04:08 +00:00
|
|
|
do {
|
|
|
|
if (det_tab != 3)
|
|
|
|
num++;
|
|
|
|
else {
|
|
|
|
tot_cargo[u->cargo_type][0] += u->cargo_count;
|
|
|
|
tot_cargo[u->cargo_type][1] += u->cargo_cap;
|
|
|
|
}
|
2005-01-26 12:51:04 +00:00
|
|
|
if (RailVehInfo(u->engine_type)->max_speed != 0)
|
|
|
|
max_speed = min(max_speed, RailVehInfo(u->engine_type)->max_speed);
|
2004-08-09 17:04:08 +00:00
|
|
|
} while ( (u = u->next) != NULL);
|
|
|
|
|
|
|
|
/* set scroll-amount seperately from counting, as to not
|
|
|
|
compute num double for more carriages of the same type
|
|
|
|
*/
|
|
|
|
if (det_tab == 3) {
|
|
|
|
for (i = 0; i != NUM_CARGO; i++) {
|
|
|
|
if (tot_cargo[i][1] > 0) // only count carriages that the train has
|
|
|
|
num++;
|
|
|
|
}
|
|
|
|
num++; // needs one more because first line is description string
|
|
|
|
}
|
|
|
|
|
|
|
|
SetVScrollCount(w, num);
|
|
|
|
|
|
|
|
w->disabled_state = 1 << (det_tab + 9);
|
|
|
|
if (v->owner != _local_player)
|
|
|
|
w->disabled_state |= (1 << 2);
|
|
|
|
|
2004-09-04 13:06:09 +00:00
|
|
|
if (!_patches.servint_trains) // disable service-scroller when interval is set to disabled
|
|
|
|
w->disabled_state |= (1 << 6) | (1 << 7);
|
|
|
|
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, v->string_id);
|
|
|
|
SetDParam(1, v->unitnumber);
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawWindowWidgets(w);
|
|
|
|
|
|
|
|
num = v->age / 366;
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(1, num);
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
x = 2;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
str = STR_0199_YEAR;
|
|
|
|
if (num != 1) {
|
|
|
|
str += STR_019A_YEARS - STR_0199_YEAR;
|
|
|
|
if ((uint16)(v->max_age - 366) < v->age)
|
|
|
|
str += STR_019B_YEARS - STR_019A_YEARS;
|
|
|
|
}
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, str);
|
|
|
|
SetDParam(2, v->max_age / 366);
|
|
|
|
SetDParam(3, GetTrainRunningCost(v) >> 8);
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawString(x, 15, STR_885D_AGE_RUNNING_COST_YR, 0);
|
|
|
|
|
2005-01-26 12:51:04 +00:00
|
|
|
SetDParam(2, max_speed * 10 >> 4);
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(1, v->u.rail.cached_power);
|
|
|
|
SetDParam(0, v->u.rail.cached_weight);
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawString(x, 25, STR_885E_WEIGHT_T_POWER_HP_MAX_SPEED, 0);
|
|
|
|
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, v->profit_this_year);
|
|
|
|
SetDParam(1, v->profit_last_year);
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawString(x, 35, STR_885F_PROFIT_THIS_YEAR_LAST_YEAR, 0);
|
|
|
|
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, 100 * (v->reliability>>8) >> 8);
|
|
|
|
SetDParam(1, v->breakdowns_since_last_service);
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawString(x, 45, STR_8860_RELIABILITY_BREAKDOWNS, 0);
|
|
|
|
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, v->service_interval);
|
|
|
|
SetDParam(1, v->date_of_last_service);
|
2004-09-04 13:06:09 +00:00
|
|
|
DrawString(x + 11, 141, _patches.servint_ispercent?STR_SERVICING_INTERVAL_PERCENT:STR_883C_SERVICING_INTERVAL_DAYS, 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
x = 1;
|
|
|
|
y = 57;
|
|
|
|
sel = w->vscroll.pos;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
// draw the first 3 details tabs
|
|
|
|
if (det_tab != 3) {
|
|
|
|
for(;;) {
|
|
|
|
if (--sel < 0 && sel >= -6) {
|
|
|
|
DrawTrainImage(v, x, y, 1, 0, INVALID_VEHICLE);
|
|
|
|
_train_details_drawer_proc[WP(w,traindetails_d).tab](v, x + 30, y + 2);
|
|
|
|
y += 14;
|
|
|
|
}
|
|
|
|
if ( (v=v->next) == NULL)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else { // draw total cargo tab
|
|
|
|
i = 0;
|
|
|
|
DrawString(x, y + 2, STR_013F_TOTAL_CAPACITY_TEXT, 0);
|
|
|
|
do {
|
|
|
|
if (tot_cargo[i][1] > 0 && --sel < 0 && sel >= -5) {
|
|
|
|
y += 14;
|
|
|
|
// STR_013F_TOTAL_CAPACITY :{LTBLUE}- {CARGO} ({SHORTCARGO})
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, i); // {CARGO} #1
|
|
|
|
SetDParam(1, tot_cargo[i][0]); // {CARGO} #2
|
|
|
|
SetDParam(2, i); // {SHORTCARGO} #1
|
|
|
|
SetDParam(3, tot_cargo[i][1]); // {SHORTCARGO} #2
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawString(x, y, STR_013F_TOTAL_CAPACITY, 0);
|
|
|
|
}
|
|
|
|
} while (++i != NUM_CARGO);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void TrainDetailsWndProc(Window *w, WindowEvent *e)
|
|
|
|
{
|
2005-05-11 16:17:03 +00:00
|
|
|
switch (e->event) {
|
2004-08-09 17:04:08 +00:00
|
|
|
case WE_PAINT:
|
|
|
|
DrawTrainDetailsWindow(w);
|
|
|
|
break;
|
|
|
|
case WE_CLICK: {
|
|
|
|
int mod;
|
2005-05-11 16:17:03 +00:00
|
|
|
const Vehicle *v;
|
|
|
|
switch (e->click.widget) {
|
2004-08-09 17:04:08 +00:00
|
|
|
case 2: /* name train */
|
2005-01-06 22:31:58 +00:00
|
|
|
v = GetVehicle(w->window_number);
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, v->unitnumber);
|
2004-08-09 17:04:08 +00:00
|
|
|
ShowQueryString(v->string_id, STR_8865_NAME_TRAIN, 31, 150, w->window_class, w->window_number);
|
|
|
|
break;
|
|
|
|
case 6: /* inc serv interval */
|
2004-09-04 13:06:09 +00:00
|
|
|
mod = _ctrl_pressed? 5 : 10;
|
2004-08-09 17:04:08 +00:00
|
|
|
goto do_change_service_int;
|
|
|
|
|
|
|
|
case 7: /* dec serv interval */
|
2004-09-04 13:06:09 +00:00
|
|
|
mod = _ctrl_pressed? -5 : -10;
|
2004-08-09 17:04:08 +00:00
|
|
|
do_change_service_int:
|
2005-01-06 22:31:58 +00:00
|
|
|
v = GetVehicle(w->window_number);
|
2004-09-04 13:06:09 +00:00
|
|
|
|
2005-05-11 16:17:03 +00:00
|
|
|
mod = GetServiceIntervalClamped(mod + v->service_interval);
|
|
|
|
if (mod == v->service_interval) return;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
DoCommandP(v->tile, v->index, mod, NULL, CMD_CHANGE_TRAIN_SERVICE_INT | CMD_MSG(STR_018A_CAN_T_CHANGE_SERVICING));
|
|
|
|
break;
|
|
|
|
/* details buttons*/
|
|
|
|
case 9: // Cargo
|
|
|
|
case 10: // Information
|
|
|
|
case 11: // Capacities
|
|
|
|
case 12: // Total cargo
|
|
|
|
CLRBIT(w->disabled_state, 9);
|
|
|
|
CLRBIT(w->disabled_state, 10);
|
|
|
|
CLRBIT(w->disabled_state, 11);
|
|
|
|
CLRBIT(w->disabled_state, 12);
|
|
|
|
SETBIT(w->disabled_state, e->click.widget);
|
|
|
|
WP(w,traindetails_d).tab = e->click.widget - 9;
|
|
|
|
SetWindowDirty(w);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
|
|
|
|
case WE_4:
|
|
|
|
if (FindWindowById(WC_VEHICLE_VIEW, w->window_number) == NULL)
|
|
|
|
DeleteWindow(w);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WE_ON_EDIT_TEXT: {
|
2005-05-15 18:50:55 +00:00
|
|
|
if (e->edittext.str[0] != '\0') {
|
|
|
|
_cmd_text = e->edittext.str;
|
|
|
|
DoCommandP(0, w->window_number, 0, NULL,
|
|
|
|
CMD_NAME_VEHICLE | CMD_MSG(STR_8866_CAN_T_NAME_TRAIN));
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const Widget _train_details_widgets[] = {
|
2005-01-03 19:45:18 +00:00
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
|
|
|
{ WWT_CAPTION, RESIZE_NONE, 14, 11, 329, 0, 13, STR_8802_DETAILS,STR_018C_WINDOW_TITLE_DRAG_THIS},
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 330, 369, 0, 13, STR_01AA_NAME, STR_8867_NAME_TRAIN},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 0, 369, 14, 55, 0x0, STR_NULL},
|
2005-01-04 21:28:09 +00:00
|
|
|
{ WWT_MATRIX, RESIZE_NONE, 14, 0, 357, 56, 139, 0x601, STR_NULL},
|
|
|
|
{ WWT_SCROLLBAR, RESIZE_NONE, 14, 358, 369, 56, 139, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST},
|
2005-01-03 19:45:18 +00:00
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 0, 10, 140, 145, STR_0188, STR_884D_INCREASE_SERVICING_INTERVAL},
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 0, 10, 146, 151, STR_0189, STR_884E_DECREASE_SERVICING_INTERVAL},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 11, 369, 140, 151, 0x0, STR_NULL},
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 0, 92, 152, 163, STR_013C_CARGO, STR_884F_SHOW_DETAILS_OF_CARGO_CARRIED},
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 93, 184, 152, 163, STR_013D_INFORMATION, STR_8850_SHOW_DETAILS_OF_TRAIN_VEHICLES},
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 185, 277, 152, 163, STR_013E_CAPACITIES, STR_8851_SHOW_CAPACITIES_OF_EACH},
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 278, 369, 152, 163, STR_013E_TOTAL_CARGO, STR_8852_SHOW_TOTAL_CARGO},
|
2004-09-07 21:48:09 +00:00
|
|
|
{ WIDGETS_END},
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static const WindowDesc _train_details_desc = {
|
|
|
|
-1,-1, 370, 164,
|
|
|
|
WC_VEHICLE_DETAILS,WC_VEHICLE_VIEW,
|
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
|
|
|
|
_train_details_widgets,
|
|
|
|
TrainDetailsWndProc
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void ShowTrainDetailsWindow(Vehicle *v)
|
|
|
|
{
|
|
|
|
Window *w;
|
|
|
|
VehicleID veh = v->index;
|
|
|
|
|
|
|
|
DeleteWindowById(WC_VEHICLE_ORDERS, veh);
|
|
|
|
DeleteWindowById(WC_VEHICLE_DETAILS, veh);
|
|
|
|
|
2004-09-10 19:02:27 +00:00
|
|
|
_alloc_wnd_parent_num = veh;
|
2004-08-09 17:04:08 +00:00
|
|
|
w = AllocateWindowDesc(&_train_details_desc);
|
|
|
|
|
|
|
|
w->window_number = veh;
|
|
|
|
w->caption_color = v->owner;
|
|
|
|
w->vscroll.cap = 6;
|
|
|
|
WP(w,traindetails_d).tab = 0;
|
|
|
|
}
|
|
|
|
|
2005-01-03 19:45:18 +00:00
|
|
|
static const Widget _player_trains_widgets[] = {
|
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
|
|
|
{ WWT_CAPTION, RESIZE_RIGHT, 14, 11, 312, 0, 13, STR_881B_TRAINS, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
|
|
|
{ WWT_STICKYBOX, RESIZE_LR, 14, 313, 324, 0, 13, 0x0, STR_STICKY_BUTTON},
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 0, 80, 14, 25, SRT_SORT_BY, STR_SORT_ORDER_TIP},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 81, 232, 14, 25, 0x0, STR_SORT_CRITERIA_TIP},
|
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 233, 243, 14, 25, STR_0225, STR_SORT_CRITERIA_TIP},
|
|
|
|
{ WWT_PANEL, RESIZE_RIGHT, 14, 244, 324, 14, 25, 0x0, STR_NULL},
|
2005-01-04 21:28:09 +00:00
|
|
|
{ WWT_MATRIX, RESIZE_RB, 14, 0, 312, 26, 207, 0x701, STR_883D_TRAINS_CLICK_ON_TRAIN_FOR},
|
|
|
|
{ WWT_SCROLLBAR, RESIZE_LRB, 14, 313, 324, 26, 207, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST},
|
2005-01-03 19:45:18 +00:00
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 0, 156, 208, 219, STR_8815_NEW_VEHICLES, STR_883E_BUILD_NEW_TRAINS_REQUIRES},
|
2005-01-04 21:28:09 +00:00
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_TB, 14, 157, 312, 208, 219, STR_REPLACE_VEHICLES, STR_REPLACE_HELP},
|
|
|
|
{ WWT_PANEL, RESIZE_RTB, 14, 313, 312, 208, 219, 0x0, STR_NULL},
|
|
|
|
{ WWT_RESIZEBOX, RESIZE_LRTB, 14, 313, 324, 208, 219, 0x0, STR_RESIZE_BUTTON},
|
2004-12-10 18:16:08 +00:00
|
|
|
{ WIDGETS_END},
|
|
|
|
};
|
2004-09-14 14:19:53 +00:00
|
|
|
|
2005-01-03 19:45:18 +00:00
|
|
|
static const Widget _other_player_trains_widgets[] = {
|
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
|
|
|
{ WWT_CAPTION, RESIZE_RIGHT, 14, 11, 312, 0, 13, STR_881B_TRAINS, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
|
|
|
{ WWT_STICKYBOX, RESIZE_LR, 14, 313, 324, 0, 13, 0x0, STR_STICKY_BUTTON},
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 0, 80, 14, 25, SRT_SORT_BY, STR_SORT_ORDER_TIP},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 81, 232, 14, 25, 0x0, STR_SORT_CRITERIA_TIP},
|
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 233, 243, 14, 25, STR_0225, STR_SORT_CRITERIA_TIP},
|
|
|
|
{ WWT_PANEL, RESIZE_RIGHT, 14, 244, 324, 14, 25, 0x0, STR_NULL},
|
2005-01-04 21:28:09 +00:00
|
|
|
{ WWT_MATRIX, RESIZE_RB, 14, 0, 312, 26, 207, 0x701, STR_883D_TRAINS_CLICK_ON_TRAIN_FOR},
|
|
|
|
{ WWT_SCROLLBAR, RESIZE_LRB, 14, 313, 324, 26, 207, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST},
|
|
|
|
{ WWT_PANEL, RESIZE_RTB, 14, 0, 312, 208, 219, 0x0, STR_NULL},
|
|
|
|
{ WWT_RESIZEBOX, RESIZE_LRTB, 14, 313, 324, 208, 219, 0x0, STR_RESIZE_BUTTON},
|
2004-12-10 18:16:08 +00:00
|
|
|
{ WIDGETS_END},
|
|
|
|
};
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
static void PlayerTrainsWndProc(Window *w, WindowEvent *e)
|
|
|
|
{
|
2004-12-10 18:16:08 +00:00
|
|
|
int station = (int)w->window_number >> 16;
|
|
|
|
int owner = w->window_number & 0xff;
|
|
|
|
vehiclelist_d *vl = &WP(w, vehiclelist_d);
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
switch(e->event) {
|
2004-09-06 18:15:13 +00:00
|
|
|
case WE_PAINT: {
|
2004-12-10 18:16:08 +00:00
|
|
|
int x = 2;
|
|
|
|
int y = PLY_WND_PRC__OFFSET_TOP_WIDGET;
|
|
|
|
int max;
|
|
|
|
int i;
|
2004-09-06 18:15:13 +00:00
|
|
|
|
2004-12-10 18:16:08 +00:00
|
|
|
BuildVehicleList(vl, VEH_Train, owner, station);
|
|
|
|
SortVehicleList(vl);
|
2004-09-14 14:19:53 +00:00
|
|
|
|
2004-12-10 18:16:08 +00:00
|
|
|
SetVScrollCount(w, vl->list_length);
|
2004-09-06 18:15:13 +00:00
|
|
|
|
2004-12-10 18:16:08 +00:00
|
|
|
// disable 'Sort By' tooltip on Unsorted sorting criteria
|
|
|
|
if (vl->sort_type == SORT_BY_UNSORTED)
|
2004-12-22 00:45:05 +00:00
|
|
|
w->disabled_state |= (1 << 3);
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
/* draw the widgets */
|
|
|
|
{
|
2004-12-10 18:16:08 +00:00
|
|
|
const Player *p = DEREF_PLAYER(owner);
|
|
|
|
if (station == -1) {
|
|
|
|
/* Company Name -- (###) Trains */
|
|
|
|
SetDParam(0, p->name_1);
|
|
|
|
SetDParam(1, p->name_2);
|
|
|
|
SetDParam(2, w->vscroll.count);
|
2005-01-03 19:45:18 +00:00
|
|
|
w->widget[1].unkA = STR_881B_TRAINS;
|
2004-12-10 18:16:08 +00:00
|
|
|
} else {
|
|
|
|
/* Station Name -- (###) Trains */
|
2005-02-04 20:40:04 +00:00
|
|
|
SetDParam(0, station);
|
2004-12-10 18:16:08 +00:00
|
|
|
SetDParam(1, w->vscroll.count);
|
2005-01-03 19:45:18 +00:00
|
|
|
w->widget[1].unkA = STR_SCHEDULED_TRAINS;
|
2004-12-10 18:16:08 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawWindowWidgets(w);
|
|
|
|
}
|
2004-09-06 21:20:01 +00:00
|
|
|
/* draw sorting criteria string */
|
2004-12-10 18:16:08 +00:00
|
|
|
DrawString(85, 15, _vehicle_sort_listing[vl->sort_type], 0x10);
|
|
|
|
/* draw arrow pointing up/down for ascending/descending sorting */
|
2005-01-31 11:03:23 +00:00
|
|
|
DoDrawString(vl->flags & VL_DESC ? "\xAA" : "\xA0", 69, 15, 0x10);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2004-12-10 18:16:08 +00:00
|
|
|
max = min(w->vscroll.pos + w->vscroll.cap, vl->list_length);
|
|
|
|
for (i = w->vscroll.pos; i < max; ++i) {
|
2005-01-06 22:31:58 +00:00
|
|
|
Vehicle *v = GetVehicle(vl->sort_list[i].index);
|
2004-12-10 18:16:08 +00:00
|
|
|
StringID str;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2004-12-10 18:16:08 +00:00
|
|
|
assert(v->type == VEH_Train && v->owner == owner);
|
2004-09-06 18:15:13 +00:00
|
|
|
|
2004-12-10 18:16:08 +00:00
|
|
|
DrawTrainImage(
|
2005-01-03 19:45:18 +00:00
|
|
|
v, x + 21, y + 6 + _traininfo_vehicle_pitch, w->hscroll.cap, 0, INVALID_VEHICLE);
|
2004-12-10 18:16:08 +00:00
|
|
|
DrawVehicleProfitButton(v, x, y + 13);
|
2004-09-07 19:01:06 +00:00
|
|
|
|
2004-12-10 18:16:08 +00:00
|
|
|
SetDParam(0, v->unitnumber);
|
2005-02-06 22:36:08 +00:00
|
|
|
if (IsTileDepotType(v->tile, TRANSPORT_RAIL) && (v->vehstatus & VS_HIDDEN))
|
2004-12-10 18:16:08 +00:00
|
|
|
str = STR_021F;
|
|
|
|
else
|
|
|
|
str = v->age > v->max_age - 366 ? STR_00E3 : STR_00E2;
|
|
|
|
DrawString(x, y + 2, str, 0);
|
|
|
|
|
|
|
|
SetDParam(0, v->profit_this_year);
|
|
|
|
SetDParam(1, v->profit_last_year);
|
|
|
|
DrawString(x + 21, y + 18, STR_0198_PROFIT_THIS_YEAR_LAST_YEAR, 0);
|
|
|
|
|
|
|
|
if (v->string_id != STR_SV_TRAIN_NAME) {
|
|
|
|
SetDParam(0, v->string_id);
|
|
|
|
DrawString(x + 21, y, STR_01AB, 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2004-12-10 18:16:08 +00:00
|
|
|
|
|
|
|
y += PLY_WND_PRC__SIZE_OF_ROW_SMALL;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2004-12-10 18:16:08 +00:00
|
|
|
break;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
case WE_CLICK: {
|
|
|
|
switch(e->click.widget) {
|
2004-12-22 00:45:05 +00:00
|
|
|
case 3: /* Flip sorting method ascending/descending */
|
2004-12-10 18:16:08 +00:00
|
|
|
vl->flags ^= VL_DESC;
|
|
|
|
vl->flags |= VL_RESORT;
|
2005-01-31 11:03:23 +00:00
|
|
|
_sorting.train.order = !!(vl->flags & VL_DESC);
|
2004-09-06 18:15:13 +00:00
|
|
|
SetWindowDirty(w);
|
|
|
|
break;
|
2004-12-10 18:16:08 +00:00
|
|
|
|
2004-12-22 00:45:05 +00:00
|
|
|
case 4: case 5:/* Select sorting criteria dropdown menu */
|
2005-01-02 17:23:04 +00:00
|
|
|
ShowDropDownMenu(w, _vehicle_sort_listing, vl->sort_type, 5, 0, 0);
|
2004-09-06 18:15:13 +00:00
|
|
|
return;
|
2004-12-10 18:16:08 +00:00
|
|
|
|
2004-12-22 00:45:05 +00:00
|
|
|
case 7: { /* Matrix to show vehicles */
|
2004-09-07 19:01:06 +00:00
|
|
|
uint32 id_v = (e->click.pt.y - PLY_WND_PRC__OFFSET_TOP_WIDGET) / PLY_WND_PRC__SIZE_OF_ROW_SMALL;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-09-07 19:01:06 +00:00
|
|
|
if (id_v >= w->vscroll.cap) { return;} // click out of bounds
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2004-09-06 18:15:13 +00:00
|
|
|
id_v += w->vscroll.pos;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2004-09-06 18:15:13 +00:00
|
|
|
{
|
|
|
|
Vehicle *v;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2004-12-10 18:16:08 +00:00
|
|
|
if (id_v >= vl->list_length) return; // click out of list bound
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-01-06 22:31:58 +00:00
|
|
|
v = GetVehicle(vl->sort_list[id_v].index);
|
2004-09-06 18:15:13 +00:00
|
|
|
|
2005-01-19 19:15:03 +00:00
|
|
|
assert(v->type == VEH_Train && v->subtype == TS_Front_Engine && v->owner == owner);
|
2004-09-06 18:15:13 +00:00
|
|
|
|
|
|
|
ShowTrainViewWindow(v);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
|
2004-12-22 00:45:05 +00:00
|
|
|
case 9: { /* Build new Vehicle */
|
2004-08-09 17:04:08 +00:00
|
|
|
uint tile;
|
|
|
|
|
2005-01-03 19:45:18 +00:00
|
|
|
if (!IsWindowOfPrototype(w, _player_trains_widgets))
|
|
|
|
break;
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
tile = _last_built_train_depot_tile;
|
|
|
|
do {
|
2005-02-06 22:36:08 +00:00
|
|
|
if (_map_owner[tile] == _local_player && IsTileDepotType(tile, TRANSPORT_RAIL)) {
|
2004-08-09 17:04:08 +00:00
|
|
|
ShowTrainDepotWindow(tile);
|
|
|
|
ShowBuildTrainWindow(tile);
|
|
|
|
return;
|
|
|
|
}
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
tile = TILE_MASK(tile + 1);
|
|
|
|
} while(tile != _last_built_train_depot_tile);
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
ShowBuildTrainWindow(0);
|
|
|
|
} break;
|
2005-01-02 17:23:04 +00:00
|
|
|
case 10: {
|
2005-01-04 15:49:30 +00:00
|
|
|
if (!IsWindowOfPrototype(w, _player_trains_widgets))
|
|
|
|
break;
|
|
|
|
|
2005-01-02 17:23:04 +00:00
|
|
|
ShowReplaceVehicleWindow(VEH_Train);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
} break;
|
|
|
|
|
2004-09-06 18:15:13 +00:00
|
|
|
case WE_DROPDOWN_SELECT: /* we have selected a dropdown item in the list */
|
2004-12-10 18:16:08 +00:00
|
|
|
if (vl->sort_type != e->dropdown.index) {
|
|
|
|
// value has changed -> resort
|
|
|
|
vl->flags |= VL_RESORT;
|
|
|
|
vl->sort_type = e->dropdown.index;
|
2005-01-31 11:03:23 +00:00
|
|
|
_sorting.train.criteria = vl->sort_type;
|
2004-12-10 18:16:08 +00:00
|
|
|
|
|
|
|
// enable 'Sort By' if a sorter criteria is chosen
|
|
|
|
if (vl->sort_type != SORT_BY_UNSORTED)
|
2005-01-31 11:03:23 +00:00
|
|
|
CLRBIT(w->disabled_state, 3);
|
2004-12-10 18:16:08 +00:00
|
|
|
}
|
2004-09-06 18:15:13 +00:00
|
|
|
SetWindowDirty(w);
|
|
|
|
break;
|
2004-12-10 18:16:08 +00:00
|
|
|
|
2004-09-06 18:15:13 +00:00
|
|
|
case WE_CREATE: /* set up resort timer */
|
2004-12-10 18:16:08 +00:00
|
|
|
vl->sort_list = NULL;
|
2005-01-31 11:03:23 +00:00
|
|
|
vl->flags = VL_REBUILD | (_sorting.train.order << (VL_DESC - 1));
|
|
|
|
vl->sort_type = _sorting.train.criteria;
|
2004-12-10 18:16:08 +00:00
|
|
|
vl->resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS;
|
2004-09-06 18:15:13 +00:00
|
|
|
break;
|
2004-12-10 18:16:08 +00:00
|
|
|
|
2004-12-22 19:16:56 +00:00
|
|
|
case WE_DESTROY:
|
|
|
|
free(vl->sort_list);
|
|
|
|
break;
|
|
|
|
|
2004-09-06 18:15:13 +00:00
|
|
|
case WE_TICK: /* resort the list every 20 seconds orso (10 days) */
|
2004-12-10 18:16:08 +00:00
|
|
|
if (--vl->resort_timer == 0) {
|
|
|
|
DEBUG(misc, 1) ("Periodic resort trains list player %d station %d",
|
|
|
|
owner, station);
|
|
|
|
vl->resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS;
|
|
|
|
vl->flags |= VL_RESORT;
|
|
|
|
SetWindowDirty(w);
|
2004-09-06 18:15:13 +00:00
|
|
|
}
|
|
|
|
break;
|
2005-01-03 19:45:18 +00:00
|
|
|
|
|
|
|
case WE_RESIZE:
|
|
|
|
/* Update the scroll + matrix */
|
|
|
|
w->hscroll.cap += e->sizing.diff.x / 29;
|
|
|
|
w->vscroll.cap += e->sizing.diff.y / PLY_WND_PRC__SIZE_OF_ROW_SMALL;
|
|
|
|
w->widget[7].unkA = (w->vscroll.cap << 8) + 1;
|
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const WindowDesc _player_trains_desc = {
|
2004-09-06 18:15:13 +00:00
|
|
|
-1, -1, 325, 220,
|
2004-08-09 17:04:08 +00:00
|
|
|
WC_TRAINS_LIST,0,
|
2005-01-03 19:45:18 +00:00
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
|
2004-08-09 17:04:08 +00:00
|
|
|
_player_trains_widgets,
|
|
|
|
PlayerTrainsWndProc
|
|
|
|
};
|
|
|
|
|
|
|
|
static const WindowDesc _other_player_trains_desc = {
|
2005-01-03 19:45:18 +00:00
|
|
|
-1, -1, 325, 220,
|
2004-08-09 17:04:08 +00:00
|
|
|
WC_TRAINS_LIST,0,
|
2005-01-03 19:45:18 +00:00
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
|
2004-08-09 17:04:08 +00:00
|
|
|
_other_player_trains_widgets,
|
|
|
|
PlayerTrainsWndProc
|
|
|
|
};
|
|
|
|
|
2004-12-10 18:16:08 +00:00
|
|
|
void ShowPlayerTrains(int player, int station)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
Window *w;
|
|
|
|
|
2004-09-06 18:15:13 +00:00
|
|
|
if (player == _local_player) {
|
2004-12-10 18:16:08 +00:00
|
|
|
w = AllocateWindowDescFront(&_player_trains_desc, (station << 16) | player);
|
2004-09-06 18:15:13 +00:00
|
|
|
} else {
|
2004-12-10 18:16:08 +00:00
|
|
|
w = AllocateWindowDescFront(&_other_player_trains_desc, (station << 16) | player);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
if (w) {
|
2005-02-22 20:32:26 +00:00
|
|
|
w->caption_color = player;
|
2005-01-03 19:45:18 +00:00
|
|
|
w->hscroll.cap = 10;
|
2004-09-06 18:15:13 +00:00
|
|
|
w->vscroll.cap = 7; // maximum number of vehicles shown
|
2005-01-03 19:45:18 +00:00
|
|
|
w->widget[7].unkA = (w->vscroll.cap << 8) + 1;
|
|
|
|
w->resize.step_height = PLY_WND_PRC__SIZE_OF_ROW_SMALL;
|
|
|
|
w->resize.step_width = 29;
|
|
|
|
w->resize.height = 220 - (PLY_WND_PRC__SIZE_OF_ROW_SMALL * 3); /* Minimum of 4 vehicles */
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|