comparison orpg/mapper/map.py @ 135:dcf4fbe09b70 beta

Traipse Beta 'OpenRPG' {091010-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 (Beta) Added Bookmarks Fix to Remote Admin Commands Minor fix to text based Server Fix to Pretty Print, from Core Fix to Splitter Nodes not being created Fix to massive amounts of images loading, from Core Added 'boot' command to remote admin Added confirmation window for sent nodes Minor changes to allow for portability to an OpenSUSE linux OS Miniatures Layer pop up box allows users to turn off Mini labels, from FlexiRPG Zoom Mouse plugin added Images added to Plugin UI Switching to Element Tree Map efficiency, from FlexiRPG Added Status Bar to Update Manager default_manifest.xml renamed to default_upmana.xml Cleaner clode for saved repositories New TrueDebug Class in orpg_log (See documentation for usage) Mercurial's hgweb folder is ported to upmana **Pretty important update that can help remove thousands of dead children from your gametree. **Children, <forms />, <group_atts />, <horizontal />, <cols />, <rows />, <height />, etc... are all tags now. Check your gametree and look for dead children!! **New Gamtree Recusion method, mapping, and context sensitivity. !!Alpha - Watch out for infinite loops!!
author sirebral
date Tue, 10 Nov 2009 14:11:28 -0600
parents 37a11fea3304
children e842a5f1b775
comparison
equal deleted inserted replaced
101:394ebb3b6a0f 135:dcf4fbe09b70
60 def __init__(self, parent, ID, isEditor=0): 60 def __init__(self, parent, ID, isEditor=0):
61 self.parent = parent 61 self.parent = parent
62 self.session = component.get("session") 62 self.session = component.get("session")
63 wx.ScrolledWindow.__init__(self, parent, ID, 63 wx.ScrolledWindow.__init__(self, parent, ID,
64 style=wx.HSCROLL | wx.VSCROLL | wx.FULL_REPAINT_ON_RESIZE | wx.SUNKEN_BORDER ) 64 style=wx.HSCROLL | wx.VSCROLL | wx.FULL_REPAINT_ON_RESIZE | wx.SUNKEN_BORDER )
65 self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM)
65 self.frame = parent 66 self.frame = parent
66 self.MAP_MODE = 1 #Mode 1 = MINI, 2 = DRAW, 3 = TAPE MEASURE 67 self.MAP_MODE = 1 #Mode 1 = MINI, 2 = DRAW, 3 = TAPE MEASURE
67 self.layers = {} 68 self.layers = {}
68 self.layers['bg'] = layer_back_ground(self) 69 self.layers['bg'] = layer_back_ground(self)
69 self.layers['grid'] = grid_layer(self) 70 self.layers['grid'] = grid_layer(self)
106 self.cacheSizeSet = False 107 self.cacheSizeSet = False
107 self.inside = 0 108 self.inside = 0
108 # miniatures drag 109 # miniatures drag
109 self.drag = None 110 self.drag = None
110 111
112 #self.Bind(wx.EVT_MOUSEWHEEL, self.MouseWheel)
113
114 def MouseWheel(self, evt):
115 if evt.CmdDown():
116 print evt.GetWheelRotation()
117 if evt.GetWheelRotation() > 0: self.on_zoom_in(None)
118 elif evt.GetWheelRotation() < 0: self.on_zoom_out(None)
119 else: pass
120
111 def better_refresh(self, event=None): 121 def better_refresh(self, event=None):
112 self.Refresh(True) 122 self.Refresh(True)
113 123
114 def pre_destory_cleanup(self): 124 def pre_destory_cleanup(self):
115 self.layers["miniatures"].del_all_miniatures() 125 self.layers["miniatures"].del_all_miniatures()
116 126
117 def processImages(self, evt=None): 127 def processImages(self, evt=None):
118 self.session = component.get("session") 128 self.session = component.get("session")
129 tabs = ['Background', 'Grid', 'Miniatures', 'Whiteboard', 'Fog', 'General']
119 if self.session.my_role() == self.session.ROLE_LURKER or (str(self.session.group_id) == '0' and str(self.session.status) == '1'): 130 if self.session.my_role() == self.session.ROLE_LURKER or (str(self.session.group_id) == '0' and str(self.session.status) == '1'):
120 cidx = self.parent.get_tab_index("Background") 131 for tab in tabs:
121 self.parent.layer_tabs.EnableTab(cidx, False) 132 cidx = self.parent.get_tab_index(tab)
122 cidx = self.parent.get_tab_index("Grid") 133 self.parent.tabs.EnableTab(cidx, False)
123 self.parent.layer_tabs.EnableTab(cidx, False) 134 elif self.session.my_role() == self.session.ROLE_PLAYER:
124 cidx = self.parent.get_tab_index("Miniatures") 135 for tab in tabs:
125 self.parent.layer_tabs.EnableTab(cidx, False) 136 cidx = self.parent.get_tab_index(tab)
126 cidx = self.parent.get_tab_index("Whiteboard") 137 if tab == "Miniatures" or tab == "Whiteboard":
127 self.parent.layer_tabs.EnableTab(cidx, False) 138 self.parent.tabs.EnableTab(cidx, True)
128 cidx = self.parent.get_tab_index("Fog") 139 else: self.parent.tabs.EnableTab(cidx, False)
129 self.parent.layer_tabs.EnableTab(cidx, False) 140 elif self.session.my_role() == self.session.ROLE_GM and str(self.session.group_id) != '0':
130 cidx = self.parent.get_tab_index("General") 141 for tab in tabs:
131 self.parent.layer_tabs.EnableTab(cidx, False) 142 cidx = self.parent.get_tab_index(tab)
132 else: 143 self.parent.tabs.EnableTab(cidx, True)
133 cidx = self.parent.get_tab_index("Background")
134 if not self.parent.layer_tabs.GetEnabled(cidx):
135 cidx = self.parent.get_tab_index("Miniatures")
136 self.parent.layer_tabs.EnableTab(cidx, True)
137 cidx = self.parent.get_tab_index("Whiteboard")
138 self.parent.layer_tabs.EnableTab(cidx, True)
139 cidx = self.parent.get_tab_index("Background")
140 self.parent.layer_tabs.EnableTab(cidx, False)
141 cidx = self.parent.get_tab_index("Grid")
142 self.parent.layer_tabs.EnableTab(cidx, False)
143 cidx = self.parent.get_tab_index("Fog")
144 self.parent.layer_tabs.EnableTab(cidx, False)
145 cidx = self.parent.get_tab_index("General")
146 self.parent.layer_tabs.EnableTab(cidx, False)
147 if self.session.my_role() == self.session.ROLE_GM:
148 cidx = self.parent.get_tab_index("Background")
149 self.parent.layer_tabs.EnableTab(cidx, True)
150 cidx = self.parent.get_tab_index("Grid")
151 self.parent.layer_tabs.EnableTab(cidx, True)
152 cidx = self.parent.get_tab_index("Fog")
153 self.parent.layer_tabs.EnableTab(cidx, True)
154 cidx = self.parent.get_tab_index("General")
155 self.parent.layer_tabs.EnableTab(cidx, True)
156 if not self.cacheSizeSet: 144 if not self.cacheSizeSet:
157 self.cacheSizeSet = True 145 self.cacheSizeSet = True
158 cacheSize = component.get('settings').get_setting("ImageCacheSize") 146 cacheSize = component.get('settings').get_setting("ImageCacheSize")
159 if len(cacheSize): self.cacheSize = int(cacheSize) 147 if len(cacheSize): self.cacheSize = int(cacheSize)
160 else: pass 148 else: pass
161 if not ImageHandler.Queue.empty(): 149 if not ImageHandler.Queue.empty():
162 (path, image_type, imageId) = ImageHandler.Queue.get() 150 (path, image_type, imageId) = ImageHandler.Queue.get()
163 img = wx.ImageFromMime(path[1], path[2]).ConvertToBitmap() 151 img = wx.ImageFromMime(path[1], path[2])
164 try: 152 # Now, apply the image to the proper object
165 # Now, apply the image to the proper object 153 if image_type == "miniature":
166 if image_type == "miniature": 154 min = self.layers['miniatures'].get_miniature_by_id(imageId)
167 min = self.layers['miniatures'].get_miniature_by_id(imageId) 155 if min: min.set_bmp(img)
168 min.set_bmp(img) 156 elif image_type == "background" or image_type == "texture":
169 elif image_type == "background" or image_type == "texture": 157 self.layers['bg'].bg_bmp = img.ConvertToBitmap()
170 self.layers['bg'].bg_bmp = img 158 if image_type == "background": self.set_size([img.GetWidth(), img.GetHeight()])
171 if image_type == "background": self.set_size([img.GetWidth(), img.GetHeight()])
172 except: pass
173 # Flag that we now need to refresh! 159 # Flag that we now need to refresh!
174 self.requireRefresh += 1 160 self.requireRefresh += 1
175
176 """ Randomly purge an item from the cache, while this is lamo, it does 161 """ Randomly purge an item from the cache, while this is lamo, it does
177 keep the cache from growing without bounds, which is pretty important!""" 162 keep the cache from growing without bounds, which is pretty important!"""
178 if len(ImageHandler.Cache) >= self.cacheSize: 163 if len(ImageHandler.Cache) >= self.cacheSize:
179 ImageHandler.cleanCache() 164 ImageHandler.cleanCache()
180 else: 165 else:
251 scrollsize = self.GetScrollPixelsPerUnit() 236 scrollsize = self.GetScrollPixelsPerUnit()
252 clientsize = self.GetClientSize() 237 clientsize = self.GetClientSize()
253 topleft1 = self.GetViewStart() 238 topleft1 = self.GetViewStart()
254 topleft = [topleft1[0]*scrollsize[0], topleft1[1]*scrollsize[1]] 239 topleft = [topleft1[0]*scrollsize[0], topleft1[1]*scrollsize[1]]
255 if (clientsize[0] > 1) and (clientsize[1] > 1): 240 if (clientsize[0] > 1) and (clientsize[1] > 1):
256 dc = wx.MemoryDC() 241 #dc = wx.MemoryDC()
257 bmp = wx.EmptyBitmap(clientsize[0]+1, clientsize[1]+1) 242 #bmp = wx.EmptyBitmap(clientsize[0]+1, clientsize[1]+1)
258 dc.SelectObject(bmp) 243 #dc.SelectObject(bmp)
244 dc = wx.AutoBufferedPaintDC(self)
259 dc.SetPen(wx.TRANSPARENT_PEN) 245 dc.SetPen(wx.TRANSPARENT_PEN)
260 dc.SetBrush(wx.Brush(self.GetBackgroundColour(), wx.SOLID)) 246 dc.SetBrush(wx.Brush(self.GetBackgroundColour(), wx.SOLID))
261 dc.DrawRectangle(0,0,clientsize[0]+1,clientsize[1]+1) 247 dc.DrawRectangle(0,0,clientsize[0]+1,clientsize[1]+1)
262 dc.SetDeviceOrigin(-topleft[0], -topleft[1]) 248 dc.SetDeviceOrigin(-topleft[0], -topleft[1])
263 dc.SetUserScale(scale, scale) 249 dc.SetUserScale(scale, scale)
268 [clientsize[0]/scale, clientsize[1]/scale]) 254 [clientsize[0]/scale, clientsize[1]/scale])
269 self.layers['whiteboard'].layerDraw(dc) 255 self.layers['whiteboard'].layerDraw(dc)
270 self.layers['fog'].layerDraw(dc, topleft, clientsize) 256 self.layers['fog'].layerDraw(dc, topleft, clientsize)
271 dc.SetPen(wx.NullPen) 257 dc.SetPen(wx.NullPen)
272 dc.SetBrush(wx.NullBrush) 258 dc.SetBrush(wx.NullBrush)
273 dc.SelectObject(wx.NullBitmap) 259 #dc.SelectObject(wx.NullBitmap)
274 del dc 260 #del dc
275 wdc = self.preppaint() 261 #wdc = self.preppaint()
276 wdc.DrawBitmap(bmp, topleft[0], topleft[1]) 262 #wdc.DrawBitmap(bmp, topleft[0], topleft[1])
277 if settings.get_setting("AlwaysShowMapScale") == "1": 263 if settings.get_setting("AlwaysShowMapScale") == "1":
278 self.showmapscale(wdc) 264 self.showmapscale(dc)
279 try: evt.Skip() 265 try: evt.Skip()
280 except: pass 266 except: pass
281 267
282 def preppaint(self): 268 def preppaint(self):
283 dc = wx.PaintDC(self) 269 dc = wx.PaintDC(self)
719 self.session = component.get('session') 705 self.session = component.get('session')
720 self.chat = component.get('chat') 706 self.chat = component.get('chat')
721 self.top_frame = component.get('frame') 707 self.top_frame = component.get('frame')
722 self.root_dir = os.getcwd() 708 self.root_dir = os.getcwd()
723 self.current_layer = 2 709 self.current_layer = 2
724 self.layer_tabs = orpgTabberWnd(self, style=FNB.FNB_NO_X_BUTTON|FNB.FNB_BOTTOM|FNB.FNB_NO_NAV_BUTTONS) 710 self.tabs = orpgTabberWnd(self, style=FNB.FNB_NO_X_BUTTON|FNB.FNB_BOTTOM|FNB.FNB_NO_NAV_BUTTONS)
725 self.layer_handlers = [] 711 self.handlers = {}
726 self.layer_handlers.append(background_handler(self.layer_tabs,-1,self.canvas)) 712 self.handlers[0]=(background_handler(self.tabs,-1,self.canvas))
727 self.layer_tabs.AddPage(self.layer_handlers[0],"Background") 713 self.tabs.AddPage(self.handlers[0],"Background")
728 self.layer_handlers.append(grid_handler(self.layer_tabs,-1,self.canvas)) 714 self.handlers[1]=(grid_handler(self.tabs,-1,self.canvas))
729 self.layer_tabs.AddPage(self.layer_handlers[1],"Grid") 715 self.tabs.AddPage(self.handlers[1],"Grid")
730 self.layer_handlers.append(miniatures_handler(self.layer_tabs,-1,self.canvas)) 716 self.handlers[2]=(miniatures_handler(self.tabs,-1,self.canvas))
731 self.layer_tabs.AddPage(self.layer_handlers[2],"Miniatures", True) 717 self.tabs.AddPage(self.handlers[2],"Miniatures", True)
732 self.layer_handlers.append(whiteboard_handler(self.layer_tabs,-1,self.canvas)) 718 self.handlers[3]=(whiteboard_handler(self.tabs,-1,self.canvas))
733 self.layer_tabs.AddPage(self.layer_handlers[3],"Whiteboard") 719 self.tabs.AddPage(self.handlers[3],"Whiteboard")
734 self.layer_handlers.append(fog_handler(self.layer_tabs,-1,self.canvas)) 720 self.handlers[4]=(fog_handler(self.tabs,-1,self.canvas))
735 self.layer_tabs.AddPage(self.layer_handlers[4],"Fog") 721 self.tabs.AddPage(self.handlers[4],"Fog")
736 self.layer_handlers.append(map_handler(self.layer_tabs,-1,self.canvas)) 722 self.handlers[5]=(map_handler(self.tabs,-1,self.canvas))
737 self.layer_tabs.AddPage(self.layer_handlers[5],"General") 723 self.tabs.AddPage(self.handlers[5],"General")
738 self.layer_tabs.SetSelection(2) 724 self.tabs.SetSelection(2)
739 self.sizer = wx.BoxSizer(wx.VERTICAL) 725 self.sizer = wx.BoxSizer(wx.VERTICAL)
740 self.sizer.Add(self.canvas, 1, wx.EXPAND) 726 self.sizer.Add(self.canvas, 1, wx.EXPAND)
741 self.sizer.Add(self.layer_tabs, 0, wx.EXPAND) 727 self.sizer.Add(self.tabs, 0, wx.EXPAND)
742 self.SetSizer(self.sizer) 728 self.SetSizer(self.sizer)
743 self.Bind(FNB.EVT_FLATNOTEBOOK_PAGE_CHANGED, self.on_layer_change) 729 self.Bind(FNB.EVT_FLATNOTEBOOK_PAGE_CHANGED, self.on_layer_change)
744 #self.Bind(wx.EVT_SIZE, self.on_size) 730 #self.Bind(wx.EVT_SIZE, self.on_size)
745 self.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeave) 731 self.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeave)
746 self.load_default() 732 self.load_default()
733
734 ## Components for making Map Based plugins that create new tabs.
735 component.add('map_tabs', self.tabs)
736 component.add('map_layers', self.handlers)
737 component.add('map_wnd', self)
747 738
748 def OnLeave(self, evt): 739 def OnLeave(self, evt):
749 if "__WXGTK__" in wx.PlatformInfo: wx.SetCursor(wx.StockCursor(wx.CURSOR_ARROW)) 740 if "__WXGTK__" in wx.PlatformInfo: wx.SetCursor(wx.StockCursor(wx.CURSOR_ARROW))
750 741
751 def load_default(self): 742 def load_default(self):
796 self.session.update_role("GM") 787 self.session.update_role("GM")
797 d.Destroy() 788 d.Destroy()
798 os.chdir(self.root_dir) 789 os.chdir(self.root_dir)
799 790
800 def get_current_layer_handler(self): 791 def get_current_layer_handler(self):
801 return self.layer_handlers[self.current_layer] 792 return self.handlers[self.current_layer]
802 793
803 def get_tab_index(self, layer): 794 def get_tab_index(self, layer):
804 """Return the index of a chatpanel in the wxNotebook.""" 795 """Return the index of a chatpanel in the wxNotebook."""
805 for i in xrange(self.layer_tabs.GetPageCount()): 796 for i in xrange(self.tabs.GetPageCount()):
806 if (self.layer_tabs.GetPageText(i) == layer): 797 if (self.tabs.GetPageText(i) == layer):
807 return i 798 return i
808 return 0 799 return 0
809 800
810 def on_layer_change(self, evt): 801 def on_layer_change(self, evt):
811 layer = self.layer_tabs.GetPage(evt.GetSelection()) 802 layer = self.tabs.GetPage(evt.GetSelection())
812 for i in xrange(0, len(self.layer_handlers)): 803 for i in xrange(0, len(self.handlers)):
813 if layer == self.layer_handlers[i]: self.current_layer = i 804 if layer == self.handlers[i]: self.current_layer = i
814 if self.current_layer == 0: 805 if self.current_layer == 0:
815 bg = self.layer_handlers[0] 806 bg = self.handlers[0]
816 if (self.session.my_role() != self.session.ROLE_GM): bg.url_path.Show(False) 807 if (self.session.my_role() != self.session.ROLE_GM): bg.url_path.Show(False)
817 else: bg.url_path.Show(True) 808 else: bg.url_path.Show(True)
818 self.canvas.Refresh(False) 809 self.canvas.Refresh(False)
819 evt.Skip() 810 evt.Skip()
820 811
821 def on_left_down(self, evt): 812 def on_left_down(self, evt):
822 self.layer_handlers[self.current_layer].on_left_down(evt) 813 self.handlers[self.current_layer].on_left_down(evt)
823 814
824 #double click handler added by Snowdog 5/03 815 #double click handler added by Snowdog 5/03
825 def on_left_dclick(self, evt): 816 def on_left_dclick(self, evt):
826 self.layer_handlers[self.current_layer].on_left_dclick(evt) 817 self.handlers[self.current_layer].on_left_dclick(evt)
827 818
828 def on_right_down(self, evt): 819 def on_right_down(self, evt):
829 self.layer_handlers[self.current_layer].on_right_down(evt) 820 self.handlers[self.current_layer].on_right_down(evt)
830 821
831 def on_left_up(self, evt): 822 def on_left_up(self, evt):
832 self.layer_handlers[self.current_layer].on_left_up(evt) 823 self.handlers[self.current_layer].on_left_up(evt)
833 824
834 def on_motion(self, evt): 825 def on_motion(self, evt):
835 self.layer_handlers[self.current_layer].on_motion(evt) 826 self.handlers[self.current_layer].on_motion(evt)
836 827
837 def MapBar(self, id, data): 828 def MapBar(self, id, data):
838 self.canvas.MAP_MODE = data 829 self.canvas.MAP_MODE = data
839 if id == 1: self.canvas.MAP_MODE = data 830 if id == 1: self.canvas.MAP_MODE = data
840 831
847 ImageHandler.flushCache() 838 ImageHandler.flushCache()
848 self.canvas.pre_destory_cleanup() 839 self.canvas.pre_destory_cleanup()
849 except: pass 840 except: pass
850 841
851 def update_tools(self): 842 def update_tools(self):
852 for h in self.layer_handlers: 843 for h in self.handlers:
853 h.update_info() 844 self.handlers[h].update_info()
854 845
855 def on_hk_map_layer(self, evt): 846 def on_hk_map_layer(self, evt):
856 id = self.top_frame.mainmenu.GetHelpString(evt.GetId()) 847 id = self.top_frame.mainmenu.GetHelpString(evt.GetId())
857 if id == "Background Layer": self.current_layer = self.get_tab_index("Background") 848 if id == "Background Layer": self.current_layer = self.get_tab_index("Background")
858 if id == "Grid Layer": self.current_layer = self.get_tab_index("Grid") 849 if id == "Grid Layer": self.current_layer = self.get_tab_index("Grid")
859 if id == "Miniature Layer": self.current_layer = self.get_tab_index("Miniatures") 850 if id == "Miniature Layer": self.current_layer = self.get_tab_index("Miniatures")
860 elif id == "Whiteboard Layer": self.current_layer = self.get_tab_index("Whiteboard") 851 elif id == "Whiteboard Layer": self.current_layer = self.get_tab_index("Whiteboard")
861 elif id == "Fog Layer": self.current_layer = self.get_tab_index("Fog") 852 elif id == "Fog Layer": self.current_layer = self.get_tab_index("Fog")
862 elif id == "General Properties": self.current_layer = self.get_tab_index("General") 853 elif id == "General Properties": self.current_layer = self.get_tab_index("General")
863 self.layer_tabs.SetSelection(self.current_layer) 854 self.tabs.SetSelection(self.current_layer)
864 855
865 def on_flush_cache(self, evt): 856 def on_flush_cache(self, evt):
866 ImageHandler.flushCache() 857 ImageHandler.flushCache()
867 858
868 def build_menu(self): 859 def build_menu(self):