VoltMod
C++23 framework for CS2 server plugins
Loading...
Searching...
No Matches
PanoramaMenuLayout.hpp
Go to the documentation of this file.
1#pragma once
2
6#include <cstddef>
7#include <functional>
8#include <optional>
9#include <span>
10#include <string>
11#include <string_view>
12#include <vector>
13
14namespace VoltMod
15{
16
17/** What a pressed button on the menu stands for. */
19{
20 Cancel,
21 Back,
22 Close,
25 Tab,
26 Row,
28 StepUp,
29};
30
32{
34 /** The tab or row index, for the kinds that have one. */
35 int Index = 0;
36};
37
38/** The text above the rows. An empty subtitle hides its line. */
40{
41 std::string_view Brand;
42 std::string_view BrandSubtitle;
43 std::string_view Breadcrumb;
44 std::string_view Title;
45 std::string_view Subtitle;
46};
47
48/** One sidebar tab as drawn. */
49struct MenuTab
50{
51 std::string_view Label;
52 std::string_view Icon;
53 bool Selected = false;
54};
55
56/**
57 * @brief The screen built from the `menu` Panorama block, as @ref PanoramaMenu draws on it.
58 *
59 * Knows element ids and classes and nothing about menus; every call names the player it draws
60 * for. A null tab or row hides it, and so does empty text for the empty-list line, the pager and
61 * the prompt. @p screen is the layout name; @p tabs, @p rows and @p iconNames come from its
62 * generated header (`Tabs.size()`, `Rows.size()`, `IconSetNames`). Each player gets their own
63 * screen, so the menu survives death and spectating. @p screens and @p iconNames must outlive
64 * this; the generated header's array does.
65 */
67{
68public:
69 PanoramaMenuLayout(ScreenManager& screens, std::string_view screen, std::size_t tabs, std::size_t rows,
70 std::span<const std::string_view> iconNames);
71
72 /** Rows on one page. */
73 int RowCount() const { return static_cast<int>(_rows.size()); }
74
75 /** Sidebar tabs, filled from the root menu's submenus. */
76 int TabCount() const { return static_cast<int>(_tabs.size()); }
77
78 /** Spawn if needed, unhide, and give the cursor. False when @p slot cannot be drawn to. */
79 bool Show(int slot);
80 void Hide(int slot);
81
82 void SetHeader(int slot, const MenuHeader& header);
83 void SetSidebarVisible(int slot, bool visible);
84 /** Show the home markup in the rows' place. A screen without any does nothing. */
85 void SetHomeVisible(int slot, bool visible);
86 void SetTab(int slot, int index, const MenuTab* tab);
87 void SetRow(int slot, int index, const MenuRow* row, std::string_view pendingHint);
88 void SetEmpty(int slot, std::string_view text);
89 void SetPager(int slot, std::string_view text);
90 void SetPrompt(int slot, std::string_view text, std::string_view hint);
91 /** An empty @p back hides the back button: the root has nothing to go back to. */
92 void SetFooter(int slot, std::string_view back, std::string_view cancel);
93
94 /** The button a pressed id names, or nothing for an id outside this screen. */
95 std::optional<MenuButton> ButtonFor(std::string_view id) const;
96
97 /** Fills `{s:<variable>}` in markup the screen adds itself, such as its `home` panel. Written
98 * with every header, so it outlives a respawned screen. */
99 void AddText(std::string_view variable, std::function<std::string(int slot)> text);
100
101private:
102 struct TabIds
103 {
104 std::string Id;
105 std::string Icon;
106 std::string LabelVar;
107 };
108
109 struct RowIds
110 {
111 std::string Id;
112 std::string Button;
113 std::string Decrease;
114 std::string Increase;
115 std::string LabelVar;
116 std::string HintVar;
117 std::string ValueVar;
118 };
119
120 struct ScreenText
121 {
122 std::string Variable;
123 std::function<std::string(int slot)> Value;
124 };
125
126 PlayerScreens _screens;
127 std::string _root;
128 std::string _subtitle;
129 std::string _close;
130 std::string _empty;
131 std::string _prompt;
132 std::string _cancel;
133 std::string _back;
134 std::string _page;
135 std::string _pagePrevious;
136 std::string _pageNext;
137 std::vector<TabIds> _tabs;
138 std::vector<RowIds> _rows;
139 std::span<const std::string_view> _iconNames;
140 std::vector<ScreenText> _texts;
141};
142
143} // namespace VoltMod
The screen built from the menu Panorama block, as PanoramaMenu draws on it.
void SetEmpty(int slot, std::string_view text)
std::optional< MenuButton > ButtonFor(std::string_view id) const
void SetHomeVisible(int slot, bool visible)
void AddText(std::string_view variable, std::function< std::string(int slot)> text)
void SetFooter(int slot, std::string_view back, std::string_view cancel)
void SetPrompt(int slot, std::string_view text, std::string_view hint)
void SetHeader(int slot, const MenuHeader &header)
void SetRow(int slot, int index, const MenuRow *row, std::string_view pendingHint)
void SetPager(int slot, std::string_view text)
void SetTab(int slot, int index, const MenuTab *tab)
void SetSidebarVisible(int slot, bool visible)
Create Screen objects and report their button presses.
static std::string ReadFile(const std::filesystem::path &path)
Definition Loader.cpp:56
std::string_view Subtitle
std::string_view BrandSubtitle
std::string_view Breadcrumb
std::string_view Label
std::string_view Icon