Merge branch 'master' of git://ctpug.org.za/naja
[naja.git] / naja / scenes / introduction.py
1 """
2 Load and save scenes.
3 """
4
5 import pygame.locals as pgl
6
7 from naja.constants import KEYS
8 from naja.events import SceneChangeEvent, LoadGameEvent
9 from naja.gamestate import GameState
10 from naja.scenes.scene import Scene
11 from naja.scenes.howto import HowtoScene
12 from naja.widgets.image_box import ImageBox
13 from naja.widgets.selector import SelectorWidget
14 from naja.widgets.text import TextWidget
15
16
17 class IntroductionScene(Scene):
18     def __init__(self, state):
19         super(IntroductionScene, self).__init__(state)
20
21         background = ImageBox(
22             (0, 0), "screens/splash.png")
23         self.add(background)
24
25         selector = SelectorWidget()
26         self.add(selector)
27
28         y_offset, y_diff = 270, 40
29         x_offset = 400
30
31         y_offset += y_diff
32         title = TextWidget(
33             (x_offset, y_offset), 'Getting started', colour='white',
34             centre=True)
35         self.add(title)
36
37         y_offset += y_diff
38         howto = TextWidget(
39             (x_offset, y_offset), 'How to play', colour='white', centre=True)
40         howto.add_callback('click', self.howto_scene)
41         selector.add(howto)
42
43         y_offset += y_diff
44         intro = TextWidget(
45             (x_offset, y_offset), 'Introductory Level', colour='white',
46             centre=True)
47         intro.add_callback('click', self.introduction_level)
48         selector.add(intro)
49
50         y_offset += 2*y_diff
51         back = TextWidget(
52             (x_offset, y_offset), 'Press ESC to return to the main menu.',
53             colour='white', centre=True)
54         self.add(back)
55
56     def howto_scene(self, event):
57         SceneChangeEvent.post(HowtoScene)
58
59     def introduction_level(self, event):
60         from naja.scenes.game import GameScene
61         LoadGameEvent.post(state=GameState.new(deck='introduction'))
62         SceneChangeEvent.post(GameScene)
63
64     def handle_scene_event(self, ev):
65         if ev.type == pgl.KEYDOWN and ev.key in KEYS.QUIT:
66             from naja.scenes.menu import MenuScene
67             SceneChangeEvent.post(MenuScene)
68             return