diff gamelib/sprite_cursor.py @ 232:0bd214cf9018

Overlay cost on building sprite cursors.
author Simon Cross <hodgestar@gmail.com>
date Fri, 04 Sep 2009 23:59:52 +0000
parents f06010d34cd3
children 9cc7bc5cd10c
line wrap: on
line diff
--- 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