CS2-Kit
C++23 library for CS2 Metamod:Source plugin development
Loading...
Searching...
No Matches
MenuOption.cpp
Go to the documentation of this file.
1#include <CS2Kit/Menu/Menu.hpp>
2#include <CS2Kit/Menu/MenuManager.hpp>
3#include <CS2Kit/Menu/Options/InputOption.hpp>
4#include <CS2Kit/Menu/Options/SubmenuOption.hpp>
5#include <CS2Kit/Sdk/ChatInputCapture.hpp>
6
7namespace CS2Kit::Menu
8{
9
10void SubmenuOption::OnActivate(int slot)
11{
12 if (!_enabled || !_factory)
13 return;
14
15 auto submenu = _factory(slot);
16 if (submenu)
17 MenuManager::Instance().OpenMenu(slot, submenu);
18}
19
20void InputOption::OnActivate(int slot)
21{
22 if (!_enabled)
23 return;
24
25 auto setter = _set;
26 int maxLen = _maxLength;
27
28 Sdk::ChatInputCapture::Instance().BeginCapture(slot, _prompt,
29 [setter, maxLen](int s, std::string_view text) -> bool {
30 if (maxLen > 0 && static_cast<int>(text.size()) > maxLen)
31 return false;
32 if (!setter)
33 return true;
34 return setter(s, text);
35 });
36}
37
38} // namespace CS2Kit::Menu