Files
gm_construct_port/code/ui/CurrentTool.cs
2021-08-05 17:54:51 +03:00

42 lines
795 B
C#

using Sandbox;
using Sandbox.Tools;
using Sandbox.UI;
using Sandbox.UI.Construct;
public class CurrentTool : Panel
{
public Label Title;
public Label Description;
public CurrentTool()
{
Title = Add.Label( "Tool", "title" );
Description = Add.Label( "This is a tool", "description" );
}
public override void Tick()
{
var tool = GetCurrentTool();
SetClass( "active", tool != null );
if ( tool != null )
{
Title.SetText( tool.ClassInfo.Title );
Description.SetText( tool.ClassInfo.Description );
}
}
BaseTool GetCurrentTool()
{
var player = Local.Pawn;
if ( player == null ) return null;
var inventory = player.Inventory;
if ( inventory == null ) return null;
if ( inventory.Active is not Tool tool ) return null;
return tool?.CurrentTool;
}
}