- add: more interaction shit

This commit is contained in:
2024-02-26 21:43:11 +03:00
parent b63a46e032
commit a31947423c
27 changed files with 752 additions and 97 deletions

View File

@@ -1,33 +1,65 @@
using Content.Shared._Amour.InteractionPanel;
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;
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();
}
public void AddButton(string id)
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.InteractionId = id;
btn.OnInteraction += _id => OnInteraction?.Invoke(_id);
Interactions.AddChild(btn);
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);
}
TargetView.SetEntity(state.Target);
PerformerView.SetEntity(state.Performer);