Skip to content

Commit

Permalink
Merge branch 'master' into fork/master
Browse files Browse the repository at this point in the history
  • Loading branch information
justalemon committed Dec 19, 2023
2 parents b596fa0 + 9f12ff3 commit 7889b05
Show file tree
Hide file tree
Showing 28 changed files with 1,077 additions and 443 deletions.
20 changes: 7 additions & 13 deletions LemonUI/Elements/BaseElement.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using LemonUI.Extensions;
using System.Drawing;
using LemonUI.Tools;

namespace LemonUI.Elements
{
Expand Down Expand Up @@ -34,12 +34,9 @@ public abstract class BaseElement : I2Dimensional
/// <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 @@ public PointF Position
/// <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 @@ public SizeF Size
/// <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
}
}
187 changes: 187 additions & 0 deletions LemonUI/Elements/ScaledBink.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
#if ALTV
using AltV.Net.Client;
#elif FIVEM
using CitizenFX.Core.Native;
#elif RAGEMP
using RAGE.Game;
#elif RPH
using Rage.Native;
#elif SHVDN3 || SHVDNC
using GTA.Native;
#endif
using System;
using System.Drawing;

namespace LemonUI.Elements
{
/// <summary>
/// A Bink Video file.
/// </summary>
public class ScaledBink : BaseElement, IDisposable
{
#region Fields

private string name = string.Empty;

#endregion

#region Properties

/// <summary>
/// The ID of the Bink Video Instance.
/// </summary>
public int Id { get; private set; } = -1;
/// <summary>
/// The name of the Bink Video file.
/// </summary>
public string Name
{
get => name;
set
{
name = value ?? throw new ArgumentNullException(nameof(value));

#if ALTV
Id = Alt.Natives.SetBinkMovie(name);
#elif FIVEM
Id = API.SetBinkMovie(name);
#elif RAGEMP
Id = Invoker.Invoke<int>(0xfc36643f7a64338f, name);
#elif RPH
Id = NativeFunction.CallByHash<int>(0xfc36643f7a64338f, name);
#elif SHVDN3 || SHVDNC
Id = Function.Call<int>(Hash.SET_BINK_MOVIE, name);
#endif
}
}

#endregion

#region Constructors

/// <summary>
/// Creates a new Bink Video playback.
/// </summary>
/// <param name="name">The name of the bik file.</param>
public ScaledBink(string name) : this(name, PointF.Empty, SizeF.Empty)
{
}
/// <summary>
/// Creates a new Bink Video playback.
/// </summary>
/// <param name="name">The name of the bik file.</param>
/// <param name="size">The size of the video window.</param>
public ScaledBink(string name, SizeF size) : this(name, PointF.Empty, size)
{
}
/// <summary>
/// Creates a new Bink Video playback.
/// </summary>
/// <param name="name">The name of the bik file.</param>
/// <param name="pos">The position of the video window.</param>
/// <param name="size">The size of the video window.</param>
public ScaledBink(string name, PointF pos, SizeF size) : base(pos, size)
{
Name = name ?? throw new ArgumentNullException(nameof(name));
}

#endregion

#region Finalizer

/// <summary>
/// Finalizes an instance of the <see cref="ScaledBink"/> class.
/// </summary>
~ScaledBink() => Dispose();

#endregion

#region Functions

/// <summary>
/// Draws the Bink Movie at the specified location.
/// </summary>
public override void Draw()
{
if (Id == -1)
{
return;
}

#if ALTV
Alt.Natives.PlayBinkMovie(Id);
Alt.Natives.DrawBinkMovie(Id, relativePosition.X, relativePosition.Y, relativeSize.Width, relativeSize.Height, 0.0f, 255, 255, 255, 255);
#elif FIVEM
API.PlayBinkMovie(Id);
API.DrawBinkMovie(Id, relativePosition.X, relativePosition.Y, relativeSize.Width, relativeSize.Height, 0.0f, 255, 255, 255, 255);
#elif RAGEMP
Invoker.Invoke<int>(0xE178310643033958, Id);
Invoker.Invoke<int>(0x7118E83EEB9F7238, Id, relativePosition.X, relativePosition.Y, relativeSize.Width, relativeSize.Height, 0.0f, 255, 255, 255, 255);
#elif RPH
NativeFunction.CallByHash<int>(0xE178310643033958, Id);
NativeFunction.CallByHash<int>(0x7118E83EEB9F7238, Id, relativePosition.X, relativePosition.Y, relativeSize.Width, relativeSize.Height, 0.0f, 255, 255, 255, 255);
#elif SHVDN3 || SHVDNC
Function.Call<int>(Hash.PLAY_BINK_MOVIE, Id);
Function.Call<int>(Hash.DRAW_BINK_MOVIE, Id, relativePosition.X, relativePosition.Y, relativeSize.Width, relativeSize.Height, 0.0f, 255, 255, 255, 255);
#endif
}
/// <summary>
/// Stops the playback of the Bink Video.
/// </summary>
/// <remarks>
/// If <see cref="Draw"/> is called after this function. playback will start again.
/// </remarks>
public void Stop()
{
if (Id == -1)
{
return;
}

#if ALTV
Alt.Natives.StopBinkMovie(Id);
#elif FIVEM
API.StopBinkMovie(Id);
#elif RAGEMP
Invoker.Invoke<int>(0x63606A61DE68898A, Id);
#elif RPH
NativeFunction.CallByHash<int>(0x63606A61DE68898A, Id);
#elif SHVDN3 || SHVDNC
Function.Call<int>(Hash.STOP_BINK_MOVIE, Id);
#endif
}
/// <summary>
/// Disposes the Bink Video ID.
/// </summary>
public void Dispose()
{
if (Id == -1)
{
return;
}

#if ALTV
Alt.Natives.ReleaseBinkMovie(Id);
#elif FIVEM
API.ReleaseBinkMovie(Id);
#elif RAGEMP
Invoker.Invoke<int>(0x04D950EEFA4EED8C, Id);
#elif RPH
NativeFunction.CallByHash<int>(0x04D950EEFA4EED8C, Id);
#elif SHVDN3 || SHVDNC
Function.Call<int>(Hash.RELEASE_BINK_MOVIE, Id);
#endif

Id = -1;
}
/// <inheritdoc/>
public override void Recalculate()
{
base.Recalculate();
relativePosition.X += relativeSize.Width * 0.5f;
relativePosition.Y += relativeSize.Height * 0.5f;
}

#endregion
}
}
Loading

0 comments on commit 7889b05

Please sign in to comment.