14 return [&scheduler](int64_t ms, std::function<void()> run) {
return scheduler.
Delay(ms, std::move(run)); };
22 : _surface(surface), _translations(translations), _states(slots), _pending(std::move(timer), slots)
27 if (!
IsValidSlot(slot) || _states[slot].Menus.empty())
31 return _states[slot].Menus.back().get();
36 if (!
IsValidSlot(slot) || _states[slot].Menus.empty())
40 return _states[slot].Menus.front().get();
45 return IsValidSlot(slot) ?
static_cast<int>(_states[slot].Menus.size()) : 0;
50 return Depth(slot) > 0;
57 if (!_states[slot].Menus.empty())
77 _states[slot].Menus.push_back(std::move(menu));
83 if (!
IsValidSlot(slot) || _states[slot].Menus.empty())
91 State& state = _states[slot];
92 state.Menus.pop_back();
93 if (state.Menus.empty())
116 if (!
IsValidSlot(slot) || _states[slot].Menus.empty())
122 _states[slot].Menus.resize(1);
126void MenuStack::Rebuild(
int slot)
128 State& state = _states[slot];
132 state.Breadcrumb.clear();
133 for (std::size_t i = 0; i + 1 < state.Menus.size(); ++i)
135 if (!state.Breadcrumb.empty())
139 state.Breadcrumb += state.Menus[i]->Title;
146 if (!menu || index < 0 || index >=
static_cast<int>(menu->
Items.size()))
148 return MenuRow{.Enabled =
false, .Selectable =
false};
152 const MenuItem& item = menu->
Items[
static_cast<std::size_t
>(index)];
159 *row.
State ? _translations.GetOr(
"menu.on", slot,
"ON") : _translations.GetOr(
"menu.off", slot,
"OFF");
162 State& state = _states[slot];
163 if (state.Rows.size() != menu->
Items.size())
165 state.Rows.assign(menu->
Items.size(), RowMemory{});
169 RowMemory& memory = state.Rows[
static_cast<std::size_t
>(index)];
170 if (memory.Value != row.
Value)
176 memory.ChangedAt = now;
178 memory.Value = row.
Value;
182 row.
Changed = memory.ChangedAt != 0 && now - memory.ChangedAt < ChangedMs;
183 row.
Pending = _pending.IsPending(slot, index);
197 if (_pending.IsPending(slot, index))
203 _pending.Apply(slot);
208 if (!menu || index < 0 || index >=
static_cast<int>(menu->
Items.size()))
214 const MenuItem item = menu->
Items[
static_cast<std::size_t
>(index)];
224 if (!menu || index < 0 || index >=
static_cast<int>(menu->
Items.size()))
230 const std::shared_ptr<Menu> held = _states[slot].Menus.back();
231 const MenuItem item = menu->
Items[
static_cast<std::size_t
>(index)];
236 if (!item.
Step(slot, direction))
244 _pending.Hold(slot, index, [
this, commit = item.
Commit, slot] {
246 Committed.Raise(slot);
255 _pending.Apply(slot);
260 return _pending.IsPending(slot, index);
std::function< Subscription(int64_t delayMs, std::function< void()> callback)> Timer
One-shot delays and repeating timers, run on the game thread.
Subscription Delay(int64_t delayMs, std::function< void()> callback)
"The occupant of this slot changed" - raised by PlayerManager, consumed below it.
static int64_t MonotonicMs()
Localization system. Loads one JSON file per language; nested objects flatten into dotted keys (categ...
@ Toggle
Carries an on/off value.
static constexpr std::string_view kBreadcrumbSeparator
constexpr bool IsValidSlot(int slot)
bool IsRowActionable(const MenuItem &item, int slot)
static PendingCommit::Timer TimerOn(Scheduler &scheduler)