18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-19 20:24:59 +01:00

feat: light programmer positions can switch the cab light (eu07/maszyna#529)

An optional third column in the LightsList rows of the .fiz sets the cab
interior light when the driver moves the light preset selector to that
position: 0 off, 1 on, 3 on dimmed (bit 2 the dimmer). Rows without the
column, or with a negative value, leave the cab light to its own switch,
so the existing tables work as before; a stray note after the two light
columns (e.g. "38 38 / A") is not read as the flag.

The light follows the occupied cab, or all cabs of a JointCabs vehicle,
as with the interior light commands; the dimmer switch is moved along.
The lightsset custom position and the AI leave the cab light alone.

Covered by tests/unit/test_lights_preset_cablight.cpp.

(eu07/maszyna#529)
This commit is contained in:
jerrrrycho
2026-11-07 23:13:00 +01:00
parent 68fdf1efdf
commit d3dd883700
5 changed files with 188 additions and 0 deletions

View File

@@ -5153,6 +5153,39 @@ void TTrain::OnCommand_universalrelayreset(TTrain *Train, command_data const &Co
}
}
// the cab interior light set by the light preset just selected, if the preset sets one (eu07/maszyna#529).
// the cab light switch (cablight_sw:) is bound to the light state and follows it by itself
void TTrain::set_cab_light_from_lights_preset()
{
auto const cablight{mvOccupied->LightsPresetCabLight(mvOccupied->LightsPos)};
if (false == cablight.has_value())
{
return;
}
auto const set{[&cablight](TCab &Cab) {
Cab.bLight = cablight->light;
Cab.bLightDim = cablight->dim;
}};
if (false == DynamicObject->JointCabs)
{
// vehicles with separate cabs get separate lighting switch states
set(Cabine[iCabn]);
}
else
{
// joint virtual cabs share lighting switch states
for (auto &cab : Cabine)
{
set(cab);
}
}
// the dimmer switch is driven by commands only, move it along
if (ggCabLightDimButton.SubModel != nullptr)
{
ggCabLightDimButton.UpdateValue(cablight->dim ? 1.f : 0.f);
}
}
void TTrain::OnCommand_lightspresetactivatenext(TTrain *Train, command_data const &Command)
{
@@ -5174,6 +5207,7 @@ void TTrain::OnCommand_lightspresetactivatenext(TTrain *Train, command_data cons
Train->mvOccupied->LightsPos = false == restartcycle ? Train->mvOccupied->LightsPos + 1 : 1; // wrap mode
Train->Dynamic()->SetLights();
Train->set_cab_light_from_lights_preset();
// visual feedback
if (Train->ggLightsButton.SubModel != nullptr)
{
@@ -5211,6 +5245,7 @@ void TTrain::OnCommand_lightspresetactivateprevious(TTrain *Train, command_data
Train->mvOccupied->LightsPos = false == restartcycle ? Train->mvOccupied->LightsPos - 1 : Train->mvOccupied->LightsPosNo; // wrap mode
Train->Dynamic()->SetLights();
Train->set_cab_light_from_lights_preset();
// visual feedback
if (Train->ggLightsButton.SubModel != nullptr)
{

View File

@@ -189,6 +189,8 @@ class TTrain {
// sets cabin controls based on current state of the vehicle
// NOTE: we can get rid of this function once we have per-cab persistent state
void set_cab_controls( int const Cab );
// sets the cab interior light as the selected light preset says, if it says anything (eu07/maszyna#529)
void set_cab_light_from_lights_preset();
// initializes a gauge matching provided label. returns: true if the label was found, false otherwise
bool initialize_gauge(cParser &Parser, std::string const &Label, int const Cabindex);
// initializes a button matching provided label. returns: true if the label was found, false otherwise