2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2007-04-04 01:35:16 +00:00
|
|
|
/** @file station_gui.cpp */
|
|
|
|
|
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 "gui.h"
|
2007-12-19 20:45:46 +00:00
|
|
|
#include "window_gui.h"
|
|
|
|
#include "textbuf_gui.h"
|
2004-08-09 17:04:08 +00:00
|
|
|
#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"
|
2007-01-14 19:57:49 +00:00
|
|
|
#include "table/sprites.h"
|
2007-01-10 18:56:51 +00:00
|
|
|
#include "helpers.hpp"
|
2007-02-20 22:09:21 +00:00
|
|
|
#include "cargotype.h"
|
2007-12-05 17:08:10 +00:00
|
|
|
#include "station_gui.h"
|
2007-12-19 23:35:14 +00:00
|
|
|
#include "station.h"
|
2006-12-07 04:12:29 +00:00
|
|
|
|
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;
|
|
|
|
|
2007-12-05 17:08:10 +00:00
|
|
|
/**
|
|
|
|
* Draw small boxes of cargo amount and ratings data at the given
|
2006-12-09 00:46:02 +00:00
|
|
|
* coordinates. If amount exceeds 576 units, it is shown 'full', same
|
|
|
|
* goes for the rating: at above 90% orso (224) it is also 'full'
|
2007-12-05 17:08:10 +00:00
|
|
|
*
|
2007-04-04 01:35:16 +00:00
|
|
|
* @param x coordinate to draw the box at
|
|
|
|
* @param y coordinate to draw the box at
|
2006-12-09 00:46:02 +00:00
|
|
|
* @param type Cargo type
|
|
|
|
* @param amount Cargo amount
|
2007-12-05 17:08:10 +00:00
|
|
|
* @param rating ratings data for that particular cargo
|
|
|
|
*
|
|
|
|
* @note Each cargo-bar is 16 pixels wide and 6 pixels high
|
|
|
|
* @note Each rating 14 pixels wide and 1 pixel high and is 1 pixel below the cargo-bar
|
|
|
|
*/
|
2006-12-09 00:46:02 +00:00
|
|
|
static void StationsWndShowStationRating(int x, int y, CargoID type, uint amount, byte rating)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2007-12-05 17:08:10 +00:00
|
|
|
static const uint units_full = 576; ///< number of units to show station as 'full'
|
|
|
|
static const uint rating_full = 224; ///< rating needed so it is shown as 'full'
|
|
|
|
|
2007-02-20 22:09:21 +00:00
|
|
|
const CargoSpec *cs = GetCargo(type);
|
2007-02-23 09:56:20 +00:00
|
|
|
if (!cs->IsValid()) return;
|
2007-02-20 22:09:21 +00:00
|
|
|
|
|
|
|
int colour = cs->rating_colour;
|
2007-12-05 17:08:10 +00:00
|
|
|
uint w = (minu(amount, units_full) + 5) / 36;
|
2006-12-09 00:46:02 +00:00
|
|
|
|
|
|
|
/* 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
|
|
|
}
|
|
|
|
|
2007-11-04 00:08:57 +00:00
|
|
|
DrawString(x + 1, y, cs->abbrev, TC_BLACK);
|
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);
|
2007-12-05 17:08:10 +00:00
|
|
|
rating = minu(rating, rating_full) / 16;
|
2006-12-09 00:46:02 +00:00
|
|
|
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
|
|
|
|
2007-03-03 09:40:34 +00:00
|
|
|
r = strcmp(buf1, _bufcache); // sort by name
|
2006-05-11 10:33:58 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2007-11-15 17:54:46 +00:00
|
|
|
static const uint32 _cargo_filter_max = ~0;
|
|
|
|
static uint32 _cargo_filter = _cargo_filter_max;
|
|
|
|
|
2006-05-11 10:33:58 +00:00
|
|
|
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;
|
2007-06-21 14:32:27 +00:00
|
|
|
Money sum1 = 0, sum2 = 0;
|
2006-05-11 10:33:58 +00:00
|
|
|
|
2007-03-03 09:40:34 +00:00
|
|
|
for (CargoID j = 0; j < NUM_CARGO; j++) {
|
2007-11-19 21:02:30 +00:00
|
|
|
if (!HasBit(_cargo_filter, j)) continue;
|
2007-06-22 11:58:59 +00:00
|
|
|
if (!st1->goods[j].cargo.Empty()) sum1 += GetTransportedGoodsIncome(st1->goods[j].cargo.Count(), 20, 50, j);
|
|
|
|
if (!st2->goods[j].cargo.Empty()) sum2 += GetTransportedGoodsIncome(st2->goods[j].cargo.Count(), 20, 50, j);
|
2006-05-11 10:33:58 +00:00
|
|
|
}
|
|
|
|
|
2007-06-21 14:32:27 +00:00
|
|
|
return (_internal_sort_order & 1) ? ClampToI32(sum2 - sum1) : ClampToI32(sum1 - sum2);
|
2006-05-11 10:33:58 +00:00
|
|
|
}
|
|
|
|
|
2007-03-08 12:26:31 +00:00
|
|
|
/**
|
|
|
|
* qsort-compatible version of sorting two stations by maximum rating
|
|
|
|
* @param a First object to be sorted, must be of type (const Station *)
|
|
|
|
* @param b Second object to be sorted, must be of type (const Station *)
|
|
|
|
* @return The sort order
|
|
|
|
* @retval >0 a should come before b in the list
|
|
|
|
* @retval <0 b should come before a in the list
|
|
|
|
*/
|
2006-05-11 10:33:58 +00:00
|
|
|
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;
|
|
|
|
|
2007-03-03 09:40:34 +00:00
|
|
|
for (CargoID j = 0; j < NUM_CARGO; j++) {
|
2007-11-19 21:02:30 +00:00
|
|
|
if (HasBit(st1->goods[j].acceptance_pickup, GoodsEntry::PICKUP)) maxr1 = max(maxr1, st1->goods[j].rating);
|
|
|
|
if (HasBit(st2->goods[j].acceptance_pickup, GoodsEntry::PICKUP)) maxr2 = max(maxr2, st2->goods[j].rating);
|
2006-05-11 10:33:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return (_internal_sort_order & 1) ? maxr2 - maxr1 : maxr1 - maxr2;
|
|
|
|
}
|
|
|
|
|
2007-12-05 17:08:10 +00:00
|
|
|
/** Flags for station list */
|
2007-03-07 12:11:48 +00:00
|
|
|
enum StationListFlags {
|
2007-12-05 17:08:10 +00:00
|
|
|
SL_ORDER = 1 << 0, ///< Order - ascending (=0), descending (=1)
|
|
|
|
SL_RESORT = 1 << 1, ///< Resort the list
|
|
|
|
SL_REBUILD = 1 << 2, ///< Rebuild the list
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2006-05-11 10:33:58 +00:00
|
|
|
|
2007-01-10 18:56:51 +00:00
|
|
|
DECLARE_ENUM_AS_BIT_SET(StationListFlags);
|
|
|
|
|
2007-12-05 17:08:10 +00:00
|
|
|
/** Information about station list */
|
2007-03-07 12:11:48 +00:00
|
|
|
struct plstations_d {
|
2007-12-05 17:08:10 +00:00
|
|
|
const Station** sort_list; ///< Pointer to list of stations
|
|
|
|
uint16 list_length; ///< Number of stations in list
|
|
|
|
uint16 resort_timer; ///< Tick counter to resort the list
|
|
|
|
byte sort_type; ///< Sort type - name, waiting, ...
|
|
|
|
byte flags; ///< Flags - SL_ORDER, SL_RESORT, SL_REBUILD
|
2007-03-07 12:11:48 +00:00
|
|
|
};
|
2006-05-11 10:33:58 +00:00
|
|
|
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(plstations_d));
|
|
|
|
|
2007-12-05 17:08:10 +00:00
|
|
|
/**
|
|
|
|
* Set the 'SL_REBUILD' flag for all station lists
|
|
|
|
*/
|
2007-03-07 11:47:46 +00:00
|
|
|
void RebuildStationLists()
|
2006-05-11 10:33:58 +00:00
|
|
|
{
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-12-05 17:08:10 +00:00
|
|
|
/**
|
|
|
|
* Set the 'SL_RESORT' flag for all station lists
|
|
|
|
*/
|
2007-03-07 11:47:46 +00:00
|
|
|
void ResortStationLists()
|
2006-05-11 10:33:58 +00:00
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
2007-12-05 17:08:10 +00:00
|
|
|
/**
|
|
|
|
* Rebuild station list if the SL_REBUILD flag is set
|
|
|
|
*
|
|
|
|
* @param sl pointer to plstations_d (station list and flags)
|
|
|
|
* @param owner player whose stations are to be in list
|
|
|
|
* @param facilities types of stations of interest
|
|
|
|
* @param cargo_filter bitmap of cargo types to include
|
|
|
|
* @param include_empty whether we should include stations without waiting cargo
|
|
|
|
*/
|
2007-03-09 22:55:57 +00:00
|
|
|
static void BuildStationsList(plstations_d* sl, PlayerID owner, byte facilities, uint32 cargo_filter, bool include_empty)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-05-11 10:33:58 +00:00
|
|
|
uint n = 0;
|
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 */
|
2007-01-11 17:29:39 +00:00
|
|
|
const Station** station_sort = MallocT<const Station*>(GetMaxStationIndex() + 1);
|
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) {
|
2007-12-19 23:35:14 +00:00
|
|
|
if (st->owner == owner || (st->owner == OWNER_NONE && !st->IsBuoy() && HasStationInUse(st->index, owner))) {
|
2006-05-11 10:33:58 +00:00
|
|
|
if (facilities & st->facilities) { //only stations with selected facilities
|
|
|
|
int num_waiting_cargo = 0;
|
2007-03-03 09:40:34 +00:00
|
|
|
for (CargoID j = 0; j < NUM_CARGO; j++) {
|
2007-06-22 11:58:59 +00:00
|
|
|
if (!st->goods[j].cargo.Empty()) {
|
2006-05-11 10:33:58 +00:00
|
|
|
num_waiting_cargo++; //count number of waiting cargo
|
2007-11-19 21:02:30 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-04-04 01:35:16 +00:00
|
|
|
/* stations without waiting cargo */
|
2007-03-09 22:55:57 +00:00
|
|
|
if (num_waiting_cargo == 0 && include_empty) {
|
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);
|
2007-01-11 17:29:39 +00:00
|
|
|
sl->sort_list = MallocT<const Station*>(n);
|
2006-05-11 10:33:58 +00:00
|
|
|
sl->list_length = n;
|
2004-09-06 18:15:13 +00:00
|
|
|
|
2007-03-03 09:40:34 +00:00
|
|
|
for (uint 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
|
|
|
}
|
|
|
|
|
2007-12-05 17:08:10 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Sort station list if the SL_RESORT flag is set
|
|
|
|
*
|
|
|
|
* @param sl pointer to plstations_d (station list and flags)
|
|
|
|
*/
|
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
|
|
|
}
|
|
|
|
|
2007-12-05 17:08:10 +00:00
|
|
|
/**
|
|
|
|
* Fuction called when any WindowEvent occurs for PlayerStations window
|
|
|
|
*
|
|
|
|
* @param w pointer to the PlayerStations window
|
|
|
|
* @param e pointer to window event
|
|
|
|
*/
|
2004-08-09 17:04:08 +00:00
|
|
|
static void PlayerStationsWndProc(Window *w, WindowEvent *e)
|
|
|
|
{
|
2007-01-10 18:56:51 +00:00
|
|
|
const PlayerID owner = (PlayerID)w->window_number;
|
2006-05-11 10:33:58 +00:00
|
|
|
static byte facilities = FACIL_TRAIN | FACIL_TRUCK_STOP | FACIL_BUS_STOP | FACIL_AIRPORT | FACIL_DOCK;
|
2007-01-11 15:30:35 +00:00
|
|
|
static Listing station_sort = {0, 0};
|
2007-03-09 22:55:57 +00:00
|
|
|
static bool include_empty = true;
|
2007-01-11 15:30:35 +00:00
|
|
|
|
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) {
|
2007-12-05 17:08:10 +00:00
|
|
|
case WE_CREATE:
|
2007-03-10 20:05:31 +00:00
|
|
|
if (_cargo_filter == _cargo_filter_max) _cargo_filter = _cargo_mask;
|
2007-03-09 22:55:57 +00:00
|
|
|
|
2007-03-03 09:40:34 +00:00
|
|
|
for (uint i = 0; i < 5; i++) {
|
2007-12-05 17:08:10 +00:00
|
|
|
if (HasBit(facilities, i)) w->LowerWidget(i + SLW_TRAIN);
|
2007-03-03 09:40:34 +00:00
|
|
|
}
|
2007-12-05 17:08:10 +00:00
|
|
|
w->SetWidgetLoweredState(SLW_FACILALL, facilities == (FACIL_TRAIN | FACIL_TRUCK_STOP | FACIL_BUS_STOP | FACIL_AIRPORT | FACIL_DOCK));
|
|
|
|
w->SetWidgetLoweredState(SLW_CARGOALL, _cargo_filter == _cargo_mask && include_empty);
|
|
|
|
w->SetWidgetLoweredState(SLW_NOCARGOWAITING, include_empty);
|
2007-03-03 09:40:34 +00:00
|
|
|
|
|
|
|
sl->sort_list = NULL;
|
|
|
|
sl->flags = SL_REBUILD;
|
|
|
|
sl->sort_type = station_sort.criteria;
|
|
|
|
if (station_sort.order) sl->flags |= SL_ORDER;
|
2007-12-05 17:08:10 +00:00
|
|
|
|
|
|
|
/* set up resort timer */
|
2007-03-03 09:40:34 +00:00
|
|
|
sl->resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS;
|
|
|
|
break;
|
2006-12-07 04:12:29 +00:00
|
|
|
|
2007-03-03 09:40:34 +00:00
|
|
|
case WE_PAINT: {
|
2007-03-09 22:55:57 +00:00
|
|
|
BuildStationsList(sl, owner, facilities, _cargo_filter, include_empty);
|
2007-03-03 09:40:34 +00:00
|
|
|
SortStationsList(sl);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-03-03 09:40:34 +00:00
|
|
|
SetVScrollCount(w, sl->list_length);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-03-03 09:40:34 +00:00
|
|
|
/* draw widgets, with player's name in the caption */
|
2007-06-25 13:30:38 +00:00
|
|
|
SetDParam(0, owner);
|
|
|
|
SetDParam(1, w->vscroll.count);
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawWindowWidgets(w);
|
2006-05-11 10:33:58 +00:00
|
|
|
|
|
|
|
/* draw sorting criteria string */
|
2007-11-04 00:08:57 +00:00
|
|
|
DrawString(85, 26, _station_sort_listing[sl->sort_type], TC_BLACK);
|
2006-05-11 10:33:58 +00:00
|
|
|
/* draw arrow pointing up/down for ascending/descending sorting */
|
2007-11-04 00:08:57 +00:00
|
|
|
DoDrawString(sl->flags & SL_ORDER ? DOWNARROW : UPARROW, 69, 26, TC_BLACK);
|
2006-05-11 10:33:58 +00:00
|
|
|
|
2007-03-03 09:40:34 +00:00
|
|
|
int cg_ofst;
|
|
|
|
int x = 89;
|
|
|
|
int y = 14;
|
2007-04-04 01:35:16 +00:00
|
|
|
int xb = 2; ///< offset from left of widget
|
2006-05-11 10:33:58 +00:00
|
|
|
|
2007-03-09 22:55:57 +00:00
|
|
|
uint i = 0;
|
|
|
|
for (CargoID c = 0; c < NUM_CARGO; c++) {
|
|
|
|
const CargoSpec *cs = GetCargo(c);
|
|
|
|
if (!cs->IsValid()) continue;
|
|
|
|
|
2007-11-19 21:02:30 +00:00
|
|
|
cg_ofst = HasBit(_cargo_filter, c) ? 2 : 1;
|
2007-03-09 22:55:57 +00:00
|
|
|
GfxFillRect(x + cg_ofst, y + cg_ofst, x + cg_ofst + 10 , y + cg_ofst + 7, cs->rating_colour);
|
2007-11-04 00:08:57 +00:00
|
|
|
DrawStringCentered(x + 6 + cg_ofst, y + cg_ofst, cs->abbrev, TC_BLACK);
|
2006-05-11 10:33:58 +00:00
|
|
|
x += 14;
|
2007-03-09 22:55:57 +00:00
|
|
|
i++;
|
2006-05-11 10:33:58 +00:00
|
|
|
}
|
|
|
|
|
2006-12-09 00:41:25 +00:00
|
|
|
x += 6;
|
2007-12-05 17:08:10 +00:00
|
|
|
cg_ofst = w->IsWidgetLowered(SLW_NOCARGOWAITING) ? 2 : 1;
|
2007-11-04 00:08:57 +00:00
|
|
|
DrawStringCentered(x + cg_ofst, y + cg_ofst, STR_ABBREV_NONE, TC_BLACK);
|
2006-05-11 10:33:58 +00:00
|
|
|
x += 14;
|
2007-12-05 17:08:10 +00:00
|
|
|
cg_ofst = w->IsWidgetLowered(SLW_CARGOALL) ? 2 : 1;
|
2007-11-04 00:08:57 +00:00
|
|
|
DrawStringCentered(x + cg_ofst, y + cg_ofst, STR_ABBREV_ALL, TC_BLACK);
|
2006-12-07 04:12:29 +00:00
|
|
|
|
2007-12-05 17:08:10 +00:00
|
|
|
cg_ofst = w->IsWidgetLowered(SLW_FACILALL) ? 2 : 1;
|
2007-11-04 00:08:57 +00:00
|
|
|
DrawString(71 + cg_ofst, y + cg_ofst, STR_ABBREV_ALL, TC_BLACK);
|
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
|
2007-11-04 00:08:57 +00:00
|
|
|
DrawString(xb, 40, STR_304A_NONE, TC_FROMSTRING);
|
2004-08-09 17:04:08 +00:00
|
|
|
return;
|
|
|
|
}
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2007-03-03 09:40:34 +00:00
|
|
|
int max = min(w->vscroll.pos + w->vscroll.cap, sl->list_length);
|
2006-05-11 10:33:58 +00:00
|
|
|
y = 40; // start of the list-widget
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-03-03 09:40:34 +00:00
|
|
|
for (int 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];
|
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);
|
2007-12-19 23:35:14 +00:00
|
|
|
|
|
|
|
/* Do not do the complex check HasStationInUse here, it may be even false
|
|
|
|
* when the order had been removed and the station list hasn't been removed yet */
|
|
|
|
assert(st->owner == owner || (st->owner == OWNER_NONE && !st->IsBuoy()));
|
2004-09-07 19:01:06 +00:00
|
|
|
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, st->index);
|
|
|
|
SetDParam(1, st->facilities);
|
2007-11-04 00:08:57 +00:00
|
|
|
x = DrawString(xb, y, STR_3049_0, TC_FROMSTRING) + 5;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-04-04 01:35:16 +00:00
|
|
|
/* show cargo waiting and station ratings */
|
2007-03-21 13:19:01 +00:00
|
|
|
for (CargoID j = 0; j < NUM_CARGO; j++) {
|
2007-06-22 11:58:59 +00:00
|
|
|
if (!st->goods[j].cargo.Empty()) {
|
|
|
|
StationsWndShowStationRating(x, y, j, st->goods[j].cargo.Count(), st->goods[j].rating);
|
2006-12-09 00:46:02 +00:00
|
|
|
x += 20;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
y += 10;
|
|
|
|
}
|
2007-03-03 09:40:34 +00:00
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
2006-12-07 04:12:29 +00:00
|
|
|
|
2007-03-03 09:40:34 +00:00
|
|
|
case WE_CLICK:
|
|
|
|
switch (e->we.click.widget) {
|
2007-12-05 17:08:10 +00:00
|
|
|
case SLW_LIST: {
|
2007-03-03 09:40:34 +00:00
|
|
|
uint32 id_v = (e->we.click.pt.y - 41) / 10;
|
2006-08-14 21:02:48 +00:00
|
|
|
|
2007-03-03 09:40:34 +00:00
|
|
|
if (id_v >= w->vscroll.cap) return; // click out of bounds
|
2004-09-07 19:01:06 +00:00
|
|
|
|
2007-03-03 09:40:34 +00:00
|
|
|
id_v += w->vscroll.pos;
|
2004-09-07 19:01:06 +00:00
|
|
|
|
2007-03-03 09:40:34 +00:00
|
|
|
if (id_v >= sl->list_length) return; // click out of list bound
|
2004-09-07 19:01:06 +00:00
|
|
|
|
2007-03-03 09:40:34 +00:00
|
|
|
const Station *st = sl->sort_list[id_v];
|
2007-12-19 23:35:14 +00:00
|
|
|
/* do not check HasStationInUse - it is slow and may be invalid */
|
|
|
|
assert(st->owner == owner || (st->owner == OWNER_NONE && !st->IsBuoy()));
|
2007-03-03 09:40:34 +00:00
|
|
|
ScrollMainWindowToTile(st->xy);
|
|
|
|
break;
|
|
|
|
}
|
2004-09-07 19:01:06 +00:00
|
|
|
|
2007-12-05 17:08:10 +00:00
|
|
|
case SLW_TRAIN:
|
|
|
|
case SLW_TRUCK:
|
|
|
|
case SLW_BUS:
|
|
|
|
case SLW_AIRPLANE:
|
|
|
|
case SLW_SHIP:
|
2007-03-03 09:40:34 +00:00
|
|
|
if (_ctrl_pressed) {
|
2007-12-05 17:08:10 +00:00
|
|
|
ToggleBit(facilities, e->we.click.widget - SLW_TRAIN);
|
2007-12-02 14:29:48 +00:00
|
|
|
w->ToggleWidgetLoweredState(e->we.click.widget);
|
2007-03-03 09:40:34 +00:00
|
|
|
} else {
|
2007-12-03 09:19:19 +00:00
|
|
|
uint i;
|
|
|
|
FOR_EACH_SET_BIT(i, facilities) {
|
2007-12-05 17:08:10 +00:00
|
|
|
w->RaiseWidget(i + SLW_TRAIN);
|
2007-03-03 09:40:34 +00:00
|
|
|
}
|
2007-12-05 17:08:10 +00:00
|
|
|
SetBit(facilities, e->we.click.widget - SLW_TRAIN);
|
2007-12-02 14:29:48 +00:00
|
|
|
w->LowerWidget(e->we.click.widget);
|
2007-03-03 09:40:34 +00:00
|
|
|
}
|
2007-12-05 17:08:10 +00:00
|
|
|
w->SetWidgetLoweredState(SLW_FACILALL, facilities == (FACIL_TRAIN | FACIL_TRUCK_STOP | FACIL_BUS_STOP | FACIL_AIRPORT | FACIL_DOCK));
|
2007-03-03 09:40:34 +00:00
|
|
|
sl->flags |= SL_REBUILD;
|
|
|
|
SetWindowDirty(w);
|
|
|
|
break;
|
|
|
|
|
2007-12-05 17:08:10 +00:00
|
|
|
case SLW_FACILALL:
|
2007-03-03 09:40:34 +00:00
|
|
|
for (uint i = 0; i < 5; i++) {
|
2007-12-05 17:08:10 +00:00
|
|
|
w->LowerWidget(i + SLW_TRAIN);
|
2007-03-03 09:40:34 +00:00
|
|
|
}
|
2007-12-05 17:08:10 +00:00
|
|
|
w->LowerWidget(SLW_FACILALL);
|
2004-09-07 19:01:06 +00:00
|
|
|
|
2007-03-03 09:40:34 +00:00
|
|
|
facilities = FACIL_TRAIN | FACIL_TRUCK_STOP | FACIL_BUS_STOP | FACIL_AIRPORT | FACIL_DOCK;
|
|
|
|
sl->flags |= SL_REBUILD;
|
|
|
|
SetWindowDirty(w);
|
|
|
|
break;
|
2006-12-07 04:12:29 +00:00
|
|
|
|
2007-12-05 17:08:10 +00:00
|
|
|
case SLW_CARGOALL: {
|
2007-03-09 22:55:57 +00:00
|
|
|
uint i = 0;
|
|
|
|
for (CargoID c = 0; c < NUM_CARGO; c++) {
|
|
|
|
if (!GetCargo(c)->IsValid()) continue;
|
2007-12-05 17:08:10 +00:00
|
|
|
w->LowerWidget(i + SLW_CARGOSTART);
|
2007-03-09 22:55:57 +00:00
|
|
|
i++;
|
2007-03-03 09:40:34 +00:00
|
|
|
}
|
2007-12-05 17:08:10 +00:00
|
|
|
w->LowerWidget(SLW_NOCARGOWAITING);
|
|
|
|
w->LowerWidget(SLW_CARGOALL);
|
2007-03-03 09:40:34 +00:00
|
|
|
|
2007-03-09 22:55:57 +00:00
|
|
|
_cargo_filter = _cargo_mask;
|
|
|
|
include_empty = true;
|
2007-03-03 09:40:34 +00:00
|
|
|
sl->flags |= SL_REBUILD;
|
|
|
|
SetWindowDirty(w);
|
|
|
|
break;
|
2007-03-09 22:55:57 +00:00
|
|
|
}
|
2007-03-03 09:40:34 +00:00
|
|
|
|
2007-12-05 17:08:10 +00:00
|
|
|
case SLW_SORTBY: // flip sorting method asc/desc
|
2007-03-03 09:40:34 +00:00
|
|
|
sl->flags ^= SL_ORDER; //DESC-flag
|
2007-11-19 21:02:30 +00:00
|
|
|
station_sort.order = HasBit(sl->flags, 0);
|
2007-03-03 09:40:34 +00:00
|
|
|
sl->flags |= SL_RESORT;
|
|
|
|
w->flags4 |= 5 << WF_TIMEOUT_SHL;
|
2007-12-05 17:08:10 +00:00
|
|
|
w->LowerWidget(SLW_SORTBY);
|
2007-03-03 09:40:34 +00:00
|
|
|
SetWindowDirty(w);
|
|
|
|
break;
|
|
|
|
|
2007-12-05 17:08:10 +00:00
|
|
|
case SLW_SORTCRITERIA:
|
|
|
|
case SLW_SORTDROPBTN: // select sorting criteria dropdown menu
|
|
|
|
ShowDropDownMenu(w, _station_sort_listing, sl->sort_type, SLW_SORTDROPBTN, 0, 0);
|
2007-03-03 09:40:34 +00:00
|
|
|
break;
|
|
|
|
|
2007-12-05 17:08:10 +00:00
|
|
|
case SLW_NOCARGOWAITING:
|
2007-03-09 22:55:57 +00:00
|
|
|
if (_ctrl_pressed) {
|
|
|
|
include_empty = !include_empty;
|
2007-12-05 17:08:10 +00:00
|
|
|
w->ToggleWidgetLoweredState(SLW_NOCARGOWAITING);
|
2007-03-09 22:55:57 +00:00
|
|
|
} else {
|
2007-12-05 17:08:10 +00:00
|
|
|
for (uint i = SLW_CARGOSTART; i < w->widget_count; i++) {
|
2007-12-02 14:29:48 +00:00
|
|
|
w->RaiseWidget(i);
|
2007-03-09 22:55:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_cargo_filter = 0;
|
|
|
|
include_empty = true;
|
|
|
|
|
2007-12-05 17:08:10 +00:00
|
|
|
w->LowerWidget(SLW_NOCARGOWAITING);
|
2007-03-09 22:55:57 +00:00
|
|
|
}
|
|
|
|
sl->flags |= SL_REBUILD;
|
2007-12-05 17:08:10 +00:00
|
|
|
w->SetWidgetLoweredState(SLW_CARGOALL, _cargo_filter == _cargo_mask && include_empty);
|
2007-03-09 22:55:57 +00:00
|
|
|
SetWindowDirty(w);
|
|
|
|
break;
|
|
|
|
|
2007-03-03 09:40:34 +00:00
|
|
|
default:
|
2007-12-05 17:08:10 +00:00
|
|
|
if (e->we.click.widget >= SLW_CARGOSTART) { // change cargo_filter
|
2007-03-09 22:55:57 +00:00
|
|
|
/* Determine the selected cargo type */
|
|
|
|
CargoID c;
|
|
|
|
int i = 0;
|
|
|
|
for (c = 0; c < NUM_CARGO; c++) {
|
|
|
|
if (!GetCargo(c)->IsValid()) continue;
|
2007-12-05 17:08:10 +00:00
|
|
|
if (e->we.click.widget - SLW_CARGOSTART == i) break;
|
2007-03-09 22:55:57 +00:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
2007-03-03 09:40:34 +00:00
|
|
|
if (_ctrl_pressed) {
|
2007-11-20 14:11:19 +00:00
|
|
|
ToggleBit(_cargo_filter, c);
|
2007-12-02 14:29:48 +00:00
|
|
|
w->ToggleWidgetLoweredState(e->we.click.widget);
|
2007-03-03 09:40:34 +00:00
|
|
|
} else {
|
2007-12-05 17:08:10 +00:00
|
|
|
for (uint i = SLW_CARGOSTART; i < w->widget_count; i++) {
|
2007-12-02 14:29:48 +00:00
|
|
|
w->RaiseWidget(i);
|
2007-03-03 09:40:34 +00:00
|
|
|
}
|
2007-12-05 17:08:10 +00:00
|
|
|
w->RaiseWidget(SLW_NOCARGOWAITING);
|
2007-03-09 22:55:57 +00:00
|
|
|
|
|
|
|
_cargo_filter = 0;
|
|
|
|
include_empty = false;
|
|
|
|
|
2007-11-20 13:35:54 +00:00
|
|
|
SetBit(_cargo_filter, c);
|
2007-12-02 14:29:48 +00:00
|
|
|
w->LowerWidget(e->we.click.widget);
|
2007-03-03 09:40:34 +00:00
|
|
|
}
|
|
|
|
sl->flags |= SL_REBUILD;
|
2007-12-05 17:08:10 +00:00
|
|
|
w->SetWidgetLoweredState(SLW_CARGOALL, _cargo_filter == _cargo_mask && include_empty);
|
2007-03-03 09:40:34 +00:00
|
|
|
SetWindowDirty(w);
|
|
|
|
}
|
|
|
|
break;
|
2006-10-03 20:16:20 +00:00
|
|
|
}
|
2006-05-11 10:33:58 +00:00
|
|
|
break;
|
2006-10-03 20:16:20 +00:00
|
|
|
|
2007-12-05 17:08:10 +00:00
|
|
|
case WE_DROPDOWN_SELECT: // we have selected a dropdown item in the list
|
2007-03-03 09:40:34 +00:00
|
|
|
if (sl->sort_type != e->we.dropdown.index) {
|
2007-04-04 01:35:16 +00:00
|
|
|
/* value has changed -> resort */
|
2007-03-03 09:40:34 +00:00
|
|
|
sl->sort_type = e->we.dropdown.index;
|
|
|
|
station_sort.criteria = sl->sort_type;
|
|
|
|
sl->flags |= SL_RESORT;
|
|
|
|
}
|
2006-05-11 10:33:58 +00:00
|
|
|
SetWindowDirty(w);
|
|
|
|
break;
|
2007-03-03 09:40:34 +00:00
|
|
|
|
|
|
|
case WE_TICK:
|
|
|
|
if (--sl->resort_timer == 0) {
|
|
|
|
DEBUG(misc, 3, "Periodic rebuild station list player %d", owner);
|
|
|
|
sl->resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS;
|
2006-05-11 10:33:58 +00:00
|
|
|
sl->flags |= SL_REBUILD;
|
|
|
|
SetWindowDirty(w);
|
|
|
|
}
|
2007-03-03 09:40:34 +00:00
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-03-03 09:40:34 +00:00
|
|
|
case WE_TIMEOUT:
|
2007-12-05 17:08:10 +00:00
|
|
|
w->RaiseWidget(SLW_SORTBY);
|
2004-08-09 17:04:08 +00:00
|
|
|
SetWindowDirty(w);
|
2007-03-03 09:40:34 +00:00
|
|
|
break;
|
2006-05-11 10:33:58 +00:00
|
|
|
|
2007-03-03 09:40:34 +00:00
|
|
|
case WE_RESIZE:
|
|
|
|
w->vscroll.cap += e->we.sizing.diff.y / 10;
|
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const Widget _player_stations_widgets[] = {
|
2007-12-05 17:08:10 +00:00
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, // SLW_CLOSEBOX
|
2006-04-15 03:08:14 +00:00
|
|
|
{ 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},
|
2007-12-05 17:08:10 +00:00
|
|
|
{ WWT_PANEL, RESIZE_RB, 14, 0, 345, 37, 161, 0x0, STR_3057_STATION_NAMES_CLICK_ON}, // SLW_LIST
|
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},
|
2007-12-05 17:08:10 +00:00
|
|
|
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 0, 13, 14, 24, STR_TRAIN, STR_USE_CTRL_TO_SELECT_MORE}, // SLW_TRAIN
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 14, 27, 14, 24, STR_LORRY, STR_USE_CTRL_TO_SELECT_MORE}, // SLW_TRUCK
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 28, 41, 14, 24, STR_BUS, STR_USE_CTRL_TO_SELECT_MORE}, // SLW_BUS
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 42, 55, 14, 24, STR_PLANE, STR_USE_CTRL_TO_SELECT_MORE}, // SLW_AIRPLANE
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 56, 69, 14, 24, STR_SHIP, STR_USE_CTRL_TO_SELECT_MORE}, // SLW_SHIP
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 70, 83, 14, 24, 0x0, STR_SELECT_ALL_FACILITIES}, // SLW_FACILALL
|
|
|
|
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 83, 88, 14, 24, 0x0, STR_NULL}, // SLW_PAN_BETWEEN
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 89, 102, 14, 24, 0x0, STR_NO_WAITING_CARGO}, // SLW_NOCARGOWAITING
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 103, 116, 14, 24, 0x0, STR_SELECT_ALL_TYPES}, // SLW_CARGOALL
|
|
|
|
{ WWT_PANEL, RESIZE_RIGHT, 14, 117, 357, 14, 24, 0x0, STR_NULL}, // SLW_PAN_RIGHT
|
|
|
|
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 0, 80, 25, 36, STR_SORT_BY, STR_SORT_ORDER_TIP}, // SLW_SORTBY
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 81, 232, 25, 36, 0x0, STR_SORT_CRITERIA_TIP}, // SLW_SORTCRITERIA
|
|
|
|
{ WWT_TEXTBTN, RESIZE_NONE, 14, 233, 243, 25, 36, STR_0225, STR_SORT_CRITERIA_TIP}, // SLW_SORTDROPBTN
|
|
|
|
{ WWT_PANEL, RESIZE_RIGHT, 14, 244, 357, 25, 36, 0x0, STR_NULL}, // SLW_PAN_SORT_RIGHT
|
2004-09-07 21:48:09 +00:00
|
|
|
{ WIDGETS_END},
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const WindowDesc _player_stations_desc = {
|
2007-07-27 12:49:04 +00:00
|
|
|
WDP_AUTO, WDP_AUTO, 358, 162, 358, 162,
|
2007-02-01 15:49:12 +00:00
|
|
|
WC_STATION_LIST, WC_NONE,
|
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
|
|
|
|
};
|
|
|
|
|
2007-12-05 17:08:10 +00:00
|
|
|
/**
|
|
|
|
* Opens window with list of player's stations
|
|
|
|
*
|
|
|
|
* @param player player whose stations' list show
|
|
|
|
*/
|
2005-09-30 20:37:25 +00:00
|
|
|
void ShowPlayerStations(PlayerID player)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2006-10-31 21:15:56 +00:00
|
|
|
if (!IsValidPlayer(player)) return;
|
|
|
|
|
2007-03-03 09:40:34 +00:00
|
|
|
Window *w = AllocateWindowDescFront(&_player_stations_desc, player);
|
|
|
|
if (w == NULL) return;
|
|
|
|
|
|
|
|
w->caption_color = (byte)w->window_number;
|
|
|
|
w->vscroll.cap = 12;
|
|
|
|
w->resize.step_height = 10;
|
|
|
|
w->resize.height = w->height - 10 * 7; // minimum if 5 in the list
|
2007-03-09 22:55:57 +00:00
|
|
|
|
|
|
|
/* Add cargo filter buttons */
|
|
|
|
uint num_active = 0;
|
|
|
|
for (CargoID c = 0; c < NUM_CARGO; c++) {
|
|
|
|
if (GetCargo(c)->IsValid()) num_active++;
|
|
|
|
}
|
|
|
|
|
|
|
|
w->widget_count += num_active;
|
|
|
|
w->widget = ReallocT(w->widget, w->widget_count + 1);
|
|
|
|
w->widget[w->widget_count].type = WWT_LAST;
|
|
|
|
|
|
|
|
uint i = 0;
|
|
|
|
for (CargoID c = 0; c < NUM_CARGO; c++) {
|
|
|
|
if (!GetCargo(c)->IsValid()) continue;
|
|
|
|
|
2007-12-05 17:08:10 +00:00
|
|
|
Widget *wi = &w->widget[SLW_CARGOSTART + i];
|
2007-03-09 22:55:57 +00:00
|
|
|
wi->type = WWT_PANEL;
|
|
|
|
wi->display_flags = RESIZE_NONE;
|
|
|
|
wi->color = 14;
|
|
|
|
wi->left = 89 + i * 14;
|
|
|
|
wi->right = wi->left + 13;
|
|
|
|
wi->top = 14;
|
|
|
|
wi->bottom = 24;
|
|
|
|
wi->data = 0;
|
|
|
|
wi->tooltips = STR_USE_CTRL_TO_SELECT_MORE;
|
|
|
|
|
2007-12-05 17:08:10 +00:00
|
|
|
if (HasBit(_cargo_filter, c)) w->LowerWidget(SLW_CARGOSTART + i);
|
2007-03-09 22:55:57 +00:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
2007-12-05 17:08:10 +00:00
|
|
|
w->widget[SLW_NOCARGOWAITING].left += num_active * 14;
|
|
|
|
w->widget[SLW_NOCARGOWAITING].right += num_active * 14;
|
|
|
|
w->widget[SLW_CARGOALL].left += num_active * 14;
|
|
|
|
w->widget[SLW_CARGOALL].right += num_active * 14;
|
|
|
|
w->widget[SLW_PAN_RIGHT].left += num_active * 14;
|
2007-03-09 22:55:57 +00:00
|
|
|
|
|
|
|
if (num_active > 15) {
|
|
|
|
/* Resize and fix the minimum width, if necessary */
|
|
|
|
ResizeWindow(w, (num_active - 15) * 14, 0);
|
|
|
|
w->resize.width = w->width;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const Widget _station_view_expanded_widgets[] = {
|
2007-12-05 17:08:10 +00:00
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, // SVW_CLOSEBOX
|
2006-04-15 03:08:14 +00:00
|
|
|
{ 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},
|
2007-12-05 17:08:10 +00:00
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 0, 236, 14, 65, 0x0, STR_NULL}, // SVW_WAITING
|
2006-04-15 03:08:14 +00:00
|
|
|
{ WWT_SCROLLBAR, RESIZE_NONE, 14, 237, 248, 14, 65, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST},
|
2007-12-05 17:08:10 +00:00
|
|
|
{ WWT_EMPTY, RESIZE_NONE, 0, 0, 0, 0, 0, 0x0, STR_NULL}, // SVW_ACCEPTLIST
|
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 0, 248, 66, 197, 0x0, STR_NULL}, // SVW_RATINGLIST
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 0, 63, 198, 209, STR_00E4_LOCATION, STR_3053_CENTER_MAIN_VIEW_ON_STATION}, // SVW_LOCATION
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 64, 128, 198, 209, STR_3033_ACCEPTS, STR_3056_SHOW_LIST_OF_ACCEPTED_CARGO}, // SVW_ACCEPTS
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 129, 192, 198, 209, STR_0130_RENAME, STR_3055_CHANGE_NAME_OF_STATION}, // SVW_RENAME
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 193, 206, 198, 209, STR_TRAIN, STR_SCHEDULED_TRAINS_TIP }, // SVW_TRAINS
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 207, 220, 198, 209, STR_LORRY, STR_SCHEDULED_ROAD_VEHICLES_TIP }, // SVW_ROADVEHS
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 221, 234, 198, 209, STR_PLANE, STR_SCHEDULED_AIRCRAFT_TIP }, // SVW_PLANES
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 235, 248, 198, 209, STR_SHIP, STR_SCHEDULED_SHIPS_TIP }, // SVW_SHIPS
|
2004-09-07 21:48:09 +00:00
|
|
|
{ WIDGETS_END},
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const Widget _station_view_widgets[] = {
|
2007-12-05 17:08:10 +00:00
|
|
|
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, // SVW_CLOSEBOX
|
2006-04-15 03:08:14 +00:00
|
|
|
{ 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},
|
2007-12-05 17:08:10 +00:00
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 0, 236, 14, 65, 0x0, STR_NULL}, // SVW_WAITING
|
2006-04-15 03:08:14 +00:00
|
|
|
{ WWT_SCROLLBAR, RESIZE_NONE, 14, 237, 248, 14, 65, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST},
|
2007-12-05 17:08:10 +00:00
|
|
|
{ WWT_PANEL, RESIZE_NONE, 14, 0, 248, 66, 97, 0x0, STR_NULL}, // SVW_ACCEPTLIST
|
|
|
|
{ WWT_EMPTY, RESIZE_NONE, 0, 0, 0, 0, 0, 0x0, STR_NULL}, // SVW_RATINGLIST
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 0, 63, 98, 109, STR_00E4_LOCATION, STR_3053_CENTER_MAIN_VIEW_ON_STATION}, // SVW_LOCATION
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 64, 128, 98, 109, STR_3032_RATINGS, STR_3054_SHOW_STATION_RATINGS}, // SVW_RATINGS
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 129, 192, 98, 109, STR_0130_RENAME, STR_3055_CHANGE_NAME_OF_STATION}, // SVW_RENAME
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 193, 206, 98, 109, STR_TRAIN, STR_SCHEDULED_TRAINS_TIP }, // SVW_TRAINS
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 207, 220, 98, 109, STR_LORRY, STR_SCHEDULED_ROAD_VEHICLES_TIP }, // SVW_ROADVEHS
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 221, 234, 98, 109, STR_PLANE, STR_SCHEDULED_AIRCRAFT_TIP }, // SVW_PLANES
|
|
|
|
{ WWT_PUSHTXTBTN, RESIZE_NONE, 14, 235, 248, 98, 109, STR_SHIP, STR_SCHEDULED_SHIPS_TIP }, // SVW_SHIPS
|
2004-09-07 21:48:09 +00:00
|
|
|
{ WIDGETS_END},
|
2004-08-09 17:04:08 +00:00
|
|
|
};
|
|
|
|
|
2007-12-05 17:08:10 +00:00
|
|
|
/**
|
|
|
|
* Draws icons of wainting cargo in the StationView window
|
|
|
|
*
|
|
|
|
* @param i type of cargo
|
|
|
|
* @param waiting number of wainting units
|
|
|
|
* @param x x on-screen coordinate where to start with drawing icons
|
|
|
|
* @param y y coordinate
|
|
|
|
*/
|
2007-03-23 20:51:42 +00:00
|
|
|
static void DrawCargoIcons(CargoID i, uint waiting, int x, int y)
|
|
|
|
{
|
2007-12-05 17:08:10 +00:00
|
|
|
uint num = min((waiting + 5) / 10, 23); // maximum is 23 icons so it won't overflow
|
2007-03-23 20:51:42 +00:00
|
|
|
if (num == 0) return;
|
|
|
|
|
|
|
|
const CargoSpec *cs = GetCargo(i);
|
2007-03-23 20:55:45 +00:00
|
|
|
SpriteID sprite;
|
|
|
|
|
|
|
|
if (cs->sprite == 0xFFFF) {
|
|
|
|
/* A value of 0xFFFF indicates we should draw a custom icon */
|
|
|
|
sprite = GetCustomCargoSprite(cs);
|
|
|
|
} else {
|
|
|
|
sprite = cs->sprite;
|
|
|
|
}
|
|
|
|
|
2007-05-20 09:17:42 +00:00
|
|
|
if (sprite == 0) sprite = SPR_CARGO_GOODS;
|
2007-03-23 20:51:42 +00:00
|
|
|
|
|
|
|
do {
|
|
|
|
DrawSprite(sprite, PAL_NONE, x, y);
|
|
|
|
x += 10;
|
|
|
|
} while (--num);
|
|
|
|
}
|
|
|
|
|
2007-12-05 17:08:10 +00:00
|
|
|
/**
|
|
|
|
* Redraws whole StationView window
|
|
|
|
*
|
|
|
|
* @param w pointer to window
|
|
|
|
*/
|
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);
|
2007-12-05 17:08:10 +00:00
|
|
|
uint num; ///< number of cargo types waiting at station
|
|
|
|
int x, y; ///< coordinates used for printing waiting/accepted/rating of cargo
|
|
|
|
int pos; ///< = w->vscroll.pos
|
2004-08-09 17:04:08 +00:00
|
|
|
StringID str;
|
|
|
|
|
2007-12-05 17:08:10 +00:00
|
|
|
/* count types of cargos waiting in station */
|
2004-08-09 17:04:08 +00:00
|
|
|
num = 1;
|
2007-03-21 13:19:01 +00:00
|
|
|
for (CargoID i = 0; i < NUM_CARGO; i++) {
|
2007-06-22 11:58:59 +00:00
|
|
|
if (!st->goods[i].cargo.Empty()) {
|
2004-08-09 17:04:08 +00:00
|
|
|
num++;
|
2007-06-22 11:58:59 +00:00
|
|
|
if (st->goods[i].cargo.Source() != station_id) num++;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
2007-12-05 17:08:10 +00:00
|
|
|
SetVScrollCount(w, num); // update scrollbar
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-12-05 17:08:10 +00:00
|
|
|
/* disable some buttons */
|
|
|
|
w->SetWidgetDisabledState(SVW_RENAME, st->owner != _local_player);
|
|
|
|
w->SetWidgetDisabledState(SVW_TRAINS, !(st->facilities & FACIL_TRAIN));
|
|
|
|
w->SetWidgetDisabledState(SVW_ROADVEHS, !(st->facilities & FACIL_TRUCK_STOP) && !(st->facilities & FACIL_BUS_STOP));
|
|
|
|
w->SetWidgetDisabledState(SVW_PLANES, !(st->facilities & FACIL_AIRPORT));
|
|
|
|
w->SetWidgetDisabledState(SVW_SHIPS, !(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;
|
2007-03-21 13:19:01 +00:00
|
|
|
for (CargoID i = 0; i < NUM_CARGO; i++) {
|
2007-06-22 11:58:59 +00:00
|
|
|
if (!st->goods[i].cargo.Empty()) str = STR_EMPTY;
|
2005-11-14 19:48:04 +00:00
|
|
|
}
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(0, str);
|
2007-11-04 00:08:57 +00:00
|
|
|
DrawString(x, y, STR_0008_WAITING, TC_FROMSTRING);
|
2004-08-09 17:04:08 +00:00
|
|
|
y += 10;
|
|
|
|
}
|
|
|
|
|
2007-03-21 13:19:01 +00:00
|
|
|
for (CargoID i = 0; i < NUM_CARGO && pos > -5; i++) {
|
2007-06-22 11:58:59 +00:00
|
|
|
uint waiting = st->goods[i].cargo.Count();
|
2005-11-14 19:48:04 +00:00
|
|
|
if (waiting == 0) continue;
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2007-06-22 11:58:59 +00:00
|
|
|
if (st->goods[i].cargo.Source() == station_id) {
|
2004-08-09 17:04:08 +00:00
|
|
|
if (--pos < 0) {
|
2007-03-23 20:51:42 +00:00
|
|
|
DrawCargoIcons(i, waiting, x, y);
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(1, waiting);
|
2006-10-20 11:53:29 +00:00
|
|
|
SetDParam(0, i);
|
2007-11-04 00:08:57 +00:00
|
|
|
DrawStringRightAligned(x + 234, y, STR_0009, TC_FROMSTRING);
|
2004-08-09 17:04:08 +00:00
|
|
|
y += 10;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* enroute */
|
|
|
|
if (--pos < 0) {
|
2007-03-23 20:51:42 +00:00
|
|
|
DrawCargoIcons(i, waiting, x, y);
|
2004-12-02 22:53:07 +00:00
|
|
|
SetDParam(1, waiting);
|
2006-10-20 11:53:29 +00:00
|
|
|
SetDParam(0, i);
|
2007-11-04 00:08:57 +00:00
|
|
|
DrawStringRightAligned(x + 234, y, STR_000A_EN_ROUTE_FROM, TC_FROMSTRING);
|
2004-08-09 17:04:08 +00:00
|
|
|
y += 10;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pos > -5 && --pos < 0) {
|
2007-06-22 11:58:59 +00:00
|
|
|
SetDParam(0, st->goods[i].cargo.Source());
|
2007-11-04 00:08:57 +00:00
|
|
|
DrawStringRightAligned(x + 234, y, STR_000B, TC_FROMSTRING);
|
2004-08-09 17:04:08 +00:00
|
|
|
y += 10;
|
|
|
|
}
|
|
|
|
}
|
2007-03-08 19:23:49 +00:00
|
|
|
}
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2007-12-05 17:08:10 +00:00
|
|
|
if (IsWindowOfPrototype(w, _station_view_widgets)) { // small window with list of accepted cargo
|
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
|
|
|
|
2007-03-21 13:19:01 +00:00
|
|
|
for (CargoID i = 0; i < NUM_CARGO; i++) {
|
2007-12-08 18:50:39 +00:00
|
|
|
if (b >= lastof(_userstring) - (1 + 2 * 4)) break; // ',' or ' ' and two calls to Utf8Encode()
|
2007-11-19 21:02:30 +00:00
|
|
|
if (HasBit(st->goods[i].acceptance_pickup, GoodsEntry::ACCEPTANCE)) {
|
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++ = ' ';
|
|
|
|
}
|
2007-02-20 22:09:21 +00:00
|
|
|
b = InlineString(b, GetCargo(i)->name);
|
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';
|
2007-12-08 18:50:39 +00:00
|
|
|
|
|
|
|
/* Make sure we detect any buffer overflow */
|
|
|
|
assert(b < endof(_userstring));
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
DrawStringMultiLine(2, 67, STR_SPEC_USERSTRING, 245);
|
2007-12-05 17:08:10 +00:00
|
|
|
} else { // extended window with list of cargo ratings
|
2007-11-04 00:08:57 +00:00
|
|
|
DrawString(2, 67, STR_3034_LOCAL_RATING_OF_TRANSPORT, TC_FROMSTRING);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
y = 77;
|
2007-03-21 13:19:01 +00:00
|
|
|
for (CargoID i = 0; i < NUM_CARGO; i++) {
|
2007-03-11 22:29:37 +00:00
|
|
|
const CargoSpec *cs = GetCargo(i);
|
|
|
|
if (!cs->IsValid()) continue;
|
|
|
|
|
|
|
|
const GoodsEntry *ge = &st->goods[i];
|
2007-11-19 21:02:30 +00:00
|
|
|
if (!HasBit(ge->acceptance_pickup, GoodsEntry::PICKUP)) continue;
|
2007-03-11 22:29:37 +00:00
|
|
|
|
|
|
|
SetDParam(0, cs->name);
|
|
|
|
SetDParam(2, ge->rating * 101 >> 8);
|
|
|
|
SetDParam(1, STR_3035_APPALLING + (ge->rating >> 5));
|
2007-11-04 00:08:57 +00:00
|
|
|
DrawString(8, y, STR_303D, TC_FROMSTRING);
|
2007-03-11 22:29:37 +00:00
|
|
|
y += 10;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-12-05 17:08:10 +00:00
|
|
|
/**
|
|
|
|
* Fuction called when any WindowEvent occurs for any StationView window
|
|
|
|
*
|
|
|
|
* @param w pointer to the StationView window
|
|
|
|
* @param e pointer to window event
|
|
|
|
*/
|
2004-08-09 17:04:08 +00:00
|
|
|
static void StationViewWndProc(Window *w, WindowEvent *e)
|
|
|
|
{
|
2005-11-14 19:48:04 +00:00
|
|
|
switch (e->event) {
|
2007-03-03 09:40:34 +00:00
|
|
|
case WE_PAINT:
|
|
|
|
DrawStationViewWindow(w);
|
2004-08-09 17:04:08 +00:00
|
|
|
break;
|
|
|
|
|
2007-03-03 09:40:34 +00:00
|
|
|
case WE_CLICK:
|
|
|
|
switch (e->we.click.widget) {
|
2007-12-05 17:08:10 +00:00
|
|
|
case SVW_LOCATION:
|
2007-03-03 09:40:34 +00:00
|
|
|
ScrollMainWindowToTile(GetStation(w->window_number)->xy);
|
|
|
|
break;
|
|
|
|
|
2007-12-05 17:08:10 +00:00
|
|
|
case SVW_RATINGS:
|
2007-03-03 09:40:34 +00:00
|
|
|
SetWindowDirty(w);
|
|
|
|
|
|
|
|
/* toggle height/widget set */
|
|
|
|
if (IsWindowOfPrototype(w, _station_view_expanded_widgets)) {
|
|
|
|
AssignWidgetToWindow(w, _station_view_widgets);
|
|
|
|
w->height = 110;
|
|
|
|
} else {
|
|
|
|
AssignWidgetToWindow(w, _station_view_expanded_widgets);
|
|
|
|
w->height = 210;
|
|
|
|
}
|
2004-09-10 19:02:27 +00:00
|
|
|
|
2007-03-03 09:40:34 +00:00
|
|
|
SetWindowDirty(w);
|
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-12-05 17:08:10 +00:00
|
|
|
case SVW_RENAME:
|
2007-03-03 09:40:34 +00:00
|
|
|
SetDParam(0, w->window_number);
|
|
|
|
ShowQueryString(STR_STATION, STR_3030_RENAME_STATION_LOADING, 31, 180, w, CS_ALPHANUMERAL);
|
|
|
|
break;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-12-05 17:08:10 +00:00
|
|
|
case SVW_TRAINS: { // Show a list of scheduled trains to this station
|
2007-03-03 09:40:34 +00:00
|
|
|
const Station *st = GetStation(w->window_number);
|
2007-03-08 16:27:54 +00:00
|
|
|
ShowVehicleListWindow(st->owner, VEH_TRAIN, (StationID)w->window_number);
|
2007-03-03 09:40:34 +00:00
|
|
|
break;
|
|
|
|
}
|
2004-12-10 18:16:08 +00:00
|
|
|
|
2007-12-05 17:08:10 +00:00
|
|
|
case SVW_ROADVEHS: { // Show a list of scheduled road-vehicles to this station
|
2007-03-03 09:40:34 +00:00
|
|
|
const Station *st = GetStation(w->window_number);
|
2007-03-08 16:27:54 +00:00
|
|
|
ShowVehicleListWindow(st->owner, VEH_ROAD, (StationID)w->window_number);
|
2007-03-03 09:40:34 +00:00
|
|
|
break;
|
|
|
|
}
|
2004-12-10 18:16:08 +00:00
|
|
|
|
2007-12-05 17:08:10 +00:00
|
|
|
case SVW_PLANES: { // Show a list of scheduled aircraft to this station
|
2007-03-03 09:40:34 +00:00
|
|
|
const Station *st = GetStation(w->window_number);
|
|
|
|
/* Since oilrigs have no owners, show the scheduled aircraft of current player */
|
|
|
|
PlayerID owner = (st->owner == OWNER_NONE) ? _current_player : st->owner;
|
2007-03-08 16:27:54 +00:00
|
|
|
ShowVehicleListWindow(owner, VEH_AIRCRAFT, (StationID)w->window_number);
|
2007-03-03 09:40:34 +00:00
|
|
|
break;
|
|
|
|
}
|
2004-12-10 18:16:08 +00:00
|
|
|
|
2007-12-05 17:08:10 +00:00
|
|
|
case SVW_SHIPS: { // Show a list of scheduled ships to this station
|
2007-03-03 09:40:34 +00:00
|
|
|
const Station *st = GetStation(w->window_number);
|
|
|
|
/* Since oilrigs/bouys have no owners, show the scheduled ships of current player */
|
|
|
|
PlayerID owner = (st->owner == OWNER_NONE) ? _current_player : st->owner;
|
2007-03-08 16:27:54 +00:00
|
|
|
ShowVehicleListWindow(owner, VEH_SHIP, (StationID)w->window_number);
|
2007-03-03 09:40:34 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2004-12-10 18:16:08 +00:00
|
|
|
break;
|
|
|
|
|
2007-03-03 09:40:34 +00:00
|
|
|
case WE_ON_EDIT_TEXT:
|
|
|
|
if (e->we.edittext.str[0] != '\0') {
|
|
|
|
_cmd_text = e->we.edittext.str;
|
|
|
|
DoCommandP(0, w->window_number, 0, NULL,
|
|
|
|
CMD_RENAME_STATION | CMD_MSG(STR_3031_CAN_T_RENAME_STATION));
|
|
|
|
}
|
2004-12-10 18:16:08 +00:00
|
|
|
break;
|
|
|
|
|
2007-03-03 09:40:34 +00:00
|
|
|
case WE_DESTROY: {
|
|
|
|
WindowNumber wno =
|
|
|
|
(w->window_number << 16) | GetStation(w->window_number)->owner;
|
2004-12-10 18:16:08 +00:00
|
|
|
|
2007-03-03 09:40:34 +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 = {
|
2007-07-27 12:49:04 +00:00
|
|
|
WDP_AUTO, WDP_AUTO, 249, 110, 249, 110,
|
2007-02-01 15:49:12 +00:00
|
|
|
WC_STATION_VIEW, WC_NONE,
|
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
|
|
|
|
};
|
|
|
|
|
2007-12-05 17:08:10 +00:00
|
|
|
/**
|
|
|
|
* Opens StationViewWindow for given station
|
|
|
|
*
|
|
|
|
* @param station station which window should be opened
|
|
|
|
*/
|
2005-10-07 07:35:15 +00:00
|
|
|
void ShowStationViewWindow(StationID station)
|
2004-08-09 17:04:08 +00:00
|
|
|
{
|
2007-03-03 09:40:34 +00:00
|
|
|
Window *w = AllocateWindowDescFront(&_station_view_desc, station);
|
|
|
|
if (w == NULL) return;
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2007-03-03 09:40:34 +00:00
|
|
|
PlayerID owner = GetStation(w->window_number)->owner;
|
|
|
|
if (owner != OWNER_NONE) w->caption_color = owner;
|
|
|
|
w->vscroll.cap = 5;
|
2004-08-09 17:04:08 +00:00
|
|
|
}
|