AppLayer::Status PauseMenu::tick(std::vector<sf::Event> &e, const sf::Time &t, sf::Vector2f m) { for (unsigned i = 0; i < e.size(); i++) { //Mouse presses if (e[i].type == sf::Event::MouseButtonReleased) { if (e[i].mouseButton.button == sf::Mouse::Left) { float x = (float)e[i].mouseButton.x; float y = (float)e[i].mouseButton.y; unsigned opt = translateOption(x, y); if (!opt) continue; processChoice(); } else if (e[i].mouseButton.button == sf::Mouse::Right) { Layer::back(); break; } } //Mouse movement else if (e[i].type == sf::Event::MouseMoved) { float x = (float)e[i].mouseMove.x; float y = (float)e[i].mouseMove.y; unsigned opt = translateOption(x, y); if (!opt) continue; selectChoice(opt); } //Keyboard events else if (e[i].type == sf::Event::KeyPressed) { bool up = controller.pressing(GameController::K_UP, e[i].key.code); bool down = controller.pressing(GameController::K_DOWN, e[i].key.code); bool enter = controller.pressing(GameController::K_ENTER, e[i].key.code); bool esc = controller.pressing(GameController::K_ESCAPE, e[i].key.code); if (down) selectChoice(m_choice + 1); else if (up) selectChoice(m_choice - 1); else if (enter) processChoice(); else if (esc) { Layer::back(); break; } } } return AppLayer::HALT; }
void MainMenuState::handleEvents() { sf::Event event; while (objects.window.pollEvent(event)) { switch (event.type) { case sf::Event::Closed: stateEvent.exitGame(); break; case sf::Event::MouseMoved: mainMenu.handleMouseMovement(event); break; case sf::Event::MouseButtonPressed: mainMenu.handleMousePressed(event); break; case sf::Event::MouseButtonReleased: processChoice(mainMenu.handleMouseReleased(event)); break; //Allow user to make selections with the keyboard. Enter makes a selection case sf::Event::KeyPressed: if (event.key.code == sf::Keyboard::Escape) stateEvent.exitGame(); else processChoice(mainMenu.handleKeyPressed(event)); break; case sf::Event::Resized: mainMenu.handleResize(event); break; default: break; } } }