summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--res/sfx/menu_activate.wavbin0 -> 62048 bytes
-rw-r--r--src/input_system.cpp4
-rw-r--r--src/menu.h9
-rw-r--r--src/menu_system.cpp16
-rw-r--r--src/menu_system.h2
5 files changed, 30 insertions, 1 deletions
diff --git a/res/sfx/menu_activate.wav b/res/sfx/menu_activate.wav new file mode 100644 index 0000000..22da52b --- /dev/null +++ b/res/sfx/menu_activate.wav
Binary files differ
diff --git a/src/input_system.cpp b/src/input_system.cpp index 0c68c49..25af7ed 100644 --- a/src/input_system.cpp +++ b/src/input_system.cpp
@@ -75,6 +75,10 @@ void InputSystem::tick(double dt) {
75 } 75 }
76 } 76 }
77 } else if (e.key.keysym.sym == SDLK_SPACE) { 77 } else if (e.key.keysym.sym == SDLK_SPACE) {
78 if (game_.getSystem<MenuSystem>().isMenuOpen()) {
79 game_.getSystem<MenuSystem>().activateOption();
80 }
81
78 if (game_.isGameplayPaused()) continue; 82 if (game_.isGameplayPaused()) continue;
79 83
80 // If there is text on screen, try to advance it. 84 // If there is text on screen, try to advance it.
diff --git a/src/menu.h b/src/menu.h index 1b91b88..967b384 100644 --- a/src/menu.h +++ b/src/menu.h
@@ -1,10 +1,13 @@
1#ifndef MENU_H_3F6E62B3 1#ifndef MENU_H_3F6E62B3
2#define MENU_H_3F6E62B3 2#define MENU_H_3F6E62B3
3 3
4#include <functional>
4#include <memory> 5#include <memory>
5#include <string> 6#include <string>
6#include <vector> 7#include <vector>
7 8
9class Game;
10
8enum class MenuType { 11enum class MenuType {
9 Command 12 Command
10}; 13};
@@ -12,6 +15,7 @@ enum class MenuType {
12struct MenuItem { 15struct MenuItem {
13 MenuType type = MenuType::Command; 16 MenuType type = MenuType::Command;
14 std::string text; 17 std::string text;
18 std::function<void(Game&)> activationFunction;
15}; 19};
16 20
17class MenuBuilder { 21class MenuBuilder {
@@ -23,6 +27,11 @@ public:
23 return *this; 27 return *this;
24 } 28 }
25 29
30 MenuBuilder& ActivationFunction(std::function<void(Game&)> val) {
31 result_.activationFunction = std::move(val);
32 return *this;
33 }
34
26 MenuItem Build() const { 35 MenuItem Build() const {
27 return result_; 36 return result_;
28 } 37 }
diff --git a/src/menu_system.cpp b/src/menu_system.cpp index a6fd566..34616a6 100644 --- a/src/menu_system.cpp +++ b/src/menu_system.cpp
@@ -40,8 +40,14 @@ void MenuSystem::openPauseMenu() {
40 40
41 menu_ = CreateMenu({ 41 menu_ = CreateMenu({
42 MenuBuilder().Command("Settings"), 42 MenuBuilder().Command("Settings"),
43 MenuBuilder().Command("Return to Main Menu"),
44 MenuBuilder().Command("Resume Game") 43 MenuBuilder().Command("Resume Game")
44 .ActivationFunction([] (Game& game) {
45 game.getSystem<MenuSystem>().closePauseMenu();
46 }),
47 MenuBuilder().Command("Quit")
48 .ActivationFunction([] (Game& game) {
49 game.quit();
50 })
45 }); 51 });
46 52
47 cursor_ = 0; 53 cursor_ = 0;
@@ -77,3 +83,11 @@ void MenuSystem::pressedDown() {
77 83
78 game_.getMixer().playSound("../res/sfx/vertical_menu.wav"); 84 game_.getMixer().playSound("../res/sfx/vertical_menu.wav");
79} 85}
86
87void MenuSystem::activateOption() {
88 game_.getMixer().playSound("../res/sfx/menu_activate.wav");
89
90 if (menu_[cursor_].type == MenuType::Command && menu_[cursor_].activationFunction) {
91 menu_[cursor_].activationFunction(game_);
92 }
93}
diff --git a/src/menu_system.h b/src/menu_system.h index fa373cb..58a574f 100644 --- a/src/menu_system.h +++ b/src/menu_system.h
@@ -28,6 +28,8 @@ public:
28 28
29 void pressedDown(); 29 void pressedDown();
30 30
31 void activateOption();
32
31 // Info 33 // Info
32 34
33 double getPauseAnimationProgress() const { return pauseAnimation_.getProgress(); } 35 double getPauseAnimationProgress() const { return pauseAnimation_.getProgress(); }