""" 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
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
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