Teleport and delete buttons in objects tab. (#28914)

* Тыкнул и нету ЦК

* review

---------

Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
This commit is contained in:
Vigers Ray
2024-08-08 14:00:08 +03:00
committed by GitHub
parent aea28b7a99
commit bd51cf330b
5 changed files with 55 additions and 11 deletions

View File

@@ -1,19 +1,21 @@
using Content.Client.Administration.Managers;
using Content.Client.Station; using Content.Client.Station;
using Content.Client.UserInterface.Controls; using Content.Client.UserInterface.Controls;
using Robust.Client.AutoGenerated; using Robust.Client.AutoGenerated;
using Robust.Client.Console;
using Robust.Client.Graphics; using Robust.Client.Graphics;
using Robust.Client.UserInterface; using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML; using Robust.Client.UserInterface.XAML;
using Robust.Shared.Map.Components; using Robust.Shared.Map.Components;
using Robust.Shared.Timing;
namespace Content.Client.Administration.UI.Tabs.ObjectsTab; namespace Content.Client.Administration.UI.Tabs.ObjectsTab;
[GenerateTypedNameReferences] [GenerateTypedNameReferences]
public sealed partial class ObjectsTab : Control public sealed partial class ObjectsTab : Control
{ {
[Dependency] private readonly IClientAdminManager _admin = default!;
[Dependency] private readonly IEntityManager _entityManager = default!; [Dependency] private readonly IEntityManager _entityManager = default!;
[Dependency] private readonly IClientConsoleHost _console = default!;
private readonly Color _altColor = Color.FromHex("#292B38"); private readonly Color _altColor = Color.FromHex("#292B38");
private readonly Color _defaultColor = Color.FromHex("#2F2F3B"); private readonly Color _defaultColor = Color.FromHex("#2F2F3B");
@@ -53,6 +55,16 @@ public sealed partial class ObjectsTab : Control
RefreshObjectList(defaultSelection); RefreshObjectList(defaultSelection);
} }
private void TeleportTo(NetEntity nent)
{
_console.ExecuteCommand($"tpto {nent}");
}
private void Delete(NetEntity nent)
{
_console.ExecuteCommand($"delete {nent}");
}
public void RefreshObjectList() public void RefreshObjectList()
{ {
RefreshObjectList(_selections[ObjectTypeOptions.SelectedId]); RefreshObjectList(_selections[ObjectTypeOptions.SelectedId]);
@@ -116,9 +128,9 @@ public sealed partial class ObjectsTab : Control
if (data is not ObjectsListData { Info: var info, BackgroundColor: var backgroundColor }) if (data is not ObjectsListData { Info: var info, BackgroundColor: var backgroundColor })
return; return;
var entry = new ObjectsTabEntry(info.Name, var entry = new ObjectsTabEntry(_admin, info.Name, info.Entity, new StyleBoxFlat { BackgroundColor = backgroundColor });
info.Entity, entry.OnTeleport += TeleportTo;
new StyleBoxFlat { BackgroundColor = backgroundColor }); entry.OnDelete += Delete;
button.ToolTip = $"{info.Name}, {info.Entity}"; button.ToolTip = $"{info.Name}, {info.Entity}";
button.AddChild(entry); button.AddChild(entry);

View File

@@ -5,11 +5,23 @@
HorizontalExpand="True" HorizontalExpand="True"
SeparationOverride="4"> SeparationOverride="4">
<Label Name="NameLabel" <Label Name="NameLabel"
SizeFlagsStretchRatio="3" SizeFlagsStretchRatio="5"
HorizontalExpand="True" HorizontalExpand="True"
ClipText="True"/> ClipText="True"/>
<customControls:VSeparator/> <customControls:VSeparator/>
<Label Name="EIDLabel" <Label Name="EIDLabel"
SizeFlagsStretchRatio="5"
HorizontalExpand="True"
ClipText="True"/>
<customControls:VSeparator/>
<Button Name="TeleportButton"
Text="{Loc object-tab-entity-teleport}"
SizeFlagsStretchRatio="3"
HorizontalExpand="True"
ClipText="True"/>
<customControls:VSeparator/>
<Button Name="DeleteButton"
Text="{Loc object-tab-entity-delete}"
SizeFlagsStretchRatio="3" SizeFlagsStretchRatio="3"
HorizontalExpand="True" HorizontalExpand="True"
ClipText="True"/> ClipText="True"/>

View File

@@ -1,4 +1,5 @@
using Robust.Client.AutoGenerated; using Content.Client.Administration.Managers;
using Robust.Client.AutoGenerated;
using Robust.Client.Graphics; using Robust.Client.Graphics;
using Robust.Client.UserInterface.Controls; using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML; using Robust.Client.UserInterface.XAML;
@@ -10,12 +11,22 @@ public sealed partial class ObjectsTabEntry : PanelContainer
{ {
public NetEntity AssocEntity; public NetEntity AssocEntity;
public ObjectsTabEntry(string name, NetEntity nent, StyleBox styleBox) public Action<NetEntity>? OnTeleport;
public Action<NetEntity>? OnDelete;
public ObjectsTabEntry(IClientAdminManager manager, string name, NetEntity nent, StyleBox styleBox)
{ {
RobustXamlLoader.Load(this); RobustXamlLoader.Load(this);
AssocEntity = nent; AssocEntity = nent;
EIDLabel.Text = nent.ToString(); EIDLabel.Text = nent.ToString();
NameLabel.Text = name; NameLabel.Text = name;
BackgroundColorPanel.PanelOverride = styleBox; BackgroundColorPanel.PanelOverride = styleBox;
TeleportButton.Disabled = !manager.CanCommand("tpto");
DeleteButton.Disabled = !manager.CanCommand("delete");
TeleportButton.OnPressed += _ => OnTeleport?.Invoke(nent);
DeleteButton.OnPressed += _ => OnDelete?.Invoke(nent);
} }
} }

View File

@@ -5,17 +5,23 @@
HorizontalExpand="True" HorizontalExpand="True"
SeparationOverride="4"> SeparationOverride="4">
<Label Name="ObjectNameLabel" <Label Name="ObjectNameLabel"
SizeFlagsStretchRatio="3" SizeFlagsStretchRatio="5"
HorizontalExpand="True" HorizontalExpand="True"
ClipText="True" ClipText="True"
Text="{Loc object-tab-object-name}" Text="{Loc object-tab-object-name}"
MouseFilter="Pass"/> MouseFilter="Pass"/>
<cc:VSeparator/> <cc:VSeparator/>
<Label Name="EntityIDLabel" <Label Name="EntityIDLabel"
SizeFlagsStretchRatio="3" SizeFlagsStretchRatio="5"
HorizontalExpand="True" HorizontalExpand="True"
ClipText="True" ClipText="True"
Text="{Loc object-tab-entity-id}" Text="{Loc object-tab-entity-id}"
MouseFilter="Pass"/> MouseFilter="Pass"/>
<Label Name="EntityTeleportLabel"
SizeFlagsStretchRatio="3"
HorizontalExpand="True"/>
<Label Name="EntityDeleteLabel"
SizeFlagsStretchRatio="3"
HorizontalExpand="True"/>
</BoxContainer> </BoxContainer>
</Control> </Control>

View File

@@ -8,3 +8,6 @@ object-tab-object-type-grids = Grids
object-tab-object-type-maps = Maps object-tab-object-type-maps = Maps
object-tab-object-type-stations = Stations object-tab-object-type-stations = Stations
object-tab-refresh-button = Refresh object-tab-refresh-button = Refresh
object-tab-entity-teleport = Teleport
object-tab-entity-delete = Delete