VoltMod
C++23 framework for CS2 server plugins
Loading...
Searching...
No Matches
PanoramaMenu.hpp
Go to the documentation of this file.
1#pragma once
2
18#include <functional>
19#include <memory>
20#include <string>
21#include <string_view>
22#include <vector>
23
24namespace VoltMod
25{
26
27/**
28 * @brief Run menu sessions on a plugin's @ref PanoramaMenuLayout.
29 *
30 * Uses the same @ref MenuStack behavior as @ref CenterHtmlMenu. Root submenus become sidebar tabs.
31 * Pass the menu to `runtime.Menus.Prefer` when Panorama should be the preferred surface.
32 */
34{
35public:
36 /** Services used by the menu. They must outlive it. */
48
49 /** @p layout must outlive this. */
51
52 /** Whether @p slot can see the layout and has every required addon. */
53 bool CanShow(int slot) const;
54
55 bool OpenSession(int slot, std::shared_ptr<Menu> menu, MenuOptions options) override;
56 void Open(int slot, std::shared_ptr<Menu> menu) override;
57 bool IsOpen(int slot) const override;
58 void Close(int slot) override;
59 void CloseAll(int slot) override;
60 void CloseAll(int slot, std::string_view replyKey) override;
61 void Prompt(int slot, std::string prompt, std::function<bool(int slot, std::string_view text)> callback) override;
62 std::string Translate(int slot, std::string_view key, std::string_view fallback) const override;
63
64private:
65 struct Tab
66 {
67 int RootIndex;
68 std::string Label;
69 std::string Icon;
70 };
71
72 struct Session
73 {
74 std::vector<Tab> Tabs;
75 int SelectedTab = -1;
76 int Page = 0;
77 /** @ref MenuOptions::HomePage of the session that is open. */
78 bool HomePage = false;
79 };
80
81 int ItemAt(int slot, int row) const;
82 void ReadTabs(int slot);
83
84 /** Draw the session, or close it when the layout cannot reach the player. */
85 void Draw(int slot);
86 void DrawTabs(int slot);
87 void DrawRows(int slot, const Menu& menu);
88 void DrawPrompt(int slot);
89
90 void OnPress(const ButtonPress& press);
91 void Activate(int slot, int index);
92 void StepRow(int slot, int row, int direction);
93 void OpenTab(int slot, int tab);
94 void TurnPage(int slot, int delta);
95
96 void Hide(int slot);
97
98 Services _services;
99 PanoramaMenuLayout& _layout;
100 MenuStack _stack;
101 PerSlot<Session> _sessions;
102 /** Declared last so press delivery stops before its target state is destroyed. */
103 Subscriptions _subs;
104};
105
106} // namespace VoltMod
Per-player pending-prompt registry for menu free-text input.
Definition ChatInput.hpp:27
Holding players still while a menu is open, for every menu surface.
The screen built from the menu Panorama block, as PanoramaMenu draws on it.
Run menu sessions on a plugin's PanoramaMenuLayout.
void CloseAll(int slot) 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
void Open(int slot, std::shared_ptr< Menu > menu) override
bool CanShow(int slot) const
bool OpenSession(int slot, std::shared_ptr< Menu > menu, MenuOptions options) override
bool IsOpen(int slot) const override
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
Create Screen objects and report their button presses.
"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
MultiAddonManager & AddonManager
VoltMod::Scheduler & Scheduler
VoltMod::Translations & Translations
VoltMod::ChatInput & ChatInput
VoltMod::MenuFreeze & Freeze