PauseMenu.cpp 960 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // ----------------------------------------------------------------
  2. // From Game Programming in C++ by Sanjay Madhav
  3. // Copyright (C) 2017 Sanjay Madhav. All rights reserved.
  4. //
  5. // Released under the BSD License
  6. // See LICENSE in root directory for full details.
  7. // ----------------------------------------------------------------
  8. #include "PauseMenu.h"
  9. #include "Game.h"
  10. #include "DialogBox.h"
  11. #include <SDL/SDL.h>
  12. PauseMenu::PauseMenu(Game* game)
  13. :UIScreen(game)
  14. {
  15. mGame->SetState(Game::EPaused);
  16. SetRelativeMouseMode(false);
  17. SetTitle("PauseTitle");
  18. AddButton("ResumeButton", [this]() {
  19. Close();
  20. });
  21. AddButton("QuitButton", [this]() {
  22. new DialogBox(mGame, "QuitText",
  23. [this]() {
  24. mGame->SetState(Game::EQuit);
  25. });
  26. });
  27. }
  28. PauseMenu::~PauseMenu()
  29. {
  30. SetRelativeMouseMode(true);
  31. mGame->SetState(Game::EGameplay);
  32. }
  33. void PauseMenu::HandleKeyPress(int key)
  34. {
  35. UIScreen::HandleKeyPress(key);
  36. if (key == SDLK_ESCAPE)
  37. {
  38. Close();
  39. }
  40. }