comparison orpg/mapper/map.py @ 71:449a8900f9ac ornery-dev

Code refining almost completed, for this round. Some included files are still in need of some clean up, but this is test worthy.
author sirebral
date Thu, 20 Aug 2009 03:00:39 -0500
parents c54768cffbd4
children 37a11fea3304
comparison
equal deleted inserted replaced
70:52a5fa913008 71:449a8900f9ac
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 from orpg.dirpath import dir_struct 34
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
40
40 from miniatures_handler import * 41 from miniatures_handler import *
41 from whiteboard_handler import * 42 from whiteboard_handler import *
42 from background_handler import * 43 from background_handler import *
43 from fog_handler import *
44 from images import ImageHandler
45 from grid_handler import * 44 from grid_handler import *
46 from map_handler import * 45 from map_handler import *
46 from fog_handler import *
47
48 from orpg.dirpath import dir_struct
49 from images import ImageHandler
47 from orpg.orpgCore import component 50 from orpg.orpgCore import component
48 51
49 # Various marker modes for player tools on the map 52 # Various marker modes for player tools on the map
50 MARKER_MODE_NONE = 0 53 MARKER_MODE_NONE = 0
51 MARKER_MODE_MEASURE = 1 54 MARKER_MODE_MEASURE = 1
53 MARKER_MODE_AREA_TARGET = 3 56 MARKER_MODE_AREA_TARGET = 3
54 57
55 class MapCanvas(wx.ScrolledWindow): 58 class MapCanvas(wx.ScrolledWindow):
56 def __init__(self, parent, ID, isEditor=0): 59 def __init__(self, parent, ID, isEditor=0):
57 self.parent = parent 60 self.parent = parent
58 self.log = component.get("log") 61 self.log = component.get('log')
59 self.log.log("Enter MapCanvas", ORPG_DEBUG)
60 self.settings = component.get("settings") 62 self.settings = component.get("settings")
61 self.session = component.get("session") 63 self.session = component.get("session")
62 wx.ScrolledWindow.__init__(self, parent, ID, 64 wx.ScrolledWindow.__init__(self, parent, ID,
63 style=wx.HSCROLL | wx.VSCROLL | wx.FULL_REPAINT_ON_RESIZE | wx.SUNKEN_BORDER ) 65 style=wx.HSCROLL | wx.VSCROLL | wx.FULL_REPAINT_ON_RESIZE | wx.SUNKEN_BORDER )
64 self.frame = parent 66 self.frame = parent
104 # Used to check if we've used the user cache size value 106 # Used to check if we've used the user cache size value
105 self.cacheSizeSet = False 107 self.cacheSizeSet = False
106 self.inside = 0 108 self.inside = 0
107 # miniatures drag 109 # miniatures drag
108 self.drag = None 110 self.drag = None
109 self.log.log("Exit MapCanvas", ORPG_DEBUG)
110 111
111 def better_refresh(self, event=None): 112 def better_refresh(self, event=None):
112 self.log.log("Enter MapCanvas->better_refresh(self)", ORPG_DEBUG)
113 self.Refresh(True) 113 self.Refresh(True)
114 self.log.log("Eexit MapCanvas->better_refresh(self)", ORPG_DEBUG)
115 114
116 def pre_destory_cleanup(self): 115 def pre_destory_cleanup(self):
117 self.log.log("Enter MapCanvas->pre_destory_cleanup(self)", ORPG_DEBUG)
118 self.layers["miniatures"].del_all_miniatures() 116 self.layers["miniatures"].del_all_miniatures()
119 self.log.log("Exit MapCanvas->pre_destory_cleanup(self)", ORPG_DEBUG)
120 117
121 def processImages(self, evt=None): 118 def processImages(self, evt=None):
122 self.log.log("Enter MapCanvas->processImages(self)", ORPG_DEBUG)
123 self.session = component.get("session") 119 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'): 120 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") 121 cidx = self.parent.get_tab_index("Background")
126 self.parent.layer_tabs.EnableTab(cidx, False) 122 self.parent.layer_tabs.EnableTab(cidx, False)
127 cidx = self.parent.get_tab_index("Grid") 123 cidx = self.parent.get_tab_index("Grid")
160 self.parent.layer_tabs.EnableTab(cidx, True) 156 self.parent.layer_tabs.EnableTab(cidx, True)
161 if not self.cacheSizeSet: 157 if not self.cacheSizeSet:
162 self.cacheSizeSet = True 158 self.cacheSizeSet = True
163 cacheSize = self.settings.get_setting("ImageCacheSize") 159 cacheSize = self.settings.get_setting("ImageCacheSize")
164 if len(cacheSize): self.cacheSize = int(cacheSize) 160 if len(cacheSize): self.cacheSize = int(cacheSize)
165 else: self.log.log("Default cache size being used.", ORPG_GENERAL) 161 else: pass
166 self.log.log("Current image cache size is set at " + str(self.cacheSize) + " images, using random purge.",
167 ORPG_GENERAL)
168 if not ImageHandler.Queue.empty(): 162 if not ImageHandler.Queue.empty():
169 (path, image_type, imageId) = ImageHandler.Queue.get() 163 (path, image_type, imageId) = ImageHandler.Queue.get()
170 img = wx.ImageFromMime(path[1], path[2]).ConvertToBitmap() 164 img = wx.ImageFromMime(path[1], path[2]).ConvertToBitmap()
171 try: 165 try:
172 # Now, apply the image to the proper object 166 # Now, apply the image to the proper object
178 if image_type == "background": self.set_size([img.GetWidth(), img.GetHeight()]) 172 if image_type == "background": self.set_size([img.GetWidth(), img.GetHeight()])
179 except: pass 173 except: pass
180 # Flag that we now need to refresh! 174 # Flag that we now need to refresh!
181 self.requireRefresh += 1 175 self.requireRefresh += 1
182 176
183 # Randomly purge an item from the cache, while this is lamo, it does 177 """ Randomly purge an item from the cache, while this is lamo, it does
184 # keep the cache from growing without bounds, which is pretty important! 178 keep the cache from growing without bounds, which is pretty important!"""
185 if len(ImageHandler.Cache) >= self.cacheSize: 179 if len(ImageHandler.Cache) >= self.cacheSize:
186 ImageHandler.cleanCache() 180 ImageHandler.cleanCache()
187 else: 181 else:
188 # Now, make sure not only that we require a refresh, but that enough time has 182 """ Now, make sure not only that we require a refresh, but that enough time has
189 # gone by since our last refresh. This keeps back to back refreshing occuring during 183 gone by since our last refresh. This keeps back to back refreshing occuring during
190 # large map loads. Of course, we are now trying to pack as many image refreshes as 184 large map loads. Of course, we are now trying to pack as many image refreshes as
191 # we can into a single cycle. 185 we can into a single cycle."""
192 if self.requireRefresh and (self.requireRefresh == self.lastRefreshValue): 186 if self.requireRefresh and (self.requireRefresh == self.lastRefreshValue):
193 if (self.lastRefreshTime) < time.time(): 187 if (self.lastRefreshTime) < time.time():
194 self.requireRefresh = 0 188 self.requireRefresh = 0
195 self.lastRefreshValue = 0 189 self.lastRefreshValue = 0
196 self.lastRefreshTime = time.time() 190 self.lastRefreshTime = time.time()
197 self.Refresh(True) 191 self.Refresh(True)
198 else: self.lastRefreshValue = self.requireRefresh 192 else: self.lastRefreshValue = self.requireRefresh
199 self.log.log("Exit MapCanvas->processImages(self)", ORPG_DEBUG)
200 193
201 def on_scroll(self, evt): 194 def on_scroll(self, evt):
202 self.log.log("Enter MapCanvas->on_scroll(self, evt)", ORPG_DEBUG)
203 if self.drag: self.drag.Hide() 195 if self.drag: self.drag.Hide()
204 if self.settings.get_setting("AlwaysShowMapScale") == "1": self.printscale() 196 if self.settings.get_setting("AlwaysShowMapScale") == "1": self.printscale()
205 evt.Skip() 197 evt.Skip()
206 self.log.log("Exit MapCanvas->on_scroll(self, evt)", ORPG_DEBUG)
207 198
208 def on_char(self, evt): 199 def on_char(self, evt):
209 self.log.log("Enter MapCanvas->on_char(self, evt)", ORPG_DEBUG)
210 if self.settings.get_setting("AlwaysShowMapScale") == "1": self.printscale() 200 if self.settings.get_setting("AlwaysShowMapScale") == "1": self.printscale()
211 evt.Skip() 201 evt.Skip()
212 self.log.log("Exit MapCanvas->on_char(self, evt)", ORPG_DEBUG)
213 202
214 def printscale(self): 203 def printscale(self):
215 self.log.log("Enter MapCanvas->printscale(self)", ORPG_DEBUG)
216 wx.BeginBusyCursor() 204 wx.BeginBusyCursor()
217 dc = wx.ClientDC(self) 205 dc = wx.ClientDC(self)
218 self.PrepareDC(dc) 206 self.PrepareDC(dc)
219 self.showmapscale(dc) 207 self.showmapscale(dc)
220 self.Refresh(True) 208 self.Refresh(True)
221 wx.EndBusyCursor() 209 wx.EndBusyCursor()
222 self.log.log("Exit MapCanvas->printscale(self)", ORPG_DEBUG)
223 210
224 def send_map_data(self, action="update"): 211 def send_map_data(self, action="update"):
225 self.log.log("Enter MapCanvas->send_map_data(self, " + action +")", ORPG_DEBUG)
226 wx.BeginBusyCursor() 212 wx.BeginBusyCursor()
227 send_text = self.toxml(action) 213 send_text = self.toxml(action)
228 if send_text: 214 if send_text:
229 if not self.isEditor: self.frame.session.send(send_text) 215 if not self.isEditor: self.frame.session.send(send_text)
230 wx.EndBusyCursor() 216 wx.EndBusyCursor()
231 self.log.log("Exit MapCanvas->send_map_data(self, " + action +")", ORPG_DEBUG)
232 217
233 def get_size(self): 218 def get_size(self):
234 self.log.log("Enter MapCanvas->get_size(self)", ORPG_DEBUG)
235 self.log.log("Exit MapCanvas->get_size(self) return " + str(self.size), ORPG_DEBUG)
236 return self.size 219 return self.size
237 220
238 def set_size(self, size): 221 def set_size(self, size):
239 self.log.log("Enter MapCanvas->set_size(self, size)", ORPG_DEBUG)
240 if size[0] < 300: size = (300, size[1]) 222 if size[0] < 300: size = (300, size[1])
241 if size[1] < 300: size = (size[0], 300) 223 if size[1] < 300: size = (size[0], 300)
242 self.size_changed = 1 224 self.size_changed = 1
243 self.size = size 225 self.size = size
244 self.fix_scroll() 226 self.fix_scroll()
245 self.layers['fog'].resize(size) 227 self.layers['fog'].resize(size)
246 self.log.log("Exit MapCanvas->set_size(self, size)", ORPG_DEBUG)
247 228
248 def fix_scroll(self): 229 def fix_scroll(self):
249 self.log.log("Enter MapCanvas->fix_scroll(self)", ORPG_DEBUG)
250 scale = self.layers['grid'].mapscale 230 scale = self.layers['grid'].mapscale
251 pos = self.GetViewStart() 231 pos = self.GetViewStart()
252 unit = self.GetScrollPixelsPerUnit() 232 unit = self.GetScrollPixelsPerUnit()
253 pos = [pos[0]*unit[0],pos[1]*unit[1]] 233 pos = [pos[0]*unit[0],pos[1]*unit[1]]
254 size = self.GetClientSize() 234 size = self.GetClientSize()
255 unit = [10*scale,10*scale] 235 unit = [10*scale,10*scale]
256 if (unit[0] == 0 or unit[1] == 0): 236 if (unit[0] == 0 or unit[1] == 0): return
257 self.log.log("Exit MapCanvas->fix_scroll(self)", ORPG_DEBUG)
258 return
259 pos[0] /= unit[0] 237 pos[0] /= unit[0]
260 pos[1] /= unit[1] 238 pos[1] /= unit[1]
261 mx = [int(self.size[0]*scale/unit[0])+1, int(self.size[1]*scale/unit[1]+1)] 239 mx = [int(self.size[0]*scale/unit[0])+1, int(self.size[1]*scale/unit[1]+1)]
262 self.SetScrollbars(unit[0], unit[1], mx[0], mx[1], pos[0], pos[1]) 240 self.SetScrollbars(unit[0], unit[1], mx[0], mx[1], pos[0], pos[1])
263 self.log.log("Exit MapCanvas->fix_scroll(self)", ORPG_DEBUG)
264 241
265 def on_resize(self, evt): 242 def on_resize(self, evt):
266 self.log.log("Enter MapCanvas->on_resize(self, evt)", ORPG_DEBUG)
267 self.fix_scroll() 243 self.fix_scroll()
268 wx.CallAfter(self.Refresh, True) 244 wx.CallAfter(self.Refresh, True)
269 evt.Skip() 245 evt.Skip()
270 self.log.log("Exit MapCanvas->on_resize(self, evt)", ORPG_DEBUG)
271 246
272 def on_erase_background(self, evt): 247 def on_erase_background(self, evt):
273 self.log.log("Enter MapCanvas->on_erase_background(self, evt)", ORPG_DEBUG)
274 evt.Skip() 248 evt.Skip()
275 self.log.log("Exit MapCanvas->on_erase_background(self, evt)", ORPG_DEBUG)
276 249
277 def on_paint(self, evt): 250 def on_paint(self, evt):
278 self.log.log("Enter MapCanvas->on_paint(self, evt)", ORPG_DEBUG)
279 scale = self.layers['grid'].mapscale 251 scale = self.layers['grid'].mapscale
280 scrollsize = self.GetScrollPixelsPerUnit() 252 scrollsize = self.GetScrollPixelsPerUnit()
281 clientsize = self.GetClientSize() 253 clientsize = self.GetClientSize()
282 topleft1 = self.GetViewStart() 254 topleft1 = self.GetViewStart()
283 topleft = [topleft1[0]*scrollsize[0], topleft1[1]*scrollsize[1]] 255 topleft = [topleft1[0]*scrollsize[0], topleft1[1]*scrollsize[1]]
305 wdc.DrawBitmap(bmp, topleft[0], topleft[1]) 277 wdc.DrawBitmap(bmp, topleft[0], topleft[1])
306 if self.frame.settings.get_setting("AlwaysShowMapScale") == "1": 278 if self.frame.settings.get_setting("AlwaysShowMapScale") == "1":
307 self.showmapscale(wdc) 279 self.showmapscale(wdc)
308 try: evt.Skip() 280 try: evt.Skip()
309 except: pass 281 except: pass
310 self.log.log("Exit MapCanvas->on_paint(self, evt)", ORPG_DEBUG)
311 282
312 def preppaint(self): 283 def preppaint(self):
313 self.log.log("Enter MapCanvas->preppaint(self)", ORPG_DEBUG)
314 dc = wx.PaintDC(self) 284 dc = wx.PaintDC(self)
315 self.PrepareDC(dc) 285 self.PrepareDC(dc)
316 self.log.log("Exit MapCanvas->preppaint(self)", ORPG_DEBUG)
317 return (dc) 286 return (dc)
318 287
319 def showmapscale(self, dc): 288 def showmapscale(self, dc):
320 self.log.log("Enter MapCanvas->showmapscale(self, dc)", ORPG_DEBUG)
321 scalestring = "Scale x" + `self.layers['grid'].mapscale`[:3] 289 scalestring = "Scale x" + `self.layers['grid'].mapscale`[:3]
322 (textWidth, textHeight) = dc.GetTextExtent(scalestring) 290 (textWidth, textHeight) = dc.GetTextExtent(scalestring)
323 dc.SetUserScale(1, 1) 291 dc.SetUserScale(1, 1)
324 dc.SetPen(wx.LIGHT_GREY_PEN) 292 dc.SetPen(wx.LIGHT_GREY_PEN)
325 dc.SetBrush(wx.LIGHT_GREY_BRUSH) 293 dc.SetBrush(wx.LIGHT_GREY_BRUSH)
328 dc.DrawRectangle(x, y, textWidth+2, textHeight+2) 296 dc.DrawRectangle(x, y, textWidth+2, textHeight+2)
329 dc.SetPen(wx.RED_PEN) 297 dc.SetPen(wx.RED_PEN)
330 dc.DrawText(scalestring, x+1, y+1) 298 dc.DrawText(scalestring, x+1, y+1)
331 dc.SetPen(wx.NullPen) 299 dc.SetPen(wx.NullPen)
332 dc.SetBrush(wx.NullBrush) 300 dc.SetBrush(wx.NullBrush)
333 self.log.log("Exit MapCanvas->showmapscale(self, dc)", ORPG_DEBUG)
334 301
335 def snapMarker(self, snapPoint): 302 def snapMarker(self, snapPoint):
336 """Based on the position and unit size, figure out where we need to snap to. As is, on 303 """Based on the position and unit size, figure out where we need to snap to. As is, on
337 a square grid, there are four possible places to snap. On a hex gid, there are 6 or 12 snap 304 a square grid, there are four possible places to snap. On a hex gid, there are 6 or 12 snap
338 points.""" 305 points."""
339 self.log.log("Enter MapCanvas->snapMarker(self, snapPoint)", ORPG_DEBUG)
340 306
341 # If snap to grid is disabled, simply return snapPoint unmodified 307 # If snap to grid is disabled, simply return snapPoint unmodified
342 if self.layers['grid'].snap: 308 if self.layers['grid'].snap:
343 # This means we need to determine where to snap our line. We will support 309 # This means we need to determine where to snap our line. We will support
344 # snapping to four different snapPoints per square for now. 310 # snapping to four different snapPoints per square for now.
360 # Now, figure out the Y snap placement 326 # Now, figure out the Y snap placement
361 if deltaY <= snapSize: quadYPos = offsetY 327 if deltaY <= snapSize: quadYPos = offsetY
362 else: quadYPos = offsetY + size 328 else: quadYPos = offsetY + size
363 # Create our snap snapPoint and return it 329 # Create our snap snapPoint and return it
364 snapPoint = wx.Point( quadXPos, quadYPos ) 330 snapPoint = wx.Point( quadXPos, quadYPos )
365 self.log.log("Exit MapCanvas->snapMarker(self, snapPoint)", ORPG_DEBUG)
366 return snapPoint 331 return snapPoint
367 332
368 # Bunch of math stuff for marking and measuring 333 # Bunch of math stuff for marking and measuring
369 def calcSlope(self, start, stop): 334 def calcSlope(self, start, stop):
370 """Calculates the slop of a line and returns it.""" 335 """Calculates the slop of a line and returns it."""
371 self.log.log("Enter MapCanvas->calcSlope(self, start, stop)", ORPG_DEBUG)
372 if start.x == stop.x: s = 0.0001 336 if start.x == stop.x: s = 0.0001
373 else: s = float((stop.y - start.y)) / float((stop.x - start.x)) 337 else: s = float((stop.y - start.y)) / float((stop.x - start.x))
374 self.log.log("Exit MapCanvas->calcSlope(self, start, stop)", ORPG_DEBUG)
375 return s 338 return s
376 339
377 def calcSlopeToAngle(self, slope): 340 def calcSlopeToAngle(self, slope):
378 """Based on the input slope, the angle (in degrees) will be returned.""" 341 """Based on the input slope, the angle (in degrees) will be returned."""
379 self.log.log("Enter MapCanvas->calcSlopeToAngle(self, slope)", ORPG_DEBUG)
380 # See if the slope is neg or positive 342 # See if the slope is neg or positive
381 if slope == abs(slope): 343 if slope == abs(slope):
382 # Slope is positive, so make sure it's not zero 344 # Slope is positive, so make sure it's not zero
383 if slope == 0: a = 0 345 if slope == 0: a = 0
384 else: a = 360 - atan(slope) * (180.0/pi) 346 else: a = 360 - atan(slope) * (180.0/pi)
385 else: a = atan(abs(slope)) * (180.0/pi) 347 else: a = atan(abs(slope)) * (180.0/pi)
386 self.log.log("Exit MapCanvas->calcSlopeToAngle(self, slope)", ORPG_DEBUG)
387 return a 348 return a
388 349
389 def calcLineAngle(self, start, stop): 350 def calcLineAngle(self, start, stop):
390 """Based on two points that are on a line, return the angle of that line.""" 351 """Based on two points that are on a line, return the angle of that line."""
391 self.log.log("Enter MapCanvas->calcLineAngle(self, start, stop)", ORPG_DEBUG)
392 a = self.calcSlopeToAngle( self.calcSlope( start, stop ) ) 352 a = self.calcSlopeToAngle( self.calcSlope( start, stop ) )
393 self.log.log("Exit MapCanvas->calcLineAngle(self, start, stop)", ORPG_DEBUG)
394 return a 353 return a
395 354
396 def calcPixelDistance(self, start, stop): 355 def calcPixelDistance(self, start, stop):
397 """Calculate the distance between two pixels and returns it. The calculated 356 """Calculate the distance between two pixels and returns it. The calculated
398 distance is the Euclidean Distance, which is: 357 distance is the Euclidean Distance, which is:
399 d = sqrt( (x2 - x1)**2 + (y2 - y1)**2 )""" 358 d = sqrt( (x2 - x1)**2 + (y2 - y1)**2 )"""
400 self.log.log("Enter MapCanvas->calcPixelDistance(self, start, stop)", ORPG_DEBUG)
401 d = sqrt( abs((stop.x - start.x)**2 - (stop.y - start.y)**2) ) 359 d = sqrt( abs((stop.x - start.x)**2 - (stop.y - start.y)**2) )
402 self.log.log("Exit MapCanvas->calcPixelDistance(self, start, stop)", ORPG_DEBUG)
403 return d 360 return d
404 361
405 def calcUnitDistance(self, start, stop, lineAngle): 362 def calcUnitDistance(self, start, stop, lineAngle):
406 self.log.log("Enter MapCanvas->calcUnitDistance(self, start, stop, lineAngle)", ORPG_DEBUG)
407 distance = self.calcPixelDistance( start, stop ) 363 distance = self.calcPixelDistance( start, stop )
408 ln = "%0.2f" % lineAngle 364 ln = "%0.2f" % lineAngle
409 if self.layers['grid'].mode == GRID_HEXAGON: 365 if self.layers['grid'].mode == GRID_HEXAGON:
410 if ln == "0.00" or ln == "359.99": ud = distance / self.layers['grid'].unit_size_y 366 if ln == "0.00" or ln == "359.99": ud = distance / self.layers['grid'].unit_size_y
411 else: ud = (sqrt(abs((stop.x - start.x)**2 + (stop.y - start.y)**2))) / self.layers['grid'].unit_size_y 367 else: ud = (sqrt(abs((stop.x - start.x)**2 + (stop.y - start.y)**2))) / self.layers['grid'].unit_size_y
412 else: 368 else:
413 if ln == "0.00" or ln == "359.99": ud = distance / self.layers['grid'].unit_size 369 if ln == "0.00" or ln == "359.99": ud = distance / self.layers['grid'].unit_size
414 else: ud = (sqrt(abs((stop.x - start.x)**2 + (stop.y - start.y)**2))) / self.layers['grid'].unit_size 370 else: ud = (sqrt(abs((stop.x - start.x)**2 + (stop.y - start.y)**2))) / self.layers['grid'].unit_size
415 #ud = sqrt( abs((stop.x - start.x)**2 - (stop.y - start.y)**2) ) 371 #ud = sqrt( abs((stop.x - start.x)**2 - (stop.y - start.y)**2) )
416 self.log.log("Exit MapCanvas->calcUnitDistance(self, start, stop, lineAngle)", ORPG_DEBUG)
417 return ud 372 return ud
418 373
419 def on_tape_motion(self, evt): 374 def on_tape_motion(self, evt):
420 """Track mouse motion so we can update the marker visual every time it's moved""" 375 """Track mouse motion so we can update the marker visual every time it's moved"""
421 self.log.log("Enter MapCanvas->on_tape_motion(self, evt)", ORPG_DEBUG)
422 # Make sure we have a mode to do anything, otherwise, we ignore this 376 # Make sure we have a mode to do anything, otherwise, we ignore this
423 if self.markerMode: 377 if self.markerMode:
424 # Grap the current DC for all of the marker modes 378 # Grap the current DC for all of the marker modes
425 dc = wx.ClientDC( self ) 379 dc = wx.ClientDC( self )
426 self.PrepareDC( dc ) 380 self.PrepareDC( dc )
427 dc.SetUserScale(self.layers['grid'].mapscale,self.layers['grid'].mapscale) 381 dc.SetUserScale(self.layers['grid'].mapscale,self.layers['grid'].mapscale)
428 # Grab the current map position 382 # Grab the current map position
429 pos = self.snapMarker( evt.GetLogicalPosition( dc ) ) 383 pos = self.snapMarker( evt.GetLogicalPosition( dc ) )
430 # Enable brush optimizations 384 # Enable brush optimizations
431 #dc.SetOptimization( True ) 385 # dc.SetOptimization( True )
432 # Set up the pen used for drawing our marker 386 # Set up the pen used for drawing our marker
433 dc.SetPen( wx.Pen(wx.RED, 1, wx.LONG_DASH) ) 387 dc.SetPen( wx.Pen(wx.RED, 1, wx.LONG_DASH) )
434 # Now, based on the marker mode, draw the right thing 388 # Now, based on the marker mode, draw the right thing
435 if self.markerMode == MARKER_MODE_MEASURE: 389 if self.markerMode == MARKER_MODE_MEASURE:
436 if self.markerStop.x != -1 and self.markerStop.y != -1: 390 if self.markerStop.x != -1 and self.markerStop.y != -1:
447 self.markerStop = pos 401 self.markerStop = pos
448 dc.SetPen(wx.NullPen) 402 dc.SetPen(wx.NullPen)
449 # Disable brush optimizations 403 # Disable brush optimizations
450 #dc.SetOptimization( False ) 404 #dc.SetOptimization( False )
451 del dc 405 del dc
452 self.log.log("Exit MapCanvas->on_tape_motion(self, evt)", ORPG_DEBUG)
453 406
454 def on_tape_down(self, evt): 407 def on_tape_down(self, evt):
455 """Greg's experimental tape measure code. Hopefully, when this is done, it will all be 408 """Greg's experimental tape measure code. Hopefully, when this is done, it will all be
456 modal based on a toolbar.""" 409 modal based on a toolbar."""
457 self.log.log("Enter MapCanvas->on_tape_down(self, evt)", ORPG_DEBUG)
458 dc = wx.ClientDC( self ) 410 dc = wx.ClientDC( self )
459 self.PrepareDC( dc ) 411 self.PrepareDC( dc )
460 dc.SetUserScale(self.layers['grid'].mapscale,self.layers['grid'].mapscale) 412 dc.SetUserScale(self.layers['grid'].mapscale,self.layers['grid'].mapscale)
461 pos = evt.GetLogicalPosition( dc ) 413 pos = evt.GetLogicalPosition( dc )
462 # If grid snap is enabled, then snap the tool to a proper position 414 # If grid snap is enabled, then snap the tool to a proper position
482 #dc.SetOptimization( False ) 434 #dc.SetOptimization( False )
483 # Save our current start and reset the stop value 435 # Save our current start and reset the stop value
484 self.markerStart = pos 436 self.markerStart = pos
485 self.markerStop = pos 437 self.markerStop = pos
486 del dc 438 del dc
487 self.log.log("Exit MapCanvas->on_tape_down(self, evt)", ORPG_DEBUG)
488 439
489 def on_tape_up(self, evt): 440 def on_tape_up(self, evt):
490 """When we release the middle button, disable any marking updates that we have been doing.""" 441 """When we release the middle button, disable any marking updates that we have been doing."""
491 self.log.log("Enter MapCanvas->on_tape_up(self, evt)", ORPG_DEBUG)
492 # If we are in measure mode, draw the actual UNIT distance 442 # If we are in measure mode, draw the actual UNIT distance
493 if self.markerMode == MARKER_MODE_MEASURE: 443 if self.markerMode == MARKER_MODE_MEASURE:
494 dc = wx.ClientDC( self ) 444 dc = wx.ClientDC( self )
495 self.PrepareDC( dc ) 445 self.PrepareDC( dc )
496 dc.SetUserScale(self.layers['grid'].mapscale,self.layers['grid'].mapscale) 446 dc.SetUserScale(self.layers['grid'].mapscale,self.layers['grid'].mapscale)
519 dc.SetFont(wx.NullFont) 469 dc.SetFont(wx.NullFont)
520 dc.SetLogicalFunction(wx.COPY) 470 dc.SetLogicalFunction(wx.COPY)
521 del font 471 del font
522 del dc 472 del dc
523 self.markerMode = MARKER_MODE_NONE 473 self.markerMode = MARKER_MODE_NONE
524 self.log.log("Exit MapCanvas->on_tape_up(self, evt)", ORPG_DEBUG)
525 474
526 # MODE 1 = MOVE, MODE 2 = whiteboard, MODE 3 = Tape measure 475 # MODE 1 = MOVE, MODE 2 = whiteboard, MODE 3 = Tape measure
527 def on_left_down(self, evt): 476 def on_left_down(self, evt):
528 self.log.log("Enter MapCanvas->on_left_down(self, evt)", ORPG_DEBUG)
529 if evt.ShiftDown(): self.on_tape_down (evt) 477 if evt.ShiftDown(): self.on_tape_down (evt)
530 else: self.frame.on_left_down(evt) 478 else: self.frame.on_left_down(evt)
531 self.log.log("Exit MapCanvas->on_left_down(self, evt)", ORPG_DEBUG)
532 479
533 def on_right_down(self, evt): 480 def on_right_down(self, evt):
534 self.log.log("Enter MapCanvas->on_right_down(self, evt)", ORPG_DEBUG)
535 if evt.ShiftDown(): pass 481 if evt.ShiftDown(): pass
536 else: self.frame.on_right_down(evt) 482 else: self.frame.on_right_down(evt)
537 self.log.log("Exit MapCanvas->on_right_down(self, evt)", ORPG_DEBUG)
538 483
539 def on_left_dclick(self, evt): 484 def on_left_dclick(self, evt):
540 self.log.log("Enter MapCanvas->on_left_dclick(self, evt)", ORPG_DEBUG)
541 if evt.ShiftDown(): pass 485 if evt.ShiftDown(): pass
542 else: self.frame.on_left_dclick(evt) 486 else: self.frame.on_left_dclick(evt)
543 self.log.log("Exit MapCanvas->on_left_dclick(self, evt)", ORPG_DEBUG)
544 487
545 def on_left_up(self, evt): 488 def on_left_up(self, evt):
546 self.log.log("Enter MapCanvas->on_left_up(self, evt)", ORPG_DEBUG)
547 if evt.ShiftDown(): self.on_tape_up(evt) 489 if evt.ShiftDown(): self.on_tape_up(evt)
548 elif component.get("tree").dragging: 490 elif component.get("tree").dragging:
549 tree = component.get("tree") 491 tree = component.get("tree")
550 if tree.drag_obj.map_aware(): 492 if tree.drag_obj.map_aware():
551 tree.drag_obj.on_send_to_map(evt) 493 tree.drag_obj.on_send_to_map(evt)
552 tree.dragging = False 494 tree.dragging = False
553 tree.drag_obj = None 495 tree.drag_obj = None
554 else: self.frame.on_left_up(evt) 496 else: self.frame.on_left_up(evt)
555 self.log.log("Exit MapCanvas->on_left_up(self, evt)", ORPG_DEBUG)
556 497
557 def on_motion(self, evt): 498 def on_motion(self, evt):
558 self.log.log("Enter MapCanvas->on_motion(self, evt)", ORPG_DEBUG)
559 if evt.ShiftDown(): self.on_tape_motion(evt) 499 if evt.ShiftDown(): self.on_tape_motion(evt)
560 elif evt.LeftIsDown() and component.get("tree").dragging: pass 500 elif evt.LeftIsDown() and component.get("tree").dragging: pass
561 else: self.frame.on_motion(evt) 501 else: self.frame.on_motion(evt)
562 self.log.log("Exit MapCanvas->on_motion(self, evt)", ORPG_DEBUG)
563 502
564 def on_zoom_out(self, evt): 503 def on_zoom_out(self, evt):
565 self.log.log("Enter MapCanvas->on_zoom_out(self, evt)", ORPG_DEBUG)
566 if self.layers['grid'].mapscale > 0.2: 504 if self.layers['grid'].mapscale > 0.2:
567 # attempt to keep same logical point at center of screen 505 # attempt to keep same logical point at center of screen
568 scale = self.layers['grid'].mapscale 506 scale = self.layers['grid'].mapscale
569 scrollsize = self.GetScrollPixelsPerUnit() 507 scrollsize = self.GetScrollPixelsPerUnit()
570 clientsize = self.GetClientSize() 508 clientsize = self.GetClientSize()
590 dc.SetPen(wx.NullPen) 528 dc.SetPen(wx.NullPen)
591 dc.SetBrush(wx.NullBrush) 529 dc.SetBrush(wx.NullBrush)
592 dc.EndDrawing() 530 dc.EndDrawing()
593 del dc 531 del dc
594 self.zoom_display_timer.Start(500,1) 532 self.zoom_display_timer.Start(500,1)
595 self.log.log("Exit MapCanvas->on_zoom_out(self, evt)", ORPG_DEBUG)
596 533
597 def on_zoom_in(self, evt): 534 def on_zoom_in(self, evt):
598 self.log.log("Enter MapCanvas->on_zoom_in(self, evt)", ORPG_DEBUG)
599 # attempt to keep same logical point at center of screen 535 # attempt to keep same logical point at center of screen
600 scale = self.layers['grid'].mapscale 536 scale = self.layers['grid'].mapscale
601 scrollsize = self.GetScrollPixelsPerUnit() 537 scrollsize = self.GetScrollPixelsPerUnit()
602 clientsize = self.GetClientSize() 538 clientsize = self.GetClientSize()
603 topleft1 = self.GetViewStart() 539 topleft1 = self.GetViewStart()
622 dc.SetPen(wx.NullPen) 558 dc.SetPen(wx.NullPen)
623 dc.SetBrush(wx.NullBrush) 559 dc.SetBrush(wx.NullBrush)
624 dc.EndDrawing() 560 dc.EndDrawing()
625 del dc 561 del dc
626 self.zoom_display_timer.Start(500, 1) 562 self.zoom_display_timer.Start(500, 1)
627 self.log.log("Exit MapCanvas->on_zoom_in(self, evt)", ORPG_DEBUG)
628 563
629 def on_prop(self, evt): 564 def on_prop(self, evt):
630 self.log.log("Enter MapCanvas->on_prop(self, evt)", ORPG_DEBUG)
631 self.session = component.get("session") 565 self.session = component.get("session")
632 self.chat = component.get("chat") 566 self.chat = component.get("chat")
633 if (self.session.my_role() != self.session.ROLE_GM): 567 if (self.session.my_role() != self.session.ROLE_GM):
634 self.chat.InfoPost("You must be a GM to use this feature") 568 self.chat.InfoPost("You must be a GM to use this feature")
635 self.log.log("Exit MapCanvas->on_prop(self, evt)", ORPG_DEBUG)
636 return 569 return
637 dlg = general_map_prop_dialog(self.frame.GetParent(),self.size,self.layers['bg'],self.layers['grid']) 570 dlg = general_map_prop_dialog(self.frame.GetParent(),self.size,self.layers['bg'],self.layers['grid'])
638 if dlg.ShowModal() == wx.ID_OK: 571 if dlg.ShowModal() == wx.ID_OK:
639 self.set_size(dlg.size) 572 self.set_size(dlg.size)
640 self.send_map_data() 573 self.send_map_data()
641 self.Refresh(False) 574 self.Refresh(False)
642 dlg.Destroy() 575 dlg.Destroy()
643 os.chdir(self.root_dir) 576 os.chdir(self.root_dir)
644 self.log.log("Exit MapCanvas->on_prop(self, evt)", ORPG_DEBUG)
645 577
646 def add_miniature(self, min_url, min_label='', min_unique=-1): 578 def add_miniature(self, min_url, min_label='', min_unique=-1):
647 self.log.log("Enter MapCanvas->add_miniature(self, min_url, min_label, min_unique)", ORPG_DEBUG)
648 if min_unique == -1: min_unique = not self.use_serial 579 if min_unique == -1: min_unique = not self.use_serial
649 if min_url == "" or min_url == "http://": return 580 if min_url == "" or min_url == "http://": return
650 if min_url[:7] != "http://" : min_url = "http://" + min_url 581 if min_url[:7] != "http://" : min_url = "http://" + min_url
651 # make label 582 # make label
652 wx.BeginBusyCursor() 583 wx.BeginBusyCursor()
657 else: min_label = "" 588 else: min_label = ""
658 if self.frame.min_url.FindString(min_url) == -1: self.frame.min_url.Append(min_url) 589 if self.frame.min_url.FindString(min_url) == -1: self.frame.min_url.Append(min_url)
659 try: 590 try:
660 id = 'mini-' + self.frame.session.get_next_id() 591 id = 'mini-' + self.frame.session.get_next_id()
661 self.layers['miniatures'].add_miniature(id, min_url, label=min_label) 592 self.layers['miniatures'].add_miniature(id, min_url, label=min_label)
662 except Exception, e: 593 except:
663 self.log.log(traceback.format_exc(), ORPG_GENERAL)
664 self.log.log("Unable to load/resolve URL: " + min_url + " on resource ' + min_label + ' !!!", ORPG_GENERAL)
665 self.layers['miniatures'].rollback_serial() 594 self.layers['miniatures'].rollback_serial()
666 wx.EndBusyCursor() 595 wx.EndBusyCursor()
667 self.send_map_data() 596 self.send_map_data()
668 self.Refresh(False) 597 self.Refresh(False)
669 self.log.log("Exit MapCanvas->add_miniature(self, min_url, min_label, min_unique)", ORPG_DEBUG)
670 598
671 def get_label_from_url(self, url=''): 599 def get_label_from_url(self, url=''):
672 self.log.log("Enter MapCanvas->get_label_from_url(self, url)", ORPG_DEBUG) 600 if url == '': return ''
673 if url == '':
674 self.log.log("Exit MapCanvas->get_label_from_url(self, url)", ORPG_DEBUG)
675 return ''
676 start = url.rfind("/")+1 601 start = url.rfind("/")+1
677 label = url[start:len(url)-4] 602 label = url[start:len(url)-4]
678 self.log.log("Exit MapCanvas->get_label_from_url(self, url)", ORPG_DEBUG)
679 return label 603 return label
680 604
681 def toxml(self, action="update"): 605 def toxml(self, action="update"):
682 self.log.log("Enter MapCanvas->toxml(self, " + action + ")", ORPG_DEBUG)
683 if action == "new": 606 if action == "new":
684 self.size_changed = 1 607 self.size_changed = 1
685 xml_str = "<map version='" + self.map_version + "'" 608 xml_str = "<map version='" + self.map_version + "'"
686 changed = self.size_changed 609 changed = self.size_changed
687 if self.size_changed: 610 if self.size_changed:
690 s = "" 613 s = ""
691 keys = self.layers.keys() 614 keys = self.layers.keys()
692 for k in keys: 615 for k in keys:
693 if (k != "fog" or action != "update"): s += self.layers[k].layerToXML(action) 616 if (k != "fog" or action != "update"): s += self.layers[k].layerToXML(action)
694 self.size_changed = 0 617 self.size_changed = 0
695 if s: 618 if s: return xml_str + " action='" + action + "'>" + s + "</map>"
696 self.log.log("Exit MapCanvas->toxml(self, " + action + ")", ORPG_DEBUG)
697 return xml_str + " action='" + action + "'>" + s + "</map>"
698 else: 619 else:
699 if changed: 620 if changed: return xml_str + " action='" + action + "'/>"
700 self.log.log("Exit MapCanvas->toxml(self, " + action + ")", ORPG_DEBUG) 621 else: return ""
701 return xml_str + " action='" + action + "'/>"
702 else:
703 self.log.log("Exit MapCanvas->toxml(self, " + action + ")", ORPG_DEBUG)
704 return ""
705 622
706 def takexml(self, xml): 623 def takexml(self, xml):
707 # 624 """
708 # Added Process Dialog to display during long map parsings 625 Added Process Dialog to display during long map parsings
709 # as well as a try block with an exception traceback to try 626 as well as a try block with an exception traceback to try
710 # and isolate some of the map related problems users have been 627 and isolate some of the map related problems users have been
711 # experiencing --Snowdog 5/15/03 628 experiencing --Snowdog 5/15/03
712 # 629
713 # Apparently Process Dialog causes problems with linux.. commenting it out. sheez. 630 Apparently Process Dialog causes problems with linux.. commenting it out. sheez.
714 # --Snowdog 5/27/03 631 --Snowdog 5/27/03
715 self.log.log("Enter MapCanvas->takexml(self, xml)", ORPG_DEBUG) 632 """
716 try: 633 try:
717 #parse the map DOM 634 #parse the map DOM
718 xml_dom = parseXml(xml) 635 xml_dom = parseXml(xml)
719 if xml_dom == None: 636 if xml_dom == None: return
720 self.log.log("xml_dom == None\n" + xml, ORPG_INFO)
721 self.log.log("Exit MapCanvas->takexml(self, xml)", ORPG_DEBUG)
722 return
723 node_list = xml_dom.getElementsByTagName("map") 637 node_list = xml_dom.getElementsByTagName("map")
724 if len(node_list) < 1: self.log.log("Invalid XML format for mapper", ORPG_INFO) 638 if len(node_list) < 1: pass
725 else: 639 else:
726 # set map version to incoming data so layers can convert 640 # set map version to incoming data so layers can convert
727 self.map_version = node_list[0].getAttribute("version") 641 self.map_version = node_list[0].getAttribute("version")
728 action = node_list[0].getAttribute("action") 642 action = node_list[0].getAttribute("action")
729 if action == "new": 643 if action == "new":
760 if name != "fog": self.layers[name].layerTakeDOM(c) 674 if name != "fog": self.layers[name].layerTakeDOM(c)
761 # all map data should be converted, set map version to current version 675 # all map data should be converted, set map version to current version
762 self.map_version = MAP_VERSION 676 self.map_version = MAP_VERSION
763 self.Refresh(False) 677 self.Refresh(False)
764 xml_dom.unlink() # eliminate circular refs 678 xml_dom.unlink() # eliminate circular refs
765 except: 679 except: pass
766 self.log.log(traceback.format_exc(), ORPG_GENERAL)
767 self.log.log("EXCEPTION: Critical Error Loading Map!!!", ORPG_GENERAL)
768 self.log.log("Exit MapCanvas->takexml(self, xml)", ORPG_DEBUG)
769 680
770 def re_ids_in_xml(self, xml): 681 def re_ids_in_xml(self, xml):
771 self.log.log("Enter MapCanvas->re_ids_in_xml(self, xml)", ORPG_DEBUG)
772 new_xml = "" 682 new_xml = ""
773 tmp_map = map_msg() 683 tmp_map = map_msg()
774 xml_dom = parseXml(str(xml)) 684 xml_dom = parseXml(str(xml))
775 node_list = xml_dom.getElementsByTagName("map") 685 node_list = xml_dom.getElementsByTagName("map")
776 if len(node_list) < 1: self.log.log("Invalid XML format for mapper", ORPG_INFO) 686 if len(node_list) < 1: pass
777 else: 687 else:
778 tmp_map.init_from_dom(node_list[0]) 688 tmp_map.init_from_dom(node_list[0])
779 if tmp_map.children.has_key("miniatures"): 689 if tmp_map.children.has_key("miniatures"):
780 miniatures_layer = tmp_map.children["miniatures"] 690 miniatures_layer = tmp_map.children["miniatures"]
781 if miniatures_layer: 691 if miniatures_layer:
799 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()
800 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()
801 l.init_prop("id", id) 711 l.init_prop("id", id)
802 new_xml = tmp_map.get_all_xml() 712 new_xml = tmp_map.get_all_xml()
803 if xml_dom: xml_dom.unlink() 713 if xml_dom: xml_dom.unlink()
804 self.log.log("Exit MapCanvas->re_ids_in_xml(self, xml)", ORPG_DEBUG)
805 return str(new_xml) 714 return str(new_xml)
806 715
807 class map_wnd(wx.Panel): 716 class map_wnd(wx.Panel):
808 def __init__(self, parent, id): 717 def __init__(self, parent, id):
809 self.log = component.get('log') 718 self.log = component.get('log')
810 self.log.log("Enter map_wnd", ORPG_DEBUG)
811 wx.Panel.__init__(self, parent, id) 719 wx.Panel.__init__(self, parent, id)
812 self.canvas = MapCanvas(self, -1) 720 self.canvas = MapCanvas(self, -1)
813 self.session = component.get('session') 721 self.session = component.get('session')
814 self.settings = component.get('settings') 722 self.settings = component.get('settings')
815 self.chat = component.get('chat') 723 self.chat = component.get('chat')
837 self.SetSizer(self.sizer) 745 self.SetSizer(self.sizer)
838 self.Bind(FNB.EVT_FLATNOTEBOOK_PAGE_CHANGED, self.on_layer_change) 746 self.Bind(FNB.EVT_FLATNOTEBOOK_PAGE_CHANGED, self.on_layer_change)
839 #self.Bind(wx.EVT_SIZE, self.on_size) 747 #self.Bind(wx.EVT_SIZE, self.on_size)
840 self.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeave) 748 self.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeave)
841 self.load_default() 749 self.load_default()
842 self.log.log("Exit map_wnd", ORPG_DEBUG)
843 750
844 def OnLeave(self, evt): 751 def OnLeave(self, evt):
845 if "__WXGTK__" in wx.PlatformInfo: wx.SetCursor(wx.StockCursor(wx.CURSOR_ARROW)) 752 if "__WXGTK__" in wx.PlatformInfo: wx.SetCursor(wx.StockCursor(wx.CURSOR_ARROW))
846 753
847 def load_default(self): 754 def load_default(self):
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()): 755 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") 756 self.chat.InfoPost("You must be a GM to use this feature")
851 self.log.log("Exit map_wnd->load_default(self)", ORPG_DEBUG)
852 return 757 return
853 f = open(dir_struct["template"] + "default_map.xml") 758 f = open(dir_struct["template"] + "default_map.xml")
854 self.new_data(f.read()) 759 self.new_data(f.read())
855 f.close() 760 f.close()
856 self.canvas.send_map_data("new") 761 self.canvas.send_map_data("new")
857 if not self.session.is_connected() and (self.session.my_role() != self.session.ROLE_GM): 762 if not self.session.is_connected() and (self.session.my_role() != self.session.ROLE_GM):
858 self.session.update_role("GM") 763 self.session.update_role("GM")
859 self.log.log("Exit map_wnd->load_default(self)", ORPG_DEBUG)
860 764
861 def new_data(self, data): 765 def new_data(self, data):
862 self.log.log("Enter map_wnd->new_data(self, data)", ORPG_DEBUG)
863 self.canvas.takexml(data) 766 self.canvas.takexml(data)
864 self.update_tools() 767 self.update_tools()
865 self.log.log("Exit map_wnd->new_data(self, data)", ORPG_DEBUG)
866 768
867 def on_save(self,evt): 769 def on_save(self,evt):
868 self.log.log("Enter map_wnd->new_data(self, data)", ORPG_DEBUG)
869 if (self.session.my_role() != self.session.ROLE_GM): 770 if (self.session.my_role() != self.session.ROLE_GM):
870 self.chat.InfoPost("You must be a GM to use this feature") 771 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)
872 return 772 return
873 d = wx.FileDialog(self.GetParent(), "Save map data", dir_struct["user"], "", "*.xml", wx.SAVE) 773 d = wx.FileDialog(self.GetParent(), "Save map data", dir_struct["user"], "", "*.xml", wx.SAVE)
874 if d.ShowModal() == wx.ID_OK: 774 if d.ShowModal() == wx.ID_OK:
875 f = open(d.GetPath(), "w") 775 f = open(d.GetPath(), "w")
876 data = '<nodehandler class="min_map" icon="compass" module="core" name="miniature Map">' 776 data = '<nodehandler class="min_map" icon="compass" module="core" name="miniature Map">'
879 data = data.replace(">",">\n") 779 data = data.replace(">",">\n")
880 f.write(data) 780 f.write(data)
881 f.close() 781 f.close()
882 d.Destroy() 782 d.Destroy()
883 os.chdir(self.root_dir) 783 os.chdir(self.root_dir)
884 self.log.log("Exit map_wnd->new_data(self, data)", ORPG_DEBUG)
885 784
886 def on_open(self, evt): 785 def on_open(self, evt):
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()): 786 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") 787 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)
891 return 788 return
892 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)
893 if d.ShowModal() == wx.ID_OK: 790 if d.ShowModal() == wx.ID_OK:
894 f = open(d.GetPath()) 791 f = open(d.GetPath())
895 map_string = f.read() 792 map_string = f.read()
900 self.update_tools() 797 self.update_tools()
901 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):
902 self.session.update_role("GM") 799 self.session.update_role("GM")
903 d.Destroy() 800 d.Destroy()
904 os.chdir(self.root_dir) 801 os.chdir(self.root_dir)
905 self.log.log("Exit map_wnd->on_open(self, evt)", ORPG_DEBUG)
906 802
907 def get_current_layer_handler(self): 803 def get_current_layer_handler(self):
908 self.log.log("Enter map_wnd->get_current_layer_handler(self)", ORPG_DEBUG)
909 self.log.log("Exit map_wnd->get_current_layer_handler(self)", ORPG_DEBUG)
910 return self.layer_handlers[self.current_layer] 804 return self.layer_handlers[self.current_layer]
911 805
912 def get_tab_index(self, layer): 806 def get_tab_index(self, layer):
913 """Return the index of a chatpanel in the wxNotebook.""" 807 """Return the index of a chatpanel in the wxNotebook."""
914 self.log.log("Enter map_wnd->get_tab_index(self, layer)", ORPG_DEBUG)
915 for i in xrange(self.layer_tabs.GetPageCount()): 808 for i in xrange(self.layer_tabs.GetPageCount()):
916 if (self.layer_tabs.GetPageText(i) == layer): 809 if (self.layer_tabs.GetPageText(i) == layer):
917 self.log.log("Exit map_wnd->get_tab_index(self, layer) return " + str(i), ORPG_DEBUG)
918 return i 810 return i
919 self.log.log("Exit map_wnd->get_tab_index(self, layer) return 0", ORPG_DEBUG)
920 return 0 811 return 0
921 812
922 def on_layer_change(self, evt): 813 def on_layer_change(self, evt):
923 self.log.log("Enter map_wnd->on_layer_change(self, evt)", ORPG_DEBUG)
924 layer = self.layer_tabs.GetPage(evt.GetSelection()) 814 layer = self.layer_tabs.GetPage(evt.GetSelection())
925 for i in xrange(0, len(self.layer_handlers)): 815 for i in xrange(0, len(self.layer_handlers)):
926 if layer == self.layer_handlers[i]: self.current_layer = i 816 if layer == self.layer_handlers[i]: self.current_layer = i
927 if self.current_layer == 0: 817 if self.current_layer == 0:
928 bg = self.layer_handlers[0] 818 bg = self.layer_handlers[0]
929 if (self.session.my_role() != self.session.ROLE_GM): bg.url_path.Show(False) 819 if (self.session.my_role() != self.session.ROLE_GM): bg.url_path.Show(False)
930 else: bg.url_path.Show(True) 820 else: bg.url_path.Show(True)
931 self.canvas.Refresh(False) 821 self.canvas.Refresh(False)
932 evt.Skip() 822 evt.Skip()
933 self.log.log("Exit map_wnd->on_layer_change(self, evt)", ORPG_DEBUG)
934 823
935 def on_left_down(self, evt): 824 def on_left_down(self, evt):
936 self.log.log("Enter map_wnd->on_left_down(self, evt)", ORPG_DEBUG)
937 self.log.log("Exit map_wnd->on_left_down(self, evt)", ORPG_DEBUG)
938 self.layer_handlers[self.current_layer].on_left_down(evt) 825 self.layer_handlers[self.current_layer].on_left_down(evt)
939 826
940 #double click handler added by Snowdog 5/03 827 #double click handler added by Snowdog 5/03
941 def on_left_dclick(self, evt): 828 def on_left_dclick(self, evt):
942 self.log.log("Enter map_wnd->on_left_dclick(self, evt)", ORPG_DEBUG)
943 self.log.log("Exit map_wnd->on_left_dclick(self, evt)", ORPG_DEBUG)
944 self.layer_handlers[self.current_layer].on_left_dclick(evt) 829 self.layer_handlers[self.current_layer].on_left_dclick(evt)
945 830
946 def on_right_down(self, evt): 831 def on_right_down(self, evt):
947 self.log.log("Enter map_wnd->on_right_down(self, evt)", ORPG_DEBUG)
948 self.log.log("Exit map_wnd->on_right_down(self, evt)", ORPG_DEBUG)
949 self.layer_handlers[self.current_layer].on_right_down(evt) 832 self.layer_handlers[self.current_layer].on_right_down(evt)
950 833
951 def on_left_up(self, evt): 834 def on_left_up(self, evt):
952 self.log.log("Enter map_wnd->on_left_up(self, evt)", ORPG_DEBUG)
953 self.log.log("Exit map_wnd->on_left_up(self, evt)", ORPG_DEBUG)
954 self.layer_handlers[self.current_layer].on_left_up(evt) 835 self.layer_handlers[self.current_layer].on_left_up(evt)
955 836
956 def on_motion(self, evt): 837 def on_motion(self, evt):
957 self.log.log("Enter map_wnd->on_motion(self, evt)", ORPG_DEBUG)
958 self.log.log("Exit map_wnd->on_motion(self, evt)", ORPG_DEBUG)
959 self.layer_handlers[self.current_layer].on_motion(evt) 838 self.layer_handlers[self.current_layer].on_motion(evt)
960 839
961 def MapBar(self, id, data): 840 def MapBar(self, id, data):
962 self.log.log("Enter map_wnd->MapBar(self, id, data)", ORPG_DEBUG)
963 self.canvas.MAP_MODE = data 841 self.canvas.MAP_MODE = data
964 if id == 1: 842 if id == 1: self.canvas.MAP_MODE = data
965 self.canvas.MAP_MODE = data
966 self.log.log("Exit map_wnd->MapBar(self, id, data)", ORPG_DEBUG)
967 843
968 def set_map_focus(self, evt): 844 def set_map_focus(self, evt):
969 self.log.log("Enter map_wnd->set_map_focus(self, evt)", ORPG_DEBUG)
970 self.canvas.SetFocus() 845 self.canvas.SetFocus()
971 self.log.log("Exit map_wnd->set_map_focus(self, evt)", ORPG_DEBUG)
972 846
973 def pre_exit_cleanup(self): 847 def pre_exit_cleanup(self):
974 self.log.log("Enter map_wnd->pre_exit_cleanup(self)", ORPG_DEBUG)
975 # do some pre exit clean up for bitmaps or other objects 848 # do some pre exit clean up for bitmaps or other objects
976 try: 849 try:
977 ImageHandler.flushCache() 850 ImageHandler.flushCache()
978 self.canvas.pre_destory_cleanup() 851 self.canvas.pre_destory_cleanup()
979 except Exception, e: 852 except: pass
980 self.log.log(traceback.format_exc(), ORPG_CRITICAL)
981 self.log.log("EXCEPTION: " + str(e), ORPG_CRITICAL)
982 self.log.log("Exit map_wnd->pre_exit_cleanup(self)", ORPG_DEBUG)
983 853
984 def update_tools(self): 854 def update_tools(self):
985 self.log.log("Enter map_wnd->update_tools(self)", ORPG_DEBUG)
986 for h in self.layer_handlers: 855 for h in self.layer_handlers:
987 h.update_info() 856 h.update_info()
988 self.log.log("Exit map_wnd->update_tools(self)", ORPG_DEBUG)
989 857
990 def on_hk_map_layer(self, evt): 858 def on_hk_map_layer(self, evt):
991 self.log.log("Enter map_wnd->on_hk_map_layer(self, evt)", ORPG_DEBUG)
992 id = self.top_frame.mainmenu.GetHelpString(evt.GetId()) 859 id = self.top_frame.mainmenu.GetHelpString(evt.GetId())
993 #print evt.GetMenu().GetTitle()
994 if id == "Background Layer": self.current_layer = self.get_tab_index("Background") 860 if id == "Background Layer": self.current_layer = self.get_tab_index("Background")
995 if id == "Grid Layer": self.current_layer = self.get_tab_index("Grid") 861 if id == "Grid Layer": self.current_layer = self.get_tab_index("Grid")
996 if id == "Miniature Layer": self.current_layer = self.get_tab_index("Miniatures") 862 if id == "Miniature Layer": self.current_layer = self.get_tab_index("Miniatures")
997 elif id == "Whiteboard Layer": self.current_layer = self.get_tab_index("Whiteboard") 863 elif id == "Whiteboard Layer": self.current_layer = self.get_tab_index("Whiteboard")
998 elif id == "Fog Layer": self.current_layer = self.get_tab_index("Fog") 864 elif id == "Fog Layer": self.current_layer = self.get_tab_index("Fog")
999 elif id == "General Properties": self.current_layer = self.get_tab_index("General") 865 elif id == "General Properties": self.current_layer = self.get_tab_index("General")
1000 self.layer_tabs.SetSelection(self.current_layer) 866 self.layer_tabs.SetSelection(self.current_layer)
1001 self.log.log("Exit map_wnd->on_hk_map_layer(self, evt)", ORPG_DEBUG)
1002 867
1003 def on_flush_cache(self, evt): 868 def on_flush_cache(self, evt):
1004 self.log.log("Enter map_wnd->on_flush_cache(self, evt)", ORPG_DEBUG)
1005 ImageHandler.flushCache() 869 ImageHandler.flushCache()
1006 self.log.log("Exit map_wnd->on_flush_cache(self, evt)", ORPG_DEBUG)
1007 870
1008 def build_menu(self): 871 def build_menu(self):
1009 self.log.log("Enter map_wnd->build_menu(self)", ORPG_DEBUG)
1010 # temp menu 872 # temp menu
1011 menu = wx.Menu() 873 menu = wx.Menu()
1012 item = wx.MenuItem(menu, wx.ID_ANY, "&Load Map", "Load Map") 874 item = wx.MenuItem(menu, wx.ID_ANY, "&Load Map", "Load Map")
1013 self.top_frame.Bind(wx.EVT_MENU, self.on_open, item) 875 self.top_frame.Bind(wx.EVT_MENU, self.on_open, item)
1014 menu.AppendItem(item) 876 menu.AppendItem(item)
1041 menu.AppendSeparator() 903 menu.AppendSeparator()
1042 item = wx.MenuItem(menu, wx.ID_ANY, "&Properties", "Properties") 904 item = wx.MenuItem(menu, wx.ID_ANY, "&Properties", "Properties")
1043 self.top_frame.Bind(wx.EVT_MENU, self.canvas.on_prop, item) 905 self.top_frame.Bind(wx.EVT_MENU, self.canvas.on_prop, item)
1044 menu.AppendItem(item) 906 menu.AppendItem(item)
1045 self.top_frame.mainmenu.Insert(2, menu, '&Map') 907 self.top_frame.mainmenu.Insert(2, menu, '&Map')
1046 self.log.log("Exit map_wnd->build_menu(self)", ORPG_DEBUG)
1047 908
1048 def get_hot_keys(self): 909 def get_hot_keys(self):
1049 self.log.log("Enter map_wnd->get_hot_keys(self)", ORPG_DEBUG)
1050 self.build_menu() 910 self.build_menu()
1051 self.log.log("Exit map_wnd->get_hot_keys(self)", ORPG_DEBUG)
1052 return [] 911 return []