summaryrefslogtreecommitdiff
path: root/src/order_gui.cpp
diff options
context:
space:
mode:
authormichi_cc <michi_cc@openttd.org>2011-11-04 00:38:59 +0000
committermichi_cc <michi_cc@openttd.org>2011-11-04 00:38:59 +0000
commit3f853e7a565fcd5e51f13f1c54079c83f625225b (patch)
tree996f3864a019e4e8f1eda2a2062736cfb0b5f28a /src/order_gui.cpp
parent5ee765b2b2fc9756ab5c1bba8171e106ec6bd50f (diff)
downloadopenttd-3f853e7a565fcd5e51f13f1c54079c83f625225b.tar.xz
(svn r23089) -Add: Allow specifying refits for go-to station orders.
Diffstat (limited to 'src/order_gui.cpp')
-rw-r--r--src/order_gui.cpp176
1 files changed, 132 insertions, 44 deletions
diff --git a/src/order_gui.cpp b/src/order_gui.cpp
index 1f7e3cd1d..499c3d36d 100644
--- a/src/order_gui.cpp
+++ b/src/order_gui.cpp
@@ -48,6 +48,7 @@ enum OrderWindowWidgets {
ORDER_WIDGET_REFIT,
ORDER_WIDGET_SERVICE,
ORDER_WIDGET_EMPTY,
+ ORDER_WIDGET_REFIT_DROPDOWN,
ORDER_WIDGET_COND_VARIABLE,
ORDER_WIDGET_COND_COMPARATOR,
ORDER_WIDGET_COND_VALUE,
@@ -61,37 +62,73 @@ enum OrderWindowWidgets {
};
/** Order load types that could be given to station orders. */
-static const StringID _station_load_types[][5] = {
+static const StringID _station_load_types[][5][5] = {
{
- STR_EMPTY,
- INVALID_STRING_ID,
- STR_ORDER_FULL_LOAD,
- STR_ORDER_FULL_LOAD_ANY,
- STR_ORDER_NO_LOAD,
- }, {
- STR_ORDER_UNLOAD,
- INVALID_STRING_ID,
- STR_ORDER_UNLOAD_FULL_LOAD,
- STR_ORDER_UNLOAD_FULL_LOAD_ANY,
- STR_ORDER_UNLOAD_NO_LOAD,
- }, {
- STR_ORDER_TRANSFER,
- INVALID_STRING_ID,
- STR_ORDER_TRANSFER_FULL_LOAD,
- STR_ORDER_TRANSFER_FULL_LOAD_ANY,
- STR_ORDER_TRANSFER_NO_LOAD,
- }, {
- /* Unload and transfer do not work together. */
- INVALID_STRING_ID,
- INVALID_STRING_ID,
- INVALID_STRING_ID,
- INVALID_STRING_ID,
+ /* No refitting. */
+ {
+ STR_EMPTY,
+ INVALID_STRING_ID,
+ STR_ORDER_FULL_LOAD,
+ STR_ORDER_FULL_LOAD_ANY,
+ STR_ORDER_NO_LOAD,
+ }, {
+ STR_ORDER_UNLOAD,
+ INVALID_STRING_ID,
+ STR_ORDER_UNLOAD_FULL_LOAD,
+ STR_ORDER_UNLOAD_FULL_LOAD_ANY,
+ STR_ORDER_UNLOAD_NO_LOAD,
+ }, {
+ STR_ORDER_TRANSFER,
+ INVALID_STRING_ID,
+ STR_ORDER_TRANSFER_FULL_LOAD,
+ STR_ORDER_TRANSFER_FULL_LOAD_ANY,
+ STR_ORDER_TRANSFER_NO_LOAD,
+ }, {
+ /* Unload and transfer do not work together. */
+ INVALID_STRING_ID,
+ INVALID_STRING_ID,
+ INVALID_STRING_ID,
+ INVALID_STRING_ID,
+ }, {
+ STR_ORDER_NO_UNLOAD,
+ INVALID_STRING_ID,
+ STR_ORDER_NO_UNLOAD_FULL_LOAD,
+ STR_ORDER_NO_UNLOAD_FULL_LOAD_ANY,
+ STR_ORDER_NO_UNLOAD_NO_LOAD,
+ }
}, {
- STR_ORDER_NO_UNLOAD,
- INVALID_STRING_ID,
- STR_ORDER_NO_UNLOAD_FULL_LOAD,
- STR_ORDER_NO_UNLOAD_FULL_LOAD_ANY,
- STR_ORDER_NO_UNLOAD_NO_LOAD,
+ /* With auto-refitting. No loading and auto-refitting do not work together. */
+ {
+ STR_ORDER_AUTO_REFIT,
+ INVALID_STRING_ID,
+ STR_ORDER_FULL_LOAD_REFIT,
+ STR_ORDER_FULL_LOAD_ANY_REFIT,
+ INVALID_STRING_ID,
+ }, {
+ STR_ORDER_UNLOAD_REFIT,
+ INVALID_STRING_ID,
+ STR_ORDER_UNLOAD_FULL_LOAD_REFIT,
+ STR_ORDER_UNLOAD_FULL_LOAD_ANY_REFIT,
+ INVALID_STRING_ID,
+ }, {
+ STR_ORDER_TRANSFER_REFIT,
+ INVALID_STRING_ID,
+ STR_ORDER_TRANSFER_FULL_LOAD_REFIT,
+ STR_ORDER_TRANSFER_FULL_LOAD_ANY_REFIT,
+ INVALID_STRING_ID,
+ }, {
+ /* Unload and transfer do not work together. */
+ INVALID_STRING_ID,
+ INVALID_STRING_ID,
+ INVALID_STRING_ID,
+ INVALID_STRING_ID,
+ }, {
+ STR_ORDER_NO_UNLOAD_REFIT,
+ INVALID_STRING_ID,
+ STR_ORDER_NO_UNLOAD_FULL_LOAD_REFIT,
+ STR_ORDER_NO_UNLOAD_FULL_LOAD_ANY_REFIT,
+ INVALID_STRING_ID,
+ }
}
};
@@ -181,6 +218,12 @@ static int DepotActionStringIndex(const Order *order)
}
}
+static const StringID _order_refit_action_dropdown[] = {
+ STR_ORDER_DROP_REFIT_AUTO,
+ STR_ORDER_DROP_REFIT_AUTO_ANY,
+ INVALID_STRING_ID
+};
+
/**
* Draws an order in order or timetable GUI
* @param v Vehicle the order belongs to
@@ -247,7 +290,10 @@ void DrawOrderString(const Vehicle *v, const Order *order, int order_index, int
SetTimetableParams(6, 7, order->wait_time);
}
} else {
- SetDParam(3, (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) ? STR_EMPTY : _station_load_types[unload][load]);
+ SetDParam(3, (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) ? STR_EMPTY : _station_load_types[order->IsRefit()][unload][load]);
+ if (order->IsRefit()) {
+ SetDParam(4, order->IsAutoRefit() ? STR_ORDER_AUTO_REFIT_ANY : CargoSpec::Get(order->GetRefitCargo())->name);
+ }
if (v->type == VEH_TRAIN && (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) == 0) {
SetDParam(5, order->GetStopLocation() + STR_ORDER_STOP_LOCATION_NEAR_END);
}
@@ -423,7 +469,7 @@ static Order GetOrderCmdFromTile(const Vehicle *v, TileIndex tile)
* The top-row buttons of one of your trains or road vehicles is one of the following three cases:
* \verbatim
* +-----------------+-----------------+-----------------+-----------------+
- * | NON-STOP | FULL_LOAD | UNLOAD | (empty) | (normal)
+ * | NON-STOP | FULL_LOAD | UNLOAD | REFIT | (normal)
* +-----------------+-----+-----------+-----------+-----+-----------------+
* | COND_VAR | COND_COMPARATOR | COND_VALUE | (for conditional orders)
* +-----------------+-----+-----------+-----------+-----+-----------------+
@@ -433,9 +479,9 @@ static Order GetOrderCmdFromTile(const Vehicle *v, TileIndex tile)
*
* Airplanes and ships have one of the following three top-row button rows:
* \verbatim
- * +--------------------------+--------------------------+
- * | FULL_LOAD | UNLOAD | (normal)
- * +-----------------+--------+--------+-----------------+
+ * +-----------------+-----------------+-----------------+
+ * | FULL_LOAD | UNLOAD | REFIT | (normal)
+ * +-----------------+-----------------+-----------------+
* | COND_VAR | COND_COMPARATOR | COND_VALUE | (for conditional orders)
* +-----------------+--------+--------+-----------------+
* | REFIT | SERVICE | (for depot order)
@@ -477,9 +523,10 @@ private:
/* ORDER_WIDGET_SEL_TOP_RIGHT */
DP_RIGHT_EMPTY = 0, ///< Display an empty panel in the right button of the top row of the train/rv order window.
+ DP_RIGHT_REFIT = 1, ///< Display 'refit' in the right button of the top row of the train/rv order window.
/* ORDER_WIDGET_SEL_TOP_ROW */
- DP_ROW_LOAD = 0, ///< Display 'load' / 'unload' buttons in the top row of the ship/airplane order window.
+ DP_ROW_LOAD = 0, ///< Display 'load' / 'unload' / 'refit' buttons in the top row of the ship/airplane order window.
DP_ROW_DEPOT = 1, ///< Display 'refit' / 'service' buttons in the top row of the ship/airplane order window.
DP_ROW_CONDITIONAL = 2, ///< Display the conditional order buttons in the top row of the ship/airplane order window.
@@ -493,6 +540,7 @@ private:
OrderPlaceObjectState goto_type;
const Vehicle *vehicle; ///< Vehicle owning the orders being displayed and manipulated.
Scrollbar *vscroll;
+ bool can_do_autorefit; ///< Vehicle chain can be auto-refitted.
/**
* Return the memorised selected order.
@@ -740,15 +788,29 @@ private:
/**
* Handle the click on the refit button.
* If ctrl is pressed, cancel refitting, else show the refit window.
- * @param i Dummy parameter.
+ * @param i Selected refit command.
+ * @param auto_refit Select refit for auto-refitting.
*/
- void OrderClick_Refit(int i)
+ void OrderClick_Refit(int i, bool auto_refit)
{
if (_ctrl_pressed) {
/* Cancel refitting */
DoCommandP(this->vehicle->tile, this->vehicle->index, (this->OrderGetSel() << 16) | (CT_NO_REFIT << 8) | CT_NO_REFIT, CMD_ORDER_REFIT);
} else {
- ShowVehicleRefitWindow(this->vehicle, this->OrderGetSel(), this);
+ if (i == 1) { // Auto-refit to available cargo type.
+ DoCommandP(this->vehicle->tile, this->vehicle->index, (this->OrderGetSel() << 16) | CT_AUTO_REFIT, CMD_ORDER_REFIT);
+ } else {
+ ShowVehicleRefitWindow(this->vehicle, this->OrderGetSel(), this, auto_refit);
+ }
+ }
+ }
+
+ /** Cache auto-refittability of the vehicle chain. */
+ void UpdateAutoRefitState()
+ {
+ this->can_do_autorefit = false;
+ for (const Vehicle *w = this->vehicle; w != NULL; w = w->Next()) {
+ if (HasBit(Engine::Get(w->engine_type)->info.misc_flags, EF_AUTO_REFIT)) this->can_do_autorefit = true;
}
}
@@ -766,6 +828,8 @@ public:
this->order_over = INVALID_VEH_ORDER_ID;
this->owner = v->owner;
+ this->UpdateAutoRefitState();
+
if (_settings_client.gui.quick_goto && v->owner == _local_company) {
/* If there are less than 2 station, make Go To active. */
int station_orders = 0;
@@ -825,6 +889,7 @@ public:
case -666:
/* Autoreplace replaced the vehicle */
this->vehicle = Vehicle::Get(this->window_number);
+ this->UpdateAutoRefitState();
break;
case -1:
@@ -945,6 +1010,7 @@ public:
}
this->DisableWidget(ORDER_WIDGET_FULL_LOAD);
this->DisableWidget(ORDER_WIDGET_UNLOAD);
+ this->DisableWidget(ORDER_WIDGET_REFIT_DROPDOWN);
} else {
this->SetWidgetDisabledState(ORDER_WIDGET_FULL_LOAD, (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) != 0); // full load
this->SetWidgetDisabledState(ORDER_WIDGET_UNLOAD, (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) != 0); // unload
@@ -957,12 +1023,16 @@ public:
train_row_sel->SetDisplayedPlane(DP_GROUNDVEHICLE_ROW_NORMAL);
left_sel->SetDisplayedPlane(DP_LEFT_LOAD);
middle_sel->SetDisplayedPlane(DP_MIDDLE_UNLOAD);
- right_sel->SetDisplayedPlane(DP_RIGHT_EMPTY);
+ right_sel->SetDisplayedPlane(DP_RIGHT_REFIT);
this->EnableWidget(ORDER_WIDGET_NON_STOP);
this->SetWidgetLoweredState(ORDER_WIDGET_NON_STOP, order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS);
}
this->SetWidgetLoweredState(ORDER_WIDGET_FULL_LOAD, order->GetLoadType() == OLF_FULL_LOAD_ANY);
this->SetWidgetLoweredState(ORDER_WIDGET_UNLOAD, order->GetUnloadType() == OUFB_UNLOAD);
+
+ /* Can only do refitting when stopping at the destination and loading cargo. */
+ this->SetWidgetDisabledState(ORDER_WIDGET_REFIT_DROPDOWN, !this->can_do_autorefit || order->GetLoadType() == OLFB_NO_LOAD || order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION);
+
break;
case OT_GOTO_WAYPOINT:
@@ -978,6 +1048,7 @@ public:
}
this->DisableWidget(ORDER_WIDGET_FULL_LOAD);
this->DisableWidget(ORDER_WIDGET_UNLOAD);
+ this->DisableWidget(ORDER_WIDGET_REFIT_DROPDOWN);
break;
case OT_GOTO_DEPOT:
@@ -1024,6 +1095,7 @@ public:
}
this->DisableWidget(ORDER_WIDGET_FULL_LOAD);
this->DisableWidget(ORDER_WIDGET_UNLOAD);
+ this->DisableWidget(ORDER_WIDGET_REFIT_DROPDOWN);
break;
}
}
@@ -1220,7 +1292,7 @@ public:
break;
case ORDER_WIDGET_REFIT:
- this->OrderClick_Refit(0);
+ this->OrderClick_Refit(0, false);
break;
case ORDER_WIDGET_SERVICE:
@@ -1231,6 +1303,14 @@ public:
}
break;
+ case ORDER_WIDGET_REFIT_DROPDOWN:
+ if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
+ this->OrderClick_Refit(0, true);
+ } else {
+ ShowDropDownMenu(this, _order_refit_action_dropdown, 0, ORDER_WIDGET_REFIT_DROPDOWN, 0, 0);
+ }
+ break;
+
case ORDER_WIDGET_TIMETABLE_VIEW:
ShowTimetableWindow(this->vehicle);
break;
@@ -1317,6 +1397,10 @@ public:
this->OrderClick_Service(index);
break;
+ case ORDER_WIDGET_REFIT_DROPDOWN:
+ this->OrderClick_Refit(index, true);
+ break;
+
case ORDER_WIDGET_COND_VARIABLE:
DoCommandP(this->vehicle->tile, this->vehicle->index + (this->OrderGetSel() << 20), MOF_COND_VARIABLE | index << 4, CMD_MODIFY_ORDER | CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER));
break;
@@ -1505,6 +1589,8 @@ static const NWidgetPart _nested_orders_train_widgets[] = {
NWidget(NWID_SELECTION, INVALID_COLOUR, ORDER_WIDGET_SEL_TOP_RIGHT),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, ORDER_WIDGET_EMPTY), SetMinimalSize(93, 12), SetFill(1, 0),
SetDataTip(STR_ORDER_REFIT, STR_ORDER_REFIT_TOOLTIP), SetResize(1, 0),
+ NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, ORDER_WIDGET_REFIT_DROPDOWN), SetMinimalSize(93, 12), SetFill(1, 0),
+ SetDataTip(STR_ORDER_REFIT_AUTO, STR_ORDER_REFIT_AUTO_TOOLTIP), SetResize(1, 0),
EndContainer(),
EndContainer(),
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
@@ -1561,12 +1647,14 @@ static const NWidgetPart _nested_orders_widgets[] = {
/* First button row. */
NWidget(NWID_HORIZONTAL),
NWidget(NWID_SELECTION, INVALID_COLOUR, ORDER_WIDGET_SEL_TOP_ROW),
- /* load + unload buttons. */
- NWidget(NWID_HORIZONTAL),
- NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, ORDER_WIDGET_FULL_LOAD), SetMinimalSize(186, 12), SetFill(1, 0),
+ /* Load + unload + refit buttons. */
+ NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
+ NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, ORDER_WIDGET_FULL_LOAD), SetMinimalSize(124, 12), SetFill(1, 0),
SetDataTip(STR_ORDER_TOGGLE_FULL_LOAD, STR_ORDER_TOOLTIP_FULL_LOAD), SetResize(1, 0),
- NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, ORDER_WIDGET_UNLOAD), SetMinimalSize(186, 12), SetFill(1, 0),
+ NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, ORDER_WIDGET_UNLOAD), SetMinimalSize(124, 12), SetFill(1, 0),
SetDataTip(STR_ORDER_TOGGLE_UNLOAD, STR_ORDER_TOOLTIP_UNLOAD), SetResize(1, 0),
+ NWidget(NWID_BUTTON_DROPDOWN, COLOUR_GREY, ORDER_WIDGET_REFIT_DROPDOWN), SetMinimalSize(124, 12), SetFill(1, 0),
+ SetDataTip(STR_ORDER_REFIT_AUTO, STR_ORDER_REFIT_AUTO_TOOLTIP), SetResize(1, 0),
EndContainer(),
/* Refit + service buttons. */
NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),