Delta-v/Content.Client/UserInterface/Systems/Ghost/Widgets/GhostGui.xaml.cs

118 lines
4.1 KiB
C#

using Content.Client._DV.Ghost; // DeltaV - freeform ghosties
using Content.Client.Stylesheets;
using Content.Client.UserInterface.Systems.Ghost.Controls;
using Content.Shared._DV.Ghost.Roles; // DeltaV - freeform ghosties
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Prototypes; // DeltaV - freeform ghosties
using Robust.Shared.Timing; // Frontier
using Content.Client._NF.UserInterface.Systems.Ghost.Controls; // Frontier
namespace Content.Client.UserInterface.Systems.Ghost.Widgets;
[GenerateTypedNameReferences]
public sealed partial class GhostGui : UIWidget
{
[Dependency] private readonly IGameTiming _gameTiming = default!; // Frontier
private TimeSpan? _respawnTime; // Frontier
public GhostTargetWindow TargetWindow { get; }
public GhostRespawnRulesWindow RulesWindow { get; } // Frontier
public DVSpawnableGhostRoleWindow VentCritterWindow { get; } // DeltaV - freeform ghosties
public event Action? RequestWarpsPressed;
public event Action? ReturnToBodyPressed;
public event Action? GhostRolesPressed;
public event Action? VentCritterPressed; // DeltaV - freeform ghosties
public event Action<ProtoId<DVSpawnableGhostRolePrototype>>? VentCritterSelected; // DeltaV - freeform ghosties
public event Action? GhostRespawnPressed; // Frontier
private int _prevNumberRoles;
public GhostGui()
{
RobustXamlLoader.Load(this);
TargetWindow = new GhostTargetWindow();
RulesWindow = new GhostRespawnRulesWindow(); // Frontier
RulesWindow.RespawnButton.OnPressed += _ => GhostRespawnPressed?.Invoke(); // Frontier
VentCritterWindow = new DVSpawnableGhostRoleWindow(); // DeltaV - freeform ghosties
VentCritterWindow.RoleSelected += role => VentCritterSelected?.Invoke(role); // DeltaV - freeform ghosties
MouseFilter = MouseFilterMode.Ignore;
GhostWarpButton.OnPressed += _ => RequestWarpsPressed?.Invoke();
ReturnToBodyButton.OnPressed += _ => ReturnToBodyPressed?.Invoke();
GhostRolesButton.OnPressed += _ => GhostRolesPressed?.Invoke();
GhostRolesButton.OnPressed += _ => GhostRolesButton.StyleClasses.Remove(StyleClass.Negative);
VentCritterButton.OnPressed += _ =>
{
VentCritterPressed?.Invoke();
VentCritterWindow.OpenCentered();
}; // DeltaV - freeform ghosties
GhostRespawnButton.OnPressed += _ => RulesWindow.OpenCentered(); // Frontier
}
public void Hide()
{
TargetWindow.Close();
VentCritterWindow.Close(); // DeltaV - freeform ghosties
Visible = false;
}
// Begin Frontier
public void UpdateRespawn(TimeSpan? respawnTime)
{
_respawnTime = respawnTime;
}
// End Frontier
public void Update(int? roles, bool? canReturnToBody)
{
ReturnToBodyButton.Disabled = !canReturnToBody ?? true;
if (roles != null)
{
GhostRolesButton.Text = Loc.GetString("ghost-gui-ghost-roles-button", ("count", roles));
if (roles > _prevNumberRoles)
{
GhostRolesButton.StyleClasses.Add(StyleClass.Negative);
}
_prevNumberRoles = (int)roles;
}
TargetWindow.Populate();
}
// Begin Frontier
protected override void FrameUpdate(FrameEventArgs args)
{
if (_respawnTime is null || _gameTiming.CurTime > _respawnTime)
{
GhostRespawnButton.Text = Loc.GetString("ghost-gui-respawn-button-allowed");
GhostRespawnButton.Disabled = false;
}
else
{
double delta = (_respawnTime.Value - _gameTiming.CurTime).TotalSeconds;
GhostRespawnButton.Text = Loc.GetString("ghost-gui-respawn-button-denied", ("time", $"{delta:f1}"));
GhostRespawnButton.Disabled = true;
}
}
// End Frontier
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (disposing)
{
TargetWindow.Dispose();
VentCritterWindow.Dispose(); // DeltaV - freeform ghosties
}
}
}