mirror of
https://github.com/daffyyyy/CS2-SimpleAdmin.git
synced 2026-11-07 20:17:04 +01:00
Migrate menus and votes to Panorama UI Kit
Replace MenuManagerCS2 with Panorama UI Kit for the admin menus and css_vote. Layout names (menu, vote, banner, toast) are configurable under MenuConfig and preloaded on startup; MenuType is removed and ConfigVersion bumped to 26. - Drop MenuManagerApi.dll and the old chat menu classes - Reference PanoramaUiKit.Shared.dll, bump CounterStrikeSharp to 1.0.376 - Add .editorconfig and CODING_CONVENTIONS.md, apply them codebase-wide - Remove the CS2-SimpleAdmin-docs site - Rewrite README for the fork
This commit is contained in:
parent
03a454b1b5
commit
460d8b2b85
112 changed files with 5559 additions and 36371 deletions
|
|
@ -1,16 +1,21 @@
|
|||
using CounterStrikeSharp.API.Core;
|
||||
using CounterStrikeSharp.API.Core;
|
||||
using CounterStrikeSharp.API.Core.Translations;
|
||||
using CounterStrikeSharp.API.Modules.Admin;
|
||||
using CounterStrikeSharp.API.Modules.Commands;
|
||||
using CounterStrikeSharp.API.Modules.Menu;
|
||||
using CounterStrikeSharp.API.Modules.Timers;
|
||||
using CS2_SimpleAdmin.Menus;
|
||||
using PanoramaUiKit.Shared.Api;
|
||||
using PanoramaUiKit.Shared.Votes;
|
||||
|
||||
namespace CS2_SimpleAdmin;
|
||||
|
||||
public partial class CS2_SimpleAdmin
|
||||
{
|
||||
private const float VoteDurationSeconds = 30f;
|
||||
|
||||
/// <summary>
|
||||
/// Handles the vote command, creates voting menu for players, and collects answers.
|
||||
/// Displays results after timeout and resets voting state.
|
||||
/// Handles the vote command: shows the vote screen to every player, collects one answer each
|
||||
/// and prints the results when the countdown ends.
|
||||
/// </summary>
|
||||
/// <param name="caller">The player/admin who initiated the vote, or null for console.</param>
|
||||
/// <param name="command">Command object containing question and options.</param>
|
||||
|
|
@ -19,80 +24,123 @@ public partial class CS2_SimpleAdmin
|
|||
public void OnVoteCommand(CCSPlayerController? caller, CommandInfo command)
|
||||
{
|
||||
if (command.ArgCount < 2 || _localizer == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Helper.LogCommand(caller, command);
|
||||
|
||||
VoteAnswers.Clear();
|
||||
|
||||
var question = command.GetArg(1);
|
||||
var answersCount = command.ArgCount;
|
||||
|
||||
if (caller == null || !SilentPlayers.Contains(caller.Slot))
|
||||
if (caller != null && SilentPlayers.Contains(caller.Slot))
|
||||
{
|
||||
for (var i = 2; i <= answersCount - 1; i++)
|
||||
{
|
||||
VoteAnswers.Add(command.GetArg(i), 0);
|
||||
}
|
||||
|
||||
foreach (var player in Helper.GetValidPlayers())
|
||||
{
|
||||
using (new WithTemporaryCulture(player.GetLanguage()))
|
||||
{
|
||||
IMenu? voteMenu = Helper.CreateMenu(_localizer["sa_admin_vote_menu_title", question]);
|
||||
if (voteMenu == null)
|
||||
return;
|
||||
//ChatMenu voteMenu = new(_localizer!["sa_admin_vote_menu_title", question]);
|
||||
|
||||
for (var i = 2; i <= answersCount - 1; i++)
|
||||
{
|
||||
voteMenu.AddMenuOption(command.GetArg(i), Helper.HandleVotes);
|
||||
}
|
||||
|
||||
voteMenu.PostSelectAction = PostSelectAction.Close;
|
||||
|
||||
Helper.PrintToCenterAll(_localizer["sa_admin_vote_message", caller == null ? _localizer["sa_console"] : caller.PlayerName, question]);
|
||||
|
||||
player.SendLocalizedMessage(_localizer,
|
||||
"sa_admin_vote_message",
|
||||
caller == null ? _localizer["sa_console"] : caller.PlayerName,
|
||||
question);
|
||||
|
||||
voteMenu.Open(player);
|
||||
|
||||
//MenuManager.OpenChatMenu(player, voteMenu);
|
||||
}
|
||||
}
|
||||
|
||||
VoteInProgress = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if (VoteInProgress)
|
||||
IPanoramaUiKit? kit = UiKit.Instance;
|
||||
if (kit == null)
|
||||
{
|
||||
AddTimer(30, () =>
|
||||
return;
|
||||
}
|
||||
|
||||
string question = command.GetArg(1);
|
||||
string callerName = Helper.GetCallerName(caller);
|
||||
List<string> answers = [];
|
||||
for (int i = 2; i < command.ArgCount; i++)
|
||||
{
|
||||
answers.Add(command.GetArg(i));
|
||||
}
|
||||
|
||||
int[] counts = new int[answers.Count];
|
||||
Dictionary<ulong, int> ballots = [];
|
||||
|
||||
VoteInProgress = true;
|
||||
|
||||
foreach (CCSPlayerController player in Helper.GetValidPlayers())
|
||||
{
|
||||
kit.Votes.Show(player, BuildVote(player, question, answers, counts, null, OnVote));
|
||||
player.SendLocalizedMessage(_localizer, "sa_admin_vote_message", callerName, question);
|
||||
}
|
||||
|
||||
Helper.PrintToCenterAll(_localizer["sa_admin_vote_message", callerName, question]);
|
||||
|
||||
AddTimer(VoteDurationSeconds, () =>
|
||||
{
|
||||
UiKit.Instance?.Votes.HideAll(UiKit.VoteLayout);
|
||||
VoteInProgress = false;
|
||||
|
||||
if (_localizer == null)
|
||||
{
|
||||
foreach (var player in Helper.GetValidPlayers())
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (CCSPlayerController player in Helper.GetValidPlayers())
|
||||
{
|
||||
player.SendLocalizedMessage(_localizer, "sa_admin_vote_message_results", question);
|
||||
|
||||
for (int i = 0; i < answers.Count; i++)
|
||||
{
|
||||
if (_localizer != null)
|
||||
player.SendLocalizedMessage(_localizer,
|
||||
"sa_admin_vote_message_results",
|
||||
question);
|
||||
player.SendLocalizedMessage(_localizer, "sa_admin_vote_message_results_answer", answers[i], counts[i]);
|
||||
}
|
||||
}
|
||||
}, TimerFlags.STOP_ON_MAPCHANGE);
|
||||
|
||||
return;
|
||||
|
||||
void OnVote(VoteEvent vote)
|
||||
{
|
||||
if (!VoteInProgress || ballots.ContainsKey(vote.Player.SteamID))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
ballots[vote.Player.SteamID] = vote.Index;
|
||||
counts[vote.Index]++;
|
||||
|
||||
IPanoramaUiKit? currentKit = UiKit.Instance;
|
||||
if (currentKit == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (CCSPlayerController player in Helper.GetValidPlayers())
|
||||
{
|
||||
int? selected = null;
|
||||
if (ballots.TryGetValue(player.SteamID, out int index))
|
||||
{
|
||||
selected = index;
|
||||
}
|
||||
|
||||
foreach (var (key, value) in VoteAnswers)
|
||||
{
|
||||
foreach (var player in Helper.GetValidPlayers())
|
||||
{
|
||||
if (_localizer != null)
|
||||
player.SendLocalizedMessage(_localizer,
|
||||
"sa_admin_vote_message_results_answer",
|
||||
key,
|
||||
value);
|
||||
}
|
||||
}
|
||||
VoteAnswers.Clear();
|
||||
VoteInProgress = false;
|
||||
}, CounterStrikeSharp.API.Modules.Timers.TimerFlags.STOP_ON_MAPCHANGE);
|
||||
currentKit.Votes.Update(player, BuildVote(player, question, answers, counts, selected, OnVote));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The vote screen for one player, locked once that player has voted.
|
||||
/// </summary>
|
||||
private static VoteOptions BuildVote(CCSPlayerController player, string question, List<string> answers, int[] counts,
|
||||
int? selected, Action<VoteEvent> onVote)
|
||||
{
|
||||
string title;
|
||||
using (new WithTemporaryCulture(player.GetLanguage()))
|
||||
{
|
||||
title = _localizer?["sa_admin_vote_menu_title", question] ?? question;
|
||||
}
|
||||
|
||||
List<VoteChoice> choices = [];
|
||||
for (int i = 0; i < answers.Count; i++)
|
||||
{
|
||||
choices.Add(new VoteChoice(answers[i], counts[i]));
|
||||
}
|
||||
|
||||
return new VoteOptions
|
||||
{
|
||||
Layout = UiKit.VoteLayout,
|
||||
Title = title,
|
||||
Choices = choices,
|
||||
Selected = selected,
|
||||
Locked = selected.HasValue,
|
||||
Seconds = VoteDurationSeconds,
|
||||
OnVote = onVote
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue