VoltMod
C++23 framework for CS2 server plugins
Loading...
Searching...
No Matches
MenuFreeze.cpp
Go to the documentation of this file.
3
4namespace VoltMod
5{
6
10
12{
13 _enabled = enabled;
14
15 // Turning it off releases whoever the previous setting already froze; leaving them stuck
16 // until they close a menu they may not know is open is not a defensible reading of "off".
17 // Turning it on catches up the sessions that were already open.
18 if (!enabled)
19 {
20 for (int slot = 0; slot < MaxPlayers; ++slot)
21 {
22 _states[slot].Movement.Release(_entities.Pawn(slot));
23 }
24 }
25
26 SyncFrameWork();
27}
28
30{
31 if (!IsValidSlot(slot))
32 {
33 return;
34 }
35
36 _states[slot].Requested = requested;
37 if (_enabled && requested)
38 {
39 _states[slot].Movement.Hold(_entities.Pawn(slot));
40 }
41
42 SyncFrameWork();
43}
44
46{
47 if (!IsValidSlot(slot))
48 {
49 return;
50 }
51
52 // Releasing is never gated on the setting: a hold taken while it was on must come back.
53 _states[slot].Requested = false;
54 _states[slot].Movement.Release(_entities.Pawn(slot));
55
56 SyncFrameWork();
57}
58
59void MenuFreeze::OnGameFrame()
60{
61 for (int slot = 0; slot < MaxPlayers; ++slot)
62 {
63 if (_states[slot].Requested)
64 {
65 _states[slot].Movement.Sync(_entities.Pawn(slot));
66 }
67 }
68}
69
70void MenuFreeze::SyncFrameWork()
71{
72 bool wanted = false;
73 if (_enabled)
74 {
75 for (int slot = 0; slot < MaxPlayers && !wanted; ++slot)
76 {
77 wanted = _states[slot].Requested;
78 }
79 }
80
81 if (!wanted)
82 {
83 _onFrame.Reset();
84 }
85 else if (!_onFrame)
86 {
87 _onFrame = _scheduler.EveryFrame([this] { OnGameFrame(); });
88 }
89}
90
91} // namespace VoltMod
runtime.Entities: finds and creates entities. Everything it returns is valid for this frame only; see...
VoltMod::Pawn Pawn(int slot)
void Close(int slot)
void Open(int slot, bool requested)
MenuFreeze(EntitySystem &entities, Scheduler &scheduler, SlotEvents &slots)
Definition MenuFreeze.cpp:7
void Enable(bool enabled)
One-shot delays and repeating timers, run on the game thread.
Definition Scheduler.hpp:18
Subscription EveryFrame(std::function< void()> callback)
Definition Scheduler.cpp:35
"The occupant of this slot changed" - raised by PlayerManager, consumed below it.
static std::string ReadFile(const std::filesystem::path &path)
Definition Loader.cpp:56
constexpr bool IsValidSlot(int slot)
Definition Slot.hpp:13
constexpr int MaxPlayers
Definition Slot.hpp:7