summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lang/english.txt5
-rw-r--r--src/vehicle_gui.cpp52
-rw-r--r--src/widgets/vehicle_widget.h2
3 files changed, 47 insertions, 12 deletions
diff --git a/src/lang/english.txt b/src/lang/english.txt
index 7c0a31f30..f2f28f794 100644
--- a/src/lang/english.txt
+++ b/src/lang/english.txt
@@ -3451,6 +3451,11 @@ STR_VEHICLE_DETAILS_SERVICING_INTERVAL_PERCENT :{BLACK}Servicin
STR_VEHICLE_DETAILS_INCREASE_SERVICING_INTERVAL_TOOLTIP :{BLACK}Increase servicing interval by 10. Ctrl+Click increases servicing interval by 5
STR_VEHICLE_DETAILS_DECREASE_SERVICING_INTERVAL_TOOLTIP :{BLACK}Decrease servicing interval by 10. Ctrl+Click decreases servicing interval by 5
+STR_SERVICE_INTERVAL_DROPDOWN_TOOLTIP :{BLACK}Change servicing interval type
+STR_VEHICLE_DETAILS_DEFAULT :Default
+STR_VEHICLE_DETAILS_DAYS :Days
+STR_VEHICLE_DETAILS_PERCENT :Percentage
+
STR_QUERY_RENAME_TRAIN_CAPTION :{WHITE}Name train
STR_QUERY_RENAME_ROAD_VEHICLE_CAPTION :{WHITE}Name road vehicle
STR_QUERY_RENAME_SHIP_CAPTION :{WHITE}Name ship
diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp
index 913220d67..d6a1bec67 100644
--- a/src/vehicle_gui.cpp
+++ b/src/vehicle_gui.cpp
@@ -1687,8 +1687,8 @@ static const NWidgetPart _nested_nontrain_vehicle_details_widgets[] = {
SetDataTip(AWV_DECREASE, STR_VEHICLE_DETAILS_DECREASE_SERVICING_INTERVAL_TOOLTIP),
NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_VD_INCREASE_SERVICING_INTERVAL), SetFill(0, 1),
SetDataTip(AWV_INCREASE, STR_VEHICLE_DETAILS_INCREASE_SERVICING_INTERVAL_TOOLTIP),
- NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_VD_DEFAULT_SERVICING_INTERVAL), SetFill(0, 1),
- SetDataTip(STR_BUTTON_DEFAULT, 0),
+ NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_VD_SERVICE_INTERVAL_DROPDOWN), SetFill(0, 1),
+ SetDataTip(STR_EMPTY, STR_SERVICE_INTERVAL_DROPDOWN_TOOLTIP),
NWidget(WWT_PANEL, COLOUR_GREY, WID_VD_SERVICING_INTERVAL), SetFill(1, 1), SetResize(1, 0), EndContainer(),
NWidget(WWT_RESIZEBOX, COLOUR_GREY),
EndContainer(),
@@ -1713,8 +1713,8 @@ static const NWidgetPart _nested_train_vehicle_details_widgets[] = {
SetDataTip(AWV_DECREASE, STR_VEHICLE_DETAILS_DECREASE_SERVICING_INTERVAL_TOOLTIP),
NWidget(WWT_PUSHARROWBTN, COLOUR_GREY, WID_VD_INCREASE_SERVICING_INTERVAL), SetFill(0, 1),
SetDataTip(AWV_INCREASE, STR_VEHICLE_DETAILS_DECREASE_SERVICING_INTERVAL_TOOLTIP),
- NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_VD_DEFAULT_SERVICING_INTERVAL), SetFill(0, 1),
- SetDataTip(STR_BUTTON_DEFAULT, 0),
+ NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_VD_SERVICE_INTERVAL_DROPDOWN), SetFill(0, 1),
+ SetDataTip(STR_EMPTY, STR_SERVICE_INTERVAL_DROPDOWN_TOOLTIP),
NWidget(WWT_PANEL, COLOUR_GREY, WID_VD_SERVICING_INTERVAL), SetFill(1, 1), SetResize(1, 0), EndContainer(),
EndContainer(),
NWidget(NWID_HORIZONTAL),
@@ -1737,6 +1737,13 @@ extern void DrawRoadVehDetails(const Vehicle *v, int left, int right, int y);
extern void DrawShipDetails(const Vehicle *v, int left, int right, int y);
extern void DrawAircraftDetails(const Aircraft *v, int left, int right, int y);
+static StringID _service_interval_dropdown[] = {
+ STR_VEHICLE_DETAILS_DEFAULT,
+ STR_VEHICLE_DETAILS_DAYS,
+ STR_VEHICLE_DETAILS_PERCENT,
+ INVALID_STRING_ID,
+};
+
/** Class for managing the vehicle details window. */
struct VehicleDetailsWindow : Window {
TrainDetailsWindowTabs tab; ///< For train vehicles: which tab is displayed.
@@ -1852,6 +1859,16 @@ struct VehicleDetailsWindow : Window {
size->height = 4 * resize->height;
break;
+ case WID_VD_SERVICE_INTERVAL_DROPDOWN: {
+ StringID *strs = _service_interval_dropdown;
+ while (*strs != INVALID_STRING_ID) {
+ *size = maxdim(*size, GetStringBoundingBox(*strs++));
+ }
+ size->width += padding.width;
+ size->height = FONT_HEIGHT_NORMAL + WD_DROPDOWNTEXT_TOP + WD_DROPDOWNTEXT_BOTTOM;
+ break;
+ }
+
case WID_VD_SERVICING_INTERVAL:
SetDParamMaxValue(0, MAX_SERVINT_DAYS); // Roughly the maximum interval
SetDParamMaxValue(1, MAX_YEAR * DAYS_IN_YEAR); // Roughly the maximum year
@@ -2011,7 +2028,10 @@ struct VehicleDetailsWindow : Window {
WID_VD_DECREASE_SERVICING_INTERVAL,
WIDGET_LIST_END);
- this->SetWidgetLoweredState(WID_VD_DEFAULT_SERVICING_INTERVAL, !v->ServiceIntervalIsCustom());
+ StringID str = v->ServiceIntervalIsCustom() ?
+ (v->ServiceIntervalIsPercent() ? STR_VEHICLE_DETAILS_PERCENT : STR_VEHICLE_DETAILS_DAYS) :
+ STR_VEHICLE_DETAILS_DEFAULT;
+ this->GetWidget<NWidgetCore>(WID_VD_SERVICE_INTERVAL_DROPDOWN)->widget_data = str;
this->DrawWidgets();
}
@@ -2040,13 +2060,9 @@ struct VehicleDetailsWindow : Window {
break;
}
- case WID_VD_DEFAULT_SERVICING_INTERVAL: {
+ case WID_VD_SERVICE_INTERVAL_DROPDOWN: {
const Vehicle *v = Vehicle::Get(this->window_number);
- if (_ctrl_pressed) {
- DoCommandP(v->tile, v->index, v->service_interval | (1 << 16) | (!v->ServiceIntervalIsPercent() << 17), CMD_CHANGE_SERVICE_INT | CMD_MSG(STR_ERROR_CAN_T_CHANGE_SERVICING));
- } else {
- DoCommandP(v->tile, v->index, v->service_interval | (!v->ServiceIntervalIsCustom() << 16) | (v->ServiceIntervalIsPercent() << 17), CMD_CHANGE_SERVICE_INT | CMD_MSG(STR_ERROR_CAN_T_CHANGE_SERVICING));
- }
+ ShowDropDownMenu(this, _service_interval_dropdown, v->ServiceIntervalIsCustom() ? (v->ServiceIntervalIsPercent() ? 2 : 1) : 0, widget, 0, 0);
break;
}
@@ -2068,6 +2084,20 @@ struct VehicleDetailsWindow : Window {
}
}
+ virtual void OnDropdownSelect(int widget, int index)
+ {
+ switch (widget) {
+ case WID_VD_SERVICE_INTERVAL_DROPDOWN: {
+ const Vehicle *v = Vehicle::Get(this->window_number);
+ bool iscustom = index != 0;
+ bool ispercent = iscustom ? (index == 2) : Company::Get(v->owner)->settings.vehicle.servint_ispercent;
+ uint16 interval = GetServiceIntervalClamped(v->GetServiceInterval(), ispercent);
+ DoCommandP(v->tile, v->index, interval | (iscustom << 16) | (ispercent << 17), CMD_CHANGE_SERVICE_INT | CMD_MSG(STR_ERROR_CAN_T_CHANGE_SERVICING));
+ break;
+ }
+ }
+ }
+
virtual void OnQueryTextFinished(char *str)
{
if (str == NULL) return;
diff --git a/src/widgets/vehicle_widget.h b/src/widgets/vehicle_widget.h
index ac9cf257b..a0902dab4 100644
--- a/src/widgets/vehicle_widget.h
+++ b/src/widgets/vehicle_widget.h
@@ -49,7 +49,7 @@ enum VehicleDetailsWidgets {
WID_VD_TOP_DETAILS, ///< Panel with generic details.
WID_VD_INCREASE_SERVICING_INTERVAL, ///< Increase the servicing interval.
WID_VD_DECREASE_SERVICING_INTERVAL, ///< Decrease the servicing interval.
- WID_VD_DEFAULT_SERVICING_INTERVAL, ///< Toggle default servicing interval.
+ WID_VD_SERVICE_INTERVAL_DROPDOWN, ///< Dropdown to select default/days/percent service interval.
WID_VD_SERVICING_INTERVAL, ///< Information about the servicing interval.
WID_VD_MIDDLE_DETAILS, ///< Details for non-trains.
WID_VD_MATRIX, ///< List of details for trains.