MenuNavigationSystem.ixx File
System for handling menu navigation input. More...
Included Headers
#include <iostream>
#include <algorithm>
#include <cassert>
#include <helios.engine.common.tags.SystemRole>
#include <helios.engine.modules.rendering.model.components.ModelAabbComponent>
#include <helios.input.gamepad.GamepadState>
#include <helios.engine.ecs>
#include <helios.engine.modules.ui.widgets.components.MenuComponent>
#include <helios.engine.modules.ui.widgets.components.UiFocusComponent>
#include <helios.engine.mechanics.lifecycle.components.Active>
#include <helios.engine.modules.ui.widgets.types>
#include <helios.engine.modules.ui.widgets.components.UiActionComponent>
#include <helios.input.types.Gamepad>
#include <helios.engine.modules.ui.widgets.commands.UiActionCommand>
#include <helios.engine.state.Bindings>
#include <helios.engine.modules.ui.widgets.components.UiStateComponent>
#include <helios.engine.runtime.world>
#include <helios.engine.ecs.components.HierarchyComponent>
#include <helios.engine.runtime.messaging.command.EngineCommandBuffer>
Namespaces Index
| namespace | helios |
| namespace | engine |
|
Main engine module aggregating core infrastructure and game systems. More... | |
| namespace | modules |
|
Domain-specific components and systems. More... | |
| namespace | ui |
|
User interface components and systems for game entities. More... | |
| namespace | widgets |
|
UI widget components and systems. More... | |
| namespace | systems |
|
UI widget processing systems. More... | |
Classes Index
| class | MenuNavigationSystem |
|
Handles gamepad input for menu navigation. More... | |
Description
System for handling menu navigation input.
File Listing
The file content with the documentation metadata removed is:
39using namespace helios::input::types;
40using namespace helios::engine::ecs::components;
41using namespace helios::engine::modules::ui::widgets::types;
42using namespace helios::engine::ecs;
43using namespace helios::engine::runtime::world;
44using namespace helios::engine::modules::ui::widgets::components;
45using namespace helios::engine::mechanics::lifecycle::components;
46using namespace helios::input::gamepad;
50export namespace helios::engine::modules::ui::widgets::systems {
68 class MenuNavigationSystem {
82 void updateMenu(helios::engine::runtime::world::UpdateContext& updateContext, MenuComponent* mc, const size_t index) {
84 auto menuItems = mc->menuItems();
86 const auto prevIndex = mc->previousSelectedIndex();
88 if (prevIndex == index && !mc->isDirty()) {
92 UiStateComponent* usc = nullptr;
95 usc = updateContext.find(menuItems[prevIndex])->get<UiStateComponent>();
97 usc->setSelected(false);
100 mc->setSelectedIndex(index);
103 usc = updateContext.find(menuItems[index])->get<UiStateComponent>();
105 usc->setSelected(true);
108 mc->clearDirty();
126 void update(helios::engine::runtime::world::UpdateContext& updateContext) noexcept {
128 MenuComponent* focusedMenu = nullptr;
130 for (auto [entity, fc, hc, active] : updateContext.view<
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>();
142 const auto size = focusedMenu->menuItems().size();
144 const auto& gamepadState = updateContext.inputSnapshot().gamepadState();
146 if (gamepadState.isButtonPressed(GamepadInput::Up)) {
148 if (focusedMenu->selectedIndex() >= 1) {
149 updateMenu(updateContext, focusedMenu, focusedMenu->selectedIndex() - 1);
154 } else if (gamepadState.isButtonPressed(GamepadInput::Down)) {
156 if (focusedMenu->selectedIndex() + 1 < size) {
157 updateMenu(updateContext, focusedMenu, focusedMenu->selectedIndex() + 1);
163 updateMenu(updateContext, focusedMenu, focusedMenu->selectedIndex());
166 if (gamepadState.isButtonPressed(GamepadInput::A)) {
167 auto* uac = updateContext.find(focusedMenu->menuItems()[focusedMenu->selectedIndex()])->get<
172 updateContext.queueCommand<helios::engine::modules::ui::widgets::commands::UiActionCommand>(
173 focusedMenu->menuItems()[focusedMenu->selectedIndex()], uac->actionId()
Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.