Skip to content

Commit

Permalink
lost and found ui (#475)
Browse files Browse the repository at this point in the history
  • Loading branch information
MilonPL authored Nov 20, 2024
1 parent fd12092 commit f491408
Show file tree
Hide file tree
Showing 21 changed files with 641 additions and 242 deletions.
60 changes: 0 additions & 60 deletions Content.Client/_CD/CryoSleep/AcceptCryoWindow.cs

This file was deleted.

17 changes: 17 additions & 0 deletions Content.Client/_CD/CryoSleep/AcceptCryoWindow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<DefaultWindow xmlns="https://spacestation14.io"
Title="{Loc 'accept-cryo-window-title'}"
MinSize="300 100"
MaxSize="300 100">
<BoxContainer Orientation="Vertical">
<BoxContainer Orientation="Vertical">
<Label Text="{Loc accept-cryo-window-prompt-text-part}" />
<BoxContainer Orientation="Horizontal" Align="Center">
<Button Name="AcceptButton"
Text="{Loc accept-cryo-window-accept-button}" />
<Control MinWidth="20" />
<Button Name="DenyButton"
Text="{Loc accept-cryo-window-deny-button}" />
</BoxContainer>
</BoxContainer>
</BoxContainer>
</DefaultWindow>
29 changes: 29 additions & 0 deletions Content.Client/_CD/CryoSleep/AcceptCryoWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Content.Shared._CD.CryoSleep;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.CustomControls;
using Robust.Client.UserInterface.XAML;

namespace Content.Client._CD.CryoSleep;

[GenerateTypedNameReferences]
public sealed partial class AcceptCryoWindow : DefaultWindow
{
public event Action<AcceptCryoUiButton>? OnChoice;

public AcceptCryoWindow()
{
RobustXamlLoader.Load(this);

AcceptButton.OnPressed += _ =>
{
OnChoice?.Invoke(AcceptCryoUiButton.Accept);
Close();
};

DenyButton.OnPressed += _ =>
{
OnChoice?.Invoke(AcceptCryoUiButton.Deny);
Close();
};
}
}
14 changes: 1 addition & 13 deletions Content.Client/_CD/CryoSleep/CryoSleepEui.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,7 @@ public sealed class CryoSleepEui : BaseEui
public CryoSleepEui()
{
_window = new AcceptCryoWindow();

_window.DenyButton.OnPressed += _ =>
{
SendMessage(new AcceptCryoChoiceMessage(AcceptCryoUiButton.Deny));
_window.Close();
};

_window.AcceptButton.OnPressed += _ =>
{
SendMessage(new AcceptCryoChoiceMessage(AcceptCryoUiButton.Accept));
_window.Close();
};
_window.OnChoice += choice => SendMessage(new AcceptCryoChoiceMessage(choice));
}

public override void Opened()
Expand All @@ -37,5 +26,4 @@ public override void Closed()
{
_window.Close();
}

}
49 changes: 49 additions & 0 deletions Content.Client/_CD/CryoSleep/LostAndFoundBUI.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using Content.Shared._CD.CryoSleep;
using Robust.Client.Player;

namespace Content.Client._CD.CryoSleep;

public sealed class LostAndFoundBoundUserInterface : BoundUserInterface
{
[Dependency] private readonly IEntityManager _entManager = default!;
[Dependency] private readonly IPlayerManager _playerManager = default!;

private LostAndFoundWindow? _window;

public LostAndFoundBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
{
_window = new LostAndFoundWindow();
_window.OnRetrieveItem += OnRetrieveItem;
}

private void OnRetrieveItem(string playerName, string slotName)
{
if ( _playerManager.LocalEntity is not { } user)
return;

var netEntity = _entManager.GetNetEntity(user);
SendMessage(new LostAndFoundRetrieveItemMessage(playerName, slotName, netEntity));
}

protected override void UpdateState(BoundUserInterfaceState state)
{
base.UpdateState(state);
if (state is LostAndFoundBuiState msg)
_window?.Populate(msg.StoredPlayers);
}

protected override void Open()
{
base.Open();
_window?.OpenCentered();
}

protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (!disposing)
return;
_window?.Close();
_window = null;
}
}
13 changes: 13 additions & 0 deletions Content.Client/_CD/CryoSleep/LostAndFoundItemControl.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<BoxContainer
xmlns="https://spacestation14.io"
Orientation="Horizontal"
HorizontalExpand="True"
Margin="5">
<RichTextLabel Name="SlotLabel" HorizontalAlignment="Left"/>
<Control HorizontalExpand="True"/>
<BoxContainer Orientation="Horizontal"
HorizontalAlignment="Right">
<Label Name="ItemLabel" Margin="0 0 5 0"/>
<Button Name="Button" Access="Public" Text="{Loc 'lost-and-found-retrieve-button'}"></Button>
</BoxContainer>
</BoxContainer>
22 changes: 22 additions & 0 deletions Content.Client/_CD/CryoSleep/LostAndFoundItemControl.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Content.Client.Message;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;

namespace Content.Client._CD.CryoSleep;

[GenerateTypedNameReferences]
public sealed partial class LostAndFoundItemControl : BoxContainer
{
public LostAndFoundItemControl(string slotName, string itemName)
{
RobustXamlLoader.Load(this);

// Replace spaces with underscores so that held items dont troll us
var locKey = $"lost-and-found-slot-{slotName.ToLower().Replace(" ", "_")}";
var localizedSlot = Loc.GetString(locKey);

SlotLabel.SetMarkup(localizedSlot);
ItemLabel.Text = itemName;
}
}
22 changes: 22 additions & 0 deletions Content.Client/_CD/CryoSleep/LostAndFoundPlayerEntry.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<BoxContainer
xmlns="https://spacestation14.io"
xmlns:graphics="clr-namespace:Robust.Client.Graphics;assembly=Robust.Client"
xmlns:xNamespace="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:style="clr-namespace:Content.Client.Stylesheets"
Orientation="Vertical"
HorizontalExpand="True"
Margin="0 0 0 5">
<PanelContainer>
<PanelContainer.PanelOverride>
<graphics:StyleBoxFlat BackgroundColor="{xNamespace:Static style:StyleNano.ButtonColorDisabled}" />
</PanelContainer.PanelOverride>
<Collapsible Name="Collapsible">
<CollapsibleHeading Name="Heading" MinHeight="35"/>
<CollapsibleBody Name="Body">
<BoxContainer Name="ItemsList"
Orientation="Vertical"
HorizontalExpand="True"/>
</CollapsibleBody>
</Collapsible>
</PanelContainer>
</BoxContainer>
37 changes: 37 additions & 0 deletions Content.Client/_CD/CryoSleep/LostAndFoundPlayerEntry.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using Content.Shared._CD.CryoSleep;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;

namespace Content.Client._CD.CryoSleep;

[GenerateTypedNameReferences]
public sealed partial class LostAndFoundPlayerEntry : BoxContainer
{
public event Action<string>? OnRetrieveItem;

public LostAndFoundPlayerEntry(string playerName, List<LostItemData> items)
{
RobustXamlLoader.Load(this);

Heading.Title = playerName;
UpdateItems(items);
}

public void UpdateItems(List<LostItemData> items)
{
var wasVisible = Collapsible.BodyVisible;
Body.Visible = items.Count != 0;

ItemsList.RemoveAllChildren();

foreach (var item in items)
{
var control = new LostAndFoundItemControl(item.SlotName, item.ItemName);
control.Button.OnPressed += _ => OnRetrieveItem?.Invoke(item.SlotName);
ItemsList.AddChild(control);
}

Collapsible.BodyVisible = wasVisible;
}
}
34 changes: 34 additions & 0 deletions Content.Client/_CD/CryoSleep/LostAndFoundWindow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<controls:FancyWindow
xmlns="https://spacestation14.io"
xmlns:graphics="clr-namespace:Robust.Client.Graphics;assembly=Robust.Client"
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
xmlns:xNamespace="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:style="clr-namespace:Content.Client.Stylesheets"
Title="{Loc 'lost-and-found-title'}"
MinSize="350 350"
SetSize="450 400">
<BoxContainer
Orientation="Vertical"
VerticalExpand="True"
HorizontalExpand="True">
<PanelContainer
VerticalExpand="True"
HorizontalExpand="True"
Margin="15">
<PanelContainer.PanelOverride>
<graphics:StyleBoxFlat BackgroundColor="{xNamespace:Static style:StyleNano.PanelDark}" />
</PanelContainer.PanelOverride>
<ScrollContainer VerticalExpand="True" HorizontalExpand="True">
<Control>
<Label Text="{Loc 'lost-and-found-no-items'}" Name="EmptyLabel" HorizontalAlignment="Center"
VerticalAlignment="Center" />
<BoxContainer Name="PlayersContainer"
Orientation="Vertical"
Margin="10"
VerticalExpand="True"
HorizontalExpand="True" />
</Control>
</ScrollContainer>
</PanelContainer>
</BoxContainer>
</controls:FancyWindow>
52 changes: 52 additions & 0 deletions Content.Client/_CD/CryoSleep/LostAndFoundWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using Content.Client.UserInterface.Controls;
using Content.Shared._CD.CryoSleep;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.XAML;

namespace Content.Client._CD.CryoSleep;

[GenerateTypedNameReferences]
public sealed partial class LostAndFoundWindow : FancyWindow
{
private readonly Dictionary<string, LostAndFoundPlayerEntry> _entries = new();

public event Action<string, string>? OnRetrieveItem;

public LostAndFoundWindow()
{
RobustXamlLoader.Load(this);
Title = Loc.GetString("lost-and-found-title");
}

public void Populate(Dictionary<string, List<LostItemData>> players)
{
EmptyLabel.Visible = players.Count == 0;

var toRemove = new HashSet<string>(_entries.Keys);

foreach (var (playerName, items) in players)
{
toRemove.Remove(playerName);

if (_entries.TryGetValue(playerName, out var existing))
{
existing.UpdateItems(items);
continue;
}

var entry = new LostAndFoundPlayerEntry(playerName, items);
entry.OnRetrieveItem += (slot) => OnRetrieveItem?.Invoke(playerName, slot);
_entries.Add(playerName, entry);
PlayersContainer.AddChild(entry);
}

// Remove entries for players who no longer have items
foreach (var playerName in toRemove)
{
if (_entries.Remove(playerName, out var entry))
{
PlayersContainer.RemoveChild(entry);
}
}
}
}
Loading

0 comments on commit f491408

Please sign in to comment.