Crayons (#2132)
* -Added Crayons + CrayonBox -Can set any crayon state and color -Added CrayonDecals * Allows to cycle through decals (not the final thing) * ItemStatus * -UI (WIP) -Selection thing works -Changed some shitty state names * -Icons -Changed decal name * Pure Texture Grid * Charges * -Reach check -Toggle interface on use * Can't draw on windows anymore * UI now shows selected decal and color * -UseSound -Nullable * Remove unused imports * -Rotation -Made decal abstract * Remove some duplicate images * Space Cleaner cleans * Loc Title Co-authored-by: Pieter-Jan Briers <pieterjan.briers@gmail.com> * Review adressed Co-authored-by: Pieter-Jan Briers <pieterjan.briers@gmail.com>
This commit is contained in:
123
Content.Client/GameObjects/Components/Crayon/CrayonWindow.cs
Normal file
123
Content.Client/GameObjects/Components/Crayon/CrayonWindow.cs
Normal file
@@ -0,0 +1,123 @@
|
||||
using Content.Client.UserInterface.Stylesheets;
|
||||
using Content.Shared.GameObjects.Components;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.Graphics.Drawing;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Client.Utility;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Utility;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Content.Client.GameObjects.Components.Crayon
|
||||
{
|
||||
public class CrayonWindow : SS14Window
|
||||
{
|
||||
public CrayonBoundUserInterface Owner { get; }
|
||||
private readonly LineEdit _search;
|
||||
private readonly GridContainer _grid;
|
||||
private Dictionary<string, Texture> _decals;
|
||||
private string _selected;
|
||||
private Color _color;
|
||||
|
||||
protected override Vector2? CustomSize => (250, 300);
|
||||
|
||||
public CrayonWindow(CrayonBoundUserInterface owner)
|
||||
{
|
||||
Title = Loc.GetString("Crayon");
|
||||
Owner = owner;
|
||||
|
||||
var vbox = new VBoxContainer();
|
||||
Contents.AddChild(vbox);
|
||||
|
||||
_search = new LineEdit();
|
||||
_search.OnTextChanged += (e) => RefreshList();
|
||||
vbox.AddChild(_search);
|
||||
|
||||
_grid = new GridContainer()
|
||||
{
|
||||
Columns = 6,
|
||||
};
|
||||
var gridScroll = new ScrollContainer()
|
||||
{
|
||||
SizeFlagsVertical = SizeFlags.FillExpand,
|
||||
Children =
|
||||
{
|
||||
_grid
|
||||
}
|
||||
};
|
||||
vbox.AddChild(gridScroll);
|
||||
}
|
||||
|
||||
private void RefreshList()
|
||||
{
|
||||
// Clear
|
||||
_grid.RemoveAllChildren();
|
||||
if (_decals == null)
|
||||
return;
|
||||
|
||||
var filter = _search.Text;
|
||||
foreach (var (decal, tex) in _decals)
|
||||
{
|
||||
if (!decal.Contains(filter))
|
||||
continue;
|
||||
|
||||
var button = new TextureButton()
|
||||
{
|
||||
TextureNormal = tex,
|
||||
Name = decal,
|
||||
ToolTip = decal,
|
||||
Modulate = _color
|
||||
};
|
||||
button.OnPressed += Button_OnPressed;
|
||||
if (_selected == decal)
|
||||
{
|
||||
var panelContainer = new PanelContainer()
|
||||
{
|
||||
PanelOverride = new StyleBoxFlat()
|
||||
{
|
||||
BackgroundColor = StyleNano.ButtonColorDefault,
|
||||
},
|
||||
Children =
|
||||
{
|
||||
button
|
||||
}
|
||||
};
|
||||
_grid.AddChild(panelContainer);
|
||||
}
|
||||
else
|
||||
{
|
||||
_grid.AddChild(button);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Button_OnPressed(BaseButton.ButtonEventArgs obj)
|
||||
{
|
||||
Owner.Select(obj.Button.Name);
|
||||
_selected = obj.Button.Name;
|
||||
RefreshList();
|
||||
}
|
||||
|
||||
public void UpdateState(CrayonBoundUserInterfaceState state)
|
||||
{
|
||||
_selected = state.Selected;
|
||||
_color = state.Color;
|
||||
RefreshList();
|
||||
}
|
||||
|
||||
public void Populate(CrayonDecalPrototype proto)
|
||||
{
|
||||
var path = new ResourcePath(proto.SpritePath);
|
||||
_decals = new Dictionary<string, Texture>();
|
||||
foreach (var state in proto.Decals)
|
||||
{
|
||||
var rsi = new SpriteSpecifier.Rsi(path, state);
|
||||
_decals.Add(state, rsi.Frame0());
|
||||
}
|
||||
|
||||
RefreshList();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user