comparison orpg/mapper/map.py @ 140:e842a5f1b775 beta

Traipse Beta 'OpenRPG' {091123-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 Gametree Recursion method, mapping, and context sensitivity. !Infinite Loops return error instead of freezing the software! New Syntax added for custom PC sheets Tip of the Day added, from Core and community Fixed Whiteboard ID to prevent random line or text deleting. Modified ID's to prevent non updated clients from ruining the fix.
author sirebral
date Mon, 23 Nov 2009 03:36:26 -0600
parents dcf4fbe09b70
children 9f4d6f7eab8d
comparison
equal deleted inserted replaced
135:dcf4fbe09b70 140:e842a5f1b775
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)
66 self.frame = parent 65 self.frame = parent
67 self.MAP_MODE = 1 #Mode 1 = MINI, 2 = DRAW, 3 = TAPE MEASURE 66 self.MAP_MODE = 1 #Mode 1 = MINI, 2 = DRAW, 3 = TAPE MEASURE
68 self.layers = {} 67 self.layers = {}
69 self.layers['bg'] = layer_back_ground(self) 68 self.layers['bg'] = layer_back_ground(self)
70 self.layers['grid'] = grid_layer(self) 69 self.layers['grid'] = grid_layer(self)
107 self.cacheSizeSet = False 106 self.cacheSizeSet = False
108 self.inside = 0 107 self.inside = 0
109 # miniatures drag 108 # miniatures drag
110 self.drag = None 109 self.drag = None
111 110
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
121 def better_refresh(self, event=None): 111 def better_refresh(self, event=None):
122 self.Refresh(True) 112 self.Refresh(True)
123 113
124 def pre_destory_cleanup(self): 114 def pre_destory_cleanup(self):
125 self.layers["miniatures"].del_all_miniatures() 115 self.layers["miniatures"].del_all_miniatures()
126 116
127 def processImages(self, evt=None): 117 def processImages(self, evt=None):
128 self.session = component.get("session") 118 self.session = component.get("session")
129 tabs = ['Background', 'Grid', 'Miniatures', 'Whiteboard', 'Fog', 'General']
130 if self.session.my_role() == self.session.ROLE_LURKER or (str(self.session.group_id) == '0' and str(self.session.status) == '1'): 119 if self.session.my_role() == self.session.ROLE_LURKER or (str(self.session.group_id) == '0' and str(self.session.status) == '1'):
131 for tab in tabs: 120 cidx = self.parent.get_tab_index("Background")
132 cidx = self.parent.get_tab_index(tab) 121 self.parent.layer_tabs.EnableTab(cidx, False)
133 self.parent.tabs.EnableTab(cidx, False) 122 cidx = self.parent.get_tab_index("Grid")
134 elif self.session.my_role() == self.session.ROLE_PLAYER: 123 self.parent.layer_tabs.EnableTab(cidx, False)
135 for tab in tabs: 124 cidx = self.parent.get_tab_index("Miniatures")
136 cidx = self.parent.get_tab_index(tab) 125 self.parent.layer_tabs.EnableTab(cidx, False)
137 if tab == "Miniatures" or tab == "Whiteboard": 126 cidx = self.parent.get_tab_index("Whiteboard")
138 self.parent.tabs.EnableTab(cidx, True) 127 self.parent.layer_tabs.EnableTab(cidx, False)
139 else: self.parent.tabs.EnableTab(cidx, False) 128 cidx = self.parent.get_tab_index("Fog")
140 elif self.session.my_role() == self.session.ROLE_GM and str(self.session.group_id) != '0': 129 self.parent.layer_tabs.EnableTab(cidx, False)
141 for tab in tabs: 130 cidx = self.parent.get_tab_index("General")
142 cidx = self.parent.get_tab_index(tab) 131 self.parent.layer_tabs.EnableTab(cidx, False)
143 self.parent.tabs.EnableTab(cidx, True) 132 else:
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)
144 if not self.cacheSizeSet: 156 if not self.cacheSizeSet:
145 self.cacheSizeSet = True 157 self.cacheSizeSet = True
146 cacheSize = component.get('settings').get_setting("ImageCacheSize") 158 cacheSize = component.get('settings').get_setting("ImageCacheSize")
147 if len(cacheSize): self.cacheSize = int(cacheSize) 159 if len(cacheSize): self.cacheSize = int(cacheSize)
148 else: pass 160 else: pass
149 if not ImageHandler.Queue.empty(): 161 if not ImageHandler.Queue.empty():
150 (path, image_type, imageId) = ImageHandler.Queue.get() 162 (path, image_type, imageId) = ImageHandler.Queue.get()
151 img = wx.ImageFromMime(path[1], path[2]) 163 img = wx.ImageFromMime(path[1], path[2])
152 # Now, apply the image to the proper object 164 try:
153 if image_type == "miniature": 165 # Now, apply the image to the proper object
154 min = self.layers['miniatures'].get_miniature_by_id(imageId) 166 if image_type == "miniature":
155 if min: min.set_bmp(img) 167 min = self.layers['miniatures'].get_miniature_by_id(imageId)
156 elif image_type == "background" or image_type == "texture": 168 if min: min.set_bmp(img)
157 self.layers['bg'].bg_bmp = img.ConvertToBitmap() 169 elif image_type == "background" or image_type == "texture":
158 if image_type == "background": self.set_size([img.GetWidth(), img.GetHeight()]) 170 self.layers['bg'].bg_bmp = img.ConvertToBitmap()
171 if image_type == "background": self.set_size([img.GetWidth(), img.GetHeight()])
172 except: pass
159 # Flag that we now need to refresh! 173 # Flag that we now need to refresh!
160 self.requireRefresh += 1 174 self.requireRefresh += 1
175
161 """ Randomly purge an item from the cache, while this is lamo, it does 176 """ Randomly purge an item from the cache, while this is lamo, it does
162 keep the cache from growing without bounds, which is pretty important!""" 177 keep the cache from growing without bounds, which is pretty important!"""
163 if len(ImageHandler.Cache) >= self.cacheSize: 178 if len(ImageHandler.Cache) >= self.cacheSize:
164 ImageHandler.cleanCache() 179 ImageHandler.cleanCache()
165 else: 180 else:
236 scrollsize = self.GetScrollPixelsPerUnit() 251 scrollsize = self.GetScrollPixelsPerUnit()
237 clientsize = self.GetClientSize() 252 clientsize = self.GetClientSize()
238 topleft1 = self.GetViewStart() 253 topleft1 = self.GetViewStart()
239 topleft = [topleft1[0]*scrollsize[0], topleft1[1]*scrollsize[1]] 254 topleft = [topleft1[0]*scrollsize[0], topleft1[1]*scrollsize[1]]
240 if (clientsize[0] > 1) and (clientsize[1] > 1): 255 if (clientsize[0] > 1) and (clientsize[1] > 1):
241 #dc = wx.MemoryDC()
242 #bmp = wx.EmptyBitmap(clientsize[0]+1, clientsize[1]+1)
243 #dc.SelectObject(bmp)
244 dc = wx.AutoBufferedPaintDC(self) 256 dc = wx.AutoBufferedPaintDC(self)
245 dc.SetPen(wx.TRANSPARENT_PEN) 257 dc.SetPen(wx.TRANSPARENT_PEN)
246 dc.SetBrush(wx.Brush(self.GetBackgroundColour(), wx.SOLID)) 258 dc.SetBrush(wx.Brush(self.GetBackgroundColour(), wx.SOLID))
247 dc.DrawRectangle(0,0,clientsize[0]+1,clientsize[1]+1) 259 dc.DrawRectangle(0,0,clientsize[0]+1,clientsize[1]+1)
248 dc.SetDeviceOrigin(-topleft[0], -topleft[1]) 260 dc.SetDeviceOrigin(-topleft[0], -topleft[1])
254 [clientsize[0]/scale, clientsize[1]/scale]) 266 [clientsize[0]/scale, clientsize[1]/scale])
255 self.layers['whiteboard'].layerDraw(dc) 267 self.layers['whiteboard'].layerDraw(dc)
256 self.layers['fog'].layerDraw(dc, topleft, clientsize) 268 self.layers['fog'].layerDraw(dc, topleft, clientsize)
257 dc.SetPen(wx.NullPen) 269 dc.SetPen(wx.NullPen)
258 dc.SetBrush(wx.NullBrush) 270 dc.SetBrush(wx.NullBrush)
259 #dc.SelectObject(wx.NullBitmap)
260 #del dc
261 #wdc = self.preppaint()
262 #wdc.DrawBitmap(bmp, topleft[0], topleft[1])
263 if settings.get_setting("AlwaysShowMapScale") == "1": 271 if settings.get_setting("AlwaysShowMapScale") == "1":
264 self.showmapscale(dc) 272 self.showmapscale(dc)
265 try: evt.Skip() 273 try: evt.Skip()
266 except: pass 274 except: pass
267
268 def preppaint(self):
269 dc = wx.PaintDC(self)
270 self.PrepareDC(dc)
271 return (dc)
272 275
273 def showmapscale(self, dc): 276 def showmapscale(self, dc):
274 scalestring = "Scale x" + `self.layers['grid'].mapscale`[:3] 277 scalestring = "Scale x" + `self.layers['grid'].mapscale`[:3]
275 (textWidth, textHeight) = dc.GetTextExtent(scalestring) 278 (textWidth, textHeight) = dc.GetTextExtent(scalestring)
276 dc.SetUserScale(1, 1) 279 dc.SetUserScale(1, 1)
705 self.session = component.get('session') 708 self.session = component.get('session')
706 self.chat = component.get('chat') 709 self.chat = component.get('chat')
707 self.top_frame = component.get('frame') 710 self.top_frame = component.get('frame')
708 self.root_dir = os.getcwd() 711 self.root_dir = os.getcwd()
709 self.current_layer = 2 712 self.current_layer = 2
710 self.tabs = orpgTabberWnd(self, style=FNB.FNB_NO_X_BUTTON|FNB.FNB_BOTTOM|FNB.FNB_NO_NAV_BUTTONS) 713 self.layer_tabs = orpgTabberWnd(self, style=FNB.FNB_NO_X_BUTTON|FNB.FNB_BOTTOM|FNB.FNB_NO_NAV_BUTTONS)
711 self.handlers = {} 714 self.layer_handlers = []
712 self.handlers[0]=(background_handler(self.tabs,-1,self.canvas)) 715 self.layer_handlers.append(background_handler(self.layer_tabs,-1,self.canvas))
713 self.tabs.AddPage(self.handlers[0],"Background") 716 self.layer_tabs.AddPage(self.layer_handlers[0],"Background")
714 self.handlers[1]=(grid_handler(self.tabs,-1,self.canvas)) 717 self.layer_handlers.append(grid_handler(self.layer_tabs,-1,self.canvas))
715 self.tabs.AddPage(self.handlers[1],"Grid") 718 self.layer_tabs.AddPage(self.layer_handlers[1],"Grid")
716 self.handlers[2]=(miniatures_handler(self.tabs,-1,self.canvas)) 719 self.layer_handlers.append(miniatures_handler(self.layer_tabs,-1,self.canvas))
717 self.tabs.AddPage(self.handlers[2],"Miniatures", True) 720 self.layer_tabs.AddPage(self.layer_handlers[2],"Miniatures", True)
718 self.handlers[3]=(whiteboard_handler(self.tabs,-1,self.canvas)) 721 self.layer_handlers.append(whiteboard_handler(self.layer_tabs,-1,self.canvas))
719 self.tabs.AddPage(self.handlers[3],"Whiteboard") 722 self.layer_tabs.AddPage(self.layer_handlers[3],"Whiteboard")
720 self.handlers[4]=(fog_handler(self.tabs,-1,self.canvas)) 723 self.layer_handlers.append(fog_handler(self.layer_tabs,-1,self.canvas))
721 self.tabs.AddPage(self.handlers[4],"Fog") 724 self.layer_tabs.AddPage(self.layer_handlers[4],"Fog")
722 self.handlers[5]=(map_handler(self.tabs,-1,self.canvas)) 725 self.layer_handlers.append(map_handler(self.layer_tabs,-1,self.canvas))
723 self.tabs.AddPage(self.handlers[5],"General") 726 self.layer_tabs.AddPage(self.layer_handlers[5],"General")
724 self.tabs.SetSelection(2) 727 self.layer_tabs.SetSelection(2)
725 self.sizer = wx.BoxSizer(wx.VERTICAL) 728 self.sizer = wx.BoxSizer(wx.VERTICAL)
726 self.sizer.Add(self.canvas, 1, wx.EXPAND) 729 self.sizer.Add(self.canvas, 1, wx.EXPAND)
727 self.sizer.Add(self.tabs, 0, wx.EXPAND) 730 self.sizer.Add(self.layer_tabs, 0, wx.EXPAND)
728 self.SetSizer(self.sizer) 731 self.SetSizer(self.sizer)
729 self.Bind(FNB.EVT_FLATNOTEBOOK_PAGE_CHANGED, self.on_layer_change) 732 self.Bind(FNB.EVT_FLATNOTEBOOK_PAGE_CHANGED, self.on_layer_change)
730 #self.Bind(wx.EVT_SIZE, self.on_size) 733 #self.Bind(wx.EVT_SIZE, self.on_size)
731 self.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeave) 734 self.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeave)
732 self.load_default() 735 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)
738 736
739 def OnLeave(self, evt): 737 def OnLeave(self, evt):
740 if "__WXGTK__" in wx.PlatformInfo: wx.SetCursor(wx.StockCursor(wx.CURSOR_ARROW)) 738 if "__WXGTK__" in wx.PlatformInfo: wx.SetCursor(wx.StockCursor(wx.CURSOR_ARROW))
741 739
742 def load_default(self): 740 def load_default(self):
787 self.session.update_role("GM") 785 self.session.update_role("GM")
788 d.Destroy() 786 d.Destroy()
789 os.chdir(self.root_dir) 787 os.chdir(self.root_dir)
790 788
791 def get_current_layer_handler(self): 789 def get_current_layer_handler(self):
792 return self.handlers[self.current_layer] 790 return self.layer_handlers[self.current_layer]
793 791
794 def get_tab_index(self, layer): 792 def get_tab_index(self, layer):
795 """Return the index of a chatpanel in the wxNotebook.""" 793 """Return the index of a chatpanel in the wxNotebook."""
796 for i in xrange(self.tabs.GetPageCount()): 794 for i in xrange(self.layer_tabs.GetPageCount()):
797 if (self.tabs.GetPageText(i) == layer): 795 if (self.layer_tabs.GetPageText(i) == layer):
798 return i 796 return i
799 return 0 797 return 0
800 798
801 def on_layer_change(self, evt): 799 def on_layer_change(self, evt):
802 layer = self.tabs.GetPage(evt.GetSelection()) 800 layer = self.layer_tabs.GetPage(evt.GetSelection())
803 for i in xrange(0, len(self.handlers)): 801 for i in xrange(0, len(self.layer_handlers)):
804 if layer == self.handlers[i]: self.current_layer = i 802 if layer == self.layer_handlers[i]: self.current_layer = i
805 if self.current_layer == 0: 803 if self.current_layer == 0:
806 bg = self.handlers[0] 804 bg = self.layer_handlers[0]
807 if (self.session.my_role() != self.session.ROLE_GM): bg.url_path.Show(False) 805 if (self.session.my_role() != self.session.ROLE_GM): bg.url_path.Show(False)
808 else: bg.url_path.Show(True) 806 else: bg.url_path.Show(True)
809 self.canvas.Refresh(False) 807 self.canvas.Refresh(False)
810 evt.Skip() 808 evt.Skip()
811 809
812 def on_left_down(self, evt): 810 def on_left_down(self, evt):
813 self.handlers[self.current_layer].on_left_down(evt) 811 self.layer_handlers[self.current_layer].on_left_down(evt)
814 812
815 #double click handler added by Snowdog 5/03 813 #double click handler added by Snowdog 5/03
816 def on_left_dclick(self, evt): 814 def on_left_dclick(self, evt):
817 self.handlers[self.current_layer].on_left_dclick(evt) 815 self.layer_handlers[self.current_layer].on_left_dclick(evt)
818 816
819 def on_right_down(self, evt): 817 def on_right_down(self, evt):
820 self.handlers[self.current_layer].on_right_down(evt) 818 self.layer_handlers[self.current_layer].on_right_down(evt)
821 819
822 def on_left_up(self, evt): 820 def on_left_up(self, evt):
823 self.handlers[self.current_layer].on_left_up(evt) 821 self.layer_handlers[self.current_layer].on_left_up(evt)
824 822
825 def on_motion(self, evt): 823 def on_motion(self, evt):
826 self.handlers[self.current_layer].on_motion(evt) 824 self.layer_handlers[self.current_layer].on_motion(evt)
827 825
828 def MapBar(self, id, data): 826 def MapBar(self, id, data):
829 self.canvas.MAP_MODE = data 827 self.canvas.MAP_MODE = data
830 if id == 1: self.canvas.MAP_MODE = data 828 if id == 1: self.canvas.MAP_MODE = data
831 829
838 ImageHandler.flushCache() 836 ImageHandler.flushCache()
839 self.canvas.pre_destory_cleanup() 837 self.canvas.pre_destory_cleanup()
840 except: pass 838 except: pass
841 839
842 def update_tools(self): 840 def update_tools(self):
843 for h in self.handlers: 841 for h in self.layer_handlers:
844 self.handlers[h].update_info() 842 h.update_info()
845 843
846 def on_hk_map_layer(self, evt): 844 def on_hk_map_layer(self, evt):
847 id = self.top_frame.mainmenu.GetHelpString(evt.GetId()) 845 id = self.top_frame.mainmenu.GetHelpString(evt.GetId())
848 if id == "Background Layer": self.current_layer = self.get_tab_index("Background") 846 if id == "Background Layer": self.current_layer = self.get_tab_index("Background")
849 if id == "Grid Layer": self.current_layer = self.get_tab_index("Grid") 847 if id == "Grid Layer": self.current_layer = self.get_tab_index("Grid")
850 if id == "Miniature Layer": self.current_layer = self.get_tab_index("Miniatures") 848 if id == "Miniature Layer": self.current_layer = self.get_tab_index("Miniatures")
851 elif id == "Whiteboard Layer": self.current_layer = self.get_tab_index("Whiteboard") 849 elif id == "Whiteboard Layer": self.current_layer = self.get_tab_index("Whiteboard")
852 elif id == "Fog Layer": self.current_layer = self.get_tab_index("Fog") 850 elif id == "Fog Layer": self.current_layer = self.get_tab_index("Fog")
853 elif id == "General Properties": self.current_layer = self.get_tab_index("General") 851 elif id == "General Properties": self.current_layer = self.get_tab_index("General")
854 self.tabs.SetSelection(self.current_layer) 852 self.layer_tabs.SetSelection(self.current_layer)
855 853
856 def on_flush_cache(self, evt): 854 def on_flush_cache(self, evt):
857 ImageHandler.flushCache() 855 ImageHandler.flushCache()
858 856
859 def build_menu(self): 857 def build_menu(self):