144 lines
3.8 KiB
C#
144 lines
3.8 KiB
C#
using Content.Client._DV.UserInterfaces.Controls;
|
|
using Robust.Client.AutoGenerated;
|
|
using Robust.Client.GameObjects;
|
|
using Robust.Client.UserInterface.Controls;
|
|
using Robust.Client.UserInterface.XAML;
|
|
using Robust.Shared.Console;
|
|
using Robust.Shared.Utility;
|
|
|
|
namespace Content.Client._DV.Objectives.Eui;
|
|
|
|
[GenerateTypedNameReferences]
|
|
public sealed partial class ObjectiveContainer : BoxContainer
|
|
{
|
|
[Dependency] private readonly EntityManager _entityManager = default!;
|
|
[Dependency] private readonly IConsoleHost _console = default!;
|
|
private readonly SpriteSystem _sprite;
|
|
|
|
private readonly SpritePickerWindow _spritePicker = new();
|
|
|
|
private ObjectiveUI? _objective = null;
|
|
|
|
public ObjectiveContainer()
|
|
{
|
|
RobustXamlLoader.Load(this);
|
|
|
|
IoCManager.InjectDependencies(this);
|
|
_sprite = _entityManager.System<SpriteSystem>();
|
|
|
|
_spritePicker.OnSpriteSelected += SetIcon;
|
|
ObjectiveTitle.OnTextChanged += OnTitleChanged;
|
|
ObjectiveIssuer.OnTextChanged += OnIssuerChanged;
|
|
|
|
ObjectiveDescription.OnTextChanged += OnDescriptionChanged;
|
|
ObjectiveDescription.Placeholder = new Rope.Leaf(Loc.GetString("objective-editor-admin-ui-placeholder-description"));
|
|
|
|
ResetButton.OnPressed += _ => ResetObjective();
|
|
ViewButton.OnPressed += _ => OnViewObjective();
|
|
IconSelectButton.OnPressed += _ => OnOpenIconSelect();
|
|
|
|
ClearData();
|
|
}
|
|
|
|
public bool HasChanges()
|
|
{
|
|
return _objective?.HasChanges ?? false;
|
|
}
|
|
|
|
public void ClearData()
|
|
{
|
|
_objective = null;
|
|
|
|
ObjectiveIssuer.Editable = false;
|
|
ObjectiveTitle.Editable = false;
|
|
ObjectiveDescription.Editable = false;
|
|
|
|
ResetButton.Disabled = true;
|
|
ViewButton.Disabled = true;
|
|
IconSelectButton.Disabled = true;
|
|
|
|
ObjectiveIssuer.Text = "";
|
|
ObjectiveTitle.Text = "";
|
|
ObjectiveDescription.TextRope = new Rope.Leaf("");
|
|
|
|
IconSelectButton.TextureNormal = null;
|
|
}
|
|
|
|
public void SetData(ObjectiveUI data)
|
|
{
|
|
_objective = data;
|
|
|
|
ObjectiveIssuer.Editable = true;
|
|
ObjectiveTitle.Editable = true;
|
|
ObjectiveDescription.Editable = true;
|
|
|
|
ResetButton.Disabled = false;
|
|
ViewButton.Disabled = false;
|
|
IconSelectButton.Disabled = false;
|
|
|
|
ObjectiveIssuer.Text = _objective.Issuer;
|
|
ObjectiveTitle.Text = _objective.Title;
|
|
ObjectiveDescription.TextRope = new Rope.Leaf(_objective.Description);
|
|
|
|
IconSelectButton.TextureNormal = _sprite.Frame0(data.Icon);
|
|
}
|
|
|
|
public void ResetObjective()
|
|
{
|
|
if (_objective is null)
|
|
return;
|
|
|
|
_objective.Reset();
|
|
IconSelectButton.TextureNormal = _sprite.Frame0(_objective.Icon);
|
|
}
|
|
|
|
private void OnTitleChanged(LineEdit.LineEditEventArgs args)
|
|
{
|
|
if (_objective is null)
|
|
return;
|
|
|
|
_objective.Title = args.Text;
|
|
}
|
|
|
|
private void OnIssuerChanged(LineEdit.LineEditEventArgs args)
|
|
{
|
|
if (_objective is null)
|
|
return;
|
|
|
|
_objective.Issuer = args.Text;
|
|
}
|
|
|
|
private void OnDescriptionChanged(TextEdit.TextEditEventArgs args)
|
|
{
|
|
if (_objective is null)
|
|
return;
|
|
|
|
_objective.Description = Rope.Collapse(args.TextRope).Trim();
|
|
}
|
|
|
|
private void OnOpenIconSelect()
|
|
{
|
|
if (_objective is null)
|
|
return;
|
|
|
|
_spritePicker.OpenWithSprite(_objective.Icon);
|
|
}
|
|
|
|
private void OnViewObjective()
|
|
{
|
|
if (_objective is null)
|
|
return;
|
|
|
|
_console.ExecuteCommand($"vv {_objective.Entity}");
|
|
}
|
|
|
|
private void SetIcon(SpriteSpecifier sprite)
|
|
{
|
|
if (_objective is null)
|
|
return;
|
|
|
|
IconSelectButton.TextureNormal = _sprite.Frame0(sprite);
|
|
_objective.Icon = sprite;
|
|
}
|
|
}
|