-
Notifications
You must be signed in to change notification settings - Fork 12
Add customisable crosshairs! Woo. Necessary, no. Cool? Maybe lol. #72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ninjrdevelop
wants to merge
7
commits into
main
Choose a base branch
from
add-customisable-crosshairs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5036649
Add customisable crosshairs! Woo. Necessary, no. Cool? Maybe lol.
ninjrdevelop b0d6d55
Forgot the crosshair file
ninjrdevelop 47126c5
Merge branch 'main' into add-customisable-crosshairs
ninjrdevelop e7bc2da
Fix math, change default.
ninjrdevelop a260177
Merge remote-tracking branch 'origin/add-customisable-crosshairs' int…
ninjrdevelop 92b1547
Merge main?
ninjrdevelop 762fbbb
Update Code/Components/Player/Player.cs
ninjrdevelop File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
This file contains hidden or 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,153 @@ | ||
using System.Security.AccessControl; | ||
using System.Text.RegularExpressions; | ||
using static System.Runtime.InteropServices.JavaScript.JSType; | ||
|
||
namespace PlayerCrosshair | ||
{ | ||
public class HudObject | ||
{ | ||
public virtual void Draw( CameraComponent camera, Vector2 centerPos ) { } | ||
} | ||
public class Circle : HudObject | ||
{ | ||
Color Color { get; set; } = Color.White; | ||
Vector2 Location { get; set; } = Vector2.Zero; | ||
Vector2 Size { get; set; } = Vector2.Zero; | ||
|
||
public Circle( Color color, Vector2 loc, Vector2 size ) | ||
{ | ||
Color = color; | ||
Location = Location; | ||
Size = size; | ||
} | ||
|
||
public override void Draw( CameraComponent camera, Vector2 centerPos) | ||
{ | ||
camera.Hud.DrawCircle(centerPos + Location, Size, Color); | ||
} | ||
} | ||
public class Line : HudObject | ||
{ | ||
Color Color { get; set; } = Color.White; | ||
Vector2 Start { get; set; } = Vector2.Zero; | ||
Vector2 End { get; set; } = Vector2.Zero; | ||
int Thickness { get; set; } = 0; | ||
|
||
public Line( Color color, Vector2 startLoc, Vector2 endLoc, int thickness ) | ||
{ | ||
Color = color; | ||
Start = startLoc; | ||
End = endLoc; | ||
Thickness = thickness; | ||
} | ||
|
||
|
||
public override void Draw( CameraComponent camera, Vector2 centerPos ) | ||
{ | ||
camera.Hud.DrawLine( centerPos + Start, centerPos + End, Thickness, Color ); | ||
} | ||
} | ||
public class Rectangle : HudObject | ||
{ | ||
Color Color { get; set; } = Color.White; | ||
int Left { get; set; } = 0; | ||
int Top { get; set; } = 0; | ||
int Width { get; set; } = 0; | ||
int Height { get; set; } = 0; | ||
int Thickness { get; set; } = 0; | ||
|
||
public Rectangle( Color color, int left, int top, int width, int height, int thickness ) | ||
{ | ||
Color = color; | ||
Left = left; | ||
Top = top; | ||
Width = width; | ||
Height = height; | ||
Thickness = thickness; | ||
} | ||
|
||
|
||
public override void Draw( CameraComponent camera, Vector2 centerPos ) | ||
{ | ||
camera.Hud.DrawRect( new Rect( centerPos.x + Left, centerPos.y + Top, Width, Height ), Color, borderWidth: new Vector4( Thickness ) ); | ||
} | ||
} | ||
|
||
|
||
public class Crosshair | ||
{ | ||
private static string Pattern = @"\((.*?)\)"; | ||
public static List<HudObject> ConfigToHudObjects( string config ) | ||
{ | ||
List<HudObject> objects = new(); | ||
|
||
foreach ( Match match in Regex.Matches( config, Pattern ) ) | ||
{ | ||
string group = match.Groups[1].Value; | ||
var items = new List<string>( group.Split( ';' ) ); | ||
|
||
string type = items.First(); | ||
|
||
List<int> values = new(); | ||
for(int i = 1; i < items.Count; i++) | ||
{ | ||
if ( int.TryParse( items[i], out var val ) ) values.Add( val ); | ||
} | ||
|
||
if (type == "circle" && values.Count >= 7 ) | ||
{ | ||
// (circle;255;255;255;-2;-2;4;4) | ||
objects.Add( | ||
new Circle( new Color( values[0], values[1], values[2] ), new Vector2( values[3], values[4] ), new Vector2( values[5], values[6] ) ) | ||
); | ||
} | ||
else if (type == "line" && values.Count >= 8 ) | ||
{ | ||
// (line;255;255;255;-25;-25;-4;-4;1) | ||
objects.Add( | ||
new Line( new Color( values[0], values[1], values[2] ), new Vector2( values[3], values[4] ), new Vector2( values[5], values[6] ), values[7] ) | ||
); | ||
} | ||
else if (type == "rect") | ||
{ | ||
if (values.Count >= 9) | ||
{ | ||
// (rect;255;255;0;-25;-25;50;50;1;1) Solid square | ||
if ( values[8] == 1 ) | ||
{ | ||
objects.Add( | ||
new Rectangle( new Color( values[0], values[1], values[2] ), values[3], values[4], values[5], values[6], values[7] ) | ||
); | ||
} | ||
else | ||
{ | ||
// (rect;255;255;0;-25;-25;50;50;1;1) Hollow square | ||
// Left, Top, Width, Height | ||
// Left: values[3] | ||
// Top: values[4] | ||
// Width: values[5] | ||
// Height: values[6] | ||
|
||
// Top left: values[3], values[4] | ||
// Top right: values[3] + values[5], values[4] | ||
// Bottom left: values[3], values[4] + values[6] | ||
// Bottom right: values[3] + values[5], values[4] + values[6] | ||
|
||
objects.Add( new Line( new Color( values[0], values[1], values[2] ), new Vector2( values[3], values[4] ), new Vector2( values[3] + values[5], values[4] ), values[7] ) ); | ||
objects.Add( new Line( new Color( values[0], values[1], values[2] ), new Vector2( values[3], values[4] ), new Vector2( values[3], values[4] + values[6] ), values[7] ) ); | ||
objects.Add( new Line( new Color( values[0], values[1], values[2] ), new Vector2( values[3] + values[5], values[4] + values[6] ), new Vector2( values[3], values[4] + values[6] ), values[7] ) ); | ||
objects.Add( new Line( new Color( values[0], values[1], values[2] ), new Vector2( values[3] + values[5], values[4] + values[6] ), new Vector2( values[3] + values[5], values[4] ), values[7] ) ); | ||
} | ||
} | ||
else | ||
{ | ||
|
||
} | ||
} | ||
|
||
} | ||
|
||
return objects; | ||
} | ||
} | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.