comparison orpg/mapper/miniatures.py @ 118:217fb049bd00 alpha

Traipse Alpha 'OpenRPG' {091028-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: Adds Bookmarks (Alpha) with cool Smiley Star and Plus Symbol images! Changes made to the map for increased portability. SnowDog has changes planned in Core, though. Added an initial push to the BCG. Not much to see, just shows off how it is re-writing Main code. Fix to remote admin commands Minor fix to texted based server, works in /System/ folder Some Core changes to gametree to correctly disply Pretty Print, thanks David! Fix to Splitter Nodes not being created. Added images to Plugin Control panel for Autostart feature Fix to massive amounts of images loading; from Core fix to gsclient so with_statement imports Added 'boot' command to remote admin Prep work in Pass tool for remote admin rankings and different passwords, ei, Server, Admin, Moderator, etc. Remote Admin Commands more organized, more prep work. Added Confirmation window for sent nodes. Minor changes to allow for portability to an OpenSUSE linux OS (hopefully without breaking) {091028} 00: Made changes to gametree to start working with Element Tree, mostly from Core Minor changes to Map to start working with Element Tree, from Core Preliminary changes to map efficiency, from FlexiRPG Miniatures Layer pop up box allows users to turn off Mini labels, from FlexiRPG Changes to main.py to start working with Element Tree
author sirebral
date Wed, 28 Oct 2009 14:24:54 -0500
parents 763a04270cf6
children 9314d63c0941
comparison
equal deleted inserted replaced
117:0f18d16f3fe7 118:217fb049bd00
35 import os.path 35 import os.path
36 import mimetypes 36 import mimetypes
37 37
38 import xml.dom.minidom as minidom 38 import xml.dom.minidom as minidom
39 from orpg.tools.orpg_settings import settings 39 from orpg.tools.orpg_settings import settings
40
41 from xml.etree.ElementTree import ElementTree, Element
42 from xml.etree.ElementTree import fromstring, tostring
40 43
41 MIN_STICKY_BACK = -0XFFFFFF 44 MIN_STICKY_BACK = -0XFFFFFF
42 MIN_STICKY_FRONT = 0xFFFFFF 45 MIN_STICKY_FRONT = 0xFFFFFF
43 46
44 ##---------------------------------------- 47 ##----------------------------------------
66 elif f < s: value = -1 69 elif f < s: value = -1
67 else: value = 1 70 else: value = 1
68 return value 71 return value
69 72
70 class BmpMiniature: 73 class BmpMiniature:
71 def __init__(self, id,path, bmp, pos=cmpPoint(0,0), 74 def __init__(self, id, path, bmp, pos=cmpPoint(0,0),
72 heading=FACE_NONE, face=FACE_NONE, label="", 75 heading=FACE_NONE, face=FACE_NONE, label="",
73 locked=False, hide=False, snap_to_align=SNAPTO_ALIGN_CENTER, 76 locked=False, hide=False, snap_to_align=SNAPTO_ALIGN_CENTER,
74 zorder=0, width=0, height=0, log=None, local=False, localPath='', localTime=-1): 77 zorder=0, width=0, height=0, log=None, local=False, localPath='', localTime=-1, func='none'):
75 self.heading = heading 78 self.heading = heading
76 self.face = face 79 self.face = face
77 self.label = label 80 self.label = label
78 self.path = path 81 self.path = path
79 self.bmp = bmp
80 self.pos = pos 82 self.pos = pos
81 self.selected = False 83 self.selected = False
82 self.locked = locked 84 self.locked = locked
83 self.snap_to_align = snap_to_align 85 self.snap_to_align = snap_to_align
84 self.hide = hide 86 self.hide = hide
95 self.right = bmp.GetWidth() 97 self.right = bmp.GetWidth()
96 self.top = 0 98 self.top = 0
97 self.bottom = bmp.GetHeight() 99 self.bottom = bmp.GetHeight()
98 self.isUpdated = False 100 self.isUpdated = False
99 self.gray = False 101 self.gray = False
102 print bmp
103 self.set_bmp(bmp)
100 104
101 def __del__(self): 105 def __del__(self):
102 del self.bmp 106 del self.image
103 self.bmp = None 107 self.image = None
104 108
105 def set_bmp(self, bmp): 109 def set_bmp(self, bmp):
106 self.bmp = bmp 110 ### Alpha ###
111 try: bmp = bmp.ConvertToImage()
112 except: pass
113 ### Still ironing out some kinks to FlexiRPG's map features ###
114 self.image = bmp
115 self.image.ConvertAlphaToMask()
116 self.generate_bmps()
117
118 def generate_bmps(self):
119 if self.width:
120 bmp = self.image.Copy()
121 bmp.Rescale(int(self.width), int(self.height))
122 else:
123 bmp = self.image
124 self.bmp = bmp.ConvertToBitmap()
125 self.bmp_gray = bmp.ConvertToGreyscale().ConvertToBitmap()
107 126
108 def set_min_props(self, heading=FACE_NONE, face=FACE_NONE, label="", locked=False, hide=False, width=0, height=0): 127 def set_min_props(self, heading=FACE_NONE, face=FACE_NONE, label="", locked=False, hide=False, width=0, height=0):
109 self.heading = heading 128 self.heading = heading
110 self.face = face 129 self.face = face
111 self.label = label 130 self.label = label
114 if hide: self.hide = True 133 if hide: self.hide = True
115 else: self.hide = False 134 else: self.hide = False
116 self.width = int(width) 135 self.width = int(width)
117 self.height = int(height) 136 self.height = int(height)
118 self.isUpdated = True 137 self.isUpdated = True
138 self.generate_bmps()
119 139
120 def hit_test(self, pt): 140 def hit_test(self, pt):
121 rect = self.get_rect() 141 rect = self.get_rect()
122 result = None 142 result = None
123 result = rect.InsideXY(pt.x, pt.y) 143 result = rect.InsideXY(pt.x, pt.y)
126 def get_rect(self): 146 def get_rect(self):
127 ret = wx.Rect(self.pos.x, self.pos.y, self.bmp.GetWidth(), self.bmp.GetHeight()) 147 ret = wx.Rect(self.pos.x, self.pos.y, self.bmp.GetWidth(), self.bmp.GetHeight())
128 return ret 148 return ret
129 149
130 def draw(self, dc, mini_layer, op=wx.COPY): 150 def draw(self, dc, mini_layer, op=wx.COPY):
131 if isinstance(self.bmp, tuple): 151 if self.hide and mini_layer.canvas.frame.session.my_role() == mini_layer.canvas.frame.session.ROLE_GM:
132 self.bmp = wx.ImageFromMime(self.bmp[1], self.bmp[2]).ConvertToBitmap() 152 # set the width and height of the image
133 if self.bmp != None and self.bmp.Ok(): 153 """
134 # check if hidden and GM: we outline the mini in grey (little bit smaller than the actual size) 154 if self.width and self.height:
135 # and write the label in the center of the mini 155 tmp_image = self.bmp.ConvertToImage()
136 if self.hide and mini_layer.canvas.frame.session.my_role() == mini_layer.canvas.frame.session.ROLE_GM: 156 tmp_image.Rescale(int(self.width), int(self.height))
137 # set the width and height of the image 157 tmp_image.ConvertAlphaToMask()
138 if self.width and self.height: 158 self.bmp = tmp_image.ConvertToBitmap()
139 tmp_image = self.bmp.ConvertToImage() 159 mask = wx.Mask(self.bmp, wx.Colour(tmp_image.GetMaskRed(),
140 tmp_image.Rescale(int(self.width), int(self.height)) 160 tmp_image.GetMaskGreen(), tmp_image.GetMaskBlue()))
141 tmp_image.ConvertAlphaToMask() 161 self.bmp.SetMask(mask)
142 self.bmp = tmp_image.ConvertToBitmap() 162 del tmp_image
143 mask = wx.Mask(self.bmp, wx.Colour(tmp_image.GetMaskRed(), 163 del mask
144 tmp_image.GetMaskGreen(), tmp_image.GetMaskBlue())) 164 """
145 self.bmp.SetMask(mask) 165 self.left = 0
146 del tmp_image 166 self.right = self.bmp.GetWidth()
147 del mask 167 self.top = 0
148 self.left = 0 168 self.bottom = self.bmp.GetHeight()
149 self.right = self.bmp.GetWidth() 169 # grey outline
150 self.top = 0 170 graypen = wx.Pen("gray", 1, wx.DOT)
151 self.bottom = self.bmp.GetHeight() 171 dc.SetPen(graypen)
152 # grey outline 172 dc.SetBrush(wx.TRANSPARENT_BRUSH)
153 graypen = wx.Pen("gray", 1, wx.DOT) 173 #if width or height < 20 then offset = 1
154 dc.SetPen(graypen) 174 if self.bmp.GetWidth() <= 20: xoffset = 1
155 dc.SetBrush(wx.TRANSPARENT_BRUSH) 175 else: xoffset = 5
156 #if width or height < 20 then offset = 1 176 if self.bmp.GetHeight() <= 20: yoffset = 1
157 if self.bmp.GetWidth() <= 20: xoffset = 1 177 else: yoffset = 5
158 else: xoffset = 5 178 dc.DrawRectangle(self.pos.x + xoffset,
159 if self.bmp.GetHeight() <= 20: yoffset = 1 179 self.pos.y + yoffset, self.bmp.GetWidth(),
160 else: yoffset = 5 180 self.bmp.GetHeight())
161 dc.DrawRectangle(self.pos.x + xoffset, 181 dc.SetBrush(wx.NullBrush)
162 self.pos.y + yoffset, self.bmp.GetWidth() - (xoffset * 2), 182 dc.SetPen(wx.NullPen)
163 self.bmp.GetHeight() - (yoffset * 2)) 183 if mini_layer.show_labels:
164 dc.SetBrush(wx.NullBrush)
165 dc.SetPen(wx.NullPen)
166 ## draw label in the center of the mini 184 ## draw label in the center of the mini
167 label = mini_layer.get_mini_label(self) 185 label = mini_layer.get_mini_label(self)
168 if len(label): 186 if len(label):
169 dc.SetTextForeground(wx.RED) 187 dc.SetTextForeground(wx.RED)
170 (textWidth,textHeight) = dc.GetTextExtent(label) 188 (textWidth,textHeight) = dc.GetTextExtent(label)
178 self.left -= int((textWidth+2-self.right)/2)+1 196 self.left -= int((textWidth+2-self.right)/2)+1
179 self.bottom = y+textHeight+2-self.pos.y 197 self.bottom = y+textHeight+2-self.pos.y
180 dc.SetPen(wx.NullPen) 198 dc.SetPen(wx.NullPen)
181 dc.SetBrush(wx.NullBrush) 199 dc.SetBrush(wx.NullBrush)
182 dc.DrawText(label, x+1, y+1) 200 dc.DrawText(label, x+1, y+1)
183 201
184 #selected outline 202 #selected outline
185 if self.selected: 203 if self.selected:
186 dc.SetPen(wx.RED_PEN) 204 dc.SetPen(wx.RED_PEN)
187 dc.SetBrush(wx.TRANSPARENT_BRUSH) 205 dc.SetBrush(wx.TRANSPARENT_BRUSH)
188 dc.DrawRectangle(self.pos.x, self.pos.y, self.bmp.GetWidth(), self.bmp.GetHeight()) 206 dc.DrawRectangle(self.pos.x, self.pos.y, self.bmp.GetWidth(), self.bmp.GetHeight())
189 dc.SetBrush(wx.NullBrush) 207 dc.SetBrush(wx.NullBrush)
190 dc.SetPen(wx.NullPen) 208 dc.SetPen(wx.NullPen)
191 return True 209 return True
192 elif self.hide: return True 210 elif self.hide: return True
193 211
194 else: 212 else:
195 # set the width and height of the image 213 bmp = self.bmp_gray if self.gray else self.bmp
196 bmp = self.bmp 214 try: dc.DrawBitmap(bmp, self.pos.x, self.pos.y, True)
197 if self.width and self.height: 215 except: print bmp
198 tmp_image = self.bmp.ConvertToImage() 216 self.left = 0
199 tmp_image.Rescale(int(self.width), int(self.height)) 217 self.right = self.bmp.GetWidth()
200 tmp_image.ConvertAlphaToMask() 218 self.top = 0
201 self.bmp = tmp_image.ConvertToBitmap() 219 self.bottom = self.bmp.GetHeight()
202 mask = wx.Mask(self.bmp, wx.Colour(tmp_image.GetMaskRed(), 220
203 tmp_image.GetMaskGreen(), tmp_image.GetMaskBlue())) 221 # Draw the facing marker if needed
204 self.bmp.SetMask(mask) 222 if self.face != 0:
205 if self.gray: 223 x_mid = self.pos.x + (self.bmp.GetWidth()/2)
206 tmp_image = tmp_image.ConvertToGreyscale() 224 x_right = self.pos.x + self.bmp.GetWidth()
207 bmp = tmp_image.ConvertToBitmap() 225 y_mid = self.pos.y + (self.bmp.GetHeight()/2)
208 else: bmp = self.bmp 226 y_bottom = self.pos.y + self.bmp.GetHeight()
209 dc.DrawBitmap(bmp, self.pos.x, self.pos.y, True) 227 dc.SetPen(wx.WHITE_PEN)
210 self.left = 0 228 dc.SetBrush(wx.RED_BRUSH)
211 self.right = self.bmp.GetWidth() 229 triangle = []
212 self.top = 0 230
213 self.bottom = self.bmp.GetHeight() 231 # Figure out which direction to draw the marker!!
214 232 tri_list = {
215 # Draw the facing marker if needed 233 FACE_WEST: [cmpPoint(self.pos.x, self.pos.y), cmpPoint(self.pos.x-5, y_mid), cmpPoint(self.pos.x, y_bottom)],
216 if self.face != 0: 234 FACE_EAST: [cmpPoint(x_right, self.pos.y), cmpPoint(x_right + 5, y_mid), cmpPoint(x_right, y_bottom)],
217 x_mid = self.pos.x + (self.bmp.GetWidth()/2) 235 FACE_SOUTH: [cmpPoint(self.pos.x, y_bottom), cmpPoint(x_mid, y_bottom + 5), cmpPoint(x_right, y_bottom)],
218 x_right = self.pos.x + self.bmp.GetWidth() 236 FACE_NORTH: [cmpPoint(self.pos.x, self.pos.y), cmpPoint(x_mid, self.pos.y - 5), cmpPoint(x_right, self.pos.y)],
219 y_mid = self.pos.y + (self.bmp.GetHeight()/2) 237 FACE_NORTHEAST: [cmpPoint(x_mid, self.pos.y), cmpPoint(x_right + 5, self.pos.y - 5), cmpPoint(x_right, y_mid), cmpPoint(x_right, self.pos.y)],
220 y_bottom = self.pos.y + self.bmp.GetHeight() 238 FACE_SOUTHEAST: [cmpPoint(x_right, y_mid), cmpPoint(x_right + 5, y_bottom + 5), cmpPoint(x_mid, y_bottom), cmpPoint(x_right, y_bottom)],
221 dc.SetPen(wx.WHITE_PEN) 239 FACE_SOUTHWEST: [cmpPoint(x_mid, y_bottom), cmpPoint(self.pos.x - 5, y_bottom + 5),
222 dc.SetBrush(wx.RED_BRUSH) 240 cmpPoint(self.pos.x, y_mid), cmpPoint(self.pos.x, y_bottom)],
223 triangle = [] 241 FACE_NORTHWEST: [cmpPoint(self.pos.x, y_mid), cmpPoint(self.pos.x - 5, self.pos.y - 5), cmpPoint(x_mid, self.pos.y), cmpPoint(self.pos.x, self.pos.y)]
224 242 }
225 # Figure out which direction to draw the marker!! 243 for tri in tri_list[self.face]:
226 if self.face == FACE_WEST: 244 triangle.append(tri)
227 triangle.append(cmpPoint(self.pos.x,self.pos.y)) 245 del tri_list
228 triangle.append(cmpPoint(self.pos.x - 5, y_mid)) 246 dc.DrawPolygon(triangle)
229 triangle.append(cmpPoint(self.pos.x, y_bottom)) 247 dc.SetBrush(wx.NullBrush)
230 elif self.face == FACE_EAST: 248 dc.SetPen(wx.NullPen)
231 triangle.append(cmpPoint(x_right, self.pos.y)) 249
232 triangle.append(cmpPoint(x_right + 5, y_mid)) 250 # Draw the heading if needed
233 triangle.append(cmpPoint(x_right, y_bottom)) 251 if self.heading:
234 elif self.face == FACE_SOUTH: 252 x_adjust = 0
235 triangle.append(cmpPoint(self.pos.x, y_bottom)) 253 y_adjust = 4
236 triangle.append(cmpPoint(x_mid, y_bottom + 5)) 254 x_half = self.bmp.GetWidth()/2
237 triangle.append(cmpPoint(x_right, y_bottom)) 255 y_half = self.bmp.GetHeight()/2
238 elif self.face == FACE_NORTH: 256 x_quarter = self.bmp.GetWidth()/4
239 triangle.append(cmpPoint(self.pos.x, self.pos.y)) 257 y_quarter = self.bmp.GetHeight()/4
240 triangle.append(cmpPoint(x_mid, self.pos.y - 5)) 258 x_3quarter = x_quarter*3
241 triangle.append(cmpPoint(x_right, self.pos.y)) 259 y_3quarter = y_quarter*3
242 elif self.face == FACE_NORTHEAST: 260 x_full = self.bmp.GetWidth()
243 triangle.append(cmpPoint(x_mid, self.pos.y)) 261 y_full = self.bmp.GetHeight()
244 triangle.append(cmpPoint(x_right + 5, self.pos.y - 5)) 262 x_center = self.pos.x + x_half
245 triangle.append(cmpPoint(x_right, y_mid)) 263 y_center = self.pos.y + y_half
246 triangle.append(cmpPoint(x_right, self.pos.y)) 264 # Remember, the pen/brush must be a different color than the
247 elif self.face == FACE_SOUTHEAST: 265 # facing marker!!!! We'll use black/cyan for starters.
248 triangle.append(cmpPoint(x_right, y_mid)) 266 # Also notice that we will draw the heading on top of the
249 triangle.append(cmpPoint(x_right + 5, y_bottom + 5)) 267 # larger facing marker.
250 triangle.append(cmpPoint(x_mid, y_bottom)) 268 dc.SetPen(wx.BLACK_PEN)
251 triangle.append(cmpPoint(x_right, y_bottom)) 269 dc.SetBrush(wx.CYAN_BRUSH)
252 elif self.face == FACE_SOUTHWEST: 270 triangle = []
253 triangle.append(cmpPoint(x_mid, y_bottom)) 271 # Figure out which direction to draw the marker!!
254 triangle.append(cmpPoint(self.pos.x - 5, y_bottom + 5)) 272 tri_list = {
255 triangle.append(cmpPoint(self.pos.x, y_mid)) 273 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)],
256 triangle.append(cmpPoint(self.pos.x, y_bottom)) 274 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 )],
257 elif self.face == FACE_NORTHWEST: 275 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)],
258 triangle.append(cmpPoint(self.pos.x, y_mid)) 276 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 )],
259 triangle.append(cmpPoint(self.pos.x - 5, self.pos.y - 5)) 277 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 )],
260 triangle.append(cmpPoint(x_mid, self.pos.y)) 278 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 )],
261 triangle.append(cmpPoint(self.pos.x, self.pos.y)) 279 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 )],
262 dc.DrawPolygon(triangle) 280 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 )]}
263 dc.SetBrush(wx.NullBrush) 281 for tri in tri_list[self.heading]:
264 dc.SetPen(wx.NullPen) 282 triangle.append(tri)
265 283 del tri_list
266 # Draw the heading if needed 284 dc.DrawPolygon(triangle)
267 if self.heading: 285 dc.SetBrush(wx.NullBrush)
268 x_adjust = 0 286 dc.SetPen(wx.NullPen)
269 y_adjust = 4 287 #selected outline
270 x_half = self.bmp.GetWidth()/2 288 if self.selected:
271 y_half = self.bmp.GetHeight()/2 289 dc.SetPen(wx.RED_PEN)
272 x_quarter = self.bmp.GetWidth()/4 290 dc.SetBrush(wx.TRANSPARENT_BRUSH)
273 y_quarter = self.bmp.GetHeight()/4 291 dc.DrawRectangle(self.pos.x, self.pos.y, self.bmp.GetWidth(), self.bmp.GetHeight())
274 x_3quarter = x_quarter*3 292 dc.SetBrush(wx.NullBrush)
275 y_3quarter = y_quarter*3 293 dc.SetPen(wx.NullPen)
276 x_full = self.bmp.GetWidth() 294 if mini_layer.show_labels:
277 y_full = self.bmp.GetHeight()
278 x_center = self.pos.x + x_half
279 y_center = self.pos.y + y_half
280 # Remember, the pen/brush must be a different color than the
281 # facing marker!!!! We'll use black/cyan for starters.
282 # Also notice that we will draw the heading on top of the
283 # larger facing marker.
284 dc.SetPen(wx.BLACK_PEN)
285 dc.SetBrush(wx.CYAN_BRUSH)
286 triangle = []
287
288 # Figure out which direction to draw the marker!!
289 if self.heading == FACE_NORTH:
290 triangle.append(cmpPoint(x_center - x_quarter, y_center - y_half ))
291 triangle.append(cmpPoint(x_center, y_center - y_3quarter ))
292 triangle.append(cmpPoint(x_center + x_quarter, y_center - y_half ))
293 elif self.heading == FACE_SOUTH:
294 triangle.append(cmpPoint(x_center - x_quarter, y_center + y_half ))
295 triangle.append(cmpPoint(x_center, y_center + y_3quarter ))
296 triangle.append(cmpPoint(x_center + x_quarter, y_center + y_half ))
297 elif self.heading == FACE_NORTHEAST:
298 triangle.append(cmpPoint(x_center + x_quarter, y_center - y_half ))
299 triangle.append(cmpPoint(x_center + x_3quarter, y_center - y_3quarter ))
300 triangle.append(cmpPoint(x_center + x_half, y_center - y_quarter ))
301 elif self.heading == FACE_EAST:
302 triangle.append(cmpPoint(x_center + x_half, y_center - y_quarter ))
303 triangle.append(cmpPoint(x_center + x_3quarter, y_center ))
304 triangle.append(cmpPoint(x_center + x_half, y_center + y_quarter ))
305 elif self.heading == FACE_SOUTHEAST:
306 triangle.append(cmpPoint(x_center + x_half, y_center + y_quarter ))
307 triangle.append(cmpPoint(x_center + x_3quarter, y_center + y_3quarter ))
308 triangle.append(cmpPoint(x_center + x_quarter, y_center + y_half ))
309 elif self.heading == FACE_SOUTHWEST:
310 triangle.append(cmpPoint(x_center - x_quarter, y_center + y_half ))
311 triangle.append(cmpPoint(x_center - x_3quarter, y_center + y_3quarter ))
312 triangle.append(cmpPoint(x_center - x_half, y_center + y_quarter ))
313 elif self.heading == FACE_WEST:
314 triangle.append(cmpPoint(x_center - x_half, y_center + y_quarter ))
315 triangle.append(cmpPoint(x_center - x_3quarter, y_center ))
316 triangle.append(cmpPoint(x_center - x_half, y_center - y_quarter ))
317 elif self.heading == FACE_NORTHWEST:
318 triangle.append(cmpPoint(x_center - x_half, y_center - y_quarter ))
319 triangle.append(cmpPoint(x_center - x_3quarter, y_center - y_3quarter ))
320 triangle.append(cmpPoint(x_center - x_quarter, y_center - y_half ))
321 dc.DrawPolygon(triangle)
322 dc.SetBrush(wx.NullBrush)
323 dc.SetPen(wx.NullPen)
324 #selected outline
325 if self.selected:
326 dc.SetPen(wx.RED_PEN)
327 dc.SetBrush(wx.TRANSPARENT_BRUSH)
328 dc.DrawRectangle(self.pos.x, self.pos.y, self.bmp.GetWidth(), self.bmp.GetHeight())
329 dc.SetBrush(wx.NullBrush)
330 dc.SetPen(wx.NullPen)
331 # draw label 295 # draw label
332 label = mini_layer.get_mini_label(self) 296 self.mini_label(mini_layer, dc)
333 if len(label): 297 self.top-=5
334 dc.SetTextForeground(wx.RED) 298 self.bottom+=5
335 (textWidth,textHeight) = dc.GetTextExtent(label) 299 self.left-=5
336 x = self.pos.x +((self.bmp.GetWidth() - textWidth) /2) - 1 300 self.right+=5
337 y = self.pos.y + self.bmp.GetHeight() + 6 301 return True
338 dc.SetPen(wx.WHITE_PEN) 302
339 dc.SetBrush(wx.WHITE_BRUSH) 303
340 dc.DrawRectangle(x,y,textWidth+2,textHeight+2) 304 def mini_label(self, mini_layer, dc):
341 if (textWidth+2 > self.right): 305 label = mini_layer.get_mini_label(self)
342 self.right += int((textWidth+2-self.right)/2)+1 306 if len(label):
343 self.left -= int((textWidth+2-self.right)/2)+1 307 dc.SetTextForeground(wx.RED)
344 self.bottom = y+textHeight+2-self.pos.y 308 (textWidth,textHeight) = dc.GetTextExtent(label)
345 dc.SetPen(wx.NullPen) 309 x = self.pos.x +((self.bmp.GetWidth() - textWidth) /2) - 1
346 dc.SetBrush(wx.NullBrush) 310 y = self.pos.y + self.bmp.GetHeight() + 6
347 dc.DrawText(label,x+1,y+1) 311 dc.SetPen(wx.WHITE_PEN)
348 self.top-=5 312 dc.SetBrush(wx.WHITE_BRUSH)
349 self.bottom+=5 313 dc.DrawRectangle(x,y,textWidth+2,textHeight+2)
350 self.left-=5 314 if (textWidth+2 > self.right):
351 self.right+=5 315 self.right += int((textWidth+2-self.right)/2)+1
352 return True 316 self.left -= int((textWidth+2-self.right)/2)+1
353 else: return False 317 self.bottom = y+textHeight+2-self.pos.y
318 dc.SetPen(wx.NullPen)
319 dc.SetBrush(wx.NullBrush)
320 dc.DrawText(label,x+1,y+1)
354 321
355 def toxml(self, action="update"): 322 def toxml(self, action="update"):
356 if action == "del": 323 mini = Element('miniature')
357 xml_str = "<miniature action='del' id='" + self.id + "'/>" 324 if action == 'del':
358 return xml_str 325 mini.set('action', action)
359 xml_str = "<miniature" 326 mini.set('id', str(self.id))
360 xml_str += " action='" + action + "'" 327 return tostring(mini)
361 xml_str += " label='" + self.label + "'" 328 mini.set('action', action)
362 xml_str+= " id='" + self.id + "'" 329 mini.set('id', str(self.id))
330 mini.set('label', self.label)
363 if self.pos != None: 331 if self.pos != None:
364 xml_str += " posx='" + str(self.pos.x) + "'" 332 mini.set('posx', str(self.pos.x))
365 xml_str += " posy='" + str(self.pos.y) + "'" 333 mini.set('posy', str(self.pos.y))
366 if self.heading != None: xml_str += " heading='" + str(self.heading) + "'" 334 if self.heading != None: mini.set('heading', str(self.heading))
367 if self.face != None: xml_str += " face='" + str(self.face) + "'" 335 if self.face != None: mini.set('face', str(self.face))
368 if self.path != None: xml_str += " path='" + urllib.quote(self.path).replace('%3A', ':') + "'" 336 if self.path != None: mini.set('path', str(urllib.quote(self.path).replace('%3A', ':')))
369 if self.locked: xml_str += " locked='1'" 337 mini.set('locked', '1') if self.locked else mini.set('locked', '0')
370 else: xml_str += " locked='0'" 338 mini.set('hide', '1') if self.hide else mini.set('hide', '0')
371 if self.hide: xml_str += " hide='1'" 339 if self.snap_to_align != None: mini.set('align', str(self.snap_to_align))
372 else: xml_str += " hide='0'" 340 if self.id != None: mini.set('zorder', str(self.zorder))
373 if self.snap_to_align != None: xml_str += " align='" + str(self.snap_to_align) + "'" 341 if self.width != None: mini.set('width', str(self.width))
374 if self.id != None: xml_str += " zorder='" + str(self.zorder) + "'" 342 if self.height != None: mini.set('height', str(self.height))
375 if self.width != None: xml_str += " width='" + str(self.width) + "'"
376 if self.height != None: xml_str += " height='" + str(self.height) + "'"
377 if self.local: 343 if self.local:
378 xml_str += ' local="' + str(self.local) + '"' 344 mini.set('local', str(self.local))
379 xml_str += ' localPath="' + str(urllib.quote(self.localPath).replace('%3A', ':')) + '"' 345 mini.set('localPath', str(urllib.quote(self.localPath).replace('%3A', ':')))
380 xml_str += ' localTime="' + str(self.localTime) + '"' 346 mini.set('localTime', str(localTime))
381 xml_str += " />"
382 if (action == "update" and self.isUpdated) or action == "new": 347 if (action == "update" and self.isUpdated) or action == "new":
383 self.isUpdated = False 348 self.isUpdated = False
384 return xml_str 349 return mini
385 else: return '' 350 else: return ''
386 351
387 def takedom(self, xml_dom): 352 def takedom(self, xml_dom):
388 self.id = xml_dom.getAttribute("id") 353 self.id = xml_dom.getAttribute("id")
389 if xml_dom.hasAttribute("posx"): 354 if xml_dom.hasAttribute("posx"): self.pos.x = int(xml_dom.getAttribute("posx"))
390 self.pos.x = int(xml_dom.getAttribute("posx")) 355 if xml_dom.hasAttribute("posy"): self.pos.y = int(xml_dom.getAttribute("posy"))
391 if xml_dom.hasAttribute("posy"): 356 if xml_dom.hasAttribute("heading"): self.heading = int(xml_dom.getAttribute("heading"))
392 self.pos.y = int(xml_dom.getAttribute("posy")) 357 if xml_dom.hasAttribute("face"): self.face = int(xml_dom.getAttribute("face"))
393 if xml_dom.hasAttribute("heading"):
394 self.heading = int(xml_dom.getAttribute("heading"))
395 if xml_dom.hasAttribute("face"):
396 self.face = int(xml_dom.getAttribute("face"))
397 if xml_dom.hasAttribute("path"): 358 if xml_dom.hasAttribute("path"):
398 self.path = urllib.unquote(xml_dom.getAttribute("path")) 359 self.path = urllib.unquote(xml_dom.getAttribute("path"))
399 self.set_bmp(ImageHandler.load(self.path, 'miniature', self.id)) 360 self.set_bmp(ImageHandler.load(self.path, 'miniature', self.id))
400 if xml_dom.hasAttribute("locked"): 361 if xml_dom.hasAttribute("locked"):
401 if xml_dom.getAttribute("locked") == '1' or xml_dom.getAttribute("locked") == 'True': self.locked = True 362 if xml_dom.getAttribute("locked") == '1' or xml_dom.getAttribute("locked") == 'True': self.locked = True
423 self.canvas = canvas 384 self.canvas = canvas
424 layer_base.__init__(self) 385 layer_base.__init__(self)
425 self.id = -1 #added. 386 self.id = -1 #added.
426 self.miniatures = [] 387 self.miniatures = []
427 self.serial_number = 0 388 self.serial_number = 0
428 389 self.show_labels = True
429 # Set the font of the labels to be the same as the chat window 390 # Set the font of the labels to be the same as the chat window
430 # only smaller. 391 # only smaller.
431 font_size = int(settings.get_setting('defaultfontsize')) 392 font_size = int(settings.get_setting('defaultfontsize'))
432 if (font_size >= 10): font_size -= 2 393 if (font_size >= 10): font_size -= 2
433 self.label_font = wx.Font(font_size, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, 394 self.label_font = wx.Font(font_size, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL,
468 def add_miniature(self, id, path, pos=cmpPoint(0,0), label="", heading=FACE_NONE, 429 def add_miniature(self, id, path, pos=cmpPoint(0,0), label="", heading=FACE_NONE,
469 face=FACE_NONE, width=0, height=0, local=False, localPath='', localTime=-1): 430 face=FACE_NONE, width=0, height=0, local=False, localPath='', localTime=-1):
470 bmp = ImageHandler.load(path, 'miniature', id) 431 bmp = ImageHandler.load(path, 'miniature', id)
471 if bmp: 432 if bmp:
472 mini = BmpMiniature(id, path, bmp, pos, heading, face, label, 433 mini = BmpMiniature(id, path, bmp, pos, heading, face, label,
473 zorder=self. get_next_highest_z(), width=width, 434 zorder=self.get_next_highest_z(), width=width,
474 height=height, local=local, localPath=localPath, localTime=localTime) 435 height=height, local=local, localPath=localPath, localTime=localTime)
475 self.miniatures.append(mini) 436 self.miniatures.append(mini)
476 xml_str = "<map><miniatures>" 437 xml_str = "<map><miniatures>"
477 xml_str += mini.toxml("new") 438 xml_str += mini.toxml("new")
478 xml_str += "</miniatures></map>" 439 xml_str += "</miniatures></map>"
522 return min_list 483 return min_list
523 else: return None 484 else: return None
524 485
525 def layerToXML(self, action="update"): 486 def layerToXML(self, action="update"):
526 """ format """ 487 """ format """
527 minis_string = "" 488 mini_string = ""
528 if self.miniatures: 489 if self.miniatures:
529 for m in self.miniatures: minis_string += m.toxml(action) 490 for m in self.miniatures: mini_string = m.toxml(action)
530 if minis_string != '': 491 if mini_string != '':
531 s = "<miniatures" 492 s = Element('miniatures')
532 s += " serial='" + str(self.serial_number) + "'" 493 s.set('serial', str(self.serial_number))
533 s += ">" 494 s.append(mini_string)
534 s += minis_string 495 #s = "<miniatures"
535 s += "</miniatures>" 496 #s += " serial='" + str(self.serial_number) + "'"
536 return s 497 #s += ">"
498 #s += mini_string
499 #s += "</miniatures>"
500 #return s
501 return tostring(s)
537 else: return "" 502 else: return ""
538 503
539 def layerTakeDOM(self, xml_dom): 504 def layerTakeDOM(self, xml_dom):
540 if xml_dom.hasAttribute('serial'): 505 if xml_dom.hasAttribute('serial'):
541 self.serial_number = int(xml_dom.getAttribute('serial')) 506 self.serial_number = int(xml_dom.getAttribute('serial'))
560 if c.getAttribute('hide') == 'True' or c.getAttribute('hide') == '1': hide = True 525 if c.getAttribute('hide') == 'True' or c.getAttribute('hide') == '1': hide = True
561 if c.getAttribute('heading'): heading = int(c.getAttribute('heading')) 526 if c.getAttribute('heading'): heading = int(c.getAttribute('heading'))
562 if c.hasAttribute('face'): face = int(c.getAttribute('face')) 527 if c.hasAttribute('face'): face = int(c.getAttribute('face'))
563 if c.hasAttribute('align'): snap_to_align = int(c.getAttribute('align')) 528 if c.hasAttribute('align'): snap_to_align = int(c.getAttribute('align'))
564 if c.getAttribute('zorder'): zorder = int(c.getAttribute('zorder')) 529 if c.getAttribute('zorder'): zorder = int(c.getAttribute('zorder'))
565 min = BmpMiniature(id, path, ImageHandler.load(path, 'miniature', id), pos, heading, 530 image = ImageHandler.load(path, 'miniature', id)
566 face, label, locked, hide, snap_to_align, zorder, width, height) 531 mini = BmpMiniature(id, path, image, pos, heading, face, label, locked, hide, snap_to_align, zorder, width, height, func='minis')
567 self.miniatures.append(min) 532 self.miniatures.append(mini)
568 if c.hasAttribute('local') and c.getAttribute('local') == 'True' and os.path.exists(urllib.unquote(c.getAttribute('localPath'))): 533 if c.hasAttribute('local') and c.getAttribute('local') == 'True' and os.path.exists(urllib.unquote(c.getAttribute('localPath'))):
569 localPath = urllib.unquote(c.getAttribute('localPath')) 534 localPath = urllib.unquote(c.getAttribute('localPath'))
570 local = True 535 local = True
571 localTime = float(c.getAttribute('localTime')) 536 localTime = float(c.getAttribute('localTime'))
572 if localTime-time.time() <= 144000: 537 if localTime-time.time() <= 144000: