VoltMod
C++23 framework for CS2 server plugins
Loading...
Searching...
No Matches
MenuPresets.hpp
Go to the documentation of this file.
1#pragma once
2
8#include <functional>
9#include <memory>
10#include <string>
11#include <string_view>
12#include <utility>
13#include <vector>
14
15namespace VoltMod
16{
17
18/** Settings for a player picker. Selections use @ref PlayerRef to handle disconnects safely. */
20{
21 std::string Title;
22 /** Runs with the selected player. */
23 std::function<void(PlayerRef target)> Pick;
24 /** Optional submenu factory. Takes precedence over @ref Pick. */
25 std::function<std::shared_ptr<Menu>(PlayerRef target)> Open;
26 /** Shown as one disabled row when nobody is connected; empty appends nothing. */
27 std::string EmptyLabel;
28 /** Dynamic enabled state for each player. */
29 std::function<bool(PlayerRef target)> Enabled;
30};
31
32/** Appends one row per connected player to @p builder. */
34
35/** Builds a menu containing only the @ref AppendPlayerRows list. */
37
38/** Duration presets with optional free-text input. */
40{
41 std::string Title;
42 /** Seconds, drawn in this order. */
43 std::vector<Labeled<int>> Presets;
44 /** Runs with the seconds the picked row - or the typed text - stands for. */
45 std::function<void(int slot, int seconds)> Pick;
46 /** Empty disables free-text input. */
47 std::string CustomLabel;
48 /** Shown over the menu while the player types. */
49 std::string CustomPrompt;
50 /** Longest chat line the free-text row accepts. */
52};
53
54/** Builds a duration menu. Invalid text prompts again. */
55std::shared_ptr<Menu> BuildDurationMenu(DurationMenu spec);
56
57/** Lines listed before a confirm dialog's two buttons. */
59{
60public:
61 /** `"{label}: {value}"`, or just `"{label}"` when @p value is empty. */
62 SummaryRows& Add(std::string label, std::string value = {})
63 {
64 _rows.emplace_back(std::move(label), std::move(value));
65 return *this;
66 }
67
68 /** Adds a row when @p condition is true. */
69 SummaryRows& AddIf(bool condition, std::string label, std::string value = {})
70 {
71 return condition ? Add(std::move(label), std::move(value)) : *this;
72 }
73
74 /** The rows, formatted one per line. Consumes them. */
75 [[nodiscard]] std::vector<std::string> Take() &&;
76
77private:
78 std::vector<std::pair<std::string, std::string>> _rows;
79};
80
81/** Settings for a confirmation menu. */
83{
84 std::string Title;
85 /** Preformatted text shown above the buttons. */
86 std::vector<std::string> Lines;
87 /** Empty labels use "Confirm" and "Cancel". */
88 std::string ConfirmLabel;
89 std::string CancelLabel;
90 std::function<void(int slot)> Confirm;
91 /** An empty callback closes the menu session. */
92 std::function<void(int slot)> Cancel;
93};
94
95/** The menu @ref ConfirmMenu describes. */
96std::shared_ptr<Menu> BuildConfirmMenu(ConfirmMenu spec);
97
98} // namespace VoltMod
The roster: every connected player, and the signals for the connection lifecycle.
SummaryRows & AddIf(bool condition, std::string label, std::string value={})
SummaryRows & Add(std::string label, std::string value={})
std::vector< std::string > Take() &&
static std::string ReadFile(const std::filesystem::path &path)
Definition Loader.cpp:56
std::shared_ptr< Menu > BuildDurationMenu(DurationMenu spec)
std::shared_ptr< Menu > BuildPlayerPicker(PlayerManager &players, PlayerPicker spec)
void AppendPlayerRows(MenuBuilder &builder, PlayerManager &players, const PlayerPicker &spec)
Definition PlayerRows.cpp:9
std::shared_ptr< Menu > BuildConfirmMenu(ConfirmMenu spec)
std::string CancelLabel
std::function< void(int slot)> Cancel
std::vector< std::string > Lines
std::string ConfirmLabel
std::function< void(int slot)> Confirm
std::vector< Labeled< int > > Presets
std::function< void(int slot, int seconds)> Pick
std::function< bool(PlayerRef target)> Enabled
std::function< void(PlayerRef target)> Pick
std::function< std::shared_ptr< Menu >(PlayerRef target)> Open
A storable reference to a player: the slot plus the SteamID that occupied it.
Definition PlayerRef.hpp:19