From 61ccf9a846e2c781dce3cb6c5ba134c4ac7161ed Mon Sep 17 00:00:00 2001 From: Cary Sandvig Date: Sat, 21 Apr 2001 00:44:53 +0000 Subject: [PATCH] woo! --- direct/src/gui/GuiGlobals.py | 21 +++++----- direct/src/showbase/ShowBase.py | 69 +++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+), 11 deletions(-) diff --git a/direct/src/gui/GuiGlobals.py b/direct/src/gui/GuiGlobals.py index 3497c6ee53..23bdecc192 100644 --- a/direct/src/gui/GuiGlobals.py +++ b/direct/src/gui/GuiGlobals.py @@ -36,11 +36,11 @@ def setDefaultDrawOrder(newDrawOrder): def getNewRolloverFunctor(sound = None): val = None - if base.wantSound: - if sound: - roll = sound - else: - roll = loader.loadSound("phase_3/audio/sfx/GUI_rollover.mp3") + if sound: + roll = sound + else: + roll = base.loadSfx("phase_3/audio/sfx/GUI_rollover.mp3") + if roll: val = AudioGuiFunctor(roll) else: val = AudioGuiFunctor() @@ -48,12 +48,11 @@ def getNewRolloverFunctor(sound = None): def getNewClickFunctor(sound = None): val = None - if base.wantSound: - if sound: - click = sound - else: - click = loader.loadSound( - "phase_3/audio/sfx/GUI_create_toon_fwd.mp3") + if sound: + click = sound + else: + click = base.loadSfx("phase_3/audio/sfx/GUI_create_toon_fwd.mp3") + if click: val = AudioGuiFunctor(click) else: val = AudioGuiFunctor() diff --git a/direct/src/showbase/ShowBase.py b/direct/src/showbase/ShowBase.py index 37d667a1b8..36e7135f99 100644 --- a/direct/src/showbase/ShowBase.py +++ b/direct/src/showbase/ShowBase.py @@ -37,6 +37,12 @@ class ShowBase: # Store dconfig variables self.wantTk = self.config.GetBool('want-tk', 0) self.wantSound = self.config.GetBool('want-sound', 1) + if not self.wantSound: + AudioManager.setAllSoundActive(0) + self.wantSfx = AudioManager.getSfxActive() + self.wantMusic = AudioManager.getMusicActive() + if not (self.wantSfx or self.wantMusic): + self.wantSound = None self.wantDIRECT = self.config.GetBool('want-directtools', 0) self.wantStats = self.config.GetBool('want-stats', 0) @@ -228,6 +234,69 @@ class ShowBase: if self.wantSound: AudioManager.spawnUpdate() + def loadSfx(self, name): + if name: + if base.wantSfx: + s = loader.loadSound(name) + return s + return None + + def loadMusic(self, name): + if name: + if base.wantMusic: + m = loader.loadSound(name) + return m + return None + + def unloadSfx(self, sfx): + if sfx: + loader.unloadSound(sfx) + + def unloadMusic(self, music): + if music: + loader.unloadSound(music) + + def playSfx(self, sfx, looping = None, interupt = 1, volume = None): + if sfx: + if base.wantSfx: + if not interupt: + if not (sfx.status() == AudioSound.PLAYING): + AudioManager.play(sfx) + else: + AudioManager.play(sfx) + if looping: + AudioManager.setLoop(sfx, 1) + if volume: + AudioManager.setVolume(sfx, volume) + + def playMusic(self, music, looping = None, interupt = 1, volume = None, + restart = None): + if music: + if base.wantMusic: + if not interupt: + if not (music.status() == AudioSound.PLAYING): + AudioManager.plsy(music) + else: + AudioManager.play(music) + if looping: + AudioManager.setLoop(music, 1) + if volume: + AudioManager.setVolume(music, volume) + if restart: + restart[0].accept("restart-music", restart[1]) + + def stopSfx(self, sfx): + if sfx: + if base.wantSfx: + AudioManager.stop(sfx) + + def stopMusic(self, music, restart = None): + if music: + if base.wantMusic: + AudioManager.stop(music) + if restart: + restart[0].ignore("restart-music") + def dataloop(self, state): # traverse the data graph. This reads all the control # inputs (from the mouse and keyboard, for instance) and also