60 lines
2 KiB
C#
60 lines
2 KiB
C#
using System.Linq;
|
|
using System.Numerics;
|
|
using Content.Client._Sunrise;
|
|
using Content.Client._Sunrise.CartridgeLoader.Cartridges;
|
|
using Content.Shared._Sunrise.CartridgeLoader.Cartridges;
|
|
using Robust.Client.AutoGenerated;
|
|
using Robust.Client.ResourceManagement;
|
|
using Robust.Client.UserInterface.Controls;
|
|
using Robust.Client.UserInterface.CustomControls;
|
|
using Robust.Client.UserInterface.XAML;
|
|
using Robust.Shared.Timing;
|
|
|
|
namespace Content.Client.MassMedia.Ui;
|
|
|
|
[GenerateTypedNameReferences]
|
|
public sealed partial class PhotoSelectorWindow : DefaultWindow
|
|
{
|
|
[Dependency] private readonly NetTexturesManager _netTexturesManager = default!;
|
|
[Dependency] private readonly IResourceCache _resourceCache = default!;
|
|
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
|
|
|
public event Action<string>? PhotoSelected;
|
|
|
|
public PhotoSelectorWindow()
|
|
{
|
|
IoCManager.InjectDependencies(this);
|
|
RobustXamlLoader.Load(this);
|
|
|
|
Title = Loc.GetString("news-write-ui-select-photo-title");
|
|
MinSize = new Vector2(560, 620);
|
|
}
|
|
|
|
public void Populate(List<PhotoMetadata> photos)
|
|
{
|
|
PhotosContainer.Children.Clear();
|
|
|
|
if (photos.Count == 0)
|
|
{
|
|
PhotosContainer.AddChild(new Label
|
|
{
|
|
Text = Loc.GetString("news-write-ui-no-photos"),
|
|
HorizontalAlignment = HAlignment.Center,
|
|
Margin = new Thickness(0, 20)
|
|
});
|
|
return;
|
|
}
|
|
|
|
foreach (var metadata in photos.OrderByDescending(p => p.Timestamp))
|
|
{
|
|
var photoControl = new PhotoItemControl(metadata.ImagePath, metadata, _netTexturesManager, _resourceCache, _gameTiming);
|
|
photoControl.MinSize = new Vector2(120, 120);
|
|
photoControl.OnPressed += _ =>
|
|
{
|
|
PhotoSelected?.Invoke(metadata.ImagePath);
|
|
Close();
|
|
};
|
|
PhotosContainer.AddChild(photoControl);
|
|
}
|
|
}
|
|
}
|