comparison orpg/mapper/miniatures.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 fdd70f11bc7e
children 37a11fea3304
comparison
equal deleted inserted replaced
70:52a5fa913008 71:449a8900f9ac
62 elif f < s: value = -1 62 elif f < s: value = -1
63 else: value = 1 63 else: value = 1
64 return value 64 return value
65 65
66 class BmpMiniature: 66 class BmpMiniature:
67 def __init__(self, id,path, bmp, pos=cmpPoint(0,0), heading=FACE_NONE, face=FACE_NONE, label="", locked=False, hide=False, snap_to_align=SNAPTO_ALIGN_CENTER, zorder=0, width=0, height=0, log=None, local=False, localPath='', localTime=-1): 67 def __init__(self, id,path, bmp, pos=cmpPoint(0,0),
68 self.log = log 68 heading=FACE_NONE, face=FACE_NONE, label="",
69 self.log.log("Enter BmpMiniature", ORPG_DEBUG) 69 locked=False, hide=False, snap_to_align=SNAPTO_ALIGN_CENTER,
70 zorder=0, width=0, height=0, log=None, local=False, localPath='', localTime=-1):
70 self.heading = heading 71 self.heading = heading
71 self.face = face 72 self.face = face
72 self.label = label 73 self.label = label
73 self.path = path 74 self.path = path
74 self.bmp = bmp 75 self.bmp = bmp
90 self.right = bmp.GetWidth() 91 self.right = bmp.GetWidth()
91 self.top = 0 92 self.top = 0
92 self.bottom = bmp.GetHeight() 93 self.bottom = bmp.GetHeight()
93 self.isUpdated = False 94 self.isUpdated = False
94 self.gray = False 95 self.gray = False
95 self.log.log("Exit BmpMiniature", ORPG_DEBUG)
96 96
97 def __del__(self): 97 def __del__(self):
98 self.log.log("Enter BmpMiniature->__del__(self)", ORPG_DEBUG)
99 del self.bmp 98 del self.bmp
100 self.bmp = None 99 self.bmp = None
101 self.log.log("Exit BmpMiniature->__del__(self)", ORPG_DEBUG)
102 100
103 def set_bmp(self, bmp): 101 def set_bmp(self, bmp):
104 self.log.log("Enter BmpMiniature->set_bmp(self, bmp)", ORPG_DEBUG)
105 self.bmp = bmp 102 self.bmp = bmp
106 self.log.log("Exit BmpMiniature->set_bmp(self, bmp)", ORPG_DEBUG)
107 103
108 def set_min_props(self, heading=FACE_NONE, face=FACE_NONE, label="", locked=False, hide=False, width=0, height=0): 104 def set_min_props(self, heading=FACE_NONE, face=FACE_NONE, label="", locked=False, hide=False, width=0, height=0):
109 self.log.log("Enter BmpMiniature->set_min_props(self, heading, face, label, locked, hide, width, height)",
110 ORPG_DEBUG)
111 self.heading = heading 105 self.heading = heading
112 self.face = face 106 self.face = face
113 self.label = label 107 self.label = label
114 if locked: self.locked = True 108 if locked: self.locked = True
115 else: self.locked = False 109 else: self.locked = False
116 if hide: self.hide = True 110 if hide: self.hide = True
117 else: self.hide = False 111 else: self.hide = False
118 self.width = int(width) 112 self.width = int(width)
119 self.height = int(height) 113 self.height = int(height)
120 self.isUpdated = True 114 self.isUpdated = True
121 self.log.log("Exit BmpMiniature->set_min_props(self, heading, face, label, locked, hide, width, height)",
122 ORPG_DEBUG)
123 115
124 def hit_test(self, pt): 116 def hit_test(self, pt):
125 self.log.log("Enter BmpMiniature->hit_test(self, pt)", ORPG_DEBUG)
126 rect = self.get_rect() 117 rect = self.get_rect()
127 result = None 118 result = None
128 result = rect.InsideXY(pt.x, pt.y) 119 result = rect.InsideXY(pt.x, pt.y)
129 self.log.log("Exit BmpMiniature->hit_test(self, pt)", ORPG_DEBUG)
130 return result 120 return result
131 121
132 def get_rect(self): 122 def get_rect(self):
133 self.log.log("Enter BmpMiniature->get_rect(self)", ORPG_DEBUG)
134 ret = wx.Rect(self.pos.x, self.pos.y, self.bmp.GetWidth(), self.bmp.GetHeight()) 123 ret = wx.Rect(self.pos.x, self.pos.y, self.bmp.GetWidth(), self.bmp.GetHeight())
135 self.log.log("Exit BmpMiniature->get_rect(self)", ORPG_DEBUG)
136 return ret 124 return ret
137 125
138 def draw(self, dc, mini_layer, op=wx.COPY): 126 def draw(self, dc, mini_layer, op=wx.COPY):
139 self.log.log("Enter BmpMiniature->draw(self, dc, mini_layer, op)", ORPG_DEBUG)
140 if isinstance(self.bmp, tuple): 127 if isinstance(self.bmp, tuple):
141 self.log.log("bmp is a tuple, it shouldnt be!", ORPG_INFO)
142 self.bmp = wx.ImageFromMime(self.bmp[1], self.bmp[2]).ConvertToBitmap() 128 self.bmp = wx.ImageFromMime(self.bmp[1], self.bmp[2]).ConvertToBitmap()
143 if self.bmp != None and self.bmp.Ok(): 129 if self.bmp != None and self.bmp.Ok():
144 # check if hidden and GM: we outline the mini in grey (little bit smaller than the actual size) 130 # check if hidden and GM: we outline the mini in grey (little bit smaller than the actual size)
145 # and write the label in the center of the mini 131 # and write the label in the center of the mini
146 if self.hide and mini_layer.canvas.frame.session.my_role() == mini_layer.canvas.frame.session.ROLE_GM: 132 if self.hide and mini_layer.canvas.frame.session.my_role() == mini_layer.canvas.frame.session.ROLE_GM:
147 self.log.log("Enter BmpMiniature->draw->Draw Hidden", ORPG_DEBUG)
148 # set the width and height of the image 133 # set the width and height of the image
149 if self.width and self.height: 134 if self.width and self.height:
150 tmp_image = self.bmp.ConvertToImage() 135 tmp_image = self.bmp.ConvertToImage()
151 tmp_image.Rescale(int(self.width), int(self.height)) 136 tmp_image.Rescale(int(self.width), int(self.height))
152 tmp_image.ConvertAlphaToMask() 137 tmp_image.ConvertAlphaToMask()
197 dc.SetPen(wx.RED_PEN) 182 dc.SetPen(wx.RED_PEN)
198 dc.SetBrush(wx.TRANSPARENT_BRUSH) 183 dc.SetBrush(wx.TRANSPARENT_BRUSH)
199 dc.DrawRectangle(self.pos.x, self.pos.y, self.bmp.GetWidth(), self.bmp.GetHeight()) 184 dc.DrawRectangle(self.pos.x, self.pos.y, self.bmp.GetWidth(), self.bmp.GetHeight())
200 dc.SetBrush(wx.NullBrush) 185 dc.SetBrush(wx.NullBrush)
201 dc.SetPen(wx.NullPen) 186 dc.SetPen(wx.NullPen)
202 self.log.log("Exit BmpMiniature->draw->Draw Hidden", ORPG_DEBUG)
203 return True 187 return True
204 elif self.hide: self.log.log("Enter/Exit BmpMiniature->draw->Skip Hidden", ORPG_DEBUG); return True 188 elif self.hide: return True
205 189
206 else: 190 else:
207 self.log.log("Enter BmpMiniature->draw->Not Hidden", ORPG_DEBUG)
208 # set the width and height of the image 191 # set the width and height of the image
209 bmp = self.bmp 192 bmp = self.bmp
210 if self.width and self.height: 193 if self.width and self.height:
211 tmp_image = self.bmp.ConvertToImage() 194 tmp_image = self.bmp.ConvertToImage()
212 tmp_image.Rescale(int(self.width), int(self.height)) 195 tmp_image.Rescale(int(self.width), int(self.height))
360 dc.DrawText(label,x+1,y+1) 343 dc.DrawText(label,x+1,y+1)
361 self.top-=5 344 self.top-=5
362 self.bottom+=5 345 self.bottom+=5
363 self.left-=5 346 self.left-=5
364 self.right+=5 347 self.right+=5
365 self.log.log("Exit BmpMiniature->draw->Not Hidden", ORPG_DEBUG)
366 return True 348 return True
367 else: self.log.log("Exit BmpMiniature->draw(self, dc, mini_layer, op) return False", ORPG_DEBUG); return False 349 else: return False
368 self.log.log("Exit BmpMiniature->draw(self, dc, mini_layer, op)", ORPG_DEBUG)
369 350
370 def toxml(self, action="update"): 351 def toxml(self, action="update"):
371 self.log.log("Enter BmpMiniature->toxml(self, " + action + ")", ORPG_DEBUG)
372 if action == "del": 352 if action == "del":
373 xml_str = "<miniature action='del' id='" + self.id + "'/>" 353 xml_str = "<miniature action='del' id='" + self.id + "'/>"
374 self.log.log(xml_str, ORPG_DEBUG)
375 self.log.log("Exit BmpMiniature->toxml(self, " + action + ")", ORPG_DEBUG)
376 return xml_str 354 return xml_str
377 xml_str = "<miniature" 355 xml_str = "<miniature"
378 xml_str += " action='" + action + "'" 356 xml_str += " action='" + action + "'"
379 xml_str += " label='" + self.label + "'" 357 xml_str += " label='" + self.label + "'"
380 xml_str+= " id='" + self.id + "'" 358 xml_str+= " id='" + self.id + "'"
395 if self.local: 373 if self.local:
396 xml_str += ' local="' + str(self.local) + '"' 374 xml_str += ' local="' + str(self.local) + '"'
397 xml_str += ' localPath="' + str(urllib.quote(self.localPath).replace('%3A', ':')) + '"' 375 xml_str += ' localPath="' + str(urllib.quote(self.localPath).replace('%3A', ':')) + '"'
398 xml_str += ' localTime="' + str(self.localTime) + '"' 376 xml_str += ' localTime="' + str(self.localTime) + '"'
399 xml_str += " />" 377 xml_str += " />"
400 self.log.log(xml_str, ORPG_DEBUG)
401 self.log.log("Exit BmpMiniature->toxml(self, " + action + ")", ORPG_DEBUG)
402 if (action == "update" and self.isUpdated) or action == "new": 378 if (action == "update" and self.isUpdated) or action == "new":
403 self.isUpdated = False 379 self.isUpdated = False
404 return xml_str 380 return xml_str
405 else: return '' 381 else: return ''
406 382
407 def takedom(self, xml_dom): 383 def takedom(self, xml_dom):
408 self.log.log("Enter BmpMiniature->takedom(self, xml_dom)", ORPG_DEBUG)
409 self.id = xml_dom.getAttribute("id") 384 self.id = xml_dom.getAttribute("id")
410 self.log.log("self.id=" + str(self.id), ORPG_DEBUG)
411 if xml_dom.hasAttribute("posx"): 385 if xml_dom.hasAttribute("posx"):
412 self.pos.x = int(xml_dom.getAttribute("posx")) 386 self.pos.x = int(xml_dom.getAttribute("posx"))
413 self.log.log("self.pos.x=" + str(self.pos.x), ORPG_DEBUG)
414 if xml_dom.hasAttribute("posy"): 387 if xml_dom.hasAttribute("posy"):
415 self.pos.y = int(xml_dom.getAttribute("posy")) 388 self.pos.y = int(xml_dom.getAttribute("posy"))
416 self.log.log("self.pos.y=" + str(self.pos.y), ORPG_DEBUG)
417 if xml_dom.hasAttribute("heading"): 389 if xml_dom.hasAttribute("heading"):
418 self.heading = int(xml_dom.getAttribute("heading")) 390 self.heading = int(xml_dom.getAttribute("heading"))
419 self.log.log("self.heading=" + str(self.heading), ORPG_DEBUG)
420 if xml_dom.hasAttribute("face"): 391 if xml_dom.hasAttribute("face"):
421 self.face = int(xml_dom.getAttribute("face")) 392 self.face = int(xml_dom.getAttribute("face"))
422 self.log.log("self.face=" + str(self.face), ORPG_DEBUG)
423 if xml_dom.hasAttribute("path"): 393 if xml_dom.hasAttribute("path"):
424 self.path = urllib.unquote(xml_dom.getAttribute("path")) 394 self.path = urllib.unquote(xml_dom.getAttribute("path"))
425 self.set_bmp(ImageHandler.load(self.path, 'miniature', self.id)) 395 self.set_bmp(ImageHandler.load(self.path, 'miniature', self.id))
426 self.log.log("self.path=" + self.path, ORPG_DEBUG)
427 if xml_dom.hasAttribute("locked"): 396 if xml_dom.hasAttribute("locked"):
428 if xml_dom.getAttribute("locked") == '1' or xml_dom.getAttribute("locked") == 'True': self.locked = True 397 if xml_dom.getAttribute("locked") == '1' or xml_dom.getAttribute("locked") == 'True': self.locked = True
429 else: self.locked = False 398 else: self.locked = False
430 self.log.log("self.locked=" + str(self.locked), ORPG_DEBUG)
431 if xml_dom.hasAttribute("hide"): 399 if xml_dom.hasAttribute("hide"):
432 if xml_dom.getAttribute("hide") == '1' or xml_dom.getAttribute("hide") == 'True': self.hide = True 400 if xml_dom.getAttribute("hide") == '1' or xml_dom.getAttribute("hide") == 'True': self.hide = True
433 else: self.hide = False 401 else: self.hide = False
434 self.log.log("self.hide=" + str(self.hide), ORPG_DEBUG)
435 if xml_dom.hasAttribute("label"): 402 if xml_dom.hasAttribute("label"):
436 self.label = xml_dom.getAttribute("label") 403 self.label = xml_dom.getAttribute("label")
437 self.log.log("self.label=" + self.label, ORPG_DEBUG)
438 if xml_dom.hasAttribute("zorder"): 404 if xml_dom.hasAttribute("zorder"):
439 self.zorder = int(xml_dom.getAttribute("zorder")) 405 self.zorder = int(xml_dom.getAttribute("zorder"))
440 self.log.log("self.zorder=" + str(self.zorder), ORPG_DEBUG)
441 if xml_dom.hasAttribute("align"): 406 if xml_dom.hasAttribute("align"):
442 if xml_dom.getAttribute("align") == '1' or xml_dom.getAttribute("align") == 'True': self.snap_to_align = 1 407 if xml_dom.getAttribute("align") == '1' or xml_dom.getAttribute("align") == 'True': self.snap_to_align = 1
443 else: self.snap_to_align = 0 408 else: self.snap_to_align = 0
444 self.log.log("self.snap_to_align=" + str(self.snap_to_align), ORPG_DEBUG)
445 if xml_dom.hasAttribute("width"): 409 if xml_dom.hasAttribute("width"):
446 self.width = int(xml_dom.getAttribute("width")) 410 self.width = int(xml_dom.getAttribute("width"))
447 self.log.log("self.width=" + str(self.width), ORPG_DEBUG)
448 if xml_dom.hasAttribute("height"): 411 if xml_dom.hasAttribute("height"):
449 self.height = int(xml_dom.getAttribute("height")) 412 self.height = int(xml_dom.getAttribute("height"))
450 self.log.log("self.height=" + str(self.height), ORPG_DEBUG)
451 self.log.log("Exit BmpMiniature->takedom(self, xml_dom)", ORPG_DEBUG)
452 413
453 ##----------------------------- 414 ##-----------------------------
454 ## miniature layer 415 ## miniature layer
455 ##----------------------------- 416 ##-----------------------------
456 class miniature_layer(layer_base): 417 class miniature_layer(layer_base):
457 def __init__(self, canvas): 418 def __init__(self, canvas):
458 self.canvas = canvas 419 self.canvas = canvas
459 self.log = self.canvas.log
460 self.log.log("Enter miniature_layer", ORPG_DEBUG)
461 self.settings = self.canvas.settings 420 self.settings = self.canvas.settings
462 layer_base.__init__(self) 421 layer_base.__init__(self)
463 self.id = -1 #added. 422 self.id = -1 #added.
464 self.miniatures = [] 423 self.miniatures = []
465 self.serial_number = 0 424 self.serial_number = 0
468 # only smaller. 427 # only smaller.
469 font_size = int(self.settings.get_setting('defaultfontsize')) 428 font_size = int(self.settings.get_setting('defaultfontsize'))
470 if (font_size >= 10): font_size -= 2 429 if (font_size >= 10): font_size -= 2
471 self.label_font = wx.Font(font_size, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 430 self.label_font = wx.Font(font_size, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL,
472 False, self.settings.get_setting('defaultfont')) 431 False, self.settings.get_setting('defaultfont'))
473 self.log.log("Exit miniature_layer", ORPG_DEBUG)
474 432
475 def next_serial(self): 433 def next_serial(self):
476 self.log.log("Enter miniature_layer->next_serial(self)", ORPG_DEBUG)
477 self.serial_number += 1 434 self.serial_number += 1
478 self.log.log("Exit miniature_layer->next_serial(self)", ORPG_DEBUG)
479 return self.serial_number 435 return self.serial_number
480 436
481 def get_next_highest_z(self): 437 def get_next_highest_z(self):
482 self.log.log("Enter miniature_layer->get_next_highest_z(self)", ORPG_DEBUG)
483 z = len(self.miniatures)+1 438 z = len(self.miniatures)+1
484 self.log.log("Exit miniature_layer->get_next_highest_z(self)", ORPG_DEBUG)
485 return z 439 return z
486 440
487 def cleanly_collapse_zorder(self): 441 def cleanly_collapse_zorder(self):
488 self.log.log("Enter miniature_layer->cleanly_collapse_zorder(self)", ORPG_DEBUG)
489 # lock the zorder stuff 442 # lock the zorder stuff
490 sorted_miniatures = self.miniatures[:] 443 sorted_miniatures = self.miniatures[:]
491 sorted_miniatures.sort(cmp_zorder) 444 sorted_miniatures.sort(cmp_zorder)
492 i = 0 445 i = 0
493 for mini in sorted_miniatures: 446 for mini in sorted_miniatures:
494 mini.zorder = i 447 mini.zorder = i
495 i = i + 1 448 i = i + 1
496 self.log.log("Exit miniature_layer->cleanly_collapse_zorder(self)", ORPG_DEBUG)
497 # unlock the zorder stuff 449 # unlock the zorder stuff
498 450
499 def collapse_zorder(self): 451 def collapse_zorder(self):
500 self.log.log("Enter miniature_layer->collapse_zorder(self)", ORPG_DEBUG)
501 # lock the zorder stuff 452 # lock the zorder stuff
502 sorted_miniatures = self.miniatures[:] 453 sorted_miniatures = self.miniatures[:]
503 sorted_miniatures.sort(cmp_zorder) 454 sorted_miniatures.sort(cmp_zorder)
504 i = 0 455 i = 0
505 for mini in sorted_miniatures: 456 for mini in sorted_miniatures:
506 if (mini.zorder != MIN_STICKY_BACK) and (mini.zorder != MIN_STICKY_FRONT): mini.zorder = i 457 if (mini.zorder != MIN_STICKY_BACK) and (mini.zorder != MIN_STICKY_FRONT): mini.zorder = i
507 else: pass 458 else: pass
508 i = i + 1 459 i = i + 1
509 self.log.log("Exit miniature_layer->collapse_zorder(self)", ORPG_DEBUG)
510 # unlock the zorder stuff 460 # unlock the zorder stuff
511 461
512 def rollback_serial(self): 462 def rollback_serial(self):
513 self.log.log("Enter miniature_layer->rollback_serial(self)", ORPG_DEBUG)
514 self.serial_number -= 1 463 self.serial_number -= 1
515 self.log.log("Exit miniature_layer->rollback_serial(self)", ORPG_DEBUG)
516 464
517 def add_miniature(self, id, path, pos=cmpPoint(0,0), label="", heading=FACE_NONE, 465 def add_miniature(self, id, path, pos=cmpPoint(0,0), label="", heading=FACE_NONE,
518 face=FACE_NONE, width=0, height=0, local=False, localPath='', localTime=-1): 466 face=FACE_NONE, width=0, height=0, local=False, localPath='', localTime=-1):
519 self.log.log("Enter miniature_layer->add_miniature(self, id, path, pos, label, heading, face, width, height)",
520 ORPG_DEBUG)
521 self.log.log("Before mini creation: " + str(self.get_next_highest_z()), ORPG_DEBUG)
522 bmp = ImageHandler.load(path, 'miniature', id) 467 bmp = ImageHandler.load(path, 'miniature', id)
523 if bmp: 468 if bmp:
524 mini = BmpMiniature(id, path, bmp, pos, heading, face, label, 469 mini = BmpMiniature(id, path, bmp, pos, heading, face, label,
525 zorder=self. get_next_highest_z(), width=width, 470 zorder=self. get_next_highest_z(), width=width,
526 height=height, log=self.log, local=local, localPath=localPath, localTime=localTime) 471 height=height, local=local, localPath=localPath, localTime=localTime)
527 self.log.log("After mini creation:" + str(self.get_next_highest_z()), ORPG_DEBUG)
528 self.miniatures.append(mini) 472 self.miniatures.append(mini)
529 self.log.log("After mini addition:" + str(self.get_next_highest_z()), ORPG_DEBUG)
530 xml_str = "<map><miniatures>" 473 xml_str = "<map><miniatures>"
531 xml_str += mini.toxml("new") 474 xml_str += mini.toxml("new")
532 xml_str += "</miniatures></map>" 475 xml_str += "</miniatures></map>"
533 self.canvas.frame.session.send(xml_str) 476 self.canvas.frame.session.send(xml_str)
534 else: self.log.log("Invalid image " + path + " has been ignored!", ORPG_DEBUG)
535 self.log.log("Exit miniature_layer->add_miniature(self, id, path, pos, label, heading, face, width, height)",
536 ORPG_DEBUG)
537 477
538 def get_miniature_by_id(self, id): 478 def get_miniature_by_id(self, id):
539 self.log.log("Enter miniature_layer->get_miniature_by_id(self, id)", ORPG_DEBUG)
540 for mini in self.miniatures: 479 for mini in self.miniatures:
541 if str(mini.id) == str(id): 480 if str(mini.id) == str(id):
542 self.log.log("Exit miniature_layer->get_miniature_by_id(self, id) return miniID: " + str(id), ORPG_DEBUG)
543 return mini 481 return mini
544 self.log.log("Exit miniature_layer->get_miniature_by_id(self, id) return None", ORPG_DEBUG)
545 return None 482 return None
546 483
547 def del_miniature(self, min): 484 def del_miniature(self, min):
548 self.log.log("Enter miniature_layer->del_miniature(self, min)", ORPG_DEBUG)
549 xml_str = "<map><miniatures>" 485 xml_str = "<map><miniatures>"
550 xml_str += min.toxml("del") 486 xml_str += min.toxml("del")
551 xml_str += "</miniatures></map>" 487 xml_str += "</miniatures></map>"
552 self.canvas.frame.session.send(xml_str) 488 self.canvas.frame.session.send(xml_str)
553 self.miniatures.remove(min) 489 self.miniatures.remove(min)
554 del min 490 del min
555 self.collapse_zorder() 491 self.collapse_zorder()
556 self.log.log("Exit miniature_layer->del_miniature(self, min)", ORPG_DEBUG)
557 492
558 def del_all_miniatures(self): 493 def del_all_miniatures(self):
559 self.log.log("Enter miniature_layer->del_all_miniatures(self)", ORPG_DEBUG)
560 while len(self.miniatures): 494 while len(self.miniatures):
561 min = self.miniatures.pop() 495 min = self.miniatures.pop()
562 del min 496 del min
563 self.collapse_zorder() 497 self.collapse_zorder()
564 self.log.log("Exit miniature_layer->del_all_miniatures(self)", ORPG_DEBUG)
565 498
566 def layerDraw(self, dc, topleft, size): 499 def layerDraw(self, dc, topleft, size):
567 self.log.log("Enter miniature_layer->layerDraw(self, dc, topleft, size)", ORPG_DEBUG)
568 dc.SetFont(self.label_font) 500 dc.SetFont(self.label_font)
569 sorted_miniatures = self.miniatures[:] 501 sorted_miniatures = self.miniatures[:]
570 sorted_miniatures.sort(cmp_zorder) 502 sorted_miniatures.sort(cmp_zorder)
571 for m in sorted_miniatures: 503 for m in sorted_miniatures:
572 if (m.pos.x>topleft[0]-m.right and 504 if (m.pos.x>topleft[0]-m.right and
573 m.pos.y>topleft[1]-m.bottom and 505 m.pos.y>topleft[1]-m.bottom and
574 m.pos.x<topleft[0]+size[0]-m.left and 506 m.pos.x<topleft[0]+size[0]-m.left and
575 m.pos.y<topleft[1]+size[1]-m.top): 507 m.pos.y<topleft[1]+size[1]-m.top):
576 m.draw(dc, self) 508 m.draw(dc, self)
577 self.log.log("Exit miniature_layer->layerDraw(self, dc, topleft, size)", ORPG_DEBUG)
578 509
579 def find_miniature(self, pt, only_unlocked=False): 510 def find_miniature(self, pt, only_unlocked=False):
580 self.log.log("Enter miniature_layer->find_miniature(self, pt, only_unlocked)", ORPG_DEBUG)
581 min_list = [] 511 min_list = []
582 for m in self.miniatures: 512 for m in self.miniatures:
583 if m.hit_test(pt): 513 if m.hit_test(pt):
584 if m.hide and self.canvas.frame.session.my_role() != self.canvas.frame.session.ROLE_GM: continue 514 if m.hide and self.canvas.frame.session.my_role() != self.canvas.frame.session.ROLE_GM: continue
585 if only_unlocked and not m.locked: min_list.append(m) 515 if only_unlocked and not m.locked: min_list.append(m)
586 elif not only_unlocked and m.locked: min_list.append(m) 516 elif not only_unlocked and m.locked: min_list.append(m)
587 else: continue 517 else: continue
588 if len(min_list) > 0: 518 if len(min_list) > 0:
589 self.log.log("Exit miniature_layer->find_miniature(self, pt, only_unlocked)", ORPG_DEBUG)
590 return min_list 519 return min_list
591 else: self.log.log("Exit miniature_layer->find_miniature(self, pt, only_unlocked)", ORPG_DEBUG); return None 520 else: return None
592 521
593 def layerToXML(self, action="update"): 522 def layerToXML(self, action="update"):
594 """ format """ 523 """ format """
595 self.log.log("Enter miniature_layer->layerToXML(self, " + action + ")", ORPG_DEBUG)
596 minis_string = "" 524 minis_string = ""
597 if self.miniatures: 525 if self.miniatures:
598 for m in self.miniatures: minis_string += m.toxml(action) 526 for m in self.miniatures: minis_string += m.toxml(action)
599 if minis_string != '': 527 if minis_string != '':
600 s = "<miniatures" 528 s = "<miniatures"
601 s += " serial='" + str(self.serial_number) + "'" 529 s += " serial='" + str(self.serial_number) + "'"
602 s += ">" 530 s += ">"
603 s += minis_string 531 s += minis_string
604 s += "</miniatures>" 532 s += "</miniatures>"
605 self.log.log("Exit miniature_layer->layerToXML(self, " + action + ")", ORPG_DEBUG)
606 return s 533 return s
607 else: self.log.log("Exit miniature_layer->layerToXML(self, " + action + ") return None", ORPG_DEBUG); return "" 534 else: return ""
608 535
609 def layerTakeDOM(self, xml_dom): 536 def layerTakeDOM(self, xml_dom):
610 self.log.log("Enter miniature_layer->layerTakeDOM(self, xml_dom)", ORPG_DEBUG)
611 if xml_dom.hasAttribute('serial'): 537 if xml_dom.hasAttribute('serial'):
612 self.serial_number = int(xml_dom.getAttribute('serial')) 538 self.serial_number = int(xml_dom.getAttribute('serial'))
613 children = xml_dom._get_childNodes() 539 children = xml_dom._get_childNodes()
614 for c in children: 540 for c in children:
615 action = c.getAttribute("action") 541 action = c.getAttribute("action")
617 if action == "del": 543 if action == "del":
618 mini = self.get_miniature_by_id(id) 544 mini = self.get_miniature_by_id(id)
619 if mini: 545 if mini:
620 self.miniatures.remove(mini) 546 self.miniatures.remove(mini)
621 del mini 547 del mini
622 else: self.log.log("Map Synchronization Error :: Update of unknown mini attempted", ORPG_DEBUG)
623 elif action == "new": 548 elif action == "new":
624 pos = cmpPoint(int(c.getAttribute('posx')),int(c.getAttribute('posy'))) 549 pos = cmpPoint(int(c.getAttribute('posx')),int(c.getAttribute('posy')))
625 path = urllib.unquote(c.getAttribute('path')) 550 path = urllib.unquote(c.getAttribute('path'))
626 label = c.getAttribute('label') 551 label = c.getAttribute('label')
627 height = width = heading = face = snap_to_align = zorder = 0 552 height = width = heading = face = snap_to_align = zorder = 0
633 if c.getAttribute('heading'): heading = int(c.getAttribute('heading')) 558 if c.getAttribute('heading'): heading = int(c.getAttribute('heading'))
634 if c.hasAttribute('face'): face = int(c.getAttribute('face')) 559 if c.hasAttribute('face'): face = int(c.getAttribute('face'))
635 if c.hasAttribute('align'): snap_to_align = int(c.getAttribute('align')) 560 if c.hasAttribute('align'): snap_to_align = int(c.getAttribute('align'))
636 if c.getAttribute('zorder'): zorder = int(c.getAttribute('zorder')) 561 if c.getAttribute('zorder'): zorder = int(c.getAttribute('zorder'))
637 min = BmpMiniature(id, path, ImageHandler.load(path, 'miniature', id), pos, heading, 562 min = BmpMiniature(id, path, ImageHandler.load(path, 'miniature', id), pos, heading,
638 face, label, locked, hide, snap_to_align, zorder, width, height, self.log) 563 face, label, locked, hide, snap_to_align, zorder, width, height)
639 self.miniatures.append(min) 564 self.miniatures.append(min)
640 if c.hasAttribute('local') and c.getAttribute('local') == 'True' and os.path.exists(urllib.unquote(c.getAttribute('localPath'))): 565 if c.hasAttribute('local') and c.getAttribute('local') == 'True' and os.path.exists(urllib.unquote(c.getAttribute('localPath'))):
641 localPath = urllib.unquote(c.getAttribute('localPath')) 566 localPath = urllib.unquote(c.getAttribute('localPath'))
642 local = True 567 local = True
643 localTime = float(c.getAttribute('localTime')) 568 localTime = float(c.getAttribute('localTime'))
653 # Otherwise, this will ensure that there's some kind of z-order 578 # Otherwise, this will ensure that there's some kind of z-order
654 self.collapse_zorder() 579 self.collapse_zorder()
655 else: 580 else:
656 mini = self.get_miniature_by_id(id) 581 mini = self.get_miniature_by_id(id)
657 if mini: mini.takedom(c) 582 if mini: mini.takedom(c)
658 else: self.log.log("Map Synchronization Error :: Update of unknown mini attempted", ORPG_DEBUG)
659 self.log.log("Exit miniature_layer->layerTakeDOM(self, xml_dom)", ORPG_DEBUG)
660 583
661 def upload(self, postdata, filename, modify=False, pos=cmpPoint(0,0)): 584 def upload(self, postdata, filename, modify=False, pos=cmpPoint(0,0)):
662 self.lock.acquire() 585 self.lock.acquire()
663 url = self.settings.get_setting('ImageServerBaseURL') 586 url = self.settings.get_setting('ImageServerBaseURL')
664 file = urllib.urlopen(url, postdata) 587 file = urllib.urlopen(url, postdata)