CrayonWindow to XAML UI (#4987)

* Create and rename files

* CrayonWindow to XAML
This commit is contained in:
Visne
2021-10-27 05:35:46 +02:00
committed by GitHub
parent 4bef8d3dde
commit ae2f9fb83a
2 changed files with 34 additions and 45 deletions

View File

@@ -0,0 +1,13 @@
<SS14Window xmlns="https://spacestation14.io"
Title="{Loc 'crayon-window-title'}"
MinSize="250 300"
SetSize="250 300">
<BoxContainer Orientation="Vertical">
<LineEdit Name="Search" />
<ScrollContainer VerticalExpand="True">
<GridContainer Name="Grid" Columns="6">
<!-- Crayon decals get added here by code -->
</GridContainer>
</ScrollContainer>
</BoxContainer>
</SS14Window>

View File

@@ -1,66 +1,43 @@
using System.Collections.Generic;
using Content.Client.Stylesheets;
using Content.Shared.Crayon;
using Robust.Client.AutoGenerated;
using Robust.Client.Graphics;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
using Robust.Client.UserInterface.XAML;
using Robust.Client.Utility;
using Robust.Shared.Localization;
using Robust.Shared.Maths;
using Robust.Shared.Utility;
using static Robust.Client.UserInterface.Controls.BaseButton;
using static Robust.Client.UserInterface.Controls.BoxContainer;
namespace Content.Client.Crayon.UI
{
public class CrayonWindow : SS14Window
[GenerateTypedNameReferences]
public partial 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;
public CrayonWindow(CrayonBoundUserInterface owner)
{
MinSize = SetSize = (250, 300);
Title = Loc.GetString("crayon-window-title");
RobustXamlLoader.Load(this);
Owner = owner;
var vbox = new BoxContainer
{
Orientation = LayoutOrientation.Vertical
};
Contents.AddChild(vbox);
_search = new LineEdit();
_search.OnTextChanged += (_) => RefreshList();
vbox.AddChild(_search);
_grid = new GridContainer()
{
Columns = 6,
};
var gridScroll = new ScrollContainer()
{
VerticalExpand = true,
Children =
{
_grid
}
};
vbox.AddChild(gridScroll);
Search.OnTextChanged += _ => RefreshList();
}
private void RefreshList()
{
// Clear
_grid.RemoveAllChildren();
if (_decals == null)
return;
Grid.RemoveAllChildren();
if (_decals == null) return;
var filter = _search.Text;
var filter = Search.Text;
foreach (var (decal, tex) in _decals)
{
if (!decal.Contains(filter))
@@ -71,7 +48,7 @@ namespace Content.Client.Crayon.UI
TextureNormal = tex,
Name = decal,
ToolTip = decal,
Modulate = _color
Modulate = _color,
};
button.OnPressed += ButtonOnPressed;
if (_selected == decal)
@@ -84,27 +61,26 @@ namespace Content.Client.Crayon.UI
},
Children =
{
button
}
button,
},
};
_grid.AddChild(panelContainer);
Grid.AddChild(panelContainer);
}
else
{
_grid.AddChild(button);
Grid.AddChild(button);
}
}
}
private void ButtonOnPressed(ButtonEventArgs obj)
{
if (obj.Button.Name != null)
{
if (obj.Button.Name == null) return;
Owner.Select(obj.Button.Name);
_selected = obj.Button.Name;
RefreshList();
}
}
public void UpdateState(CrayonBoundUserInterfaceState state)
{