16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-23 00:29:19 +02:00

Prevent multiple battery switches in hold conditions

This commit is contained in:
2025-07-23 12:29:04 +02:00
parent d36995aeff
commit c0437946c7
2 changed files with 18 additions and 8 deletions

View File

@@ -1163,6 +1163,7 @@ class TMoverParameters
int UniversalBrakeButtonFlag[3] = {0, 0, 0}; /* mozliwe działania przycisków hamulcowych */ int UniversalBrakeButtonFlag[3] = {0, 0, 0}; /* mozliwe działania przycisków hamulcowych */
int UniversalResetButtonFlag[3] = {0, 0, 0}; // customizable reset buttons assignments int UniversalResetButtonFlag[3] = {0, 0, 0}; // customizable reset buttons assignments
int TurboTest = 0; int TurboTest = 0;
bool batterySwAlreadyFired = false; // czy przycisk baterii juz zostal wcisniety
bool isBatteryButtonImpulse = false; // czy przelacznik baterii traktowac jako pojedynczy przycisk bool isBatteryButtonImpulse = false; // czy przelacznik baterii traktowac jako pojedynczy przycisk
bool shouldHoldBatteryButton = false; // czy nalezy przytrzymac przycisk baterii aby wlaczyc/wylaczyc baterie bool shouldHoldBatteryButton = false; // czy nalezy przytrzymac przycisk baterii aby wlaczyc/wylaczyc baterie
float BatteryButtonHoldTime = 1.f; // minimalny czas przytrzymania przycisku baterii float BatteryButtonHoldTime = 1.f; // minimalny czas przytrzymania przycisku baterii

View File

@@ -2503,12 +2503,17 @@ void TTrain::OnCommand_batteryenable( TTrain *Train, command_data const &Command
Train->ggBatteryOnButton.UpdateValue(0.0f, Train->dsbSwitch); Train->ggBatteryOnButton.UpdateValue(0.0f, Train->dsbSwitch);
Train->fBatteryTimer = -1.f; // Train->fBatteryTimer = -1.f; //
Train->allowBatteryToggle = true; Train->allowBatteryToggle = true;
Train->mvOccupied->batterySwAlreadyFired = false;
} }
else if (Command.action == GLFW_REPEAT && Train->mvOccupied->shouldHoldBatteryButton) else if (Command.action == GLFW_REPEAT && Train->mvOccupied->shouldHoldBatteryButton)
{ {
// trzymamy przycisk // trzymamy przycisk
if (Train->fBatteryTimer <= 0.0 && Train->mvOccupied->Battery == false) { if (Train->fBatteryTimer <= 0.0 && Train->mvOccupied->Battery == false && !Train->mvOccupied->batterySwAlreadyFired)
{
Train->mvOccupied->BatterySwitch(true); Train->mvOccupied->BatterySwitch(true);
Train->mvOccupied->batterySwAlreadyFired = true;
// side-effects // side-effects
if (Train->mvOccupied->LightsPosNo > 0) if (Train->mvOccupied->LightsPosNo > 0)
{ {
@@ -2516,7 +2521,6 @@ void TTrain::OnCommand_batteryenable( TTrain *Train, command_data const &Command
} }
Train->allowBatteryToggle = false; Train->allowBatteryToggle = false;
} }
} }
} }
} }
@@ -2581,20 +2585,25 @@ void TTrain::OnCommand_batterydisable( TTrain *Train, command_data const &Comman
Train->ggBatteryButton.UpdateValue(0.0f, Train->dsbSwitch); Train->ggBatteryButton.UpdateValue(0.0f, Train->dsbSwitch);
Train->ggBatteryOffButton.UpdateValue(0.0f, Train->dsbSwitch); Train->ggBatteryOffButton.UpdateValue(0.0f, Train->dsbSwitch);
Train->allowBatteryToggle = true; Train->allowBatteryToggle = true;
Train->mvOccupied->batterySwAlreadyFired = false;
} }
else if (Command.action == GLFW_REPEAT && Train->mvOccupied->shouldHoldBatteryButton) else if (Command.action == GLFW_REPEAT && Train->mvOccupied->shouldHoldBatteryButton)
{ {
// trzymamy przycisk // trzymamy przycisk
if (Train->fBatteryTimer <= 0.0 && Train->mvOccupied->Battery == true) { if (Train->fBatteryTimer <= 0.0 && Train->mvOccupied->Battery == true && !Train->mvOccupied->batterySwAlreadyFired)
{
Train->mvOccupied->BatterySwitch(false); Train->mvOccupied->BatterySwitch(false);
Train->allowBatteryToggle = false; Train->mvOccupied->batterySwAlreadyFired = true;
// side-effects // side-effects
if (Train->mvOccupied->LightsPosNo > 0) if (Train->mvOccupied->LightsPosNo > 0)
{ {
Train->Dynamic()->SetLights(); Train->Dynamic()->SetLights();
} }
Train->allowBatteryToggle = false;
} }
} }
} }
} }