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