Basic shitty grid background for map editor viewports

This commit is contained in:
PJB3005
2026-05-06 16:39:45 +02:00
parent 5ece553c56
commit ef1b056721
3 changed files with 79 additions and 1 deletions
@@ -0,0 +1,47 @@
using System.Collections.Generic;
using System.Numerics;
using Robust.Client.Graphics;
using Robust.Shared.Enums;
using Robust.Shared.Maths;
namespace Robust.Client.MapEditor;
internal sealed class GridBackgroundOverlay : Overlay
{
public readonly Dictionary<long, Parameters> ViewportParameters = new();
public override OverlaySpace Space => OverlaySpace.WorldSpaceBelowWorld;
protected internal override void Draw(in OverlayDrawArgs args)
{
if (!ViewportParameters.TryGetValue(args.Viewport.Id, out var parameters))
return;
// TODO: This sucks and should just cover the entire WorldAABB.
// Also, line thickness probably needs accounting for. Probably needs to become a screen-space overlay?
for (var x = -128; x < 128; x += 8)
{
var color = parameters.Color;
if (x == 0)
color = parameters.YAxisColor;
args.WorldHandle.DrawLine(new Vector2(x, -128), new Vector2(x, 128), color);
}
for (var y = -128; y < 128; y += 8)
{
var color = parameters.Color;
if (y == 0)
color = parameters.XAxisColor;
args.WorldHandle.DrawLine(new Vector2(-128, y), new Vector2(128, y), color);
}
}
public sealed class Parameters
{
public Color Color = Color.FromHex("#222");
public Color XAxisColor = Color.FromHex("#A22");
public Color YAxisColor = Color.FromHex("#2A2");
}
}
@@ -4,12 +4,15 @@ using Robust.Client.Graphics;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.CustomControls;
using Robust.Shared.Graphics;
using Robust.Shared.IoC;
using Robust.Shared.Timing;
namespace Robust.Client.MapEditor.Interface.Panels.Helpers;
internal sealed class MapViewportContainer : ViewportContainer
{
[Dependency] private readonly IOverlayManager _overlayManager = null!;
private Vector2? _dragStartPos;
private Vector2 _dragStartWorldPos;
@@ -17,8 +20,12 @@ internal sealed class MapViewportContainer : ViewportContainer
public event Action<Vector2>? WorldPosChanged;
private readonly GridBackgroundOverlay.Parameters _gridParameters = new();
public MapViewportContainer()
{
IoCManager.InjectDependencies(this);
MouseFilter = MouseFilterMode.Stop;
}
@@ -70,4 +77,20 @@ internal sealed class MapViewportContainer : ViewportContainer
if (Viewport != null)
Viewport.Eye = Eye;
}
protected override void Resized()
{
// TODO: The way this state is managed sucks. Wish I could set overlays on a per-viewport basis sanely.
if (Viewport != null && _overlayManager.TryGetOverlay(out GridBackgroundOverlay? bg))
{
bg.ViewportParameters.Remove(Viewport.Id);
}
base.Resized();
if (Viewport != null && _overlayManager.TryGetOverlay(out bg))
{
bg.ViewportParameters[Viewport.Id] = _gridParameters;
}
}
}
+9 -1
View File
@@ -1,4 +1,5 @@
using Robust.Client.Input;
using Robust.Client.Graphics;
using Robust.Client.Input;
using Robust.Client.MapEditor.Interface;
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
@@ -14,6 +15,9 @@ internal sealed class MapEditorState : State.State
[Dependency] private readonly IUserInterfaceManager _uiManager = null!;
[Dependency] private readonly IEntitySystemManager _entitySystem = null!;
[Dependency] private readonly IInputManager _inputManager = null!;
[Dependency] private readonly IOverlayManager _overlayManager = null!;
private readonly GridBackgroundOverlay _gridBackground = new();
private readonly MapEditorMain _main;
@@ -30,10 +34,14 @@ internal sealed class MapEditorState : State.State
LayoutContainer.SetAnchorAndMarginPreset(_main, LayoutContainer.LayoutPreset.Wide);
_inputManager.Contexts.SetActiveContext(MapEditorInputContext.ContextName);
_overlayManager.AddOverlay(_gridBackground);
}
protected override void Shutdown()
{
_overlayManager.RemoveOverlay<GridBackgroundOverlay>();
_main.Orphan();
_main.Shutdown();
}