6 import pygame.locals as pgl
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
17 class PuzzleListScene(Scene):
18 def __init__(self, state):
19 super(PuzzleListScene, self).__init__(state)
21 background = ImageBox(
22 (0, 0), "screens/splash.png")
25 selector = SelectorWidget()
29 y_offset, y_diff = 270, 36
34 (x_offset, y_offset), 'CHOOSE PUZZLE', colour='white',
38 for puzzle in PUZZLES:
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,
46 puzzle_but.add_callback('click', callback)
47 selector.add(puzzle_but)
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)
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)