CrayonWindow to XAML UI (#4987)
* Create and rename files * CrayonWindow to XAML
This commit is contained in:
13
Content.Client/Crayon/UI/CrayonWindow.xaml
Normal file
13
Content.Client/Crayon/UI/CrayonWindow.xaml
Normal 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>
|
||||||
@@ -1,66 +1,43 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Content.Client.Stylesheets;
|
using Content.Client.Stylesheets;
|
||||||
using Content.Shared.Crayon;
|
using Content.Shared.Crayon;
|
||||||
|
using Robust.Client.AutoGenerated;
|
||||||
using Robust.Client.Graphics;
|
using Robust.Client.Graphics;
|
||||||
using Robust.Client.UserInterface.Controls;
|
using Robust.Client.UserInterface.Controls;
|
||||||
using Robust.Client.UserInterface.CustomControls;
|
using Robust.Client.UserInterface.CustomControls;
|
||||||
|
using Robust.Client.UserInterface.XAML;
|
||||||
using Robust.Client.Utility;
|
using Robust.Client.Utility;
|
||||||
using Robust.Shared.Localization;
|
|
||||||
using Robust.Shared.Maths;
|
using Robust.Shared.Maths;
|
||||||
using Robust.Shared.Utility;
|
using Robust.Shared.Utility;
|
||||||
using static Robust.Client.UserInterface.Controls.BaseButton;
|
using static Robust.Client.UserInterface.Controls.BaseButton;
|
||||||
using static Robust.Client.UserInterface.Controls.BoxContainer;
|
|
||||||
|
|
||||||
namespace Content.Client.Crayon.UI
|
namespace Content.Client.Crayon.UI
|
||||||
{
|
{
|
||||||
public class CrayonWindow : SS14Window
|
[GenerateTypedNameReferences]
|
||||||
|
public partial class CrayonWindow : SS14Window
|
||||||
{
|
{
|
||||||
public CrayonBoundUserInterface Owner { get; }
|
public CrayonBoundUserInterface Owner { get; }
|
||||||
private readonly LineEdit _search;
|
|
||||||
private readonly GridContainer _grid;
|
|
||||||
private Dictionary<string, Texture>? _decals;
|
private Dictionary<string, Texture>? _decals;
|
||||||
private string? _selected;
|
private string? _selected;
|
||||||
private Color _color;
|
private Color _color;
|
||||||
|
|
||||||
public CrayonWindow(CrayonBoundUserInterface owner)
|
public CrayonWindow(CrayonBoundUserInterface owner)
|
||||||
{
|
{
|
||||||
MinSize = SetSize = (250, 300);
|
RobustXamlLoader.Load(this);
|
||||||
Title = Loc.GetString("crayon-window-title");
|
|
||||||
Owner = owner;
|
Owner = owner;
|
||||||
|
|
||||||
var vbox = new BoxContainer
|
Search.OnTextChanged += _ => RefreshList();
|
||||||
{
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RefreshList()
|
private void RefreshList()
|
||||||
{
|
{
|
||||||
// Clear
|
// Clear
|
||||||
_grid.RemoveAllChildren();
|
Grid.RemoveAllChildren();
|
||||||
if (_decals == null)
|
if (_decals == null) return;
|
||||||
return;
|
|
||||||
|
|
||||||
var filter = _search.Text;
|
var filter = Search.Text;
|
||||||
foreach (var (decal, tex) in _decals)
|
foreach (var (decal, tex) in _decals)
|
||||||
{
|
{
|
||||||
if (!decal.Contains(filter))
|
if (!decal.Contains(filter))
|
||||||
@@ -71,7 +48,7 @@ namespace Content.Client.Crayon.UI
|
|||||||
TextureNormal = tex,
|
TextureNormal = tex,
|
||||||
Name = decal,
|
Name = decal,
|
||||||
ToolTip = decal,
|
ToolTip = decal,
|
||||||
Modulate = _color
|
Modulate = _color,
|
||||||
};
|
};
|
||||||
button.OnPressed += ButtonOnPressed;
|
button.OnPressed += ButtonOnPressed;
|
||||||
if (_selected == decal)
|
if (_selected == decal)
|
||||||
@@ -84,26 +61,25 @@ namespace Content.Client.Crayon.UI
|
|||||||
},
|
},
|
||||||
Children =
|
Children =
|
||||||
{
|
{
|
||||||
button
|
button,
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
_grid.AddChild(panelContainer);
|
Grid.AddChild(panelContainer);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_grid.AddChild(button);
|
Grid.AddChild(button);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ButtonOnPressed(ButtonEventArgs obj)
|
private void ButtonOnPressed(ButtonEventArgs obj)
|
||||||
{
|
{
|
||||||
if (obj.Button.Name != null)
|
if (obj.Button.Name == null) return;
|
||||||
{
|
|
||||||
Owner.Select(obj.Button.Name);
|
Owner.Select(obj.Button.Name);
|
||||||
_selected = obj.Button.Name;
|
_selected = obj.Button.Name;
|
||||||
RefreshList();
|
RefreshList();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void UpdateState(CrayonBoundUserInterfaceState state)
|
public void UpdateState(CrayonBoundUserInterfaceState state)
|
||||||
Reference in New Issue
Block a user