VoltMod
C++23 framework for CS2 server plugins
Loading...
Searching...
No Matches
VoltMod::MenuStack Class Reference

One player's open menus, and the row behaviour every surface shares. More...

#include <MenuStack.hpp>

Public Member Functions

 MenuStack (MenuSurface &surface, Translations &translations, Scheduler &scheduler, SlotEvents &slots)
 
 MenuStack (MenuSurface &surface, Translations &translations, PendingCommit::Timer timer, SlotEvents &slots)
 
Menu * Current (int slot)
 
Menu * Root (int slot)
 
int Depth (int slot) const
 
bool IsOpen (int slot) const
 
bool AnyOpen () const
 
std::string_view Breadcrumb (int slot) const
 
void Push (int slot, std::shared_ptr< Menu > menu)
 
void Pop (int slot)
 
void Clear (int slot)
 
void PopToRoot (int slot)
 
MenuRow Describe (int slot, int index)
 
void Activate (int slot, int index)
 
bool Step (int slot, int index, int direction)
 
void ApplyPending (int slot)
 
bool IsPending (int slot, int index) const
 

Public Attributes

Event< int > Committed
 

Detailed Description

One player's open menus, and the row behaviour every surface shares.

The half of a menu session that has nothing to do with how it is drawn: the stack, the breadcrumb, how a row describes itself, what activating a row does, and how a stepped value is held back so a burst of presses is one action. CenterHtmlMenu draws this as center HTML; a plugin drawing its own Panorama screen holds one too, so the same Menu behaves the same way whichever surface a player is on.

What stays outside: the cursor, page shape, key or click routing, freezing, and prompts. Those differ per surface, and a surface that has no cursor should not be made to carry one.

SDK-free. A surface hands it the Scheduler; the tests hand it a PendingCommit::Timer they fire by hand.

Definition at line 34 of file MenuStack.hpp.

Constructor & Destructor Documentation

◆ MenuStack() [1/2]

VoltMod::MenuStack::MenuStack ( MenuSurface &  surface,
Translations &  translations,
Scheduler &  scheduler,
SlotEvents &  slots 
)

surface is what a row's Activate callback is handed: the surface owning this stack. A slot's stack is dropped when slots reports it changed hands. Every reference must outlive this instance.

Definition at line 17 of file MenuStack.cpp.

◆ MenuStack() [2/2]

VoltMod::MenuStack::MenuStack ( MenuSurface &  surface,
Translations &  translations,
PendingCommit::Timer  timer,
SlotEvents &  slots 
)

The same, with the held commit's delay driven by timer instead of a Scheduler.

Definition at line 21 of file MenuStack.cpp.

Member Function Documentation

◆ Activate()

void VoltMod::MenuStack::Activate ( int  slot,
int  index 
)

Run row index, as if it had been selected and confirmed. Ignores rows that are disabled, unselectable, or out of range.

Runs a commit held for another row first, and cancels one held for this row: a row whose activation is its own commit would otherwise apply the value twice.

Definition at line 187 of file MenuStack.cpp.

References VoltMod::MenuItem::Activate, VoltMod::PendingCommit::Apply(), Current(), VoltMod::PendingCommit::Drop(), VoltMod::PendingCommit::IsPending(), VoltMod::IsRowActionable(), VoltMod::IsValidSlot(), and VoltMod::ReadFile().

◆ AnyOpen()

bool VoltMod::MenuStack::AnyOpen ( ) const

Definition at line 53 of file MenuStack.cpp.

References VoltMod::MaxPlayers, and VoltMod::ReadFile().

◆ ApplyPending()

void VoltMod::MenuStack::ApplyPending ( int  slot)

Apply whatever a stepped row was left showing, and forget it. Every way out of a row that is not another step goes through here.

Definition at line 253 of file MenuStack.cpp.

Referenced by Clear(), Pop(), and PopToRoot().

◆ Breadcrumb()

std::string_view VoltMod::MenuStack::Breadcrumb ( int  slot) const

Parent menu titles joined. Valid until the stack changes.

Definition at line 65 of file MenuStack.cpp.

References Breadcrumb(), VoltMod::IsValidSlot(), and VoltMod::ReadFile().

Referenced by Breadcrumb().

◆ Clear()

void VoltMod::MenuStack::Clear ( int  slot)

Clear the whole stack, applying whatever a stepped row was left showing.

Definition at line 103 of file MenuStack.cpp.

References ApplyPending(), VoltMod::IsValidSlot(), and VoltMod::ReadFile().

Referenced by VoltMod::CenterHtmlMenu::CloseAll(), and VoltMod::PanoramaMenu::CloseAll().

◆ Current()

Menu * VoltMod::MenuStack::Current ( int  slot)

Top menu, or null when none is open.

Definition at line 25 of file MenuStack.cpp.

References VoltMod::IsValidSlot(), and VoltMod::ReadFile().

Referenced by Activate(), Describe(), and Step().

◆ Depth()

int VoltMod::MenuStack::Depth ( int  slot) const

Definition at line 43 of file MenuStack.cpp.

References VoltMod::IsValidSlot(), and VoltMod::ReadFile().

Referenced by VoltMod::PanoramaMenu::Close(), and IsOpen().

◆ Describe()

MenuRow VoltMod::MenuStack::Describe ( int  slot,
int  index 
)

Row index as it describes itself, with MenuRow::Pending and MenuRow::Changed filled in and a Toggle's on/off word spelled. An index with no row behind it describes as a disabled, unselectable line.

Definition at line 143 of file MenuStack.cpp.

References Current(), VoltMod::MenuRow::Enabled, VoltMod::Translations::GetOr(), VoltMod::PendingCommit::IsPending(), VoltMod::Time::MonotonicMs(), VoltMod::ReadFile(), and VoltMod::Toggle.

◆ IsOpen()

◆ IsPending()

bool VoltMod::MenuStack::IsPending ( int  slot,
int  index 
) const

True while slot is holding a stepped value for row index.

Definition at line 258 of file MenuStack.cpp.

◆ Pop()

void VoltMod::MenuStack::Pop ( int  slot)

Pop the top menu, applying whatever a stepped row was left showing. Ask IsOpen after it: an empty stack is the caller's cue to unfreeze and take the menu off screen.

Definition at line 81 of file MenuStack.cpp.

References ApplyPending(), VoltMod::IsValidSlot(), and VoltMod::ReadFile().

Referenced by VoltMod::CenterHtmlMenu::Close(), and VoltMod::PanoramaMenu::Close().

◆ PopToRoot()

void VoltMod::MenuStack::PopToRoot ( int  slot)

Pop every menu but the root without closing the session, for a surface where entering a branch is a jump rather than a push. Does nothing when nothing is open.

Definition at line 114 of file MenuStack.cpp.

References ApplyPending(), VoltMod::IsValidSlot(), and VoltMod::ReadFile().

◆ Push()

void VoltMod::MenuStack::Push ( int  slot,
std::shared_ptr< Menu >  menu 
)

◆ Root()

Menu * VoltMod::MenuStack::Root ( int  slot)

Bottom menu - the one the session was opened with - or null.

Definition at line 34 of file MenuStack.cpp.

References VoltMod::IsValidSlot(), and VoltMod::ReadFile().

◆ Step()

bool VoltMod::MenuStack::Step ( int  slot,
int  index,
int  direction 
)

Step row index's value by direction (-1 or +1). True when the row consumed it, which is what tells a keyboard surface to page instead. A row with a MenuItem::Commit is stepped, not applied: the commit is held so a burst of presses runs one action.

Definition at line 221 of file MenuStack.cpp.

References Committed, Current(), VoltMod::PendingCommit::Hold(), VoltMod::Event< Args >::Raise(), and VoltMod::ReadFile().

Member Data Documentation

◆ Committed

Event<int > VoltMod::MenuStack::Committed

A held commit was applied. A surface that redraws every frame can ignore this; one that draws on demand needs it, because the commit lands on a timer rather than on a press.

Definition at line 97 of file MenuStack.hpp.

Referenced by VoltMod::PanoramaMenu::PanoramaMenu(), and Step().


The documentation for this class was generated from the following files: