VoltMod
C++23 framework for CS2 server plugins
Loading...
Searching...
No Matches
MenuRouter.hpp
Go to the documentation of this file.
1#pragma once
2
5#include <functional>
6#include <memory>
7#include <string>
8#include <string_view>
9
10namespace VoltMod
11{
12
13/**
14 * @brief `runtime.Menus`: the surface menus start on, chosen once per session.
15 *
16 * A session starts on the preferred surface when it can draw for the player, and on the fallback
17 * otherwise. Every later call follows the surface holding that player's session, and a player has
18 * one session across both. Rows and flows are built against this, so they never pick a surface
19 * themselves. SDK-free.
20 */
22{
23public:
24 /** @p fallback takes every session no preferred surface does, and must outlive this. */
26
27 /** Try @p surface first for new sessions while the returned Subscription is held; hold it no
28 * longer than @p surface lives. A later call replaces the preference. */
30
31 bool OpenSession(int slot, std::shared_ptr<Menu> menu, MenuOptions options) override;
32 void Open(int slot, std::shared_ptr<Menu> menu) override;
33 bool IsOpen(int slot) const override;
34 void Close(int slot) override;
35 void CloseAll(int slot) override;
36 void CloseAll(int slot, std::string_view replyKey) override;
37 void Prompt(int slot, std::string prompt, std::function<bool(int slot, std::string_view text)> callback) override;
38 std::string Translate(int slot, std::string_view key, std::string_view fallback) const override;
39
40private:
41 /** The surface holding @p slot's session; the fallback when there is none. */
42 MenuSurface& SessionOf(int slot) const;
43
44 MenuSurface& _fallback;
45 MenuSurface* _preferred = nullptr;
46};
47
48} // namespace VoltMod
runtime.Menus: the surface menus start on, chosen once per session.
bool OpenSession(int slot, std::shared_ptr< Menu > menu, MenuOptions options) override
void CloseAll(int slot) override
Subscription Prefer(MenuSurface &surface)
Definition MenuRouter.cpp:9
bool IsOpen(int slot) const override
void Open(int slot, std::shared_ptr< Menu > menu) override
void Prompt(int slot, std::string prompt, std::function< bool(int slot, std::string_view text)> callback) override
std::string Translate(int slot, std::string_view key, std::string_view fallback) const override
Owns one registration and releases it on destruction.
static std::string ReadFile(const std::filesystem::path &path)
Definition Loader.cpp:56