Mercurial > rinkhals
comparison gamelib/mainmenu.py @ 532:0667189a5973
New load level dialog.
author | Simon Cross <hodgestar@gmail.com> |
---|---|
date | Fri, 27 Nov 2009 21:28:20 +0000 |
parents | b112bcf4d435 |
children | 296c73dcd286 |
comparison
equal
deleted
inserted
replaced
531:452cde9af2a2 | 532:0667189a5973 |
---|---|
5 import constants | 5 import constants |
6 import engine | 6 import engine |
7 import imagecache | 7 import imagecache |
8 import gameboard | 8 import gameboard |
9 import savegame | 9 import savegame |
10 import loadlevel | |
10 | 11 |
11 def make_main_menu(level): | 12 def make_main_menu(level): |
12 """Create a main menu""" | 13 """Create a main menu""" |
13 main_menu = MainMenu(level) | 14 main_menu = MainMenu(level) |
14 | 15 |
29 | 30 |
30 class MainMenu(gui.Table): | 31 class MainMenu(gui.Table): |
31 def __init__(self, level, **params): | 32 def __init__(self, level, **params): |
32 gui.Table.__init__(self, **params) | 33 gui.Table.__init__(self, **params) |
33 self.mode = None | 34 self.mode = None |
35 self.level_name = level.level_name | |
34 | 36 |
35 def fullscreen_toggled(): | 37 def fullscreen_toggled(): |
36 pygame.display.toggle_fullscreen() | 38 pygame.display.toggle_fullscreen() |
37 | 39 |
38 def quit_pressed(): | 40 def quit_pressed(): |
40 | 42 |
41 def start_game(): | 43 def start_game(): |
42 pygame.event.post(engine.START_DAY) | 44 pygame.event.post(engine.START_DAY) |
43 | 45 |
44 def choose_level(): | 46 def choose_level(): |
45 pygame.event.post(engine.GO_LEVEL_SCREEN) | 47 def load_func(new_level): |
48 pygame.event.post(pygame.event.Event(engine.DO_LOAD_LEVEL, level=new_level)) | |
49 self.level_name = new_level.level_name | |
50 self.redraw() | |
51 loadlevel.LoadLevelDialog(level, load_func).open() | |
46 | 52 |
47 def load_game(): | 53 def load_game(): |
48 savegame.RestoreDialog(gameboard.GameBoard.restore_game).open() | 54 savegame.RestoreDialog(gameboard.GameBoard.restore_game).open() |
49 | 55 |
50 def help_pressed(): | 56 def help_pressed(): |
61 change_button = gui.Button('Choose level') | 67 change_button = gui.Button('Choose level') |
62 change_button.connect(gui.CLICK, choose_level) | 68 change_button.connect(gui.CLICK, choose_level) |
63 self.tr() | 69 self.tr() |
64 self.td(change_button, **td_kwargs) | 70 self.td(change_button, **td_kwargs) |
65 | 71 |
66 start_button = gui.Button(level.level_name) | 72 self.start_button = gui.Button(level.level_name) |
67 start_button.connect(gui.CLICK, start_game) | 73 self.start_button.connect(gui.CLICK, start_game) |
68 self.tr() | 74 self.tr() |
69 self.td(start_button, **td_kwargs) | 75 self.td(self.start_button, **td_kwargs) |
70 | 76 |
71 loadgame_button = gui.Button('Restore Game') | 77 loadgame_button = gui.Button('Restore Game') |
72 loadgame_button.connect(gui.CLICK, load_game) | 78 loadgame_button.connect(gui.CLICK, load_game) |
73 self.tr() | 79 self.tr() |
74 self.td(loadgame_button, **td_kwargs) | 80 self.td(loadgame_button, **td_kwargs) |
88 # self.tr() | 94 # self.tr() |
89 # self.td(fullscreen_toggle, **td_kwargs) | 95 # self.td(fullscreen_toggle, **td_kwargs) |
90 | 96 |
91 self.tr() | 97 self.tr() |
92 self.td(quit_button, **td_kwargs) | 98 self.td(quit_button, **td_kwargs) |
99 | |
100 def redraw(self): | |
101 self.start_button.value = self.level_name |