1
0

IVoteHandle.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. using Content.Server.Voting.Managers;
  2. using Robust.Shared.Player;
  3. namespace Content.Server.Voting
  4. {
  5. /// <summary>
  6. /// A handle to vote, active or past.
  7. /// </summary>
  8. /// <remarks>
  9. /// <para>
  10. /// Vote options are referred to by UI/networking as integer IDs.
  11. /// These IDs are the index of the vote option in the <see cref="VoteOptions.Options"/> list
  12. /// used to create the vote.
  13. /// </para>
  14. /// </remarks>
  15. public interface IVoteHandle
  16. {
  17. /// <summary>
  18. /// The numeric ID of the vote. Can be used in <see cref="IVoteManager.TryGetVote"/>.
  19. /// </summary>
  20. int Id { get; }
  21. /// <summary>
  22. /// The title of the vote.
  23. /// </summary>
  24. string Title { get; }
  25. /// <summary>
  26. /// Text representing who/what initiated the vote.
  27. /// </summary>
  28. string InitiatorText { get; }
  29. /// <summary>
  30. /// Whether the vote has finished and is no longer active.
  31. /// </summary>
  32. bool Finished { get; }
  33. /// <summary>
  34. /// Whether the vote was cancelled by an administrator and did not finish naturally.
  35. /// </summary>
  36. /// <remarks>
  37. /// If this is true, <see cref="Finished"/> is also true.
  38. /// </remarks>
  39. bool Cancelled { get; }
  40. /// <summary>
  41. /// Dictionary of votes cast by players, matching the option's id.
  42. /// </summary>
  43. IReadOnlyDictionary<ICommonSession, int> CastVotes { get; }
  44. /// <summary>
  45. /// Current count of votes per option type.
  46. /// </summary>
  47. IReadOnlyDictionary<object, int> VotesPerOption { get; }
  48. /// <summary>
  49. /// Invoked when this vote has successfully finished.
  50. /// </summary>
  51. event VoteFinishedEventHandler OnFinished;
  52. /// <summary>
  53. /// Invoked if this vote gets cancelled.
  54. /// </summary>
  55. event VoteCancelledEventHandler OnCancelled;
  56. /// <summary>
  57. /// Check whether a certain integer option ID is valid.
  58. /// </summary>
  59. /// <param name="optionId">The integer ID of the option.</param>
  60. /// <returns>True if the option ID is valid, false otherwise.</returns>
  61. bool IsValidOption(int optionId);
  62. /// <summary>
  63. /// Cast a vote for a specific player.
  64. /// </summary>
  65. /// <param name="session">The player session to vote for.</param>
  66. /// <param name="optionId">
  67. /// The integer option ID to vote for. If null, "no vote" is selected (abstaining).
  68. /// </param>
  69. /// <exception cref="ArgumentOutOfRangeException">
  70. /// <paramref name="optionId"/> is not a valid option ID.
  71. /// </exception>
  72. void CastVote(ICommonSession session, int? optionId);
  73. /// <summary>
  74. /// Cancel this vote.
  75. /// </summary>
  76. void Cancel();
  77. }
  78. }