changeset 681:497b6d7c55e7 pyntnclick

Reimplement JIM-style in gamelib
author Neil Muller <neil@dip.sun.ac.za>
date Sun, 12 Feb 2012 23:57:14 +0200
parents c9562e24bfed
children 0749438e325e
files gamelib/custom_widgets.py gamelib/scenes/game_widgets.py pyntnclick/state.py
diffstat 3 files changed, 27 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gamelib/custom_widgets.py	Sun Feb 12 23:57:14 2012 +0200
@@ -0,0 +1,20 @@
+"""Custom widgets for Suspened Sentence"""
+
+import pygame
+from pyntnclick.widgets.text import ModalWrappedTextLabel
+
+
+class JimLabel(ModalWrappedTextLabel):
+    """Custom widget for JIM's speech"""
+
+    def __init__(self, gd, mesg):
+        rect = pygame.Rect((0, 0), (1, 1))
+        super(JimLabel, self).__init__(rect, gd,
+                text=mesg, fontname='Monospace.ttf', fontsize=20,
+                bg_color=pygame.Color(255, 175, 127, 191),
+                color=pygame.Color(0, 0, 0),
+                border_color=pygame.Color(127, 15, 0))
+        # Centre the widget
+        # Should this happen automatically in state?
+        self.rect.center = (gd.constants.screen[0] / 2,
+                gd.constants.screen[1] / 2)
--- a/gamelib/scenes/game_widgets.py	Sun Feb 12 23:10:00 2012 +0200
+++ b/gamelib/scenes/game_widgets.py	Sun Feb 12 23:57:14 2012 +0200
@@ -3,6 +3,8 @@
 
 from pyntnclick.state import Thing, Result
 
+from gamelib.custom_widgets import JimLabel
+
 
 class Door(Thing):
     """A door somewhere"""
@@ -31,7 +33,7 @@
 def make_jim_dialog(mesg, game):
     "Utility helper function"
     if game.data.get_jim_state() == 'online':
-        return Result(mesg, style='JIM')
+        return Result(widget=JimLabel(game.gd, mesg))
     else:
         return None
 
--- a/pyntnclick/state.py	Sun Feb 12 23:10:00 2012 +0200
+++ b/pyntnclick/state.py	Sun Feb 12 23:57:14 2012 +0200
@@ -20,11 +20,11 @@
     """Result of interacting with a thing"""
 
     def __init__(self, message=None, soundfile=None, detail_view=None,
-                 style=None, close_detail=False, end_game=False):
+                 widget=None, close_detail=False, end_game=False):
         self.message = message
         self.soundfile = soundfile
         self.detail_view = detail_view
-        self.style = style
+        self.widget = widget
         self.close_detail = close_detail
         self.end_game = end_game
 
@@ -36,6 +36,8 @@
     def process(self, scene_widget):
         """Helper function to do the right thing with a result object"""
         self.play_sound(scene_widget)
+        if self.widget:
+            scene_widget.queue_widget(self.widget)
         if self.message:
             scene_widget.show_message(self.message)
         if self.detail_view: