changeset 210:eb101b6fb3dd

Transparent message dialogs.
author Jeremy Thurgood <firxen@gmail.com>
date Thu, 26 Aug 2010 16:29:54 +0200
parents aeb96ca5f76c
children 969b1cb4b567
files gamelib/gamescreen.py gamelib/scenes/cryo.py gamelib/scenes/map.py gamelib/state.py gamelib/widgets.py
diffstat 5 files changed, 41 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/gamelib/gamescreen.py	Thu Aug 26 14:59:29 2010 +0200
+++ b/gamelib/gamescreen.py	Thu Aug 26 16:29:54 2010 +0200
@@ -91,10 +91,10 @@
     def _mouse_move(self, pos):
         self.state.mouse_move(pos, self.screen)
 
-    def show_message(self, message):
+    def show_message(self, message, style=None):
         self.parent.cursor_highlight(False)
         # Display the message as a modal dialog
-        MessageDialog(self.screen, message, 60).present()
+        MessageDialog(self.screen, message, 60, style=style).present()
         # queue a redraw to show updated state
         self.invalidate()
         # The cursor could have gone anywhere
@@ -153,8 +153,8 @@
     def _mouse_move(self, pos):
         self.state.mouse_move_detail(self.global_to_local(pos), self.screen)
 
-    def show_message(self, message):
-        self.parent.show_message(message)
+    def show_message(self, message, style=None):
+        self.parent.show_message(message, style)
         self.invalidate()
 
 
--- a/gamelib/scenes/cryo.py	Thu Aug 26 14:59:29 2010 +0200
+++ b/gamelib/scenes/cryo.py	Thu Aug 26 16:29:54 2010 +0200
@@ -134,7 +134,7 @@
                     "the ship. Your behaviour during this time will "
                     "be added to your record and will be relayed to "
                     "prison officials when we reach the destination. "
-                    "Please report to the bridge.'")
+                    "Please report to the bridge.'", style="JIM")
 
     def leave(self):
         # Stop music
--- a/gamelib/scenes/map.py	Thu Aug 26 14:59:29 2010 +0200
+++ b/gamelib/scenes/map.py	Thu Aug 26 16:29:54 2010 +0200
@@ -37,12 +37,12 @@
                 "JIM say 'Under the terms of the emergency conscription "
                 "act, I have downloaded the ship schematics to your "
                 "neural implant to help you navigate around the ship. "
-                "Please report to the bridge.'"),
+                "Please report to the bridge.'", style="JIM"),
                 Result(
                 "JIM continues 'Prisoner 84c7-d10dcfda0878. You are classed "
                 "as a class 1 felon. Obtaining access to the ship shematics "
                 "consitutes a level 2 offence and carries a minimal penalty "
-                "of an additional 3 years on you sentence.'"))
+                "of an additional 3 years on you sentence.'", style="JIM"))
 
 
 class DoorThing(Thing):
--- a/gamelib/state.py	Thu Aug 26 14:59:29 2010 +0200
+++ b/gamelib/state.py	Thu Aug 26 16:29:54 2010 +0200
@@ -18,19 +18,20 @@
 class Result(object):
     """Result of interacting with a thing"""
 
-    def __init__(self, message=None, soundfile=None, detail_view=None):
+    def __init__(self, message=None, soundfile=None, detail_view=None, style=None):
         self.message = message
         self.sound = None
         if soundfile:
             self.sound = get_sound(soundfile)
         self.detail_view = detail_view
+        self.style = style
 
     def process(self, scene_widget):
         """Helper function to do the right thing with a result object"""
         if self.sound:
             self.sound.play()
         if self.message:
-            scene_widget.show_message(self.message)
+            scene_widget.show_message(self.message, self.style)
         if self.detail_view:
             scene_widget.show_detail(self.detail_view)
 
@@ -258,7 +259,7 @@
         label.set_margin(5)
         label.border_width = 1
         label.border_color = (0, 0, 0)
-        label.bg_color = (127, 127, 127)
+        label.bg_color = Color(127, 127, 127, 255)
         label.fg_color = (0, 0, 0)
         return label
 
--- a/gamelib/widgets.py	Thu Aug 26 14:59:29 2010 +0200
+++ b/gamelib/widgets.py	Thu Aug 26 16:29:54 2010 +0200
@@ -6,6 +6,8 @@
 import textwrap
 
 import albow.controls
+from pygame.color import Color
+from pygame.locals import BLEND_ADD
 
 from cursor import CursorWidget
 
@@ -20,19 +22,46 @@
         self.margin = margin
         self.size = (w + 2 * d, h + 2 * d)
 
+    def draw_all(self, surface):
+        bg_color = self.bg_color
+        self.bg_color = None
+        if bg_color is not None:
+            new_surface = surface.convert_alpha()
+            new_surface.fill(bg_color)
+            surface.blit(new_surface, surface.get_rect())
+        albow.controls.Label.draw_all(self, surface)
+        self._draw_all_no_bg(surface)
+        self.bg_color = bg_color
+
+    def _draw_all_no_bg(self, surface):
+        pass
+
 
 class MessageDialog(BoomLabel, CursorWidget):
 
-    def __init__(self, screen, text, wrap_width, **kwds):
+    def __init__(self, screen, text, wrap_width, style=None, **kwds):
         CursorWidget.__init__(self, screen)
         paras = text.split("\n\n")
         text = "\n".join([textwrap.fill(para, wrap_width) for para in paras])
         albow.controls.Label.__init__(self, text, **kwds)
+        self.set_style(style)
+
+    def set_style(self, style):
         self.set_margin(5)
         self.border_width = 1
         self.border_color = (0, 0, 0)
         self.bg_color = (127, 127, 127)
         self.fg_color = (0, 0, 0)
+        if style == "JIM":
+            self.bg_color = Color(127, 0, 0, 191)
+            self.fg_color = (0, 0, 0)
+            self.border_color = (255, 0, 0)
+
+    def draw_all(self, surface):
+        BoomLabel.draw_all(self, surface)
+
+    def _draw_all_no_bg(self, surface):
+        CursorWidget.draw_all(self, surface)
 
     def mouse_down(self, event):
         self.dismiss()