Skip to content

Commit c1cdf55

Browse files
committedMar 10, 2017
Whoa, vehicle fixing independence
1 parent a8648d2 commit c1cdf55

10 files changed

+1271
-1092
lines changed
 

‎.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
bin
2-
obj
2+
obj
3+
.vs

‎DevMenu.cs

+95-71
Original file line numberDiff line numberDiff line change
@@ -10,78 +10,102 @@
1010
using System.Security;
1111
using CitizenFX.Core.Native;
1212

13-
namespace FRFuel.Dev {
14-
public class DevMenu {
15-
protected MenuPool menuPool;
16-
protected UIMenu mainMenu;
17-
18-
protected UIMenuItem position;
19-
protected UIMenuItem vehicleModelId;
20-
protected UIMenuItem vehicleFuelTank;
21-
protected UIMenuItem knownVehicle;
22-
23-
protected UIMenuItem netVehicleId;
24-
protected UIMenuItem netVehicleIdControl;
25-
protected UIMenuItem decoration;
26-
27-
protected Text txt = new Text("", new PointF(600f, 100f), .5f);
28-
29-
public DevMenu() {
30-
menuPool = new MenuPool();
31-
mainMenu = new UIMenu("FRFuel dev menu", "things");
32-
33-
position = new UIMenuItem("Pos");
34-
position.Enabled = false;
35-
36-
vehicleModelId = new UIMenuItem("Vehicle model ID");
37-
vehicleModelId.Enabled = false;
38-
39-
knownVehicle = new UIMenuItem("Is known vehicle");
40-
knownVehicle.Enabled = false;
41-
42-
vehicleFuelTank = new UIMenuItem("Vehicle fuel tank");
43-
44-
mainMenu.AddItem(position);
45-
mainMenu.AddItem(knownVehicle);
46-
mainMenu.AddItem(vehicleModelId);
47-
mainMenu.AddItem(vehicleFuelTank);
48-
49-
mainMenu.OnItemSelect += (sende, item, index) => {
50-
if (item == vehicleFuelTank && Game.PlayerPed.IsInVehicle()) {
51-
BaseScript.TriggerServerEvent(
52-
"frfuel:dev:saveFuel",
53-
"{" + Game.PlayerPed.CurrentVehicle.Model.Hash.ToString() + ", " + Game.PlayerPed.CurrentVehicle.FuelLevel.ToString() + "f},"
54-
);
55-
Screen.ShowNotification("Fuel to model saved");
13+
namespace FRFuel.Dev
14+
{
15+
public class DevMenu
16+
{
17+
protected MenuPool menuPool;
18+
protected UIMenu mainMenu;
19+
20+
protected UIMenuItem position;
21+
protected UIMenuItem deleteVehicle;
22+
23+
protected UIMenuItem vehicleModelId;
24+
protected UIMenuItem vehicleFuelTank;
25+
protected UIMenuItem knownVehicle;
26+
27+
protected UIMenuItem netVehicleId;
28+
protected UIMenuItem netVehicleIdControl;
29+
protected UIMenuItem decoration;
30+
31+
protected Text txt = new Text("", new PointF(600f, 100f), .5f);
32+
33+
public DevMenu()
34+
{
35+
menuPool = new MenuPool();
36+
mainMenu = new UIMenu("FRFuel dev menu", "things");
37+
38+
position = new UIMenuItem("Pos");
39+
position.Enabled = false;
40+
41+
deleteVehicle = new UIMenuItem("Delete last vehicle");
42+
43+
vehicleModelId = new UIMenuItem("Vehicle model ID");
44+
vehicleModelId.Enabled = false;
45+
46+
knownVehicle = new UIMenuItem("Is known vehicle");
47+
knownVehicle.Enabled = false;
48+
49+
vehicleFuelTank = new UIMenuItem("Vehicle fuel tank");
50+
51+
mainMenu.AddItem(position);
52+
mainMenu.AddItem(deleteVehicle);
53+
mainMenu.AddItem(knownVehicle);
54+
mainMenu.AddItem(vehicleModelId);
55+
mainMenu.AddItem(vehicleFuelTank);
56+
57+
mainMenu.OnItemSelect += (sende, item, index) =>
58+
{
59+
if (item == vehicleFuelTank && Game.PlayerPed.IsInVehicle())
60+
{
61+
BaseScript.TriggerServerEvent(
62+
"frfuel:dev:saveFuel",
63+
"{" + Game.PlayerPed.CurrentVehicle.Model.Hash.ToString() + ", " + Game.PlayerPed.CurrentVehicle.FuelLevel.ToString() + "f},"
64+
);
65+
Screen.ShowNotification("Fuel to model saved");
66+
}
67+
68+
if (item == deleteVehicle)
69+
{
70+
if (Game.PlayerPed.LastVehicle != null)
71+
{
72+
Function.Call(Hash.SET_ENTITY_AS_MISSION_ENTITY, Game.PlayerPed.LastVehicle, false, false);
73+
Game.PlayerPed.LastVehicle.Delete();
74+
}
75+
}
76+
};
77+
78+
menuPool.Add(mainMenu);
79+
menuPool.RefreshIndex();
5680
}
57-
};
5881

59-
menuPool.Add(mainMenu);
60-
menuPool.RefreshIndex();
61-
}
62-
63-
public void OnTick() {
64-
position.Text = "Pos: " + Game.PlayerPed.Position.ToString();
65-
66-
if (Game.PlayerPed.IsInVehicle()) {
67-
Vehicle vehicle = Game.PlayerPed.CurrentVehicle;
68-
69-
knownVehicle.SetRightLabel(VehiclesPetrolTanks.dict.ContainsKey(vehicle.Model.Hash) ? "Yes" : "No");
70-
vehicleModelId.SetRightLabel(vehicle.DisplayName.ToString());
71-
vehicleFuelTank.SetRightLabel(vehicle.FuelLevel.ToString());
72-
} else {
73-
vehicleModelId.SetRightLabel("ped or not driver");
74-
vehicleFuelTank.SetRightLabel("ped or not driver");
75-
}
76-
77-
mainMenu.MouseControlsEnabled = false;
78-
menuPool.MouseEdgeEnabled = false;
79-
menuPool.ControlDisablingEnabled = false;
80-
menuPool.ProcessMenus();
81-
82-
if (Game.IsControlJustReleased(0, Control.InteractionMenu)) {
83-
mainMenu.Visible = !mainMenu.Visible;
84-
}
82+
public void OnTick()
83+
{
84+
position.Text = "Pos: " + Game.PlayerPed.Position.ToString();
85+
86+
if (Game.PlayerPed.IsInVehicle())
87+
{
88+
Vehicle vehicle = Game.PlayerPed.CurrentVehicle;
89+
90+
knownVehicle.SetRightLabel(VehiclesPetrolTanks.dict.ContainsKey(vehicle.Model.Hash) ? "Yes" : "No");
91+
vehicleModelId.SetRightLabel(vehicle.DisplayName.ToString());
92+
vehicleFuelTank.SetRightLabel(vehicle.FuelLevel.ToString());
93+
}
94+
else
95+
{
96+
vehicleModelId.SetRightLabel("ped or not driver");
97+
vehicleFuelTank.SetRightLabel("ped or not driver");
98+
}
99+
100+
mainMenu.MouseControlsEnabled = false;
101+
menuPool.MouseEdgeEnabled = false;
102+
menuPool.ControlDisablingEnabled = false;
103+
menuPool.ProcessMenus();
104+
105+
if (Game.IsControlJustReleased(0, Control.InteractionMenu))
106+
{
107+
mainMenu.Visible = !mainMenu.Visible;
108+
}
109+
}
85110
}
86-
}
87111
}

‎EntityDecoration.cs

+66-49
Original file line numberDiff line numberDiff line change
@@ -2,61 +2,78 @@
22
using CitizenFX.Core;
33
using CitizenFX.Core.Native;
44

5-
namespace FRFuel {
6-
public enum DecorationType {
7-
Float = 1,
8-
Bool = 2,
9-
Int = 3,
10-
Time = 5
11-
}
12-
13-
public class EntityDecoration {
14-
protected static Type floatType = typeof(float);
15-
protected static Type boolType = typeof(bool);
16-
protected static Type intType = typeof(int);
17-
18-
public static bool ExistOn(Entity entity, string propertyName) {
19-
return Function.Call<bool>(Hash.DECOR_EXIST_ON, entity.NativeValue, propertyName);
5+
namespace FRFuel
6+
{
7+
public enum DecorationType
8+
{
9+
Float = 1,
10+
Bool = 2,
11+
Int = 3,
12+
Time = 5
2013
}
2114

22-
public static void RegisterProperty(string propertyName, DecorationType type) {
23-
Function.Call(Hash.DECOR_REGISTER, propertyName, (int) type);
24-
}
15+
public class EntityDecoration
16+
{
17+
protected static Type floatType = typeof(float);
18+
protected static Type boolType = typeof(bool);
19+
protected static Type intType = typeof(int);
2520

26-
public static void Set(Entity entity, string propertyName, float floatValue) {
27-
Function.Call(Hash._DECOR_SET_FLOAT, entity.NativeValue, propertyName, floatValue);
28-
}
21+
public static bool ExistOn(Entity entity, string propertyName)
22+
{
23+
return Function.Call<bool>(Hash.DECOR_EXIST_ON, entity.NativeValue, propertyName);
24+
}
2925

30-
public static void Set(Entity entity, string propertyName, int intValue) {
31-
Function.Call(Hash.DECOR_SET_INT, entity.NativeValue, propertyName, intValue);
32-
}
26+
public static void RegisterProperty(string propertyName, DecorationType type)
27+
{
28+
Function.Call(Hash.DECOR_REGISTER, propertyName, (int) type);
29+
}
3330

34-
public static void Set(Entity entity, string propertyName, bool boolValue) {
35-
Function.Call(Hash.DECOR_SET_BOOL, entity.NativeValue, propertyName, boolValue);
36-
}
31+
public static void Set(Entity entity, string propertyName, float floatValue)
32+
{
33+
Function.Call(Hash._DECOR_SET_FLOAT, entity.NativeValue, propertyName, floatValue);
34+
}
35+
36+
public static void Set(Entity entity, string propertyName, int intValue)
37+
{
38+
Function.Call(Hash.DECOR_SET_INT, entity.NativeValue, propertyName, intValue);
39+
}
40+
41+
public static void Set(Entity entity, string propertyName, bool boolValue)
42+
{
43+
Function.Call(Hash.DECOR_SET_BOOL, entity.NativeValue, propertyName, boolValue);
44+
}
45+
46+
public static T Get<T>(Entity entity, string propertyName)
47+
{
48+
if (!ExistOn(entity, propertyName))
49+
{
50+
throw new EntityDecorationUnregisteredPropertyException();
51+
}
52+
53+
Type genericType = typeof(T);
54+
Hash nativeMethod;
55+
56+
if (genericType == floatType)
57+
{
58+
nativeMethod = Hash._DECOR_GET_FLOAT;
59+
}
60+
else if (genericType == intType)
61+
{
62+
nativeMethod = Hash.DECOR_GET_INT;
63+
}
64+
else if (genericType == boolType)
65+
{
66+
nativeMethod = Hash.DECOR_GET_BOOL;
67+
}
68+
else
69+
{
70+
throw new EntityDecorationUndefinedTypeException();
71+
}
3772

38-
public static T Get<T>(Entity entity, string propertyName) {
39-
if (!ExistOn(entity, propertyName)) {
40-
throw new EntityDecorationUnregisteredPropertyException();
41-
}
42-
43-
Type genericType = typeof(T);
44-
Hash nativeMethod;
45-
46-
if (genericType == floatType) {
47-
nativeMethod = Hash._DECOR_GET_FLOAT;
48-
} else if (genericType == intType) {
49-
nativeMethod = Hash.DECOR_GET_INT;
50-
} else if (genericType == boolType) {
51-
nativeMethod = Hash.DECOR_GET_BOOL;
52-
} else {
53-
throw new EntityDecorationUndefinedTypeException();
54-
}
55-
56-
return (T) Function.Call<T>(nativeMethod, entity.NativeValue, propertyName);
73+
return (T) Function.Call<T>(nativeMethod, entity.NativeValue, propertyName);
74+
}
5775
}
58-
}
5976

60-
public class EntityDecorationUnregisteredPropertyException : Exception {}
61-
public class EntityDecorationUndefinedTypeException : Exception {}
77+
public class EntityDecorationUnregisteredPropertyException : Exception { }
78+
public class EntityDecorationUndefinedTypeException : Exception { }
6279
}

‎FRFuel.cs

+416-343
Large diffs are not rendered by default.

‎FRFuel.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
<DefineConstants>TRACE</DefineConstants>
3030
<ErrorReport>prompt</ErrorReport>
3131
<WarningLevel>4</WarningLevel>
32-
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
32+
<AllowUnsafeBlocks>false</AllowUnsafeBlocks>
3333
</PropertyGroup>
3434
<ItemGroup>
3535
<Reference Include="CitizenFX.Core">

‎FRFuel.sln

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 14
4+
VisualStudioVersion = 14.0.25420.1
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FRFuel", "FRFuel.csproj", "{11AE476B-DD55-40F9-A374-174808F0C106}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{11AE476B-DD55-40F9-A374-174808F0C106}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{11AE476B-DD55-40F9-A374-174808F0C106}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{11AE476B-DD55-40F9-A374-174808F0C106}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{11AE476B-DD55-40F9-A374-174808F0C106}.Release|Any CPU.Build.0 = Release|Any CPU
18+
{57AFD88B-342A-45AD-B26F-274854E3A068}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
19+
{57AFD88B-342A-45AD-B26F-274854E3A068}.Debug|Any CPU.Build.0 = Debug|Any CPU
20+
{57AFD88B-342A-45AD-B26F-274854E3A068}.Release|Any CPU.ActiveCfg = Release|Any CPU
21+
{57AFD88B-342A-45AD-B26F-274854E3A068}.Release|Any CPU.Build.0 = Release|Any CPU
22+
EndGlobalSection
23+
GlobalSection(SolutionProperties) = preSolution
24+
HideSolutionNode = FALSE
25+
EndGlobalSection
26+
EndGlobal

‎GasStations.cs

+31-29
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,34 @@
11
using CitizenFX.Core;
22

3-
namespace FRFuel {
4-
public static class GasStations {
5-
public static Vector3[] positions = {
6-
new Vector3(49.41872f, 2778.793f, 58.04395f),
7-
new Vector3(263.8949f, 2606.463f, 44.98339f),
8-
new Vector3(1039.958f, 2671.134f, 39.55091f),
9-
new Vector3(1207.26f, 2660.175f, 37.89996f),
10-
new Vector3(2539.685f, 2594.192f, 37.94488f),
11-
new Vector3(2679.858f, 3263.946f, 55.24057f),
12-
new Vector3(2005.055f, 3773.887f, 32.40393f),
13-
new Vector3(1687.156f, 4929.392f, 42.07809f),
14-
new Vector3(1701.314f, 6416.028f, 32.76395f),
15-
new Vector3(179.8573f, 6602.839f, 31.86817f),
16-
new Vector3(-94.46199f, 6419.594f, 31.48952f),
17-
new Vector3(-2554.996f, 2334.402f, 33.07803f),
18-
new Vector3(-1800.375f, 803.6619f, 138.6512f),
19-
new Vector3(-1437.622f, -276.7476f, 46.20771f),
20-
new Vector3(-2096.243f, -320.2867f, 13.16857f),
21-
new Vector3(-724.6192f, -935.1631f, 19.21386f),
22-
new Vector3(-526.0198f, -1211.003f, 18.18483f),
23-
new Vector3(-70.21484f, -1761.792f, 29.53402f),
24-
new Vector3(265.6484f, -1261.309f, 29.29294f),
25-
new Vector3(819.6538f, -1028.846f, 26.40342f),
26-
new Vector3(1208.951f, -1402.567f, 35.22419f),
27-
new Vector3(1181.381f, -330.8471f, 69.31651f),
28-
new Vector3(620.8434f, 269.1009f, 103.0895f),
29-
new Vector3(2581.321f, 362.0393f, 108.4688f)
30-
};
31-
}
3+
namespace FRFuel
4+
{
5+
public static class GasStations
6+
{
7+
public static Vector3[] positions = {
8+
new Vector3(49.41872f, 2778.793f, 58.04395f),
9+
new Vector3(263.8949f, 2606.463f, 44.98339f),
10+
new Vector3(1039.958f, 2671.134f, 39.55091f),
11+
new Vector3(1207.26f, 2660.175f, 37.89996f),
12+
new Vector3(2539.685f, 2594.192f, 37.94488f),
13+
new Vector3(2679.858f, 3263.946f, 55.24057f),
14+
new Vector3(2005.055f, 3773.887f, 32.40393f),
15+
new Vector3(1687.156f, 4929.392f, 42.07809f),
16+
new Vector3(1701.314f, 6416.028f, 32.76395f),
17+
new Vector3(179.8573f, 6602.839f, 31.86817f),
18+
new Vector3(-94.46199f, 6419.594f, 31.48952f),
19+
new Vector3(-2554.996f, 2334.402f, 33.07803f),
20+
new Vector3(-1800.375f, 803.6619f, 138.6512f),
21+
new Vector3(-1437.622f, -276.7476f, 46.20771f),
22+
new Vector3(-2096.243f, -320.2867f, 13.16857f),
23+
new Vector3(-724.6192f, -935.1631f, 19.21386f),
24+
new Vector3(-526.0198f, -1211.003f, 18.18483f),
25+
new Vector3(-70.21484f, -1761.792f, 29.53402f),
26+
new Vector3(265.6484f, -1261.309f, 29.29294f),
27+
new Vector3(819.6538f, -1028.846f, 26.40342f),
28+
new Vector3(1208.951f, -1402.567f, 35.22419f),
29+
new Vector3(1181.381f, -330.8471f, 69.31651f),
30+
new Vector3(620.8434f, 269.1009f, 103.0895f),
31+
new Vector3(2581.321f, 362.0393f, 108.4688f)
32+
};
33+
}
3234
}

‎HUD.cs

+177-160
Original file line numberDiff line numberDiff line change
@@ -2,189 +2,206 @@
22
using CitizenFX.Core;
33
using CitizenFX.Core.UI;
44
using CitizenFX.Core.Native;
5-
using System.Threading.Tasks;
65
using System.Drawing;
76
using TinyTween;
87

9-
namespace FRFuel {
10-
public class HUD {
11-
protected Scaleform buttons = new Scaleform("instructional_buttons");
12-
13-
protected float fuelBarWidth = 180f;
14-
protected float fuelBarHeight = 6f;
15-
16-
protected Color fuelBarColourNormal;
17-
protected Color fuelBarColourWarning;
18-
19-
protected Rectangle fuelBarBackdrop;
20-
protected Rectangle fuelBarBack;
21-
protected Rectangle fuelBar;
22-
23-
public Vector3 markerPutDown = new Vector3(0f, 0f, 3f);
24-
public Vector3 markerDir = new Vector3();
25-
public Vector3 markerRot = new Vector3();
26-
public Vector3 markerScale = new Vector3(15f);
27-
public Color markerColour = Color.FromArgb(50, 255, 179, 0);
28-
29-
protected Tween<float> fuelBarColorTween = new FloatTween();
30-
protected bool fuelBarAnimationDir = true;
31-
protected PointF basePosition = new PointF(0f, 584f);
32-
33-
public PointF Position {
34-
set {
35-
fuelBarBackdrop.Position = value;
36-
fuelBarBack.Position = new PointF(value.X, value.Y + 3f);
37-
fuelBar.Position = fuelBarBack.Position;
38-
}
39-
}
40-
41-
public HUD() {
42-
PointF fuelBarBackdropPosition = basePosition;
43-
PointF fuelBarBackPosition = new PointF(fuelBarBackdropPosition.X, fuelBarBackdropPosition.Y + 3f);
44-
PointF fuelBarPosition = fuelBarBackPosition;
45-
46-
SizeF fuelBarBackdropSize = new SizeF(fuelBarWidth, 12f);
47-
SizeF fuelBarBackSize = new SizeF(fuelBarWidth, fuelBarHeight);
48-
SizeF fuelBarSize = fuelBarBackSize;
8+
namespace FRFuel
9+
{
10+
public class HUD
11+
{
12+
protected Scaleform buttons = new Scaleform("instructional_buttons");
13+
14+
protected float fuelBarWidth = 180f;
15+
protected float fuelBarHeight = 6f;
16+
17+
protected Color fuelBarColourNormal;
18+
protected Color fuelBarColourWarning;
19+
20+
protected Rectangle fuelBarBackdrop;
21+
protected Rectangle fuelBarBack;
22+
protected Rectangle fuelBar;
23+
24+
public Vector3 markerPutDown = new Vector3(0f, 0f, 3f);
25+
public Vector3 markerDir = new Vector3();
26+
public Vector3 markerRot = new Vector3();
27+
public Vector3 markerScale = new Vector3(15f);
28+
public Color markerColour = Color.FromArgb(50, 255, 179, 0);
29+
30+
protected Tween<float> fuelBarColorTween = new FloatTween();
31+
protected bool fuelBarAnimationDir = true;
32+
protected PointF basePosition = new PointF(0f, 584f);
33+
34+
public PointF Position
35+
{
36+
set
37+
{
38+
fuelBarBackdrop.Position = value;
39+
fuelBarBack.Position = new PointF(value.X, value.Y + 3f);
40+
fuelBar.Position = fuelBarBack.Position;
41+
}
42+
}
4943

50-
Color fuelBarBackdropColour = Color.FromArgb(100, 0, 0, 0);
51-
Color fuelBarBackColour = Color.FromArgb(50, 255, 179, 0);
44+
public HUD()
45+
{
46+
PointF fuelBarBackdropPosition = basePosition;
47+
PointF fuelBarBackPosition = new PointF(fuelBarBackdropPosition.X, fuelBarBackdropPosition.Y + 3f);
48+
PointF fuelBarPosition = fuelBarBackPosition;
5249

53-
fuelBarColourNormal = Color.FromArgb(150, 255, 179, 0);
54-
fuelBarColourWarning = Color.FromArgb(255, 255, 245, 220);
50+
SizeF fuelBarBackdropSize = new SizeF(fuelBarWidth, 12f);
51+
SizeF fuelBarBackSize = new SizeF(fuelBarWidth, fuelBarHeight);
52+
SizeF fuelBarSize = fuelBarBackSize;
5553

56-
fuelBarBackdrop = new Rectangle(fuelBarBackdropPosition, fuelBarBackdropSize, fuelBarBackdropColour);
57-
fuelBarBack = new Rectangle(fuelBarBackPosition, fuelBarBackSize, fuelBarBackColour);
58-
fuelBar = new Rectangle(fuelBarPosition, fuelBarSize, fuelBarColourNormal);
59-
}
54+
Color fuelBarBackdropColour = Color.FromArgb(100, 0, 0, 0);
55+
Color fuelBarBackColour = Color.FromArgb(50, 255, 179, 0);
6056

61-
/// <summary>
62-
/// Reloads scaleform movie to ensure that it will be rendered
63-
/// Workaround for bug
64-
/// Looks safe to span on every tick /shrug
65-
/// </summary>
66-
public void ReloadScaleformMovie() {
67-
buttons = new Scaleform("instructional_buttons");
68-
}
57+
fuelBarColourNormal = Color.FromArgb(150, 255, 179, 0);
58+
fuelBarColourWarning = Color.FromArgb(255, 255, 245, 220);
6959

70-
/// <summary>
71-
/// Renders fuel bar
72-
/// </summary>
73-
/// <param name="currentFuelLevel"></param>
74-
/// <param name="maxFuelLevel"></param>
75-
public void RenderBar(float currentFuelLevel, float maxFuelLevel) {
76-
float fuelLevelPercentage = (100f / maxFuelLevel) * currentFuelLevel;
77-
PointF safeZone = GetSafezoneBounds();
78-
79-
Position = new PointF(basePosition.X + safeZone.X, basePosition.Y - safeZone.Y);
80-
81-
fuelBar.Size = new SizeF(
82-
(fuelBarWidth / 100f) * fuelLevelPercentage,
83-
fuelBarHeight
84-
);
85-
86-
if (maxFuelLevel > 0 && currentFuelLevel < 9f) {
87-
if (fuelBarColorTween.State == TweenState.Stopped) {
88-
fuelBarAnimationDir = !fuelBarAnimationDir;
89-
90-
fuelBarColorTween.Start(
91-
fuelBarAnimationDir ? 100f : 255f,
92-
fuelBarAnimationDir ? 255f : 100f,
93-
.5f, // seconds
94-
ScaleFuncs.QuarticEaseOut
95-
);
60+
fuelBarBackdrop = new Rectangle(fuelBarBackdropPosition, fuelBarBackdropSize, fuelBarBackdropColour);
61+
fuelBarBack = new Rectangle(fuelBarBackPosition, fuelBarBackSize, fuelBarBackColour);
62+
fuelBar = new Rectangle(fuelBarPosition, fuelBarSize, fuelBarColourNormal);
9663
}
9764

98-
fuelBarColorTween.Update(Game.LastFrameTime);
65+
/// <summary>
66+
/// Reloads scaleform movie to ensure that it will be rendered
67+
/// Workaround for bug
68+
/// Looks safe to span on every tick /shrug
69+
/// </summary>
70+
public void ReloadScaleformMovie()
71+
{
72+
buttons = new Scaleform("instructional_buttons");
73+
}
9974

100-
fuelBar.Color = Color.FromArgb((int) Math.Floor(fuelBarColorTween.CurrentValue), fuelBarColourWarning);
101-
} else {
102-
fuelBar.Color = fuelBarColourNormal;
75+
/// <summary>
76+
/// Renders fuel bar
77+
/// </summary>
78+
/// <param name="currentFuelLevel"></param>
79+
/// <param name="maxFuelLevel"></param>
80+
public void RenderBar(float currentFuelLevel, float maxFuelLevel)
81+
{
82+
float fuelLevelPercentage = (100f / maxFuelLevel) * currentFuelLevel;
83+
PointF safeZone = GetSafezoneBounds();
84+
85+
Position = new PointF(basePosition.X + safeZone.X, basePosition.Y - safeZone.Y);
86+
87+
fuelBar.Size = new SizeF(
88+
(fuelBarWidth / 100f) * fuelLevelPercentage,
89+
fuelBarHeight
90+
);
91+
92+
if (maxFuelLevel > 0 && currentFuelLevel < 9f)
93+
{
94+
if (fuelBarColorTween.State == TweenState.Stopped)
95+
{
96+
fuelBarAnimationDir = !fuelBarAnimationDir;
97+
98+
fuelBarColorTween.Start(
99+
fuelBarAnimationDir ? 100f : 255f,
100+
fuelBarAnimationDir ? 255f : 100f,
101+
.5f, // seconds
102+
ScaleFuncs.QuarticEaseOut
103+
);
104+
}
105+
106+
fuelBarColorTween.Update(Game.LastFrameTime);
107+
108+
fuelBar.Color = Color.FromArgb((int) Math.Floor(fuelBarColorTween.CurrentValue), fuelBarColourWarning);
109+
}
110+
else
111+
{
112+
fuelBar.Color = fuelBarColourNormal;
113+
114+
if (fuelBarColorTween.State != TweenState.Stopped)
115+
{
116+
fuelBarColorTween.Stop(StopBehavior.ForceComplete);
117+
}
118+
}
119+
120+
fuelBarBackdrop.Draw();
121+
fuelBarBack.Draw();
122+
fuelBar.Draw();
123+
}
103124

104-
if (fuelBarColorTween.State != TweenState.Stopped) {
105-
fuelBarColorTween.Stop(StopBehavior.ForceComplete);
125+
/// <summary>
126+
/// Returns user-configured screen safe zone offset
127+
/// </summary>
128+
/// <returns></returns>
129+
public static PointF GetSafezoneBounds()
130+
{
131+
float t = Function.Call<float>(Hash.GET_SAFE_ZONE_SIZE);
132+
133+
return new PointF(
134+
(int) Math.Round((1280 - (1280 * t)) / 2),
135+
(int) Math.Round((720 - (720 * t)) / 2)
136+
);
106137
}
107-
}
108138

109-
fuelBarBackdrop.Draw();
110-
fuelBarBack.Draw();
111-
fuelBar.Draw();
112-
}
139+
/// <summary>
140+
/// Renders gas station marker
141+
/// </summary>
142+
/// <param name="pos"></param>
143+
public void RenderMarker(Vector3 pos)
144+
{
145+
World.DrawMarker(
146+
MarkerType.VerticalCylinder,
147+
pos - markerPutDown,
148+
markerDir,
149+
markerRot,
150+
markerScale,
151+
markerColour
152+
);
153+
}
113154

114-
/// <summary>
115-
/// Returns user-configure screen safe zone offset
116-
/// </summary>
117-
/// <returns></returns>
118-
public static PointF GetSafezoneBounds() {
119-
float t = Function.Call<float>(Hash.GET_SAFE_ZONE_SIZE);
120-
121-
return new PointF(
122-
(int) Math.Round((1280 - (1280 * t)) / 2),
123-
(int) Math.Round((720 - (720 * t)) / 2)
124-
);
125-
}
155+
/// <summary>
156+
/// Change instructions for engine cut off
157+
/// </summary>
158+
public void InstructTurnOffEngine()
159+
{
160+
buttons.CallFunction("CLEAR_ALL");
161+
buttons.CallFunction("TOGGLE_MOUSE_BUTTONS", 0);
162+
buttons.CallFunction("CREATE_CONTAINER");
126163

127-
/// <summary>
128-
/// Renders gas station marker
129-
/// </summary>
130-
/// <param name="pos"></param>
131-
public void RenderMarker(Vector3 pos) {
132-
World.DrawMarker(
133-
MarkerType.VerticalCylinder,
134-
pos - markerPutDown,
135-
markerDir,
136-
markerRot,
137-
markerScale,
138-
markerColour
139-
);
140-
}
164+
buttons.CallFunction("SET_DATA_SLOT", 0, Function.Call<string>((Hash) 0x0499D7B09FC9B407, 2, (int) Control.VehicleHorn, 0), "Turn off engine");
141165

142-
/// <summary>
143-
/// Change instructions for engine cut off
144-
/// </summary>
145-
public void InstructTurnOffEngine() {
146-
buttons.CallFunction("CLEAR_ALL");
147-
buttons.CallFunction("TOGGLE_MOUSE_BUTTONS", 0);
148-
buttons.CallFunction("CREATE_CONTAINER");
149-
150-
buttons.CallFunction("SET_DATA_SLOT", 0, Function.Call<string>((Hash) 0x0499D7B09FC9B407, 2, (int) Control.VehicleHorn, 0), "Turn off engine");
151-
152-
buttons.CallFunction("DRAW_INSTRUCTIONAL_BUTTONS", -1);
153-
}
166+
buttons.CallFunction("DRAW_INSTRUCTIONAL_BUTTONS", -1);
167+
}
154168

155-
/// <summary>
156-
/// Change instructions for refueling and engine spin up
157-
/// </summary>
158-
public void InstructRefuelOrTurnOnEngine() {
159-
buttons.CallFunction("CLEAR_ALL");
160-
buttons.CallFunction("TOGGLE_MOUSE_BUTTONS", 0);
161-
buttons.CallFunction("CREATE_CONTAINER");
169+
/// <summary>
170+
/// Change instructions for refueling and engine spin up
171+
/// </summary>
172+
public void InstructRefuelOrTurnOnEngine()
173+
{
174+
buttons.CallFunction("CLEAR_ALL");
175+
buttons.CallFunction("TOGGLE_MOUSE_BUTTONS", 0);
176+
buttons.CallFunction("CREATE_CONTAINER");
162177

163-
buttons.CallFunction("SET_DATA_SLOT", 0, Function.Call<string>((Hash) 0x0499D7B09FC9B407, 2, (int) Control.Jump, 0), "Refuel");
164-
buttons.CallFunction("SET_DATA_SLOT", 1, Function.Call<string>((Hash) 0x0499D7B09FC9B407, 2, (int) Control.VehicleHorn, 0), "Turn on engine");
178+
buttons.CallFunction("SET_DATA_SLOT", 0, Function.Call<string>((Hash) 0x0499D7B09FC9B407, 2, (int) Control.Jump, 0), "Refuel");
179+
buttons.CallFunction("SET_DATA_SLOT", 1, Function.Call<string>((Hash) 0x0499D7B09FC9B407, 2, (int) Control.VehicleHorn, 0), "Turn on engine");
165180

166-
buttons.CallFunction("DRAW_INSTRUCTIONAL_BUTTONS", -1);
167-
}
181+
buttons.CallFunction("DRAW_INSTRUCTIONAL_BUTTONS", -1);
182+
}
168183

169-
/// <summary>
170-
/// Change instructions for manual refueling
171-
/// </summary>
172-
/// <param name="label"></param>
173-
public void InstructManualRefuel(string label) {
174-
buttons.CallFunction("CLEAR_ALL");
175-
buttons.CallFunction("TOGGLE_MOUSE_BUTTONS", 0);
176-
buttons.CallFunction("CREATE_CONTAINER");
184+
/// <summary>
185+
/// Change instructions for manual refueling
186+
/// </summary>
187+
/// <param name="label"></param>
188+
public void InstructManualRefuel(string label)
189+
{
190+
buttons.CallFunction("CLEAR_ALL");
191+
buttons.CallFunction("TOGGLE_MOUSE_BUTTONS", 0);
192+
buttons.CallFunction("CREATE_CONTAINER");
177193

178-
buttons.CallFunction("SET_DATA_SLOT", 0, Function.Call<string>((Hash) 0x0499D7B09FC9B407, 2, (int) Control.Attack, 0), label);
194+
buttons.CallFunction("SET_DATA_SLOT", 0, Function.Call<string>((Hash) 0x0499D7B09FC9B407, 2, (int) Control.Attack, 0), label);
179195

180-
buttons.CallFunction("DRAW_INSTRUCTIONAL_BUTTONS", -1);
181-
}
196+
buttons.CallFunction("DRAW_INSTRUCTIONAL_BUTTONS", -1);
197+
}
182198

183-
/// <summary>
184-
/// Renders instruction
185-
/// </summary>
186-
public void RenderInstructions() {
187-
buttons.Render2D();
199+
/// <summary>
200+
/// Renders instruction
201+
/// </summary>
202+
public void RenderInstructions()
203+
{
204+
buttons.Render2D();
205+
}
188206
}
189-
}
190207
}

‎InLoopOutAnimation.cs

+87-72
Original file line numberDiff line numberDiff line change
@@ -1,93 +1,108 @@
11
using CitizenFX.Core;
22
using CitizenFX.Core.Native;
33

4-
namespace FRFuel {
5-
public enum State {
6-
Starting,
7-
Looping,
8-
Ended
9-
}
4+
namespace FRFuel
5+
{
6+
public enum State
7+
{
8+
Starting,
9+
Looping,
10+
Ended
11+
}
1012

11-
public struct Animation {
12-
public string dict;
13-
public string name;
13+
public struct Animation
14+
{
15+
public string dict;
16+
public string name;
1417

15-
public Animation(string animationDictionary, string animationName) {
16-
dict = animationDictionary;
17-
name = animationName;
18+
public Animation(string animationDictionary, string animationName)
19+
{
20+
dict = animationDictionary;
21+
name = animationName;
22+
}
1823
}
19-
}
2024

21-
public class InLoopOutAnimation {
22-
protected Animation start;
23-
protected Animation loop;
24-
protected Animation end;
25+
public class InLoopOutAnimation
26+
{
27+
protected Animation start;
28+
protected Animation loop;
29+
protected Animation end;
2530

26-
protected State state;
31+
protected State state;
2732

28-
public InLoopOutAnimation(Animation start, Animation loop, Animation end) {
29-
this.start = start;
30-
this.loop = loop;
31-
this.end = end;
33+
public InLoopOutAnimation(Animation start, Animation loop, Animation end)
34+
{
35+
this.start = start;
36+
this.loop = loop;
37+
this.end = end;
3238

33-
state = State.Ended;
34-
}
39+
state = State.Ended;
40+
}
3541

36-
public void Magick(Ped ped) {
37-
if (state == State.Ended) {
38-
PlayStart(ped);
39-
return;
40-
}
42+
public void Magick(Ped ped)
43+
{
44+
if (state == State.Ended)
45+
{
46+
PlayStart(ped);
47+
return;
48+
}
4149

42-
if (state == State.Starting) {
43-
if (!IsAnimationPlaying(ped, start)) {
44-
state = State.Looping;
45-
PlayLoop(ped);
50+
if (state == State.Starting)
51+
{
52+
if (!IsAnimationPlaying(ped, start))
53+
{
54+
state = State.Looping;
55+
PlayLoop(ped);
56+
}
57+
}
4658
}
47-
}
48-
}
4959

50-
protected void PlayStart(Ped ped) {
51-
ped.Task.PlayAnimation(
52-
start.dict,
53-
start.name,
54-
8f,
55-
-1,
56-
AnimationFlags.None
57-
);
58-
state = State.Starting;
59-
}
60+
protected void PlayStart(Ped ped)
61+
{
62+
ped.Task.PlayAnimation(
63+
start.dict,
64+
start.name,
65+
8f,
66+
-1,
67+
AnimationFlags.None
68+
);
69+
state = State.Starting;
70+
}
6071

61-
protected void PlayLoop(Ped ped) {
62-
ped.Task.PlayAnimation(
63-
loop.dict,
64-
loop.name,
65-
50f,
66-
-1,
67-
AnimationFlags.Loop
68-
);
69-
state = State.Looping;
70-
}
72+
protected void PlayLoop(Ped ped)
73+
{
74+
ped.Task.PlayAnimation(
75+
loop.dict,
76+
loop.name,
77+
50f,
78+
-1,
79+
AnimationFlags.Loop
80+
);
81+
state = State.Looping;
82+
}
7183

72-
protected void PlayEnd(Ped ped) {
73-
ped.Task.PlayAnimation(
74-
end.dict,
75-
end.name,
76-
8f,
77-
-1,
78-
AnimationFlags.CancelableWithMovement
79-
);
80-
state = State.Ended;
81-
}
84+
protected void PlayEnd(Ped ped)
85+
{
86+
ped.Task.PlayAnimation(
87+
end.dict,
88+
end.name,
89+
8f,
90+
-1,
91+
AnimationFlags.CancelableWithMovement
92+
);
93+
state = State.Ended;
94+
}
8295

83-
public void RewindAndStop(Ped ped) {
84-
Function.Call(Hash.STOP_ENTITY_ANIM, ped.NativeValue, loop.name, loop.dict, true);
96+
public void RewindAndStop(Ped ped)
97+
{
98+
Function.Call(Hash.STOP_ENTITY_ANIM, ped.NativeValue, loop.name, loop.dict, true);
8599

86-
PlayEnd(ped);
87-
}
100+
PlayEnd(ped);
101+
}
88102

89-
protected bool IsAnimationPlaying(Ped ped, Animation anim) {
90-
return Function.Call<bool>(Hash.IS_ENTITY_PLAYING_ANIM, ped.NativeValue, anim.dict, anim.name, 3);
103+
protected bool IsAnimationPlaying(Ped ped, Animation anim)
104+
{
105+
return Function.Call<bool>(Hash.IS_ENTITY_PLAYING_ANIM, ped.NativeValue, anim.dict, anim.name, 3);
106+
}
91107
}
92-
}
93108
}

‎VehiclesPetrolTanks.cs

+370-366
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
Please sign in to comment.