Skip to content

Commit

Permalink
Merge pull request #31 from Corvax-Frontier/Up16072024
Browse files Browse the repository at this point in the history
Up16072024
  • Loading branch information
Vonsant authored Jul 16, 2024
2 parents d4b23ac + 6edeadb commit 18d2859
Show file tree
Hide file tree
Showing 718 changed files with 19,703 additions and 7,650 deletions.
20 changes: 19 additions & 1 deletion Content.Client/Ghost/GhostSystem.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
using Content.Client._NF.Respawn;
using Content.Client.Movement.Systems;
using Content.Client.UserInterface.Systems.Ghost.Widgets;
using Content.Shared.Actions;
using Content.Shared.Ghost;
using Content.Shared.Mind;
using Robust.Client.Console;
using Robust.Client.GameObjects;
using Robust.Client.Graphics;
using Robust.Client.Player;
using Robust.Client.UserInterface;
using Robust.Shared.Player;
using Robust.Shared.Timing;

namespace Content.Client.Ghost
{
Expand All @@ -15,6 +20,19 @@ public sealed class GhostSystem : SharedGhostSystem
[Dependency] private readonly IPlayerManager _playerManager = default!;
[Dependency] private readonly SharedActionsSystem _actions = default!;
[Dependency] private readonly ContentEyeSystem _contentEye = default!;
[Dependency] private readonly IUserInterfaceManager _uiManager = default!;
[Dependency] private readonly IGameTiming _gameTiming = default!;
[Dependency] private readonly RespawnSystem _respawn = default!;

public override void Update(float frameTime)
{
foreach (var ghost in EntityManager.EntityQuery<GhostComponent, MindComponent>(true))
{
var ui = _uiManager.GetActiveUIWidgetOrNull<GhostGui>();
if (ui != null && Player != null)
ui.UpdateRespawn(_respawn.RespawnResetTime);
}
}

public int AvailableGhostRoleCount { get; private set; }

Expand Down Expand Up @@ -182,4 +200,4 @@ public void ToggleGhostVisibility()
GhostVisibility = !GhostVisibility;
}
}
}
}
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.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();
}
}
}
44 changes: 40 additions & 4 deletions Content.Client/UserInterface/Systems/Ghost/GhostUIController.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
using Content.Client.Gameplay;
using Content.Client._NF.Respawn;
using Content.Client.Gameplay;
using Content.Client.Ghost;
using Content.Client.UserInterface.Systems.Gameplay;
using Content.Client.UserInterface.Systems.Ghost.Widgets;
using Content.Shared.Ghost;
using Content.Shared._NF.CCVar;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controllers;
using Robust.Shared.Configuration;
using Robust.Shared.Console;

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>
public sealed class GhostUIController : UIController, IOnSystemChanged<GhostSystem>, IOnSystemChanged<RespawnSystem>
{
[Dependency] private readonly IEntityNetworkManager _net = default!;
[Dependency] private readonly IConfigurationManager _cfg = default!;
[Dependency] private readonly IConsoleHost _consoleHost = default!;

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

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

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

private void UpdateRespawn(TimeSpan? timeOfDeath)
{
Gui?.UpdateRespawn(timeOfDeath);
}

public void UpdateGui()
{
if (Gui == null)
Expand All @@ -64,7 +76,10 @@ public void UpdateGui()
}

Gui.Visible = _system?.IsGhost ?? false;
Gui.Update(_system?.AvailableGhostRoleCount, _system?.Player?.CanReturnToBody);
Gui.Update(_system?.AvailableGhostRoleCount, _system?.Player?.CanReturnToBody,
_respawn?.RespawnResetTime,
_cfg.GetCVar(NF14CVars.RespawnTime)
);
}

private void OnPlayerRemoved(GhostComponent component)
Expand Down Expand Up @@ -120,10 +135,16 @@ public void LoadGui()
Gui.ReturnToBodyPressed += ReturnToBody;
Gui.GhostRolesPressed += GhostRolesPressed;
Gui.TargetWindow.WarpClicked += OnWarpClicked;
Gui.GhostRespawnPressed += GuiOnGhostRespawnPressed;

UpdateGui();
}

private void GuiOnGhostRespawnPressed()
{
_consoleHost.ExecuteCommand("ghostrespawn");
}

public void UnloadGui()
{
if (Gui == null)
Expand Down Expand Up @@ -153,4 +174,19 @@ private void GhostRolesPressed()
{
_system?.OpenGhostRoles();
}
}

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

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

private void OnRespawnReseted()
{
UpdateGui();
}
}
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}" />
</BoxContainer>
</widgets:GhostGui>
Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
using Content.Client.Stylesheets;
using Content.Client.UserInterface.Systems.Ghost.Controls;
using Content.Shared._NF.CCVar;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Configuration;
using Robust.Shared.Timing;

namespace Content.Client.UserInterface.Systems.Ghost.Widgets;

[GenerateTypedNameReferences]
public sealed partial class GhostGui : UIWidget
{
[Dependency] private readonly IGameTiming _gameTiming = default!;
[Dependency] private readonly IConfigurationManager _configurationManager = default!;

private TimeSpan? _timeOfDeath;
private float _minTimeToRespawn;

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

public event Action? GhostRespawnPressed;

public event Action? RequestWarpsPressed;
public event Action? ReturnToBodyPressed;
Expand All @@ -20,12 +32,22 @@ public GhostGui()
RobustXamlLoader.Load(this);

TargetWindow = new GhostTargetWindow();
RulesWindow = new GhostRespawnRulesWindow();

MouseFilter = MouseFilterMode.Ignore;

RulesWindow.RespawnButton.OnPressed += _ => GhostRespawnPressed?.Invoke();

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

public void UpdateRespawn(TimeSpan? todd)
{
_timeOfDeath = todd;
_minTimeToRespawn = _configurationManager.GetCVar(NF14CVars.RespawnTime);
}

public void Hide()
Expand All @@ -34,9 +56,11 @@ public void Hide()
Visible = false;
}

public void Update(int? roles, bool? canReturnToBody)
public void Update(int? roles, bool? canReturnToBody, TimeSpan? timeOfDeath, float minTimeToRespawn)
{
ReturnToBodyButton.Disabled = !canReturnToBody ?? true;
_timeOfDeath = timeOfDeath;
_minTimeToRespawn = minTimeToRespawn;

if (roles != null)
{
Expand All @@ -54,6 +78,28 @@ public void Update(int? roles, bool? canReturnToBody)
TargetWindow.Populate();
}

protected override void FrameUpdate(FrameEventArgs args)
{
if (_timeOfDeath is null)
{
GhostRespawnButton.Text = Loc.GetString("ghost-gui-respawn-button-allowed");
GhostRespawnButton.Disabled = false;
return;
}

var delta = (_minTimeToRespawn - _gameTiming.CurTime.Subtract(_timeOfDeath.Value).TotalSeconds);
if (delta <= 0)
{
GhostRespawnButton.Text = Loc.GetString("ghost-gui-respawn-button-allowed");
GhostRespawnButton.Disabled = false;
}
else
{
GhostRespawnButton.Text = Loc.GetString("ghost-gui-respawn-button-denied", ("time", $"{delta:f1}"));
GhostRespawnButton.Disabled = true;
}
}

protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
Expand All @@ -63,4 +109,4 @@ protected override void Dispose(bool disposing)
TargetWindow.Dispose();
}
}
}
}
22 changes: 22 additions & 0 deletions Content.Client/_NF/Respawn/RespawnSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using Content.Shared._NF.Respawn;

namespace Content.Client._NF.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
Expand Up @@ -5,6 +5,8 @@
using Content.Shared.Chemistry.EntitySystems;
using Content.Shared.Chemistry.Reagent;
using Content.Shared.Database;
using Content.Server.Body.Components;
using Content.Shared.DoAfter;
using Content.Shared.FixedPoint;
using Content.Shared.Forensics;
using Content.Shared.IdentityManagement;
Expand All @@ -22,6 +24,7 @@ namespace Content.Server.Chemistry.EntitySystems
public sealed partial class ChemistrySystem
{
[Dependency] private readonly UseDelaySystem _useDelay = default!;
[Dependency] private readonly SharedDoAfterSystem _doAfterSystem = default!;

private void InitializeHypospray()
{
Expand All @@ -30,6 +33,7 @@ private void InitializeHypospray()
SubscribeLocalEvent<HyposprayComponent, SolutionContainerChangedEvent>(OnSolutionChange);
SubscribeLocalEvent<HyposprayComponent, UseInHandEvent>(OnUseInHand);
SubscribeLocalEvent<HyposprayComponent, ComponentGetState>(OnHypoGetState);
SubscribeLocalEvent<HyposprayComponent, HyposprayDoAfterEvent>(HyposprayDoAfter);
}

private void OnHypoGetState(Entity<HyposprayComponent> entity, ref ComponentGetState args)
Expand Down Expand Up @@ -61,8 +65,29 @@ public void OnAfterInteract(Entity<HyposprayComponent> entity, ref AfterInteract
var target = args.Target;
var user = args.User;

TryDoInject(entity, target, user);
if (target != user && HasComp<BloodstreamComponent>(target))
{
_doAfterSystem.TryStartDoAfter(new DoAfterArgs(EntityManager, user, TimeSpan.FromSeconds(1), new HyposprayDoAfterEvent(), entity.Owner, target: target, used: user)
{
BreakOnUserMove = true,
BreakOnDamage = true,
BreakOnTargetMove = true,
MovementThreshold = 0.1f,
});
}
else
{
TryDoInject(entity, target, user);
}
}

private void HyposprayDoAfter(Entity<HyposprayComponent> entity, ref HyposprayDoAfterEvent args)
{
if (args.Cancelled || args.Handled || args.Args.Target == null)
return;
TryDoInject(entity, args.Args.Target.Value, args.Args.User);
args.Handled = true;
}

public void OnAttack(Entity<HyposprayComponent> entity, ref MeleeHitEvent args)
{
Expand Down
Loading

0 comments on commit 18d2859

Please sign in to comment.