mirror of
https://github.com/minetest/minetest.git
synced 2024-11-30 11:33:44 +01:00
Add mute setting (toggled by the mute key and in the volume menu) (#6415)
* Add mute setting (toggled by the mute key and in the volume menu)
This commit is contained in:
parent
6f1c907204
commit
9eb163ab4f
@ -763,6 +763,8 @@ enable_sound (Sound) bool true
|
|||||||
|
|
||||||
sound_volume (Volume) float 0.7 0.0 1.0
|
sound_volume (Volume) float 0.7 0.0 1.0
|
||||||
|
|
||||||
|
mute_sound (Mute sound) bool false
|
||||||
|
|
||||||
[Client]
|
[Client]
|
||||||
|
|
||||||
[*Network]
|
[*Network]
|
||||||
|
@ -37,6 +37,7 @@ void set_default_settings(Settings *settings)
|
|||||||
settings->setDefault("address", "");
|
settings->setDefault("address", "");
|
||||||
settings->setDefault("enable_sound", "true");
|
settings->setDefault("enable_sound", "true");
|
||||||
settings->setDefault("sound_volume", "0.8");
|
settings->setDefault("sound_volume", "0.8");
|
||||||
|
settings->setDefault("mute_sound", "false");
|
||||||
settings->setDefault("enable_mesh_cache", "false");
|
settings->setDefault("enable_mesh_cache", "false");
|
||||||
settings->setDefault("mesh_generation_interval", "0");
|
settings->setDefault("mesh_generation_interval", "0");
|
||||||
settings->setDefault("meshgen_block_cache_size", "20");
|
settings->setDefault("meshgen_block_cache_size", "20");
|
||||||
|
31
src/game.cpp
31
src/game.cpp
@ -2553,14 +2553,12 @@ void Game::processKeyInput()
|
|||||||
} else if (wasKeyDown(KeyType::NOCLIP)) {
|
} else if (wasKeyDown(KeyType::NOCLIP)) {
|
||||||
toggleNoClip();
|
toggleNoClip();
|
||||||
} else if (wasKeyDown(KeyType::MUTE)) {
|
} else if (wasKeyDown(KeyType::MUTE)) {
|
||||||
float volume = g_settings->getFloat("sound_volume");
|
bool new_mute_sound = !g_settings->getBool("mute_sound");
|
||||||
if (volume < 0.001f) {
|
g_settings->setBool("mute_sound", new_mute_sound);
|
||||||
g_settings->setFloat("sound_volume", 1.0f);
|
if (new_mute_sound)
|
||||||
showStatusTextSimple("Volume changed to 100%");
|
showStatusTextSimple("Sound muted");
|
||||||
} else {
|
else
|
||||||
g_settings->setFloat("sound_volume", 0.0f);
|
showStatusTextSimple("Sound unmuted");
|
||||||
showStatusTextSimple("Volume changed to 0%");
|
|
||||||
}
|
|
||||||
runData.statustext_time = 0;
|
runData.statustext_time = 0;
|
||||||
} else if (wasKeyDown(KeyType::INC_VOLUME)) {
|
} else if (wasKeyDown(KeyType::INC_VOLUME)) {
|
||||||
float new_volume = rangelim(g_settings->getFloat("sound_volume") + 0.1f, 0.0f, 1.0f);
|
float new_volume = rangelim(g_settings->getFloat("sound_volume") + 0.1f, 0.0f, 1.0f);
|
||||||
@ -3558,13 +3556,18 @@ void Game::updateSound(f32 dtime)
|
|||||||
camera->getDirection(),
|
camera->getDirection(),
|
||||||
camera->getCameraNode()->getUpVector());
|
camera->getCameraNode()->getUpVector());
|
||||||
|
|
||||||
// Check if volume is in the proper range, else fix it.
|
bool mute_sound = g_settings->getBool("mute_sound");
|
||||||
float old_volume = g_settings->getFloat("sound_volume");
|
if (mute_sound) {
|
||||||
float new_volume = rangelim(old_volume, 0.0f, 1.0f);
|
sound->setListenerGain(0.0f);
|
||||||
sound->setListenerGain(new_volume);
|
} else {
|
||||||
|
// Check if volume is in the proper range, else fix it.
|
||||||
|
float old_volume = g_settings->getFloat("sound_volume");
|
||||||
|
float new_volume = rangelim(old_volume, 0.0f, 1.0f);
|
||||||
|
sound->setListenerGain(new_volume);
|
||||||
|
|
||||||
if (old_volume != new_volume) {
|
if (old_volume != new_volume) {
|
||||||
g_settings->setFloat("sound_volume", new_volume);
|
g_settings->setFloat("sound_volume", new_volume);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
LocalPlayer *player = client->getEnv().getLocalPlayer();
|
LocalPlayer *player = client->getEnv().getLocalPlayer();
|
||||||
|
@ -33,6 +33,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||||||
const int ID_soundText = 263;
|
const int ID_soundText = 263;
|
||||||
const int ID_soundExitButton = 264;
|
const int ID_soundExitButton = 264;
|
||||||
const int ID_soundSlider = 265;
|
const int ID_soundSlider = 265;
|
||||||
|
const int ID_soundMuteButton = 266;
|
||||||
|
|
||||||
GUIVolumeChange::GUIVolumeChange(gui::IGUIEnvironment* env,
|
GUIVolumeChange::GUIVolumeChange(gui::IGUIEnvironment* env,
|
||||||
gui::IGUIElement* parent, s32 id,
|
gui::IGUIElement* parent, s32 id,
|
||||||
@ -85,7 +86,7 @@ void GUIVolumeChange::regenerateGui(v2u32 screensize)
|
|||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
core::rect<s32> rect(0, 0, 160, 20);
|
core::rect<s32> rect(0, 0, 160, 20);
|
||||||
rect = rect + v2s32(size.X / 2 - 80, size.Y / 2 - 35);
|
rect = rect + v2s32(size.X / 2 - 80, size.Y / 2 - 70);
|
||||||
|
|
||||||
const wchar_t *text = wgettext("Sound Volume: ");
|
const wchar_t *text = wgettext("Sound Volume: ");
|
||||||
core::stringw volume_text = text;
|
core::stringw volume_text = text;
|
||||||
@ -105,12 +106,20 @@ void GUIVolumeChange::regenerateGui(v2u32 screensize)
|
|||||||
}
|
}
|
||||||
{
|
{
|
||||||
core::rect<s32> rect(0, 0, 300, 20);
|
core::rect<s32> rect(0, 0, 300, 20);
|
||||||
rect = rect + v2s32(size.X/2-150, size.Y/2);
|
rect = rect + v2s32(size.X / 2 - 150, size.Y / 2);
|
||||||
gui::IGUIScrollBar *e = Environment->addScrollBar(true,
|
gui::IGUIScrollBar *e = Environment->addScrollBar(true,
|
||||||
rect, this, ID_soundSlider);
|
rect, this, ID_soundSlider);
|
||||||
e->setMax(100);
|
e->setMax(100);
|
||||||
e->setPos(volume);
|
e->setPos(volume);
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
core::rect<s32> rect(0, 0, 160, 20);
|
||||||
|
rect = rect + v2s32(size.X / 2 - 80, size.Y / 2 - 35);
|
||||||
|
const wchar_t *text = wgettext("Muted");
|
||||||
|
Environment->addCheckBox(g_settings->getBool("mute_sound"), rect, this,
|
||||||
|
ID_soundMuteButton, text);
|
||||||
|
delete[] text;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GUIVolumeChange::drawMenu()
|
void GUIVolumeChange::drawMenu()
|
||||||
@ -136,29 +145,50 @@ bool GUIVolumeChange::OnEvent(const SEvent& event)
|
|||||||
quitMenu();
|
quitMenu();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
} else if (event.EventType == EET_GUI_EVENT) {
|
||||||
|
if (event.GUIEvent.EventType == gui::EGET_CHECKBOX_CHANGED) {
|
||||||
|
gui::IGUIElement *e = getElementFromId(ID_soundMuteButton);
|
||||||
|
if (e != NULL && e->getType() == gui::EGUIET_CHECK_BOX) {
|
||||||
|
g_settings->setBool("mute_sound", ((gui::IGUICheckBox*)e)->isChecked());
|
||||||
|
}
|
||||||
|
|
||||||
if (event.GUIEvent.EventType == gui::EGET_BUTTON_CLICKED) {
|
Environment->setFocus(this);
|
||||||
if (event.GUIEvent.Caller->getID() == ID_soundExitButton) {
|
|
||||||
quitMenu();
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (event.GUIEvent.EventType == gui::EGET_SCROLL_BAR_CHANGED) {
|
if (event.GUIEvent.EventType == gui::EGET_BUTTON_CLICKED) {
|
||||||
if (event.GUIEvent.Caller->getID() == ID_soundSlider) {
|
if (event.GUIEvent.Caller->getID() == ID_soundExitButton) {
|
||||||
s32 pos = ((gui::IGUIScrollBar*)event.GUIEvent.Caller)->getPos();
|
quitMenu();
|
||||||
g_settings->setFloat("sound_volume", (float) pos / 100);
|
return true;
|
||||||
|
}
|
||||||
gui::IGUIElement *e = getElementFromId(ID_soundText);
|
Environment->setFocus(this);
|
||||||
const wchar_t *text = wgettext("Sound Volume: ");
|
|
||||||
core::stringw volume_text = text;
|
|
||||||
delete [] text;
|
|
||||||
|
|
||||||
volume_text += core::stringw(pos) + core::stringw("%");
|
|
||||||
e->setText(volume_text.c_str());
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (event.GUIEvent.EventType == gui::EGET_ELEMENT_FOCUS_LOST
|
||||||
|
&& isVisible()) {
|
||||||
|
if (!canTakeFocus(event.GUIEvent.Element)) {
|
||||||
|
dstream << "GUIMainMenu: Not allowing focus change."
|
||||||
|
<< std::endl;
|
||||||
|
// Returning true disables focus change
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (event.GUIEvent.EventType == gui::EGET_SCROLL_BAR_CHANGED) {
|
||||||
|
if (event.GUIEvent.Caller->getID() == ID_soundSlider) {
|
||||||
|
s32 pos = ((gui::IGUIScrollBar*)event.GUIEvent.Caller)->getPos();
|
||||||
|
g_settings->setFloat("sound_volume", (float) pos / 100);
|
||||||
|
|
||||||
|
gui::IGUIElement *e = getElementFromId(ID_soundText);
|
||||||
|
const wchar_t *text = wgettext("Sound Volume: ");
|
||||||
|
core::stringw volume_text = text;
|
||||||
|
delete [] text;
|
||||||
|
|
||||||
|
volume_text += core::stringw(pos) + core::stringw("%");
|
||||||
|
e->setText(volume_text.c_str());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return Parent ? Parent->OnEvent(event) : false;
|
return Parent ? Parent->OnEvent(event) : false;
|
||||||
|
Loading…
Reference in New Issue
Block a user