Mercurial > sypikslang
changeset 62:38f41d046c6f
Make button font a parameter. Tweak indication of points to be spent
author | Neil Muller <drnlmuller@gmail.com> |
---|---|
date | Tue, 08 May 2012 17:29:02 +0200 |
parents | a253fae32a6f |
children | 364ff3479ef2 |
files | gamelib/gamegui.py gamelib/gui.py gamelib/gui_base.py |
diffstat | 3 files changed, 18 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/gamelib/gamegui.py Tue May 08 16:27:44 2012 +0200 +++ b/gamelib/gamegui.py Tue May 08 17:29:02 2012 +0200 @@ -6,7 +6,7 @@ from pygame import image from gamelib.data import filepath -from gamelib.gui_base import Window +from gamelib.gui_base import Window, font_small from gamelib.gui import BigButton from gamelib.engine import PopWindow from gamelib.constants import WIDTH @@ -54,14 +54,14 @@ self.points = 0 self.parent = parent super(ScienceWidget, self).__init__(pos, '%s: %d' % (science.NAME, - science.points)) + science.points), font_small) def on_click(self): if (self.parent.available_points > 0 and self.science.can_spend(self.parent.game.lab, self.points + 1)): self.points += 1 - self.text = '%s: %d' % (self.science.NAME, - self.science.points + self.points) + self.text = '%s: %d + %d' % (self.science.NAME, + self.science.points, self.points) self.parent.available_points -= 1 self._draw_text()
--- a/gamelib/gui.py Tue May 08 16:27:44 2012 +0200 +++ b/gamelib/gui.py Tue May 08 17:29:02 2012 +0200 @@ -1,7 +1,7 @@ from pygame import image from gamelib import data -from gamelib.gui_base import Drawable, TextButton +from gamelib.gui_base import Drawable, TextButton, font_large class ImageDrawable(Drawable): @@ -20,9 +20,9 @@ BG_IMAGE_NORMAL = image.load(data.filepath('images/button_normal.png')) BG_IMAGE_DOWN = image.load(data.filepath('images/button_down.png')) - def __init__(self, pos, text): + def __init__(self, pos, text, font=font_large, shadow=True): rect1 = (0, 0, self.WIDTH, self.HEIGHT) n = ImageDrawable(rect1, self.BG_IMAGE_NORMAL) d = ImageDrawable(rect1, self.BG_IMAGE_DOWN) rect2 = (pos[0], pos[1], self.WIDTH, self.HEIGHT) - super(BigButton, self).__init__(rect2, n, d, text) + super(BigButton, self).__init__(rect2, n, d, text, font, shadow)
--- a/gamelib/gui_base.py Tue May 08 16:27:44 2012 +0200 +++ b/gamelib/gui_base.py Tue May 08 17:29:02 2012 +0200 @@ -152,19 +152,23 @@ class TextButton(Button): - def __init__(self, rect, normal_drawable, down_drawable, text): + def __init__(self, rect, normal_drawable, down_drawable, text, font, + shadow): super(TextButton, self).__init__(rect, normal_drawable, down_drawable) self.surface = Surface((rect[2], rect[3])) self.text = text + self.font = font + self.shadow = shadow self._draw_text() def _draw_text(self): - font_large.set_bold(True) - self.text_surface = font_large.render(self.text, True, (128, 128, 128)) - shadow = font_large.render(self.text, True, (0, 0, 0)) - font_large.set_bold(False) - self.text_surface.blit(shadow, (-2, -2)) - size = font_large.size(self.text) + self.font.set_bold(True) + self.text_surface = self.font.render(self.text, True, (128, 128, 128)) + if self.shadow: + shadow = self.font.render(self.text, True, (0, 0, 0)) + self.text_surface.blit(shadow, (-2, -2)) + self.font.set_bold(False) + size = self.font.size(self.text) self.text_offset = ((self.rect[2] - size[0]) / 2, (self.rect[3] - size[1]) / 2)