Add files via upload

This commit is contained in:
celisej567
2021-08-05 17:54:51 +03:00
committed by GitHub
parent d58ad89d11
commit 76b55e2a87
57 changed files with 5632 additions and 0 deletions

41
code/ui/CurrentTool.cs Normal file
View 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;
}
}

21
code/ui/Health.cs Normal file
View File

@@ -0,0 +1,21 @@
using Sandbox;
using Sandbox.UI;
using Sandbox.UI.Construct;
public class Health : Panel
{
public Label Label;
public Health()
{
Label = Add.Label( "100", "value" );
}
public override void Tick()
{
var player = Local.Pawn;
if ( player == null ) return;
Label.Text = $"{player.Health.CeilToInt()}";
}
}

103
code/ui/InventoryBar.cs Normal file
View File

@@ -0,0 +1,103 @@
using Sandbox;
using Sandbox.UI;
using System.Collections.Generic;
public class InventoryBar : Panel
{
readonly List<InventoryIcon> slots = new();
public InventoryBar()
{
for ( int i = 0; i < 9; i++ )
{
var icon = new InventoryIcon( i + 1, this );
slots.Add( icon );
}
}
public override void Tick()
{
base.Tick();
var player = Local.Pawn;
if ( player == null ) return;
if ( player.Inventory == null ) return;
for ( int i = 0; i < slots.Count; i++ )
{
UpdateIcon( player.Inventory.GetSlot( i ), slots[i], i );
}
}
private static void UpdateIcon( Entity ent, InventoryIcon inventoryIcon, int i )
{
if ( ent == null )
{
inventoryIcon.Clear();
return;
}
inventoryIcon.TargetEnt = ent;
inventoryIcon.Label.Text = ent.ClassInfo.Title;
inventoryIcon.SetClass( "active", ent.IsActiveChild() );
}
[Event( "buildinput" )]
public void ProcessClientInput( InputBuilder input )
{
var player = Local.Pawn as Player;
if ( player == null )
return;
var inventory = player.Inventory;
if ( inventory == null )
return;
if ( player.ActiveChild is PhysGun physgun && physgun.BeamActive )
{
return;
}
if ( input.Pressed( InputButton.Slot1 ) ) SetActiveSlot( input, inventory, 0 );
if ( input.Pressed( InputButton.Slot2 ) ) SetActiveSlot( input, inventory, 1 );
if ( input.Pressed( InputButton.Slot3 ) ) SetActiveSlot( input, inventory, 2 );
if ( input.Pressed( InputButton.Slot4 ) ) SetActiveSlot( input, inventory, 3 );
if ( input.Pressed( InputButton.Slot5 ) ) SetActiveSlot( input, inventory, 4 );
if ( input.Pressed( InputButton.Slot6 ) ) SetActiveSlot( input, inventory, 5 );
if ( input.Pressed( InputButton.Slot7 ) ) SetActiveSlot( input, inventory, 6 );
if ( input.Pressed( InputButton.Slot8 ) ) SetActiveSlot( input, inventory, 7 );
if ( input.Pressed( InputButton.Slot9 ) ) SetActiveSlot( input, inventory, 8 );
if ( input.MouseWheel != 0 ) SwitchActiveSlot( input, inventory, -input.MouseWheel );
}
private static void SetActiveSlot( InputBuilder input, IBaseInventory inventory, int i )
{
var player = Local.Pawn;
if ( player == null )
return;
var ent = inventory.GetSlot( i );
if ( player.ActiveChild == ent )
return;
if ( ent == null )
return;
input.ActiveChild = ent;
}
private static void SwitchActiveSlot( InputBuilder input, IBaseInventory inventory, int idelta )
{
var count = inventory.Count();
if ( count == 0 ) return;
var slot = inventory.GetActiveSlot();
var nextSlot = slot + idelta;
while ( nextSlot < 0 ) nextSlot += count;
while ( nextSlot >= count ) nextSlot -= count;
SetActiveSlot( input, inventory, nextSlot );
}
}

24
code/ui/InventoryIcon.cs Normal file
View File

@@ -0,0 +1,24 @@

using Sandbox;
using Sandbox.UI;
using Sandbox.UI.Construct;
public class InventoryIcon : Panel
{
public Entity TargetEnt;
public Label Label;
public Label Number;
public InventoryIcon( int i, Panel parent )
{
Parent = parent;
Label = Add.Label( "empty", "item-name" );
Number = Add.Label( $"{i}", "slot-number" );
}
public void Clear()
{
Label.Text = "";
SetClass( "active", false );
}
}

25
code/ui/SandboxHud.cs Normal file
View File

@@ -0,0 +1,25 @@
using Sandbox;
using Sandbox.UI;
[Library]
public partial class SandboxHud : HudEntity<RootPanel>
{
public SandboxHud()
{
if ( !IsClient )
return;
RootPanel.StyleSheet.Load( "/ui/SandboxHud.scss" );
RootPanel.AddChild<NameTags>();
RootPanel.AddChild<CrosshairCanvas>();
RootPanel.AddChild<ChatBox>();
RootPanel.AddChild<VoiceList>();
RootPanel.AddChild<KillFeed>();
RootPanel.AddChild<Scoreboard<ScoreboardEntry>>();
RootPanel.AddChild<Health>();
RootPanel.AddChild<InventoryBar>();
RootPanel.AddChild<CurrentTool>();
RootPanel.AddChild<SpawnMenu>();
}
}

135
code/ui/SandboxHud.scss Normal file
View File

@@ -0,0 +1,135 @@
Health
{
position: absolute;
background-color: rgba( black, 0.5 );
right: 100px;
bottom: 48px;
font-size: 40px;
font-weight: bold;
color: white;
height: 80px;
padding: 0 20px;
align-items: center;
}
CurrentTool
{
position: absolute;
background: linear-gradient(to right, rgba(black, 0.5), rgba(black, 0.0));
top: 100px;
left: 0px;
padding: 30px 70px;
flex-direction: column;
width: 560px;
opacity: 0.0;
&.active
{
opacity: 1.0;
}
.title
{
font-size: 50px;
font-weight: bold;
text-shadow: 4px 4px 10px rgba( black, 0.3 );
color: white;
}
.description
{
padding-top: 5px;
padding-left: 10px;
font-size: 18px;
font-weight: normal;
text-shadow: 2px 2px 5px rgba( black, 0.3 );
color: white;
opacity: 0.8;
}
}
rootpanel
{
background-color: rgba( #333, 0 );
transition: background-color 0.2s ease-in;
&.spawnmenuopen
{
transition: background-color 0.3s ease-out;
background-color: rgba( #333, 0.9 );
}
&.devcamera
{
display: none;
}
}
InventoryBar
{
position: absolute;
width: 100%;
bottom: 48px;
justify-content: center;
align-items: flex-end;
}
InventoryIcon
{
width: 80px;
height: 80px;
background-color: rgba( #222, 0.3 );
margin: 0px 2px;
position: relative;
transition: all 0.2s ease-in-out;
margin-top: 10px;
font-family: poppins;
.item-name
{
padding: 5px;
color: white;
text-align: center;
left: 0;
right: 0;
font-size: 10px;
position: absolute;
bottom: 0;
opacity: 0.7;
transition: all 0.5s ease-in-out;
text-shadow: 1px 1px 5px black;
}
.slot-number
{
font-size: 25px;
color: black;
font-weight: 900;
opacity: 0.3;
position: absolute;
top: 1px;
right: 5px;
}
&.active
{
background-color: rgba( #0094ff, 0.5 );
transition: all 0.1s ease-out;
width: 100px;
height: 100px;
.slot-number
{
color: #275576;
}
.item-name
{
opacity: 1;
transition: all 0.1s ease-out;
font-size: 13px;
}
}
}

78
code/ui/SpawnMenu.cs Normal file
View File

@@ -0,0 +1,78 @@

using Sandbox;
using Sandbox.UI;
using Sandbox.UI.Construct;
using System;
using System.Reflection.Metadata;
using System.Threading.Tasks;
[Library]
public partial class SpawnMenu : Panel
{
public static SpawnMenu Instance;
public SpawnMenu()
{
Instance = this;
StyleSheet.Load( "/ui/SpawnMenu.scss" );
var left = Add.Panel( "left" );
{
var tabs = left.AddChild<ButtonGroup>();
tabs.AddClass( "tabs" );
var body = left.Add.Panel( "body" );
{
var props = body.AddChild<SpawnList>();
tabs.SelectedButton = tabs.AddButtonActive( "Props", ( b ) => props.SetClass( "active", b ) );
var ents = body.AddChild<EntityList>();
tabs.AddButtonActive( "Entities", ( b ) => ents.SetClass( "active", b ) );
}
}
var right = Add.Panel( "right" );
{
var tabs = right.Add.Panel( "tabs" );
{
tabs.Add.Button( "Tools" ).AddClass( "active" );
tabs.Add.Button( "Utility" );
}
var body = right.Add.Panel( "body" );
{
var list = body.Add.Panel( "toollist" );
{
foreach ( var entry in Library.GetAllAttributes<Sandbox.Tools.BaseTool>() )
{
if ( entry.Title == "BaseTool" )
continue;
var button = list.Add.Button( entry.Title );
button.SetClass( "active", entry.Name == ConsoleSystem.GetValue( "tool_current" ) );
button.AddEventListener( "onclick", () =>
{
ConsoleSystem.Run( "tool_current", entry.Name );
ConsoleSystem.Run( "inventory_current", "weapon_tool" );
foreach ( var child in list.Children )
child.SetClass( "active", child == button );
} );
}
}
body.Add.Panel( "inspector" );
}
}
}
public override void Tick()
{
base.Tick();
Parent.SetClass( "spawnmenuopen", Input.Down( InputButton.Menu ) );
}
}

177
code/ui/SpawnMenu.scss Normal file
View File

@@ -0,0 +1,177 @@
spawnmenu {
left: 0px;
right: 0px;
top: 0px;
bottom: 0px;
margin: 100px;
margin-bottom: 200px;
border-radius: 5px;
pointer-events: none;
transition: all 0.1s ease-out;
position: absolute;
font-family: poppins;
opacity: 0;
.tabs {
font-size: 16px;
flex-shrink: 0;
margin-bottom: 4px;
padding-left: 10px;
button {
padding: 6px 5px;
margin-right: 10px;
font-size: 13px;
align-items: center;
font-weight: 600;
opacity: 0.2;
color: #fff;
cursor: pointer;
//border-radius: 5px;
label {
text-shadow: 1px 1px 4px rgba( black, 0.2 );
}
&:hover {
opacity: 1;
}
&.active {
transform: scale( 1 );
opacity: 1;
color: #fff;
// background-color: #fff;//( #3273eb, 0.2 );
//color: #3273eb;
}
}
}
.left {
flex-grow: 1;
flex-direction: column;
position: relative;
left: -500px;
transition: all 0.3s ease-in;
.body {
border-radius: 10px;
background-color: rgba( #111, 0.7 );
flex-grow: 1;
}
}
.right {
margin-left: 10px;
flex-direction: column;
min-width: 450px;
flex-shrink: 0;
left: 500px;
transition: all 0.3s ease-in;
.body {
// background-color: rgba( #333, 0.95 );
flex-grow: 1;
border-radius: 10px;
background-color: rgba( #111, 0.7 );
padding: 10px;
.toollist {
flex-direction: column;
width: 150px;
color: #aaa;
button {
padding: 3px 10px;
font-size: 11px;
transition: all 0.2s ease-out;
cursor: pointer;
&:hover {
//border-left: 3px solid #3273eb;
color: white;
}
&.active {
//border-left: 5px solid #3273eb;
color: white;
}
}
}
.inspector {
//background-color: rgba( #111, 0.7 );
flex-grow: 1;
margin-left: 5px;
border-radius: 0 3px 3px 0;
}
}
}
}
.spawnmenuopen spawnmenu {
transition: all 0.2s ease-out;
pointer-events: all;
opacity: 1;
transform: scale( 1 );
.left, .right {
left: 0;
transition: all 0.1s ease-out;
}
}
.spawnpage {
display: none;
&.active {
display: flex;
opacity: 1;
}
.canvas {
overflow: scroll;
width: 100%;
flex-grow: 1;
flex-wrap: wrap;
justify-content: space-between;
margin: 10px;
border-radius: 5px;
.cell {
padding: 5px;
}
.icon {
border-radius: 16px;
color: rgba( #fff, 0.5 );
font-size: 12px;
text-align: center;
cursor: pointer;
width: 100%;
height: 100%;
background-position: center;
background-size: cover;
background-color: rgba(black, 0.1);
background-image: url( /entity/spawnicon.png );
label {
font-size: 9px;
position: absolute;
bottom: -17px;
left: 0;
right: 0;
pointer-events: none;
}
&:hover {
color: #fff;
background-color: rgba(black, 0.4);
}
&:active {
}
}
}
}

View File

@@ -0,0 +1,38 @@
using Sandbox;
using Sandbox.UI;
using Sandbox.UI.Construct;
using Sandbox.UI.Tests;
using System.Linq;
[Library]
public partial class EntityList : Panel
{
VirtualScrollPanel Canvas;
public EntityList()
{
AddClass( "spawnpage" );
AddChild( out Canvas, "canvas" );
Canvas.Layout.AutoColumns = true;
Canvas.Layout.ItemSize = new Vector2( 100, 100 );
Canvas.OnCreateCell = ( cell, data ) =>
{
var entry = (LibraryAttribute)data;
var btn = cell.Add.Button( entry.Title );
btn.AddClass( "icon" );
btn.AddEventListener( "onclick", () => ConsoleSystem.Run( "spawn_entity", entry.Name ) );
btn.Style.Background = new PanelBackground
{
Texture = Texture.Load( $"/entity/{entry.Name}.png", false )
};
};
var ents = Library.GetAllAttributes<Entity>().Where( x => x.Spawnable ).OrderBy( x => x.Title ).ToArray();
foreach ( var entry in ents )
{
Canvas.AddItem( entry );
}
}
}

37
code/ui/left/SpawnList.cs Normal file
View File

@@ -0,0 +1,37 @@
using Sandbox;
using Sandbox.UI;
using Sandbox.UI.Tests;
[Library]
public partial class SpawnList : Panel
{
VirtualScrollPanel Canvas;
public SpawnList()
{
AddClass( "spawnpage" );
AddChild( out Canvas, "canvas" );
Canvas.Layout.AutoColumns = true;
Canvas.Layout.ItemSize = new Vector2( 100, 100 );
Canvas.OnCreateCell = ( cell, data ) =>
{
var file = (string)data;
var panel = cell.Add.Panel( "icon" );
panel.AddEventListener( "onclick", () => ConsoleSystem.Run( "spawn", "models/" + file ) );
panel.Style.Background = new PanelBackground
{
Texture = Texture.Load( $"/models/{file}_c.png", false )
};
};
foreach ( var file in FileSystem.Mounted.FindFile( "models", "*.vmdl_c.png", true ) )
{
if ( string.IsNullOrWhiteSpace( file ) ) continue;
if ( file.Contains( "_lod0" ) ) continue;
if ( file.Contains( "clothes" ) ) continue;
Canvas.AddItem( file.Remove( file.Length - 6 ) );
}
}
}