main cult

This commit is contained in:
EnefFlow
2024-01-27 15:19:52 +03:00
committed by Aviu00
parent 6310813ce6
commit 4fab8188f0
429 changed files with 12281 additions and 9 deletions

View File

@@ -0,0 +1,56 @@
using Content.Shared.White.Cult.UI;
using JetBrains.Annotations;
using Robust.Client.GameObjects;
using Robust.Shared.Prototypes;
using Robust.Shared.Timing;
namespace Content.Client._White.Cult.UI.Altar;
[UsedImplicitly]
public sealed class AltarBUI : BoundUserInterface
{
private AltarWindow? _window;
public AltarBUI(EntityUid owner, Enum uiKey) : base(owner, uiKey)
{
IoCManager.InjectDependencies(this);
}
protected override void Open()
{
base.Open();
_window = new AltarWindow();
_window.OnClose += Close;
_window.OnItemSelected += OnItemSelected;
}
private void OnItemSelected(string item)
{
var evt = new AltarBuyRequest(item);
SendMessage(evt);
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (!disposing) return;
_window?.Dispose();
}
protected override void UpdateState(BoundUserInterfaceState state)
{
base.UpdateState(state);
if (state is AltarListingBUIState listingState)
{
_window?.SetListing(listingState.Items);
}
else if(state is AltarTimerBUIState timerState)
{
_window?.SetTimer(timerState.NextTimeUse);
}
}
}

View File

@@ -0,0 +1,9 @@
<Control SetSize="50 50" MaxSize="50 50" xmlns="https://spacestation14.io"
xmlns:graphics="clr-namespace:Robust.Client.Graphics;assembly=Robust.Client">
<PanelContainer>
<PanelContainer.PanelOverride>
<graphics:StyleBoxFlat BackgroundColor="#000000FF" />
</PanelContainer.PanelOverride>
<TextureButton Name="BuyListingButton" Access="Public" HorizontalAlignment="Center" VerticalAlignment="Center" SetSize="48 48" MaxSize="48 48"/>
</PanelContainer>
</Control>

View File

@@ -0,0 +1,21 @@
using Robust.Client.AutoGenerated;
using Robust.Client.Graphics;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Prototypes;
namespace Content.Client._White.Cult.UI.Altar;
[GenerateTypedNameReferences]
public partial class AltarListingControl : Control
{
public AltarListingControl(EntityPrototype prototype, Texture icon, Action<string>? clickAction)
{
RobustXamlLoader.Load(this);
ToolTip = $"{prototype.Name}\n{prototype.Description}";
BuyListingButton.TextureNormal = icon;
BuyListingButton.OnButtonDown += _ => clickAction?.Invoke(prototype.ID);
}
}

View File

@@ -0,0 +1,7 @@
<DefaultWindow xmlns="https://spacestation14.io"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="{Loc agent-id-menu-title}">
<RichTextLabel Name="TimerLabel"></RichTextLabel>
<BoxContainer Name="ListingContainer" Orientation="Horizontal" SeparationOverride="4" MinWidth="150">
</BoxContainer>
</DefaultWindow>

View File

@@ -0,0 +1,92 @@
using Content.Client.GameTicking.Managers;
using Content.Client.TextScreen;
using Robust.Client.AutoGenerated;
using Robust.Client.GameObjects;
using Robust.Client.Graphics;
using Robust.Client.UserInterface.Controls;
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<string>? OnItemSelected;
private TimeSpan? _nextTimeUse = null!;
private List<AltarListingControl> _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<string> prototypes)
{
foreach (var prototypeId in prototypes)
{
var prototype = _prototypeManager.Index<EntityPrototype>(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;
}
}
}