2021-04-28 10:49:37 -07:00
|
|
|
using System.Collections.Generic;
|
2019-07-26 13:53:06 +02:00
|
|
|
using JetBrains.Annotations;
|
|
|
|
|
using Robust.Shared.GameObjects;
|
|
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Client.Window
|
2019-07-26 13:53:06 +02:00
|
|
|
{
|
|
|
|
|
[UsedImplicitly]
|
|
|
|
|
public sealed class WindowSystem : EntitySystem
|
|
|
|
|
{
|
2020-11-27 11:00:49 +01:00
|
|
|
private readonly Queue<IEntity> _dirtyEntities = new();
|
2019-07-26 13:53:06 +02:00
|
|
|
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
2020-02-19 17:08:59 -08:00
|
|
|
SubscribeLocalEvent<WindowSmoothDirtyEvent>(HandleDirtyEvent);
|
2021-04-28 10:49:37 -07:00
|
|
|
SubscribeLocalEvent<WindowComponent, SnapGridPositionChangedEvent>(HandleSnapGridMove);
|
2019-07-26 13:53:06 +02:00
|
|
|
}
|
|
|
|
|
|
2021-04-09 16:08:12 +02:00
|
|
|
public override void Shutdown()
|
|
|
|
|
{
|
|
|
|
|
base.Shutdown();
|
|
|
|
|
|
|
|
|
|
UnsubscribeLocalEvent<WindowSmoothDirtyEvent>();
|
2021-04-28 10:49:37 -07:00
|
|
|
UnsubscribeLocalEvent<WindowComponent, SnapGridPositionChangedEvent>(HandleSnapGridMove);
|
2021-04-09 16:08:12 +02:00
|
|
|
}
|
|
|
|
|
|
2020-02-19 14:39:00 -08:00
|
|
|
private void HandleDirtyEvent(WindowSmoothDirtyEvent ev)
|
2019-07-26 13:53:06 +02:00
|
|
|
{
|
2020-02-19 14:39:00 -08:00
|
|
|
if (ev.Sender.HasComponent<WindowComponent>())
|
2019-07-26 13:53:06 +02:00
|
|
|
{
|
2020-02-19 14:39:00 -08:00
|
|
|
_dirtyEntities.Enqueue(ev.Sender);
|
2019-07-26 13:53:06 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-28 10:49:37 -07:00
|
|
|
private static void HandleSnapGridMove(EntityUid uid, WindowComponent component, SnapGridPositionChangedEvent args)
|
|
|
|
|
{
|
|
|
|
|
component.SnapGridOnPositionChanged();
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-26 13:53:06 +02:00
|
|
|
public override void FrameUpdate(float frameTime)
|
|
|
|
|
{
|
|
|
|
|
base.FrameUpdate(frameTime);
|
|
|
|
|
|
|
|
|
|
// Performance: This could be spread over multiple updates, or made parallel.
|
|
|
|
|
while (_dirtyEntities.Count > 0)
|
|
|
|
|
{
|
2019-11-29 17:08:24 +01:00
|
|
|
var entity = _dirtyEntities.Dequeue();
|
|
|
|
|
if (entity.Deleted)
|
|
|
|
|
{
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
entity.GetComponent<WindowComponent>().UpdateSprite();
|
2019-07-26 13:53:06 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Event raised by a <see cref="WindowComponent"/> when it needs to be recalculated.
|
|
|
|
|
/// </summary>
|
2021-03-09 11:22:48 -08:00
|
|
|
public sealed class WindowSmoothDirtyEvent : EntityEventArgs
|
2019-07-26 13:53:06 +02:00
|
|
|
{
|
2020-02-19 14:39:00 -08:00
|
|
|
public IEntity Sender { get; }
|
|
|
|
|
|
|
|
|
|
public WindowSmoothDirtyEvent(IEntity sender)
|
|
|
|
|
{
|
|
|
|
|
Sender = sender;
|
|
|
|
|
}
|
2019-07-26 13:53:06 +02:00
|
|
|
}
|
|
|
|
|
}
|