comparison orpg/mapper/miniatures.py @ 152:6081bdc2b8d5 beta

Traipse Beta 'OpenRPG' {091125-00} Traipse is a distribution of OpenRPG that is designed to be easy to setup and go. Traipse also makes it easy for developers to work on code without fear of sacrifice. 'Ornery-Orc' continues the trend of 'Grumpy' and adds fixes to the code. 'Ornery-Orc's main goal is to offer more advanced features and enhance the productivity of the user. Update Summary (Beta) Added Bookmarks Fix to Remote Admin Commands Minor fix to text based Server Fix to Pretty Print, from Core Fix to Splitter Nodes not being created Fix to massive amounts of images loading, from Core Added 'boot' command to remote admin Added confirmation window for sent nodes Minor changes to allow for portability to an OpenSUSE linux OS Miniatures Layer pop up box allows users to turn off Mini labels, from FlexiRPG Zoom Mouse plugin added Images added to Plugin UI Switching to Element Tree Map efficiency, from FlexiRPG Added Status Bar to Update Manager default_manifest.xml renamed to default_upmana.xml Cleaner clode for saved repositories New TrueDebug Class in orpg_log (See documentation for usage) Mercurial's hgweb folder is ported to upmana Pretty important update that can help remove thousands of dead children from your gametree. Children, <forms />, <group_atts />, <horizontal />, <cols />, <rows />, <height />, etc... are all tags now. Check your gametree and look for dead children!! New Gametree Recursion method, mapping, and context sensitivity. !Infinite Loops return error instead of freezing the software! New Syntax added for custom PC sheets Tip of the Day added, from Core and community Fixed Whiteboard ID to prevent random line or text deleting. Modified ID's to prevent non updated clients from ruining the fix.
author sirebral
date Wed, 25 Nov 2009 06:16:35 -0600
parents e842a5f1b775
children 52100f68dfe1
comparison
equal deleted inserted replaced
150:6c5f46a5924b 152:6081bdc2b8d5
27 # utilities in the orpg project. 27 # utilities in the orpg project.
28 # 28 #
29 __version__ = "$Id: miniatures.py,v 1.46 2007/12/07 20:39:50 digitalxero Exp $" 29 __version__ = "$Id: miniatures.py,v 1.46 2007/12/07 20:39:50 digitalxero Exp $"
30 30
31 from base import * 31 from base import *
32 import thread 32 import thread, time, urllib, os.path, mimetypes
33 import time
34 import urllib
35 import os.path
36 import mimetypes
37 33
38 import xml.dom.minidom as minidom 34 import xml.dom.minidom as minidom
39 from orpg.tools.orpg_settings import settings 35 from orpg.tools.orpg_settings import settings
40 36
41 from xml.etree.ElementTree import ElementTree, Element 37 from xml.etree.ElementTree import ElementTree, Element
104 def __del__(self): 100 def __del__(self):
105 del self.image 101 del self.image
106 self.image = None 102 self.image = None
107 103
108 def set_bmp(self, bmp): 104 def set_bmp(self, bmp):
109 ### Alpha ###
110 try: bmp = bmp.ConvertToImage()
111 except: pass
112 ### Still ironing out some kinks to FlexiRPG's map features ###
113 self.image = bmp 105 self.image = bmp
114 self.image.ConvertAlphaToMask() 106 self.image.ConvertAlphaToMask()
115 self.generate_bmps() 107 self.generate_bmps()
116 108
117 def generate_bmps(self): 109 def generate_bmps(self):
147 return ret 139 return ret
148 140
149 def draw(self, dc, mini_layer, op=wx.COPY): 141 def draw(self, dc, mini_layer, op=wx.COPY):
150 if self.hide and mini_layer.canvas.frame.session.my_role() == mini_layer.canvas.frame.session.ROLE_GM: 142 if self.hide and mini_layer.canvas.frame.session.my_role() == mini_layer.canvas.frame.session.ROLE_GM:
151 # set the width and height of the image 143 # set the width and height of the image
152 """
153 if self.width and self.height:
154 tmp_image = self.bmp.ConvertToImage()
155 tmp_image.Rescale(int(self.width), int(self.height))
156 tmp_image.ConvertAlphaToMask()
157 self.bmp = tmp_image.ConvertToBitmap()
158 mask = wx.Mask(self.bmp, wx.Colour(tmp_image.GetMaskRed(),
159 tmp_image.GetMaskGreen(), tmp_image.GetMaskBlue()))
160 self.bmp.SetMask(mask)
161 del tmp_image
162 del mask
163 """
164 self.left = 0 144 self.left = 0
165 self.right = self.bmp.GetWidth() 145 self.right = self.bmp.GetWidth()
166 self.top = 0 146 self.top = 0
167 self.bottom = self.bmp.GetHeight() 147 self.bottom = self.bmp.GetHeight()
168 # grey outline 148 # grey outline
267 dc.SetPen(wx.BLACK_PEN) 247 dc.SetPen(wx.BLACK_PEN)
268 dc.SetBrush(wx.CYAN_BRUSH) 248 dc.SetBrush(wx.CYAN_BRUSH)
269 triangle = [] 249 triangle = []
270 # Figure out which direction to draw the marker!! 250 # Figure out which direction to draw the marker!!
271 tri_list = { 251 tri_list = {
272 FACE_NORTH: [cmpPoint(x_center - x_quarter, y_center - y_half ), cmpPoint(x_center, y_center - y_3quarter ), cmpPoint(x_center + x_quarter, y_center - y_half)], 252 FACE_NORTH: [cmpPoint(x_center - x_quarter, y_center - y_half ),
273 FACE_SOUTH: [cmpPoint(x_center - x_quarter, y_center + y_half ), cmpPoint(x_center, y_center + y_3quarter ), cmpPoint(x_center + x_quarter, y_center + y_half )], 253 cmpPoint(x_center, y_center - y_3quarter ),
274 FACE_NORTHEAST: [cmpPoint(x_center + x_quarter, y_center - y_half ), cmpPoint(x_center + x_3quarter, y_center - y_3quarter ), cmpPoint(x_center + x_half, y_center - y_quarter)], 254 cmpPoint(x_center + x_quarter, y_center - y_half)],
275 FACE_EAST: [cmpPoint(x_center + x_half, y_center - y_quarter ), cmpPoint(x_center + x_3quarter, y_center ), cmpPoint(x_center + x_half, y_center + y_quarter )], 255 FACE_SOUTH: [cmpPoint(x_center - x_quarter, y_center + y_half ),
276 FACE_SOUTHEAST: [cmpPoint(x_center + x_half, y_center + y_quarter ), cmpPoint(x_center + x_3quarter, y_center + y_3quarter ), cmpPoint(x_center + x_quarter, y_center + y_half )], 256 cmpPoint(x_center, y_center + y_3quarter ),
277 FACE_SOUTHWEST: [cmpPoint(x_center - x_quarter, y_center + y_half ), cmpPoint(x_center - x_3quarter, y_center + y_3quarter ), cmpPoint(x_center - x_half, y_center + y_quarter )], 257 cmpPoint(x_center + x_quarter, y_center + y_half )],
278 FACE_WEST: [cmpPoint(x_center - x_half, y_center + y_quarter ), cmpPoint(x_center - x_3quarter, y_center ), cmpPoint(x_center - x_half, y_center - y_quarter )], 258 FACE_NORTHEAST: [cmpPoint(x_center + x_quarter, y_center - y_half ),
279 FACE_NORTHWEST: [cmpPoint(x_center - x_half, y_center - y_quarter ), cmpPoint(x_center - x_3quarter, y_center - y_3quarter ), cmpPoint(x_center - x_quarter, y_center - y_half )]} 259 cmpPoint(x_center + x_3quarter, y_center - y_3quarter ),
260 cmpPoint(x_center + x_half, y_center - y_quarter)],
261 FACE_EAST: [cmpPoint(x_center + x_half, y_center - y_quarter ),
262 cmpPoint(x_center + x_3quarter, y_center ),
263 cmpPoint(x_center + x_half, y_center + y_quarter )],
264 FACE_SOUTHEAST: [cmpPoint(x_center + x_half, y_center + y_quarter ),
265 cmpPoint(x_center + x_3quarter, y_center + y_3quarter ),
266 cmpPoint(x_center + x_quarter, y_center + y_half )],
267 FACE_SOUTHWEST: [cmpPoint(x_center - x_quarter, y_center + y_half ),
268 cmpPoint(x_center - x_3quarter, y_center + y_3quarter ),
269 cmpPoint(x_center - x_half, y_center + y_quarter )],
270 FACE_WEST: [cmpPoint(x_center - x_half, y_center + y_quarter ),
271 cmpPoint(x_center - x_3quarter, y_center ),
272 cmpPoint(x_center - x_half, y_center - y_quarter )],
273 FACE_NORTHWEST: [cmpPoint(x_center - x_half, y_center - y_quarter ),
274 cmpPoint(x_center - x_3quarter, y_center - y_3quarter ),
275 cmpPoint(x_center - x_quarter, y_center - y_half )]}
280 for tri in tri_list[self.heading]: 276 for tri in tri_list[self.heading]:
281 triangle.append(tri) 277 triangle.append(tri)
282 del tri_list 278 del tri_list
283 dc.DrawPolygon(triangle) 279 dc.DrawPolygon(triangle)
284 dc.SetBrush(wx.NullBrush) 280 dc.SetBrush(wx.NullBrush)
350 print xml_str; return xml_str 346 print xml_str; return xml_str
351 else: return '' 347 else: return ''
352 348
353 def takedom(self, xml_dom): 349 def takedom(self, xml_dom):
354 self.id = xml_dom.getAttribute("id") 350 self.id = xml_dom.getAttribute("id")
355 if xml_dom.hasAttribute("posx"): 351 if xml_dom.hasAttribute("posx"): self.pos.x = int(xml_dom.getAttribute("posx"))
356 self.pos.x = int(xml_dom.getAttribute("posx")) 352 if xml_dom.hasAttribute("posy"): self.pos.y = int(xml_dom.getAttribute("posy"))
357 if xml_dom.hasAttribute("posy"): 353 if xml_dom.hasAttribute("heading"): self.heading = int(xml_dom.getAttribute("heading"))
358 self.pos.y = int(xml_dom.getAttribute("posy")) 354 if xml_dom.hasAttribute("face"): self.face = int(xml_dom.getAttribute("face"))
359 if xml_dom.hasAttribute("heading"):
360 self.heading = int(xml_dom.getAttribute("heading"))
361 if xml_dom.hasAttribute("face"):
362 self.face = int(xml_dom.getAttribute("face"))
363 if xml_dom.hasAttribute("path"): 355 if xml_dom.hasAttribute("path"):
364 self.path = urllib.unquote(xml_dom.getAttribute("path")) 356 self.path = urllib.unquote(xml_dom.getAttribute("path"))
365 self.set_bmp(ImageHandler.load(self.path, 'miniature', self.id)) 357 self.set_bmp(ImageHandler.load(self.path, 'miniature', self.id))
366 if xml_dom.hasAttribute("locked"): 358 if xml_dom.hasAttribute("locked"):
367 if xml_dom.getAttribute("locked") == '1' or xml_dom.getAttribute("locked") == 'True': self.locked = True 359 if xml_dom.getAttribute("locked") == '1' or xml_dom.getAttribute("locked") == 'True': self.locked = True
368 else: self.locked = False 360 else: self.locked = False
369 if xml_dom.hasAttribute("hide"): 361 if xml_dom.hasAttribute("hide"):
370 if xml_dom.getAttribute("hide") == '1' or xml_dom.getAttribute("hide") == 'True': self.hide = True 362 if xml_dom.getAttribute("hide") == '1' or xml_dom.getAttribute("hide") == 'True': self.hide = True
371 else: self.hide = False 363 else: self.hide = False
372 if xml_dom.hasAttribute("label"): 364 if xml_dom.hasAttribute("label"): self.label = xml_dom.getAttribute("label")
373 self.label = xml_dom.getAttribute("label") 365 if xml_dom.hasAttribute("zorder"): self.zorder = int(xml_dom.getAttribute("zorder"))
374 if xml_dom.hasAttribute("zorder"):
375 self.zorder = int(xml_dom.getAttribute("zorder"))
376 if xml_dom.hasAttribute("align"): 366 if xml_dom.hasAttribute("align"):
377 if xml_dom.getAttribute("align") == '1' or xml_dom.getAttribute("align") == 'True': self.snap_to_align = 1 367 if xml_dom.getAttribute("align") == '1' or xml_dom.getAttribute("align") == 'True': self.snap_to_align = 1
378 else: self.snap_to_align = 0 368 else: self.snap_to_align = 0
379 if xml_dom.hasAttribute("width"): 369 if xml_dom.hasAttribute("width"): self.width = int(xml_dom.getAttribute("width"))
380 self.width = int(xml_dom.getAttribute("width")) 370 if xml_dom.hasAttribute("height"): self.height = int(xml_dom.getAttribute("height"))
381 if xml_dom.hasAttribute("height"):
382 self.height = int(xml_dom.getAttribute("height"))
383 371
384 ##----------------------------- 372 ##-----------------------------
385 ## miniature layer 373 ## miniature layer
386 ##----------------------------- 374 ##-----------------------------
387 class miniature_layer(layer_base): 375 class miniature_layer(layer_base):
446 xml_str += "</miniatures></map>" 434 xml_str += "</miniatures></map>"
447 self.canvas.frame.session.send(xml_str) 435 self.canvas.frame.session.send(xml_str)
448 436
449 def get_miniature_by_id(self, id): 437 def get_miniature_by_id(self, id):
450 for mini in self.miniatures: 438 for mini in self.miniatures:
451 if str(mini.id) == str(id): 439 if str(mini.id) == str(id): return mini
452 return mini
453 return None 440 return None
454 441
455 def del_miniature(self, min): 442 def del_miniature(self, min):
456 xml_str = "<map><miniatures>" 443 xml_str = "<map><miniatures>"
457 xml_str += min.toxml("del") 444 xml_str += min.toxml("del")
511 for c in children: 498 for c in children:
512 action = c.getAttribute("action") 499 action = c.getAttribute("action")
513 id = c.getAttribute('id') 500 id = c.getAttribute('id')
514 if action == "del": 501 if action == "del":
515 mini = self.get_miniature_by_id(id) 502 mini = self.get_miniature_by_id(id)
516 if mini: 503 if mini: self.miniatures.remove(mini); del mini
517 self.miniatures.remove(mini)
518 del mini
519 elif action == "new": 504 elif action == "new":
520 pos = cmpPoint(int(c.getAttribute('posx')),int(c.getAttribute('posy'))) 505 pos = cmpPoint(int(c.getAttribute('posx')),int(c.getAttribute('posy')))
521 path = urllib.unquote(c.getAttribute('path')) 506 path = urllib.unquote(c.getAttribute('path'))
522 label = c.getAttribute('label') 507 label = c.getAttribute('label')
523 height = width = heading = face = snap_to_align = zorder = 0 508 height = width = heading = face = snap_to_align = zorder = 0
544 filename = os.path.split(localPath) 529 filename = os.path.split(localPath)
545 (imgtype,j) = mimetypes.guess_type(filename[1]) 530 (imgtype,j) = mimetypes.guess_type(filename[1])
546 postdata = urllib.urlencode({'filename':filename[1], 'imgdata':imgdata, 'imgtype':imgtype}) 531 postdata = urllib.urlencode({'filename':filename[1], 'imgdata':imgdata, 'imgtype':imgtype})
547 thread.start_new_thread(self.upload, (postdata, localPath, True)) 532 thread.start_new_thread(self.upload, (postdata, localPath, True))
548 # collapse the zorder. If the client behaved well, then nothing should change. 533 # collapse the zorder. If the client behaved well, then nothing should change.
549 # Otherwise, this will ensure that there's some kind of z-order 534 # Otherwise, this will ensure that there's some kind of z-order
550 self.collapse_zorder() 535 self.collapse_zorder()
551 else: 536 else:
552 mini = self.get_miniature_by_id(id) 537 mini = self.get_miniature_by_id(id)
553 if mini: mini.takedom(c) 538 if mini: mini.takedom(c)
554 539
573 else: 558 else:
574 self.miniatures[len(self.miniatures)-1].local = True 559 self.miniatures[len(self.miniatures)-1].local = True
575 self.miniatures[len(self.miniatures)-1].localPath = filename 560 self.miniatures[len(self.miniatures)-1].localPath = filename
576 self.miniatures[len(self.miniatures)-1].localTime = time.time() 561 self.miniatures[len(self.miniatures)-1].localTime = time.time()
577 self.miniatures[len(self.miniatures)-1].path = path 562 self.miniatures[len(self.miniatures)-1].path = path
578 else: 563 else: print xml_dom.get('msg')
579 print xml_dom.get('msg')
580 except Exception, e: 564 except Exception, e:
581 print e 565 print e
582 print recvdata 566 print recvdata
583 finally: 567 finally:
584 urllib.urlcleanup() 568 urllib.urlcleanup()