Saved games can now be loaded as well.
[naja.git] / naja / scenes / menu.py
1 """
2 Main menu scene.
3 """
4
5 import pygame.locals as pgl
6
7 from naja.constants import KEYS
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.widgets.selector import SelectorWidget
14 from naja.widgets.text import TextWidget
15
16
17 class MenuScene(Scene):
18     def __init__(self, state):
19         super(MenuScene, self).__init__(state)
20         selector = SelectorWidget()
21         self.add(selector)
22
23         run_game = TextWidget((100, 100), 'Game', fontsize=32, colour='white')
24         run_game.add_callback(
25             'click', lambda event: SceneChangeEvent.post(GameScene))
26         selector.add(run_game)
27
28         credits = TextWidget(
29             (100, 150), 'Credits', fontsize=32, colour='white')
30         credits.add_callback(
31             'click', lambda event: SceneChangeEvent.post(CreditsScene))
32         selector.add(credits)
33
34         load = TextWidget((100, 200), 'Load', fontsize=32, colour='white')
35         load.add_callback(
36             'click', lambda event: SceneChangeEvent.post(LoadGameScene))
37         selector.add(load)
38
39         save = TextWidget((100, 250), 'Save', fontsize=32, colour='white')
40         save.add_callback(
41             'click', lambda event: SceneChangeEvent.post(SaveGameScene))
42         selector.add(save)
43
44         quit = TextWidget((100, 300), 'Quit', fontsize=32, colour='white')
45         quit.add_callback('click', lambda event: QuitGameEvent.post())
46         selector.add(quit)
47
48     def handle_scene_event(self, ev):
49         if ev.type == pgl.KEYDOWN:
50             if ev.key in KEYS.QUIT:
51                 QuitGameEvent.post()
52                 return