2019-09-19 11:43:46 -07:00
|
|
|
|
using Robust.Client.Interfaces.GameObjects.Components;
|
2019-04-15 21:11:38 -06:00
|
|
|
|
using Robust.Shared.GameObjects;
|
|
|
|
|
|
using Robust.Shared.GameObjects.Components.Transform;
|
2020-02-19 14:39:00 -08:00
|
|
|
|
using Robust.Shared.Interfaces.GameObjects;
|
2019-04-04 15:09:06 +02:00
|
|
|
|
|
|
|
|
|
|
namespace Content.Client.GameObjects.Components
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
2019-09-19 11:43:46 -07:00
|
|
|
|
/// Simple component that automatically hides the sibling
|
|
|
|
|
|
/// <see cref="ISpriteComponent" /> when the tile it's on is not a sub floor
|
|
|
|
|
|
/// (plating).
|
2019-04-04 15:09:06 +02:00
|
|
|
|
/// </summary>
|
2019-09-19 11:43:46 -07:00
|
|
|
|
/// <seealso cref="P:Content.Shared.Maps.ContentTileDefinition.IsSubFloor" />
|
2019-07-31 15:02:36 +02:00
|
|
|
|
[RegisterComponent]
|
2019-04-04 15:09:06 +02:00
|
|
|
|
public sealed class SubFloorHideComponent : Component
|
|
|
|
|
|
{
|
|
|
|
|
|
private SnapGridComponent _snapGridComponent;
|
|
|
|
|
|
|
2019-09-19 11:43:46 -07:00
|
|
|
|
/// <inheritdoc />
|
2019-04-04 15:09:06 +02:00
|
|
|
|
public override string Name => "SubFloorHide";
|
|
|
|
|
|
|
2019-09-19 11:43:46 -07:00
|
|
|
|
/// <inheritdoc />
|
2019-04-04 15:09:06 +02:00
|
|
|
|
public override void Initialize()
|
|
|
|
|
|
{
|
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
|
|
|
|
|
|
_snapGridComponent = Owner.GetComponent<SnapGridComponent>();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-09-18 11:29:12 -07:00
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
protected override void Startup()
|
2019-04-04 15:09:06 +02:00
|
|
|
|
{
|
|
|
|
|
|
base.Startup();
|
|
|
|
|
|
|
|
|
|
|
|
_snapGridComponent.OnPositionChanged += SnapGridOnPositionChanged;
|
2020-02-19 17:08:59 -08:00
|
|
|
|
Owner.EntityManager.EventBus.RaiseEvent(EventSource.Local, new SubFloorHideDirtyEvent(Owner));
|
2019-04-04 15:09:06 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-09-18 11:29:12 -07:00
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
protected override void Shutdown()
|
2019-04-04 15:09:06 +02:00
|
|
|
|
{
|
|
|
|
|
|
base.Shutdown();
|
|
|
|
|
|
|
2019-12-22 04:23:38 -08:00
|
|
|
|
if(Owner.Transform.Running == false)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
2019-04-04 15:09:06 +02:00
|
|
|
|
_snapGridComponent.OnPositionChanged -= SnapGridOnPositionChanged;
|
2020-02-19 17:08:59 -08:00
|
|
|
|
Owner.EntityManager.EventBus.RaiseEvent(EventSource.Local, new SubFloorHideDirtyEvent(Owner));
|
2019-04-04 15:09:06 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void SnapGridOnPositionChanged()
|
|
|
|
|
|
{
|
2020-02-19 17:08:59 -08:00
|
|
|
|
Owner.EntityManager.EventBus.RaiseEvent(EventSource.Local, new SubFloorHideDirtyEvent(Owner));
|
2019-04-04 15:09:06 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-02-19 14:39:00 -08:00
|
|
|
|
internal sealed class SubFloorHideDirtyEvent : EntitySystemMessage
|
|
|
|
|
|
{
|
|
|
|
|
|
public IEntity Sender { get; }
|
|
|
|
|
|
|
|
|
|
|
|
public SubFloorHideDirtyEvent(IEntity sender)
|
|
|
|
|
|
{
|
|
|
|
|
|
Sender = sender;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2019-04-04 15:09:06 +02:00
|
|
|
|
}
|