mirror of
https://github.com/celisej567/gm_construct_port.git
synced 2026-09-19 20:11:46 +03:00
Add files via upload
This commit is contained in:
41
code/ui/CurrentTool.cs
Normal file
41
code/ui/CurrentTool.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user