Skip to content

Commit

Permalink
Thirdperson crosshair changes + small bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
timmybo5 committed Aug 24, 2021
1 parent 29f4414 commit 724576e
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 11 deletions.
3 changes: 3 additions & 0 deletions code/ExamplePlayer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ public override void Respawn()
Inventory.Add(new SWB_CSS.GrenadeHE());

Inventory.Add(new SWB_CSS.Deagle());

Inventory.Add(new SWB_CSS.Super90());
Inventory.Add(new SWB_CSS.MAC10());

Inventory.Add(new SWB_CSS.AK47());
Inventory.Add(new SWB_CSS.M4A1());
Inventory.Add(new SWB_CSS.M249());
Expand Down
5 changes: 5 additions & 0 deletions code/swb_base/PlayerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,11 @@ public bool Alive()
return Health <= 0;
}

public bool InFirstPerson()
{
return Owner.Camera is FirstPersonCamera;
}

[ClientRpc]
public void DidDamage(Vector3 pos, float amount, float health, float healthinv)
{
Expand Down
5 changes: 5 additions & 0 deletions code/swb_base/ViewModelBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ public override void PostCameraSetup(ref CameraSetup camSetup)
Rotation = camSetup.Rotation;
Position = camSetup.Position;
if (weapon.IsDormant) return;
if (Owner != null && Owner.Health <= 0)
{
this.EnableDrawing = false;
return;
}

// Smoothly transition the vectors with the target values
FinalVectorPos = FinalVectorPos.LerpTo(TargetVectorPos, animSpeed * RealTime.Delta);
Expand Down
3 changes: 2 additions & 1 deletion code/swb_base/WeaponBase.Var.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ public partial class WeaponBase
public virtual int Bucket => 1; // Inventory slot position
public virtual int BucketWeight => 100; // Inventory slot position weight ( higher = more important )
public virtual bool DrawCrosshair => true; // Draw the crosshair
public virtual bool DrawCrosshairDot => true; // Draw the crosshair dot
public virtual bool DrawCrosshairLines => true; // Draw the crosshair lines
public virtual bool DrawHitmarker => true; // Draw the hitmarker
public virtual bool PlayHitmarkerSound => true; // Draw the hitmarker
public virtual bool PlayHitmarkerSound => true; // Play the hitmarker sound
public virtual bool DropWeaponOnDeath => true; // Drop the weapon on death
public virtual string FreezeViewModelOnZoom => null; // Some weapons have looping idle animations -> force spam another animation to "freeze" it
public virtual int FOV => 65; // Default FOV
Expand Down
20 changes: 14 additions & 6 deletions code/swb_base/ui/Crosshair.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,18 @@ public override void Tick()
if (player == null) return;

var weapon = player.ActiveChild as WeaponBase;
bool isValidWeapon = weapon != null;

var hideCrosshairLines = weapon != null ? !weapon.DrawCrosshairLines : true;
var hideCrosshairDot = isValidWeapon ? !weapon.DrawCrosshairDot : true;
CenterDot.SetClass("hideCrosshair", hideCrosshairDot);

var hideCrosshairLines = isValidWeapon ? !weapon.DrawCrosshairLines : true;
LeftBar.SetClass("hideCrosshair", hideCrosshairLines);
RightBar.SetClass("hideCrosshair", hideCrosshairLines);
TopBar.SetClass("hideCrosshair", hideCrosshairLines);
BottomBar.SetClass("hideCrosshair", hideCrosshairLines);

if (hideCrosshairLines) return;
var shouldTuck = weapon.ShouldTuck();
if (!isValidWeapon) return;

// Crosshair spread offset
var screenOffset = spreadOffset * weapon.GetRealSpread();
Expand All @@ -98,7 +101,7 @@ public override void Tick()
BottomBar.Style.MarginTop = screenOffset;

// Sprint spread offsets
if (weapon.IsRunning || shouldTuck || weapon.IsReloading)
if (weapon.IsRunning || weapon.ShouldTuck() || weapon.IsReloading)
{
LeftBar.Style.Left = -sprintOffset;
RightBar.Style.Left = sprintOffset - 5;
Expand All @@ -110,8 +113,13 @@ public override void Tick()
else if (weapon.IsZooming)
{
wasZooming = true;
CenterDot.Style.Opacity = 0;
HideBarLines();
var playerBase = player as PlayerBase;

if (playerBase == null || playerBase.InFirstPerson())
{
CenterDot.Style.Opacity = 0;
HideBarLines();
}
}
else if (LeftBar.Style.Left == -sprintOffset || wasZooming)
{
Expand Down
5 changes: 3 additions & 2 deletions code/swb_base/ui/Crosshair.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
border-radius: 50%;
top: -1px;
left: -1px;
width: 4px;
height: 4px;
width: 5px;
height: 5px;
box-shadow: 1px 1px 2px 0px black;
//border: 1px thin black;
transition: all 0.1s ease-out 0s;
}

Expand Down
2 changes: 0 additions & 2 deletions code/swb_base/ui/Hitmarker.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Threading.Tasks;
using Sandbox;
using Sandbox.UI;

namespace SWB_Base
Expand Down Expand Up @@ -55,7 +54,6 @@ async Task Lifetime()
await Task.Delay(100);
AddClass("fadeOut");
await Task.Delay(300);
Sound.FromScreen("swb_hitmarker");
Delete();
}
}
Expand Down

0 comments on commit 724576e

Please # to comment.