comparison orpg/mapper/map.py @ 236:9230a33defd9 beta

Traipse Beta 'OpenRPG' {100616-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 (Closing/Closed) New Features: New to Map, can re-order Grid, Miniatures, and Whiteboard layer draw order New to Server GUI, can now clear log Updates: Update to Warhammer PC Sheet. Rollers set as macros. Should work with little maintanence. Update to Browser Server window. Display rooms with ' " & cleaner Update to Server. Handles ' " & cleaner. 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 Fix to Single and Double quotes in Whiteboard text Fix to Background images not showing when using the Image Server Fix to Duplicate chat names appearing Fix to Server GUI's logging output Fix to FNB.COLORFUL_TABS bug.
author sirebral
date Wed, 16 Jun 2010 03:06:20 -0500
parents 13054be69834
children
comparison
equal deleted inserted replaced
226:b29454610f36 236:9230a33defd9
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 exception = "\nDeprecated call to: Function re_ids_in_xml, line 679, map.py\nThis can mangle XML, please report!"
681 logger.exception(exception)
673 new_xml = "" 682 new_xml = ""
674 tmp_map = map_msg() 683 tmp_map = map_msg()
675 xml_dom = parseXml(str(xml)) 684 xml_dom = fromstring(xml)
676 node_list = xml_dom.getElementsByTagName("map") 685 node_list = xml_dom.findall("map")
677 if len(node_list) < 1: pass 686 if len(node_list) < 1: pass
678 else: 687 else:
679 tmp_map.init_from_dom(node_list[0]) 688 tmp_map.init_from_dom(node_list[0])
680 if tmp_map.children.has_key("miniatures"): 689 if tmp_map.children.has_key("miniatures"):
681 miniatures_layer = tmp_map.children["miniatures"] 690 miniatures_layer = tmp_map.children["miniatures"]
699 if l.tagname == 'line': id = 'line-' + self.frame.session.get_next_id() 708 if l.tagname == 'line': id = 'line-' + self.frame.session.get_next_id()
700 elif l.tagname == 'text': id = 'text-' + self.frame.session.get_next_id() 709 elif l.tagname == 'text': id = 'text-' + self.frame.session.get_next_id()
701 elif l.tagname == 'circle': id = 'circle-' + self.frame.session.get_next_id() 710 elif l.tagname == 'circle': id = 'circle-' + self.frame.session.get_next_id()
702 l.init_prop("id", id) 711 l.init_prop("id", id)
703 new_xml = tmp_map.get_all_xml() 712 new_xml = tmp_map.get_all_xml()
704 if xml_dom: xml_dom.unlink() 713 return new_xml
705 return str(new_xml)
706 714
707 class map_wnd(wx.Panel): 715 class map_wnd(wx.Panel):
708 def __init__(self, parent, id): 716 def __init__(self, parent, id):
709 wx.Panel.__init__(self, parent, id) 717 wx.Panel.__init__(self, parent, id)
710 self.canvas = MapCanvas(self, -1) 718 self.canvas = MapCanvas(self, -1)
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)
776 self.chat.InfoPost("You must be a GM to use this feature") 787 self.chat.InfoPost("You must be a GM to use this feature")
777 return 788 return
778 d = wx.FileDialog(self.GetParent(), "Select a file", dir_struct["user"], "", "*.xml", wx.OPEN) 789 d = wx.FileDialog(self.GetParent(), "Select a file", dir_struct["user"], "", "*.xml", wx.OPEN)
779 if d.ShowModal() == wx.ID_OK: 790 if d.ShowModal() == wx.ID_OK:
780 f = open(d.GetPath()) 791 f = open(d.GetPath())
781 map_string = f.read() 792 new_xml = f.read()
782 new_xml = self.canvas.re_ids_in_xml(map_string) 793 f.close()
783 if new_xml: 794 if new_xml != None:
784 self.canvas.takexml(new_xml) 795 self.canvas.takexml(new_xml)
785 self.canvas.send_map_data("new") 796 self.canvas.send_map_data("new")
786 self.update_tools() 797 self.update_tools()
787 if not self.session.is_connected() and (self.session.my_role() != self.session.ROLE_GM): 798 if not self.session.is_connected() and (self.session.my_role() != self.session.ROLE_GM):
788 self.session.update_role("GM") 799 self.session.update_role("GM")