Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/client/App.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
#include "PauseMenu.hpp"
#include "AudioManager.hpp"
#include "ControlsMenu.hpp"
#include "SoundsMenu.hpp"

std::atomic<bool>& interrupted();

Expand Down Expand Up @@ -183,6 +184,7 @@ class App {
std::shared_ptr<GraphicsMenu> graphicsMenu;
std::shared_ptr<PauseMenu> pauseMenu;
std::shared_ptr<ControlsMenu> controlsMenu;
std::shared_ptr<SoundsMenu> soundsMenu;
GLuint menuDirtTex = 0;

std::unique_ptr<PlayerListHUD> playerListHUD;
Expand Down
2 changes: 1 addition & 1 deletion include/client/AudioManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class AudioManager {

// ---- volumes (cached so sliders survive restart of music tracks) ------
float masterVolume = 1.0f;
float musicVolume = 0.0f;
float musicVolume = 0.8f;
float sfxVolume = 1.0f;

// Per-SoundId multiplier; filled with 1.0 in init().
Expand Down
10 changes: 0 additions & 10 deletions include/client/menus/GraphicsMenu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,6 @@ class GraphicsMenu : public Menu {
std::function<bool()> get,
std::function<void(bool)> set);

void addFloatSlider(const std::string& label, float min, float max,
std::function<float()> get,
std::function<void(float)> set,
int precision = 0);

void addIntSlider(const std::string& label, int min, int max,
std::function<int()> get,
std::function<void(int)> set);

// Lay out widgets after all add* calls. The caller adds widgets up front, then
// calls this once
void commit() { build(); }
Expand All @@ -36,7 +27,6 @@ class GraphicsMenu : public Menu {
void build() override;

std::vector<Toggle> toggles;
std::vector<Slider> sliders;

Button doneButton;
GLuint dirtTexture = 0;
Expand Down
11 changes: 11 additions & 0 deletions include/client/menus/Menu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,23 @@ class Menu {
bool clickSlider(Slider& s, float glX, float glY);
void dragSlider(Slider& s, float glX);

std::vector<Slider> sliders;

private:
static void applySliderAtX(Slider& s, float glX);

public:
static GLuint loadTexture2D(const char* path, bool pixelated = true, int* outWidth = nullptr, int* outHeight = nullptr);

void addFloatSlider(const std::string& label, float min, float max,
std::function<float()> get,
std::function<void(float)> set,
int precision = 0);

void addIntSlider(const std::string& label, int min, int max,
std::function<int()> get,
std::function<void(int)> set);

protected:

virtual void onRender() = 0;
Expand Down
3 changes: 3 additions & 0 deletions include/client/menus/SettingsMenu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class SettingsMenu : public Menu {
}
void setChangeControlsCallback(std::function<void()> cb) { changeControls = std::move(cb); }
void setGraphicsCallback(std::function<void()> cb) { onGraphics = std::move(cb); }
void setSoundsCallback(std::function<void()> cb) { onSounds = std::move(cb); }

void handleMouseClick(double mouseX, double mouseY, int button, int action) override;
void handleMouseMove(double mouseX, double mouseY) override;
Expand All @@ -43,11 +44,13 @@ class SettingsMenu : public Menu {
std::function<void()> onDone;
std::function<void()> changeControls;
std::function<void()> onGraphics;
std::function<void()> onSounds;

GLuint dirtTexture = 0;
Button doneButton;
Button changeControlsButton;
Button graphicsButton;
Button soundsButton;
Button nameBox; // box
};

Expand Down
31 changes: 31 additions & 0 deletions include/client/menus/SoundsMenu.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#ifndef SOUNDSMENU_HPP
#define SOUNDSMENU_HPP

#include "Menu.hpp"
#include <functional>
#include <vector>

class SoundsMenu : public Menu {
public:
SoundsMenu(float width, float height, GLuint dirtTex);

void setDoneCallback(std::function<void()> cb) { onDone = std::move(cb); }

void handleMouseClick(double mouseX, double mouseY, int button, int action) override;
void handleMouseMove(double mouseX, double mouseY) override;

// Lay out widgets after all add* calls. The caller adds widgets up front, then
// calls this once
void commit() { build(); }

private:
void onRender() override;
void build() override;

Button doneButton;
GLuint dirtTexture = 0;

std::function<void()> onDone;
};

#endif
47 changes: 47 additions & 0 deletions src/client/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ void App::init(const std::string& serverIp) {
if (app->graphicsMenu) app->graphicsMenu->resize(width, height);
if (app->pauseMenu) app->pauseMenu->resize(width, height);
if (app->controlsMenu) app->controlsMenu->resize(width, height);
if (app->soundsMenu) app->soundsMenu->resize(width, height);
});

glfwMakeContextCurrent(window);
Expand Down Expand Up @@ -438,6 +439,7 @@ void App::init(const std::string& serverIp) {
graphicsMenu = std::make_shared<GraphicsMenu>(screenWidth, screenHeight, menuDirtTex);
pauseMenu = std::make_shared<PauseMenu>(screenWidth, screenHeight);
controlsMenu = std::make_shared<ControlsMenu>(screenWidth, screenHeight, menuDirtTex);
soundsMenu = std::make_shared<SoundsMenu>(screenWidth, screenHeight, menuDirtTex);

graphicsMenu->addToggle("V-Sync",
[this]() { return vsync; },
Expand Down Expand Up @@ -467,6 +469,38 @@ void App::init(const std::string& serverIp) {
graphicsMenu->commit();
controlsArray = controlsMenu->getControlsArray();

soundsMenu->addIntSlider("Master Volume", 0, 100,
[this]() {
if (audio)
return static_cast<int>(audio->getMasterVolume() * 100);
return 100;
},
[this](int v) {
if (audio)
audio->setMasterVolume(static_cast<float>(v) / 100);
});
soundsMenu->addIntSlider("Music Volume", 0, 100,
[this]() {
if (audio)
return static_cast<int>(audio->getMusicVolume() * 100);
return 100;
},
[this](int v) {
if (audio)
audio->setMusicVolume(static_cast<float>(v) / 100);
});
soundsMenu->addIntSlider("Effects Volume", 0, 100,
[this]() {
if (audio)
return static_cast<int>(audio->getSfxVolume() * 100);
return 100;
},
[this](int v) {
if (audio)
audio->setSfxVolume(static_cast<float>(v) / 100);
});
soundsMenu->commit();

mainMenu->setButtonCallback([this](int btn) {
switch (btn) {
case 0: break; // Singleplayer - disabled
Expand Down Expand Up @@ -518,6 +552,14 @@ void App::init(const std::string& serverIp) {
menuManager = settingsMenu;
});

settingsMenu->setSoundsCallback([this]() {
menuManager = soundsMenu;
});

soundsMenu->setDoneCallback([this]() {
menuManager = settingsMenu;
});

pauseMenu->setContinueCallback([this]() {
menuManager.reset();
if (!uiInteractive)
Expand Down Expand Up @@ -3107,6 +3149,7 @@ void App::cleanup() {
settingsMenu.reset();
graphicsMenu.reset();
controlsMenu.reset();
soundsMenu.reset();
pauseMenu.reset();
autoExposure.reset();
sceneFBO.reset();
Expand Down Expand Up @@ -3182,6 +3225,10 @@ bool App::popSubMenuOnEscape() {
menuManager = settingsMenu;
return true;
}
if (mgr == soundsMenu) {
menuManager = settingsMenu;
return true;
}
if (mgr == controlsMenu) {
// Don't pop while a key rebind is pending — the rebinder consumes ESC.
if (!controlsMenu->getChangeRequested())
Expand Down
8 changes: 4 additions & 4 deletions src/client/AudioManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,10 @@ void AudioManager::loadAllAssets() {
"assets/sounds/footsteps/grass/grass5.wav",
"assets/sounds/footsteps/grass/grass6.wav",
});
Comment thread
ldominiq marked this conversation as resolved.
loadSfx(SoundId::Footstep_Water, {"assets/sounds/footsteps/water/splash1.wav"});
loadSfx(SoundId::Footstep_Water, {
"assets/sounds/liquids/splash.wav",
"assets/sounds/liquids/splash2.wav",
});

// Block break / place — keyed by material group.
loadSfx(SoundId::Break_Stone, {
Expand Down Expand Up @@ -199,7 +202,6 @@ void AudioManager::loadAllAssets() {
"assets/sounds/blocks/gravel/gravel3.wav",
"assets/sounds/blocks/gravel/gravel4.wav",
});
loadSfx(SoundId::Break_Leaves, {"assets/sounds/blocks/break/leaves.wav"});
loadSfx(SoundId::Break_Snow, {
"assets/sounds/blocks/snow/snow1.wav",
"assets/sounds/blocks/snow/snow2.wav",
Expand Down Expand Up @@ -285,7 +287,6 @@ void AudioManager::loadAllAssets() {
"assets/sounds/mobs/creeper/explode3.wav",
"assets/sounds/mobs/creeper/explode4.wav"});

loadSfx(SoundId::Player_Jump, {"assets/sounds/player/jump.wav"});
loadSfx(SoundId::Player_Splash, {
"assets/sounds/liquids/splash.wav",
"assets/sounds/liquids/splash2.wav",
Expand Down Expand Up @@ -327,7 +328,6 @@ void AudioManager::loadAllAssets() {
"assets/sounds/player/damage/hit3.wav"});
// Generic Minecraft-style "block pop" used for pickup up items
loadSfx(SoundId::Block_Pop, {"assets/sounds/player/pop.wav"});
loadSfx(SoundId::UI_Click, {"assets/sounds/ui/button_click.wav"});

// Per-biome ambient music. Streamed (no full decode in RAM).
loadMusic(BiomeType::PLAINS, "assets/sounds/music/plains.ogg");
Expand Down
30 changes: 0 additions & 30 deletions src/client/menus/GraphicsMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,36 +29,6 @@ void GraphicsMenu::addToggle(const std::string& label,
toggles.push_back(std::move(t));
}

void GraphicsMenu::addFloatSlider(const std::string& label, float min, float max,
std::function<float()> get,
std::function<void(float)> set,
int precision)
{
Slider s;
s.label = label;
s.minVal = min;
s.maxVal = max;
s.isInt = false;
s.precision = precision;
s.getF = std::move(get);
s.setF = std::move(set);
sliders.push_back(std::move(s));
}

void GraphicsMenu::addIntSlider(const std::string& label, int min, int max,
std::function<int()> get,
std::function<void(int)> set)
{
Slider s;
s.label = label;
s.minVal = static_cast<float>(min);
s.maxVal = static_cast<float>(max);
s.isInt = true;
s.getI = std::move(get);
s.setI = std::move(set);
sliders.push_back(std::move(s));
}

void GraphicsMenu::build()
{
float centerX = fullscreenWidth / 2.0f;
Expand Down
30 changes: 30 additions & 0 deletions src/client/menus/Menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,36 @@
applySliderAtX(s, glX);
}

void Menu::addFloatSlider(const std::string& label, float min, float max,

Check warning on line 290 in src/client/menus/Menu.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace this const reference to "std::string" by a "std::string_view".

See more on https://sonarcloud.io/project/issues?id=ldominiq_ft_minecraft&issues=AZ5QUWeUoI4Cm-ZmQSOm&open=AZ5QUWeUoI4Cm-ZmQSOm&pullRequest=106
std::function<float()> get,
std::function<void(float)> set,
int precision)
{
Slider s;
s.label = label;
s.minVal = min;
s.maxVal = max;
s.isInt = false;
s.precision = precision;
s.getF = std::move(get);
s.setF = std::move(set);
sliders.push_back(std::move(s));
}

void Menu::addIntSlider(const std::string& label, int min, int max,

Check warning on line 306 in src/client/menus/Menu.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace this const reference to "std::string" by a "std::string_view".

See more on https://sonarcloud.io/project/issues?id=ldominiq_ft_minecraft&issues=AZ5QUWeUoI4Cm-ZmQSOn&open=AZ5QUWeUoI4Cm-ZmQSOn&pullRequest=106
std::function<int()> get,
std::function<void(int)> set)
{
Slider s;
s.label = label;
s.minVal = static_cast<float>(min);
s.maxVal = static_cast<float>(max);
s.isInt = true;
s.getI = std::move(get);
s.setI = std::move(set);
sliders.push_back(std::move(s));
}

void Menu::drawSlider(const Slider& s)
{
float border = 2.0f * menuScale;
Expand Down
11 changes: 11 additions & 0 deletions src/client/menus/SettingsMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ SettingsMenu::SettingsMenu(float width, float height, GLuint dirtTex)
doneButton.label = "Done";
changeControlsButton.label = "Controls";
graphicsButton.label = "Graphics";
soundsButton.label = "Sounds";
resize(width, height);
username = "nameless";
loadUsername();
Expand Down Expand Up @@ -57,6 +58,11 @@ void SettingsMenu::build()
graphicsButton.x = centerX - btnW / 2.0f;
graphicsButton.y = changeControlsButton.y - btnH - 20.0f * menuScale;

soundsButton.w = btnW;
soundsButton.h = btnH;
soundsButton.x = centerX - btnW / 2.0f;
soundsButton.y = graphicsButton.y - btnH - 20.0f * menuScale;

doneButton.w = btnW;
doneButton.h = btnH;
doneButton.x = centerX - btnW / 2.0f;
Expand Down Expand Up @@ -97,6 +103,9 @@ void SettingsMenu::onRender()
drawButton(graphicsButton.x, graphicsButton.y, graphicsButton.w, graphicsButton.h,
graphicsButton.label, graphicsButton.hovered);

drawButton(soundsButton.x, soundsButton.y, soundsButton.w, soundsButton.h,
soundsButton.label, soundsButton.hovered);

textRenderer.setScale(savedScale);
}

Expand All @@ -108,6 +117,7 @@ void SettingsMenu::handleMouseMove(double mouseX, double mouseY)
updateHover(doneButton, glX, glY);
updateHover(changeControlsButton, glX, glY);
updateHover(graphicsButton, glX, glY);
updateHover(soundsButton, glX, glY);
}

void SettingsMenu::handleMouseClick(double mouseX, double mouseY, int button, int action)
Expand All @@ -121,6 +131,7 @@ void SettingsMenu::handleMouseClick(double mouseX, double mouseY, int button, in
if (isInside(doneButton, glX, glY) && onDone) onDone();
if (isInside(changeControlsButton, glX, glY) && changeControls) changeControls();
if (isInside(graphicsButton, glX, glY) && onGraphics) onGraphics();
if (isInside(soundsButton, glX, glY) && onSounds) onSounds();
}

void SettingsMenu::saveUsername(const char* filename)
Expand Down
Loading
Loading