# HG changeset patch # User Stefano Rivera # Date 1301945644 -7200 # Node ID f64c38c5512d76c739d1cea338053ea18ec69520 # Parent 982f34d0aac03c46de2e9efa6bc1546b7459c06e Use TextChoice data in menu screen (it's no longer hacked to death) diff -r 982f34d0aac0 -r f64c38c5512d skaapsteker/menuscene.py --- a/skaapsteker/menuscene.py Mon Apr 04 21:30:39 2011 +0200 +++ b/skaapsteker/menuscene.py Mon Apr 04 21:34:04 2011 +0200 @@ -10,22 +10,24 @@ super(MenuScene, self).__init__() self.widgets.append(Text("MENU:", (50, 50), color='white', size=48)) self.cur_game = cur_game - if cur_game is None: - self.choice = TextChoice(("level1", "level2", "Quit"), (50, 100), color='white') - else: - self.choice = TextChoice(("level1", "level2", "Resume Game", "Quit"), (50, 100), color='white') + menu_options = [ + ('Level 1', 'level1'), + ('Level 2', 'level2'), + ('Quit', 'quit'), + ] + if cur_game is not None: + menu_options.insert(0, ('Resume Game', 'resume')) + self.choice = TextChoice(menu_options, (50, 100), color='white') self.choice.callbacks.append(self.selected) self.widgets.append(self.choice) def selected(self, option, data): "Callback from menu TextChoice" - if option == 0: - ChangeScene.post(LevelScene('level1')) - elif option == 1: - ChangeScene.post(LevelScene('level2')) - elif option == len(self.choice.options) - 1: + if data.startswith('level'): + ChangeScene.post(LevelScene(data)) + elif data == 'quit': pygame.event.post(pygame.event.Event(QUIT)) - elif option == 2 and self.cur_game is not None: + elif data == 'resume': self.cur_game.thaw() ChangeScene.post(self.cur_game)