tron@2186: /* $Id$ */ tron@2186: richk@10724: /** @file station_gui.cpp The GUI for stations. */ richk@6719: truelight@0: #include "stdafx.h" Darkvater@1891: #include "openttd.h" tron@1299: #include "debug.h" truelight@0: #include "gui.h" rubidium@6872: #include "window_gui.h" rubidium@6872: #include "textbuf_gui.h" richk@10184: #include "station_base.h" rubidium@6872: #include "player_func.h" rubidium@6872: #include "economy_func.h" truelight@0: #include "town.h" rubidium@6872: #include "command_func.h" tron@2159: #include "variables.h" tron@2159: #include "vehicle_gui.h" peter1138@6417: #include "cargotype.h" rubidium@6872: #include "station_gui.h" richk@10184: #include "station_func.h" rubidium@6872: #include "strings_func.h" rubidium@6872: #include "core/alloc_func.hpp" rubidium@6872: #include "window_func.h" rubidium@6872: #include "viewport_func.h" rubidium@6872: #include "gfx_func.h" rubidium@6872: #include "widgets/dropdown_func.h" richk@10184: #include "newgrf_cargo.h" richk@10724: #include "string_func.h" truelight@0: rubidium@6872: #include "table/strings.h" rubidium@6872: #include "table/sprites.h" belugas@5271: celestar@3812: typedef int CDECL StationSortListingTypeFunction(const void*, const void*); celestar@3812: celestar@3812: static StationSortListingTypeFunction StationNameSorter; celestar@3812: static StationSortListingTypeFunction StationTypeSorter; celestar@3812: static StationSortListingTypeFunction StationWaitingSorter; celestar@3812: static StationSortListingTypeFunction StationRatingMaxSorter; celestar@3812: rubidium@6872: bool _station_show_coverage; rubidium@6872: rubidium@6872: /** rubidium@6872: * Draw small boxes of cargo amount and ratings data at the given Darkvater@5293: * coordinates. If amount exceeds 576 units, it is shown 'full', same Darkvater@5293: * goes for the rating: at above 90% orso (224) it is also 'full' rubidium@6872: * richk@6719: * @param x coordinate to draw the box at richk@6719: * @param y coordinate to draw the box at Darkvater@5293: * @param type Cargo type Darkvater@5293: * @param amount Cargo amount rubidium@6872: * @param rating ratings data for that particular cargo rubidium@6872: * rubidium@6872: * @note Each cargo-bar is 16 pixels wide and 6 pixels high rubidium@6872: * @note Each rating 14 pixels wide and 1 pixel high and is 1 pixel below the cargo-bar rubidium@6872: */ Darkvater@5293: static void StationsWndShowStationRating(int x, int y, CargoID type, uint amount, byte rating) truelight@0: { rubidium@6872: static const uint units_full = 576; ///< number of units to show station as 'full' rubidium@6872: static const uint rating_full = 224; ///< rating needed so it is shown as 'full' rubidium@6872: peter1138@6417: const CargoSpec *cs = GetCargo(type); peter1138@6448: if (!cs->IsValid()) return; peter1138@6417: peter1138@6417: int colour = cs->rating_colour; rubidium@6872: uint w = (minu(amount, units_full) + 5) / 36; truelight@0: Darkvater@5293: /* Draw total cargo (limited) on station (fits into 16 pixels) */ Darkvater@5293: if (w != 0) GfxFillRect(x, y, x + w - 1, y + 6, colour); truelight@0: Darkvater@5293: /* Draw a one pixel-wide bar of additional cargo meter, useful Darkvater@5293: * for stations with only a small amount (<=30) */ Darkvater@5293: if (w == 0) { Darkvater@5293: uint rest = amount / 5; Darkvater@5293: if (rest != 0) { Darkvater@5293: w += x; Darkvater@5293: GfxFillRect(w, y + 6 - rest, w, y + 6, colour); Darkvater@5293: } truelight@0: } truelight@0: rubidium@6871: DrawString(x + 1, y, cs->abbrev, TC_BLACK); truelight@0: Darkvater@5293: /* Draw green/red ratings bar (fits into 14 pixels) */ Darkvater@5293: y += 8; Darkvater@5293: GfxFillRect(x + 1, y, x + 14, y, 0xB8); rubidium@6872: rating = minu(rating, rating_full) / 16; Darkvater@5293: if (rating != 0) GfxFillRect(x + 1, y, x + rating, y, 0xD0); truelight@0: } truelight@0: celestar@3812: const StringID _station_sort_listing[] = { celestar@3812: STR_SORT_BY_DROPDOWN_NAME, celestar@3812: STR_SORT_BY_FACILITY, celestar@3812: STR_SORT_BY_WAITING, celestar@3812: STR_SORT_BY_RATING_MAX, celestar@3812: INVALID_STRING_ID celestar@3812: }; truelight@0: truelight@0: static char _bufcache[64]; richk@10242: static const Station *_last_station; celestar@3812: static int _internal_sort_order; truelight@0: darkvater@164: static int CDECL StationNameSorter(const void *a, const void *b) truelight@0: { richk@10242: const Station *st1 = *(const Station**)a; richk@10242: const Station *st2 = *(const Station**)b; truelight@0: char buf1[64]; truelight@0: Darkvater@4416: SetDParam(0, st1->index); Darkvater@4912: GetString(buf1, STR_STATION, lastof(buf1)); darkvater@164: tron@4277: if (st2 != _last_station) { tron@4277: _last_station = st2; Darkvater@4416: SetDParam(0, st2->index); Darkvater@4912: GetString(_bufcache, STR_STATION, lastof(_bufcache)); darkvater@164: } truelight@0: richk@10242: int r = strcmp(buf1, _bufcache); // sort by name celestar@3812: return (_internal_sort_order & 1) ? -r : r; truelight@0: } truelight@0: celestar@3812: static int CDECL StationTypeSorter(const void *a, const void *b) truelight@0: { richk@10242: const Station *st1 = *(const Station**)a; richk@10242: const Station *st2 = *(const Station**)b; celestar@3812: return (_internal_sort_order & 1) ? st2->facilities - st1->facilities : st1->facilities - st2->facilities; celestar@3812: } celestar@3812: richk@10242: static const uint32 _cargo_filter_max = UINT32_MAX; rubidium@6871: static uint32 _cargo_filter = _cargo_filter_max; rubidium@6871: celestar@3812: static int CDECL StationWaitingSorter(const void *a, const void *b) celestar@3812: { richk@10242: const Station *st1 = *(const Station**)a; richk@10242: const Station *st2 = *(const Station**)b; richk@6720: Money sum1 = 0, sum2 = 0; celestar@3812: peter1138@6528: for (CargoID j = 0; j < NUM_CARGO; j++) { rubidium@6871: if (!HasBit(_cargo_filter, j)) continue; richk@6720: if (!st1->goods[j].cargo.Empty()) sum1 += GetTransportedGoodsIncome(st1->goods[j].cargo.Count(), 20, 50, j); richk@6720: if (!st2->goods[j].cargo.Empty()) sum2 += GetTransportedGoodsIncome(st2->goods[j].cargo.Count(), 20, 50, j); celestar@3812: } celestar@3812: richk@6720: return (_internal_sort_order & 1) ? ClampToI32(sum2 - sum1) : ClampToI32(sum1 - sum2); celestar@3812: } celestar@3812: celestar@6579: /** celestar@6579: * qsort-compatible version of sorting two stations by maximum rating celestar@6579: * @param a First object to be sorted, must be of type (const Station *) celestar@6579: * @param b Second object to be sorted, must be of type (const Station *) celestar@6579: * @return The sort order celestar@6579: * @retval >0 a should come before b in the list celestar@6579: * @retval <0 b should come before a in the list celestar@6579: */ celestar@3812: static int CDECL StationRatingMaxSorter(const void *a, const void *b) celestar@3812: { richk@10242: const Station *st1 = *(const Station**)a; richk@10242: const Station *st2 = *(const Station**)b; celestar@3812: byte maxr1 = 0; celestar@3812: byte maxr2 = 0; celestar@3812: peter1138@6528: for (CargoID j = 0; j < NUM_CARGO; j++) { rubidium@6871: if (HasBit(st1->goods[j].acceptance_pickup, GoodsEntry::PICKUP)) maxr1 = max(maxr1, st1->goods[j].rating); rubidium@6871: if (HasBit(st2->goods[j].acceptance_pickup, GoodsEntry::PICKUP)) maxr2 = max(maxr2, st2->goods[j].rating); celestar@3812: } celestar@3812: celestar@3812: return (_internal_sort_order & 1) ? maxr2 - maxr1 : maxr1 - maxr2; celestar@3812: } celestar@3812: richk@10724: typedef GUIList GUIStationList; celestar@3812: rubidium@6872: /** richk@10724: * Rebuild station list if the VL_REBUILD flag is set rubidium@6872: * rubidium@6872: * @param sl pointer to plstations_d (station list and flags) rubidium@6872: * @param owner player whose stations are to be in list rubidium@6872: * @param facilities types of stations of interest rubidium@6872: * @param cargo_filter bitmap of cargo types to include rubidium@6872: * @param include_empty whether we should include stations without waiting cargo rubidium@6872: */ richk@10724: static void BuildStationsList(GUIStationList *sl, PlayerID owner, byte facilities, uint32 cargo_filter, bool include_empty) celestar@3812: { richk@10724: if (!(sl->flags & VL_REBUILD)) return; truelight@919: richk@10731: sl->Clear(); truelight@0: Darkvater@5568: DEBUG(misc, 3, "Building station list for player %d", owner); celestar@3812: richk@10731: const Station *st; truelight@0: FOR_ALL_STATIONS(st) { rubidium@6872: if (st->owner == owner || (st->owner == OWNER_NONE && !st->IsBuoy() && HasStationInUse(st->index, owner))) { celestar@3812: if (facilities & st->facilities) { //only stations with selected facilities celestar@3812: int num_waiting_cargo = 0; peter1138@6528: for (CargoID j = 0; j < NUM_CARGO; j++) { richk@6720: if (!st->goods[j].cargo.Empty()) { celestar@3812: num_waiting_cargo++; //count number of waiting cargo rubidium@6871: if (HasBit(cargo_filter, j)) { richk@10731: *sl->Append() = st; celestar@3812: break; celestar@3812: } celestar@3812: } celestar@3812: } richk@6719: /* stations without waiting cargo */ peter1138@6597: if (num_waiting_cargo == 0 && include_empty) { richk@10731: *sl->Append() = st; celestar@3812: } celestar@3812: } truelight@0: } truelight@0: } truelight@0: richk@10731: sl->Compact(); darkvater@164: richk@10724: sl->flags &= ~VL_REBUILD; richk@10724: sl->flags |= VL_RESORT; darkvater@243: } darkvater@243: rubidium@6872: rubidium@6872: /** richk@10724: * Sort station list if the VL_RESORT flag is set rubidium@6872: * rubidium@6872: * @param sl pointer to plstations_d (station list and flags) rubidium@6872: */ richk@10724: static void SortStationsList(GUIStationList *sl) darkvater@243: { richk@10242: static StationSortListingTypeFunction *const _station_sorter[] = { celestar@3812: &StationNameSorter, celestar@3812: &StationTypeSorter, celestar@3812: &StationWaitingSorter, celestar@3812: &StationRatingMaxSorter celestar@3812: }; darkvater@164: richk@10724: if (!(sl->flags & VL_RESORT)) return; darkvater@174: richk@10724: _internal_sort_order = sl->flags & VL_DESC; tron@4277: _last_station = NULL; // used for "cache" in namesorting richk@10731: qsort((void*)sl->Begin(), sl->Length(), sizeof(sl->Begin()), _station_sorter[sl->sort_type]); truelight@193: celestar@3812: sl->resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS; richk@10724: sl->flags &= ~VL_RESORT; truelight@0: } truelight@0: rubidium@6872: /** richk@10724: * The list of stations per player. rubidium@6872: */ richk@10724: struct PlayerStationsWindow : public Window, public GUIStationList truelight@0: { richk@10724: static Listing station_sort; richk@10724: static byte facilities; richk@10724: static bool include_empty; celestar@3812: richk@10724: PlayerStationsWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number) richk@10724: { richk@10724: this->caption_color = (byte)this->window_number; richk@10724: this->vscroll.cap = 12; richk@10724: this->resize.step_height = 10; richk@10724: this->resize.height = this->height - 10 * 7; // minimum if 5 in the list truelight@0: richk@10724: /* Add cargo filter buttons */ richk@10724: uint num_active = 0; richk@10724: for (CargoID c = 0; c < NUM_CARGO; c++) { richk@10724: if (GetCargo(c)->IsValid()) num_active++; tron@4268: } darkvater@174: richk@10724: this->widget_count += num_active; richk@10724: this->widget = ReallocT(this->widget, this->widget_count + 1); richk@10724: this->widget[this->widget_count].type = WWT_LAST; peter1138@6528: richk@10724: uint i = 0; richk@10724: for (CargoID c = 0; c < NUM_CARGO; c++) { richk@10724: if (!GetCargo(c)->IsValid()) continue; richk@10724: richk@10724: Widget *wi = &this->widget[SLW_CARGOSTART + i]; richk@10724: wi->type = WWT_PANEL; richk@10724: wi->display_flags = RESIZE_NONE; richk@10724: wi->color = 14; richk@10724: wi->left = 89 + i * 14; richk@10724: wi->right = wi->left + 13; richk@10724: wi->top = 14; richk@10724: wi->bottom = 24; richk@10724: wi->data = 0; richk@10724: wi->tooltips = STR_USE_CTRL_TO_SELECT_MORE; richk@10724: richk@10724: if (HasBit(_cargo_filter, c)) this->LowerWidget(SLW_CARGOSTART + i); richk@10724: i++; richk@10724: } richk@10724: richk@10724: this->widget[SLW_NOCARGOWAITING].left += num_active * 14; richk@10724: this->widget[SLW_NOCARGOWAITING].right += num_active * 14; richk@10724: this->widget[SLW_CARGOALL].left += num_active * 14; richk@10724: this->widget[SLW_CARGOALL].right += num_active * 14; richk@10724: this->widget[SLW_PAN_RIGHT].left += num_active * 14; richk@10724: richk@10724: if (num_active > 15) { richk@10724: /* Resize and fix the minimum width, if necessary */ richk@10724: ResizeWindow(this, (num_active - 15) * 14, 0); richk@10724: this->resize.width = this->width; richk@10724: } richk@10724: richk@10724: if (_cargo_filter == _cargo_filter_max) _cargo_filter = _cargo_mask; richk@10724: richk@10724: for (uint i = 0; i < 5; i++) { richk@10724: if (HasBit(facilities, i)) this->LowerWidget(i + SLW_TRAIN); richk@10724: } richk@10724: this->SetWidgetLoweredState(SLW_FACILALL, facilities == (FACIL_TRAIN | FACIL_TRUCK_STOP | FACIL_BUS_STOP | FACIL_AIRPORT | FACIL_DOCK)); richk@10724: this->SetWidgetLoweredState(SLW_CARGOALL, _cargo_filter == _cargo_mask && include_empty); richk@10724: this->SetWidgetLoweredState(SLW_NOCARGOWAITING, include_empty); richk@10724: richk@10724: this->flags = VL_REBUILD; richk@10724: this->sort_type = station_sort.criteria; richk@10724: if (station_sort.order) this->flags |= VL_DESC; richk@10724: richk@10724: /* set up resort timer */ richk@10724: this->resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS; richk@10731: richk@10731: this->FindWindowPlacementAndResize(desc); richk@10724: } richk@10724: richk@10724: virtual void OnPaint() richk@10724: { richk@10724: PlayerID owner = (PlayerID)this->window_number; richk@10724: richk@10724: BuildStationsList(this, owner, facilities, _cargo_filter, include_empty); richk@10724: SortStationsList(this); richk@10724: richk@10731: SetVScrollCount(this, this->Length()); richk@10724: richk@10724: /* draw widgets, with player's name in the caption */ richk@10724: SetDParam(0, owner); richk@10724: SetDParam(1, this->vscroll.count); richk@10724: richk@10724: /* Set text of sort by dropdown */ richk@10724: this->widget[SLW_SORTDROPBTN].data = _station_sort_listing[this->sort_type]; richk@10724: richk@10724: this->DrawWidgets(); richk@10724: richk@10724: /* draw arrow pointing up/down for ascending/descending sorting */ richk@10724: this->DrawSortButtonState(SLW_SORTBY, this->flags & VL_DESC ? SBS_DOWN : SBS_UP); richk@10724: richk@10724: int cg_ofst; richk@10724: int x = 89; richk@10724: int y = 14; richk@10724: int xb = 2; ///< offset from left of widget richk@10724: richk@10724: uint i = 0; richk@10724: for (CargoID c = 0; c < NUM_CARGO; c++) { richk@10724: const CargoSpec *cs = GetCargo(c); richk@10724: if (!cs->IsValid()) continue; richk@10724: richk@10724: cg_ofst = HasBit(_cargo_filter, c) ? 2 : 1; richk@10724: GfxFillRect(x + cg_ofst, y + cg_ofst, x + cg_ofst + 10 , y + cg_ofst + 7, cs->rating_colour); richk@10724: DrawStringCentered(x + 6 + cg_ofst, y + cg_ofst, cs->abbrev, TC_BLACK); richk@10724: x += 14; richk@10724: i++; richk@10724: } richk@10724: richk@10724: x += 6; richk@10724: cg_ofst = this->IsWidgetLowered(SLW_NOCARGOWAITING) ? 2 : 1; richk@10724: DrawStringCentered(x + cg_ofst, y + cg_ofst, STR_ABBREV_NONE, TC_BLACK); richk@10724: x += 14; richk@10724: cg_ofst = this->IsWidgetLowered(SLW_CARGOALL) ? 2 : 1; richk@10724: DrawStringCentered(x + cg_ofst, y + cg_ofst, STR_ABBREV_ALL, TC_BLACK); richk@10724: richk@10724: cg_ofst = this->IsWidgetLowered(SLW_FACILALL) ? 2 : 1; richk@10724: DrawString(71 + cg_ofst, y + cg_ofst, STR_ABBREV_ALL, TC_BLACK); richk@10724: richk@10724: if (this->vscroll.count == 0) { // player has no stations richk@10724: DrawString(xb, 40, STR_304A_NONE, TC_FROMSTRING); richk@10724: return; richk@10724: } richk@10724: richk@10731: int max = min(this->vscroll.pos + this->vscroll.cap, this->Length()); richk@10724: y = 40; // start of the list-widget richk@10724: richk@10724: for (int i = this->vscroll.pos; i < max; ++i) { // do until max number of stations of owner richk@10731: const Station *st = *this->Get(i); richk@10724: int x; richk@10724: richk@10724: assert(st->xy != 0); richk@10724: richk@10724: /* Do not do the complex check HasStationInUse here, it may be even false richk@10724: * when the order had been removed and the station list hasn't been removed yet */ richk@10724: assert(st->owner == owner || (st->owner == OWNER_NONE && !st->IsBuoy())); richk@10724: richk@10724: SetDParam(0, st->index); richk@10724: SetDParam(1, st->facilities); richk@10724: x = DrawString(xb, y, STR_3049_0, TC_FROMSTRING) + 5; richk@10724: richk@10724: /* show cargo waiting and station ratings */ richk@10724: for (CargoID j = 0; j < NUM_CARGO; j++) { richk@10724: if (!st->goods[j].cargo.Empty()) { richk@10724: StationsWndShowStationRating(x, y, j, st->goods[j].cargo.Count(), st->goods[j].rating); richk@10724: x += 20; richk@10724: } richk@10724: } richk@10724: y += 10; richk@10724: } richk@10724: } richk@10724: richk@10724: virtual void OnClick(Point pt, int widget) richk@10724: { richk@10724: switch (widget) { richk@10724: case SLW_LIST: { richk@10724: uint32 id_v = (pt.y - 41) / 10; richk@10724: richk@10724: if (id_v >= this->vscroll.cap) return; // click out of bounds richk@10724: richk@10724: id_v += this->vscroll.pos; richk@10724: richk@10731: if (id_v >= this->Length()) return; // click out of list bound richk@10724: richk@10731: const Station *st = *this->Get(id_v); richk@10724: /* do not check HasStationInUse - it is slow and may be invalid */ richk@10724: assert(st->owner == (PlayerID)this->window_number || (st->owner == OWNER_NONE && !st->IsBuoy())); richk@10724: richk@10724: if (_ctrl_pressed) { richk@10724: ShowExtraViewPortWindow(st->xy); richk@10724: } else { richk@10724: ScrollMainWindowToTile(st->xy); richk@10724: } richk@10724: break; richk@10724: } richk@10724: richk@10724: case SLW_TRAIN: richk@10724: case SLW_TRUCK: richk@10724: case SLW_BUS: richk@10724: case SLW_AIRPLANE: richk@10724: case SLW_SHIP: richk@10724: if (_ctrl_pressed) { richk@10724: ToggleBit(facilities, widget - SLW_TRAIN); richk@10724: this->ToggleWidgetLoweredState(widget); richk@10724: } else { richk@10724: uint i; richk@10724: FOR_EACH_SET_BIT(i, facilities) { richk@10724: this->RaiseWidget(i + SLW_TRAIN); peter1138@6528: } richk@10724: SetBit(facilities, widget - SLW_TRAIN); richk@10724: this->LowerWidget(widget); richk@10724: } richk@10724: this->SetWidgetLoweredState(SLW_FACILALL, facilities == (FACIL_TRAIN | FACIL_TRUCK_STOP | FACIL_BUS_STOP | FACIL_AIRPORT | FACIL_DOCK)); richk@10724: this->flags |= VL_REBUILD; richk@10724: this->SetDirty(); richk@10724: break; peter1138@6528: richk@10724: case SLW_FACILALL: richk@10724: for (uint i = 0; i < 5; i++) { richk@10724: this->LowerWidget(i + SLW_TRAIN); richk@10724: } richk@10724: this->LowerWidget(SLW_FACILALL); richk@10724: richk@10724: facilities = FACIL_TRAIN | FACIL_TRUCK_STOP | FACIL_BUS_STOP | FACIL_AIRPORT | FACIL_DOCK; richk@10724: this->flags |= VL_REBUILD; richk@10724: this->SetDirty(); richk@10724: break; richk@10724: richk@10724: case SLW_CARGOALL: { richk@10724: uint i = 0; richk@10724: for (CargoID c = 0; c < NUM_CARGO; c++) { richk@10724: if (!GetCargo(c)->IsValid()) continue; richk@10724: this->LowerWidget(i + SLW_CARGOSTART); richk@10724: i++; richk@10724: } richk@10724: this->LowerWidget(SLW_NOCARGOWAITING); richk@10724: this->LowerWidget(SLW_CARGOALL); richk@10724: richk@10724: _cargo_filter = _cargo_mask; richk@10724: include_empty = true; richk@10724: this->flags |= VL_REBUILD; richk@10724: this->SetDirty(); richk@10724: break; richk@10724: } richk@10724: richk@10724: case SLW_SORTBY: // flip sorting method asc/desc richk@10724: this->flags ^= VL_DESC; //DESC-flag richk@10724: station_sort.order = HasBit(this->flags, 0); richk@10724: this->flags |= VL_RESORT; richk@10724: this->flags4 |= 5 << WF_TIMEOUT_SHL; richk@10724: this->LowerWidget(SLW_SORTBY); richk@10724: this->SetDirty(); richk@10724: break; richk@10724: richk@10724: case SLW_SORTDROPBTN: // select sorting criteria dropdown menu richk@10724: ShowDropDownMenu(this, _station_sort_listing, this->sort_type, SLW_SORTDROPBTN, 0, 0); richk@10724: break; richk@10724: richk@10724: case SLW_NOCARGOWAITING: richk@10724: if (_ctrl_pressed) { richk@10724: include_empty = !include_empty; richk@10724: this->ToggleWidgetLoweredState(SLW_NOCARGOWAITING); richk@10724: } else { richk@10724: for (uint i = SLW_CARGOSTART; i < this->widget_count; i++) { richk@10724: this->RaiseWidget(i); peter1138@6528: } peter1138@6528: richk@10724: _cargo_filter = 0; richk@10724: include_empty = true; peter1138@6528: richk@10724: this->LowerWidget(SLW_NOCARGOWAITING); richk@10724: } richk@10724: this->flags |= VL_REBUILD; richk@10724: this->SetWidgetLoweredState(SLW_CARGOALL, _cargo_filter == _cargo_mask && include_empty); richk@10724: this->SetDirty(); richk@10724: break; richk@10724: richk@10724: default: richk@10724: if (widget >= SLW_CARGOSTART) { // change cargo_filter richk@10724: /* Determine the selected cargo type */ richk@10724: CargoID c; richk@10724: int i = 0; richk@10724: for (c = 0; c < NUM_CARGO; c++) { peter1138@6597: if (!GetCargo(c)->IsValid()) continue; richk@10724: if (widget - SLW_CARGOSTART == i) break; peter1138@6597: i++; peter1138@6528: } peter1138@6528: peter1138@6597: if (_ctrl_pressed) { richk@10724: ToggleBit(_cargo_filter, c); richk@10724: this->ToggleWidgetLoweredState(widget); peter1138@6597: } else { richk@10724: for (uint i = SLW_CARGOSTART; i < this->widget_count; i++) { richk@10724: this->RaiseWidget(i); peter1138@6597: } richk@10724: this->RaiseWidget(SLW_NOCARGOWAITING); peter1138@6597: peter1138@6597: _cargo_filter = 0; richk@10724: include_empty = false; peter1138@6597: richk@10724: SetBit(_cargo_filter, c); richk@10724: this->LowerWidget(widget); peter1138@6528: } richk@10724: this->flags |= VL_REBUILD; richk@10724: this->SetWidgetLoweredState(SLW_CARGOALL, _cargo_filter == _cargo_mask && include_empty); richk@10724: this->SetDirty(); richk@10724: } richk@10724: break; richk@10724: } richk@10724: } peter1138@6528: richk@10724: virtual void OnDropdownSelect(int widget, int index) richk@10724: { richk@10724: if (this->sort_type != index) { richk@10724: /* value has changed -> resort */ richk@10724: this->sort_type = index; richk@10724: station_sort.criteria = this->sort_type; richk@10724: this->flags |= VL_RESORT; richk@10724: } richk@10724: this->SetDirty(); richk@10724: } belugas@5271: richk@10724: virtual void OnTick() richk@10724: { richk@10724: if (_pause_game != 0) return; richk@10724: if (--this->resort_timer == 0) { richk@10724: DEBUG(misc, 3, "Periodic rebuild station list player %d", this->window_number); richk@10724: this->resort_timer = DAY_TICKS * PERIODIC_RESORT_DAYS; richk@10724: this->flags |= VL_REBUILD; richk@10724: this->SetDirty(); richk@10724: } richk@10724: } truelight@0: richk@10724: virtual void OnTimeout() richk@10724: { richk@10724: this->RaiseWidget(SLW_SORTBY); richk@10724: this->SetDirty(); richk@10724: } truelight@867: richk@10724: virtual void OnResize(Point new_size, Point delta) richk@10724: { richk@10724: this->vscroll.cap += delta.y / 10; truelight@0: } richk@10731: richk@10731: virtual void OnInvalidateData(int data) richk@10731: { richk@10731: this->flags |= (data == 0 ? VL_REBUILD : VL_RESORT); richk@10731: } richk@10724: }; richk@10724: richk@10724: Listing PlayerStationsWindow::station_sort = {0, 0}; richk@10724: byte PlayerStationsWindow::facilities = FACIL_TRAIN | FACIL_TRUCK_STOP | FACIL_BUS_STOP | FACIL_AIRPORT | FACIL_DOCK; richk@10724: bool PlayerStationsWindow::include_empty = true; richk@10724: truelight@0: truelight@0: static const Widget _player_stations_widgets[] = { rubidium@6872: { WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, // SLW_CLOSEBOX belugas@3554: { WWT_CAPTION, RESIZE_RIGHT, 14, 11, 345, 0, 13, STR_3048_STATIONS, STR_018C_WINDOW_TITLE_DRAG_THIS}, belugas@3554: { WWT_STICKYBOX, RESIZE_LR, 14, 346, 357, 0, 13, 0x0, STR_STICKY_BUTTON}, rubidium@6872: { WWT_PANEL, RESIZE_RB, 14, 0, 345, 37, 161, 0x0, STR_3057_STATION_NAMES_CLICK_ON}, // SLW_LIST peter1138@5128: { WWT_SCROLLBAR, RESIZE_LRB, 14, 346, 357, 37, 149, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, celestar@3812: { WWT_RESIZEBOX, RESIZE_LRTB, 14, 346, 357, 150, 161, 0x0, STR_RESIZE_BUTTON}, celestar@3812: rubidium@6872: { WWT_TEXTBTN, RESIZE_NONE, 14, 0, 13, 14, 24, STR_TRAIN, STR_USE_CTRL_TO_SELECT_MORE}, // SLW_TRAIN rubidium@6872: { WWT_TEXTBTN, RESIZE_NONE, 14, 14, 27, 14, 24, STR_LORRY, STR_USE_CTRL_TO_SELECT_MORE}, // SLW_TRUCK rubidium@6872: { WWT_TEXTBTN, RESIZE_NONE, 14, 28, 41, 14, 24, STR_BUS, STR_USE_CTRL_TO_SELECT_MORE}, // SLW_BUS rubidium@6872: { WWT_TEXTBTN, RESIZE_NONE, 14, 42, 55, 14, 24, STR_PLANE, STR_USE_CTRL_TO_SELECT_MORE}, // SLW_AIRPLANE rubidium@6872: { WWT_TEXTBTN, RESIZE_NONE, 14, 56, 69, 14, 24, STR_SHIP, STR_USE_CTRL_TO_SELECT_MORE}, // SLW_SHIP rubidium@6872: { WWT_PANEL, RESIZE_NONE, 14, 70, 83, 14, 24, 0x0, STR_SELECT_ALL_FACILITIES}, // SLW_FACILALL celestar@3812: rubidium@6872: { WWT_PANEL, RESIZE_NONE, 14, 83, 88, 14, 24, 0x0, STR_NULL}, // SLW_PAN_BETWEEN rubidium@6872: { WWT_PANEL, RESIZE_NONE, 14, 89, 102, 14, 24, 0x0, STR_NO_WAITING_CARGO}, // SLW_NOCARGOWAITING rubidium@6872: { WWT_PANEL, RESIZE_NONE, 14, 103, 116, 14, 24, 0x0, STR_SELECT_ALL_TYPES}, // SLW_CARGOALL rubidium@6872: { WWT_PANEL, RESIZE_RIGHT, 14, 117, 357, 14, 24, 0x0, STR_NULL}, // SLW_PAN_RIGHT rubidium@6872: rubidium@6872: { WWT_TEXTBTN, RESIZE_NONE, 14, 0, 80, 25, 36, STR_SORT_BY, STR_SORT_ORDER_TIP}, // SLW_SORTBY rubidium@6872: { WWT_DROPDOWN, RESIZE_NONE, 14, 81, 243, 25, 36, 0x0, STR_SORT_CRITERIA_TIP}, // SLW_SORTDROPBTN rubidium@6872: { WWT_PANEL, RESIZE_RIGHT, 14, 244, 357, 25, 36, 0x0, STR_NULL}, // SLW_PAN_SORT_RIGHT darkvater@176: { WIDGETS_END}, truelight@0: }; truelight@0: truelight@0: static const WindowDesc _player_stations_desc = { richk@6743: WDP_AUTO, WDP_AUTO, 358, 162, 358, 162, rubidium@6144: WC_STATION_LIST, WC_NONE, belugas@5271: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON | WDF_RESIZABLE, truelight@0: _player_stations_widgets, truelight@0: }; truelight@0: rubidium@6872: /** rubidium@6872: * Opens window with list of player's stations rubidium@6872: * rubidium@6872: * @param player player whose stations' list show rubidium@6872: */ tron@2475: void ShowPlayerStations(PlayerID player) truelight@0: { Darkvater@5005: if (!IsValidPlayer(player)) return; Darkvater@5005: richk@10724: AllocateWindowDescFront(&_player_stations_desc, player); truelight@0: } truelight@0: truelight@0: static const Widget _station_view_widgets[] = { rubidium@6872: { WWT_CLOSEBOX, RESIZE_NONE, 14, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, // SVW_CLOSEBOX rubidium@6877: { WWT_CAPTION, RESIZE_RIGHT, 14, 11, 236, 0, 13, STR_300A_0, STR_018C_WINDOW_TITLE_DRAG_THIS}, rubidium@6877: { WWT_STICKYBOX, RESIZE_LR, 14, 237, 248, 0, 13, 0x0, STR_STICKY_BUTTON}, rubidium@6877: { WWT_PANEL, RESIZE_RB, 14, 0, 236, 14, 65, 0x0, STR_NULL}, // SVW_WAITING rubidium@6877: { WWT_SCROLLBAR, RESIZE_LRB, 14, 237, 248, 14, 65, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST}, rubidium@6877: { WWT_PANEL, RESIZE_RTB, 14, 0, 248, 66, 97, 0x0, STR_NULL}, // SVW_ACCEPTLIST / SVW_RATINGLIST rubidium@6877: { WWT_PUSHTXTBTN, RESIZE_TB, 14, 0, 59, 98, 109, STR_00E4_LOCATION, STR_3053_CENTER_MAIN_VIEW_ON_STATION}, // SVW_LOCATION rubidium@6877: { WWT_PUSHTXTBTN, RESIZE_TB, 14, 60, 120, 98, 109, STR_3032_RATINGS, STR_3054_SHOW_STATION_RATINGS}, // SVW_RATINGS / SVW_ACCEPTS rubidium@6877: { WWT_PUSHTXTBTN, RESIZE_RTB, 14, 121, 180, 98, 109, STR_0130_RENAME, STR_3055_CHANGE_NAME_OF_STATION}, // SVW_RENAME rubidium@6877: { WWT_PUSHTXTBTN, RESIZE_LRTB, 14, 181, 194, 98, 109, STR_TRAIN, STR_SCHEDULED_TRAINS_TIP }, // SVW_TRAINS rubidium@6877: { WWT_PUSHTXTBTN, RESIZE_LRTB, 14, 195, 208, 98, 109, STR_LORRY, STR_SCHEDULED_ROAD_VEHICLES_TIP }, // SVW_ROADVEHS rubidium@6877: { WWT_PUSHTXTBTN, RESIZE_LRTB, 14, 209, 222, 98, 109, STR_PLANE, STR_SCHEDULED_AIRCRAFT_TIP }, // SVW_PLANES rubidium@6877: { WWT_PUSHTXTBTN, RESIZE_LRTB, 14, 223, 236, 98, 109, STR_SHIP, STR_SCHEDULED_SHIPS_TIP }, // SVW_SHIPS rubidium@6877: { WWT_RESIZEBOX, RESIZE_LRTB, 14, 237, 248, 98, 109, 0x0, STR_RESIZE_BUTTON}, darkvater@176: { WIDGETS_END}, truelight@0: }; truelight@0: richk@10184: SpriteID GetCargoSprite(CargoID i) peter1138@6690: { peter1138@6690: const CargoSpec *cs = GetCargo(i); peter1138@6691: SpriteID sprite; peter1138@6691: peter1138@6691: if (cs->sprite == 0xFFFF) { peter1138@6691: /* A value of 0xFFFF indicates we should draw a custom icon */ peter1138@6691: sprite = GetCustomCargoSprite(cs); peter1138@6691: } else { peter1138@6691: sprite = cs->sprite; peter1138@6691: } peter1138@6691: richk@6719: if (sprite == 0) sprite = SPR_CARGO_GOODS; peter1138@6690: richk@10184: return sprite; richk@10184: } richk@10184: richk@10184: /** richk@10184: * Draws icons of waiting cargo in the StationView window richk@10184: * richk@10184: * @param i type of cargo richk@10184: * @param waiting number of waiting units richk@10184: * @param x x on-screen coordinate where to start with drawing icons richk@10184: * @param y y coordinate richk@10184: */ richk@10184: static void DrawCargoIcons(CargoID i, uint waiting, int x, int y, uint width) richk@10184: { richk@10184: uint num = min((waiting + 5) / 10, width / 10); // maximum is width / 10 icons so it won't overflow richk@10184: if (num == 0) return; richk@10184: richk@10184: SpriteID sprite = GetCargoSprite(i); richk@10184: peter1138@6690: do { peter1138@6690: DrawSprite(sprite, PAL_NONE, x, y); peter1138@6690: x += 10; peter1138@6690: } while (--num); peter1138@6690: } peter1138@6690: rubidium@6877: struct CargoData { rubidium@6877: CargoID cargo; rubidium@6877: StationID source; rubidium@6877: uint count; rubidium@6877: rubidium@6877: CargoData(CargoID cargo, StationID source, uint count) : rubidium@6877: cargo(cargo), rubidium@6877: source(source), rubidium@6877: count(count) rubidium@6877: { } rubidium@6877: }; rubidium@6877: rubidium@6877: typedef std::list CargoDataList; rubidium@6877: rubidium@6872: /** richk@10724: * The StationView window rubidium@6872: */ richk@10724: struct StationViewWindow : public Window { richk@10724: uint32 cargo; ///< Bitmask of cargo types to expand richk@10724: uint16 cargo_rows[NUM_CARGO]; ///< Header row for each cargo type richk@10184: richk@10724: StationViewWindow(const WindowDesc *desc, WindowNumber window_number) : Window(desc, window_number) richk@10724: { richk@10724: PlayerID owner = GetStation(window_number)->owner; richk@10724: if (owner != OWNER_NONE) this->caption_color = owner; richk@10724: this->vscroll.cap = 5; richk@10724: this->resize.step_height = 10; richk@10184: richk@10724: this->FindWindowPlacementAndResize(desc); richk@10724: } richk@10184: richk@10724: ~StationViewWindow() richk@10724: { richk@10724: WindowNumber wno = richk@10724: (this->window_number << 16) | VLW_STATION_LIST | GetStation(this->window_number)->owner; richk@10724: richk@10724: DeleteWindowById(WC_TRAINS_LIST, wno); richk@10724: DeleteWindowById(WC_ROADVEH_LIST, wno); richk@10724: DeleteWindowById(WC_SHIPS_LIST, wno); richk@10724: DeleteWindowById(WC_AIRCRAFT_LIST, wno); richk@10724: } richk@10724: richk@10724: virtual void OnPaint() richk@10724: { richk@10724: StationID station_id = this->window_number; richk@10724: const Station *st = GetStation(station_id); richk@10724: CargoDataList cargolist; richk@10724: uint32 transfers = 0; richk@10724: richk@10724: /* count types of cargos waiting in station */ richk@10724: for (CargoID i = 0; i < NUM_CARGO; i++) { richk@10724: if (st->goods[i].cargo.Empty()) { richk@10724: this->cargo_rows[i] = 0; richk@10724: } else { richk@10724: /* Add an entry for total amount of cargo of this type waiting. */ richk@10724: cargolist.push_back(CargoData(i, INVALID_STATION, st->goods[i].cargo.Count())); richk@10724: richk@10724: /* Set the row for this cargo entry for the expand/hide button */ richk@10724: this->cargo_rows[i] = cargolist.size(); richk@10724: richk@10724: /* Add an entry for each distinct cargo source. */ richk@10724: const CargoList::List *packets = st->goods[i].cargo.Packets(); richk@10724: for (CargoList::List::const_iterator it = packets->begin(); it != packets->end(); it++) { richk@10724: const CargoPacket *cp = *it; richk@10724: if (cp->source != station_id) { richk@10724: bool added = false; richk@10724: richk@10724: /* Enable the expand/hide button for this cargo type */ richk@10724: SetBit(transfers, i); richk@10724: richk@10724: /* Don't add cargo lines if not expanded */ richk@10724: if (!HasBit(this->cargo, i)) break; richk@10724: richk@10724: /* Check if we already have this source in the list */ richk@10724: for (CargoDataList::iterator jt = cargolist.begin(); jt != cargolist.end(); jt++) { richk@10724: CargoData *cd = &(*jt); richk@10724: if (cd->cargo == i && cd->source == cp->source) { richk@10724: cd->count += cp->count; richk@10724: added = true; richk@10724: break; richk@10724: } rubidium@6877: } richk@10724: richk@10724: if (!added) cargolist.push_back(CargoData(i, cp->source, cp->count)); rubidium@6877: } rubidium@6877: } rubidium@6877: } truelight@0: } richk@10724: SetVScrollCount(this, cargolist.size() + 1); // update scrollbar richk@10242: richk@10724: /* disable some buttons */ richk@10724: this->SetWidgetDisabledState(SVW_RENAME, st->owner != _local_player); richk@10724: this->SetWidgetDisabledState(SVW_TRAINS, !(st->facilities & FACIL_TRAIN)); richk@10724: this->SetWidgetDisabledState(SVW_ROADVEHS, !(st->facilities & FACIL_TRUCK_STOP) && !(st->facilities & FACIL_BUS_STOP)); richk@10724: this->SetWidgetDisabledState(SVW_PLANES, !(st->facilities & FACIL_AIRPORT)); richk@10724: this->SetWidgetDisabledState(SVW_SHIPS, !(st->facilities & FACIL_DOCK)); truelight@0: richk@10724: SetDParam(0, st->index); richk@10724: SetDParam(1, st->facilities); richk@10724: this->DrawWidgets(); richk@10724: richk@10724: int x = 2; ///< coordinates used for printing waiting/accepted/rating of cargo richk@10724: int y = 15; richk@10724: int pos = this->vscroll.pos; ///< = this->vscroll.pos richk@10724: richk@10724: uint width = this->widget[SVW_WAITING].right - this->widget[SVW_WAITING].left - 4; richk@10724: int maxrows = this->vscroll.cap; richk@10724: richk@10724: StringID str; richk@10724: rubidium@6877: if (--pos < 0) { richk@10724: str = STR_00D0_NOTHING; richk@10724: for (CargoID i = 0; i < NUM_CARGO; i++) { richk@10724: if (!st->goods[i].cargo.Empty()) str = STR_EMPTY; truelight@0: } richk@10724: SetDParam(0, str); richk@10724: DrawString(x, y, STR_0008_WAITING, TC_FROMSTRING); rubidium@6877: y += 10; truelight@0: } truelight@0: richk@10724: for (CargoDataList::const_iterator it = cargolist.begin(); it != cargolist.end() && pos > -maxrows; ++it) { richk@10724: if (--pos < 0) { richk@10724: const CargoData *cd = &(*it); richk@10724: if (cd->source == INVALID_STATION) { richk@10724: /* Heading */ richk@10724: DrawCargoIcons(cd->cargo, cd->count, x, y, width); richk@10724: SetDParam(0, cd->cargo); richk@10724: SetDParam(1, cd->count); richk@10724: if (HasBit(transfers, cd->cargo)) { richk@10724: /* This cargo has transfers waiting so show the expand or shrink 'button' */ richk@10724: const char *sym = HasBit(this->cargo, cd->cargo) ? "-" : "+"; richk@10724: DrawStringRightAligned(x + width - 8, y, STR_0009, TC_FROMSTRING); richk@10724: DoDrawString(sym, x + width - 6, y, TC_YELLOW); richk@10724: } else { richk@10724: DrawStringRightAligned(x + width, y, STR_0009, TC_FROMSTRING); richk@10724: } peter1138@5038: } else { richk@10724: SetDParam(0, cd->cargo); richk@10724: SetDParam(1, cd->count); richk@10724: SetDParam(2, cd->source); richk@10724: DrawStringRightAlignedTruncated(x + width, y, STR_EN_ROUTE_FROM, TC_FROMSTRING, width); peter1138@5038: } richk@10724: richk@10724: y += 10; truelight@0: } truelight@0: } truelight@193: richk@10724: if (this->widget[SVW_ACCEPTS].data == STR_3032_RATINGS) { // small window with list of accepted cargo richk@10724: char *b = _userstring; richk@10724: bool first = true; peter1138@6623: richk@10724: b = InlineString(b, STR_000C_ACCEPTS); peter1138@6623: richk@10724: for (CargoID i = 0; i < NUM_CARGO; i++) { richk@10724: if (b >= lastof(_userstring) - (1 + 2 * 4)) break; // ',' or ' ' and two calls to Utf8Encode() richk@10724: if (HasBit(st->goods[i].acceptance_pickup, GoodsEntry::ACCEPTANCE)) { richk@10724: if (first) { richk@10724: first = false; richk@10724: } else { richk@10724: /* Add a comma if this is not the first item */ richk@10724: *b++ = ','; richk@10724: *b++ = ' '; richk@10724: } richk@10724: b = InlineString(b, GetCargo(i)->name); richk@10724: } richk@10724: } richk@10724: richk@10724: /* If first is still true then no cargo is accepted */ richk@10724: if (first) b = InlineString(b, STR_00D0_NOTHING); richk@10724: richk@10724: *b = '\0'; richk@10724: richk@10724: /* Make sure we detect any buffer overflow */ richk@10724: assert(b < endof(_userstring)); richk@10724: richk@10724: DrawStringMultiLine(2, this->widget[SVW_ACCEPTLIST].top + 1, STR_SPEC_USERSTRING, this->widget[SVW_ACCEPTLIST].right - this->widget[SVW_ACCEPTLIST].left); richk@10724: } else { // extended window with list of cargo ratings richk@10724: y = this->widget[SVW_RATINGLIST].top + 1; richk@10724: richk@10724: DrawString(2, y, STR_3034_LOCAL_RATING_OF_TRANSPORT, TC_FROMSTRING); peter1138@6623: y += 10; truelight@0: richk@10724: for (CargoID i = 0; i < NUM_CARGO; i++) { richk@10724: const CargoSpec *cs = GetCargo(i); richk@10724: if (!cs->IsValid()) continue; richk@10184: richk@10724: const GoodsEntry *ge = &st->goods[i]; richk@10724: if (!HasBit(ge->acceptance_pickup, GoodsEntry::PICKUP)) continue; richk@10724: richk@10724: SetDParam(0, cs->name); richk@10724: SetDParam(2, ge->rating * 101 >> 8); richk@10724: SetDParam(1, STR_3035_APPALLING + (ge->rating >> 5)); richk@10724: DrawString(8, y, STR_303D, TC_FROMSTRING); richk@10724: y += 10; richk@10724: } richk@10184: } richk@10184: } truelight@193: richk@10724: void HandleCargoWaitingClick(int row) richk@10724: { richk@10724: if (row == 0) return; peter1138@6528: richk@10724: for (CargoID c = 0; c < NUM_CARGO; c++) { richk@10724: if (this->cargo_rows[c] == row) { richk@10724: ToggleBit(this->cargo, c); richk@10724: this->InvalidateWidget(SVW_WAITING); richk@10724: break; richk@10724: } richk@10724: } richk@10724: } peter1138@6528: richk@10724: virtual void OnClick(Point pt, int widget) richk@10724: { richk@10724: switch (widget) { richk@10724: case SVW_WAITING: richk@10724: this->HandleCargoWaitingClick((pt.y - this->widget[SVW_WAITING].top) / 10 + this->vscroll.pos); richk@10724: break; peter1138@6528: richk@10724: case SVW_LOCATION: richk@10724: if (_ctrl_pressed) { richk@10724: ShowExtraViewPortWindow(GetStation(this->window_number)->xy); richk@10724: } else { richk@10724: ScrollMainWindowToTile(GetStation(this->window_number)->xy); richk@10724: } richk@10724: break; peter1138@6528: richk@10724: case SVW_RATINGS: richk@10724: this->SetDirty(); richk@10724: richk@10724: if (this->widget[SVW_RATINGS].data == STR_3032_RATINGS) { richk@10724: /* Switch to ratings view */ richk@10724: this->widget[SVW_RATINGS].data = STR_3033_ACCEPTS; richk@10724: this->widget[SVW_RATINGS].tooltips = STR_3056_SHOW_LIST_OF_ACCEPTED_CARGO; richk@10724: ResizeWindowForWidget(this, SVW_ACCEPTLIST, 0, 100); richk@10724: } else { richk@10724: /* Switch to accepts view */ richk@10724: this->widget[SVW_RATINGS].data = STR_3032_RATINGS; richk@10724: this->widget[SVW_RATINGS].tooltips = STR_3054_SHOW_STATION_RATINGS; richk@10724: ResizeWindowForWidget(this, SVW_ACCEPTLIST, 0, -100); peter1138@6528: } peter1138@6528: richk@10724: this->SetDirty(); richk@10724: break; truelight@0: richk@10724: case SVW_RENAME: richk@10724: SetDParam(0, this->window_number); richk@10724: ShowQueryString(STR_STATION, STR_3030_RENAME_STATION_LOADING, 31, 180, this, CS_ALPHANUMERAL); richk@10724: break; peter1138@6528: richk@10724: case SVW_TRAINS: { // Show a list of scheduled trains to this station richk@10724: const Station *st = GetStation(this->window_number); richk@10724: ShowVehicleListWindow(st->owner, VEH_TRAIN, (StationID)this->window_number); richk@10724: break; richk@10724: } richk@10724: richk@10724: case SVW_ROADVEHS: { // Show a list of scheduled road-vehicles to this station richk@10724: const Station *st = GetStation(this->window_number); richk@10724: ShowVehicleListWindow(st->owner, VEH_ROAD, (StationID)this->window_number); richk@10724: break; richk@10724: } richk@10724: richk@10724: case SVW_PLANES: { // Show a list of scheduled aircraft to this station richk@10724: const Station *st = GetStation(this->window_number); richk@10724: /* Since oilrigs have no owners, show the scheduled aircraft of current player */ richk@10724: PlayerID owner = (st->owner == OWNER_NONE) ? _current_player : st->owner; richk@10724: ShowVehicleListWindow(owner, VEH_AIRCRAFT, (StationID)this->window_number); richk@10724: break; richk@10724: } richk@10724: richk@10724: case SVW_SHIPS: { // Show a list of scheduled ships to this station richk@10724: const Station *st = GetStation(this->window_number); richk@10724: /* Since oilrigs/bouys have no owners, show the scheduled ships of current player */ richk@10724: PlayerID owner = (st->owner == OWNER_NONE) ? _current_player : st->owner; richk@10724: ShowVehicleListWindow(owner, VEH_SHIP, (StationID)this->window_number); richk@10724: break; richk@10724: } tron@588: } richk@10724: } rubidium@6877: richk@10724: virtual void OnQueryTextFinished(char *str) richk@10724: { richk@10724: if (!StrEmpty(str)) { richk@10724: _cmd_text = str; richk@10724: DoCommandP(0, this->window_number, 0, NULL, richk@10724: CMD_RENAME_STATION | CMD_MSG(STR_3031_CAN_T_RENAME_STATION)); richk@10724: } truelight@0: } richk@10724: richk@10724: virtual void OnResize(Point new_size, Point delta) richk@10724: { richk@10724: if (delta.x != 0) ResizeButtons(this, SVW_LOCATION, SVW_RENAME); richk@10724: this->vscroll.cap += delta.y / (int)this->resize.step_height; richk@10724: } richk@10724: }; truelight@0: truelight@0: truelight@0: static const WindowDesc _station_view_desc = { richk@6743: WDP_AUTO, WDP_AUTO, 249, 110, 249, 110, rubidium@6144: WC_STATION_VIEW, WC_NONE, rubidium@6877: WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE, truelight@0: _station_view_widgets, truelight@0: }; truelight@0: rubidium@6872: /** rubidium@6872: * Opens StationViewWindow for given station rubidium@6872: * rubidium@6872: * @param station station which window should be opened rubidium@6872: */ tron@2498: void ShowStationViewWindow(StationID station) truelight@0: { richk@10724: AllocateWindowDescFront(&_station_view_desc, station); truelight@0: }