Files
tbd-station-14/Content.Client/Salvage/UI/OfferingWindow.xaml.cs
metalgearsloth bf79acd127 Salvage magnet revamp (#23119)
* Generic offering window

* More work

* weh

* Parity

* Progression meter

* magnet

* rona

* PG asteroid work

* code red

* Asteroid spawnings

* clams

* a

* Marker fixes

* More fixes

* Workings of biome asteroids

* A

* Fix this loading code

* a

* Fix masking

* weh

* Fixes

* Magnet claiming

* toe

* petogue

* magnet

* Bunch of fixes

* Fix default

* Fixes

* asteroids

* Fix offerings

* Localisation and a bunch of fixes

* a

* Fixes

* Preliminary draft

* Announcement fixes

* Fixes and bump spawn rate

* Fix asteroid spawns and UI

* More fixes

* Expeditions fix

* fix

* Gravity

* Fix announcement rounding

* a

* Offset tweak

* sus

* jankass

* Fix merge
2024-01-04 14:25:32 +11:00

118 lines
2.9 KiB
C#

using Content.Client.Computer;
using Content.Client.UserInterface.Controls;
using Content.Shared.Shuttles.BUIStates;
using Robust.Client.AutoGenerated;
using Robust.Client.Graphics;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Timing;
namespace Content.Client.Salvage.UI;
/// <summary>
/// Generic window for offering multiple selections with a timer.
/// </summary>
[GenerateTypedNameReferences]
public sealed partial class OfferingWindow : FancyWindow,
IComputerWindow<EmergencyConsoleBoundUserInterfaceState>
{
[Dependency] private readonly IGameTiming _timing = default!;
public bool Claimed;
public TimeSpan NextOffer;
private TimeSpan? _progression;
/// <summary>
/// Time between NextOffers
/// </summary>
public TimeSpan Cooldown;
/// <summary>
/// Time between Progressions
/// </summary>
public TimeSpan ProgressionCooldown;
/// <summary>
/// Secondary timer used for tracking active progress.
/// </summary>
public TimeSpan? Progression
{
get => _progression;
set
{
if (_progression == value)
return;
_progression = value;
if (value == null)
{
ProgressionBox.Visible = false;
}
else
{
ProgressionBox.Visible = true;
}
}
}
public OfferingWindow()
{
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);
ProgressionBar.ForegroundStyleBoxOverride = new StyleBoxFlat(Color.FromHex("#C74EBD"));
}
public void AddOption(OfferingWindowOption option)
{
Container.AddChild(option);
}
public void ClearOptions()
{
Container.DisposeAllChildren();
}
protected override void FrameUpdate(FrameEventArgs args)
{
base.FrameUpdate(args);
if (_progression != null)
{
var remaining = _progression.Value - _timing.CurTime;
if (remaining < TimeSpan.Zero)
{
ProgressionBar.Value = 1f;
ProgressionText.Text = "00:00";
}
else
{
ProgressionBar.Value = 1f - (float) (remaining / ProgressionCooldown);
ProgressionText.Text = $"{remaining.Minutes:00}:{remaining.Seconds:00}";
}
}
if (Claimed)
{
NextOfferBar.Value = 1f;
NextOfferText.Text = "00:00";
}
else
{
var remaining = NextOffer - _timing.CurTime;
if (remaining < TimeSpan.Zero)
{
NextOfferBar.Value = 1f;
NextOfferText.Text = "00:00";
}
else
{
NextOfferBar.Value = 1f - (float) (remaining / Cooldown);
NextOfferText.Text = $"{remaining.Minutes:00}:{remaining.Seconds:00}";
}
}
}
}