85 lines
2.6 KiB
C#
85 lines
2.6 KiB
C#
using Content.Client.UserInterface.Controls;
|
|
using Content.Shared._DV.Reputation;
|
|
using Robust.Client.AutoGenerated;
|
|
using Robust.Client.UserInterface.Controls;
|
|
using Robust.Client.UserInterface.XAML;
|
|
|
|
namespace Content.Client._DV.Reputation.UI;
|
|
|
|
[GenerateTypedNameReferences]
|
|
public sealed partial class ContractsWindow : FancyWindow
|
|
{
|
|
[Dependency] private EntityManager _entMan = default!;
|
|
private readonly ReputationSystem _reputation;
|
|
|
|
public event Action<int>? OnAccept;
|
|
public event Action<int>? OnComplete;
|
|
public event Action<int>? OnReject;
|
|
|
|
public EntityUid Owner;
|
|
|
|
public ContractsWindow()
|
|
{
|
|
RobustXamlLoader.Load(this);
|
|
IoCManager.InjectDependencies(this);
|
|
|
|
_reputation = _entMan.System<ReputationSystem>();
|
|
UpdateState();
|
|
}
|
|
|
|
public void UpdateState()
|
|
{
|
|
if (!_entMan.TryGetComponent<StoreContractsComponent>(Owner, out var store))
|
|
return;
|
|
|
|
if (_reputation.GetContracts(store.Mind) is not {} contracts)
|
|
return;
|
|
|
|
var comp = contracts.Comp;
|
|
if (comp.CurrentLevel is {} level)
|
|
Level.Text = Loc.GetString(level.Name);
|
|
Reputation.Text = $"{comp.Reputation} Reputation";
|
|
|
|
Contracts.RemoveAllChildren();
|
|
var slotsFull = true;
|
|
for (int i = 0; i < comp.Slots.Count; i++)
|
|
{
|
|
var index = i;
|
|
if (comp.Slots[i].ObjectiveTitle is {} title)
|
|
{
|
|
var contract = new Contract(title);
|
|
contract.OnComplete += () => OnComplete?.Invoke(index);
|
|
Contracts.AddChild(contract);
|
|
// TODO: green when objective is complete
|
|
}
|
|
else
|
|
{
|
|
var empty = new EmptyContract(comp.Slots[i].NextUnlock);
|
|
empty.OnUnlock += EnableAccepts;
|
|
if (!empty.IsLocked)
|
|
slotsFull = false;
|
|
Contracts.AddChild(empty);
|
|
}
|
|
}
|
|
|
|
Offerings.RemoveAllChildren();
|
|
for (int i = 0; i < comp.OfferingSlots.Count; i++)
|
|
{
|
|
var index = i;
|
|
var offering = new ContractOffering(comp.OfferingSlots[i]);
|
|
offering.AcceptDisabled = slotsFull;
|
|
offering.OnAccept += () => OnAccept?.Invoke(index);
|
|
offering.OnReject += () => OnReject?.Invoke(index);
|
|
Offerings.AddChild(offering);
|
|
}
|
|
}
|
|
|
|
private void EnableAccepts()
|
|
{
|
|
foreach (var child in Offerings.Children)
|
|
{
|
|
((ContractOffering) child).AcceptDisabled = false;
|
|
}
|
|
}
|
|
}
|