#include "menu_system.h" #include "game.h" #include "script_system.h" void MenuSystem::tick(double dt) { pauseAnimation_.tick(dt); if (openState_ == OpenState::Animating && pauseAnimation_.isComplete()) { if (pauseAnimation_.getProgress() == 0.0) { openState_ = OpenState::Closed; game_.unpauseGameplay(); } else if (pauseAnimation_.getProgress() == 1.0) { openState_ = OpenState::Open; } } else if (openState_ == OpenState::Open) { cursorBobTimer_.accumulate(dt); while (cursorBobTimer_.step()) { if (cursorBobDown_) { cursorBob_++; if (cursorBob_ >= 4) { cursorBobDown_ = false; } } else { cursorBob_--; if (cursorBob_ <= 0) { cursorBobDown_ = true; } } } } } void MenuSystem::openPauseMenu() { pauseAnimation_.start(125, 1.0); openState_ = OpenState::Animating; game_.pauseGameplay(); std::vector builders = { MenuBuilder().Command("Settings"), MenuBuilder().Command("Resume Game") .ActivationFunction([] (Game& game) { game.getSystem().closePauseMenu(); }), MenuBuilder().Command("Quit") .ActivationFunction([] (Game& game) { game.quit(); }) }; if (game_.getMap().hasExitArea()) { builders.push_back(MenuBuilder().Command("Exit Area") .ActivationFunction([] (Game& game) { game.getSystem().closePauseMenu(); game.getSystem().runScript(game.getMap().getName(), "exit_area"); })); } menu_ = CreateMenu(builders); cursor_ = 0; } void MenuSystem::closePauseMenu() { pauseAnimation_.start(125, 0.0); openState_ = OpenState::Animating; } void MenuSystem::pressedUp() { cursor_--; if (cursor_ < 0) { cursor_ = menu_.size() - 1; } cursorBob_ = 0; cursorBobDown_ = true; game_.getMixer().playSound("../res/sfx/vertical_menu.wav"); } void MenuSystem::pressedDown() { cursor_++; if (cursor_ >= menu_.size()) { cursor_ = 0; } cursorBob_ = 0; cursorBobDown_ = true; game_.getMixer().playSound("../res/sfx/vertical_menu.wav"); } void MenuSystem::activateOption() { game_.getMixer().playSound("../res/sfx/menu_activate.wav"); if (menu_[cursor_].type == MenuType::Command && menu_[cursor_].activationFunction) { menu_[cursor_].activationFunction(game_); } }