VoltMod
C++23 framework for CS2 server plugins
Loading...
Searching...
No Matches
ScreenManager.cpp
Go to the documentation of this file.
1#include "Ui/LayoutPath.hpp"
2#include "Ui/ScreenEntity.hpp"
3
7#include <algorithm>
8#include <format>
9#include <string>
10#include <string_view>
11#include <utility>
12
13namespace VoltMod
14{
15
17 Visibility& visibility, const NetChannels& clients, Connector connect)
18 : Pressed({.OnFirst = [this] { return WatchPresses(); }, .OnLast = [this] { _host.Reset(); }}),
19 _entities(entities),
20 _bindings(bindings),
21 _slots(slots),
22 _visibility(visibility),
23 _clients(clients),
24 _connect(std::move(connect))
25{}
26
27bool ScreenManager::WatchPresses()
28{
29 if (!_bindings.ClientFilterTable)
30 {
31 Log::Warn("Screens: the client filter table did not bind; button presses will not arrive.");
32 return false;
33 }
34 _host = _connect(*this);
35 return true;
36}
37
38void ScreenManager::OnPress(int slot, std::string_view buttonId)
39{
40 Pressed.Raise({.Slot = slot, .ButtonId = std::string(buttonId)});
41}
42
43Result<Screen> ScreenManager::Create(std::string_view layout, int slot)
44{
45 if (!IsValidSlot(slot))
46 {
47 return std::unexpected(Error::Invalid(std::format("slot {} is not a player slot", slot)));
48 }
49
50 auto path = LayoutPath::Parse(layout);
51 if (!path)
52 {
53 return std::unexpected(path.error());
54 }
55
56 return Screen(
57 std::make_unique<ScreenEntity>(_entities, _slots, _visibility, _clients, _live, std::move(*path), slot));
58}
59
60bool ScreenManager::HasCursor(int slot) const
61{
62 return std::ranges::any_of(
63 _live, [slot](const ScreenEntity* screen) { return screen->Owner() == slot && screen->HasCursor(); });
64}
65
67{
68 const std::pair<bool, std::string_view> needed[] = {
69 {static_cast<bool>(_bindings.CustomHudSetHasClass), "CCSCustomHudLayout::SetHasClass"},
70 {static_cast<bool>(_bindings.CustomHudSetDialogVariable), "CCSCustomHudLayout::SetDialogVariableString"},
71 {static_cast<bool>(_bindings.CustomHudSetInputCapture), "CCSCustomHudLayout::SetInputCaptureEnabled"},
72 {static_cast<bool>(_bindings.ClientFilterTable), "CServerSideClient::INetworkMessageProcessingPreFilter"},
73 };
74 for (const auto& [bound, key] : needed)
75 {
76 if (!bound)
77 {
78 return std::unexpected(Error::Unsupported(std::format("gamedata '{}' did not bind", key)));
79 }
80 }
81 return {};
82}
83
84} // namespace VoltMod
runtime.Entities: finds and creates entities. Everything it returns is valid for this frame only; see...
static Result< LayoutPath > Parse(std::string_view layout)
Per-client network access: latency, userids, usercmd status and the client's replicated userinfo cvar...
The custom_hud_layout entity behind a Screen: spawning, removal, and every write.
int Owner() const noexcept
bool HasCursor(int slot) const
ScreenManager(EntitySystem &entities, const Bindings &bindings, SlotEvents &slots, Visibility &visibility, const NetChannels &clients, Connector connect)
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)
A spawned Panorama layout created by ScreenManager.
Definition Screen.hpp:23
"The occupant of this slot changed" - raised by PlayerManager, consumed below it.
Which clients receive which entities, filtered after CheckTransmit.
void Warn(std::format_string< Args... > fmt, Args &&... args)
Definition Log.hpp:88
std::expected< void, Error > Status
Definition Result.hpp:67
std::expected< T, Error > Result
Definition Result.hpp:64
constexpr bool IsValidSlot(int slot)
Definition Slot.hpp:13
ClassTable ClientFilterTable
Definition Bindings.hpp:64
static Error Invalid(std::string detail)
Definition Result.hpp:51
static Error Unsupported(std::string detail)
Definition Result.hpp:57