Skip to content

Commit d218207

Browse files
committed
Added sample to demonstrate usage
1 parent 9eff791 commit d218207

File tree

5 files changed

+87
-0
lines changed

5 files changed

+87
-0
lines changed

samples/HelloMenu/HelloMenu.cs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
using System;
2+
3+
using CounterStrikeSharp.API.Core;
4+
using CounterStrikeSharp.API.Core.Attributes;
5+
using CounterStrikeSharp.API.Core.Attributes.Registration;
6+
using CounterStrikeSharp.API.Modules.Commands;
7+
8+
using CSSUniversalMenuAPI;
9+
10+
namespace HelloMenu;
11+
12+
[MinimumApiVersion(314)]
13+
public sealed class TeamDeathmatchPlugin : BasePlugin
14+
{
15+
public override string ModuleName => "CsGals.TeamDeathmatch";
16+
public override string ModuleDescription => "Team Deathmatch gamemode plugin";
17+
public override string ModuleVersion => Verlite.Version.Full;
18+
19+
20+
[ConsoleCommand("css_hello")]
21+
public void HelloMenu(CCSPlayerController player, CommandInfo info)
22+
{
23+
var menu = UniversalMenu.CreateMenu(player);
24+
menu.Title = "Hello";
25+
26+
var playerItem = menu.CreateItem();
27+
playerItem.Title = "Player";
28+
playerItem.Selected += PlayerItem_Selected;
29+
30+
var aboutItem = menu.CreateItem();
31+
aboutItem.Title = "About";
32+
aboutItem.Selected += AboutItem_Selected;
33+
34+
menu.Display();
35+
}
36+
37+
private void PlayerItem_Selected(IMenuItem menuItem)
38+
{
39+
var player = menuItem.Menu.Player;
40+
player.PrintToChat($"Hello {player.PlayerName}");
41+
42+
// close does not happen implicitly, you need to tell it to close
43+
menuItem.Menu.Close();
44+
}
45+
46+
private void AboutItem_Selected(IMenuItem menuItem)
47+
{
48+
var childMenu = UniversalMenu.CreateMenu(menuItem.Menu);
49+
50+
var authorItem = childMenu.CreateItem();
51+
authorItem.Title = $"Author: Ashleigh Adams";
52+
authorItem.Enabled = false;
53+
54+
var versionItem = childMenu.CreateItem();
55+
versionItem.Title = $"Version: {Verlite.Version.Full}";
56+
versionItem.Enabled = false;
57+
58+
var revItem = childMenu.CreateItem();
59+
revItem.Title = $"Revision: {Verlite.Version.Commit[..8]}";
60+
revItem.Enabled = false;
61+
62+
childMenu.Display();
63+
}
64+
}

samples/HelloMenu/HelloMenu.csproj

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
</PropertyGroup>
5+
6+
<ItemGroup>
7+
<PackageReference Include="CSSUniversalMenuApi" Version="0.4.0" ExcludeAssets="runtime" />
8+
</ItemGroup>
9+
10+
</Project>

samples/HelloMenu/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Menu usage sample
2+
3+
Example menu showing usage of CSSUniversalMenuAPI
4+
5+
![](docs/MainMenu.png)
6+
![](docs/ChildMenu.png)
7+
8+
## Build instructions
9+
10+
```sh
11+
dotnet publish -c Release -o artifacts/HelloMenu
12+
```
13+
127 KB
Loading
102 KB
Loading

0 commit comments

Comments
 (0)