5 import pygame.locals as pgl
7 from naja.constants import KEYS, PALETTE
8 from naja.events import SceneChangeEvent, QuitGameEvent
9 from naja.scenes.scene import Scene
10 from naja.scenes.credits import CreditsScene
11 from naja.scenes.game import GameScene
12 from naja.scenes.howto import HowtoScene
13 from naja.scenes.load_save import LoadGameScene, SaveGameScene
14 from naja.scenes.new_game import NewGameScene
15 from naja.widgets.selector import SelectorWidget
16 from naja.widgets.text import TextWidget
19 class MenuScene(Scene):
20 def __init__(self, state):
21 super(MenuScene, self).__init__(state)
22 selector = SelectorWidget()
28 (100, y_offset), 'Resume Game', colour=PALETTE.WHITE,
29 unselectable_colour=PALETTE.GREY)
30 resume.add_callback('click', self.scene_callback(GameScene))
31 resume.set_selectable_callback(lambda: state is not None)
35 new = TextWidget((100, y_offset), 'New Game', colour=PALETTE.WHITE)
36 new.add_callback('click', self.scene_callback(NewGameScene))
40 load = TextWidget((100, y_offset), 'Load', colour=PALETTE.WHITE)
41 load.add_callback('click', self.scene_callback(LoadGameScene))
46 (100, y_offset), 'Save', colour=PALETTE.WHITE,
47 unselectable_colour=PALETTE.GREY)
48 save.add_callback('click', self.scene_callback(SaveGameScene))
49 save.set_selectable_callback(lambda: state is not None)
54 (100, y_offset), 'How To Play', fontsize=32, colour='white')
56 'click', lambda event: SceneChangeEvent.post(HowtoScene))
60 credits = TextWidget((100, y_offset), 'Credits', colour=PALETTE.WHITE)
61 credits.add_callback('click', self.scene_callback(CreditsScene))
65 quit = TextWidget((100, y_offset), 'Quit', colour=PALETTE.WHITE)
66 quit.add_callback('click', lambda event: QuitGameEvent.post())
69 def scene_callback(self, scene_class):
70 return lambda event: SceneChangeEvent.post(scene_class)
72 def handle_scene_event(self, ev):
73 if ev.type == pgl.KEYDOWN:
74 if ev.key in KEYS.QUIT: