Initial implementation of tracerestrict speed restriction feature

This commit is contained in:
Jonathan G Rennison
2019-12-05 18:34:05 +00:00
parent 030e8bf762
commit aa8aae9a62
14 changed files with 182 additions and 6 deletions

View File

@@ -2364,6 +2364,7 @@ struct VehicleDetailsWindow : Window {
bool vehicle_group_line_shown;
bool vehicle_weight_ratio_line_shown;
bool vehicle_slots_line_shown;
bool vehicle_speed_restriction_line_shown;
/** Initialize a newly created vehicle details window */
VehicleDetailsWindow(WindowDesc *desc, WindowNumber window_number) : Window(desc)
@@ -2460,6 +2461,12 @@ struct VehicleDetailsWindow : Window {
return HasBit(Train::From(v)->flags, VRF_HAVE_SLOT);
}
bool ShouldShowSpeedRestrictionLine(const Vehicle *v) const
{
if (v->type != VEH_TRAIN) return false;
return Train::From(v)->speed_restriction != 0;
}
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
{
switch (widget) {
@@ -2469,10 +2476,12 @@ struct VehicleDetailsWindow : Window {
this->vehicle_group_line_shown = ShouldShowGroupLine(v);
this->vehicle_weight_ratio_line_shown = ShouldShowWeightRatioLine(v);
this->vehicle_slots_line_shown = ShouldShowSlotsLine(v);
this->vehicle_speed_restriction_line_shown = ShouldShowSpeedRestrictionLine(v);
int lines = 4;
if (this->vehicle_group_line_shown) lines++;
if (this->vehicle_weight_ratio_line_shown) lines++;
if (this->vehicle_slots_line_shown) lines++;
if (this->vehicle_speed_restriction_line_shown) lines++;
size->height = WD_FRAMERECT_TOP + lines * FONT_HEIGHT_NORMAL + WD_FRAMERECT_BOTTOM;
for (uint i = 0; i < 5; i++) SetDParamMaxValue(i, INT16_MAX);
@@ -2723,9 +2732,17 @@ struct VehicleDetailsWindow : Window {
y += FONT_HEIGHT_NORMAL;
}
bool should_show_speed_restriction = this->ShouldShowSpeedRestrictionLine(v);
if (should_show_speed_restriction) {
SetDParam(0, Train::From(v)->speed_restriction);
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_VEHICLE_INFO_SPEED_RESTRICTION);
y += FONT_HEIGHT_NORMAL;
}
if (this->vehicle_weight_ratio_line_shown != should_show_weight_ratio ||
this->vehicle_weight_ratio_line_shown != should_show_weight_ratio ||
this->vehicle_slots_line_shown != should_show_slots) {
this->vehicle_slots_line_shown != should_show_slots ||
this->vehicle_speed_restriction_line_shown != should_show_speed_restriction) {
const_cast<VehicleDetailsWindow *>(this)->ReInit();
}
break;