diff gamelib/scenes/game_widgets.py @ 852:f95830b58336

Merge pyntnclick
author Stefano Rivera <stefano@rivera.za.net>
date Sat, 21 Jun 2014 22:04:35 +0200
parents bdebe693453f
children
line wrap: on
line diff
--- a/gamelib/scenes/game_widgets.py	Sat Jun 21 17:38:39 2014 +0000
+++ b/gamelib/scenes/game_widgets.py	Sat Jun 21 22:04:35 2014 +0200
@@ -1,7 +1,10 @@
 """Generic, game specific widgets"""
 
 
-from gamelib.state import Thing, Result
+from pyntnclick.i18n import _
+from pyntnclick.state import Thing, Result
+
+from gamelib.custom_widgets import JimLabel
 
 
 class Door(Thing):
@@ -19,23 +22,29 @@
 
     def interact_without(self):
         """Go to map."""
-        self.state.set_current_scene("map")
+        self.game.change_scene("map")
 
     def get_description(self):
-        return 'An open doorway leads to the rest of the ship.'
+        return _('An open doorway leads to the rest of the ship.')
 
     def interact_default(self, item):
         return self.interact_without()
 
 
-def make_jim_dialog(mesg, state):
+def make_jim_dialog(mesg, game):
     "Utility helper function"
-    if state.scenes['bridge'].get_data('ai status') == 'online':
-        return Result(mesg, style='JIM')
+    if game.data.get_jim_state() == 'online':
+        return Result(widget=JimLabel(game.gd, mesg))
     else:
         return None
 
 
+def make_sentence_dialog(prisoner, game):
+    return make_jim_dialog(
+            _("Prisoner %(id)s, your total sentence is now %(sen)d years.") % {
+                "id": prisoner, 'sen': game.data.get_total_sentence()}, game) 
+
+
 class BaseCamera(Thing):
     "Base class for the camera puzzles"
 
@@ -45,30 +54,37 @@
     }
 
     def get_description(self):
-        status = self.state.scenes['bridge'].get_data('ai status')
+        status = self.state.get_jim_state()
         if status == 'online':
-            return "A security camera watches over the room"
+            return _("A security camera watches over the room")
         elif status == 'looping':
-            return "The security camera is currently offline but should be" \
-                    " working soon"
+            return _("The security camera is currently offline but should be"
+                     " working soon")
         else:
-            return "The security camera is powered down"
+            return _("The security camera is powered down")
 
     def is_interactive(self, tool=None):
-        return self.state.scenes['bridge'].get_data('ai status') == 'online'
+        return self.state.get_jim_state() == 'online'
 
     def interact_with_escher_poster(self, item):
         # Order matters here, because of helper function
-        if self.state.scenes['bridge'].get_data('ai status') == 'online':
-            ai_response = make_jim_dialog("3D scene reconstruction failed."
-                    " Critical error. Entering emergency shutdown.",
-                    self.state)
-            self.state.scenes['bridge'].set_data('ai status', 'looping')
+        if self.state.get_jim_state() == 'online':
+            ai_response = make_jim_dialog(_("3D scene reconstruction failed."
+                                            " Critical error."
+                                            " Entering emergency shutdown."),
+                                          self.game)
+            self.game.data.loop_ai()
             return ai_response
 
+    def select_interact(self):
+        if 'bridge' not in self.state:
+            # We aren't completely set up yet
+            return self.INITIAL
+        return self.state.get_jim_state()
+
     def animate(self):
-        ai_status = self.state.scenes['bridge'].get_data('ai status')
+        ai_status = self.state.get_jim_state()
         if ai_status != self.get_data('status'):
             self.set_data('status', ai_status)
-            self.set_interact(ai_status)
+            self.set_interact()
         super(BaseCamera, self).animate()