Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better mapping editor (Part 1 - UI) #34302

Open
wants to merge 53 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
ac1f841
add layers menu and erase tile button
poeMota Dec 29, 2024
a9431b0
add fixgridatmos and rmgrid buttons
poeMota Dec 29, 2024
e71bc27
remove delete button
poeMota Dec 29, 2024
1d53251
fix texture
poeMota Dec 29, 2024
37fb585
add icons
poeMota Dec 29, 2024
c7aa953
move layers buttons to xaml
poeMota Dec 30, 2024
7af1db3
add move grid button
poeMota Dec 30, 2024
1491c6b
add secondary use cancel actions
poeMota Dec 30, 2024
84b81c4
add grid VV button and decales parents
poeMota Dec 31, 2024
22f5281
add shaddow toggle button
poeMota Dec 31, 2024
ab8ef7b
idk what i do
poeMota Dec 31, 2024
905fb77
add erase decal overlay
poeMota Jan 2, 2025
96e1d16
rename layers window to visibility window
poeMota Jan 2, 2025
ef841b0
rework editor ui layout
poeMota Jan 4, 2025
eb770e8
cleanup
poeMota Jan 4, 2025
503a38b
better pick action overlay
poeMota Jan 4, 2025
4d2466d
add gallery layout for decals
poeMota Jan 5, 2025
c5e801f
unfuck fucking ui
poeMota Jan 5, 2025
e0077b8
better icons
poeMota Jan 6, 2025
b020a13
fix gallery layout search
poeMota Jan 6, 2025
103b6b2
locale and rename stuff
poeMota Jan 6, 2025
5ea27fb
add dical picker
poeMota Jan 7, 2025
4d48c81
fix
poeMota Jan 7, 2025
5ad5b63
decal color pick
poeMota Jan 7, 2025
7a8deeb
add decal switch on middle mouse
poeMota Jan 8, 2025
849446e
better bindings
poeMota Jan 8, 2025
940769d
fixes and cleanup
poeMota Jan 8, 2025
14714a3
add use custom color button
poeMota Jan 8, 2025
342b2ec
fixes
poeMota Jan 8, 2025
c530479
add favorite objects list
poeMota Jan 9, 2025
35f9fba
add search for entities by prototype id
poeMota Jan 9, 2025
be84c6f
rename
poeMota Jan 9, 2025
98dce20
add mapping objects templates
poeMota Jan 11, 2025
63219c9
add pipes color action and decal rotation
poeMota Jan 11, 2025
3c49e4d
fix escape menu in editor
poeMota Jan 11, 2025
2742733
add chat toggle button
poeMota Jan 11, 2025
bf51518
save favorites objects locally
poeMota Jan 12, 2025
295b3bd
todo
poeMota Jan 13, 2025
645e401
update mappingclientsidesetup command
poeMota Jan 13, 2025
4a605d1
fix admin menu in editor
poeMota Jan 13, 2025
d1a560d
update mapping templates
poeMota Jan 14, 2025
a1c155e
add buttons tooltip
poeMota Jan 14, 2025
4dbf263
add palette for atmos pipes
poeMota Jan 15, 2025
c7ffa48
comments and code cleanup
poeMota Jan 15, 2025
97dbaba
remove mapping overlay disabling on server
poeMota Jan 15, 2025
7cb92cf
cleanup
poeMota Jan 15, 2025
6e2ce7b
fix decal pick bind
poeMota Jan 15, 2025
29dfaf7
fix yaml linter
poeMota Jan 15, 2025
b1f2b5f
split pr into parts
poeMota Jan 21, 2025
31c6057
fix null prototypes search
poeMota Jan 21, 2025
5fd9b05
review
poeMota Feb 5, 2025
c99ddde
forgot
poeMota Feb 5, 2025
98308cb
fix typecheck
poeMota Feb 5, 2025
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
5 changes: 3 additions & 2 deletions Content.Client/Commands/MappingClientSideSetupCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ public override void Execute(IConsoleShell shell, string argStr, string[] args)
{
_entitySystemManager.GetEntitySystem<MarkerSystem>().MarkersVisible = true;
_lightManager.Enabled = false;
shell.ExecuteCommand("showsubfloorforever");
_entitySystemManager.GetEntitySystem<ActionsSystem>().LoadActionAssignments("/mapping_actions.yml", false);
shell.ExecuteCommand("showsubfloor");
shell.ExecuteCommand("zoom 1.5");
shell.ExecuteCommand("scene MappingState");
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Content.Client/Mapping/MappingActionsButton.xaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<mapping:MappingActionsButton
xmlns="https://spacestation14.io"
xmlns:mapping="clr-namespace:Content.Client.Mapping"
StyleClasses="ButtonSquare" ToggleMode="True" SetSize="32 32" Margin="0 0 5 0"
StyleClasses="ButtonSquare" ToggleMode="True" SetSize="48 48" Margin="0 0 5 0"
TooltipDelay="0">
<TextureRect Name="Texture" Access="Public" Stretch="Scale" SetSize="16 16"
<TextureRect Name="Texture" Access="Public" Stretch="KeepAspectCentered" SetSize="24 24"
HorizontalAlignment="Center" VerticalAlignment="Center" />
</mapping:MappingActionsButton>
46 changes: 46 additions & 0 deletions Content.Client/Mapping/MappingManager.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,35 @@
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Content.Shared.Decals;
using Content.Shared.Mapping;
using Content.Shared.Maps;
using Robust.Client.UserInterface;
using Robust.Shared.Network;
using Robust.Shared.Prototypes;

namespace Content.Client.Mapping;

public sealed class MappingManager : IPostInjectInit
{
[Dependency] private readonly IFileDialogManager _file = default!;
[Dependency] private readonly IClientNetManager _net = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;

private Stream? _saveStream;
private MappingMapDataMessage? _mapData;
private List<IPrototype>? _favoritePrototypes;

public event Action<List<IPrototype>>? OnFavoritePrototypesLoaded;

public void PostInject()
{
_net.RegisterNetMessage<MappingSaveMapMessage>();
_net.RegisterNetMessage<MappingSaveMapErrorMessage>(OnSaveError);
_net.RegisterNetMessage<MappingMapDataMessage>(OnMapData);
_net.RegisterNetMessage<MappingFavoritesDataMessage>(OnFavoritesData);
_net.RegisterNetMessage<MappingFavoritesSaveMessage>();
}

private void OnSaveError(MappingSaveMapErrorMessage message)
Expand All @@ -43,6 +53,23 @@ private async void OnMapData(MappingMapDataMessage message)
_mapData = null;
}

private void OnFavoritesData(MappingFavoritesDataMessage message)
{
_favoritePrototypes = new List<IPrototype>();

foreach (var prototype in message.PrototypeIDs)
{
if (_prototypeManager.TryIndex<EntityPrototype>(prototype, out var entity))
_favoritePrototypes.Add(entity);
else if (_prototypeManager.TryIndex<ContentTileDefinition>(prototype, out var tile))
_favoritePrototypes.Add(tile);
else if (_prototypeManager.TryIndex<DecalPrototype>(prototype, out var decal))
_favoritePrototypes.Add(decal);
}

OnFavoritePrototypesLoaded?.Invoke(_favoritePrototypes);
}

public async Task SaveMap()
{
if (_saveStream != null)
Expand All @@ -66,4 +93,23 @@ public async Task SaveMap()

_saveStream = stream;
}

public void SaveFavorites(List<MappingPrototype> prototypes)
{
// TODO: that doesnt save null prototypes (mapping templates and abstract parents)
var msg = new MappingFavoritesSaveMessage()
{
PrototypeIDs = prototypes
.FindAll(p => p.Prototype != null)
.Select(p => p.Prototype!.ID)
.ToList(),
};
_net.ClientSendMessage(msg);
}

public void LoadFavorites()
{
var request = new MappingFavoritesLoadMessage();
_net.ClientSendMessage(request);
}
}
37 changes: 17 additions & 20 deletions Content.Client/Mapping/MappingOverlay.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
using Robust.Client.GameObjects;
using Robust.Client.Graphics;
using Robust.Client.Input;
using Robust.Client.Player;
using Robust.Client.UserInterface;
using Robust.Shared.Enums;
using Robust.Shared.Prototypes;
using static Content.Client.Mapping.MappingState;
Expand All @@ -12,13 +9,8 @@ namespace Content.Client.Mapping;
public sealed class MappingOverlay : Overlay
{
[Dependency] private readonly IEntityManager _entities = default!;
[Dependency] private readonly IPlayerManager _player = default!;
[Dependency] private readonly IPrototypeManager _prototypes = default!;

// 1 off in case something else uses these colors since we use them to compare
private static readonly Color PickColor = new(1, 255, 0);
private static readonly Color DeleteColor = new(255, 1, 0);

private readonly Dictionary<EntityUid, Color> _oldColors = new();

private readonly MappingState _state;
Expand All @@ -38,41 +30,46 @@ protected override void Draw(in OverlayDrawArgs args)
{
foreach (var (id, color) in _oldColors)
{
if (!_entities.TryGetComponent(id, out SpriteComponent? sprite))
continue;

if (sprite.Color == DeleteColor || sprite.Color == PickColor)
if (_entities.TryGetComponent(id, out SpriteComponent? sprite))
sprite.Color = color;
}

_oldColors.Clear();

if (_player.LocalEntity == null)
return;

var handle = args.WorldHandle;
handle.UseShader(_shader);

switch (_state.State)
switch (_state.Meta.State)
{
case CursorState.Pick:
case CursorState.Tile:
{
if (_state.GetHoveredTileBox2() is { } box)
args.WorldHandle.DrawRect(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 = PickColor;
sprite.Color = _state.Meta.Color;
}

break;
}
case CursorState.Delete:
case CursorState.EntityOrTile:
{
if (_state.GetHoveredEntity() is { } entity &&
_entities.TryGetComponent(entity, out SpriteComponent? sprite))
{
_oldColors[entity] = sprite.Color;
sprite.Color = DeleteColor;
sprite.Color = _state.Meta.Color;
}
else if (_state.GetHoveredTileBox2() is { } box)
{
args.WorldHandle.DrawRect(box, _state.Meta.SecondColor ?? _state.Meta.Color);
}

break;
Expand Down
5 changes: 5 additions & 0 deletions Content.Client/Mapping/MappingPrototype.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ public sealed class MappingPrototype
/// </summary>
public readonly string Name;

/// <summary>
/// Whether the prototype is in the “Favorites” list.
/// </summary>
public bool Favorite;

/// <summary>
/// Which other prototypes (buttons) this one is nested inside of.
/// </summary>
Expand Down
17 changes: 10 additions & 7 deletions Content.Client/Mapping/MappingPrototypeList.xaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
<mapping:MappingPrototypeList
<mapping:MappingPrototypeList
xmlns="https://spacestation14.io"
xmlns:mapping="clr-namespace:Content.Client.Mapping">
<BoxContainer Orientation="Vertical">
<BoxContainer Orientation="Horizontal">
<Button Name="CollapseAllButton" Access="Public" Text="-" SetSize="48 48"
StyleClasses="ButtonSquare" ToolTip="Collapse All" TooltipDelay="0" />
<LineEdit Name="SearchBar" SetHeight="48" HorizontalExpand="True" Access="Public" />
<Button Name="ClearSearchButton" Access="Public" Text="X" SetSize="48 48"
StyleClasses="ButtonSquare" />
<BoxContainer Orientation="Horizontal" Margin="2 1 1 5">
<mapping:MappingActionsButton Name="CollapseAllButton" Access="Public"
ToolTip="{Loc 'mapping-collapse-all-tooltip'}"
TooltipDelay="0" ToggleMode="False" />
<LineEdit Name="SearchBar" SetHeight="48" HorizontalExpand="True" Access="Public"
PlaceHolder="{Loc 'mapping-search'}" />
<mapping:MappingActionsButton Name="ClearSearchButton" Access="Public"
ToolTip="{Loc 'mapping-clear-search-tooltip'}"
TooltipDelay="0" ToggleMode="False" />
</BoxContainer>
<ScrollContainer Name="ScrollContainer" Access="Public" VerticalExpand="True"
ReserveScrollbarSpace="True">
Expand Down
Loading
Loading