Add setoutfit command (#2874)
* Add setoutfit command * Adds setoutfit as a verb and adds a proper UI to the command * Removes from AdminMenuWindow * Changes the SetOutfit verb to be a component verb instead of a global verb * Addresses reviews * Remove empty method * Remove on server aswell
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
#nullable enable
|
||||
#nullable enable
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Content.Client.GameObjects.EntitySystems;
|
||||
using Content.Client.StationEvents;
|
||||
using Content.Shared.Atmos;
|
||||
using Content.Shared.Roles;
|
||||
using Robust.Client.Console;
|
||||
using Robust.Client.Graphics.Drawing;
|
||||
using Robust.Client.Interfaces.Placement;
|
||||
@@ -44,7 +45,7 @@ namespace Content.Client.UserInterface.AdminMenu
|
||||
{
|
||||
new SpawnEntitiesCommandButton(),
|
||||
new SpawnTilesCommandButton(),
|
||||
new StationEventsCommandButton(),
|
||||
new StationEventsCommandButton()
|
||||
};
|
||||
private readonly List<CommandButton> _debugButtons = new()
|
||||
{
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
using Content.Client.Eui;
|
||||
using Content.Shared.Eui;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Shared.IoC;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Content.Shared.Administration;
|
||||
|
||||
namespace Content.Client.UserInterface.AdminMenu.SetOutfit
|
||||
{
|
||||
[UsedImplicitly]
|
||||
public sealed class SetOutfitEui : BaseEui
|
||||
{
|
||||
private readonly SetOutfitMenu _window;
|
||||
public SetOutfitEui()
|
||||
{
|
||||
_window = new SetOutfitMenu();
|
||||
}
|
||||
|
||||
public override void Opened()
|
||||
{
|
||||
_window.OpenCentered();
|
||||
}
|
||||
|
||||
public override void Closed()
|
||||
{
|
||||
base.Closed();
|
||||
_window.Close();
|
||||
}
|
||||
|
||||
public override void HandleState(EuiStateBase state)
|
||||
{
|
||||
var outfitState = (SetOutfitEuiState) state;
|
||||
_window.TargetEntityId = outfitState.TargetEntityId;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<customControls:SS14Window
|
||||
xmlns:customControls="clr-namespace:Robust.Client.UserInterface.CustomControls;assembly=Robust.Client"
|
||||
xmlns:controls="clr-namespace:Robust.Client.UserInterface.Controls;assembly=Robust.Client"
|
||||
xmlns:userInterface="clr-namespace:Robust.Client.UserInterface;assembly=Robust.Client">
|
||||
<controls:HBoxContainer SizeFlagsHorizontal="FillExpand">
|
||||
<controls:VBoxContainer SizeFlagsHorizontal="FillExpand" SizeFlagsStretchRatio="0.45">
|
||||
<controls:HBoxContainer SizeFlagsHorizontal="FillExpand" SizeFlagsVertical="FillExpand"
|
||||
SizeFlagsStretchRatio="0.1">
|
||||
<controls:LineEdit Name="SearchBar" PlaceHolder="Search" SizeFlagsHorizontal="FillExpand"
|
||||
SizeFlagsStretchRatio="0.6" />
|
||||
</controls:HBoxContainer>
|
||||
<controls:ItemList Name="OutfitList" SelectMode="Single" SizeFlagsVertical="FillExpand"
|
||||
SizeFlagsStretchRatio="0.9" />
|
||||
<controls:Button Name="ConfirmButton" SizeFlagsHorizontal="FillExpand" />
|
||||
</controls:VBoxContainer>
|
||||
</controls:HBoxContainer>
|
||||
</customControls:SS14Window>
|
||||
@@ -0,0 +1,105 @@
|
||||
#nullable enable
|
||||
using System;
|
||||
using Content.Shared.Construction;
|
||||
using Content.Shared.Roles;
|
||||
using Robust.Client.AutoGenerated;
|
||||
using Robust.Client.Console;
|
||||
using Robust.Client.Interfaces.ResourceManagement;
|
||||
using Robust.Client.UserInterface.Controls;
|
||||
using Robust.Client.UserInterface.CustomControls;
|
||||
using Robust.Client.UserInterface.XAML;
|
||||
using Robust.Client.Utility;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Client.UserInterface.AdminMenu.SetOutfit
|
||||
{
|
||||
[GenerateTypedNameReferences]
|
||||
public partial class SetOutfitMenu : SS14Window
|
||||
{
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
[Dependency] private readonly IClientConsole _console = default!;
|
||||
|
||||
public EntityUid? TargetEntityId { get; set; }
|
||||
protected override Vector2? CustomSize => (250, 320);
|
||||
|
||||
private StartingGearPrototype? _selectedOutfit;
|
||||
|
||||
public SetOutfitMenu()
|
||||
{
|
||||
IoCManager.InjectDependencies(this);
|
||||
RobustXamlLoader.Load(this);
|
||||
|
||||
Title = Loc.GetString("Set Outfit");
|
||||
|
||||
ConfirmButton.Text = Loc.GetString("Confirm");
|
||||
ConfirmButton.OnPressed += ConfirmButtonOnOnPressed;
|
||||
SearchBar.OnTextChanged += SearchBarOnOnTextChanged;
|
||||
OutfitList.OnItemSelected += OutfitListOnOnItemSelected;
|
||||
OutfitList.OnItemDeselected += OutfitListOnOnItemDeselected;
|
||||
PopulateList();
|
||||
}
|
||||
|
||||
private void ConfirmButtonOnOnPressed(BaseButton.ButtonEventArgs obj)
|
||||
{
|
||||
if (TargetEntityId == null || _selectedOutfit == null)
|
||||
return;
|
||||
var command = $"setoutfit {TargetEntityId} {_selectedOutfit.ID}";
|
||||
_console.ProcessCommand(command);
|
||||
Close();
|
||||
}
|
||||
|
||||
private void OutfitListOnOnItemSelected(ItemList.ItemListSelectedEventArgs obj)
|
||||
{
|
||||
_selectedOutfit = (StartingGearPrototype) obj.ItemList[obj.ItemIndex].Metadata!;
|
||||
ConfirmButton.Disabled = false;
|
||||
}
|
||||
|
||||
private void OutfitListOnOnItemDeselected(ItemList.ItemListDeselectedEventArgs obj)
|
||||
{
|
||||
_selectedOutfit = null;
|
||||
ConfirmButton.Disabled = true;
|
||||
}
|
||||
|
||||
|
||||
private void SearchBarOnOnTextChanged(LineEdit.LineEditEventArgs obj)
|
||||
{
|
||||
PopulateByFilter(SearchBar.Text);
|
||||
}
|
||||
|
||||
private void PopulateList()
|
||||
{
|
||||
foreach (var gear in _prototypeManager.EnumeratePrototypes<StartingGearPrototype>())
|
||||
{
|
||||
OutfitList.Add(GetItem(gear, OutfitList));
|
||||
}
|
||||
}
|
||||
|
||||
private void PopulateByFilter(string filter)
|
||||
{
|
||||
OutfitList.Clear();
|
||||
foreach (var gear in _prototypeManager.EnumeratePrototypes<StartingGearPrototype>())
|
||||
{
|
||||
if (!string.IsNullOrEmpty(filter) &&
|
||||
gear.ID.ToLowerInvariant().Contains(filter.Trim().ToLowerInvariant()))
|
||||
{
|
||||
OutfitList.Add(GetItem(gear, OutfitList));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static ItemList.Item GetItem(StartingGearPrototype gear, ItemList itemList)
|
||||
{
|
||||
return new(itemList)
|
||||
{
|
||||
Metadata = gear,
|
||||
Text = gear.ID
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user