Mercurial > traipse_dev
comparison orpg/mapper/background.py @ 137:54446a995007 alpha
Traipse Alpha 'OpenRPG' {091018-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 (Cleaning up for 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 Recusion method, mapping, and context sensitivity. !!Alpha - Watch out for infinite loops!!
author | sirebral |
---|---|
date | Wed, 18 Nov 2009 19:57:52 -0600 |
parents | 217fb049bd00 |
children | 8e07c1a2c69b |
comparison
equal
deleted
inserted
replaced
136:b4e02e8cd314 | 137:54446a995007 |
---|---|
38 from orpg.orpgCore import component | 38 from orpg.orpgCore import component |
39 from orpg.tools.orpg_log import logger | 39 from orpg.tools.orpg_log import logger |
40 from orpg.tools.decorators import debugging | 40 from orpg.tools.decorators import debugging |
41 from orpg.tools.orpg_settings import settings | 41 from orpg.tools.orpg_settings import settings |
42 | 42 |
43 from xml.etree.ElementTree import ElementTree, Element, tostring, fromstring, parse | |
44 | |
43 ##----------------------------- | 45 ##----------------------------- |
44 ## background layer | 46 ## background layer |
45 ##----------------------------- | 47 ##----------------------------- |
46 | 48 |
47 BG_NONE = 0 | 49 BG_NONE = 0 |
48 BG_TEXTURE = 1 | 50 BG_TEXTURE = 1 |
49 BG_IMAGE = 2 | 51 BG_IMAGE = 2 |
50 BG_COLOR = 3 | 52 BG_COLOR = 3 |
51 | 53 |
52 class layer_back_ground(layer_base): | 54 class layer_back_ground(layer_base): |
53 @debugging | 55 |
54 def __init__(self, canvas): | 56 def __init__(self, canvas): |
55 self.canvas = canvas | 57 self.canvas = canvas |
56 self.log = component.get('log') | 58 self.log = component.get('log') |
57 layer_base.__init__(self) | 59 layer_base.__init__(self) |
58 self.canvas = canvas | 60 self.canvas = canvas |
59 self.r_h = RGBHex() | 61 self.r_h = RGBHex() |
60 self.clear() | 62 self.clear() |
61 | 63 |
62 @debugging | 64 |
63 def error_loading_image(self, image): | 65 def error_loading_image(self, image): |
64 msg = "Unable to load image:" + `image` | 66 msg = "Unable to load image:" + `image` |
65 dlg = wx.MessageDialog(self.canvas,msg,'File not Found',wx.ICON_EXCLAMATION) | 67 dlg = wx.MessageDialog(self.canvas,msg,'File not Found',wx.ICON_EXCLAMATION) |
66 dlg.ShowModal() | 68 dlg.ShowModal() |
67 dlg.Destroy() | 69 dlg.Destroy() |
68 | 70 |
69 @debugging | 71 |
70 def clear(self): | 72 def clear(self): |
71 self.type = BG_NONE | 73 self.type = BG_NONE |
72 self.bg_bmp = None | 74 self.bg_bmp = None |
73 self.bg_color = None | 75 self.bg_color = None |
74 self.img_path = None | 76 self.img_path = None |
75 self.local = False | 77 self.local = False |
76 self.localPath = '' | 78 self.localPath = '' |
77 self.localTime = -1 | 79 self.localTime = -1 |
78 self.isUpdated = True | 80 self.isUpdated = True |
79 | 81 |
80 @debugging | 82 |
81 def get_type(self): | 83 def get_type(self): |
82 return self.type | 84 return self.type |
83 | 85 |
84 @debugging | 86 |
85 def get_img_path(self): | 87 def get_img_path(self): |
86 if self.img_path: return self.img_path | 88 if self.img_path: return self.img_path |
87 else: return "" | 89 else: return "" |
88 | 90 |
89 @debugging | 91 |
90 def get_color(self): | 92 def get_color(self): |
91 hexcolor = "#FFFFFF" | 93 hexcolor = "#FFFFFF" |
92 if self.bg_color: | 94 if self.bg_color: |
93 (red,green,blue) = self.bg_color.Get() | 95 (red,green,blue) = self.bg_color.Get() |
94 hexcolor = self.r_h.hexstring(red, green, blue) | 96 hexcolor = self.r_h.hexstring(red, green, blue) |
95 return hexcolor | 97 return hexcolor |
96 | 98 |
97 @debugging | 99 |
98 def set_texture(self, path): | 100 def set_texture(self, path): |
99 self.isUpdated = True | 101 self.isUpdated = True |
100 self.type = BG_TEXTURE | 102 self.type = BG_TEXTURE |
101 if self.img_path != path: | 103 if self.img_path != path: |
102 try: | 104 try: |
105 logger.general("Invalid image type!") | 107 logger.general("Invalid image type!") |
106 raise Exception, "Invalid image type!" | 108 raise Exception, "Invalid image type!" |
107 except: self.error_loading_image(path) | 109 except: self.error_loading_image(path) |
108 self.img_path = path | 110 self.img_path = path |
109 | 111 |
110 @debugging | 112 |
111 def set_image(self, path, scale): | 113 def set_image(self, path, scale): |
112 self.isUpdated = True | 114 self.isUpdated = True |
113 self.type = BG_IMAGE | 115 self.type = BG_IMAGE |
114 if self.img_path != path: | 116 if self.img_path != path: |
115 self.bg_bmp = ImageHandler.load(path, "background", 0) | 117 self.bg_bmp = ImageHandler.load(path, "background", 0) |
119 raise Exception, "Invalid image type!" | 121 raise Exception, "Invalid image type!" |
120 except: self.error_loading_image(path) | 122 except: self.error_loading_image(path) |
121 self.img_path = path | 123 self.img_path = path |
122 return (self.bg_bmp.GetWidth(),self.bg_bmp.GetHeight()) | 124 return (self.bg_bmp.GetWidth(),self.bg_bmp.GetHeight()) |
123 | 125 |
124 @debugging | 126 |
125 def set_color(self, color): | 127 def set_color(self, color): |
126 self.isUpdated = True | 128 self.isUpdated = True |
127 self.type = BG_COLOR | 129 self.type = BG_COLOR |
128 (r,g,b) = color.Get() | 130 (r,g,b) = color.Get() |
129 self.bg_color = cmpColour(r,g,b) | 131 self.bg_color = cmpColour(r,g,b) |
130 self.canvas.SetBackgroundColour(self.bg_color) | 132 self.canvas.SetBackgroundColour(self.bg_color) |
131 | 133 |
132 @debugging | 134 |
133 def layerDraw(self, dc, scale, topleft, size): | 135 def layerDraw(self, dc, scale, topleft, size): |
134 if self.bg_bmp == None or not self.bg_bmp.Ok() or ((self.type != BG_TEXTURE) and (self.type != BG_IMAGE)): | 136 if self.bg_bmp == None or not self.bg_bmp.Ok() or ((self.type != BG_TEXTURE) and (self.type != BG_IMAGE)): |
135 return False | 137 return False |
136 dc2 = wx.MemoryDC() | 138 dc2 = wx.MemoryDC() |
137 | 139 |
208 dc.Blit(posx, posy, newW, newH, dc2, cl, ct) | 210 dc.Blit(posx, posy, newW, newH, dc2, cl, ct) |
209 dc2.SelectObject(wx.NullBitmap) | 211 dc2.SelectObject(wx.NullBitmap) |
210 del dc2 | 212 del dc2 |
211 return True | 213 return True |
212 | 214 |
213 @debugging | 215 |
214 def layerToXML(self, action="update"): | 216 def layerToXML(self, action="update"): |
215 xml_str = "<bg" | 217 xml = Element('bg') |
216 if self.bg_color != None: | 218 if self.bg_color != None: |
217 (red,green,blue) = self.bg_color.Get() | 219 (red,green,blue) = self.bg_color.Get() |
218 hexcolor = self.r_h.hexstring(red, green, blue) | 220 hexcolor = self.r_h.hexstring(red, green, blue) |
219 xml_str += ' color="' + hexcolor + '"' | 221 xml.set('color', hexcolor) |
220 if self.img_path != None: xml_str += ' path="' + urllib.quote(self.img_path).replace('%3A', ':') + '"' | 222 if self.img_path != None: xml.set('path', urllib.quote(self.img_path).replace('%3A', ':')) |
221 if self.type != None: xml_str += ' type="' + str(self.type) + '"' | 223 if self.type != None: xml.set('type', str(self.type)) |
222 if self.local and self.img_path != None: | 224 if self.local and self.img_path != None: |
223 xml_str += ' local="True"' | 225 xml.set('local', 'True') |
224 xml_str += ' localPath="' + urllib.quote(self.localPath).replace('%3A', ':') + '"' | 226 xml.set('localPath', urllib.quote(self.localPath).replace('%3A', ':')) |
225 xml_str += ' localTime="' + str(self.localTime) + '"' | 227 xml.set('localTime', str(self.localTime)) |
226 xml_str += "/>" | |
227 logger.debug(xml_str) | |
228 if (action == "update" and self.isUpdated) or action == "new": | 228 if (action == "update" and self.isUpdated) or action == "new": |
229 self.isUpdated = False | 229 self.isUpdated = False |
230 return xml_str | 230 return tostring(xml) |
231 else: return '' | 231 else: return '' |
232 | 232 |
233 @debugging | 233 |
234 def layerTakeDOM(self, xml_dom): | 234 def layerTakeDOM(self, xml_dom): |
235 type = BG_COLOR | 235 type = BG_COLOR |
236 color = xml_dom.getAttribute("color") | 236 color = xml_dom.get("color") |
237 logger.debug("color=" + color) | |
238 path = urllib.unquote(xml_dom.getAttribute("path")) | |
239 logger.debug("path=" + path) | |
240 # Begin ted's map changes | 237 # Begin ted's map changes |
241 if xml_dom.hasAttribute("color"): | 238 if xml_dom.get("color"): |
242 r,g,b = self.r_h.rgb_tuple(xml_dom.getAttribute("color")) | 239 r,g,b = self.r_h.rgb_tuple(xml_dom.get("color")) |
243 self.set_color(cmpColour(r,g,b)) | 240 self.set_color(cmpColour(r,g,b)) |
244 # End ted's map changes | 241 # End ted's map changes |
245 if xml_dom.hasAttribute("type"): | 242 if xml_dom.get("type"): |
246 type = int(xml_dom.getAttribute("type")) | 243 type = int(xml_dom.get("type")) |
247 logger.debug("type=" + str(type)) | 244 logger.debug("type=" + str(type)) |
248 if type == BG_TEXTURE: | 245 if type == BG_TEXTURE: |
249 if path != "": self.set_texture(path) | 246 if xml_dom.get('path') != "": self.set_texture(xml_dom.get('path')) |
250 elif type == BG_IMAGE: | 247 elif type == BG_IMAGE: |
251 if path != "": self.set_image(path, 1) | 248 if xml_dom.get('path') != "": self.set_image(xml_dom.get('path'), 1) |
252 elif type == BG_NONE: self.clear() | 249 elif type == BG_NONE: self.clear() |
253 if xml_dom.hasAttribute('local') and xml_dom.getAttribute('local') == 'True' and os.path.exists(urllib.unquote(xml_dom.getAttribute('localPath'))): | 250 if xml_dom.get('local') and xml_dom.get('local') == 'True' and os.path.exists(urllib.unquote(xml_dom.get('localPath'))): |
254 self.localPath = urllib.unquote(xml_dom.getAttribute('localPath')) | 251 self.localPath = urllib.unquote(xml_dom.get('localPath')) |
255 self.local = True | 252 self.local = True |
256 self.localTime = int(xml_dom.getAttribute('localTime')) | 253 self.localTime = int(xml_dom.get('localTime')) |
257 if self.localTime-time.time() <= 144000: | 254 if self.localTime-time.time() <= 144000: |
258 file = open(self.localPath, "rb") | 255 file = open(self.localPath, "rb") |
259 imgdata = file.read() | 256 imgdata = file.read() |
260 file.close() | 257 file.close() |
261 filename = os.path.split(self.localPath) | 258 filename = os.path.split(self.localPath) |
262 (imgtype,j) = mimetypes.guess_type(filename[1]) | 259 (imgtype,j) = mimetypes.guess_type(filename[1]) |
263 postdata = urllib.urlencode({'filename':filename[1], 'imgdata':imgdata, 'imgtype':imgtype}) | 260 postdata = urllib.urlencode({'filename':filename[1], |
261 'imgdata':imgdata, | |
262 'imgtype':imgtype}) | |
264 thread.start_new_thread(self.upload, (postdata, self.localPath, type)) | 263 thread.start_new_thread(self.upload, (postdata, self.localPath, type)) |
265 | 264 |
266 @debugging | 265 |
267 def upload(self, postdata, filename, type): | 266 def upload(self, postdata, filename, type): |
268 self.lock.acquire() | 267 self.lock.acquire() |
269 if type == 'Image' or type == 'Texture': | 268 if type == 'Image' or type == 'Texture': |
270 url = component.get('settings').get_setting('ImageServerBaseURL') | 269 url = component.get('settings').get_setting('ImageServerBaseURL') |
271 file = urllib.urlopen(url, postdata) | 270 recvdata = parse(urllib.urlopen(url, postdata)) |
272 recvdata = file.read() | |
273 file.close() | |
274 try: | 271 try: |
275 xml_dom = minidom.parseString(recvdata)._get_documentElement() | 272 xml_dom = fromstring(recvdata).getroot() |
276 if xml_dom.nodeName == 'path': | 273 xml_dom = fromstring(recvdata) |
277 path = xml_dom.getAttribute('url') | 274 if xml_dom.tag == 'path': |
275 path = xml_dom.get('url') | |
278 path = urllib.unquote(path) | 276 path = urllib.unquote(path) |
279 if type == 'Image': self.set_image(path, 1) | 277 if type == 'Image': self.set_image(path, 1) |
280 else: self.set_texture(path) | 278 else: self.set_texture(path) |
281 self.localPath = filename | 279 self.localPath = filename |
282 self.local = True | 280 self.local = True |
283 self.localTime = time.time() | 281 self.localTime = time.time() |
284 else: | 282 else: |
285 print xml_dom.getAttribute('msg') | 283 print xml_dom.get('msg') |
286 except Exception, e: | 284 except Exception, e: |
287 print e | 285 print e |
288 print recvdata | 286 print recvdata |
289 self.lock.release() | 287 self.lock.release() |