Skip to content
This repository has been archived by the owner on Jan 2, 2021. It is now read-only.

Feat/main menu v2 #119

Merged
merged 14 commits into from
Nov 28, 2020
Prev Previous commit
Next Next commit
Added menu navigation sound
  • Loading branch information
yanis-fourel committed Nov 28, 2020
commit bfc9e395b998533ee2899b153e2c8f3d2553ee43
Binary file added data/sounds/menu/accept.wav
Binary file not shown.
Binary file added data/sounds/menu/back.wav
Binary file not shown.
Binary file added data/sounds/menu/change.wav
Binary file not shown.
8 changes: 7 additions & 1 deletion src/Application/src/menu/Credits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,20 @@ void game::menu::Credits::create(entt::registry &, ThePURGE &)

void game::menu::Credits::draw(entt::registry &, ThePURGE &game)
{
static auto holder = engine::Core::Holder{};

ImGui::SetNextWindowPos(ImVec2(0, 0));
ImGui::SetNextWindowSize(frac2pixel({1.f, 1.f}));
ImGui::Begin("Credits", nullptr, ImGuiWindowFlags_NoDecoration);
drawTexture(m_texture, ImVec2(0, 0), frac2pixel(ImVec2(1, 1)));
ImGui::End();


if (close()) game.setMenu(std::make_unique<menu::MainMenu>());
if (close()) {
holder.instance->getAudioManager().getSound(holder.instance->settings().data_folder + "sounds/menu/back.wav")->play();

game.setMenu(std::make_unique<menu::MainMenu>());
}
}

void game::menu::Credits::event(entt::registry &, ThePURGE &, const engine::Event &e)
Expand Down
8 changes: 7 additions & 1 deletion src/Application/src/menu/HowToPlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ void game::menu::HowToPlay::create(entt::registry &, ThePURGE &)

void game::menu::HowToPlay::draw(entt::registry &, ThePURGE &game)
{
static auto holder = engine::Core::Holder{};

ImGui::SetNextWindowPos(ImVec2(0, 0));
ImGui::SetNextWindowSize(frac2pixel({1.f, 1.f}));
ImGui::Begin("HowToPlay", nullptr, ImGuiWindowFlags_NoDecoration);
Expand All @@ -31,7 +33,11 @@ void game::menu::HowToPlay::draw(entt::registry &, ThePURGE &game)

ImGui::End();

if (close()) game.setMenu(std::make_unique<menu::MainMenu>());
if (close()) {
holder.instance->getAudioManager().getSound(holder.instance->settings().data_folder + "sounds/menu/back.wav")->play();

game.setMenu(std::make_unique<menu::MainMenu>());
}
}

void game::menu::HowToPlay::event(entt::registry &, ThePURGE &, const engine::Event &e)
Expand Down
26 changes: 15 additions & 11 deletions src/Application/src/menu/MainMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,28 +59,32 @@ void game::menu::MainMenu::draw(entt::registry &world, ThePURGE &game)

drawTexture(m_backgroundTexture, ImVec2(0, 0), frac2pixel({1.f, 1.f}));

if (up() && m_selected > 0) m_selected--;
if (down() && m_selected < Button::MAX - 1) m_selected++;
if (up() && m_selected > 0) {
holder.instance->getAudioManager().getSound(holder.instance->settings().data_folder + "sounds/menu/change.wav")->play();

m_selected--;
}
if (down() && m_selected < Button::MAX - 1) {
holder.instance->getAudioManager().getSound(holder.instance->settings().data_folder + "sounds/menu/change.wav")->play();

m_selected++;
}

drawTexture(m_buttons.at(m_selected));

ImGui::End();

if (select()) {
holder.instance->getAudioManager().getSound(holder.instance->settings().data_folder + "sounds/menu/accept.wav")->play();

switch (m_selected) {
case Button::PLAY:
game.setMenu(nullptr);
game.logics()->onGameStart.publish(world);
return;
case Button::HOWTOPLAY:
game.setMenu(std::make_unique<menu::HowToPlay>());
return;
case Button::CREDITS:
game.setMenu(std::make_unique<menu::Credits>());
return;
case Button::EXIT:
holder.instance->close();
break;
case Button::HOWTOPLAY: game.setMenu(std::make_unique<menu::HowToPlay>()); return;
case Button::CREDITS: game.setMenu(std::make_unique<menu::Credits>()); return;
case Button::EXIT: holder.instance->close(); break;
}
}
}
Expand Down