HUD Entity

image

It seems like I missed it and maybe it was previously known, but judging on @garry’s recent commit it seems like we’ll have a HUD entity, I’d like to know a few things about its conceptual behavior.

  • Will the HUD entity be clientside or serverside?

  • Can we have multiple HUD entities with different classes and HUDPaint methods associated with them and switch between those with something like localPlayer.SetHudEntity on the client and if it’s serverside, with something like player.SetHudEntity on the server?

Basically, imagine we have a security camera that we can view from using a first person view, having a HUD entity, we could change player’s current one to the one of the camera and change the HUD this nicely and easily, or couldn’t we?

3 Likes

I’m guessing a HUD Entity means something like a screen, in gmod we had to initialise them with this https://wiki.facepunch.com/gmod/cam.Start3D2D.

1 Like

It’s just an entity that creates a panel clientside.

namespace Sandbox
{
	/// <summary>
	/// An entity that holds the HUD class. This is an entity so you can 
	/// add RPCs and shit to let your server send messages to control the
	/// HUd.
	/// </summary>
	[ClassLibrary( "hud" )]
	public class Hud : Entity
	{
		public static Hud Current { get; set; }
		public RootPanel RootPanel { get; set; }

		public Hud()
		{
			Transmit = TransmitType.Always;
			Current = this;

			if ( IsClient )
			{
				//
				// The root panel that holds 
				// all the other controls.
				//
				RootPanel = new RootPanel();
				RootPanel.Style.Set( "pointer-events: none; width: 100%; height: 100%;" );
				RootPanel.AcceptsFocus = false;
			}
		}

		protected override void OnDestroy()
		{
			base.OnDestroy();

			//
			// clean up the panel 
			// or it'll stick around forever
			//
			RootPanel?.Delete();
			RootPanel = null;
		}
	}
}

I made it an entity so you can update the HUD from the server via RPCs and variables. So for something like a counter-strike gamemode, you might have a replicated variable that represents the round timer etc…

7 Likes

Oooh, now I see.

That’s great, so it’s nothing really special but just an addon-scoped nice implementation of a server-updated HUD.
Thanks for clarifying!

1 Like

Also @garry there’s a small typo (HUd) in the comment, nothing special but still :smiley:

image

1 Like

:nerd_face:
-You-

2 Likes

:dizzy_face: typing errors

2 Likes