Merge commit '13.0-RC1~2'
This commit is contained in:
@@ -29,6 +29,11 @@
|
||||
#include "aircraft.h"
|
||||
#include "engine_func.h"
|
||||
#include "vehicle_func.h"
|
||||
#include "vehiclelist.h"
|
||||
#include "vehicle_func.h"
|
||||
#include "error.h"
|
||||
#include "order_cmd.h"
|
||||
#include "company_cmd.h"
|
||||
|
||||
#include "widgets/order_widget.h"
|
||||
|
||||
@@ -548,7 +553,7 @@ private:
|
||||
VehicleOrderID GetOrderFromPt(int y)
|
||||
{
|
||||
NWidgetBase *nwid = this->GetWidget<NWidgetBase>(WID_O_ORDER_LIST);
|
||||
uint sel = (y - nwid->pos_y - WD_FRAMERECT_TOP) / nwid->resize_y; // Selected line in the WID_O_ORDER_LIST panel.
|
||||
uint sel = (y - nwid->pos_y - WidgetDimensions::scaled.framerect.top) / nwid->resize_y; // Selected line in the WID_O_ORDER_LIST panel.
|
||||
|
||||
if (sel >= this->vscroll->GetCapacity()) return INVALID_VEH_ORDER_ID;
|
||||
|
||||
@@ -594,7 +599,7 @@ private:
|
||||
}
|
||||
if (order->GetLoadType() == load_type) return; // If we still match, do nothing
|
||||
|
||||
DoCommandP(this->vehicle->tile, this->vehicle->index + (sel_ord << 20), MOF_LOAD | (load_type << 4), CMD_MODIFY_ORDER | CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER));
|
||||
Command<CMD_MODIFY_ORDER>::Post(STR_ERROR_CAN_T_MODIFY_THIS_ORDER, this->vehicle->tile, this->vehicle->index, sel_ord, MOF_LOAD, load_type);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -609,7 +614,7 @@ private:
|
||||
if (order == nullptr) return;
|
||||
i = (order->GetDepotOrderType() & ODTFB_SERVICE) ? DA_ALWAYS_GO : DA_SERVICE;
|
||||
}
|
||||
DoCommandP(this->vehicle->tile, this->vehicle->index + (sel_ord << 20), MOF_DEPOT_ACTION | (i << 4), CMD_MODIFY_ORDER | CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER));
|
||||
Command<CMD_MODIFY_ORDER>::Post(STR_ERROR_CAN_T_MODIFY_THIS_ORDER, this->vehicle->tile, this->vehicle->index, sel_ord, MOF_DEPOT_ACTION, i);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -620,11 +625,11 @@ private:
|
||||
Order order;
|
||||
order.next = nullptr;
|
||||
order.index = 0;
|
||||
order.MakeGoToDepot(0, ODTFB_PART_OF_ORDERS,
|
||||
order.MakeGoToDepot(INVALID_DEPOT, ODTFB_PART_OF_ORDERS,
|
||||
_settings_client.gui.new_nonstop && this->vehicle->IsGroundVehicle() ? ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS : ONSF_STOP_EVERYWHERE);
|
||||
order.SetDepotActionType(ODATFB_NEAREST_DEPOT);
|
||||
|
||||
DoCommandP(this->vehicle->tile, this->vehicle->index + (this->OrderGetSel() << 20), order.Pack(), CMD_INSERT_ORDER | CMD_MSG(STR_ERROR_CAN_T_INSERT_NEW_ORDER));
|
||||
Command<CMD_INSERT_ORDER>::Post(STR_ERROR_CAN_T_INSERT_NEW_ORDER, this->vehicle->tile, this->vehicle->index, this->OrderGetSel(), order);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -644,11 +649,11 @@ private:
|
||||
}
|
||||
if (order->GetUnloadType() == unload_type) return; // If we still match, do nothing
|
||||
|
||||
DoCommandP(this->vehicle->tile, this->vehicle->index + (sel_ord << 20), MOF_UNLOAD | (unload_type << 4), CMD_MODIFY_ORDER | CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER));
|
||||
Command<CMD_MODIFY_ORDER>::Post(STR_ERROR_CAN_T_MODIFY_THIS_ORDER, this->vehicle->tile, this->vehicle->index, sel_ord, MOF_UNLOAD, unload_type);
|
||||
|
||||
/* Transfer and unload orders with leave empty as default */
|
||||
if (unload_type == OUFB_TRANSFER || unload_type == OUFB_UNLOAD) {
|
||||
DoCommandP(this->vehicle->tile, this->vehicle->index + (sel_ord << 20), MOF_LOAD | (OLFB_NO_LOAD << 4), CMD_MODIFY_ORDER);
|
||||
Command<CMD_MODIFY_ORDER>::Post(this->vehicle->tile, this->vehicle->index, sel_ord, MOF_LOAD, OLFB_NO_LOAD);
|
||||
this->SetWidgetDirty(WID_O_FULL_LOAD);
|
||||
}
|
||||
}
|
||||
@@ -672,7 +677,7 @@ private:
|
||||
}
|
||||
|
||||
this->SetWidgetDirty(WID_O_NON_STOP);
|
||||
DoCommandP(this->vehicle->tile, this->vehicle->index + (sel_ord << 20), MOF_NON_STOP | non_stop << 4, CMD_MODIFY_ORDER | CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER));
|
||||
Command<CMD_MODIFY_ORDER>::Post(STR_ERROR_CAN_T_MODIFY_THIS_ORDER, this->vehicle->tile, this->vehicle->index, sel_ord, MOF_NON_STOP, non_stop);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -685,8 +690,8 @@ private:
|
||||
if (_ctrl_pressed && this->vehicle->cur_implicit_order_index == this->OrderGetSel()) return;
|
||||
if (this->vehicle->GetNumOrders() <= 1) return;
|
||||
|
||||
DoCommandP(this->vehicle->tile, this->vehicle->index, _ctrl_pressed ? this->OrderGetSel() : ((this->vehicle->cur_implicit_order_index + 1) % this->vehicle->GetNumOrders()),
|
||||
CMD_SKIP_TO_ORDER | CMD_MSG(_ctrl_pressed ? STR_ERROR_CAN_T_SKIP_TO_ORDER : STR_ERROR_CAN_T_SKIP_ORDER));
|
||||
Command<CMD_SKIP_TO_ORDER>::Post(_ctrl_pressed ? STR_ERROR_CAN_T_SKIP_TO_ORDER : STR_ERROR_CAN_T_SKIP_ORDER,
|
||||
this->vehicle->tile, this->vehicle->index, _ctrl_pressed ? this->OrderGetSel() : ((this->vehicle->cur_implicit_order_index + 1) % this->vehicle->GetNumOrders()));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -697,7 +702,7 @@ private:
|
||||
/* When networking, move one order lower */
|
||||
int selected = this->selected_order + (int)_networking;
|
||||
|
||||
if (DoCommandP(this->vehicle->tile, this->vehicle->index, this->OrderGetSel(), CMD_DELETE_ORDER | CMD_MSG(STR_ERROR_CAN_T_DELETE_THIS_ORDER))) {
|
||||
if (Command<CMD_DELETE_ORDER>::Post(STR_ERROR_CAN_T_DELETE_THIS_ORDER, this->vehicle->tile, this->vehicle->index, this->OrderGetSel())) {
|
||||
this->selected_order = selected >= this->vehicle->GetNumOrders() ? -1 : selected;
|
||||
this->UpdateButtonState();
|
||||
}
|
||||
@@ -722,7 +727,7 @@ private:
|
||||
/* Get another vehicle that share orders with this vehicle. */
|
||||
Vehicle *other_shared = (this->vehicle->FirstShared() == this->vehicle) ? this->vehicle->NextShared() : this->vehicle->PreviousShared();
|
||||
/* Copy the order list of the other vehicle. */
|
||||
if (DoCommandP(this->vehicle->tile, this->vehicle->index | CO_COPY << 30, other_shared->index, CMD_CLONE_ORDER | CMD_MSG(STR_ERROR_CAN_T_STOP_SHARING_ORDER_LIST))) {
|
||||
if (Command<CMD_CLONE_ORDER>::Post(STR_ERROR_CAN_T_STOP_SHARING_ORDER_LIST, this->vehicle->tile, CO_COPY, this->vehicle->index, other_shared->index)) {
|
||||
this->UpdateButtonState();
|
||||
}
|
||||
}
|
||||
@@ -737,10 +742,10 @@ private:
|
||||
{
|
||||
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);
|
||||
Command<CMD_ORDER_REFIT>::Post(this->vehicle->tile, this->vehicle->index, this->OrderGetSel(), CT_NO_REFIT);
|
||||
} else {
|
||||
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);
|
||||
Command<CMD_ORDER_REFIT>::Post(this->vehicle->tile, this->vehicle->index, this->OrderGetSel(), CT_AUTO_REFIT);
|
||||
} else {
|
||||
ShowVehicleRefitWindow(this->vehicle, this->OrderGetSel(), this, auto_refit);
|
||||
}
|
||||
@@ -793,8 +798,8 @@ public:
|
||||
{
|
||||
switch (widget) {
|
||||
case WID_O_ORDER_LIST:
|
||||
resize->height = GetMinButtonSize(FONT_HEIGHT_NORMAL);
|
||||
size->height = 4 * resize->height + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
|
||||
resize->height = FONT_HEIGHT_NORMAL;
|
||||
size->height = 6 * resize->height + padding.height;
|
||||
break;
|
||||
|
||||
case WID_O_COND_VARIABLE: {
|
||||
@@ -1075,13 +1080,14 @@ public:
|
||||
{
|
||||
if (widget != WID_O_ORDER_LIST) return;
|
||||
|
||||
Rect ir = r.Shrink(WidgetDimensions::scaled.frametext, WidgetDimensions::scaled.framerect);
|
||||
bool rtl = _current_text_dir == TD_RTL;
|
||||
SetDParamMaxValue(0, this->vehicle->GetNumOrders(), 2);
|
||||
int index_column_width = GetStringBoundingBox(STR_ORDER_INDEX).width + 2 * GetSpriteSize(rtl ? SPR_ARROW_RIGHT : SPR_ARROW_LEFT).width + 3;
|
||||
int middle = rtl ? r.right - WD_FRAMETEXT_RIGHT - index_column_width : r.left + WD_FRAMETEXT_LEFT + index_column_width;
|
||||
int index_column_width = GetStringBoundingBox(STR_ORDER_INDEX).width + 2 * GetSpriteSize(rtl ? SPR_ARROW_RIGHT : SPR_ARROW_LEFT).width + WidgetDimensions::scaled.hsep_normal;
|
||||
int middle = rtl ? ir.right - index_column_width : ir.left + index_column_width;
|
||||
|
||||
int y = ir.top;
|
||||
int line_height = this->GetWidget<NWidgetBase>(WID_O_ORDER_LIST)->resize_y;
|
||||
int y = Center(r.top + WD_FRAMERECT_TOP, line_height);
|
||||
|
||||
int i = this->vscroll->GetPosition();
|
||||
const Order *order = this->vehicle->GetOrder(i);
|
||||
@@ -1093,10 +1099,10 @@ public:
|
||||
|
||||
if (i != this->selected_order && i == this->order_over) {
|
||||
/* Highlight dragged order destination. */
|
||||
int top = (this->order_over < this->selected_order ? y : y + line_height) - WD_FRAMERECT_TOP;
|
||||
int bottom = std::min(top + 2, r.bottom - WD_FRAMERECT_BOTTOM);
|
||||
top = std::max(top - 3, r.top + WD_FRAMERECT_TOP);
|
||||
GfxFillRect(r.left + WD_FRAMETEXT_LEFT, top, r.right - WD_FRAMETEXT_RIGHT, bottom, _colour_gradient[COLOUR_GREY][7]);
|
||||
int top = (this->order_over < this->selected_order ? y : y + line_height) - WidgetDimensions::scaled.framerect.top;
|
||||
int bottom = std::min(top + 2, ir.bottom);
|
||||
top = std::max(top - 3, ir.top);
|
||||
GfxFillRect(ir.left, top, ir.right, bottom, _colour_gradient[COLOUR_GREY][7]);
|
||||
break;
|
||||
}
|
||||
y += line_height;
|
||||
@@ -1106,7 +1112,7 @@ public:
|
||||
}
|
||||
|
||||
/* Reset counters for drawing the orders. */
|
||||
y = Center(r.top + WD_FRAMERECT_TOP, line_height);
|
||||
y = ir.top;
|
||||
i = this->vscroll->GetPosition();
|
||||
order = this->vehicle->GetOrder(i);
|
||||
}
|
||||
@@ -1116,7 +1122,7 @@ public:
|
||||
/* Don't draw anything if it extends past the end of the window. */
|
||||
if (!this->vscroll->IsVisible(i)) break;
|
||||
|
||||
DrawOrderString(this->vehicle, order, i, y, i == this->selected_order, false, r.left + WD_FRAMETEXT_LEFT, middle, r.right - WD_FRAMETEXT_RIGHT);
|
||||
DrawOrderString(this->vehicle, order, i, y, i == this->selected_order, false, ir.left, middle, ir.right);
|
||||
y += line_height;
|
||||
|
||||
i++;
|
||||
@@ -1125,7 +1131,7 @@ public:
|
||||
|
||||
if (this->vscroll->IsVisible(i)) {
|
||||
StringID str = this->vehicle->IsOrderListShared() ? STR_ORDERS_END_OF_SHARED_ORDERS : STR_ORDERS_END_OF_ORDERS;
|
||||
DrawString(rtl ? r.left + WD_FRAMETEXT_LEFT : middle, rtl ? middle : r.right - WD_FRAMETEXT_RIGHT, y, str, (i == this->selected_order) ? TC_WHITE : TC_BLACK);
|
||||
DrawString(rtl ? ir.left : middle, rtl ? middle : ir.right, y, str, (i == this->selected_order) ? TC_WHITE : TC_BLACK);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1162,7 +1168,7 @@ public:
|
||||
order.index = 0;
|
||||
order.MakeConditional(order_id);
|
||||
|
||||
DoCommandP(this->vehicle->tile, this->vehicle->index + (this->OrderGetSel() << 20), order.Pack(), CMD_INSERT_ORDER | CMD_MSG(STR_ERROR_CAN_T_INSERT_NEW_ORDER));
|
||||
Command<CMD_INSERT_ORDER>::Post(STR_ERROR_CAN_T_INSERT_NEW_ORDER, this->vehicle->tile, this->vehicle->index, this->OrderGetSel(), order);
|
||||
}
|
||||
ResetObjectToPlace();
|
||||
break;
|
||||
@@ -1185,9 +1191,9 @@ public:
|
||||
this->selected_order = -1;
|
||||
} else if (sel == this->selected_order) {
|
||||
if (this->vehicle->type == VEH_TRAIN && sel < this->vehicle->GetNumOrders()) {
|
||||
DoCommandP(this->vehicle->tile, this->vehicle->index + (sel << 20),
|
||||
MOF_STOP_LOCATION | ((this->vehicle->GetOrder(sel)->GetStopLocation() + 1) % OSL_END) << 4,
|
||||
CMD_MODIFY_ORDER | CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER));
|
||||
Command<CMD_MODIFY_ORDER>::Post(STR_ERROR_CAN_T_MODIFY_THIS_ORDER,
|
||||
this->vehicle->tile, this->vehicle->index, sel,
|
||||
MOF_STOP_LOCATION, (this->vehicle->GetOrder(sel)->GetStopLocation() + 1) % OSL_END);
|
||||
}
|
||||
} else {
|
||||
/* Select clicked order */
|
||||
@@ -1334,7 +1340,7 @@ public:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
DoCommandP(this->vehicle->tile, this->vehicle->index + (sel << 20), MOF_COND_VALUE | Clamp(value, 0, 2047) << 4, CMD_MODIFY_ORDER | CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER));
|
||||
Command<CMD_MODIFY_ORDER>::Post(STR_ERROR_CAN_T_MODIFY_THIS_ORDER, this->vehicle->tile, this->vehicle->index, sel, MOF_COND_VALUE, Clamp(value, 0, 2047));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1372,11 +1378,11 @@ public:
|
||||
break;
|
||||
|
||||
case WID_O_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));
|
||||
Command<CMD_MODIFY_ORDER>::Post(STR_ERROR_CAN_T_MODIFY_THIS_ORDER, this->vehicle->tile, this->vehicle->index, this->OrderGetSel(), MOF_COND_VARIABLE, index);
|
||||
break;
|
||||
|
||||
case WID_O_COND_COMPARATOR:
|
||||
DoCommandP(this->vehicle->tile, this->vehicle->index + (this->OrderGetSel() << 20), MOF_COND_COMPARATOR | index << 4, CMD_MODIFY_ORDER | CMD_MSG(STR_ERROR_CAN_T_MODIFY_THIS_ORDER));
|
||||
Command<CMD_MODIFY_ORDER>::Post(STR_ERROR_CAN_T_MODIFY_THIS_ORDER, this->vehicle->tile, this->vehicle->index, this->OrderGetSel(), MOF_COND_COMPARATOR, index);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -1389,7 +1395,7 @@ public:
|
||||
VehicleOrderID to_order = this->GetOrderFromPt(pt.y);
|
||||
|
||||
if (!(from_order == to_order || from_order == INVALID_VEH_ORDER_ID || from_order > this->vehicle->GetNumOrders() || to_order == INVALID_VEH_ORDER_ID || to_order > this->vehicle->GetNumOrders()) &&
|
||||
DoCommandP(this->vehicle->tile, this->vehicle->index, from_order | (to_order << 16), CMD_MOVE_ORDER | CMD_MSG(STR_ERROR_CAN_T_MOVE_THIS_ORDER))) {
|
||||
Command<CMD_MOVE_ORDER>::Post(STR_ERROR_CAN_T_MOVE_THIS_ORDER, this->vehicle->tile, this->vehicle->index, from_order, to_order)) {
|
||||
this->selected_order = -1;
|
||||
this->UpdateButtonState();
|
||||
}
|
||||
@@ -1441,7 +1447,7 @@ public:
|
||||
const Order cmd = GetOrderCmdFromTile(this->vehicle, tile);
|
||||
if (cmd.IsType(OT_NOTHING)) return;
|
||||
|
||||
if (DoCommandP(this->vehicle->tile, this->vehicle->index + (this->OrderGetSel() << 20), cmd.Pack(), CMD_INSERT_ORDER | CMD_MSG(STR_ERROR_CAN_T_INSERT_NEW_ORDER))) {
|
||||
if (Command<CMD_INSERT_ORDER>::Post(STR_ERROR_CAN_T_INSERT_NEW_ORDER, this->vehicle->tile, this->vehicle->index, this->OrderGetSel(), cmd)) {
|
||||
/* With quick goto the Go To button stays active */
|
||||
if (!_settings_client.gui.quick_goto) ResetObjectToPlace();
|
||||
}
|
||||
@@ -1458,14 +1464,48 @@ public:
|
||||
bool share_order = _ctrl_pressed || this->goto_type == OPOS_SHARE;
|
||||
if (this->vehicle->GetNumOrders() != 0 && !share_order) return false;
|
||||
|
||||
if (DoCommandP(this->vehicle->tile, this->vehicle->index | (share_order ? CO_SHARE : CO_COPY) << 30, v->index,
|
||||
share_order ? CMD_CLONE_ORDER | CMD_MSG(STR_ERROR_CAN_T_SHARE_ORDER_LIST) : CMD_CLONE_ORDER | CMD_MSG(STR_ERROR_CAN_T_COPY_ORDER_LIST))) {
|
||||
if (Command<CMD_CLONE_ORDER>::Post(share_order ? STR_ERROR_CAN_T_SHARE_ORDER_LIST : STR_ERROR_CAN_T_COPY_ORDER_LIST,
|
||||
this->vehicle->tile, share_order ? CO_SHARE : CO_COPY, this->vehicle->index, v->index)) {
|
||||
this->selected_order = -1;
|
||||
ResetObjectToPlace();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clones an order list from a vehicle list. If this doesn't make sense (because not all vehicles in the list have the same orders), then it displays an error.
|
||||
* @return This always returns true, which indicates that the contextual action handled the mouse click.
|
||||
* Note that it's correct behaviour to always handle the click even though an error is displayed,
|
||||
* because users aren't going to expect the default action to be performed just because they overlooked that cloning doesn't make sense.
|
||||
*/
|
||||
bool OnVehicleSelect(VehicleList::const_iterator begin, VehicleList::const_iterator end) override
|
||||
{
|
||||
bool share_order = _ctrl_pressed || this->goto_type == OPOS_SHARE;
|
||||
if (this->vehicle->GetNumOrders() != 0 && !share_order) return false;
|
||||
|
||||
if (!share_order) {
|
||||
/* If CTRL is not pressed: If all the vehicles in this list have the same orders, then copy orders */
|
||||
if (AllEqual(begin, end, [](const Vehicle *v1, const Vehicle *v2) {
|
||||
return VehiclesHaveSameOrderList(v1, v2);
|
||||
})) {
|
||||
OnVehicleSelect(*begin);
|
||||
} else {
|
||||
ShowErrorMessage(STR_ERROR_CAN_T_COPY_ORDER_LIST, STR_ERROR_CAN_T_COPY_ORDER_VEHICLE_LIST, WL_INFO);
|
||||
}
|
||||
} else {
|
||||
/* If CTRL is pressed: If all the vehicles in this list share orders, then copy orders */
|
||||
if (AllEqual(begin, end, [](const Vehicle *v1, const Vehicle *v2) {
|
||||
return v1->FirstShared() == v2->FirstShared();
|
||||
})) {
|
||||
OnVehicleSelect(*begin);
|
||||
} else {
|
||||
ShowErrorMessage(STR_ERROR_CAN_T_SHARE_ORDER_LIST, STR_ERROR_CAN_T_SHARE_ORDER_VEHICLE_LIST, WL_INFO);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void OnPlaceObjectAbort() override
|
||||
{
|
||||
this->goto_type = OPOS_NONE;
|
||||
|
||||
Reference in New Issue
Block a user