2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "stdafx.h"
|
2005-06-02 19:30:21 +00:00
|
|
|
#include "openttd.h"
|
2005-02-05 15:58:59 +00:00
|
|
|
#include "debug.h"
|
2005-07-22 07:02:20 +00:00
|
|
|
#include "functions.h"
|
2005-02-06 08:18:00 +00:00
|
|
|
#include "strings.h"
|
2004-11-25 10:47:30 +00:00
|
|
|
#include "table/strings.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "window.h"
|
|
|
|
#include "gui.h"
|
|
|
|
#include "station.h"
|
|
|
|
#include "gfx.h"
|
|
|
|
#include "player.h"
|
2006-05-11 10:33:58 +00:00
|
|
|
#include "economy.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
#include "town.h"
|
|
|
|
#include "command.h"
|
2005-07-21 22:15:02 +00:00
|
|
|
#include "variables.h"
|
|
|
|
#include "vehicle_gui.h"
|
2006-08-14 14:21:15 +00:00
|
|
|
#include "date.h"
|
2006-09-28 23:05:03 +00:00
|
|
|
#include "vehicle.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-12-07 04:12:29 +00:00
|
|
|
enum StationListWidgets {
|
|
|
|
STATIONLIST_WIDGET_CLOSEBOX = 0,
|
|
|
|
STATIONLIST_WIDGET_LIST = 3,
|
|
|
|
STATIONLIST_WIDGET_TRAIN =6,
|
|
|
|
STATIONLIST_WIDGET_TRUCK,
|
|
|
|
STATIONLIST_WIDGET_BUS,
|
|
|
|
STATIONLIST_WIDGET_AIRPLANE,
|
|
|
|
STATIONLIST_WIDGET_SHIP,
|
|
|
|
STATIONLIST_WIDGET_CARGOSTART = 12,
|
2006-12-07 21:21:02 +00:00
|
|
|
STATIONLIST_WIDGET_NOCARGOWAITING = 24,
|
2006-12-07 04:12:29 +00:00
|
|
|
STATIONLIST_WIDGET_FACILALL = 26,
|
|
|
|
STATIONLIST_WIDGET_CARGOALL,
|
|
|
|
STATIONLIST_WIDGET_SORTBY,
|
|
|
|
STATIONLIST_WIDGET_SORTCRITERIA,
|
|
|
|
STATIONLIST_WIDGET_SORTDROPBTN,
|
|
|
|
CARGO_ALL_SELECTED = 0x1FFF,
|
|
|
|
};
|
|
|
|
|
2006-05-11 10:33:58 +00:00
|
|
|
typedef int CDECL StationSortListingTypeFunction(const void*, const void*);
|
|
|
|
|
|
|
|
static StationSortListingTypeFunction StationNameSorter;
|
|
|
|
static StationSortListingTypeFunction StationTypeSorter;
|
|
|
|
static StationSortListingTypeFunction StationWaitingSorter;
|
|
|
|
static StationSortListingTypeFunction StationRatingMaxSorter;
|
|
|
|
|
2006-12-09 00:46:02 +00:00
|
|
|
/** Draw small boxes of cargo amount and ratings data at the given
|
|
|
|
* coordinates. If amount exceeds 576 units, it is shown 'full', same
|
|
|
|
* goes for the rating: at above 90% orso (224) it is also 'full'
|
|
|
|
* Each cargo-bar is 16 pixels wide and 6 pixels high
|
|
|
|
* Each rating 14 pixels wide and 1 pixel high and is 1 pixel below the cargo-bar
|
|
|
|
* @param x,y X/Y coordinate to draw the box at
|
|
|
|
* @param type Cargo type
|
|
|
|
* @param amount Cargo amount
|
|
|
|
* @param rating ratings data for that particular cargo */
|
|
|
|
static void StationsWndShowStationRating(int x, int y, CargoID type, uint amount, byte rating)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-12-09 00:46:02 +00:00
|
|
|
int colour = _cargo_colours[type];
|
|
|
|
uint w = (minu(amount, 576) + 5) / 36;
|
|
|
|
|
|
|
|
/* Draw total cargo (limited) on station (fits into 16 pixels) */
|
|
|
|
if (w != 0) GfxFillRect(x, y, x + w - 1, y + 6, colour);
|
|
|
|
|
|
|
|
/* Draw a one pixel-wide bar of additional cargo meter, useful
|
|
|
|
* for stations with only a small amount (<=30) */
|
|
|
|
if (w == 0) {
|
|
|
|
uint rest = amount / 5;
|
|
|
|
if (rest != 0) {
|
|
|
|
w += x;
|
|
|
|
GfxFillRect(w, y + 6 - rest, w, y + 6, colour);
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
DrawString(x + 1, y, _cargoc.names_short[type], 0x10);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-12-09 00:46:02 +00:00
|
|
|
/* Draw green/red ratings bar (fits into 14 pixels) */
|
|
|
|
y += 8;
|
|
|
|
GfxFillRect(x + 1, y, x + 14, y, 0xB8);
|
|
|
|
rating = minu(rating, 224) / 16;
|
|
|
|
if (rating != 0) GfxFillRect(x + 1, y, x + rating, y, 0xD0);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2006-05-11 10:33:58 +00:00
|
|
|
const StringID _station_sort_listing[] = {
|
|
|
|
STR_SORT_BY_DROPDOWN_NAME,
|
|
|
|
STR_SORT_BY_FACILITY,
|
|
|
|
STR_SORT_BY_WAITING,
|
|
|
|
STR_SORT_BY_RATING_MAX,
|
|
|
|
INVALID_STRING_ID
|
|
|
|
};
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
static char _bufcache[64];
|
2006-08-15 07:07:17 +00:00
|
|
|
static const Station* _last_station;
|
2006-05-11 10:33:58 +00:00
|
|
|
static int _internal_sort_order;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2004-09-06 18:15:13 +00:00
|
|
|
static int CDECL StationNameSorter(const void *a, const void *b)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-08-14 21:02:48 +00:00
|
|
|
const Station* st1 = *(const Station**)a;
|
|
|
|
const Station* st2 = *(const Station**)b;
|
2004-08-09 17:04:08 +00:00
|
|
|
char buf1[64];
|
2006-05-11 10:33:58 +00:00
|
|
|
int r;
|
2004-09-06 18:15:13 +00:00
|
|
|
|
2006-08-27 10:04:33 +00:00
|
|
|
SetDParam(0, st1->index);
|
2006-10-21 23:31:34 +00:00
|
|
|
GetString(buf1, STR_STATION, lastof(buf1));
|
2004-09-06 18:15:13 +00:00
|
|
|
|
2006-08-15 07:07:17 +00:00
|
|
|
if (st2 != _last_station) {
|
|
|
|
_last_station = st2;
|
2006-08-27 10:04:33 +00:00
|
|
|
SetDParam(0, st2->index);
|
2006-10-21 23:31:34 +00:00
|
|
|
GetString(_bufcache, STR_STATION, lastof(_bufcache));
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2004-09-06 18:15:13 +00:00
|
|
|
|
2006-05-11 10:33:58 +00:00
|
|
|
r = strcmp(buf1, _bufcache); // sort by name
|
|
|
|
return (_internal_sort_order & 1) ? -r : r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int CDECL StationTypeSorter(const void *a, const void *b)
|
|
|
|
{
|
2006-08-14 21:02:48 +00:00
|
|
|
const Station* st1 = *(const Station**)a;
|
|
|
|
const Station* st2 = *(const Station**)b;
|
2006-05-11 10:33:58 +00:00
|
|
|
return (_internal_sort_order & 1) ? st2->facilities - st1->facilities : st1->facilities - st2->facilities;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int CDECL StationWaitingSorter(const void *a, const void *b)
|
|
|
|
{
|
2006-08-14 21:02:48 +00:00
|
|
|
const Station* st1 = *(const Station**)a;
|
|
|
|
const Station* st2 = *(const Station**)b;
|
2006-05-11 10:33:58 +00:00
|
|
|
int sum1 = 0, sum2 = 0;
|
|
|
|
int j;
|
|
|
|
|
|
|
|
for (j = 0; j < NUM_CARGO; j++) {
|
|
|
|
if (st1->goods[j].waiting_acceptance & 0xfff) sum1 += GetTransportedGoodsIncome(st1->goods[j].waiting_acceptance & 0xfff, 20, 50, j);
|
|
|
|
if (st2->goods[j].waiting_acceptance & 0xfff) sum2 += GetTransportedGoodsIncome(st2->goods[j].waiting_acceptance & 0xfff, 20, 50, j);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (_internal_sort_order & 1) ? sum2 - sum1 : sum1 - sum2;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int CDECL StationRatingMaxSorter(const void *a, const void *b)
|
|
|
|
{
|
2006-08-14 21:02:48 +00:00
|
|
|
const Station* st1 = *(const Station**)a;
|
|
|
|
const Station* st2 = *(const Station**)b;
|
2006-05-11 10:33:58 +00:00
|
|
|
byte maxr1 = 0;
|
|
|
|
byte maxr2 = 0;
|
|
|
|
int j;
|
|
|
|
|
|
|
|
for (j = 0; j < NUM_CARGO; j++) {
|
|
|
|
if (st1->goods[j].waiting_acceptance & 0xfff) maxr1 = max(maxr1, st1->goods[j].rating);
|
|
|
|
if (st2->goods[j].waiting_acceptance & 0xfff) maxr2 = max(maxr2, st2->goods[j].rating);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (_internal_sort_order & 1) ? maxr2 - maxr1 : maxr1 - maxr2;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef enum StationListFlags {
|
|
|
|
SL_ORDER = 0x01,
|
|
|
|
SL_RESORT = 0x02,
|
|
|
|
SL_REBUILD = 0x04,
|
|
|
|
} StationListFlags;
|
|
|
|
|
|
|
|
typedef struct plstations_d {
|
2006-08-14 21:02:48 +00:00
|
|
|
const Station** sort_list;
|
2006-05-11 10:33:58 +00:00
|
|
|
uint16 list_length;
|
|
|
|
byte sort_type;
|
|
|
|
StationListFlags flags;
|
|
|
|
uint16 resort_timer; //was byte refresh_counter;
|
|
|
|
} plstations_d;
|
|
|
|
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(plstations_d));
|
|
|
|
|
|
|
|
void RebuildStationLists(void)
|
|
|
|
{
|
2006-11-18 16:47:02 +00:00
|
|
|
Window* const *wz;
|
2006-05-11 10:33:58 +00:00
|
|
|
|
2006-11-18 16:47:02 +00:00
|
|
|
FOR_ALL_WINDOWS(wz) {
|
|
|
|
Window *w = *wz;
|
2006-05-11 10:33:58 +00:00
|
|
|
if (w->window_class == WC_STATION_LIST) {
|
|
|
|
WP(w, plstations_d).flags |= SL_REBUILD;
|
|
|
|
SetWindowDirty(w);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResortStationLists(void)
|
|
|
|
{
|
2006-11-18 16:47:02 +00:00
|
|
|
Window* const *wz;
|
2006-05-11 10:33:58 +00:00
|
|
|
|
2006-11-18 16:47:02 +00:00
|
|
|
FOR_ALL_WINDOWS(wz) {
|
|
|
|
Window *w = *wz;
|
2006-05-11 10:33:58 +00:00
|
|
|
if (w->window_class == WC_STATION_LIST) {
|
|
|
|
WP(w, plstations_d).flags |= SL_RESORT;
|
|
|
|
SetWindowDirty(w);
|
|
|
|
}
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
2006-05-11 10:33:58 +00:00
|
|
|
static void BuildStationsList(plstations_d* sl, PlayerID owner, byte facilities, uint16 cargo_filter)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-05-11 10:33:58 +00:00
|
|
|
uint n = 0;
|
|
|
|
uint i, j;
|
2006-08-14 21:02:48 +00:00
|
|
|
const Station** station_sort;
|
2004-09-14 14:19:53 +00:00
|
|
|
const Station *st;
|
|
|
|
|
2006-05-11 10:33:58 +00:00
|
|
|
if (!(sl->flags & SL_REBUILD)) return;
|
2005-01-06 22:31:58 +00:00
|
|
|
|
|
|
|
/* Create array for sorting */
|
2006-12-05 13:58:20 +00:00
|
|
|
station_sort = malloc((GetMaxStationIndex() + 1) * sizeof(station_sort[0]));
|
2006-12-26 17:36:18 +00:00
|
|
|
if (station_sort == NULL) error("Could not allocate memory for the station-sorting-list");
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-12-26 17:36:18 +00:00
|
|
|
DEBUG(misc, 3, "Building station list for player %d", owner);
|
2006-05-11 10:33:58 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
FOR_ALL_STATIONS(st) {
|
2006-08-22 15:33:35 +00:00
|
|
|
if (st->owner == owner) {
|
2006-05-11 10:33:58 +00:00
|
|
|
if (facilities & st->facilities) { //only stations with selected facilities
|
|
|
|
int num_waiting_cargo = 0;
|
|
|
|
for (j = 0; j < NUM_CARGO; j++) {
|
|
|
|
if (st->goods[j].waiting_acceptance & 0xFFF) {
|
|
|
|
num_waiting_cargo++; //count number of waiting cargo
|
|
|
|
if (HASBIT(cargo_filter, j)) {
|
2006-08-14 21:02:48 +00:00
|
|
|
station_sort[n++] = st;
|
2006-05-11 10:33:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//stations without waiting cargo
|
|
|
|
if (num_waiting_cargo == 0 && HASBIT(cargo_filter, NUM_CARGO)) {
|
2006-08-14 21:02:48 +00:00
|
|
|
station_sort[n++] = st;
|
2006-05-11 10:33:58 +00:00
|
|
|
}
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-08-15 07:07:17 +00:00
|
|
|
free((void*)sl->sort_list);
|
2006-05-11 10:33:58 +00:00
|
|
|
sl->sort_list = malloc(n * sizeof(sl->sort_list[0]));
|
|
|
|
if (n != 0 && sl->sort_list == NULL) error("Could not allocate memory for the station-sorting-list");
|
|
|
|
sl->list_length = n;
|
2004-09-06 18:15:13 +00:00
|
|
|
|
2006-08-14 21:02:48 +00:00
|
|
|
for (i = 0; i < n; ++i) sl->sort_list[i] = station_sort[i];
|
2004-09-14 14:19:53 +00:00
|
|
|
|
2006-05-11 10:33:58 +00:00
|
|
|
sl->flags &= ~SL_REBUILD;
|
|
|
|
sl->flags |= SL_RESORT;
|
2006-08-15 07:07:17 +00:00
|
|
|
free((void*)station_sort);
|
2004-09-14 14:19:53 +00:00
|
|
|
}
|
|
|
|
|
2006-05-11 10:33:58 +00:00
|
|
|
static void SortStationsList(plstations_d *sl)
|
2004-09-14 14:19:53 +00:00
|
|
|
{
|
2006-05-11 10:33:58 +00:00
|
|
|
static StationSortListingTypeFunction* const _station_sorter[] = {
|
|
|
|
&StationNameSorter,
|
|
|
|
&StationTypeSorter,
|
|
|
|
&StationWaitingSorter,
|
|
|
|
&StationRatingMaxSorter
|
|
|
|
};
|
2004-09-07 19:01:06 +00:00
|
|
|
|
2006-05-11 10:33:58 +00:00
|
|
|
if (!(sl->flags & SL_RESORT)) return;
|
2004-09-14 14:19:53 +00:00
|
|
|
|
2006-05-11 10:33:58 +00:00
|
|
|
_internal_sort_order = sl->flags & SL_ORDER;
|
2006-08-15 07:07:17 +00:00
|
|
|
_last_station = NULL; // used for "cache" in namesorting
|
2006-08-15 09:28:27 +00:00
|
|
|
qsort((void*)sl->sort_list, sl->list_length, sizeof(sl->sort_list[0]), _station_sorter[sl->sort_type]);
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2006-05-11 10:33:58 +00:00
|
|
|
sl->resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS;
|
|
|
|
sl->flags &= ~SL_RESORT;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void PlayerStationsWndProc(Window *w, WindowEvent *e)
|
|
|
|
{
|
2006-05-11 10:33:58 +00:00
|
|
|
const PlayerID owner = w->window_number;
|
|
|
|
static byte facilities = FACIL_TRAIN | FACIL_TRUCK_STOP | FACIL_BUS_STOP | FACIL_AIRPORT | FACIL_DOCK;
|
2006-12-07 04:12:29 +00:00
|
|
|
static uint16 cargo_filter = CARGO_ALL_SELECTED;
|
2006-05-11 10:33:58 +00:00
|
|
|
plstations_d *sl = &WP(w, plstations_d);
|
2006-05-11 15:14:50 +00:00
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
switch (e->event) {
|
2006-12-07 04:12:29 +00:00
|
|
|
case WE_CREATE: { /* set up resort timer */
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < 5; i++) {
|
|
|
|
if (HASBIT(facilities, i)) LowerWindowWidget(w, i + STATIONLIST_WIDGET_TRAIN);
|
|
|
|
}
|
|
|
|
for (i = 0; i < NUM_CARGO; i++) {
|
|
|
|
if (HASBIT(cargo_filter, i)) LowerWindowWidget(w, i + STATIONLIST_WIDGET_CARGOSTART);
|
|
|
|
}
|
|
|
|
SetWindowWidgetLoweredState(w, STATIONLIST_WIDGET_FACILALL, facilities == (FACIL_TRAIN | FACIL_TRUCK_STOP | FACIL_BUS_STOP | FACIL_AIRPORT | FACIL_DOCK));
|
|
|
|
SetWindowWidgetLoweredState(w, STATIONLIST_WIDGET_CARGOALL, cargo_filter == CARGO_ALL_SELECTED);
|
2006-12-08 02:25:04 +00:00
|
|
|
SetWindowWidgetLoweredState(w, STATIONLIST_WIDGET_NOCARGOWAITING, HASBIT(cargo_filter, STATIONLIST_WIDGET_NOCARGOWAITING - NUM_CARGO));
|
2006-12-07 04:12:29 +00:00
|
|
|
|
|
|
|
sl->sort_list = NULL;
|
|
|
|
sl->flags = SL_REBUILD;
|
|
|
|
sl->sort_type = 0;
|
|
|
|
sl->resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
case WE_PAINT: {
|
2006-05-11 10:33:58 +00:00
|
|
|
BuildStationsList(sl, owner, facilities, cargo_filter);
|
|
|
|
SortStationsList(sl);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-05-11 10:33:58 +00:00
|
|
|
SetVScrollCount(w, sl->list_length);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
/* draw widgets, with player's name in the caption */
|
|
|
|
{
|
2005-10-07 07:35:15 +00:00
|
|
|
const Player* p = GetPlayer(owner);
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, p->name_1);
|
|
|
|
SetDParam(1, p->name_2);
|
|
|
|
SetDParam(2, w->vscroll.count);
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawWindowWidgets(w);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2006-05-11 10:33:58 +00:00
|
|
|
int max;
|
2006-12-07 04:12:29 +00:00
|
|
|
int i, cg_ofst;
|
2006-05-11 10:33:58 +00:00
|
|
|
int x = 0, y = 0, xb = 2; // offset from top of widget
|
|
|
|
|
|
|
|
/* draw sorting criteria string */
|
|
|
|
DrawString(85, 26, _station_sort_listing[sl->sort_type], 0x10);
|
|
|
|
/* draw arrow pointing up/down for ascending/descending sorting */
|
|
|
|
DoDrawString(sl->flags & SL_ORDER ? DOWNARROW : UPARROW, 69, 26, 0x10);
|
|
|
|
|
|
|
|
|
2006-12-09 00:41:25 +00:00
|
|
|
x = 89;
|
2006-05-11 10:33:58 +00:00
|
|
|
y = 14;
|
|
|
|
|
|
|
|
for (i = 0; i < NUM_CARGO; i++) {
|
2006-12-07 04:12:29 +00:00
|
|
|
cg_ofst = IsWindowWidgetLowered(w, i + STATIONLIST_WIDGET_CARGOSTART) ? 2 : 1;
|
|
|
|
|
2006-12-09 00:41:25 +00:00
|
|
|
GfxFillRect(x + cg_ofst, y + cg_ofst, x + cg_ofst + 10 , y + cg_ofst + 7, _cargo_colours[i]);
|
|
|
|
DrawStringCentered(x + 6 + cg_ofst, y + cg_ofst, _cargoc.names_short[i], 0x10);
|
2006-05-11 10:33:58 +00:00
|
|
|
x += 14;
|
|
|
|
}
|
|
|
|
|
2006-12-09 00:41:25 +00:00
|
|
|
x += 6;
|
|
|
|
cg_ofst = IsWindowWidgetLowered(w, STATIONLIST_WIDGET_NOCARGOWAITING) ? 2 : 1;
|
|
|
|
DrawStringCentered(x + cg_ofst, y + cg_ofst, STR_ABBREV_NONE, 16);
|
2006-05-11 10:33:58 +00:00
|
|
|
x += 14;
|
2006-12-09 00:41:25 +00:00
|
|
|
cg_ofst = IsWindowWidgetLowered(w, STATIONLIST_WIDGET_CARGOALL) ? 2 : 1;
|
|
|
|
DrawStringCentered(x + cg_ofst, y + cg_ofst, STR_ABBREV_ALL, 16);
|
2006-12-07 04:12:29 +00:00
|
|
|
|
2006-12-09 00:41:25 +00:00
|
|
|
cg_ofst = IsWindowWidgetLowered(w, STATIONLIST_WIDGET_FACILALL) ? 2 : 1;
|
|
|
|
DrawString(71 + cg_ofst, y + cg_ofst, STR_ABBREV_ALL, 16);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-07-08 22:25:24 +00:00
|
|
|
if (w->vscroll.count == 0) { // player has no stations
|
2006-05-11 10:33:58 +00:00
|
|
|
DrawString(xb, 40, STR_304A_NONE, 0);
|
2004-08-09 17:04:08 +00:00
|
|
|
return;
|
|
|
|
}
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2006-05-11 10:33:58 +00:00
|
|
|
max = min(w->vscroll.pos + w->vscroll.cap, sl->list_length);
|
|
|
|
y = 40; // start of the list-widget
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-05-11 10:33:58 +00:00
|
|
|
for (i = w->vscroll.pos; i < max; ++i) { // do until max number of stations of owner
|
2006-12-09 00:46:02 +00:00
|
|
|
const Station *st = sl->sort_list[i];
|
|
|
|
CargoID j;
|
2005-11-13 13:43:55 +00:00
|
|
|
int x;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-12-09 00:46:02 +00:00
|
|
|
assert(st->xy != 0);
|
2006-05-11 10:33:58 +00:00
|
|
|
assert(st->owner == owner);
|
2004-09-07 19:01:06 +00:00
|
|
|
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, st->index);
|
|
|
|
SetDParam(1, st->facilities);
|
2004-08-09 17:04:08 +00:00
|
|
|
x = DrawString(xb, y, STR_3049_0, 0) + 5;
|
|
|
|
|
|
|
|
// show cargo waiting and station ratings
|
2005-11-14 19:48:04 +00:00
|
|
|
for (j = 0; j != NUM_CARGO; j++) {
|
2006-12-09 00:46:02 +00:00
|
|
|
uint amount = GB(st->goods[j].waiting_acceptance, 0, 12);
|
2005-11-14 19:48:04 +00:00
|
|
|
|
2006-12-09 00:46:02 +00:00
|
|
|
if (amount != 0) {
|
|
|
|
StationsWndShowStationRating(x, y, j, amount, st->goods[j].rating);
|
|
|
|
x += 20;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
y += 10;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} break;
|
2006-12-07 04:12:29 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
case WE_CLICK: {
|
2006-09-23 02:39:24 +00:00
|
|
|
switch (e->we.click.widget) {
|
2006-12-07 04:12:29 +00:00
|
|
|
case STATIONLIST_WIDGET_LIST: {
|
2006-08-14 21:02:48 +00:00
|
|
|
const Station* st;
|
|
|
|
|
2006-09-23 02:39:24 +00:00
|
|
|
uint32 id_v = (e->we.click.pt.y - 41) / 10;
|
2004-09-07 19:01:06 +00:00
|
|
|
|
2005-11-14 19:48:04 +00:00
|
|
|
if (id_v >= w->vscroll.cap) return; // click out of bounds
|
2004-09-07 19:01:06 +00:00
|
|
|
|
|
|
|
id_v += w->vscroll.pos;
|
|
|
|
|
2006-05-11 15:14:50 +00:00
|
|
|
if (id_v >= sl->list_length) return; // click out of list bound
|
2004-09-07 19:01:06 +00:00
|
|
|
|
2006-08-14 21:02:48 +00:00
|
|
|
st = sl->sort_list[id_v];
|
|
|
|
assert(st->owner == owner);
|
|
|
|
ScrollMainWindowToTile(st->xy);
|
|
|
|
break;
|
|
|
|
}
|
2004-09-07 19:01:06 +00:00
|
|
|
|
2006-12-07 04:12:29 +00:00
|
|
|
case STATIONLIST_WIDGET_TRAIN:
|
|
|
|
case STATIONLIST_WIDGET_TRUCK:
|
|
|
|
case STATIONLIST_WIDGET_BUS:
|
|
|
|
case STATIONLIST_WIDGET_AIRPLANE:
|
|
|
|
case STATIONLIST_WIDGET_SHIP:
|
2006-05-11 10:33:58 +00:00
|
|
|
if (_ctrl_pressed) {
|
2006-12-07 04:12:29 +00:00
|
|
|
TOGGLEBIT(facilities, e->we.click.widget - STATIONLIST_WIDGET_TRAIN);
|
2006-10-03 20:16:20 +00:00
|
|
|
ToggleWidgetLoweredState(w, e->we.click.widget);
|
2006-05-11 10:33:58 +00:00
|
|
|
} else {
|
2006-10-03 20:16:20 +00:00
|
|
|
int i;
|
|
|
|
for (i = 0; facilities != 0; i++, facilities >>= 1) {
|
2006-12-07 04:12:29 +00:00
|
|
|
if (HASBIT(facilities, 0)) RaiseWindowWidget(w, i + STATIONLIST_WIDGET_TRAIN);
|
2006-10-03 20:16:20 +00:00
|
|
|
}
|
2006-12-07 04:12:29 +00:00
|
|
|
SETBIT(facilities, e->we.click.widget - STATIONLIST_WIDGET_TRAIN);
|
2006-10-03 20:16:20 +00:00
|
|
|
LowerWindowWidget(w, e->we.click.widget);
|
2006-05-11 10:33:58 +00:00
|
|
|
}
|
2006-12-07 04:12:29 +00:00
|
|
|
SetWindowWidgetLoweredState(w, STATIONLIST_WIDGET_FACILALL, facilities == (FACIL_TRAIN | FACIL_TRUCK_STOP | FACIL_BUS_STOP | FACIL_AIRPORT | FACIL_DOCK));
|
2006-05-11 10:33:58 +00:00
|
|
|
sl->flags |= SL_REBUILD;
|
|
|
|
SetWindowDirty(w);
|
|
|
|
break;
|
2006-12-07 04:12:29 +00:00
|
|
|
|
|
|
|
case STATIONLIST_WIDGET_FACILALL: {
|
2006-10-03 20:16:20 +00:00
|
|
|
int i;
|
|
|
|
for (i = 0; i < 5; i++) {
|
2006-12-07 04:12:29 +00:00
|
|
|
LowerWindowWidget(w, i + STATIONLIST_WIDGET_TRAIN);
|
2006-10-03 20:16:20 +00:00
|
|
|
}
|
2006-12-07 04:12:29 +00:00
|
|
|
LowerWindowWidget(w, STATIONLIST_WIDGET_FACILALL);
|
2006-10-03 20:16:20 +00:00
|
|
|
|
2006-05-11 10:33:58 +00:00
|
|
|
facilities = FACIL_TRAIN | FACIL_TRUCK_STOP | FACIL_BUS_STOP | FACIL_AIRPORT | FACIL_DOCK;
|
|
|
|
sl->flags |= SL_REBUILD;
|
|
|
|
SetWindowDirty(w);
|
|
|
|
break;
|
2006-10-03 20:16:20 +00:00
|
|
|
}
|
2006-12-07 04:12:29 +00:00
|
|
|
case STATIONLIST_WIDGET_CARGOALL: {
|
2006-10-03 20:16:20 +00:00
|
|
|
int i;
|
|
|
|
for (i = 0; i < NUM_CARGO; i++) {
|
2006-12-07 04:12:29 +00:00
|
|
|
LowerWindowWidget(w, i + STATIONLIST_WIDGET_CARGOSTART);
|
2006-10-03 20:16:20 +00:00
|
|
|
}
|
2006-12-08 02:25:04 +00:00
|
|
|
LowerWindowWidget(w, STATIONLIST_WIDGET_NOCARGOWAITING);
|
2006-12-07 04:12:29 +00:00
|
|
|
LowerWindowWidget(w, STATIONLIST_WIDGET_CARGOALL);
|
2006-10-03 20:16:20 +00:00
|
|
|
|
2006-12-07 04:12:29 +00:00
|
|
|
cargo_filter = CARGO_ALL_SELECTED;
|
2006-05-11 10:33:58 +00:00
|
|
|
sl->flags |= SL_REBUILD;
|
|
|
|
SetWindowDirty(w);
|
|
|
|
break;
|
2006-10-03 20:16:20 +00:00
|
|
|
}
|
2006-12-07 04:12:29 +00:00
|
|
|
case STATIONLIST_WIDGET_SORTBY: /*flip sorting method asc/desc*/
|
2006-05-11 10:33:58 +00:00
|
|
|
TOGGLEBIT(sl->flags, 0); //DESC-flag
|
|
|
|
sl->flags |= SL_RESORT;
|
2006-12-07 04:12:29 +00:00
|
|
|
w->flags4 |= 5 << WF_TIMEOUT_SHL;
|
|
|
|
LowerWindowWidget(w, STATIONLIST_WIDGET_SORTBY);
|
2006-05-11 10:33:58 +00:00
|
|
|
SetWindowDirty(w);
|
|
|
|
break;
|
2006-12-07 04:12:29 +00:00
|
|
|
|
|
|
|
case STATIONLIST_WIDGET_SORTCRITERIA:
|
|
|
|
case STATIONLIST_WIDGET_SORTDROPBTN: /* select sorting criteria dropdown menu */
|
|
|
|
ShowDropDownMenu(w, _station_sort_listing, sl->sort_type, STATIONLIST_WIDGET_SORTDROPBTN, 0, 0);
|
2006-05-11 10:33:58 +00:00
|
|
|
break;
|
2006-12-07 04:12:29 +00:00
|
|
|
|
2006-05-11 10:33:58 +00:00
|
|
|
default:
|
2006-12-07 21:21:02 +00:00
|
|
|
if (e->we.click.widget >= STATIONLIST_WIDGET_CARGOSTART && e->we.click.widget <= STATIONLIST_WIDGET_NOCARGOWAITING) { //change cargo_filter
|
2006-05-11 10:33:58 +00:00
|
|
|
if (_ctrl_pressed) {
|
2006-12-07 04:12:29 +00:00
|
|
|
TOGGLEBIT(cargo_filter, e->we.click.widget - STATIONLIST_WIDGET_CARGOSTART);
|
2006-10-03 20:16:20 +00:00
|
|
|
ToggleWidgetLoweredState(w, e->we.click.widget);
|
2006-05-11 10:33:58 +00:00
|
|
|
} else {
|
2006-10-03 20:16:20 +00:00
|
|
|
int i;
|
|
|
|
for (i = 0; cargo_filter != 0; i++, cargo_filter >>= 1) {
|
2006-12-07 04:12:29 +00:00
|
|
|
if (HASBIT(cargo_filter, 0)) RaiseWindowWidget(w, i + STATIONLIST_WIDGET_CARGOSTART);
|
2006-10-03 20:16:20 +00:00
|
|
|
}
|
2006-12-07 04:12:29 +00:00
|
|
|
SETBIT(cargo_filter, e->we.click.widget - STATIONLIST_WIDGET_CARGOSTART);
|
2006-10-03 20:16:20 +00:00
|
|
|
LowerWindowWidget(w, e->we.click.widget);
|
2006-05-11 10:33:58 +00:00
|
|
|
}
|
|
|
|
sl->flags |= SL_REBUILD;
|
2006-12-07 04:12:29 +00:00
|
|
|
SetWindowWidgetLoweredState(w, STATIONLIST_WIDGET_CARGOALL, cargo_filter == CARGO_ALL_SELECTED);
|
2006-05-11 10:33:58 +00:00
|
|
|
SetWindowDirty(w);
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
} break;
|
2006-12-07 04:12:29 +00:00
|
|
|
|
2006-05-11 10:33:58 +00:00
|
|
|
case WE_DROPDOWN_SELECT: /* we have selected a dropdown item in the list */
|
2006-09-23 02:39:24 +00:00
|
|
|
if (sl->sort_type != e->we.dropdown.index) {
|
2006-05-11 10:33:58 +00:00
|
|
|
// value has changed -> resort
|
2006-09-23 02:39:24 +00:00
|
|
|
sl->sort_type = e->we.dropdown.index;
|
2006-05-11 10:33:58 +00:00
|
|
|
sl->flags |= SL_RESORT;
|
|
|
|
}
|
|
|
|
SetWindowDirty(w);
|
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-05-11 10:33:58 +00:00
|
|
|
case WE_TICK:
|
|
|
|
if (--sl->resort_timer == 0) {
|
2006-12-26 17:36:18 +00:00
|
|
|
DEBUG(misc, 3, "Periodic rebuild station list player %d", owner);
|
2006-05-11 10:33:58 +00:00
|
|
|
sl->resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS;
|
|
|
|
sl->flags |= VL_REBUILD;
|
2004-08-09 17:04:08 +00:00
|
|
|
SetWindowDirty(w);
|
|
|
|
}
|
|
|
|
break;
|
2005-01-03 19:45:18 +00:00
|
|
|
|
2006-12-07 04:12:29 +00:00
|
|
|
case WE_TIMEOUT:
|
|
|
|
RaiseWindowWidget(w, STATIONLIST_WIDGET_SORTBY);
|
|
|
|
SetWindowDirty(w);
|
2006-05-11 10:33:58 +00:00
|
|
|
break;
|
|
|
|
|
2005-01-03 19:45:18 +00:00
|
|
|
case WE_RESIZE:
|
2006-09-23 02:39:24 +00:00
|
|
|
w->vscroll.cap += e->we.sizing.diff.y / 10;
|
2005-01-03 19:45:18 +00:00
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const Widget _player_stations_widgets[] = {
|
2006-04-15 03:08:14 +00:00
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
|
|
|
{ WWT_CAPTION, RESIZE_RIGHT, 14, 11, 345, 0, 13, STR_3048_STATIONS, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
|
|
|
{ WWT_STICKYBOX, RESIZE_LR, 14, 346, 357, 0, 13, 0x0, STR_STICKY_BUTTON},
|
2006-05-11 10:33:58 +00:00
|
|
|
{ WWT_PANEL, RESIZE_RB, 14, 0, 345, 37, 161, 0x0, STR_3057_STATION_NAMES_CLICK_ON},
|
2006-11-18 17:34:20 +00:00
|
|
|
{ WWT_SCROLLBAR, RESIZE_LRB, 14, 346, 357, 37, 149, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST},
|
2006-05-11 10:33:58 +00:00
|
|
|
{ WWT_RESIZEBOX, RESIZE_LRTB, 14, 346, 357, 150, 161, 0x0, STR_RESIZE_BUTTON},
|
|
|
|
//Index 6
|
2006-08-22 14:38:37 +00:00
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 0, 13, 14, 24, STR_TRAIN, STR_USE_CTRL_TO_SELECT_MORE},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 14, 27, 14, 24, STR_LORRY, STR_USE_CTRL_TO_SELECT_MORE},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 28, 41, 14, 24, STR_BUS, STR_USE_CTRL_TO_SELECT_MORE},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 42, 55, 14, 24, STR_PLANE, STR_USE_CTRL_TO_SELECT_MORE},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 56, 69, 14, 24, STR_SHIP, STR_USE_CTRL_TO_SELECT_MORE},
|
2006-05-11 10:33:58 +00:00
|
|
|
//Index 11
|
2006-08-22 14:38:37 +00:00
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 83, 88, 14, 24, 0x0, STR_USE_CTRL_TO_SELECT_MORE},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 89, 102, 14, 24, 0x0, STR_USE_CTRL_TO_SELECT_MORE},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 103, 116, 14, 24, 0x0, STR_USE_CTRL_TO_SELECT_MORE},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 117, 130, 14, 24, 0x0, STR_USE_CTRL_TO_SELECT_MORE},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 131, 144, 14, 24, 0x0, STR_USE_CTRL_TO_SELECT_MORE},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 145, 158, 14, 24, 0x0, STR_USE_CTRL_TO_SELECT_MORE},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 159, 172, 14, 24, 0x0, STR_USE_CTRL_TO_SELECT_MORE},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 173, 186, 14, 24, 0x0, STR_USE_CTRL_TO_SELECT_MORE},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 187, 200, 14, 24, 0x0, STR_USE_CTRL_TO_SELECT_MORE},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 201, 214, 14, 24, 0x0, STR_USE_CTRL_TO_SELECT_MORE},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 215, 228, 14, 24, 0x0, STR_USE_CTRL_TO_SELECT_MORE},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 229, 242, 14, 24, 0x0, STR_USE_CTRL_TO_SELECT_MORE},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 243, 256, 14, 24, 0x0, STR_USE_CTRL_TO_SELECT_MORE},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 257, 270, 14, 24, 0x0, STR_NO_WAITING_CARGO},
|
|
|
|
{ WWT_PANEL, RESIZE_RIGHT, 14, 285, 357, 14, 24, 0x0, STR_NULL},
|
2006-05-11 10:33:58 +00:00
|
|
|
|
|
|
|
//26
|
2006-08-22 14:38:37 +00:00
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 70, 83, 14, 24, 0x0, STR_SELECT_ALL_FACILITIES},
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 271, 284, 14, 24, 0x0, STR_SELECT_ALL_TYPES},
|
2006-05-11 10:33:58 +00:00
|
|
|
|
|
|
|
//28
|
2006-12-07 04:12:29 +00:00
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 0, 80, 25, 36, STR_SORT_BY, STR_SORT_ORDER_TIP},
|
2006-08-22 14:38:37 +00:00
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 81, 232, 25, 36, 0x0, STR_SORT_CRITERIA_TIP},
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 233, 243, 25, 36, STR_0225, STR_SORT_CRITERIA_TIP},
|
2006-11-18 17:34:20 +00:00
|
|
|
{ WWT_PANEL, RESIZE_RIGHT, 14, 244, 357, 25, 36, 0x0, STR_NULL},
|
2004-09-07 21:48:09 +00:00
|
|
|
{ WIDGETS_END},
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const WindowDesc _player_stations_desc = {
|
2006-11-10 19:24:14 +00:00
|
|
|
WDP_AUTO, WDP_AUTO, 358, 162,
|
2004-08-09 17:04:08 +00:00
|
|
|
WC_STATION_LIST,0,
|
2006-12-07 04:12:29 +00:00
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON | WDF_RESIZABLE,
|
2004-08-09 17:04:08 +00:00
|
|
|
_player_stations_widgets,
|
|
|
|
PlayerStationsWndProc
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2005-09-30 20:37:25 +00:00
|
|
|
void ShowPlayerStations(PlayerID player)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
Window *w;
|
|
|
|
|
2006-10-31 21:15:56 +00:00
|
|
|
if (!IsValidPlayer(player)) return;
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
w = AllocateWindowDescFront(&_player_stations_desc, player);
|
2005-10-23 13:04:44 +00:00
|
|
|
if (w != NULL) {
|
2004-08-09 17:04:08 +00:00
|
|
|
w->caption_color = (byte)w->window_number;
|
|
|
|
w->vscroll.cap = 12;
|
2005-01-03 19:45:18 +00:00
|
|
|
w->resize.step_height = 10;
|
|
|
|
w->resize.height = w->height - 10 * 7; // minimum if 5 in the list
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const Widget _station_view_expanded_widgets[] = {
|
2006-04-15 03:08:14 +00:00
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
|
|
|
{ WWT_CAPTION, RESIZE_NONE, 14, 11, 236, 0, 13, STR_300A_0, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
|
|
|
{ WWT_STICKYBOX, RESIZE_NONE, 14, 237, 248, 0, 13, 0x0, STR_STICKY_BUTTON},
|
2006-10-24 14:15:17 +00:00
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 0, 236, 14, 65, 0x0, STR_NULL},
|
2006-04-15 03:08:14 +00:00
|
|
|
{ WWT_SCROLLBAR, RESIZE_NONE, 14, 237, 248, 14, 65, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST},
|
|
|
|
{ WWT_EMPTY, RESIZE_NONE, 0, 0, 0, 0, 0, 0x0, STR_NULL},
|
2006-10-24 14:15:17 +00:00
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 0, 248, 66, 197, 0x0, STR_NULL},
|
2006-04-15 03:08:14 +00:00
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 0, 63, 198, 209, STR_00E4_LOCATION, STR_3053_CENTER_MAIN_VIEW_ON_STATION},
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 64, 128, 198, 209, STR_3033_ACCEPTS, STR_3056_SHOW_LIST_OF_ACCEPTED_CARGO},
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 129, 192, 198, 209, STR_0130_RENAME, STR_3055_CHANGE_NAME_OF_STATION},
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 193, 206, 198, 209, STR_TRAIN, STR_SCHEDULED_TRAINS_TIP },
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 207, 220, 198, 209, STR_LORRY, STR_SCHEDULED_ROAD_VEHICLES_TIP },
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 221, 234, 198, 209, STR_PLANE, STR_SCHEDULED_AIRCRAFT_TIP },
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 235, 248, 198, 209, STR_SHIP, STR_SCHEDULED_SHIPS_TIP },
|
2004-09-07 21:48:09 +00:00
|
|
|
{ WIDGETS_END},
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const Widget _station_view_widgets[] = {
|
2006-04-15 03:08:14 +00:00
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
|
|
|
|
{ WWT_CAPTION, RESIZE_NONE, 14, 11, 236, 0, 13, STR_300A_0, STR_018C_WINDOW_TITLE_DRAG_THIS},
|
|
|
|
{ WWT_STICKYBOX, RESIZE_NONE, 14, 237, 248, 0, 13, 0x0, STR_STICKY_BUTTON},
|
2006-10-24 14:15:17 +00:00
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 0, 236, 14, 65, 0x0, STR_NULL},
|
2006-04-15 03:08:14 +00:00
|
|
|
{ WWT_SCROLLBAR, RESIZE_NONE, 14, 237, 248, 14, 65, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST},
|
2006-10-24 14:15:17 +00:00
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 0, 248, 66, 97, 0x0, STR_NULL},
|
2006-04-15 03:08:14 +00:00
|
|
|
{ WWT_EMPTY, RESIZE_NONE, 0, 0, 0, 0, 0, 0x0, STR_NULL},
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 0, 63, 98, 109, STR_00E4_LOCATION, STR_3053_CENTER_MAIN_VIEW_ON_STATION},
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 64, 128, 98, 109, STR_3032_RATINGS, STR_3054_SHOW_STATION_RATINGS},
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 129, 192, 98, 109, STR_0130_RENAME, STR_3055_CHANGE_NAME_OF_STATION},
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 193, 206, 98, 109, STR_TRAIN, STR_SCHEDULED_TRAINS_TIP },
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 207, 220, 98, 109, STR_LORRY, STR_SCHEDULED_ROAD_VEHICLES_TIP },
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 221, 234, 98, 109, STR_PLANE, STR_SCHEDULED_AIRCRAFT_TIP },
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 235, 248, 98, 109, STR_SHIP, STR_SCHEDULED_SHIPS_TIP },
|
2004-09-07 21:48:09 +00:00
|
|
|
{ WIDGETS_END},
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void DrawStationViewWindow(Window *w)
|
|
|
|
{
|
2005-11-13 13:43:55 +00:00
|
|
|
StationID station_id = w->window_number;
|
|
|
|
const Station* st = GetStation(station_id);
|
|
|
|
uint i;
|
|
|
|
uint num;
|
2004-08-09 17:04:08 +00:00
|
|
|
int x,y;
|
|
|
|
int pos;
|
|
|
|
StringID str;
|
|
|
|
|
|
|
|
num = 1;
|
2005-11-14 19:48:04 +00:00
|
|
|
for (i = 0; i != NUM_CARGO; i++) {
|
2005-10-11 13:54:21 +00:00
|
|
|
if (GB(st->goods[i].waiting_acceptance, 0, 12) != 0) {
|
2004-08-09 17:04:08 +00:00
|
|
|
num++;
|
2005-11-14 19:48:04 +00:00
|
|
|
if (st->goods[i].enroute_from != station_id) num++;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
SetVScrollCount(w, num);
|
|
|
|
|
2006-10-03 02:08:15 +00:00
|
|
|
SetWindowWidgetDisabledState(w, 9, st->owner != _local_player);
|
|
|
|
SetWindowWidgetDisabledState(w, 10, !(st->facilities & FACIL_TRAIN));
|
|
|
|
SetWindowWidgetDisabledState(w, 11, !(st->facilities & FACIL_TRUCK_STOP) && !(st->facilities & FACIL_BUS_STOP));
|
|
|
|
SetWindowWidgetDisabledState(w, 12, !(st->facilities & FACIL_AIRPORT));
|
|
|
|
SetWindowWidgetDisabledState(w, 13, !(st->facilities & FACIL_DOCK));
|
2004-12-10 18:16:08 +00:00
|
|
|
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, st->index);
|
|
|
|
SetDParam(1, st->facilities);
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawWindowWidgets(w);
|
|
|
|
|
|
|
|
x = 2;
|
|
|
|
y = 15;
|
|
|
|
pos = w->vscroll.pos;
|
|
|
|
|
|
|
|
if (--pos < 0) {
|
|
|
|
str = STR_00D0_NOTHING;
|
2005-11-14 19:48:04 +00:00
|
|
|
for (i = 0; i != NUM_CARGO; i++) {
|
2005-10-11 13:54:21 +00:00
|
|
|
if (GB(st->goods[i].waiting_acceptance, 0, 12) != 0) str = STR_EMPTY;
|
2005-11-14 19:48:04 +00:00
|
|
|
}
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, str);
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawString(x, y, STR_0008_WAITING, 0);
|
|
|
|
y += 10;
|
|
|
|
}
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
do {
|
2005-10-11 13:54:21 +00:00
|
|
|
uint waiting = GB(st->goods[i].waiting_acceptance, 0, 12);
|
2005-11-14 19:48:04 +00:00
|
|
|
if (waiting == 0) continue;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
num = (waiting + 5) / 10;
|
|
|
|
if (num != 0) {
|
|
|
|
int cur_x = x;
|
|
|
|
num = min(num, 23);
|
|
|
|
do {
|
|
|
|
DrawSprite(_cargoc.sprites[i], cur_x, y);
|
|
|
|
cur_x += 10;
|
|
|
|
} while (--num);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( st->goods[i].enroute_from == station_id) {
|
|
|
|
if (--pos < 0) {
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(1, waiting);
|
2006-10-20 11:53:29 +00:00
|
|
|
SetDParam(0, i);
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawStringRightAligned(x + 234, y, STR_0009, 0);
|
|
|
|
y += 10;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* enroute */
|
|
|
|
if (--pos < 0) {
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(1, waiting);
|
2006-10-20 11:53:29 +00:00
|
|
|
SetDParam(0, i);
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawStringRightAligned(x + 234, y, STR_000A_EN_ROUTE_FROM, 0);
|
|
|
|
y += 10;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pos > -5 && --pos < 0) {
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, st->goods[i].enroute_from);
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawStringRightAligned(x + 234, y, STR_000B, 0);
|
|
|
|
y += 10;
|
|
|
|
}
|
|
|
|
}
|
2005-11-14 15:22:12 +00:00
|
|
|
} while (pos > -5 && ++i != NUM_CARGO);
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2005-01-03 19:45:18 +00:00
|
|
|
if (IsWindowOfPrototype(w, _station_view_widgets)) {
|
2005-03-25 14:19:33 +00:00
|
|
|
char *b = _userstring;
|
2006-11-06 15:25:02 +00:00
|
|
|
bool first = true;
|
2005-02-06 22:25:27 +00:00
|
|
|
|
2005-03-25 11:32:58 +00:00
|
|
|
b = InlineString(b, STR_000C_ACCEPTS);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-03-25 14:19:33 +00:00
|
|
|
for (i = 0; i != NUM_CARGO; i++) {
|
|
|
|
if (b >= endof(_userstring) - 5 - 1) break;
|
2004-08-09 17:04:08 +00:00
|
|
|
if (st->goods[i].waiting_acceptance & 0x8000) {
|
2006-11-06 15:25:02 +00:00
|
|
|
if (first) {
|
|
|
|
first = false;
|
|
|
|
} else {
|
|
|
|
/* Add a comma if this is not the first item */
|
|
|
|
*b++ = ',';
|
|
|
|
*b++ = ' ';
|
|
|
|
}
|
2005-03-25 11:32:58 +00:00
|
|
|
b = InlineString(b, _cargoc.names_s[i]);
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2006-11-06 15:25:02 +00:00
|
|
|
/* If first is still true then no cargo is accepted */
|
|
|
|
if (first) b = InlineString(b, STR_00D0_NOTHING);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2006-11-06 15:25:02 +00:00
|
|
|
*b = '\0';
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawStringMultiLine(2, 67, STR_SPEC_USERSTRING, 245);
|
|
|
|
} else {
|
|
|
|
DrawString(2, 67, STR_3034_LOCAL_RATING_OF_TRANSPORT, 0);
|
|
|
|
|
|
|
|
y = 77;
|
2005-11-14 19:48:04 +00:00
|
|
|
for (i = 0; i != NUM_CARGO; i++) {
|
2005-02-02 16:16:43 +00:00
|
|
|
if (st->goods[i].enroute_from != INVALID_STATION) {
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, _cargoc.names_s[i]);
|
|
|
|
SetDParam(2, st->goods[i].rating * 101 >> 8);
|
|
|
|
SetDParam(1, STR_3035_APPALLING + (st->goods[i].rating >> 5));
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawString(8, y, STR_303D, 0);
|
|
|
|
y += 10;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void StationViewWndProc(Window *w, WindowEvent *e)
|
|
|
|
{
|
2005-11-14 19:48:04 +00:00
|
|
|
switch (e->event) {
|
2004-08-09 17:04:08 +00:00
|
|
|
case WE_PAINT:
|
|
|
|
DrawStationViewWindow(w);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WE_CLICK:
|
2006-09-23 02:39:24 +00:00
|
|
|
switch (e->we.click.widget) {
|
2004-12-22 01:32:30 +00:00
|
|
|
case 7:
|
2005-01-06 22:31:58 +00:00
|
|
|
ScrollMainWindowToTile(GetStation(w->window_number)->xy);
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
|
|
|
|
2004-12-22 01:32:30 +00:00
|
|
|
case 8:
|
2004-08-09 17:04:08 +00:00
|
|
|
SetWindowDirty(w);
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
/* toggle height/widget set */
|
2005-01-03 19:45:18 +00:00
|
|
|
if (IsWindowOfPrototype(w, _station_view_expanded_widgets)) {
|
|
|
|
AssignWidgetToWindow(w, _station_view_widgets);
|
|
|
|
w->height = 110;
|
|
|
|
} else {
|
|
|
|
AssignWidgetToWindow(w, _station_view_expanded_widgets);
|
2005-01-04 21:28:09 +00:00
|
|
|
w->height = 210;
|
2005-01-03 19:45:18 +00:00
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
SetWindowDirty(w);
|
|
|
|
break;
|
|
|
|
|
2004-12-22 01:32:30 +00:00
|
|
|
case 9: {
|
2005-07-15 18:30:13 +00:00
|
|
|
SetDParam(0, w->window_number);
|
2006-08-19 09:31:22 +00:00
|
|
|
ShowQueryString(STR_STATION, STR_3030_RENAME_STATION_LOADING, 31, 180, w->window_class, w->window_number, CS_ALPHANUMERAL);
|
2005-07-08 22:25:24 +00:00
|
|
|
} break;
|
2004-12-10 18:16:08 +00:00
|
|
|
|
2005-05-14 22:03:25 +00:00
|
|
|
case 10: { /* Show a list of scheduled trains to this station */
|
2005-01-06 22:31:58 +00:00
|
|
|
const Station *st = GetStation(w->window_number);
|
2006-09-28 23:05:03 +00:00
|
|
|
ShowVehicleListWindow(st->owner, w->window_number, VEH_Train);
|
2004-12-10 18:16:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-05-14 22:03:25 +00:00
|
|
|
case 11: { /* Show a list of scheduled road-vehicles to this station */
|
2005-01-06 22:31:58 +00:00
|
|
|
const Station *st = GetStation(w->window_number);
|
2006-09-28 23:05:03 +00:00
|
|
|
ShowVehicleListWindow(st->owner, w->window_number, VEH_Road);
|
2004-12-10 18:16:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-05-14 22:03:25 +00:00
|
|
|
case 12: { /* Show a list of scheduled aircraft to this station */
|
2005-01-06 22:31:58 +00:00
|
|
|
const Station *st = GetStation(w->window_number);
|
2005-05-14 22:03:25 +00:00
|
|
|
/* Since oilrigs have no owners, show the scheduled aircraft of current player */
|
|
|
|
PlayerID owner = (st->owner == OWNER_NONE) ? _current_player : st->owner;
|
2006-09-28 23:05:03 +00:00
|
|
|
ShowVehicleListWindow(owner, w->window_number, VEH_Aircraft);
|
2004-12-10 18:16:08 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-05-14 22:03:25 +00:00
|
|
|
case 13: { /* Show a list of scheduled ships to this station */
|
2005-01-06 22:31:58 +00:00
|
|
|
const Station *st = GetStation(w->window_number);
|
2005-05-14 22:03:25 +00:00
|
|
|
/* Since oilrigs/bouys have no owners, show the scheduled ships of current player */
|
|
|
|
PlayerID owner = (st->owner == OWNER_NONE) ? _current_player : st->owner;
|
2006-09-28 23:05:03 +00:00
|
|
|
ShowVehicleListWindow(owner, w->window_number, VEH_Ship);
|
2004-12-10 18:16:08 +00:00
|
|
|
break;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2005-10-23 13:04:44 +00:00
|
|
|
case WE_ON_EDIT_TEXT:
|
2006-09-23 02:39:24 +00:00
|
|
|
if (e->we.edittext.str[0] != '\0') {
|
|
|
|
_cmd_text = e->we.edittext.str;
|
2005-10-20 17:23:33 +00:00
|
|
|
DoCommandP(0, w->window_number, 0, NULL,
|
2005-05-15 18:50:55 +00:00
|
|
|
CMD_RENAME_STATION | CMD_MSG(STR_3031_CAN_T_RENAME_STATION));
|
|
|
|
}
|
2005-10-23 13:04:44 +00:00
|
|
|
break;
|
2004-12-10 18:16:08 +00:00
|
|
|
|
|
|
|
case WE_DESTROY: {
|
|
|
|
WindowNumber wno =
|
2005-01-06 22:31:58 +00:00
|
|
|
(w->window_number << 16) | GetStation(w->window_number)->owner;
|
2004-12-10 18:16:08 +00:00
|
|
|
|
|
|
|
DeleteWindowById(WC_TRAINS_LIST, wno);
|
|
|
|
DeleteWindowById(WC_ROADVEH_LIST, wno);
|
|
|
|
DeleteWindowById(WC_SHIPS_LIST, wno);
|
|
|
|
DeleteWindowById(WC_AIRCRAFT_LIST, wno);
|
|
|
|
break;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static const WindowDesc _station_view_desc = {
|
2006-11-10 19:24:14 +00:00
|
|
|
WDP_AUTO, WDP_AUTO, 249, 110,
|
2004-08-09 17:04:08 +00:00
|
|
|
WC_STATION_VIEW,0,
|
2004-12-22 01:32:30 +00:00
|
|
|
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON,
|
2004-08-09 17:04:08 +00:00
|
|
|
_station_view_widgets,
|
|
|
|
StationViewWndProc
|
|
|
|
};
|
|
|
|
|
2005-10-07 07:35:15 +00:00
|
|
|
void ShowStationViewWindow(StationID station)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
|
|
|
Window *w;
|
|
|
|
|
|
|
|
w = AllocateWindowDescFront(&_station_view_desc, station);
|
2005-10-23 13:04:44 +00:00
|
|
|
if (w != NULL) {
|
2005-10-20 17:43:13 +00:00
|
|
|
PlayerID owner = GetStation(w->window_number)->owner;
|
|
|
|
if (owner != OWNER_NONE) w->caption_color = owner;
|
2004-08-09 17:04:08 +00:00
|
|
|
w->vscroll.cap = 5;
|
|
|
|
}
|
|
|
|
}
|