Mercurial > traipse_dev
comparison orpg/mapper/fog.py @ 20:072ffc1d466f traipse_dev
2nd attempt. Still untested.
author | sirebral |
---|---|
date | Sat, 25 Jul 2009 19:23:25 -0500 |
parents | 78407d627cba |
children | 449a8900f9ac |
comparison
equal
deleted
inserted
replaced
19:78407d627cba | 20:072ffc1d466f |
---|---|
68 if action == "del": | 68 if action == "del": |
69 elem.setAttribute( "action", action ) | 69 elem.setAttribute( "action", action ) |
70 elem.setAttribute( "outline", localOutline ) | 70 elem.setAttribute( "outline", localOutline ) |
71 if localOutline == 'points': | 71 if localOutline == 'points': |
72 list = self.points_to_elements( self.outline ) | 72 list = self.points_to_elements( self.outline ) |
73 for p in list: | 73 for p in list: elem.appendChild( p ) |
74 elem.appendChild( p ) | |
75 str = elem.toxml() | 74 str = elem.toxml() |
76 elem.unlink() | 75 elem.unlink() |
77 self.log.log(str, ORPG_DEBUG) | 76 self.log.log(str, ORPG_DEBUG) |
78 self.log.log("Exit FogArea->toxml(self, " + action + ")", ORPG_DEBUG) | 77 self.log.log("Exit FogArea->toxml(self, " + action + ")", ORPG_DEBUG) |
79 return str | 78 return str |
80 elem.setAttribute( "action", action ) | 79 elem.setAttribute( "action", action ) |
81 if localOutline != None: | 80 if localOutline != None: |
82 elem.setAttribute( "outline", localOutline ) | 81 elem.setAttribute( "outline", localOutline ) |
83 if localOutline == 'points': | 82 if localOutline == 'points': |
84 list = self.points_to_elements( self.outline ) | 83 list = self.points_to_elements( self.outline ) |
85 for p in list: | 84 for p in list: elem.appendChild( p ) |
86 elem.appendChild( p ) | |
87 xml_str = elem.toxml() | 85 xml_str = elem.toxml() |
88 elem.unlink() | 86 elem.unlink() |
89 self.log.log(xml_str, ORPG_DEBUG) | 87 self.log.log(xml_str, ORPG_DEBUG) |
90 self.log.log("Exit FogArea->toxml(self, " + action + ")", ORPG_DEBUG) | 88 self.log.log("Exit FogArea->toxml(self, " + action + ")", ORPG_DEBUG) |
91 return xml_str | 89 return xml_str |
95 self.canvas = canvas | 93 self.canvas = canvas |
96 self.log = self.canvas.log | 94 self.log = self.canvas.log |
97 self.log.log("Enter fog_layer", ORPG_DEBUG) | 95 self.log.log("Enter fog_layer", ORPG_DEBUG) |
98 layer_base.__init__(self) | 96 layer_base.__init__(self) |
99 self.color = wx.Color(128,128,128) | 97 self.color = wx.Color(128,128,128) |
100 if "__WXGTK__" not in wx.PlatformInfo: | 98 if "__WXGTK__" not in wx.PlatformInfo: self.color = wx.Color(128,128,128, 128) |
101 self.color = wx.Color(128,128,128, 128) | |
102 self.fogregion = wx.Region() | 99 self.fogregion = wx.Region() |
103 self.fogregion.Clear() | 100 self.fogregion.Clear() |
104 self.fog_bmp = None | 101 self.fog_bmp = None |
105 self.width = 0 | 102 self.width = 0 |
106 self.height = 0 | 103 self.height = 0 |
130 try: | 127 try: |
131 if self.width == size[0] and self.height == size[1]: | 128 if self.width == size[0] and self.height == size[1]: |
132 self.log.log("Exit fog_layer->resize(self, size)", ORPG_DEBUG) | 129 self.log.log("Exit fog_layer->resize(self, size)", ORPG_DEBUG) |
133 return | 130 return |
134 self.recompute_fog() | 131 self.recompute_fog() |
135 except: | 132 except: pass |
136 pass | |
137 self.log.log("Exit fog_layer->resize(self, size)", ORPG_DEBUG) | 133 self.log.log("Exit fog_layer->resize(self, size)", ORPG_DEBUG) |
138 | 134 |
139 def recompute_fog(self): | 135 def recompute_fog(self): |
140 self.log.log("Enter fog_layer->recompute_fog(self)", ORPG_DEBUG) | 136 self.log.log("Enter fog_layer->recompute_fog(self)", ORPG_DEBUG) |
141 if not self.use_fog: | 137 if not self.use_fog: |
155 return | 151 return |
156 if "__WXGTK__" in wx.PlatformInfo: | 152 if "__WXGTK__" in wx.PlatformInfo: |
157 mdc = wx.MemoryDC() | 153 mdc = wx.MemoryDC() |
158 mdc.SelectObject(self.fog_bmp) | 154 mdc.SelectObject(self.fog_bmp) |
159 mdc.SetPen(wx.TRANSPARENT_PEN) | 155 mdc.SetPen(wx.TRANSPARENT_PEN) |
160 if (self.canvas.frame.session.role == "GM"): | 156 if (self.canvas.frame.session.role == "GM"): color = self.color |
161 color = self.color | 157 else: color = wx.BLACK |
162 else: | |
163 color = wx.BLACK | |
164 self.last_role = self.canvas.frame.session.role | 158 self.last_role = self.canvas.frame.session.role |
165 mdc.SetBrush(wx.Brush(color,wx.SOLID)) | 159 mdc.SetBrush(wx.Brush(color,wx.SOLID)) |
166 mdc.DestroyClippingRegion() | 160 mdc.DestroyClippingRegion() |
167 mdc.DrawRectangle(0, 0, self.width+2, self.height+2) | 161 mdc.DrawRectangle(0, 0, self.width+2, self.height+2) |
168 mdc.SetBrush(wx.Brush(wx.WHITE, wx.SOLID)) | 162 mdc.SetBrush(wx.Brush(wx.WHITE, wx.SOLID)) |
176 def layerDraw(self, dc, topleft, size): | 170 def layerDraw(self, dc, topleft, size): |
177 self.log.log("Enter fog_layer->layerDraw(self, dc, topleft, size)", ORPG_DEBUG) | 171 self.log.log("Enter fog_layer->layerDraw(self, dc, topleft, size)", ORPG_DEBUG) |
178 if self.fog_bmp == None or not self.fog_bmp.Ok() or not self.use_fog: | 172 if self.fog_bmp == None or not self.fog_bmp.Ok() or not self.use_fog: |
179 self.log.log("Exit fog_layer->layerDraw(self, dc, topleft, size)", ORPG_DEBUG) | 173 self.log.log("Exit fog_layer->layerDraw(self, dc, topleft, size)", ORPG_DEBUG) |
180 return | 174 return |
181 if self.last_role != self.canvas.frame.session.role: | 175 if self.last_role != self.canvas.frame.session.role: self.fill_fog() |
182 self.fill_fog() | |
183 if "__WXGTK__" not in wx.PlatformInfo: | 176 if "__WXGTK__" not in wx.PlatformInfo: |
184 gc = wx.GraphicsContext.Create(dc) | 177 gc = wx.GraphicsContext.Create(dc) |
185 gc.SetBrush(wx.Brush(wx.BLACK)) | 178 gc.SetBrush(wx.Brush(wx.BLACK)) |
186 if (self.canvas.frame.session.role == "GM"): | 179 if (self.canvas.frame.session.role == "GM"): |
187 gc.SetBrush(wx.Brush(self.color)) | 180 gc.SetBrush(wx.Brush(self.color)) |
188 rgn = wx.Region(0, 0, self.canvas.size[0]+2, self.canvas.size[1]+2) | 181 rgn = wx.Region(0, 0, self.canvas.size[0]+2, self.canvas.size[1]+2) |
189 if not self.fogregion.IsEmpty(): | 182 if not self.fogregion.IsEmpty(): rgn.SubtractRegion(self.fogregion) |
190 rgn.SubtractRegion(self.fogregion) | |
191 gc.ClipRegion(rgn) | 183 gc.ClipRegion(rgn) |
192 gc.DrawRectangle(0, 0, self.canvas.size[0]+2, self.canvas.size[1]+2) | 184 gc.DrawRectangle(0, 0, self.canvas.size[0]+2, self.canvas.size[1]+2) |
193 else: | 185 else: |
194 sc = dc.GetUserScale() | 186 sc = dc.GetUserScale() |
195 bmp = wx.EmptyBitmap(size[0],size[1]) | 187 bmp = wx.EmptyBitmap(size[0],size[1]) |
200 mdc.SetBrush(wx.Brush(wx.WHITE, wx.SOLID)) | 192 mdc.SetBrush(wx.Brush(wx.WHITE, wx.SOLID)) |
201 mdc.DrawRectangle(0,0,size[0],size[1]) | 193 mdc.DrawRectangle(0,0,size[0],size[1]) |
202 srct = [int(topleft[0]/(sc[0]*COURSE)), int(topleft[1]/(sc[1]*COURSE))] | 194 srct = [int(topleft[0]/(sc[0]*COURSE)), int(topleft[1]/(sc[1]*COURSE))] |
203 srcsz = [int((int(size[0]/COURSE+1)*COURSE)/(sc[0]*COURSE))+2, | 195 srcsz = [int((int(size[0]/COURSE+1)*COURSE)/(sc[0]*COURSE))+2, |
204 int((int(size[1]/COURSE+1)*COURSE)/(sc[1]*COURSE))+2] | 196 int((int(size[1]/COURSE+1)*COURSE)/(sc[1]*COURSE))+2] |
205 if (srct[0]+srcsz[0] > self.width): | 197 if (srct[0]+srcsz[0] > self.width): srcsz[0] = self.width-srct[0] |
206 srcsz[0] = self.width-srct[0] | 198 if (srct[1]+srcsz[1] > self.height): srcsz[1] = self.height-srct[1] |
207 if (srct[1]+srcsz[1] > self.height): | |
208 srcsz[1] = self.height-srct[1] | |
209 img = wx.ImageFromBitmap(self.fog_bmp).GetSubImage(wx.Rect(srct[0], srct[1], srcsz[0], srcsz[1])) | 199 img = wx.ImageFromBitmap(self.fog_bmp).GetSubImage(wx.Rect(srct[0], srct[1], srcsz[0], srcsz[1])) |
210 img.Rescale(srcsz[0]*COURSE*sc[0], srcsz[1]*COURSE*sc[1]) | 200 img.Rescale(srcsz[0]*COURSE*sc[0], srcsz[1]*COURSE*sc[1]) |
211 fog = wx.BitmapFromImage(img) | 201 fog = wx.BitmapFromImage(img) |
212 mdc.SetDeviceOrigin(-topleft[0], -topleft[1]) | 202 mdc.SetDeviceOrigin(-topleft[0], -topleft[1]) |
213 mdc.DrawBitmap(fog, srct[0]*COURSE*sc[0], srct[1]*COURSE*sc[1]) | 203 mdc.DrawBitmap(fog, srct[0]*COURSE*sc[0], srct[1]*COURSE*sc[1]) |
230 area += ";" | 220 area += ";" |
231 area += str(i.X) + "," + str(i.Y) | 221 area += str(i.X) + "," + str(i.Y) |
232 if mode == 'new': | 222 if mode == 'new': |
233 if self.fogregion.IsEmpty(): | 223 if self.fogregion.IsEmpty(): |
234 self.fogregion = regn | 224 self.fogregion = regn |
235 else: | 225 else: self.fogregion.UnionRegion(regn) |
236 self.fogregion.UnionRegion(regn) | |
237 self.add_area(area, show) | 226 self.add_area(area, show) |
238 else: | 227 else: |
239 if not self.fogregion.IsEmpty(): | 228 if not self.fogregion.IsEmpty(): |
240 self.fogregion.SubtractRegion(regn) | 229 self.fogregion.SubtractRegion(regn) |
241 else: | 230 else: |
261 list = IRegion().scan_Convert(polypt) | 250 list = IRegion().scan_Convert(polypt) |
262 for i in list: | 251 for i in list: |
263 if regn.IsEmpty(): | 252 if regn.IsEmpty(): |
264 if "__WXGTK__" not in wx.PlatformInfo: | 253 if "__WXGTK__" not in wx.PlatformInfo: |
265 regn = wx.Region(i.left*COURSE, i.y*COURSE, i.right*COURSE+1-i.left*COURSE, 1*COURSE) | 254 regn = wx.Region(i.left*COURSE, i.y*COURSE, i.right*COURSE+1-i.left*COURSE, 1*COURSE) |
266 else: | 255 else: regn = wx.Region(i.left, i.y, i.right+1-i.left, 1) |
267 regn = wx.Region(i.left, i.y, i.right+1-i.left, 1) | |
268 else: | 256 else: |
269 if "__WXGTK__" not in wx.PlatformInfo: | 257 if "__WXGTK__" not in wx.PlatformInfo: |
270 regn.Union(i.left*COURSE, i.y*COURSE, i.right*COURSE+1-i.left*COURSE, 1*COURSE) | 258 regn.Union(i.left*COURSE, i.y*COURSE, i.right*COURSE+1-i.left*COURSE, 1*COURSE) |
271 else: | 259 else: regn.Union(i.left, i.y, i.right+1-i.left, 1) |
272 regn.Union(i.left, i.y, i.right+1-i.left, 1) | |
273 self.log.log("Exit fog_layer->scanConvert(self, polypt)", ORPG_DEBUG) | 260 self.log.log("Exit fog_layer->scanConvert(self, polypt)", ORPG_DEBUG) |
274 return regn | 261 return regn |
275 | 262 |
276 def add_area(self, area="", show="Yes"): | 263 def add_area(self, area="", show="Yes"): |
277 self.log.log("Enter fog_layer->add_area(self, area, show)", ORPG_DEBUG) | 264 self.log.log("Enter fog_layer->add_area(self, area, show)", ORPG_DEBUG) |
278 poly = FogArea(area, self.log) | 265 poly = FogArea(area, self.log) |
279 xml_str = "<map><fog>" | 266 xml_str = "<map><fog>" |
280 xml_str += poly.toxml("new") | 267 xml_str += poly.toxml("new") |
281 xml_str += "</fog></map>" | 268 xml_str += "</fog></map>" |
282 if show == "Yes": | 269 if show == "Yes": self.canvas.frame.session.send(xml_str) |
283 self.canvas.frame.session.send(xml_str) | |
284 self.log.log(xml_str, ORPG_DEBUG) | 270 self.log.log(xml_str, ORPG_DEBUG) |
285 self.log.log("Exit fog_layer->add_area(self, area, show)", ORPG_DEBUG) | 271 self.log.log("Exit fog_layer->add_area(self, area, show)", ORPG_DEBUG) |
286 | 272 |
287 def del_area(self, area="", show="Yes"): | 273 def del_area(self, area="", show="Yes"): |
288 self.log.log("Enter fog_layer->del_area(self, area, show)", ORPG_DEBUG) | 274 self.log.log("Enter fog_layer->del_area(self, area, show)", ORPG_DEBUG) |
289 poly = FogArea(area, self.log) | 275 poly = FogArea(area, self.log) |
290 xml_str = "<map><fog>" | 276 xml_str = "<map><fog>" |
291 xml_str += poly.toxml("del") | 277 xml_str += poly.toxml("del") |
292 xml_str += "</fog></map>" | 278 xml_str += "</fog></map>" |
293 if show == "Yes": | 279 if show == "Yes": self.canvas.frame.session.send(xml_str) |
294 self.canvas.frame.session.send(xml_str) | |
295 self.log.log(xml_str, ORPG_DEBUG) | 280 self.log.log(xml_str, ORPG_DEBUG) |
296 self.log.log("Exit fog_layer->del_area(self, area, show)", ORPG_DEBUG) | 281 self.log.log("Exit fog_layer->del_area(self, area, show)", ORPG_DEBUG) |
297 | 282 |
298 def layerToXML(self, action="update"): | 283 def layerToXML(self, action="update"): |
299 self.log.log("Enter fog_layer->layerToXML(self, " + action + ")", ORPG_DEBUG) | 284 self.log.log("Enter fog_layer->layerToXML(self, " + action + ")", ORPG_DEBUG) |
300 if not self.use_fog: | 285 if not self.use_fog: |
301 self.log.log("Exit fog_layer->layerToXML(self, " + action + ") return None", ORPG_DEBUG) | 286 self.log.log("Exit fog_layer->layerToXML(self, " + action + ") return None", ORPG_DEBUG) |
302 return "" | 287 return "" |
303 fog_string = "" | 288 fog_string = "" |
304 ri = wx.RegionIterator(self.fogregion) | 289 ri = wx.RegionIterator(self.fogregion) |
305 if not (ri.HaveRects()): | 290 if not (ri.HaveRects()): fog_string = FogArea("all", self.log).toxml("del") |
306 fog_string = FogArea("all", self.log).toxml("del") | |
307 while ri.HaveRects(): | 291 while ri.HaveRects(): |
308 if "__WXGTK__" not in wx.PlatformInfo: | 292 if "__WXGTK__" not in wx.PlatformInfo: |
309 x1 = ri.GetX()/COURSE | 293 x1 = ri.GetX()/COURSE |
310 x2 = x1+(ri.GetW()/COURSE)-1 | 294 x2 = x1+(ri.GetW()/COURSE)-1 |
311 y1 = ri.GetY()/COURSE | 295 y1 = ri.GetY()/COURSE |
337 self.log.log("Enter fog_layer->layerTakeDOM(self, xml_dom)", ORPG_DEBUG) | 321 self.log.log("Enter fog_layer->layerTakeDOM(self, xml_dom)", ORPG_DEBUG) |
338 try: | 322 try: |
339 if not self.use_fog: | 323 if not self.use_fog: |
340 self.use_fog = True | 324 self.use_fog = True |
341 self.recompute_fog() | 325 self.recompute_fog() |
342 if xml_dom.hasAttribute('serial'): | 326 if xml_dom.hasAttribute('serial'): self.serial_number = int(xml_dom.getAttribute('serial')) |
343 self.serial_number = int(xml_dom.getAttribute('serial')) | |
344 children = xml_dom._get_childNodes() | 327 children = xml_dom._get_childNodes() |
345 for l in children: | 328 for l in children: |
346 action = l.getAttribute("action") | 329 action = l.getAttribute("action") |
347 outline = l.getAttribute("outline") | 330 outline = l.getAttribute("outline") |
348 if (outline == "all"): | 331 if (outline == "all"): |
363 y = point.getAttribute( "y" ) | 346 y = point.getAttribute( "y" ) |
364 if (x != lastx or y != lasty): | 347 if (x != lastx or y != lasty): |
365 polyline.append(IPoint().make(int(x), int(y))) | 348 polyline.append(IPoint().make(int(x), int(y))) |
366 lastx = x | 349 lastx = x |
367 lasty = y | 350 lasty = y |
368 if (len(polyline) > 1): | 351 if (len(polyline) > 1): self.createregn2(polyline, action, "No") |
369 self.createregn2(polyline, action, "No") | |
370 self.fill_fog() | 352 self.fill_fog() |
371 except: | 353 except: self.log.log(traceback.format_exc(), ORPG_GENERAL) |
372 self.log.log(traceback.format_exc(), ORPG_GENERAL) | |
373 self.log.log("Exit fog_layer->layerTakeDOM(self, xml_dom)", ORPG_DEBUG) | 354 self.log.log("Exit fog_layer->layerTakeDOM(self, xml_dom)", ORPG_DEBUG) |