mirror of
https://github.com/space-wizards/space-station-14.git
synced 2026-02-14 19:29:53 +01:00
63 lines
1.6 KiB
C#
63 lines
1.6 KiB
C#
using Robust.Client.UserInterface.Controls;
|
|
using Robust.Shared.IoC;
|
|
using Robust.Shared.Localization;
|
|
|
|
namespace Content.Client.Voting.UI
|
|
{
|
|
/// <summary>
|
|
/// LITERALLY just a button that opens the vote call menu.
|
|
/// Automatically disables itself if the client cannot call votes.
|
|
/// </summary>
|
|
public sealed class VoteCallMenuButton : Button
|
|
{
|
|
[Dependency] private readonly IVoteManager _voteManager = default!;
|
|
|
|
private VoteCallMenu? _voteCallMenu;
|
|
|
|
public VoteCallMenuButton()
|
|
{
|
|
IoCManager.InjectDependencies(this);
|
|
|
|
Text = Loc.GetString("ui-vote-menu-button");
|
|
ToggleMode = true;
|
|
OnPressed += OnOnPressed;
|
|
}
|
|
|
|
private void OnOnPressed(ButtonEventArgs obj)
|
|
{
|
|
if (_voteCallMenu is { IsOpen: true })
|
|
{
|
|
_voteCallMenu.Close();
|
|
return;
|
|
}
|
|
|
|
_voteCallMenu = new VoteCallMenu();
|
|
_voteCallMenu.OnClose += () => Pressed = false;
|
|
_voteCallMenu.OpenCentered();
|
|
}
|
|
|
|
protected override void EnteredTree()
|
|
{
|
|
base.EnteredTree();
|
|
|
|
UpdateCanCall(_voteManager.CanCallVote);
|
|
_voteManager.CanCallVoteChanged += UpdateCanCall;
|
|
}
|
|
|
|
protected override void ExitedTree()
|
|
{
|
|
base.ExitedTree();
|
|
|
|
if (_voteCallMenu is { IsOpen: true })
|
|
_voteCallMenu.Close();
|
|
|
|
_voteManager.CanCallVoteChanged += UpdateCanCall;
|
|
}
|
|
|
|
private void UpdateCanCall(bool canCall)
|
|
{
|
|
Disabled = !canCall;
|
|
}
|
|
}
|
|
}
|