diff gamelib/gamegui.py @ 138:14917385a0fd

Better handling of mission results and turn-end messages.
author Jeremy Thurgood <firxen@gmail.com>
date Thu, 10 May 2012 22:33:26 +0200
parents 208a79a49c26
children 07be37129447
line wrap: on
line diff
--- a/gamelib/gamegui.py	Thu May 10 20:56:40 2012 +0200
+++ b/gamelib/gamegui.py	Thu May 10 22:33:26 2012 +0200
@@ -17,8 +17,7 @@
         font_medium, font_large)
 from gamelib.gui import BigButton, ImageDrawable
 from gamelib.engine import PopWindow, AddWindow, GameOver
-from gamelib.constants import (WIDTH, HEIGHT, FAILURE, SUCCESS, NEW_SCIENCE,
-        NEW_SCHEMATIC, GAME_WIN)
+from gamelib.constants import WIDTH, HEIGHT, FAILURE, SUCCESS, GAME_WIN, INFO
 from gamelib.gamestate import Game
 
 
@@ -325,26 +324,36 @@
             self.add_child(results)
         else:
             y = 200
-            for msg_type, msg in messages:
+            for msg_type, msg, loot in messages:
                 # FIXME: Better widgets
-                if msg_type in [NEW_SCHEMATIC, NEW_SCIENCE]:
-                    text = TextBox((50, y, 750, 25),
-                            msg, font_medium, (60, 60, 255))
+                if msg_type == INFO:
+                    y = self.display_message(y, msg, loot, (60, 60, 255))
                 elif msg_type == FAILURE:
-                    text = TextBox((50, y, 750, 25),
-                            msg, font_medium, (255, 60, 60))
+                    y = self.display_message(y, msg, loot, (255, 60, 60))
                 elif msg_type == SUCCESS:
-                    text = TextBox((50, y, 750, 25),
-                            msg, font_medium, (60, 255, 60))
+                    y = self.display_message(y, msg, loot, (60, 255, 60))
                 elif msg_type == GAME_WIN:
                     self._make_win_screen(turn, msg)
                     self.is_game_over = True
                     break
                 else:
-                    text = TextBox((50, y, 750, 25),
-                            msg, font_medium, (255, 255, 0))
-                y += text.rect.height + 10
-                self.add_child(text)
+                    y = self.display_message(y, msg, loot, (255, 255, 0))
+
+    def display_message(self, y, msg, loot, colour, font=font_medium):
+        text = TextBox((50, y, 700, 25), msg, font, colour)
+        y += text.rect.height + 5
+        self.add_child(text)
+        for kind, value in loot.items():
+            y += self.display_loot_item(y, kind, value)
+        return y + 5
+
+    def display_loot_item(self, y, kind, value):
+        if hasattr(value, 'NAME'):
+            value = value.NAME
+        msg = "* %s: %s" % (kind, value)
+        text = TextBox((60, y, 690, 25), msg, font_medium, (255, 255, 60))
+        self.add_child(text)
+        return text.rect.height + 5
 
     def _make_win_screen(self, turn, msg):
         # Clear existing widgets, and turn this into a won screen