VoltMod
C++23 framework for CS2 server plugins
Loading...
Searching...
No Matches
Screen.hpp
Go to the documentation of this file.
1#pragma once
2
4#include <memory>
5#include <span>
6#include <string_view>
7
8namespace VoltMod
9{
10
11/**
12 * @brief A spawned Panorama layout created by @ref ScreenManager.
13 *
14 * A screen is networked only to its owner and remains visible while the owner is dead or spectating.
15 * Writes name the owner or @ref EveryoneSlot, which mean the same; any other slot is ignored.
16 *
17 * Writes do not spawn the entity. Call @ref EnsureSpawned before drawing; it also respawns after a
18 * map change. Unchanged values are not resent, and a failed write is logged once and retried on the
19 * next change. Destruction removes the entity. Operations are inert unless
20 * @ref ScreenManager::Available succeeds.
21 */
22class Screen
23{
24public:
25 /** Construct an empty screen. Writes do nothing until an entity is assigned. */
28
29 Screen(Screen&&) noexcept;
30 /** Replace the entity, removing the one previously held by this screen. */
31 Screen& operator=(Screen&&) noexcept;
32 Screen(const Screen&) = delete;
33 Screen& operator=(const Screen&) = delete;
34
35 explicit operator bool() const;
36
37 /** Spawn or respawn until @p slot can be written to. False logs why once per attempt. */
38 bool EnsureSpawned(int slot);
39
40 /** Set the text a `text="{s:variable}"` Label shows, for @p slot or @ref EveryoneSlot. */
41 void SetText(int slot, std::string_view variable, std::string_view value);
42
43 void SetClass(int slot, std::string_view elementId, std::string_view className, bool on);
44
45 void SetHidden(int slot, std::string_view elementId, bool hidden);
46
47 /** Turn `<block>--<name>` on for @p elementId and every other of @p names off, such as an icon
48 * set's shown icon or a bar's step. Only changes are sent, so these classes come from here alone,
49 * never from the markup or @ref SetClass. @p names is the generated header's `IconSetNames` or `BarNames`. */
50 void SetModifier(int slot, std::string_view elementId, std::string_view block,
51 std::span<const std::string_view> names, std::string_view name);
52
53 void ShowCursor(int slot, bool shown);
54
55 /** Whether @ref ShowCursor last showed the cursor and the entity is still there. */
56 bool HasCursor() const;
57
58 /** Remove the entity now. The next @ref EnsureSpawned creates a new one. */
59 void Remove();
60
61private:
62 friend class ScreenManager;
63
64 explicit Screen(std::unique_ptr<ScreenEntity> entity);
65
66 std::unique_ptr<ScreenEntity> _entity;
67};
68
69} // namespace VoltMod
The custom_hud_layout entity behind a Screen: spawning, removal, and every write.
void ShowCursor(int slot, bool shown)
Definition Screen.cpp:64
bool HasCursor() const
Definition Screen.cpp:59
void SetHidden(int slot, std::string_view elementId, bool hidden)
Definition Screen.cpp:45
void SetModifier(int slot, std::string_view elementId, std::string_view block, std::span< const std::string_view > names, std::string_view name)
Definition Screen.cpp:50
bool EnsureSpawned(int slot)
Definition Screen.cpp:24
void Remove()
Definition Screen.cpp:72
void SetClass(int slot, std::string_view elementId, std::string_view className, bool on)
Definition Screen.cpp:37
friend class ScreenManager
Definition Screen.hpp:62
void SetText(int slot, std::string_view variable, std::string_view value)
Definition Screen.cpp:29
Screen(Screen &&) noexcept