-
Notifications
You must be signed in to change notification settings - Fork 28
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
41 changed files
with
304 additions
and
128 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
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
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 |
---|---|---|
@@ -0,0 +1,100 @@ | ||
using System; | ||
using System.Linq; | ||
using Sandbox; | ||
using Sandbox.UI; | ||
using Sandbox.UI.Construct; | ||
using SWB_Base; | ||
|
||
/// <summary> | ||
/// When a player is within radius of the camera we add this to their entity. | ||
/// We remove it again when they go out of range. | ||
/// </summary> | ||
internal class NameTagComponent : EntityComponent<PlayerBase> | ||
{ | ||
NameTag NameTag; | ||
|
||
protected override void OnActivate() | ||
{ | ||
NameTag = new NameTag(Entity.Client?.Name ?? Entity.Name, Entity.Client?.PlayerId); | ||
} | ||
|
||
protected override void OnDeactivate() | ||
{ | ||
NameTag?.Delete(); | ||
NameTag = null; | ||
} | ||
|
||
/// <summary> | ||
/// Called for every tag, while it's active | ||
/// </summary> | ||
[Event.Frame] | ||
public void FrameUpdate() | ||
{ | ||
var tx = Entity.GetAttachment("hat") ?? Entity.Transform; | ||
tx.Position += Vector3.Up * 10.0f; | ||
tx.Rotation = Rotation.LookAt(-CurrentView.Rotation.Forward); | ||
|
||
NameTag.Transform = tx; | ||
} | ||
|
||
/// <summary> | ||
/// Called once per frame to manage component creation/deletion | ||
/// </summary> | ||
[Event.Frame] | ||
public static void SystemUpdate() | ||
{ | ||
// Check if deathmatch hud is active | ||
var hasDeathmatchHud = Sandbox.Entity.All.OfType<DeathmatchHud>().Count() > 0; | ||
|
||
if (!hasDeathmatchHud) return; | ||
|
||
foreach (var player in Sandbox.Entity.All.OfType<PlayerBase>()) | ||
{ | ||
if (player.IsLocalPawn && player.IsFirstPersonMode) | ||
{ | ||
var c = player.Components.Get<NameTagComponent>(); | ||
c?.Remove(); | ||
continue; | ||
} | ||
|
||
var shouldRemove = player.Position.Distance(CurrentView.Position) > 500; | ||
shouldRemove = shouldRemove || player.LifeState != LifeState.Alive; | ||
shouldRemove = shouldRemove || player.IsDormant; | ||
|
||
if (shouldRemove) | ||
{ | ||
var c = player.Components.Get<NameTagComponent>(); | ||
c?.Remove(); | ||
continue; | ||
} | ||
|
||
// Add a component if it doesn't have one | ||
player.Components.GetOrCreate<NameTagComponent>(); | ||
} | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// A nametag panel in the world | ||
/// </summary> | ||
public class NameTag : WorldPanel | ||
{ | ||
public Panel Avatar; | ||
public Label NameLabel; | ||
|
||
internal NameTag(string title, long? steamid) | ||
{ | ||
StyleSheet.Load("deathmatch_dep/ui/Nametags.scss"); | ||
|
||
if (steamid != null) | ||
{ | ||
Avatar = Add.Panel("avatar"); | ||
Avatar.Style.SetBackgroundImage($"avatar:{steamid}"); | ||
} | ||
|
||
NameLabel = Add.Label(title, "title"); | ||
|
||
// this is the actual size and shape of the world panel | ||
PanelBounds = new Rect(-500, -100, 1000, 200); | ||
} | ||
} |
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,22 @@ | ||
NameTag { | ||
justify-content: center; | ||
align-items: center; | ||
mix-blend-mode: lighten; | ||
|
||
.title { | ||
font-family: Roboto; | ||
font-size: 30px; | ||
white-space: nowrap; | ||
color: #fa2; | ||
mix-blend-mode: lighten; | ||
text-shadow: 0px 0px 5px #f40; | ||
} | ||
|
||
.avatar { | ||
width: 30px; | ||
height: 30px; | ||
margin-right: 15px; | ||
border-radius: 100px; | ||
background-size: cover; | ||
} | ||
} |
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
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
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
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
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
Oops, something went wrong.