Skip to content

Commit

Permalink
Port respawning from Frontierstation/Corvax
Browse files Browse the repository at this point in the history
  • Loading branch information
sowelipililimute committed Feb 21, 2025
1 parent 4f1d717 commit 783fc5b
Show file tree
Hide file tree
Showing 11 changed files with 435 additions and 0 deletions.
48 changes: 48 additions & 0 deletions Content.Client/UserInterface/Systems/Ghost/GhostUIController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,25 @@
using Content.Client.UserInterface.Systems.Gameplay;
using Content.Client.UserInterface.Systems.Ghost.Widgets;
using Content.Shared.Ghost;
using Robust.Client.Console; // Frontier
using Robust.Shared.Console; // Frontier
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controllers;
using Content.Client._Corvax.Respawn; // Frontier
using Content.Shared._NF.CCVar; // Frontier
using Robust.Shared.Configuration; // Frontier

namespace Content.Client.UserInterface.Systems.Ghost;

// TODO hud refactor BEFORE MERGE fix ghost gui being too far up
public sealed class GhostUIController : UIController, IOnSystemChanged<GhostSystem>
{
[Dependency] private readonly IEntityNetworkManager _net = default!;
[Dependency] private readonly IConsoleHost _consoleHost = default!; // Frontier
[Dependency] private readonly IConfigurationManager _cfg = default!; // Frontier

[UISystemDependency] private readonly GhostSystem? _system = default;
[UISystemDependency] private readonly RespawnSystem? _respawn = default; // Frontier

private GhostGui? Gui => UIManager.GetActiveUIWidgetOrNull<GhostGui>();

Expand Down Expand Up @@ -56,6 +64,24 @@ public void OnSystemUnloaded(GhostSystem system)
system.GhostRoleCountUpdated -= OnRoleCountUpdated;
}

// Begin Frontier
public void OnSystemLoaded(RespawnSystem system)
{
system.RespawnReseted += OnRespawnReseted;
}

public void OnSystemUnloaded(RespawnSystem system)
{
system.RespawnReseted -= OnRespawnReseted;
}

private void OnRespawnReseted()
{
UpdateGui();
UpdateRespawn(_respawn?.RespawnResetTime);
}
// End Frontier

public void UpdateGui()
{
if (Gui == null)
Expand All @@ -67,6 +93,13 @@ public void UpdateGui()
Gui.Update(_system?.AvailableGhostRoleCount, _system?.Player?.CanReturnToBody);
}

// Begin Frontier
private void UpdateRespawn(TimeSpan? timeOfDeath)
{
Gui?.UpdateRespawn(timeOfDeath);
}
// End Frontier

private void OnPlayerRemoved(GhostComponent component)
{
Gui?.Hide();
Expand All @@ -83,6 +116,7 @@ private void OnPlayerAttached(GhostComponent component)
return;

Gui.Visible = true;
UpdateRespawn(_respawn?.RespawnResetTime); // Frontier
UpdateGui();
}

Expand Down Expand Up @@ -127,10 +161,18 @@ public void LoadGui()
Gui.GhostRolesPressed += GhostRolesPressed;
Gui.TargetWindow.WarpClicked += OnWarpClicked;
Gui.TargetWindow.OnGhostnadoClicked += OnGhostnadoClicked;
Gui.GhostRespawnPressed += GuiOnGhostRespawnPressed; // Frontier

UpdateGui();
}

// Begin Frontier
private void GuiOnGhostRespawnPressed()
{
_consoleHost.ExecuteCommand("ghostrespawn");
}
// End Frontier

public void UnloadGui()
{
if (Gui == null)
Expand All @@ -140,6 +182,7 @@ public void UnloadGui()
Gui.ReturnToBodyPressed -= ReturnToBody;
Gui.GhostRolesPressed -= GhostRolesPressed;
Gui.TargetWindow.WarpClicked -= OnWarpClicked;
Gui.GhostRespawnPressed -= GuiOnGhostRespawnPressed; // Frontier

Gui.Hide();
}
Expand All @@ -160,4 +203,9 @@ private void GhostRolesPressed()
{
_system?.OpenGhostRoles();
}

private void RespawnPressed()
{
IoCManager.Resolve<IClientConsoleHost>().RemoteExecuteCommand(null, "ghostrespawn");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
<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="GhostRespawnButton" Text="{Loc ghost-gui-respawn}" /> <!-- Frontier -->
</BoxContainer>
</widgets:GhostGui>
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,42 @@
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Timing; // Frontier
using Robust.Shared.Configuration; // 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
[Dependency] private readonly IConfigurationManager _configurationManager = default!; // Frontier

private TimeSpan? _respawnTime; // Frontier

public GhostTargetWindow TargetWindow { get; }
public GhostRespawnRulesWindow RulesWindow { get; } // Frontier

public event Action? RequestWarpsPressed;
public event Action? ReturnToBodyPressed;
public event Action? GhostRolesPressed;
public event Action? GhostRespawnPressed; // Frontier

public GhostGui()
{
RobustXamlLoader.Load(this);

TargetWindow = new GhostTargetWindow();
RulesWindow = new GhostRespawnRulesWindow(); // Frontier
RulesWindow.RespawnButton.OnPressed += _ => GhostRespawnPressed?.Invoke(); // Frontier

MouseFilter = MouseFilterMode.Ignore;

GhostWarpButton.OnPressed += _ => RequestWarpsPressed?.Invoke();
ReturnToBodyButton.OnPressed += _ => ReturnToBodyPressed?.Invoke();
GhostRolesButton.OnPressed += _ => GhostRolesPressed?.Invoke();
GhostRespawnButton.OnPressed += _ => RulesWindow.OpenCentered(); // Frontier
}

public void Hide()
Expand All @@ -34,6 +47,13 @@ public void Hide()
Visible = false;
}

// Begin Frontier
public void UpdateRespawn(TimeSpan? respawnTime)
{
_respawnTime = respawnTime;
}
// End Frontier

public void Update(int? roles, bool? canReturnToBody)
{
ReturnToBodyButton.Disabled = !canReturnToBody ?? true;
Expand All @@ -54,6 +74,23 @@ public void Update(int? roles, bool? canReturnToBody)
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);
Expand Down
22 changes: 22 additions & 0 deletions Content.Client/_Corvax/Respawn/RespawnSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Content.Shared._Corvax.Respawn;

namespace Content.Client._Corvax.Respawn;

public sealed class RespawnSystem : EntitySystem
{
public TimeSpan? RespawnResetTime { get; private set; }

public event Action? RespawnReseted;

public override void Initialize()
{
SubscribeNetworkEvent<RespawnResetEvent>(OnRespawnReset);
}

private void OnRespawnReset(RespawnResetEvent e)
{
RespawnResetTime = e.Time;

RespawnReseted?.Invoke();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<controls:FancyWindow xmlns="https://spacestation14.io"
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
xmlns:graphics="clr-namespace:Robust.Client.Graphics;assembly=Robust.Client"
Title="{Loc 'ghost-respawn-rules-window-title'}"
MinSize="500 350">
<ScrollContainer VerticalExpand="True" HorizontalExpand="True" HScrollEnabled="False" Margin="5">
<PanelContainer StyleClasses="Inset">
<PanelContainer.PanelOverride>
<graphics:StyleBoxFlat BackgroundColor="#303133"/>
</PanelContainer.PanelOverride>

<BoxContainer Orientation="Vertical" VerticalExpand="True" SeparationOverride="5">
<PanelContainer Name="TextContainer" StyleClasses="Inset" Margin="5">
<PanelContainer.PanelOverride>
<!-- <graphics:StyleBoxFlat BackgroundColor="#464950"/> -->
<graphics:StyleBoxFlat BackgroundColor="#303133"/>
</PanelContainer.PanelOverride>
</PanelContainer>

<Control VerticalExpand="True" VerticalAlignment="Stretch" />
<Button Name="ConfirmRespawnButton" Text="{Loc 'ghost-respawn-rules-window-confirm-button'}" Margin="5" />
</BoxContainer>
</PanelContainer>
</ScrollContainer>
</controls:FancyWindow>
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Content.Client.UserInterface.Controls;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Utility;

namespace Content.Client._NF.UserInterface.Systems.Ghost.Controls
{
[GenerateTypedNameReferences]
public sealed partial class GhostRespawnRulesWindow : FancyWindow
{
public PanelContainer RulesContainer => TextContainer;
public RichTextLabel RulesLabel = new() { Margin = new Thickness(5, 5, 5, 5) };
public Button RespawnButton => ConfirmRespawnButton;

public GhostRespawnRulesWindow()
{
RobustXamlLoader.Load(this);

var message = new FormattedMessage();
message.AddMarkup(Loc.GetString("ghost-respawn-rules-window-rules"));
RulesLabel.SetMessage(message);
RulesContainer.AddChild(RulesLabel);
RulesLabel.SetPositionFirst();

RespawnButton.OnPressed += _ => Close();
}
}
}
Loading

0 comments on commit 783fc5b

Please sign in to comment.