Use new splash screen.
authorSimon Cross <hodgestar@gmail.com>
Sat, 5 Mar 2016 19:52:14 +0000 (21:52 +0200)
committerSimon Cross <hodgestar@gmail.com>
Sat, 5 Mar 2016 19:52:14 +0000 (21:52 +0200)
koperkapel/scenes/menu.py

index 65128b9e49d3184028320914508063cbc727c877..b5d7815ebf36532bac8c50dd355a4a088917404e 100644 (file)
@@ -1,8 +1,9 @@
 """ Main menu scene. """
 
 from pgzero.constants import keys
-from ..actors.buttons import TextButton
+from pgzero.loaders import images
 from ..actors.navigator import ActorNavigator
+from ..actors.orientatedsurf import OrientatedSurfActor, SelectableSurfActor
 from .base import Scene, ChangeSceneEvent, WorldEvent, QuitEvent
 
 
@@ -11,22 +12,37 @@ class MenuScene(Scene):
 
     def __init__(self):
         super().__init__()
-        self._title = self.actors.add(TextButton("Main Menu"))
-        self._title.pos = (300, 100)
+        self.actors.add_layer("buttons", level=10)
+        self._init_bg()
+        self._init_buttons()
+
+    def _init_bg(self):
+        self.actors.default.clear()
+        self.actors.default.add(OrientatedSurfActor(
+            images.load("splash/background")))
+
+    def _init_buttons(self):
         self._nav = ActorNavigator()
-        self._menu = [
-            TextButton("New Game", action=self.change_to_new_game),
-            TextButton("Resume", action=self.change_to_resume),
-            TextButton("Credits", action=self.change_to_credits),
-            TextButton("Quit", action=self.quit),
+        menu = [
+            self._build_button("new_game", action=self.change_to_new_game),
+            self._build_button("resume_game", action=self.change_to_resume),
+            self._build_button("credits", action=self.change_to_credits),
+            self._build_button("quit", action=self.quit),
         ]
-        for i, item in enumerate(self._menu):
+        for i, item in enumerate(menu):
             item.pos = (300, 200 + (i * 100))
             self.actors.add(item)
         self._nav.connect(
-            self._menu, [keys.DOWN, keys.RIGHT], [keys.UP, keys.LEFT],
+            menu, [keys.DOWN, keys.RIGHT], [keys.UP, keys.LEFT],
             wrap=True)
-        self._nav.current.select()
+        self._nav.current.selected = True
+
+    def _build_button(self, name, action):
+        actor = SelectableSurfActor(
+            images.load("splash/%s" % (name,)),
+            images.load("splash/%s_selected" % (name,)))
+        actor.action = action
+        return actor
 
     def change_to_resume(self):
         from .level import GameLevelScene
@@ -54,6 +70,6 @@ class MenuScene(Scene):
         else:
             prev, current = self._nav.follow(key)
             if prev is not None:
-                prev.deselect()
+                prev.selected = False
             if current is not None:
-                current.select()
+                current.selected = True