-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
177 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using System.Drawing; | ||
using CitizenFX.Core; | ||
using CitizenFX.Core.Native; | ||
using PolyZone.Extensions; | ||
using PolyZone.Zones; | ||
|
||
namespace PolyZone.Debug.Drawing; | ||
|
||
public static class CircleDrawingExtensions | ||
{ | ||
/// <summary> | ||
/// Draws the circle in the world for the player, uses <see cref="API.GetGroundZFor_3dCoord"/> to determine the Z level | ||
/// </summary> | ||
/// <param name="circleZone">The <see cref="CircleZone"/></param> | ||
/// <param name="color">The <see cref="Color"/></param> | ||
public static void Draw(this CircleZone circleZone, in Color color) => circleZone.Draw(color, out _); | ||
|
||
public static void Draw(this CircleZone circleZone, in Color color, out Vector3 centerOfCircle) | ||
{ | ||
var groundZ = 999.0f; | ||
|
||
API.GetGroundZFor_3dCoord(circleZone.Center.X, circleZone.Center.Y, groundZ, ref groundZ, false); | ||
|
||
centerOfCircle = new Vector3(circleZone.Center.X, circleZone.Center.Y, groundZ); | ||
|
||
World.DrawMarker(MarkerType.VerticalCylinder, | ||
centerOfCircle, | ||
Vector3.Zero, | ||
Vector3.Zero, | ||
new Vector3(circleZone.Radius * 2, circleZone.Radius * 2, 0.5f), | ||
color); | ||
} | ||
|
||
public static void DrawDebug(this CircleZone circleZone, Entity? comparativeEntity = null) | ||
{ | ||
comparativeEntity ??= Game.Player.Character; | ||
|
||
const int alpha = 150; | ||
var insideColor = Color.FromArgb(alpha, 0, 255, 0); | ||
var outsideColor = Color.FromArgb(alpha, 255, 0, 0); | ||
|
||
var isInside = comparativeEntity.IsInside(circleZone); | ||
var color = isInside ? insideColor : outsideColor; | ||
|
||
circleZone.Draw(color, out var centerOfCircle); | ||
|
||
Internal.Drawing.Draw3dText(centerOfCircle, $"Distance: { comparativeEntity.DistanceTo(circleZone) }", color, 5.0f); | ||
} | ||
} |
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,55 @@ | ||
using System.Drawing; | ||
using CitizenFX.Core; | ||
using CitizenFX.Core.Native; | ||
using PolyZone.Shapes.Interfaces; | ||
|
||
namespace PolyZone.Debug.Drawing; | ||
|
||
public static class PolygonExtensions | ||
{ | ||
public static IPolygon Draw(this IPolygon polygon, Color color) | ||
{ | ||
/*for (var i = 0; i < polygon.Points.Count - 1; i++) | ||
{ | ||
var startPoint = polygon.Points[i]; | ||
var endPoint = polygon.Points[i + 1]; | ||
DrawPoly(startPoint, endPoint, r, g, b, a); | ||
}*/ | ||
|
||
var start = polygon.Points.ElementAt(polygon.Points.Count - 1); | ||
var end = polygon.Points.ElementAt(0); | ||
|
||
var bottomLeft = new Vector3(start.X, start.Y, 200); | ||
var topLeft = new Vector3(start.X, start.Y, 400); | ||
var bottomRight = new Vector3(end.X, end.Y, 200); | ||
var topRight = new Vector3(end.X, end.Y, 400); | ||
|
||
API.DrawPoly( | ||
bottomLeft.X, bottomLeft.Y, bottomLeft.Z, | ||
topLeft.X, topLeft.Y, topLeft.Z, | ||
bottomRight.X, bottomRight.Y, bottomLeft.Z, | ||
color.R, color.G, color.B, color.A); | ||
|
||
API.DrawPoly( | ||
topLeft.X, topLeft.Y, topLeft.Z, | ||
topRight.X, topRight.Y, topRight.Z, | ||
bottomRight.X, bottomRight.Y, bottomLeft.Z, | ||
color.R, color.G, color.B, color.A); | ||
|
||
API.DrawPoly( | ||
bottomRight.X, bottomRight.Y, bottomRight.Z, | ||
topRight.X, topRight.Y, topRight.Z, | ||
topLeft.X, topLeft.Y, topLeft.Z, | ||
color.R, color.G, color.B, color.A); | ||
|
||
API.DrawPoly( | ||
bottomRight.X, bottomRight.Y, bottomRight.Z, | ||
topLeft.X, topLeft.Y, topLeft.Z, | ||
bottomLeft.X, bottomLeft.Y, bottomLeft.Z, | ||
color.R, color.G, color.B, color.A); | ||
|
||
|
||
return polygon; | ||
} | ||
} |
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,38 @@ | ||
using System.Drawing; | ||
using CitizenFX.Core; | ||
using CitizenFX.Core.Native; | ||
|
||
namespace PolyZone.Debug.Internal; | ||
|
||
internal static class Drawing | ||
{ | ||
internal static void Draw3dText(Vector3 pos, string text, Color color, float size = 0.35f) | ||
{ | ||
float _x = 0; | ||
float _y = 0; | ||
|
||
var onScreen = API.World3dToScreen2d(pos.X, pos.Y, pos.Z, ref _x, ref _y); | ||
var pCoords = API.GetGameplayCamCoords(); | ||
|
||
var distance = API.GetDistanceBetweenCoords(pCoords.X,pCoords.Y,pCoords.Z, pos.X, pos.Y, pos.Z, true); | ||
var txtScale = 1 / distance * 2; | ||
var fov = 1 / API.GetGameplayCamFov() * 100; | ||
var scale = txtScale * fov * size; | ||
|
||
if (onScreen) | ||
{ | ||
API.SetTextScale(0.0f, scale); | ||
API.SetTextFont(4); | ||
API.SetTextProportional(true); | ||
API.SetTextColour(color.R, color.G, color.B, color.A); | ||
API.SetTextDropShadow(); | ||
API.SetTextEdge(0, 0, 0, 0, 150); | ||
API.SetTextDropShadow(); | ||
API.SetTextOutline(); | ||
API.SetTextEntry("STRING"); | ||
API.SetTextCentre(false); | ||
API.AddTextComponentString(text); | ||
API.DrawText(_x, _y); | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,8 +1,28 @@ | ||
using CitizenFX.Core; | ||
using PolyZone.Debug.Drawing; | ||
using PolyZone.Zones; | ||
using Serilog; | ||
using Serilog.Sinks; | ||
|
||
namespace PolyZone.Debug; | ||
|
||
public class Script : BaseScript | ||
{ | ||
private readonly CircleZone _circleZone; | ||
|
||
public Script() | ||
{ | ||
Log.Logger = new LoggerConfiguration() | ||
.MinimumLevel.Debug() | ||
.WriteTo.FiveM() | ||
.CreateLogger(); | ||
|
||
_circleZone = new CircleZone(new Vector2(242, -1312), 15.0f); | ||
} | ||
|
||
[Tick] | ||
public async Task OnTick() | ||
Check warning on line 24 in src/PolyZone.Debug/Script.cs GitHub Actions / build
|
||
{ | ||
_circleZone.DrawDebug(); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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