Mercurial > pyntnclick
comparison gamelib/state.py @ 65:cab924519037
Move some description management from widget to state object
author | Neil Muller <neil@dip.sun.ac.za> |
---|---|
date | Mon, 23 Aug 2010 19:45:07 +0200 |
parents | 3087be3463e0 |
children | 158a13a48d48 |
comparison
equal
deleted
inserted
replaced
64:c21e4521512e | 65:cab924519037 |
---|---|
34 self.items = {} | 34 self.items = {} |
35 # list of item objects in inventory | 35 # list of item objects in inventory |
36 self.inventory = [] | 36 self.inventory = [] |
37 # Result of the most recent action | 37 # Result of the most recent action |
38 self.msg = None | 38 self.msg = None |
39 self.description = None | |
39 # current scene | 40 # current scene |
40 self.current_scene = None | 41 self.current_scene = None |
41 | 42 |
42 def add_scene(self, scene): | 43 def add_scene(self, scene): |
43 self.scenes[scene.name] = scene | 44 self.scenes[scene.name] = scene |
66 return self.msg | 67 return self.msg |
67 | 68 |
68 def clear_message(self): | 69 def clear_message(self): |
69 self.msg = None | 70 self.msg = None |
70 | 71 |
71 def get_description(self, pos): | 72 # FIXME: sort out how state.interact and description updating should work |
72 """Get the description associated with current mouse position""" | 73 |
73 return self.current_scene.get_description(pos) | 74 def check_for_new_description(self, pos): |
75 """Check if the current mouse position causes a new description""" | |
76 old_desc = self.description | |
77 self.description = self.current_scene.check_description(pos) | |
78 return old_desc != self.description | |
79 | |
80 def get_description(self): | |
81 return self.description | |
74 | 82 |
75 def message(self, msg): | 83 def message(self, msg): |
76 self.msg = msg | 84 self.msg = msg |
77 | 85 |
78 | 86 |
134 | 142 |
135 def draw(self, surface): | 143 def draw(self, surface): |
136 self.draw_background(surface) | 144 self.draw_background(surface) |
137 self.draw_things(surface) | 145 self.draw_things(surface) |
138 | 146 |
139 def get_description(self, pos): | 147 def check_description(self, pos): |
140 desc = None | 148 desc = None |
141 for thing in self.things.itervalues(): | 149 for thing in self.things.itervalues(): |
142 # Last thing in the list that matches wins | 150 # Last thing in the list that matches wins |
143 if Rect(thing.rect).collidepoint(pos): | 151 if Rect(thing.rect).collidepoint(pos): |
144 desc = thing.get_description() | 152 desc = thing.get_description() |