--- a/src/station_gui.cpp Fri Apr 25 02:15:34 2008 +0000
+++ b/src/station_gui.cpp Mon May 26 20:45:25 2008 +0000
@@ -1,6 +1,6 @@
/* $Id$ */
-/** @file station_gui.cpp */
+/** @file station_gui.cpp The GUI for stations. */
#include "stdafx.h"
#include "openttd.h"
@@ -25,6 +25,7 @@
#include "gfx_func.h"
#include "widgets/dropdown_func.h"
#include "newgrf_cargo.h"
+#include "string_func.h"
#include "table/strings.h"
#include "table/sprites.h"
@@ -164,60 +165,43 @@
return (_internal_sort_order & 1) ? maxr2 - maxr1 : maxr1 - maxr2;
}
-/** Flags for station list */
-enum StationListFlags {
- SL_ORDER = 1 << 0, ///< Order - ascending (=0), descending (=1)
- SL_RESORT = 1 << 1, ///< Resort the list
- SL_REBUILD = 1 << 2, ///< Rebuild the list
-};
-
-DECLARE_ENUM_AS_BIT_SET(StationListFlags);
-
-/** Information about station list */
-struct plstations_d {
- 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
-};
-assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(plstations_d));
+typedef GUIList<const Station*> GUIStationList;
/**
* Set the station sort flag for all station-list windows.
* @param sl_flag Sort list flag to set for all station-list windows
*/
-static void SetStationListsFlag(StationListFlags sl_flag)
+static void SetStationListsFlag(SortListFlags sl_flag)
{
Window *const *wz;
FOR_ALL_WINDOWS(wz) {
Window *w = *wz;
if (w->window_class == WC_STATION_LIST) {
- WP(w, plstations_d).flags |= sl_flag;
- SetWindowDirty(w);
+ dynamic_cast<GUIStationList*>(w)->flags |= sl_flag;
+ w->SetDirty();
}
}
}
/**
- * Set the 'SL_REBUILD' flag for all station lists
+ * Set the 'VL_REBUILD' flag for all station lists
*/
void RebuildStationLists()
{
- SetStationListsFlag(SL_REBUILD);
+ SetStationListsFlag(VL_REBUILD);
}
/**
- * Set the 'SL_RESORT' flag for all station lists
+ * Set the 'VL_RESORT' flag for all station lists
*/
void ResortStationLists()
{
- SetStationListsFlag(SL_RESORT);
+ SetStationListsFlag(VL_RESORT);
}
/**
- * Rebuild station list if the SL_REBUILD flag is set
+ * Rebuild station list if the VL_REBUILD flag is set
*
* @param sl pointer to plstations_d (station list and flags)
* @param owner player whose stations are to be in list
@@ -225,12 +209,12 @@
* @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(GUIStationList *sl, PlayerID owner, byte facilities, uint32 cargo_filter, bool include_empty)
{
uint n = 0;
const Station *st;
- if (!(sl->flags & SL_REBUILD)) return;
+ if (!(sl->flags & VL_REBUILD)) return;
/* Create array for sorting */
const Station **station_sort = MallocT<const Station*>(GetMaxStationIndex() + 1);
@@ -264,18 +248,18 @@
for (uint i = 0; i < n; ++i) sl->sort_list[i] = station_sort[i];
- sl->flags &= ~SL_REBUILD;
- sl->flags |= SL_RESORT;
+ sl->flags &= ~VL_REBUILD;
+ sl->flags |= VL_RESORT;
free((void*)station_sort);
}
/**
- * Sort station list if the SL_RESORT flag is set
+ * Sort station list if the VL_RESORT flag is set
*
* @param sl pointer to plstations_d (station list and flags)
*/
-static void SortStationsList(plstations_d *sl)
+static void SortStationsList(GUIStationList *sl)
{
static StationSortListingTypeFunction *const _station_sorter[] = {
&StationNameSorter,
@@ -284,293 +268,349 @@
&StationRatingMaxSorter
};
- if (!(sl->flags & SL_RESORT)) return;
+ if (!(sl->flags & VL_RESORT)) return;
- _internal_sort_order = sl->flags & SL_ORDER;
+ _internal_sort_order = sl->flags & VL_DESC;
_last_station = NULL; // used for "cache" in namesorting
qsort((void*)sl->sort_list, sl->list_length, sizeof(sl->sort_list[0]), _station_sorter[sl->sort_type]);
sl->resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS;
- sl->flags &= ~SL_RESORT;
+ sl->flags &= ~VL_RESORT;
}
/**
- * Fuction called when any WindowEvent occurs for PlayerStations window
- *
- * @param w pointer to the PlayerStations window
- * @param e pointer to window event
+ * The list of stations per player.
*/
-static void PlayerStationsWndProc(Window *w, WindowEvent *e)
+struct PlayerStationsWindow : public Window, public GUIStationList
{
- const PlayerID owner = (PlayerID)w->window_number;
- static byte facilities = FACIL_TRAIN | FACIL_TRUCK_STOP | FACIL_BUS_STOP | FACIL_AIRPORT | FACIL_DOCK;
- static Listing station_sort = {0, 0};
- static bool include_empty = true;
-
- plstations_d *sl = &WP(w, plstations_d);
-
- switch (e->event) {
- case WE_CREATE:
- if (_cargo_filter == _cargo_filter_max) _cargo_filter = _cargo_mask;
-
- for (uint i = 0; i < 5; i++) {
- if (HasBit(facilities, i)) w->LowerWidget(i + SLW_TRAIN);
- }
- 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);
-
- sl->sort_list = NULL;
- sl->flags = SL_REBUILD;
- sl->sort_type = station_sort.criteria;
- if (station_sort.order) sl->flags |= SL_ORDER;
-
- /* set up resort timer */
- sl->resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS;
- break;
-
- case WE_PAINT: {
- BuildStationsList(sl, owner, facilities, _cargo_filter, include_empty);
- SortStationsList(sl);
-
- SetVScrollCount(w, sl->list_length);
-
- /* draw widgets, with player's name in the caption */
- SetDParam(0, owner);
- SetDParam(1, w->vscroll.count);
-
- /* Set text of sort by dropdown */
- w->widget[SLW_SORTDROPBTN].data = _station_sort_listing[sl->sort_type];
-
- DrawWindowWidgets(w);
-
- /* draw arrow pointing up/down for ascending/descending sorting */
- DrawSortButtonState(w, SLW_SORTBY, sl->flags & SL_ORDER ? SBS_DOWN : SBS_UP);
+ static Listing station_sort;
+ static byte facilities;
+ static bool include_empty;
- int cg_ofst;
- int x = 89;
- int y = 14;
- int xb = 2; ///< offset from left of widget
-
- uint i = 0;
- for (CargoID c = 0; c < NUM_CARGO; c++) {
- const CargoSpec *cs = GetCargo(c);
- if (!cs->IsValid()) continue;
-
- cg_ofst = HasBit(_cargo_filter, c) ? 2 : 1;
- GfxFillRect(x + cg_ofst, y + cg_ofst, x + cg_ofst + 10 , y + cg_ofst + 7, cs->rating_colour);
- DrawStringCentered(x + 6 + cg_ofst, y + cg_ofst, cs->abbrev, TC_BLACK);
- x += 14;
- i++;
- }
-
- x += 6;
- cg_ofst = w->IsWidgetLowered(SLW_NOCARGOWAITING) ? 2 : 1;
- DrawStringCentered(x + cg_ofst, y + cg_ofst, STR_ABBREV_NONE, TC_BLACK);
- x += 14;
- cg_ofst = w->IsWidgetLowered(SLW_CARGOALL) ? 2 : 1;
- DrawStringCentered(x + cg_ofst, y + cg_ofst, STR_ABBREV_ALL, TC_BLACK);
-
- cg_ofst = w->IsWidgetLowered(SLW_FACILALL) ? 2 : 1;
- DrawString(71 + cg_ofst, y + cg_ofst, STR_ABBREV_ALL, TC_BLACK);
+ PlayerStationsWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number)
+ {
+ this->caption_color = (byte)this->window_number;
+ this->vscroll.cap = 12;
+ this->resize.step_height = 10;
+ this->resize.height = this->height - 10 * 7; // minimum if 5 in the list
- if (w->vscroll.count == 0) { // player has no stations
- DrawString(xb, 40, STR_304A_NONE, TC_FROMSTRING);
- return;
- }
-
- int max = min(w->vscroll.pos + w->vscroll.cap, sl->list_length);
- y = 40; // start of the list-widget
-
- for (int i = w->vscroll.pos; i < max; ++i) { // do until max number of stations of owner
- const Station *st = sl->sort_list[i];
- int x;
-
- assert(st->xy != 0);
-
- /* 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()));
-
- SetDParam(0, st->index);
- SetDParam(1, st->facilities);
- x = DrawString(xb, y, STR_3049_0, TC_FROMSTRING) + 5;
-
- /* show cargo waiting and station ratings */
- for (CargoID j = 0; j < NUM_CARGO; j++) {
- if (!st->goods[j].cargo.Empty()) {
- StationsWndShowStationRating(x, y, j, st->goods[j].cargo.Count(), st->goods[j].rating);
- x += 20;
- }
- }
- y += 10;
- }
- break;
+ /* Add cargo filter buttons */
+ uint num_active = 0;
+ for (CargoID c = 0; c < NUM_CARGO; c++) {
+ if (GetCargo(c)->IsValid()) num_active++;
}
- case WE_CLICK:
- switch (e->we.click.widget) {
- case SLW_LIST: {
- uint32 id_v = (e->we.click.pt.y - 41) / 10;
-
- if (id_v >= w->vscroll.cap) return; // click out of bounds
-
- id_v += w->vscroll.pos;
-
- if (id_v >= sl->list_length) return; // click out of list bound
-
- const Station *st = sl->sort_list[id_v];
- /* do not check HasStationInUse - it is slow and may be invalid */
- assert(st->owner == owner || (st->owner == OWNER_NONE && !st->IsBuoy()));
- ScrollMainWindowToTile(st->xy);
- break;
- }
+ this->widget_count += num_active;
+ this->widget = ReallocT(this->widget, this->widget_count + 1);
+ this->widget[this->widget_count].type = WWT_LAST;
- case SLW_TRAIN:
- case SLW_TRUCK:
- case SLW_BUS:
- case SLW_AIRPLANE:
- case SLW_SHIP:
- if (_ctrl_pressed) {
- ToggleBit(facilities, e->we.click.widget - SLW_TRAIN);
- w->ToggleWidgetLoweredState(e->we.click.widget);
- } else {
- uint i;
- FOR_EACH_SET_BIT(i, facilities) {
- w->RaiseWidget(i + SLW_TRAIN);
- }
- SetBit(facilities, e->we.click.widget - SLW_TRAIN);
- w->LowerWidget(e->we.click.widget);
+ uint i = 0;
+ for (CargoID c = 0; c < NUM_CARGO; c++) {
+ if (!GetCargo(c)->IsValid()) continue;
+
+ Widget *wi = &this->widget[SLW_CARGOSTART + i];
+ 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;
+
+ if (HasBit(_cargo_filter, c)) this->LowerWidget(SLW_CARGOSTART + i);
+ i++;
+ }
+
+ this->widget[SLW_NOCARGOWAITING].left += num_active * 14;
+ this->widget[SLW_NOCARGOWAITING].right += num_active * 14;
+ this->widget[SLW_CARGOALL].left += num_active * 14;
+ this->widget[SLW_CARGOALL].right += num_active * 14;
+ this->widget[SLW_PAN_RIGHT].left += num_active * 14;
+
+ if (num_active > 15) {
+ /* Resize and fix the minimum width, if necessary */
+ ResizeWindow(this, (num_active - 15) * 14, 0);
+ this->resize.width = this->width;
+ }
+
+ if (_cargo_filter == _cargo_filter_max) _cargo_filter = _cargo_mask;
+
+ for (uint i = 0; i < 5; i++) {
+ if (HasBit(facilities, i)) this->LowerWidget(i + SLW_TRAIN);
+ }
+ this->SetWidgetLoweredState(SLW_FACILALL, facilities == (FACIL_TRAIN | FACIL_TRUCK_STOP | FACIL_BUS_STOP | FACIL_AIRPORT | FACIL_DOCK));
+ this->SetWidgetLoweredState(SLW_CARGOALL, _cargo_filter == _cargo_mask && include_empty);
+ this->SetWidgetLoweredState(SLW_NOCARGOWAITING, include_empty);
+
+ this->sort_list = NULL;
+ this->flags = VL_REBUILD;
+ this->sort_type = station_sort.criteria;
+ if (station_sort.order) this->flags |= VL_DESC;
+
+ /* set up resort timer */
+ this->resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS;
+ }
+
+ virtual void OnPaint()
+ {
+ PlayerID owner = (PlayerID)this->window_number;
+
+ BuildStationsList(this, owner, facilities, _cargo_filter, include_empty);
+ SortStationsList(this);
+
+ SetVScrollCount(this, this->list_length);
+
+ /* draw widgets, with player's name in the caption */
+ SetDParam(0, owner);
+ SetDParam(1, this->vscroll.count);
+
+ /* Set text of sort by dropdown */
+ this->widget[SLW_SORTDROPBTN].data = _station_sort_listing[this->sort_type];
+
+ this->DrawWidgets();
+
+ /* draw arrow pointing up/down for ascending/descending sorting */
+ this->DrawSortButtonState(SLW_SORTBY, this->flags & VL_DESC ? SBS_DOWN : SBS_UP);
+
+ int cg_ofst;
+ int x = 89;
+ int y = 14;
+ int xb = 2; ///< offset from left of widget
+
+ uint i = 0;
+ for (CargoID c = 0; c < NUM_CARGO; c++) {
+ const CargoSpec *cs = GetCargo(c);
+ if (!cs->IsValid()) continue;
+
+ cg_ofst = HasBit(_cargo_filter, c) ? 2 : 1;
+ GfxFillRect(x + cg_ofst, y + cg_ofst, x + cg_ofst + 10 , y + cg_ofst + 7, cs->rating_colour);
+ DrawStringCentered(x + 6 + cg_ofst, y + cg_ofst, cs->abbrev, TC_BLACK);
+ x += 14;
+ i++;
+ }
+
+ x += 6;
+ cg_ofst = this->IsWidgetLowered(SLW_NOCARGOWAITING) ? 2 : 1;
+ DrawStringCentered(x + cg_ofst, y + cg_ofst, STR_ABBREV_NONE, TC_BLACK);
+ x += 14;
+ cg_ofst = this->IsWidgetLowered(SLW_CARGOALL) ? 2 : 1;
+ DrawStringCentered(x + cg_ofst, y + cg_ofst, STR_ABBREV_ALL, TC_BLACK);
+
+ cg_ofst = this->IsWidgetLowered(SLW_FACILALL) ? 2 : 1;
+ DrawString(71 + cg_ofst, y + cg_ofst, STR_ABBREV_ALL, TC_BLACK);
+
+ if (this->vscroll.count == 0) { // player has no stations
+ DrawString(xb, 40, STR_304A_NONE, TC_FROMSTRING);
+ return;
+ }
+
+ int max = min(this->vscroll.pos + this->vscroll.cap, this->list_length);
+ y = 40; // start of the list-widget
+
+ for (int i = this->vscroll.pos; i < max; ++i) { // do until max number of stations of owner
+ const Station *st = this->sort_list[i];
+ int x;
+
+ assert(st->xy != 0);
+
+ /* 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()));
+
+ SetDParam(0, st->index);
+ SetDParam(1, st->facilities);
+ x = DrawString(xb, y, STR_3049_0, TC_FROMSTRING) + 5;
+
+ /* show cargo waiting and station ratings */
+ for (CargoID j = 0; j < NUM_CARGO; j++) {
+ if (!st->goods[j].cargo.Empty()) {
+ StationsWndShowStationRating(x, y, j, st->goods[j].cargo.Count(), st->goods[j].rating);
+ x += 20;
+ }
+ }
+ y += 10;
+ }
+ }
+
+ virtual void OnClick(Point pt, int widget)
+ {
+ switch (widget) {
+ case SLW_LIST: {
+ uint32 id_v = (pt.y - 41) / 10;
+
+ if (id_v >= this->vscroll.cap) return; // click out of bounds
+
+ id_v += this->vscroll.pos;
+
+ if (id_v >= this->list_length) return; // click out of list bound
+
+ const Station *st = this->sort_list[id_v];
+ /* do not check HasStationInUse - it is slow and may be invalid */
+ assert(st->owner == (PlayerID)this->window_number || (st->owner == OWNER_NONE && !st->IsBuoy()));
+
+ if (_ctrl_pressed) {
+ ShowExtraViewPortWindow(st->xy);
+ } else {
+ ScrollMainWindowToTile(st->xy);
+ }
+ break;
+ }
+
+ case SLW_TRAIN:
+ case SLW_TRUCK:
+ case SLW_BUS:
+ case SLW_AIRPLANE:
+ case SLW_SHIP:
+ if (_ctrl_pressed) {
+ ToggleBit(facilities, widget - SLW_TRAIN);
+ this->ToggleWidgetLoweredState(widget);
+ } else {
+ uint i;
+ FOR_EACH_SET_BIT(i, facilities) {
+ this->RaiseWidget(i + SLW_TRAIN);
}
- w->SetWidgetLoweredState(SLW_FACILALL, facilities == (FACIL_TRAIN | FACIL_TRUCK_STOP | FACIL_BUS_STOP | FACIL_AIRPORT | FACIL_DOCK));
- sl->flags |= SL_REBUILD;
- SetWindowDirty(w);
- break;
+ SetBit(facilities, widget - SLW_TRAIN);
+ this->LowerWidget(widget);
+ }
+ this->SetWidgetLoweredState(SLW_FACILALL, facilities == (FACIL_TRAIN | FACIL_TRUCK_STOP | FACIL_BUS_STOP | FACIL_AIRPORT | FACIL_DOCK));
+ this->flags |= VL_REBUILD;
+ this->SetDirty();
+ break;
- case SLW_FACILALL:
- for (uint i = 0; i < 5; i++) {
- w->LowerWidget(i + SLW_TRAIN);
+ case SLW_FACILALL:
+ for (uint i = 0; i < 5; i++) {
+ this->LowerWidget(i + SLW_TRAIN);
+ }
+ this->LowerWidget(SLW_FACILALL);
+
+ facilities = FACIL_TRAIN | FACIL_TRUCK_STOP | FACIL_BUS_STOP | FACIL_AIRPORT | FACIL_DOCK;
+ this->flags |= VL_REBUILD;
+ this->SetDirty();
+ break;
+
+ case SLW_CARGOALL: {
+ uint i = 0;
+ for (CargoID c = 0; c < NUM_CARGO; c++) {
+ if (!GetCargo(c)->IsValid()) continue;
+ this->LowerWidget(i + SLW_CARGOSTART);
+ i++;
+ }
+ this->LowerWidget(SLW_NOCARGOWAITING);
+ this->LowerWidget(SLW_CARGOALL);
+
+ _cargo_filter = _cargo_mask;
+ include_empty = true;
+ this->flags |= VL_REBUILD;
+ this->SetDirty();
+ break;
+ }
+
+ case SLW_SORTBY: // flip sorting method asc/desc
+ this->flags ^= VL_DESC; //DESC-flag
+ station_sort.order = HasBit(this->flags, 0);
+ this->flags |= VL_RESORT;
+ this->flags4 |= 5 << WF_TIMEOUT_SHL;
+ this->LowerWidget(SLW_SORTBY);
+ this->SetDirty();
+ break;
+
+ case SLW_SORTDROPBTN: // select sorting criteria dropdown menu
+ ShowDropDownMenu(this, _station_sort_listing, this->sort_type, SLW_SORTDROPBTN, 0, 0);
+ break;
+
+ case SLW_NOCARGOWAITING:
+ if (_ctrl_pressed) {
+ include_empty = !include_empty;
+ this->ToggleWidgetLoweredState(SLW_NOCARGOWAITING);
+ } else {
+ for (uint i = SLW_CARGOSTART; i < this->widget_count; i++) {
+ this->RaiseWidget(i);
}
- w->LowerWidget(SLW_FACILALL);
- facilities = FACIL_TRAIN | FACIL_TRUCK_STOP | FACIL_BUS_STOP | FACIL_AIRPORT | FACIL_DOCK;
- sl->flags |= SL_REBUILD;
- SetWindowDirty(w);
- break;
+ _cargo_filter = 0;
+ include_empty = true;
- case SLW_CARGOALL: {
- uint i = 0;
- for (CargoID c = 0; c < NUM_CARGO; c++) {
+ this->LowerWidget(SLW_NOCARGOWAITING);
+ }
+ this->flags |= VL_REBUILD;
+ this->SetWidgetLoweredState(SLW_CARGOALL, _cargo_filter == _cargo_mask && include_empty);
+ this->SetDirty();
+ break;
+
+ default:
+ if (widget >= SLW_CARGOSTART) { // change cargo_filter
+ /* Determine the selected cargo type */
+ CargoID c;
+ int i = 0;
+ for (c = 0; c < NUM_CARGO; c++) {
if (!GetCargo(c)->IsValid()) continue;
- w->LowerWidget(i + SLW_CARGOSTART);
+ if (widget - SLW_CARGOSTART == i) break;
i++;
}
- w->LowerWidget(SLW_NOCARGOWAITING);
- w->LowerWidget(SLW_CARGOALL);
-
- _cargo_filter = _cargo_mask;
- include_empty = true;
- sl->flags |= SL_REBUILD;
- SetWindowDirty(w);
- break;
- }
- case SLW_SORTBY: // flip sorting method asc/desc
- sl->flags ^= SL_ORDER; //DESC-flag
- station_sort.order = HasBit(sl->flags, 0);
- sl->flags |= SL_RESORT;
- w->flags4 |= 5 << WF_TIMEOUT_SHL;
- w->LowerWidget(SLW_SORTBY);
- SetWindowDirty(w);
- break;
-
- case SLW_SORTDROPBTN: // select sorting criteria dropdown menu
- ShowDropDownMenu(w, _station_sort_listing, sl->sort_type, SLW_SORTDROPBTN, 0, 0);
- break;
-
- case SLW_NOCARGOWAITING:
if (_ctrl_pressed) {
- include_empty = !include_empty;
- w->ToggleWidgetLoweredState(SLW_NOCARGOWAITING);
+ ToggleBit(_cargo_filter, c);
+ this->ToggleWidgetLoweredState(widget);
} else {
- for (uint i = SLW_CARGOSTART; i < w->widget_count; i++) {
- w->RaiseWidget(i);
+ for (uint i = SLW_CARGOSTART; i < this->widget_count; i++) {
+ this->RaiseWidget(i);
}
+ this->RaiseWidget(SLW_NOCARGOWAITING);
_cargo_filter = 0;
- include_empty = true;
-
- w->LowerWidget(SLW_NOCARGOWAITING);
- }
- sl->flags |= SL_REBUILD;
- w->SetWidgetLoweredState(SLW_CARGOALL, _cargo_filter == _cargo_mask && include_empty);
- SetWindowDirty(w);
- break;
-
- default:
- if (e->we.click.widget >= SLW_CARGOSTART) { // change cargo_filter
- /* Determine the selected cargo type */
- CargoID c;
- int i = 0;
- for (c = 0; c < NUM_CARGO; c++) {
- if (!GetCargo(c)->IsValid()) continue;
- if (e->we.click.widget - SLW_CARGOSTART == i) break;
- i++;
- }
-
- if (_ctrl_pressed) {
- ToggleBit(_cargo_filter, c);
- w->ToggleWidgetLoweredState(e->we.click.widget);
- } else {
- for (uint i = SLW_CARGOSTART; i < w->widget_count; i++) {
- w->RaiseWidget(i);
- }
- w->RaiseWidget(SLW_NOCARGOWAITING);
-
- _cargo_filter = 0;
- include_empty = false;
+ include_empty = false;
- SetBit(_cargo_filter, c);
- w->LowerWidget(e->we.click.widget);
- }
- sl->flags |= SL_REBUILD;
- w->SetWidgetLoweredState(SLW_CARGOALL, _cargo_filter == _cargo_mask && include_empty);
- SetWindowDirty(w);
+ SetBit(_cargo_filter, c);
+ this->LowerWidget(widget);
}
- break;
- }
- break;
+ this->flags |= VL_REBUILD;
+ this->SetWidgetLoweredState(SLW_CARGOALL, _cargo_filter == _cargo_mask && include_empty);
+ this->SetDirty();
+ }
+ break;
+ }
+ }
- case WE_DROPDOWN_SELECT: // we have selected a dropdown item in the list
- if (sl->sort_type != e->we.dropdown.index) {
- /* value has changed -> resort */
- sl->sort_type = e->we.dropdown.index;
- station_sort.criteria = sl->sort_type;
- sl->flags |= SL_RESORT;
- }
- SetWindowDirty(w);
- break;
+ virtual void OnDropdownSelect(int widget, int index)
+ {
+ if (this->sort_type != index) {
+ /* value has changed -> resort */
+ this->sort_type = index;
+ station_sort.criteria = this->sort_type;
+ this->flags |= VL_RESORT;
+ }
+ this->SetDirty();
+ }
- case WE_TICK:
- if (_pause_game != 0) break;
- if (--sl->resort_timer == 0) {
- DEBUG(misc, 3, "Periodic rebuild station list player %d", owner);
- sl->resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS;
- sl->flags |= SL_REBUILD;
- SetWindowDirty(w);
- }
- break;
+ virtual void OnTick()
+ {
+ if (_pause_game != 0) return;
+ if (--this->resort_timer == 0) {
+ DEBUG(misc, 3, "Periodic rebuild station list player %d", this->window_number);
+ this->resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS;
+ this->flags |= VL_REBUILD;
+ this->SetDirty();
+ }
+ }
- case WE_TIMEOUT:
- w->RaiseWidget(SLW_SORTBY);
- SetWindowDirty(w);
- break;
+ virtual void OnTimeout()
+ {
+ this->RaiseWidget(SLW_SORTBY);
+ this->SetDirty();
+ }
- case WE_RESIZE:
- w->vscroll.cap += e->we.sizing.diff.y / 10;
- break;
+ virtual void OnResize(Point new_size, Point delta)
+ {
+ this->vscroll.cap += delta.y / 10;
}
-}
+};
+
+Listing PlayerStationsWindow::station_sort = {0, 0};
+byte PlayerStationsWindow::facilities = FACIL_TRAIN | FACIL_TRUCK_STOP | FACIL_BUS_STOP | FACIL_AIRPORT | FACIL_DOCK;
+bool PlayerStationsWindow::include_empty = true;
+
static const Widget _player_stations_widgets[] = {
{ WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, // SLW_CLOSEBOX
@@ -603,7 +643,7 @@
WC_STATION_LIST, WC_NONE,
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON | WDF_RESIZABLE,
_player_stations_widgets,
- PlayerStationsWndProc
+ NULL
};
/**
@@ -615,54 +655,7 @@
{
if (!IsValidPlayer(player)) return;
- 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
-
- /* 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;
-
- Widget *wi = &w->widget[SLW_CARGOSTART + i];
- 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;
-
- if (HasBit(_cargo_filter, c)) w->LowerWidget(SLW_CARGOSTART + i);
- i++;
- }
-
- 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;
-
- if (num_active > 15) {
- /* Resize and fix the minimum width, if necessary */
- ResizeWindow(w, (num_active - 15) * 14, 0);
- w->resize.width = w->width;
- }
+ AllocateWindowDescFront<PlayerStationsWindow>(&_player_stations_desc, player);
}
static const Widget _station_view_widgets[] = {
@@ -721,12 +714,6 @@
} while (--num);
}
-struct stationview_d {
- uint32 cargo; ///< Bitmask of cargo types to expand
- uint16 cargo_rows[NUM_CARGO]; ///< Header row for each cargo type
-};
-assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(stationview_d));
-
struct CargoData {
CargoID cargo;
StationID source;
@@ -742,281 +729,285 @@
typedef std::list<CargoData> CargoDataList;
/**
- * Redraws whole StationView window
- *
- * @param w pointer to window
+ * The StationView window
*/
-static void DrawStationViewWindow(Window *w)
-{
- StationID station_id = w->window_number;
- const Station *st = GetStation(station_id);
- CargoDataList cargolist;
- uint32 transfers = 0;
-
- /* count types of cargos waiting in station */
- for (CargoID i = 0; i < NUM_CARGO; i++) {
- if (st->goods[i].cargo.Empty()) {
- WP(w, stationview_d).cargo_rows[i] = 0;
- } else {
- /* Add an entry for total amount of cargo of this type waiting. */
- cargolist.push_back(CargoData(i, INVALID_STATION, st->goods[i].cargo.Count()));
-
- /* Set the row for this cargo entry for the expand/hide button */
- WP(w, stationview_d).cargo_rows[i] = cargolist.size();
+struct StationViewWindow : public Window {
+ uint32 cargo; ///< Bitmask of cargo types to expand
+ uint16 cargo_rows[NUM_CARGO]; ///< Header row for each cargo type
- /* Add an entry for each distinct cargo source. */
- const CargoList::List *packets = st->goods[i].cargo.Packets();
- for (CargoList::List::const_iterator it = packets->begin(); it != packets->end(); it++) {
- const CargoPacket *cp = *it;
- if (cp->source != station_id) {
- bool added = false;
-
- /* Enable the expand/hide button for this cargo type */
- SetBit(transfers, i);
+ StationViewWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number)
+ {
+ PlayerID owner = GetStation(window_number)->owner;
+ if (owner != OWNER_NONE) this->caption_color = owner;
+ this->vscroll.cap = 5;
+ this->resize.step_height = 10;
- /* Don't add cargo lines if not expanded */
- if (!HasBit(WP(w, stationview_d).cargo, i)) break;
+ this->FindWindowPlacementAndResize(desc);
+ }
- /* Check if we already have this source in the list */
- for (CargoDataList::iterator jt = cargolist.begin(); jt != cargolist.end(); jt++) {
- CargoData *cd = &(*jt);
- if (cd->cargo == i && cd->source == cp->source) {
- cd->count += cp->count;
- added = true;
- break;
+ ~StationViewWindow()
+ {
+ WindowNumber wno =
+ (this->window_number << 16) | VLW_STATION_LIST | GetStation(this->window_number)->owner;
+
+ DeleteWindowById(WC_TRAINS_LIST, wno);
+ DeleteWindowById(WC_ROADVEH_LIST, wno);
+ DeleteWindowById(WC_SHIPS_LIST, wno);
+ DeleteWindowById(WC_AIRCRAFT_LIST, wno);
+ }
+
+ virtual void OnPaint()
+ {
+ StationID station_id = this->window_number;
+ const Station *st = GetStation(station_id);
+ CargoDataList cargolist;
+ uint32 transfers = 0;
+
+ /* count types of cargos waiting in station */
+ for (CargoID i = 0; i < NUM_CARGO; i++) {
+ if (st->goods[i].cargo.Empty()) {
+ this->cargo_rows[i] = 0;
+ } else {
+ /* Add an entry for total amount of cargo of this type waiting. */
+ cargolist.push_back(CargoData(i, INVALID_STATION, st->goods[i].cargo.Count()));
+
+ /* Set the row for this cargo entry for the expand/hide button */
+ this->cargo_rows[i] = cargolist.size();
+
+ /* Add an entry for each distinct cargo source. */
+ const CargoList::List *packets = st->goods[i].cargo.Packets();
+ for (CargoList::List::const_iterator it = packets->begin(); it != packets->end(); it++) {
+ const CargoPacket *cp = *it;
+ if (cp->source != station_id) {
+ bool added = false;
+
+ /* Enable the expand/hide button for this cargo type */
+ SetBit(transfers, i);
+
+ /* Don't add cargo lines if not expanded */
+ if (!HasBit(this->cargo, i)) break;
+
+ /* Check if we already have this source in the list */
+ for (CargoDataList::iterator jt = cargolist.begin(); jt != cargolist.end(); jt++) {
+ CargoData *cd = &(*jt);
+ if (cd->cargo == i && cd->source == cp->source) {
+ cd->count += cp->count;
+ added = true;
+ break;
+ }
}
+
+ if (!added) cargolist.push_back(CargoData(i, cp->source, cp->count));
}
-
- if (!added) cargolist.push_back(CargoData(i, cp->source, cp->count));
}
}
}
- }
- SetVScrollCount(w, cargolist.size() + 1); // update scrollbar
-
- /* 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));
-
- SetDParam(0, st->index);
- SetDParam(1, st->facilities);
- DrawWindowWidgets(w);
-
- int x = 2; ///< coordinates used for printing waiting/accepted/rating of cargo
- int y = 15;
- int pos = w->vscroll.pos; ///< = w->vscroll.pos
-
- uint width = w->widget[SVW_WAITING].right - w->widget[SVW_WAITING].left - 4;
- int maxrows = w->vscroll.cap;
-
- StringID str;
+ SetVScrollCount(this, cargolist.size() + 1); // update scrollbar
- if (--pos < 0) {
- str = STR_00D0_NOTHING;
- for (CargoID i = 0; i < NUM_CARGO; i++) {
- if (!st->goods[i].cargo.Empty()) str = STR_EMPTY;
- }
- SetDParam(0, str);
- DrawString(x, y, STR_0008_WAITING, TC_FROMSTRING);
- y += 10;
- }
+ /* disable some buttons */
+ this->SetWidgetDisabledState(SVW_RENAME, st->owner != _local_player);
+ this->SetWidgetDisabledState(SVW_TRAINS, !(st->facilities & FACIL_TRAIN));
+ this->SetWidgetDisabledState(SVW_ROADVEHS, !(st->facilities & FACIL_TRUCK_STOP) && !(st->facilities & FACIL_BUS_STOP));
+ this->SetWidgetDisabledState(SVW_PLANES, !(st->facilities & FACIL_AIRPORT));
+ this->SetWidgetDisabledState(SVW_SHIPS, !(st->facilities & FACIL_DOCK));
- for (CargoDataList::const_iterator it = cargolist.begin(); it != cargolist.end() && pos > -maxrows; ++it) {
+ SetDParam(0, st->index);
+ SetDParam(1, st->facilities);
+ this->DrawWidgets();
+
+ int x = 2; ///< coordinates used for printing waiting/accepted/rating of cargo
+ int y = 15;
+ int pos = this->vscroll.pos; ///< = this->vscroll.pos
+
+ uint width = this->widget[SVW_WAITING].right - this->widget[SVW_WAITING].left - 4;
+ int maxrows = this->vscroll.cap;
+
+ StringID str;
+
if (--pos < 0) {
- const CargoData *cd = &(*it);
- if (cd->source == INVALID_STATION) {
- /* Heading */
- DrawCargoIcons(cd->cargo, cd->count, x, y, width);
- SetDParam(0, cd->cargo);
- SetDParam(1, cd->count);
- if (HasBit(transfers, cd->cargo)) {
- /* This cargo has transfers waiting so show the expand or shrink 'button' */
- const char *sym = HasBit(WP(w, stationview_d).cargo, cd->cargo) ? "-" : "+";
- DrawStringRightAligned(x + width - 8, y, STR_0009, TC_FROMSTRING);
- DoDrawString(sym, x + width - 6, y, TC_YELLOW);
- } else {
- DrawStringRightAligned(x + width, y, STR_0009, TC_FROMSTRING);
- }
- } else {
- SetDParam(0, cd->cargo);
- SetDParam(1, cd->count);
- SetDParam(2, cd->source);
- DrawStringRightAlignedTruncated(x + width, y, STR_EN_ROUTE_FROM, TC_FROMSTRING, width);
+ str = STR_00D0_NOTHING;
+ for (CargoID i = 0; i < NUM_CARGO; i++) {
+ if (!st->goods[i].cargo.Empty()) str = STR_EMPTY;
}
-
+ SetDParam(0, str);
+ DrawString(x, y, STR_0008_WAITING, TC_FROMSTRING);
y += 10;
}
- }
-
- if (w->widget[SVW_ACCEPTS].data == STR_3032_RATINGS) { // small window with list of accepted cargo
- char *b = _userstring;
- bool first = true;
-
- b = InlineString(b, STR_000C_ACCEPTS);
- for (CargoID i = 0; i < NUM_CARGO; i++) {
- if (b >= lastof(_userstring) - (1 + 2 * 4)) break; // ',' or ' ' and two calls to Utf8Encode()
- if (HasBit(st->goods[i].acceptance_pickup, GoodsEntry::ACCEPTANCE)) {
- if (first) {
- first = false;
+ for (CargoDataList::const_iterator it = cargolist.begin(); it != cargolist.end() && pos > -maxrows; ++it) {
+ if (--pos < 0) {
+ const CargoData *cd = &(*it);
+ if (cd->source == INVALID_STATION) {
+ /* Heading */
+ DrawCargoIcons(cd->cargo, cd->count, x, y, width);
+ SetDParam(0, cd->cargo);
+ SetDParam(1, cd->count);
+ if (HasBit(transfers, cd->cargo)) {
+ /* This cargo has transfers waiting so show the expand or shrink 'button' */
+ const char *sym = HasBit(this->cargo, cd->cargo) ? "-" : "+";
+ DrawStringRightAligned(x + width - 8, y, STR_0009, TC_FROMSTRING);
+ DoDrawString(sym, x + width - 6, y, TC_YELLOW);
+ } else {
+ DrawStringRightAligned(x + width, y, STR_0009, TC_FROMSTRING);
+ }
} else {
- /* Add a comma if this is not the first item */
- *b++ = ',';
- *b++ = ' ';
+ SetDParam(0, cd->cargo);
+ SetDParam(1, cd->count);
+ SetDParam(2, cd->source);
+ DrawStringRightAlignedTruncated(x + width, y, STR_EN_ROUTE_FROM, TC_FROMSTRING, width);
}
- b = InlineString(b, GetCargo(i)->name);
+
+ y += 10;
}
}
- /* If first is still true then no cargo is accepted */
- if (first) b = InlineString(b, STR_00D0_NOTHING);
-
- *b = '\0';
-
- /* Make sure we detect any buffer overflow */
- assert(b < endof(_userstring));
-
- DrawStringMultiLine(2, w->widget[SVW_ACCEPTLIST].top + 1, STR_SPEC_USERSTRING, w->widget[SVW_ACCEPTLIST].right - w->widget[SVW_ACCEPTLIST].left);
- } else { // extended window with list of cargo ratings
- y = w->widget[SVW_RATINGLIST].top + 1;
-
- DrawString(2, y, STR_3034_LOCAL_RATING_OF_TRANSPORT, TC_FROMSTRING);
- y += 10;
-
- for (CargoID i = 0; i < NUM_CARGO; i++) {
- const CargoSpec *cs = GetCargo(i);
- if (!cs->IsValid()) continue;
+ if (this->widget[SVW_ACCEPTS].data == STR_3032_RATINGS) { // small window with list of accepted cargo
+ char *b = _userstring;
+ bool first = true;
- const GoodsEntry *ge = &st->goods[i];
- if (!HasBit(ge->acceptance_pickup, GoodsEntry::PICKUP)) continue;
+ b = InlineString(b, STR_000C_ACCEPTS);
- SetDParam(0, cs->name);
- SetDParam(2, ge->rating * 101 >> 8);
- SetDParam(1, STR_3035_APPALLING + (ge->rating >> 5));
- DrawString(8, y, STR_303D, TC_FROMSTRING);
+ for (CargoID i = 0; i < NUM_CARGO; i++) {
+ if (b >= lastof(_userstring) - (1 + 2 * 4)) break; // ',' or ' ' and two calls to Utf8Encode()
+ if (HasBit(st->goods[i].acceptance_pickup, GoodsEntry::ACCEPTANCE)) {
+ if (first) {
+ first = false;
+ } else {
+ /* Add a comma if this is not the first item */
+ *b++ = ',';
+ *b++ = ' ';
+ }
+ b = InlineString(b, GetCargo(i)->name);
+ }
+ }
+
+ /* If first is still true then no cargo is accepted */
+ if (first) b = InlineString(b, STR_00D0_NOTHING);
+
+ *b = '\0';
+
+ /* Make sure we detect any buffer overflow */
+ assert(b < endof(_userstring));
+
+ DrawStringMultiLine(2, this->widget[SVW_ACCEPTLIST].top + 1, STR_SPEC_USERSTRING, this->widget[SVW_ACCEPTLIST].right - this->widget[SVW_ACCEPTLIST].left);
+ } else { // extended window with list of cargo ratings
+ y = this->widget[SVW_RATINGLIST].top + 1;
+
+ DrawString(2, y, STR_3034_LOCAL_RATING_OF_TRANSPORT, TC_FROMSTRING);
y += 10;
- }
- }
-}
-static void HandleCargoWaitingClick(Window *w, int row)
-{
- if (row == 0) return;
+ for (CargoID i = 0; i < NUM_CARGO; i++) {
+ const CargoSpec *cs = GetCargo(i);
+ if (!cs->IsValid()) continue;
- for (CargoID c = 0; c < NUM_CARGO; c++) {
- if (WP(w, stationview_d).cargo_rows[c] == row) {
- ToggleBit(WP(w, stationview_d).cargo, c);
- w->InvalidateWidget(SVW_WAITING);
- break;
+ const GoodsEntry *ge = &st->goods[i];
+ if (!HasBit(ge->acceptance_pickup, GoodsEntry::PICKUP)) continue;
+
+ SetDParam(0, cs->name);
+ SetDParam(2, ge->rating * 101 >> 8);
+ SetDParam(1, STR_3035_APPALLING + (ge->rating >> 5));
+ DrawString(8, y, STR_303D, TC_FROMSTRING);
+ y += 10;
+ }
}
}
-}
-
-
-/**
- * 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)
-{
- switch (e->event) {
- case WE_PAINT:
- DrawStationViewWindow(w);
- break;
-
- case WE_CLICK:
- switch (e->we.click.widget) {
- case SVW_WAITING:
- HandleCargoWaitingClick(w, (e->we.click.pt.y - w->widget[SVW_WAITING].top) / 10 + w->vscroll.pos);
- break;
-
- case SVW_LOCATION:
- ScrollMainWindowToTile(GetStation(w->window_number)->xy);
- break;
- case SVW_RATINGS:
- SetWindowDirty(w);
+ void HandleCargoWaitingClick(int row)
+ {
+ if (row == 0) return;
- if (w->widget[SVW_RATINGS].data == STR_3032_RATINGS) {
- /* Switch to ratings view */
- w->widget[SVW_RATINGS].data = STR_3033_ACCEPTS;
- w->widget[SVW_RATINGS].tooltips = STR_3056_SHOW_LIST_OF_ACCEPTED_CARGO;
- ResizeWindowForWidget(w, SVW_ACCEPTLIST, 0, 100);
- } else {
- /* Switch to accepts view */
- w->widget[SVW_RATINGS].data = STR_3032_RATINGS;
- w->widget[SVW_RATINGS].tooltips = STR_3054_SHOW_STATION_RATINGS;
- ResizeWindowForWidget(w, SVW_ACCEPTLIST, 0, -100);
- }
+ for (CargoID c = 0; c < NUM_CARGO; c++) {
+ if (this->cargo_rows[c] == row) {
+ ToggleBit(this->cargo, c);
+ this->InvalidateWidget(SVW_WAITING);
+ break;
+ }
+ }
+ }
- SetWindowDirty(w);
- break;
+ virtual void OnClick(Point pt, int widget)
+ {
+ switch (widget) {
+ case SVW_WAITING:
+ this->HandleCargoWaitingClick((pt.y - this->widget[SVW_WAITING].top) / 10 + this->vscroll.pos);
+ break;
- case SVW_RENAME:
- SetDParam(0, w->window_number);
- ShowQueryString(STR_STATION, STR_3030_RENAME_STATION_LOADING, 31, 180, w, CS_ALPHANUMERAL);
- break;
+ case SVW_LOCATION:
+ if (_ctrl_pressed) {
+ ShowExtraViewPortWindow(GetStation(this->window_number)->xy);
+ } else {
+ ScrollMainWindowToTile(GetStation(this->window_number)->xy);
+ }
+ break;
- case SVW_TRAINS: { // Show a list of scheduled trains to this station
- const Station *st = GetStation(w->window_number);
- ShowVehicleListWindow(st->owner, VEH_TRAIN, (StationID)w->window_number);
- break;
+ case SVW_RATINGS:
+ this->SetDirty();
+
+ if (this->widget[SVW_RATINGS].data == STR_3032_RATINGS) {
+ /* Switch to ratings view */
+ this->widget[SVW_RATINGS].data = STR_3033_ACCEPTS;
+ this->widget[SVW_RATINGS].tooltips = STR_3056_SHOW_LIST_OF_ACCEPTED_CARGO;
+ ResizeWindowForWidget(this, SVW_ACCEPTLIST, 0, 100);
+ } else {
+ /* Switch to accepts view */
+ this->widget[SVW_RATINGS].data = STR_3032_RATINGS;
+ this->widget[SVW_RATINGS].tooltips = STR_3054_SHOW_STATION_RATINGS;
+ ResizeWindowForWidget(this, SVW_ACCEPTLIST, 0, -100);
}
- case SVW_ROADVEHS: { // Show a list of scheduled road-vehicles to this station
- const Station *st = GetStation(w->window_number);
- ShowVehicleListWindow(st->owner, VEH_ROAD, (StationID)w->window_number);
- break;
- }
-
- case SVW_PLANES: { // Show a list of scheduled aircraft to this station
- 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;
- ShowVehicleListWindow(owner, VEH_AIRCRAFT, (StationID)w->window_number);
- break;
- }
-
- case SVW_SHIPS: { // Show a list of scheduled ships to this station
- 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;
- ShowVehicleListWindow(owner, VEH_SHIP, (StationID)w->window_number);
- break;
- }
- }
- break;
+ this->SetDirty();
+ break;
- 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));
- }
- break;
-
- case WE_DESTROY: {
- WindowNumber wno =
- (w->window_number << 16) | VLW_STATION_LIST | GetStation(w->window_number)->owner;
+ case SVW_RENAME:
+ SetDParam(0, this->window_number);
+ ShowQueryString(STR_STATION, STR_3030_RENAME_STATION_LOADING, 31, 180, this, CS_ALPHANUMERAL);
+ break;
- DeleteWindowById(WC_TRAINS_LIST, wno);
- DeleteWindowById(WC_ROADVEH_LIST, wno);
- DeleteWindowById(WC_SHIPS_LIST, wno);
- DeleteWindowById(WC_AIRCRAFT_LIST, wno);
- break;
+ case SVW_TRAINS: { // Show a list of scheduled trains to this station
+ const Station *st = GetStation(this->window_number);
+ ShowVehicleListWindow(st->owner, VEH_TRAIN, (StationID)this->window_number);
+ break;
+ }
+
+ case SVW_ROADVEHS: { // Show a list of scheduled road-vehicles to this station
+ const Station *st = GetStation(this->window_number);
+ ShowVehicleListWindow(st->owner, VEH_ROAD, (StationID)this->window_number);
+ break;
+ }
+
+ case SVW_PLANES: { // Show a list of scheduled aircraft to this station
+ const Station *st = GetStation(this->window_number);
+ /* Since oilrigs have no owners, show the scheduled aircraft of current player */
+ PlayerID owner = (st->owner == OWNER_NONE) ? _current_player : st->owner;
+ ShowVehicleListWindow(owner, VEH_AIRCRAFT, (StationID)this->window_number);
+ break;
+ }
+
+ case SVW_SHIPS: { // Show a list of scheduled ships to this station
+ const Station *st = GetStation(this->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;
+ ShowVehicleListWindow(owner, VEH_SHIP, (StationID)this->window_number);
+ break;
+ }
}
+ }
- case WE_RESIZE:
- if (e->we.sizing.diff.x != 0) ResizeButtons(w, SVW_LOCATION, SVW_RENAME);
- w->vscroll.cap += e->we.sizing.diff.y / (int)w->resize.step_height;
- break;
+ virtual void OnQueryTextFinished(char *str)
+ {
+ if (!StrEmpty(str)) {
+ _cmd_text = str;
+ DoCommandP(0, this->window_number, 0, NULL,
+ CMD_RENAME_STATION | CMD_MSG(STR_3031_CAN_T_RENAME_STATION));
+ }
}
-}
+
+ virtual void OnResize(Point new_size, Point delta)
+ {
+ if (delta.x != 0) ResizeButtons(this, SVW_LOCATION, SVW_RENAME);
+ this->vscroll.cap += delta.y / (int)this->resize.step_height;
+ }
+};
static const WindowDesc _station_view_desc = {
@@ -1024,7 +1015,7 @@
WC_STATION_VIEW, WC_NONE,
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
_station_view_widgets,
- StationViewWndProc
+ NULL
};
/**
@@ -1034,11 +1025,5 @@
*/
void ShowStationViewWindow(StationID station)
{
- Window *w = AllocateWindowDescFront(&_station_view_desc, station);
- if (w == NULL) return;
-
- PlayerID owner = GetStation(w->window_number)->owner;
- if (owner != OWNER_NONE) w->caption_color = owner;
- w->vscroll.cap = 5;
- w->resize.step_height = 10;
+ AllocateWindowDescFront<StationViewWindow>(&_station_view_desc, station);
}