Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

soundsettings.cpp

Go to the documentation of this file.
00001 /*
00002      This file is part of Advanced Strategic Command; http://www.asc-hq.de
00003      Copyright (C) 1994-1999  Martin Bickel  and  Marc Schellenberger
00004  
00005      This program is free software; you can redistribute it and/or modify
00006      it under the terms of the GNU General Public License as published by
00007      the Free Software Foundation; either version 2 of the License, or
00008      (at your option) any later version.
00009  
00010      This program is distributed in the hope that it will be useful,
00011      but WITHOUT ANY WARRANTY; without even the implied warranty of
00012      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013      GNU General Public License for more details.
00014  
00015      You should have received a copy of the GNU General Public License
00016      along with this program; see the file COPYING. If not, write to the 
00017      Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
00018      Boston, MA  02111-1307  USA
00019 */
00020 
00021 
00022 #include "../paradialog.h"
00023 #include "../gameoptions.h"
00024 #include "../soundList.h"
00025 #include "../widgets/textrenderer.h"
00026 
00027 class SoundSettings : public ASC_PG_Dialog
00028 {
00029       CGameOptions::SoundSettings sSettings;
00030       void updateSettings();
00031    public:
00032       SoundSettings(PG_Widget* parent, const PG_Rect& r, PG_MessageObject* caller);
00033       static void soundSettings(PG_MessageObject* caller);      
00034    protected:
00035 
00036       bool radioButtonEvent( PG_RadioButton* button, bool state);
00037       bool buttonEvent( PG_Button* button );
00038       bool eventScrollTrack(PG_ScrollBar* slider, long data);
00039 
00040       bool diag();
00041 };
00042 
00043 
00044 void soundSettings( PG_MessageObject* caller)
00045 {
00046    SoundSettings::soundSettings(caller );
00047 }
00048 
00049 
00050 SoundSettings::SoundSettings(PG_Widget* parent, const PG_Rect& r, PG_MessageObject* c ) :
00051       ASC_PG_Dialog(parent, r, "Sound Settings", SHOW_CLOSE )
00052 {
00053    sSettings = CGameOptions::Instance()->sound;
00054 
00055    PG_CheckButton* musb = new PG_CheckButton(this, PG_Rect( 30, 50, 200, 20 ), "Enable Music", 1 );
00056    musb->sigClick.connect(SigC::slot( *this, &SoundSettings::radioButtonEvent ));
00057    new PG_Label ( this, PG_Rect(30, 80, 150, 20), "Music Volume" );
00058    PG_Slider* mus = new PG_Slider(this, PG_Rect(180, 80, 200, 20), PG_Slider::HORIZONTAL, 21);
00059    mus->SetRange(0,100);
00060    mus->SetPosition(sSettings.musicVolume);
00061    mus->sigScrollTrack.connect( SigC::slot( *this, &SoundSettings::eventScrollTrack ));
00062 
00063    if ( sSettings.muteMusic )
00064       musb->SetUnpressed();
00065    else
00066       musb->SetPressed();
00067 
00068 
00069    PG_CheckButton* sndb = new PG_CheckButton(this, PG_Rect( 30, 150, 200, 20 ), "Enable Sound", 2 );
00070    sndb->sigClick.connect(SigC::slot( *this, &SoundSettings::radioButtonEvent ));
00071    new PG_Label ( this, PG_Rect(30, 180, 150, 20), "Sound Volume" );
00072    PG_Slider* snd = new PG_Slider(this, PG_Rect(180, 180, 200, 20), PG_Slider::HORIZONTAL, 31);
00073    snd->SetRange(0,100);
00074    snd->SetPosition(sSettings.soundVolume);
00075    snd->sigScrollTrack.connect( SigC::slot( *this, &SoundSettings::eventScrollTrack ));
00076    if ( sSettings.muteEffects )
00077       sndb->SetUnpressed();
00078    else
00079       sndb->SetPressed();
00080 
00081 
00082    PG_Button* b1 = new PG_Button(this, PG_Rect(30,r.h-40,(r.w-70)/2,30), "OK", 100);
00083    b1->sigClick.connect(SigC::slot( *this, &SoundSettings::closeWindow ));
00084 
00085    PG_Button* b2 = new PG_Button(this, PG_Rect(r.w/2+5,r.h-40,(r.w-70)/2,30), "Cancel", 101);
00086    b2->sigClick.connect(SigC::slot( *this, &SoundSettings::buttonEvent ));
00087 
00088    sigClose.connect( SigC::slot( *this, &SoundSettings::closeWindow ));
00089    
00090 
00091    PG_Button* b3 = new PG_Button(this, PG_Rect( Width() -100, 25, 90, 20 ), "Diagnostics" );
00092    b3->sigClick.connect( SigC::slot( *this, &SoundSettings::diag));
00093 
00094    // caller = c;
00095    // SetInputFocus();
00096 }
00097 
00098 
00099 void SoundSettings::updateSettings()
00100 {
00101    SoundSystem::getInstance()->setMusicVolume( CGameOptions::Instance()->sound.musicVolume );
00102    SoundSystem::getInstance()->setEffectVolume( CGameOptions::Instance()->sound.soundVolume );
00103    SoundSystem::getInstance()->setEffectsMute( CGameOptions::Instance()->sound.muteEffects );
00104    if ( CGameOptions::Instance()->sound.muteMusic )
00105       SoundSystem::getInstance()->pauseMusic();
00106    else
00107       SoundSystem::getInstance()->resumeMusic();
00108 
00109 }
00110 
00111 bool SoundSettings::radioButtonEvent( PG_RadioButton* button, bool state)
00112 {
00113    if ( button->GetID() == 1 )
00114       CGameOptions::Instance()->sound.muteMusic = !state;
00115    if ( button->GetID() == 2 )
00116       CGameOptions::Instance()->sound.muteEffects = !state;
00117    updateSettings();
00118    return true;
00119 }
00120 
00121 
00122 bool SoundSettings::eventScrollTrack(PG_ScrollBar* slider, long data)
00123 {
00124    if(slider->GetID() == 21) {
00125       CGameOptions::Instance()->sound.musicVolume = data;
00126       CGameOptions::Instance()->setChanged();
00127       updateSettings();
00128       return true;
00129    }
00130 
00131    if(slider->GetID() == 31) {
00132       CGameOptions::Instance()->sound.soundVolume = data;
00133       CGameOptions::Instance()->setChanged();
00134       updateSettings();
00135       return true;
00136    }
00137    return false;
00138 }
00139 
00140 
00141 bool SoundSettings::diag()
00142 {
00143    ASCString text = SoundSystem::getInstance()->getDiagnosticText();
00144    ViewFormattedText vft( "Sound Diagnostics", text, PG_Rect( -1, -1, 500, 500 ));
00145    vft.Show();
00146    vft.RunModal();
00147    return true;
00148 }
00149 
00150 
00151 bool SoundSettings::buttonEvent( PG_Button* button )
00152 {
00153    quitModalLoop(2);
00154    CGameOptions::Instance()->sound = sSettings;
00155    updateSettings();
00156    return true;
00157 }
00158 
00159 void SoundSettings::soundSettings(PG_MessageObject* caller)
00160 {
00161    // printf("c1c %d \n", ticker );
00162    SoundSettings wnd1(NULL, PG_Rect(50,50,500,300), caller);
00163    // printf("c2c %d \n", ticker );
00164    wnd1.Show();
00165    // printf("c3c %d \n", ticker );
00166    wnd1.RunModal();
00167    // printf("c4c %d \n", ticker );
00168 }
00169 

Generated on Tue Jun 24 01:27:52 2008 for Advanced Strategic Command by  doxygen 1.4.2