Mercurial > skaapsteker
changeset 110:f64c38c5512d
Use TextChoice data in menu screen (it's no longer hacked to death)
author | Stefano Rivera <stefano@rivera.za.net> |
---|---|
date | Mon, 04 Apr 2011 21:34:04 +0200 |
parents | 982f34d0aac0 |
children | 601d2a500e4a |
files | skaapsteker/menuscene.py |
diffstat | 1 files changed, 12 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- 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)