2013-02-23 16:01:35 +01:00
|
|
|
/*
|
2013-02-24 18:40:43 +01:00
|
|
|
Part of Minetest
|
2013-02-24 19:38:45 +01:00
|
|
|
Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>
|
|
|
|
Copyright (C) 2013 Ciaran Gultnieks <ciaran@ciarang.com>
|
2013-02-23 16:01:35 +01:00
|
|
|
Copyright (C) 2013 RealBadAngel, Maciej Kasatkin <mk@realbadangel.pl>
|
|
|
|
|
|
|
|
Permission to use, copy, modify, and distribute this software for any
|
|
|
|
purpose with or without fee is hereby granted, provided that the above
|
|
|
|
copyright notice and this permission notice appear in all copies.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "guiVolumeChange.h"
|
|
|
|
#include "debug.h"
|
|
|
|
#include "serialization.h"
|
|
|
|
#include <string>
|
|
|
|
#include <IGUICheckBox.h>
|
|
|
|
#include <IGUIButton.h>
|
|
|
|
#include <IGUIScrollBar.h>
|
|
|
|
#include <IGUIStaticText.h>
|
|
|
|
#include <IGUIFont.h>
|
2013-08-11 04:09:45 +02:00
|
|
|
#include "settings.h"
|
2013-02-23 16:01:35 +01:00
|
|
|
|
|
|
|
#include "gettext.h"
|
|
|
|
|
2017-05-28 15:23:30 +02:00
|
|
|
const int ID_soundText = 263;
|
|
|
|
const int ID_soundExitButton = 264;
|
|
|
|
const int ID_soundSlider = 265;
|
2017-09-26 08:17:50 +02:00
|
|
|
const int ID_soundMuteButton = 266;
|
2013-02-23 16:01:35 +01:00
|
|
|
|
|
|
|
GUIVolumeChange::GUIVolumeChange(gui::IGUIEnvironment* env,
|
|
|
|
gui::IGUIElement* parent, s32 id,
|
2016-10-09 10:27:14 +02:00
|
|
|
IMenuManager *menumgr
|
2013-02-23 16:01:35 +01:00
|
|
|
):
|
2014-04-15 19:49:32 +02:00
|
|
|
GUIModalMenu(env, parent, id, menumgr)
|
2013-02-23 16:01:35 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
GUIVolumeChange::~GUIVolumeChange()
|
|
|
|
{
|
|
|
|
removeChildren();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GUIVolumeChange::removeChildren()
|
|
|
|
{
|
2017-05-28 15:23:30 +02:00
|
|
|
if (gui::IGUIElement *e = getElementFromId(ID_soundText))
|
2016-10-09 10:27:14 +02:00
|
|
|
e->remove();
|
|
|
|
|
|
|
|
if (gui::IGUIElement *e = getElementFromId(ID_soundExitButton))
|
|
|
|
e->remove();
|
|
|
|
|
|
|
|
if (gui::IGUIElement *e = getElementFromId(ID_soundSlider))
|
|
|
|
e->remove();
|
2013-02-23 16:01:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void GUIVolumeChange::regenerateGui(v2u32 screensize)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
Remove stuff
|
|
|
|
*/
|
|
|
|
removeChildren();
|
|
|
|
/*
|
|
|
|
Calculate new sizes and positions
|
|
|
|
*/
|
2018-11-26 22:55:24 +01:00
|
|
|
const float s = m_gui_scale;
|
2017-05-28 15:23:30 +02:00
|
|
|
DesiredRect = core::rect<s32>(
|
2018-11-26 22:55:24 +01:00
|
|
|
screensize.X / 2 - 380 * s / 2,
|
|
|
|
screensize.Y / 2 - 200 * s / 2,
|
|
|
|
screensize.X / 2 + 380 * s / 2,
|
|
|
|
screensize.Y / 2 + 200 * s / 2
|
2013-02-23 16:01:35 +01:00
|
|
|
);
|
|
|
|
recalculateAbsolutePosition(false);
|
|
|
|
|
2017-05-28 15:23:30 +02:00
|
|
|
v2s32 size = DesiredRect.getSize();
|
|
|
|
int volume = (int)(g_settings->getFloat("sound_volume") * 100);
|
|
|
|
|
2013-02-23 16:01:35 +01:00
|
|
|
/*
|
|
|
|
Add stuff
|
|
|
|
*/
|
|
|
|
{
|
2018-11-26 22:55:24 +01:00
|
|
|
core::rect<s32> rect(0, 0, 160 * s, 20 * s);
|
|
|
|
rect = rect + v2s32(size.X / 2 - 80 * s, size.Y / 2 - 70 * s);
|
2017-05-28 15:23:30 +02:00
|
|
|
|
2015-02-01 23:59:23 +01:00
|
|
|
const wchar_t *text = wgettext("Sound Volume: ");
|
2017-05-28 15:23:30 +02:00
|
|
|
core::stringw volume_text = text;
|
|
|
|
delete [] text;
|
|
|
|
|
|
|
|
volume_text += core::stringw(volume) + core::stringw("%");
|
|
|
|
Environment->addStaticText(volume_text.c_str(), rect, false,
|
|
|
|
true, this, ID_soundText);
|
2013-02-23 16:01:35 +01:00
|
|
|
}
|
|
|
|
{
|
2018-11-26 22:55:24 +01:00
|
|
|
core::rect<s32> rect(0, 0, 80 * s, 30 * s);
|
|
|
|
rect = rect + v2s32(size.X / 2 - 80 * s / 2, size.Y / 2 + 55 * s);
|
2015-02-01 23:59:23 +01:00
|
|
|
const wchar_t *text = wgettext("Exit");
|
2013-02-23 16:01:35 +01:00
|
|
|
Environment->addButton(rect, this, ID_soundExitButton,
|
2013-04-07 19:15:17 +02:00
|
|
|
text);
|
|
|
|
delete[] text;
|
2013-02-23 16:01:35 +01:00
|
|
|
}
|
|
|
|
{
|
2018-11-26 22:55:24 +01:00
|
|
|
core::rect<s32> rect(0, 0, 300 * s, 20 * s);
|
|
|
|
rect = rect + v2s32(size.X / 2 - 150 * s, size.Y / 2);
|
2013-02-23 16:01:35 +01:00
|
|
|
gui::IGUIScrollBar *e = Environment->addScrollBar(true,
|
|
|
|
rect, this, ID_soundSlider);
|
|
|
|
e->setMax(100);
|
|
|
|
e->setPos(volume);
|
|
|
|
}
|
2017-09-26 08:17:50 +02:00
|
|
|
{
|
2018-11-26 22:55:24 +01:00
|
|
|
core::rect<s32> rect(0, 0, 160 * s, 20 * s);
|
|
|
|
rect = rect + v2s32(size.X / 2 - 80 * s, size.Y / 2 - 35 * s);
|
2017-09-26 08:17:50 +02:00
|
|
|
const wchar_t *text = wgettext("Muted");
|
|
|
|
Environment->addCheckBox(g_settings->getBool("mute_sound"), rect, this,
|
|
|
|
ID_soundMuteButton, text);
|
|
|
|
delete[] text;
|
|
|
|
}
|
2013-02-23 16:01:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void GUIVolumeChange::drawMenu()
|
|
|
|
{
|
|
|
|
gui::IGUISkin* skin = Environment->getSkin();
|
|
|
|
if (!skin)
|
|
|
|
return;
|
|
|
|
video::IVideoDriver* driver = Environment->getVideoDriver();
|
2016-10-09 10:27:14 +02:00
|
|
|
video::SColor bgcolor(140, 0, 0, 0);
|
2013-02-23 16:01:35 +01:00
|
|
|
driver->draw2DRectangle(bgcolor, AbsoluteRect, &AbsoluteClippingRect);
|
|
|
|
gui::IGUIElement::draw();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GUIVolumeChange::OnEvent(const SEvent& event)
|
|
|
|
{
|
2016-10-09 10:27:14 +02:00
|
|
|
if (event.EventType == EET_KEY_INPUT_EVENT) {
|
|
|
|
if (event.KeyInput.Key == KEY_ESCAPE && event.KeyInput.PressedDown) {
|
2013-02-23 16:01:35 +01:00
|
|
|
quitMenu();
|
|
|
|
return true;
|
|
|
|
}
|
2016-10-09 10:27:14 +02:00
|
|
|
|
|
|
|
if (event.KeyInput.Key == KEY_RETURN && event.KeyInput.PressedDown) {
|
2013-02-23 16:01:35 +01:00
|
|
|
quitMenu();
|
|
|
|
return true;
|
|
|
|
}
|
2017-09-26 08:17:50 +02:00
|
|
|
} 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());
|
|
|
|
}
|
|
|
|
|
|
|
|
Environment->setFocus(this);
|
2016-10-09 10:27:14 +02:00
|
|
|
return true;
|
2013-02-23 16:01:35 +01:00
|
|
|
}
|
2016-10-09 10:27:14 +02:00
|
|
|
|
2017-09-26 08:17:50 +02:00
|
|
|
if (event.GUIEvent.EventType == gui::EGET_BUTTON_CLICKED) {
|
|
|
|
if (event.GUIEvent.Caller->getID() == ID_soundExitButton) {
|
|
|
|
quitMenu();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
Environment->setFocus(this);
|
|
|
|
}
|
2016-10-09 10:27:14 +02:00
|
|
|
|
2017-09-26 08:17:50 +02:00
|
|
|
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;
|
|
|
|
}
|
2013-02-23 16:01:35 +01:00
|
|
|
}
|
2017-09-26 08:17:50 +02:00
|
|
|
|
2016-10-09 10:27:14 +02:00
|
|
|
}
|
|
|
|
|
2013-02-23 16:01:35 +01:00
|
|
|
return Parent ? Parent->OnEvent(event) : false;
|
|
|
|
}
|
|
|
|
|