diff options
author | Alan Aguiar <alanjas@hotmail.com> | 2013-12-31 20:21:37 (GMT) |
---|---|---|
committer | Alan Aguiar <alanjas@hotmail.com> | 2013-12-31 20:21:37 (GMT) |
commit | 40d5cfa7da883d512d1b8cdf32f5555b83e7954f (patch) | |
tree | 2ad389ef81d293e9d1af2995eecdf9ecd8fec37f | |
parent | 2347d4f1eb0b217e0e3ea1ccfc09a3b9cc14854b (diff) |
add button for sound control
-rwxr-xr-x | activity.py | 21 | ||||
-rwxr-xr-x | reversi.py | 17 |
2 files changed, 31 insertions, 7 deletions
diff --git a/activity.py b/activity.py index bfa3cee..9ff5d2a 100755 --- a/activity.py +++ b/activity.py @@ -21,7 +21,7 @@ import reversi class ReversiActivity(activity.Activity): def __init__(self, handle): activity.Activity.__init__(self, handle) - + self.sound_enable = True self.game = reversi.ReversiController(self) self.build_toolbar() self._pygamecanvas = sugargame.canvas.PygameCanvas(self) @@ -72,6 +72,15 @@ class ReversiActivity(activity.Activity): item.add(self.current_label) toolbar_box.toolbar.insert(item, -1) + separator = gtk.SeparatorToolItem() + toolbar_box.toolbar.insert(separator, -1) + separator.show() + + sound_button = ToolButton('speaker-muted-100') + sound_button.set_tooltip(_('Sound')) + sound_button.connect('clicked', self.sound_control) + toolbar_box.toolbar.insert(sound_button, -1) + # separator and stop separator = gtk.SeparatorToolItem() separator.props.draw = False @@ -239,3 +248,13 @@ class ReversiActivity(activity.Activity): def set_current_player(self, player): self.current_label.set_text(' %s' % player) + def sound_control(self, button): + self.sound_enable = not self.sound_enable + self.game.change_sound(self.sound_enable) + if not self.sound_enable: + button.set_icon('speaker-muted-000') + button.set_tooltip(_('No sound')) + else: + button.set_icon('speaker-muted-100') + button.set_tooltip(_('Sound')) + @@ -370,9 +370,9 @@ class RestartButton: def update_image(self): self.image = pygame.Surface(self.rect.size) self.image.fill(background_color) + self.image.set_colorkey(background_color) top_ellipse_rect = pygame.Rect((0, 0), self.rect.size) - #pygame.draw.rect(self.image, (0, 0, 0), top_ellipse_rect, 1) # this line is for debugging only top_ellipse_rect.height = self.rect.height * 0.2 pygame.draw.ellipse(self.image, (0, 0, 0), top_ellipse_rect, 3) @@ -667,6 +667,7 @@ class ReversiController: def __init__(self, parent=None): self.parent = parent + self.sound_enable = True random.seed() self.clock = pygame.time.Clock() @@ -710,11 +711,12 @@ class ReversiController: self.set_state("EndGame") def play_sound(self, sound_name): - if not self.sounds.has_key(sound_name): - print "ReversiController.play_sound(\"%s\") - WARNING, sound does not exist!" % str(sound_name) - else: - sound = self.sounds[sound_name] - sound.play() + if self.sound_enable: + if not self.sounds.has_key(sound_name): + print "ReversiController.play_sound(\"%s\") - WARNING, sound does not exist!" % str(sound_name) + else: + sound = self.sounds[sound_name] + sound.play() def play_put_down_piece_sound(self, num_cells_flipped): #possible_sound_names = ['putdownflip2', 'putdownflip3', 'putdownflip4', 'putdownflip5', 'putdownflip'] @@ -776,6 +778,9 @@ class ReversiController: def set_current_player(self, player): if self.parent is not None: self.parent.set_current_player(player) + + def change_sound(self, sound): + self.sound_enable = sound def run(self): global screen_size |