comparison orpg/mapper/background.py @ 140:e842a5f1b775 beta

Traipse Beta 'OpenRPG' {091123-00} Traipse is a distribution of OpenRPG that is designed to be easy to setup and go. Traipse also makes it easy for developers to work on code without fear of sacrifice. 'Ornery-Orc' continues the trend of 'Grumpy' and adds fixes to the code. 'Ornery-Orc's main goal is to offer more advanced features and enhance the productivity of the user. Update Summary (Beta) Added Bookmarks Fix to Remote Admin Commands Minor fix to text based Server Fix to Pretty Print, from Core Fix to Splitter Nodes not being created Fix to massive amounts of images loading, from Core Added 'boot' command to remote admin Added confirmation window for sent nodes Minor changes to allow for portability to an OpenSUSE linux OS Miniatures Layer pop up box allows users to turn off Mini labels, from FlexiRPG Zoom Mouse plugin added Images added to Plugin UI Switching to Element Tree Map efficiency, from FlexiRPG Added Status Bar to Update Manager default_manifest.xml renamed to default_upmana.xml Cleaner clode for saved repositories New TrueDebug Class in orpg_log (See documentation for usage) Mercurial's hgweb folder is ported to upmana Pretty important update that can help remove thousands of dead children from your gametree. Children, <forms />, <group_atts />, <horizontal />, <cols />, <rows />, <height />, etc... are all tags now. Check your gametree and look for dead children!! New Gametree Recursion method, mapping, and context sensitivity. !Infinite Loops return error instead of freezing the software! New Syntax added for custom PC sheets Tip of the Day added, from Core and community Fixed Whiteboard ID to prevent random line or text deleting. Modified ID's to prevent non updated clients from ruining the fix.
author sirebral
date Mon, 23 Nov 2009 03:36:26 -0600
parents dcf4fbe09b70
children 6081bdc2b8d5
comparison
equal deleted inserted replaced
135:dcf4fbe09b70 140:e842a5f1b775
48 BG_TEXTURE = 1 48 BG_TEXTURE = 1
49 BG_IMAGE = 2 49 BG_IMAGE = 2
50 BG_COLOR = 3 50 BG_COLOR = 3
51 51
52 class layer_back_ground(layer_base): 52 class layer_back_ground(layer_base):
53 @debugging 53
54 def __init__(self, canvas): 54 def __init__(self, canvas):
55 self.canvas = canvas 55 self.canvas = canvas
56 self.log = component.get('log') 56 self.log = component.get('log')
57 layer_base.__init__(self) 57 layer_base.__init__(self)
58 self.canvas = canvas 58 self.canvas = canvas
59 self.r_h = RGBHex() 59 self.r_h = RGBHex()
60 self.clear() 60 self.clear()
61 61
62 @debugging 62
63 def error_loading_image(self, image): 63 def error_loading_image(self, image):
64 msg = "Unable to load image:" + `image` 64 msg = "Unable to load image:" + `image`
65 dlg = wx.MessageDialog(self.canvas,msg,'File not Found',wx.ICON_EXCLAMATION) 65 dlg = wx.MessageDialog(self.canvas,msg,'File not Found',wx.ICON_EXCLAMATION)
66 dlg.ShowModal() 66 dlg.ShowModal()
67 dlg.Destroy() 67 dlg.Destroy()
68 68
69 @debugging 69
70 def clear(self): 70 def clear(self):
71 self.type = BG_NONE 71 self.type = BG_NONE
72 self.bg_bmp = None 72 self.bg_bmp = None
73 self.bg_color = None 73 self.bg_color = None
74 self.img_path = None 74 self.img_path = None
75 self.local = False 75 self.local = False
76 self.localPath = '' 76 self.localPath = ''
77 self.localTime = -1 77 self.localTime = -1
78 self.isUpdated = True 78 self.isUpdated = True
79 79
80 @debugging 80
81 def get_type(self): 81 def get_type(self):
82 return self.type 82 return self.type
83 83
84 @debugging 84
85 def get_img_path(self): 85 def get_img_path(self):
86 if self.img_path: return self.img_path 86 if self.img_path: return self.img_path
87 else: return "" 87 else: return ""
88 88
89 @debugging 89
90 def get_color(self): 90 def get_color(self):
91 hexcolor = "#FFFFFF" 91 hexcolor = "#FFFFFF"
92 if self.bg_color: 92 if self.bg_color:
93 (red,green,blue) = self.bg_color.Get() 93 (red,green,blue) = self.bg_color.Get()
94 hexcolor = self.r_h.hexstring(red, green, blue) 94 hexcolor = self.r_h.hexstring(red, green, blue)
95 return hexcolor 95 return hexcolor
96 96
97 @debugging 97
98 def set_texture(self, path): 98 def set_texture(self, path):
99 self.isUpdated = True 99 self.isUpdated = True
100 self.type = BG_TEXTURE 100 self.type = BG_TEXTURE
101 if self.img_path != path: 101 if self.img_path != path:
102 try: 102 try:
103 self.bg_bmp = ImageHandler.load(path, "texture", 0) 103 self.bg_bmp = ImageHandler.load(path, "texture", 0).ConvertToBitmap()
104 if self.bg_bmp == None: 104 if self.bg_bmp == None:
105 logger.general("Invalid image type!") 105 logger.general("Invalid image type!")
106 raise Exception, "Invalid image type!" 106 raise Exception, "Invalid image type!"
107 except: self.error_loading_image(path) 107 except: self.error_loading_image(path)
108 self.img_path = path 108 self.img_path = path
109 109
110 @debugging 110
111 def set_image(self, path, scale): 111 def set_image(self, path, scale):
112 self.isUpdated = True 112 self.isUpdated = True
113 self.type = BG_IMAGE 113 self.type = BG_IMAGE
114 if self.img_path != path: 114 if self.img_path != path:
115 self.bg_bmp = ImageHandler.load(path, "background", 0) 115 self.bg_bmp = ImageHandler.load(path, "background", 0).ConvertToBitmap()
116 try: 116 try:
117 if self.bg_bmp == None: 117 if self.bg_bmp == None:
118 logger.general("Invalid image type!") 118 logger.general("Invalid image type!")
119 raise Exception, "Invalid image type!" 119 raise Exception, "Invalid image type!"
120 except: self.error_loading_image(path) 120 except: self.error_loading_image(path)
121 self.img_path = path 121 self.img_path = path
122 return (self.bg_bmp.GetWidth(),self.bg_bmp.GetHeight()) 122 return (self.bg_bmp.GetWidth(),self.bg_bmp.GetHeight())
123 123
124 @debugging 124
125 def set_color(self, color): 125 def set_color(self, color):
126 self.isUpdated = True 126 self.isUpdated = True
127 self.type = BG_COLOR 127 self.type = BG_COLOR
128 (r,g,b) = color.Get() 128 (r,g,b) = color.Get()
129 self.bg_color = cmpColour(r,g,b) 129 self.bg_color = cmpColour(r,g,b)
130 self.canvas.SetBackgroundColour(self.bg_color) 130 self.canvas.SetBackgroundColour(self.bg_color)
131 131
132 @debugging 132
133 def layerDraw(self, dc, scale, topleft, size): 133 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)): 134 if self.bg_bmp == None or not self.bg_bmp.Ok() or ((self.type != BG_TEXTURE) and (self.type != BG_IMAGE)):
135 return False 135 return False
136 dc2 = wx.MemoryDC() 136 dc2 = wx.MemoryDC()
137
138 ### Temporary ###
139 try: self.bg_bmp = self.bg_bmp.ConvertToBitmap()
140 except: pass
141 #################
142
143 dc2.SelectObject(self.bg_bmp) 137 dc2.SelectObject(self.bg_bmp)
144 topLeft = [int(topleft[0]/scale), int(topleft[1]/scale)] 138 topLeft = [int(topleft[0]/scale), int(topleft[1]/scale)]
145 topRight = [int((topleft[0]+size[0]+1)/scale)+1, int((topleft[1]+size[1]+1)/scale)+1] 139 topRight = [int((topleft[0]+size[0]+1)/scale)+1, int((topleft[1]+size[1]+1)/scale)+1]
146 if (topRight[0] > self.canvas.size[0]): topRight[0] = self.canvas.size[0] 140 if (topRight[0] > self.canvas.size[0]): topRight[0] = self.canvas.size[0]
147 if (topRight[1] > self.canvas.size[1]): topRight[1] = self.canvas.size[1] 141 if (topRight[1] > self.canvas.size[1]): topRight[1] = self.canvas.size[1]
208 dc.Blit(posx, posy, newW, newH, dc2, cl, ct) 202 dc.Blit(posx, posy, newW, newH, dc2, cl, ct)
209 dc2.SelectObject(wx.NullBitmap) 203 dc2.SelectObject(wx.NullBitmap)
210 del dc2 204 del dc2
211 return True 205 return True
212 206
213 @debugging 207
214 def layerToXML(self, action="update"): 208 def layerToXML(self, action="update"):
215 xml_str = "<bg" 209 xml_str = "<bg"
216 if self.bg_color != None: 210 if self.bg_color != None:
217 (red,green,blue) = self.bg_color.Get() 211 (red,green,blue) = self.bg_color.Get()
218 hexcolor = self.r_h.hexstring(red, green, blue) 212 hexcolor = self.r_h.hexstring(red, green, blue)
228 if (action == "update" and self.isUpdated) or action == "new": 222 if (action == "update" and self.isUpdated) or action == "new":
229 self.isUpdated = False 223 self.isUpdated = False
230 return xml_str 224 return xml_str
231 else: return '' 225 else: return ''
232 226
233 @debugging 227
234 def layerTakeDOM(self, xml_dom): 228 def layerTakeDOM(self, xml_dom):
235 type = BG_COLOR 229 type = BG_COLOR
236 color = xml_dom.getAttribute("color") 230 color = xml_dom.getAttribute("color")
237 logger.debug("color=" + color) 231 logger.debug("color=" + color)
238 path = urllib.unquote(xml_dom.getAttribute("path")) 232 path = urllib.unquote(xml_dom.getAttribute("path"))
261 filename = os.path.split(self.localPath) 255 filename = os.path.split(self.localPath)
262 (imgtype,j) = mimetypes.guess_type(filename[1]) 256 (imgtype,j) = mimetypes.guess_type(filename[1])
263 postdata = urllib.urlencode({'filename':filename[1], 'imgdata':imgdata, 'imgtype':imgtype}) 257 postdata = urllib.urlencode({'filename':filename[1], 'imgdata':imgdata, 'imgtype':imgtype})
264 thread.start_new_thread(self.upload, (postdata, self.localPath, type)) 258 thread.start_new_thread(self.upload, (postdata, self.localPath, type))
265 259
266 @debugging 260
267 def upload(self, postdata, filename, type): 261 def upload(self, postdata, filename, type):
268 self.lock.acquire() 262 self.lock.acquire()
269 if type == 'Image' or type == 'Texture': 263 if type == 'Image' or type == 'Texture':
270 url = component.get('settings').get_setting('ImageServerBaseURL') 264 url = component.get('settings').get_setting('ImageServerBaseURL')
271 file = urllib.urlopen(url, postdata) 265 file = urllib.urlopen(url, postdata)