diff --git a/Content.Client/Content.Client.csproj b/Content.Client/Content.Client.csproj index e7a8cd5092..16c1964505 100644 --- a/Content.Client/Content.Client.csproj +++ b/Content.Client/Content.Client.csproj @@ -86,6 +86,7 @@ + @@ -93,6 +94,7 @@ + diff --git a/Content.Client/EntryPoint.cs b/Content.Client/EntryPoint.cs index cb53bb6d8a..7e6901fabd 100644 --- a/Content.Client/EntryPoint.cs +++ b/Content.Client/EntryPoint.cs @@ -25,6 +25,7 @@ using SS14.Shared.Interfaces.GameObjects; using SS14.Shared.IoC; using SS14.Shared.Prototypes; using System; +using Content.Client.GameObjects.Components; using Content.Client.GameObjects.Components.Mobs; using Content.Client.GameObjects.Components.Sound; using Content.Client.UserInterface; @@ -107,6 +108,8 @@ namespace Content.Client factory.Register(); factory.RegisterReference(); + factory.Register(); + IoCManager.Register(); IoCManager.Register(); IoCManager.Register(); diff --git a/Content.Client/GameObjects/Components/SubFloorHideComponent.cs b/Content.Client/GameObjects/Components/SubFloorHideComponent.cs new file mode 100644 index 0000000000..50cd10f33f --- /dev/null +++ b/Content.Client/GameObjects/Components/SubFloorHideComponent.cs @@ -0,0 +1,50 @@ +using Content.Shared.Maps; +using SS14.Client.Interfaces.GameObjects.Components; +using SS14.Shared.GameObjects; +using SS14.Shared.GameObjects.Components.Transform; + +namespace Content.Client.GameObjects.Components +{ + /// + /// Simple component that automatically hides the sibling when the tile it's on + /// is not a sub floor (plating). + /// + /// + public sealed class SubFloorHideComponent : Component + { + private SnapGridComponent _snapGridComponent; + + public override string Name => "SubFloorHide"; + + public override void Initialize() + { + base.Initialize(); + + _snapGridComponent = Owner.GetComponent(); + } + + public override void Startup() + { + base.Startup(); + + _snapGridComponent.OnPositionChanged += SnapGridOnPositionChanged; + Owner.EntityManager.RaiseEvent(Owner, new SubFloorHideDirtyEvent()); + } + + public override void Shutdown() + { + base.Shutdown(); + + _snapGridComponent.OnPositionChanged -= SnapGridOnPositionChanged; + } + + private void SnapGridOnPositionChanged() + { + Owner.EntityManager.RaiseEvent(Owner, new SubFloorHideDirtyEvent()); + } + } + + internal sealed class SubFloorHideDirtyEvent : EntitySystemMessage + { + } +} diff --git a/Content.Client/GameObjects/EntitySystems/SubFloorHideSystem.cs b/Content.Client/GameObjects/EntitySystems/SubFloorHideSystem.cs new file mode 100644 index 0000000000..2f9fb91559 --- /dev/null +++ b/Content.Client/GameObjects/EntitySystems/SubFloorHideSystem.cs @@ -0,0 +1,80 @@ +using Content.Client.GameObjects.Components; +using Content.Shared.Maps; +using SS14.Client.Interfaces.GameObjects.Components; +using SS14.Shared.GameObjects.Components.Transform; +using SS14.Shared.GameObjects.Systems; +using SS14.Shared.Interfaces.GameObjects; +using SS14.Shared.Interfaces.Map; +using SS14.Shared.IoC; +using SS14.Shared.Map; + +namespace Content.Client.GameObjects.EntitySystems +{ + /// + /// Entity system backing . + /// + internal sealed class SubFloorHideSystem : EntitySystem + { +#pragma warning disable 649 + [Dependency] private readonly IMapManager _mapManager; + [Dependency] private readonly ITileDefinitionManager _tileDefinitionManager; +#pragma warning restore 649 + + public override void Initialize() + { + base.Initialize(); + + IoCManager.InjectDependencies(this); + + _mapManager.GridChanged += MapManagerOnGridChanged; + _mapManager.TileChanged += MapManagerOnTileChanged; + + SubscribeEvent(HandleDirtyEvent); + } + + private void HandleDirtyEvent(object sender, SubFloorHideDirtyEvent ev) + { + if (!(sender is IEntity senderEnt)) + { + return; + } + + var sprite = senderEnt.GetComponent(); + var grid = _mapManager.GetGrid(senderEnt.Transform.GridID); + var position = senderEnt.Transform.GridPosition; + var tileRef = grid.GetTile(position); + var tileDef = (ContentTileDefinition) _tileDefinitionManager[tileRef.Tile.TileId]; + sprite.Visible = tileDef.IsSubFloor; + } + + private void MapManagerOnTileChanged(object sender, TileChangedEventArgs e) + { + UpdateTile(_mapManager.GetGrid(e.NewTile.GridIndex), e.NewTile.GridTile); + } + + private void MapManagerOnGridChanged(object sender, GridChangedEventArgs e) + { + foreach (var modified in e.Modified) + { + UpdateTile(e.Grid, modified.position); + } + } + + private void UpdateTile(IMapGrid grid, MapIndices position) + { + var tile = grid.GetTile(position); + var tileDef = (ContentTileDefinition) _tileDefinitionManager[tile.Tile.TileId]; + foreach (var snapGridComponent in grid.GetSnapGridCell(position, SnapGridOffset.Center)) + { + var entity = snapGridComponent.Owner; + if (!entity.HasComponent() || + !entity.TryGetComponent(out ISpriteComponent spriteComponent)) + { + continue; + } + + spriteComponent.Visible = tileDef.IsSubFloor; + } + } + } +} diff --git a/Content.Server/EntryPoint.cs b/Content.Server/EntryPoint.cs index 3f70e845a1..950fa6f629 100644 --- a/Content.Server/EntryPoint.cs +++ b/Content.Server/EntryPoint.cs @@ -140,6 +140,9 @@ namespace Content.Server factory.Register(); factory.RegisterReference(); + factory.RegisterIgnore("IconSmooth"); + factory.RegisterIgnore("SubFloorHide"); + IoCManager.Register(); IoCManager.Register(); IoCManager.Register(); diff --git a/Content.Server/GameObjects/Components/Interactable/Tools/CrowbarComponent.cs b/Content.Server/GameObjects/Components/Interactable/Tools/CrowbarComponent.cs index 12b2a8cea3..870b77e26d 100644 --- a/Content.Server/GameObjects/Components/Interactable/Tools/CrowbarComponent.cs +++ b/Content.Server/GameObjects/Components/Interactable/Tools/CrowbarComponent.cs @@ -1,10 +1,40 @@ -namespace Content.Server.GameObjects.Components.Interactable.Tools +using Content.Server.GameObjects.EntitySystems; +using Content.Shared.Maps; +using SS14.Server.GameObjects.EntitySystems; +using SS14.Shared.Interfaces.GameObjects; +using SS14.Shared.Interfaces.Map; +using SS14.Shared.IoC; +using SS14.Shared.Map; + +namespace Content.Server.GameObjects.Components.Interactable.Tools { - public class CrowbarComponent : ToolComponent + public class CrowbarComponent : ToolComponent, IAfterAttack { +#pragma warning disable 649 + [Dependency] private readonly ITileDefinitionManager _tileDefinitionManager; + [Dependency] private readonly IEntitySystemManager _entitySystemManager; +#pragma warning restore 649 + /// /// Tool that can be used to crowbar things apart, such as deconstructing /// public override string Name => "Crowbar"; + + public CrowbarComponent() + { + IoCManager.InjectDependencies(this); + } + + public void Afterattack(IEntity user, GridCoordinates clicklocation, IEntity attacked) + { + var tile = clicklocation.Grid.GetTile(clicklocation); + var tileDef = (ContentTileDefinition) tile.TileDef; + if (tileDef.CanCrowbar) + { + var underplating = _tileDefinitionManager["underplating"]; + clicklocation.Grid.SetTile(clicklocation, underplating.TileId); + _entitySystemManager.GetEntitySystem().Play("/Audio/items/crowbar.ogg", Owner); + } + } } -} \ No newline at end of file +} diff --git a/Content.Shared/Maps/ContentTileDefinition.cs b/Content.Shared/Maps/ContentTileDefinition.cs index 2cc4fdcc26..17a42e6a0b 100644 --- a/Content.Shared/Maps/ContentTileDefinition.cs +++ b/Content.Shared/Maps/ContentTileDefinition.cs @@ -16,6 +16,8 @@ namespace Content.Shared.Maps public ushort TileId { get; private set; } public string DisplayName { get; private set; } public string SpriteName { get; private set; } + public bool IsSubFloor { get; private set; } + public bool CanCrowbar { get; private set; } public void AssignTileId(ushort id) { @@ -27,6 +29,16 @@ namespace Content.Shared.Maps Name = mapping.GetNode("name").ToString(); DisplayName = mapping.GetNode("display_name").ToString(); SpriteName = mapping.GetNode("texture").ToString(); + + if (mapping.TryGetNode("is_subfloor", out var node)) + { + IsSubFloor = node.AsBool(); + } + + if (mapping.TryGetNode("can_crowbar", out node)) + { + CanCrowbar = node.AsBool(); + } } } } diff --git a/Resources/Prototypes/Entities/Power.yml b/Resources/Prototypes/Entities/Power.yml index 94dc3a0533..c49ea8244c 100644 --- a/Resources/Prototypes/Entities/Power.yml +++ b/Resources/Prototypes/Entities/Power.yml @@ -20,6 +20,7 @@ base: cable_ key: power_cables mode: CardinalFlags + - type: SubFloorHide snap: - Wire diff --git a/Resources/Prototypes/Tiles/floors.yml b/Resources/Prototypes/Tiles/floors.yml index 9a05599dbe..3e835548ad 100644 --- a/Resources/Prototypes/Tiles/floors.yml +++ b/Resources/Prototypes/Tiles/floors.yml @@ -2,13 +2,19 @@ name: floor display_name: Floor texture: "floor_steel" + is_subfloor: false + can_crowbar: true - type: tile name: floor_white display_name: White Floor texture: "floor_white" + is_subfloor: false + can_crowbar: true - type: tile name: floor_techmaint display_name: Techmaint Floor texture: "floor_techmaint" + is_subfloor: false + can_crowbar: true diff --git a/Resources/Prototypes/Tiles/plating.yml b/Resources/Prototypes/Tiles/plating.yml index da2af74abe..38256a223d 100644 --- a/Resources/Prototypes/Tiles/plating.yml +++ b/Resources/Prototypes/Tiles/plating.yml @@ -2,8 +2,10 @@ name: plating display_name: Plating texture: plating + is_subfloor: true - type: tile name: underplating display_name: Underplating texture: underplating + is_subfloor: true