changeset 232:0bd214cf9018

Overlay cost on building sprite cursors.
author Simon Cross <hodgestar@gmail.com>
date Fri, 04 Sep 2009 23:59:52 +0000
parents 857040b211d5
children d3d5352f5853
files gamelib/gameboard.py gamelib/sprite_cursor.py
diffstat 2 files changed, 20 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/gamelib/gameboard.py	Fri Sep 04 23:59:28 2009 +0000
+++ b/gamelib/gameboard.py	Fri Sep 04 23:59:52 2009 +0000
@@ -258,7 +258,7 @@
         self.select_animal_to_place(None)
         sprite_curs = None
         if buildings.is_building(tool):
-            sprite_curs = sprite_cursor.SpriteCursor(tool.IMAGE, self.tv)
+            sprite_curs = sprite_cursor.SpriteCursor(tool.IMAGE, self.tv, tool.BUY_PRICE)
         if tool == constants.TOOL_BUY_FENCE:
             sprite_curs = sprite_cursor.SpriteCursor("tiles/fence.png", self.tv)
         self.set_cursor(cursor, sprite_curs)
--- a/gamelib/sprite_cursor.py	Fri Sep 04 23:59:28 2009 +0000
+++ b/gamelib/sprite_cursor.py	Fri Sep 04 23:59:52 2009 +0000
@@ -3,14 +3,32 @@
    Currently mostly used when placing buildings.
    """
 
+import pygame
+import pygame.font
+from pygame.locals import SRCALPHA
+
 import imagecache
+import constants
 from pgu.vid import Sprite
 
+# ignore os.popen3 warning generated by pygame.font.SysFont
+import warnings
+warnings.filterwarnings("ignore", "os.popen3 is deprecated.")
+
 class SpriteCursor(Sprite):
     """A Sprite used as an on-board cursor."""
 
-    def __init__(self, image_name, tv):
+    def __init__(self, image_name, tv, cost=None):
+        self._font = pygame.font.SysFont('Vera', 20, bold=True)
         image = imagecache.load_image(image_name, ["sprite_cursor"])
+
+        if cost is not None:
+            image = image.copy()
+            text = self._font.render(str(cost), True, constants.FG_COLOR)
+            w, h = image.get_size()
+            x, y = text.get_size()
+            image.blit(text, (w - x, h - y))
+
         # Create the sprite somewhere far off screen
         Sprite.__init__(self, image, (-1000, -1000))
         self._tv = tv