if (this->mainMenuActive)
{
mainMenuEvents();
}
if (this->startMenuActive)
{
this->startMenuEvents();
}
if (this->resourceMenuActive)
{
this->resourceMenuEvents();
}
void Game::mainMenuEvents()
{
switch (this->events.key.code)
{
case sf::Keyboard::Down:
{
++this->mainMenuHighlight;
if (this->mainMenuHighlight > MAIN_COMMAND)
{
this->mainMenuHighlight = MAIN_RESOURCE;
}
}break;
case sf::Keyboard::Up:
{
--this->mainMenuHighlight;
if (this->mainMenuHighlight < MAIN_RESOURCE)
{
this->mainMenuHighlight = MAIN_COMMAND;
}
}break;
case sf::Keyboard::Enter:
{
this->mainMenuActive = false;
if (this->mainMenuHighlight == MAIN_RESOURCE)
{
this->resourceMenuActive = true;
std::cout << "Resource: " << resourceMenuActive << std::endl;
}
}break;
case sf::Keyboard::Escape:
{
this->mainMenuActive = false;
this->startMenuActive = true;
}break;
}
}
void Game::startMenuEvents()
{
switch (this->events.key.code)
{
case sf::Keyboard::Down:
{
++this->startMenuHighlight;
if (this->startMenuHighlight > START_EXIT_GAME)
{
this->startMenuHighlight = START_NEW_GAME;
}
std::cout << "start: " << this->startMenuHighlight << std::endl;
} break;
case sf::Keyboard::Up:
{
--this->startMenuHighlight;
if (this->startMenuHighlight < START_NEW_GAME)
{
this->startMenuHighlight = START_EXIT_GAME;
}
std::cout << "start: " << this->startMenuHighlight << std::endl;
} break;
case sf::Keyboard::Enter:
{
if (this->startMenuHighlight == START_NEW_GAME)
{
this->startMenuActive = false;
this->mainMenuActive = true;
}
if (this->startMenuHighlight == START_EXIT_GAME)
{
this->gameIsRunning = false;
}
}
}
}
void Game::resourceMenuEvents()
{
switch (this->events.key.code)
{
case sf::Keyboard::Down:
{
++this->resourceMenuHighlight;
if (this->resourceMenuHighlight > CHEMIST)
{
this->resourceMenuHighlight = BANKMAN;
}
}break;
case sf::Keyboard::Up:
{
--this->resourceMenuHighlight;
if (this->resourceMenuHighlight < BANKMAN)
{
this->resourceMenuHighlight = CHEMIST;
}
}break;
case sf::Keyboard::Enter:
{
if (resourceMenuHighlight == BANKMAN)
{
++this->overviewInfoValue;
}
} break;
case sf::Keyboard::Escape:
{
this->resourceMenuActive = false;
this->mainMenuActive = true;
}break;
}
}
----(THIS IS JUST A LITTLE BIT OF CODE FROM THE PROGRAM)----
My program renders 3 menus at the moment: startMenu -> mainMenu -> resourceMenu.
all menus handle sf::Event::KeyPressed: (Enter/Up/Down).
in resourceMenu when i press enter a number gets updated on the screen.
THE PROBLEM is that when i press enter from the mainMenu-Screen, the resourceMenu also registers that Enter was pressed and thus the resource number gets updated as soon as the resourceMenu is rendered to the screen.
What i want to achieve is this:
mainMenu (if Enter is pressed) -> resourceMenu displayed (if Enter is pressed) -> update resourceValue.
what i have:
mainMenu (if Enter is pressed) -> resourceMenu displayed (and since you pressed Enter in mainMenu resourceValue will be updated from that keyPress)
i guess i want to separate the sf::keyboard::Enter from each menu and make it so that the menus don't respond to eachothers keypress-Events.
Thanks in advance!