VoltMod
C++23 framework for CS2 server plugins
Loading...
Searching...
No Matches
ScreenManager.hpp
Go to the documentation of this file.
1#pragma once
2
11#include <VoltMod/Ui/Screen.hpp>
12#include <functional>
13#include <string_view>
14
15namespace VoltMod
16{
17
18/**
19 * @brief Create @ref Screen objects and report their button presses.
20 *
21 * @p layout must be a bare name (`"welcome"`) or a resource name under
22 * `panorama/layout/custom_game/` with its source `.xml` extension. Other forms are rejected before
23 * reaching the client.
24 */
26{
27public:
28 /** Subscribes a ScreenManager to the host's button presses; dropping the result unsubscribes. */
29 using Connector = std::function<Subscription(ScreenManager&)>;
30
31 /** The services must outlive this one; @p connect runs when the first press handler arrives. */
34
35 ScreenManager(const ScreenManager&) = delete;
37
38 /** Return the reason screens are unavailable, or success when all required bindings exist. */
39 Status Available() const;
40
41 /** A screen every player receives. Spawned on its first @ref Screen::EnsureSpawned. */
42 Result<Screen> Shared(std::string_view layout);
43
44 /**
45 * A screen only @p slot receives, removed when the slot changes hands. This requires
46 * @ref Visibility::Available because otherwise the entity would reach everyone.
47 */
48 Result<Screen> ForPlayer(std::string_view layout, int slot);
49
50 /** Every button press from every layout; filter on @ref ButtonPress::ButtonId. A subscription is
51 * refused when the FilterMessage bindings are missing. */
53
54 /** @internal A press the host read, on the frame after it arrived. */
55 void OnPress(int slot, std::string_view buttonId);
56
57private:
58 Result<Screen> Create(std::string_view layout, int owner);
59 bool ListenForPresses();
60
61 EntitySystem& _entities;
62 const Bindings& _bindings;
63 SlotEvents& _slots;
64 Visibility& _visibility;
65 Connector _connect;
66 /** Declared after @ref Pressed: unsubscribes before the event goes. */
67 Subscription _host;
68};
69
70} // namespace VoltMod
runtime.Entities: finds and creates entities. Everything it returns is valid for this frame only; see...
A multicast signal with a fixed handler signature: the one way to subscribe in VoltMod.
Definition Event.hpp:54
Create Screen objects and report their button presses.
Result< Screen > Shared(std::string_view layout)
ScreenManager & operator=(const ScreenManager &)=delete
ScreenManager(const ScreenManager &)=delete
Event< const ButtonPress & > Pressed
Result< Screen > ForPlayer(std::string_view layout, int slot)
void OnPress(int slot, std::string_view buttonId)
std::function< Subscription(ScreenManager &)> Connector
"The occupant of this slot changed" - raised by PlayerManager, consumed below it.
Owns one registration and releases it on destruction.
Which clients receive which entities, filtered after CheckTransmit.
static std::string ReadFile(const std::filesystem::path &path)
Definition Loader.cpp:56
std::expected< void, Error > Status
Definition Result.hpp:67
std::expected< T, Error > Result
Definition Result.hpp:64