comparison orpg/mapper/map.py @ 66:c54768cffbd4 ornery-dev

Traipse Dev 'OpenRPG' {090818-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: *Unstable* This is the first wave of Code Refinement updates. Includes new material from Core Beta; new debugger material (partially implemented), beginnings of switch to etree, TerminalWriter, and a little more. open_rpg has been renamed to component; functioning now as component.get(), component.add(), component.delete(). This version has known bugs, specifically with the gametree and nodes. I think the XML files where not removed during testing of Core and switching back.
author sirebral
date Tue, 18 Aug 2009 06:33:37 -0500
parents 072ffc1d466f
children 449a8900f9ac
comparison
equal deleted inserted replaced
65:4840657c23c5 66:c54768cffbd4
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 *
34 import orpg.dirpath 34 from orpg.dirpath import dir_struct
35 import random 35 import random
36 import os 36 import os
37 import thread 37 import thread
38 import gc 38 import gc
39 import traceback 39 import traceback
42 from background_handler import * 42 from background_handler import *
43 from fog_handler import * 43 from fog_handler import *
44 from images import ImageHandler 44 from images import ImageHandler
45 from grid_handler import * 45 from grid_handler import *
46 from map_handler import * 46 from map_handler import *
47 from orpg.orpgCore import open_rpg 47 from orpg.orpgCore import component
48 48
49 # Various marker modes for player tools on the map 49 # Various marker modes for player tools on the map
50 MARKER_MODE_NONE = 0 50 MARKER_MODE_NONE = 0
51 MARKER_MODE_MEASURE = 1 51 MARKER_MODE_MEASURE = 1
52 MARKER_MODE_TARGET = 2 52 MARKER_MODE_TARGET = 2
53 MARKER_MODE_AREA_TARGET = 3 53 MARKER_MODE_AREA_TARGET = 3
54 54
55 class MapCanvas(wx.ScrolledWindow): 55 class MapCanvas(wx.ScrolledWindow):
56 def __init__(self, parent, ID, isEditor=0): 56 def __init__(self, parent, ID, isEditor=0):
57 self.parent = parent 57 self.parent = parent
58 self.log = open_rpg.get_component("log") 58 self.log = component.get("log")
59 self.log.log("Enter MapCanvas", ORPG_DEBUG) 59 self.log.log("Enter MapCanvas", ORPG_DEBUG)
60 self.settings = open_rpg.get_component("settings") 60 self.settings = component.get("settings")
61 self.session = open_rpg.get_component("session") 61 self.session = component.get("session")
62 wx.ScrolledWindow.__init__(self, parent, ID, 62 wx.ScrolledWindow.__init__(self, parent, ID,
63 style=wx.HSCROLL | wx.VSCROLL | wx.FULL_REPAINT_ON_RESIZE | wx.SUNKEN_BORDER ) 63 style=wx.HSCROLL | wx.VSCROLL | wx.FULL_REPAINT_ON_RESIZE | wx.SUNKEN_BORDER )
64 self.frame = parent 64 self.frame = parent
65 self.MAP_MODE = 1 #Mode 1 = MINI, 2 = DRAW, 3 = TAPE MEASURE 65 self.MAP_MODE = 1 #Mode 1 = MINI, 2 = DRAW, 3 = TAPE MEASURE
66 self.layers = {} 66 self.layers = {}
118 self.layers["miniatures"].del_all_miniatures() 118 self.layers["miniatures"].del_all_miniatures()
119 self.log.log("Exit MapCanvas->pre_destory_cleanup(self)", ORPG_DEBUG) 119 self.log.log("Exit MapCanvas->pre_destory_cleanup(self)", ORPG_DEBUG)
120 120
121 def processImages(self, evt=None): 121 def processImages(self, evt=None):
122 self.log.log("Enter MapCanvas->processImages(self)", ORPG_DEBUG) 122 self.log.log("Enter MapCanvas->processImages(self)", ORPG_DEBUG)
123 self.session = open_rpg.get_component("session") 123 self.session = component.get("session")
124 if self.session.my_role() == self.session.ROLE_LURKER or (str(self.session.group_id) == '0' and str(self.session.status) == '1'): 124 if self.session.my_role() == self.session.ROLE_LURKER or (str(self.session.group_id) == '0' and str(self.session.status) == '1'):
125 cidx = self.parent.get_tab_index("Background") 125 cidx = self.parent.get_tab_index("Background")
126 self.parent.layer_tabs.EnableTab(cidx, False) 126 self.parent.layer_tabs.EnableTab(cidx, False)
127 cidx = self.parent.get_tab_index("Grid") 127 cidx = self.parent.get_tab_index("Grid")
128 self.parent.layer_tabs.EnableTab(cidx, False) 128 self.parent.layer_tabs.EnableTab(cidx, False)
543 self.log.log("Exit MapCanvas->on_left_dclick(self, evt)", ORPG_DEBUG) 543 self.log.log("Exit MapCanvas->on_left_dclick(self, evt)", ORPG_DEBUG)
544 544
545 def on_left_up(self, evt): 545 def on_left_up(self, evt):
546 self.log.log("Enter MapCanvas->on_left_up(self, evt)", ORPG_DEBUG) 546 self.log.log("Enter MapCanvas->on_left_up(self, evt)", ORPG_DEBUG)
547 if evt.ShiftDown(): self.on_tape_up(evt) 547 if evt.ShiftDown(): self.on_tape_up(evt)
548 elif open_rpg.get_component("tree").dragging: 548 elif component.get("tree").dragging:
549 tree = open_rpg.get_component("tree") 549 tree = component.get("tree")
550 if tree.drag_obj.map_aware(): 550 if tree.drag_obj.map_aware():
551 tree.drag_obj.on_send_to_map(evt) 551 tree.drag_obj.on_send_to_map(evt)
552 tree.dragging = False 552 tree.dragging = False
553 tree.drag_obj = None 553 tree.drag_obj = None
554 else: self.frame.on_left_up(evt) 554 else: self.frame.on_left_up(evt)
555 self.log.log("Exit MapCanvas->on_left_up(self, evt)", ORPG_DEBUG) 555 self.log.log("Exit MapCanvas->on_left_up(self, evt)", ORPG_DEBUG)
556 556
557 def on_motion(self, evt): 557 def on_motion(self, evt):
558 self.log.log("Enter MapCanvas->on_motion(self, evt)", ORPG_DEBUG) 558 self.log.log("Enter MapCanvas->on_motion(self, evt)", ORPG_DEBUG)
559 if evt.ShiftDown(): self.on_tape_motion(evt) 559 if evt.ShiftDown(): self.on_tape_motion(evt)
560 elif evt.LeftIsDown() and open_rpg.get_component("tree").dragging: pass 560 elif evt.LeftIsDown() and component.get("tree").dragging: pass
561 else: self.frame.on_motion(evt) 561 else: self.frame.on_motion(evt)
562 self.log.log("Exit MapCanvas->on_motion(self, evt)", ORPG_DEBUG) 562 self.log.log("Exit MapCanvas->on_motion(self, evt)", ORPG_DEBUG)
563 563
564 def on_zoom_out(self, evt): 564 def on_zoom_out(self, evt):
565 self.log.log("Enter MapCanvas->on_zoom_out(self, evt)", ORPG_DEBUG) 565 self.log.log("Enter MapCanvas->on_zoom_out(self, evt)", ORPG_DEBUG)
626 self.zoom_display_timer.Start(500, 1) 626 self.zoom_display_timer.Start(500, 1)
627 self.log.log("Exit MapCanvas->on_zoom_in(self, evt)", ORPG_DEBUG) 627 self.log.log("Exit MapCanvas->on_zoom_in(self, evt)", ORPG_DEBUG)
628 628
629 def on_prop(self, evt): 629 def on_prop(self, evt):
630 self.log.log("Enter MapCanvas->on_prop(self, evt)", ORPG_DEBUG) 630 self.log.log("Enter MapCanvas->on_prop(self, evt)", ORPG_DEBUG)
631 self.session = open_rpg.get_component("session") 631 self.session = component.get("session")
632 self.chat = open_rpg.get_component("chat") 632 self.chat = component.get("chat")
633 if (self.session.my_role() != self.session.ROLE_GM): 633 if (self.session.my_role() != self.session.ROLE_GM):
634 self.chat.InfoPost("You must be a GM to use this feature") 634 self.chat.InfoPost("You must be a GM to use this feature")
635 self.log.log("Exit MapCanvas->on_prop(self, evt)", ORPG_DEBUG) 635 self.log.log("Exit MapCanvas->on_prop(self, evt)", ORPG_DEBUG)
636 return 636 return
637 dlg = general_map_prop_dialog(self.frame.GetParent(),self.size,self.layers['bg'],self.layers['grid']) 637 dlg = general_map_prop_dialog(self.frame.GetParent(),self.size,self.layers['bg'],self.layers['grid'])
804 self.log.log("Exit MapCanvas->re_ids_in_xml(self, xml)", ORPG_DEBUG) 804 self.log.log("Exit MapCanvas->re_ids_in_xml(self, xml)", ORPG_DEBUG)
805 return str(new_xml) 805 return str(new_xml)
806 806
807 class map_wnd(wx.Panel): 807 class map_wnd(wx.Panel):
808 def __init__(self, parent, id): 808 def __init__(self, parent, id):
809 self.log = open_rpg.get_component('log') 809 self.log = component.get('log')
810 self.log.log("Enter map_wnd", ORPG_DEBUG) 810 self.log.log("Enter map_wnd", ORPG_DEBUG)
811 wx.Panel.__init__(self, parent, id) 811 wx.Panel.__init__(self, parent, id)
812 self.canvas = MapCanvas(self, -1) 812 self.canvas = MapCanvas(self, -1)
813 self.session = open_rpg.get_component('session') 813 self.session = component.get('session')
814 self.settings = open_rpg.get_component('settings') 814 self.settings = component.get('settings')
815 self.chat = open_rpg.get_component('chat') 815 self.chat = component.get('chat')
816 self.top_frame = open_rpg.get_component('frame') 816 self.top_frame = component.get('frame')
817 self.root_dir = os.getcwd() 817 self.root_dir = os.getcwd()
818 self.current_layer = 2 818 self.current_layer = 2
819 self.layer_tabs = orpgTabberWnd(self, style=FNB.FNB_NO_X_BUTTON|FNB.FNB_BOTTOM|FNB.FNB_NO_NAV_BUTTONS) 819 self.layer_tabs = orpgTabberWnd(self, style=FNB.FNB_NO_X_BUTTON|FNB.FNB_BOTTOM|FNB.FNB_NO_NAV_BUTTONS)
820 self.layer_handlers = [] 820 self.layer_handlers = []
821 self.layer_handlers.append(background_handler(self.layer_tabs,-1,self.canvas)) 821 self.layer_handlers.append(background_handler(self.layer_tabs,-1,self.canvas))
848 self.log.log("Enter map_wnd->load_default(self)", ORPG_DEBUG) 848 self.log.log("Enter map_wnd->load_default(self)", ORPG_DEBUG)
849 if self.session.is_connected() and (self.session.my_role() != self.session.ROLE_GM) and (self.session.use_roles()): 849 if self.session.is_connected() and (self.session.my_role() != self.session.ROLE_GM) and (self.session.use_roles()):
850 self.chat.InfoPost("You must be a GM to use this feature") 850 self.chat.InfoPost("You must be a GM to use this feature")
851 self.log.log("Exit map_wnd->load_default(self)", ORPG_DEBUG) 851 self.log.log("Exit map_wnd->load_default(self)", ORPG_DEBUG)
852 return 852 return
853 f = open(orpg.dirpath.dir_struct["template"] + "default_map.xml") 853 f = open(dir_struct["template"] + "default_map.xml")
854 self.new_data(f.read()) 854 self.new_data(f.read())
855 f.close() 855 f.close()
856 self.canvas.send_map_data("new") 856 self.canvas.send_map_data("new")
857 if not self.session.is_connected() and (self.session.my_role() != self.session.ROLE_GM): 857 if not self.session.is_connected() and (self.session.my_role() != self.session.ROLE_GM):
858 self.session.update_role("GM") 858 self.session.update_role("GM")
868 self.log.log("Enter map_wnd->new_data(self, data)", ORPG_DEBUG) 868 self.log.log("Enter map_wnd->new_data(self, data)", ORPG_DEBUG)
869 if (self.session.my_role() != self.session.ROLE_GM): 869 if (self.session.my_role() != self.session.ROLE_GM):
870 self.chat.InfoPost("You must be a GM to use this feature") 870 self.chat.InfoPost("You must be a GM to use this feature")
871 self.log.log("Exit map_wnd->new_data(self, data)", ORPG_DEBUG) 871 self.log.log("Exit map_wnd->new_data(self, data)", ORPG_DEBUG)
872 return 872 return
873 d = wx.FileDialog(self.GetParent(), "Save map data", orpg.dirpath.dir_struct["user"], "", "*.xml", wx.SAVE) 873 d = wx.FileDialog(self.GetParent(), "Save map data", dir_struct["user"], "", "*.xml", wx.SAVE)
874 if d.ShowModal() == wx.ID_OK: 874 if d.ShowModal() == wx.ID_OK:
875 f = open(d.GetPath(), "w") 875 f = open(d.GetPath(), "w")
876 data = '<nodehandler class="min_map" icon="compass" module="core" name="miniature Map">' 876 data = '<nodehandler class="min_map" icon="compass" module="core" name="miniature Map">'
877 data += self.canvas.toxml("new") 877 data += self.canvas.toxml("new")
878 data += "</nodehandler>" 878 data += "</nodehandler>"
887 self.log.log("Enter map_wnd->on_open(self, evt)", ORPG_DEBUG) 887 self.log.log("Enter map_wnd->on_open(self, evt)", ORPG_DEBUG)
888 if self.session.is_connected() and (self.session.my_role() != self.session.ROLE_GM) and (self.session.use_roles()): 888 if self.session.is_connected() and (self.session.my_role() != self.session.ROLE_GM) and (self.session.use_roles()):
889 self.chat.InfoPost("You must be a GM to use this feature") 889 self.chat.InfoPost("You must be a GM to use this feature")
890 self.log.log("Exit map_wnd->on_open(self, evt)", ORPG_DEBUG) 890 self.log.log("Exit map_wnd->on_open(self, evt)", ORPG_DEBUG)
891 return 891 return
892 d = wx.FileDialog(self.GetParent(), "Select a file", orpg.dirpath.dir_struct["user"], "", "*.xml", wx.OPEN) 892 d = wx.FileDialog(self.GetParent(), "Select a file", dir_struct["user"], "", "*.xml", wx.OPEN)
893 if d.ShowModal() == wx.ID_OK: 893 if d.ShowModal() == wx.ID_OK:
894 f = open(d.GetPath()) 894 f = open(d.GetPath())
895 map_string = f.read() 895 map_string = f.read()
896 new_xml = self.canvas.re_ids_in_xml(map_string) 896 new_xml = self.canvas.re_ids_in_xml(map_string)
897 if new_xml: 897 if new_xml: