Skip to content

Commit

Permalink
Merge branch 'patch-1'
Browse files Browse the repository at this point in the history
  • Loading branch information
TomGrobbe committed Mar 18, 2019
2 parents b3132b7 + dc67691 commit 3763567
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 65,519 deletions.
18 changes: 18 additions & 0 deletions FRFuel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ public class FRFuel : BaseScript

protected bool initialized = false;
public static Control engineToggleControl = Control.VehicleHorn;

private string fuelBarNormalHexColor = "FFB300"; // 255, 179, 0
private string fuelBarWarningHexColor = "FFF5DC"; // 255, 179, 0
#endregion

/// <summary>
Expand Down Expand Up @@ -150,6 +153,20 @@ protected void LoadConfig()
{
engineToggleControl = (Control)tmpControl;
}

fuelBarNormalHexColor = Config.Get("FuelBarNormalColor", fuelBarNormalHexColor).Replace("\"", "").Replace("#", "");
// normal color
int r = MathUtil.Clamp(int.Parse(fuelBarNormalHexColor.Substring(0, 2), System.Globalization.NumberStyles.HexNumber), 0, 255);
int g = MathUtil.Clamp(int.Parse(fuelBarNormalHexColor.Substring(2, 2), System.Globalization.NumberStyles.HexNumber), 0, 255);
int b = MathUtil.Clamp(int.Parse(fuelBarNormalHexColor.Substring(4, 2), System.Globalization.NumberStyles.HexNumber), 0, 255);

fuelBarWarningHexColor = Config.Get("FuelBarWarningColor", fuelBarNormalHexColor).Replace("\"", "").Replace("#", "");
// warning color
int wR = MathUtil.Clamp(int.Parse(fuelBarWarningHexColor.Substring(0, 2), System.Globalization.NumberStyles.HexNumber), 0, 255);
int wG = MathUtil.Clamp(int.Parse(fuelBarWarningHexColor.Substring(2, 2), System.Globalization.NumberStyles.HexNumber), 0, 255);
int wB = MathUtil.Clamp(int.Parse(fuelBarWarningHexColor.Substring(4, 2), System.Globalization.NumberStyles.HexNumber), 0, 255);
hud.UpdateBarColors(r, g, b, wR, wG, wB);

#if DEBUG
Debug.WriteLine($"CreatePickups: {Config.Get("CreatePickups", "true")}");
Debug.WriteLine($"ShowHud: {Config.Get("ShowHud", "true")}");
Expand Down Expand Up @@ -235,6 +252,7 @@ public async Task ManageNearbyJerryCanPickUps()
}
});
}
await Task.FromResult(0);
}
#endregion

Expand Down
14 changes: 9 additions & 5 deletions FRFuel.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,23 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<DebugType>embedded</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>false</AllowUnsafeBlocks>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>
<ItemGroup>
<Reference Include="CitizenFX.Core">
<HintPath>dist\CitizenFX.Core.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Newtonsoft.Json, Version=11.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>dist\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
Expand All @@ -67,6 +65,12 @@
<None Include="LICENSE.md" />
<None Include="README.md" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="CitizenFX.Core.Client">
<Version>1.0.1132</Version>
<ExcludeAssets>runtime</ExcludeAssets>
</PackageReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>
Expand Down
75 changes: 54 additions & 21 deletions HUD.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,24 @@ public class HUD
{
protected Scaleform buttons = new Scaleform("instructional_buttons");

protected float fuelBarWidth = GetBarWidth();
protected float fuelBarWidth() { return GetBarWidth(); }
protected float fuelBarHeight = 6f;

protected Color fuelBarColourNormal;
protected Color fuelBarColourWarning;

protected Rectangle fuelBarBackdrop;
protected Rectangle fuelBarBack;
protected Rectangle fuelBar;
protected CitizenFX.Core.UI.Rectangle fuelBarBackdrop;
protected CitizenFX.Core.UI.Rectangle fuelBarBack;
protected CitizenFX.Core.UI.Rectangle fuelBar;

protected Tween<float> fuelBarColorTween = new FloatTween();
protected bool fuelBarAnimationDir = true;
protected PointF basePosition = new PointF(0f, 584f);

protected SizeF fuelBarBackdropSize;
protected SizeF fuelBarBackSize;
protected SizeF fuelBarSize;

public PointF Position
{
set
Expand All @@ -42,19 +46,35 @@ public HUD()
PointF fuelBarBackPosition = new PointF(fuelBarBackdropPosition.X, fuelBarBackdropPosition.Y + 3f);
PointF fuelBarPosition = fuelBarBackPosition;

SizeF fuelBarBackdropSize = new SizeF(fuelBarWidth, 12f);
SizeF fuelBarBackSize = new SizeF(fuelBarWidth, fuelBarHeight);
SizeF fuelBarSize = fuelBarBackSize;
fuelBarBackdropSize = new SizeF(fuelBarWidth(), 12f);
fuelBarBackSize = new SizeF(fuelBarWidth(), fuelBarHeight);
fuelBarSize = fuelBarBackSize;

Color fuelBarBackdropColour = Color.FromArgb(100, 0, 0, 0);
Color fuelBarBackColour = Color.FromArgb(50, 255, 179, 0);

/// Default colors will be changed in the <see cref="FRFuel.LoadConfig"/> function, by calling the <see cref="UpdateBarColors"/> function.
fuelBarColourNormal = Color.FromArgb(150, 255, 179, 0);
fuelBarColourWarning = Color.FromArgb(255, 255, 245, 220);

fuelBarBackdrop = new Rectangle(fuelBarBackdropPosition, fuelBarBackdropSize, fuelBarBackdropColour);
fuelBarBack = new Rectangle(fuelBarBackPosition, fuelBarBackSize, fuelBarBackColour);
fuelBar = new Rectangle(fuelBarPosition, fuelBarSize, fuelBarColourNormal);
fuelBarBackdrop = new CitizenFX.Core.UI.Rectangle(fuelBarBackdropPosition, fuelBarBackdropSize, fuelBarBackdropColour);
fuelBarBack = new CitizenFX.Core.UI.Rectangle(fuelBarBackPosition, fuelBarBackSize, fuelBarBackColour);
fuelBar = new CitizenFX.Core.UI.Rectangle(fuelBarPosition, fuelBarSize, fuelBarColourNormal);
}

/// <summary>
/// Updates the <see cref="fuelBarColourNormal"/> and <see cref="fuelBarColourWarning"/> colors.
/// </summary>
/// <param name="red"></param>
/// <param name="green"></param>
/// <param name="blue"></param>
/// <param name="warningRed"></param>
/// <param name="warningGreen"></param>
/// <param name="warningBlue"></param>
public void UpdateBarColors(int red, int green, int blue, int warningRed, int warningGreen, int warningBlue)
{
fuelBarColourNormal = Color.FromArgb(150, red, green, blue);
fuelBarColourWarning = Color.FromArgb(255, warningRed, warningGreen, warningBlue);
}

/// <summary>
Expand All @@ -77,12 +97,24 @@ public void RenderBar(float currentFuelLevel, float maxFuelLevel)
float fuelLevelPercentage = (100f / maxFuelLevel) * currentFuelLevel;
PointF safeZone = GetSafezoneBounds();

Position = new PointF(basePosition.X + safeZone.X, basePosition.Y - safeZone.Y);
if (IsBigmapActive())
{
Position = new PointF(basePosition.X + safeZone.X, basePosition.Y - safeZone.Y - 180f);
}
else
{
Position = new PointF(basePosition.X + safeZone.X, basePosition.Y - safeZone.Y);
}

fuelBarBackdropSize = new SizeF(fuelBarWidth(), 12f);
fuelBarSize = new SizeF((fuelBarWidth() / 100f) * fuelLevelPercentage, fuelBarHeight);
fuelBarBackSize = fuelBarSize;

fuelBar.Size = fuelBarSize;
fuelBarBackdrop.Size = fuelBarBackdropSize;
fuelBarBack.Size = fuelBarBackSize;


fuelBar.Size = new SizeF(
(fuelBarWidth / 100f) * fuelLevelPercentage,
fuelBarHeight
);

if (maxFuelLevel > 0 && currentFuelLevel < 9f)
{
Expand Down Expand Up @@ -155,26 +187,27 @@ public static float GetBarWidth()
{
float width;
double aspect = Screen.AspectRatio;
bool bigMap = IsBigmapActive();

switch (aspect)
{
case (float)1.5: // 3:2
width = 212f;
width = bigMap ? 336f : 212f;
break;
case (float)1.33333337306976: // 4:3
width = 240f;
width = bigMap ? 378f : 240f;
break;
case (float)1.66666662693024: // 5:3
width = 191f;
width = bigMap ? 302f : 191f;
break;
case (float)1.25: // 5:4
width = 255f;
width = bigMap ? 405f : 255f;
break;
case (float)1.60000002384186: // 16:10
width = 200f;
width = bigMap ? 316f : 200f;
break;
default:
width = 180f; // 16:9
width = bigMap ? 285f : 180f; // 16:9
break;
}
return width;
Expand Down
Binary file removed dist/CitizenFX.Core.dll
Binary file not shown.
Loading

0 comments on commit 3763567

Please sign in to comment.