Mercurial > traipse
comparison orpg/mapper/map.py @ 13:211ac836b6a0 grumpy-goblin
{090731-00} Fixes problem with Name & Settings window, cleans code.
author | sirebral |
---|---|
date | Fri, 31 Jul 2009 15:22:11 -0500 |
parents | 5df1340bda13 |
children | 97265586402b |
comparison
equal
deleted
inserted
replaced
12:d492f137cd3c | 13:211ac836b6a0 |
---|---|
57 self.parent = parent | 57 self.parent = parent |
58 self.log = open_rpg.get_component("log") | 58 self.log = open_rpg.get_component("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 = open_rpg.get_component("settings") |
61 self.session = open_rpg.get_component("session") | 61 self.session = open_rpg.get_component("session") |
62 wx.ScrolledWindow.__init__(self, parent, ID, style=wx.HSCROLL | wx.VSCROLL | wx.FULL_REPAINT_ON_RESIZE | wx.SUNKEN_BORDER ) | 62 wx.ScrolledWindow.__init__(self, parent, ID, |
63 style=wx.HSCROLL | wx.VSCROLL | wx.FULL_REPAINT_ON_RESIZE | wx.SUNKEN_BORDER ) | |
63 self.frame = parent | 64 self.frame = parent |
64 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 |
65 self.layers = {} | 66 self.layers = {} |
66 self.layers['bg'] = layer_back_ground(self) | 67 self.layers['bg'] = layer_back_ground(self) |
67 self.layers['grid'] = grid_layer(self) | 68 self.layers['grid'] = grid_layer(self) |
158 cidx = self.parent.get_tab_index("General") | 159 cidx = self.parent.get_tab_index("General") |
159 self.parent.layer_tabs.EnableTab(cidx, True) | 160 self.parent.layer_tabs.EnableTab(cidx, True) |
160 if not self.cacheSizeSet: | 161 if not self.cacheSizeSet: |
161 self.cacheSizeSet = True | 162 self.cacheSizeSet = True |
162 cacheSize = self.settings.get_setting("ImageCacheSize") | 163 cacheSize = self.settings.get_setting("ImageCacheSize") |
163 if len(cacheSize): | 164 if len(cacheSize): self.cacheSize = int(cacheSize) |
164 self.cacheSize = int(cacheSize) | 165 else: self.log.log("Default cache size being used.", ORPG_GENERAL) |
165 else: | 166 self.log.log("Current image cache size is set at " + str(self.cacheSize) + " images, using random purge.", |
166 self.log.log("Default cache size being used.", ORPG_GENERAL) | 167 ORPG_GENERAL) |
167 self.log.log("Current image cache size is set at " + str(self.cacheSize) + " images, using random purge.", ORPG_GENERAL) | |
168 if not ImageHandler.Queue.empty(): | 168 if not ImageHandler.Queue.empty(): |
169 (path, image_type, imageId) = ImageHandler.Queue.get() | 169 (path, image_type, imageId) = ImageHandler.Queue.get() |
170 img = wx.ImageFromMime(path[1], path[2]).ConvertToBitmap() | 170 img = wx.ImageFromMime(path[1], path[2]).ConvertToBitmap() |
171 try: | 171 try: |
172 # Now, apply the image to the proper object | 172 # Now, apply the image to the proper object |
173 if image_type == "miniature": | 173 if image_type == "miniature": |
174 min = self.layers['miniatures'].get_miniature_by_id(imageId) | 174 min = self.layers['miniatures'].get_miniature_by_id(imageId) |
175 min.set_bmp(img) | 175 min.set_bmp(img) |
176 elif image_type == "background" or image_type == "texture": | 176 elif image_type == "background" or image_type == "texture": |
177 self.layers['bg'].bg_bmp = img | 177 self.layers['bg'].bg_bmp = img |
178 if image_type == "background": | 178 if image_type == "background": self.set_size([img.GetWidth(), img.GetHeight()]) |
179 self.set_size([img.GetWidth(), img.GetHeight()]) | 179 except: pass |
180 except: | |
181 pass | |
182 # Flag that we now need to refresh! | 180 # Flag that we now need to refresh! |
183 self.requireRefresh += 1 | 181 self.requireRefresh += 1 |
184 | 182 |
185 # Randomly purge an item from the cache, while this is lamo, it does | 183 # Randomly purge an item from the cache, while this is lamo, it does |
186 # keep the cache from growing without bounds, which is pretty important! | 184 # keep the cache from growing without bounds, which is pretty important! |
195 if (self.lastRefreshTime) < time.time(): | 193 if (self.lastRefreshTime) < time.time(): |
196 self.requireRefresh = 0 | 194 self.requireRefresh = 0 |
197 self.lastRefreshValue = 0 | 195 self.lastRefreshValue = 0 |
198 self.lastRefreshTime = time.time() | 196 self.lastRefreshTime = time.time() |
199 self.Refresh(True) | 197 self.Refresh(True) |
200 else: | 198 else: self.lastRefreshValue = self.requireRefresh |
201 self.lastRefreshValue = self.requireRefresh | |
202 self.log.log("Exit MapCanvas->processImages(self)", ORPG_DEBUG) | 199 self.log.log("Exit MapCanvas->processImages(self)", ORPG_DEBUG) |
203 | 200 |
204 def on_scroll(self, evt): | 201 def on_scroll(self, evt): |
205 self.log.log("Enter MapCanvas->on_scroll(self, evt)", ORPG_DEBUG) | 202 self.log.log("Enter MapCanvas->on_scroll(self, evt)", ORPG_DEBUG) |
206 if self.drag: | 203 if self.drag: self.drag.Hide() |
207 self.drag.Hide() | 204 if self.settings.get_setting("AlwaysShowMapScale") == "1": self.printscale() |
208 if self.settings.get_setting("AlwaysShowMapScale") == "1": | |
209 self.printscale() | |
210 evt.Skip() | 205 evt.Skip() |
211 self.log.log("Exit MapCanvas->on_scroll(self, evt)", ORPG_DEBUG) | 206 self.log.log("Exit MapCanvas->on_scroll(self, evt)", ORPG_DEBUG) |
212 | 207 |
213 def on_char(self, evt): | 208 def on_char(self, evt): |
214 self.log.log("Enter MapCanvas->on_char(self, evt)", ORPG_DEBUG) | 209 self.log.log("Enter MapCanvas->on_char(self, evt)", ORPG_DEBUG) |
215 if self.settings.get_setting("AlwaysShowMapScale") == "1": | 210 if self.settings.get_setting("AlwaysShowMapScale") == "1": self.printscale() |
216 self.printscale() | |
217 evt.Skip() | 211 evt.Skip() |
218 self.log.log("Exit MapCanvas->on_char(self, evt)", ORPG_DEBUG) | 212 self.log.log("Exit MapCanvas->on_char(self, evt)", ORPG_DEBUG) |
219 | 213 |
220 def printscale(self): | 214 def printscale(self): |
221 self.log.log("Enter MapCanvas->printscale(self)", ORPG_DEBUG) | 215 self.log.log("Enter MapCanvas->printscale(self)", ORPG_DEBUG) |
230 def send_map_data(self, action="update"): | 224 def send_map_data(self, action="update"): |
231 self.log.log("Enter MapCanvas->send_map_data(self, " + action +")", ORPG_DEBUG) | 225 self.log.log("Enter MapCanvas->send_map_data(self, " + action +")", ORPG_DEBUG) |
232 wx.BeginBusyCursor() | 226 wx.BeginBusyCursor() |
233 send_text = self.toxml(action) | 227 send_text = self.toxml(action) |
234 if send_text: | 228 if send_text: |
235 if not self.isEditor: | 229 if not self.isEditor: self.frame.session.send(send_text) |
236 self.frame.session.send(send_text) | |
237 wx.EndBusyCursor() | 230 wx.EndBusyCursor() |
238 self.log.log("Exit MapCanvas->send_map_data(self, " + action +")", ORPG_DEBUG) | 231 self.log.log("Exit MapCanvas->send_map_data(self, " + action +")", ORPG_DEBUG) |
239 | 232 |
240 def get_size(self): | 233 def get_size(self): |
241 self.log.log("Enter MapCanvas->get_size(self)", ORPG_DEBUG) | 234 self.log.log("Enter MapCanvas->get_size(self)", ORPG_DEBUG) |
242 self.log.log("Exit MapCanvas->get_size(self) return " + str(self.size), ORPG_DEBUG) | 235 self.log.log("Exit MapCanvas->get_size(self) return " + str(self.size), ORPG_DEBUG) |
243 return self.size | 236 return self.size |
244 | 237 |
245 def set_size(self, size): | 238 def set_size(self, size): |
246 self.log.log("Enter MapCanvas->set_size(self, size)", ORPG_DEBUG) | 239 self.log.log("Enter MapCanvas->set_size(self, size)", ORPG_DEBUG) |
247 if size[0] < 300: | 240 if size[0] < 300: size = (300, size[1]) |
248 size = (300, size[1]) | 241 if size[1] < 300: size = (size[0], 300) |
249 if size[1] < 300: | |
250 size = (size[0], 300) | |
251 self.size_changed = 1 | 242 self.size_changed = 1 |
252 self.size = size | 243 self.size = size |
253 self.fix_scroll() | 244 self.fix_scroll() |
254 self.layers['fog'].resize(size) | 245 self.layers['fog'].resize(size) |
255 self.log.log("Exit MapCanvas->set_size(self, size)", ORPG_DEBUG) | 246 self.log.log("Exit MapCanvas->set_size(self, size)", ORPG_DEBUG) |
298 dc.SetBrush(wx.Brush(self.GetBackgroundColour(), wx.SOLID)) | 289 dc.SetBrush(wx.Brush(self.GetBackgroundColour(), wx.SOLID)) |
299 dc.DrawRectangle(0,0,clientsize[0]+1,clientsize[1]+1) | 290 dc.DrawRectangle(0,0,clientsize[0]+1,clientsize[1]+1) |
300 dc.SetDeviceOrigin(-topleft[0], -topleft[1]) | 291 dc.SetDeviceOrigin(-topleft[0], -topleft[1]) |
301 dc.SetUserScale(scale, scale) | 292 dc.SetUserScale(scale, scale) |
302 self.layers['bg'].layerDraw(dc, scale, topleft, clientsize) | 293 self.layers['bg'].layerDraw(dc, scale, topleft, clientsize) |
303 self.layers['grid'].layerDraw(dc, [topleft[0]/scale, topleft[1]/scale], [clientsize[0]/scale, clientsize[1]/scale]) | 294 self.layers['grid'].layerDraw(dc, [topleft[0]/scale, topleft[1]/scale], |
304 self.layers['miniatures'].layerDraw(dc, [topleft[0]/scale, topleft[1]/scale], [clientsize[0]/scale, clientsize[1]/scale]) | 295 [clientsize[0]/scale, clientsize[1]/scale]) |
296 self.layers['miniatures'].layerDraw(dc, [topleft[0]/scale, topleft[1]/scale], | |
297 [clientsize[0]/scale, clientsize[1]/scale]) | |
305 self.layers['whiteboard'].layerDraw(dc) | 298 self.layers['whiteboard'].layerDraw(dc) |
306 self.layers['fog'].layerDraw(dc, topleft, clientsize) | 299 self.layers['fog'].layerDraw(dc, topleft, clientsize) |
307 dc.SetPen(wx.NullPen) | 300 dc.SetPen(wx.NullPen) |
308 dc.SetBrush(wx.NullBrush) | 301 dc.SetBrush(wx.NullBrush) |
309 dc.SelectObject(wx.NullBitmap) | 302 dc.SelectObject(wx.NullBitmap) |
310 del dc | 303 del dc |
311 wdc = self.preppaint() | 304 wdc = self.preppaint() |
312 wdc.DrawBitmap(bmp, topleft[0], topleft[1]) | 305 wdc.DrawBitmap(bmp, topleft[0], topleft[1]) |
313 if self.frame.settings.get_setting("AlwaysShowMapScale") == "1": | 306 if self.frame.settings.get_setting("AlwaysShowMapScale") == "1": |
314 self.showmapscale(wdc) | 307 self.showmapscale(wdc) |
315 try: | 308 try: evt.Skip() |
316 evt.Skip() | 309 except: pass |
317 except: | |
318 pass | |
319 self.log.log("Exit MapCanvas->on_paint(self, evt)", ORPG_DEBUG) | 310 self.log.log("Exit MapCanvas->on_paint(self, evt)", ORPG_DEBUG) |
320 | 311 |
321 def preppaint(self): | 312 def preppaint(self): |
322 self.log.log("Enter MapCanvas->preppaint(self)", ORPG_DEBUG) | 313 self.log.log("Enter MapCanvas->preppaint(self)", ORPG_DEBUG) |
323 dc = wx.PaintDC(self) | 314 dc = wx.PaintDC(self) |
350 # If snap to grid is disabled, simply return snapPoint unmodified | 341 # If snap to grid is disabled, simply return snapPoint unmodified |
351 if self.layers['grid'].snap: | 342 if self.layers['grid'].snap: |
352 # This means we need to determine where to snap our line. We will support | 343 # This means we need to determine where to snap our line. We will support |
353 # snapping to four different snapPoints per square for now. | 344 # snapping to four different snapPoints per square for now. |
354 # TODO!!! | 345 # TODO!!! |
355 if self.layers['grid'].mode == GRID_HEXAGON: | 346 if self.layers['grid'].mode == GRID_HEXAGON: size = self.layers['grid'].unit_size_y |
356 size = self.layers['grid'].unit_size_y | |
357 else: | 347 else: |
358 size = int(self.layers['grid'].unit_size) | 348 size = int(self.layers['grid'].unit_size) |
359 # Find the uppper left hand corner of the grid we are to snap to | 349 # Find the uppper left hand corner of the grid we are to snap to |
360 offsetX = (snapPoint.x / size) * size | 350 offsetX = (snapPoint.x / size) * size |
361 offsetY = (snapPoint.y / size) * size | 351 offsetY = (snapPoint.y / size) * size |
363 deltaX = snapPoint.x - offsetX | 353 deltaX = snapPoint.x - offsetX |
364 deltaY = snapPoint.y - offsetY | 354 deltaY = snapPoint.y - offsetY |
365 # Now, figure our what quadrant (x, y) we need to snap to | 355 # Now, figure our what quadrant (x, y) we need to snap to |
366 snapSize = size / 2 | 356 snapSize = size / 2 |
367 # Figure out the X snap placement | 357 # Figure out the X snap placement |
368 if deltaX <= snapSize: | 358 if deltaX <= snapSize: quadXPos = offsetX |
369 quadXPos = offsetX | 359 else: quadXPos = offsetX + size |
370 else: | |
371 quadXPos = offsetX + size | |
372 # Now, figure out the Y snap placement | 360 # Now, figure out the Y snap placement |
373 if deltaY <= snapSize: | 361 if deltaY <= snapSize: quadYPos = offsetY |
374 quadYPos = offsetY | 362 else: quadYPos = offsetY + size |
375 else: | |
376 quadYPos = offsetY + size | |
377 # Create our snap snapPoint and return it | 363 # Create our snap snapPoint and return it |
378 snapPoint = wx.Point( quadXPos, quadYPos ) | 364 snapPoint = wx.Point( quadXPos, quadYPos ) |
379 self.log.log("Exit MapCanvas->snapMarker(self, snapPoint)", ORPG_DEBUG) | 365 self.log.log("Exit MapCanvas->snapMarker(self, snapPoint)", ORPG_DEBUG) |
380 return snapPoint | 366 return snapPoint |
381 | 367 |
382 # Bunch of math stuff for marking and measuring | 368 # Bunch of math stuff for marking and measuring |
383 def calcSlope(self, start, stop): | 369 def calcSlope(self, start, stop): |
384 """Calculates the slop of a line and returns it.""" | 370 """Calculates the slop of a line and returns it.""" |
385 self.log.log("Enter MapCanvas->calcSlope(self, start, stop)", ORPG_DEBUG) | 371 self.log.log("Enter MapCanvas->calcSlope(self, start, stop)", ORPG_DEBUG) |
386 if start.x == stop.x: | 372 if start.x == stop.x: s = 0.0001 |
387 s = 0.0001 | 373 else: s = float((stop.y - start.y)) / float((stop.x - start.x)) |
388 else: | |
389 s = float((stop.y - start.y)) / float((stop.x - start.x)) | |
390 self.log.log("Exit MapCanvas->calcSlope(self, start, stop)", ORPG_DEBUG) | 374 self.log.log("Exit MapCanvas->calcSlope(self, start, stop)", ORPG_DEBUG) |
391 return s | 375 return s |
392 | 376 |
393 def calcSlopeToAngle(self, slope): | 377 def calcSlopeToAngle(self, slope): |
394 """Based on the input slope, the angle (in degrees) will be returned.""" | 378 """Based on the input slope, the angle (in degrees) will be returned.""" |
395 self.log.log("Enter MapCanvas->calcSlopeToAngle(self, slope)", ORPG_DEBUG) | 379 self.log.log("Enter MapCanvas->calcSlopeToAngle(self, slope)", ORPG_DEBUG) |
396 # See if the slope is neg or positive | 380 # See if the slope is neg or positive |
397 if slope == abs(slope): | 381 if slope == abs(slope): |
398 # Slope is positive, so make sure it's not zero | 382 # Slope is positive, so make sure it's not zero |
399 if slope == 0: | 383 if slope == 0: a = 0 |
400 a = 0 | 384 else: a = 360 - atan(slope) * (180.0/pi) |
401 else: | 385 else: a = atan(abs(slope)) * (180.0/pi) |
402 # We are positive and NOT zero | |
403 a = 360 - atan(slope) * (180.0/pi) | |
404 else: | |
405 # Slope is negative so work on the abs of it | |
406 a = atan(abs(slope)) * (180.0/pi) | |
407 self.log.log("Exit MapCanvas->calcSlopeToAngle(self, slope)", ORPG_DEBUG) | 386 self.log.log("Exit MapCanvas->calcSlopeToAngle(self, slope)", ORPG_DEBUG) |
408 return a | 387 return a |
409 | 388 |
410 def calcLineAngle(self, start, stop): | 389 def calcLineAngle(self, start, stop): |
411 """Based on two points that are on a line, return the angle of that line.""" | 390 """Based on two points that are on a line, return the angle of that line.""" |
426 def calcUnitDistance(self, start, stop, lineAngle): | 405 def calcUnitDistance(self, start, stop, lineAngle): |
427 self.log.log("Enter MapCanvas->calcUnitDistance(self, start, stop, lineAngle)", ORPG_DEBUG) | 406 self.log.log("Enter MapCanvas->calcUnitDistance(self, start, stop, lineAngle)", ORPG_DEBUG) |
428 distance = self.calcPixelDistance( start, stop ) | 407 distance = self.calcPixelDistance( start, stop ) |
429 ln = "%0.2f" % lineAngle | 408 ln = "%0.2f" % lineAngle |
430 if self.layers['grid'].mode == GRID_HEXAGON: | 409 if self.layers['grid'].mode == GRID_HEXAGON: |
431 if ln == "0.00" or ln == "359.99": | 410 if ln == "0.00" or ln == "359.99": ud = distance / self.layers['grid'].unit_size_y |
432 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 |
433 else: | |
434 ud = (sqrt(abs((stop.x - start.x)**2 + (stop.y - start.y)**2))) / self.layers['grid'].unit_size_y | |
435 else: | 412 else: |
436 if ln == "0.00" or ln == "359.99": | 413 if ln == "0.00" or ln == "359.99": ud = distance / self.layers['grid'].unit_size |
437 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 |
438 else: | |
439 ud = (sqrt(abs((stop.x - start.x)**2 + (stop.y - start.y)**2))) / self.layers['grid'].unit_size | |
440 #ud = sqrt( abs((stop.x - start.x)**2 - (stop.y - start.y)**2) ) | 415 #ud = sqrt( abs((stop.x - start.x)**2 - (stop.y - start.y)**2) ) |
441 self.log.log("Exit MapCanvas->calcUnitDistance(self, start, stop, lineAngle)", ORPG_DEBUG) | 416 self.log.log("Exit MapCanvas->calcUnitDistance(self, start, stop, lineAngle)", ORPG_DEBUG) |
442 return ud | 417 return ud |
443 | 418 |
444 def on_tape_motion(self, evt): | 419 def on_tape_motion(self, evt): |
549 self.log.log("Exit MapCanvas->on_tape_up(self, evt)", ORPG_DEBUG) | 524 self.log.log("Exit MapCanvas->on_tape_up(self, evt)", ORPG_DEBUG) |
550 | 525 |
551 # MODE 1 = MOVE, MODE 2 = whiteboard, MODE 3 = Tape measure | 526 # MODE 1 = MOVE, MODE 2 = whiteboard, MODE 3 = Tape measure |
552 def on_left_down(self, evt): | 527 def on_left_down(self, evt): |
553 self.log.log("Enter MapCanvas->on_left_down(self, evt)", ORPG_DEBUG) | 528 self.log.log("Enter MapCanvas->on_left_down(self, evt)", ORPG_DEBUG) |
554 if evt.ShiftDown(): | 529 if evt.ShiftDown(): self.on_tape_down (evt) |
555 self.on_tape_down (evt) | 530 else: self.frame.on_left_down(evt) |
556 else: | |
557 self.frame.on_left_down(evt) | |
558 self.log.log("Exit MapCanvas->on_left_down(self, evt)", ORPG_DEBUG) | 531 self.log.log("Exit MapCanvas->on_left_down(self, evt)", ORPG_DEBUG) |
559 | 532 |
560 def on_right_down(self, evt): | 533 def on_right_down(self, evt): |
561 self.log.log("Enter MapCanvas->on_right_down(self, evt)", ORPG_DEBUG) | 534 self.log.log("Enter MapCanvas->on_right_down(self, evt)", ORPG_DEBUG) |
562 if evt.ShiftDown(): | 535 if evt.ShiftDown(): pass |
563 pass | 536 else: self.frame.on_right_down(evt) |
564 else: | |
565 self.frame.on_right_down(evt) | |
566 self.log.log("Exit MapCanvas->on_right_down(self, evt)", ORPG_DEBUG) | 537 self.log.log("Exit MapCanvas->on_right_down(self, evt)", ORPG_DEBUG) |
567 | 538 |
568 def on_left_dclick(self, evt): | 539 def on_left_dclick(self, evt): |
569 self.log.log("Enter MapCanvas->on_left_dclick(self, evt)", ORPG_DEBUG) | 540 self.log.log("Enter MapCanvas->on_left_dclick(self, evt)", ORPG_DEBUG) |
570 if evt.ShiftDown(): | 541 if evt.ShiftDown(): pass |
571 pass | 542 else: self.frame.on_left_dclick(evt) |
572 else: | |
573 self.frame.on_left_dclick(evt) | |
574 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) |
575 | 544 |
576 def on_left_up(self, evt): | 545 def on_left_up(self, evt): |
577 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) |
578 if evt.ShiftDown(): | 547 if evt.ShiftDown(): self.on_tape_up(evt) |
579 self.on_tape_up(evt) | |
580 elif open_rpg.get_component("tree").dragging: | 548 elif open_rpg.get_component("tree").dragging: |
581 tree = open_rpg.get_component("tree") | 549 tree = open_rpg.get_component("tree") |
582 if tree.drag_obj.map_aware(): | 550 if tree.drag_obj.map_aware(): |
583 tree.drag_obj.on_send_to_map(evt) | 551 tree.drag_obj.on_send_to_map(evt) |
584 tree.dragging = False | 552 tree.dragging = False |
585 tree.drag_obj = None | 553 tree.drag_obj = None |
586 else: | 554 else: self.frame.on_left_up(evt) |
587 self.frame.on_left_up(evt) | |
588 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) |
589 | 556 |
590 def on_motion(self, evt): | 557 def on_motion(self, evt): |
591 self.log.log("Enter MapCanvas->on_motion(self, evt)", ORPG_DEBUG) | 558 self.log.log("Enter MapCanvas->on_motion(self, evt)", ORPG_DEBUG) |
592 if evt.ShiftDown(): | 559 if evt.ShiftDown(): self.on_tape_motion(evt) |
593 self.on_tape_motion(evt) | 560 elif evt.LeftIsDown() and open_rpg.get_component("tree").dragging: pass |
594 elif evt.LeftIsDown() and open_rpg.get_component("tree").dragging: | 561 else: self.frame.on_motion(evt) |
595 pass | |
596 else: | |
597 self.frame.on_motion(evt) | |
598 self.log.log("Exit MapCanvas->on_motion(self, evt)", ORPG_DEBUG) | 562 self.log.log("Exit MapCanvas->on_motion(self, evt)", ORPG_DEBUG) |
599 | 563 |
600 def on_zoom_out(self, evt): | 564 def on_zoom_out(self, evt): |
601 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) |
602 if self.layers['grid'].mapscale > 0.2: | 566 if self.layers['grid'].mapscale > 0.2: |
679 os.chdir(self.root_dir) | 643 os.chdir(self.root_dir) |
680 self.log.log("Exit MapCanvas->on_prop(self, evt)", ORPG_DEBUG) | 644 self.log.log("Exit MapCanvas->on_prop(self, evt)", ORPG_DEBUG) |
681 | 645 |
682 def add_miniature(self, min_url, min_label='', min_unique=-1): | 646 def add_miniature(self, min_url, min_label='', min_unique=-1): |
683 self.log.log("Enter MapCanvas->add_miniature(self, min_url, min_label, min_unique)", ORPG_DEBUG) | 647 self.log.log("Enter MapCanvas->add_miniature(self, min_url, min_label, min_unique)", ORPG_DEBUG) |
684 if min_unique == -1: | 648 if min_unique == -1: min_unique = not self.use_serial |
685 min_unique = not self.use_serial | 649 if min_url == "" or min_url == "http://": return |
686 if min_url == "" or min_url == "http://": | 650 if min_url[:7] != "http://" : min_url = "http://" + min_url |
687 return | |
688 if min_url[:7] != "http://" : | |
689 min_url = "http://" + min_url | |
690 # make label | 651 # make label |
691 wx.BeginBusyCursor() | 652 wx.BeginBusyCursor() |
692 if self.auto_label: | 653 if self.auto_label: |
693 if min_label == '': | 654 if min_label == '': min_label = self.get_label_from_url( min_url ) |
694 min_label = self.get_label_from_url( min_url ) | |
695 if not min_unique and self.use_serial: | 655 if not min_unique and self.use_serial: |
696 min_label = '%s %d' % ( min_label, self.layers['miniatures'].next_serial() ) | 656 min_label = '%s %d' % ( min_label, self.layers['miniatures'].next_serial() ) |
697 else: | 657 else: min_label = "" |
698 min_label = "" | 658 if self.frame.min_url.FindString(min_url) == -1: self.frame.min_url.Append(min_url) |
699 if self.frame.min_url.FindString(min_url) == -1: | |
700 self.frame.min_url.Append(min_url) | |
701 try: | 659 try: |
702 id = 'mini-' + self.frame.session.get_next_id() | 660 id = 'mini-' + self.frame.session.get_next_id() |
703 self.layers['miniatures'].add_miniature(id, min_url, label=min_label) | 661 self.layers['miniatures'].add_miniature(id, min_url, label=min_label) |
704 except Exception, e: | 662 except Exception, e: |
705 self.log.log(traceback.format_exc(), ORPG_GENERAL) | 663 self.log.log(traceback.format_exc(), ORPG_GENERAL) |
730 xml_str += " sizex='" + str(self.size[0]) + "'" | 688 xml_str += " sizex='" + str(self.size[0]) + "'" |
731 xml_str += " sizey='" + str(self.size[1]) + "'" | 689 xml_str += " sizey='" + str(self.size[1]) + "'" |
732 s = "" | 690 s = "" |
733 keys = self.layers.keys() | 691 keys = self.layers.keys() |
734 for k in keys: | 692 for k in keys: |
735 if (k != "fog" or action != "update"): | 693 if (k != "fog" or action != "update"): s += self.layers[k].layerToXML(action) |
736 s += self.layers[k].layerToXML(action) | |
737 self.size_changed = 0 | 694 self.size_changed = 0 |
738 if s: | 695 if s: |
739 self.log.log("Exit MapCanvas->toxml(self, " + action + ")", ORPG_DEBUG) | 696 self.log.log("Exit MapCanvas->toxml(self, " + action + ")", ORPG_DEBUG) |
740 return xml_str + " action='" + action + "'>" + s + "</map>" | 697 return xml_str + " action='" + action + "'>" + s + "</map>" |
741 else: | 698 else: |
762 if xml_dom == None: | 719 if xml_dom == None: |
763 self.log.log("xml_dom == None\n" + xml, ORPG_INFO) | 720 self.log.log("xml_dom == None\n" + xml, ORPG_INFO) |
764 self.log.log("Exit MapCanvas->takexml(self, xml)", ORPG_DEBUG) | 721 self.log.log("Exit MapCanvas->takexml(self, xml)", ORPG_DEBUG) |
765 return | 722 return |
766 node_list = xml_dom.getElementsByTagName("map") | 723 node_list = xml_dom.getElementsByTagName("map") |
767 if len(node_list) < 1: | 724 if len(node_list) < 1: self.log.log("Invalid XML format for mapper", ORPG_INFO) |
768 self.log.log("Invalid XML format for mapper", ORPG_INFO) | |
769 else: | 725 else: |
770 # set map version to incoming data so layers can convert | 726 # set map version to incoming data so layers can convert |
771 self.map_version = node_list[0].getAttribute("version") | 727 self.map_version = node_list[0].getAttribute("version") |
772 action = node_list[0].getAttribute("action") | 728 action = node_list[0].getAttribute("action") |
773 if action == "new": | 729 if action == "new": |
774 self.layers = {} | 730 self.layers = {} |
775 try: | 731 try: self.layers['bg'] = layer_back_ground(self) |
776 self.layers['bg'] = layer_back_ground(self) | 732 except: pass |
777 except: | 733 try: self.layers['grid'] = grid_layer(self) |
778 pass | 734 except: pass |
779 try: | 735 try: self.layers['miniatures'] = miniature_layer(self) |
780 self.layers['grid'] = grid_layer(self) | 736 except: pass |
781 except: | 737 try: self.layers['whiteboard'] = whiteboard_layer(self) |
782 pass | 738 except: pass |
783 try: | 739 try: self.layers['fog'] = fog_layer(self) |
784 self.layers['miniatures'] = miniature_layer(self) | 740 except: pass |
785 except: | |
786 pass | |
787 try: | |
788 self.layers['whiteboard'] = whiteboard_layer(self) | |
789 except: | |
790 pass | |
791 try: | |
792 self.layers['fog'] = fog_layer(self) | |
793 except: | |
794 pass | |
795 sizex = node_list[0].getAttribute("sizex") | 741 sizex = node_list[0].getAttribute("sizex") |
796 if sizex != "": | 742 if sizex != "": |
797 sizex = int(float(sizex)) | 743 sizex = int(float(sizex)) |
798 sizey = self.size[1] | 744 sizey = self.size[1] |
799 self.set_size((sizex,sizey)) | 745 self.set_size((sizex,sizey)) |
806 self.size_changed = 0 | 752 self.size_changed = 0 |
807 children = node_list[0]._get_childNodes() | 753 children = node_list[0]._get_childNodes() |
808 #fog layer must be computed first, so that no data is inadvertently revealed | 754 #fog layer must be computed first, so that no data is inadvertently revealed |
809 for c in children: | 755 for c in children: |
810 name = c._get_nodeName() | 756 name = c._get_nodeName() |
811 if name == "fog": | 757 if name == "fog": self.layers[name].layerTakeDOM(c) |
812 self.layers[name].layerTakeDOM(c) | |
813 for c in children: | 758 for c in children: |
814 name = c._get_nodeName() | 759 name = c._get_nodeName() |
815 if name != "fog": | 760 if name != "fog": self.layers[name].layerTakeDOM(c) |
816 self.layers[name].layerTakeDOM(c) | |
817 # all map data should be converted, set map version to current version | 761 # all map data should be converted, set map version to current version |
818 self.map_version = MAP_VERSION | 762 self.map_version = MAP_VERSION |
819 self.Refresh(False) | 763 self.Refresh(False) |
820 xml_dom.unlink() # eliminate circular refs | 764 xml_dom.unlink() # eliminate circular refs |
821 except: | 765 except: |
827 self.log.log("Enter MapCanvas->re_ids_in_xml(self, xml)", ORPG_DEBUG) | 771 self.log.log("Enter MapCanvas->re_ids_in_xml(self, xml)", ORPG_DEBUG) |
828 new_xml = "" | 772 new_xml = "" |
829 tmp_map = map_msg() | 773 tmp_map = map_msg() |
830 xml_dom = parseXml(str(xml)) | 774 xml_dom = parseXml(str(xml)) |
831 node_list = xml_dom.getElementsByTagName("map") | 775 node_list = xml_dom.getElementsByTagName("map") |
832 if len(node_list) < 1: | 776 if len(node_list) < 1: self.log.log("Invalid XML format for mapper", ORPG_INFO) |
833 self.log.log("Invalid XML format for mapper", ORPG_INFO) | |
834 else: | 777 else: |
835 tmp_map.init_from_dom(node_list[0]) | 778 tmp_map.init_from_dom(node_list[0]) |
836 if tmp_map.children.has_key("miniatures"): | 779 if tmp_map.children.has_key("miniatures"): |
837 miniatures_layer = tmp_map.children["miniatures"] | 780 miniatures_layer = tmp_map.children["miniatures"] |
838 if miniatures_layer: | 781 if miniatures_layer: |
850 if whiteboard_layer: | 793 if whiteboard_layer: |
851 lines = whiteboard_layer.get_children().keys() | 794 lines = whiteboard_layer.get_children().keys() |
852 if lines: | 795 if lines: |
853 for line in lines: | 796 for line in lines: |
854 l = whiteboard_layer.children[line] | 797 l = whiteboard_layer.children[line] |
855 if l.tagname == 'line': | 798 if l.tagname == 'line': id = 'line-' + self.frame.session.get_next_id() |
856 id = 'line-' + self.frame.session.get_next_id() | 799 elif l.tagname == 'text': id = 'text-' + self.frame.session.get_next_id() |
857 elif l.tagname == 'text': | 800 elif l.tagname == 'circle': id = 'circle-' + self.frame.session.get_next_id() |
858 id = 'text-' + self.frame.session.get_next_id() | |
859 elif l.tagname == 'circle': | |
860 id = 'circle-' + self.frame.session.get_next_id() | |
861 l.init_prop("id", id) | 801 l.init_prop("id", id) |
862 new_xml = tmp_map.get_all_xml() | 802 new_xml = tmp_map.get_all_xml() |
863 if xml_dom: | 803 if xml_dom: xml_dom.unlink() |
864 xml_dom.unlink() | |
865 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) |
866 return str(new_xml) | 805 return str(new_xml) |
867 | 806 |
868 class map_wnd(wx.Panel): | 807 class map_wnd(wx.Panel): |
869 def __init__(self, parent, id): | 808 def __init__(self, parent, id): |
890 self.layer_handlers.append(fog_handler(self.layer_tabs,-1,self.canvas)) | 829 self.layer_handlers.append(fog_handler(self.layer_tabs,-1,self.canvas)) |
891 self.layer_tabs.AddPage(self.layer_handlers[4],"Fog") | 830 self.layer_tabs.AddPage(self.layer_handlers[4],"Fog") |
892 self.layer_handlers.append(map_handler(self.layer_tabs,-1,self.canvas)) | 831 self.layer_handlers.append(map_handler(self.layer_tabs,-1,self.canvas)) |
893 self.layer_tabs.AddPage(self.layer_handlers[5],"General") | 832 self.layer_tabs.AddPage(self.layer_handlers[5],"General") |
894 self.layer_tabs.SetSelection(2) | 833 self.layer_tabs.SetSelection(2) |
895 | |
896 self.sizer = wx.BoxSizer(wx.VERTICAL) | 834 self.sizer = wx.BoxSizer(wx.VERTICAL) |
897 self.sizer.Add(self.canvas, 1, wx.EXPAND) | 835 self.sizer.Add(self.canvas, 1, wx.EXPAND) |
898 self.sizer.Add(self.layer_tabs, 0, wx.EXPAND) | 836 self.sizer.Add(self.layer_tabs, 0, wx.EXPAND) |
899 self.SetSizer(self.sizer) | 837 self.SetSizer(self.sizer) |
900 | |
901 self.Bind(FNB.EVT_FLATNOTEBOOK_PAGE_CHANGED, self.on_layer_change) | 838 self.Bind(FNB.EVT_FLATNOTEBOOK_PAGE_CHANGED, self.on_layer_change) |
902 #self.Bind(wx.EVT_SIZE, self.on_size) | 839 #self.Bind(wx.EVT_SIZE, self.on_size) |
903 self.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeave) | 840 self.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeave) |
904 self.load_default() | 841 self.load_default() |
905 self.log.log("Exit map_wnd", ORPG_DEBUG) | 842 self.log.log("Exit map_wnd", ORPG_DEBUG) |
906 | 843 |
907 def OnLeave(self, evt): | 844 def OnLeave(self, evt): |
908 if "__WXGTK__" in wx.PlatformInfo: | 845 if "__WXGTK__" in wx.PlatformInfo: wx.SetCursor(wx.StockCursor(wx.CURSOR_ARROW)) |
909 wx.SetCursor(wx.StockCursor(wx.CURSOR_ARROW)) | |
910 | 846 |
911 def load_default(self): | 847 def load_default(self): |
912 self.log.log("Enter map_wnd->load_default(self)", ORPG_DEBUG) | 848 self.log.log("Enter map_wnd->load_default(self)", ORPG_DEBUG) |
913 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()): |
914 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") |
985 | 921 |
986 def on_layer_change(self, evt): | 922 def on_layer_change(self, evt): |
987 self.log.log("Enter map_wnd->on_layer_change(self, evt)", ORPG_DEBUG) | 923 self.log.log("Enter map_wnd->on_layer_change(self, evt)", ORPG_DEBUG) |
988 layer = self.layer_tabs.GetPage(evt.GetSelection()) | 924 layer = self.layer_tabs.GetPage(evt.GetSelection()) |
989 for i in xrange(0, len(self.layer_handlers)): | 925 for i in xrange(0, len(self.layer_handlers)): |
990 if layer == self.layer_handlers[i]: | 926 if layer == self.layer_handlers[i]: self.current_layer = i |
991 self.current_layer = i | |
992 if self.current_layer == 0: | 927 if self.current_layer == 0: |
993 bg = self.layer_handlers[0] | 928 bg = self.layer_handlers[0] |
994 if (self.session.my_role() != self.session.ROLE_GM): | 929 if (self.session.my_role() != self.session.ROLE_GM): bg.url_path.Show(False) |
995 bg.url_path.Show(False) | 930 else: bg.url_path.Show(True) |
996 else: | |
997 bg.url_path.Show(True) | |
998 self.canvas.Refresh(False) | 931 self.canvas.Refresh(False) |
999 evt.Skip() | 932 evt.Skip() |
1000 self.log.log("Exit map_wnd->on_layer_change(self, evt)", ORPG_DEBUG) | 933 self.log.log("Exit map_wnd->on_layer_change(self, evt)", ORPG_DEBUG) |
1001 | 934 |
1002 def on_left_down(self, evt): | 935 def on_left_down(self, evt): |
1056 | 989 |
1057 def on_hk_map_layer(self, evt): | 990 def on_hk_map_layer(self, evt): |
1058 self.log.log("Enter map_wnd->on_hk_map_layer(self, evt)", ORPG_DEBUG) | 991 self.log.log("Enter map_wnd->on_hk_map_layer(self, evt)", ORPG_DEBUG) |
1059 id = self.top_frame.mainmenu.GetHelpString(evt.GetId()) | 992 id = self.top_frame.mainmenu.GetHelpString(evt.GetId()) |
1060 #print evt.GetMenu().GetTitle() | 993 #print evt.GetMenu().GetTitle() |
1061 if id == "Background Layer": | 994 if id == "Background Layer": self.current_layer = self.get_tab_index("Background") |
1062 self.current_layer = self.get_tab_index("Background") | 995 if id == "Grid Layer": self.current_layer = self.get_tab_index("Grid") |
1063 if id == "Grid Layer": | 996 if id == "Miniature Layer": self.current_layer = self.get_tab_index("Miniatures") |
1064 self.current_layer = self.get_tab_index("Grid") | 997 elif id == "Whiteboard Layer": self.current_layer = self.get_tab_index("Whiteboard") |
1065 if id == "Miniature Layer": | 998 elif id == "Fog Layer": self.current_layer = self.get_tab_index("Fog") |
1066 self.current_layer = self.get_tab_index("Miniatures") | 999 elif id == "General Properties": self.current_layer = self.get_tab_index("General") |
1067 elif id == "Whiteboard Layer": | |
1068 self.current_layer = self.get_tab_index("Whiteboard") | |
1069 elif id == "Fog Layer": | |
1070 self.current_layer = self.get_tab_index("Fog") | |
1071 elif id == "General Properties": | |
1072 self.current_layer = self.get_tab_index("General") | |
1073 self.layer_tabs.SetSelection(self.current_layer) | 1000 self.layer_tabs.SetSelection(self.current_layer) |
1074 self.log.log("Exit map_wnd->on_hk_map_layer(self, evt)", ORPG_DEBUG) | 1001 self.log.log("Exit map_wnd->on_hk_map_layer(self, evt)", ORPG_DEBUG) |
1075 | 1002 |
1076 def on_flush_cache(self, evt): | 1003 def on_flush_cache(self, evt): |
1077 self.log.log("Enter map_wnd->on_flush_cache(self, evt)", ORPG_DEBUG) | 1004 self.log.log("Enter map_wnd->on_flush_cache(self, evt)", ORPG_DEBUG) |