Merge branch 'tracerestrict' into tracerestrict-sx
This commit is contained in:
@@ -36,11 +36,9 @@
|
||||
#include "cargotype.h"
|
||||
#include "sortlist_type.h"
|
||||
#include "group.h"
|
||||
#include "unit_conversion.h"
|
||||
#include "table/sprites.h"
|
||||
|
||||
extern uint ConvertSpeedToDisplaySpeed(uint speed);
|
||||
extern uint ConvertDisplaySpeedToSpeed(uint speed);
|
||||
|
||||
/** Widget IDs */
|
||||
enum TraceRestrictWindowWidgets {
|
||||
TR_WIDGET_CAPTION,
|
||||
@@ -240,10 +238,27 @@ static StringID GetDropDownStringByValue(const TraceRestrictDropDownListSet *lis
|
||||
return list_set->string_array[GetDropDownListIndexByValue(list_set, value, false)];
|
||||
}
|
||||
|
||||
typedef uint TraceRestrictGuiItemType;
|
||||
|
||||
static TraceRestrictGuiItemType GetItemGuiType(TraceRestrictItem item)
|
||||
{
|
||||
TraceRestrictItemType type = GetTraceRestrictType(item);
|
||||
if (IsTraceRestrictTypeAuxSubtype(type)) {
|
||||
return type | (GetTraceRestrictAuxField(item) << 16);
|
||||
} else {
|
||||
return type;
|
||||
}
|
||||
}
|
||||
|
||||
static TraceRestrictItemType ItemTypeFromGuiType(TraceRestrictGuiItemType type)
|
||||
{
|
||||
return static_cast<TraceRestrictItemType>(type & 0xFFFF);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the appropriate type dropdown TraceRestrictDropDownListSet for the given item type @p type
|
||||
*/
|
||||
static const TraceRestrictDropDownListSet *GetTypeDropDownListSet(TraceRestrictItemType type)
|
||||
static const TraceRestrictDropDownListSet *GetTypeDropDownListSet(TraceRestrictGuiItemType type)
|
||||
{
|
||||
static const StringID str_action[] = {
|
||||
STR_TRACE_RESTRICT_PF_DENY,
|
||||
@@ -272,6 +287,11 @@ static const TraceRestrictDropDownListSet *GetTypeDropDownListSet(TraceRestrictI
|
||||
STR_TRACE_RESTRICT_VARIABLE_ENTRY_DIRECTION,
|
||||
STR_TRACE_RESTRICT_VARIABLE_PBS_ENTRY_SIGNAL,
|
||||
STR_TRACE_RESTRICT_VARIABLE_TRAIN_GROUP,
|
||||
STR_TRACE_RESTRICT_VARIABLE_TRAIN_WEIGHT,
|
||||
STR_TRACE_RESTRICT_VARIABLE_TRAIN_POWER,
|
||||
STR_TRACE_RESTRICT_VARIABLE_TRAIN_MAX_TE,
|
||||
STR_TRACE_RESTRICT_VARIABLE_TRAIN_POWER_WEIGHT_RATIO,
|
||||
STR_TRACE_RESTRICT_VARIABLE_TRAIN_MAX_TE_WEIGHT_RATIO,
|
||||
STR_TRACE_RESTRICT_VARIABLE_UNDEFINED,
|
||||
INVALID_STRING_ID,
|
||||
};
|
||||
@@ -285,13 +305,18 @@ static const TraceRestrictDropDownListSet *GetTypeDropDownListSet(TraceRestrictI
|
||||
TRIT_COND_ENTRY_DIRECTION,
|
||||
TRIT_COND_PBS_ENTRY_SIGNAL,
|
||||
TRIT_COND_TRAIN_GROUP,
|
||||
TRIT_COND_PHYS_PROP | (TRPPCAF_WEIGHT << 16),
|
||||
TRIT_COND_PHYS_PROP | (TRPPCAF_POWER << 16),
|
||||
TRIT_COND_PHYS_PROP | (TRPPCAF_MAX_TE << 16),
|
||||
TRIT_COND_PHYS_RATIO | (TRPPRCAF_POWER_WEIGHT << 16),
|
||||
TRIT_COND_PHYS_RATIO | (TRPPRCAF_MAX_TE_WEIGHT << 16),
|
||||
TRIT_COND_UNDEFINED,
|
||||
};
|
||||
static const TraceRestrictDropDownListSet set_cond = {
|
||||
str_cond, val_cond,
|
||||
};
|
||||
|
||||
return IsTraceRestrictTypeConditional(type) ? &set_cond : &set_action;
|
||||
return IsTraceRestrictTypeConditional(ItemTypeFromGuiType(type)) ? &set_cond : &set_action;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -378,8 +403,9 @@ static StringID GetCargoStringByID(CargoID cargo)
|
||||
/**
|
||||
* Get the StringID for a given item type @p type
|
||||
*/
|
||||
static StringID GetTypeString(TraceRestrictItemType type)
|
||||
static StringID GetTypeString(TraceRestrictItem item)
|
||||
{
|
||||
TraceRestrictGuiItemType type = GetItemGuiType(item);
|
||||
return GetDropDownStringByValue(GetTypeDropDownListSet(type), type);
|
||||
}
|
||||
|
||||
@@ -446,6 +472,11 @@ static bool IsIntegerValueType(TraceRestrictValueType type)
|
||||
switch (type) {
|
||||
case TRVT_INT:
|
||||
case TRVT_SPEED:
|
||||
case TRVT_WEIGHT:
|
||||
case TRVT_POWER:
|
||||
case TRVT_FORCE:
|
||||
case TRVT_POWER_WEIGHT_RATIO:
|
||||
case TRVT_FORCE_WEIGHT_RATIO:
|
||||
return true;
|
||||
|
||||
default:
|
||||
@@ -467,6 +498,36 @@ static uint ConvertIntegerValue(TraceRestrictValueType type, uint in, bool to_di
|
||||
? ConvertSpeedToDisplaySpeed(in) * 10 / 16
|
||||
: ConvertDisplaySpeedToSpeed(in) * 16 / 10;
|
||||
|
||||
case TRVT_WEIGHT:
|
||||
return to_display
|
||||
? ConvertWeightToDisplayWeight(in)
|
||||
: ConvertDisplayWeightToWeight(in);
|
||||
break;
|
||||
|
||||
case TRVT_POWER:
|
||||
return to_display
|
||||
? ConvertPowerToDisplayPower(in)
|
||||
: ConvertDisplayPowerToPower(in);
|
||||
break;
|
||||
|
||||
case TRVT_FORCE:
|
||||
return to_display
|
||||
? ConvertForceToDisplayForce(in)
|
||||
: ConvertDisplayForceToForce(in);
|
||||
break;
|
||||
|
||||
case TRVT_POWER_WEIGHT_RATIO:
|
||||
return to_display
|
||||
? ConvertPowerToDisplayPower(in) * 10
|
||||
: ConvertDisplayPowerToPower(in) / 10;
|
||||
break;
|
||||
|
||||
case TRVT_FORCE_WEIGHT_RATIO:
|
||||
return to_display
|
||||
? ConvertForceToDisplayForce(in) * 10
|
||||
: ConvertDisplayForceToForce(in) / 10;
|
||||
break;
|
||||
|
||||
case TRVT_PF_PENALTY:
|
||||
return in;
|
||||
|
||||
@@ -549,7 +610,7 @@ static void DrawInstructionStringConditionalCommon(TraceRestrictItem item, const
|
||||
{
|
||||
assert(GetTraceRestrictCondFlags(item) <= TRCF_OR);
|
||||
SetDParam(0, _program_cond_type[GetTraceRestrictCondFlags(item)]);
|
||||
SetDParam(1, GetTypeString(GetTraceRestrictType(item)));
|
||||
SetDParam(1, GetTypeString(item));
|
||||
SetDParam(2, GetDropDownStringByValue(GetCondOpDropDownListSet(properties), GetTraceRestrictCondOp(item)));
|
||||
}
|
||||
|
||||
@@ -694,6 +755,35 @@ static void DrawInstructionString(const TraceRestrictProgram *prog, TraceRestric
|
||||
break;
|
||||
}
|
||||
|
||||
case TRVT_WEIGHT:
|
||||
instruction_string = STR_TRACE_RESTRICT_CONDITIONAL_COMPARE_WEIGHT;
|
||||
DrawInstructionStringConditionalIntegerCommon(item, properties);
|
||||
break;
|
||||
|
||||
case TRVT_POWER:
|
||||
instruction_string = STR_TRACE_RESTRICT_CONDITIONAL_COMPARE_POWER;
|
||||
DrawInstructionStringConditionalIntegerCommon(item, properties);
|
||||
break;
|
||||
|
||||
case TRVT_FORCE:
|
||||
instruction_string = STR_TRACE_RESTRICT_CONDITIONAL_COMPARE_FORCE;
|
||||
DrawInstructionStringConditionalIntegerCommon(item, properties);
|
||||
break;
|
||||
|
||||
case TRVT_POWER_WEIGHT_RATIO:
|
||||
instruction_string = STR_TRACE_RESTRICT_CONDITIONAL_COMPARE_POWER_WEIGHT_RATIO;
|
||||
DrawInstructionStringConditionalIntegerCommon(item, properties);
|
||||
SetDParam(4, STR_UNITS_WEIGHT_LONG_METRIC);
|
||||
SetDParam(5, 100);
|
||||
break;
|
||||
|
||||
case TRVT_FORCE_WEIGHT_RATIO:
|
||||
instruction_string = STR_TRACE_RESTRICT_CONDITIONAL_COMPARE_FORCE_WEIGHT_RATIO;
|
||||
DrawInstructionStringConditionalIntegerCommon(item, properties);
|
||||
SetDParam(4, STR_UNITS_WEIGHT_LONG_METRIC);
|
||||
SetDParam(5, 100);
|
||||
break;
|
||||
|
||||
default:
|
||||
NOT_REACHED();
|
||||
break;
|
||||
@@ -904,7 +994,7 @@ public:
|
||||
case TR_WIDGET_TYPE_COND:
|
||||
case TR_WIDGET_TYPE_NONCOND: {
|
||||
TraceRestrictItem item = this->GetSelected();
|
||||
TraceRestrictItemType type = GetTraceRestrictType(item);
|
||||
TraceRestrictGuiItemType type = GetItemGuiType(item);
|
||||
|
||||
if (type != TRIT_NULL) {
|
||||
this->ShowDropDownListWithValue(GetTypeDropDownListSet(type), type, false, widget, 0, 0, 0);
|
||||
@@ -1083,11 +1173,8 @@ public:
|
||||
|
||||
case TR_WIDGET_TYPE_COND:
|
||||
case TR_WIDGET_TYPE_NONCOND: {
|
||||
SetTraceRestrictTypeAndNormalise(item, static_cast<TraceRestrictItemType>(value));
|
||||
if (GetTraceRestrictType(item) == TRIT_COND_LAST_STATION && GetTraceRestrictAuxField(item) != TROCAF_STATION) {
|
||||
// if changing type from another order type to last visited station, reset value if not currently a station
|
||||
SetTraceRestrictValueDefault(item, TRVT_ORDER);
|
||||
}
|
||||
SetTraceRestrictTypeAndNormalise(item, static_cast<TraceRestrictItemType>(value & 0xFFFF), value >> 16);
|
||||
|
||||
TraceRestrictDoCommandP(this->tile, this->track, TRDCT_MODIFY_ITEM, this->selected_instruction - 1, item, STR_TRACE_RESTRICT_ERROR_CAN_T_MODIFY_ITEM);
|
||||
break;
|
||||
}
|
||||
@@ -1649,7 +1736,7 @@ private:
|
||||
this->EnableWidget(type_widget);
|
||||
|
||||
this->GetWidget<NWidgetCore>(type_widget)->widget_data =
|
||||
GetTypeString(GetTraceRestrictType(item));
|
||||
GetTypeString(item);
|
||||
|
||||
if (properties.cond_type == TRCOT_BINARY || properties.cond_type == TRCOT_ALL) {
|
||||
middle_sel->SetDisplayedPlane(DPM_COMPARATOR);
|
||||
|
Reference in New Issue
Block a user