summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorStar Rauchenberger <fefferburbia@gmail.com>2021-03-13 11:34:59 -0500
committerStar Rauchenberger <fefferburbia@gmail.com>2021-03-13 15:34:50 -0500
commit10c92d7f54759d9356ac948f6d019a82e40e3f4d (patch)
treed31fed66978bc8a97cacbced7e40e146a6200cc4 /src
parent37bbad70090071a473a04583e373491557906699 (diff)
downloadtanetane-10c92d7f54759d9356ac948f6d019a82e40e3f4d.tar.gz
tanetane-10c92d7f54759d9356ac948f6d019a82e40e3f4d.tar.bz2
tanetane-10c92d7f54759d9356ac948f6d019a82e40e3f4d.zip
Added pause menu open and close sound
#7
Diffstat (limited to 'src')
-rw-r--r--src/menu.h7
-rw-r--r--src/menu_system.cpp23
-rw-r--r--src/menu_system.h2
3 files changed, 25 insertions, 7 deletions
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
21class MenuBuilder { 22class 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
67void MenuSystem::closePauseMenu() { 70void 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
72void MenuSystem::pressedUp() { 79void MenuSystem::pressedUp() {
@@ -96,9 +103,13 @@ void MenuSystem::pressedDown() {
96} 103}
97 104
98void MenuSystem::activateOption() { 105void 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