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
12#include <VoltMod/Ui/Screen.hpp>
13#include <functional>
14#include <string_view>
15#include <vector>
16
17namespace VoltMod
18{
19
20/**
21 * @brief Create @ref Screen objects and report their button presses.
22 *
23 * Every screen belongs to one player: a screen everyone received would send each player's state to
24 * every client. @p layout must be a bare name (`"welcome"`) or a resource name under
25 * `panorama/layout/custom_game/` with its source `.xml` extension. Other forms are rejected before
26 * reaching the client.
27 */
29{
30public:
31 /** Subscribes a ScreenManager to the host's button presses; dropping the result unsubscribes. */
32 using Connector = std::function<Subscription(ScreenManager&)>;
33
34 /** The services must outlive this one; @p connect runs when the first press handler arrives. */
35 ScreenManager(EntitySystem& entities, const Bindings& bindings, SlotEvents& slots, Visibility& visibility,
36 const NetChannels& clients, Connector connect);
37
38 ScreenManager(const ScreenManager&) = delete;
40
41 /** Return the reason screens are unavailable, or success when all required bindings exist. */
42 Status Available() const;
43
44 /** A screen only @p slot receives, removed when the slot changes hands. Spawned on its first
45 * @ref Screen::EnsureSpawned. */
46 Result<Screen> Create(std::string_view layout, int slot);
47
48 /** Whether any of @p slot's screens shows the cursor, so the player's clicks and keys go to it. */
49 bool HasCursor(int slot) const;
50
51 /** Every button press from every layout; filter on @ref ButtonPress::ButtonId. A subscription is
52 * refused when the client filter table did not bind. */
54
55 /** @internal A press the host read, on the frame after it arrived. */
56 void OnPress(int slot, std::string_view buttonId);
57
58private:
59 bool WatchPresses();
60
61 EntitySystem& _entities;
62 const Bindings& _bindings;
63 SlotEvents& _slots;
64 Visibility& _visibility;
65 const NetChannels& _clients;
66 Connector _connect;
67 /** Every screen entity this created that still exists. */
68 std::vector<const ScreenEntity*> _live;
69 /** Declared after @ref Pressed: unsubscribes before the event goes. */
70 Subscription _host;
71};
72
73} // 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
Per-client network access: latency, userids, usercmd status and the client's replicated userinfo cvar...
bool HasCursor(int slot) const
ScreenManager & operator=(const ScreenManager &)=delete
ScreenManager(EntitySystem &entities, const Bindings &bindings, SlotEvents &slots, Visibility &visibility, const NetChannels &clients, Connector connect)
ScreenManager(const ScreenManager &)=delete
Event< const ButtonPress & > Pressed
void OnPress(int slot, std::string_view buttonId)
std::function< Subscription(ScreenManager &)> Connector
Result< Screen > Create(std::string_view layout, int slot)
"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.
std::expected< void, Error > Status
Definition Result.hpp:67
std::expected< T, Error > Result
Definition Result.hpp:64