changeset 446:a6de33fecb97

Hook up splash screen
author Stefano Rivera <stefano@rivera.za.net>
date Sun, 29 Aug 2010 00:30:17 +0200
parents ef39ffe3fcc2
children 9c285017535d
files gamelib/menu.py
diffstat 1 files changed, 40 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/gamelib/menu.py	Sun Aug 29 00:27:35 2010 +0200
+++ b/gamelib/menu.py	Sun Aug 29 00:30:17 2010 +0200
@@ -3,25 +3,52 @@
 # Main menu for the game
 
 from albow.screen import Screen
-from albow.controls import Button, Label
+from albow.controls import Image, Button, Label
 from albow.layout import Column
+from albow.resource import get_image
+from pygame import Rect
+
+class SplashButton(Image):
+    """The fancy hand button for the widget"""
+
+    def __init__(self, filename, x, y, action, enable=None):
+        this_image = get_image('splash', filename)
+        Image.__init__(self, image=this_image)
+        self.action = action
+        self.set_rect(Rect((x, y), this_image.get_size()))
+        self.enable = enable
+
+    def draw(self, surface):
+        if self.is_enabled():
+            surface.blit(self.get_image(), self.get_rect())
+
+    def mouse_down(self, event):
+        if self.is_enabled():
+            self.action()
+
+    def is_enabled(self):
+        if self.enable:
+            return self.enable()
+        return True
 
 
 class MenuScreen(Screen):
     def __init__(self, shell):
         Screen.__init__(self, shell)
-        StartButton = Button('Start New Game', action = self.start)
-        ResumeButton = Button('Resume Game', action = self.resume,
-                enable=self.check_running)
-        QuitButton = Button('Quit', action = shell.quit)
-        Title = Label('Suspended Sentence')
-        menu = Column([
-            Title,
-            StartButton,
-            ResumeButton,
-            QuitButton,
-            ], align='l', spacing=20)
-        self.add_centered(menu)
+        self._background = get_image('splash', 'splash.png')
+        self._start_button = SplashButton('play.png', 16, 523, self.start)
+        self._resume_button = SplashButton('resume.png', 256, 523, self.resume,
+                                           enable=self.check_running)
+        self._quit_button = SplashButton('quit.png', 580, 523, shell.quit)
+        self.add(self._start_button)
+        self.add(self._resume_button)
+        self.add(self._quit_button)
+
+    def draw(self, surface):
+        surface.blit(self._background, (0, 0))
+        self._start_button.draw(surface)
+        self._resume_button.draw(surface)
+        self._quit_button.draw(surface)
 
     def start(self):
         self.shell.game_screen.start_game()
@@ -34,5 +61,3 @@
         if self.shell.game_screen.running:
             self.shell.show_screen(self.shell.game_screen)
 
-
-