Files
tbd-station-14/Content.Client/UserInterface/Systems/Ghost/Widgets/GhostGui.xaml.cs
Kara c71850a53f Convert ghost toggle button into an action (#12658)
* Convert ghost toggle button into an action

* figs
2022-11-18 16:30:53 -06:00

67 lines
1.7 KiB
C#

using Content.Client.Stylesheets;
using Content.Client.UserInterface.Systems.Ghost.Controls;
using Robust.Client.AutoGenerated;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.XAML;
namespace Content.Client.UserInterface.Systems.Ghost.Widgets;
[GenerateTypedNameReferences]
public sealed partial class GhostGui : UIWidget
{
public GhostTargetWindow TargetWindow { get; }
public event Action? RequestWarpsPressed;
public event Action? ReturnToBodyPressed;
public event Action? GhostRolesPressed;
public GhostGui()
{
RobustXamlLoader.Load(this);
TargetWindow = new GhostTargetWindow();
MouseFilter = MouseFilterMode.Ignore;
GhostWarpButton.OnPressed += _ => RequestWarpsPressed?.Invoke();
ReturnToBodyButton.OnPressed += _ => ReturnToBodyPressed?.Invoke();
GhostRolesButton.OnPressed += _ => GhostRolesPressed?.Invoke();
}
public void Hide()
{
TargetWindow.Close();
Visible = false;
}
public void Update(int? roles, bool? canReturnToBody)
{
ReturnToBodyButton.Disabled = !canReturnToBody ?? true;
if (roles != null)
{
GhostRolesButton.Text = Loc.GetString("ghost-gui-ghost-roles-button", ("count", roles));
if (roles > 0)
{
GhostRolesButton.StyleClasses.Add(StyleBase.ButtonCaution);
}
else
{
GhostRolesButton.StyleClasses.Remove(StyleBase.ButtonCaution);
}
}
TargetWindow.Populate();
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
if (disposing)
{
TargetWindow.Dispose();
}
}
}