| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- using System;
- using Content.Client.Stylesheets;
- using Content.Shared.Ghost;
- using Robust.Client.AutoGenerated;
- using Robust.Client.UserInterface;
- using Robust.Client.UserInterface.Controls;
- using Robust.Client.UserInterface.XAML;
- using Robust.Shared.Timing;
- using Robust.Shared.Utility;
- namespace Content.Client.Voting.UI
- {
- [GenerateTypedNameReferences]
- public sealed partial class VotePopup : Control
- {
- [Dependency] private readonly IGameTiming _gameTiming = default!;
- [Dependency] private readonly IVoteManager _voteManager = default!;
- [Dependency] private readonly IEntityNetworkManager _net = default!;
- private readonly VoteManager.ActiveVote _vote;
- private readonly Button[] _voteButtons;
- private readonly NetEntity? _targetEntity;
- public VotePopup(VoteManager.ActiveVote vote)
- {
- _vote = vote;
- IoCManager.InjectDependencies(this);
- RobustXamlLoader.Load(this);
- Stylesheet = IoCManager.Resolve<IStylesheetManager>().SheetSpace;
- if (_vote.TargetEntity != null && _vote.TargetEntity != 0)
- {
- _targetEntity = new NetEntity(_vote.TargetEntity.Value);
- FollowVoteTarget.Visible = true;
- FollowVoteTarget.OnPressed += _ => AttemptFollowVoteEntity();
- }
- Modulate = Color.White.WithAlpha(0.75f);
- _voteButtons = new Button[vote.Entries.Length];
- var group = new ButtonGroup();
- for (var i = 0; i < _voteButtons.Length; i++)
- {
- var button = new Button
- {
- ToggleMode = true,
- Group = group
- };
- _voteButtons[i] = button;
- VoteOptionsContainer.AddChild(button);
- var i1 = i;
- button.OnPressed += _ => _voteManager.SendCastVote(vote.Id, i1);
- }
- }
- public void UpdateData()
- {
- VoteTitle.SetMessage(FormattedMessage.FromUnformatted(_vote.Title));
- VoteCaller.Text = Loc.GetString("ui-vote-created", ("initiator", _vote.Initiator));
- for (var i = 0; i < _voteButtons.Length; i++)
- {
- var entry = _vote.Entries[i];
- if (_vote.DisplayVotes)
- {
- _voteButtons[i].Text = Loc.GetString("ui-vote-button", ("text", entry.Text), ("votes", entry.Votes));
- }
- else
- {
- _voteButtons[i].Text = Loc.GetString("ui-vote-button-no-votes", ("text", entry.Text));
- }
- if (_vote.OurVote == i)
- _voteButtons[i].Pressed = true;
- }
- }
- private void AttemptFollowVoteEntity()
- {
- if (_targetEntity != null)
- {
- var msg = new GhostWarpToTargetRequestEvent(_targetEntity.Value);
- _net.SendSystemNetworkMessage(msg);
- }
- }
- protected override void FrameUpdate(FrameEventArgs args)
- {
- // Logger.Debug($"{_gameTiming.ServerTime}, {_vote.StartTime}, {_vote.EndTime}");
- var curTime = _gameTiming.RealTime;
- var timeLeft = _vote.EndTime - curTime;
- if (timeLeft < TimeSpan.Zero)
- timeLeft = TimeSpan.Zero;
- // Round up a second.
- timeLeft = TimeSpan.FromSeconds(Math.Ceiling(timeLeft.TotalSeconds));
- TimeLeftBar.Value = Math.Min(1, (float) ((curTime.TotalSeconds - _vote.StartTime.TotalSeconds) /
- (_vote.EndTime.TotalSeconds - _vote.StartTime.TotalSeconds)));
- TimeLeftText.Text = $"{timeLeft:m\\:ss}";
- }
- }
- }
|