2021-06-09 22:19:39 +02:00
|
|
|
using Content.Client.Items.Components;
|
|
|
|
|
using Content.Shared.Light.Component;
|
2021-02-11 01:13:03 -08:00
|
|
|
using Robust.Client.Graphics;
|
2020-01-09 00:27:52 +01:00
|
|
|
using Robust.Client.UserInterface;
|
|
|
|
|
using Robust.Client.UserInterface.Controls;
|
2021-12-27 18:15:16 +11:00
|
|
|
using Robust.Shared.Analyzers;
|
2020-01-09 00:27:52 +01:00
|
|
|
using Robust.Shared.GameObjects;
|
|
|
|
|
using Robust.Shared.Maths;
|
|
|
|
|
using Robust.Shared.Timing;
|
|
|
|
|
using Robust.Shared.ViewVariables;
|
2021-07-18 18:39:31 +02:00
|
|
|
using static Robust.Client.UserInterface.Controls.BoxContainer;
|
2020-01-09 00:27:52 +01:00
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Client.Light.Components
|
2020-01-09 00:27:52 +01:00
|
|
|
{
|
|
|
|
|
[RegisterComponent]
|
2021-12-27 18:15:16 +11:00
|
|
|
[Friend(typeof(HandheldLightSystem))]
|
2020-01-09 00:27:52 +01:00
|
|
|
public sealed class HandheldLightComponent : SharedHandheldLightComponent, IItemStatus
|
|
|
|
|
{
|
2021-12-27 18:15:16 +11:00
|
|
|
public byte? Level;
|
2020-01-09 00:27:52 +01:00
|
|
|
|
|
|
|
|
public Control MakeControl()
|
|
|
|
|
{
|
|
|
|
|
return new StatusControl(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private sealed class StatusControl : Control
|
|
|
|
|
{
|
|
|
|
|
private const float TimerCycle = 1;
|
|
|
|
|
|
|
|
|
|
private readonly HandheldLightComponent _parent;
|
2020-11-01 07:56:46 +11:00
|
|
|
private readonly PanelContainer[] _sections = new PanelContainer[StatusLevels - 1];
|
2020-01-09 00:27:52 +01:00
|
|
|
|
|
|
|
|
private float _timer;
|
|
|
|
|
|
2021-03-10 14:48:29 +01:00
|
|
|
private static readonly StyleBoxFlat StyleBoxLit = new()
|
2020-01-09 00:27:52 +01:00
|
|
|
{
|
2021-09-20 21:50:02 -07:00
|
|
|
BackgroundColor = Color.LimeGreen
|
2020-01-09 00:27:52 +01:00
|
|
|
};
|
|
|
|
|
|
2021-03-10 14:48:29 +01:00
|
|
|
private static readonly StyleBoxFlat StyleBoxUnlit = new()
|
2020-01-09 00:27:52 +01:00
|
|
|
{
|
|
|
|
|
BackgroundColor = Color.Black
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public StatusControl(HandheldLightComponent parent)
|
|
|
|
|
{
|
|
|
|
|
_parent = parent;
|
|
|
|
|
|
2021-07-18 18:39:31 +02:00
|
|
|
var wrapper = new BoxContainer
|
2020-01-09 00:27:52 +01:00
|
|
|
{
|
2021-07-18 18:39:31 +02:00
|
|
|
Orientation = LayoutOrientation.Horizontal,
|
2020-01-09 00:27:52 +01:00
|
|
|
SeparationOverride = 4,
|
2021-02-21 12:38:56 +01:00
|
|
|
HorizontalAlignment = HAlignment.Center
|
2020-01-09 00:27:52 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
AddChild(wrapper);
|
|
|
|
|
|
|
|
|
|
for (var i = 0; i < _sections.Length; i++)
|
|
|
|
|
{
|
2021-02-21 12:38:56 +01:00
|
|
|
var panel = new PanelContainer {MinSize = (20, 20)};
|
2020-01-09 00:27:52 +01:00
|
|
|
wrapper.AddChild(panel);
|
|
|
|
|
_sections[i] = panel;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-26 17:10:31 -07:00
|
|
|
protected override void FrameUpdate(FrameEventArgs args)
|
2020-01-09 00:27:52 +01:00
|
|
|
{
|
2021-03-26 17:10:31 -07:00
|
|
|
base.FrameUpdate(args);
|
2020-01-09 00:27:52 +01:00
|
|
|
|
|
|
|
|
_timer += args.DeltaSeconds;
|
|
|
|
|
_timer %= TimerCycle;
|
|
|
|
|
|
2021-12-27 18:15:16 +11:00
|
|
|
var level = _parent.Level;
|
2020-01-09 00:27:52 +01:00
|
|
|
|
2020-11-01 07:56:46 +11:00
|
|
|
for (var i = 0; i < _sections.Length; i++)
|
2020-01-09 00:27:52 +01:00
|
|
|
{
|
2020-11-01 07:56:46 +11:00
|
|
|
if (i == 0)
|
|
|
|
|
{
|
2022-01-05 17:20:25 +13:00
|
|
|
if (level == 0 || level == null)
|
2020-11-01 07:56:46 +11:00
|
|
|
{
|
2021-03-10 14:48:29 +01:00
|
|
|
_sections[0].PanelOverride = StyleBoxUnlit;
|
2020-11-01 07:56:46 +11:00
|
|
|
}
|
|
|
|
|
else if (level == 1)
|
|
|
|
|
{
|
|
|
|
|
// Flash the last light.
|
2021-03-10 14:48:29 +01:00
|
|
|
_sections[0].PanelOverride = _timer > TimerCycle / 2 ? StyleBoxLit : StyleBoxUnlit;
|
2020-11-01 07:56:46 +11:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-03-10 14:48:29 +01:00
|
|
|
_sections[0].PanelOverride = StyleBoxLit;
|
2020-11-01 07:56:46 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-10 14:48:29 +01:00
|
|
|
_sections[i].PanelOverride = level >= i + 2 ? StyleBoxLit : StyleBoxUnlit;
|
2020-01-09 00:27:52 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|