Mercurial > pyntnclick
changeset 825:c5171ad0c3cd pyntnclick
Make engine computer start using text for alerts
author | Neil Muller <neil@dip.sun.ac.za> |
---|---|
date | Tue, 29 Jan 2013 12:45:54 +0200 |
parents | 9f542ef6e498 |
children | 3a00c9337731 |
files | gamelib/scenes/engine.py pyntnclick/utils.py |
diffstat | 2 files changed, 17 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/gamelib/scenes/engine.py Tue Jan 29 11:41:03 2013 +0200 +++ b/gamelib/scenes/engine.py Tue Jan 29 12:45:54 2013 +0200 @@ -2,6 +2,7 @@ from pyntnclick.i18n import _ from pyntnclick.cursor import CursorSprite +from pyntnclick.utils import render_text from pyntnclick.state import Scene, Item, Thing, Result from pyntnclick.scenewidgets import ( InteractNoImage, InteractRectUnion, InteractImage, InteractAnimated, @@ -546,9 +547,9 @@ NAME = "engine_comp_detail" ALERTS = { - 'cryo leaking': 'ec_cryo_leaking.png', - 'cryo empty': 'ec_cryo_reservoir_empty.png', - 'super malfunction': 'ec_cryo_super_malfunction.png', + 'cryo leaking': _("Cryo system leaking!"), + 'cryo empty': _("Cryo reservoir empty!"), + 'super malfunction': _("Superconductor malfunction!"), } # Point to start drawing changeable alerts @@ -557,8 +558,9 @@ def setup(self): self._alert_messages = {} - for key, name in self.ALERTS.iteritems(): - self._alert_messages[key] = self.get_image(self.FOLDER, name) + for key, msg in self.ALERTS.iteritems(): + self._alert_messages[key] = render_text(msg, 'DejaVuSans-Bold.ttf', + 30, 'red', (0, 0, 0, 0), self.resource, (480, 33), False) def _draw_alerts(self, surface): xpos, ypos = self.ALERT_OFFSET
--- a/pyntnclick/utils.py Tue Jan 29 11:41:03 2013 +0200 +++ b/pyntnclick/utils.py Tue Jan 29 12:45:54 2013 +0200 @@ -42,13 +42,16 @@ return pygame.Color(*color) -def render_text(text, fontname, font_size, color, bg_color, resource, size): +def render_text(text, fontname, font_size, color, bg_color, resource, size, + centre=True): """Render the text so it will fit in the given size, reducing font size as needed. Note that this does not do any text wrapping.""" done = False width, height = size + color = convert_color(color) + bg_color = convert_color(bg_color) surface = Surface(size, SRCALPHA).convert_alpha() surface.fill(bg_color) while not done and font_size > 0: @@ -60,8 +63,11 @@ font_size -= 1 else: done = True - # Centre the text in the rect - x = max(0, (width - text_surf.get_width()) / 2) - y = max(0, (height - text_surf.get_height()) / 2) + if centre: + # Centre the text in the rect + x = max(0, (width - text_surf.get_width()) / 2) + y = max(0, (height - text_surf.get_height()) / 2) + else: + x = y = 0 surface.blit(text_surf, (x, y)) return surface