diff options
author | Star Rauchenberger <fefferburbia@gmail.com> | 2021-03-13 09:51:24 -0500 |
---|---|---|
committer | Star Rauchenberger <fefferburbia@gmail.com> | 2021-03-13 15:34:50 -0500 |
commit | f9dd0fbabe5348fcd9841978cdd9d3a5824a5dec (patch) | |
tree | 2d27fd932135254f8cc7f73146f78a283f4038a4 | |
parent | 7b0ac7fc096b2dadb47780e9afd141395b6a111b (diff) | |
download | tanetane-f9dd0fbabe5348fcd9841978cdd9d3a5824a5dec.tar.gz tanetane-f9dd0fbabe5348fcd9841978cdd9d3a5824a5dec.tar.bz2 tanetane-f9dd0fbabe5348fcd9841978cdd9d3a5824a5dec.zip |
Pause menu commands can do something
#7
-rw-r--r-- | res/sfx/menu_activate.wav | bin | 0 -> 62048 bytes | |||
-rw-r--r-- | src/input_system.cpp | 4 | ||||
-rw-r--r-- | src/menu.h | 9 | ||||
-rw-r--r-- | src/menu_system.cpp | 16 | ||||
-rw-r--r-- | src/menu_system.h | 2 |
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 | ||
9 | class Game; | ||
10 | |||
8 | enum class MenuType { | 11 | enum class MenuType { |
9 | Command | 12 | Command |
10 | }; | 13 | }; |
@@ -12,6 +15,7 @@ enum class MenuType { | |||
12 | struct MenuItem { | 15 | struct 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 | ||
17 | class MenuBuilder { | 21 | class 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 | |||
87 | void 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(); } |