Skip to main content

MenuDisplaySystem Class Template

Controls menu visibility based on game and match state. More...

Declaration

template <typename StateLft, typename StateRgt> class helios::engine::modules::ui::widgets::systems::MenuDisplaySystem<StateLft, StateRgt> { ... }

Public Member Typedefs Index

template <typename StateLft, typename StateRgt>
usingEngineRoleTag = helios::engine::common::tags::SystemRole

Public Constructors Index

template <typename StateLft, typename StateRgt>
MenuDisplaySystem (CombinedStateToIdMapPair< StateLft, StateRgt, MenuId > stateToMenuMap)

Constructs the system with a state-to-menu policy. More...

Public Member Functions Index

template <typename StateLft, typename StateRgt>
voidupdate (helios::engine::runtime::world::UpdateContext &updateContext) noexcept

Updates menu visibility based on current state. More...

Protected Member Functions Index

template <typename StateLft, typename StateRgt>
voidfocusMenu (helios::engine::runtime::world::UpdateContext &updateContext, const MenuId menuId, View< MenuComponent > &components)

Focuses the first item of a menu. More...

Private Member Functions Index

template <typename StateLft, typename StateRgt>
voidshowMenu (const MenuId menuId, const bool show, View< MenuComponent > &components)

Shows or hides a menu by ID. More...

Private Member Attributes Index

template <typename StateLft, typename StateRgt>
std::vector< MenuId >prevMenuIds_

Previously active menu IDs for change detection. More...

template <typename StateLft, typename StateRgt>
CombinedStateToIdMapPair< StateLft, StateRgt, MenuId >stateToMenuMap_

Policy mapping states to menu IDs. More...

template <typename StateLft, typename StateRgt>
std::vector< GameObject >inactiveItems_

Cache for inactive focused items to be cleaned up. More...

Description

Controls menu visibility based on game and match state.

Uses a CombinedStateToIdMapPair to determine which menus should be active for the current state combination. Automatically shows/hides menus and manages focus when states change.

## Behavior

  • Menus not associated with the current state are hidden
  • Menus associated with the current state are shown
  • When no item has focus, the first menu's default item is focused
  • Inactive focused items have their UiFocusComponent removed
See Also

CombinedStateToIdMapPair

See Also

MenuComponent

See Also

MenuNavigationSystem

Definition at line 63 of file MenuDisplaySystem.ixx.

Public Member Typedefs

EngineRoleTag

template <typename StateLft, typename StateRgt>
using helios::engine::modules::ui::widgets::systems::MenuDisplaySystem< StateLft, StateRgt >::EngineRoleTag = helios::engine::common::tags::SystemRole

Public Constructors

MenuDisplaySystem()

template <typename StateLft, typename StateRgt>
helios::engine::modules::ui::widgets::systems::MenuDisplaySystem< StateLft, StateRgt >::MenuDisplaySystem (CombinedStateToIdMapPair< StateLft, StateRgt, MenuId > stateToMenuMap)
inline explicit

Constructs the system with a state-to-menu policy.

Parameters
stateToMenuMap

Policy mapping game/match states to menu IDs.

Definition at line 128 of file MenuDisplaySystem.ixx.

129 : stateToMenuMap_(std::move(stateToMenuMap)) {
130
131 inactiveItems_.reserve(INACTIVE_FOCUSED_ITEMS_CACHE_CAPACITY);
132 }

Public Member Functions

update()

template <typename StateLft, typename StateRgt>
void helios::engine::modules::ui::widgets::systems::MenuDisplaySystem< StateLft, StateRgt >::update (helios::engine::runtime::world::UpdateContext & updateContext)
inline noexcept

Updates menu visibility based on current state.

Queries the current game and match state, then: 1. Hides menus that are no longer active 2. Shows menus for the current state 3. Ensures at least one menu item has focus

Parameters
updateContext

The current frame's update context.

Definition at line 144 of file MenuDisplaySystem.ixx.

145
146
147 auto& session = updateContext.session();
148
149 auto gameState = session.state<StateLft>();
150 auto matchState = session.state<StateRgt>();
151
152 auto menuIds = stateToMenuMap_.ids(gameState, matchState);
153
154 if (menuIds.empty() && prevMenuIds_.empty()) {
155 return;
156 }
157
158 View<MenuComponent> components = updateContext.view<MenuComponent>().whereEnabled();
159
160
161 for (auto& prevMenuId : prevMenuIds_) {
162 if (std::ranges::find(menuIds, prevMenuId) == menuIds.end()) {
163 showMenu(prevMenuId, false, components);
164 }
165 }
166
167 prevMenuIds_.assign(menuIds.begin(), menuIds.end());
168 for (auto& menuId : menuIds) {
169 showMenu(menuId, true,components);
170 }
171
172 if (menuIds.empty()) {
173 return;
174 }
175
176
177 bool hasFocus = false;
178 inactiveItems_.clear();
179
180 for (auto [entity, fc] : updateContext.view<UiFocusComponent>().whereEnabled()) {
181
182 /**
183 * @todo Check if item is child element of menu?
184 */
185 if (entity.isActive()) {
186 hasFocus = true;
187 break;
188 }
189
190 /**
191 * @todo guaranteee that the UiFocusComponent is exclusive,
192 * break here if first comp with focus was found.
193 */
194 inactiveItems_.push_back(entity);
195 }
196
197 for (auto& item : inactiveItems_) {
198 item.remove<UiFocusComponent>();
199 }
200
201 // focus an item from the first menu
202 if (!hasFocus) {
203 focusMenu(updateContext, menuIds[0], components);
204 }
205
206 }

Reference helios::engine::modules::ui::widgets::systems::MenuDisplaySystem< StateLft, StateRgt >::focusMenu.

Protected Member Functions

focusMenu()

template <typename StateLft, typename StateRgt>
void helios::engine::modules::ui::widgets::systems::MenuDisplaySystem< StateLft, StateRgt >::focusMenu (helios::engine::runtime::world::UpdateContext & updateContext, const MenuId menuId, View< MenuComponent > & components)
inline protected

Focuses the first item of a menu.

Parameters
menuId

The menu to focus.

components

View of all MenuComponent entities.

Definition at line 103 of file MenuDisplaySystem.ixx.

104 for (auto [entity, mc] : components) {
105 if (mc->menuId() == menuId) {
106 mc->selectDefaultIndex();
107
108 if (mc->menuItems().size() > mc->selectedIndex()) {
109 auto menuItem = updateContext.find(mc->menuItems()[mc->selectedIndex()]);
110 menuItem->getOrAdd<UiFocusComponent>();
111 }
112 break;
113 }
114 }
115 }

Reference helios::engine::runtime::world::UpdateContext::find.

Referenced by helios::engine::modules::ui::widgets::systems::MenuDisplaySystem< StateLft, StateRgt >::update.

Private Member Functions

showMenu()

template <typename StateLft, typename StateRgt>
void helios::engine::modules::ui::widgets::systems::MenuDisplaySystem< StateLft, StateRgt >::showMenu (const MenuId menuId, const bool show, View< MenuComponent > & components)
inline

Shows or hides a menu by ID.

Parameters
menuId

The menu to show/hide.

show

True to show, false to hide.

components

View of all MenuComponent entities.

Definition at line 88 of file MenuDisplaySystem.ixx.

88 void showMenu(const MenuId menuId, const bool show, View<MenuComponent>& components) {
89 for (auto [entity, mc] : components) {
90 if (mc->menuId() == menuId) {
91 entity.setActive(show);
92 }
93 }
94 }

Private Member Attributes

inactiveItems_

template <typename StateLft, typename StateRgt>
std::vector<GameObject> helios::engine::modules::ui::widgets::systems::MenuDisplaySystem< StateLft, StateRgt >::inactiveItems_

Cache for inactive focused items to be cleaned up.

Definition at line 79 of file MenuDisplaySystem.ixx.

79 std::vector<GameObject> inactiveItems_;

prevMenuIds_

template <typename StateLft, typename StateRgt>
std::vector<MenuId> helios::engine::modules::ui::widgets::systems::MenuDisplaySystem< StateLft, StateRgt >::prevMenuIds_

Previously active menu IDs for change detection.

Definition at line 69 of file MenuDisplaySystem.ixx.

69 std::vector<MenuId> prevMenuIds_;

stateToMenuMap_

template <typename StateLft, typename StateRgt>
CombinedStateToIdMapPair<StateLft, StateRgt, MenuId> helios::engine::modules::ui::widgets::systems::MenuDisplaySystem< StateLft, StateRgt >::stateToMenuMap_

Policy mapping states to menu IDs.

Definition at line 74 of file MenuDisplaySystem.ixx.


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


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.