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:
@@ -0,0 +1,49 @@
|
||||
using Content.Shared.GameObjects.Components;
|
||||
using Robust.Client.GameObjects.Components.UserInterface;
|
||||
using Robust.Shared.GameObjects.Components.UserInterface;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Prototypes;
|
||||
using System.Linq;
|
||||
|
||||
namespace Content.Client.GameObjects.Components.Crayon
|
||||
{
|
||||
public class CrayonBoundUserInterface : BoundUserInterface
|
||||
{
|
||||
public CrayonBoundUserInterface(ClientUserInterfaceComponent owner, object uiKey) : base(owner, uiKey)
|
||||
{
|
||||
}
|
||||
|
||||
private CrayonWindow _menu;
|
||||
|
||||
protected override void Open()
|
||||
{
|
||||
base.Open();
|
||||
_menu = new CrayonWindow(this);
|
||||
|
||||
_menu.OnClose += Close;
|
||||
var prototypeManager = IoCManager.Resolve<IPrototypeManager>();
|
||||
var crayonDecals = prototypeManager.EnumeratePrototypes<CrayonDecalPrototype>().FirstOrDefault();
|
||||
if (crayonDecals != null)
|
||||
_menu.Populate(crayonDecals);
|
||||
_menu.OpenCentered();
|
||||
}
|
||||
|
||||
protected override void UpdateState(BoundUserInterfaceState state)
|
||||
{
|
||||
base.UpdateState(state);
|
||||
_menu.UpdateState((CrayonBoundUserInterfaceState) state);
|
||||
}
|
||||
|
||||
public void Select(string state)
|
||||
{
|
||||
SendMessage(new CrayonSelectMessage(state));
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
base.Dispose(disposing);
|
||||
|
||||
_menu.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
using Content.Client.UserInterface.Stylesheets;
|
||||
using Content.Client.Utility;
|
||||
using Content.Shared.GameObjects.Components;
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Timing;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Client.GameObjects.Components.Crayon
|
||||
{
|
||||
[RegisterComponent]
|
||||
public class CrayonComponent : SharedCrayonComponent, IItemStatus
|
||||
{
|
||||
[ViewVariables(VVAccess.ReadWrite)] private bool _uiUpdateNeeded;
|
||||
[ViewVariables(VVAccess.ReadWrite)] private string Color => _color;
|
||||
[ViewVariables] private int Charges { get; set; }
|
||||
[ViewVariables] private int Capacity { get; set; }
|
||||
|
||||
Control IItemStatus.MakeControl()
|
||||
{
|
||||
return new StatusControl(this);
|
||||
}
|
||||
|
||||
public override void HandleComponentState(ComponentState curState, ComponentState nextState)
|
||||
{
|
||||
if (!(curState is CrayonComponentState state))
|
||||
return;
|
||||
|
||||
_color = state.Color;
|
||||
SelectedState = state.State;
|
||||
Charges = state.Charges;
|
||||
Capacity = state.Capacity;
|
||||
|
||||
_uiUpdateNeeded = true;
|
||||
}
|
||||
|
||||
private sealed class StatusControl : Control
|
||||
{
|
||||
private readonly CrayonComponent _parent;
|
||||
private readonly RichTextLabel _label;
|
||||
|
||||
public StatusControl(CrayonComponent parent)
|
||||
{
|
||||
_parent = parent;
|
||||
_label = new RichTextLabel { StyleClasses = { StyleNano.StyleClassItemStatus } };
|
||||
AddChild(_label);
|
||||
|
||||
parent._uiUpdateNeeded = true;
|
||||
}
|
||||
|
||||
protected override void Update(FrameEventArgs args)
|
||||
{
|
||||
base.Update(args);
|
||||
|
||||
if (!_parent._uiUpdateNeeded)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_parent._uiUpdateNeeded = false;
|
||||
_label.SetMarkup(Loc.GetString("Drawing: [color={0}]{1}[/color] ({2}/{3})",
|
||||
_parent.Color,
|
||||
_parent.SelectedState,
|
||||
_parent.Charges,
|
||||
_parent.Capacity));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
using Content.Shared.GameObjects.Components;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.Interfaces.GameObjects.Components;
|
||||
using Robust.Shared.Maths;
|
||||
|
||||
namespace Content.Client.GameObjects.Components.Crayon
|
||||
{
|
||||
public class CrayonDecalVisualizer : AppearanceVisualizer
|
||||
{
|
||||
public override void OnChangeData(AppearanceComponent component)
|
||||
{
|
||||
base.OnChangeData(component);
|
||||
|
||||
var sprite = component.Owner.GetComponent<SpriteComponent>();
|
||||
|
||||
var state = component.GetData<string>(CrayonVisuals.State);
|
||||
var color = component.GetData<Color>(CrayonVisuals.Color);
|
||||
var rotation = component.GetData<Angle>(CrayonVisuals.Rotation);
|
||||
|
||||
sprite.LayerSetState(0, state);
|
||||
sprite.LayerSetColor(0, color);
|
||||
sprite.Rotation = rotation;
|
||||
}
|
||||
}
|
||||
}
|
||||
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