Mercurial > rinkhals
comparison gamelib/mainmenu.py @ 560:8cd13b82585e
Allow ESC to exit high score menu and then still exit game if pressed a second time.
author | Simon Cross <hodgestar@gmail.com> |
---|---|
date | Sat, 28 Nov 2009 18:27:59 +0000 |
parents | 296c73dcd286 |
children | a8dde729000a |
comparison
equal
deleted
inserted
replaced
559:b71b7fcf6dc1 | 560:8cd13b82585e |
---|---|
1 """Main menu.""" | 1 """Main menu.""" |
2 | 2 |
3 from pgu import gui | 3 from pgu import gui |
4 from pygame.locals import QUIT, KEYDOWN, K_ESCAPE | |
4 import pygame | 5 import pygame |
5 import constants | 6 import constants |
6 import engine | 7 import engine |
7 import imagecache | 8 import imagecache |
8 import gameboard | 9 import gameboard |
27 gui.Container.paint(self, s) | 28 gui.Container.paint(self, s) |
28 | 29 |
29 def get_mode(self): | 30 def get_mode(self): |
30 return self.widgets[0].mode | 31 return self.widgets[0].mode |
31 | 32 |
33 def event(self, e): | |
34 if gui.Container.event(self, e): | |
35 return True | |
36 if e.type is KEYDOWN: | |
37 if e.key == K_ESCAPE: | |
38 pygame.event.post(pygame.event.Event(QUIT)) | |
39 return True | |
40 elif e.key == K_s: | |
41 pygame.event.post(engine.START_DAY) | |
42 return True | |
43 elif e.key == K_i: | |
44 pygame.event.post(engine.GO_HELP_SCREEN) | |
45 return True | |
46 return False | |
47 | |
48 | |
32 class MainMenu(gui.Table): | 49 class MainMenu(gui.Table): |
33 def __init__(self, level, **params): | 50 def __init__(self, level, **params): |
34 gui.Table.__init__(self, **params) | 51 gui.Table.__init__(self, **params) |
35 self.mode = None | 52 self.mode = None |
36 self.level = level | 53 self.level = level |
53 | 70 |
54 def load_game(): | 71 def load_game(): |
55 savegame.RestoreDialog(gameboard.GameBoard.restore_game).open() | 72 savegame.RestoreDialog(gameboard.GameBoard.restore_game).open() |
56 | 73 |
57 def scores_pressed(): | 74 def scores_pressed(): |
58 scoreboard = gameover.Scoreboard(self.level) | 75 gameover.ScoreDialog(self.level).open() |
59 title = gui.Label("High Scores for Level %s" % self.level.level_name) | |
60 gui.Dialog(title, scoreboard).open() | |
61 | 76 |
62 def help_pressed(): | 77 def help_pressed(): |
63 pygame.event.post(engine.GO_HELP_SCREEN) | 78 pygame.event.post(engine.GO_HELP_SCREEN) |
64 | 79 |
65 style = { | 80 style = { |
103 # fullscreen_toggle = gui.Button("Toggle Fullscreen") | 118 # fullscreen_toggle = gui.Button("Toggle Fullscreen") |
104 # fullscreen_toggle.connect(gui.CLICK, fullscreen_toggled) | 119 # fullscreen_toggle.connect(gui.CLICK, fullscreen_toggled) |
105 # self.tr() | 120 # self.tr() |
106 # self.td(fullscreen_toggle, **td_kwargs) | 121 # self.td(fullscreen_toggle, **td_kwargs) |
107 | 122 |
108 | |
109 def redraw(self): | 123 def redraw(self): |
110 self.start_button.value = self.level.level_name | 124 self.start_button.value = self.level.level_name |