Files
tbd-station-14/Content.Client/Administration/UI/Tabs/AtmosTab/AddGasWindow.xaml.cs
Pieter-Jan Briers 68ce53ae17 Random spontaneous cleanup PR (#25131)
* Use new Subs.CVar helper

Removes manual config OnValueChanged calls, removes need to remember to manually unsubscribe.

This both reduces boilerplate and fixes many issues where subscriptions weren't removed on entity system shutdown.

* Fix a bunch of warnings

* More warning fixes

* Use new DateTime serializer to get rid of ISerializationHooks in changelog code.

* Get rid of some more ISerializationHooks for enums

* And a little more

* Apply suggestions from code review

Co-authored-by: 0x6273 <0x40@keemail.me>

---------

Co-authored-by: 0x6273 <0x40@keemail.me>
2024-02-13 16:48:39 -05:00

69 lines
2.4 KiB
C#

using System.Linq;
using Content.Client.Atmos.EntitySystems;
using Content.Shared.Atmos.Prototypes;
using JetBrains.Annotations;
using Robust.Client.AutoGenerated;
using Robust.Client.Console;
using Robust.Client.Player;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
using Robust.Shared.Map.Components;
namespace Content.Client.Administration.UI.Tabs.AtmosTab
{
[GenerateTypedNameReferences]
[UsedImplicitly]
public sealed partial class AddGasWindow : DefaultWindow
{
private List<NetEntity>? _gridData;
private IEnumerable<GasPrototype>? _gasData;
protected override void EnteredTree()
{
// Fill out grids
var entManager = IoCManager.Resolve<IEntityManager>();
var playerManager = IoCManager.Resolve<IPlayerManager>();
var gridQuery = entManager.AllEntityQueryEnumerator<MapGridComponent>();
_gridData ??= new List<NetEntity>();
_gridData.Clear();
while (gridQuery.MoveNext(out var uid, out _))
{
_gridData.Add(entManager.GetNetEntity(uid));
var player = playerManager.LocalEntity;
var playerGrid = entManager.GetComponentOrNull<TransformComponent>(player)?.GridUid;
GridOptions.AddItem($"{uid} {(playerGrid == uid ? " (Current)" : "")}");
}
GridOptions.OnItemSelected += eventArgs => GridOptions.SelectId(eventArgs.Id);
// Fill out gases
_gasData = entManager.System<AtmosphereSystem>().Gases;
foreach (var gas in _gasData)
{
var gasName = Loc.GetString(gas.Name);
GasOptions.AddItem($"{gasName} ({gas.ID})");
}
GasOptions.OnItemSelected += eventArgs => GasOptions.SelectId(eventArgs.Id);
SubmitButton.OnPressed += SubmitButtonOnOnPressed;
}
private void SubmitButtonOnOnPressed(BaseButton.ButtonEventArgs obj)
{
if (_gridData == null || _gasData == null)
return;
var gridIndex = _gridData[GridOptions.SelectedId];
var gasList = _gasData.ToList();
var gasId = gasList[GasOptions.SelectedId].ID;
IoCManager.Resolve<IClientConsoleHost>().ExecuteCommand(
$"addgas {TileXSpin.Value} {TileYSpin.Value} {gridIndex} {gasId} {AmountSpin.Value}");
}
}
}