CatStation/Content.Client/Voting/UI/VoteCallMenuButton.cs
Pieter-Jan Briers 5168b5f3d4
IoC source gen compatibility (#43863)
* IoC source gen compatibility

Can be merged before or after https://github.com/space-wizards/RobustToolbox/pull/6549 doesn't really matter.

* Missed a spot
2026-05-09 03:29:58 +00:00

62 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 partial class VoteCallMenuButton : Button
{
[Dependency] private 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;
}
}
}