using Content.Client.TextScreen; using Robust.Client.AutoGenerated; using Robust.Client.GameObjects; using Robust.Client.UserInterface.CustomControls; using Robust.Client.UserInterface.XAML; using Robust.Shared.Prototypes; using Robust.Shared.Timing; namespace Content.Client._White.Cult.UI.Altar; [GenerateTypedNameReferences] public partial class AltarWindow : DefaultWindow { [Dependency] private readonly IGameTiming _gameTiming = default!; [Dependency] private readonly SpriteSystem _spriteSystem = default!; [Dependency] private readonly PrototypeManager _prototypeManager = default!; public event Action? OnItemSelected; private TimeSpan? _nextTimeUse = null!; private List _listingControls = new(); public AltarWindow() { RobustXamlLoader.Load(this); IoCManager.InjectDependencies(this); } protected override void FrameUpdate(FrameEventArgs args) { base.FrameUpdate(args); if (_nextTimeUse == null) return; var remainingTime = _nextTimeUse.Value - _gameTiming.CurTime; if (remainingTime.TotalSeconds < 0) { remainingTime = TimeSpan.Zero; } var remainingTimeText = TextScreenSystem.TimeToString(remainingTime); TimerLabel.SetMessage(remainingTimeText); } public void SetListing(List prototypes) { foreach (var prototypeId in prototypes) { var prototype = _prototypeManager.Index(prototypeId); if(prototype == null) return; var prototypeIcon = _spriteSystem.GetPrototypeIcon(prototype).Default; AddListingControl(prototype); } } public void AddListingControl(EntityPrototype entityPrototype) { var icon = _spriteSystem.GetPrototypeIcon(entityPrototype).Default; var control = new AltarListingControl(entityPrototype, icon, OnItemSelected); ListingContainer.AddChild(control); _listingControls.Add(control); } public void SetTimer(TimeSpan? timer) { _nextTimeUse = timer; if (timer == null) { TimerLabel.SetMessage("Алтарь готов к использованию"); SetListingButtonsState(true); return; } SetListingButtonsState(false); } private void SetListingButtonsState(bool enabled) { foreach (var listingControl in _listingControls) { listingControl.BuyListingButton.Disabled = enabled; } } }