Skip to main content

MenuNavigationSystem Class

Handles gamepad input for menu navigation. More...

Declaration

class helios::engine::modules::ui::widgets::systems::MenuNavigationSystem { ... }

Public Member Typedefs Index

usingEngineRoleTag = helios::engine::common::tags::SystemRole

Public Member Functions Index

voidupdate (helios::engine::runtime::world::UpdateContext &updateContext) noexcept

Processes menu navigation input. More...

Private Member Functions Index

voidupdateMenu (helios::engine::runtime::world::UpdateContext &updateContext, MenuComponent *mc, const size_t index)

Updates menu selection state. More...

Description

Handles gamepad input for menu navigation.

Processes Up/Down input to change selection and A button to activate the selected menu item. Updates UiStateComponent selection state and issues UiActionCommand on activation.

## Input Handling

  • **Up/Down**: Navigate through menu items
  • **A Button**: Activate selected item (triggers UiActionCommand)
See Also

MenuComponent

See Also

MenuDisplaySystem

See Also

UiActionCommand

Definition at line 68 of file MenuNavigationSystem.ixx.

Public Member Typedefs

EngineRoleTag

using helios::engine::modules::ui::widgets::systems::MenuNavigationSystem::EngineRoleTag = helios::engine::common::tags::SystemRole

Public Member Functions

update()

void helios::engine::modules::ui::widgets::systems::MenuNavigationSystem::update (helios::engine::runtime::world::UpdateContext & updateContext)
inline noexcept

Processes menu navigation input.

Finds the currently focused menu item, handles Up/Down navigation, and triggers UiActionCommand when the A button is pressed on an item with a UiActionComponent.

Parameters
updateContext

The current frame's update context.

Definition at line 126 of file MenuNavigationSystem.ixx.

127
128 MenuComponent* focusedMenu = nullptr;
129
130 for (auto [entity, fc, hc, active] : updateContext.view<
132 >().whereEnabled()) {
133 assert(hc->parent() && updateContext.find(*hc->parent()) && updateContext.find(*hc->parent())->get<MenuComponent>() && "Item expected to have parent menu component.");
134 focusedMenu = updateContext.find(*hc->parent())->get<MenuComponent>();
135 break;
136 }
137
138 if (!focusedMenu) {
139 return;
140 }
141
142 const auto size = focusedMenu->menuItems().size();
143
144 const auto& gamepadState = updateContext.inputSnapshot().gamepadState();
145
146 if (gamepadState.isButtonPressed(GamepadInput::Up)) {
147
148 if (focusedMenu->selectedIndex() >= 1) {
149 updateMenu(updateContext, focusedMenu, focusedMenu->selectedIndex() - 1);
150 } else {
151 updateMenu(updateContext, focusedMenu, 0);
152 }
153
154 } else if (gamepadState.isButtonPressed(GamepadInput::Down)) {
155
156 if (focusedMenu->selectedIndex() + 1 < size) {
157 updateMenu(updateContext, focusedMenu, focusedMenu->selectedIndex() + 1);
158 } else {
159 updateMenu(updateContext, focusedMenu, size - 1);
160 }
161
162 } else {
163 updateMenu(updateContext, focusedMenu, focusedMenu->selectedIndex());
164 }
165
166 if (gamepadState.isButtonPressed(GamepadInput::A)) {
167 auto* uac = updateContext.find(focusedMenu->menuItems()[focusedMenu->selectedIndex()])->get<
169 >();
170
171 if (uac) {
173 focusedMenu->menuItems()[focusedMenu->selectedIndex()], uac->actionId()
174 );
175 }
176 }
177 }

References helios::input::types::A, helios::input::types::Down, helios::engine::runtime::world::UpdateContext::find, helios::input::InputSnapshot::gamepadState, helios::engine::runtime::world::UpdateContext::inputSnapshot, helios::engine::modules::ui::widgets::components::MenuComponent::menuItems, helios::engine::runtime::world::UpdateContext::queueCommand, helios::engine::modules::ui::widgets::components::MenuComponent::selectedIndex, helios::input::types::Up and helios::engine::runtime::world::UpdateContext::view.

Private Member Functions

updateMenu()

void helios::engine::modules::ui::widgets::systems::MenuNavigationSystem::updateMenu (helios::engine::runtime::world::UpdateContext & updateContext, MenuComponent * mc, const size_t index)
inline

Updates menu selection state.

Moves focus to the new index, updates UiStateComponent selection flags, and clears the dirty flag.

Parameters
updateContext

The current frame's update context.

mc

The menu component to update.

index

The new selected index.

gamepadState

The current gamepad state.

Definition at line 82 of file MenuNavigationSystem.ixx.

82 void updateMenu(helios::engine::runtime::world::UpdateContext& updateContext, MenuComponent* mc, const size_t index) {
83
84 auto menuItems = mc->menuItems();
85
86 const auto prevIndex = mc->previousSelectedIndex();
87
88 if (prevIndex == index && !mc->isDirty()) {
89 return;
90 }
91
92 UiStateComponent* usc = nullptr;
93
94 if (index != prevIndex) {
95 usc = updateContext.find(menuItems[prevIndex])->get<UiStateComponent>();
96 if (usc) {
97 usc->setSelected(false);
98 }
99 }
100 mc->setSelectedIndex(index);
101
102 // update ui state
103 usc = updateContext.find(menuItems[index])->get<UiStateComponent>();
104 if (usc) {
105 usc->setSelected(true);
106 }
107
108 mc->clearDirty();
109 }

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


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.