changeset 133:0530547a131f

Better map handling, detail_view stuff in Result.
author Jeremy Thurgood <firxen@gmail.com>
date Tue, 24 Aug 2010 19:49:10 +0200
parents 686bb74a52f8
children faac82748f5a
files gamelib/gamescreen.py gamelib/scenes/cryo.py gamelib/scenes/map.py gamelib/state.py
diffstat 4 files changed, 27 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/gamelib/gamescreen.py	Tue Aug 24 19:22:01 2010 +0200
+++ b/gamelib/gamescreen.py	Tue Aug 24 19:49:10 2010 +0200
@@ -15,7 +15,7 @@
 from hand import HandButton
 from popupmenu import PopupMenu, PopupMenuButton
 from state import initial_state, Item
-
+from widgets import MessageDialog
 
 class InventoryView(PaletteView):
 
@@ -78,6 +78,12 @@
         if not self.subwidgets:
             self.state.mouse_move(event.pos)
 
+    def show_message(self, message):
+        # Display the message as a modal dialog
+        MessageDialog(message, 60).present()
+        # queue a redraw to show updated state
+        self.invalidate()
+
     def show_detail(self, detail):
         w, h = self.state.set_current_detail(detail)
         self.detail.set_image_rect(Rect(0, 0, w, h))
--- a/gamelib/scenes/cryo.py	Tue Aug 24 19:22:01 2010 +0200
+++ b/gamelib/scenes/cryo.py	Tue Aug 24 19:49:10 2010 +0200
@@ -49,8 +49,11 @@
     NAME = "cryo.unit.1"
 
     INTERACTS = {
-        "unit": InteractRectUnion(((520, 430, 80, 50), (550, 470, 90, 60),
-            (600, 510, 60, 40)))
+        "unit": InteractRectUnion((
+                (520, 430, 80, 50),
+                (550, 470, 90, 60),
+                (600, 510, 60, 40),
+                ))
     }
 
     INITIAL = "unit"
--- a/gamelib/scenes/map.py	Tue Aug 24 19:22:01 2010 +0200
+++ b/gamelib/scenes/map.py	Tue Aug 24 19:49:10 2010 +0200
@@ -40,8 +40,13 @@
     def interact_without(self):
         """Go to destination."""
         if self.DEST in self.state.scenes:
-            self.state.set_current_scene(self.DEST)
-            return Result("You head for the %s." % self.DEST)
+            if self.state.scenes[self.DEST].get_data('accessible'):
+                self.state.set_current_scene(self.DEST)
+                return Result()
+            else:
+                return Result("You can't go there right now.")
+        else:
+            return Result("You *could* go there, but it doesn't actually exist.")
 
     def check_dest(self):
         if self.DEST in self.state.scenes:
--- a/gamelib/state.py	Tue Aug 24 19:22:01 2010 +0200
+++ b/gamelib/state.py	Tue Aug 24 19:49:10 2010 +0200
@@ -2,7 +2,7 @@
 
 from albow.resource import get_image
 from albow.utils import frame_rect
-from widgets import BoomLabel, MessageDialog
+from widgets import BoomLabel
 from pygame.locals import BLEND_ADD
 from pygame.rect import Rect
 from pygame.surface import Surface
@@ -16,22 +16,21 @@
 class Result(object):
     """Result of interacting with a thing"""
 
-    def __init__(self, message=None, soundfile=None):
+    def __init__(self, message=None, soundfile=None, detail_view=None):
         self.message = message
         self.sound = None
         if soundfile:
             self.sound = get_sound(soundfile)
+        self.detail_view = detail_view
 
-    def process(self, scene):
+    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:
-            # Display the message as a modal dialog
-            MessageDialog(self.message, 60).present()
-            # queue a redraw to show updated state
-            scene.invalidate()
-
+            scene_widget.show_message(self.message)
+        if self.detail_view:
+            scene_widget.show_detail(self.detail_view)
 
 def initial_state(screen):
     """Load the initial state."""
@@ -491,7 +490,7 @@
         return None
 
     def is_interactive(self):
-        return True
+        return self.current_interact is not None
 
     def enter(self, item):
         """Called when the cursor enters the Thing."""