changeset 450:ece69836f00a

Image buttons for game over screen
author Neil Muller <neil@dip.sun.ac.za>
date Sun, 29 Aug 2010 00:50:25 +0200
parents a30f91ee5b33
children 8b1951cb7710
files gamelib/endscreen.py gamelib/menu.py gamelib/widgets.py
diffstat 3 files changed, 40 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/gamelib/endscreen.py	Sun Aug 29 00:31:03 2010 +0200
+++ b/gamelib/endscreen.py	Sun Aug 29 00:50:25 2010 +0200
@@ -7,21 +7,26 @@
 from albow.resource import get_image
 from albow.layout import Column
 
+from gamelib.widgets import BoomImageButton
+
+class EndImageButton(BoomImageButton):
+
+    FOLDER = 'won'
+
 
 class EndScreen(Screen):
     def __init__(self, shell):
         Screen.__init__(self, shell)
         self.background = get_image('won', 'won.png')
-        StartButton = Button('Main Menu', action = self.main_menu)
-        QuitButton = Button('Quit', action = shell.quit)
-        self.add(StartButton)
-        StartButton.rect.bottomleft = (50, 550)
-        self.add(QuitButton)
-        QuitButton.rect.bottomleft = (250, 550)
+        self._menu_button = EndImageButton('menu.png', 26, 500, action=self.main_menu)
+        self._quit_button = EndImageButton('quit.png', 250, 500, action=shell.quit)
+        self.add(self._menu_button)
+        self.add(self._quit_button)
 
     def draw(self, surface):
         surface.blit(self.background, (0,0))
-        super(EndScreen, self).draw(surface)
+        self._menu_button.draw(surface)
+        self._quit_button.draw(surface)
 
     def main_menu(self):
         self.shell.show_screen(self.shell.menu_screen)
--- a/gamelib/menu.py	Sun Aug 29 00:31:03 2010 +0200
+++ b/gamelib/menu.py	Sun Aug 29 00:50:25 2010 +0200
@@ -8,28 +8,12 @@
 from albow.resource import get_image
 from pygame import Rect
 
-class SplashButton(Image):
-    """The fancy hand button for the widget"""
+from gamelib.widgets import BoomImageButton
 
-    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())
+class SplashButton(BoomImageButton):
 
-    def mouse_down(self, event):
-        if self.is_enabled():
-            self.action()
-
-    def is_enabled(self):
-        if self.enable:
-            return self.enable()
-        return True
+    FOLDER = 'splash'
 
 
 class MenuScreen(Screen):
--- a/gamelib/widgets.py	Sun Aug 29 00:31:03 2010 +0200
+++ b/gamelib/widgets.py	Sun Aug 29 00:50:25 2010 +0200
@@ -176,3 +176,28 @@
             # A menu item needs to be invoked
             self.invoke_item(item)
 
+class BoomImageButton(albow.controls.Image):
+    """The fancy image button for the screens"""
+
+    FOLDER = None
+
+    def __init__(self, filename, x, y, action, enable=None):
+        this_image = get_image(self.FOLDER, filename)
+        albow.controls.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
+