# HG changeset patch # User Simon Cross # Date 1252108792 0 # Node ID 0bd214cf9018996dcde6f310edfc6127a3831467 # Parent 857040b211d51d7809db7801f7ccc66d2d06c7ab Overlay cost on building sprite cursors. diff -r 857040b211d5 -r 0bd214cf9018 gamelib/gameboard.py --- 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) diff -r 857040b211d5 -r 0bd214cf9018 gamelib/sprite_cursor.py --- 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