Allow changing colour of orders in order list and timetable windows

pull/507/head
Jonathan G Rennison 1 year ago
parent ab98af8dd2
commit 3b6f7c09ad

@ -19,6 +19,7 @@
#include "vehicle_type.h"
#include "date_type.h"
#include "schdispatch.h"
#include "gfx_type.h"
#include "saveload/saveload_common.h"
#include <memory>
@ -55,6 +56,7 @@ struct OrderExtraInfo {
uint32 xdata = 0; ///< Extra arbitrary data
uint16 dispatch_index = 0; ///< Scheduled dispatch index + 1
uint8 xflags = 0; ///< Extra flags
uint8 colour = 0; ///< Order colour + 1
};
namespace upstream_sl {
@ -574,6 +576,22 @@ public:
return this->extra != nullptr && this->extra->dispatch_index > 0 && (!require_wait_timetabled || this->IsWaitTimetabled());
}
/** Get order colour */
inline Colours GetColour() const
{
uint8 value = this->extra != nullptr ? this->extra->colour : 0;
return (Colours)(value - 1);
}
/** Set order colour */
inline void SetColour(Colours colour)
{
if (colour != this->GetColour()) {
this->CheckExtraInfoAlloced();
this->extra->colour = ((uint8)colour) + 1;
}
}
void AssignOrder(const Order &other);
bool Equals(const Order &other) const;

@ -1794,33 +1794,37 @@ CommandCost CmdModifyOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
Order *order = v->GetOrder(sel_ord);
assert(order != nullptr);
switch (order->GetType()) {
case OT_GOTO_STATION:
if (mof != MOF_NON_STOP && mof != MOF_STOP_LOCATION && mof != MOF_UNLOAD && mof != MOF_LOAD && mof != MOF_CARGO_TYPE_UNLOAD && mof != MOF_CARGO_TYPE_LOAD && mof != MOF_RV_TRAVEL_DIR) return CMD_ERROR;
break;
if (mof == MOF_COLOUR) {
if (order->GetType() == OT_IMPLICIT) return CMD_ERROR;
} else {
switch (order->GetType()) {
case OT_GOTO_STATION:
if (mof != MOF_NON_STOP && mof != MOF_STOP_LOCATION && mof != MOF_UNLOAD && mof != MOF_LOAD && mof != MOF_CARGO_TYPE_UNLOAD && mof != MOF_CARGO_TYPE_LOAD && mof != MOF_RV_TRAVEL_DIR) return CMD_ERROR;
break;
case OT_GOTO_DEPOT:
if (mof != MOF_NON_STOP && mof != MOF_DEPOT_ACTION) return CMD_ERROR;
break;
case OT_GOTO_DEPOT:
if (mof != MOF_NON_STOP && mof != MOF_DEPOT_ACTION) return CMD_ERROR;
break;
case OT_GOTO_WAYPOINT:
if (mof != MOF_NON_STOP && mof != MOF_WAYPOINT_FLAGS && mof != MOF_RV_TRAVEL_DIR) return CMD_ERROR;
break;
case OT_GOTO_WAYPOINT:
if (mof != MOF_NON_STOP && mof != MOF_WAYPOINT_FLAGS && mof != MOF_RV_TRAVEL_DIR) return CMD_ERROR;
break;
case OT_CONDITIONAL:
if (mof != MOF_COND_VARIABLE && mof != MOF_COND_COMPARATOR && mof != MOF_COND_VALUE && mof != MOF_COND_VALUE_2 && mof != MOF_COND_VALUE_3 && mof != MOF_COND_DESTINATION) return CMD_ERROR;
break;
case OT_CONDITIONAL:
if (mof != MOF_COND_VARIABLE && mof != MOF_COND_COMPARATOR && mof != MOF_COND_VALUE && mof != MOF_COND_VALUE_2 && mof != MOF_COND_VALUE_3 && mof != MOF_COND_DESTINATION) return CMD_ERROR;
break;
case OT_RELEASE_SLOT:
if (mof != MOF_SLOT) return CMD_ERROR;
break;
case OT_RELEASE_SLOT:
if (mof != MOF_SLOT) return CMD_ERROR;
break;
case OT_COUNTER:
if (mof != MOF_COUNTER_ID && mof != MOF_COUNTER_OP && mof != MOF_COUNTER_VALUE) return CMD_ERROR;
break;
case OT_COUNTER:
if (mof != MOF_COUNTER_ID && mof != MOF_COUNTER_OP && mof != MOF_COUNTER_VALUE) return CMD_ERROR;
break;
default:
return CMD_ERROR;
default:
return CMD_ERROR;
}
}
switch (mof) {
@ -2017,6 +2021,12 @@ CommandCost CmdModifyOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
case MOF_COUNTER_VALUE:
break;
case MOF_COLOUR:
if (data >= COLOUR_END && data != INVALID_COLOUR) {
return CMD_ERROR;
}
break;
}
if (flags & DC_EXEC) {
@ -2258,6 +2268,10 @@ CommandCost CmdModifyOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3
order->GetXDataRef() = data;
break;
case MOF_COLOUR:
order->SetColour((Colours)data);
break;
default: NOT_REACHED();
}

@ -645,12 +645,6 @@ static const StringID _order_manage_list_dropdown[] = {
INVALID_STRING_ID
};
static const StringID _order_manage_dropdown[] = {
STR_ORDER_DUPLICATE_ORDER,
STR_ORDER_CHANGE_JUMP_TARGET,
INVALID_STRING_ID
};
/** Variables for conditional orders; this defines the order of appearance in the dropdown box */
static const OrderConditionVariable _order_conditional_variable[] = {
OCV_LOAD_PERCENTAGE,
@ -858,8 +852,13 @@ void DrawOrderString(const Vehicle *v, const Order *order, int order_index, int
TextColour colour = TC_BLACK;
if (order->IsType(OT_IMPLICIT)) {
colour = (selected ? TC_SILVER : TC_GREY) | TC_NO_SHADE;
} else if (selected) {
colour = TC_WHITE;
} else {
if (selected) {
colour = TC_WHITE;
} else {
Colours order_colour = order->GetColour();
if (order_colour != INVALID_COLOUR) colour = TC_IS_PALETTE_COLOUR | (TextColour)_colour_value[order_colour];
}
}
SetDParam(0, order_index + 1);
@ -2599,10 +2598,22 @@ public:
const Order *order = this->vehicle->GetOrder(sel);
if (order == nullptr) break;
uint hidden_mask = 0;
if (!order->IsType(OT_CONDITIONAL)) hidden_mask |= 2;
ShowDropDownMenu(this, _order_manage_dropdown, -1, widget, 0, hidden_mask, UINT_MAX, DDSF_LOST_FOCUS);
DropDownList list;
list.emplace_back(new DropDownListStringItem(STR_ORDER_DUPLICATE_ORDER, 0, false));
if (order->IsType(OT_CONDITIONAL)) list.emplace_back(new DropDownListStringItem(STR_ORDER_CHANGE_JUMP_TARGET, 1, false));
if (!order->IsType(OT_IMPLICIT)) {
list.emplace_back(new DropDownListItem(-1, false));
list.emplace_back(new DropDownListStringItem(STR_COLOUR_DEFAULT, 0x100 + INVALID_COLOUR, false));
auto add_colour = [&](Colours colour) {
list.emplace_back(new DropDownListStringItem(STR_COLOUR_DARK_BLUE + colour, 0x100 + colour, false));
};
add_colour(COLOUR_YELLOW);
add_colour(COLOUR_LIGHT_BLUE);
add_colour(COLOUR_GREEN);
add_colour(COLOUR_ORANGE);
add_colour(COLOUR_PINK);
}
ShowDropDownList(this, std::move(list), 0x100 + order->GetColour(), widget, 0, true, false, DDSF_LOST_FOCUS);
break;
}
@ -3097,6 +3108,10 @@ public:
ResetObjectToPlace();
break;
}
if (index >= 0x100 && index <= 0x100 + INVALID_COLOUR) {
this->ModifyOrder(this->OrderGetSel(), MOF_COLOUR | (index & 0xFF) << 8);
break;
}
switch (index) {
case 0:
DoCommandP(this->vehicle->tile, this->vehicle->index, this->OrderGetSel(), CMD_DUPLICATE_ORDER | CMD_MSG(STR_ERROR_CAN_T_INSERT_NEW_ORDER));

@ -202,6 +202,7 @@ enum ModifyOrderFlags {
MOF_COUNTER_ID, ///< Change the counter ID
MOF_COUNTER_OP, ///< Change the counter operation
MOF_COUNTER_VALUE, ///< Change the counter value
MOF_COLOUR, ///< Change the colour value
MOF_END
};
template <> struct EnumPropsT<ModifyOrderFlags> : MakeEnumPropsT<ModifyOrderFlags, byte, MOF_NON_STOP, MOF_END, MOF_END, 8> {};

@ -122,7 +122,7 @@ const SlxiSubChunkInfo _sl_xv_sub_chunk_infos[] = {
{ XSLFI_TRAIN_FLAGS_EXTRA, XSCF_NULL, 1, 1, "train_flags_extra", nullptr, nullptr, nullptr },
{ XSLFI_VEHICLE_FLAGS_EXTRA, XSCF_NULL, 1, 1, "veh_flags_extra", nullptr, nullptr, nullptr },
{ XSLFI_TRAIN_THROUGH_LOAD, XSCF_NULL, 2, 2, "train_through_load", nullptr, nullptr, nullptr },
{ XSLFI_ORDER_EXTRA_DATA, XSCF_NULL, 1, 1, "order_extra_data", nullptr, nullptr, nullptr },
{ XSLFI_ORDER_EXTRA_DATA, XSCF_NULL, 2, 2, "order_extra_data", nullptr, nullptr, nullptr },
{ XSLFI_WHOLE_MAP_CHUNK, XSCF_NULL, 2, 2, "whole_map_chunk", nullptr, nullptr, "WMAP" },
{ XSLFI_ST_LAST_VEH_TYPE, XSCF_NULL, 1, 1, "station_last_veh_type", nullptr, nullptr, nullptr },
{ XSLFI_SELL_AT_DEPOT_ORDER, XSCF_NULL, 1, 1, "sell_at_depot_order", nullptr, nullptr, nullptr },

@ -218,6 +218,7 @@ const SaveLoadTable GetOrderExtraInfoDescription()
SLE_CONDVAR_X(OrderExtraInfo, xflags, SLE_UINT8, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_TIMETABLE_EXTRA)),
SLE_CONDVAR_X(OrderExtraInfo, xdata, SLE_UINT32, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_ORDER_EXTRA_DATA)),
SLE_CONDVAR_X(OrderExtraInfo, dispatch_index, SLE_UINT16, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_SCHEDULED_DISPATCH, 3)),
SLE_CONDVAR_X(OrderExtraInfo, colour, SLE_UINT8, SL_MIN_VERSION, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_ORDER_EXTRA_DATA, 2)),
};
return _order_extra_info_desc;

Loading…
Cancel
Save