diff options
| -rw-r--r-- | code/pawn/Player.cs | 25 | ||||
| -rw-r--r-- | code/ui/Hud.razor | 1 | ||||
| -rw-r--r-- | code/ui/character/LookingAtInfo.razor | 57 |
3 files changed, 83 insertions, 0 deletions
diff --git a/code/pawn/Player.cs b/code/pawn/Player.cs index 1d87d94..7073bb1 100644 --- a/code/pawn/Player.cs +++ b/code/pawn/Player.cs @@ -60,6 +60,8 @@ public partial class Player : AnimatedEntity [Net, Predicted]
public TimeSince TimeSinceDeath { get; set; } = 0;
+ public Player LookingAt { get; set; }
+
public override void Spawn()
{
SetModel( "models/citizen/citizen.vmdl" );
@@ -189,6 +191,29 @@ public partial class Player : AnimatedEntity Components.Create<SpectatorCameraComponent>();
}
+ if ( Game.IsClient )
+ {
+ var start = AimRay.Position;
+ var end = AimRay.Position + AimRay.Forward * 5000;
+
+ var trace = Trace.Ray( start, end )
+ .UseHitboxes()
+ .WithAnyTags( "solid", "livingplayer" )
+ .Ignore( this )
+ .Size( 1f );
+
+ var tr = trace.Run();
+ if ( tr.Hit && tr.Entity.IsValid() && tr.Entity is Player player )
+ {
+ LookingAt = player;
+ }
+ else
+ {
+ LookingAt = null;
+ }
+ }
+
+
}
public override void BuildInput()
diff --git a/code/ui/Hud.razor b/code/ui/Hud.razor index 9fcdfdc..d6fe5b6 100644 --- a/code/ui/Hud.razor +++ b/code/ui/Hud.razor @@ -14,6 +14,7 @@ <BlindedOverlay/>
<RoleOverlay/>
<DeathOverlay/>
+ <LookingAtInfo/>
<ChatBox/>
<VoiceList/>
<PhaseTimer/>
diff --git a/code/ui/character/LookingAtInfo.razor b/code/ui/character/LookingAtInfo.razor new file mode 100644 index 0000000..4a54b81 --- /dev/null +++ b/code/ui/character/LookingAtInfo.razor @@ -0,0 +1,57 @@ +@using Sandbox;
+@using Sandbox.UI;
+@using System;
+
+@namespace MurderGame
+@inherits Panel
+
+<style>
+lookingatinfo {
+ top: 0;
+ left: 0;
+ width: 100vw;
+ height: 100vh;
+ position: absolute;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ flex-direction: column;
+}
+.box {
+ /* backdrop-filter-blur: 8px;
+ background-color: rgba(0, 0, 0, 0.20);
+ padding: 10px;
+ color: white; */
+ font-weight: 700;
+ font-size: 25px;
+ font-family: "Roboto";
+ margin-top: 60px;
+}
+.text {
+ text-shadow: 1px 1px 0px 0px rgba(0,0,0,0.75);
+}
+</style>
+
+<div class="box" style="color: @GetLookingAtColour()">
+ <span class="text">@GetLookingAtName()</span>
+</div>
+
+@code
+{
+ public string GetLookingAtName()
+ {
+ if (Game.LocalPawn is not Player player) return "";
+ return player.LookingAt is not { } lookingAt ? "" : lookingAt.CharacterName;
+ }
+
+ public string GetLookingAtColour()
+ {
+ if (Game.LocalPawn is not Player player) return "white";
+ return player.LookingAt is not { } lookingAt ? "white" : lookingAt.HexColor;
+ }
+
+ protected override int BuildHash()
+ {
+ return GetLookingAtName().GetHashCode();
+ }
+}
|
