Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Content.Client/Light/RoofOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public sealed class RoofOverlay : Overlay

public override OverlaySpace Space => OverlaySpace.BeforeLighting;

public const int ContentZIndex = BeforeLightTargetOverlay.ContentZIndex + 1;
public const int ContentZIndex = BeforeLightTargetOverlay.ContentZIndex + 2; // ECHO-Tweak: 1 -> 2

public RoofOverlay(IEntityManager entManager)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Content.Client._ECHO.ZLevels;

[RegisterComponent]
public sealed partial class ZLightMimicComponent : Component
{
[ViewVariables]
public EntityUid Host;
}
131 changes: 131 additions & 0 deletions Content.Client/_ECHO/ZLevels/Overlays/ZLevelLightOverlay.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
using System.Numerics;
using Content.Client.Light;
using Content.Shared.Light.Components;
using Content.Shared.Light.EntitySystems;
using Robust.Client.GameObjects;
using Robust.Client.Graphics;
using Robust.Shared.Enums;
using Robust.Shared.Map;
using Robust.Shared.Map.Components;
using Robust.Shared.Prototypes;

namespace Content.Client._Echo.Postprocessing;

public sealed class ZLevelLightOverlay : Overlay
{
private readonly IEntityManager _entManager;
[Dependency] private readonly IMapManager _mapManager = default!;
[Dependency] private readonly IOverlayManager _overlay = default!;

private readonly EntityLookupSystem _lookup;
private readonly SharedMapSystem _mapSystem;
private readonly SharedRoofSystem _roof = default!;
private readonly SharedTransformSystem _xformSystem;

private List<Entity<MapGridComponent>> _grids = new();

public override OverlaySpace Space => OverlaySpace.WorldSpace;
public override bool RequestScreenTexture => true;
public const int ContentZIndex = RoofOverlay.ContentZIndex - 1;

public ZLevelLightOverlay(IEntityManager entManager)
{
_entManager = entManager;
IoCManager.InjectDependencies(this);

_lookup = _entManager.System<EntityLookupSystem>();
_mapSystem = _entManager.System<SharedMapSystem>();
_roof = _entManager.System<SharedRoofSystem>();
_xformSystem = _entManager.System<SharedTransformSystem>();

ZIndex = ContentZIndex;
}

protected override void Draw(in OverlayDrawArgs args)
{
if (args.Viewport.Eye == null || !_entManager.HasComponent<MapLightComponent>(args.MapUid))
return;

var viewport = args.Viewport;
var eye = args.Viewport.Eye;

var worldHandle = args.WorldHandle;
var lightoverlay = _overlay.GetOverlay<BeforeLightTargetOverlay>();
var lightRes = lightoverlay.GetCachedForViewport(args.Viewport);
var bounds = lightoverlay.EnlargedBounds;
var target = lightRes.EnlargedLightTarget;

_grids.Clear();
_mapManager.FindGridsIntersecting(args.MapId, bounds, ref _grids, approx: true, includeMap: true);
var lightScale = viewport.LightRenderTarget.Size / (Vector2) viewport.Size;
var scale = viewport.RenderScale / (Vector2.One / lightScale);

worldHandle.RenderInRenderTarget(target,
() =>
{
var invMatrix = target.GetWorldToLocalMatrix(eye, scale);

for (var i = 0; i < _grids.Count; i++)
{
var grid = _grids[i];

if (!_entManager.TryGetComponent(grid.Owner, out ImplicitRoofComponent? roof))
continue;

var gridMatrix = _xformSystem.GetWorldMatrix(grid.Owner);
var matty = Matrix3x2.Multiply(gridMatrix, invMatrix);

worldHandle.SetTransform(matty);

var tileEnumerator = _mapSystem.GetTilesEnumerator(grid.Owner, grid, bounds);
var color = roof.Color;

while (tileEnumerator.MoveNext(out var tileRef))
{
var local = _lookup.GetLocalBounds(tileRef, grid.Comp.TileSize);
worldHandle.DrawRect(local, color);
}

// Don't need it for the next stage.
_grids.RemoveAt(i);
i--;
}
}, null);

worldHandle.RenderInRenderTarget(target,
() =>
{
var invMatrix = target.GetWorldToLocalMatrix(eye, scale);

foreach (var grid in _grids)
{
if (!_entManager.TryGetComponent(grid.Owner, out RoofComponent? roof))
continue;

var gridMatrix = _xformSystem.GetWorldMatrix(grid.Owner);
var matty = Matrix3x2.Multiply(gridMatrix, invMatrix);

worldHandle.SetTransform(matty);

var tileEnumerator = _mapSystem.GetTilesEnumerator(grid.Owner, grid, bounds);
var roofEnt = (grid.Owner, grid.Comp, roof);

// Due to stencilling we essentially draw on unrooved tiles
while (tileEnumerator.MoveNext(out var tileRef))
{
var color = _roof.GetColor(roofEnt, tileRef.GridIndices);

if (color == null)
{
continue;
}

var local = _lookup.GetLocalBounds(tileRef, grid.Comp.TileSize);
worldHandle.DrawRect(local, color.Value);
}
}
}, null);

worldHandle.SetTransform(Matrix3x2.Identity);
}
}
60 changes: 60 additions & 0 deletions Content.Client/_ECHO/ZLevels/Systems/ZLightSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
using System.Linq;
using Robust.Client.GameObjects;

namespace Content.Client._ECHO.ZLevels;

public sealed class ZLightSystem : EntitySystem
{
[Dependency] private readonly PointLightSystem _lightSys = default!;
[Dependency] private readonly ContainerSystem _container = default!;

private Dictionary<Entity<PointLightComponent>, Entity<ZLightMimicComponent>> _mimics = new();

public override void FrameUpdate(float frameTime)
{
for (var i = _mimics.Count - 1; i >= 0; i--)
{
if (_mimics.ElementAt(i).Key.Owner is not { Valid: true })
{
QueueDel(_mimics.ElementAt(i).Value);
}
}

_mimics.Remove(new Entity<PointLightComponent>());

var query = EntityQueryEnumerator<PointLightComponent>();
while (query.MoveNext(out var uid, out var light))
{

}
}

private void EnsureMimic(Entity<PointLightComponent> ent)
{
if (_mimics.TryGetValue(ent, out var mimic))
{
_lightSys.SetCastShadows(mimic, ent.Comp.CastShadows);
_lightSys.SetColor(mimic, ent.Comp.Color);
_lightSys.SetCurveFactor(mimic, ent.Comp.CurveFactor);
_lightSys.SetEnergy(mimic, ent.Comp.Energy);
_lightSys.SetFalloff(mimic, ent.Comp.Falloff);
_lightSys.SetMask(ent.Comp.MaskPath, Comp<PointLightComponent>(mimic));
_lightSys.SetRadius(mimic, ent.Comp.Radius);
_lightSys.SetSoftness(mimic, ent.Comp.Radius);
_lightSys.SetEnabled(mimic, false);
}
else if (!ent.Comp.ContainerOccluded || !_container.IsEntityInContainer(ent.Owner))
{
mimic = Spawn("");
}
else
{
return;
}
}

private void ClearMimics()
{

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using Content.Shared._Echo.ZLevels;
using Robust.Client.UserInterface;

namespace Content.Client._ECHO.ZLevels.UI;

public sealed partial class ElevatorControllerBoundUserInterface : BoundUserInterface
{
private ElevatorControllerMenu? _menu;

public ElevatorControllerBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
{
}

protected override void Open()
{
base.Open();

_menu = this.CreateWindow<ElevatorControllerMenu>();
}

protected override void UpdateState(BoundUserInterfaceState state)
{
base.UpdateState(state);

if (state is not ElevatorControllerUiState cast)
return;

_menu?.Populate(cast.Data, cast.InProgress);
}
}
38 changes: 38 additions & 0 deletions Content.Client/_ECHO/ZLevels/UI/ElevatorControllerMenu.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<controls:FancyWindow xmlns="https://spacestation14.io"
xmlns:gfx="clr-namespace:Robust.Client.Graphics;assembly=Robust.Client"
xmlns:controls="clr-namespace:Content.Client.UserInterface.Controls"
xmlns:customControls="clr-namespace:Content.Client.Administration.UI.CustomControls"
Title="{Loc 'elevator-controller-menu-title'}"
MinSize="400 400"
SetSize="400 700">
<BoxContainer Orientation="Horizontal" VerticalExpand="True" HorizontalExpand="True">

<PanelContainer Name="FloorsListPanel">
<BoxContainer Orientation="Vertical">
<ScrollContainer HorizontalExpand="True" VerticalExpand="True" Margin="8, 8, 8, 8" MinHeight="256">

<!-- If there is no data yet, this will be displayed -->
<BoxContainer Name="FetchingAvailableFloorsContainer" HorizontalAlignment="Center" HorizontalExpand="True" VerticalExpand="True" ReservesSpace="False">
<Label Text="{Loc 'holopad-window-fetching-contacts-list'}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</BoxContainer>

<!-- Container for the contacts -->
<BoxContainer Name="ContactsList" Orientation="Vertical" HorizontalExpand="True" VerticalExpand="True" Margin="10 0 10 0"/>
</ScrollContainer>
</BoxContainer>
</PanelContainer>

<!-- Footer -->
<BoxContainer Orientation="Vertical">
<PanelContainer StyleClasses="LowDivider" />
<BoxContainer Orientation="Horizontal" Margin="10 2 5 0" VerticalAlignment="Bottom">
<Label Text="{Loc 'holopad-window-flavor-left'}" StyleClasses="WindowFooterText" />
<Label Text="{Loc 'holopad-window-flavor-right'}" StyleClasses="WindowFooterText"
HorizontalAlignment="Right" HorizontalExpand="True" Margin="0 0 5 0" />
<!-- <TextureRect StyleClasses="NTLogoDark" Stretch="KeepAspectCentered"
VerticalAlignment="Center" HorizontalAlignment="Right" SetSize="19 19"/> -->
</BoxContainer>
</BoxContainer>

</BoxContainer>
</controls:FancyWindow>
61 changes: 61 additions & 0 deletions Content.Client/_ECHO/ZLevels/UI/ElevatorControllerMenu.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System.Linq;
using Content.Client.UserInterface.Controls;
using Content.Shared._Echo.ZLevels;
using Content.Shared.Access.Systems;
using Robust.Client.AutoGenerated;
using Robust.Client.Player;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;

namespace Content.Client._ECHO.ZLevels.UI;

[GenerateTypedNameReferences]
public sealed partial class ElevatorControllerMenu : FancyWindow
{
[Dependency] private readonly IEntityManager _entMan = default!;
[Dependency] private readonly IPlayerManager _player = default!;
private readonly AccessReaderSystem _access;

public ElevatorControllerMenu()
{
RobustXamlLoader.Load(this);
IoCManager.InjectDependencies(this);

_access = _entMan.System<AccessReaderSystem>();
}

public void Populate(List<ElevatorFloorData> data, bool inProgress)
{
ContactsList.RemoveAllChildren();

ContactsList.Visible = data.Count > 0;
FetchingAvailableFloorsContainer.Visible = data.Count <= 0;

if (!_player.LocalEntity.HasValue)
return;

data.OrderBy(x => x.Priority);

foreach (var item in data)
{
var button = new Button()
{
Text = item.Name,
HorizontalExpand = true,
Margin = new Thickness(16, 6),
ToolTip = HasAccess(item) ? null : Loc.GetString("elevator-access-denied-tooltip"),
Disabled = inProgress || !HasAccess(item)
};

ContactsList.AddChild(button);
}
}

private bool HasAccess(ElevatorFloorData data)
{
if (!_player.LocalEntity.HasValue)
return true;

return data.Access == null || _access.FindAccessTags(_player.LocalEntity.Value).Contains(data.Access.Value);
}
}
10 changes: 10 additions & 0 deletions Content.Server/_ECHO/ZLevels/Components/ElevatorComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace Content.Server._Echo.ZLevels;

[RegisterComponent]
public sealed partial class ElevatorComponent : Component
{
[DataField]
public string Group = "";

public bool InProgress = false;
}
19 changes: 19 additions & 0 deletions Content.Server/_ECHO/ZLevels/Components/ElevatorPointComponent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System.Numerics;

namespace Content.Shared._Echo.ZLevels;

[RegisterComponent]
public sealed partial class ElevatorPointComponent : Component
{
[DataField]
public ElevatorFloorData FloorData;

[DataField]
public string Group = "";

[DataField(required: true)]
public Vector2 Offset = Vector2.Zero;

[DataField(required: true)]
public string GridPath = "";
}
Loading
Loading