comparison orpg/mapper/map.py @ 228:24769389a7ba alpha

Traipse Alpha 'OpenRPG' {100612-01} 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 04:38:29 -0500
parents ff36cdfcf515
children cc7629ab526d
comparison
equal deleted inserted replaced
225:2c6db2043764 228:24769389a7ba
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
257 dc.SetPen(wx.TRANSPARENT_PEN) 259 dc.SetPen(wx.TRANSPARENT_PEN)
258 dc.SetBrush(wx.Brush(self.GetBackgroundColour(), wx.SOLID)) 260 dc.SetBrush(wx.Brush(self.GetBackgroundColour(), wx.SOLID))
259 dc.DrawRectangle(0,0,clientsize[0]+1,clientsize[1]+1) 261 dc.DrawRectangle(0,0,clientsize[0]+1,clientsize[1]+1)
260 dc.SetDeviceOrigin(-topleft[0], -topleft[1]) 262 dc.SetDeviceOrigin(-topleft[0], -topleft[1])
261 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))
262 self.layers['bg'].layerDraw(dc, scale, topleft, clientsize) 269 self.layers['bg'].layerDraw(dc, scale, topleft, clientsize)
263 self.layers['grid'].layerDraw(dc, [topleft[0]/scale, topleft[1]/scale], 270
264 [clientsize[0]/scale, clientsize[1]/scale]) 271 for layer in layer_order:
265 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],
266 [clientsize[0]/scale, clientsize[1]/scale]) 273 [clientsize[0]/scale, clientsize[1]/scale])
267 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
268 self.layers['fog'].layerDraw(dc, topleft, clientsize) 278 self.layers['fog'].layerDraw(dc, topleft, clientsize)
269 dc.SetPen(wx.NullPen) 279 dc.SetPen(wx.NullPen)
270 dc.SetBrush(wx.NullBrush) 280 dc.SetBrush(wx.NullBrush)
271 281 dc.SelectObject(wx.NullBitmap); del dc
272 dc.SelectObject(wx.NullBitmap)
273 del dc
274 wdc = self.preppaint() 282 wdc = self.preppaint()
275 wdc.DrawBitmap(bmp, topleft[0], topleft[1]) 283 wdc.DrawBitmap(bmp, topleft[0], topleft[1])
276
277 if settings.get_setting("AlwaysShowMapScale") == "1": 284 if settings.get_setting("AlwaysShowMapScale") == "1":
278 self.showmapscale(wdc) 285 self.showmapscale(wdc)
279 try: evt.Skip() 286 try: evt.Skip()
280 except: pass 287 except: pass
281 288
620 627
621 Apparently Process Dialog causes problems with linux.. commenting it out. sheez. 628 Apparently Process Dialog causes problems with linux.. commenting it out. sheez.
622 --Snowdog 5/27/03 629 --Snowdog 5/27/03
623 """ 630 """
624 try: 631 try:
625 #parse the map DOM 632 xml_dom = fromstring(xml)
626 xml_dom = parseXml(xml)
627 if xml_dom == None: return 633 if xml_dom == None: return
628 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]
629 if len(node_list) < 1: pass 637 if len(node_list) < 1: pass
630 else: 638 else:
631 # set map version to incoming data so layers can convert 639 # set map version to incoming data so layers can convert
632 self.map_version = node_list[0].getAttribute("version") 640 self.map_version = node_list[0].get("version")
633 action = node_list[0].getAttribute("action") 641 action = node_list[0].get("action")
634 if action == "new": 642 if action == "new":
635 self.layers = {} 643 self.layers = {}
636 try: self.layers['bg'] = layer_back_ground(self) 644 try: self.layers['bg'] = layer_back_ground(self)
637 except: pass 645 except: pass
638 try: self.layers['grid'] = grid_layer(self) 646 try: self.layers['grid'] = grid_layer(self)
641 except: pass 649 except: pass
642 try: self.layers['whiteboard'] = whiteboard_layer(self) 650 try: self.layers['whiteboard'] = whiteboard_layer(self)
643 except: pass 651 except: pass
644 try: self.layers['fog'] = fog_layer(self) 652 try: self.layers['fog'] = fog_layer(self)
645 except: pass 653 except: pass
646 sizex = node_list[0].getAttribute("sizex") 654 sizex = node_list[0].get("sizex") or ''
647 if sizex != "": 655 if sizex != "":
648 sizex = int(float(sizex)) 656 sizex = int(float(sizex))
649 sizey = self.size[1] 657 sizey = self.size[1]
650 self.set_size((sizex,sizey)) 658 self.set_size((sizex,sizey))
651 self.size_changed = 0 659 self.size_changed = 0
652 sizey = node_list[0].getAttribute("sizey") 660 sizey = node_list[0].get("sizey") or ''
653 if sizey != "": 661 if sizey != "":
654 sizey = int(float(sizey)) 662 sizey = int(float(sizey))
655 sizex = self.size[0] 663 sizex = self.size[0]
656 self.set_size((sizex,sizey)) 664 self.set_size((sizex,sizey))
657 self.size_changed = 0 665 self.size_changed = 0
658 children = node_list[0]._get_childNodes() 666 children = node_list[0].getchildren()
659 #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
660 for c in children: 668 for c in children:
661 name = c._get_nodeName() 669 name = c.tag
662 if name == "fog": self.layers[name].layerTakeDOM(c) 670 if name == "fog": self.layers[name].layerTakeDOM(c)
663 for c in children: 671 for c in children:
664 name = c._get_nodeName() 672 name = c.tag
665 if name != "fog": self.layers[name].layerTakeDOM(c) 673 if name != "fog": self.layers[name].layerTakeDOM(c)
666 # 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
667 self.map_version = MAP_VERSION 675 self.map_version = MAP_VERSION
668 self.Refresh(False) 676 self.Refresh(True)
669 xml_dom.unlink() # eliminate circular refs
670 except: pass 677 except: pass
671 678
672 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)
673 new_xml = "" 681 new_xml = ""
674 tmp_map = map_msg() 682 tmp_map = map_msg()
675 xml_dom = parseXml(str(xml)) 683 xml_dom = parseXml(str(xml))
676 node_list = xml_dom.getElementsByTagName("map") 684 node_list = xml_dom.getElementsByTagName("map")
677 if len(node_list) < 1: pass 685 if len(node_list) < 1: pass
712 self.top_frame = component.get('frame') 720 self.top_frame = component.get('frame')
713 self.chat = self.top_frame.chat 721 self.chat = self.top_frame.chat
714 self.root_dir = os.getcwd() 722 self.root_dir = os.getcwd()
715 self.current_layer = 2 723 self.current_layer = 2
716 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
717 self.layer_handlers = [] 726 self.layer_handlers = []
718 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))
719 self.layer_tabs.AddPage(self.layer_handlers[0],"Background") 728 self.layer_tabs.AddPage(self.layer_handlers[0], "Background")
720 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))
721 self.layer_tabs.AddPage(self.layer_handlers[1],"Grid") 730 self.layer_tabs.AddPage(self.layer_handlers[1], "Grid")
722 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))
723 self.layer_tabs.AddPage(self.layer_handlers[2],"Miniatures", True) 732 self.layer_tabs.AddPage(self.layer_handlers[2], "Miniatures", True)
724 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))
725 self.layer_tabs.AddPage(self.layer_handlers[3],"Whiteboard") 734 self.layer_tabs.AddPage(self.layer_handlers[3], "Whiteboard")
726 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))
727 self.layer_tabs.AddPage(self.layer_handlers[4],"Fog") 736 self.layer_tabs.AddPage(self.layer_handlers[4], "Fog")
728 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))
729 self.layer_tabs.AddPage(self.layer_handlers[5],"General") 738 self.layer_tabs.AddPage(self.layer_handlers[5], "General")
730 self.layer_tabs.SetSelection(2) 739 self.layer_tabs.SetSelection(2)
740
741 self.layer_order = {1: 'grid', 2: 'miniatures', 3: 'whiteboard'}
731 self.sizer = wx.BoxSizer(wx.VERTICAL) 742 self.sizer = wx.BoxSizer(wx.VERTICAL)
732 self.sizer.Add(self.canvas, 1, wx.EXPAND) 743 self.sizer.Add(self.canvas, 1, wx.EXPAND)
733 self.sizer.Add(self.layer_tabs, 0, wx.EXPAND) 744 self.sizer.Add(self.layer_tabs, 0, wx.EXPAND)
734 self.SetSizer(self.sizer) 745 self.SetSizer(self.sizer)
735 self.Bind(FNB.EVT_FLATNOTEBOOK_PAGE_CHANGED, self.on_layer_change) 746 self.Bind(FNB.EVT_FLATNOTEBOOK_PAGE_CHANGED, self.on_layer_change)