VoltMod
C++23 framework for CS2 server plugins
Loading...
Searching...
No Matches
CenterHtmlMenu.hpp
Go to the documentation of this file.
1#pragma once
2
15#include <cstdint>
16#include <functional>
17#include <memory>
18#include <string>
19#include <string_view>
20
21namespace VoltMod
22{
23
24/**
25 * @brief Menus drawn as center HTML and driven with W/S/A/D/E/R. It needs no client addon, so
26 * `runtime.Menus` falls back to it for a player another surface cannot draw for.
27 */
29{
30public:
31 /** All must outlive the menu. */
43
44 explicit CenterHtmlMenu(const Services& services);
45
46 bool OpenSession(int slot, std::shared_ptr<Menu> menu, MenuOptions options) override;
47 void Open(int slot, std::shared_ptr<Menu> menu) override;
48 bool IsOpen(int slot) const override;
49 void Close(int slot) override;
50 void CloseAll(int slot) override;
51 void CloseAll(int slot, std::string_view replyKey) override;
52 void Prompt(int slot, std::string prompt, std::function<bool(int slot, std::string_view text)> callback) override;
53 std::string Translate(int slot, std::string_view key, std::string_view fallback) const override;
54
55private:
56 /** Presses closer together than this are ignored. */
57 static constexpr int64_t PressGapMs = 200;
58 /** Rows can show live values, so an idle page is rebuilt this often. */
59 static constexpr int64_t RenderIntervalMs = 250;
60 /** The game drops center HTML on death or a team switch, so an idle page is re-sent this often. */
61 static constexpr int64_t ResendIntervalMs = 100;
62
63 /** What one player was last sent. */
64 struct Page
65 {
66 std::string Html;
67 int64_t RenderedAt = 0;
68 int64_t SentAt = 0;
69 };
70
71 /** One player's place in the menu on top. */
72 struct Cursor
73 {
74 int Selected = 0;
75 uint64_t PrevButtons = 0;
76 int64_t LastInputTime = 0;
77 Page LastSent;
78 };
79
80 /** Push @p menu onto an open session and start the per-frame work. */
81 void Push(int slot, std::shared_ptr<Menu> menu);
82
83 /** Put the cursor back on the first selectable row of whatever is now on top. */
84 void ResetCursor(int slot);
85
86 /** Move @p slot's cursor to row @p index, applying the value pending on the row it leaves. */
87 void Select(int slot, int index);
88
89 /** Send the menu on top, or its chat prompt. Rebuilt when @p changed; sent when it differs or
90 * the last send is old. */
91 void Draw(int slot, bool changed);
92 std::string Render(int slot, Menu& menu);
93
94 void OnGameFrame();
95
96 /** The W/S/A/D/E/R controls for @p slot. True when a press was consumed. */
97 bool ReadKeys(int slot);
98 bool RunKey(int slot, uint64_t pressed);
99 void MoveCursor(int slot, int step);
100 void JumpPage(int slot, int delta);
101
102 Services _services;
103 /** What every menu surface shares. */
104 MenuStack _stack;
105 PerSlot<Cursor> _cursors;
106 /** Declared last: per-frame delivery drops before the state it touches. */
107 Subscription _onFrame;
108};
109
110} // namespace VoltMod
Menus drawn as center HTML and driven with W/S/A/D/E/R. It needs no client addon, so runtime....
bool OpenSession(int slot, std::shared_ptr< Menu > menu, MenuOptions options) override
void CloseAll(int slot) override
void Open(int slot, std::shared_ptr< Menu > menu) override
bool IsOpen(int slot) const override
void Prompt(int slot, std::string prompt, std::function< bool(int slot, std::string_view text)> callback) override
std::string Translate(int slot, std::string_view key, std::string_view fallback) const override
Per-player pending-prompt registry for menu free-text input.
Definition ChatInput.hpp:27
runtime.Entities: finds and creates entities. Everything it returns is valid for this frame only; see...
Holding players still while a menu is open, for every menu surface.
Send chat, center print, center HTML, and alert messages.
Definition Messages.hpp:30
The one permission and targeting gate, plus the plugin's reply callback.
Definition Policy.hpp:41
One-shot delays and repeating timers, run on the game thread.
Definition Scheduler.hpp:18
"The occupant of this slot changed" - raised by PlayerManager, consumed below it.
Localization system. Loads one JSON file per language; nested objects flatten into dotted keys (categ...
static std::string ReadFile(const std::filesystem::path &path)
Definition Loader.cpp:56
VoltMod::Translations & Translations