Fix item/clothing visual & networking bugs (#10116)

This commit is contained in:
Leon Friedrich
2022-07-29 13:02:09 +12:00
committed by GitHub
parent e22679501c
commit d279f6172a
16 changed files with 278 additions and 239 deletions

View File

@@ -1,4 +1,4 @@
using Content.Client.Items.Components;
using Content.Shared.Light;
using Content.Shared.Light.Component;
using Robust.Client.Graphics;
using Robust.Client.UserInterface;
@@ -6,103 +6,79 @@ using Robust.Client.UserInterface.Controls;
using Robust.Shared.Timing;
using static Robust.Client.UserInterface.Controls.BoxContainer;
namespace Content.Client.Light.Components
namespace Content.Client.Light.Components;
public sealed class HandheldLightStatus : Control
{
[RegisterComponent]
[Access(typeof(HandheldLightSystem))]
public sealed class HandheldLightComponent : SharedHandheldLightComponent, IItemStatus
private const float TimerCycle = 1;
private readonly HandheldLightComponent _parent;
private readonly PanelContainer[] _sections = new PanelContainer[HandheldLightComponent.StatusLevels - 1];
private float _timer;
private static readonly StyleBoxFlat StyleBoxLit = new()
{
public byte? Level;
public bool Activated;
BackgroundColor = Color.LimeGreen
};
/// <summary>
/// Whether to automatically set item-prefixes when toggling the flashlight.
/// </summary>
/// <remarks>
/// Flashlights should probably be using explicit unshaded sprite, in-hand and clothing layers, this is
/// mostly here for backwards compatibility.
/// </remarks>
[DataField("addPrefix")]
public bool AddPrefix = false;
private static readonly StyleBoxFlat StyleBoxUnlit = new()
{
BackgroundColor = Color.Black
};
public Control MakeControl()
public HandheldLightStatus(HandheldLightComponent parent)
{
_parent = parent;
var wrapper = new BoxContainer
{
return new StatusControl(this);
Orientation = LayoutOrientation.Horizontal,
SeparationOverride = 4,
HorizontalAlignment = HAlignment.Center
};
AddChild(wrapper);
for (var i = 0; i < _sections.Length; i++)
{
var panel = new PanelContainer {MinSize = (20, 20)};
wrapper.AddChild(panel);
_sections[i] = panel;
}
}
private sealed class StatusControl : Control
protected override void FrameUpdate(FrameEventArgs args)
{
base.FrameUpdate(args);
_timer += args.DeltaSeconds;
_timer %= TimerCycle;
var level = _parent.Level;
for (var i = 0; i < _sections.Length; i++)
{
private const float TimerCycle = 1;
private readonly HandheldLightComponent _parent;
private readonly PanelContainer[] _sections = new PanelContainer[StatusLevels - 1];
private float _timer;
private static readonly StyleBoxFlat StyleBoxLit = new()
if (i == 0)
{
BackgroundColor = Color.LimeGreen
};
private static readonly StyleBoxFlat StyleBoxUnlit = new()
{
BackgroundColor = Color.Black
};
public StatusControl(HandheldLightComponent parent)
{
_parent = parent;
var wrapper = new BoxContainer
if (level == 0 || level == null)
{
Orientation = LayoutOrientation.Horizontal,
SeparationOverride = 4,
HorizontalAlignment = HAlignment.Center
};
AddChild(wrapper);
for (var i = 0; i < _sections.Length; i++)
{
var panel = new PanelContainer {MinSize = (20, 20)};
wrapper.AddChild(panel);
_sections[i] = panel;
_sections[0].PanelOverride = StyleBoxUnlit;
}
else if (level == 1)
{
// Flash the last light.
_sections[0].PanelOverride = _timer > TimerCycle / 2 ? StyleBoxLit : StyleBoxUnlit;
}
else
{
_sections[0].PanelOverride = StyleBoxLit;
}
continue;
}
protected override void FrameUpdate(FrameEventArgs args)
{
base.FrameUpdate(args);
_timer += args.DeltaSeconds;
_timer %= TimerCycle;
var level = _parent.Level;
for (var i = 0; i < _sections.Length; i++)
{
if (i == 0)
{
if (level == 0 || level == null)
{
_sections[0].PanelOverride = StyleBoxUnlit;
}
else if (level == 1)
{
// Flash the last light.
_sections[0].PanelOverride = _timer > TimerCycle / 2 ? StyleBoxLit : StyleBoxUnlit;
}
else
{
_sections[0].PanelOverride = StyleBoxLit;
}
continue;
}
_sections[i].PanelOverride = level >= i + 2 ? StyleBoxLit : StyleBoxUnlit;
}
}
_sections[i].PanelOverride = level >= i + 2 ? StyleBoxLit : StyleBoxUnlit;
}
}
}