diff --git a/Assets/particles/physgun_beam.vpcf_c b/Assets/particles/physgun_beam.vpcf_c index e06fcd5..3da6076 100644 --- a/Assets/particles/physgun_beam.vpcf_c +++ b/Assets/particles/physgun_beam.vpcf_c @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:df7936a826de0a9843e8783a0571eae14f355709f771d7f0254de4c1d53d1fd2 +oid sha256:85f1f24ad7937e1c0fabe44ef4ab6dc5667a47b3251ac42eaaccf43902ec15af size 3011 diff --git a/Assets/particles/physgun_end_nohit.vpcf_c b/Assets/particles/physgun_end_nohit.vpcf_c index 00b8947..3759d18 100644 --- a/Assets/particles/physgun_end_nohit.vpcf_c +++ b/Assets/particles/physgun_end_nohit.vpcf_c @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:e1e9797f7c8bad0b91775af4564c961e7861ccacd1a482f09706ee6de355f5ca +oid sha256:ecb1d3206ce3766046648e90de15ce63705265d0e7f990a61235407991583000 size 3785 diff --git a/Assets/particles/physgun_hitsmoke.vpcf_c b/Assets/particles/physgun_hitsmoke.vpcf_c index 9a294e9..3bac39e 100644 --- a/Assets/particles/physgun_hitsmoke.vpcf_c +++ b/Assets/particles/physgun_hitsmoke.vpcf_c @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:6b8e486a5d40c48a17361ed3408cb3edb16f0bc5cdeadaba6a94b9ece5fdc321 +oid sha256:f44c3ae906b4d69cb467ded13b3f2c6e70975d6149dd01120aac92e3a0505597 size 3149 diff --git a/Assets/particles/physgun_light.vpcf_c b/Assets/particles/physgun_light.vpcf_c index 5e10480..940170a 100644 --- a/Assets/particles/physgun_light.vpcf_c +++ b/Assets/particles/physgun_light.vpcf_c @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:1c597edbcf0da7f2b5e3d79b94dcfc3fe1ab3963b7705fd478bfc5ed585f1cb0 +oid sha256:09f461a791295480393f7688a7f81fae3e588066ee88c0be2dccbf60bacf88ae size 1989 diff --git a/Assets/particles/physgun_start.vpcf_c b/Assets/particles/physgun_start.vpcf_c index 1def791..392fa36 100644 --- a/Assets/particles/physgun_start.vpcf_c +++ b/Assets/particles/physgun_start.vpcf_c @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:bf6bfa8e04aa186960df660050ad149995f1f183eda012a9d1dccfe32cebcf34 +oid sha256:c45f3d8d8ee958e7821dc94ef25528fb0bcd97ff5c7b0e0cfb9a31da2afed93d size 3289 diff --git a/Code/Components/Player/Player.Crosshair.cs b/Code/Components/Player/Player.Crosshair.cs new file mode 100644 index 0000000..f0c93ff --- /dev/null +++ b/Code/Components/Player/Player.Crosshair.cs @@ -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 ConfigToHudObjects( string config ) + { + List objects = new(); + + foreach ( Match match in Regex.Matches( config, Pattern ) ) + { + string group = match.Groups[1].Value; + var items = new List( group.Split( ';' ) ); + + string type = items.First(); + + List 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; + } + } +} diff --git a/Code/Components/Player/Player.cs b/Code/Components/Player/Player.cs index 95a800f..9302fd1 100644 --- a/Code/Components/Player/Player.cs +++ b/Code/Components/Player/Player.cs @@ -38,6 +38,8 @@ public PlayerSettings Settings public Ray AimRay => new( EyeTransform.Position, EyeTransform.Rotation.Forward ); public bool SuppressScrollWheelInventory { get; set; } = false; + private List hudObjects = new(); + public bool isInParty() { return PartyId != 0UL; @@ -59,13 +61,33 @@ protected override void OnUpdate() } // Crosshair + DrawCrosshair(); + } + + /// + /// Draws the player's crosshair based on what they've defined + /// + private void DrawCrosshair() + { + if ( IsProxy ) return; + if ( hudObjects.Count == 0 ) RegenerateCrosshair(); + Vector3 trace = Vector3.Zero; if ( Controller.ThirdPerson ) trace = Player.DoBasicTrace().HitPosition; - if ( !Controller.ThirdPerson || trace == Vector3.Zero) trace = AimRay.Position + AimRay.Forward * 5000; + if ( !Controller.ThirdPerson || trace == Vector3.Zero ) trace = AimRay.Position + AimRay.Forward * 5000; Vector2 loc = Scene.Camera.PointToScreenPixels( trace ); - Scene.Camera.Hud.DrawCircle( new Vector2( loc.x, loc.y ), new Vector2( 5, 5 ), Color.White ); + + foreach(var obj in hudObjects) + { + obj.Draw( Scene.Camera, loc ); + } + } + + public void RegenerateCrosshair() + { + hudObjects = PlayerCrosshair.Crosshair.ConfigToHudObjects( Settings.CustomCrosshair ); } /// diff --git a/Code/Components/Player/PlayerSettings.cs b/Code/Components/Player/PlayerSettings.cs index 4b96d1d..2b66b13 100644 --- a/Code/Components/Player/PlayerSettings.cs +++ b/Code/Components/Player/PlayerSettings.cs @@ -18,6 +18,21 @@ public bool UseHumanModel } } + public static string CustomCrosshairDefault = "(circle;255;255;255;-3;-3;6;6)"; + private string customCrosshair = CustomCrosshairDefault; + public string CustomCrosshair + { + get => customCrosshair; + set + { + if ( customCrosshair == value ) return; + customCrosshair = value; + SetDirty(); + + if (player != null) player.RegenerateCrosshair(); + } + } + private bool usePhysgunSound = true; public bool UsePhysgunSound { @@ -60,6 +75,7 @@ public static void Save() public static PlayerSettings Load() { var loaded = FileSystem.Data.ReadJson( "playersettings.json" ) ?? new PlayerSettings(); + loaded.player = Player.FindLocalPlayer(); loaded.SetDirty( false ); return loaded; } diff --git a/Code/UI/Utilities/PlayerSettingsPage.razor b/Code/UI/Utilities/PlayerSettingsPage.razor index 654cde0..32b403f 100644 --- a/Code/UI/Utilities/PlayerSettingsPage.razor +++ b/Code/UI/Utilities/PlayerSettingsPage.razor @@ -9,10 +9,16 @@ + + + + + @code { + private TextEntry CrosshairEntryPanel { get; set; } PlayerDresser dresser { get; set; } = Player.Local.Body.GetComponent(); void TogglePlayerModelType() @@ -22,7 +28,19 @@ dresser.ChangePlayerModelType(!dresser.UseHumanModel); } - void TogglePhysgunSound() { + void TogglePhysgunSound() + { Player.Local.Settings.UsePhysgunSound = !Player.Local.Settings.UsePhysgunSound; - } + } + void ResetCrosshairs() + { + Player.Local.Settings.CustomCrosshair = PlayerSettings.CustomCrosshairDefault; + CrosshairEntryPanel.Blur(); + } + + void UpdateCrosshairs() + { + Player.Local.Settings.CustomCrosshair = CrosshairEntryPanel.Text; + CrosshairEntryPanel.Blur(); + } }