1
0
Fork 0

(svn r11576) -Codechange: enumerize and comment station GUI

release/0.6
smatz 2007-12-05 17:08:10 +00:00
parent 079482f0a2
commit eda5921284
9 changed files with 264 additions and 151 deletions

View File

@ -669,6 +669,9 @@
<File <File
RelativePath=".\..\src\station.h"> RelativePath=".\..\src\station.h">
</File> </File>
<File
RelativePath=".\..\src\station_gui.h">
</File>
<File <File
RelativePath=".\..\src\stdafx.h"> RelativePath=".\..\src\stdafx.h">
</File> </File>

View File

@ -1123,6 +1123,10 @@
RelativePath=".\..\src\station.h" RelativePath=".\..\src\station.h"
> >
</File> </File>
<File
RelativePath=".\..\src\station_gui.h"
>
</File>
<File <File
RelativePath=".\..\src\stdafx.h" RelativePath=".\..\src\stdafx.h"
> >

View File

@ -1120,6 +1120,10 @@
RelativePath=".\..\src\station.h" RelativePath=".\..\src\station.h"
> >
</File> </File>
<File
RelativePath=".\..\src\station_gui.h"
>
</File>
<File <File
RelativePath=".\..\src\stdafx.h" RelativePath=".\..\src\stdafx.h"
> >

View File

@ -189,6 +189,7 @@ sound.h
sprite.h sprite.h
spritecache.h spritecache.h
station.h station.h
station_gui.h
stdafx.h stdafx.h
string.h string.h
texteff.hpp texteff.hpp

View File

@ -36,6 +36,7 @@
#include "helpers.hpp" #include "helpers.hpp"
#include "cargotype.h" #include "cargotype.h"
#include "roadveh.h" #include "roadveh.h"
#include "station_gui.h"
Station::Station(TileIndex tile) Station::Station(TileIndex tile)
{ {
@ -133,7 +134,7 @@ void Station::AddFacility(byte new_facility_bit, TileIndex facil_xy)
void Station::MarkDirty() const void Station::MarkDirty() const
{ {
if (sign.width_1 != 0) { if (sign.width_1 != 0) {
InvalidateWindowWidget(WC_STATION_VIEW, index, 1); InvalidateWindowWidget(WC_STATION_VIEW, index, SVW_CAPTION);
/* We use ZOOM_LVL_MAX here, as every viewport can have an other zoom, /* We use ZOOM_LVL_MAX here, as every viewport can have an other zoom,
* and there is no way for us to know which is the biggest. So make the * and there is no way for us to know which is the biggest. So make the

View File

@ -250,10 +250,6 @@ StationSet FindStationsAroundIndustryTile(TileIndex tile, int w, int h);
void ShowStationViewWindow(StationID station); void ShowStationViewWindow(StationID station);
void UpdateAllStationVirtCoord(); void UpdateAllStationVirtCoord();
/* sorter stuff */
void RebuildStationLists();
void ResortStationLists();
static inline StationID GetMaxStationIndex() static inline StationID GetMaxStationIndex()
{ {
/* TODO - This isn't the real content of the function, but /* TODO - This isn't the real content of the function, but

View File

@ -45,6 +45,7 @@
#include "autoslope.h" #include "autoslope.h"
#include "transparency.h" #include "transparency.h"
#include "water.h" #include "water.h"
#include "station_gui.h"
DEFINE_OLD_POOL_GENERIC(Station, Station) DEFINE_OLD_POOL_GENERIC(Station, Station)
DEFINE_OLD_POOL_GENERIC(RoadStop, RoadStop) DEFINE_OLD_POOL_GENERIC(RoadStop, RoadStop)
@ -662,7 +663,7 @@ static void UpdateStationAcceptance(Station *st, bool show_msg)
} }
/* redraw the station view since acceptance changed */ /* redraw the station view since acceptance changed */
InvalidateWindowWidget(WC_STATION_VIEW, st->index, 5); InvalidateWindowWidget(WC_STATION_VIEW, st->index, SVW_ACCEPTLIST);
} }
static void UpdateStationSignCoord(Station *st) static void UpdateStationSignCoord(Station *st)
@ -2533,9 +2534,9 @@ static void UpdateStationRating(Station *st)
StationID index = st->index; StationID index = st->index;
if (waiting_changed) { if (waiting_changed) {
InvalidateWindow(WC_STATION_VIEW, index); InvalidateWindow(WC_STATION_VIEW, index); // update whole window
} else { } else {
InvalidateWindowWidget(WC_STATION_VIEW, index, 6); InvalidateWindowWidget(WC_STATION_VIEW, index, SVW_RATINGLIST); // update only ratings list
} }
} }

View File

@ -23,23 +23,7 @@
#include "table/sprites.h" #include "table/sprites.h"
#include "helpers.hpp" #include "helpers.hpp"
#include "cargotype.h" #include "cargotype.h"
#include "station_gui.h"
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 = 20,
STATIONLIST_WIDGET_NOCARGOWAITING = 12,
STATIONLIST_WIDGET_FACILALL = 14,
STATIONLIST_WIDGET_CARGOALL,
STATIONLIST_WIDGET_SORTBY,
STATIONLIST_WIDGET_SORTCRITERIA,
STATIONLIST_WIDGET_SORTDROPBTN,
};
typedef int CDECL StationSortListingTypeFunction(const void*, const void*); typedef int CDECL StationSortListingTypeFunction(const void*, const void*);
@ -48,23 +32,30 @@ static StationSortListingTypeFunction StationTypeSorter;
static StationSortListingTypeFunction StationWaitingSorter; static StationSortListingTypeFunction StationWaitingSorter;
static StationSortListingTypeFunction StationRatingMaxSorter; static StationSortListingTypeFunction StationRatingMaxSorter;
/** Draw small boxes of cargo amount and ratings data at the given /**
* Draw small boxes of cargo amount and ratings data at the given
* coordinates. If amount exceeds 576 units, it is shown 'full', same * coordinates. If amount exceeds 576 units, it is shown 'full', same
* goes for the rating: at above 90% orso (224) it is also 'full' * 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 coordinate to draw the box at * @param x coordinate to draw the box at
* @param y coordinate to draw the box at * @param y coordinate to draw the box at
* @param type Cargo type * @param type Cargo type
* @param amount Cargo amount * @param amount Cargo amount
* @param rating ratings data for that particular cargo */ * @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
*/
static void StationsWndShowStationRating(int x, int y, CargoID type, uint amount, byte rating) static void StationsWndShowStationRating(int x, int y, CargoID type, uint amount, byte rating)
{ {
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'
const CargoSpec *cs = GetCargo(type); const CargoSpec *cs = GetCargo(type);
if (!cs->IsValid()) return; if (!cs->IsValid()) return;
int colour = cs->rating_colour; int colour = cs->rating_colour;
uint w = (minu(amount, 576) + 5) / 36; uint w = (minu(amount, units_full) + 5) / 36;
/* Draw total cargo (limited) on station (fits into 16 pixels) */ /* Draw total cargo (limited) on station (fits into 16 pixels) */
if (w != 0) GfxFillRect(x, y, x + w - 1, y + 6, colour); if (w != 0) GfxFillRect(x, y, x + w - 1, y + 6, colour);
@ -84,7 +75,7 @@ static void StationsWndShowStationRating(int x, int y, CargoID type, uint amount
/* Draw green/red ratings bar (fits into 14 pixels) */ /* Draw green/red ratings bar (fits into 14 pixels) */
y += 8; y += 8;
GfxFillRect(x + 1, y, x + 14, y, 0xB8); GfxFillRect(x + 1, y, x + 14, y, 0xB8);
rating = minu(rating, 224) / 16; rating = minu(rating, rating_full) / 16;
if (rating != 0) GfxFillRect(x + 1, y, x + rating, y, 0xD0); if (rating != 0) GfxFillRect(x + 1, y, x + rating, y, 0xD0);
} }
@ -168,23 +159,28 @@ static int CDECL StationRatingMaxSorter(const void *a, const void *b)
return (_internal_sort_order & 1) ? maxr2 - maxr1 : maxr1 - maxr2; return (_internal_sort_order & 1) ? maxr2 - maxr1 : maxr1 - maxr2;
} }
/** Flags for station list */
enum StationListFlags { enum StationListFlags {
SL_ORDER = 0x01, SL_ORDER = 1 << 0, ///< Order - ascending (=0), descending (=1)
SL_RESORT = 0x02, SL_RESORT = 1 << 1, ///< Resort the list
SL_REBUILD = 0x04, SL_REBUILD = 1 << 2, ///< Rebuild the list
}; };
DECLARE_ENUM_AS_BIT_SET(StationListFlags); DECLARE_ENUM_AS_BIT_SET(StationListFlags);
/** Information about station list */
struct plstations_d { struct plstations_d {
const Station** sort_list; const Station** sort_list; ///< Pointer to list of stations
uint16 list_length; uint16 list_length; ///< Number of stations in list
byte sort_type; uint16 resort_timer; ///< Tick counter to resort the list
StationListFlags flags; byte sort_type; ///< Sort type - name, waiting, ...
uint16 resort_timer; //was byte refresh_counter; byte flags; ///< Flags - SL_ORDER, SL_RESORT, SL_REBUILD
}; };
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(plstations_d)); assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(plstations_d));
/**
* Set the 'SL_REBUILD' flag for all station lists
*/
void RebuildStationLists() void RebuildStationLists()
{ {
Window* const *wz; Window* const *wz;
@ -198,6 +194,9 @@ void RebuildStationLists()
} }
} }
/**
* Set the 'SL_RESORT' flag for all station lists
*/
void ResortStationLists() void ResortStationLists()
{ {
Window* const *wz; Window* const *wz;
@ -211,6 +210,15 @@ void ResortStationLists()
} }
} }
/**
* 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
*/
static void BuildStationsList(plstations_d* sl, PlayerID owner, byte facilities, uint32 cargo_filter, bool include_empty) static void BuildStationsList(plstations_d* sl, PlayerID owner, byte facilities, uint32 cargo_filter, bool include_empty)
{ {
uint n = 0; uint n = 0;
@ -257,6 +265,12 @@ static void BuildStationsList(plstations_d* sl, PlayerID owner, byte facilities,
free((void*)station_sort); free((void*)station_sort);
} }
/**
* Sort station list if the SL_RESORT flag is set
*
* @param sl pointer to plstations_d (station list and flags)
*/
static void SortStationsList(plstations_d *sl) static void SortStationsList(plstations_d *sl)
{ {
static StationSortListingTypeFunction* const _station_sorter[] = { static StationSortListingTypeFunction* const _station_sorter[] = {
@ -276,6 +290,12 @@ static void SortStationsList(plstations_d *sl)
sl->flags &= ~SL_RESORT; sl->flags &= ~SL_RESORT;
} }
/**
* Fuction called when any WindowEvent occurs for PlayerStations window
*
* @param w pointer to the PlayerStations window
* @param e pointer to window event
*/
static void PlayerStationsWndProc(Window *w, WindowEvent *e) static void PlayerStationsWndProc(Window *w, WindowEvent *e)
{ {
const PlayerID owner = (PlayerID)w->window_number; const PlayerID owner = (PlayerID)w->window_number;
@ -286,20 +306,22 @@ static void PlayerStationsWndProc(Window *w, WindowEvent *e)
plstations_d *sl = &WP(w, plstations_d); plstations_d *sl = &WP(w, plstations_d);
switch (e->event) { switch (e->event) {
case WE_CREATE: /* set up resort timer */ case WE_CREATE:
if (_cargo_filter == _cargo_filter_max) _cargo_filter = _cargo_mask; if (_cargo_filter == _cargo_filter_max) _cargo_filter = _cargo_mask;
for (uint i = 0; i < 5; i++) { for (uint i = 0; i < 5; i++) {
if (HasBit(facilities, i)) w->LowerWidget(i + STATIONLIST_WIDGET_TRAIN); if (HasBit(facilities, i)) w->LowerWidget(i + SLW_TRAIN);
} }
w->SetWidgetLoweredState(STATIONLIST_WIDGET_FACILALL, facilities == (FACIL_TRAIN | FACIL_TRUCK_STOP | FACIL_BUS_STOP | FACIL_AIRPORT | FACIL_DOCK)); w->SetWidgetLoweredState(SLW_FACILALL, facilities == (FACIL_TRAIN | FACIL_TRUCK_STOP | FACIL_BUS_STOP | FACIL_AIRPORT | FACIL_DOCK));
w->SetWidgetLoweredState(STATIONLIST_WIDGET_CARGOALL, _cargo_filter == _cargo_mask && include_empty); w->SetWidgetLoweredState(SLW_CARGOALL, _cargo_filter == _cargo_mask && include_empty);
w->SetWidgetLoweredState(STATIONLIST_WIDGET_NOCARGOWAITING, include_empty); w->SetWidgetLoweredState(SLW_NOCARGOWAITING, include_empty);
sl->sort_list = NULL; sl->sort_list = NULL;
sl->flags = SL_REBUILD; sl->flags = SL_REBUILD;
sl->sort_type = station_sort.criteria; sl->sort_type = station_sort.criteria;
if (station_sort.order) sl->flags |= SL_ORDER; if (station_sort.order) sl->flags |= SL_ORDER;
/* set up resort timer */
sl->resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS; sl->resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS;
break; break;
@ -337,13 +359,13 @@ static void PlayerStationsWndProc(Window *w, WindowEvent *e)
} }
x += 6; x += 6;
cg_ofst = w->IsWidgetLowered(STATIONLIST_WIDGET_NOCARGOWAITING) ? 2 : 1; cg_ofst = w->IsWidgetLowered(SLW_NOCARGOWAITING) ? 2 : 1;
DrawStringCentered(x + cg_ofst, y + cg_ofst, STR_ABBREV_NONE, TC_BLACK); DrawStringCentered(x + cg_ofst, y + cg_ofst, STR_ABBREV_NONE, TC_BLACK);
x += 14; x += 14;
cg_ofst = w->IsWidgetLowered(STATIONLIST_WIDGET_CARGOALL) ? 2 : 1; cg_ofst = w->IsWidgetLowered(SLW_CARGOALL) ? 2 : 1;
DrawStringCentered(x + cg_ofst, y + cg_ofst, STR_ABBREV_ALL, TC_BLACK); DrawStringCentered(x + cg_ofst, y + cg_ofst, STR_ABBREV_ALL, TC_BLACK);
cg_ofst = w->IsWidgetLowered(STATIONLIST_WIDGET_FACILALL) ? 2 : 1; cg_ofst = w->IsWidgetLowered(SLW_FACILALL) ? 2 : 1;
DrawString(71 + cg_ofst, y + cg_ofst, STR_ABBREV_ALL, TC_BLACK); DrawString(71 + cg_ofst, y + cg_ofst, STR_ABBREV_ALL, TC_BLACK);
if (w->vscroll.count == 0) { // player has no stations if (w->vscroll.count == 0) { // player has no stations
@ -379,7 +401,7 @@ static void PlayerStationsWndProc(Window *w, WindowEvent *e)
case WE_CLICK: case WE_CLICK:
switch (e->we.click.widget) { switch (e->we.click.widget) {
case STATIONLIST_WIDGET_LIST: { case SLW_LIST: {
uint32 id_v = (e->we.click.pt.y - 41) / 10; uint32 id_v = (e->we.click.pt.y - 41) / 10;
if (id_v >= w->vscroll.cap) return; // click out of bounds if (id_v >= w->vscroll.cap) return; // click out of bounds
@ -394,47 +416,47 @@ static void PlayerStationsWndProc(Window *w, WindowEvent *e)
break; break;
} }
case STATIONLIST_WIDGET_TRAIN: case SLW_TRAIN:
case STATIONLIST_WIDGET_TRUCK: case SLW_TRUCK:
case STATIONLIST_WIDGET_BUS: case SLW_BUS:
case STATIONLIST_WIDGET_AIRPLANE: case SLW_AIRPLANE:
case STATIONLIST_WIDGET_SHIP: case SLW_SHIP:
if (_ctrl_pressed) { if (_ctrl_pressed) {
ToggleBit(facilities, e->we.click.widget - STATIONLIST_WIDGET_TRAIN); ToggleBit(facilities, e->we.click.widget - SLW_TRAIN);
w->ToggleWidgetLoweredState(e->we.click.widget); w->ToggleWidgetLoweredState(e->we.click.widget);
} else { } else {
uint i; uint i;
FOR_EACH_SET_BIT(i, facilities) { FOR_EACH_SET_BIT(i, facilities) {
w->RaiseWidget(i + STATIONLIST_WIDGET_TRAIN); w->RaiseWidget(i + SLW_TRAIN);
} }
SetBit(facilities, e->we.click.widget - STATIONLIST_WIDGET_TRAIN); SetBit(facilities, e->we.click.widget - SLW_TRAIN);
w->LowerWidget(e->we.click.widget); w->LowerWidget(e->we.click.widget);
} }
w->SetWidgetLoweredState(STATIONLIST_WIDGET_FACILALL, facilities == (FACIL_TRAIN | FACIL_TRUCK_STOP | FACIL_BUS_STOP | FACIL_AIRPORT | FACIL_DOCK)); w->SetWidgetLoweredState(SLW_FACILALL, facilities == (FACIL_TRAIN | FACIL_TRUCK_STOP | FACIL_BUS_STOP | FACIL_AIRPORT | FACIL_DOCK));
sl->flags |= SL_REBUILD; sl->flags |= SL_REBUILD;
SetWindowDirty(w); SetWindowDirty(w);
break; break;
case STATIONLIST_WIDGET_FACILALL: case SLW_FACILALL:
for (uint i = 0; i < 5; i++) { for (uint i = 0; i < 5; i++) {
w->LowerWidget(i + STATIONLIST_WIDGET_TRAIN); w->LowerWidget(i + SLW_TRAIN);
} }
w->LowerWidget(STATIONLIST_WIDGET_FACILALL); w->LowerWidget(SLW_FACILALL);
facilities = FACIL_TRAIN | FACIL_TRUCK_STOP | FACIL_BUS_STOP | FACIL_AIRPORT | FACIL_DOCK; facilities = FACIL_TRAIN | FACIL_TRUCK_STOP | FACIL_BUS_STOP | FACIL_AIRPORT | FACIL_DOCK;
sl->flags |= SL_REBUILD; sl->flags |= SL_REBUILD;
SetWindowDirty(w); SetWindowDirty(w);
break; break;
case STATIONLIST_WIDGET_CARGOALL: { case SLW_CARGOALL: {
uint i = 0; uint i = 0;
for (CargoID c = 0; c < NUM_CARGO; c++) { for (CargoID c = 0; c < NUM_CARGO; c++) {
if (!GetCargo(c)->IsValid()) continue; if (!GetCargo(c)->IsValid()) continue;
w->LowerWidget(i + STATIONLIST_WIDGET_CARGOSTART); w->LowerWidget(i + SLW_CARGOSTART);
i++; i++;
} }
w->LowerWidget(STATIONLIST_WIDGET_NOCARGOWAITING); w->LowerWidget(SLW_NOCARGOWAITING);
w->LowerWidget(STATIONLIST_WIDGET_CARGOALL); w->LowerWidget(SLW_CARGOALL);
_cargo_filter = _cargo_mask; _cargo_filter = _cargo_mask;
include_empty = true; include_empty = true;
@ -443,47 +465,47 @@ static void PlayerStationsWndProc(Window *w, WindowEvent *e)
break; break;
} }
case STATIONLIST_WIDGET_SORTBY: /*flip sorting method asc/desc*/ case SLW_SORTBY: // flip sorting method asc/desc
sl->flags ^= SL_ORDER; //DESC-flag sl->flags ^= SL_ORDER; //DESC-flag
station_sort.order = HasBit(sl->flags, 0); station_sort.order = HasBit(sl->flags, 0);
sl->flags |= SL_RESORT; sl->flags |= SL_RESORT;
w->flags4 |= 5 << WF_TIMEOUT_SHL; w->flags4 |= 5 << WF_TIMEOUT_SHL;
w->LowerWidget(STATIONLIST_WIDGET_SORTBY); w->LowerWidget(SLW_SORTBY);
SetWindowDirty(w); SetWindowDirty(w);
break; break;
case STATIONLIST_WIDGET_SORTCRITERIA: case SLW_SORTCRITERIA:
case STATIONLIST_WIDGET_SORTDROPBTN: /* select sorting criteria dropdown menu */ case SLW_SORTDROPBTN: // select sorting criteria dropdown menu
ShowDropDownMenu(w, _station_sort_listing, sl->sort_type, STATIONLIST_WIDGET_SORTDROPBTN, 0, 0); ShowDropDownMenu(w, _station_sort_listing, sl->sort_type, SLW_SORTDROPBTN, 0, 0);
break; break;
case STATIONLIST_WIDGET_NOCARGOWAITING: case SLW_NOCARGOWAITING:
if (_ctrl_pressed) { if (_ctrl_pressed) {
include_empty = !include_empty; include_empty = !include_empty;
w->ToggleWidgetLoweredState(STATIONLIST_WIDGET_NOCARGOWAITING); w->ToggleWidgetLoweredState(SLW_NOCARGOWAITING);
} else { } else {
for (uint i = STATIONLIST_WIDGET_CARGOSTART; i < w->widget_count; i++) { for (uint i = SLW_CARGOSTART; i < w->widget_count; i++) {
w->RaiseWidget(i); w->RaiseWidget(i);
} }
_cargo_filter = 0; _cargo_filter = 0;
include_empty = true; include_empty = true;
w->LowerWidget(STATIONLIST_WIDGET_NOCARGOWAITING); w->LowerWidget(SLW_NOCARGOWAITING);
} }
sl->flags |= SL_REBUILD; sl->flags |= SL_REBUILD;
w->SetWidgetLoweredState(STATIONLIST_WIDGET_CARGOALL, _cargo_filter == _cargo_mask && include_empty); w->SetWidgetLoweredState(SLW_CARGOALL, _cargo_filter == _cargo_mask && include_empty);
SetWindowDirty(w); SetWindowDirty(w);
break; break;
default: default:
if (e->we.click.widget >= STATIONLIST_WIDGET_CARGOSTART) { //change cargo_filter if (e->we.click.widget >= SLW_CARGOSTART) { // change cargo_filter
/* Determine the selected cargo type */ /* Determine the selected cargo type */
CargoID c; CargoID c;
int i = 0; int i = 0;
for (c = 0; c < NUM_CARGO; c++) { for (c = 0; c < NUM_CARGO; c++) {
if (!GetCargo(c)->IsValid()) continue; if (!GetCargo(c)->IsValid()) continue;
if (e->we.click.widget - STATIONLIST_WIDGET_CARGOSTART == i) break; if (e->we.click.widget - SLW_CARGOSTART == i) break;
i++; i++;
} }
@ -491,10 +513,10 @@ static void PlayerStationsWndProc(Window *w, WindowEvent *e)
ToggleBit(_cargo_filter, c); ToggleBit(_cargo_filter, c);
w->ToggleWidgetLoweredState(e->we.click.widget); w->ToggleWidgetLoweredState(e->we.click.widget);
} else { } else {
for (uint i = STATIONLIST_WIDGET_CARGOSTART; i < w->widget_count; i++) { for (uint i = SLW_CARGOSTART; i < w->widget_count; i++) {
w->RaiseWidget(i); w->RaiseWidget(i);
} }
w->RaiseWidget(STATIONLIST_WIDGET_NOCARGOWAITING); w->RaiseWidget(SLW_NOCARGOWAITING);
_cargo_filter = 0; _cargo_filter = 0;
include_empty = false; include_empty = false;
@ -503,14 +525,14 @@ static void PlayerStationsWndProc(Window *w, WindowEvent *e)
w->LowerWidget(e->we.click.widget); w->LowerWidget(e->we.click.widget);
} }
sl->flags |= SL_REBUILD; sl->flags |= SL_REBUILD;
w->SetWidgetLoweredState(STATIONLIST_WIDGET_CARGOALL, _cargo_filter == _cargo_mask && include_empty); w->SetWidgetLoweredState(SLW_CARGOALL, _cargo_filter == _cargo_mask && include_empty);
SetWindowDirty(w); SetWindowDirty(w);
} }
break; break;
} }
break; break;
case WE_DROPDOWN_SELECT: /* we have selected a dropdown item in the list */ case WE_DROPDOWN_SELECT: // we have selected a dropdown item in the list
if (sl->sort_type != e->we.dropdown.index) { if (sl->sort_type != e->we.dropdown.index) {
/* value has changed -> resort */ /* value has changed -> resort */
sl->sort_type = e->we.dropdown.index; sl->sort_type = e->we.dropdown.index;
@ -530,7 +552,7 @@ static void PlayerStationsWndProc(Window *w, WindowEvent *e)
break; break;
case WE_TIMEOUT: case WE_TIMEOUT:
w->RaiseWidget(STATIONLIST_WIDGET_SORTBY); w->RaiseWidget(SLW_SORTBY);
SetWindowDirty(w); SetWindowDirty(w);
break; break;
@ -541,32 +563,29 @@ static void PlayerStationsWndProc(Window *w, WindowEvent *e)
} }
static const Widget _player_stations_widgets[] = { static const Widget _player_stations_widgets[] = {
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, { WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, // SLW_CLOSEBOX
{ WWT_CAPTION, RESIZE_RIGHT, 14, 11, 345, 0, 13, STR_3048_STATIONS, STR_018C_WINDOW_TITLE_DRAG_THIS}, { 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}, { WWT_STICKYBOX, RESIZE_LR, 14, 346, 357, 0, 13, 0x0, STR_STICKY_BUTTON},
{ WWT_PANEL, RESIZE_RB, 14, 0, 345, 37, 161, 0x0, STR_3057_STATION_NAMES_CLICK_ON}, { WWT_PANEL, RESIZE_RB, 14, 0, 345, 37, 161, 0x0, STR_3057_STATION_NAMES_CLICK_ON}, // SLW_LIST
{ WWT_SCROLLBAR, RESIZE_LRB, 14, 346, 357, 37, 149, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, { WWT_SCROLLBAR, RESIZE_LRB, 14, 346, 357, 37, 149, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST},
{ WWT_RESIZEBOX, RESIZE_LRTB, 14, 346, 357, 150, 161, 0x0, STR_RESIZE_BUTTON}, { WWT_RESIZEBOX, RESIZE_LRTB, 14, 346, 357, 150, 161, 0x0, STR_RESIZE_BUTTON},
//Index 6
{ 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},
//Index 11
{ 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_NO_WAITING_CARGO},
{ WWT_PANEL, RESIZE_RIGHT, 14, 117, 357, 14, 24, 0x0, STR_NULL},
//14 { WWT_TEXTBTN, RESIZE_NONE, 14, 0, 13, 14, 24, STR_TRAIN, STR_USE_CTRL_TO_SELECT_MORE}, // SLW_TRAIN
{ WWT_PANEL, RESIZE_NONE, 14, 70, 83, 14, 24, 0x0, STR_SELECT_ALL_FACILITIES}, { WWT_TEXTBTN, RESIZE_NONE, 14, 14, 27, 14, 24, STR_LORRY, STR_USE_CTRL_TO_SELECT_MORE}, // SLW_TRUCK
{ WWT_PANEL, RESIZE_NONE, 14, 103, 116, 14, 24, 0x0, STR_SELECT_ALL_TYPES}, { 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
//16 { WWT_PANEL, RESIZE_NONE, 14, 83, 88, 14, 24, 0x0, STR_NULL}, // SLW_PAN_BETWEEN
{ WWT_TEXTBTN, RESIZE_NONE, 14, 0, 80, 25, 36, STR_SORT_BY, STR_SORT_ORDER_TIP}, { WWT_PANEL, RESIZE_NONE, 14, 89, 102, 14, 24, 0x0, STR_NO_WAITING_CARGO}, // SLW_NOCARGOWAITING
{ WWT_PANEL, RESIZE_NONE, 14, 81, 232, 25, 36, 0x0, STR_SORT_CRITERIA_TIP}, { WWT_PANEL, RESIZE_NONE, 14, 103, 116, 14, 24, 0x0, STR_SELECT_ALL_TYPES}, // SLW_CARGOALL
{ WWT_TEXTBTN, RESIZE_NONE, 14, 233, 243, 25, 36, STR_0225, STR_SORT_CRITERIA_TIP}, { WWT_PANEL, RESIZE_RIGHT, 14, 117, 357, 14, 24, 0x0, STR_NULL}, // SLW_PAN_RIGHT
{ WWT_PANEL, RESIZE_RIGHT, 14, 244, 357, 25, 36, 0x0, STR_NULL},
{ 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
{ WIDGETS_END}, { WIDGETS_END},
}; };
@ -578,7 +597,11 @@ static const WindowDesc _player_stations_desc = {
PlayerStationsWndProc PlayerStationsWndProc
}; };
/**
* Opens window with list of player's stations
*
* @param player player whose stations' list show
*/
void ShowPlayerStations(PlayerID player) void ShowPlayerStations(PlayerID player)
{ {
if (!IsValidPlayer(player)) return; if (!IsValidPlayer(player)) return;
@ -605,7 +628,7 @@ void ShowPlayerStations(PlayerID player)
for (CargoID c = 0; c < NUM_CARGO; c++) { for (CargoID c = 0; c < NUM_CARGO; c++) {
if (!GetCargo(c)->IsValid()) continue; if (!GetCargo(c)->IsValid()) continue;
Widget *wi = &w->widget[STATIONLIST_WIDGET_CARGOSTART + i]; Widget *wi = &w->widget[SLW_CARGOSTART + i];
wi->type = WWT_PANEL; wi->type = WWT_PANEL;
wi->display_flags = RESIZE_NONE; wi->display_flags = RESIZE_NONE;
wi->color = 14; wi->color = 14;
@ -616,15 +639,15 @@ void ShowPlayerStations(PlayerID player)
wi->data = 0; wi->data = 0;
wi->tooltips = STR_USE_CTRL_TO_SELECT_MORE; wi->tooltips = STR_USE_CTRL_TO_SELECT_MORE;
if (HasBit(_cargo_filter, c)) w->LowerWidget(STATIONLIST_WIDGET_CARGOSTART + i); if (HasBit(_cargo_filter, c)) w->LowerWidget(SLW_CARGOSTART + i);
i++; i++;
} }
w->widget[STATIONLIST_WIDGET_NOCARGOWAITING].left += num_active * 14; w->widget[SLW_NOCARGOWAITING].left += num_active * 14;
w->widget[STATIONLIST_WIDGET_NOCARGOWAITING].right += num_active * 14; w->widget[SLW_NOCARGOWAITING].right += num_active * 14;
w->widget[STATIONLIST_WIDGET_CARGOALL].left += num_active * 14; w->widget[SLW_CARGOALL].left += num_active * 14;
w->widget[STATIONLIST_WIDGET_CARGOALL].right += num_active * 14; w->widget[SLW_CARGOALL].right += num_active * 14;
w->widget[13].left += num_active * 14; w->widget[SLW_PAN_RIGHT].left += num_active * 14;
if (num_active > 15) { if (num_active > 15) {
/* Resize and fix the minimum width, if necessary */ /* Resize and fix the minimum width, if necessary */
@ -634,45 +657,52 @@ void ShowPlayerStations(PlayerID player)
} }
static const Widget _station_view_expanded_widgets[] = { static const Widget _station_view_expanded_widgets[] = {
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, { WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, // SVW_CLOSEBOX
{ WWT_CAPTION, RESIZE_NONE, 14, 11, 236, 0, 13, STR_300A_0, STR_018C_WINDOW_TITLE_DRAG_THIS}, { 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}, { WWT_STICKYBOX, RESIZE_NONE, 14, 237, 248, 0, 13, 0x0, STR_STICKY_BUTTON},
{ WWT_PANEL, RESIZE_NONE, 14, 0, 236, 14, 65, 0x0, STR_NULL}, { WWT_PANEL, RESIZE_NONE, 14, 0, 236, 14, 65, 0x0, STR_NULL}, // SVW_WAITING
{ WWT_SCROLLBAR, RESIZE_NONE, 14, 237, 248, 14, 65, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, { 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}, { 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}, { 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}, { 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}, { 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}, { 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 }, { 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 }, { 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 }, { 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 }, { WWT_PUSHTXTBTN, RESIZE_NONE, 14, 235, 248, 198, 209, STR_SHIP, STR_SCHEDULED_SHIPS_TIP }, // SVW_SHIPS
{ WIDGETS_END}, { WIDGETS_END},
}; };
static const Widget _station_view_widgets[] = { static const Widget _station_view_widgets[] = {
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, { WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, // SVW_CLOSEBOX
{ WWT_CAPTION, RESIZE_NONE, 14, 11, 236, 0, 13, STR_300A_0, STR_018C_WINDOW_TITLE_DRAG_THIS}, { 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}, { WWT_STICKYBOX, RESIZE_NONE, 14, 237, 248, 0, 13, 0x0, STR_STICKY_BUTTON},
{ WWT_PANEL, RESIZE_NONE, 14, 0, 236, 14, 65, 0x0, STR_NULL}, { WWT_PANEL, RESIZE_NONE, 14, 0, 236, 14, 65, 0x0, STR_NULL}, // SVW_WAITING
{ WWT_SCROLLBAR, RESIZE_NONE, 14, 237, 248, 14, 65, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, { WWT_SCROLLBAR, RESIZE_NONE, 14, 237, 248, 14, 65, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST},
{ WWT_PANEL, RESIZE_NONE, 14, 0, 248, 66, 97, 0x0, STR_NULL}, { 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}, { 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}, { 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}, { 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}, { 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 }, { 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 }, { 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 }, { 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 }, { WWT_PUSHTXTBTN, RESIZE_NONE, 14, 235, 248, 98, 109, STR_SHIP, STR_SCHEDULED_SHIPS_TIP }, // SVW_SHIPS
{ WIDGETS_END}, { WIDGETS_END},
}; };
/**
* 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
*/
static void DrawCargoIcons(CargoID i, uint waiting, int x, int y) static void DrawCargoIcons(CargoID i, uint waiting, int x, int y)
{ {
uint num = min((waiting + 5) / 10, 23); uint num = min((waiting + 5) / 10, 23); // maximum is 23 icons so it won't overflow
if (num == 0) return; if (num == 0) return;
const CargoSpec *cs = GetCargo(i); const CargoSpec *cs = GetCargo(i);
@ -693,15 +723,21 @@ static void DrawCargoIcons(CargoID i, uint waiting, int x, int y)
} while (--num); } while (--num);
} }
/**
* Redraws whole StationView window
*
* @param w pointer to window
*/
static void DrawStationViewWindow(Window *w) static void DrawStationViewWindow(Window *w)
{ {
StationID station_id = w->window_number; StationID station_id = w->window_number;
const Station* st = GetStation(station_id); const Station* st = GetStation(station_id);
uint num; uint num; ///< number of cargo types waiting at station
int x,y; int x, y; ///< coordinates used for printing waiting/accepted/rating of cargo
int pos; int pos; ///< = w->vscroll.pos
StringID str; StringID str;
/* count types of cargos waiting in station */
num = 1; num = 1;
for (CargoID i = 0; i < NUM_CARGO; i++) { for (CargoID i = 0; i < NUM_CARGO; i++) {
if (!st->goods[i].cargo.Empty()) { if (!st->goods[i].cargo.Empty()) {
@ -709,13 +745,14 @@ static void DrawStationViewWindow(Window *w)
if (st->goods[i].cargo.Source() != station_id) num++; if (st->goods[i].cargo.Source() != station_id) num++;
} }
} }
SetVScrollCount(w, num); SetVScrollCount(w, num); // update scrollbar
w->SetWidgetDisabledState( 9, st->owner != _local_player); /* disable some buttons */
w->SetWidgetDisabledState(10, !(st->facilities & FACIL_TRAIN)); w->SetWidgetDisabledState(SVW_RENAME, st->owner != _local_player);
w->SetWidgetDisabledState(11, !(st->facilities & FACIL_TRUCK_STOP) && !(st->facilities & FACIL_BUS_STOP)); w->SetWidgetDisabledState(SVW_TRAINS, !(st->facilities & FACIL_TRAIN));
w->SetWidgetDisabledState(12, !(st->facilities & FACIL_AIRPORT)); w->SetWidgetDisabledState(SVW_ROADVEHS, !(st->facilities & FACIL_TRUCK_STOP) && !(st->facilities & FACIL_BUS_STOP));
w->SetWidgetDisabledState(13, !(st->facilities & FACIL_DOCK)); w->SetWidgetDisabledState(SVW_PLANES, !(st->facilities & FACIL_AIRPORT));
w->SetWidgetDisabledState(SVW_SHIPS, !(st->facilities & FACIL_DOCK));
SetDParam(0, st->index); SetDParam(0, st->index);
SetDParam(1, st->facilities); SetDParam(1, st->facilities);
@ -765,7 +802,7 @@ static void DrawStationViewWindow(Window *w)
} }
} }
if (IsWindowOfPrototype(w, _station_view_widgets)) { if (IsWindowOfPrototype(w, _station_view_widgets)) { // small window with list of accepted cargo
char *b = _userstring; char *b = _userstring;
bool first = true; bool first = true;
@ -790,7 +827,7 @@ static void DrawStationViewWindow(Window *w)
*b = '\0'; *b = '\0';
DrawStringMultiLine(2, 67, STR_SPEC_USERSTRING, 245); DrawStringMultiLine(2, 67, STR_SPEC_USERSTRING, 245);
} else { } else { // extended window with list of cargo ratings
DrawString(2, 67, STR_3034_LOCAL_RATING_OF_TRANSPORT, TC_FROMSTRING); DrawString(2, 67, STR_3034_LOCAL_RATING_OF_TRANSPORT, TC_FROMSTRING);
y = 77; y = 77;
@ -811,6 +848,12 @@ static void DrawStationViewWindow(Window *w)
} }
/**
* Fuction called when any WindowEvent occurs for any StationView window
*
* @param w pointer to the StationView window
* @param e pointer to window event
*/
static void StationViewWndProc(Window *w, WindowEvent *e) static void StationViewWndProc(Window *w, WindowEvent *e)
{ {
switch (e->event) { switch (e->event) {
@ -820,11 +863,11 @@ static void StationViewWndProc(Window *w, WindowEvent *e)
case WE_CLICK: case WE_CLICK:
switch (e->we.click.widget) { switch (e->we.click.widget) {
case 7: case SVW_LOCATION:
ScrollMainWindowToTile(GetStation(w->window_number)->xy); ScrollMainWindowToTile(GetStation(w->window_number)->xy);
break; break;
case 8: case SVW_RATINGS:
SetWindowDirty(w); SetWindowDirty(w);
/* toggle height/widget set */ /* toggle height/widget set */
@ -839,24 +882,24 @@ static void StationViewWndProc(Window *w, WindowEvent *e)
SetWindowDirty(w); SetWindowDirty(w);
break; break;
case 9: case SVW_RENAME:
SetDParam(0, w->window_number); SetDParam(0, w->window_number);
ShowQueryString(STR_STATION, STR_3030_RENAME_STATION_LOADING, 31, 180, w, CS_ALPHANUMERAL); ShowQueryString(STR_STATION, STR_3030_RENAME_STATION_LOADING, 31, 180, w, CS_ALPHANUMERAL);
break; break;
case 10: { /* Show a list of scheduled trains to this station */ case SVW_TRAINS: { // Show a list of scheduled trains to this station
const Station *st = GetStation(w->window_number); const Station *st = GetStation(w->window_number);
ShowVehicleListWindow(st->owner, VEH_TRAIN, (StationID)w->window_number); ShowVehicleListWindow(st->owner, VEH_TRAIN, (StationID)w->window_number);
break; break;
} }
case 11: { /* Show a list of scheduled road-vehicles to this station */ case SVW_ROADVEHS: { // Show a list of scheduled road-vehicles to this station
const Station *st = GetStation(w->window_number); const Station *st = GetStation(w->window_number);
ShowVehicleListWindow(st->owner, VEH_ROAD, (StationID)w->window_number); ShowVehicleListWindow(st->owner, VEH_ROAD, (StationID)w->window_number);
break; break;
} }
case 12: { /* Show a list of scheduled aircraft to this station */ case SVW_PLANES: { // Show a list of scheduled aircraft to this station
const Station *st = GetStation(w->window_number); const Station *st = GetStation(w->window_number);
/* Since oilrigs have no owners, show the scheduled aircraft of current player */ /* Since oilrigs have no owners, show the scheduled aircraft of current player */
PlayerID owner = (st->owner == OWNER_NONE) ? _current_player : st->owner; PlayerID owner = (st->owner == OWNER_NONE) ? _current_player : st->owner;
@ -864,7 +907,7 @@ static void StationViewWndProc(Window *w, WindowEvent *e)
break; break;
} }
case 13: { /* Show a list of scheduled ships to this station */ case SVW_SHIPS: { // Show a list of scheduled ships to this station
const Station *st = GetStation(w->window_number); const Station *st = GetStation(w->window_number);
/* Since oilrigs/bouys have no owners, show the scheduled ships of current player */ /* Since oilrigs/bouys have no owners, show the scheduled ships of current player */
PlayerID owner = (st->owner == OWNER_NONE) ? _current_player : st->owner; PlayerID owner = (st->owner == OWNER_NONE) ? _current_player : st->owner;
@ -904,6 +947,11 @@ static const WindowDesc _station_view_desc = {
StationViewWndProc StationViewWndProc
}; };
/**
* Opens StationViewWindow for given station
*
* @param station station which window should be opened
*/
void ShowStationViewWindow(StationID station) void ShowStationViewWindow(StationID station)
{ {
Window *w = AllocateWindowDescFront(&_station_view_desc, station); Window *w = AllocateWindowDescFront(&_station_view_desc, station);

55
src/station_gui.h 100644
View File

@ -0,0 +1,55 @@
/* $Id$ */
/** @file station_gui.h Contains enums and function declarations connected with stations GUI */
#ifndef STATION_GUI_H
#define STATION_GUI_H
/** Enum for PlayerStations, referring to _player_stations_widgets */
enum StationListWidgets {
SLW_CLOSEBOX = 0, ///< Close 'X' button
SLW_LIST = 3, ///< The main panel, list of stations
SLW_TRAIN = 6, ///< 'TRAIN' button - list only facilities where is a railroad station
SLW_TRUCK,
SLW_BUS,
SLW_AIRPLANE,
SLW_SHIP,
SLW_FACILALL, ///< 'ALL' button - list all facilities
SLW_PAN_BETWEEN = 12, ///< Small panel between list of types of ficilities and list of cargo types
SLW_NOCARGOWAITING = 13, ///< 'NO' button - list stations where no cargo is waiting
SLW_CARGOALL = 14, ///< 'ALL' button - list all stations
SLW_PAN_RIGHT = 15, ///< Panel right of list of cargo types
SLW_SORTBY = 16, ///< 'Sort by' button - reverse sort direction
SLW_SORTCRITERIA = 17, ///< Button - list of criteria
SLW_SORTDROPBTN = 18, ///< Dropdown button
SLW_PAN_SORT_RIGHT = 19, ///< Panel right of sorting options
SLW_CARGOSTART = 20, ///< Widget numbers used for list of cargo types (not present in _player_stations_widgets)
};
/** Enum for StationView, referring to _station_view_widgets and _station_view_expanded_widgets */
enum StationViewWidgets {
SVW_CLOSEBOX = 0, ///< Close 'X' button
SVW_CAPTION = 1, ///< Caption of the window
SVW_WAITING = 3, ///< List of waiting cargo
SVW_ACCEPTLIST = 5, ///< List of accepted cargos
SVW_RATINGLIST = 6, ///< Ratings of cargos
SVW_LOCATION = 7, ///< 'Location' button
SVW_RATINGS = 8, ///< 'Ratings' button
SVW_ACCEPTS = 8, ///< 'Accepts' button
SVW_RENAME = 9, ///< 'Rename' button
SVW_TRAINS = 10, ///< List of scheduled trains button
SVW_ROADVEHS, ///< List of scheduled road vehs button
SVW_PLANES, ///< List of scheduled planes button
SVW_SHIPS, ///< List of scheduled ships button
};
/* sorter stuff */
void RebuildStationLists();
void ResortStationLists();
#endif /* STATION_GUI_H */