100 lines
3.0 KiB
C#
100 lines
3.0 KiB
C#
using System.Linq;
|
|
using Content.Shared._Amour.InteractionPanel;
|
|
using Robust.Client.AutoGenerated;
|
|
using Robust.Client.UserInterface.Controls;
|
|
using Robust.Client.UserInterface.CustomControls;
|
|
using Robust.Client.UserInterface.XAML;
|
|
using Robust.Shared.Prototypes;
|
|
using Robust.Shared.Utility;
|
|
|
|
namespace Content.Client._Amour.InteractionPanel.UI;
|
|
|
|
[GenerateTypedNameReferences]
|
|
public sealed partial class InteractionPanelWindow : DefaultWindow
|
|
{
|
|
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
|
public event Action<string>? OnInteraction;
|
|
|
|
public event Action? OnUpdateRequired;
|
|
|
|
public Dictionary<string, int> Groups = new();
|
|
|
|
public InteractionPanelWindow()
|
|
{
|
|
RobustXamlLoader.Load(this);
|
|
IoCManager.InjectDependencies(this);
|
|
|
|
DisCheckbox.OnPressed += _ => OnUpdateRequired?.Invoke();
|
|
UpdateButton.OnPressed += _ => OnUpdateRequired?.Invoke();
|
|
}
|
|
|
|
public void AddButton(InteractionEntry entry)
|
|
{
|
|
if (!_prototypeManager.TryIndex<InteractionPrototype>(entry.Prototype, out var prototype)
|
|
|| !_prototypeManager.TryIndex(prototype.Group, out var groupPrototype))
|
|
return;
|
|
|
|
if (!Groups.TryGetValue(prototype.Group, out var box))
|
|
return;
|
|
|
|
if (DisCheckbox.Pressed && !entry.Enabled)
|
|
return;
|
|
|
|
var btn = new InteractionPanelButton();
|
|
btn.Color = groupPrototype.Color;
|
|
btn.InteractionId = entry.Prototype;
|
|
btn.OnInteraction += id => OnInteraction?.Invoke(id);
|
|
|
|
btn.Disabled = !entry.Enabled;
|
|
|
|
Interactions.GetChild(box).AddChild(btn);
|
|
}
|
|
|
|
public void Update(InteractionState state)
|
|
{
|
|
Interactions.Children.Clear();
|
|
Groups.Clear();
|
|
foreach (var prototype in _prototypeManager.EnumeratePrototypes<InteractionGroupPrototype>().OrderBy(p => p.Priority))
|
|
{
|
|
var box = new BoxContainer();
|
|
Interactions.AddChild(box);
|
|
box.Orientation = BoxContainer.LayoutOrientation.Vertical;
|
|
Groups.Add(prototype.ID, Interactions.ChildCount - 1);
|
|
}
|
|
|
|
var messageUser = new FormattedMessage();
|
|
if (state.DescUser.Count == 0)
|
|
{
|
|
messageUser.AddMarkup($"- {Loc.GetString("interaction-empty")}\n");
|
|
}
|
|
|
|
foreach (var desc in state.DescUser)
|
|
{
|
|
messageUser.AddMarkup($"- {Loc.GetString(desc)}\n");
|
|
}
|
|
PerformerDesc.SetMessage(messageUser);
|
|
|
|
var messageTarget = new FormattedMessage();
|
|
if (state.DescTarget.Count == 0)
|
|
{
|
|
messageTarget.AddMarkup($"- {Loc.GetString("interaction-empty")}\n");
|
|
}
|
|
|
|
foreach (var desc in state.DescTarget)
|
|
{
|
|
messageTarget.AddMarkup($"- {Loc.GetString(desc)}\n");
|
|
}
|
|
TargerDesc.SetMessage(messageTarget);
|
|
|
|
|
|
TargetView.SetEntity(state.Target);
|
|
PerformerView.SetEntity(state.Performer);
|
|
|
|
foreach (var interaction in state.AvailableInteractions)
|
|
{
|
|
AddButton(interaction);
|
|
}
|
|
}
|
|
}
|
|
|