Merge remote-tracking branch 'upstream/master'
This commit is contained in:
@@ -35,6 +35,7 @@
|
||||
#include "error.h"
|
||||
#include "order_cmd.h"
|
||||
#include "company_cmd.h"
|
||||
#include "core/string_consumer.hpp"
|
||||
|
||||
#include "widgets/order_widget.h"
|
||||
|
||||
@@ -42,6 +43,7 @@
|
||||
|
||||
#include "citymania/cm_commands.hpp"
|
||||
#include "citymania/cm_hotkeys.hpp"
|
||||
#include "citymania/cm_station_gui.hpp"
|
||||
|
||||
#include "safeguards.h"
|
||||
|
||||
@@ -119,14 +121,14 @@ static const StringID _station_load_types[][5][5] = {
|
||||
}
|
||||
};
|
||||
|
||||
static const StringID _order_non_stop_drowdown[] = {
|
||||
static const StringID _order_non_stop_dropdown[] = {
|
||||
STR_ORDER_GO_TO,
|
||||
STR_ORDER_GO_NON_STOP_TO,
|
||||
STR_ORDER_GO_VIA,
|
||||
STR_ORDER_GO_NON_STOP_VIA,
|
||||
};
|
||||
|
||||
static const StringID _order_full_load_drowdown[] = {
|
||||
static const StringID _order_full_load_dropdown[] = {
|
||||
STR_ORDER_DROP_LOAD_IF_POSSIBLE,
|
||||
STR_EMPTY,
|
||||
STR_ORDER_DROP_FULL_LOAD_ALL,
|
||||
@@ -134,7 +136,7 @@ static const StringID _order_full_load_drowdown[] = {
|
||||
STR_ORDER_DROP_NO_LOADING,
|
||||
};
|
||||
|
||||
static const StringID _order_unload_drowdown[] = {
|
||||
static const StringID _order_unload_dropdown[] = {
|
||||
STR_ORDER_DROP_UNLOAD_IF_ACCEPTED,
|
||||
STR_ORDER_DROP_UNLOAD,
|
||||
STR_ORDER_DROP_TRANSFER,
|
||||
@@ -304,7 +306,7 @@ static StringID GetOrderGoToString(const Order &order)
|
||||
* @param middle X position between order index and order text
|
||||
* @param right Right border for text drawing
|
||||
*/
|
||||
void DrawOrderString(const Vehicle *v, const Order *order, int order_index, int y, bool selected, bool timetable, int left, int middle, int right)
|
||||
void DrawOrderString(const Vehicle *v, const Order *order, VehicleOrderID order_index, int y, bool selected, bool timetable, int left, int middle, int right)
|
||||
{
|
||||
bool rtl = _current_text_dir == TD_RTL;
|
||||
|
||||
@@ -434,26 +436,16 @@ void DrawOrderString(const Vehicle *v, const Order *order, int order_index, int
|
||||
|
||||
/* Check range for aircraft. */
|
||||
if (v->type == VEH_AIRCRAFT && Aircraft::From(v)->GetRange() > 0 && order->IsGotoOrder()) {
|
||||
const Order *next = order->next != nullptr ? order->next : v->GetFirstOrder();
|
||||
if (GetOrderDistance(order, next, v) > Aircraft::From(v)->acache.cached_max_range_sqr) {
|
||||
if (GetOrderDistance(order_index, v->orders->GetNext(order_index), v) > Aircraft::From(v)->acache.cached_max_range_sqr) {
|
||||
line += GetString(STR_ORDER_OUT_OF_RANGE);
|
||||
}
|
||||
}
|
||||
|
||||
DrawString(rtl ? left : middle, rtl ? middle : right, y, line, colour);
|
||||
|
||||
uint order_dist_sq = 0;
|
||||
uint order_dist_mh = 0;
|
||||
const Order *next2 = order->next != NULL ? order->next : v->GetFirstOrder();
|
||||
TileIndex prev_tile = order->GetLocation(v, true);
|
||||
TileIndex cur_tile = next2->GetLocation(v, true);
|
||||
if (prev_tile != INVALID_TILE && cur_tile != INVALID_TILE){
|
||||
order_dist_sq = IntSqrt(DistanceSquare(prev_tile, cur_tile));
|
||||
order_dist_mh = DistanceManhattan(prev_tile, cur_tile);
|
||||
}
|
||||
|
||||
auto dists = citymania::GetOrderDistances(order_index, v->orders->GetNext(order_index), v);
|
||||
// FIXME rtl
|
||||
DrawString(middle, right, y, GetString(CM_STR_ORDER_DIST, order_dist_sq, order_dist_mh), TC_WHITE, SA_RIGHT);
|
||||
DrawString(middle, right, y, GetString(CM_STR_ORDER_DIST, IntSqrt(dists.first), dists.second), TC_WHITE, SA_RIGHT);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -464,9 +456,7 @@ void DrawOrderString(const Vehicle *v, const Order *order, int order_index, int
|
||||
*/
|
||||
static std::pair<Order, FeederOrderMod> GetOrderCmdFromTile(const Vehicle *v, TileIndex tile)
|
||||
{
|
||||
/* Override the index as it is not coming from a pool, so would not be initialised correctly. */
|
||||
Order order;
|
||||
order.index = OrderID::Begin();
|
||||
Order order{};
|
||||
|
||||
/* check depot first */
|
||||
if (IsDepotTypeTile(tile, (TransportType)(uint)v->type) && IsTileOwner(tile, _local_company)) {
|
||||
@@ -793,9 +783,7 @@ private:
|
||||
*/
|
||||
void OrderClick_NearestDepot()
|
||||
{
|
||||
Order order;
|
||||
order.next = nullptr;
|
||||
order.index = OrderID::Begin();
|
||||
Order order{};
|
||||
order.MakeGoToDepot(DepotID::Invalid(), 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);
|
||||
@@ -964,10 +952,7 @@ public:
|
||||
|
||||
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;
|
||||
for (const Order *order : v->Orders()) {
|
||||
if (order->IsType(OT_GOTO_STATION)) station_orders++;
|
||||
}
|
||||
int station_orders = std::ranges::count_if(v->Orders(), [](const Order &order) { return order.IsType(OT_GOTO_STATION); });
|
||||
|
||||
if (station_orders < 2) this->OrderClick_Goto(OPOS_GOTO);
|
||||
}
|
||||
@@ -978,7 +963,7 @@ public:
|
||||
{
|
||||
switch (widget) {
|
||||
case WID_O_ORDER_LIST:
|
||||
resize.height = GetCharacterHeight(FS_NORMAL);
|
||||
fill.height = resize.height = GetCharacterHeight(FS_NORMAL);
|
||||
size.height = 6 * resize.height + padding.height;
|
||||
break;
|
||||
|
||||
@@ -1262,11 +1247,12 @@ public:
|
||||
int y = ir.top;
|
||||
int line_height = this->GetWidget<NWidgetBase>(WID_O_ORDER_LIST)->resize_y;
|
||||
|
||||
int i = this->vscroll->GetPosition();
|
||||
const Order *order = this->vehicle->GetOrder(i);
|
||||
VehicleOrderID i = this->vscroll->GetPosition();
|
||||
VehicleOrderID num_orders = this->vehicle->GetNumOrders();
|
||||
|
||||
/* First draw the highlighting underground if it exists. */
|
||||
if (this->order_over != INVALID_VEH_ORDER_ID) {
|
||||
while (order != nullptr) {
|
||||
while (i < num_orders) {
|
||||
/* Don't draw anything if it extends past the end of the window. */
|
||||
if (!this->vscroll->IsVisible(i)) break;
|
||||
|
||||
@@ -1281,25 +1267,22 @@ public:
|
||||
y += line_height;
|
||||
|
||||
i++;
|
||||
order = order->next;
|
||||
}
|
||||
|
||||
/* Reset counters for drawing the orders. */
|
||||
y = ir.top;
|
||||
i = this->vscroll->GetPosition();
|
||||
order = this->vehicle->GetOrder(i);
|
||||
}
|
||||
|
||||
/* Draw the orders. */
|
||||
while (order != nullptr) {
|
||||
while (i < num_orders) {
|
||||
/* 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, ir.left, middle, ir.right);
|
||||
DrawOrderString(this->vehicle, this->vehicle->GetOrder(i), i, y, i == this->selected_order, false, ir.left, middle, ir.right);
|
||||
y += line_height;
|
||||
|
||||
i++;
|
||||
order = order->next;
|
||||
}
|
||||
|
||||
if (this->vscroll->IsVisible(i)) {
|
||||
@@ -1351,9 +1334,7 @@ public:
|
||||
if (this->goto_type == OPOS_CONDITIONAL) {
|
||||
VehicleOrderID order_id = this->GetOrderFromPt(_cursor.pos.y - this->top);
|
||||
if (order_id != INVALID_VEH_ORDER_ID) {
|
||||
Order order;
|
||||
order.next = nullptr;
|
||||
order.index = OrderID::Begin();
|
||||
Order order{};
|
||||
order.MakeConditional(order_id);
|
||||
|
||||
Command<CMD_INSERT_ORDER>::Post(STR_ERROR_CAN_T_INSERT_NEW_ORDER, this->vehicle->tile, this->vehicle->index, this->OrderGetSel(), order);
|
||||
@@ -1376,8 +1357,8 @@ public:
|
||||
if (sel == INVALID_VEH_ORDER_ID || this->vehicle->owner != _local_company) {
|
||||
/* Deselect clicked order */
|
||||
this->selected_order = -1;
|
||||
} else if (sel == this->selected_order) {
|
||||
if (click_count > 1 && this->vehicle->type == VEH_TRAIN && sel < this->vehicle->GetNumOrders()) {
|
||||
} else if (sel == this->selected_order && click_count > 1) {
|
||||
if (this->vehicle->type == VEH_TRAIN && sel < this->vehicle->GetNumOrders()) {
|
||||
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);
|
||||
@@ -1414,7 +1395,7 @@ public:
|
||||
} else {
|
||||
const Order *o = this->vehicle->GetOrder(this->OrderGetSel());
|
||||
assert(o != nullptr);
|
||||
ShowDropDownMenu(this, _order_non_stop_drowdown, o->GetNonStopType(), WID_O_NON_STOP, 0,
|
||||
ShowDropDownMenu(this, _order_non_stop_dropdown, o->GetNonStopType(), WID_O_NON_STOP, 0,
|
||||
o->IsType(OT_GOTO_STATION) ? 0 : (o->IsType(OT_GOTO_WAYPOINT) ? 3 : 12));
|
||||
}
|
||||
break;
|
||||
@@ -1443,7 +1424,7 @@ public:
|
||||
if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
|
||||
this->OrderClick_FullLoad(OLF_FULL_LOAD_ANY, true);
|
||||
} else {
|
||||
ShowDropDownMenu(this, _order_full_load_drowdown, this->vehicle->GetOrder(this->OrderGetSel())->GetLoadType(), WID_O_FULL_LOAD, 0, 2);
|
||||
ShowDropDownMenu(this, _order_full_load_dropdown, this->vehicle->GetOrder(this->OrderGetSel())->GetLoadType(), WID_O_FULL_LOAD, 0, 2);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -1451,7 +1432,7 @@ public:
|
||||
if (this->GetWidget<NWidgetLeaf>(widget)->ButtonHit(pt)) {
|
||||
this->OrderClick_Unload(OUFB_UNLOAD, true);
|
||||
} else {
|
||||
ShowDropDownMenu(this, _order_unload_drowdown, this->vehicle->GetOrder(this->OrderGetSel())->GetUnloadType(), WID_O_UNLOAD, 0, 8);
|
||||
ShowDropDownMenu(this, _order_unload_dropdown, this->vehicle->GetOrder(this->OrderGetSel())->GetUnloadType(), WID_O_UNLOAD, 0, 8);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -1511,25 +1492,26 @@ public:
|
||||
if (!str.has_value() || str->empty()) return;
|
||||
|
||||
VehicleOrderID sel = this->OrderGetSel();
|
||||
uint value = atoi(str->c_str());
|
||||
auto value = ParseInteger(*str, 10, true);
|
||||
if (!value.has_value()) return;
|
||||
|
||||
switch (this->vehicle->GetOrder(sel)->GetConditionVariable()) {
|
||||
case OCV_MAX_SPEED:
|
||||
value = ConvertDisplaySpeedToSpeed(value, this->vehicle->type);
|
||||
value = ConvertDisplaySpeedToSpeed(*value, this->vehicle->type);
|
||||
break;
|
||||
|
||||
case OCV_RELIABILITY:
|
||||
case OCV_LOAD_PERCENTAGE:
|
||||
value = Clamp(value, 0, 100);
|
||||
value = Clamp(*value, 0, 100);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
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));
|
||||
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));
|
||||
}
|
||||
|
||||
void OnDropdownSelect(WidgetID widget, int index) override
|
||||
void OnDropdownSelect(WidgetID widget, int index, int) override
|
||||
{
|
||||
switch (widget) {
|
||||
case WID_O_NON_STOP:
|
||||
@@ -1965,7 +1947,7 @@ void ShowOrdersWindow(const Vehicle *v)
|
||||
/* Using a different WindowDescs for _local_company causes problems.
|
||||
* Due to this we have to close order windows in ChangeWindowOwner/CloseCompanyWindows,
|
||||
* because we cannot change switch the WindowDescs and keeping the old WindowDesc results
|
||||
* in crashed due to missing widges.
|
||||
* in crashed due to missing widget.
|
||||
* TODO Rewrite the order GUI to not use different WindowDescs.
|
||||
*/
|
||||
if (v->owner != _local_company) {
|
||||
|
||||
Reference in New Issue
Block a user