Add show passenger and show freight buttons to departure window

This commit is contained in:
Jonathan G Rennison
2017-09-22 22:24:44 +01:00
parent 7d5f277a96
commit 07ca7cfb8c
5 changed files with 71 additions and 8 deletions

View File

@@ -76,9 +76,11 @@ static bool IsArrival(const Order *order, StationID station) {
* @param show_vehicle_types the types of vehicles to include in the departure list * @param show_vehicle_types the types of vehicles to include in the departure list
* @param type the type of departures to get (departures or arrivals) * @param type the type of departures to get (departures or arrivals)
* @param show_vehicles_via whether to include vehicles that have this station in their orders but do not stop at it * @param show_vehicles_via whether to include vehicles that have this station in their orders but do not stop at it
* @param show_pax whether to include passenger vehicles
* @param show_freight whether to include freight vehicles
* @return a list of departures, which is empty if an error occurred * @return a list of departures, which is empty if an error occurred
*/ */
DepartureList* MakeDepartureList(StationID station, bool show_vehicle_types[5], DepartureType type, bool show_vehicles_via) DepartureList* MakeDepartureList(StationID station, bool show_vehicle_types[5], DepartureType type, bool show_vehicles_via, bool show_pax, bool show_freight)
{ {
/* This function is the meat of the departure boards functionality. */ /* This function is the meat of the departure boards functionality. */
/* As an overview, it works by repeatedly considering the best possible next departure to show. */ /* As an overview, it works by repeatedly considering the best possible next departure to show. */
@@ -90,6 +92,8 @@ DepartureList* MakeDepartureList(StationID station, bool show_vehicle_types[5],
/* The list of departures which will be returned as a result. */ /* The list of departures which will be returned as a result. */
SmallVector<Departure*, 32> *result = new SmallVector<Departure*, 32>(); SmallVector<Departure*, 32> *result = new SmallVector<Departure*, 32>();
if (!show_pax && !show_freight) return result;
/* A list of the next scheduled orders to be considered for inclusion in the departure list. */ /* A list of the next scheduled orders to be considered for inclusion in the departure list. */
SmallVector<OrderDate*, 32> next_orders; SmallVector<OrderDate*, 32> next_orders;
@@ -120,19 +124,19 @@ DepartureList* MakeDepartureList(StationID station, bool show_vehicle_types[5],
/* Get the first order for each vehicle for the station we're interested in that doesn't have No Loading set. */ /* Get the first order for each vehicle for the station we're interested in that doesn't have No Loading set. */
/* We find the least order while we're at it. */ /* We find the least order while we're at it. */
for (const Vehicle **v = vehicles.Begin(); v != vehicles.End(); v++) { for (const Vehicle **v = vehicles.Begin(); v != vehicles.End(); v++) {
if (_settings_client.gui.departure_only_passengers) { if (show_pax != show_freight) {
bool carries_passengers = false; bool carries_passengers = false;
const Vehicle *u = *v; const Vehicle *u = *v;
while (u != NULL) { while (u != NULL) {
if (u->cargo_type == CT_PASSENGERS && u->cargo_cap > 0) { if (u->cargo_cap > 0 && IsCargoInClass(u->cargo_type, CC_PASSENGERS)) {
carries_passengers = true; carries_passengers = true;
break; break;
} }
u = u->Next(); u = u->Next();
} }
if (carries_passengers == false) { if (carries_passengers != show_pax) {
continue; continue;
} }
} }

View File

@@ -16,6 +16,7 @@
#include "core/smallvec_type.hpp" #include "core/smallvec_type.hpp"
#include "departures_type.h" #include "departures_type.h"
DepartureList* MakeDepartureList(StationID station, bool show_vehicle_types[4], DepartureType type = D_DEPARTURE, bool show_vehicles_via = false); DepartureList* MakeDepartureList(StationID station, bool show_vehicle_types[4], DepartureType type = D_DEPARTURE,
bool show_vehicles_via = false, bool show_pax = true, bool show_freight = true);
#endif /* DEPARTURES_FUNC_H */ #endif /* DEPARTURES_FUNC_H */

View File

@@ -53,6 +53,8 @@ static const NWidgetPart _nested_departures_list[] = {
NWidget(NWID_HORIZONTAL), NWidget(NWID_HORIZONTAL),
NWidget(WWT_PANEL, COLOUR_GREY), SetMinimalSize(0, 12), SetResize(1, 0), SetFill(1, 1), EndContainer(), NWidget(WWT_PANEL, COLOUR_GREY), SetMinimalSize(0, 12), SetResize(1, 0), SetFill(1, 1), EndContainer(),
NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_DB_SHOW_PAX), SetMinimalSize(6, 12), SetFill(0, 1), SetDataTip(STR_DEPARTURES_PAX, STR_DEPARTURES_PAX_TOOLTIP),
NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_DB_SHOW_FREIGHT), SetMinimalSize(6, 12), SetFill(0, 1), SetDataTip(STR_DEPARTURES_FREIGHT, STR_DEPARTURES_FREIGHT_TOOLTIP),
NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_DB_SHOW_ARRS), SetMinimalSize(6, 12), SetFill(0, 1), SetDataTip(STR_DEPARTURES_ARRIVALS, STR_DEPARTURES_ARRIVALS_TOOLTIP), NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_DB_SHOW_ARRS), SetMinimalSize(6, 12), SetFill(0, 1), SetDataTip(STR_DEPARTURES_ARRIVALS, STR_DEPARTURES_ARRIVALS_TOOLTIP),
NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_DB_SHOW_DEPS), SetMinimalSize(6, 12), SetFill(0, 1), SetDataTip(STR_DEPARTURES_DEPARTURES, STR_DEPARTURES_DEPARTURES_TOOLTIP), NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_DB_SHOW_DEPS), SetMinimalSize(6, 12), SetFill(0, 1), SetDataTip(STR_DEPARTURES_DEPARTURES, STR_DEPARTURES_DEPARTURES_TOOLTIP),
NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_DB_SHOW_VIA), SetMinimalSize(11, 12), SetFill(0, 1), SetDataTip(STR_DEPARTURES_VIA_BUTTON, STR_DEPARTURES_VIA_TOOLTIP), NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_DB_SHOW_VIA), SetMinimalSize(11, 12), SetFill(0, 1), SetDataTip(STR_DEPARTURES_VIA_BUTTON, STR_DEPARTURES_VIA_TOOLTIP),
@@ -88,6 +90,9 @@ protected:
int calc_tick_countdown; ///< The number of ticks to wait until recomputing the departure list. Signed in case it goes below zero. int calc_tick_countdown; ///< The number of ticks to wait until recomputing the departure list. Signed in case it goes below zero.
bool show_types[4]; ///< The vehicle types to show in the departure list. bool show_types[4]; ///< The vehicle types to show in the departure list.
bool departure_types[3]; ///< The types of departure to show in the departure list. bool departure_types[3]; ///< The types of departure to show in the departure list.
bool show_pax; ///< Show passenger vehicles
bool show_freight; ///< Show freight vehicles
bool cargo_buttons_disabled;///< Show pax/freight buttons disabled
uint min_width; ///< The minimum width of this window. uint min_width; ///< The minimum width of this window.
Scrollbar *vscroll; Scrollbar *vscroll;
@@ -95,6 +100,30 @@ protected:
static void RecomputeDateWidth(); static void RecomputeDateWidth();
virtual void DrawDeparturesListItems(const Rect &r) const; virtual void DrawDeparturesListItems(const Rect &r) const;
void DeleteDeparturesList(DepartureList* list); void DeleteDeparturesList(DepartureList* list);
void ToggleCargoFilter(int widget, bool &flag)
{
flag = !flag;
this->SetWidgetLoweredState(widget, flag);
/* We need to recompute the departures list. */
this->calc_tick_countdown = 0;
/* We need to redraw the button that was pressed. */
this->SetWidgetDirty(widget);
}
void SetCargoFilterDisabledState()
{
this->cargo_buttons_disabled = _settings_client.gui.departure_only_passengers;
this->SetWidgetDisabledState(WID_DB_SHOW_PAX, cargo_buttons_disabled);
this->SetWidgetDisabledState(WID_DB_SHOW_FREIGHT, cargo_buttons_disabled);
if (this->cargo_buttons_disabled) {
this->show_pax = true;
this->LowerWidget(WID_DB_SHOW_PAX);
this->show_freight = false;
this->RaiseWidget(WID_DB_SHOW_FREIGHT);
}
}
public: public:
DeparturesWindow(WindowDesc *desc, WindowNumber window_number) : Window(desc), DeparturesWindow(WindowDesc *desc, WindowNumber window_number) : Window(desc),
@@ -114,9 +143,14 @@ public:
departure_types[0] = true; departure_types[0] = true;
departure_types[1] = false; departure_types[1] = false;
departure_types[2] = false; departure_types[2] = false;
show_pax = true;
show_freight = true;
this->LowerWidget(WID_DB_SHOW_DEPS); this->LowerWidget(WID_DB_SHOW_DEPS);
this->RaiseWidget(WID_DB_SHOW_ARRS); this->RaiseWidget(WID_DB_SHOW_ARRS);
this->RaiseWidget(WID_DB_SHOW_VIA); this->RaiseWidget(WID_DB_SHOW_VIA);
this->LowerWidget(WID_DB_SHOW_PAX);
this->LowerWidget(WID_DB_SHOW_FREIGHT);
this->SetCargoFilterDisabledState();
for (uint i = 0; i < 4; ++i) { for (uint i = 0; i < 4; ++i) {
show_types[i] = true; show_types[i] = true;
@@ -213,7 +247,7 @@ public:
this->SetWidgetDirty(widget); this->SetWidgetDirty(widget);
break; break;
case WID_DB_LIST: // Matrix to show departures case WID_DB_LIST: { // Matrix to show departures
/* We need to find the departure corresponding to where the user clicked. */ /* We need to find the departure corresponding to where the user clicked. */
uint32 id_v = (pt.y - this->GetWidget<NWidgetBase>(WID_DB_LIST)->pos_y) / this->entry_height; uint32 id_v = (pt.y - this->GetWidget<NWidgetBase>(WID_DB_LIST)->pos_y) / this->entry_height;
@@ -252,6 +286,15 @@ public:
} }
} }
break;
}
case WID_DB_SHOW_PAX:
this->ToggleCargoFilter(widget, this->show_pax);
break;
case WID_DB_SHOW_FREIGHT:
this->ToggleCargoFilter(widget, this->show_freight);
break; break;
} }
} }
@@ -270,6 +313,13 @@ public:
this->RecomputeDateWidth(); this->RecomputeDateWidth();
} }
if (this->cargo_buttons_disabled != _settings_client.gui.departure_only_passengers) {
this->SetCargoFilterDisabledState();
this->calc_tick_countdown = 0;
this->SetWidgetDirty(WID_DB_SHOW_PAX);
this->SetWidgetDirty(WID_DB_SHOW_FREIGHT);
}
/* We need to redraw the scrolling text in its new position. */ /* We need to redraw the scrolling text in its new position. */
this->SetWidgetDirty(WID_DB_LIST); this->SetWidgetDirty(WID_DB_LIST);
@@ -278,8 +328,10 @@ public:
this->calc_tick_countdown = _settings_client.gui.departure_calc_frequency; this->calc_tick_countdown = _settings_client.gui.departure_calc_frequency;
this->DeleteDeparturesList(this->departures); this->DeleteDeparturesList(this->departures);
this->DeleteDeparturesList(this->arrivals); this->DeleteDeparturesList(this->arrivals);
this->departures = (this->departure_types[0] ? MakeDepartureList(this->station, this->show_types, D_DEPARTURE, Twaypoint || this->departure_types[2]) : new DepartureList()); bool show_pax = _settings_client.gui.departure_only_passengers ? true : this->show_pax;
this->arrivals = (this->departure_types[1] && !_settings_client.gui.departure_show_both ? MakeDepartureList(this->station, this->show_types, D_ARRIVAL ) : new DepartureList()); bool show_freight = _settings_client.gui.departure_only_passengers ? false : this->show_freight;
this->departures = (this->departure_types[0] ? MakeDepartureList(this->station, this->show_types, D_DEPARTURE, Twaypoint || this->departure_types[2], show_pax, show_freight) : new DepartureList());
this->arrivals = (this->departure_types[1] && !_settings_client.gui.departure_show_both ? MakeDepartureList(this->station, this->show_types, D_ARRIVAL, false, show_pax, show_freight) : new DepartureList());
this->SetWidgetDirty(WID_DB_LIST); this->SetWidgetDirty(WID_DB_LIST);
} }

View File

@@ -3190,9 +3190,13 @@ STR_STATION_VIEW_CLOSE_AIRPORT_TOOLTIP :{BLACK}Prevent
# Departures window # Departures window
STR_DEPARTURES_CAPTION :{WHITE}{STATION} Live Travel Information STR_DEPARTURES_CAPTION :{WHITE}{STATION} Live Travel Information
STR_DEPARTURES_CAPTION_WAYPOINT :{WHITE}{WAYPOINT} Live Travel Information STR_DEPARTURES_CAPTION_WAYPOINT :{WHITE}{WAYPOINT} Live Travel Information
STR_DEPARTURES_PAX :{BLACK}{TINY_FONT}P
STR_DEPARTURES_FREIGHT :{BLACK}{TINY_FONT}F
STR_DEPARTURES_DEPARTURES :{BLACK}{TINY_FONT}D STR_DEPARTURES_DEPARTURES :{BLACK}{TINY_FONT}D
STR_DEPARTURES_ARRIVALS :{BLACK}{TINY_FONT}A STR_DEPARTURES_ARRIVALS :{BLACK}{TINY_FONT}A
STR_DEPARTURES_VIA_BUTTON :{BLACK}{TINY_FONT}via STR_DEPARTURES_VIA_BUTTON :{BLACK}{TINY_FONT}via
STR_DEPARTURES_PAX_TOOLTIP :{BLACK}Show passenger departures
STR_DEPARTURES_FREIGHT_TOOLTIP :{BLACK}Show freight departures
STR_DEPARTURES_DEPARTURES_TOOLTIP :{BLACK}Show timetabled departures STR_DEPARTURES_DEPARTURES_TOOLTIP :{BLACK}Show timetabled departures
STR_DEPARTURES_ARRIVALS_TOOLTIP :{BLACK}Show timetabled arrivals STR_DEPARTURES_ARRIVALS_TOOLTIP :{BLACK}Show timetabled arrivals
STR_DEPARTURES_VIA_TOOLTIP :{BLACK}Show timetabled vehicles that do not stop here STR_DEPARTURES_VIA_TOOLTIP :{BLACK}Show timetabled vehicles that do not stop here

View File

@@ -17,6 +17,8 @@ enum DeparturesWindowWidgets {
WID_DB_CAPTION, ///< Window caption WID_DB_CAPTION, ///< Window caption
WID_DB_LIST, ///< List of departures WID_DB_LIST, ///< List of departures
WID_DB_SCROLLBAR, ///< List scrollbar WID_DB_SCROLLBAR, ///< List scrollbar
WID_DB_SHOW_PAX, ///< Toggle passenger departures button
WID_DB_SHOW_FREIGHT, ///< Toggle freight button
WID_DB_SHOW_DEPS, ///< Toggle departures button WID_DB_SHOW_DEPS, ///< Toggle departures button
WID_DB_SHOW_ARRS, ///< Toggle arrivals button WID_DB_SHOW_ARRS, ///< Toggle arrivals button
WID_DB_SHOW_VIA, ///< Toggle via button WID_DB_SHOW_VIA, ///< Toggle via button