Changeset 255
- Timestamp:
- 01/07/07 21:45:29 (5 years ago)
- Files:
-
- 1 modified
-
trunk/src/pyspacewar/ui.py (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/pyspacewar/ui.py
r254 r255 1433 1433 def init_menu(self): 1434 1434 """Initialize the mode.""" 1435 def title(label, on): 1436 return label + '\t' + (on and 'on' or 'off') 1435 1437 self.menu_items = [ 1436 1438 ('Screen size\t%dx%d' % self.ui.fullscreen_mode, 1437 1439 self.ui.screen_resolution_menu), 1438 (self.ui.fullscreen and 'Full screen mode\ton' 1439 or 'Full screen mode\toff', 1440 (title('Full screen mode', self.ui.fullscreen), 1440 1441 self.toggle_fullscreen), 1441 (self.ui.show_missile_trails and 'Missile orbits\ton' 1442 or 'Missile orbits\toff', 1442 (title('Missile orbits', self.ui.show_missile_trails), 1443 1443 self.toggle_missile_orbits), 1444 (self.ui.sound_in_vacuum and 'Sound in vacuum\ton' 1445 or 'Sound in vacuum\toff', 1444 (title('Music', self.ui.music), 1445 self.toggle_music), 1446 (title('Sound', self.ui.sound), 1447 self.toggle_sound), 1448 (title('Sound in vacuum', self.ui.sound_in_vacuum), 1446 1449 self.toggle_sound_in_vacuum), 1447 1450 ('Controls', self.ui.controls_menu), … … 1471 1474 """Toggle missile orbits and reflect the setting in the menu.""" 1472 1475 self.ui.toggle_missile_orbits() 1476 self.reinit_menu() 1477 1478 def toggle_music(self): 1479 """Toggle music and reflect the setting in the menu.""" 1480 self.ui.toggle_music() 1481 self.reinit_menu() 1482 1483 def toggle_sound(self): 1484 """Toggle sound effects and reflect the setting in the menu.""" 1485 self.ui.toggle_sound() 1473 1486 self.reinit_menu() 1474 1487 … … 1779 1792 fullscreen_mode = None # Desired video mode (w, h) 1780 1793 show_missile_trails = True # Show missile trails by default 1794 music = True # Do we have background music? 1795 sound = True # Do we have sound effects? 1781 1796 sound_in_vacuum = True # Can you hear what happens to AI ships? 1782 1797 show_debug_info = False # Hide debug info by default … … 1829 1844 self.show_missile_trails = config.getboolean('video', 1830 1845 'show_missile_trails') 1831 self.sound_in_vacuum = config.getboolean('sound', 1832 'sound_in_vacuum') 1846 self.music = config.getboolean('sound', 'music') 1847 self.sound = config.getboolean('sound', 'sound') 1848 self.sound_in_vacuum = config.getboolean('sound', 'sound_in_vacuum') 1833 1849 for action in self.controls: 1834 1850 key = config.get('controls', action) … … 1862 1878 str(self.show_missile_trails)) 1863 1879 config.add_section('sound') 1880 config.set('sound', 'music', str(self.music)) 1881 config.set('sound', 'sound', str(self.sound)) 1864 1882 config.set('sound', 'sound_in_vacuum', str(self.sound_in_vacuum)) 1865 1883 config.add_section('controls') … … 1997 2015 config.read([find('sounds', 'sounds.ini')]) 1998 2016 self.sounds = {} 1999 self.sound_looping = {}2017 self.sound_looping = sets.Set() 2000 2018 for name in ['thruster', 'fire', 'bounce', 'hit', 'explode', 'respawn', 2001 2019 'menu']: … … 2023 2041 self.music_files[what] = find('music', filename) 2024 2042 2025 def play_music(self, which ):2043 def play_music(self, which, restart=False): 2026 2044 """Loop the music file for a certain mode.""" 2027 if which == self.now_playing: 2045 if which == self.now_playing and not restart: 2046 return 2047 self.now_playing = which 2048 if not self.music: 2028 2049 return 2029 2050 filename = self.music_files.get(which) … … 2037 2058 print "pyspacewar: could not load %s" % filename 2038 2059 pygame.mixer.music.stop() 2039 self.now_playing = which2040 2060 2041 2061 def play_sound(self, which): 2042 2062 """Play a certain sound effect.""" 2043 if which in self.sounds :2063 if which in self.sounds and self.sound: 2044 2064 self.sounds[which].play() 2045 2065 2046 2066 def start_sound(self, which): 2047 2067 """Start looping a certain sound effect.""" 2048 if not self.sound_looping.get(which) and which in self.sounds: 2049 self.sounds[which].play(-1) 2050 self.sound_looping[which] = True 2068 if which not in self.sound_looping and which in self.sounds: 2069 if self.sound: 2070 self.sounds[which].play(-1) 2071 self.sound_looping.add(which) 2051 2072 2052 2073 def stop_sound(self, which): 2053 2074 """Stop playing a certain sound effect.""" 2054 if self.sound_looping.get(which) and which in self.sounds:2075 if which in self.sound_looping: 2055 2076 self.sounds[which].stop() 2056 self.sound_looping [which] = False2077 self.sound_looping.remove(which) 2057 2078 2058 2079 def _init_fonts(self): … … 2307 2328 self.show_missile_trails = not self.show_missile_trails 2308 2329 2330 def toggle_music(self): 2331 """Toggle music.""" 2332 self.music = not self.music 2333 if self.music: 2334 self.play_music(self.now_playing, restart=True) 2335 else: 2336 pygame.mixer.music.stop() 2337 2338 def toggle_sound(self): 2339 """Toggle sound effects.""" 2340 self.sound = not self.sound 2341 for sound in self.sound_looping: 2342 if self.sound: 2343 self.sounds[sound].play(-1) 2344 else: 2345 self.sounds[sound].stop() 2346 2309 2347 def toggle_sound_in_vacuum(self): 2310 2348 """Toggle sound in vacuum."""
