comparison orpg/mapper/map.py @ 227:81d0bfd5e800 alpha

Traipse Alpha 'OpenRPG' {100612-00} Traipse is a distribution of OpenRPG that is designed to be easy to setup and go. Traipse also makes it easy for developers to work on code without fear of sacrifice. 'Ornery-Orc' continues the trend of 'Grumpy' and adds fixes to the code. 'Ornery-Orc's main goal is to offer more advanced features and enhance the productivity of the user. Update Summary (Preparing to close updates) New Features: New to Map, can re-order Grid, Miniatures, and Whiteboard layer draw order Fixes: Fix to InterParse that was causing an Infernal Loop with Namespace Internal Fix to XML data, removed old Minidom and switched to Element Tree Fix to Server that was causing eternal attempt to find a Server ID, in Register Rooms thread Fix to metaservers.xml file not being created
author sirebral
date Sat, 12 Jun 2010 03:50:37 -0500
parents ff19dd30064b
children
comparison
equal deleted inserted replaced
182:4b2884f29a72 227:81d0bfd5e800
19 # 19 #
20 # File: mapper/map.py 20 # File: mapper/map.py
21 # Author: OpenRPG 21 # Author: OpenRPG
22 # Maintainer: 22 # Maintainer:
23 # Version: 23 # Version:
24 # $Id: map.py,v 1.73 2007/12/07 20:39:49 digitalxero Exp $ 24 # $Id: map.py,v Traipse 'Ornery-Orc' prof.ebral Exp $
25 # 25 #
26 # Description: 26 # Description:
27 # 27 #
28 __version__ = "$Id: map.py,v 1.73 2007/12/07 20:39:49 digitalxero Exp $" 28 __version__ = "$Id: map.py,v Traipse 'Ornery-Orc' prof.ebral Exp $"
29 29
30 from map_version import MAP_VERSION 30 from map_version import MAP_VERSION
31 from map_msg import * 31 from map_msg import *
32 from min_dialogs import * 32 from min_dialogs import *
33 from map_prop_dialog import * 33 from map_prop_dialog import *
43 43
44 from orpg.dirpath import dir_struct 44 from orpg.dirpath import dir_struct
45 from images import ImageHandler 45 from images import ImageHandler
46 from orpg.orpgCore import component 46 from orpg.orpgCore import component
47 from orpg.tools.orpg_settings import settings 47 from orpg.tools.orpg_settings import settings
48 from xml.etree.ElementTree import ElementTree, Element, parse
49 from xml.etree.ElementTree import fromstring, tostring
48 50
49 # Various marker modes for player tools on the map 51 # Various marker modes for player tools on the map
50 MARKER_MODE_NONE = 0 52 MARKER_MODE_NONE = 0
51 MARKER_MODE_MEASURE = 1 53 MARKER_MODE_MEASURE = 1
52 MARKER_MODE_TARGET = 2 54 MARKER_MODE_TARGET = 2
154 cacheSize = component.get('settings').get_setting("ImageCacheSize") 156 cacheSize = component.get('settings').get_setting("ImageCacheSize")
155 if len(cacheSize): self.cacheSize = int(cacheSize) 157 if len(cacheSize): self.cacheSize = int(cacheSize)
156 else: pass 158 else: pass
157 if not ImageHandler.Queue.empty(): 159 if not ImageHandler.Queue.empty():
158 (path, image_type, imageId) = ImageHandler.Queue.get() 160 (path, image_type, imageId) = ImageHandler.Queue.get()
159 if path == 'failed': img = wx.Image(dir_struct["icon"] + "failed.png", wx.BITMAP_TYPE_PNG) 161 if (path == 'failed' or path == dir_struct["icon"] + "failed.png"):
162 img = wx.Image(dir_struct["icon"] + "failed.png", wx.BITMAP_TYPE_PNG)
160 else: img = wx.ImageFromMime(path[1], path[2]) 163 else: img = wx.ImageFromMime(path[1], path[2])
161 try: 164 try:
162 # Now, apply the image to the proper object 165 # Now, apply the image to the proper object
163 if image_type == "miniature": 166 if image_type == "miniature":
164 min = self.layers['miniatures'].get_miniature_by_id(imageId) 167 min = self.layers['miniatures'].get_miniature_by_id(imageId)
248 scrollsize = self.GetScrollPixelsPerUnit() 251 scrollsize = self.GetScrollPixelsPerUnit()
249 clientsize = self.GetClientSize() 252 clientsize = self.GetClientSize()
250 topleft1 = self.GetViewStart() 253 topleft1 = self.GetViewStart()
251 topleft = [topleft1[0]*scrollsize[0], topleft1[1]*scrollsize[1]] 254 topleft = [topleft1[0]*scrollsize[0], topleft1[1]*scrollsize[1]]
252 if (clientsize[0] > 1) and (clientsize[1] > 1): 255 if (clientsize[0] > 1) and (clientsize[1] > 1):
253 self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM) 256 dc = wx.MemoryDC()
254 dc = wx.AutoBufferedPaintDC(self) 257 bmp = wx.EmptyBitmap(clientsize[0]+1, clientsize[1]+1)
258 dc.SelectObject(bmp)
255 dc.SetPen(wx.TRANSPARENT_PEN) 259 dc.SetPen(wx.TRANSPARENT_PEN)
256 dc.SetBrush(wx.Brush(self.GetBackgroundColour(), wx.SOLID)) 260 dc.SetBrush(wx.Brush(self.GetBackgroundColour(), wx.SOLID))
257 dc.DrawRectangle(0,0,clientsize[0]+1,clientsize[1]+1) 261 dc.DrawRectangle(0,0,clientsize[0]+1,clientsize[1]+1)
258 dc.SetDeviceOrigin(-topleft[0], -topleft[1]) 262 dc.SetDeviceOrigin(-topleft[0], -topleft[1])
259 dc.SetUserScale(scale, scale) 263 dc.SetUserScale(scale, scale)
264
265 layer_order = []
266 for i in xrange (0, len(self.parent.layer_handlers)-1):
267 if self.parent.layer_tabs.GetPageText(i) in ('Background', 'Fog', 'General'): pass
268 else: layer_order.append(self.parent.layer_tabs.GetPageText(i))
260 self.layers['bg'].layerDraw(dc, scale, topleft, clientsize) 269 self.layers['bg'].layerDraw(dc, scale, topleft, clientsize)
261 self.layers['grid'].layerDraw(dc, [topleft[0]/scale, topleft[1]/scale], 270
262 [clientsize[0]/scale, clientsize[1]/scale]) 271 for layer in layer_order:
263 self.layers['miniatures'].layerDraw(dc, [topleft[0]/scale, topleft[1]/scale], 272 if layer == 'Grid': self.layers['grid'].layerDraw(dc, [topleft[0]/scale, topleft[1]/scale],
264 [clientsize[0]/scale, clientsize[1]/scale]) 273 [clientsize[0]/scale, clientsize[1]/scale])
265 self.layers['whiteboard'].layerDraw(dc) 274 if layer == 'Miniatures': self.layers['miniatures'].layerDraw(dc, [topleft[0]/scale, topleft[1]/scale],
275 [clientsize[0]/scale, clientsize[1]/scale])
276 if layer == 'Whiteboard': self.layers['whiteboard'].layerDraw(dc)
277
266 self.layers['fog'].layerDraw(dc, topleft, clientsize) 278 self.layers['fog'].layerDraw(dc, topleft, clientsize)
267 dc.SetPen(wx.NullPen) 279 dc.SetPen(wx.NullPen)
268 dc.SetBrush(wx.NullBrush) 280 dc.SetBrush(wx.NullBrush)
281 dc.SelectObject(wx.NullBitmap); del dc
282 wdc = self.preppaint()
283 wdc.DrawBitmap(bmp, topleft[0], topleft[1])
269 if settings.get_setting("AlwaysShowMapScale") == "1": 284 if settings.get_setting("AlwaysShowMapScale") == "1":
270 self.showmapscale(dc) 285 self.showmapscale(wdc)
271 try: evt.Skip() 286 try: evt.Skip()
272 except: pass 287 except: pass
288
289 def preppaint(self):
290 dc = wx.PaintDC(self)
291 self.PrepareDC(dc)
292 return (dc)
273 293
274 def showmapscale(self, dc): 294 def showmapscale(self, dc):
275 scalestring = "Scale x" + `self.layers['grid'].mapscale`[:3] 295 scalestring = "Scale x" + `self.layers['grid'].mapscale`[:3]
276 (textWidth, textHeight) = dc.GetTextExtent(scalestring) 296 (textWidth, textHeight) = dc.GetTextExtent(scalestring)
277 dc.SetUserScale(1, 1) 297 dc.SetUserScale(1, 1)
365 dc = wx.ClientDC( self ) 385 dc = wx.ClientDC( self )
366 self.PrepareDC( dc ) 386 self.PrepareDC( dc )
367 dc.SetUserScale(self.layers['grid'].mapscale,self.layers['grid'].mapscale) 387 dc.SetUserScale(self.layers['grid'].mapscale,self.layers['grid'].mapscale)
368 # Grab the current map position 388 # Grab the current map position
369 pos = self.snapMarker( evt.GetLogicalPosition( dc ) ) 389 pos = self.snapMarker( evt.GetLogicalPosition( dc ) )
370 # Enable brush optimizations
371 # dc.SetOptimization( True )
372 # Set up the pen used for drawing our marker 390 # Set up the pen used for drawing our marker
373 dc.SetPen( wx.Pen(wx.RED, 1, wx.LONG_DASH) ) 391 dc.SetPen( wx.Pen(wx.RED, 1, wx.LONG_DASH) )
374 # Now, based on the marker mode, draw the right thing 392 # Now, based on the marker mode, draw the right thing
375 if self.markerMode == MARKER_MODE_MEASURE: 393 if self.markerMode == MARKER_MODE_MEASURE:
376 if self.markerStop.x != -1 and self.markerStop.y != -1: 394 if self.markerStop.x != -1 and self.markerStop.y != -1:
384 # Restore the default DC function 402 # Restore the default DC function
385 dc.SetLogicalFunction(wx.COPY) 403 dc.SetLogicalFunction(wx.COPY)
386 # As long as we are in marker mode, we ned to update the stop point 404 # As long as we are in marker mode, we ned to update the stop point
387 self.markerStop = pos 405 self.markerStop = pos
388 dc.SetPen(wx.NullPen) 406 dc.SetPen(wx.NullPen)
389 # Disable brush optimizations
390 #dc.SetOptimization( False )
391 del dc 407 del dc
392 408
393 def on_tape_down(self, evt): 409 def on_tape_down(self, evt):
394 """Greg's experimental tape measure code. Hopefully, when this is done, it will all be 410 """Greg's experimental tape measure code. Hopefully, when this is done, it will all be
395 modal based on a toolbar.""" 411 modal based on a toolbar."""
401 pos = self.snapMarker( evt.GetLogicalPosition( dc ) ) 417 pos = self.snapMarker( evt.GetLogicalPosition( dc ) )
402 # Maker mode should really be set by a toolbar 418 # Maker mode should really be set by a toolbar
403 self.markerMode = MARKER_MODE_MEASURE 419 self.markerMode = MARKER_MODE_MEASURE
404 # Erase the old line if her have one 420 # Erase the old line if her have one
405 if self.markerStart.x != -1 and self.markerStart.y != -1: 421 if self.markerStart.x != -1 and self.markerStart.y != -1:
406 # Enable brush optimizations
407 #dc.SetOptimization( True )
408 # Set up the pen used for drawing our marker 422 # Set up the pen used for drawing our marker
409 dc.SetPen( wx.Pen(wx.RED, 1, wx.LONG_DASH) ) 423 dc.SetPen( wx.Pen(wx.RED, 1, wx.LONG_DASH) )
410 # Set the DC function that we need 424 # Set the DC function that we need
411 dc.SetLogicalFunction(wx.INVERT) 425 dc.SetLogicalFunction(wx.INVERT)
412 # Draw the marker line 426 # Draw the marker line
414 dc.DrawLine( self.markerStart.x, self.markerStart.y, self.markerStop.x, self.markerStop.y ) 428 dc.DrawLine( self.markerStart.x, self.markerStart.y, self.markerStop.x, self.markerStop.y )
415 dc.EndDrawing() 429 dc.EndDrawing()
416 # Restore the default DC function and pen 430 # Restore the default DC function and pen
417 dc.SetLogicalFunction(wx.COPY) 431 dc.SetLogicalFunction(wx.COPY)
418 dc.SetPen(wx.NullPen) 432 dc.SetPen(wx.NullPen)
419 # Disable brush optimizations
420 #dc.SetOptimization( False )
421 # Save our current start and reset the stop value 433 # Save our current start and reset the stop value
422 self.markerStart = pos 434 self.markerStart = pos
423 self.markerStop = pos 435 self.markerStop = pos
424 del dc 436 del dc
425 437
615 627
616 Apparently Process Dialog causes problems with linux.. commenting it out. sheez. 628 Apparently Process Dialog causes problems with linux.. commenting it out. sheez.
617 --Snowdog 5/27/03 629 --Snowdog 5/27/03
618 """ 630 """
619 try: 631 try:
620 #parse the map DOM 632 xml_dom = fromstring(xml)
621 xml_dom = parseXml(xml)
622 if xml_dom == None: return 633 if xml_dom == None: return
623 node_list = xml_dom.getElementsByTagName("map") 634 node_list = xml_dom.findall("map")
635 if len(node_list) < 1:
636 if xml_dom.tag == 'map': node_list = [xml_dom]
624 if len(node_list) < 1: pass 637 if len(node_list) < 1: pass
625 else: 638 else:
626 # set map version to incoming data so layers can convert 639 # set map version to incoming data so layers can convert
627 self.map_version = node_list[0].getAttribute("version") 640 self.map_version = node_list[0].get("version")
628 action = node_list[0].getAttribute("action") 641 action = node_list[0].get("action")
629 if action == "new": 642 if action == "new":
630 self.layers = {} 643 self.layers = {}
631 try: self.layers['bg'] = layer_back_ground(self) 644 try: self.layers['bg'] = layer_back_ground(self)
632 except: pass 645 except: pass
633 try: self.layers['grid'] = grid_layer(self) 646 try: self.layers['grid'] = grid_layer(self)
636 except: pass 649 except: pass
637 try: self.layers['whiteboard'] = whiteboard_layer(self) 650 try: self.layers['whiteboard'] = whiteboard_layer(self)
638 except: pass 651 except: pass
639 try: self.layers['fog'] = fog_layer(self) 652 try: self.layers['fog'] = fog_layer(self)
640 except: pass 653 except: pass
641 sizex = node_list[0].getAttribute("sizex") 654 sizex = node_list[0].get("sizex") or ''
642 if sizex != "": 655 if sizex != "":
643 sizex = int(float(sizex)) 656 sizex = int(float(sizex))
644 sizey = self.size[1] 657 sizey = self.size[1]
645 self.set_size((sizex,sizey)) 658 self.set_size((sizex,sizey))
646 self.size_changed = 0 659 self.size_changed = 0
647 sizey = node_list[0].getAttribute("sizey") 660 sizey = node_list[0].get("sizey") or ''
648 if sizey != "": 661 if sizey != "":
649 sizey = int(float(sizey)) 662 sizey = int(float(sizey))
650 sizex = self.size[0] 663 sizex = self.size[0]
651 self.set_size((sizex,sizey)) 664 self.set_size((sizex,sizey))
652 self.size_changed = 0 665 self.size_changed = 0
653 children = node_list[0]._get_childNodes() 666 children = node_list[0].getchildren()
654 #fog layer must be computed first, so that no data is inadvertently revealed 667 #fog layer must be computed first, so that no data is inadvertently revealed
655 for c in children: 668 for c in children:
656 name = c._get_nodeName() 669 name = c.tag
657 if name == "fog": self.layers[name].layerTakeDOM(c) 670 if name == "fog": self.layers[name].layerTakeDOM(c)
658 for c in children: 671 for c in children:
659 name = c._get_nodeName() 672 name = c.tag
660 if name != "fog": self.layers[name].layerTakeDOM(c) 673 if name != "fog": self.layers[name].layerTakeDOM(c)
661 # all map data should be converted, set map version to current version 674 # all map data should be converted, set map version to current version
662 self.map_version = MAP_VERSION 675 self.map_version = MAP_VERSION
663 self.Refresh(False) 676 self.Refresh(True)
664 xml_dom.unlink() # eliminate circular refs
665 except: pass 677 except: pass
666 678
667 def re_ids_in_xml(self, xml): 679 def re_ids_in_xml(self, xml):
680 debug(('Developers note. Deprecated call to re_ids_in_xml!!'), parents=True)
668 new_xml = "" 681 new_xml = ""
669 tmp_map = map_msg() 682 tmp_map = map_msg()
670 xml_dom = parseXml(str(xml)) 683 xml_dom = parseXml(str(xml))
671 node_list = xml_dom.getElementsByTagName("map") 684 node_list = xml_dom.getElementsByTagName("map")
672 if len(node_list) < 1: pass 685 if len(node_list) < 1: pass
707 self.top_frame = component.get('frame') 720 self.top_frame = component.get('frame')
708 self.chat = self.top_frame.chat 721 self.chat = self.top_frame.chat
709 self.root_dir = os.getcwd() 722 self.root_dir = os.getcwd()
710 self.current_layer = 2 723 self.current_layer = 2
711 self.layer_tabs = orpgTabberWnd(self, style=FNB.FNB_NO_X_BUTTON|FNB.FNB_BOTTOM|FNB.FNB_NO_NAV_BUTTONS) 724 self.layer_tabs = orpgTabberWnd(self, style=FNB.FNB_NO_X_BUTTON|FNB.FNB_BOTTOM|FNB.FNB_NO_NAV_BUTTONS)
725
712 self.layer_handlers = [] 726 self.layer_handlers = []
713 self.layer_handlers.append(background_handler(self.layer_tabs,-1,self.canvas)) 727 self.layer_handlers.append(background_handler(self.layer_tabs, -1, self.canvas))
714 self.layer_tabs.AddPage(self.layer_handlers[0],"Background") 728 self.layer_tabs.AddPage(self.layer_handlers[0], "Background")
715 self.layer_handlers.append(grid_handler(self.layer_tabs,-1,self.canvas)) 729 self.layer_handlers.append(grid_handler(self.layer_tabs, -1, self.canvas))
716 self.layer_tabs.AddPage(self.layer_handlers[1],"Grid") 730 self.layer_tabs.AddPage(self.layer_handlers[1], "Grid")
717 self.layer_handlers.append(miniatures_handler(self.layer_tabs,-1,self.canvas)) 731 self.layer_handlers.append(miniatures_handler(self.layer_tabs, -1, self.canvas))
718 self.layer_tabs.AddPage(self.layer_handlers[2],"Miniatures", True) 732 self.layer_tabs.AddPage(self.layer_handlers[2], "Miniatures", True)
719 self.layer_handlers.append(whiteboard_handler(self.layer_tabs,-1,self.canvas)) 733 self.layer_handlers.append(whiteboard_handler(self.layer_tabs, -1, self.canvas))
720 self.layer_tabs.AddPage(self.layer_handlers[3],"Whiteboard") 734 self.layer_tabs.AddPage(self.layer_handlers[3], "Whiteboard")
721 self.layer_handlers.append(fog_handler(self.layer_tabs,-1,self.canvas)) 735 self.layer_handlers.append(fog_handler(self.layer_tabs, -1, self.canvas))
722 self.layer_tabs.AddPage(self.layer_handlers[4],"Fog") 736 self.layer_tabs.AddPage(self.layer_handlers[4], "Fog")
723 self.layer_handlers.append(map_handler(self.layer_tabs,-1,self.canvas)) 737 self.layer_handlers.append(map_handler(self.layer_tabs, -1, self.canvas))
724 self.layer_tabs.AddPage(self.layer_handlers[5],"General") 738 self.layer_tabs.AddPage(self.layer_handlers[5], "General")
725 self.layer_tabs.SetSelection(2) 739 self.layer_tabs.SetSelection(2)
740
741 self.layer_order = {1: 'grid', 2: 'miniatures', 3: 'whiteboard'}
726 self.sizer = wx.BoxSizer(wx.VERTICAL) 742 self.sizer = wx.BoxSizer(wx.VERTICAL)
727 self.sizer.Add(self.canvas, 1, wx.EXPAND) 743 self.sizer.Add(self.canvas, 1, wx.EXPAND)
728 self.sizer.Add(self.layer_tabs, 0, wx.EXPAND) 744 self.sizer.Add(self.layer_tabs, 0, wx.EXPAND)
729 self.SetSizer(self.sizer) 745 self.SetSizer(self.sizer)
730 self.Bind(FNB.EVT_FLATNOTEBOOK_PAGE_CHANGED, self.on_layer_change) 746 self.Bind(FNB.EVT_FLATNOTEBOOK_PAGE_CHANGED, self.on_layer_change)