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.load_save import LoadGameScene, SaveGameScene
13 from naja.scenes.new_game import NewGameScene
14 from naja.widgets.selector import SelectorWidget
15 from naja.widgets.text import TextWidget
18 class MenuScene(Scene):
19 def __init__(self, state):
20 super(MenuScene, self).__init__(state)
21 selector = SelectorWidget()
27 (100, y_offset), 'Resume Game', colour=PALETTE.WHITE,
28 unselectable_colour=PALETTE.GREY)
29 resume.add_callback('click', self.scene_callback(GameScene))
30 resume.set_selectable_callback(lambda: state is not None)
34 new = TextWidget((100, y_offset), 'New Game', colour=PALETTE.WHITE)
35 new.add_callback('click', self.scene_callback(NewGameScene))
39 load = TextWidget((100, y_offset), 'Load', colour=PALETTE.WHITE)
40 load.add_callback('click', self.scene_callback(LoadGameScene))
45 (100, y_offset), 'Save', colour=PALETTE.WHITE,
46 unselectable_colour=PALETTE.GREY)
47 save.add_callback('click', self.scene_callback(SaveGameScene))
48 save.set_selectable_callback(lambda: state is not None)
52 credits = TextWidget((100, y_offset), 'Credits', colour=PALETTE.WHITE)
53 credits.add_callback('click', self.scene_callback(CreditsScene))
57 quit = TextWidget((100, y_offset), 'Quit', colour=PALETTE.WHITE)
58 quit.add_callback('click', lambda event: QuitGameEvent.post())
61 def scene_callback(self, scene_class):
62 return lambda event: SceneChangeEvent.post(scene_class)
64 def handle_scene_event(self, ev):
65 if ev.type == pgl.KEYDOWN:
66 if ev.key in KEYS.QUIT: