Files
tbd-station-14/Content.Client/UserInterface/Systems/Ghost/Widgets/GhostGui.xaml.cs
Jacob Tong 9f485d7124 Add toggle ghost visibility button to ghost GUI (#12325)
* Add toggle ghost visibility button to ghosts

* Rename to toggleghosts
2022-11-01 20:14:06 -05:00

69 lines
1.9 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 event Action? ToggleGhostVisibility;
public GhostGui()
{
RobustXamlLoader.Load(this);
TargetWindow = new GhostTargetWindow();
MouseFilter = MouseFilterMode.Ignore;
GhostWarpButton.OnPressed += _ => RequestWarpsPressed?.Invoke();
ReturnToBodyButton.OnPressed += _ => ReturnToBodyPressed?.Invoke();
GhostRolesButton.OnPressed += _ => GhostRolesPressed?.Invoke();
ToggleGhostVisibilityButton.OnPressed += _ => ToggleGhostVisibility?.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();
}
}
}