Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
UltimateJester committed Jan 28, 2024
2 parents eae0e64 + 8fead90 commit 6e2442f
Show file tree
Hide file tree
Showing 38 changed files with 492 additions and 184 deletions.
2 changes: 2 additions & 0 deletions Content.Client/Chemistry/UI/ReagentDispenserWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ public void UpdateReagentsList(List<KeyValuePair<string, KeyValuePair<string,str
return;

ChemicalList.Children.Clear();
//Sort inventory by reagentLabel
inventory.Sort((x, y) => x.Value.Key.CompareTo(y.Value.Key));

foreach (KeyValuePair<string, KeyValuePair<string, string>> entry in inventory)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public sealed class CommunicationsConsoleBoundUserInterface : BoundUserInterface

[ViewVariables]
public bool CanAnnounce { get; private set; }
[ViewVariables]
public bool CanBroadcast { get; private set; }

[ViewVariables]
public bool CanCall { get; private set; }
Expand Down Expand Up @@ -71,6 +73,11 @@ public void AnnounceButtonPressed(string message)
SendMessage(new CommunicationsConsoleAnnounceMessage(msg));
}

public void BroadcastButtonPressed(string message)
{
SendMessage(new CommunicationsConsoleBroadcastMessage(message));
}

public void CallShuttle()
{
SendMessage(new CommunicationsConsoleCallEmergencyShuttleMessage());
Expand All @@ -89,6 +96,7 @@ protected override void UpdateState(BoundUserInterfaceState state)
return;

CanAnnounce = commsState.CanAnnounce;
CanBroadcast = commsState.CanBroadcast;
CanCall = commsState.CanCall;
_expectedCountdownTime = commsState.ExpectedCountdownEnd;
CountdownStarted = commsState.CountdownStarted;
Expand All @@ -102,6 +110,7 @@ protected override void UpdateState(BoundUserInterfaceState state)
_menu.AlertLevelButton.Disabled = !AlertLevelSelectable;
_menu.EmergencyShuttleButton.Disabled = !CanCall;
_menu.AnnounceButton.Disabled = !CanAnnounce;
_menu.BroadcastButton.Disabled = !CanBroadcast;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<BoxContainer Orientation="Vertical" HorizontalExpand="True" VerticalExpand="True" Margin="5">
<TextEdit Name="MessageInput" HorizontalExpand="True" VerticalExpand="True" Margin="0 0 0 5" MinHeight="100" />
<Button Name="AnnounceButton" Text="{Loc 'comms-console-menu-announcement-button'}" StyleClasses="OpenLeft" Access="Public" />
<Button Name="BroadcastButton" Text="{Loc 'comms-console-menu-broadcast-button'}" StyleClasses="OpenLeft" Access="Public" />

<OptionButton Name="AlertLevelButton" StyleClasses="OpenRight" Access="Public" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public CommunicationsConsoleMenu(CommunicationsConsoleBoundUserInterface owner)
AnnounceButton.OnPressed += (_) => Owner.AnnounceButtonPressed(Rope.Collapse(MessageInput.TextRope));
AnnounceButton.Disabled = !owner.CanAnnounce;

BroadcastButton.OnPressed += (_) => Owner.BroadcastButtonPressed(Rope.Collapse(MessageInput.TextRope));
BroadcastButton.Disabled = !owner.CanBroadcast;

AlertLevelButton.OnItemSelected += args =>
{
var metadata = AlertLevelButton.GetItemMetadata(args.Id);
Expand Down
2 changes: 1 addition & 1 deletion Content.Client/Pinpointer/UI/NavMapControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public partial class NavMapControl : MapGridControl
Margin = new Thickness(4f, 0f),
VerticalAlignment = VAlignment.Center,
HorizontalAlignment = HAlignment.Center,
Pressed = false,
Pressed = true,
};

public NavMapControl() : base(MinDisplayedRange, MaxDisplayedRange, DefaultDisplayedRange)
Expand Down
75 changes: 55 additions & 20 deletions Content.Client/TextScreen/TextScreenSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,19 +99,43 @@ private void OnTimerInit(EntityUid uid, TextScreenTimerComponent timer, Componen
/// Called by <see cref="SharedAppearanceSystem.SetData"/> to handle text updates,
/// and spawn a <see cref="TextScreenTimerComponent"/> if necessary
/// </summary>
/// <remarks>
/// The appearance updates are batched; order matters for both sender and receiver.
/// </remarks>
protected override void OnAppearanceChange(EntityUid uid, TextScreenVisualsComponent component, ref AppearanceChangeEvent args)
{
if (!Resolve(uid, ref args.Sprite))
return;

var appearance = args.Component;
if (args.AppearanceData.TryGetValue(TextScreenVisuals.Color, out var color) && color is Color)
component.Color = (Color) color;

// DefaultText: broadcast updates from comms consoles
// ScreenText: the text accompanying shuttle timers e.g. "ETA"
if (args.AppearanceData.TryGetValue(TextScreenVisuals.DefaultText, out var newDefault) && newDefault is string)
{
string?[] defaultText = SegmentText((string) newDefault, component);
component.Text = defaultText;
component.TextToDraw = defaultText;
ResetText(uid, component);
BuildTextLayers(uid, component, args.Sprite);
DrawLayers(uid, component.LayerStatesToDraw);
}
if (args.AppearanceData.TryGetValue(TextScreenVisuals.ScreenText, out var text) && text is string)
{
component.TextToDraw = SegmentText((string) text, component);
ResetText(uid, component);
BuildTextLayers(uid, component, args.Sprite);
DrawLayers(uid, component.LayerStatesToDraw);
}

if (AppearanceSystem.TryGetData(uid, TextScreenVisuals.TargetTime, out TimeSpan time, appearance))
if (args.AppearanceData.TryGetValue(TextScreenVisuals.TargetTime, out var time) && time is TimeSpan)
{
if (time > _gameTiming.CurTime)
var target = (TimeSpan) time;
if (target > _gameTiming.CurTime)
{
var timer = EnsureComp<TextScreenTimerComponent>(uid);
timer.Target = time;
timer.Target = target;
BuildTimerLayers(uid, timer, component);
DrawLayers(uid, timer.LayerStatesToDraw);
}
Expand All @@ -120,14 +144,6 @@ protected override void OnAppearanceChange(EntityUid uid, TextScreenVisualsCompo
OnTimerFinish(uid, component);
}
}

if (AppearanceSystem.TryGetData(uid, TextScreenVisuals.ScreenText, out string?[] text, appearance))
{
component.TextToDraw = text;
ResetText(uid, component);
BuildTextLayers(uid, component, args.Sprite);
DrawLayers(uid, component.LayerStatesToDraw);
}
}

/// <summary>
Expand All @@ -151,10 +167,28 @@ private void OnTimerFinish(EntityUid uid, TextScreenVisualsComponent screen)
DrawLayers(uid, screen.LayerStatesToDraw);
}

/// <summary>
/// Converts string to string?[] based on
/// <see cref="TextScreenVisualsComponent.RowLength"/> and <see cref="TextScreenVisualsComponent.Rows"/>.
/// </summary>
private string?[] SegmentText(string text, TextScreenVisualsComponent component)
{
int segment = component.RowLength;
var segmented = new string?[Math.Min(component.Rows, (text.Length - 1) / segment + 1)];

// populate segmented with a string sliding window using Substring.
// (Substring(5, 5) will return the 5 characters starting from 5th index)
// the Mins are for the very short string case, the very long string case, and to not OOB the end of the string.
for (int i = 0; i < Math.Min(text.Length, segment * component.Rows); i += segment)
segmented[i / segment] = text.Substring(i, Math.Min(text.Length - i, segment)).Trim();

return segmented;
}

/// <summary>
/// Clears <see cref="TextScreenVisualsComponent.LayerStatesToDraw"/>, and instantiates new blank defaults.
/// </summary>
public void ResetText(EntityUid uid, TextScreenVisualsComponent component, SpriteComponent? sprite = null)
private void ResetText(EntityUid uid, TextScreenVisualsComponent component, SpriteComponent? sprite = null)
{
if (!Resolve(uid, ref sprite))
return;
Expand All @@ -167,11 +201,12 @@ public void ResetText(EntityUid uid, TextScreenVisualsComponent component, Sprit
for (var row = 0; row < component.Rows; row++)
for (var i = 0; i < component.RowLength; i++)
{
sprite.LayerMapReserveBlank(TextMapKey + row + i);
component.LayerStatesToDraw.Add(TextMapKey + row + i, null);
sprite.LayerSetRSI(TextMapKey + row + i, new ResPath(TextPath));
sprite.LayerSetColor(TextMapKey + row + i, component.Color);
sprite.LayerSetState(TextMapKey + row + i, DefaultState);
var key = TextMapKey + row + i;
sprite.LayerMapReserveBlank(key);
component.LayerStatesToDraw.Add(key, null);
sprite.LayerSetRSI(key, new ResPath(TextPath));
sprite.LayerSetColor(key, component.Color);
sprite.LayerSetState(key, DefaultState);
}
}

Expand All @@ -182,7 +217,7 @@ public void ResetText(EntityUid uid, TextScreenVisualsComponent component, Sprit
/// <remarks>
/// Remember to set <see cref="TextScreenVisualsComponent.TextToDraw"/> to a string?[] first.
/// </remarks>
public void BuildTextLayers(EntityUid uid, TextScreenVisualsComponent component, SpriteComponent? sprite = null)
private void BuildTextLayers(EntityUid uid, TextScreenVisualsComponent component, SpriteComponent? sprite = null)
{
if (!Resolve(uid, ref sprite))
return;
Expand Down Expand Up @@ -211,7 +246,7 @@ public void BuildTextLayers(EntityUid uid, TextScreenVisualsComponent component,
/// <summary>
/// Populates timer.LayerStatesToDraw & the sprite component's layer dict with calculated offsets.
/// </summary>
public void BuildTimerLayers(EntityUid uid, TextScreenTimerComponent timer, TextScreenVisualsComponent screen)
private void BuildTimerLayers(EntityUid uid, TextScreenTimerComponent timer, TextScreenVisualsComponent screen)
{
if (!TryComp<SpriteComponent>(uid, out var sprite))
return;
Expand Down
3 changes: 1 addition & 2 deletions Content.Client/TextScreen/TextScreenVisualsComponent.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Numerics;
using Content.Shared.TextScreen;
using Robust.Client.Graphics;

namespace Content.Client.TextScreen;
Expand Down Expand Up @@ -37,7 +36,7 @@ public sealed partial class TextScreenVisualsComponent : Component
/// Number of rows of text this screen can render.
/// </summary>
[DataField("rows")]
public int Rows = 1;
public int Rows = 2;

/// <summary>
/// Spacing between each text row
Expand Down
35 changes: 23 additions & 12 deletions Content.Server/Anomaly/Effects/GravityAnomalySystem.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Content.Server.Singularity.Components;
using Content.Server.Physics.Components;
using Content.Server.Singularity.Components;
using Content.Shared.Anomaly.Components;
using Content.Shared.Anomaly.Effects;
using Content.Shared.Anomaly.Effects.Components;
Expand All @@ -19,21 +20,31 @@ public override void Initialize()
SubscribeLocalEvent<GravityAnomalyComponent, AnomalyStabilityChangedEvent>(OnStabilityChanged);
}

private void OnSeverityChanged(EntityUid uid, GravityAnomalyComponent component, ref AnomalySeverityChangedEvent args)
private void OnSeverityChanged(Entity<GravityAnomalyComponent> anomaly, ref AnomalySeverityChangedEvent args)
{
if (TryComp<RadiationSourceComponent>(uid, out var radSource))
radSource.Intensity = component.MaxRadiationIntensity * args.Severity;
if (TryComp<RadiationSourceComponent>(anomaly, out var radSource))
radSource.Intensity = anomaly.Comp.MaxRadiationIntensity * args.Severity;

if (!TryComp<GravityWellComponent>(uid, out var gravityWell))
return;
var accel = (component.MaxAccel - component.MinAccel) * args.Severity + component.MinAccel;
gravityWell.BaseRadialAcceleration = accel;
gravityWell.BaseTangentialAcceleration = accel * 0.2f;
if (TryComp<GravityWellComponent>(anomaly, out var gravityWell))
{
var accel = MathHelper.Lerp(anomaly.Comp.MinAccel, anomaly.Comp.MaxAccel, args.Severity);
gravityWell.BaseRadialAcceleration = accel;

var radialAccel = MathHelper.Lerp(anomaly.Comp.MinRadialAccel, anomaly.Comp.MaxRadialAccel, args.Severity);
gravityWell.BaseTangentialAcceleration = radialAccel;
}

if (TryComp<RandomWalkComponent>(anomaly, out var randomWalk))
{
var speed = MathHelper.Lerp(anomaly.Comp.MinSpeed, anomaly.Comp.MaxSpeed, args.Severity);
randomWalk.MinSpeed = speed - anomaly.Comp.SpeedVariation;
randomWalk.MaxSpeed = speed + anomaly.Comp.SpeedVariation;
}
}

private void OnStabilityChanged(EntityUid uid, GravityAnomalyComponent component, ref AnomalyStabilityChangedEvent args)
private void OnStabilityChanged(Entity<GravityAnomalyComponent> anomaly, ref AnomalyStabilityChangedEvent args)
{
if (TryComp<GravityWellComponent>(uid, out var gravityWell))
gravityWell.MaxRange = component.MaxGravityWellRange * args.Stability;
if (TryComp<GravityWellComponent>(anomaly, out var gravityWell))
gravityWell.MaxRange = anomaly.Comp.MaxGravityWellRange * args.Stability;
}
}
14 changes: 9 additions & 5 deletions Content.Server/Communications/CommunicationsConsoleComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@ public sealed partial class CommunicationsConsoleComponent : SharedCommunication
/// <summary>
/// Remaining cooldown between making announcements.
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[ViewVariables]
[DataField]
public float AnnouncementCooldownRemaining;

[ViewVariables]
[DataField]
public float BroadcastCooldownRemaining;

/// <summary>
/// Fluent ID for the announcement title
/// If a Fluent ID isn't found, just uses the raw string
Expand All @@ -27,28 +31,28 @@ public sealed partial class CommunicationsConsoleComponent : SharedCommunication
/// <summary>
/// Announcement color
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[ViewVariables]
[DataField]
public Color Color = Color.Gold;

/// <summary>
/// Time in seconds between announcement delays on a per-console basis
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[ViewVariables]
[DataField]
public int Delay = 90;

/// <summary>
/// Time in seconds of announcement cooldown when a new console is created on a per-console basis
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[ViewVariables]
[DataField]
public int InitialDelay = 30;

/// <summary>
/// Can call or recall the shuttle
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
[ViewVariables]
[DataField]
public bool CanShuttle = true;

Expand Down
26 changes: 26 additions & 0 deletions Content.Server/Communications/CommunicationsConsoleSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@
using Content.Server.Administration.Logs;
using Content.Server.AlertLevel;
using Content.Server.Chat.Systems;
using Content.Server.DeviceNetwork;
using Content.Server.DeviceNetwork.Components;
using Content.Server.DeviceNetwork.Systems;
using Content.Server.Interaction;
using Content.Server.Popups;
using Content.Server.RoundEnd;
using Content.Server.Screens;
using Content.Server.Screens.Components;
using Content.Server.Shuttles.Systems;
using Content.Server.Station.Systems;
using Content.Shared.Access.Components;
Expand All @@ -27,6 +32,7 @@ public sealed class CommunicationsConsoleSystem : EntitySystem
[Dependency] private readonly InteractionSystem _interaction = default!;
[Dependency] private readonly AlertLevelSystem _alertLevelSystem = default!;
[Dependency] private readonly ChatSystem _chatSystem = default!;
[Dependency] private readonly DeviceNetworkSystem _deviceNetworkSystem = default!;
[Dependency] private readonly EmergencyShuttleSystem _emergency = default!;
[Dependency] private readonly IdCardSystem _idCardSystem = default!;
[Dependency] private readonly PopupSystem _popupSystem = default!;
Expand All @@ -49,6 +55,7 @@ public override void Initialize()
// Messages from the BUI
SubscribeLocalEvent<CommunicationsConsoleComponent, CommunicationsConsoleSelectAlertLevelMessage>(OnSelectAlertLevelMessage);
SubscribeLocalEvent<CommunicationsConsoleComponent, CommunicationsConsoleAnnounceMessage>(OnAnnounceMessage);
SubscribeLocalEvent<CommunicationsConsoleComponent, CommunicationsConsoleBroadcastMessage>(OnBroadcastMessage);
SubscribeLocalEvent<CommunicationsConsoleComponent, CommunicationsConsoleCallEmergencyShuttleMessage>(OnCallShuttleMessage);
SubscribeLocalEvent<CommunicationsConsoleComponent, CommunicationsConsoleRecallEmergencyShuttleMessage>(OnRecallShuttleMessage);

Expand Down Expand Up @@ -162,6 +169,7 @@ public void UpdateCommsConsoleInterface(EntityUid uid, CommunicationsConsoleComp

_uiSystem.SetUiState(ui, new CommunicationsConsoleInterfaceState(
CanAnnounce(comp),
CanBroadcast(comp),
CanCallOrRecall(comp),
levels,
currentLevel,
Expand All @@ -175,6 +183,11 @@ private static bool CanAnnounce(CommunicationsConsoleComponent comp)
return comp.AnnouncementCooldownRemaining <= 0f;
}

private static bool CanBroadcast(CommunicationsConsoleComponent comp)
{
return comp.AnnouncementCooldownRemaining <= 0f;
}

private bool CanUse(EntityUid user, EntityUid console)
{
// This shouldn't technically be possible because of BUI but don't trust client.
Expand Down Expand Up @@ -278,6 +291,19 @@ private void OnAnnounceMessage(EntityUid uid, CommunicationsConsoleComponent com
_adminLogger.Add(LogType.Chat, LogImpact.Low, $"{ToPrettyString(message.Session.AttachedEntity.Value):player} has sent the following station announcement: {msg}");
}

private void OnBroadcastMessage(EntityUid uid, CommunicationsConsoleComponent component, CommunicationsConsoleBroadcastMessage message)
{
if (!TryComp<DeviceNetworkComponent>(uid, out var net))
return;

var payload = new NetworkPayload
{
[ScreenMasks.Text] = message.Message
};

_deviceNetworkSystem.QueuePacket(uid, null, payload, net.TransmitFrequency);
}

private void OnCallShuttleMessage(EntityUid uid, CommunicationsConsoleComponent comp, CommunicationsConsoleCallEmergencyShuttleMessage message)
{
if (!CanCallOrRecall(comp))
Expand Down
Loading

0 comments on commit 6e2442f

Please sign in to comment.