fix cant turn off battle snds bug

This commit is contained in:
cxgeorge 2002-09-27 05:22:50 +00:00
parent e293c9cf9f
commit 907e6b55cb

View File

@ -50,8 +50,8 @@ class ShowBase:
self.screenshotExtension = self.config.GetString('screenshot-extension', 'jpg') self.screenshotExtension = self.config.GetString('screenshot-extension', 'jpg')
self.musicManager = None self.musicManager = None
self.musicManagerIsValid = None self.musicManagerIsValid = None
self.sfxManager = None self.sfxManagerList = []
self.sfxManagerIsValid = None self.sfxManagerIsValidList = []
self.wantDIRECT = self.config.GetBool('want-directtools', 0) self.wantDIRECT = self.config.GetBool('want-directtools', 0)
self.wantStats = self.config.GetBool('want-stats', 0) self.wantStats = self.config.GetBool('want-stats', 0)
@ -133,7 +133,7 @@ class ShowBase:
self.physicsMgrEnabled = 0 self.physicsMgrEnabled = 0
self.physicsMgrAngular = 0 self.physicsMgrAngular = 0
self.createAudioManager() self.createBaseAudioManagers()
self.createStats() self.createStats()
self.AppHasAudioFocus = 1 self.AppHasAudioFocus = 1
@ -495,52 +495,112 @@ class ShowBase:
if self.wantStats: if self.wantStats:
PStatClient.connect() PStatClient.connect()
def createAudioManager(self): def addSfxManager(self, extraSfxManager):
self.sfxManager = AudioManager.createAudioManager() # keep a list of sfx manager objects to apply settings to, since there may be others
self.sfxManagerIsValid=self.sfxManager!=None \ # in addition to the one we create here
and self.sfxManager.isValid() self.sfxManagerList.append(extraSfxManager)
if self.sfxManagerIsValid: newSfxManagerIsValid = (extraSfxManager!=None) and extraSfxManager.isValid()
self.sfxManager.setActive(self.sfxActive) self.sfxManagerIsValidList.append(newSfxManagerIsValid)
if newSfxManagerIsValid:
extraSfxManager.setActive(self.sfxActive)
def createBaseAudioManagers(self):
sfxManager = AudioManager.createAudioManager()
self.addSfxManager(sfxManager)
self.musicManager = AudioManager.createAudioManager() self.musicManager = AudioManager.createAudioManager()
self.musicManagerIsValid=self.musicManager!=None \ self.musicManagerIsValid=self.musicManager!=None \
and self.musicManager.isValid() and self.musicManager.isValid()
if self.musicManagerIsValid: if self.musicManagerIsValid:
self.musicManager.setActive(self.musicActive) self.musicManager.setActive(self.musicActive)
# Turn down the music globally
# Eventually we may want to control this in the options page # enableMusic/enableSoundEffects are meant to be called in response to a user request
self.musicManager.setVolume(0.7) # so sfxActive/musicActive represent how things *should* be, regardless of App/OS/HW state
def enableMusic(self, bEnableMusic):
# dont setActive(1) if no audiofocus
if self.AppHasAudioFocus and self.musicManagerIsValid:
self.musicManager.setActive(bEnableMusic)
self.musicActive = bEnableMusic
if bEnableMusic:
self.notify.debug("Enabling music")
else:
self.notify.debug("Disabling music")
def SetAllSfxEnables(self, bEnabled):
for i in range(len(self.sfxManagerList)):
if (self.sfxManagerIsValidList[i]):
self.sfxManagerList[i].setActive(bEnabled)
def enableSoundEffects(self, bEnableSoundEffects):
# dont setActive(1) if no audiofocus
if self.AppHasAudioFocus or (bEnableSoundEffects==0):
self.SetAllSfxEnables(bEnableSoundEffects)
self.sfxActive=bEnableSoundEffects
if bEnableSoundEffects:
self.notify.debug("Enabling sound effects")
else:
self.notify.debug("Disabling sound effects")
# enable/disableAllAudio allow a programmable global override-off for current audio settings.
# they're meant to be called when app loses audio focus (switched out), so we can turn off sound
# without affecting internal sfxActive/musicActive sound settings, so things
# come back ok when the app is switched back to
def disableAllAudio(self):
self.AppHasAudioFocus = 0
self.SetAllSfxEnables(0)
if self.musicManagerIsValid:
self.musicManager.setActive(0)
self.notify.debug("Disabling audio")
def enableAllAudio(self):
self.AppHasAudioFocus = 1
self.SetAllSfxEnables(self.sfxActive)
if self.musicManagerIsValid:
self.musicManager.setActive(self.musicActive)
self.notify.debug("Enabling audio")
def loadSfx(self, name): def loadSfx(self, name):
# showbase's sfxManager should always be at front of list
if(not self.sfxManagerIsValidList[0]):
# dont print a warning if mgr invalid, since they should already know
return None
sound = None
if (name): if (name):
sound=self.sfxManager.getSound(name) sound=self.sfxManagerList[0].getSound(name)
if sound == None: if sound == None:
self.notify.warning("Could not load sound file %s." % name) self.notify.warning("Could not load sound file %s." % name)
return sound return sound
def loadMusic(self, name): def loadMusic(self, name):
if(not self.musicManagerIsValid):
return None
sound = None
if (name): if (name):
sound=self.musicManager.getSound(name) sound=self.musicManager.getSound(name)
if sound == None: if sound == None:
self.notify.warning("Could not load music file %s." % name) self.notify.warning("Could not load music file %s." % name)
return sound return sound
def playSfx(self, sfx, looping = 0, interupt = 1, volume = None, def playSfx(self, sfx, looping = 0, interrupt = 1, volume = None, time = 0.0):
time = 0.):
if sfx: if sfx:
if volume != None: if volume != None:
sfx.setVolume(volume) sfx.setVolume(volume)
if interupt or (sfx.status() != AudioSound.PLAYING):
# dont start over if it's already playing, unless "interrupt" was specified
if interrupt or (sfx.status() != AudioSound.PLAYING):
sfx.setTime(time) sfx.setTime(time)
sfx.setLoop(looping) sfx.setLoop(looping)
sfx.play() sfx.play()
def playMusic(self, music, looping = 0, interupt = 1, volume = None, def playMusic(self, music, looping = 0, interrupt = 1, volume = None, time = 0.0):
time = 0.0):
if music: if music:
if volume != None: if volume != None:
music.setVolume(volume) music.setVolume(volume)
if interupt or (music.status() != AudioSound.PLAYING):
# if interrupt was set to 0, start over even if it's already playing
if interrupt or (music.status() != AudioSound.PLAYING):
music.setTime(time) music.setTime(time)
music.setLoop(looping) music.setLoop(looping)
music.play() music.play()
@ -901,43 +961,6 @@ class ShowBase:
state.frameIndex += 1 state.frameIndex += 1
return Task.cont return Task.cont
# these are meant to be called in response to a user request
def EnableMusic(self, bEnableMusic):
# dont setActive(1) if no audiofocus
if self.AppHasAudioFocus and self.musicManagerIsValid:
self.musicManager.setActive(bEnableMusic)
self.musicActive = bEnableMusic
if bEnableMusic:
self.notify.debug("Enabling music")
else:
self.notify.debug("Disabling music")
def EnableSoundEffects(self, bEnableSoundEffects):
# dont setActive(1) if no audiofocus
if self.AppHasAudioFocus and self.sfxManagerIsValid:
self.sfxManager.setActive(bEnableSoundEffects)
self.sfxActive=bEnableSoundEffects
if bEnableSoundEffects:
self.notify.debug("Enabling sound effects")
else:
self.notify.debug("Disabling sound effects")
# these are meant to be called by the sw when app loses audio focus (switched out)
def DisableAudio(self):
self.AppHasAudioFocus = 0
if self.sfxManagerIsValid:
self.sfxManager.setActive(0)
if self.musicManagerIsValid:
self.musicManager.setActive(0)
self.notify.debug("Disabling audio")
def EnableAudio(self):
self.AppHasAudioFocus = 1
if self.sfxManagerIsValid:
self.sfxManager.setActive(self.sfxActive)
if self.musicManagerIsValid:
self.musicManager.setActive(self.musicActive)
self.notify.debug("Enabling audio")
def run(self): def run(self):
self.taskMgr.run() self.taskMgr.run()