Fork Copy bool Menu::updatePollEvents() { sf::Event ev; // Poll for events from the window if (this->window->pollEvent(ev)) { // Handle window close event if (ev.type == sf::Event::Closed) { this->window->close(); } // Handle option selection if not in creators mode if (!this->isCreators) { // Handle key pressed events with debounce if (ev.type == sf::Event::KeyPressed && !this->changed) { this->changed = true; // Handle up navigation if (ev.key.code == sf::Keyboard::Up || ev.key.code == sf::Keyboard::W) { if (this->isMapSelection) { // Cycle up through map options if (--this->selectedMap < 0) { this->selectedMap = 3; } // Update cursor position for selected map this->cursor_sprite.setPosition(sf::Vector2f( this->text_map[this->selectedMap].getGlobalBounds().left - this->cursor_sprite.getGlobalBounds().width, this->text_map[this->selectedMap].getGlobalBounds().top + this->text_map[this->selectedMap].getGlobalBounds().height / 2.f - this->cursor_sprite.getGlobalBounds().height / 2.f )); } else { // Cycle up through main menu options if (--this->selectedOption < 0) { this->selectedOption = this->numberOfOptions - 1; } // Update cursor position for selected menu option this->cursor_sprite.setPosition(sf::Vector2f( this->text_menu[this->selectedOption].getGlobalBounds().left - this->cursor_sprite.getGlobalBounds().width, this->text_menu[this->selectedOption].getGlobalBounds().top + this->text_menu[this->selectedOption].getGlobalBounds().height / 2.f - this->cursor_sprite.getGlobalBounds().height / 2.f )); } } // Handle down navigation else if (ev.key.code == sf::Keyboard::Down || ev.key.code == sf::Keyboard::S) { if (this->isMapSelection) { // Cycle down through map options if (++this->selectedMap >= 4) { this->selectedMap = 0; } // Update cursor position for selected map this->cursor_sprite.setPosition(sf::Vector2f( this->text_map[this->selectedMap].getGlobalBounds().left - this->cursor_sprite.getGlobalBounds().width, this->text_map[this->selectedMap].getGlobalBounds().top + this->text_map[this->selectedMap].getGlobalBounds().height / 2.f - this->cursor_sprite.getGlobalBounds().height / 2.f )); } else { // Cycle down through main menu options if (++this->selectedOption >= this->numberOfOptions) { this->selectedOption = 0; } // Update cursor position for selected menu option this->cursor_sprite.setPosition(sf::Vector2f( this->text_menu[this->selectedOption].getGlobalBounds().left - this->cursor_sprite.getGlobalBounds().width, this->text_menu[this->selectedOption].getGlobalBounds().top + this->text_menu[this->selectedOption].getGlobalBounds().height / 2.f - this->cursor_sprite.getGlobalBounds().height / 2.f )); } } // Handle enter key for selection else if (ev.key.code == sf::Keyboard::Return && this->selectedOption < 3) { if (this->isMapSelection) { // Confirm map selection and exit menu return true; } else if (this->selectedOption == 0) { // Enter map selection mode for 1 player this->initMapSelection(); this->changed = false; return false; } else if (this->selectedOption == 1) { std::cout << "SSSS" << std::endl; // Debug print this->selectedMap = -1; // Special value for 2 players mode return true; // Proceed to 2 players mode } else { return true; // Proceed for other options } } // Handle escape to exit map selection else if (ev.key.code == sf::Keyboard::Escape && this->isMapSelection) { this->isMapSelection = false; } // Handle enter for exit option else if (ev.key.code == sf::Keyboard::Return && this->selectedOption == 4) { this->window->close(); } } // Handle enter for credits without debounce if (ev.type == sf::Event::KeyPressed && ev.key.code == sf::Keyboard::Return && this->selectedOption == 3) { this->isCreators = true; } // Reset debounce on key release if (ev.type == sf::Event::KeyReleased) { this->changed = false; } } else { // Handle exit from creators mode if (ev.type == sf::Event::KeyPressed && (ev.key.code == sf::Keyboard::Return || ev.key.code == sf::Keyboard::Escape)) { this->isCreators = false; } } } // No event or no action taken, continue menu loop return false; }