]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
cancelable brig timers (#26557)
authoravery <51971268+graevy@users.noreply.github.com>
Sun, 31 Mar 2024 20:44:02 +0000 (13:44 -0700)
committerGitHub <noreply@github.com>
Sun, 31 Mar 2024 20:44:02 +0000 (16:44 -0400)
brig timers now cancelable. also some screensystem yakshave

Content.Client/TextScreen/TextScreenSystem.cs
Content.Server/DeviceLinking/Components/SignalTimerComponent.cs
Content.Server/DeviceLinking/Systems/SignalTimerSystem.cs
Content.Server/Screens/Systems/ScreenSystem.cs

index b4d67f5f218ea5f67a2a91a07a39352b2f460481..53a620bd46d366c29433d96cd17d851fdeabf7ed 100644 (file)
@@ -112,17 +112,11 @@ public sealed class TextScreenSystem : VisualizerSystem<TextScreenVisualsCompone
         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"
+        // DefaultText: fallback text e.g. broadcast updates from comms consoles
         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);
-        }
+            component.Text = SegmentText((string) newDefault, component);
+
+        // ScreenText: currently rendered text e.g. the "ETA" accompanying shuttle timers
         if (args.AppearanceData.TryGetValue(TextScreenVisuals.ScreenText, out var text) && text is string)
         {
             component.TextToDraw = SegmentText((string) text, component);
index 2e9b369b99a1db57e07f6b83eadc307cb9d8b74d..b3535cde1fd11eb0e7d296c1f54015608943b165 100644 (file)
@@ -23,6 +23,12 @@ public sealed partial class SignalTimerComponent : Component
     [DataField, ViewVariables(VVAccess.ReadWrite)]
     public string Label = string.Empty;
 
+    /// <summary>
+    ///     Default max width of a label (how many letters can this render?)
+    /// </summary>
+    [DataField, ViewVariables(VVAccess.ReadWrite)]
+    public int MaxLength = 5;
+
     /// <summary>
     ///     The port that gets signaled when the timer triggers.
     /// </summary>
index f9c2d3430e99666c085dbba3e5c1e28126d0d552..0e214ee865a47433dab0495ee9e60fee7ecc98e8 100644 (file)
@@ -39,6 +39,7 @@ public sealed class SignalTimerSystem : EntitySystem
 
     private void OnInit(EntityUid uid, SignalTimerComponent component, ComponentInit args)
     {
+        _appearanceSystem.SetData(uid, TextScreenVisuals.DefaultText, component.Label);
         _appearanceSystem.SetData(uid, TextScreenVisuals.ScreenText, component.Label);
         _signalSystem.EnsureSinkPorts(uid, component.Trigger);
     }
@@ -66,11 +67,6 @@ public sealed class SignalTimerSystem : EntitySystem
     {
         RemComp<ActiveSignalTimerComponent>(uid);
 
-        if (TryComp<AppearanceComponent>(uid, out var appearance))
-        {
-            _appearanceSystem.SetData(uid, TextScreenVisuals.ScreenText, signalTimer.Label, appearance);
-        }
-
         _audio.PlayPvs(signalTimer.DoneSound, uid);
         _signalSystem.InvokePort(uid, signalTimer.TriggerPort);
 
@@ -139,10 +135,15 @@ public sealed class SignalTimerSystem : EntitySystem
         if (!IsMessageValid(uid, args))
             return;
 
-        component.Label = args.Text[..Math.Min(5, args.Text.Length)];
+        component.Label = args.Text[..Math.Min(component.MaxLength, args.Text.Length)];
 
         if (!HasComp<ActiveSignalTimerComponent>(uid))
+        {
+            // could maybe move the defaulttext update out of this block,
+            // if you delved deep into appearance update batching
+            _appearanceSystem.SetData(uid, TextScreenVisuals.DefaultText, component.Label);
             _appearanceSystem.SetData(uid, TextScreenVisuals.ScreenText, component.Label);
+        }
     }
 
     /// <summary>
@@ -166,7 +167,15 @@ public sealed class SignalTimerSystem : EntitySystem
     {
         if (!IsMessageValid(uid, args))
             return;
-        OnStartTimer(uid, component);
+
+        // feedback received: pressing the timer button while a timer is running should cancel the timer.
+        if (HasComp<ActiveSignalTimerComponent>(uid))
+        {
+            _appearanceSystem.SetData(uid, TextScreenVisuals.TargetTime, _gameTiming.CurTime);
+            Trigger(uid, component);
+        }
+        else
+            OnStartTimer(uid, component);
     }
 
     private void OnSignalReceived(EntityUid uid, SignalTimerComponent component, ref SignalReceivedEvent args)
index 19790f64d5b1f254b2b5487f2897428e752b4139..782fe38c8884dc840079a46d866e3e0cf4ee7367 100644 (file)
@@ -56,6 +56,7 @@ public sealed class ScreenSystem : EntitySystem
             )
         {
             _appearanceSystem.SetData(uid, TextScreenVisuals.DefaultText, text);
+            _appearanceSystem.SetData(uid, TextScreenVisuals.ScreenText, text);
         }
     }