Files
wwdpublic/Content.Client/Mapping/MappingOverlay.cs
sleepyyapril a4ab8448b9 Mapping Mini-Wizmerge & New Central Command (#1610)
# Description

<!--
Explain this PR in as much detail as applicable

Some example prompts to consider:
How might this affect the game? The codebase?
What might be some alternatives to this?
How/Who does this benefit/hurt [the game/codebase]?
-->

Ports https://github.com/space-wizards/space-station-14/pull/32294
Ports https://github.com/ss14-harmony/ss14-harmony/pull/310 (and
everything needed for it to function)
Early-merges
https://github.com/space-wizards/space-station-14/pull/34302

Adds the ability for multiple central command maps that get randomly
selected.
Tested and works.

---

# Changelog

<!--
You can add an author after the `🆑` to change the name that appears
in the changelog (ex: `🆑 Death`)
Leaving it blank will default to your GitHub display name
This includes all available types for the changelog
-->

🆑 Several contributors
- add: Added a new central command map that is randomly picked alongside
the old one (thank you to Spanky from Harmony)
- add: Added Advanced SMES for mappers.
- add: Added the atmospheric network monitor for seeing what the
temperature, moles, and pressure is on every pipe everywhere through a
computer.
- add: Nukie med bundle now contains a compact defibrillator.
- add: Ported a better mapping editor.
- add: Added the throngler plushie.
- remove: Removed the Throngler as a possible loot spawn for gamble
crates.

---------

Signed-off-by: sleepyyapril <123355664+sleepyyapril@users.noreply.github.com>

(cherry picked from commit 9272f65b64392f66a7cd4fd7c84bb152dc93b65a)
2025-01-20 21:34:45 +03:00

120 lines
4.0 KiB
C#

using System.Numerics;
using Robust.Client.GameObjects;
using Robust.Client.Graphics;
using Robust.Shared.Enums;
using Robust.Shared.Map;
using Robust.Shared.Prototypes;
using static Content.Client.Mapping.MappingState;
namespace Content.Client.Mapping;
public sealed class MappingOverlay : Overlay
{
[Dependency] private readonly IEntityManager _entities = default!;
[Dependency] private readonly IPrototypeManager _prototypes = default!;
private readonly Dictionary<EntityUid, Color> _oldColors = new();
private readonly MappingState _state;
private readonly ShaderInstance _shader;
public override OverlaySpace Space => OverlaySpace.WorldSpace;
public MappingOverlay(MappingState state)
{
IoCManager.InjectDependencies(this);
_state = state;
_shader = _prototypes.Index<ShaderPrototype>("unshaded").Instance();
}
protected override void Draw(in OverlayDrawArgs args)
{
foreach (var (id, color) in _oldColors)
{
if (_entities.TryGetComponent(id, out SpriteComponent? sprite))
sprite.Color = color;
}
_oldColors.Clear();
var handle = args.WorldHandle;
handle.UseShader(_shader);
switch (_state.Meta.State)
{
case CursorState.Tile:
{
if (_state.GetHoveredTileBox2() is { } box)
args.WorldHandle.DrawRect(box, _state.Meta.Color);
break;
}
case CursorState.Decal:
{
if (_state.GetHoveredDecalData() is { } hovered)
{
var (texture, box) = hovered;
args.WorldHandle.DrawTextureRect(texture, box, _state.Meta.Color);
}
break;
}
case CursorState.Entity:
{
if (_state.GetHoveredEntity() is { } entity &&
_entities.TryGetComponent(entity, out SpriteComponent? sprite))
{
_oldColors[entity] = sprite.Color;
sprite.Color = _state.Meta.Color;
}
break;
}
case CursorState.Grid:
{
if (args.MapId == MapId.Nullspace || _state.GetHoveredGrid() is not { } grid)
break;
var mapSystem = _entities.System<SharedMapSystem>();
var xformSystem = _entities.System<SharedTransformSystem>();
var tileSize = grid.Comp.TileSize;
var tileDimensions = new Vector2(tileSize, tileSize);
var (_, _, worldMatrix, invMatrix) = xformSystem.GetWorldPositionRotationMatrixWithInv(grid.Owner);
args.WorldHandle.SetTransform(worldMatrix);
var bounds = args.WorldBounds;
bounds = new Box2Rotated(bounds.Box.Enlarged(1), bounds.Rotation, bounds.Origin);
var localAABB = invMatrix.TransformBox(bounds);
var enumerator = mapSystem.GetLocalTilesEnumerator(grid.Owner, grid, localAABB);
while (enumerator.MoveNext(out var tileRef))
{
var box = Box2.FromDimensions(tileRef.GridIndices, tileDimensions);
args.WorldHandle.DrawRect(box, _state.Meta.Color);
}
break;
}
case CursorState.EntityOrTile:
{
if (_state.GetHoveredEntity() is { } entity &&
_entities.TryGetComponent(entity, out SpriteComponent? sprite))
{
_oldColors[entity] = sprite.Color;
sprite.Color = _state.Meta.Color;
}
else if (_state.GetHoveredTileBox2() is { } box)
{
args.WorldHandle.DrawRect(box, _state.Meta.SecondColor ?? _state.Meta.Color);
}
break;
}
}
handle.UseShader(null);
}
}