Skip to content

Commit

Permalink
Merge pull request #13 from Immersive-Plugins-Team/1.4.1
Browse files Browse the repository at this point in the history
1.4.1
  • Loading branch information
opus49 authored May 28, 2023
2 parents fa433e9 + f760266 commit c7866d1
Show file tree
Hide file tree
Showing 54 changed files with 410 additions and 3,168 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @opus49
60 changes: 0 additions & 60 deletions .github/workflows/release.yml

This file was deleted.

12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
# Changelog
_The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/)._

## [1.4.1] - 2023-05-27

### Added
- Player Status Handler so that GrammarPolice and CalloutInterface can sync
- The ability to safely retrieve the current weather
- MathHelperExtensions for some vector math and wrap angle
- Notification shortcuts have been added as well

### Removed
- All new GUI elements have been moved to RawCanvasUI
- The callouts.cs code has been moved to CalloutInterface

## [1.4] - 2023-04-17

### Added
Expand Down
35 changes: 0 additions & 35 deletions IPT.Common/API/Enums.cs

This file was deleted.

23 changes: 21 additions & 2 deletions IPT.Common/API/Events.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using IPT.Common.User.Inputs;
using IPT.Common.User.Inputs;

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

/// <summary>
/// Delegate event handler for player status changes.
/// </summary>
/// <param name="playerStatus">The new status.</param>
public delegate void PlayerStatusChangeEventHandler(PlayerStatus playerStatus);

/// <summary>
/// Event for user input changes.
/// </summary>
Expand All @@ -31,6 +36,11 @@ public static class Events
/// </summary>
public static event HoldableUserInputEventHandler OnHoldableUserInput;

/// <summary>
/// Event for player status changes.
/// </summary>
public static event PlayerStatusChangeEventHandler OnPlayerStatusChange;

/// <summary>
/// Fires an event for a user input change.
/// </summary>
Expand All @@ -49,5 +59,14 @@ internal static void FireHoldableUserInput(HoldableCombo combo, bool isLongPress
{
OnHoldableUserInput?.Invoke(combo, isLongPress);
}

/// <summary>
/// Fires an event for a player status change.
/// </summary>
/// <param name="playerStatus">The new player status.</param>
internal static void FirePlayerStatusChange(PlayerStatus playerStatus)
{
OnPlayerStatusChange?.Invoke(playerStatus);
}
}
}
16 changes: 16 additions & 0 deletions IPT.Common/API/Functions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using Rage;
using Rage.Native;

namespace IPT.Common.API
{
Expand Down Expand Up @@ -35,5 +36,20 @@ public static Texture LoadTexture(string filename)

return null;
}

/// <summary>
/// Safely gets the current weather.
/// </summary>
/// <returns>The current weather type.</returns>
public static EWeatherType GetWeatherType()
{
int weatherType = NativeFunction.Natives.GET_PREV_WEATHER_TYPE_HASH_NAME<int>();
if (Enum.IsDefined(typeof(EWeatherType), weatherType))
{
return (EWeatherType)weatherType;
}

return EWeatherType.Neutral;
}
}
}
13 changes: 0 additions & 13 deletions IPT.Common/API/Math.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,19 +94,6 @@ public static int Snap(int value, int min, int max, int increment)
return cValue;
}

/// <summary>
/// Gets the angle (0-180 degrees) between the source and target entities.
/// </summary>
/// <param name="source">The source entity.</param>
/// <param name="target">The target entity.</param>
/// <returns>A double indicating the angle in degrees.</returns>
public static double GetVectorAngle(Entity source, Entity target)
{
var targetVector = target.Position - source.Position;
var dotProduct = Vector3.Dot(source.ForwardVector.ToNormalized(), targetVector.ToNormalized());
return ConvertRadiansToDegrees(System.Math.Acos(dotProduct));
}

/// <summary>
/// Converts radians into degrees.
/// </summary>
Expand Down
71 changes: 71 additions & 0 deletions IPT.Common/API/MathHelperExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
using Rage;

namespace IPT.Common.API
{
/// <summary>
/// Math helper.
/// </summary>
public static class MathHelperExtensions
{
/// <summary>
/// Calculates a forward vector.
/// </summary>
/// <param name="heading">The heading for the vector.</param>
/// <returns>A forward vector.</returns>
public static Vector3 GetForwardVector(float heading)
{
var headingRads = MathHelper.ConvertDegreesToRadians(90f - heading);
float x = System.Convert.ToSingle(-System.Math.Cos(headingRads));
float y = System.Convert.ToSingle(System.Math.Sin(headingRads));
return new Vector3(x, y, 0f);
}

/// <summary>
/// Gets the angle (0-180 degrees) between the source and target entities.
/// </summary>
/// <param name="source">The source entity.</param>
/// <param name="target">The target entity.</param>
/// <returns>A double indicating the angle in degrees.</returns>
public static double GetVectorAngle(Entity source, Entity target)
{
var targetVector = target.Position - source.Position;
var dotProduct = Vector3.Dot(source.ForwardVector.ToNormalized(), targetVector.ToNormalized());
return MathHelper.ConvertRadiansToDegrees(System.Math.Acos(dotProduct));
}

/// <summary>
/// Gets the angle (0-180 degrees) between the source and target positions given the heading.
/// </summary>
/// <param name="sourcePosition">The source position.</param>
/// <param name="targetPosition">The target position.</param>
/// <param name="heading">The in-game heading (where 0 degrees is due north).</param>
/// <returns>The offset from 0 degrees (straight towards) between the source and target along a heading.</returns>
public static double GetVectorAngle(Vector3 sourcePosition, Vector3 targetPosition, float heading)
{
var targetVector = targetPosition - sourcePosition;
var forwardVector = GetForwardVector(heading);
var dotProduct = Vector3.Dot(forwardVector.ToNormalized(), targetVector.ToNormalized());
return MathHelper.ConvertRadiansToDegrees(System.Math.Acos(dotProduct));
}

/// <summary>
/// Wraps an angle.
/// </summary>
/// <param name="angle">The angle.</param>
/// <returns>The wrapped angle.</returns>
public static float WrapAngle(float angle)
{
angle %= 360f;
if (angle > 180f)
{
angle -= 360f;
}
else if (angle < -180f)
{
angle += 360f;
}

return angle;
}
}
}
50 changes: 50 additions & 0 deletions IPT.Common/API/Notifications.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using IPT.Common.Handlers;
using Rage;

namespace IPT.Common.API
{
/// <summary>
/// Notification commands for a consistent style.
/// </summary>
public static class Notifications
{
/// <summary>
/// Sends a notification that looks like a message from the dispatcher.
/// </summary>
/// <param name="message">The message.</param>
public static void DispatchMessage(string message)
{
Game.DisplayNotification($"~b~Dispatch: ~w~{message}");
}

/// <summary>
/// Sends a dispach related notification.
/// </summary>
/// <param name="subtitle">The category of notification.</param>
/// <param name="message">The message.</param>
public static void DispatchNotification(string subtitle, string message)
{
OfficialNotification("DISPATCH", subtitle, message);
}

/// <summary>
/// Sends an official looking notification.
/// </summary>
/// <param name="title">The title of the notification.</param>
/// <param name="subtitle">The substitle of the notification.</param>
/// <param name="message">The message of the notification.</param>
public static void OfficialNotification(string title, string subtitle, string message)
{
Game.DisplayNotification("3dtextures", "mpgroundlogo_cops", title, $"~b~{subtitle}", message);
}

/// <summary>
/// Sends the status notification.
/// </summary>
public static void StatusNotification()
{
string message = $"~w~Callsign: ~g~{PlayerHandler.GetCallsign()}~n~~w~Status: {PlayerHandler.GetStatus().ToColorString()}";
DispatchNotification("~b~Officer Status", message);
}
}
}
2 changes: 1 addition & 1 deletion IPT.Common/API/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static class Player
/// <returns>The angle in degrees.</returns>
public static double GetVectorAngleTo(Entity entity)
{
return Math.GetVectorAngle(Game.LocalPlayer.Character, entity);
return MathHelperExtensions.GetVectorAngle(Game.LocalPlayer.Character, entity);
}
}
}
Loading

0 comments on commit c7866d1

Please sign in to comment.