2024-01-27 15:19:52 +03:00
|
|
|
|
using Content.Client._White.UserInterface.Radial;
|
2024-01-28 18:37:24 +07:00
|
|
|
|
using Content.Shared._White.Cult;
|
2025-04-13 19:03:49 +05:00
|
|
|
|
using Content.Shared._White.Cult.Components;
|
2024-01-28 18:37:24 +07:00
|
|
|
|
using Content.Shared._White.Cult.UI;
|
2025-04-13 19:03:49 +05:00
|
|
|
|
using Robust.Client.Player;
|
2024-01-27 15:19:52 +03:00
|
|
|
|
using Robust.Shared.Prototypes;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Content.Client._White.Cult.UI.CultistFactory;
|
|
|
|
|
|
|
|
|
|
|
|
public sealed class CultistFactoryBUI : BoundUserInterface
|
|
|
|
|
|
{
|
|
|
|
|
|
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
2025-04-13 19:03:49 +05:00
|
|
|
|
[Dependency] private readonly EntityManager _entityManager = default!;
|
2024-01-27 15:19:52 +03:00
|
|
|
|
private RadialContainer? _radialContainer;
|
|
|
|
|
|
|
|
|
|
|
|
private bool _updated = false;
|
|
|
|
|
|
|
|
|
|
|
|
public CultistFactoryBUI(EntityUid owner, Enum uiKey) : base(owner, uiKey)
|
|
|
|
|
|
{
|
|
|
|
|
|
IoCManager.InjectDependencies(this);
|
|
|
|
|
|
}
|
|
|
|
|
|
private void ResetUI()
|
|
|
|
|
|
{
|
2025-04-13 19:03:49 +05:00
|
|
|
|
_radialContainer?.Dispose();
|
2024-01-27 15:19:52 +03:00
|
|
|
|
_radialContainer = null;
|
|
|
|
|
|
_updated = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override void Open()
|
|
|
|
|
|
{
|
|
|
|
|
|
base.Open();
|
|
|
|
|
|
|
|
|
|
|
|
if (_radialContainer != null)
|
|
|
|
|
|
ResetUI();
|
|
|
|
|
|
|
2025-04-13 19:03:49 +05:00
|
|
|
|
if(!CanOpen())
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
2024-01-27 15:19:52 +03:00
|
|
|
|
_radialContainer = new RadialContainer();
|
|
|
|
|
|
|
2024-03-22 17:23:33 +09:00
|
|
|
|
_radialContainer.Closed += Close;
|
|
|
|
|
|
|
2024-01-27 15:19:52 +03:00
|
|
|
|
if (State != null)
|
|
|
|
|
|
UpdateState(State);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void PopulateRadial(IReadOnlyCollection<string> ids)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var id in ids)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!_prototypeManager.TryIndex<CultistFactoryProductionPrototype>(id, out var prototype))
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
if (_radialContainer == null)
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
var button = _radialContainer.AddButton(prototype.Name, prototype.Icon);
|
|
|
|
|
|
button.Controller.OnPressed += _ =>
|
|
|
|
|
|
{
|
|
|
|
|
|
Select(id);
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void Select(string id)
|
|
|
|
|
|
{
|
2025-04-13 19:03:49 +05:00
|
|
|
|
SendPredictedMessage(new CultistFactoryItemSelectedMessage(id));
|
2024-01-27 15:19:52 +03:00
|
|
|
|
ResetUI();
|
|
|
|
|
|
Close();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-04-13 19:03:49 +05:00
|
|
|
|
private bool CanOpen()
|
|
|
|
|
|
{
|
|
|
|
|
|
var localPlayer = IoCManager.Resolve<IPlayerManager>().LocalPlayer;
|
|
|
|
|
|
|
|
|
|
|
|
var uid = localPlayer?.ControlledEntity;
|
|
|
|
|
|
|
|
|
|
|
|
return uid != null && _entityManager.HasComponent<CultistComponent>(uid);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-01-27 15:19:52 +03:00
|
|
|
|
protected override void Dispose(bool disposing)
|
|
|
|
|
|
{
|
|
|
|
|
|
base.Dispose(disposing);
|
|
|
|
|
|
ResetUI();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override void UpdateState(BoundUserInterfaceState state)
|
|
|
|
|
|
{
|
|
|
|
|
|
base.UpdateState(state);
|
|
|
|
|
|
|
|
|
|
|
|
if (_updated)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
if (state is CultistFactoryBUIState newState)
|
|
|
|
|
|
{
|
|
|
|
|
|
PopulateRadial(newState.Ids);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (_radialContainer == null)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
_radialContainer?.OpenAttachedLocalPlayer();
|
|
|
|
|
|
_updated = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|