Compare commits

...

6 Commits

Author SHA1 Message Date
WidovV
5ce04649fd Add CenterHtmlMenu button colors (#398) 2024-04-06 21:43:38 +10:00
Michael Wilson
7b7202fe8a [no ci] Update README.md 2024-04-05 11:54:53 +10:00
Michael Wilson
cadb817ed2 fix: mark center html menu constructor as obsolete, throw error (#396) 2024-04-04 09:33:22 +10:00
luxury fabka
211516cce5 added Open method to each menu type (#385)
Co-authored-by: Michael Wilson <roflmuffin@users.noreply.github.com>
Co-authored-by: Roflmuffin <shortguy014@gmail.com>
2024-04-01 18:04:12 +10:00
Roflmuffin
ab211a42e6 [skip ci] chore: update ApiCompat to v202, disable suppression file 2024-03-26 12:46:42 +10:00
Roflmuffin
696ecadee4 fix: bad vector math 2024-03-26 12:16:53 +10:00
12 changed files with 111 additions and 1147 deletions

View File

@@ -1,6 +1,6 @@
# CounterStrikeSharp
CounterStrikeSharp is a server side modding framework for Counter-Strike: Global Offensive. This project attempts to implement a .NET Core scripting layer on top of a Metamod Source Plugin, allowing developers to create plugins that interact with the game server in a modern language (C#) to facilitate the creation of maintainable and testable code.
CounterStrikeSharp is a server side modding framework for Counter-Strike 2. This project implements a .NET 8 scripting layer on top of a Metamod Source Plugin, allowing developers to create plugins that interact with the game server in a modern language (C#) to facilitate the creation of maintainable and testable code.
[Come and join our Discord](https://discord.gg/eAZU3guKWU)
@@ -18,14 +18,12 @@ Detailed installation instructions can be found in the [docs](https://docs.cssha
## What works?
_(Note, these were features in the previous VSP.NET project, but have not been implemented yet in this project)_
These features are the core of the platform and work pretty well/have a low risk of causing issues.
- [x] Console Commands, Server Commands (e.g. css_mycommand)
- [x] Chat Commands with `!` and `/` prefixes (e.g. !mycommand)
- [ ] **(In Progress)** Console Variables
- [x] Game Event Handlers & Custom Events (e.g. player_death)
- [x] Fake Console Variables (commands which mimic ConVar behaviour as these have not been fully reverse engineered)
- [x] Game Event Handlers & Firing of Events (e.g. player_death)
- [x] Basic event value get/set (string, bool, int32, float)
- [x] Complex event values get/set (ehandle, pawn, player controller)
- [x] Game Tick Based Timers (e.g. repeating map timers)
@@ -34,7 +32,7 @@ These features are the core of the platform and work pretty well/have a low risk
- [x] Client Listeners (e.g. connect, disconnect, put in server)
- [x] OnMapStart
- [x] OnTick
- [x] Server Information (current map, game time, tick rate, model precaching)
- [x] Server Information (current map, game time)
- [x] Schema System Access (access player values like current weapon, money, location etc.)
## Links

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@@ -7,7 +7,6 @@
<EnablePackageValidation>true</EnablePackageValidation>
<NoWarn>$(NoWarn);CS1591;CP0003</NoWarn>
<Nullable>enable</Nullable>
<GenerateCompatibilitySuppressionFile>true</GenerateCompatibilitySuppressionFile>
<Authors>Roflmuffin</Authors>
<Description>Official server side runtime assembly for CounterStrikeSharp</Description>
<PackageProjectUrl>http://docs.cssharp.dev/</PackageProjectUrl>
@@ -21,7 +20,7 @@
</PropertyGroup>
<PropertyGroup>
<ApiCompatValidateAssemblies>true</ApiCompatValidateAssemblies>
<ApiCompatContractAssembly>.\ApiCompat\v151.dll</ApiCompatContractAssembly>
<ApiCompatContractAssembly>.\ApiCompat\v202.dll</ApiCompatContractAssembly>
</PropertyGroup>
<ItemGroup>
<None Remove="Modules\Commands\CommandInfo"/>

View File

@@ -28,23 +28,35 @@ public enum PostSelectAction
public abstract class BaseMenu : IMenu
{
public string Title { get; set; }
public List<ChatMenuOption> MenuOptions { get; } = new();
public PostSelectAction PostSelectAction { get; set; } = PostSelectAction.Reset;
public bool ExitButton { get; set; } = true;
protected BaseMenu(string title)
{
Title = title;
}
public virtual ChatMenuOption AddMenuOption(string display, Action<CCSPlayerController, ChatMenuOption> onSelect, bool disabled = false)
public virtual ChatMenuOption AddMenuOption(string display, Action<CCSPlayerController, ChatMenuOption> onSelect,
bool disabled = false)
{
var option = new ChatMenuOption(display, disabled, onSelect);
MenuOptions.Add(option);
return option;
}
public abstract void Open(CCSPlayerController player);
public void OpenToAll()
{
foreach (var player in Utilities.GetPlayers())
{
Open(player);
}
}
}
// This must be called ChatMenuOption to maintain backwards compatibility with the old API
public class ChatMenuOption
{
@@ -114,7 +126,7 @@ public abstract class BaseMenuInstance : IMenuInstance
if (menuItemIndex >= 0 && menuItemIndex < Menu.MenuOptions.Count)
{
var menuOption = Menu.MenuOptions[menuItemIndex];
if (!menuOption.Disabled)
{
menuOption.OnSelect(Player, menuOption);
@@ -142,7 +154,7 @@ public abstract class BaseMenuInstance : IMenuInstance
Page = 0;
PrevPageOffsets.Clear();
}
public virtual void Close()
{
MenuManager.CloseActiveMenu(Player);

View File

@@ -21,10 +21,35 @@ namespace CounterStrikeSharp.API.Modules.Menu;
public class CenterHtmlMenu : BaseMenu
{
private readonly BasePlugin? _plugin;
public string TitleColor { get; set; } = "yellow";
public string EnabledColor { get; set; } = "green";
public string DisabledColor { get; set; } = "grey";
public string PrevPageColor { get; set; } = "yellow";
public string NextPageColor { get; set; } = "yellow";
public string CloseColor { get; set; } = "red";
public CenterHtmlMenu(string title, BasePlugin plugin) : base(ModifyTitle(title))
{
_plugin = plugin;
}
[Obsolete("Use the constructor that takes a BasePlugin")]
public CenterHtmlMenu(string title) : base(ModifyTitle(title))
{
}
public override void Open(CCSPlayerController player)
{
if (_plugin == null)
{
throw new InvalidOperationException("This method is unsupported with the CenterHtmlMenu constructor used." +
"Please provide a BasePlugin in the constructor.");
};
MenuManager.OpenCenterHtmlMenu(_plugin, player, this);
}
public override ChatMenuOption AddMenuOption(string display, Action<CCSPlayerController, ChatMenuOption> onSelect,
bool disabled = false)
{
@@ -77,35 +102,40 @@ public class CenterHtmlMenuInstance : BaseMenuInstance
return;
}
if (Menu is not CenterHtmlMenu centerHtmlMenu)
{
return;
}
var builder = new StringBuilder();
builder.Append($"<b><font color='yellow'>{Menu.Title}</font></b>");
builder.Append($"<b><font color='{centerHtmlMenu.TitleColor}'>{centerHtmlMenu.Title}</font></b>");
builder.AppendLine("<br>");
var keyOffset = 1;
for (var i = CurrentOffset; i < Math.Min(CurrentOffset + MenuItemsPerPage, Menu.MenuOptions.Count); i++)
for (var i = CurrentOffset; i < Math.Min(CurrentOffset + MenuItemsPerPage, centerHtmlMenu.MenuOptions.Count); i++)
{
var option = Menu.MenuOptions[i];
string color = option.Disabled ? "grey" : "green";
var option = centerHtmlMenu.MenuOptions[i];
string color = option.Disabled ? centerHtmlMenu.DisabledColor : centerHtmlMenu.EnabledColor;
builder.Append($"<font color='{color}'>!{keyOffset++}</font> {option.Text}");
builder.AppendLine("<br>");
}
if (HasPrevButton)
{
builder.AppendFormat("<font color='yellow'>!7</font> &#60;- Prev");
builder.AppendFormat($"<font color='{centerHtmlMenu.PrevPageColor}'>!7</font> &#60;- Prev");
builder.AppendLine("<br>");
}
if (HasNextButton)
{
builder.AppendFormat("<font color='yellow'>!8</font> -> Next");
builder.AppendFormat($"<font color='{centerHtmlMenu.NextPageColor}'>!8</font> -> Next");
builder.AppendLine("<br>");
}
if (Menu.ExitButton)
if (centerHtmlMenu.ExitButton)
{
builder.AppendFormat("<font color='red'>!9</font> -> Close");
builder.AppendFormat($"<font color='{centerHtmlMenu.CloseColor}'>!9</font> -> Close");
builder.AppendLine("<br>");
}

View File

@@ -20,10 +20,21 @@ namespace CounterStrikeSharp.API.Modules.Menu;
public class ChatMenu : BaseMenu
{
public char TitleColor { get; set; } = ChatColors.Yellow;
public char EnabledColor { get; set; } = ChatColors.Green;
public char DisabledColor { get; set; } = ChatColors.Grey;
public char PrevPageColor { get; set; } = ChatColors.Yellow;
public char NextPageColor { get; set; } = ChatColors.Yellow;
public char CloseColor { get; set; } = ChatColors.Red;
public ChatMenu(string title) : base(title)
{
ExitButton = false;
}
public override void Open(CCSPlayerController player)
{
MenuManager.OpenChatMenu(player, this);
}
}
public class ChatMenuInstance : BaseMenuInstance
@@ -34,30 +45,35 @@ public class ChatMenuInstance : BaseMenuInstance
public override void Display()
{
Player.PrintToChat(Menu.Title);
if (Menu is not ChatMenu chatMenu)
{
return;
}
Player.PrintToChat($" {chatMenu.TitleColor} {chatMenu.Title}");
Player.PrintToChat("---");
var keyOffset = 1;
for (var i = CurrentOffset; i < Math.Min(CurrentOffset + MenuItemsPerPage, Menu.MenuOptions.Count); i++)
{
var option = Menu.MenuOptions[i];
Player.PrintToChat($" {(option.Disabled ? ChatColors.Grey : ChatColors.Green)} !{keyOffset++} {ChatColors.Default}{option.Text}");
char color = option.Disabled ? chatMenu.DisabledColor : chatMenu.EnabledColor;
Player.PrintToChat($" {color} !{keyOffset++} {ChatColors.Default}{option.Text}");
}
if (HasPrevButton)
{
Player.PrintToChat($" {ChatColors.Yellow}!7 {ChatColors.Default}-> Prev");
Player.PrintToChat($" {chatMenu.PrevPageColor}!7 {ChatColors.Default}-> Prev");
}
if (HasNextButton)
{
Player.PrintToChat($" {ChatColors.Yellow}!8 {ChatColors.Default}-> Next");
Player.PrintToChat($" {chatMenu.NextPageColor}!8 {ChatColors.Default}-> Next");
}
if (Menu.ExitButton)
{
Player.PrintToChat($" {ChatColors.Red}!9 {ChatColors.Default}-> Close");
Player.PrintToChat($" {chatMenu.CloseColor}!9 {ChatColors.Default}-> Close");
}
}
}

View File

@@ -21,6 +21,11 @@ public class ConsoleMenu : BaseMenu
public ConsoleMenu(string title) : base(title)
{
}
public override void Open(CCSPlayerController player)
{
MenuManager.OpenConsoleMenu(player, this);
}
}
public class ConsoleMenuInstance : BaseMenuInstance

View File

@@ -20,16 +20,18 @@ namespace CounterStrikeSharp.API.Modules.Menu;
public interface IMenu
{
public string Title { get; set; }
public List<ChatMenuOption> MenuOptions { get; }
public PostSelectAction PostSelectAction
string Title { get; set; }
List<ChatMenuOption> MenuOptions { get; }
PostSelectAction PostSelectAction
{
get { throw new NotImplementedException(); }
set { throw new NotImplementedException(); }
}
public bool ExitButton { get; set; }
bool ExitButton { get; set; }
public ChatMenuOption AddMenuOption(string display, Action<CCSPlayerController, ChatMenuOption> onSelect, bool disabled = false);
ChatMenuOption AddMenuOption(string display, Action<CCSPlayerController, ChatMenuOption> onSelect, bool disabled = false);
void Open(CCSPlayerController player);
void OpenToAll();
}
public interface IMenuInstance

View File

@@ -41,7 +41,7 @@ public static class MenuManager
ActiveMenus.Remove(player.Handle);
}
public static void OpenChatMenu(CCSPlayerController player, ChatMenu menu)
{
CloseActiveMenu(player);
@@ -49,7 +49,7 @@ public static class MenuManager
ActiveMenus[player.Handle] = new ChatMenuInstance(player, menu);
ActiveMenus[player.Handle].Display();
}
public static void OpenCenterHtmlMenu(BasePlugin plugin, CCSPlayerController player, CenterHtmlMenu menu)
{
CloseActiveMenu(player);
@@ -57,7 +57,7 @@ public static class MenuManager
ActiveMenus[player.Handle] = new CenterHtmlMenuInstance(plugin, player, menu);
ActiveMenus[player.Handle].Display();
}
public static void OpenConsoleMenu(CCSPlayerController player, ConsoleMenu menu)
{
CloseActiveMenu(player);

View File

@@ -1,4 +1,4 @@
/*
/*
* This file is part of CounterStrikeSharp.
* CounterStrikeSharp is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -75,7 +75,7 @@ namespace CounterStrikeSharp.API.Modules.Utils
{
this.X += vector.X;
this.Y += vector.Y;
this.Z = this.Z = vector.Z;
this.Z += vector.Z;
}