comparison gamelib/state.py @ 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 b43599b7f8a2
comparison
equal deleted inserted replaced
132:686bb74a52f8 133:0530547a131f
1 """Utilities and base classes for dealing with scenes.""" 1 """Utilities and base classes for dealing with scenes."""
2 2
3 from albow.resource import get_image 3 from albow.resource import get_image
4 from albow.utils import frame_rect 4 from albow.utils import frame_rect
5 from widgets import BoomLabel, MessageDialog 5 from widgets import BoomLabel
6 from pygame.locals import BLEND_ADD 6 from pygame.locals import BLEND_ADD
7 from pygame.rect import Rect 7 from pygame.rect import Rect
8 from pygame.surface import Surface 8 from pygame.surface import Surface
9 from pygame.color import Color 9 from pygame.color import Color
10 10
14 14
15 15
16 class Result(object): 16 class Result(object):
17 """Result of interacting with a thing""" 17 """Result of interacting with a thing"""
18 18
19 def __init__(self, message=None, soundfile=None): 19 def __init__(self, message=None, soundfile=None, detail_view=None):
20 self.message = message 20 self.message = message
21 self.sound = None 21 self.sound = None
22 if soundfile: 22 if soundfile:
23 self.sound = get_sound(soundfile) 23 self.sound = get_sound(soundfile)
24 24 self.detail_view = detail_view
25 def process(self, scene): 25
26 def process(self, scene_widget):
26 """Helper function to do the right thing with a result object""" 27 """Helper function to do the right thing with a result object"""
27 if self.sound: 28 if self.sound:
28 self.sound.play() 29 self.sound.play()
29 if self.message: 30 if self.message:
30 # Display the message as a modal dialog 31 scene_widget.show_message(self.message)
31 MessageDialog(self.message, 60).present() 32 if self.detail_view:
32 # queue a redraw to show updated state 33 scene_widget.show_detail(self.detail_view)
33 scene.invalidate()
34
35 34
36 def initial_state(screen): 35 def initial_state(screen):
37 """Load the initial state.""" 36 """Load the initial state."""
38 state = State(screen) 37 state = State(screen)
39 state.load_scenes("cryo") 38 state.load_scenes("cryo")
489 488
490 def get_description(self): 489 def get_description(self):
491 return None 490 return None
492 491
493 def is_interactive(self): 492 def is_interactive(self):
494 return True 493 return self.current_interact is not None
495 494
496 def enter(self, item): 495 def enter(self, item):
497 """Called when the cursor enters the Thing.""" 496 """Called when the cursor enters the Thing."""
498 pass 497 pass
499 498