Skip to content

Commit 6b99066

Browse files
author
kwolekr
committedFeb 23, 2013
Merge pull request luanti-org#503 from RealBadAngel/master
Add sound volume controls to ingame menu
2 parents bc2e9db + 4d73d99 commit 6b99066

7 files changed

+268
-1
lines changed
 

‎src/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,7 @@ set(minetest_SRCS
297297
guiFormSpecMenu.cpp
298298
guiPauseMenu.cpp
299299
guiPasswordChange.cpp
300+
guiVolumeChange.cpp
300301
guiDeathScreen.cpp
301302
guiChatConsole.cpp
302303
guiCreateWorld.cpp

‎src/game.cpp

+8
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2929
#include "server.h"
3030
#include "guiPauseMenu.h"
3131
#include "guiPasswordChange.h"
32+
#include "guiVolumeChange.h"
3233
#include "guiFormSpecMenu.h"
3334
#include "guiTextInputMenu.h"
3435
#include "guiDeathScreen.h"
@@ -1519,6 +1520,13 @@ void the_game(
15191520
g_gamecallback->changepassword_requested = false;
15201521
}
15211522

1523+
if(g_gamecallback->changevolume_requested)
1524+
{
1525+
(new GUIVolumeChange(guienv, guiroot, -1,
1526+
&g_menumgr, &client))->drop();
1527+
g_gamecallback->changevolume_requested = false;
1528+
}
1529+
15221530
/* Process TextureSource's queue */
15231531
tsrc->processQueue();
15241532

‎src/guiPauseMenu.cpp

+17-1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,11 @@ void GUIPauseMenu::removeChildren()
7979
if(e != NULL)
8080
e->remove();
8181
}
82+
{
83+
gui::IGUIElement *e = getElementFromId(262);
84+
if(e != NULL)
85+
e->remove();
86+
}
8287
}
8388

8489
void GUIPauseMenu::regenerateGui(v2u32 screensize)
@@ -108,7 +113,7 @@ void GUIPauseMenu::regenerateGui(v2u32 screensize)
108113
*/
109114
const s32 btn_height = 30;
110115
const s32 btn_gap = 20;
111-
const s32 btn_num = m_simple_singleplayer_mode ? 3 : 4;
116+
const s32 btn_num = m_simple_singleplayer_mode ? 4 : 5;
112117
s32 btn_y = size.Y/2-((btn_num*btn_height+(btn_num-1)*btn_gap))/2;
113118
changeCtype("");
114119
{
@@ -128,6 +133,13 @@ void GUIPauseMenu::regenerateGui(v2u32 screensize)
128133
}
129134
btn_y += btn_height + btn_gap;
130135
}
136+
{
137+
core::rect<s32> rect(0, 0, 140, btn_height);
138+
rect = rect + v2s32(size.X/2-140/2, btn_y);
139+
Environment->addButton(rect, this, 262,
140+
wgettext("Sound Volume"));
141+
}
142+
btn_y += btn_height + btn_gap;
131143
{
132144
core::rect<s32> rect(0, 0, 140, btn_height);
133145
rect = rect + v2s32(size.X/2-140/2, btn_y);
@@ -236,6 +248,10 @@ bool GUIPauseMenu::OnEvent(const SEvent& event)
236248
quitMenu();
237249
m_gamecallback->changePassword();
238250
return true;
251+
case 262:
252+
quitMenu();
253+
m_gamecallback->changeVolume();
254+
return true;
239255
case 260: // disconnect
240256
m_gamecallback->disconnect();
241257
quitMenu();

‎src/guiPauseMenu.h

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class IGameCallback
2929
virtual void exitToOS() = 0;
3030
virtual void disconnect() = 0;
3131
virtual void changePassword() = 0;
32+
virtual void changeVolume() = 0;
3233
};
3334

3435
class GUIPauseMenu : public GUIModalMenu

‎src/guiVolumeChange.cpp

+181
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
/*
2+
Part of Minetest-c55
3+
Copyright (C) 2011 celeron55, Perttu Ahola <celeron55@gmail.com>
4+
Copyright (C) 2011 Ciaran Gultnieks <ciaran@ciarang.com>
5+
Copyright (C) 2013 RealBadAngel, Maciej Kasatkin <mk@realbadangel.pl>
6+
7+
Permission to use, copy, modify, and distribute this software for any
8+
purpose with or without fee is hereby granted, provided that the above
9+
copyright notice and this permission notice appear in all copies.
10+
11+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18+
*/
19+
20+
#include "guiVolumeChange.h"
21+
#include "debug.h"
22+
#include "serialization.h"
23+
#include <string>
24+
#include <IGUICheckBox.h>
25+
#include <IGUIButton.h>
26+
#include <IGUIScrollBar.h>
27+
#include <IGUIStaticText.h>
28+
#include <IGUIFont.h>
29+
#include "main.h"
30+
31+
#include "gettext.h"
32+
33+
const int ID_soundText1 = 263;
34+
const int ID_soundText2 = 264;
35+
const int ID_soundExitButton = 265;
36+
const int ID_soundSlider = 266;
37+
38+
GUIVolumeChange::GUIVolumeChange(gui::IGUIEnvironment* env,
39+
gui::IGUIElement* parent, s32 id,
40+
IMenuManager *menumgr,
41+
Client* client
42+
):
43+
GUIModalMenu(env, parent, id, menumgr),
44+
m_client(client)
45+
{
46+
}
47+
48+
GUIVolumeChange::~GUIVolumeChange()
49+
{
50+
removeChildren();
51+
}
52+
53+
void GUIVolumeChange::removeChildren()
54+
{
55+
{
56+
gui::IGUIElement *e = getElementFromId(ID_soundText1);
57+
if(e != NULL)
58+
e->remove();
59+
}
60+
{
61+
gui::IGUIElement *e = getElementFromId(ID_soundText2);
62+
if(e != NULL)
63+
e->remove();
64+
}
65+
{
66+
gui::IGUIElement *e = getElementFromId(ID_soundExitButton);
67+
if(e != NULL)
68+
e->remove();
69+
}
70+
{
71+
gui::IGUIElement *e = getElementFromId(ID_soundSlider);
72+
if(e != NULL)
73+
e->remove();
74+
}
75+
}
76+
77+
void GUIVolumeChange::regenerateGui(v2u32 screensize)
78+
{
79+
/*
80+
Remove stuff
81+
*/
82+
removeChildren();
83+
84+
/*
85+
Calculate new sizes and positions
86+
*/
87+
core::rect<s32> rect(
88+
screensize.X/2 - 380/2,
89+
screensize.Y/2 - 200/2,
90+
screensize.X/2 + 380/2,
91+
screensize.Y/2 + 200/2
92+
);
93+
94+
DesiredRect = rect;
95+
recalculateAbsolutePosition(false);
96+
97+
v2s32 size = rect.getSize();
98+
v2s32 topleft_client(40, 0);
99+
v2s32 size_client = size - v2s32(40, 0);
100+
int volume=(int)(g_settings->getFloat("sound_volume")*100);
101+
/*
102+
Add stuff
103+
*/
104+
changeCtype("");
105+
{
106+
core::rect<s32> rect(0, 0, 120, 20);
107+
rect = rect + v2s32(size.X/2-60, size.Y/2-35);
108+
Environment->addStaticText(wgettext("Sound Volume: "), rect, false,
109+
true, this, ID_soundText1);
110+
}
111+
{
112+
core::rect<s32> rect(0, 0, 30, 20);
113+
rect = rect + v2s32(size.X/2+40, size.Y/2-35);
114+
Environment->addStaticText(core::stringw(volume).c_str(), rect, false,
115+
true, this, ID_soundText2);
116+
}
117+
{
118+
core::rect<s32> rect(0, 0, 80, 30);
119+
rect = rect + v2s32(size.X/2-80/2, size.Y/2+55);
120+
Environment->addButton(rect, this, ID_soundExitButton,
121+
wgettext("Exit"));
122+
}
123+
{
124+
core::rect<s32> rect(0, 0, 300, 20);
125+
rect = rect + v2s32(size.X/2-150, size.Y/2);
126+
gui::IGUIScrollBar *e = Environment->addScrollBar(true,
127+
rect, this, ID_soundSlider);
128+
e->setMax(100);
129+
e->setPos(volume);
130+
}
131+
changeCtype("");
132+
}
133+
134+
void GUIVolumeChange::drawMenu()
135+
{
136+
gui::IGUISkin* skin = Environment->getSkin();
137+
if (!skin)
138+
return;
139+
video::IVideoDriver* driver = Environment->getVideoDriver();
140+
video::SColor bgcolor(140,0,0,0);
141+
driver->draw2DRectangle(bgcolor, AbsoluteRect, &AbsoluteClippingRect);
142+
gui::IGUIElement::draw();
143+
}
144+
145+
bool GUIVolumeChange::OnEvent(const SEvent& event)
146+
{
147+
if(event.EventType==EET_KEY_INPUT_EVENT)
148+
{
149+
if(event.KeyInput.Key==KEY_ESCAPE && event.KeyInput.PressedDown)
150+
{
151+
quitMenu();
152+
return true;
153+
}
154+
if(event.KeyInput.Key==KEY_RETURN && event.KeyInput.PressedDown)
155+
{
156+
quitMenu();
157+
return true;
158+
}
159+
}
160+
if(event.GUIEvent.EventType==gui::EGET_BUTTON_CLICKED)
161+
{
162+
if (event.GUIEvent.Caller->getID() == ID_soundExitButton)
163+
{
164+
quitMenu();
165+
return true;
166+
}
167+
}
168+
if(event.GUIEvent.EventType==gui::EGET_SCROLL_BAR_CHANGED)
169+
{
170+
if (event.GUIEvent.Caller->getID() == ID_soundSlider)
171+
{
172+
s32 pos = ((gui::IGUIScrollBar*)event.GUIEvent.Caller)->getPos();
173+
g_settings->setFloat("sound_volume",(float)pos/100);
174+
gui::IGUIElement *e = getElementFromId(ID_soundText2);
175+
e->setText( core::stringw(pos).c_str() );
176+
return true;
177+
}
178+
}
179+
return Parent ? Parent->OnEvent(event) : false;
180+
}
181+

‎src/guiVolumeChange.h

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
Part of Minetest-c55
3+
Copyright (C) 2010-11 celeron55, Perttu Ahola <celeron55@gmail.com>
4+
Copyright (C) 2011 Ciaran Gultnieks <ciaran@ciarang.com>
5+
Copyright (C) 2013 RealBadAngel, Maciej Kasatkin <mk@realbadangel.pl>
6+
7+
Permission to use, copy, modify, and distribute this software for any
8+
purpose with or without fee is hereby granted, provided that the above
9+
copyright notice and this permission notice appear in all copies.
10+
11+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18+
*/
19+
20+
#ifndef GUIVOLUMECHANGE_HEADER
21+
#define GUIVOLUMECHANGE_HEADER
22+
23+
#include "irrlichttypes_extrabloated.h"
24+
#include "modalMenu.h"
25+
#include "client.h"
26+
#include <string>
27+
28+
class GUIVolumeChange : public GUIModalMenu
29+
{
30+
public:
31+
GUIVolumeChange(gui::IGUIEnvironment* env,
32+
gui::IGUIElement* parent, s32 id,
33+
IMenuManager *menumgr,
34+
Client* client);
35+
~GUIVolumeChange();
36+
37+
void removeChildren();
38+
/*
39+
Remove and re-add (or reposition) stuff
40+
*/
41+
void regenerateGui(v2u32 screensize);
42+
43+
void drawMenu();
44+
45+
bool OnEvent(const SEvent& event);
46+
47+
private:
48+
Client* m_client;
49+
50+
};
51+
52+
#endif
53+

‎src/mainmenumanager.h

+7
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ class MainGameCallback : public IGameCallback
9494
MainGameCallback(IrrlichtDevice *a_device):
9595
disconnect_requested(false),
9696
changepassword_requested(false),
97+
changevolume_requested(false),
9798
device(a_device)
9899
{
99100
}
@@ -113,8 +114,14 @@ class MainGameCallback : public IGameCallback
113114
changepassword_requested = true;
114115
}
115116

117+
virtual void changeVolume()
118+
{
119+
changevolume_requested = true;
120+
}
121+
116122
bool disconnect_requested;
117123
bool changepassword_requested;
124+
bool changevolume_requested;
118125
IrrlichtDevice *device;
119126
};
120127

0 commit comments

Comments
 (0)
Please sign in to comment.