Skip to content
This repository has been archived by the owner on Aug 8, 2024. It is now read-only.

Commit

Permalink
Merge pull request #35 from dexslab/master
Browse files Browse the repository at this point in the history
More code cleanup, Fixed stale vehicle removal, Added Pattern decrement
  • Loading branch information
ejb1123 authored Jan 29, 2018
2 parents 7af971a + 93a9e8f commit fd97c8a
Show file tree
Hide file tree
Showing 11 changed files with 170 additions and 73 deletions.
5 changes: 4 additions & 1 deletion src/Extra/Extra.cs
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,9 @@ internal async void ExtraTicker()
return;
}
}
#if DEBUG
//CitizenFX.Core.Debug.WriteLine($"Allow flash ran on extra {Id}");
#endif
}
else if (allowflash > flashrate)
{
Expand All @@ -266,7 +269,7 @@ internal async void ExtraTicker()
}
else
{
if (bool.Parse(_extraInfo.AllowEnvLight))
if (!String.IsNullOrEmpty(_extraInfo.AllowEnvLight) && bool.Parse(_extraInfo.AllowEnvLight))
{
DrawEnvLight();
}
Expand Down
27 changes: 21 additions & 6 deletions src/Light/Light.Loop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -306,29 +306,44 @@ internal void ToggleSclKB()
internal void ChgPrmPattKB()
{
Game.DisableControlThisFrame(0, configuration.ControlConfiguration.KeyBindings.ChgPattPrmL);
if (Game.IsDisabledControlJustPressed(0, configuration.ControlConfiguration.KeyBindings.ChgPattPrmL))
if (Game.IsDisabledControlJustPressed(0, configuration.ControlConfiguration.KeyBindings.ChgPattPrmL) && !Game.IsControlPressed(0, Control.CharacterWheel))
{
ChgPrmPatt();
ChgPrmPatt(false);
RemoteEventManager.SendEvent(RemoteEventManager.Commands.ChgPattPrmL, _vehicle, true, Game.Player.ServerId);
}
else if (Game.IsDisabledControlJustPressed(0, configuration.ControlConfiguration.KeyBindings.ChgPattPrmL) && Game.IsControlPressed(0, Control.CharacterWheel))
{
ChgPrmPatt(true);
RemoteEventManager.SendEvent(RemoteEventManager.Commands.ChgPattPrmL, _vehicle, true, Game.Player.ServerId);
}
}

internal void ChgSecPattKB()
{
Game.DisableControlThisFrame(0, configuration.ControlConfiguration.KeyBindings.ChgPattSecL);
if (Game.IsDisabledControlJustPressed(0, configuration.ControlConfiguration.KeyBindings.ChgPattSecL))
if (Game.IsDisabledControlJustPressed(0, configuration.ControlConfiguration.KeyBindings.ChgPattSecL) && !Game.IsControlPressed(0, Control.CharacterWheel))
{
ChgSecPatt();
ChgSecPatt(false);
RemoteEventManager.SendEvent(RemoteEventManager.Commands.ChangeSecPatt, _vehicle, true, Game.Player.ServerId);
}
else if (Game.IsDisabledControlJustPressed(0, configuration.ControlConfiguration.KeyBindings.ChgPattSecL) && Game.IsControlPressed(0, Control.CharacterWheel))
{
ChgSecPatt(true);
RemoteEventManager.SendEvent(RemoteEventManager.Commands.ChangeSecPatt, _vehicle, true, Game.Player.ServerId);
}
}

internal void ChgWrnPattKB()
{
Game.DisableControlThisFrame(0, configuration.ControlConfiguration.KeyBindings.ChgPattWrnL);
if (Game.IsDisabledControlJustPressed(0, configuration.ControlConfiguration.KeyBindings.ChgPattWrnL))
if (Game.IsDisabledControlJustPressed(0, configuration.ControlConfiguration.KeyBindings.ChgPattWrnL) && !Game.IsControlPressed(0, Control.CharacterWheel))
{
ChgWrnPatt(false);
RemoteEventManager.SendEvent(RemoteEventManager.Commands.ChgPattWrnL, _vehicle, true, Game.Player.ServerId);
}
else if (Game.IsDisabledControlJustPressed(0, configuration.ControlConfiguration.KeyBindings.ChgPattWrnL) && Game.IsControlPressed(0, Control.CharacterWheel))
{
ChgWrnPatt();
ChgWrnPatt(true);
RemoteEventManager.SendEvent(RemoteEventManager.Commands.ChgPattWrnL, _vehicle, true, Game.Player.ServerId);
}
}
Expand Down
31 changes: 22 additions & 9 deletions src/Light/Lights.Patterns.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,21 @@ public int CurrentPrmPattern
break;
case 2:
e.Pattern = CHP.LightStage2[CurrentSecPattern][e.Id];
_prmPatterns = 1;
_wrnPatterns = 1;
_secPatterns = CHP.LightStage2.Count;
break;
case 3:
e.Pattern = CHP.LightStage3[CurrentWrnPattern][e.Id];
_prmPatterns = 1;
_secPatterns = 1;
_wrnPatterns = CHP.LightStage3.Count;
break;
default:
e.Pattern = CHP.LightStage1[e.Id];
_prmPatterns = 1;
_wrnPatterns = 1;
_secPatterns = 1;
break;
}
_prefix = "C";
Expand All @@ -113,9 +120,9 @@ public int CurrentPrmPattern
CitizenFX.Core.Debug.WriteLine($"{e.Id} error {ex.Message}");
}
}
#if DEBUG
CitizenFX.Core.Debug.WriteLine($"Current primary pattern is {CurrentPrmPattern}");
#endif

Utils.DebugWriteLine($"Current primary pattern is {CurrentPrmPattern}");

ElsUiPanel.SetUiDesc(_prefix + CurrentPrmPattern.ToString().PadLeft(3,'0'), ExtraEnum.PRML.ToString());
}
}
Expand Down Expand Up @@ -157,6 +164,7 @@ public int CurrentSecPattern
break;
case "marq":
e.Pattern = Marquee.SecondaryPatterns[CurrentSecPattern][e.Id];
_secPatterns = Marquee.SecondaryPatterns.Count;
_prefix = "M";
break;
case "chp":
Expand Down Expand Up @@ -191,9 +199,7 @@ public int CurrentSecPattern
}
}
ElsUiPanel.SetUiDesc(_prefix + CurrentSecPattern.ToString().PadLeft(3,'0'), ExtraEnum.SECL.ToString());
#if DEBUG
CitizenFX.Core.Debug.WriteLine($"Current secondary pattern is {CurrentSecPattern}");
#endif
Utils.DebugWriteLine($"Current secondary pattern is {CurrentSecPattern}");
}
}

Expand All @@ -214,10 +220,12 @@ public int CurrentWrnPattern
{
case "leds":
e.Pattern = Leds.WarningPatterns[CurrentWrnPattern][e.Id];
_wrnPatterns = Leds.WarningPatterns.Count;
_prefix = "L";
break;
case "strb":
e.Pattern = Strobe.WarningPatterns[CurrentWrnPattern][e.Id];
_wrnPatterns = Strobe.WarningPatterns.Count;
_prefix = "S";
break;
case "chp":
Expand Down Expand Up @@ -252,9 +260,7 @@ public int CurrentWrnPattern
}
}
ElsUiPanel.SetUiDesc(_prefix + CurrentWrnPattern.ToString().PadLeft(3,'0'), ExtraEnum.WRNL.ToString());
#if DEBUG
CitizenFX.Core.Debug.WriteLine($"Current warning pattern is {CurrentWrnPattern}");
#endif
Utils.DebugWriteLine($"Current warning pattern is {CurrentWrnPattern}");
}
}

Expand Down Expand Up @@ -320,5 +326,12 @@ private void SetupWrnPatterns()
CurrentWrnPattern = WrnScanPatts[0];
}
}

internal void SetCHP()
{
CurrentPrmPattern = 0;
CurrentSecPattern = 0;
CurrentWrnPattern = 0;
}
}
}
88 changes: 76 additions & 12 deletions src/Light/Lights.logic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,39 +126,81 @@ internal void ToggleScl()
ElsUiPanel.ToggleUiBtnState(_extras.SCL.TurnedOn, "SCL");
}

internal async void ChgPrmPatt()
internal async void ChgPrmPatt(bool decrement)
{
if (CurrentPrmPattern == _prmPatterns - 1)
if (decrement)
{
CurrentPrmPattern = 0;
if (CurrentPrmPattern == 0)
{
CurrentPrmPattern = _prmPatterns -1;
}
else
{
CurrentPrmPattern--;
}
}
else
{
CurrentPrmPattern++;
if (CurrentPrmPattern == _prmPatterns - 1)
{
CurrentPrmPattern = 0;
}
else
{
CurrentPrmPattern++;
}
}
}

internal async void ChgSecPatt()
internal async void ChgSecPatt(bool decrement)
{
if (CurrentSecPattern == _secPatterns - 1)
if (decrement)
{
CurrentSecPattern = 0;
if (CurrentSecPattern == 0)
{
CurrentSecPattern = _secPatterns - 1;
}
else
{
CurrentSecPattern--;
}
}
else
{
CurrentSecPattern++;
if (CurrentSecPattern == _secPatterns - 1)
{
CurrentSecPattern = 0;
}
else
{
CurrentSecPattern++;
}
}
}

internal async void ChgWrnPatt()
internal async void ChgWrnPatt(bool decrement)
{
if (CurrentWrnPattern == _wrnPatterns - 1)
if (decrement)
{
CurrentWrnPattern = 0;
if (CurrentWrnPattern == 0)
{
CurrentWrnPattern = _wrnPatterns - 1;
}
else
{
CurrentWrnPattern--;
}
}
else
{
CurrentWrnPattern++;
if (CurrentWrnPattern == _wrnPatterns - 1)
{
CurrentWrnPattern = 0;
}
else
{
CurrentWrnPattern++;
}
}
}

Expand Down Expand Up @@ -404,6 +446,10 @@ internal async void ToggleLightStage()
{
e.IsPatternRunning = false;
}
if (_vcfroot.SECL.LightingFormat.ToLower().Equals("chp"))
{
_extras.SBRN.IsPatternRunning = false;
}
ElsUiPanel.ToggleUiBtnState(false, "PRML");
ElsUiPanel.ToggleUiBtnState(false, "SECL");
ElsUiPanel.ToggleUiBtnState(false, "WRNL");
Expand All @@ -430,6 +476,12 @@ internal async void ToggleLightStage()
}
e.IsPatternRunning = true;
}
if (_vcfroot.SECL.LightingFormat.ToLower().Equals("chp"))
{
SetCHP();
_extras.SBRN.Pattern = CHP.LightStage1[10];
_extras.SBRN.IsPatternRunning = true;
}
ElsUiPanel.ToggleUiBtnState(true, "SECL");
secLights = true;
break;
Expand Down Expand Up @@ -475,6 +527,12 @@ internal async void ToggleLightStage()
e.IsPatternRunning = false;
e.IsPatternRunning = true;
}
if (_vcfroot.PRML.LightingFormat.ToLower().Equals("chp"))
{
SetCHP();
_extras.SBRN.Pattern = CHP.LightStage2[CurrentSecPattern][10];
_extras.SBRN.IsPatternRunning = true;
}
ElsUiPanel.ToggleUiBtnState(true, "PRML");
ElsUiPanel.ToggleUiBtnState(true, "SECL");
break;
Expand Down Expand Up @@ -544,6 +602,12 @@ internal async void ToggleLightStage()
e.IsPatternRunning = true;
}
wrnLights = true;
if (_vcfroot.PRML.LightingFormat.ToLower().Equals("chp"))
{
SetCHP();
_extras.SBRN.Pattern = CHP.LightStage3[CurrentWrnPattern][10];
_extras.SBRN.IsPatternRunning = true;
}
ElsUiPanel.ToggleUiBtnState(true, "PRML");
ElsUiPanel.ToggleUiBtnState(true, "WRNL");
break;
Expand Down
34 changes: 34 additions & 0 deletions src/Manager/VehicleManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
using CitizenFX.Core.UI;
using System.Drawing;
using System.Collections;
using System.Threading.Tasks;
using ELS.configuration;

namespace ELS.Manager
{
Expand Down Expand Up @@ -100,6 +102,15 @@ internal async void RunTickAsync()
#endif
}
vehicleList.RunExternalTick();
if (lastDeleteTime == 0)
{
lastDeleteTime = Game.GameTime;
}
if (Game.GameTime - lastDeleteTime >= Global.DeleteInterval)
{
DeleteStale();
lastDeleteTime = Game.GameTime;
}
}
catch (Exception e)
{
Expand All @@ -109,6 +120,29 @@ internal async void RunTickAsync()
//TODO Chnage how I check for the panic alarm
}

int lastDeleteTime = 0;
private async Task DeleteStale()
{
PlayerList list = new PlayerList();
#if DEBUG
CitizenFX.Core.Debug.WriteLine("Running Delete");
#endif
foreach (ELSVehicle v in vehicleList.ToList())
{
foreach (Player p in list)
{
if (p.Character.IsSittingInELSVehicle() && p.Character.CurrentVehicle.GetNetworkId() == v.GetNetworkId())
{
continue;
}
else
{
v.Delete();
}
}
}
}

/// <summary>
/// Proxies the sync data to a certain vehicle
/// </summary>
Expand Down
Loading

0 comments on commit fd97c8a

Please sign in to comment.