Skip to content

Commit

Permalink
CCTV System is in place for getting Holodisks... *
Browse files Browse the repository at this point in the history
Getting some weird errors with the UI system that makes it not testable, but it works in theory.
It's super crummy regardless, but it would work for putting Holograms in game.
  • Loading branch information
Pspritechologist committed Feb 10, 2024
1 parent f6706a9 commit bc384d3
Show file tree
Hide file tree
Showing 26 changed files with 438 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using Content.Shared.SimpleStation14.Holograms;
using Robust.Client.GameObjects;

namespace Content.Client.SimpleStation14.Holograms.CctvDatabaseUi;

public sealed class CctvDatabaseBoundUserInterface : BoundUserInterface
{
[ViewVariables]
private CctvDatabaseWindow? _menu;

public CctvDatabaseBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
{
}

protected override void Open()
{
_menu = new CctvDatabaseWindow();

_menu.OpenCentered();
_menu.OnClose += Close;

_menu.PrintRequested += SendPrintRequest;
}

private void SendPrintRequest(int index)
{
Logger.Error($"Sending message for index {index}");
SendMessage(new CctvDatabasePrintRequestMessage(index));
}

protected override void UpdateState(BoundUserInterfaceState state)
{
base.UpdateState(state);

switch (state)
{
case CctvDatabaseState cctvState:
_menu?.UpdateState(cctvState);
break;
}
}

protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (!disposing)
return;

_menu?.Dispose();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<controls:FancyWindow
xmlns="https://spacestation14.io"
xmlns:ui="clr-namespace:Content.Client.UserInterface.Controls"
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
Title="{Loc 'cctv-database-user-interface-title'}"
SetSize="250 550"
MinSize="200 350">
<BoxContainer
HorizontalExpand="True"
VerticalExpand="True"
Orientation="Vertical">
<BoxContainer
HorizontalExpand="True"
VerticalExpand="False"
Orientation="Horizontal">
<Label
Name="MessageLabel"
Text="{Loc 'cctv-database-user-interface-message-idle'}"/>
</BoxContainer>
<ScrollContainer
HorizontalExpand="False"
VerticalExpand="True"
Margin="8, 8, 8, 8">
<GridContainer
Name="TargetList"
HorizontalExpand="True"
VerticalExpand="True"
HSeparationOverride="8"
Columns="2">
</GridContainer>
</ScrollContainer>
</BoxContainer>
</controls:FancyWindow>
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
using Content.Client.UserInterface.Controls;
using Content.Shared.SimpleStation14.Holograms;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.Controls;
using Robust.Shared.Timing;

namespace Content.Client.SimpleStation14.Holograms.CctvDatabaseUi;

[GenerateTypedNameReferences]
public sealed partial class CctvDatabaseWindow : FancyWindow
{
[Dependency] private readonly IGameTiming _timing = default!;

public Action<int>? PrintRequested;

private const string IdleMessage = "cctv-database-user-interface-message-idle";
private const string PrintingMessage = "cctv-database-user-interface-message-printing";

private TimeSpan? _printTime;

public void UpdateState(CctvDatabaseState state)
{
var entries = state.CrewManifest;
_printTime = state.FinishedPrintingTime;

TargetList.RemoveAllChildren();

var disabled = state.FinishedPrintingTime != null;
for (var i = 0; i < entries.Count; i++)
{
var label = new Label
{
Text = entries[i],
};

var button = new Button
{
Text = "Print",
Disabled = disabled,
};

var index = i;
button.OnPressed += _ => PrintRequested?.Invoke(index);

TargetList.AddChild(label);
TargetList.AddChild(button);
}

MessageLabel.Text = state.FinishedPrintingTime.ToString() ?? Loc.GetString(IdleMessage);
}

protected override void FrameUpdate(FrameEventArgs args)
{
base.FrameUpdate(args);

if (_printTime == null)
return;

var timeLeft = _printTime.Value - _timing.CurTime;
MessageLabel.Text = timeLeft > TimeSpan.Zero
? $"{Loc.GetString(PrintingMessage)}: {timeLeft.TotalSeconds:0.0}"
: Loc.GetString(IdleMessage);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace Content.Server.SimpleStation14.Holograms.CctvDatabase;

/// <summary>
/// Marks this entity as an active <see cref="CctvDatabaseConsoleComponent"/>.
/// </summary>
[RegisterComponent]
public sealed class CctvDatabaseConsoleActiveComponent : Component
{
/// <summary>
/// The mind currently being printed.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
public Mind.Mind? PrintingMind;

/// <summary>
/// The time the mind will be printed at.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
public TimeSpan PrintTime = TimeSpan.Zero;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace Content.Server.SimpleStation14.Holograms.CctvDatabase;

/// <summary>
/// Marks this entity as a CCTV Database console, allowing it to print CCTV footage onto disks.
/// </summary>
/// <remarks>
/// Mostly a temporary thing for the Hologram system, should be expanded when recordings are actually a thing?
/// </remarks>
[RegisterComponent]
public sealed class CctvDatabaseConsoleComponent : Component
{
/// <summary>
/// The amount of time it takes this Console to print a disk.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
public TimeSpan TimeToPrint = TimeSpan.FromMinutes(1.5);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
//TODO: HOLO In the future the entire CCTV Database system should be completely replaced
// with something that uses station records, requires tracked camera time,
// and a whole bunch of other stuff that'll be fun to use.
// For the time being, this works.

using Content.Server.GameTicking;
using Content.Server.Mind.Components;
using Content.Server.SimpleStation14.Holograms.Components;
using Content.Server.Station.Systems;
using Content.Shared.SimpleStation14.Holograms;
using Robust.Server.GameObjects;
using Robust.Shared.Timing;

namespace Content.Server.SimpleStation14.Holograms.CctvDatabase;

public sealed class CctvDatabaseSystem : EntitySystem
{
[Dependency] private readonly UserInterfaceSystem _ui = default!;
[Dependency] private readonly StationSystem _station = default!;
[Dependency] private readonly IGameTiming _timing = default!;

private const string HoloDiskPrototype = "HologramDisk";

public override void Initialize()
{
base.Initialize();

SubscribeLocalEvent<HologramTargetComponent, PlayerSpawnCompleteEvent>(OnPlayerSpawn);

SubscribeLocalEvent<CctvDatabaseConsoleComponent, BoundUIOpenedEvent>(OnUIOpened);
SubscribeLocalEvent<CctvDatabaseConsoleComponent, CctvDatabasePrintRequestMessage>(OnPrintRequest);
}

public override void Update(float delta)
{
while (EntityQueryEnumerator<CctvDatabaseConsoleActiveComponent>().MoveNext(out var console, out var activeComp))
{
Log.Error($"{activeComp.PrintTime} >= {_timing.CurTime}");
if (activeComp.PrintTime >= _timing.CurTime)
FinishPrint(console, activeComp);
}
}

private void OnPlayerSpawn(EntityUid player, HologramTargetComponent holoTargetComp, PlayerSpawnCompleteEvent args)
{
if (!TryComp<StationCctvDatabaseComponent>(args.Station, out var stationDatabaseComp))
return;
if (!TryComp<MindContainerComponent>(player, out var mindContainerComp) || mindContainerComp.Mind is not { } mind)
return;

stationDatabaseComp.PotentialsList.Add(mind);

while (EntityQueryEnumerator<CctvDatabaseConsoleComponent>().MoveNext(out var console, out _))
UpdateUserInterface(console);
}

private void OnUIOpened(EntityUid uid, CctvDatabaseConsoleComponent component, BoundUIOpenedEvent args)
{
if (args.UiKey is not CctvDatabaseUiKey.Key)
return;

UpdateUserInterface(uid);
}

private void UpdateUserInterface(EntityUid uid, CctvDatabaseConsoleActiveComponent? activeComp = null)
{
if (!_ui.TryGetUi(uid, CctvDatabaseUiKey.Key, out var bui))
return;

if (_station.GetOwningStation(uid) is not { } station || !TryComp<StationCctvDatabaseComponent>(station, out var stationDatabaseComp))
return;

TimeSpan? finishTime = null;

if (Resolve(uid, ref activeComp, false))
finishTime = activeComp.PrintTime;

_ui.TrySetUiState(uid, CctvDatabaseUiKey.Key, new CctvDatabaseState(stationDatabaseComp.PotentialsList.ConvertAll(x => x.CharacterName ?? "Unknown"), finishTime));
}

private void OnPrintRequest(EntityUid console, CctvDatabaseConsoleComponent consoleComp, CctvDatabasePrintRequestMessage args)
{
if (HasComp<CctvDatabaseConsoleActiveComponent>(console))
return;

if (_station.GetOwningStation(console) is not { } station || !TryComp<StationCctvDatabaseComponent>(station, out var stationDatabaseComp))
return;

if (stationDatabaseComp.PotentialsList.Count <= args.Index) // Should never happen.
{
Log.Error($"CCTV Database console {console} tried to print a disk with index {args.Index} but the list only has {stationDatabaseComp.PotentialsList.Count} entries.");
return;
}

var mind = stationDatabaseComp.PotentialsList[args.Index];
var activeComp = AddComp<CctvDatabaseConsoleActiveComponent>(console);
activeComp.PrintingMind = mind;
activeComp.PrintTime = consoleComp.TimeToPrint + _timing.CurTime;
UpdateUserInterface(console, activeComp);
}

private void FinishPrint(EntityUid console, CctvDatabaseConsoleActiveComponent activeComp)
{
var disk = Spawn(HoloDiskPrototype, Transform(console).Coordinates);
var diskComp = EnsureComp<HologramDiskComponent>(disk);
diskComp.HoloMind = activeComp.PrintingMind;
RemComp<CctvDatabaseConsoleActiveComponent>(console);
UpdateUserInterface(console);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Content.Server.SimpleStation14.Holograms.CctvDatabase;

[RegisterComponent]
public sealed class StationCctvDatabaseComponent : Component
{
public List<Mind.Mind> PotentialsList = new();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Content.Server.SimpleStation14.Holograms.Components;

[RegisterComponent]
public sealed class HologramDiskWriterComponent : Component
{
[DataField("diskSlot")]
public string DiskSlot = "disk_slot";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//TODO: HOLO In the future, this and the entire CCTV Database system should be completely replaced
// with something that uses station records, requires tracked camera time,
// and a whole bunch of other stuff that'll be fun to use.
// For the time being, this works.

namespace Content.Server.SimpleStation14.Holograms.Components;

[RegisterComponent]
public sealed class HologramTargetComponent : Component
{ }
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Content.Server.SimpleStation14.Holograms.Components;

[RegisterComponent]
public sealed class StationHologramDatabaseComponent : Component
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Content.Server.Mind.Components;
using Content.Server.Power.Components;
using Content.Shared.Interaction;
using Content.Shared.SimpleStation14.Holograms;
using Robust.Shared.Containers;

namespace Content.Server.SimpleStation14.Holograms;

public sealed partial class HologramServerSystem
{
public void InitializeDiskWriter()
{
base.Initialize();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Content.Server.GameTicking;
using Content.Server.SimpleStation14.Holograms.Components;

namespace Content.Server.SimpleStation14.Holograms;

public sealed partial class HologramServerSystem
{
private void InitializeStation()
{
SubscribeLocalEvent<StationHologramDatabaseComponent, PlayerSpawnCompleteEvent>(OnPlayerSpawn);
}

private void OnPlayerSpawn(EntityUid player, StationHologramDatabaseComponent component, PlayerSpawnCompleteEvent args)
{
}
}

Loading

0 comments on commit bc384d3

Please sign in to comment.