Mercurial > traipse
comparison orpg/mapper/map.py @ 18:97265586402b ornery-orc
Traipse 'OpenRPG' {090827-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:
Update Manager is now in version 0.8. While not every button works, users can now browse the different revisions and their different changesets. The code has been refined some with feature from Core added to it. A Crash report is now created if the users software crashes. Update Manager has been moved to the Traipse Suite menu item, and a Debug Console as been added as well.
author | sirebral |
---|---|
date | Thu, 27 Aug 2009 01:04:43 -0500 |
parents | 211ac836b6a0 |
children | ff154cf3350c |
comparison
equal
deleted
inserted
replaced
17:265b987cce4f | 18:97265586402b |
---|---|
29 | 29 |
30 from map_version import MAP_VERSION | 30 from map_version import MAP_VERSION |
31 from map_msg import * | 31 from map_msg import * |
32 from min_dialogs import * | 32 from min_dialogs import * |
33 from map_prop_dialog import * | 33 from map_prop_dialog import * |
34 import orpg.dirpath | 34 |
35 import random | 35 import random |
36 import os | 36 import os |
37 import thread | 37 import thread |
38 import gc | 38 #import gc #Garbage Collecter Needed? |
39 import traceback | 39 import traceback |
40 | |
40 from miniatures_handler import * | 41 from miniatures_handler import * |
41 from whiteboard_handler import * | 42 from whiteboard_handler import * |
42 from background_handler import * | 43 from background_handler import * |
43 from fog_handler import * | |
44 from images import ImageHandler | |
45 from grid_handler import * | 44 from grid_handler import * |
46 from map_handler import * | 45 from map_handler import * |
47 from orpg.orpgCore import open_rpg | 46 from fog_handler import * |
47 | |
48 from orpg.dirpath import dir_struct | |
49 from images import ImageHandler | |
50 from orpg.orpgCore import component | |
51 from orpg.tools.orpg_settings import settings | |
48 | 52 |
49 # Various marker modes for player tools on the map | 53 # Various marker modes for player tools on the map |
50 MARKER_MODE_NONE = 0 | 54 MARKER_MODE_NONE = 0 |
51 MARKER_MODE_MEASURE = 1 | 55 MARKER_MODE_MEASURE = 1 |
52 MARKER_MODE_TARGET = 2 | 56 MARKER_MODE_TARGET = 2 |
53 MARKER_MODE_AREA_TARGET = 3 | 57 MARKER_MODE_AREA_TARGET = 3 |
54 | 58 |
55 class MapCanvas(wx.ScrolledWindow): | 59 class MapCanvas(wx.ScrolledWindow): |
56 def __init__(self, parent, ID, isEditor=0): | 60 def __init__(self, parent, ID, isEditor=0): |
57 self.parent = parent | 61 self.parent = parent |
58 self.log = open_rpg.get_component("log") | 62 self.session = component.get("session") |
59 self.log.log("Enter MapCanvas", ORPG_DEBUG) | |
60 self.settings = open_rpg.get_component("settings") | |
61 self.session = open_rpg.get_component("session") | |
62 wx.ScrolledWindow.__init__(self, parent, ID, | 63 wx.ScrolledWindow.__init__(self, parent, ID, |
63 style=wx.HSCROLL | wx.VSCROLL | wx.FULL_REPAINT_ON_RESIZE | wx.SUNKEN_BORDER ) | 64 style=wx.HSCROLL | wx.VSCROLL | wx.FULL_REPAINT_ON_RESIZE | wx.SUNKEN_BORDER ) |
64 self.frame = parent | 65 self.frame = parent |
65 self.MAP_MODE = 1 #Mode 1 = MINI, 2 = DRAW, 3 = TAPE MEASURE | 66 self.MAP_MODE = 1 #Mode 1 = MINI, 2 = DRAW, 3 = TAPE MEASURE |
66 self.layers = {} | 67 self.layers = {} |
104 # Used to check if we've used the user cache size value | 105 # Used to check if we've used the user cache size value |
105 self.cacheSizeSet = False | 106 self.cacheSizeSet = False |
106 self.inside = 0 | 107 self.inside = 0 |
107 # miniatures drag | 108 # miniatures drag |
108 self.drag = None | 109 self.drag = None |
109 self.log.log("Exit MapCanvas", ORPG_DEBUG) | |
110 | 110 |
111 def better_refresh(self, event=None): | 111 def better_refresh(self, event=None): |
112 self.log.log("Enter MapCanvas->better_refresh(self)", ORPG_DEBUG) | |
113 self.Refresh(True) | 112 self.Refresh(True) |
114 self.log.log("Eexit MapCanvas->better_refresh(self)", ORPG_DEBUG) | |
115 | 113 |
116 def pre_destory_cleanup(self): | 114 def pre_destory_cleanup(self): |
117 self.log.log("Enter MapCanvas->pre_destory_cleanup(self)", ORPG_DEBUG) | |
118 self.layers["miniatures"].del_all_miniatures() | 115 self.layers["miniatures"].del_all_miniatures() |
119 self.log.log("Exit MapCanvas->pre_destory_cleanup(self)", ORPG_DEBUG) | |
120 | 116 |
121 def processImages(self, evt=None): | 117 def processImages(self, evt=None): |
122 self.log.log("Enter MapCanvas->processImages(self)", ORPG_DEBUG) | 118 self.session = component.get("session") |
123 self.session = open_rpg.get_component("session") | |
124 if self.session.my_role() == self.session.ROLE_LURKER or (str(self.session.group_id) == '0' and str(self.session.status) == '1'): | 119 if self.session.my_role() == self.session.ROLE_LURKER or (str(self.session.group_id) == '0' and str(self.session.status) == '1'): |
125 cidx = self.parent.get_tab_index("Background") | 120 cidx = self.parent.get_tab_index("Background") |
126 self.parent.layer_tabs.EnableTab(cidx, False) | 121 self.parent.layer_tabs.EnableTab(cidx, False) |
127 cidx = self.parent.get_tab_index("Grid") | 122 cidx = self.parent.get_tab_index("Grid") |
128 self.parent.layer_tabs.EnableTab(cidx, False) | 123 self.parent.layer_tabs.EnableTab(cidx, False) |
158 self.parent.layer_tabs.EnableTab(cidx, True) | 153 self.parent.layer_tabs.EnableTab(cidx, True) |
159 cidx = self.parent.get_tab_index("General") | 154 cidx = self.parent.get_tab_index("General") |
160 self.parent.layer_tabs.EnableTab(cidx, True) | 155 self.parent.layer_tabs.EnableTab(cidx, True) |
161 if not self.cacheSizeSet: | 156 if not self.cacheSizeSet: |
162 self.cacheSizeSet = True | 157 self.cacheSizeSet = True |
163 cacheSize = self.settings.get_setting("ImageCacheSize") | 158 cacheSize = component.get('settings').get_setting("ImageCacheSize") |
164 if len(cacheSize): self.cacheSize = int(cacheSize) | 159 if len(cacheSize): self.cacheSize = int(cacheSize) |
165 else: self.log.log("Default cache size being used.", ORPG_GENERAL) | 160 else: pass |
166 self.log.log("Current image cache size is set at " + str(self.cacheSize) + " images, using random purge.", | |
167 ORPG_GENERAL) | |
168 if not ImageHandler.Queue.empty(): | 161 if not ImageHandler.Queue.empty(): |
169 (path, image_type, imageId) = ImageHandler.Queue.get() | 162 (path, image_type, imageId) = ImageHandler.Queue.get() |
170 img = wx.ImageFromMime(path[1], path[2]).ConvertToBitmap() | 163 img = wx.ImageFromMime(path[1], path[2]).ConvertToBitmap() |
171 try: | 164 try: |
172 # Now, apply the image to the proper object | 165 # Now, apply the image to the proper object |
178 if image_type == "background": self.set_size([img.GetWidth(), img.GetHeight()]) | 171 if image_type == "background": self.set_size([img.GetWidth(), img.GetHeight()]) |
179 except: pass | 172 except: pass |
180 # Flag that we now need to refresh! | 173 # Flag that we now need to refresh! |
181 self.requireRefresh += 1 | 174 self.requireRefresh += 1 |
182 | 175 |
183 # Randomly purge an item from the cache, while this is lamo, it does | 176 """ Randomly purge an item from the cache, while this is lamo, it does |
184 # keep the cache from growing without bounds, which is pretty important! | 177 keep the cache from growing without bounds, which is pretty important!""" |
185 if len(ImageHandler.Cache) >= self.cacheSize: | 178 if len(ImageHandler.Cache) >= self.cacheSize: |
186 ImageHandler.cleanCache() | 179 ImageHandler.cleanCache() |
187 else: | 180 else: |
188 # Now, make sure not only that we require a refresh, but that enough time has | 181 """ Now, make sure not only that we require a refresh, but that enough time has |
189 # gone by since our last refresh. This keeps back to back refreshing occuring during | 182 gone by since our last refresh. This keeps back to back refreshing occuring during |
190 # large map loads. Of course, we are now trying to pack as many image refreshes as | 183 large map loads. Of course, we are now trying to pack as many image refreshes as |
191 # we can into a single cycle. | 184 we can into a single cycle.""" |
192 if self.requireRefresh and (self.requireRefresh == self.lastRefreshValue): | 185 if self.requireRefresh and (self.requireRefresh == self.lastRefreshValue): |
193 if (self.lastRefreshTime) < time.time(): | 186 if (self.lastRefreshTime) < time.time(): |
194 self.requireRefresh = 0 | 187 self.requireRefresh = 0 |
195 self.lastRefreshValue = 0 | 188 self.lastRefreshValue = 0 |
196 self.lastRefreshTime = time.time() | 189 self.lastRefreshTime = time.time() |
197 self.Refresh(True) | 190 self.Refresh(True) |
198 else: self.lastRefreshValue = self.requireRefresh | 191 else: self.lastRefreshValue = self.requireRefresh |
199 self.log.log("Exit MapCanvas->processImages(self)", ORPG_DEBUG) | |
200 | 192 |
201 def on_scroll(self, evt): | 193 def on_scroll(self, evt): |
202 self.log.log("Enter MapCanvas->on_scroll(self, evt)", ORPG_DEBUG) | |
203 if self.drag: self.drag.Hide() | 194 if self.drag: self.drag.Hide() |
204 if self.settings.get_setting("AlwaysShowMapScale") == "1": self.printscale() | 195 if component.get('settings').get_setting("AlwaysShowMapScale") == "1": self.printscale() |
205 evt.Skip() | 196 evt.Skip() |
206 self.log.log("Exit MapCanvas->on_scroll(self, evt)", ORPG_DEBUG) | |
207 | 197 |
208 def on_char(self, evt): | 198 def on_char(self, evt): |
209 self.log.log("Enter MapCanvas->on_char(self, evt)", ORPG_DEBUG) | 199 if component.get('settings').get_setting("AlwaysShowMapScale") == "1": self.printscale() |
210 if self.settings.get_setting("AlwaysShowMapScale") == "1": self.printscale() | |
211 evt.Skip() | 200 evt.Skip() |
212 self.log.log("Exit MapCanvas->on_char(self, evt)", ORPG_DEBUG) | |
213 | 201 |
214 def printscale(self): | 202 def printscale(self): |
215 self.log.log("Enter MapCanvas->printscale(self)", ORPG_DEBUG) | |
216 wx.BeginBusyCursor() | 203 wx.BeginBusyCursor() |
217 dc = wx.ClientDC(self) | 204 dc = wx.ClientDC(self) |
218 self.PrepareDC(dc) | 205 self.PrepareDC(dc) |
219 self.showmapscale(dc) | 206 self.showmapscale(dc) |
220 self.Refresh(True) | 207 self.Refresh(True) |
221 wx.EndBusyCursor() | 208 wx.EndBusyCursor() |
222 self.log.log("Exit MapCanvas->printscale(self)", ORPG_DEBUG) | |
223 | 209 |
224 def send_map_data(self, action="update"): | 210 def send_map_data(self, action="update"): |
225 self.log.log("Enter MapCanvas->send_map_data(self, " + action +")", ORPG_DEBUG) | |
226 wx.BeginBusyCursor() | 211 wx.BeginBusyCursor() |
227 send_text = self.toxml(action) | 212 send_text = self.toxml(action) |
228 if send_text: | 213 if send_text: |
229 if not self.isEditor: self.frame.session.send(send_text) | 214 if not self.isEditor: self.frame.session.send(send_text) |
230 wx.EndBusyCursor() | 215 wx.EndBusyCursor() |
231 self.log.log("Exit MapCanvas->send_map_data(self, " + action +")", ORPG_DEBUG) | |
232 | 216 |
233 def get_size(self): | 217 def get_size(self): |
234 self.log.log("Enter MapCanvas->get_size(self)", ORPG_DEBUG) | |
235 self.log.log("Exit MapCanvas->get_size(self) return " + str(self.size), ORPG_DEBUG) | |
236 return self.size | 218 return self.size |
237 | 219 |
238 def set_size(self, size): | 220 def set_size(self, size): |
239 self.log.log("Enter MapCanvas->set_size(self, size)", ORPG_DEBUG) | |
240 if size[0] < 300: size = (300, size[1]) | 221 if size[0] < 300: size = (300, size[1]) |
241 if size[1] < 300: size = (size[0], 300) | 222 if size[1] < 300: size = (size[0], 300) |
242 self.size_changed = 1 | 223 self.size_changed = 1 |
243 self.size = size | 224 self.size = size |
244 self.fix_scroll() | 225 self.fix_scroll() |
245 self.layers['fog'].resize(size) | 226 self.layers['fog'].resize(size) |
246 self.log.log("Exit MapCanvas->set_size(self, size)", ORPG_DEBUG) | |
247 | 227 |
248 def fix_scroll(self): | 228 def fix_scroll(self): |
249 self.log.log("Enter MapCanvas->fix_scroll(self)", ORPG_DEBUG) | |
250 scale = self.layers['grid'].mapscale | 229 scale = self.layers['grid'].mapscale |
251 pos = self.GetViewStart() | 230 pos = self.GetViewStart() |
252 unit = self.GetScrollPixelsPerUnit() | 231 unit = self.GetScrollPixelsPerUnit() |
253 pos = [pos[0]*unit[0],pos[1]*unit[1]] | 232 pos = [pos[0]*unit[0],pos[1]*unit[1]] |
254 size = self.GetClientSize() | 233 size = self.GetClientSize() |
255 unit = [10*scale,10*scale] | 234 unit = [10*scale,10*scale] |
256 if (unit[0] == 0 or unit[1] == 0): | 235 if (unit[0] == 0 or unit[1] == 0): return |
257 self.log.log("Exit MapCanvas->fix_scroll(self)", ORPG_DEBUG) | |
258 return | |
259 pos[0] /= unit[0] | 236 pos[0] /= unit[0] |
260 pos[1] /= unit[1] | 237 pos[1] /= unit[1] |
261 mx = [int(self.size[0]*scale/unit[0])+1, int(self.size[1]*scale/unit[1]+1)] | 238 mx = [int(self.size[0]*scale/unit[0])+1, int(self.size[1]*scale/unit[1]+1)] |
262 self.SetScrollbars(unit[0], unit[1], mx[0], mx[1], pos[0], pos[1]) | 239 self.SetScrollbars(unit[0], unit[1], mx[0], mx[1], pos[0], pos[1]) |
263 self.log.log("Exit MapCanvas->fix_scroll(self)", ORPG_DEBUG) | |
264 | 240 |
265 def on_resize(self, evt): | 241 def on_resize(self, evt): |
266 self.log.log("Enter MapCanvas->on_resize(self, evt)", ORPG_DEBUG) | |
267 self.fix_scroll() | 242 self.fix_scroll() |
268 wx.CallAfter(self.Refresh, True) | 243 wx.CallAfter(self.Refresh, True) |
269 evt.Skip() | 244 evt.Skip() |
270 self.log.log("Exit MapCanvas->on_resize(self, evt)", ORPG_DEBUG) | |
271 | 245 |
272 def on_erase_background(self, evt): | 246 def on_erase_background(self, evt): |
273 self.log.log("Enter MapCanvas->on_erase_background(self, evt)", ORPG_DEBUG) | |
274 evt.Skip() | 247 evt.Skip() |
275 self.log.log("Exit MapCanvas->on_erase_background(self, evt)", ORPG_DEBUG) | |
276 | 248 |
277 def on_paint(self, evt): | 249 def on_paint(self, evt): |
278 self.log.log("Enter MapCanvas->on_paint(self, evt)", ORPG_DEBUG) | |
279 scale = self.layers['grid'].mapscale | 250 scale = self.layers['grid'].mapscale |
280 scrollsize = self.GetScrollPixelsPerUnit() | 251 scrollsize = self.GetScrollPixelsPerUnit() |
281 clientsize = self.GetClientSize() | 252 clientsize = self.GetClientSize() |
282 topleft1 = self.GetViewStart() | 253 topleft1 = self.GetViewStart() |
283 topleft = [topleft1[0]*scrollsize[0], topleft1[1]*scrollsize[1]] | 254 topleft = [topleft1[0]*scrollsize[0], topleft1[1]*scrollsize[1]] |
301 dc.SetBrush(wx.NullBrush) | 272 dc.SetBrush(wx.NullBrush) |
302 dc.SelectObject(wx.NullBitmap) | 273 dc.SelectObject(wx.NullBitmap) |
303 del dc | 274 del dc |
304 wdc = self.preppaint() | 275 wdc = self.preppaint() |
305 wdc.DrawBitmap(bmp, topleft[0], topleft[1]) | 276 wdc.DrawBitmap(bmp, topleft[0], topleft[1]) |
306 if self.frame.settings.get_setting("AlwaysShowMapScale") == "1": | 277 if settings.get_setting("AlwaysShowMapScale") == "1": |
307 self.showmapscale(wdc) | 278 self.showmapscale(wdc) |
308 try: evt.Skip() | 279 try: evt.Skip() |
309 except: pass | 280 except: pass |
310 self.log.log("Exit MapCanvas->on_paint(self, evt)", ORPG_DEBUG) | |
311 | 281 |
312 def preppaint(self): | 282 def preppaint(self): |
313 self.log.log("Enter MapCanvas->preppaint(self)", ORPG_DEBUG) | |
314 dc = wx.PaintDC(self) | 283 dc = wx.PaintDC(self) |
315 self.PrepareDC(dc) | 284 self.PrepareDC(dc) |
316 self.log.log("Exit MapCanvas->preppaint(self)", ORPG_DEBUG) | |
317 return (dc) | 285 return (dc) |
318 | 286 |
319 def showmapscale(self, dc): | 287 def showmapscale(self, dc): |
320 self.log.log("Enter MapCanvas->showmapscale(self, dc)", ORPG_DEBUG) | |
321 scalestring = "Scale x" + `self.layers['grid'].mapscale`[:3] | 288 scalestring = "Scale x" + `self.layers['grid'].mapscale`[:3] |
322 (textWidth, textHeight) = dc.GetTextExtent(scalestring) | 289 (textWidth, textHeight) = dc.GetTextExtent(scalestring) |
323 dc.SetUserScale(1, 1) | 290 dc.SetUserScale(1, 1) |
324 dc.SetPen(wx.LIGHT_GREY_PEN) | 291 dc.SetPen(wx.LIGHT_GREY_PEN) |
325 dc.SetBrush(wx.LIGHT_GREY_BRUSH) | 292 dc.SetBrush(wx.LIGHT_GREY_BRUSH) |
328 dc.DrawRectangle(x, y, textWidth+2, textHeight+2) | 295 dc.DrawRectangle(x, y, textWidth+2, textHeight+2) |
329 dc.SetPen(wx.RED_PEN) | 296 dc.SetPen(wx.RED_PEN) |
330 dc.DrawText(scalestring, x+1, y+1) | 297 dc.DrawText(scalestring, x+1, y+1) |
331 dc.SetPen(wx.NullPen) | 298 dc.SetPen(wx.NullPen) |
332 dc.SetBrush(wx.NullBrush) | 299 dc.SetBrush(wx.NullBrush) |
333 self.log.log("Exit MapCanvas->showmapscale(self, dc)", ORPG_DEBUG) | |
334 | 300 |
335 def snapMarker(self, snapPoint): | 301 def snapMarker(self, snapPoint): |
336 """Based on the position and unit size, figure out where we need to snap to. As is, on | 302 """Based on the position and unit size, figure out where we need to snap to. As is, on |
337 a square grid, there are four possible places to snap. On a hex gid, there are 6 or 12 snap | 303 a square grid, there are four possible places to snap. On a hex gid, there are 6 or 12 snap |
338 points.""" | 304 points.""" |
339 self.log.log("Enter MapCanvas->snapMarker(self, snapPoint)", ORPG_DEBUG) | |
340 | 305 |
341 # If snap to grid is disabled, simply return snapPoint unmodified | 306 # If snap to grid is disabled, simply return snapPoint unmodified |
342 if self.layers['grid'].snap: | 307 if self.layers['grid'].snap: |
343 # This means we need to determine where to snap our line. We will support | 308 # This means we need to determine where to snap our line. We will support |
344 # snapping to four different snapPoints per square for now. | 309 # snapping to four different snapPoints per square for now. |
360 # Now, figure out the Y snap placement | 325 # Now, figure out the Y snap placement |
361 if deltaY <= snapSize: quadYPos = offsetY | 326 if deltaY <= snapSize: quadYPos = offsetY |
362 else: quadYPos = offsetY + size | 327 else: quadYPos = offsetY + size |
363 # Create our snap snapPoint and return it | 328 # Create our snap snapPoint and return it |
364 snapPoint = wx.Point( quadXPos, quadYPos ) | 329 snapPoint = wx.Point( quadXPos, quadYPos ) |
365 self.log.log("Exit MapCanvas->snapMarker(self, snapPoint)", ORPG_DEBUG) | |
366 return snapPoint | 330 return snapPoint |
367 | 331 |
368 # Bunch of math stuff for marking and measuring | 332 # Bunch of math stuff for marking and measuring |
369 def calcSlope(self, start, stop): | 333 def calcSlope(self, start, stop): |
370 """Calculates the slop of a line and returns it.""" | 334 """Calculates the slop of a line and returns it.""" |
371 self.log.log("Enter MapCanvas->calcSlope(self, start, stop)", ORPG_DEBUG) | |
372 if start.x == stop.x: s = 0.0001 | 335 if start.x == stop.x: s = 0.0001 |
373 else: s = float((stop.y - start.y)) / float((stop.x - start.x)) | 336 else: s = float((stop.y - start.y)) / float((stop.x - start.x)) |
374 self.log.log("Exit MapCanvas->calcSlope(self, start, stop)", ORPG_DEBUG) | |
375 return s | 337 return s |
376 | 338 |
377 def calcSlopeToAngle(self, slope): | 339 def calcSlopeToAngle(self, slope): |
378 """Based on the input slope, the angle (in degrees) will be returned.""" | 340 """Based on the input slope, the angle (in degrees) will be returned.""" |
379 self.log.log("Enter MapCanvas->calcSlopeToAngle(self, slope)", ORPG_DEBUG) | |
380 # See if the slope is neg or positive | 341 # See if the slope is neg or positive |
381 if slope == abs(slope): | 342 if slope == abs(slope): |
382 # Slope is positive, so make sure it's not zero | 343 # Slope is positive, so make sure it's not zero |
383 if slope == 0: a = 0 | 344 if slope == 0: a = 0 |
384 else: a = 360 - atan(slope) * (180.0/pi) | 345 else: a = 360 - atan(slope) * (180.0/pi) |
385 else: a = atan(abs(slope)) * (180.0/pi) | 346 else: a = atan(abs(slope)) * (180.0/pi) |
386 self.log.log("Exit MapCanvas->calcSlopeToAngle(self, slope)", ORPG_DEBUG) | |
387 return a | 347 return a |
388 | 348 |
389 def calcLineAngle(self, start, stop): | 349 def calcLineAngle(self, start, stop): |
390 """Based on two points that are on a line, return the angle of that line.""" | 350 """Based on two points that are on a line, return the angle of that line.""" |
391 self.log.log("Enter MapCanvas->calcLineAngle(self, start, stop)", ORPG_DEBUG) | |
392 a = self.calcSlopeToAngle( self.calcSlope( start, stop ) ) | 351 a = self.calcSlopeToAngle( self.calcSlope( start, stop ) ) |
393 self.log.log("Exit MapCanvas->calcLineAngle(self, start, stop)", ORPG_DEBUG) | |
394 return a | 352 return a |
395 | 353 |
396 def calcPixelDistance(self, start, stop): | 354 def calcPixelDistance(self, start, stop): |
397 """Calculate the distance between two pixels and returns it. The calculated | 355 """Calculate the distance between two pixels and returns it. The calculated |
398 distance is the Euclidean Distance, which is: | 356 distance is the Euclidean Distance, which is: |
399 d = sqrt( (x2 - x1)**2 + (y2 - y1)**2 )""" | 357 d = sqrt( (x2 - x1)**2 + (y2 - y1)**2 )""" |
400 self.log.log("Enter MapCanvas->calcPixelDistance(self, start, stop)", ORPG_DEBUG) | |
401 d = sqrt( abs((stop.x - start.x)**2 - (stop.y - start.y)**2) ) | 358 d = sqrt( abs((stop.x - start.x)**2 - (stop.y - start.y)**2) ) |
402 self.log.log("Exit MapCanvas->calcPixelDistance(self, start, stop)", ORPG_DEBUG) | |
403 return d | 359 return d |
404 | 360 |
405 def calcUnitDistance(self, start, stop, lineAngle): | 361 def calcUnitDistance(self, start, stop, lineAngle): |
406 self.log.log("Enter MapCanvas->calcUnitDistance(self, start, stop, lineAngle)", ORPG_DEBUG) | |
407 distance = self.calcPixelDistance( start, stop ) | 362 distance = self.calcPixelDistance( start, stop ) |
408 ln = "%0.2f" % lineAngle | 363 ln = "%0.2f" % lineAngle |
409 if self.layers['grid'].mode == GRID_HEXAGON: | 364 if self.layers['grid'].mode == GRID_HEXAGON: |
410 if ln == "0.00" or ln == "359.99": ud = distance / self.layers['grid'].unit_size_y | 365 if ln == "0.00" or ln == "359.99": 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 | 366 else: ud = (sqrt(abs((stop.x - start.x)**2 + (stop.y - start.y)**2))) / self.layers['grid'].unit_size_y |
412 else: | 367 else: |
413 if ln == "0.00" or ln == "359.99": ud = distance / self.layers['grid'].unit_size | 368 if ln == "0.00" or ln == "359.99": 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 | 369 else: ud = (sqrt(abs((stop.x - start.x)**2 + (stop.y - start.y)**2))) / self.layers['grid'].unit_size |
415 #ud = sqrt( abs((stop.x - start.x)**2 - (stop.y - start.y)**2) ) | 370 #ud = sqrt( abs((stop.x - start.x)**2 - (stop.y - start.y)**2) ) |
416 self.log.log("Exit MapCanvas->calcUnitDistance(self, start, stop, lineAngle)", ORPG_DEBUG) | |
417 return ud | 371 return ud |
418 | 372 |
419 def on_tape_motion(self, evt): | 373 def on_tape_motion(self, evt): |
420 """Track mouse motion so we can update the marker visual every time it's moved""" | 374 """Track mouse motion so we can update the marker visual every time it's moved""" |
421 self.log.log("Enter MapCanvas->on_tape_motion(self, evt)", ORPG_DEBUG) | |
422 # Make sure we have a mode to do anything, otherwise, we ignore this | 375 # Make sure we have a mode to do anything, otherwise, we ignore this |
423 if self.markerMode: | 376 if self.markerMode: |
424 # Grap the current DC for all of the marker modes | 377 # Grap the current DC for all of the marker modes |
425 dc = wx.ClientDC( self ) | 378 dc = wx.ClientDC( self ) |
426 self.PrepareDC( dc ) | 379 self.PrepareDC( dc ) |
427 dc.SetUserScale(self.layers['grid'].mapscale,self.layers['grid'].mapscale) | 380 dc.SetUserScale(self.layers['grid'].mapscale,self.layers['grid'].mapscale) |
428 # Grab the current map position | 381 # Grab the current map position |
429 pos = self.snapMarker( evt.GetLogicalPosition( dc ) ) | 382 pos = self.snapMarker( evt.GetLogicalPosition( dc ) ) |
430 # Enable brush optimizations | 383 # Enable brush optimizations |
431 #dc.SetOptimization( True ) | 384 # dc.SetOptimization( True ) |
432 # Set up the pen used for drawing our marker | 385 # Set up the pen used for drawing our marker |
433 dc.SetPen( wx.Pen(wx.RED, 1, wx.LONG_DASH) ) | 386 dc.SetPen( wx.Pen(wx.RED, 1, wx.LONG_DASH) ) |
434 # Now, based on the marker mode, draw the right thing | 387 # Now, based on the marker mode, draw the right thing |
435 if self.markerMode == MARKER_MODE_MEASURE: | 388 if self.markerMode == MARKER_MODE_MEASURE: |
436 if self.markerStop.x != -1 and self.markerStop.y != -1: | 389 if self.markerStop.x != -1 and self.markerStop.y != -1: |
447 self.markerStop = pos | 400 self.markerStop = pos |
448 dc.SetPen(wx.NullPen) | 401 dc.SetPen(wx.NullPen) |
449 # Disable brush optimizations | 402 # Disable brush optimizations |
450 #dc.SetOptimization( False ) | 403 #dc.SetOptimization( False ) |
451 del dc | 404 del dc |
452 self.log.log("Exit MapCanvas->on_tape_motion(self, evt)", ORPG_DEBUG) | |
453 | 405 |
454 def on_tape_down(self, evt): | 406 def on_tape_down(self, evt): |
455 """Greg's experimental tape measure code. Hopefully, when this is done, it will all be | 407 """Greg's experimental tape measure code. Hopefully, when this is done, it will all be |
456 modal based on a toolbar.""" | 408 modal based on a toolbar.""" |
457 self.log.log("Enter MapCanvas->on_tape_down(self, evt)", ORPG_DEBUG) | |
458 dc = wx.ClientDC( self ) | 409 dc = wx.ClientDC( self ) |
459 self.PrepareDC( dc ) | 410 self.PrepareDC( dc ) |
460 dc.SetUserScale(self.layers['grid'].mapscale,self.layers['grid'].mapscale) | 411 dc.SetUserScale(self.layers['grid'].mapscale,self.layers['grid'].mapscale) |
461 pos = evt.GetLogicalPosition( dc ) | 412 pos = evt.GetLogicalPosition( dc ) |
462 # If grid snap is enabled, then snap the tool to a proper position | 413 # If grid snap is enabled, then snap the tool to a proper position |
482 #dc.SetOptimization( False ) | 433 #dc.SetOptimization( False ) |
483 # Save our current start and reset the stop value | 434 # Save our current start and reset the stop value |
484 self.markerStart = pos | 435 self.markerStart = pos |
485 self.markerStop = pos | 436 self.markerStop = pos |
486 del dc | 437 del dc |
487 self.log.log("Exit MapCanvas->on_tape_down(self, evt)", ORPG_DEBUG) | |
488 | 438 |
489 def on_tape_up(self, evt): | 439 def on_tape_up(self, evt): |
490 """When we release the middle button, disable any marking updates that we have been doing.""" | 440 """When we release the middle button, disable any marking updates that we have been doing.""" |
491 self.log.log("Enter MapCanvas->on_tape_up(self, evt)", ORPG_DEBUG) | |
492 # If we are in measure mode, draw the actual UNIT distance | 441 # If we are in measure mode, draw the actual UNIT distance |
493 if self.markerMode == MARKER_MODE_MEASURE: | 442 if self.markerMode == MARKER_MODE_MEASURE: |
494 dc = wx.ClientDC( self ) | 443 dc = wx.ClientDC( self ) |
495 self.PrepareDC( dc ) | 444 self.PrepareDC( dc ) |
496 dc.SetUserScale(self.layers['grid'].mapscale,self.layers['grid'].mapscale) | 445 dc.SetUserScale(self.layers['grid'].mapscale,self.layers['grid'].mapscale) |
519 dc.SetFont(wx.NullFont) | 468 dc.SetFont(wx.NullFont) |
520 dc.SetLogicalFunction(wx.COPY) | 469 dc.SetLogicalFunction(wx.COPY) |
521 del font | 470 del font |
522 del dc | 471 del dc |
523 self.markerMode = MARKER_MODE_NONE | 472 self.markerMode = MARKER_MODE_NONE |
524 self.log.log("Exit MapCanvas->on_tape_up(self, evt)", ORPG_DEBUG) | |
525 | 473 |
526 # MODE 1 = MOVE, MODE 2 = whiteboard, MODE 3 = Tape measure | 474 # MODE 1 = MOVE, MODE 2 = whiteboard, MODE 3 = Tape measure |
527 def on_left_down(self, evt): | 475 def on_left_down(self, evt): |
528 self.log.log("Enter MapCanvas->on_left_down(self, evt)", ORPG_DEBUG) | |
529 if evt.ShiftDown(): self.on_tape_down (evt) | 476 if evt.ShiftDown(): self.on_tape_down (evt) |
530 else: self.frame.on_left_down(evt) | 477 else: self.frame.on_left_down(evt) |
531 self.log.log("Exit MapCanvas->on_left_down(self, evt)", ORPG_DEBUG) | |
532 | 478 |
533 def on_right_down(self, evt): | 479 def on_right_down(self, evt): |
534 self.log.log("Enter MapCanvas->on_right_down(self, evt)", ORPG_DEBUG) | |
535 if evt.ShiftDown(): pass | 480 if evt.ShiftDown(): pass |
536 else: self.frame.on_right_down(evt) | 481 else: self.frame.on_right_down(evt) |
537 self.log.log("Exit MapCanvas->on_right_down(self, evt)", ORPG_DEBUG) | |
538 | 482 |
539 def on_left_dclick(self, evt): | 483 def on_left_dclick(self, evt): |
540 self.log.log("Enter MapCanvas->on_left_dclick(self, evt)", ORPG_DEBUG) | |
541 if evt.ShiftDown(): pass | 484 if evt.ShiftDown(): pass |
542 else: self.frame.on_left_dclick(evt) | 485 else: self.frame.on_left_dclick(evt) |
543 self.log.log("Exit MapCanvas->on_left_dclick(self, evt)", ORPG_DEBUG) | |
544 | 486 |
545 def on_left_up(self, evt): | 487 def on_left_up(self, evt): |
546 self.log.log("Enter MapCanvas->on_left_up(self, evt)", ORPG_DEBUG) | |
547 if evt.ShiftDown(): self.on_tape_up(evt) | 488 if evt.ShiftDown(): self.on_tape_up(evt) |
548 elif open_rpg.get_component("tree").dragging: | 489 elif component.get("tree").dragging: |
549 tree = open_rpg.get_component("tree") | 490 tree = component.get("tree") |
550 if tree.drag_obj.map_aware(): | 491 if tree.drag_obj.map_aware(): |
551 tree.drag_obj.on_send_to_map(evt) | 492 tree.drag_obj.on_send_to_map(evt) |
552 tree.dragging = False | 493 tree.dragging = False |
553 tree.drag_obj = None | 494 tree.drag_obj = None |
554 else: self.frame.on_left_up(evt) | 495 else: self.frame.on_left_up(evt) |
555 self.log.log("Exit MapCanvas->on_left_up(self, evt)", ORPG_DEBUG) | |
556 | 496 |
557 def on_motion(self, evt): | 497 def on_motion(self, evt): |
558 self.log.log("Enter MapCanvas->on_motion(self, evt)", ORPG_DEBUG) | |
559 if evt.ShiftDown(): self.on_tape_motion(evt) | 498 if evt.ShiftDown(): self.on_tape_motion(evt) |
560 elif evt.LeftIsDown() and open_rpg.get_component("tree").dragging: pass | 499 elif evt.LeftIsDown() and component.get("tree").dragging: pass |
561 else: self.frame.on_motion(evt) | 500 else: self.frame.on_motion(evt) |
562 self.log.log("Exit MapCanvas->on_motion(self, evt)", ORPG_DEBUG) | |
563 | 501 |
564 def on_zoom_out(self, evt): | 502 def on_zoom_out(self, evt): |
565 self.log.log("Enter MapCanvas->on_zoom_out(self, evt)", ORPG_DEBUG) | |
566 if self.layers['grid'].mapscale > 0.2: | 503 if self.layers['grid'].mapscale > 0.2: |
567 # attempt to keep same logical point at center of screen | 504 # attempt to keep same logical point at center of screen |
568 scale = self.layers['grid'].mapscale | 505 scale = self.layers['grid'].mapscale |
569 scrollsize = self.GetScrollPixelsPerUnit() | 506 scrollsize = self.GetScrollPixelsPerUnit() |
570 clientsize = self.GetClientSize() | 507 clientsize = self.GetClientSize() |
590 dc.SetPen(wx.NullPen) | 527 dc.SetPen(wx.NullPen) |
591 dc.SetBrush(wx.NullBrush) | 528 dc.SetBrush(wx.NullBrush) |
592 dc.EndDrawing() | 529 dc.EndDrawing() |
593 del dc | 530 del dc |
594 self.zoom_display_timer.Start(500,1) | 531 self.zoom_display_timer.Start(500,1) |
595 self.log.log("Exit MapCanvas->on_zoom_out(self, evt)", ORPG_DEBUG) | |
596 | 532 |
597 def on_zoom_in(self, evt): | 533 def on_zoom_in(self, evt): |
598 self.log.log("Enter MapCanvas->on_zoom_in(self, evt)", ORPG_DEBUG) | |
599 # attempt to keep same logical point at center of screen | 534 # attempt to keep same logical point at center of screen |
600 scale = self.layers['grid'].mapscale | 535 scale = self.layers['grid'].mapscale |
601 scrollsize = self.GetScrollPixelsPerUnit() | 536 scrollsize = self.GetScrollPixelsPerUnit() |
602 clientsize = self.GetClientSize() | 537 clientsize = self.GetClientSize() |
603 topleft1 = self.GetViewStart() | 538 topleft1 = self.GetViewStart() |
622 dc.SetPen(wx.NullPen) | 557 dc.SetPen(wx.NullPen) |
623 dc.SetBrush(wx.NullBrush) | 558 dc.SetBrush(wx.NullBrush) |
624 dc.EndDrawing() | 559 dc.EndDrawing() |
625 del dc | 560 del dc |
626 self.zoom_display_timer.Start(500, 1) | 561 self.zoom_display_timer.Start(500, 1) |
627 self.log.log("Exit MapCanvas->on_zoom_in(self, evt)", ORPG_DEBUG) | |
628 | 562 |
629 def on_prop(self, evt): | 563 def on_prop(self, evt): |
630 self.log.log("Enter MapCanvas->on_prop(self, evt)", ORPG_DEBUG) | 564 self.session = component.get("session") |
631 self.session = open_rpg.get_component("session") | 565 self.chat = component.get("chat") |
632 self.chat = open_rpg.get_component("chat") | |
633 if (self.session.my_role() != self.session.ROLE_GM): | 566 if (self.session.my_role() != self.session.ROLE_GM): |
634 self.chat.InfoPost("You must be a GM to use this feature") | 567 self.chat.InfoPost("You must be a GM to use this feature") |
635 self.log.log("Exit MapCanvas->on_prop(self, evt)", ORPG_DEBUG) | |
636 return | 568 return |
637 dlg = general_map_prop_dialog(self.frame.GetParent(),self.size,self.layers['bg'],self.layers['grid']) | 569 dlg = general_map_prop_dialog(self.frame.GetParent(),self.size,self.layers['bg'],self.layers['grid']) |
638 if dlg.ShowModal() == wx.ID_OK: | 570 if dlg.ShowModal() == wx.ID_OK: |
639 self.set_size(dlg.size) | 571 self.set_size(dlg.size) |
640 self.send_map_data() | 572 self.send_map_data() |
641 self.Refresh(False) | 573 self.Refresh(False) |
642 dlg.Destroy() | 574 dlg.Destroy() |
643 os.chdir(self.root_dir) | 575 os.chdir(self.root_dir) |
644 self.log.log("Exit MapCanvas->on_prop(self, evt)", ORPG_DEBUG) | |
645 | 576 |
646 def add_miniature(self, min_url, min_label='', min_unique=-1): | 577 def add_miniature(self, min_url, min_label='', min_unique=-1): |
647 self.log.log("Enter MapCanvas->add_miniature(self, min_url, min_label, min_unique)", ORPG_DEBUG) | |
648 if min_unique == -1: min_unique = not self.use_serial | 578 if min_unique == -1: min_unique = not self.use_serial |
649 if min_url == "" or min_url == "http://": return | 579 if min_url == "" or min_url == "http://": return |
650 if min_url[:7] != "http://" : min_url = "http://" + min_url | 580 if min_url[:7] != "http://" : min_url = "http://" + min_url |
651 # make label | 581 # make label |
652 wx.BeginBusyCursor() | 582 wx.BeginBusyCursor() |
657 else: min_label = "" | 587 else: min_label = "" |
658 if self.frame.min_url.FindString(min_url) == -1: self.frame.min_url.Append(min_url) | 588 if self.frame.min_url.FindString(min_url) == -1: self.frame.min_url.Append(min_url) |
659 try: | 589 try: |
660 id = 'mini-' + self.frame.session.get_next_id() | 590 id = 'mini-' + self.frame.session.get_next_id() |
661 self.layers['miniatures'].add_miniature(id, min_url, label=min_label) | 591 self.layers['miniatures'].add_miniature(id, min_url, label=min_label) |
662 except Exception, e: | 592 except: |
663 self.log.log(traceback.format_exc(), ORPG_GENERAL) | |
664 self.log.log("Unable to load/resolve URL: " + min_url + " on resource ' + min_label + ' !!!", ORPG_GENERAL) | |
665 self.layers['miniatures'].rollback_serial() | 593 self.layers['miniatures'].rollback_serial() |
666 wx.EndBusyCursor() | 594 wx.EndBusyCursor() |
667 self.send_map_data() | 595 self.send_map_data() |
668 self.Refresh(False) | 596 self.Refresh(False) |
669 self.log.log("Exit MapCanvas->add_miniature(self, min_url, min_label, min_unique)", ORPG_DEBUG) | |
670 | 597 |
671 def get_label_from_url(self, url=''): | 598 def get_label_from_url(self, url=''): |
672 self.log.log("Enter MapCanvas->get_label_from_url(self, url)", ORPG_DEBUG) | 599 if url == '': return '' |
673 if url == '': | |
674 self.log.log("Exit MapCanvas->get_label_from_url(self, url)", ORPG_DEBUG) | |
675 return '' | |
676 start = url.rfind("/")+1 | 600 start = url.rfind("/")+1 |
677 label = url[start:len(url)-4] | 601 label = url[start:len(url)-4] |
678 self.log.log("Exit MapCanvas->get_label_from_url(self, url)", ORPG_DEBUG) | |
679 return label | 602 return label |
680 | 603 |
681 def toxml(self, action="update"): | 604 def toxml(self, action="update"): |
682 self.log.log("Enter MapCanvas->toxml(self, " + action + ")", ORPG_DEBUG) | |
683 if action == "new": | 605 if action == "new": |
684 self.size_changed = 1 | 606 self.size_changed = 1 |
685 xml_str = "<map version='" + self.map_version + "'" | 607 xml_str = "<map version='" + self.map_version + "'" |
686 changed = self.size_changed | 608 changed = self.size_changed |
687 if self.size_changed: | 609 if self.size_changed: |
690 s = "" | 612 s = "" |
691 keys = self.layers.keys() | 613 keys = self.layers.keys() |
692 for k in keys: | 614 for k in keys: |
693 if (k != "fog" or action != "update"): s += self.layers[k].layerToXML(action) | 615 if (k != "fog" or action != "update"): s += self.layers[k].layerToXML(action) |
694 self.size_changed = 0 | 616 self.size_changed = 0 |
695 if s: | 617 if s: return xml_str + " action='" + action + "'>" + s + "</map>" |
696 self.log.log("Exit MapCanvas->toxml(self, " + action + ")", ORPG_DEBUG) | |
697 return xml_str + " action='" + action + "'>" + s + "</map>" | |
698 else: | 618 else: |
699 if changed: | 619 if changed: return xml_str + " action='" + action + "'/>" |
700 self.log.log("Exit MapCanvas->toxml(self, " + action + ")", ORPG_DEBUG) | 620 else: return "" |
701 return xml_str + " action='" + action + "'/>" | |
702 else: | |
703 self.log.log("Exit MapCanvas->toxml(self, " + action + ")", ORPG_DEBUG) | |
704 return "" | |
705 | 621 |
706 def takexml(self, xml): | 622 def takexml(self, xml): |
707 # | 623 """ |
708 # Added Process Dialog to display during long map parsings | 624 Added Process Dialog to display during long map parsings |
709 # as well as a try block with an exception traceback to try | 625 as well as a try block with an exception traceback to try |
710 # and isolate some of the map related problems users have been | 626 and isolate some of the map related problems users have been |
711 # experiencing --Snowdog 5/15/03 | 627 experiencing --Snowdog 5/15/03 |
712 # | 628 |
713 # Apparently Process Dialog causes problems with linux.. commenting it out. sheez. | 629 Apparently Process Dialog causes problems with linux.. commenting it out. sheez. |
714 # --Snowdog 5/27/03 | 630 --Snowdog 5/27/03 |
715 self.log.log("Enter MapCanvas->takexml(self, xml)", ORPG_DEBUG) | 631 """ |
716 try: | 632 try: |
717 #parse the map DOM | 633 #parse the map DOM |
718 xml_dom = parseXml(xml) | 634 xml_dom = parseXml(xml) |
719 if xml_dom == None: | 635 if xml_dom == None: return |
720 self.log.log("xml_dom == None\n" + xml, ORPG_INFO) | |
721 self.log.log("Exit MapCanvas->takexml(self, xml)", ORPG_DEBUG) | |
722 return | |
723 node_list = xml_dom.getElementsByTagName("map") | 636 node_list = xml_dom.getElementsByTagName("map") |
724 if len(node_list) < 1: self.log.log("Invalid XML format for mapper", ORPG_INFO) | 637 if len(node_list) < 1: pass |
725 else: | 638 else: |
726 # set map version to incoming data so layers can convert | 639 # set map version to incoming data so layers can convert |
727 self.map_version = node_list[0].getAttribute("version") | 640 self.map_version = node_list[0].getAttribute("version") |
728 action = node_list[0].getAttribute("action") | 641 action = node_list[0].getAttribute("action") |
729 if action == "new": | 642 if action == "new": |
760 if name != "fog": self.layers[name].layerTakeDOM(c) | 673 if name != "fog": self.layers[name].layerTakeDOM(c) |
761 # all map data should be converted, set map version to current version | 674 # all map data should be converted, set map version to current version |
762 self.map_version = MAP_VERSION | 675 self.map_version = MAP_VERSION |
763 self.Refresh(False) | 676 self.Refresh(False) |
764 xml_dom.unlink() # eliminate circular refs | 677 xml_dom.unlink() # eliminate circular refs |
765 except: | 678 except: pass |
766 self.log.log(traceback.format_exc(), ORPG_GENERAL) | |
767 self.log.log("EXCEPTION: Critical Error Loading Map!!!", ORPG_GENERAL) | |
768 self.log.log("Exit MapCanvas->takexml(self, xml)", ORPG_DEBUG) | |
769 | 679 |
770 def re_ids_in_xml(self, xml): | 680 def re_ids_in_xml(self, xml): |
771 self.log.log("Enter MapCanvas->re_ids_in_xml(self, xml)", ORPG_DEBUG) | |
772 new_xml = "" | 681 new_xml = "" |
773 tmp_map = map_msg() | 682 tmp_map = map_msg() |
774 xml_dom = parseXml(str(xml)) | 683 xml_dom = parseXml(str(xml)) |
775 node_list = xml_dom.getElementsByTagName("map") | 684 node_list = xml_dom.getElementsByTagName("map") |
776 if len(node_list) < 1: self.log.log("Invalid XML format for mapper", ORPG_INFO) | 685 if len(node_list) < 1: pass |
777 else: | 686 else: |
778 tmp_map.init_from_dom(node_list[0]) | 687 tmp_map.init_from_dom(node_list[0]) |
779 if tmp_map.children.has_key("miniatures"): | 688 if tmp_map.children.has_key("miniatures"): |
780 miniatures_layer = tmp_map.children["miniatures"] | 689 miniatures_layer = tmp_map.children["miniatures"] |
781 if miniatures_layer: | 690 if miniatures_layer: |
799 elif l.tagname == 'text': id = 'text-' + self.frame.session.get_next_id() | 708 elif l.tagname == 'text': id = 'text-' + self.frame.session.get_next_id() |
800 elif l.tagname == 'circle': id = 'circle-' + self.frame.session.get_next_id() | 709 elif l.tagname == 'circle': id = 'circle-' + self.frame.session.get_next_id() |
801 l.init_prop("id", id) | 710 l.init_prop("id", id) |
802 new_xml = tmp_map.get_all_xml() | 711 new_xml = tmp_map.get_all_xml() |
803 if xml_dom: xml_dom.unlink() | 712 if xml_dom: xml_dom.unlink() |
804 self.log.log("Exit MapCanvas->re_ids_in_xml(self, xml)", ORPG_DEBUG) | |
805 return str(new_xml) | 713 return str(new_xml) |
806 | 714 |
807 class map_wnd(wx.Panel): | 715 class map_wnd(wx.Panel): |
808 def __init__(self, parent, id): | 716 def __init__(self, parent, id): |
809 self.log = open_rpg.get_component('log') | |
810 self.log.log("Enter map_wnd", ORPG_DEBUG) | |
811 wx.Panel.__init__(self, parent, id) | 717 wx.Panel.__init__(self, parent, id) |
812 self.canvas = MapCanvas(self, -1) | 718 self.canvas = MapCanvas(self, -1) |
813 self.session = open_rpg.get_component('session') | 719 self.session = component.get('session') |
814 self.settings = open_rpg.get_component('settings') | 720 self.chat = component.get('chat') |
815 self.chat = open_rpg.get_component('chat') | 721 self.top_frame = component.get('frame') |
816 self.top_frame = open_rpg.get_component('frame') | |
817 self.root_dir = os.getcwd() | 722 self.root_dir = os.getcwd() |
818 self.current_layer = 2 | 723 self.current_layer = 2 |
819 self.layer_tabs = orpgTabberWnd(self, style=FNB.FNB_NO_X_BUTTON|FNB.FNB_BOTTOM|FNB.FNB_NO_NAV_BUTTONS) | 724 self.layer_tabs = orpgTabberWnd(self, style=FNB.FNB_NO_X_BUTTON|FNB.FNB_BOTTOM|FNB.FNB_NO_NAV_BUTTONS) |
820 self.layer_handlers = [] | 725 self.layer_handlers = [] |
821 self.layer_handlers.append(background_handler(self.layer_tabs,-1,self.canvas)) | 726 self.layer_handlers.append(background_handler(self.layer_tabs,-1,self.canvas)) |
837 self.SetSizer(self.sizer) | 742 self.SetSizer(self.sizer) |
838 self.Bind(FNB.EVT_FLATNOTEBOOK_PAGE_CHANGED, self.on_layer_change) | 743 self.Bind(FNB.EVT_FLATNOTEBOOK_PAGE_CHANGED, self.on_layer_change) |
839 #self.Bind(wx.EVT_SIZE, self.on_size) | 744 #self.Bind(wx.EVT_SIZE, self.on_size) |
840 self.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeave) | 745 self.Bind(wx.EVT_LEAVE_WINDOW, self.OnLeave) |
841 self.load_default() | 746 self.load_default() |
842 self.log.log("Exit map_wnd", ORPG_DEBUG) | |
843 | 747 |
844 def OnLeave(self, evt): | 748 def OnLeave(self, evt): |
845 if "__WXGTK__" in wx.PlatformInfo: wx.SetCursor(wx.StockCursor(wx.CURSOR_ARROW)) | 749 if "__WXGTK__" in wx.PlatformInfo: wx.SetCursor(wx.StockCursor(wx.CURSOR_ARROW)) |
846 | 750 |
847 def load_default(self): | 751 def load_default(self): |
848 self.log.log("Enter map_wnd->load_default(self)", ORPG_DEBUG) | |
849 if self.session.is_connected() and (self.session.my_role() != self.session.ROLE_GM) and (self.session.use_roles()): | 752 if self.session.is_connected() and (self.session.my_role() != self.session.ROLE_GM) and (self.session.use_roles()): |
850 self.chat.InfoPost("You must be a GM to use this feature") | 753 self.chat.InfoPost("You must be a GM to use this feature") |
851 self.log.log("Exit map_wnd->load_default(self)", ORPG_DEBUG) | |
852 return | 754 return |
853 f = open(orpg.dirpath.dir_struct["template"] + "default_map.xml") | 755 f = open(dir_struct["template"] + "default_map.xml") |
854 self.new_data(f.read()) | 756 self.new_data(f.read()) |
855 f.close() | 757 f.close() |
856 self.canvas.send_map_data("new") | 758 self.canvas.send_map_data("new") |
857 if not self.session.is_connected() and (self.session.my_role() != self.session.ROLE_GM): | 759 if not self.session.is_connected() and (self.session.my_role() != self.session.ROLE_GM): |
858 self.session.update_role("GM") | 760 self.session.update_role("GM") |
859 self.log.log("Exit map_wnd->load_default(self)", ORPG_DEBUG) | |
860 | 761 |
861 def new_data(self, data): | 762 def new_data(self, data): |
862 self.log.log("Enter map_wnd->new_data(self, data)", ORPG_DEBUG) | |
863 self.canvas.takexml(data) | 763 self.canvas.takexml(data) |
864 self.update_tools() | 764 self.update_tools() |
865 self.log.log("Exit map_wnd->new_data(self, data)", ORPG_DEBUG) | |
866 | 765 |
867 def on_save(self,evt): | 766 def on_save(self,evt): |
868 self.log.log("Enter map_wnd->new_data(self, data)", ORPG_DEBUG) | |
869 if (self.session.my_role() != self.session.ROLE_GM): | 767 if (self.session.my_role() != self.session.ROLE_GM): |
870 self.chat.InfoPost("You must be a GM to use this feature") | 768 self.chat.InfoPost("You must be a GM to use this feature") |
871 self.log.log("Exit map_wnd->new_data(self, data)", ORPG_DEBUG) | |
872 return | 769 return |
873 d = wx.FileDialog(self.GetParent(), "Save map data", orpg.dirpath.dir_struct["user"], "", "*.xml", wx.SAVE) | 770 d = wx.FileDialog(self.GetParent(), "Save map data", dir_struct["user"], "", "*.xml", wx.SAVE) |
874 if d.ShowModal() == wx.ID_OK: | 771 if d.ShowModal() == wx.ID_OK: |
875 f = open(d.GetPath(), "w") | 772 f = open(d.GetPath(), "w") |
876 data = '<nodehandler class="min_map" icon="compass" module="core" name="miniature Map">' | 773 data = '<nodehandler class="min_map" icon="compass" module="core" name="miniature Map">' |
877 data += self.canvas.toxml("new") | 774 data += self.canvas.toxml("new") |
878 data += "</nodehandler>" | 775 data += "</nodehandler>" |
879 data = data.replace(">",">\n") | 776 data = data.replace(">",">\n") |
880 f.write(data) | 777 f.write(data) |
881 f.close() | 778 f.close() |
882 d.Destroy() | 779 d.Destroy() |
883 os.chdir(self.root_dir) | 780 os.chdir(self.root_dir) |
884 self.log.log("Exit map_wnd->new_data(self, data)", ORPG_DEBUG) | |
885 | 781 |
886 def on_open(self, evt): | 782 def on_open(self, evt): |
887 self.log.log("Enter map_wnd->on_open(self, evt)", ORPG_DEBUG) | |
888 if self.session.is_connected() and (self.session.my_role() != self.session.ROLE_GM) and (self.session.use_roles()): | 783 if self.session.is_connected() and (self.session.my_role() != self.session.ROLE_GM) and (self.session.use_roles()): |
889 self.chat.InfoPost("You must be a GM to use this feature") | 784 self.chat.InfoPost("You must be a GM to use this feature") |
890 self.log.log("Exit map_wnd->on_open(self, evt)", ORPG_DEBUG) | |
891 return | 785 return |
892 d = wx.FileDialog(self.GetParent(), "Select a file", orpg.dirpath.dir_struct["user"], "", "*.xml", wx.OPEN) | 786 d = wx.FileDialog(self.GetParent(), "Select a file", dir_struct["user"], "", "*.xml", wx.OPEN) |
893 if d.ShowModal() == wx.ID_OK: | 787 if d.ShowModal() == wx.ID_OK: |
894 f = open(d.GetPath()) | 788 f = open(d.GetPath()) |
895 map_string = f.read() | 789 map_string = f.read() |
896 new_xml = self.canvas.re_ids_in_xml(map_string) | 790 new_xml = self.canvas.re_ids_in_xml(map_string) |
897 if new_xml: | 791 if new_xml: |
900 self.update_tools() | 794 self.update_tools() |
901 if not self.session.is_connected() and (self.session.my_role() != self.session.ROLE_GM): | 795 if not self.session.is_connected() and (self.session.my_role() != self.session.ROLE_GM): |
902 self.session.update_role("GM") | 796 self.session.update_role("GM") |
903 d.Destroy() | 797 d.Destroy() |
904 os.chdir(self.root_dir) | 798 os.chdir(self.root_dir) |
905 self.log.log("Exit map_wnd->on_open(self, evt)", ORPG_DEBUG) | |
906 | 799 |
907 def get_current_layer_handler(self): | 800 def get_current_layer_handler(self): |
908 self.log.log("Enter map_wnd->get_current_layer_handler(self)", ORPG_DEBUG) | |
909 self.log.log("Exit map_wnd->get_current_layer_handler(self)", ORPG_DEBUG) | |
910 return self.layer_handlers[self.current_layer] | 801 return self.layer_handlers[self.current_layer] |
911 | 802 |
912 def get_tab_index(self, layer): | 803 def get_tab_index(self, layer): |
913 """Return the index of a chatpanel in the wxNotebook.""" | 804 """Return the index of a chatpanel in the wxNotebook.""" |
914 self.log.log("Enter map_wnd->get_tab_index(self, layer)", ORPG_DEBUG) | |
915 for i in xrange(self.layer_tabs.GetPageCount()): | 805 for i in xrange(self.layer_tabs.GetPageCount()): |
916 if (self.layer_tabs.GetPageText(i) == layer): | 806 if (self.layer_tabs.GetPageText(i) == layer): |
917 self.log.log("Exit map_wnd->get_tab_index(self, layer) return " + str(i), ORPG_DEBUG) | |
918 return i | 807 return i |
919 self.log.log("Exit map_wnd->get_tab_index(self, layer) return 0", ORPG_DEBUG) | |
920 return 0 | 808 return 0 |
921 | 809 |
922 def on_layer_change(self, evt): | 810 def on_layer_change(self, evt): |
923 self.log.log("Enter map_wnd->on_layer_change(self, evt)", ORPG_DEBUG) | |
924 layer = self.layer_tabs.GetPage(evt.GetSelection()) | 811 layer = self.layer_tabs.GetPage(evt.GetSelection()) |
925 for i in xrange(0, len(self.layer_handlers)): | 812 for i in xrange(0, len(self.layer_handlers)): |
926 if layer == self.layer_handlers[i]: self.current_layer = i | 813 if layer == self.layer_handlers[i]: self.current_layer = i |
927 if self.current_layer == 0: | 814 if self.current_layer == 0: |
928 bg = self.layer_handlers[0] | 815 bg = self.layer_handlers[0] |
929 if (self.session.my_role() != self.session.ROLE_GM): bg.url_path.Show(False) | 816 if (self.session.my_role() != self.session.ROLE_GM): bg.url_path.Show(False) |
930 else: bg.url_path.Show(True) | 817 else: bg.url_path.Show(True) |
931 self.canvas.Refresh(False) | 818 self.canvas.Refresh(False) |
932 evt.Skip() | 819 evt.Skip() |
933 self.log.log("Exit map_wnd->on_layer_change(self, evt)", ORPG_DEBUG) | |
934 | 820 |
935 def on_left_down(self, evt): | 821 def on_left_down(self, evt): |
936 self.log.log("Enter map_wnd->on_left_down(self, evt)", ORPG_DEBUG) | |
937 self.log.log("Exit map_wnd->on_left_down(self, evt)", ORPG_DEBUG) | |
938 self.layer_handlers[self.current_layer].on_left_down(evt) | 822 self.layer_handlers[self.current_layer].on_left_down(evt) |
939 | 823 |
940 #double click handler added by Snowdog 5/03 | 824 #double click handler added by Snowdog 5/03 |
941 def on_left_dclick(self, evt): | 825 def on_left_dclick(self, evt): |
942 self.log.log("Enter map_wnd->on_left_dclick(self, evt)", ORPG_DEBUG) | |
943 self.log.log("Exit map_wnd->on_left_dclick(self, evt)", ORPG_DEBUG) | |
944 self.layer_handlers[self.current_layer].on_left_dclick(evt) | 826 self.layer_handlers[self.current_layer].on_left_dclick(evt) |
945 | 827 |
946 def on_right_down(self, evt): | 828 def on_right_down(self, evt): |
947 self.log.log("Enter map_wnd->on_right_down(self, evt)", ORPG_DEBUG) | |
948 self.log.log("Exit map_wnd->on_right_down(self, evt)", ORPG_DEBUG) | |
949 self.layer_handlers[self.current_layer].on_right_down(evt) | 829 self.layer_handlers[self.current_layer].on_right_down(evt) |
950 | 830 |
951 def on_left_up(self, evt): | 831 def on_left_up(self, evt): |
952 self.log.log("Enter map_wnd->on_left_up(self, evt)", ORPG_DEBUG) | |
953 self.log.log("Exit map_wnd->on_left_up(self, evt)", ORPG_DEBUG) | |
954 self.layer_handlers[self.current_layer].on_left_up(evt) | 832 self.layer_handlers[self.current_layer].on_left_up(evt) |
955 | 833 |
956 def on_motion(self, evt): | 834 def on_motion(self, evt): |
957 self.log.log("Enter map_wnd->on_motion(self, evt)", ORPG_DEBUG) | |
958 self.log.log("Exit map_wnd->on_motion(self, evt)", ORPG_DEBUG) | |
959 self.layer_handlers[self.current_layer].on_motion(evt) | 835 self.layer_handlers[self.current_layer].on_motion(evt) |
960 | 836 |
961 def MapBar(self, id, data): | 837 def MapBar(self, id, data): |
962 self.log.log("Enter map_wnd->MapBar(self, id, data)", ORPG_DEBUG) | |
963 self.canvas.MAP_MODE = data | 838 self.canvas.MAP_MODE = data |
964 if id == 1: | 839 if id == 1: self.canvas.MAP_MODE = data |
965 self.canvas.MAP_MODE = data | |
966 self.log.log("Exit map_wnd->MapBar(self, id, data)", ORPG_DEBUG) | |
967 | 840 |
968 def set_map_focus(self, evt): | 841 def set_map_focus(self, evt): |
969 self.log.log("Enter map_wnd->set_map_focus(self, evt)", ORPG_DEBUG) | |
970 self.canvas.SetFocus() | 842 self.canvas.SetFocus() |
971 self.log.log("Exit map_wnd->set_map_focus(self, evt)", ORPG_DEBUG) | |
972 | 843 |
973 def pre_exit_cleanup(self): | 844 def pre_exit_cleanup(self): |
974 self.log.log("Enter map_wnd->pre_exit_cleanup(self)", ORPG_DEBUG) | |
975 # do some pre exit clean up for bitmaps or other objects | 845 # do some pre exit clean up for bitmaps or other objects |
976 try: | 846 try: |
977 ImageHandler.flushCache() | 847 ImageHandler.flushCache() |
978 self.canvas.pre_destory_cleanup() | 848 self.canvas.pre_destory_cleanup() |
979 except Exception, e: | 849 except: pass |
980 self.log.log(traceback.format_exc(), ORPG_CRITICAL) | |
981 self.log.log("EXCEPTION: " + str(e), ORPG_CRITICAL) | |
982 self.log.log("Exit map_wnd->pre_exit_cleanup(self)", ORPG_DEBUG) | |
983 | 850 |
984 def update_tools(self): | 851 def update_tools(self): |
985 self.log.log("Enter map_wnd->update_tools(self)", ORPG_DEBUG) | |
986 for h in self.layer_handlers: | 852 for h in self.layer_handlers: |
987 h.update_info() | 853 h.update_info() |
988 self.log.log("Exit map_wnd->update_tools(self)", ORPG_DEBUG) | |
989 | 854 |
990 def on_hk_map_layer(self, evt): | 855 def on_hk_map_layer(self, evt): |
991 self.log.log("Enter map_wnd->on_hk_map_layer(self, evt)", ORPG_DEBUG) | |
992 id = self.top_frame.mainmenu.GetHelpString(evt.GetId()) | 856 id = self.top_frame.mainmenu.GetHelpString(evt.GetId()) |
993 #print evt.GetMenu().GetTitle() | |
994 if id == "Background Layer": self.current_layer = self.get_tab_index("Background") | 857 if id == "Background Layer": self.current_layer = self.get_tab_index("Background") |
995 if id == "Grid Layer": self.current_layer = self.get_tab_index("Grid") | 858 if id == "Grid Layer": self.current_layer = self.get_tab_index("Grid") |
996 if id == "Miniature Layer": self.current_layer = self.get_tab_index("Miniatures") | 859 if id == "Miniature Layer": self.current_layer = self.get_tab_index("Miniatures") |
997 elif id == "Whiteboard Layer": self.current_layer = self.get_tab_index("Whiteboard") | 860 elif id == "Whiteboard Layer": self.current_layer = self.get_tab_index("Whiteboard") |
998 elif id == "Fog Layer": self.current_layer = self.get_tab_index("Fog") | 861 elif id == "Fog Layer": self.current_layer = self.get_tab_index("Fog") |
999 elif id == "General Properties": self.current_layer = self.get_tab_index("General") | 862 elif id == "General Properties": self.current_layer = self.get_tab_index("General") |
1000 self.layer_tabs.SetSelection(self.current_layer) | 863 self.layer_tabs.SetSelection(self.current_layer) |
1001 self.log.log("Exit map_wnd->on_hk_map_layer(self, evt)", ORPG_DEBUG) | |
1002 | 864 |
1003 def on_flush_cache(self, evt): | 865 def on_flush_cache(self, evt): |
1004 self.log.log("Enter map_wnd->on_flush_cache(self, evt)", ORPG_DEBUG) | |
1005 ImageHandler.flushCache() | 866 ImageHandler.flushCache() |
1006 self.log.log("Exit map_wnd->on_flush_cache(self, evt)", ORPG_DEBUG) | |
1007 | 867 |
1008 def build_menu(self): | 868 def build_menu(self): |
1009 self.log.log("Enter map_wnd->build_menu(self)", ORPG_DEBUG) | |
1010 # temp menu | 869 # temp menu |
1011 menu = wx.Menu() | 870 menu = wx.Menu() |
1012 item = wx.MenuItem(menu, wx.ID_ANY, "&Load Map", "Load Map") | 871 item = wx.MenuItem(menu, wx.ID_ANY, "&Load Map", "Load Map") |
1013 self.top_frame.Bind(wx.EVT_MENU, self.on_open, item) | 872 self.top_frame.Bind(wx.EVT_MENU, self.on_open, item) |
1014 menu.AppendItem(item) | 873 menu.AppendItem(item) |
1041 menu.AppendSeparator() | 900 menu.AppendSeparator() |
1042 item = wx.MenuItem(menu, wx.ID_ANY, "&Properties", "Properties") | 901 item = wx.MenuItem(menu, wx.ID_ANY, "&Properties", "Properties") |
1043 self.top_frame.Bind(wx.EVT_MENU, self.canvas.on_prop, item) | 902 self.top_frame.Bind(wx.EVT_MENU, self.canvas.on_prop, item) |
1044 menu.AppendItem(item) | 903 menu.AppendItem(item) |
1045 self.top_frame.mainmenu.Insert(2, menu, '&Map') | 904 self.top_frame.mainmenu.Insert(2, menu, '&Map') |
1046 self.log.log("Exit map_wnd->build_menu(self)", ORPG_DEBUG) | |
1047 | 905 |
1048 def get_hot_keys(self): | 906 def get_hot_keys(self): |
1049 self.log.log("Enter map_wnd->get_hot_keys(self)", ORPG_DEBUG) | |
1050 self.build_menu() | 907 self.build_menu() |
1051 self.log.log("Exit map_wnd->get_hot_keys(self)", ORPG_DEBUG) | |
1052 return [] | 908 return [] |