2021-04-28 10:49:37 -07:00
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Diagnostics.CodeAnalysis;
|
2020-10-29 21:42:11 +02:00
|
|
|
using Content.Client.GameObjects.EntitySystems;
|
2020-10-08 17:41:23 +02:00
|
|
|
using Content.Shared.GameObjects.Components;
|
2019-07-26 13:53:06 +02:00
|
|
|
using Robust.Client.GameObjects;
|
|
|
|
|
using Robust.Shared.GameObjects;
|
2021-04-28 10:49:37 -07:00
|
|
|
using Robust.Shared.IoC;
|
|
|
|
|
using Robust.Shared.Map;
|
2021-03-05 01:08:38 +01:00
|
|
|
using Robust.Shared.Serialization.Manager.Attributes;
|
2019-07-26 13:53:06 +02:00
|
|
|
using static Content.Client.GameObjects.Components.IconSmoothing.IconSmoothComponent;
|
|
|
|
|
|
|
|
|
|
namespace Content.Client.GameObjects.Components
|
|
|
|
|
{
|
2019-07-31 15:02:36 +02:00
|
|
|
[RegisterComponent]
|
2020-10-08 17:41:23 +02:00
|
|
|
[ComponentReference(typeof(SharedWindowComponent))]
|
|
|
|
|
public sealed class WindowComponent : SharedWindowComponent
|
2019-07-26 13:53:06 +02:00
|
|
|
{
|
2021-04-28 10:49:37 -07:00
|
|
|
[Dependency] private readonly IMapManager _mapManager = default!;
|
|
|
|
|
|
2021-03-05 01:08:38 +01:00
|
|
|
[DataField("base")]
|
2021-03-10 14:48:29 +01:00
|
|
|
private string? _stateBase;
|
|
|
|
|
|
|
|
|
|
private ISpriteComponent? _sprite;
|
2019-07-26 13:53:06 +02:00
|
|
|
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
|
|
|
|
_sprite = Owner.GetComponent<ISpriteComponent>();
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-18 11:29:12 -07:00
|
|
|
/// <inheritdoc />
|
|
|
|
|
protected override void Startup()
|
2019-07-26 13:53:06 +02:00
|
|
|
{
|
|
|
|
|
base.Startup();
|
|
|
|
|
|
2020-02-19 17:08:59 -08:00
|
|
|
Owner.EntityManager.EventBus.RaiseEvent(EventSource.Local, new WindowSmoothDirtyEvent(Owner));
|
2019-07-26 13:53:06 +02:00
|
|
|
|
2021-03-10 14:48:29 +01:00
|
|
|
if (_sprite != null)
|
|
|
|
|
{
|
|
|
|
|
var state0 = $"{_stateBase}0";
|
|
|
|
|
const string cracksRSIPath = "/Textures/Constructible/Structures/Windows/cracks.rsi";
|
|
|
|
|
_sprite.LayerMapSet(CornerLayers.SE, _sprite.AddLayerState(state0));
|
|
|
|
|
_sprite.LayerSetDirOffset(CornerLayers.SE, SpriteComponent.DirectionOffset.None);
|
|
|
|
|
_sprite.LayerMapSet(WindowDamageLayers.DamageSE, _sprite.AddLayerState("0_1", cracksRSIPath));
|
|
|
|
|
_sprite.LayerSetVisible(WindowDamageLayers.DamageSE, false);
|
|
|
|
|
|
|
|
|
|
_sprite.LayerMapSet(CornerLayers.NE, _sprite.AddLayerState(state0));
|
|
|
|
|
_sprite.LayerSetDirOffset(CornerLayers.NE, SpriteComponent.DirectionOffset.CounterClockwise);
|
|
|
|
|
_sprite.LayerMapSet(WindowDamageLayers.DamageNE, _sprite.AddLayerState("0_1", cracksRSIPath));
|
|
|
|
|
_sprite.LayerSetDirOffset(WindowDamageLayers.DamageNE, SpriteComponent.DirectionOffset.CounterClockwise);
|
|
|
|
|
_sprite.LayerSetVisible(WindowDamageLayers.DamageNE, false);
|
|
|
|
|
|
|
|
|
|
_sprite.LayerMapSet(CornerLayers.NW, _sprite.AddLayerState(state0));
|
|
|
|
|
_sprite.LayerSetDirOffset(CornerLayers.NW, SpriteComponent.DirectionOffset.Flip);
|
|
|
|
|
_sprite.LayerMapSet(WindowDamageLayers.DamageNW, _sprite.AddLayerState("0_1", cracksRSIPath));
|
|
|
|
|
_sprite.LayerSetDirOffset(WindowDamageLayers.DamageNW, SpriteComponent.DirectionOffset.Flip);
|
|
|
|
|
_sprite.LayerSetVisible(WindowDamageLayers.DamageNW, false);
|
|
|
|
|
|
|
|
|
|
_sprite.LayerMapSet(CornerLayers.SW, _sprite.AddLayerState(state0));
|
|
|
|
|
_sprite.LayerSetDirOffset(CornerLayers.SW, SpriteComponent.DirectionOffset.Clockwise);
|
|
|
|
|
_sprite.LayerMapSet(WindowDamageLayers.DamageSW, _sprite.AddLayerState("0_1", cracksRSIPath));
|
|
|
|
|
_sprite.LayerSetDirOffset(WindowDamageLayers.DamageSW, SpriteComponent.DirectionOffset.Clockwise);
|
|
|
|
|
_sprite.LayerSetVisible(WindowDamageLayers.DamageSW, false);
|
|
|
|
|
}
|
2019-07-26 13:53:06 +02:00
|
|
|
}
|
|
|
|
|
|
2021-04-28 10:49:37 -07:00
|
|
|
public void SnapGridOnPositionChanged()
|
2019-07-26 13:53:06 +02:00
|
|
|
{
|
2020-02-19 17:08:59 -08:00
|
|
|
Owner.EntityManager.EventBus.RaiseEvent(EventSource.Local, new WindowSmoothDirtyEvent(Owner));
|
2019-07-26 13:53:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void UpdateSprite()
|
|
|
|
|
{
|
|
|
|
|
var lowWall = FindLowWall();
|
|
|
|
|
if (lowWall == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-10 14:48:29 +01:00
|
|
|
if (_sprite != null)
|
|
|
|
|
{
|
|
|
|
|
_sprite.LayerSetState(CornerLayers.NE, $"{_stateBase}{(int) lowWall.LastCornerNE}");
|
|
|
|
|
_sprite.LayerSetState(CornerLayers.SE, $"{_stateBase}{(int) lowWall.LastCornerSE}");
|
|
|
|
|
_sprite.LayerSetState(CornerLayers.SW, $"{_stateBase}{(int) lowWall.LastCornerSW}");
|
|
|
|
|
_sprite.LayerSetState(CornerLayers.NW, $"{_stateBase}{(int) lowWall.LastCornerNW}");
|
|
|
|
|
}
|
2019-07-26 13:53:06 +02:00
|
|
|
}
|
|
|
|
|
|
2021-03-10 14:48:29 +01:00
|
|
|
private LowWallComponent? FindLowWall()
|
2019-07-26 13:53:06 +02:00
|
|
|
{
|
2021-04-28 10:49:37 -07:00
|
|
|
if (!Owner.Transform.Anchored)
|
2021-03-10 14:48:29 +01:00
|
|
|
return null;
|
|
|
|
|
|
2021-04-28 10:49:37 -07:00
|
|
|
var grid = _mapManager.GetGrid(Owner.Transform.GridID);
|
|
|
|
|
var coords = Owner.Transform.Coordinates;
|
|
|
|
|
foreach (var entity in grid.GetLocal(coords))
|
2019-07-26 13:53:06 +02:00
|
|
|
{
|
2021-04-28 10:49:37 -07:00
|
|
|
if (Owner.EntityManager.ComponentManager.TryGetComponent(entity, out LowWallComponent? lowWall))
|
2019-07-26 13:53:06 +02:00
|
|
|
{
|
|
|
|
|
return lowWall;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-10-29 21:42:11 +02:00
|
|
|
|
|
|
|
|
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
2020-12-04 11:57:33 +01:00
|
|
|
public enum WindowDamageLayers : byte
|
2020-10-29 21:42:11 +02:00
|
|
|
{
|
|
|
|
|
DamageSE,
|
|
|
|
|
DamageNE,
|
|
|
|
|
DamageNW,
|
|
|
|
|
DamageSW
|
|
|
|
|
}
|
2019-07-26 13:53:06 +02:00
|
|
|
}
|