v1.0.4
This commit is contained in:
parent
a7009be3e0
commit
898f86f888
137 changed files with 3553 additions and 3780 deletions
66
WASDMenuAPI - SRC Files/Classes/WasdManager.cs
Normal file
66
WASDMenuAPI - SRC Files/Classes/WasdManager.cs
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
using CounterStrikeSharp.API.Core;
|
||||
using WASDSharedAPI;
|
||||
|
||||
namespace WASDMenuAPI.Classes;
|
||||
|
||||
public class WasdManager : IWasdMenuManager
|
||||
{
|
||||
public void OpenMainMenu(CCSPlayerController? player, IWasdMenu? menu)
|
||||
{
|
||||
if(player == null)
|
||||
return;
|
||||
WASDMenuAPI.Players[player.SteamID].OpenMainMenu((WasdMenu?)menu);
|
||||
}
|
||||
|
||||
public void CloseMenu(CCSPlayerController? player)
|
||||
{
|
||||
if(player == null)
|
||||
return;
|
||||
WASDMenuAPI.Players[player.SteamID].OpenMainMenu(null);
|
||||
}
|
||||
|
||||
public void CloseSubMenu(CCSPlayerController? player)
|
||||
{
|
||||
if(player == null)
|
||||
return;
|
||||
WASDMenuAPI.Players[player.SteamID].CloseSubMenu();
|
||||
}
|
||||
|
||||
public void CloseAllSubMenus(CCSPlayerController? player)
|
||||
{
|
||||
if(player == null)
|
||||
return;
|
||||
WASDMenuAPI.Players[player.SteamID].CloseAllSubMenus();
|
||||
}
|
||||
|
||||
public void OpenSubMenu(CCSPlayerController? player, IWasdMenu? menu)
|
||||
{
|
||||
if (player == null)
|
||||
return;
|
||||
WASDMenuAPI.Players[player.SteamID].OpenSubMenu(menu);
|
||||
}
|
||||
|
||||
public IWasdMenu CreateMenu(string title = "", string controlText = "")
|
||||
{
|
||||
WasdMenu menu = new WasdMenu
|
||||
{
|
||||
Title = title,
|
||||
ControlText = controlText
|
||||
};
|
||||
return menu;
|
||||
}
|
||||
|
||||
public bool HasMenu(CCSPlayerController? player)
|
||||
{
|
||||
if (player == null)
|
||||
return false;
|
||||
return WASDMenuAPI.Players.ContainsKey(player.SteamID);
|
||||
}
|
||||
|
||||
public void UpdateActiveMenu(CCSPlayerController? player, Dictionary<string, Action<CCSPlayerController, IWasdMenuOption>> list)
|
||||
{
|
||||
if (player == null)
|
||||
return;
|
||||
WASDMenuAPI.Players[player.SteamID].UpdateActiveMenu(list);
|
||||
}
|
||||
}
|
||||
25
WASDMenuAPI - SRC Files/Classes/WasdMenu.cs
Normal file
25
WASDMenuAPI - SRC Files/Classes/WasdMenu.cs
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
using CounterStrikeSharp.API.Core;
|
||||
using WASDSharedAPI;
|
||||
|
||||
namespace WASDMenuAPI.Classes;
|
||||
|
||||
public class WasdMenu : IWasdMenu
|
||||
{
|
||||
public string Title { get; set; } = "";
|
||||
public string ControlText { get; set; } = "";
|
||||
public LinkedList<IWasdMenuOption>? Options { get; set; } = new();
|
||||
public LinkedListNode<IWasdMenuOption>? Prev { get; set; } = null;
|
||||
public LinkedListNode<IWasdMenuOption> Add(string display, Action<CCSPlayerController, IWasdMenuOption> onChoice)
|
||||
{
|
||||
if (Options == null)
|
||||
Options = new();
|
||||
WasdMenuOption newOption = new WasdMenuOption
|
||||
{
|
||||
OptionDisplay = display,
|
||||
OnChoose = onChoice,
|
||||
Index = Options.Count,
|
||||
Parent = this
|
||||
};
|
||||
return Options.AddLast(newOption);
|
||||
}
|
||||
}
|
||||
13
WASDMenuAPI - SRC Files/Classes/WasdMenuOption.cs
Normal file
13
WASDMenuAPI - SRC Files/Classes/WasdMenuOption.cs
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
using CounterStrikeSharp.API.Core;
|
||||
using WASDMenuAPI.Classes;
|
||||
using WASDSharedAPI;
|
||||
|
||||
namespace WASDMenuAPI;
|
||||
|
||||
public class WasdMenuOption : IWasdMenuOption
|
||||
{
|
||||
public IWasdMenu? Parent { get; set; }
|
||||
public string? OptionDisplay { get; set; }
|
||||
public Action<CCSPlayerController, IWasdMenuOption>? OnChoose { get; set; }
|
||||
public int Index { get; set; }
|
||||
}
|
||||
229
WASDMenuAPI - SRC Files/Classes/WasdMenuPlayer.cs
Normal file
229
WASDMenuAPI - SRC Files/Classes/WasdMenuPlayer.cs
Normal file
|
|
@ -0,0 +1,229 @@
|
|||
using System.Text;
|
||||
using CounterStrikeSharp.API;
|
||||
using CounterStrikeSharp.API.Core;
|
||||
using WASDMenuAPI.Classes;
|
||||
using WASDSharedAPI;
|
||||
|
||||
namespace WASDMenuAPI;
|
||||
|
||||
public class WasdMenuPlayer
|
||||
{
|
||||
public CCSPlayerController player { get; set; }
|
||||
public WasdMenu? MainMenu = null;
|
||||
public LinkedListNode<IWasdMenuOption>? CurrentChoice = null;
|
||||
public LinkedListNode<IWasdMenuOption>? MenuStart = null;
|
||||
public string CenterHtml = "";
|
||||
public int VisibleOptions = 3;
|
||||
public PlayerButtons Buttons { get; set; }
|
||||
|
||||
public int scrollIndex = 0;
|
||||
public int maxLength = 21;
|
||||
public int scrollJump = 3;
|
||||
|
||||
public void OpenMainMenu(WasdMenu? menu)
|
||||
{
|
||||
if (menu == null)
|
||||
{
|
||||
MainMenu = null;
|
||||
CurrentChoice = null;
|
||||
CenterHtml = "";
|
||||
return;
|
||||
}
|
||||
MainMenu = menu;
|
||||
CurrentChoice = MainMenu.Options?.First;
|
||||
MenuStart = CurrentChoice;
|
||||
UpdateCenterHtml();
|
||||
}
|
||||
|
||||
public void OpenSubMenu(IWasdMenu? menu)
|
||||
{
|
||||
if (menu == null)
|
||||
{
|
||||
CurrentChoice = MainMenu?.Options?.First;
|
||||
MenuStart = CurrentChoice;
|
||||
UpdateCenterHtml();
|
||||
return;
|
||||
}
|
||||
|
||||
CurrentChoice = menu.Options?.First;
|
||||
MenuStart = CurrentChoice;
|
||||
UpdateCenterHtml();
|
||||
}
|
||||
public void GoBackToPrev(LinkedListNode<IWasdMenuOption>? menu)
|
||||
{
|
||||
if (menu == null)
|
||||
{
|
||||
CurrentChoice = MainMenu?.Options?.First;
|
||||
MenuStart = CurrentChoice;
|
||||
UpdateCenterHtml();
|
||||
return;
|
||||
}
|
||||
|
||||
CurrentChoice = menu;
|
||||
if (CurrentChoice.Value.Index >= 5 )
|
||||
{
|
||||
MenuStart = CurrentChoice;
|
||||
for (int i = 0; i < VisibleOptions; i++)
|
||||
{
|
||||
MenuStart = MenuStart?.Previous;
|
||||
}
|
||||
}
|
||||
else
|
||||
MenuStart = CurrentChoice.List?.First;
|
||||
UpdateCenterHtml();
|
||||
}
|
||||
|
||||
public void CloseSubMenu()
|
||||
{
|
||||
if (CurrentChoice?.Value.Parent?.Prev == null)
|
||||
return;
|
||||
GoBackToPrev(CurrentChoice?.Value.Parent.Prev);
|
||||
}
|
||||
|
||||
public void CloseAllSubMenus()
|
||||
{
|
||||
OpenSubMenu(null);
|
||||
}
|
||||
|
||||
public void Choose()
|
||||
{
|
||||
CurrentChoice?.Value.OnChoose?.Invoke(player, CurrentChoice.Value);
|
||||
}
|
||||
|
||||
public void ScrollDown()
|
||||
{
|
||||
if(CurrentChoice == null || MainMenu == null)
|
||||
return;
|
||||
scrollIndex = 0;
|
||||
CurrentChoice = CurrentChoice.Next ?? CurrentChoice.List?.First;
|
||||
MenuStart = CurrentChoice!.Value.Index >= VisibleOptions ? MenuStart!.Next : CurrentChoice.List?.First;
|
||||
UpdateCenterHtml();
|
||||
}
|
||||
|
||||
public void ScrollUp()
|
||||
{
|
||||
if(CurrentChoice == null || MainMenu == null)
|
||||
return;
|
||||
scrollIndex = 0;
|
||||
CurrentChoice = CurrentChoice.Previous ?? CurrentChoice.List?.Last;
|
||||
if (CurrentChoice == CurrentChoice?.List?.Last && CurrentChoice?.Value.Index >= VisibleOptions)
|
||||
{
|
||||
MenuStart = CurrentChoice;
|
||||
for (int i = 0; i < VisibleOptions - 1; i++)
|
||||
MenuStart = MenuStart?.Previous;
|
||||
}
|
||||
else
|
||||
MenuStart = CurrentChoice!.Value.Index >= VisibleOptions ? MenuStart!.Previous : CurrentChoice.List?.First;
|
||||
UpdateCenterHtml();
|
||||
}
|
||||
|
||||
private void UpdateCenterHtml()
|
||||
{
|
||||
if (CurrentChoice == null || MainMenu == null || MenuStart == null)
|
||||
return;
|
||||
|
||||
StringBuilder builder = new();
|
||||
string endControl = "";
|
||||
LinkedListNode<IWasdMenuOption>? option = MenuStart;
|
||||
|
||||
if (option?.Value?.Parent?.Title != "")
|
||||
builder.AppendLine($"{option.Value.Parent?.Title}</u><font class='fontSize-m' color='white'><br>");
|
||||
|
||||
if (option?.Value?.Parent?.ControlText != "")
|
||||
endControl = option?.Value?.Parent?.ControlText ?? "";
|
||||
|
||||
int shown = 0;
|
||||
int maxOptions = VisibleOptions;
|
||||
|
||||
while (shown < maxOptions && option != null && option.Value != null)
|
||||
{
|
||||
/* if (shown == maxOptions - 1 && option.Next != null)
|
||||
{
|
||||
builder.AppendLine(
|
||||
$"<img src='https://raw.githubusercontent.com/oqyh/cs2-Kill-Sound-GoldKingZ/main/Resources/arrow.gif' class=''> <img src='https://raw.githubusercontent.com/oqyh/cs2-Kill-Sound-GoldKingZ/main/Resources/arrow.gif' class=''> <img src='https://raw.githubusercontent.com/oqyh/cs2-Kill-Sound-GoldKingZ/main/Resources/arrow.gif' class=''> <br>");
|
||||
break;
|
||||
}*/
|
||||
string text = option.Value.OptionDisplay!;
|
||||
if (option == CurrentChoice)
|
||||
{
|
||||
if (text.Length > maxLength)
|
||||
{
|
||||
if (scrollIndex >= text.Length - maxLength)
|
||||
{
|
||||
text = text.Substring(scrollIndex);
|
||||
if (Server.TickCount % 32 == 0)
|
||||
scrollIndex = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
text = text.Substring(scrollIndex, maxLength);
|
||||
if (Server.TickCount % 32 == 0)
|
||||
scrollIndex += scrollJump;
|
||||
}
|
||||
}
|
||||
|
||||
builder.AppendLine($"</font><font color='purple'>[ </font><font color='orange'>{text}</font><font color='purple'> ]</font><font color='white'> <br>");
|
||||
}
|
||||
else
|
||||
builder.AppendLine($"{text.Substring(0, maxLength)} <br>");
|
||||
|
||||
option = option.Next;
|
||||
shown++;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(endControl))
|
||||
builder.AppendLine(endControl);
|
||||
|
||||
builder.AppendLine("</div>");
|
||||
CenterHtml = builder.ToString();
|
||||
}
|
||||
|
||||
public void UpdateActiveMenu(Dictionary<string, Action<CCSPlayerController, IWasdMenuOption>> list)
|
||||
{
|
||||
if (list.Count == 0)
|
||||
{
|
||||
OpenMainMenu(null);
|
||||
return;
|
||||
}
|
||||
|
||||
if (MainMenu == null || MainMenu.Options == null)
|
||||
return;
|
||||
|
||||
MainMenu.Options.Clear();
|
||||
bool choiceExists = false;
|
||||
|
||||
foreach (var item in list)
|
||||
{
|
||||
WasdMenuOption newOption = new WasdMenuOption
|
||||
{
|
||||
OptionDisplay = item.Key,
|
||||
OnChoose = item.Value,
|
||||
Index = MainMenu.Options.Count,
|
||||
Parent = MainMenu
|
||||
};
|
||||
MainMenu.Options.AddLast(newOption);
|
||||
|
||||
if (CurrentChoice?.Value?.OptionDisplay == item.Key)
|
||||
{
|
||||
CurrentChoice = MainMenu.Options?.Last;
|
||||
choiceExists = true;
|
||||
}
|
||||
}
|
||||
if (!choiceExists)
|
||||
CurrentChoice = MainMenu.Options?.First;
|
||||
|
||||
if (CurrentChoice != null)
|
||||
{
|
||||
if (CurrentChoice.Value.Index >= VisibleOptions)
|
||||
{
|
||||
MenuStart = CurrentChoice;
|
||||
for (int i = 0; i < VisibleOptions - 1; i++)
|
||||
MenuStart = MenuStart?.Previous;
|
||||
}
|
||||
else
|
||||
MenuStart = MainMenu.Options?.First;
|
||||
}
|
||||
|
||||
UpdateCenterHtml();
|
||||
}
|
||||
}
|
||||
13
WASDMenuAPI - SRC Files/Interfaces/IWasdMenu.cs
Normal file
13
WASDMenuAPI - SRC Files/Interfaces/IWasdMenu.cs
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
using CounterStrikeSharp.API.Core;
|
||||
|
||||
namespace WASDSharedAPI;
|
||||
|
||||
public interface IWasdMenu
|
||||
{
|
||||
public string? Title { get; set; }
|
||||
public string? ControlText { get; set; }
|
||||
public LinkedList<IWasdMenuOption>? Options { get; set; }
|
||||
// previous option node
|
||||
public LinkedListNode<IWasdMenuOption>? Prev { get; set; }
|
||||
public LinkedListNode<IWasdMenuOption> Add(string display, Action<CCSPlayerController, IWasdMenuOption> onChoice);
|
||||
}
|
||||
21
WASDMenuAPI - SRC Files/Interfaces/IWasdMenuManager.cs
Normal file
21
WASDMenuAPI - SRC Files/Interfaces/IWasdMenuManager.cs
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
using CounterStrikeSharp.API.Core;
|
||||
|
||||
namespace WASDSharedAPI;
|
||||
|
||||
public interface IWasdMenuManager
|
||||
{
|
||||
//open the menu as main menu
|
||||
public void OpenMainMenu(CCSPlayerController? player, IWasdMenu? menu);
|
||||
//close all menus
|
||||
public void CloseMenu(CCSPlayerController? player);
|
||||
//close current submenu and go to previous menu/submenu
|
||||
public void CloseSubMenu(CCSPlayerController? player);
|
||||
//close all submenus and go to main menu
|
||||
public void CloseAllSubMenus(CCSPlayerController? player);
|
||||
//open menu as submenu
|
||||
public void OpenSubMenu(CCSPlayerController? player, IWasdMenu? menu);
|
||||
//create new menu object
|
||||
public IWasdMenu CreateMenu(string title = "", string ControlText = "");
|
||||
public bool HasMenu(CCSPlayerController? player);
|
||||
public void UpdateActiveMenu(CCSPlayerController? player, Dictionary<string, Action<CCSPlayerController, IWasdMenuOption>> list);
|
||||
}
|
||||
11
WASDMenuAPI - SRC Files/Interfaces/IWasdMenuOption.cs
Normal file
11
WASDMenuAPI - SRC Files/Interfaces/IWasdMenuOption.cs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
using CounterStrikeSharp.API.Core;
|
||||
|
||||
namespace WASDSharedAPI;
|
||||
|
||||
public interface IWasdMenuOption
|
||||
{
|
||||
public IWasdMenu? Parent { get; set; }
|
||||
public string? OptionDisplay { get; set; }
|
||||
public Action<CCSPlayerController, IWasdMenuOption>? OnChoose { get; set; }
|
||||
public int Index { get; set; }
|
||||
}
|
||||
73
WASDMenuAPI - SRC Files/WASDMenuAPI.cs
Normal file
73
WASDMenuAPI - SRC Files/WASDMenuAPI.cs
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
using CounterStrikeSharp.API;
|
||||
using CounterStrikeSharp.API.Core;
|
||||
using WASDMenuAPI.Classes;
|
||||
|
||||
namespace WASDMenuAPI;
|
||||
|
||||
public class WASDMenuAPI
|
||||
{
|
||||
public string ModuleName => "WASDMenuAPI";
|
||||
public string ModuleVersion => "1.0.2";
|
||||
public string ModuleAuthor => "Interesting";
|
||||
|
||||
public static readonly Dictionary<ulong, WasdMenuPlayer> Players = [];
|
||||
|
||||
public static void LoadPlugin(BasePlugin basePlugin, bool hotReload)
|
||||
{
|
||||
var wasdMenuManager = new WasdManager();
|
||||
basePlugin.RegisterEventHandler<EventPlayerActivate>((@event, info) =>
|
||||
{
|
||||
if (@event.Userid != null)
|
||||
Players[@event.Userid.SteamID] = new WasdMenuPlayer
|
||||
{
|
||||
player = @event.Userid,
|
||||
Buttons = 0
|
||||
};
|
||||
return HookResult.Continue;
|
||||
});
|
||||
basePlugin.RegisterEventHandler<EventPlayerDisconnect>((@event, info) =>
|
||||
{
|
||||
if (@event.Userid != null) Players.Remove(@event.Userid.SteamID);
|
||||
return HookResult.Continue;
|
||||
});
|
||||
|
||||
basePlugin.RegisterListener<Listeners.OnTick>(OnTick);
|
||||
|
||||
if(hotReload)
|
||||
foreach (var pl in Utilities.GetPlayers())
|
||||
{
|
||||
Players[pl.SteamID] = new WasdMenuPlayer
|
||||
{
|
||||
player = pl,
|
||||
Buttons = pl.Buttons
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public static void OnTick()
|
||||
{
|
||||
foreach (var player in Players.Values.Where(p => p.MainMenu != null))
|
||||
{
|
||||
if ((player.Buttons & PlayerButtons.Forward) == 0 && (player.player.Buttons & PlayerButtons.Forward) != 0)
|
||||
{
|
||||
player.ScrollUp();
|
||||
}
|
||||
else if((player.Buttons & PlayerButtons.Back) == 0 && (player.player.Buttons & PlayerButtons.Back) != 0)
|
||||
{
|
||||
player.ScrollDown();
|
||||
}
|
||||
else if((player.Buttons & PlayerButtons.Use) == 0 && (player.player.Buttons & PlayerButtons.Use) != 0)
|
||||
{
|
||||
player.Choose();
|
||||
}
|
||||
|
||||
player.Buttons = player.player.Buttons;
|
||||
if(player.CenterHtml != "")
|
||||
Server.NextFrame(() =>
|
||||
player.player.PrintToCenterHtml(player.CenterHtml)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
13
WASDMenuAPI - SRC Files/WASDMenuAPI.csproj
Normal file
13
WASDMenuAPI - SRC Files/WASDMenuAPI.csproj
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="CounterStrikeSharp.API" Version="1.0.246" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
25
WASDMenuAPI - SRC Files/WASDMenuAPI.sln
Normal file
25
WASDMenuAPI - SRC Files/WASDMenuAPI.sln
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.9.34728.123
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WASDMenuAPI", "WASDMenuAPI.csproj", "{0119D01B-2F71-4918-B638-795C423E143F}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{0119D01B-2F71-4918-B638-795C423E143F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{0119D01B-2F71-4918-B638-795C423E143F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{0119D01B-2F71-4918-B638-795C423E143F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{0119D01B-2F71-4918-B638-795C423E143F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {33517EB0-9056-4518-864C-37D0AFF4124B}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
Loading…
Add table
Add a link
Reference in a new issue