Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Animation via YTD #153

Merged
merged 17 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 6 additions & 12 deletions LemonUI/Elements/BaseElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@
/// <summary>
/// The 1080 scaled position.
/// </summary>
protected internal PointF literalPosition = PointF.Empty;

Check warning on line 16 in LemonUI/Elements/BaseElement.cs

View workflow job for this annotation

GitHub Actions / lint-and-compile (Debug)

Check warning on line 16 in LemonUI/Elements/BaseElement.cs

View workflow job for this annotation

GitHub Actions / lint-and-compile (Debug)

Field 'literalPosition' should begin with upper-case letter (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1307.md)

Check warning on line 16 in LemonUI/Elements/BaseElement.cs

View workflow job for this annotation

GitHub Actions / lint-and-compile (Release)

Check warning on line 16 in LemonUI/Elements/BaseElement.cs

View workflow job for this annotation

GitHub Actions / lint-and-compile (Release)

Field 'literalPosition' should begin with upper-case letter (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1307.md)

Check warning on line 16 in LemonUI/Elements/BaseElement.cs

View workflow job for this annotation

GitHub Actions / lint-and-compile (Debug)

Check warning on line 16 in LemonUI/Elements/BaseElement.cs

View workflow job for this annotation

GitHub Actions / lint-and-compile (Debug)

Field 'literalPosition' should begin with upper-case letter (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1307.md)

Check warning on line 16 in LemonUI/Elements/BaseElement.cs

View workflow job for this annotation

GitHub Actions / lint-and-compile (Release)

Check warning on line 16 in LemonUI/Elements/BaseElement.cs

View workflow job for this annotation

GitHub Actions / lint-and-compile (Release)

Field 'literalPosition' should begin with upper-case letter (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1307.md)
/// <summary>
/// The relative position between 0 and 1.
/// </summary>
protected internal PointF relativePosition = PointF.Empty;

Check warning on line 20 in LemonUI/Elements/BaseElement.cs

View workflow job for this annotation

GitHub Actions / lint-and-compile (Debug)

Check warning on line 20 in LemonUI/Elements/BaseElement.cs

View workflow job for this annotation

GitHub Actions / lint-and-compile (Debug)

Field 'relativePosition' should begin with upper-case letter (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1307.md)

Check warning on line 20 in LemonUI/Elements/BaseElement.cs

View workflow job for this annotation

GitHub Actions / lint-and-compile (Release)

Check warning on line 20 in LemonUI/Elements/BaseElement.cs

View workflow job for this annotation

GitHub Actions / lint-and-compile (Release)

Field 'relativePosition' should begin with upper-case letter (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1307.md)

Check warning on line 20 in LemonUI/Elements/BaseElement.cs

View workflow job for this annotation

GitHub Actions / lint-and-compile (Debug)

Check warning on line 20 in LemonUI/Elements/BaseElement.cs

View workflow job for this annotation

GitHub Actions / lint-and-compile (Debug)

Field 'relativePosition' should begin with upper-case letter (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1307.md)

Check warning on line 20 in LemonUI/Elements/BaseElement.cs

View workflow job for this annotation

GitHub Actions / lint-and-compile (Release)

Check warning on line 20 in LemonUI/Elements/BaseElement.cs

View workflow job for this annotation

GitHub Actions / lint-and-compile (Release)

Field 'relativePosition' should begin with upper-case letter (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1307.md)
/// <summary>
/// The 1080 scaled size.
/// </summary>
protected internal SizeF literalSize = SizeF.Empty;

Check warning on line 24 in LemonUI/Elements/BaseElement.cs

View workflow job for this annotation

GitHub Actions / lint-and-compile (Debug)

Check warning on line 24 in LemonUI/Elements/BaseElement.cs

View workflow job for this annotation

GitHub Actions / lint-and-compile (Debug)

Check warning on line 24 in LemonUI/Elements/BaseElement.cs

View workflow job for this annotation

GitHub Actions / lint-and-compile (Release)

Check warning on line 24 in LemonUI/Elements/BaseElement.cs

View workflow job for this annotation

GitHub Actions / lint-and-compile (Release)

Check warning on line 24 in LemonUI/Elements/BaseElement.cs

View workflow job for this annotation

GitHub Actions / lint-and-compile (Debug)

Check warning on line 24 in LemonUI/Elements/BaseElement.cs

View workflow job for this annotation

GitHub Actions / lint-and-compile (Debug)

Check warning on line 24 in LemonUI/Elements/BaseElement.cs

View workflow job for this annotation

GitHub Actions / lint-and-compile (Release)

Check warning on line 24 in LemonUI/Elements/BaseElement.cs

View workflow job for this annotation

GitHub Actions / lint-and-compile (Release)

/// <summary>
/// The relative size between 0 and 1.
/// </summary>
protected internal SizeF relativeSize = SizeF.Empty;

Check warning on line 28 in LemonUI/Elements/BaseElement.cs

View workflow job for this annotation

GitHub Actions / lint-and-compile (Debug)

Check warning on line 28 in LemonUI/Elements/BaseElement.cs

View workflow job for this annotation

GitHub Actions / lint-and-compile (Release)

Check warning on line 28 in LemonUI/Elements/BaseElement.cs

View workflow job for this annotation

GitHub Actions / lint-and-compile (Debug)

Check warning on line 28 in LemonUI/Elements/BaseElement.cs

View workflow job for this annotation

GitHub Actions / lint-and-compile (Debug)

Field 'relativeSize' should begin with upper-case letter (https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1307.md)

Check warning on line 28 in LemonUI/Elements/BaseElement.cs

View workflow job for this annotation

GitHub Actions / lint-and-compile (Release)


#endregion

Expand All @@ -34,12 +34,9 @@
/// <summary>
/// The Position of the drawable.
/// </summary>
public PointF Position
public virtual PointF Position
{
get
{
return literalPosition;
}
get => literalPosition;
set
{
literalPosition = value;
Expand All @@ -49,12 +46,9 @@
/// <summary>
/// The Size of the drawable.
/// </summary>
public SizeF Size
public virtual SizeF Size
{
get
{
return literalSize;
}
get => literalSize;
set
{
literalSize = value;
Expand All @@ -64,11 +58,11 @@
/// <summary>
/// The Color of the drawable.
/// </summary>
public Color Color { get; set; } = Color.FromArgb(255, 255, 255, 255);
public virtual Color Color { get; set; } = Color.FromArgb(255, 255, 255, 255);
/// <summary>
/// The rotation of the drawable.
/// </summary>
public float Heading { get; set; } = 0;
public virtual float Heading { get; set; } = 0;

#endregion

Expand Down
148 changes: 148 additions & 0 deletions LemonUI/Elements/ScaledAnim.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
#if ALTV
using AltV.Net.Client;
#elif FIVEM
using CitizenFX.Core;
#elif RAGEMP
using RAGE.Game;
#elif RPH
using Rage.Native;
#elif SHVDN3 || SHVDNC
using GTA;
#endif
using System;
using System.Drawing;

namespace LemonUI.Elements
{
/// <summary>
/// A scaled animation using YTD files with all of the frames.
/// </summary>
public class ScaledAnim : ScaledTexture
{
#region Fields

private float frameRate;
private int start = 0;
private int duration;

#endregion

#region Properties

/// <summary>
/// The total number of frames per second.
/// </summary>
public float FrameRate
{
get => frameRate;
set
{
if (value <= 0)
{
throw new ArgumentOutOfRangeException(nameof(value), "The Frame Rate can't be equal or lower to zero.");
}

frameRate = value;
}
}
/// <summary>
/// The duration of the animation in milliseconds.
/// </summary>
public int Duration
{
get => duration;
set
{
if (value < 0)
{
throw new ArgumentOutOfRangeException(nameof(value), "The duration can't be under zero.");
}

duration = value;
}
}

#endregion

#region Constructors

/// <summary>
/// Creates a new dictionary based animation.
/// </summary>
/// <param name="dict">The texture dictionary (YTD) to use.</param>
public ScaledAnim(string dict) : this(dict, PointF.Empty, SizeF.Empty)
{
}
/// <summary>
/// Creates a new dictionary based animation.
/// </summary>
/// <param name="dict">The texture dictionary (YTD) to use.</param>
/// <param name="size">The size of the animation.</param>
public ScaledAnim(string dict, SizeF size) : this(dict, PointF.Empty, size)
{
}
/// <summary>
/// Creates a new dictionary based animation.
/// </summary>
/// <param name="dict">The texture dictionary (YTD) to use.</param>
/// <param name="pos">The position of the animation.</param>
/// <param name="size">The size of the animation.</param>
public ScaledAnim(string dict, PointF pos, SizeF size) : base(pos, size, dict, string.Empty)
{
Dictionary = dict ?? throw new ArgumentNullException(nameof(dict));
}

#endregion

#region Functions

/// <summary>
/// Draws the animation.
/// </summary>
public override void Draw()
{
if (Duration <= 0)
{
return;
}

#if ALTV
int time = Alt.Natives.GetGameTimer();
#elif RAGEMP
int time = Misc.GetGameTimer();
#elif RPH
int time = NativeFunction.CallByHash<int>(0x9CD27B0045628463);
#elif FIVEM || SHVDN3 || SHVDNC
int time = Game.GameTime;
#endif

int end = start + Duration;

if (start == 0 || end <= time)
{
start = time;
}

float progress = (time - (float)start) / Duration;
int totalFrames = (int)((duration / 1000.0f) * frameRate);
int currentFrame = (int)(totalFrames * progress) + 1;

if (progress < 0)
{
currentFrame = 1;
start = time;
}
else if (currentFrame >= totalFrames)
{
currentFrame = totalFrames;
start = time;
}

Texture = currentFrame.ToString();

base.Draw();
}

#endregion
}
}
Loading