Hook the introduction into the menus
authorStefano Rivera <stefano@rivera.za.net>
Sat, 17 May 2014 19:31:39 +0000 (21:31 +0200)
committerStefano Rivera <stefano@rivera.za.net>
Sat, 17 May 2014 19:31:39 +0000 (21:31 +0200)
naja/scenes/howto.py
naja/scenes/introduction.py [new file with mode: 0644]
naja/scenes/menu.py

index cf6f3549fcf6d66eefd6375bde6b4992eb8259e7..4d341786d780968b739c96aa6589e39c266f1863 100644 (file)
@@ -62,7 +62,7 @@ class HowtoScene(Scene):
             box_width=740, view_port=(780, 540)))
 
     def handle_scene_event(self, ev):
-        from naja.scenes.menu import MenuScene
+        from naja.scenes.introduction import IntroductionScene
         if ev.type == pgl.KEYDOWN and ev.key in KEYS.QUIT:
-            SceneChangeEvent.post(MenuScene)
+            SceneChangeEvent.post(IntroductionScene)
             return
diff --git a/naja/scenes/introduction.py b/naja/scenes/introduction.py
new file mode 100644 (file)
index 0000000..95defaa
--- /dev/null
@@ -0,0 +1,68 @@
+"""
+Load and save scenes.
+"""
+
+import pygame.locals as pgl
+
+from naja.constants import KEYS
+from naja.events import SceneChangeEvent, LoadGameEvent
+from naja.gamestate import GameState
+from naja.scenes.scene import Scene
+from naja.scenes.howto import HowtoScene
+from naja.widgets.image_box import ImageBox
+from naja.widgets.selector import SelectorWidget
+from naja.widgets.text import TextWidget
+
+
+class IntroductionScene(Scene):
+    def __init__(self, state):
+        super(IntroductionScene, self).__init__(state)
+
+        background = ImageBox(
+            (0, 0), "screens/splash.png")
+        self.add(background)
+
+        selector = SelectorWidget()
+        self.add(selector)
+
+        y_offset, y_diff = 270, 40
+        x_offset = 400
+
+        y_offset += y_diff
+        title = TextWidget(
+            (x_offset, y_offset), 'Getting started', colour='white',
+            centre=True)
+        self.add(title)
+
+        y_offset += y_diff
+        howto = TextWidget(
+            (x_offset, y_offset), 'How to play', colour='white', centre=True)
+        howto.add_callback('click', self.howto_scene)
+        selector.add(howto)
+
+        y_offset += y_diff
+        intro = TextWidget(
+            (x_offset, y_offset), 'Introductory Level', colour='white',
+            centre=True)
+        intro.add_callback('click', self.introduction_level)
+        selector.add(intro)
+
+        y_offset += 2*y_diff
+        back = TextWidget(
+            (x_offset, y_offset), 'Press ESC to return to the main menu.',
+            colour='white', centre=True)
+        self.add(back)
+
+    def howto_scene(self, event):
+        SceneChangeEvent.post(HowtoScene)
+
+    def introduction_level(self, event):
+        from naja.scenes.game import GameScene
+        LoadGameEvent.post(state=GameState.new(deck='introduction'))
+        SceneChangeEvent.post(GameScene)
+
+    def handle_scene_event(self, ev):
+        if ev.type == pgl.KEYDOWN and ev.key in KEYS.QUIT:
+            from naja.scenes.menu import MenuScene
+            SceneChangeEvent.post(MenuScene)
+            return
index 84911c3eb1987b13e00e8758d258b102d63ad49f..2431e07cf2cc9f4be35c1e9419f59f17376c4405 100644 (file)
@@ -10,7 +10,7 @@ from naja.options import options
 from naja.scenes.scene import Scene
 from naja.scenes.credits import CreditsScene
 from naja.scenes.game import GameScene
-from naja.scenes.howto import HowtoScene
+from naja.scenes.introduction import IntroductionScene
 from naja.scenes.load_save import LoadGameScene, SaveGameScene
 from naja.scenes.new_game import NewGameScene
 from naja.scenes.puzzlelist import PuzzleListScene
@@ -33,6 +33,13 @@ class MenuScene(Scene):
         y_offset, y_diff = 270, 36
         x_offset = 400
 
+        y_offset += y_diff
+        intro = TextWidget(
+            (x_offset, y_offset), 'Introduction', colour=PALETTE.WHITE,
+            centre=True)
+        intro.add_callback('click', self.scene_callback(IntroductionScene))
+        selector.add(intro)
+
         y_offset += y_diff
         resume = TextWidget(
             (x_offset, y_offset), 'Resume Game', colour=PALETTE.WHITE,
@@ -41,6 +48,11 @@ class MenuScene(Scene):
         resume.set_selectable_callback(lambda: state is not None)
         selector.add(resume)
 
+        if state is None:
+            selector.position = 2
+        else:
+            selector.position = 1
+
         y_offset += y_diff
         new = TextWidget(
             (x_offset, y_offset), 'New Random Game', colour=PALETTE.WHITE,
@@ -70,13 +82,6 @@ class MenuScene(Scene):
         save.set_selectable_callback(lambda: state is not None)
         selector.add(save)
 
-        y_offset += y_diff
-        howto = TextWidget(
-            (x_offset, y_offset), 'How To Play', colour=PALETTE.WHITE,
-            centre=True)
-        howto.add_callback('click', self.scene_callback(HowtoScene))
-        selector.add(howto)
-
         y_offset += y_diff
         credits = TextWidget(
             (x_offset, y_offset), 'Credits', colour=PALETTE.WHITE,