diff options
-rw-r--r-- | res/sfx/menu_close.wav | bin | 0 -> 22434 bytes | |||
-rw-r--r-- | res/sfx/menu_open.wav | bin | 0 -> 26830 bytes | |||
-rw-r--r-- | src/menu.h | 7 | ||||
-rw-r--r-- | src/menu_system.cpp | 23 | ||||
-rw-r--r-- | src/menu_system.h | 2 |
5 files changed, 25 insertions, 7 deletions
diff --git a/res/sfx/menu_close.wav b/res/sfx/menu_close.wav new file mode 100644 index 0000000..90a6a93 --- /dev/null +++ b/res/sfx/menu_close.wav | |||
Binary files differ | |||
diff --git a/res/sfx/menu_open.wav b/res/sfx/menu_open.wav new file mode 100644 index 0000000..45dd1ba --- /dev/null +++ b/res/sfx/menu_open.wav | |||
Binary files differ | |||
diff --git a/src/menu.h b/src/menu.h index 967b384..528f8c8 100644 --- a/src/menu.h +++ b/src/menu.h | |||
@@ -16,6 +16,7 @@ struct MenuItem { | |||
16 | MenuType type = MenuType::Command; | 16 | MenuType type = MenuType::Command; |
17 | std::string text; | 17 | std::string text; |
18 | std::function<void(Game&)> activationFunction; | 18 | std::function<void(Game&)> activationFunction; |
19 | bool playSfx = false; | ||
19 | }; | 20 | }; |
20 | 21 | ||
21 | class MenuBuilder { | 22 | class MenuBuilder { |
@@ -24,6 +25,7 @@ public: | |||
24 | MenuBuilder& Command(std::string text) { | 25 | MenuBuilder& Command(std::string text) { |
25 | result_.type = MenuType::Command; | 26 | result_.type = MenuType::Command; |
26 | result_.text = std::move(text); | 27 | result_.text = std::move(text); |
28 | result_.playSfx = true; | ||
27 | return *this; | 29 | return *this; |
28 | } | 30 | } |
29 | 31 | ||
@@ -32,6 +34,11 @@ public: | |||
32 | return *this; | 34 | return *this; |
33 | } | 35 | } |
34 | 36 | ||
37 | MenuBuilder& SkipSoundEffect() { | ||
38 | result_.playSfx = false; | ||
39 | return *this; | ||
40 | } | ||
41 | |||
35 | MenuItem Build() const { | 42 | MenuItem Build() const { |
36 | return result_; | 43 | return result_; |
37 | } | 44 | } |
diff --git a/src/menu_system.cpp b/src/menu_system.cpp index 468fa6e..6b03fca 100644 --- a/src/menu_system.cpp +++ b/src/menu_system.cpp | |||
@@ -44,7 +44,8 @@ void MenuSystem::openPauseMenu() { | |||
44 | MenuBuilder().Command("Resume Game") | 44 | MenuBuilder().Command("Resume Game") |
45 | .ActivationFunction([] (Game& game) { | 45 | .ActivationFunction([] (Game& game) { |
46 | game.getSystem<MenuSystem>().closePauseMenu(); | 46 | game.getSystem<MenuSystem>().closePauseMenu(); |
47 | }), | 47 | }) |
48 | .SkipSoundEffect(), | ||
48 | MenuBuilder().Command("Quit") | 49 | MenuBuilder().Command("Quit") |
49 | .ActivationFunction([] (Game& game) { | 50 | .ActivationFunction([] (Game& game) { |
50 | game.quit(); | 51 | game.quit(); |
@@ -54,7 +55,7 @@ void MenuSystem::openPauseMenu() { | |||
54 | if (game_.getMap().hasExitArea()) { | 55 | if (game_.getMap().hasExitArea()) { |
55 | builders.push_back(MenuBuilder().Command("Exit Area") | 56 | builders.push_back(MenuBuilder().Command("Exit Area") |
56 | .ActivationFunction([] (Game& game) { | 57 | .ActivationFunction([] (Game& game) { |
57 | game.getSystem<MenuSystem>().closePauseMenu(); | 58 | game.getSystem<MenuSystem>().closePauseMenu(false); |
58 | game.getSystem<ScriptSystem>().runScript(game.getMap().getName(), "exit_area"); | 59 | game.getSystem<ScriptSystem>().runScript(game.getMap().getName(), "exit_area"); |
59 | })); | 60 | })); |
60 | } | 61 | } |
@@ -62,11 +63,17 @@ void MenuSystem::openPauseMenu() { | |||
62 | menu_ = CreateMenu(builders); | 63 | menu_ = CreateMenu(builders); |
63 | 64 | ||
64 | cursor_ = 0; | 65 | cursor_ = 0; |
66 | |||
67 | game_.getMixer().playSound("../res/sfx/menu_open.wav"); | ||
65 | } | 68 | } |
66 | 69 | ||
67 | void MenuSystem::closePauseMenu() { | 70 | void MenuSystem::closePauseMenu(bool playSfx) { |
68 | pauseAnimation_.start(125, 0.0); | 71 | pauseAnimation_.start(125, 0.0); |
69 | openState_ = OpenState::Animating; | 72 | openState_ = OpenState::Animating; |
73 | |||
74 | if (playSfx) { | ||
75 | game_.getMixer().playSound("../res/sfx/menu_close.wav"); | ||
76 | } | ||
70 | } | 77 | } |
71 | 78 | ||
72 | void MenuSystem::pressedUp() { | 79 | void MenuSystem::pressedUp() { |
@@ -96,9 +103,13 @@ void MenuSystem::pressedDown() { | |||
96 | } | 103 | } |
97 | 104 | ||
98 | void MenuSystem::activateOption() { | 105 | void MenuSystem::activateOption() { |
99 | game_.getMixer().playSound("../res/sfx/menu_activate.wav"); | 106 | if (menu_[cursor_].type == MenuType::Command) { |
107 | if (menu_[cursor_].playSfx) { | ||
108 | game_.getMixer().playSound("../res/sfx/menu_activate.wav"); | ||
109 | } | ||
100 | 110 | ||
101 | if (menu_[cursor_].type == MenuType::Command && menu_[cursor_].activationFunction) { | 111 | if (menu_[cursor_].activationFunction) { |
102 | menu_[cursor_].activationFunction(game_); | 112 | menu_[cursor_].activationFunction(game_); |
113 | } | ||
103 | } | 114 | } |
104 | } | 115 | } |
diff --git a/src/menu_system.h b/src/menu_system.h index 58a574f..736d555 100644 --- a/src/menu_system.h +++ b/src/menu_system.h | |||
@@ -22,7 +22,7 @@ public: | |||
22 | 22 | ||
23 | void openPauseMenu(); | 23 | void openPauseMenu(); |
24 | 24 | ||
25 | void closePauseMenu(); | 25 | void closePauseMenu(bool playSfx = true); |
26 | 26 | ||
27 | void pressedUp(); | 27 | void pressedUp(); |
28 | 28 | ||