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
3
#include <
VoltMod/Core/Signals/Subscription.hpp
>
4
#include <
VoltMod/Menu/MenuModel.hpp
>
5
#include <functional>
6
#include <memory>
7
#include <string>
8
#include <string_view>
9
10
namespace
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
*/
21
class
MenuRouter
final
:
public
MenuSurface
22
{
23
public
:
24
/** @p fallback takes every session no preferred surface does, and must outlive this. */
25
explicit
MenuRouter
(
MenuSurface
&
fallback
);
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. */
29
[[
nodiscard
]]
Subscription
Prefer
(
MenuSurface
&
surface
);
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
40
private
:
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
MenuModel.hpp
Subscription.hpp
VoltMod::MenuRouter
runtime.Menus: the surface menus start on, chosen once per session.
Definition
MenuRouter.hpp:22
VoltMod::MenuRouter::OpenSession
bool OpenSession(int slot, std::shared_ptr< Menu > menu, MenuOptions options) override
Definition
MenuRouter.cpp:21
VoltMod::MenuRouter::CloseAll
void CloseAll(int slot) override
Definition
MenuRouter.cpp:58
VoltMod::MenuRouter::Prefer
Subscription Prefer(MenuSurface &surface)
Definition
MenuRouter.cpp:9
VoltMod::MenuRouter::IsOpen
bool IsOpen(int slot) const override
Definition
MenuRouter.cpp:48
VoltMod::MenuRouter::Open
void Open(int slot, std::shared_ptr< Menu > menu) override
Definition
MenuRouter.cpp:37
VoltMod::MenuRouter::Prompt
void Prompt(int slot, std::string prompt, std::function< bool(int slot, std::string_view text)> callback) override
Definition
MenuRouter.cpp:68
VoltMod::MenuRouter::Translate
std::string Translate(int slot, std::string_view key, std::string_view fallback) const override
Definition
MenuRouter.cpp:73
VoltMod::MenuSurface
Definition
MenuModel.hpp:73
VoltMod::Subscription
Owns one registration and releases it on destruction.
Definition
Subscription.hpp:34
VoltMod
Definition
Options.hpp:13
VoltMod::MenuButtonKind::Close
@ Close
VoltMod::ReadFile
static std::string ReadFile(const std::filesystem::path &path)
Definition
Loader.cpp:56
VoltMod::MenuOptions
Definition
MenuModel.hpp:61
include
VoltMod
Menu
MenuRouter.hpp
Generated by
1.9.8