From: Simon Cross Date: Sat, 5 Mar 2016 19:52:14 +0000 (+0200) Subject: Use new splash screen. X-Git-Url: https://git.ctpug.org.za/?a=commitdiff_plain;h=3a22af1a0404b9bbbf7523b9337b84f6587bb004;p=koperkapel.git Use new splash screen. --- diff --git a/koperkapel/scenes/menu.py b/koperkapel/scenes/menu.py index 65128b9..b5d7815 100644 --- a/koperkapel/scenes/menu.py +++ b/koperkapel/scenes/menu.py @@ -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