Skip to content

Commit fa433e9

Browse files
authored
Merge pull request #12 from Immersive-Plugins-Team/gui
Added RawUI
2 parents e2d29f2 + bf4a685 commit fa433e9

46 files changed

Lines changed: 3125 additions & 14 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
# Changelog
22
_The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/)._
33

4+
## [1.4] - 2023-04-17
5+
6+
### Added
7+
- GUI classes (BaseFrame, Cursor, TextureFrame, TextureSprite)
8+
- New functions in Math class to handle some trig
9+
- New static Player class to interact with aforementioned functions
10+
411
## [1.3] - 2022-01-31
512

613
### Added
@@ -13,7 +20,6 @@ _The format is based on [Keep a Changelog](http://keepachangelog.com/) and this
1320
### Fixed
1421
- GetCalloutFromHandler is now safer
1522

16-
1723
## [1.2] - 2022-01-17
1824

1925
### Added

IPT.Common/API/Enums.cs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
namespace IPT.Common.API
2+
{
3+
#pragma warning disable 1591, SA1602
4+
5+
/// <summary>
6+
/// The cursor type.
7+
/// </summary>
8+
public enum CursorType
9+
{
10+
Default,
11+
Pointing,
12+
Resizing,
13+
}
14+
15+
/// <summary>
16+
/// The mouse status.
17+
/// </summary>
18+
public enum MouseStatus
19+
{
20+
Up,
21+
Down,
22+
}
23+
24+
/// <summary>
25+
/// A scroll or mouse wheel status.
26+
/// </summary>
27+
public enum ScrollWheelStatus
28+
{
29+
Up,
30+
Down,
31+
None,
32+
}
33+
34+
#pragma warning restore 1591, SA1602
35+
}

IPT.Common/API/Events.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using IPT.Common.User.Inputs;
1+
using System;
2+
using IPT.Common.User.Inputs;
23

34
namespace IPT.Common.API
45
{

IPT.Common/API/Functions.cs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
namespace IPT.Common.API
1+
using System;
2+
using Rage;
3+
4+
namespace IPT.Common.API
25
{
36
/// <summary>
47
/// Common helper functions.
@@ -13,5 +16,24 @@ public static bool IsGamePaused()
1316
{
1417
return Rage.Game.IsPaused || Rage.Native.NativeFunction.Natives.IS_PAUSE_MENU_ACTIVE<bool>();
1518
}
19+
20+
/// <summary>
21+
/// Loads a texture from disk.
22+
/// </summary>
23+
/// <param name="filename">The filename of the texture.</param>
24+
/// <returns>A Rage texture object.</returns>
25+
public static Texture LoadTexture(string filename)
26+
{
27+
try
28+
{
29+
return Game.CreateTextureFromFile(filename);
30+
}
31+
catch (Exception ex)
32+
{
33+
API.Logging.Error("could not load texture", ex);
34+
}
35+
36+
return null;
37+
}
1638
}
1739
}

IPT.Common/API/Math.cs

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
1-
namespace IPT.Common.API
1+
using Rage;
2+
3+
namespace IPT.Common.API
24
{
35
/// <summary>
46
/// Additional math-related functions.
57
/// </summary>
68
public static class Math
79
{
10+
/// <summary>
11+
/// A value used for converting radians to degrees.
12+
/// </summary>
13+
public static readonly double Rad2Deg = 180.0 / System.Math.PI;
14+
15+
/// <summary>
16+
/// A value used for converting degrees to radians.
17+
/// </summary>
18+
public static readonly double Deg2Rad = System.Math.PI / 180.0;
19+
820
/// <summary>
921
/// Clamps a float between two (inclusive) values.
1022
/// </summary>
@@ -81,5 +93,38 @@ public static int Snap(int value, int min, int max, int increment)
8193

8294
return cValue;
8395
}
96+
97+
/// <summary>
98+
/// Gets the angle (0-180 degrees) between the source and target entities.
99+
/// </summary>
100+
/// <param name="source">The source entity.</param>
101+
/// <param name="target">The target entity.</param>
102+
/// <returns>A double indicating the angle in degrees.</returns>
103+
public static double GetVectorAngle(Entity source, Entity target)
104+
{
105+
var targetVector = target.Position - source.Position;
106+
var dotProduct = Vector3.Dot(source.ForwardVector.ToNormalized(), targetVector.ToNormalized());
107+
return ConvertRadiansToDegrees(System.Math.Acos(dotProduct));
108+
}
109+
110+
/// <summary>
111+
/// Converts radians into degrees.
112+
/// </summary>
113+
/// <param name="radians">The initial value in radians.</param>
114+
/// <returns>A double value representing the radians in degrees.</returns>
115+
public static double ConvertRadiansToDegrees(double radians)
116+
{
117+
return radians * Rad2Deg;
118+
}
119+
120+
/// <summary>
121+
/// Converts degrees into radians.
122+
/// </summary>
123+
/// <param name="degrees">The initial value in degrees.</param>
124+
/// <returns>A double value representing the degrees in radians.</returns>
125+
public static double ConvertDegreesToRadians(double degrees)
126+
{
127+
return degrees * Deg2Rad;
128+
}
84129
}
85130
}

IPT.Common/API/Player.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using Rage;
2+
3+
namespace IPT.Common.API
4+
{
5+
/// <summary>
6+
/// Helpful player functions.
7+
/// </summary>
8+
public static class Player
9+
{
10+
/// <summary>
11+
/// Gets the angle between the player and the entity.
12+
/// </summary>
13+
/// <param name="entity">The target entity.</param>
14+
/// <returns>The angle in degrees.</returns>
15+
public static double GetVectorAngleTo(Entity entity)
16+
{
17+
return Math.GetVectorAngle(Game.LocalPlayer.Character, entity);
18+
}
19+
}
20+
}

IPT.Common/Callouts.cs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Collections.Generic;
22
using System.Linq;
33
using System.Reflection;
4+
using IPT.Common.API;
45

56
namespace IPT.Common
67
{
@@ -51,18 +52,29 @@ public static Dictionary<string, List<string>> GetCallouts()
5152
foreach (var plugin in LSPD_First_Response.Mod.API.Functions.GetAllUserPlugins())
5253
{
5354
var names = new List<string>();
54-
foreach (var callout in plugin.GetTypes().Where(x => typeof(LSPD_First_Response.Mod.Callouts.Callout).IsAssignableFrom(x)))
55+
try
5556
{
56-
var attribute = callout.GetCustomAttributes(typeof(LSPD_First_Response.Mod.Callouts.CalloutInfoAttribute), true).FirstOrDefault();
57-
if (attribute is LSPD_First_Response.Mod.Callouts.CalloutInfoAttribute calloutInfo)
57+
foreach (var callout in plugin.GetTypes().Where(x => typeof(LSPD_First_Response.Mod.Callouts.Callout).IsAssignableFrom(x)))
5858
{
59-
names.Add(calloutInfo.Name);
59+
var attribute = callout.GetCustomAttributes(typeof(LSPD_First_Response.Mod.Callouts.CalloutInfoAttribute), true).FirstOrDefault();
60+
if (attribute is LSPD_First_Response.Mod.Callouts.CalloutInfoAttribute calloutInfo)
61+
{
62+
names.Add(calloutInfo.Name);
63+
}
6064
}
61-
}
6265

63-
if (names.Any())
66+
if (names.Any())
67+
{
68+
callouts[plugin.GetName().Name] = names;
69+
}
70+
}
71+
catch (System.Reflection.ReflectionTypeLoadException ex)
6472
{
65-
callouts[plugin.GetName().Name] = names;
73+
Logging.Warning($"there was an error while trying to access plugin: {plugin.FullName}");
74+
foreach (var entry in ex.LoaderExceptions)
75+
{
76+
Logging.Error($"{plugin.FullName}: ", entry);
77+
}
6678
}
6779
}
6880

0 commit comments

Comments
 (0)