# HG changeset patch # User Neil Muller # Date 1359456354 -7200 # Node ID c5171ad0c3cd9a75104e723dcd369480b1e87b87 # Parent 9f542ef6e498ac28a5db22a42993a7798b15df83 Make engine computer start using text for alerts diff -r 9f542ef6e498 -r c5171ad0c3cd gamelib/scenes/engine.py --- 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 diff -r 9f542ef6e498 -r c5171ad0c3cd pyntnclick/utils.py --- 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