17 : _services(services),
19 _cursors(services.Slots)
33 Push(slot, std::move(menu));
44 if (!_stack.IsOpen(slot))
50 Push(slot, std::move(menu));
53void CenterHtmlMenu::Push(
int slot, std::shared_ptr<Menu> menu)
55 _stack.
Push(slot, std::move(menu));
64void CenterHtmlMenu::ResetCursor(
int slot)
66 Cursor& cursor = _cursors[slot];
80 _services.ChatInput.CancelCapture(slot);
82 if (!_stack.IsOpen(slot))
89 if (_stack.IsOpen(slot))
96 _services.Freeze.Close(slot);
97 _services.Messages.ClearCenterHtml(slot);
107 _services.ChatInput.CancelCapture(slot);
109 if (!_stack.IsOpen(slot))
116 _services.Freeze.Close(slot);
117 _services.Messages.ClearCenterHtml(slot);
122 if (
auto& reply = _services.Policy.Reply; reply)
124 reply(slot, _services.Translations.Get(std::string(replyKey), slot));
132 _services.ChatInput.BeginCapture(slot, std::move(prompt), std::move(callback));
133 _cursors[slot].LastSent = {};
138 return _services.Translations.GetOr(key, slot, fallback);
143 return _stack.IsOpen(slot);
146void CenterHtmlMenu::Draw(
int slot,
bool changed)
154 Page& page = _cursors[slot].LastSent;
156 const bool stale = changed || page.Html.empty() || now - page.RenderedAt >= RenderIntervalMs;
159 std::string html = Render(slot, *menu);
160 page.RenderedAt = now;
161 if (html != page.Html)
163 page.Html = std::move(html);
169 const Body body = CurrentBody(slot);
172 _services.Messages.SendCenterHtml(slot, page.Html);
178std::string CenterHtmlMenu::Render(
int slot,
Menu& menu)
181 if (
auto prompt = _services.ChatInput.GetPrompt(slot))
186 const CenterHtmlView view{
187 .Describe = [
this, slot](
int index) {
return _stack.Describe(slot, index); },
188 .Breadcrumb = _stack.Breadcrumb(slot),
190 .SelectedIndex = _cursors[slot].Selected,
191 .IsSubmenu = _stack.Depth(slot) > 1,
196void CenterHtmlMenu::OnGameFrame()
200 if (!_stack.IsOpen(slot))
205 const bool pressed = ReadKeys(slot);
208 if (_stack.IsOpen(slot))
215 if (!_stack.AnyOpen())
221CenterHtmlMenu::Body CenterHtmlMenu::CurrentBody(
int slot)
const
223 const Controller controller = _services.Entities.Controller(slot);
224 const Pawn pawn = controller.Pawn();
225 return {.Pawn = pawn.Ref(), .Alive = pawn.IsAlive(), .TeamNum = controller.TeamNum()};
One-shot delays and repeating timers, run on the game thread.
Subscription EveryFrame(std::function< void()> callback)
static int64_t MonotonicMs()
Localization system. Loads one JSON file per language; nested objects flatten into dotted keys (categ...
std::string RenderMenuHtml(const Menu *menu, const CenterHtmlView &view, Translations &translations)
std::string RenderCaptureOverlay(const std::string &menuTitle, std::string_view prompt)
constexpr bool IsValidSlot(int slot)
constexpr int64_t CenterHtmlKeepAliveMs