74 lines
2 KiB
C#
74 lines
2 KiB
C#
using Content.Client.UserInterface.Controls;
|
|
using Content.Shared._Sunrise.CommandConsole;
|
|
using Robust.Client.AutoGenerated;
|
|
using Robust.Client.Console;
|
|
using Robust.Client.UserInterface;
|
|
using Robust.Client.UserInterface.XAML;
|
|
using Robust.Shared.Utility;
|
|
|
|
namespace Content.Client._Sunrise.CommandConsole;
|
|
|
|
[GenerateTypedNameReferences]
|
|
public sealed partial class CommandConsoleWindow : FancyWindow
|
|
{
|
|
private EntityUid? _owner;
|
|
private readonly IEntityManager _entMan;
|
|
private readonly IClientConsoleHost _consoleHost;
|
|
|
|
public CommandConsoleWindow(CommandConsoleBoundUserInterface userInterface, EntityUid? owner)
|
|
{
|
|
RobustXamlLoader.Load(this);
|
|
|
|
_entMan = IoCManager.Resolve<IEntityManager>();
|
|
_consoleHost = IoCManager.Resolve<IClientConsoleHost>();
|
|
|
|
_owner = owner;
|
|
|
|
ExecuteButton.OnPressed += _ =>
|
|
{
|
|
SaveProgress();
|
|
ExecuteCommands(Rope.Collapse(CommandInput.TextRope));
|
|
};
|
|
}
|
|
|
|
private void ExecuteCommands(string commands)
|
|
{
|
|
// split commands into lines and execute each line as a command
|
|
foreach (var command in commands.Split('\n'))
|
|
{
|
|
_consoleHost.ExecuteCommand(command);
|
|
}
|
|
}
|
|
|
|
protected override void Opened()
|
|
{
|
|
base.Opened();
|
|
LoadProgress();
|
|
}
|
|
|
|
public override void Close()
|
|
{
|
|
base.Close();
|
|
|
|
SaveProgress();
|
|
}
|
|
|
|
private void SaveProgress()
|
|
{
|
|
// Сохраняем прогресс
|
|
if (_entMan.TryGetComponent(_owner, out CommandConsoleComponent? commandConsoleComponent))
|
|
{
|
|
commandConsoleComponent.Input = Rope.Collapse(CommandInput.TextRope);
|
|
}
|
|
}
|
|
|
|
private void LoadProgress()
|
|
{
|
|
// Загружаем прогресс
|
|
if (_entMan.TryGetComponent(_owner, out CommandConsoleComponent? commandConsoleComponent) && commandConsoleComponent.Input != null)
|
|
{
|
|
CommandInput.TextRope = new Rope.Leaf(commandConsoleComponent.Input);
|
|
}
|
|
}
|
|
}
|
|
|