mirror of
https://github.com/DeltaV-Station/Delta-v.git
synced 2026-10-01 00:27:59 +00:00
Add the ability to spawn in as a vent critter at will (#6187)
* Add the ability to spawn in as a vent critter at will * cooldown
This commit is contained in:
@@ -2,10 +2,12 @@
|
||||
using Content.Client.Ghost;
|
||||
using Content.Client.UserInterface.Systems.Gameplay;
|
||||
using Content.Client.UserInterface.Systems.Ghost.Widgets;
|
||||
using Content.Shared._DV.Ghost.Roles; // DeltaV - freeform ghosties
|
||||
using Content.Shared.Ghost;
|
||||
using Robust.Shared.Console; // Frontier
|
||||
using Robust.Client.UserInterface;
|
||||
using Robust.Client.UserInterface.Controllers;
|
||||
using Robust.Shared.Prototypes; // DeltaV - freeform ghosties
|
||||
using Content.Shared._Corvax.Respawn; // Frontier
|
||||
|
||||
namespace Content.Client.UserInterface.Systems.Ghost;
|
||||
@@ -33,6 +35,7 @@ public sealed class GhostUIController : UIController, IOnSystemChanged<GhostSyst
|
||||
|
||||
// DeltaV
|
||||
SubscribeNetworkEvent<RespawnResetEvent>(OnRespawnReseted);
|
||||
SubscribeNetworkEvent<DVSpawnableGhostRoleCooldownUpdateEvent>(OnVentCritterCooldownUpdate); // DeltaV - freeform ghosties
|
||||
}
|
||||
|
||||
private void OnScreenLoad()
|
||||
@@ -151,6 +154,8 @@ public sealed class GhostUIController : UIController, IOnSystemChanged<GhostSyst
|
||||
Gui.RequestWarpsPressed += RequestWarps;
|
||||
Gui.ReturnToBodyPressed += ReturnToBody;
|
||||
Gui.GhostRolesPressed += GhostRolesPressed;
|
||||
Gui.VentCritterPressed += OnVentCritterPressed; // DeltaV - freeform ghosties
|
||||
Gui.VentCritterSelected += OnVentCritterSelected; // DeltaV - freeform ghosties
|
||||
Gui.TargetWindow.WarpClicked += OnWarpClicked;
|
||||
Gui.TargetWindow.OnGhostnadoClicked += OnGhostnadoClicked;
|
||||
Gui.GhostRespawnPressed += GuiOnGhostRespawnPressed; // Frontier
|
||||
@@ -173,6 +178,8 @@ public sealed class GhostUIController : UIController, IOnSystemChanged<GhostSyst
|
||||
Gui.RequestWarpsPressed -= RequestWarps;
|
||||
Gui.ReturnToBodyPressed -= ReturnToBody;
|
||||
Gui.GhostRolesPressed -= GhostRolesPressed;
|
||||
Gui.VentCritterPressed -= OnVentCritterPressed; // DeltaV - freeform ghosties
|
||||
Gui.VentCritterSelected -= OnVentCritterSelected; // DeltaV - freeform ghosties
|
||||
Gui.TargetWindow.WarpClicked -= OnWarpClicked;
|
||||
Gui.GhostRespawnPressed -= GuiOnGhostRespawnPressed; // Frontier
|
||||
|
||||
@@ -195,4 +202,21 @@ public sealed class GhostUIController : UIController, IOnSystemChanged<GhostSyst
|
||||
{
|
||||
_system?.OpenGhostRoles();
|
||||
}
|
||||
|
||||
// Begin DeltaV - freeform ghosties
|
||||
private void OnVentCritterPressed()
|
||||
{
|
||||
_net.SendSystemNetworkMessage(new DVSpawnableGhostRoleCooldownRequestEvent());
|
||||
}
|
||||
|
||||
private void OnVentCritterSelected(ProtoId<DVSpawnableGhostRolePrototype> role)
|
||||
{
|
||||
_net.SendSystemNetworkMessage(new DVSpawnableGhostRoleRequestEvent(role));
|
||||
}
|
||||
|
||||
private void OnVentCritterCooldownUpdate(DVSpawnableGhostRoleCooldownUpdateEvent msg, EntitySessionEventArgs args)
|
||||
{
|
||||
Gui?.VentCritterWindow.SetCooldownEnd(msg.CooldownEnd);
|
||||
}
|
||||
// End DeltaV - freeform ghosties
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
<Button Name="ReturnToBodyButton" Text="{Loc ghost-gui-return-to-body-button}" />
|
||||
<Button Name="GhostWarpButton" Text="{Loc ghost-gui-ghost-warp-button}" />
|
||||
<Button Name="GhostRolesButton" />
|
||||
<Button Name="VentCritterButton" Text="{Loc ghost-gui-spawn-vent-critter-button}" /> <!-- DeltaV: freeform ghosties -->
|
||||
<Button Name="GhostRespawnButton" Text="{Loc ghost-gui-respawn}" /> <!-- Frontier -->
|
||||
</BoxContainer>
|
||||
</widgets:GhostGui>
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
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
|
||||
|
||||
@@ -17,10 +20,13 @@ public sealed partial class GhostGui : UIWidget
|
||||
|
||||
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;
|
||||
|
||||
@@ -31,6 +37,8 @@ public sealed partial class GhostGui : UIWidget
|
||||
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;
|
||||
|
||||
@@ -38,12 +46,18 @@ public sealed partial class GhostGui : UIWidget
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -97,6 +111,7 @@ public sealed partial class GhostGui : UIWidget
|
||||
if (disposing)
|
||||
{
|
||||
TargetWindow.Dispose();
|
||||
VentCritterWindow.Dispose(); // DeltaV - freeform ghosties
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,145 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using Content.Client.UserInterface.Controls;
|
||||
using Content.Client.UserInterface.Systems.Ghost.Controls.Roles;
|
||||
using Content.Shared._DV.Ghost.Roles;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Content.Client._DV.Ghost;
|
||||
|
||||
public sealed class DVSpawnableGhostRoleWindow : FancyWindow
|
||||
{
|
||||
public event Action<ProtoId<DVSpawnableGhostRolePrototype>>? RoleSelected;
|
||||
|
||||
private GhostRoleRulesWindow? _windowRules;
|
||||
private readonly BoxContainer _entries;
|
||||
[Dependency] private readonly IPrototypeManager _prototype = default!;
|
||||
[Dependency] private readonly IGameTiming _timing = default!;
|
||||
private readonly List<Button> _spawnButtons = new();
|
||||
private TimeSpan? _cooldownEnd;
|
||||
|
||||
public DVSpawnableGhostRoleWindow()
|
||||
{
|
||||
IoCManager.InjectDependencies(this);
|
||||
|
||||
Title = Loc.GetString("ghost-gui-spawn-vent-critter-window-title");
|
||||
MinSize = new Vector2(490, 400);
|
||||
SetSize = new Vector2(490, 500);
|
||||
|
||||
_entries = new BoxContainer
|
||||
{
|
||||
Orientation = BoxContainer.LayoutOrientation.Vertical,
|
||||
SeparationOverride = 8,
|
||||
Margin = new Thickness(8),
|
||||
};
|
||||
|
||||
var scroll = new ScrollContainer
|
||||
{
|
||||
HScrollEnabled = false,
|
||||
Children =
|
||||
{
|
||||
_entries,
|
||||
},
|
||||
};
|
||||
|
||||
ContentsContainer.AddChild(scroll);
|
||||
Populate();
|
||||
|
||||
OnClose += () => _windowRules?.Close();
|
||||
}
|
||||
|
||||
private void Populate()
|
||||
{
|
||||
var roles = _prototype.EnumeratePrototypes<DVSpawnableGhostRolePrototype>()
|
||||
.OrderBy(role => Loc.GetString(role.Name));
|
||||
|
||||
foreach (var role in roles)
|
||||
{
|
||||
var info = new GhostRoleInfoBox(Loc.GetString(role.Name), Loc.GetString(role.Description));
|
||||
|
||||
var button = new Button
|
||||
{
|
||||
Text = Loc.GetString("ghost-gui-spawn-vent-critter-spawn-button"),
|
||||
VerticalAlignment = VAlignment.Center,
|
||||
};
|
||||
|
||||
var id = new ProtoId<DVSpawnableGhostRolePrototype>(role.ID);
|
||||
button.OnPressed += _ =>
|
||||
{
|
||||
if (IsCooldownActive())
|
||||
return;
|
||||
|
||||
_windowRules?.Close();
|
||||
|
||||
_windowRules = new GhostRoleRulesWindow(Loc.GetString(role.Rules),
|
||||
_ =>
|
||||
{
|
||||
RoleSelected?.Invoke(id);
|
||||
Close();
|
||||
});
|
||||
_windowRules.OnClose += () =>
|
||||
{
|
||||
_windowRules = null;
|
||||
};
|
||||
_windowRules.OpenCentered();
|
||||
};
|
||||
|
||||
_entries.AddChild(info);
|
||||
_entries.AddChild(button);
|
||||
_spawnButtons.Add(button);
|
||||
}
|
||||
|
||||
if (_entries.ChildCount != 0)
|
||||
return;
|
||||
|
||||
_entries.AddChild(new Label
|
||||
{
|
||||
Text = Loc.GetString("ghost-gui-spawn-vent-critter-none"),
|
||||
});
|
||||
}
|
||||
|
||||
public void SetCooldownEnd(TimeSpan? cooldownEnd)
|
||||
{
|
||||
_cooldownEnd = cooldownEnd;
|
||||
UpdateCooldownButtons();
|
||||
}
|
||||
|
||||
protected override void FrameUpdate(FrameEventArgs args)
|
||||
{
|
||||
base.FrameUpdate(args);
|
||||
|
||||
UpdateCooldownButtons();
|
||||
}
|
||||
|
||||
[MemberNotNullWhen(true, nameof(_cooldownEnd))]
|
||||
private bool IsCooldownActive()
|
||||
{
|
||||
return _cooldownEnd > _timing.CurTime;
|
||||
}
|
||||
|
||||
private void UpdateCooldownButtons()
|
||||
{
|
||||
if (IsCooldownActive())
|
||||
{
|
||||
var seconds = Math.Ceiling((_cooldownEnd.Value - _timing.CurTime).TotalSeconds);
|
||||
foreach (var button in _spawnButtons)
|
||||
{
|
||||
button.Disabled = true;
|
||||
button.Text = Loc.GetString("ghost-gui-spawn-vent-critter-spawn-cooldown", ("time", seconds));
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var button in _spawnButtons)
|
||||
{
|
||||
button.Disabled = false;
|
||||
button.Text = Loc.GetString("ghost-gui-spawn-vent-critter-spawn-button");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user