cancelable brig timers (#26557)

brig timers now cancelable. also some screensystem yakshave
This commit is contained in:
avery
2024-03-31 13:44:02 -07:00
committed by GitHub
parent 7f2e6ccbb8
commit 5eff7f169e
4 changed files with 27 additions and 17 deletions

View 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>

View 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)