-
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into fork/master
- Loading branch information
Showing
28 changed files
with
1,077 additions
and
443 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
Oops, something went wrong.