diff --git a/Gauge.cpp b/Gauge.cpp index 4c4da7b2..c52de766 100644 --- a/Gauge.cpp +++ b/Gauge.cpp @@ -180,7 +180,7 @@ void TGauge::DecValue(double fNewDesired) void TGauge::UpdateValue( double fNewDesired, PSound Fallbacksound ) { - auto const desiredtimes100 = static_cast( 100.0 * fNewDesired ); + auto const desiredtimes100 = static_cast( std::round( 100.0 * fNewDesired ) ); if( static_cast( std::round( 100.0 * ( fDesiredValue - fOffset ) / fScale ) ) == desiredtimes100 ) { return; } diff --git a/Train.cpp b/Train.cpp index 46dbb7b9..066e98e1 100644 --- a/Train.cpp +++ b/Train.cpp @@ -1361,6 +1361,14 @@ void TTrain::OnCommand_batterytoggle( TTrain *Train, command_data const &Command void TTrain::OnCommand_pantographtogglefront( TTrain *Train, command_data const &Command ) { + return ( + Train->mvControlled->ActiveCab < 0 ? + pantographtogglerear( Train, Command ) : + pantographtogglefront( Train, Command ) ); +} + +void TTrain::pantographtogglefront( TTrain *Train, command_data const &Command ) { + if( Command.action == GLFW_PRESS ) { // only reacting to press, so the switch doesn't flip back and forth if key is held down if( false == Train->mvControlled->PantFrontUp ) { @@ -1368,60 +1376,99 @@ void TTrain::OnCommand_pantographtogglefront( TTrain *Train, command_data const Train->mvControlled->PantFrontSP = false; if( Train->mvControlled->PantFront( true ) ) { if( Train->mvControlled->PantFrontStart != 1 ) { -#ifdef EU07_USE_OLD_CONTROLSOUNDS - // sound feedback - Train->play_sound( Train->dsbSwitch ); -#endif // visual feedback - if( Train->ggPantFrontButton.SubModel ) - Train->ggPantFrontButton.UpdateValue( 1.0, Train->dsbSwitch ); - // NOTE: currently we animate the selectable pantograph control based on standard key presses - // TODO: implement actual selection control, and refactor handling this control setup in a separate method - if( Train->ggPantSelectedButton.SubModel ) - Train->ggPantSelectedButton.UpdateValue( 1.0, Train->dsbSwitch ); - // pantograph control can have two-button setup - if( Train->ggPantFrontButtonOff.SubModel ) - Train->ggPantFrontButtonOff.UpdateValue( 0.0, Train->dsbSwitch ); - // NOTE: currently we animate the selectable pantograph control based on standard key presses - // TODO: implement actual selection control, and refactor handling this control setup in a separate method - if( Train->ggPantSelectedDownButton.SubModel ) - Train->ggPantSelectedDownButton.UpdateValue( 0.0, Train->dsbSwitch ); + if( Train->mvControlled->ActiveCab < 0 ) { + if( Train->ggPantRearButton.SubModel ) + Train->ggPantRearButton.UpdateValue( 1.0, Train->dsbSwitch ); + // NOTE: currently we animate the selectable pantograph control based on standard key presses + // TODO: implement actual selection control, and refactor handling this control setup in a separate method + if( Train->ggPantSelectedButton.SubModel ) + Train->ggPantSelectedButton.UpdateValue( 1.0, Train->dsbSwitch ); + // pantograph control can have two-button setup + if( Train->ggPantRearButtonOff.SubModel ) + Train->ggPantRearButtonOff.UpdateValue( 0.0, Train->dsbSwitch ); + // NOTE: currently we animate the selectable pantograph control based on standard key presses + // TODO: implement actual selection control, and refactor handling this control setup in a separate method + if( Train->ggPantSelectedDownButton.SubModel ) + Train->ggPantSelectedDownButton.UpdateValue( 0.0, Train->dsbSwitch ); + } + else { + if( Train->ggPantFrontButton.SubModel ) + Train->ggPantFrontButton.UpdateValue( 1.0, Train->dsbSwitch ); + // NOTE: currently we animate the selectable pantograph control based on standard key presses + // TODO: implement actual selection control, and refactor handling this control setup in a separate method + if( Train->ggPantSelectedButton.SubModel ) + Train->ggPantSelectedButton.UpdateValue( 1.0, Train->dsbSwitch ); + // pantograph control can have two-button setup + if( Train->ggPantFrontButtonOff.SubModel ) + Train->ggPantFrontButtonOff.UpdateValue( 0.0, Train->dsbSwitch ); + // NOTE: currently we animate the selectable pantograph control based on standard key presses + // TODO: implement actual selection control, and refactor handling this control setup in a separate method + if( Train->ggPantSelectedDownButton.SubModel ) + Train->ggPantSelectedDownButton.UpdateValue( 0.0, Train->dsbSwitch ); + } } } } else { // ...or turn off if( Train->mvOccupied->PantSwitchType == "impulse" ) { - if( ( Train->ggPantFrontButtonOff.SubModel == nullptr ) - && ( Train->ggPantSelectedDownButton.SubModel == nullptr ) ) { - // with impulse buttons we expect a dedicated switch to lower the pantograph, and if the cabin lacks it - // then another control has to be used (like pantographlowerall) - // TODO: we should have a way to define presense of cab controls without having to bind these to 3d submodels - return; + if( Train->mvControlled->ActiveCab < 0 ) { + if( ( Train->ggPantRearButtonOff.SubModel == nullptr ) + && ( Train->ggPantSelectedDownButton.SubModel == nullptr ) ) { + // with impulse buttons we expect a dedicated switch to lower the pantograph, and if the cabin lacks it + // then another control has to be used (like pantographlowerall) + // TODO: we should have a way to define presense of cab controls without having to bind these to 3d submodels + return; + } + } + else { + if( ( Train->ggPantFrontButtonOff.SubModel == nullptr ) + && ( Train->ggPantSelectedDownButton.SubModel == nullptr ) ) { + // with impulse buttons we expect a dedicated switch to lower the pantograph, and if the cabin lacks it + // then another control has to be used (like pantographlowerall) + // TODO: we should have a way to define presense of cab controls without having to bind these to 3d submodels + return; + } } } Train->mvControlled->PantFrontSP = false; if( false == Train->mvControlled->PantFront( false ) ) { if( Train->mvControlled->PantFrontStart != 0 ) { -#ifdef EU07_USE_OLD_CONTROLSOUNDS - // sound feedback - Train->play_sound( Train->dsbSwitch ); -#endif // visual feedback - if( Train->ggPantFrontButton.SubModel ) - Train->ggPantFrontButton.UpdateValue( 0.0, Train->dsbSwitch ); - // NOTE: currently we animate the selectable pantograph control based on standard key presses - // TODO: implement actual selection control, and refactor handling this control setup in a separate method - if( Train->ggPantSelectedButton.SubModel ) - Train->ggPantSelectedButton.UpdateValue( 0.0, Train->dsbSwitch ); - // pantograph control can have two-button setup - if( Train->ggPantFrontButtonOff.SubModel ) - Train->ggPantFrontButtonOff.UpdateValue( 1.0, Train->dsbSwitch ); - // NOTE: currently we animate the selectable pantograph control based on standard key presses - // TODO: implement actual selection control, and refactor handling this control setup in a separate method - if( Train->ggPantSelectedDownButton.SubModel ) - Train->ggPantSelectedDownButton.UpdateValue( 1.0, Train->dsbSwitch ); + if( Train->mvControlled->ActiveCab < 0 ) { + // in rear cab switch functions are swapped + if( Train->ggPantRearButton.SubModel ) + Train->ggPantRearButton.UpdateValue( 0.0, Train->dsbSwitch ); + // NOTE: currently we animate the selectable pantograph control based on standard key presses + // TODO: implement actual selection control, and refactor handling this control setup in a separate method + if( Train->ggPantSelectedButton.SubModel ) + Train->ggPantSelectedButton.UpdateValue( 0.0, Train->dsbSwitch ); + // pantograph control can have two-button setup + if( Train->ggPantRearButtonOff.SubModel ) + Train->ggPantRearButtonOff.UpdateValue( 1.0, Train->dsbSwitch ); + // NOTE: currently we animate the selectable pantograph control based on standard key presses + // TODO: implement actual selection control, and refactor handling this control setup in a separate method + if( Train->ggPantSelectedDownButton.SubModel ) + Train->ggPantSelectedDownButton.UpdateValue( 1.0, Train->dsbSwitch ); + } + else { + // in front cab switches map normally + if( Train->ggPantFrontButton.SubModel ) + Train->ggPantFrontButton.UpdateValue( 0.0, Train->dsbSwitch ); + // NOTE: currently we animate the selectable pantograph control based on standard key presses + // TODO: implement actual selection control, and refactor handling this control setup in a separate method + if( Train->ggPantSelectedButton.SubModel ) + Train->ggPantSelectedButton.UpdateValue( 0.0, Train->dsbSwitch ); + // pantograph control can have two-button setup + if( Train->ggPantFrontButtonOff.SubModel ) + Train->ggPantFrontButtonOff.UpdateValue( 1.0, Train->dsbSwitch ); + // NOTE: currently we animate the selectable pantograph control based on standard key presses + // TODO: implement actual selection control, and refactor handling this control setup in a separate method + if( Train->ggPantSelectedDownButton.SubModel ) + Train->ggPantSelectedDownButton.UpdateValue( 1.0, Train->dsbSwitch ); + } } } } @@ -1429,29 +1476,37 @@ void TTrain::OnCommand_pantographtogglefront( TTrain *Train, command_data const else if( Command.action == GLFW_RELEASE ) { // impulse switches return automatically to neutral position if( Train->mvOccupied->PantSwitchType == "impulse" ) { -#ifdef EU07_USE_OLD_CONTROLSOUNDS - if( Train->ggPantFrontButton.GetValue() > 0.35 ) { - Train->play_sound( Train->dsbSwitch ); - } -#endif - if( Train->ggPantFrontButton.SubModel ) - Train->ggPantFrontButton.UpdateValue( 0.0, Train->dsbSwitch ); - // NOTE: currently we animate the selectable pantograph control based on standard key presses - // TODO: implement actual selection control, and refactor handling this control setup in a separate method - if( Train->ggPantSelectedButton.SubModel ) - Train->ggPantSelectedButton.UpdateValue( 0.0, Train->dsbSwitch ); - // also the switch off button, in cabs which have it -#ifdef EU07_USE_OLD_CONTROLSOUNDS - if( Train->ggPantFrontButtonOff.GetValue() > 0.35 ) { - Train->play_sound( Train->dsbSwitch ); - } -#endif - if( Train->ggPantFrontButtonOff.SubModel ) - Train->ggPantFrontButtonOff.UpdateValue( 0.0, Train->dsbSwitch ); - if( Train->ggPantSelectedDownButton.SubModel ) { + if( Train->mvControlled->ActiveCab < 0 ) { + if( Train->ggPantRearButton.SubModel ) + Train->ggPantRearButton.UpdateValue( 0.0, Train->dsbSwitch ); // NOTE: currently we animate the selectable pantograph control based on standard key presses // TODO: implement actual selection control, and refactor handling this control setup in a separate method - Train->ggPantSelectedDownButton.UpdateValue( 0.0, Train->dsbSwitch ); + if( Train->ggPantSelectedButton.SubModel ) + Train->ggPantSelectedButton.UpdateValue( 0.0, Train->dsbSwitch ); + // also the switch off button, in cabs which have it + if( Train->ggPantRearButtonOff.SubModel ) + Train->ggPantRearButtonOff.UpdateValue( 0.0, Train->dsbSwitch ); + if( Train->ggPantSelectedDownButton.SubModel ) { + // NOTE: currently we animate the selectable pantograph control based on standard key presses + // TODO: implement actual selection control, and refactor handling this control setup in a separate method + Train->ggPantSelectedDownButton.UpdateValue( 0.0, Train->dsbSwitch ); + } + } + else { + if( Train->ggPantFrontButton.SubModel ) + Train->ggPantFrontButton.UpdateValue( 0.0, Train->dsbSwitch ); + // NOTE: currently we animate the selectable pantograph control based on standard key presses + // TODO: implement actual selection control, and refactor handling this control setup in a separate method + if( Train->ggPantSelectedButton.SubModel ) + Train->ggPantSelectedButton.UpdateValue( 0.0, Train->dsbSwitch ); + // also the switch off button, in cabs which have it + if( Train->ggPantFrontButtonOff.SubModel ) + Train->ggPantFrontButtonOff.UpdateValue( 0.0, Train->dsbSwitch ); + if( Train->ggPantSelectedDownButton.SubModel ) { + // NOTE: currently we animate the selectable pantograph control based on standard key presses + // TODO: implement actual selection control, and refactor handling this control setup in a separate method + Train->ggPantSelectedDownButton.UpdateValue( 0.0, Train->dsbSwitch ); + } } } } @@ -1459,6 +1514,14 @@ void TTrain::OnCommand_pantographtogglefront( TTrain *Train, command_data const void TTrain::OnCommand_pantographtogglerear( TTrain *Train, command_data const &Command ) { + return ( + Train->mvControlled->ActiveCab < 0 ? + pantographtogglefront( Train, Command ) : + pantographtogglerear( Train, Command ) ); +} + +void TTrain::pantographtogglerear( TTrain *Train, command_data const &Command ) { + if( Command.action == GLFW_PRESS ) { // only reacting to press, so the switch doesn't flip back and forth if key is held down if( false == Train->mvControlled->PantRearUp ) { @@ -1466,60 +1529,100 @@ void TTrain::OnCommand_pantographtogglerear( TTrain *Train, command_data const & Train->mvControlled->PantRearSP = false; if( Train->mvControlled->PantRear( true ) ) { if( Train->mvControlled->PantRearStart != 1 ) { -#ifdef EU07_USE_OLD_CONTROLSOUNDS - // sound feedback - Train->play_sound( Train->dsbSwitch ); -#endif // visual feedback - if( Train->ggPantRearButton.SubModel ) - Train->ggPantRearButton.UpdateValue( 1.0, Train->dsbSwitch ); - // NOTE: currently we animate the selectable pantograph control based on standard key presses - // TODO: implement actual selection control, and refactor handling this control setup in a separate method - if( Train->ggPantSelectedButton.SubModel ) - Train->ggPantSelectedButton.UpdateValue( 1.0, Train->dsbSwitch ); - // pantograph control can have two-button setup - if( Train->ggPantRearButtonOff.SubModel ) - Train->ggPantRearButtonOff.UpdateValue( 0.0, Train->dsbSwitch ); - // NOTE: currently we animate the selectable pantograph control based on standard key presses - // TODO: implement actual selection control, and refactor handling this control setup in a separate method - if( Train->ggPantSelectedDownButton.SubModel ) - Train->ggPantSelectedDownButton.UpdateValue( 0.0, Train->dsbSwitch ); + if( Train->mvControlled->ActiveCab < 0 ) { + // in rear cab switch functions are swapped + if( Train->ggPantFrontButton.SubModel ) + Train->ggPantFrontButton.UpdateValue( 1.0, Train->dsbSwitch ); + // NOTE: currently we animate the selectable pantograph control based on standard key presses + // TODO: implement actual selection control, and refactor handling this control setup in a separate method + if( Train->ggPantSelectedButton.SubModel ) + Train->ggPantSelectedButton.UpdateValue( 1.0, Train->dsbSwitch ); + // pantograph control can have two-button setup + if( Train->ggPantFrontButtonOff.SubModel ) + Train->ggPantFrontButtonOff.UpdateValue( 0.0, Train->dsbSwitch ); + // NOTE: currently we animate the selectable pantograph control based on standard key presses + // TODO: implement actual selection control, and refactor handling this control setup in a separate method + if( Train->ggPantSelectedDownButton.SubModel ) + Train->ggPantSelectedDownButton.UpdateValue( 0.0, Train->dsbSwitch ); + } + else { + if( Train->ggPantRearButton.SubModel ) + Train->ggPantRearButton.UpdateValue( 1.0, Train->dsbSwitch ); + // NOTE: currently we animate the selectable pantograph control based on standard key presses + // TODO: implement actual selection control, and refactor handling this control setup in a separate method + if( Train->ggPantSelectedButton.SubModel ) + Train->ggPantSelectedButton.UpdateValue( 1.0, Train->dsbSwitch ); + // pantograph control can have two-button setup + if( Train->ggPantRearButtonOff.SubModel ) + Train->ggPantRearButtonOff.UpdateValue( 0.0, Train->dsbSwitch ); + // NOTE: currently we animate the selectable pantograph control based on standard key presses + // TODO: implement actual selection control, and refactor handling this control setup in a separate method + if( Train->ggPantSelectedDownButton.SubModel ) + Train->ggPantSelectedDownButton.UpdateValue( 0.0, Train->dsbSwitch ); + } } } } else { // ...or turn off if( Train->mvOccupied->PantSwitchType == "impulse" ) { - if( ( Train->ggPantRearButtonOff.SubModel == nullptr ) - && ( Train->ggPantSelectedDownButton.SubModel == nullptr ) ) { - // with impulse buttons we expect a dedicated switch to lower the pantograph, and if the cabin lacks it - // then another control has to be used (like pantographlowerall) - // TODO: we should have a way to define presense of cab controls without having to bind these to 3d submodels - return; + if( Train->mvControlled->ActiveCab < 0 ) { + // in rear cab switch functions are swapped + if( ( Train->ggPantFrontButtonOff.SubModel == nullptr ) + && ( Train->ggPantSelectedDownButton.SubModel == nullptr ) ) { + // with impulse buttons we expect a dedicated switch to lower the pantograph, and if the cabin lacks it + // then another control has to be used (like pantographlowerall) + // TODO: we should have a way to define presense of cab controls without having to bind these to 3d submodels + return; + } + } + else { + if( ( Train->ggPantRearButtonOff.SubModel == nullptr ) + && ( Train->ggPantSelectedDownButton.SubModel == nullptr ) ) { + // with impulse buttons we expect a dedicated switch to lower the pantograph, and if the cabin lacks it + // then another control has to be used (like pantographlowerall) + // TODO: we should have a way to define presense of cab controls without having to bind these to 3d submodels + return; + } } } Train->mvControlled->PantRearSP = false; if( false == Train->mvControlled->PantRear( false ) ) { if( Train->mvControlled->PantRearStart != 0 ) { -#ifdef EU07_USE_OLD_CONTROLSOUNDS - // sound feedback - Train->play_sound( Train->dsbSwitch ); -#endif // visual feedback - if( Train->ggPantRearButton.SubModel ) - Train->ggPantRearButton.UpdateValue( 0.0, Train->dsbSwitch ); - // NOTE: currently we animate the selectable pantograph control based on standard key presses - // TODO: implement actual selection control, and refactor handling this control setup in a separate method - if( Train->ggPantSelectedButton.SubModel ) - Train->ggPantSelectedButton.UpdateValue( 0.0, Train->dsbSwitch ); - // pantograph control can have two-button setup - if( Train->ggPantRearButtonOff.SubModel ) - Train->ggPantRearButtonOff.UpdateValue( 1.0, Train->dsbSwitch ); - // NOTE: currently we animate the selectable pantograph control based on standard key presses - // TODO: implement actual selection control, and refactor handling this control setup in a separate method - if( Train->ggPantSelectedDownButton.SubModel ) - Train->ggPantSelectedDownButton.UpdateValue( 1.0, Train->dsbSwitch ); + if( Train->mvControlled->ActiveCab < 0 ) { + // in rear cab switch functions are swapped + if( Train->ggPantFrontButton.SubModel ) + Train->ggPantFrontButton.UpdateValue( 0.0, Train->dsbSwitch ); + // NOTE: currently we animate the selectable pantograph control based on standard key presses + // TODO: implement actual selection control, and refactor handling this control setup in a separate method + if( Train->ggPantSelectedButton.SubModel ) + Train->ggPantSelectedButton.UpdateValue( 0.0, Train->dsbSwitch ); + // pantograph control can have two-button setup + if( Train->ggPantFrontButtonOff.SubModel ) + Train->ggPantFrontButtonOff.UpdateValue( 1.0, Train->dsbSwitch ); + // NOTE: currently we animate the selectable pantograph control based on standard key presses + // TODO: implement actual selection control, and refactor handling this control setup in a separate method + if( Train->ggPantSelectedDownButton.SubModel ) + Train->ggPantSelectedDownButton.UpdateValue( 1.0, Train->dsbSwitch ); + } + else { + if( Train->ggPantRearButton.SubModel ) + Train->ggPantRearButton.UpdateValue( 0.0, Train->dsbSwitch ); + // NOTE: currently we animate the selectable pantograph control based on standard key presses + // TODO: implement actual selection control, and refactor handling this control setup in a separate method + if( Train->ggPantSelectedButton.SubModel ) + Train->ggPantSelectedButton.UpdateValue( 0.0, Train->dsbSwitch ); + // pantograph control can have two-button setup + if( Train->ggPantRearButtonOff.SubModel ) + Train->ggPantRearButtonOff.UpdateValue( 1.0, Train->dsbSwitch ); + // NOTE: currently we animate the selectable pantograph control based on standard key presses + // TODO: implement actual selection control, and refactor handling this control setup in a separate method + if( Train->ggPantSelectedDownButton.SubModel ) + Train->ggPantSelectedDownButton.UpdateValue( 1.0, Train->dsbSwitch ); + } } } } @@ -1527,29 +1630,38 @@ void TTrain::OnCommand_pantographtogglerear( TTrain *Train, command_data const & else if( Command.action == GLFW_RELEASE ) { // impulse switches return automatically to neutral position if( Train->mvOccupied->PantSwitchType == "impulse" ) { -#ifdef EU07_USE_OLD_CONTROLSOUNDS - if( Train->ggPantRearButton.GetValue() > 0.35 ) { - Train->play_sound( Train->dsbSwitch ); - } -#endif - if( Train->ggPantRearButton.SubModel ) - Train->ggPantRearButton.UpdateValue( 0.0, Train->dsbSwitch ); - // NOTE: currently we animate the selectable pantograph control based on standard key presses - // TODO: implement actual selection control, and refactor handling this control setup in a separate method - if( Train->ggPantSelectedButton.SubModel ) - Train->ggPantSelectedButton.UpdateValue( 0.0, Train->dsbSwitch ); - // also the switch off button, in cabs which have it -#ifdef EU07_USE_OLD_CONTROLSOUNDS - if( Train->ggPantRearButtonOff.GetValue() > 0.35 ) { - Train->play_sound( Train->dsbSwitch ); - } -#endif - if( Train->ggPantRearButtonOff.SubModel ) - Train->ggPantRearButtonOff.UpdateValue( 0.0, Train->dsbSwitch ); - if( Train->ggPantSelectedDownButton.SubModel ) { + if( Train->mvControlled->ActiveCab < 0 ) { + // in rear cab switch functions are swapped + if( Train->ggPantFrontButton.SubModel ) + Train->ggPantFrontButton.UpdateValue( 0.0, Train->dsbSwitch ); // NOTE: currently we animate the selectable pantograph control based on standard key presses // TODO: implement actual selection control, and refactor handling this control setup in a separate method - Train->ggPantSelectedDownButton.UpdateValue( 0.0, Train->dsbSwitch ); + if( Train->ggPantSelectedButton.SubModel ) + Train->ggPantSelectedButton.UpdateValue( 0.0, Train->dsbSwitch ); + // also the switch off button, in cabs which have it + if( Train->ggPantFrontButtonOff.SubModel ) + Train->ggPantFrontButtonOff.UpdateValue( 0.0, Train->dsbSwitch ); + if( Train->ggPantSelectedDownButton.SubModel ) { + // NOTE: currently we animate the selectable pantograph control based on standard key presses + // TODO: implement actual selection control, and refactor handling this control setup in a separate method + Train->ggPantSelectedDownButton.UpdateValue( 0.0, Train->dsbSwitch ); + } + } + else { + if( Train->ggPantRearButton.SubModel ) + Train->ggPantRearButton.UpdateValue( 0.0, Train->dsbSwitch ); + // NOTE: currently we animate the selectable pantograph control based on standard key presses + // TODO: implement actual selection control, and refactor handling this control setup in a separate method + if( Train->ggPantSelectedButton.SubModel ) + Train->ggPantSelectedButton.UpdateValue( 0.0, Train->dsbSwitch ); + // also the switch off button, in cabs which have it + if( Train->ggPantRearButtonOff.SubModel ) + Train->ggPantRearButtonOff.UpdateValue( 0.0, Train->dsbSwitch ); + if( Train->ggPantSelectedDownButton.SubModel ) { + // NOTE: currently we animate the selectable pantograph control based on standard key presses + // TODO: implement actual selection control, and refactor handling this control setup in a separate method + Train->ggPantSelectedDownButton.UpdateValue( 0.0, Train->dsbSwitch ); + } } } } @@ -6329,12 +6441,21 @@ bool TTrain::Update( double const Deltatime ) || ( mvControlled->ConverterFlag ) ) { if( ggPantAllDownButton.GetValue() == 0.0 ) { // the 'lower all' button overrides state of switches, while active itself + // when in rear cab we treat switches as reversed, i.e. front controls physical rear + auto const frontpantographswitch = ( + mvControlled->ActiveCab < 0 ? + ggPantRearButton.GetValue() >= 1.0 : + ggPantFrontButton.GetValue() >= 1.0 ); + auto const rearpantographswitch = ( + mvControlled->ActiveCab < 0 ? + ggPantFrontButton.GetValue() >= 1.0 : + ggPantRearButton.GetValue() >= 1.0 ); if( ( false == mvControlled->PantFrontUp ) - && ( ggPantFrontButton.GetValue() >= 1.0 ) ) { + && ( frontpantographswitch ) ) { mvControlled->PantFront( true ); } if( ( false == mvControlled->PantRearUp ) - && ( ggPantRearButton.GetValue() >= 1.0 ) ) { + && ( rearpantographswitch ) ) { mvControlled->PantRear( true ); } } @@ -7205,42 +7326,50 @@ void TTrain::set_cab_controls() { } // pantographs if( mvOccupied->PantSwitchType != "impulse" ) { + auto const pantograph = ( + mvControlled->ActiveCab < 0 ? + mvControlled->PantRearUp : + mvControlled->PantFrontUp ); ggPantFrontButton.PutValue( - ( mvControlled->PantFrontUp ? + ( pantograph ? 1.0 : 0.0 ) ); ggPantFrontButtonOff.PutValue( - ( mvControlled->PantFrontUp ? + ( pantograph ? 0.0 : 1.0 ) ); // NOTE: currently we animate the selectable pantograph control for both pantographs // TODO: implement actual selection control, and refactor handling this control setup in a separate method ggPantSelectedButton.PutValue( - ( mvControlled->PantFrontUp ? + ( pantograph ? 1.0 : 0.0 ) ); ggPantSelectedDownButton.PutValue( - ( mvControlled->PantFrontUp ? + ( pantograph ? 0.0 : 1.0 ) ); } if( mvOccupied->PantSwitchType != "impulse" ) { + auto const pantograph = ( + mvControlled->ActiveCab < 0 ? + mvControlled->PantFrontUp : + mvControlled->PantRearUp ); ggPantRearButton.PutValue( - ( mvControlled->PantRearUp ? + ( pantograph ? 1.0 : 0.0 ) ); ggPantRearButtonOff.PutValue( - ( mvControlled->PantRearUp ? + ( pantograph ? 0.0 : 1.0 ) ); // NOTE: currently we animate the selectable pantograph control for both pantographs // TODO: implement actual selection control, and refactor handling this control setup in a separate method ggPantSelectedButton.PutValue( - ( mvControlled->PantRearUp ? + ( pantograph ? 1.0 : 0.0 ) ); ggPantSelectedDownButton.PutValue( - ( mvControlled->PantRearUp ? + ( pantograph ? 0.0 : 1.0 ) ); } diff --git a/Train.h b/Train.h index c9c9e6d2..5331386f 100644 --- a/Train.h +++ b/Train.h @@ -155,7 +155,9 @@ class TTrain static void OnCommand_pantographcompressorvalvetoggle( TTrain *Train, command_data const &Command ); static void OnCommand_pantographcompressoractivate( TTrain *Train, command_data const &Command ); static void OnCommand_pantographtogglefront( TTrain *Train, command_data const &Command ); + static void pantographtogglefront( TTrain *Train, command_data const &Command ); static void OnCommand_pantographtogglerear( TTrain *Train, command_data const &Command ); + static void pantographtogglerear( TTrain *Train, command_data const &Command ); static void OnCommand_pantographlowerall( TTrain *Train, command_data const &Command ); static void OnCommand_linebreakertoggle( TTrain *Train, command_data const &Command ); static void OnCommand_convertertoggle( TTrain *Train, command_data const &Command );