mirror of
https://github.com/daffyyyy/CS2-SimpleAdmin.git
synced 2026-11-07 12:07:05 +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
81
CS2-SimpleAdmin/Menus/UiKit.cs
Normal file
81
CS2-SimpleAdmin/Menus/UiKit.cs
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
using CounterStrikeSharp.API.Core.Capabilities;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using PanoramaUiKit.Shared.Api;
|
||||
using PanoramaUiKit.Shared.Banners;
|
||||
using PanoramaUiKit.Shared.Common;
|
||||
using PanoramaUiKit.Shared.Menus;
|
||||
using PanoramaUiKit.Shared.Toasts;
|
||||
using PanoramaUiKit.Shared.Votes;
|
||||
|
||||
namespace CS2_SimpleAdmin.Menus;
|
||||
|
||||
/// <summary>
|
||||
/// Access to the Panorama UI Kit plugin and the layouts SimpleAdmin draws on.
|
||||
/// </summary>
|
||||
internal static class UiKit
|
||||
{
|
||||
private static readonly PluginCapability<IPanoramaUiKit> Capability = new(IPanoramaUiKit.CapabilityName);
|
||||
|
||||
internal static MenuLayout MenuLayout { get; private set; } = new() { Name = "uikit_menu" };
|
||||
|
||||
internal static VoteLayout VoteLayout { get; private set; } = new() { Name = "uikit_vote" };
|
||||
|
||||
internal static BannerLayout BannerLayout { get; private set; } = new() { Name = "uikit_banner" };
|
||||
|
||||
internal static ToastLayout ToastLayout { get; private set; } = new() { Name = "uikit_toast" };
|
||||
|
||||
/// <summary>
|
||||
/// Resolved on every use so a hot reload of the kit is picked up.
|
||||
/// </summary>
|
||||
internal static IPanoramaUiKit? Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
try
|
||||
{
|
||||
return Capability.Get();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal static void Configure(MenuConfig config)
|
||||
{
|
||||
MenuLayout = new MenuLayout { Name = config.MenuLayout };
|
||||
VoteLayout = new VoteLayout { Name = config.VoteLayout };
|
||||
BannerLayout = new BannerLayout { Name = config.BannerLayout };
|
||||
ToastLayout = new ToastLayout { Name = config.ToastLayout };
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Spawns the layouts up front: creating one on first use sends the client one big burst.
|
||||
/// </summary>
|
||||
internal static bool Preload(ILogger logger)
|
||||
{
|
||||
IPanoramaUiKit? kit = Instance;
|
||||
if (kit == null)
|
||||
{
|
||||
logger.LogError("Panorama UI Kit not found: install PanoramaUiKit and shared/PanoramaUiKit.Shared.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (kit.Version != IPanoramaUiKit.ApiVersion)
|
||||
{
|
||||
logger.LogWarning("Panorama UI Kit API v{Running}, SimpleAdmin built against v{Built}.", kit.Version, IPanoramaUiKit.ApiVersion);
|
||||
}
|
||||
|
||||
UiLayout[] layouts = [MenuLayout, VoteLayout, BannerLayout, ToastLayout];
|
||||
foreach (UiLayout layout in layouts)
|
||||
{
|
||||
if (!kit.Preload(layout))
|
||||
{
|
||||
logger.LogError("Layout {Layout} was refused, see the Panorama UI Kit log.", layout);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue