H.O.N.K. mech (#14670)
Co-authored-by: deltanedas <@deltanedas:kde.org>
This commit is contained in:
36
Content.Client/Mech/Ui/Equipment/MechSoundboardUi.cs
Normal file
36
Content.Client/Mech/Ui/Equipment/MechSoundboardUi.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using Content.Client.UserInterface.Fragments;
|
||||
using Content.Shared.Mech;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.UserInterface;
|
||||
|
||||
namespace Content.Client.Mech.Ui.Equipment;
|
||||
|
||||
public sealed class MechSoundboardUi : UIFragment
|
||||
{
|
||||
private MechSoundboardUiFragment? _fragment;
|
||||
|
||||
public override Control GetUIFragmentRoot()
|
||||
{
|
||||
return _fragment!;
|
||||
}
|
||||
|
||||
public override void Setup(BoundUserInterface userInterface, EntityUid? fragmentOwner)
|
||||
{
|
||||
if (fragmentOwner == null)
|
||||
return;
|
||||
|
||||
_fragment = new MechSoundboardUiFragment();
|
||||
_fragment.OnPlayAction += sound =>
|
||||
{
|
||||
userInterface.SendMessage(new MechSoundboardPlayMessage(fragmentOwner.Value, sound));
|
||||
};
|
||||
}
|
||||
|
||||
public override void UpdateState(BoundUserInterfaceState state)
|
||||
{
|
||||
if (state is not MechSoundboardUiState soundboardState)
|
||||
return;
|
||||
|
||||
_fragment?.UpdateContents(soundboardState);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<equipment:MechSoundboardUiFragment
|
||||
xmlns:equipment="clr-namespace:Content.Client.Mech.Ui.Equipment"
|
||||
xmlns="https://spacestation14.io" Margin="1 0 2 0" HorizontalExpand="True" VerticalExpand="True">
|
||||
<BoxContainer Orientation="Vertical"
|
||||
HorizontalExpand="True"
|
||||
VerticalExpand="True">
|
||||
<ItemList Name="Sounds"
|
||||
VerticalExpand="True"
|
||||
MinHeight="160"
|
||||
HorizontalExpand="True"
|
||||
SelectMode="Button"/>
|
||||
</BoxContainer>
|
||||
</equipment:MechSoundboardUiFragment>
|
||||
@@ -0,0 +1,28 @@
|
||||
using Content.Shared.Mech;
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
|
||||
namespace Content.Client.Mech.Ui.Equipment;
|
||||
|
||||
[GenerateTypedNameReferences]
|
||||
public sealed partial class MechSoundboardUiFragment : BoxContainer
|
||||
{
|
||||
public event Action<int>? OnPlayAction;
|
||||
|
||||
public MechSoundboardUiFragment()
|
||||
{
|
||||
RobustXamlLoader.Load(this);
|
||||
IoCManager.InjectDependencies(this);
|
||||
}
|
||||
|
||||
public void UpdateContents(MechSoundboardUiState state)
|
||||
{
|
||||
foreach (var sound in state.Sounds)
|
||||
{
|
||||
Sounds.AddItem(Loc.GetString($"mech-soundboard-{sound}")).OnSelected += item => {
|
||||
OnPlayAction?.Invoke(Sounds.IndexOf(item));
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user