2021-03-10 14:48:29 +01:00
|
|
|
|
using System.Linq;
|
2021-06-09 22:19:39 +02:00
|
|
|
|
using Content.Shared.Crayon;
|
2021-12-03 15:35:57 +01:00
|
|
|
|
using Content.Shared.Decals;
|
2021-02-11 01:13:03 -08:00
|
|
|
|
using Robust.Client.GameObjects;
|
2024-07-21 14:48:13 +10:00
|
|
|
|
using Robust.Client.UserInterface;
|
2021-03-10 14:48:29 +01:00
|
|
|
|
using Robust.Shared.Prototypes;
|
2020-10-13 13:40:05 +02:00
|
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
|
namespace Content.Client.Crayon.UI
|
2020-10-13 13:40:05 +02:00
|
|
|
|
{
|
2022-02-16 00:23:23 -07:00
|
|
|
|
public sealed class CrayonBoundUserInterface : BoundUserInterface
|
2020-10-13 13:40:05 +02:00
|
|
|
|
{
|
2024-07-21 14:48:13 +10:00
|
|
|
|
[Dependency] private readonly IPrototypeManager _protoManager = default!;
|
|
|
|
|
|
|
2023-07-08 09:02:17 -07:00
|
|
|
|
[ViewVariables]
|
|
|
|
|
|
private CrayonWindow? _menu;
|
|
|
|
|
|
|
|
|
|
|
|
public CrayonBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
|
2020-10-13 13:40:05 +02:00
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override void Open()
|
|
|
|
|
|
{
|
|
|
|
|
|
base.Open();
|
2024-07-21 14:48:13 +10:00
|
|
|
|
_menu = this.CreateWindow<CrayonWindow>();
|
|
|
|
|
|
_menu.OnColorSelected += SelectColor;
|
|
|
|
|
|
_menu.OnSelected += Select;
|
|
|
|
|
|
PopulateCrayons();
|
2024-07-20 20:42:27 -04:00
|
|
|
|
_menu.OpenCenteredLeft();
|
2024-07-20 15:40:16 +10:00
|
|
|
|
}
|
|
|
|
|
|
|
2024-07-21 14:48:13 +10:00
|
|
|
|
private void PopulateCrayons()
|
|
|
|
|
|
{
|
|
|
|
|
|
var crayonDecals = _protoManager.EnumeratePrototypes<DecalPrototype>().Where(x => x.Tags.Contains("crayon"));
|
|
|
|
|
|
_menu?.Populate(crayonDecals);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override void OnProtoReload(PrototypesReloadedEventArgs args)
|
|
|
|
|
|
{
|
|
|
|
|
|
base.OnProtoReload(args);
|
|
|
|
|
|
|
|
|
|
|
|
if (!args.WasModified<DecalPrototype>())
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
PopulateCrayons();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-10-13 13:40:05 +02:00
|
|
|
|
protected override void UpdateState(BoundUserInterfaceState state)
|
|
|
|
|
|
{
|
|
|
|
|
|
base.UpdateState(state);
|
2021-03-10 14:48:29 +01:00
|
|
|
|
|
|
|
|
|
|
_menu?.UpdateState((CrayonBoundUserInterfaceState) state);
|
2020-10-13 13:40:05 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Select(string state)
|
|
|
|
|
|
{
|
|
|
|
|
|
SendMessage(new CrayonSelectMessage(state));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-05-09 07:16:43 +02:00
|
|
|
|
public void SelectColor(Color color)
|
2022-04-28 05:23:45 -07:00
|
|
|
|
{
|
|
|
|
|
|
SendMessage(new CrayonColorMessage(color));
|
|
|
|
|
|
}
|
2020-10-13 13:40:05 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|