mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-03-22 15:05:03 +01:00
Battery button impulse behavior
This commit is contained in:
188
Train.cpp
188
Train.cpp
@@ -2398,7 +2398,8 @@ void TTrain::OnCommand_cabsignalacknowledge( TTrain *Train, command_data const &
|
||||
|
||||
void TTrain::OnCommand_batterytoggle( TTrain *Train, command_data const &Command )
|
||||
{
|
||||
if( Command.action != GLFW_REPEAT ) {
|
||||
if (Train->allowBatteryToggle || Command.action != GLFW_REPEAT)
|
||||
{
|
||||
// keep the switch from flipping back and forth if key is held down
|
||||
if( false == Train->mvOccupied->Power24vIsAvailable ) {
|
||||
// turn on
|
||||
@@ -2412,44 +2413,160 @@ void TTrain::OnCommand_batterytoggle( TTrain *Train, command_data const &Command
|
||||
}
|
||||
|
||||
void TTrain::OnCommand_batteryenable( TTrain *Train, command_data const &Command ) {
|
||||
if (!Train->mvOccupied->isBatteryButtonImpulse)
|
||||
{ // regular button behavior
|
||||
if (Command.action == GLFW_PRESS)
|
||||
{
|
||||
// visual feedback
|
||||
Train->ggBatteryButton.UpdateValue(1.0f, Train->dsbSwitch);
|
||||
Train->ggBatteryOnButton.UpdateValue(1.0f, Train->dsbSwitch);
|
||||
|
||||
if( Command.action == GLFW_PRESS ) {
|
||||
// visual feedback
|
||||
Train->ggBatteryButton.UpdateValue( 1.0f, Train->dsbSwitch );
|
||||
Train->ggBatteryOnButton.UpdateValue( 1.0f, Train->dsbSwitch );
|
||||
|
||||
Train->mvOccupied->BatterySwitch( true );
|
||||
|
||||
// side-effects
|
||||
if( Train->mvOccupied->LightsPosNo > 0 ) {
|
||||
Train->Dynamic()->SetLights();
|
||||
}
|
||||
Train->mvOccupied->BatterySwitch(true);
|
||||
Train->allowBatteryToggle = false;
|
||||
// side-effects
|
||||
if (Train->mvOccupied->LightsPosNo > 0)
|
||||
{
|
||||
Train->Dynamic()->SetLights();
|
||||
}
|
||||
}
|
||||
else if (Command.action == GLFW_RELEASE)
|
||||
{
|
||||
if (Train->ggBatteryButton.type() == TGaugeType::push)
|
||||
{
|
||||
// return the switch to neutral position
|
||||
Train->ggBatteryButton.UpdateValue(0.5f);
|
||||
}
|
||||
Train->ggBatteryOnButton.UpdateValue(0.0f, Train->dsbSwitch);
|
||||
Train->allowBatteryToggle = true;
|
||||
}
|
||||
}
|
||||
else if( Command.action == GLFW_RELEASE ) {
|
||||
if( Train->ggBatteryButton.type() == TGaugeType::push ) {
|
||||
// return the switch to neutral position
|
||||
Train->ggBatteryButton.UpdateValue( 0.5f );
|
||||
else // impulse button behavior
|
||||
{
|
||||
if (Command.action == GLFW_PRESS)
|
||||
{
|
||||
if (Train->mvOccupied->shouldHoldBatteryButton)
|
||||
{
|
||||
// jesli przycisk trzeba przytrzymac
|
||||
Train->ggBatteryButton.UpdateValue(1.0f, Train->dsbSwitch);
|
||||
Train->ggBatteryOnButton.UpdateValue(1.0f, Train->dsbSwitch);
|
||||
Train->fBatteryTimer = Train->mvOccupied->BatteryButtonHoldTime; // start timer
|
||||
}
|
||||
else
|
||||
{
|
||||
// jesli przycisk dziala od razu
|
||||
Train->mvOccupied->BatterySwitch(true);
|
||||
Train->allowBatteryToggle = false;
|
||||
// side-effects
|
||||
if (Train->mvOccupied->LightsPosNo > 0)
|
||||
{
|
||||
Train->Dynamic()->SetLights();
|
||||
}
|
||||
|
||||
// visual feedback
|
||||
Train->ggBatteryButton.UpdateValue(1.0f, Train->dsbSwitch);
|
||||
Train->ggBatteryOnButton.UpdateValue(1.0f, Train->dsbSwitch);
|
||||
}
|
||||
}
|
||||
Train->ggBatteryOnButton.UpdateValue( 0.0f, Train->dsbSwitch );
|
||||
else if (Command.action == GLFW_RELEASE)
|
||||
{
|
||||
// visual feedback
|
||||
Train->ggBatteryButton.UpdateValue(0.0f, Train->dsbSwitch);
|
||||
Train->ggBatteryOnButton.UpdateValue(0.0f, Train->dsbSwitch);
|
||||
Train->fBatteryTimer = -1.f; //
|
||||
Train->allowBatteryToggle = true;
|
||||
}
|
||||
else if (Command.action == GLFW_REPEAT && Train->mvOccupied->shouldHoldBatteryButton)
|
||||
{
|
||||
// trzymamy przycisk
|
||||
if (Train->fBatteryTimer <= 0.0 && Train->mvOccupied->Battery == false) {
|
||||
Train->mvOccupied->BatterySwitch(true);
|
||||
// side-effects
|
||||
if (Train->mvOccupied->LightsPosNo > 0)
|
||||
{
|
||||
Train->Dynamic()->SetLights();
|
||||
}
|
||||
Train->allowBatteryToggle = false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TTrain::OnCommand_batterydisable( TTrain *Train, command_data const &Command ) {
|
||||
// TBD, TODO: ewentualnie zablokować z FIZ, np. w samochodach się nie odłącza akumulatora
|
||||
if( Command.action == GLFW_PRESS ) {
|
||||
// visual feedback
|
||||
Train->ggBatteryButton.UpdateValue( 0.0f, Train->dsbSwitch );
|
||||
Train->ggBatteryOffButton.UpdateValue( 1.0f, Train->dsbSwitch );
|
||||
if (!Train->mvOccupied->isBatteryButtonImpulse)
|
||||
{ // regular button behavior
|
||||
if (Command.action == GLFW_PRESS)
|
||||
{
|
||||
// visual feedback
|
||||
Train->ggBatteryButton.UpdateValue(0.0f, Train->dsbSwitch);
|
||||
Train->ggBatteryOffButton.UpdateValue(1.0f, Train->dsbSwitch);
|
||||
|
||||
Train->mvOccupied->BatterySwitch( false );
|
||||
}
|
||||
else if( Command.action == GLFW_RELEASE ) {
|
||||
if( Train->ggBatteryButton.type() == TGaugeType::push ) {
|
||||
// return the switch to neutral position
|
||||
Train->ggBatteryButton.UpdateValue( 0.5f );
|
||||
}
|
||||
Train->ggBatteryOffButton.UpdateValue( 0.0f, Train->dsbSwitch );
|
||||
}
|
||||
Train->mvOccupied->BatterySwitch(false);
|
||||
|
||||
// side-effects
|
||||
if (Train->mvOccupied->LightsPosNo > 0)
|
||||
{
|
||||
Train->Dynamic()->SetLights();
|
||||
}
|
||||
}
|
||||
else if (Command.action == GLFW_RELEASE)
|
||||
{
|
||||
if (Train->ggBatteryButton.type() == TGaugeType::push)
|
||||
{
|
||||
// return the switch to neutral position
|
||||
Train->ggBatteryButton.UpdateValue(0.5f);
|
||||
}
|
||||
Train->ggBatteryOffButton.UpdateValue(0.0f, Train->dsbSwitch);
|
||||
}
|
||||
}
|
||||
else // impulse button behavior
|
||||
{
|
||||
if (Command.action == GLFW_PRESS)
|
||||
{
|
||||
if (Train->mvOccupied->shouldHoldBatteryButton)
|
||||
{
|
||||
// jesli przycisk trzeba przytrzymac
|
||||
Train->ggBatteryButton.UpdateValue(1.0f, Train->dsbSwitch);
|
||||
Train->ggBatteryOffButton.UpdateValue(1.0f, Train->dsbSwitch);
|
||||
Train->fBatteryTimer = Train->mvOccupied->BatteryButtonHoldTime; // start timer
|
||||
}
|
||||
else
|
||||
{
|
||||
// jesli przycisk dziala od razu
|
||||
Train->mvOccupied->BatterySwitch(false);
|
||||
Train->allowBatteryToggle = false;
|
||||
|
||||
// side-effects
|
||||
if (Train->mvOccupied->LightsPosNo > 0)
|
||||
{
|
||||
Train->Dynamic()->SetLights();
|
||||
}
|
||||
// visual feedback
|
||||
Train->ggBatteryButton.UpdateValue(1.0f, Train->dsbSwitch);
|
||||
Train->ggBatteryOffButton.UpdateValue(1.0f, Train->dsbSwitch);
|
||||
}
|
||||
}
|
||||
else if (Command.action == GLFW_RELEASE)
|
||||
{
|
||||
// visual feedback
|
||||
Train->ggBatteryButton.UpdateValue(0.0f, Train->dsbSwitch);
|
||||
Train->ggBatteryOffButton.UpdateValue(0.0f, Train->dsbSwitch);
|
||||
Train->allowBatteryToggle = true;
|
||||
}
|
||||
else if (Command.action == GLFW_REPEAT && Train->mvOccupied->shouldHoldBatteryButton)
|
||||
{
|
||||
// trzymamy przycisk
|
||||
if (Train->fBatteryTimer <= 0.0 && Train->mvOccupied->Battery == true) {
|
||||
Train->mvOccupied->BatterySwitch(false);
|
||||
Train->allowBatteryToggle = false;
|
||||
// side-effects
|
||||
if (Train->mvOccupied->LightsPosNo > 0)
|
||||
{
|
||||
Train->Dynamic()->SetLights();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TTrain::OnCommand_cabactivationtoggle(TTrain *Train, command_data const &Command) {
|
||||
@@ -6967,9 +7084,14 @@ bool TTrain::Update( double const Deltatime )
|
||||
if (trainLenghtMeasureTimer >= 0.f) {
|
||||
trainLenghtMeasureTimer -= Deltatime;
|
||||
if (trainLenghtMeasureTimer < 0.f)
|
||||
{
|
||||
trainLenghtMeasureTimer = -1.f;
|
||||
}
|
||||
}
|
||||
|
||||
// battery timer
|
||||
if (fBatteryTimer >= 0.f) {
|
||||
fBatteryTimer -= Deltatime;
|
||||
if (fBatteryTimer < 0.f)
|
||||
fBatteryTimer = -1.f;
|
||||
}
|
||||
|
||||
// helper variables
|
||||
|
||||
Reference in New Issue
Block a user