Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Content.Client/_Crescent/PointCannons/TargetingConsoleBUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ protected override void Open()
_window.OpenCentered();
_window.OnClose += Close;

_window.OnServerRefresh += OnRefreshServer;

_window.Radar.OnRadarClick += (coords) =>
{
_coords = _formSys.ToMapCoordinates(coords).Position;
Expand Down Expand Up @@ -103,4 +105,9 @@ protected override void UpdateState(BoundUserInterfaceState state)
_controlled = consoleState.ControlledCannons;
_window?.UpdateState(consoleState);
}

private void OnRefreshServer()
{
SendMessage(new FireControlConsoleRefreshServerMessage());
}
}
20 changes: 18 additions & 2 deletions Content.Client/_Crescent/PointCannons/TargetingConsoleWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,29 @@
MaxWidth="300"
Margin="5 5 5 5"
Orientation="Vertical">

<!-- Cannons status -->
<BoxContainer HorizontalAlignment="Left"
MinWidth="295"
MaxWidth="295"
MinHeight="75"
MaxHeight="75"
Orientation="Vertical">
<controls:StripeBack>
<Label Text="Cannon status" HorizontalAlignment="Center" />
</controls:StripeBack>
<PanelContainer VerticalExpand="False" HorizontalExpand="True">
<Button Name="RefreshButton" Access="Public" Text="{Loc admin-logs-refresh}"
StyleClasses="ButtonSquare" Margin="2 2 2 2"/>
</PanelContainer>
</BoxContainer>

<!-- Ammo status -->
<BoxContainer HorizontalAlignment="Left"
MinWidth="295"
MaxWidth="295"
MinHeight="395"
MaxHeight="395"
MinHeight="320"
MaxHeight="320"
Orientation="Vertical">
<controls:StripeBack>
<Label Text="Ammo status" HorizontalAlignment="Center" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@ public sealed partial class TargetingConsoleWindow : FancyWindow, IComputerWindo
{
public ShuttleNavControl Radar => NavRadar;
public Action<string>? OnCannonGroupChange;
public Action? OnServerRefresh;

public TargetingConsoleWindow()
{
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);

RefreshButton.OnPressed += _ => OnServerRefresh?.Invoke();
}

public void UpdateState(TargetingConsoleBoundUserInterfaceState state)
Expand Down
66 changes: 0 additions & 66 deletions Content.Server/_Crescent/Hardpoint/HardpointSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,11 @@ namespace Content.Server._Crescent.Hardpoint;
public sealed class HardpointSystem : SharedHardpointSystem
{
[Dependency] private readonly PointCannonSystem _cannonSystem = default!;
[Dependency] private readonly IGameTiming _gameTiming = default!;
[Dependency] private readonly DeviceLinkSystem _signalSystem = default!;
[Dependency] private readonly SharedGunSystem _gun = default!;
// Explosions can cause a lot of lookups and events to fire. So we time-limit it based on grids
private const float UpdateDelay = 60f;
private float InternalTimer = 0f;
private HashSet<EntityUid> QueuedGrids = new();
/// <inheritdoc/>
public override void Initialize()
{
SubscribeLocalEvent<FixturesComponent, AnchorStateChangedEvent>(OnFixtureAnchor);
SubscribeLocalEvent<HardpointComponent, HardpointCannonAnchoredEvent>(OnCannonAnchor);
SubscribeLocalEvent<HardpointComponent, HardpointCannonDeanchoredEvent>(OnCannonDeanchor);
SubscribeLocalEvent<HardpointFixedMountComponent, SignalReceivedEvent>(OnSignalReceived);
}
Expand All @@ -56,30 +49,6 @@ private void OnSignalReceived(EntityUid uid, HardpointFixedMountComponent compon
_gun.SetEnabled(hard.anchoring.Value, autoShoot, !autoShoot.Enabled);
}

public void OnFixtureAnchor(EntityUid uid, FixturesComponent comp, ref AnchorStateChangedEvent args)
{
if (args.Transform.GridUid is null)
return;
QueueHardpointRefresh(args.Transform.GridUid.Value);
}

public void QueueHardpointRefresh(EntityUid grid)
{
if (QueuedGrids.Contains(grid))
return;
QueuedGrids.Add(grid);
}


public void OnCannonAnchor(EntityUid uid, HardpointComponent comp, ref HardpointCannonAnchoredEvent args)
{
// This is just for turret-cannons!
if (!TryComp<PointCannonComponent>(args.cannonUid, out var compx))
return;
_cannonSystem.LinkCannonToAllConsoles(args.cannonUid);
QueueHardpointRefresh(args.gridUid);
}

public void OnCannonDeanchor(EntityUid uid, HardpointComponent comp, ref HardpointCannonDeanchoredEvent args)
{
// This is just for turret-cannons!
Expand All @@ -88,39 +57,4 @@ public void OnCannonDeanchor(EntityUid uid, HardpointComponent comp, ref Hardpoi
_cannonSystem.UnlinkCannon(args.CannonUid);
}

public override void Update(float frameTime)
{
base.Update(frameTime);

if (!_gameTiming.IsFirstTimePredicted)
return;

InternalTimer += frameTime;
if (InternalTimer < UpdateDelay)
return;
InternalTimer = 0;
EntityQuery<HardpointComponent> hardpointQuery = GetEntityQuery<HardpointComponent>();
foreach(var grid in QueuedGrids)
{
if (TerminatingOrDeleted(grid))
{
QueuedGrids.Remove(grid);
continue;
}
HashSet<Entity<HardpointComponent>> lookupList = new();
_lookupSystem.GetGridEntities(grid, lookupList);
foreach (var entity in lookupList)
{
if (entity.Comp.anchoring is null)
continue;
if (TerminatingOrDeleted(entity.Comp.anchoring.Value))
continue;
// This is just for turret-cannons!
if (!TryComp<PointCannonComponent>(entity.Comp.anchoring.Value, out var compx))
continue;
_cannonSystem.RefreshFiringRanges(entity.Comp.anchoring.Value, null, null, compx, entity.Comp.CannonRangeCheckRange);
}
}
QueuedGrids.Clear();
}
}
Loading
Loading