summaryrefslogtreecommitdiff
path: root/train_gui.c
diff options
context:
space:
mode:
Diffstat (limited to 'train_gui.c')
-rw-r--r--train_gui.c195
1 files changed, 12 insertions, 183 deletions
diff --git a/train_gui.c b/train_gui.c
index ee739ed8f..2aef94fc6 100644
--- a/train_gui.c
+++ b/train_gui.c
@@ -321,7 +321,7 @@ static const WindowDesc _new_rail_vehicle_desc = {
NewRailVehicleWndProc
};
-static void ShowBuildTrainWindow(TileIndex tile)
+void ShowBuildTrainWindow(TileIndex tile)
{
Window *w;
@@ -353,7 +353,7 @@ static int WagonLengthToPixels(int len) {
return (len * _traininfo_vehicle_width) / 8;
}
-static void DrawTrainImage(const Vehicle *v, int x, int y, int count, int skip, VehicleID selection)
+void DrawTrainImage(const Vehicle *v, int x, int y, int count, int skip, VehicleID selection)
{
DrawPixelInfo tmp_dpi, *old_dpi;
int dx = -(skip * 8) / _traininfo_vehicle_width;
@@ -1372,7 +1372,7 @@ static void ShowTrainDetailsWindow(const Vehicle *v)
WP(w,traindetails_d).tab = 0;
}
-static const Widget _player_trains_widgets[] = {
+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},
@@ -1404,187 +1404,12 @@ static const Widget _other_player_trains_widgets[] = {
{ WIDGETS_END},
};
-static void PlayerTrainsWndProc(Window *w, WindowEvent *e)
-{
- OrderID order = INVALID_ORDER;
- StationID station = INVALID_STATION;
- PlayerID owner = GB(w->window_number, 0, 8);
- vehiclelist_d *vl = &WP(w, vehiclelist_d);
-
- if (w->window_number & SHARE_FLAG) {
- order = GB(w->window_number, 16, 16);
- } else {
- station = GB(w->window_number, 16, 16);
- }
-
- switch (e->event) {
- case WE_PAINT: {
- int x = 2;
- int y = PLY_WND_PRC__OFFSET_TOP_WIDGET;
- int max;
- int i;
-
- BuildVehicleList(vl, VEH_Train, owner, station, order);
- SortVehicleList(vl);
- SetVScrollCount(w, vl->list_length);
-
- // disable 'Sort By' tooltip on Unsorted sorting criteria
- if (vl->sort_type == SORT_BY_UNSORTED) w->disabled_state |= (1 << 3);
-
- /* draw the widgets */
- {
- if (order != INVALID_ORDER) {
- /* Shared Orders -- (###) Trains */
- SetDParam(0, w->vscroll.count);
- w->widget[1].unkA = STR_VEH_WITH_SHARED_ORDERS_LIST;
- w->widget[9].unkA = STR_EMPTY;
- w->widget[10].unkA = STR_EMPTY;
- SETBIT(w->disabled_state, 9);
- SETBIT(w->disabled_state, 10);
- } else if (station == INVALID_STATION) {
- const Player *p = GetPlayer(owner);
- /* Company Name -- (###) Trains */
- SetDParam(0, p->name_1);
- SetDParam(1, p->name_2);
- SetDParam(2, w->vscroll.count);
- w->widget[1].unkA = STR_881B_TRAINS;
- } else {
- /* Station Name -- (###) Trains */
- SetDParam(0, station);
- SetDParam(1, w->vscroll.count);
- w->widget[1].unkA = STR_SCHEDULED_TRAINS;
- }
- DrawWindowWidgets(w);
- }
- /* draw sorting criteria string */
- DrawString(85, 15, _vehicle_sort_listing[vl->sort_type], 0x10);
- /* draw arrow pointing up/down for ascending/descending sorting */
- DoDrawString(vl->flags & VL_DESC ? DOWNARROW : UPARROW, 69, 15, 0x10);
-
- max = min(w->vscroll.pos + w->vscroll.cap, vl->list_length);
- for (i = w->vscroll.pos; i < max; ++i) {
- const Vehicle* v = vl->sort_list[i];
- StringID str;
-
- assert(v->type == VEH_Train && v->owner == owner);
-
- DrawTrainImage(v, x + 21, y + 6, w->hscroll.cap, 0, INVALID_VEHICLE);
- DrawVehicleProfitButton(v, x, y + 13);
-
- SetDParam(0, v->unitnumber);
- if (IsTileDepotType(v->tile, TRANSPORT_RAIL) && (v->vehstatus & VS_HIDDEN)) {
- 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);
- }
-
- y += PLY_WND_PRC__SIZE_OF_ROW_SMALL;
- }
- break;
- }
-
- case WE_CLICK: {
- switch (e->click.widget) {
- case 3: /* Flip sorting method ascending/descending */
- vl->flags ^= VL_DESC;
- vl->flags |= VL_RESORT;
- _sorting.train.order = !!(vl->flags & VL_DESC);
- SetWindowDirty(w);
- break;
-
- case 4: case 5:/* Select sorting criteria dropdown menu */
- ShowDropDownMenu(w, _vehicle_sort_listing, vl->sort_type, 5, 0, 0);
- return;
-
- case 7: { /* Matrix to show vehicles */
- uint32 id_v = (e->click.pt.y - PLY_WND_PRC__OFFSET_TOP_WIDGET) / PLY_WND_PRC__SIZE_OF_ROW_SMALL;
- const Vehicle *v;
-
- if (id_v >= w->vscroll.cap) return; // click out of bounds
-
- id_v += w->vscroll.pos;
-
- if (id_v >= vl->list_length) return; // click out of list bound
-
- v = vl->sort_list[id_v];
-
- assert(v->type == VEH_Train && IsFrontEngine(v) && v->owner == owner);
-
- ShowTrainViewWindow(v);
- } break;
-
- case 9: /* Build new Vehicle */
- if (!IsWindowOfPrototype(w, _player_trains_widgets)) break;
- ShowBuildTrainWindow(0);
- break;
-
- case 10:
- if (!IsWindowOfPrototype(w, _player_trains_widgets)) break;
- ShowReplaceVehicleWindow(VEH_Train);
- break;
-
- }
- } break;
-
- case WE_DROPDOWN_SELECT: /* we have selected a dropdown item in the list */
- if (vl->sort_type != e->dropdown.index) {
- // value has changed -> resort
- vl->flags |= VL_RESORT;
- vl->sort_type = e->dropdown.index;
- _sorting.train.criteria = vl->sort_type;
-
- // enable 'Sort By' if a sorter criteria is chosen
- if (vl->sort_type != SORT_BY_UNSORTED) CLRBIT(w->disabled_state, 3);
- }
- SetWindowDirty(w);
- break;
-
- case WE_CREATE: /* set up resort timer */
- vl->sort_list = NULL;
- vl->flags = VL_REBUILD | (_sorting.train.order << (VL_DESC - 1));
- vl->sort_type = _sorting.train.criteria;
- vl->resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS;
- break;
-
- case WE_DESTROY:
- free((void*)vl->sort_list);
- break;
-
- case WE_TICK: /* resort the list every 20 seconds orso (10 days) */
- 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);
- }
- break;
-
- case WE_RESIZE:
- /* Update the scroll + matrix */
- w->hscroll.cap += e->sizing.diff.x;
- w->vscroll.cap += e->sizing.diff.y / PLY_WND_PRC__SIZE_OF_ROW_SMALL;
- w->widget[7].unkA = (w->vscroll.cap << 8) + 1;
- break;
- }
-}
-
static const WindowDesc _player_trains_desc = {
-1, -1, 325, 220,
WC_TRAINS_LIST,0,
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
_player_trains_widgets,
- PlayerTrainsWndProc
+ PlayerVehWndProc
};
static const WindowDesc _other_player_trains_desc = {
@@ -1592,7 +1417,7 @@ static const WindowDesc _other_player_trains_desc = {
WC_TRAINS_LIST,0,
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
_other_player_trains_widgets,
- PlayerTrainsWndProc
+ PlayerVehWndProc
};
static void ShowPlayerTrainsLocal(PlayerID player, StationID station, OrderID order, bool show_shared)
@@ -1600,15 +1425,19 @@ static void ShowPlayerTrainsLocal(PlayerID player, StationID station, OrderID or
Window *w;
if (show_shared) {
- w = AllocateWindowDescFront(&_player_trains_desc, (order << 16) | SHARE_FLAG);
+ w = AllocateWindowDescFront(&_player_trains_desc, (order << 16) | (VEH_Train << 11) | SHARE_FLAG);
} else {
if (player == _local_player) {
- w = AllocateWindowDescFront(&_player_trains_desc, (station << 16) | player);
+ w = AllocateWindowDescFront(&_player_trains_desc, (station << 16) | (VEH_Train << 11) | player);
} else {
- w = AllocateWindowDescFront(&_other_player_trains_desc, (station << 16) | player);
+ w = AllocateWindowDescFront(&_other_player_trains_desc, (station << 16) | (VEH_Train << 11) | player);
}
}
if (w != NULL) {
+ vehiclelist_d *vl = &WP(w, vehiclelist_d);
+ vl->flags = VL_REBUILD | (_sorting.train.order << (VL_DESC - 1));
+ vl->sort_type = _sorting.train.criteria;
+
w->caption_color = player;
w->hscroll.cap = 10 * 29;
w->vscroll.cap = 7; // maximum number of vehicles shown