I feel nothing for you.
[naja.git] / naja / scenes / puzzlelist.py
1 """
2 Load and save scenes.
3 """
4
5 import functools
6 import pygame.locals as pgl
7
8 from naja.constants import KEYS, PUZZLES
9 from naja.events import SceneChangeEvent, LoadGameEvent
10 from naja.gamestate import GameState, load_location_deck
11 from naja.scenes.scene import Scene
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 PuzzleListScene(Scene):
18     def __init__(self, state):
19         super(PuzzleListScene, self).__init__(state)
20
21         background = ImageBox(
22             (0, 0), "screens/splash.png")
23         self.add(background)
24
25         selector = SelectorWidget()
26         selector.position = 1
27         self.add(selector)
28
29         y_offset, y_diff = 270, 36
30         x_offset = 400
31
32         y_offset += y_diff
33         title = TextWidget(
34             (x_offset, y_offset), 'CHOOSE PUZZLE', colour='white',
35             centre=True)
36         self.add(title)
37
38         for puzzle in PUZZLES:
39             y_offset += y_diff
40             deck = load_location_deck('puzzles/%s' % puzzle)
41             puzzle_but = TextWidget(
42                (x_offset, y_offset), deck['description'], fontsize=32,
43                colour='white', centre=True)
44             callback = functools.partial(self.start_puzzle_game,
45                                          puzzle=puzzle)
46             puzzle_but.add_callback('click', callback)
47             selector.add(puzzle_but)
48
49     def start_puzzle_game(self, event, puzzle=None):
50         from naja.scenes.game import GameScene
51         level = 'puzzles/%s' % puzzle
52         state = GameState.new(deck=level)
53         LoadGameEvent.post(state=state)
54         SceneChangeEvent.post(GameScene)
55
56     def handle_scene_event(self, ev):
57         if ev.type == pgl.KEYDOWN and ev.key in KEYS.QUIT:
58             from naja.scenes.menu import MenuScene
59             SceneChangeEvent.post(MenuScene)
60             return