Advanced Strategic Command
soundsettings.cpp
Go to the documentation of this file.
1 /*
2  This file is part of Advanced Strategic Command; http://www.asc-hq.de
3  Copyright (C) 1994-2010 Martin Bickel and Marc Schellenberger
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program; see the file COPYING. If not, write to the
17  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18  Boston, MA 02111-1307 USA
19 */
20 
21 
22 #include "../paradialog.h"
23 #include "../gameoptions.h"
24 #include "../soundList.h"
25 #include "../widgets/textrenderer.h"
26 
28 {
30  void updateSettings();
31  public:
32  SoundSettings(PG_Widget* parent, const PG_Rect& r, PG_MessageObject* caller);
33  static void soundSettings(PG_MessageObject* caller);
34  protected:
35 
36  bool toggleMusic( bool state);
37  bool toggleSound( bool state);
38  bool buttonEvent( );
39  bool eventScrollTrack_sound(long data);
40  bool eventScrollTrack_music(long data);
41 
42  bool diag();
43 };
44 
45 
46 void soundSettings( PG_MessageObject* caller)
47 {
49 }
50 
51 
52 SoundSettings::SoundSettings(PG_Widget* parent, const PG_Rect& r, PG_MessageObject* c ) :
53  ASC_PG_Dialog(parent, r, "Sound Settings", SHOW_CLOSE )
54 {
55  sSettings = CGameOptions::Instance()->sound;
56 
57  PG_CheckButton* musb = new PG_CheckButton(this, PG_Rect( 30, 50, 200, 20 ), "Enable Music", 1 );
58  musb->sigClick.connect( sigc::mem_fun( *this, &SoundSettings::toggleMusic ));
59  new PG_Label ( this, PG_Rect(30, 80, 150, 20), "Music Volume" );
60  PG_Slider* mus = new PG_Slider(this, PG_Rect(180, 80, 200, 20), PG_Slider::HORIZONTAL, 21);
61  mus->SetRange(0,100);
62  mus->SetPosition(sSettings.musicVolume);
63  mus->sigScrollTrack.connect( sigc::mem_fun( *this, &SoundSettings::eventScrollTrack_music ));
64 
65  if ( sSettings.muteMusic )
66  musb->SetUnpressed();
67  else
68  musb->SetPressed();
69 
70 
71  PG_CheckButton* sndb = new PG_CheckButton(this, PG_Rect( 30, 150, 200, 20 ), "Enable Sound", 2 );
72  sndb->sigClick.connect( sigc::mem_fun( *this, &SoundSettings::toggleSound ));
73  new PG_Label ( this, PG_Rect(30, 180, 150, 20), "Sound Volume" );
74  PG_Slider* snd = new PG_Slider(this, PG_Rect(180, 180, 200, 20), PG_Slider::HORIZONTAL, 31);
75  snd->SetRange(0,100);
76  snd->SetPosition(sSettings.soundVolume);
77  snd->sigScrollTrack.connect( sigc::mem_fun( *this, &SoundSettings::eventScrollTrack_sound ));
78  if ( sSettings.muteEffects )
79  sndb->SetUnpressed();
80  else
81  sndb->SetPressed();
82 
83 
84  PG_Button* b1 = new PG_Button(this, PG_Rect(30,r.h-40,(r.w-70)/2,30), "OK", 100);
85  b1->sigClick.connect( sigc::hide(sigc::mem_fun( *this, &SoundSettings::closeWindow )));
86 
87  PG_Button* b2 = new PG_Button(this, PG_Rect(r.w/2+5,r.h-40,(r.w-70)/2,30), "Cancel", 101);
88  b2->sigClick.connect( sigc::hide(sigc::mem_fun( *this, &SoundSettings::buttonEvent )));
89 
90  sigClose.connect( sigc::mem_fun( *this, &SoundSettings::closeWindow ));
91 
92 
93  PG_Button* b3 = new PG_Button(this, PG_Rect( Width() -100, 25, 90, 20 ), "Diagnostics" );
94  b3->sigClick.connect( sigc::hide( sigc::mem_fun( *this, &SoundSettings::diag)));
95 
96  // caller = c;
97  // SetInputFocus();
98 }
99 
100 
101 void SoundSettings::updateSettings()
102 {
106  if ( CGameOptions::Instance()->sound.muteMusic )
108  else
110 
111 }
112 
113 bool SoundSettings::toggleMusic( bool state)
114 {
116  updateSettings();
117  return true;
118 }
119 
120 bool SoundSettings::toggleSound( bool state)
121 {
123  updateSettings();
124  return true;
125 }
126 
127 
129 {
132  updateSettings();
133  return true;
134 }
135 
137 {
140  updateSettings();
141  return true;
142 }
143 
144 
146 {
148  ViewFormattedText vft( "Sound Diagnostics", text, PG_Rect( -1, -1, 500, 500 ));
149  vft.Show();
150  vft.RunModal();
151  return true;
152 }
153 
154 
156 {
157  quitModalLoop(2);
158  CGameOptions::Instance()->sound = sSettings;
159  updateSettings();
160  return true;
161 }
162 
163 void SoundSettings::soundSettings(PG_MessageObject* caller)
164 {
165  // printf("c1c %d \n", ticker );
166  SoundSettings wnd1(NULL, PG_Rect(50,50,500,300), caller);
167  // printf("c2c %d \n", ticker );
168  wnd1.Show();
169  // printf("c3c %d \n", ticker );
170  wnd1.RunModal();
171  // printf("c4c %d \n", ticker );
172 }
173 
SoundSettings(PG_Widget *parent, const PG_Rect &r, PG_MessageObject *caller)
void setEffectsMute(bool mute)
Turns the sound on and off.
Definition: sound.cpp:128
void pauseMusic()
Pauses the music that is currently being played.
Definition: sound.cpp:227
bool toggleMusic(bool state)
static void soundSettings(PG_MessageObject *caller)
bool toggleSound(bool state)
bool muteMusic
muted soud can be reactivated during the game
Definition: gameoptions.h:174
void soundSettings(PG_MessageObject *caller)
PG_MessageObject * caller
Definition: paradialog.h:131
bool eventScrollTrack_music(long data)
void setMusicVolume(int Volume)
Sets the music volume. Range is 0 .. 100.
Definition: sound.cpp:264
ASCString getDiagnosticText()
Definition: sound.cpp:150
The ASCString class provides an abstract way to manipulate strings.
Definition: ascstring.h:14
void resumeMusic()
resumes the music
Definition: sound.cpp:238
static SoundSystem * getInstance()
Definition: sound.h:127
void setChanged(bool flag=true)
Definition: gameoptions.h:272
bool quitModalLoop(int value)
Definition: paradialog.cpp:545
Adapter class for using Paragui Dialogs in ASC. This class transfers the event control from ASC to Pa...
Definition: paradialog.h:127
struct CGameOptions::SoundSettings sound
bool muteEffects
muted soud can be reactivated during the game
Definition: gameoptions.h:171
virtual bool closeWindow()
Definition: paradialog.cpp:580
bool eventScrollTrack_sound(long data)
static CGameOptions * Instance()
returns the only Instance
Definition: gameoptions.cpp:38
void setEffectVolume(int Volume)
Sets the sound effect volume. Range is 0 .. 100.
Definition: sound.cpp:274