Skip to content

Commit c7866d1

Browse files
authored
Merge pull request #13 from Immersive-Plugins-Team/1.4.1
1.4.1
2 parents fa433e9 + f760266 commit c7866d1

54 files changed

Lines changed: 410 additions & 3168 deletions

Some content is hidden

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

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* @opus49

.github/workflows/release.yml

Lines changed: 0 additions & 60 deletions
This file was deleted.

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
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.1] - 2023-05-27
5+
6+
### Added
7+
- Player Status Handler so that GrammarPolice and CalloutInterface can sync
8+
- The ability to safely retrieve the current weather
9+
- MathHelperExtensions for some vector math and wrap angle
10+
- Notification shortcuts have been added as well
11+
12+
### Removed
13+
- All new GUI elements have been moved to RawCanvasUI
14+
- The callouts.cs code has been moved to CalloutInterface
15+
416
## [1.4] - 2023-04-17
517

618
### Added

IPT.Common/API/Enums.cs

Lines changed: 0 additions & 35 deletions
This file was deleted.

IPT.Common/API/Events.cs

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

43
namespace IPT.Common.API
54
{
@@ -21,6 +20,12 @@ public static class Events
2120
/// <param name="isLongPress">True if it was a long press, otherwise false.</param>
2221
public delegate void HoldableUserInputEventHandler(HoldableCombo combo, bool isLongPress);
2322

23+
/// <summary>
24+
/// Delegate event handler for player status changes.
25+
/// </summary>
26+
/// <param name="playerStatus">The new status.</param>
27+
public delegate void PlayerStatusChangeEventHandler(PlayerStatus playerStatus);
28+
2429
/// <summary>
2530
/// Event for user input changes.
2631
/// </summary>
@@ -31,6 +36,11 @@ public static class Events
3136
/// </summary>
3237
public static event HoldableUserInputEventHandler OnHoldableUserInput;
3338

39+
/// <summary>
40+
/// Event for player status changes.
41+
/// </summary>
42+
public static event PlayerStatusChangeEventHandler OnPlayerStatusChange;
43+
3444
/// <summary>
3545
/// Fires an event for a user input change.
3646
/// </summary>
@@ -49,5 +59,14 @@ internal static void FireHoldableUserInput(HoldableCombo combo, bool isLongPress
4959
{
5060
OnHoldableUserInput?.Invoke(combo, isLongPress);
5161
}
62+
63+
/// <summary>
64+
/// Fires an event for a player status change.
65+
/// </summary>
66+
/// <param name="playerStatus">The new player status.</param>
67+
internal static void FirePlayerStatusChange(PlayerStatus playerStatus)
68+
{
69+
OnPlayerStatusChange?.Invoke(playerStatus);
70+
}
5271
}
5372
}

IPT.Common/API/Functions.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using Rage;
3+
using Rage.Native;
34

45
namespace IPT.Common.API
56
{
@@ -35,5 +36,20 @@ public static Texture LoadTexture(string filename)
3536

3637
return null;
3738
}
39+
40+
/// <summary>
41+
/// Safely gets the current weather.
42+
/// </summary>
43+
/// <returns>The current weather type.</returns>
44+
public static EWeatherType GetWeatherType()
45+
{
46+
int weatherType = NativeFunction.Natives.GET_PREV_WEATHER_TYPE_HASH_NAME<int>();
47+
if (Enum.IsDefined(typeof(EWeatherType), weatherType))
48+
{
49+
return (EWeatherType)weatherType;
50+
}
51+
52+
return EWeatherType.Neutral;
53+
}
3854
}
3955
}

IPT.Common/API/Math.cs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -94,19 +94,6 @@ public static int Snap(int value, int min, int max, int increment)
9494
return cValue;
9595
}
9696

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-
11097
/// <summary>
11198
/// Converts radians into degrees.
11299
/// </summary>
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
using Rage;
2+
3+
namespace IPT.Common.API
4+
{
5+
/// <summary>
6+
/// Math helper.
7+
/// </summary>
8+
public static class MathHelperExtensions
9+
{
10+
/// <summary>
11+
/// Calculates a forward vector.
12+
/// </summary>
13+
/// <param name="heading">The heading for the vector.</param>
14+
/// <returns>A forward vector.</returns>
15+
public static Vector3 GetForwardVector(float heading)
16+
{
17+
var headingRads = MathHelper.ConvertDegreesToRadians(90f - heading);
18+
float x = System.Convert.ToSingle(-System.Math.Cos(headingRads));
19+
float y = System.Convert.ToSingle(System.Math.Sin(headingRads));
20+
return new Vector3(x, y, 0f);
21+
}
22+
23+
/// <summary>
24+
/// Gets the angle (0-180 degrees) between the source and target entities.
25+
/// </summary>
26+
/// <param name="source">The source entity.</param>
27+
/// <param name="target">The target entity.</param>
28+
/// <returns>A double indicating the angle in degrees.</returns>
29+
public static double GetVectorAngle(Entity source, Entity target)
30+
{
31+
var targetVector = target.Position - source.Position;
32+
var dotProduct = Vector3.Dot(source.ForwardVector.ToNormalized(), targetVector.ToNormalized());
33+
return MathHelper.ConvertRadiansToDegrees(System.Math.Acos(dotProduct));
34+
}
35+
36+
/// <summary>
37+
/// Gets the angle (0-180 degrees) between the source and target positions given the heading.
38+
/// </summary>
39+
/// <param name="sourcePosition">The source position.</param>
40+
/// <param name="targetPosition">The target position.</param>
41+
/// <param name="heading">The in-game heading (where 0 degrees is due north).</param>
42+
/// <returns>The offset from 0 degrees (straight towards) between the source and target along a heading.</returns>
43+
public static double GetVectorAngle(Vector3 sourcePosition, Vector3 targetPosition, float heading)
44+
{
45+
var targetVector = targetPosition - sourcePosition;
46+
var forwardVector = GetForwardVector(heading);
47+
var dotProduct = Vector3.Dot(forwardVector.ToNormalized(), targetVector.ToNormalized());
48+
return MathHelper.ConvertRadiansToDegrees(System.Math.Acos(dotProduct));
49+
}
50+
51+
/// <summary>
52+
/// Wraps an angle.
53+
/// </summary>
54+
/// <param name="angle">The angle.</param>
55+
/// <returns>The wrapped angle.</returns>
56+
public static float WrapAngle(float angle)
57+
{
58+
angle %= 360f;
59+
if (angle > 180f)
60+
{
61+
angle -= 360f;
62+
}
63+
else if (angle < -180f)
64+
{
65+
angle += 360f;
66+
}
67+
68+
return angle;
69+
}
70+
}
71+
}

IPT.Common/API/Notifications.cs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
using IPT.Common.Handlers;
2+
using Rage;
3+
4+
namespace IPT.Common.API
5+
{
6+
/// <summary>
7+
/// Notification commands for a consistent style.
8+
/// </summary>
9+
public static class Notifications
10+
{
11+
/// <summary>
12+
/// Sends a notification that looks like a message from the dispatcher.
13+
/// </summary>
14+
/// <param name="message">The message.</param>
15+
public static void DispatchMessage(string message)
16+
{
17+
Game.DisplayNotification($"~b~Dispatch: ~w~{message}");
18+
}
19+
20+
/// <summary>
21+
/// Sends a dispach related notification.
22+
/// </summary>
23+
/// <param name="subtitle">The category of notification.</param>
24+
/// <param name="message">The message.</param>
25+
public static void DispatchNotification(string subtitle, string message)
26+
{
27+
OfficialNotification("DISPATCH", subtitle, message);
28+
}
29+
30+
/// <summary>
31+
/// Sends an official looking notification.
32+
/// </summary>
33+
/// <param name="title">The title of the notification.</param>
34+
/// <param name="subtitle">The substitle of the notification.</param>
35+
/// <param name="message">The message of the notification.</param>
36+
public static void OfficialNotification(string title, string subtitle, string message)
37+
{
38+
Game.DisplayNotification("3dtextures", "mpgroundlogo_cops", title, $"~b~{subtitle}", message);
39+
}
40+
41+
/// <summary>
42+
/// Sends the status notification.
43+
/// </summary>
44+
public static void StatusNotification()
45+
{
46+
string message = $"~w~Callsign: ~g~{PlayerHandler.GetCallsign()}~n~~w~Status: {PlayerHandler.GetStatus().ToColorString()}";
47+
DispatchNotification("~b~Officer Status", message);
48+
}
49+
}
50+
}

IPT.Common/API/Player.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public static class Player
1414
/// <returns>The angle in degrees.</returns>
1515
public static double GetVectorAngleTo(Entity entity)
1616
{
17-
return Math.GetVectorAngle(Game.LocalPlayer.Character, entity);
17+
return MathHelperExtensions.GetVectorAngle(Game.LocalPlayer.Character, entity);
1818
}
1919
}
2020
}

0 commit comments

Comments
 (0)