Ignore:
Timestamp:
Apr 4, 2011, 7:34:04 PM (10 years ago)
Author:
Stefano Rivera <stefano@…>
Branch:
default
rebase_source:
4dcb4d7effd8162217153ceb155ef19ed8dd614f
Message:

Use TextChoice? data in menu screen (it's no longer hacked to death)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • skaapsteker/menuscene.py

    r109 r110  
    1111        self.widgets.append(Text("MENU:", (50, 50), color='white', size=48))
    1212        self.cur_game = cur_game
    13         if cur_game is None:
    14             self.choice = TextChoice(("level1", "level2", "Quit"), (50, 100), color='white')
    15         else:
    16             self.choice = TextChoice(("level1", "level2", "Resume Game", "Quit"), (50, 100), color='white')
     13        menu_options = [
     14            ('Level 1', 'level1'),
     15            ('Level 2', 'level2'),
     16            ('Quit', 'quit'),
     17        ]
     18        if cur_game is not None:
     19            menu_options.insert(0, ('Resume Game', 'resume'))
     20        self.choice = TextChoice(menu_options, (50, 100), color='white')
    1721        self.choice.callbacks.append(self.selected)
    1822        self.widgets.append(self.choice)
     
    2024    def selected(self, option, data):
    2125        "Callback from menu TextChoice"
    22         if option == 0:
    23             ChangeScene.post(LevelScene('level1'))
    24         elif option == 1:
    25             ChangeScene.post(LevelScene('level2'))
    26         elif option == len(self.choice.options) - 1:
     26        if data.startswith('level'):
     27            ChangeScene.post(LevelScene(data))
     28        elif data == 'quit':
    2729            pygame.event.post(pygame.event.Event(QUIT))
    28         elif option == 2 and self.cur_game is not None:
     30        elif data == 'resume':
    2931            self.cur_game.thaw()
    3032            ChangeScene.post(self.cur_game)
Note: See TracChangeset for help on using the changeset viewer.