Skip to content

About

A Metamod:Source plugin that provides a shared menu API for CS2.

Topics

Resources

Stars

6 stars

Watchers

1 watching

Forks

Latest commit

 

History

266 Commits

Folders and files

Repository files navigation

CS2 Menu API

Downloads Last commit Open issues Closed issues Size GitHub Workflow Status

A Metamod:Source plugin that provides a shared menu API for CS2.

It owns player input and rendering so other Metamod plugins can create interactive menus without each one reimplementing chat parsing, HTML rendering, and pagination.

Menu types

Type Render Navigation
Chat Numbered list printed to chat Type an item number, 0 exits, page keys follow items
HTML Center-screen panel Movement keys - W/S move, D select, A exit by default (configurable)
Panorama Menu window from the workshop addon Mouse clicks

Pass MenuType::Default to use the server's configured default style.

For commands see: COMMANDS.md.

Plugins that support this library

Usage

Dependencies

Installation

  1. Download the latest release.
  2. Extract the downloaded .zip file into your server's root folder (~/game/csgo/).
  3. (Optional) If you use CounterStrikeSharp and/or SwiftlyS2, you might want to install the bridge plugins.

Note

On its own, this plugin does nothing visible, it's a library other plugins use.

Configuration

cfg/cs2menus/core.cfg, reloaded automatically on every map change. Every key is explained in the file.

Section What it sets
General Chat prefixes accepted in front of a menu selection number
Menu Default menu type and language, logging, then the chat menus' and the HTML menus' looks and keys
Panorama The workshop addon's ID and whether MultiAddonManager mounts it, the window's font, colors and sounds
Database Per-player preferences (menu type, HTML keys) through sql_mm, off by default

Panorama menus need the workshop addon on the clients, so the server has to mount it: with MultiAddonManager loaded and MountAddon on, cs2menus does that itself. Without the addon they fall back to HTML menus.

API

Acquire the interface via Metamod's factory:

#include "ics2menus.h"

ICS2Menus *g_pMenus = nullptr;

void AcquireMenus() {
    g_pMenus = (ICS2Menus *)g_SMAPI->MetaFactory(CS2MENUS_INTERFACE, nullptr, nullptr);
}

Re-resolve it from IMetamodListener::OnPluginLoad / OnPluginUnload so you never hold a dangling pointer.

Example

MenuHandle m = g_pMenus->CreateMenu(MenuType::Default, "\x04Pick a map",
    [](MenuHandle menu, int slot, int item) {
        const char *info = g_pMenus->GetItemInfo(menu, item); // e.g. "de_dust2"
        // ... act on the selection
    });

g_pMenus->AddItem(m, "Dust II", "de_dust2", false);
g_pMenus->AddItem(m, "Mirage",  "de_mirage", false);
g_pMenus->AddItem(m, "Coming soon", "", /*disabled*/ true);

// One-shot: free the menu when the player's display ends.
g_pMenus->SetMenuEndCallback(m, [](MenuHandle menu, int slot, MenuEndReason reason) {
    g_pMenus->DestroyMenu(menu);
});

// HTML-only: override nav keys for this menu (no-op for chat menus).
g_pMenus->SetMenuKey(m, MenuNavAction::Select, MenuButton::Use);   // E selects
g_pMenus->SetMenuKey(m, MenuNavAction::Back,   MenuButton::Speed); // Shift backs out

g_pMenus->DisplayMenu(m, slot, 20.0f); // show to one player, 20s timeout (0 = none)

The full surface is documented in ics2menus.h, which lives in mm-utils with a menus_client.h helper that does the acquiring above.

Past plain lists it has value items (toggles, steppers, choices), sections, per-menu styling, a history with a back arrow, and for Panorama the grid, showcase, studio, columns and table layouts with tile badges, tabs, chips, an info card, typed input, a message line, a confirm dialog and notices. Each of those falls back to a list on chat and HTML menus.

SwiftlyS2 and CounterStrikeSharp

CS2Menus supports both platforms via bridges.

Build

Prerequisites

  • This repository is cloned recursively (ie. has submodules)
  • python3
  • ambuild, make sure ambuild command is available via the PATH environment variable;
  • MSVC (VS build tools)/Clang installed for Windows/Linux.

AMBuild

mkdir -p build && cd build
python3 ../configure.py --enable-optimize
ambuild

Docker

docker compose run --rm build

Credits

Contributing

Feel free to create PRs or issues regarding anything, but keep in mind that this is very much just for fkz and I won't spend time adding features I won't use.

About

A Metamod:Source plugin that provides a shared menu API for CS2.

Topics

Resources

Stars

6 stars

Watchers

1 watching

Forks

Releases

Sponsor this project

Contributors

Languages