2021-06-21 02:13:54 +02:00
|
|
|
using System.Collections.Generic;
|
2021-06-09 22:19:39 +02:00
|
|
|
using Content.Client.Stylesheets;
|
|
|
|
|
using Content.Shared.Crayon;
|
2021-12-03 15:35:57 +01:00
|
|
|
using Content.Shared.Decals;
|
2021-10-27 05:35:46 +02:00
|
|
|
using Robust.Client.AutoGenerated;
|
2020-10-13 13:40:05 +02:00
|
|
|
using Robust.Client.Graphics;
|
|
|
|
|
using Robust.Client.UserInterface.Controls;
|
|
|
|
|
using Robust.Client.UserInterface.CustomControls;
|
2021-10-27 05:35:46 +02:00
|
|
|
using Robust.Client.UserInterface.XAML;
|
2020-10-13 13:40:05 +02:00
|
|
|
using Robust.Client.Utility;
|
2023-09-11 19:18:06 +10:00
|
|
|
using Robust.Shared.Graphics;
|
2020-10-13 13:40:05 +02:00
|
|
|
using Robust.Shared.Maths;
|
|
|
|
|
using Robust.Shared.Utility;
|
2021-03-10 14:48:29 +01:00
|
|
|
using static Robust.Client.UserInterface.Controls.BaseButton;
|
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
|
|
|
{
|
2021-10-27 05:35:46 +02:00
|
|
|
[GenerateTypedNameReferences]
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed partial class CrayonWindow : DefaultWindow
|
2020-10-13 13:40:05 +02:00
|
|
|
{
|
2021-03-10 14:48:29 +01:00
|
|
|
private Dictionary<string, Texture>? _decals;
|
|
|
|
|
private string? _selected;
|
2020-10-13 13:40:05 +02:00
|
|
|
private Color _color;
|
|
|
|
|
|
2024-07-21 14:48:13 +10:00
|
|
|
public event Action<Color>? OnColorSelected;
|
|
|
|
|
public event Action<string>? OnSelected;
|
|
|
|
|
|
|
|
|
|
public CrayonWindow()
|
2020-10-13 13:40:05 +02:00
|
|
|
{
|
2021-10-27 05:35:46 +02:00
|
|
|
RobustXamlLoader.Load(this);
|
2020-10-13 13:40:05 +02:00
|
|
|
|
2021-10-27 05:35:46 +02:00
|
|
|
Search.OnTextChanged += _ => RefreshList();
|
2022-04-28 05:23:45 -07:00
|
|
|
ColorSelector.OnColorChanged += SelectColor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SelectColor(Color color)
|
|
|
|
|
{
|
|
|
|
|
_color = color;
|
|
|
|
|
|
2024-07-21 14:48:13 +10:00
|
|
|
OnColorSelected?.Invoke(color);
|
2022-04-28 05:23:45 -07:00
|
|
|
RefreshList();
|
2020-10-13 13:40:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void RefreshList()
|
|
|
|
|
{
|
|
|
|
|
// Clear
|
2024-07-21 14:48:13 +10:00
|
|
|
Grid.DisposeAllChildren();
|
|
|
|
|
if (_decals == null)
|
|
|
|
|
return;
|
2020-10-13 13:40:05 +02:00
|
|
|
|
2021-10-27 05:35:46 +02:00
|
|
|
var filter = Search.Text;
|
2020-10-13 13:40:05 +02:00
|
|
|
foreach (var (decal, tex) in _decals)
|
|
|
|
|
{
|
|
|
|
|
if (!decal.Contains(filter))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
var button = new TextureButton()
|
|
|
|
|
{
|
|
|
|
|
TextureNormal = tex,
|
|
|
|
|
Name = decal,
|
|
|
|
|
ToolTip = decal,
|
2021-10-27 05:35:46 +02:00
|
|
|
Modulate = _color,
|
2020-10-13 13:40:05 +02:00
|
|
|
};
|
2021-03-10 14:48:29 +01:00
|
|
|
button.OnPressed += ButtonOnPressed;
|
2020-10-13 13:40:05 +02:00
|
|
|
if (_selected == decal)
|
|
|
|
|
{
|
|
|
|
|
var panelContainer = new PanelContainer()
|
|
|
|
|
{
|
|
|
|
|
PanelOverride = new StyleBoxFlat()
|
|
|
|
|
{
|
|
|
|
|
BackgroundColor = StyleNano.ButtonColorDefault,
|
|
|
|
|
},
|
|
|
|
|
Children =
|
|
|
|
|
{
|
2021-10-27 05:35:46 +02:00
|
|
|
button,
|
|
|
|
|
},
|
2020-10-13 13:40:05 +02:00
|
|
|
};
|
2021-10-27 05:35:46 +02:00
|
|
|
Grid.AddChild(panelContainer);
|
2020-10-13 13:40:05 +02:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-10-27 05:35:46 +02:00
|
|
|
Grid.AddChild(button);
|
2020-10-13 13:40:05 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-10 14:48:29 +01:00
|
|
|
private void ButtonOnPressed(ButtonEventArgs obj)
|
2020-10-13 13:40:05 +02:00
|
|
|
{
|
2021-10-27 05:35:46 +02:00
|
|
|
if (obj.Button.Name == null) return;
|
|
|
|
|
|
|
|
|
|
_selected = obj.Button.Name;
|
2024-07-22 19:22:59 -07:00
|
|
|
OnSelected?.Invoke(_selected);
|
2021-10-27 05:35:46 +02:00
|
|
|
RefreshList();
|
2020-10-13 13:40:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void UpdateState(CrayonBoundUserInterfaceState state)
|
|
|
|
|
{
|
|
|
|
|
_selected = state.Selected;
|
2022-04-28 05:23:45 -07:00
|
|
|
ColorSelector.Visible = state.SelectableColor;
|
2020-10-13 13:40:05 +02:00
|
|
|
_color = state.Color;
|
2022-04-28 05:23:45 -07:00
|
|
|
|
|
|
|
|
if (ColorSelector.Visible)
|
|
|
|
|
{
|
|
|
|
|
ColorSelector.Color = state.Color;
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-13 13:40:05 +02:00
|
|
|
RefreshList();
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-03 15:35:57 +01:00
|
|
|
public void Populate(IEnumerable<DecalPrototype> prototypes)
|
2020-10-13 13:40:05 +02:00
|
|
|
{
|
|
|
|
|
_decals = new Dictionary<string, Texture>();
|
2021-12-03 15:35:57 +01:00
|
|
|
foreach (var decalPrototype in prototypes)
|
2020-10-13 13:40:05 +02:00
|
|
|
{
|
2021-12-03 15:35:57 +01:00
|
|
|
_decals.Add(decalPrototype.ID, decalPrototype.Sprite.Frame0());
|
2020-10-13 13:40:05 +02:00
|
|
|
}
|
2021-02-21 12:38:56 +01:00
|
|
|
|
2020-10-13 13:40:05 +02:00
|
|
|
RefreshList();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|