From: <ch...@us...> - 2009-03-03 19:53:08
|
Revision: 284 http://virtplayground.svn.sourceforge.net/virtplayground/?rev=284&view=rev Author: chozone Date: 2009-03-03 19:53:06 +0000 (Tue, 03 Mar 2009) Log Message: ----------- Added new avatar type: avatar_multipart. Also really small bugfix in playground. Modified Paths: -------------- branches/VP-Grounds/modules/playground.py Added Paths: ----------- branches/VP-Grounds/modules/playground/avatar-multipart.py Added: branches/VP-Grounds/modules/playground/avatar-multipart.py =================================================================== --- branches/VP-Grounds/modules/playground/avatar-multipart.py (rev 0) +++ branches/VP-Grounds/modules/playground/avatar-multipart.py 2009-03-03 19:53:06 UTC (rev 284) @@ -0,0 +1,88 @@ +from functions import * + +class Object(): + def __init__(self, data, share): + self.sh = share + + self.imageList=data['Avatar'][1:] + self.imageNameList=data['Avatar'][1:] + self.rect = Rect(data['Pos'][1], data['Pos'][2], 0, 0) + self.zorder = self.rect.top + self.rect.height + + def show(self): + """ + Start the whole process of: + checking whether avatar is downloaded, [download it], return avatar, and finally: blit ourselves. + This has to be a seperate def. If you put this right into __init__, we will make playground blit + ourself, before the initialisation is ready. And so, if that's not ready, we're not in the objects + list of the playground, and we will not be blitted. + """ + + #We have multiple images, so loop through them, to download them all + for image in self.imageList: + self.sh['Downloader'].getImage(image, self.imageUpdate, image) + + def imageUpdate(self, image, *arg): + """ + The downloader will call this when he's finished. + Will load in the image, and make playground blit our rect. + """ + imageName=arg[0] + image=image + + self.imageList[self.imageNameList.index(imageName)]=image + + #Does our list still contain strings? + #(wich indicates we are still awaiting some downloads) + for img in self.imageList: + if type(img)!=tuple: return + + self.buildAvatar() + + def update(self, screen, rect): + if self.rect.colliderect(rect): #Check if the rect collide with ours + rect = rect.move(-self.rect[0], -self.rect[1]) #Move rect to our position + myPos = (self.rect[0] + rect[0], self.rect[1] + rect[1]) #Calculate our position from the rect + screen.blit(self.image, myPos, rect) #Blit + + + def move(self, pos): + """ + Call this def to move this avatar to pos x=pos[1], y=pos[2]. + Will update rect, and make playground module update our old+new area + """ + oldRect=self.rect.__copy__() + + self.rect.x=pos[1] + self.rect.y=pos[2] + self.zorder = self.rect.top + self.rect.height + + updateRect=oldRect.union(self.rect) + + self.sh['Playground'].blit(updateRect) + + + def buildAvatar(self): + oldRect=self.rect.__copy__() #So we can combine it later with our new rect, so we can also update te old area + + #Update Width(w) and height(h) + self.rect.w=max([rect.w for img,rect in self.imageList]) + self.rect.h=0 + for img, rect in self.imageList: self.rect.h+=rect.h + + #And the zorder('cause we have new height) + self.zorder=self.rect.top+self.rect.height + + #Create clean surface for our avatar + self.image=pygame.Surface(self.rect.size, SRCALPHA, 32) + + #Blit all parts on this fresh surface + y=0 + for img,rect in self.imageList: + x=self.rect.w/2-rect.w/2 + self.image.blit(img, (x,y)) + y+=rect.h + + #Combine rects, and update area. It's time to show ourselves! :D + updateRect=self.rect.union(oldRect) + self.sh['Playground'].blit(updateRect) Modified: branches/VP-Grounds/modules/playground.py =================================================================== --- branches/VP-Grounds/modules/playground.py 2009-02-26 21:42:09 UTC (rev 283) +++ branches/VP-Grounds/modules/playground.py 2009-03-03 19:53:06 UTC (rev 284) @@ -110,7 +110,7 @@ if user.has_key('Pos') and user['Pos'] != None: #Has user gone offline, and should we delete the avatar object? - if user.has_key('Action') and user['Action']=='Offline': + if user.has_key('Action') and user['Action']=='Offline' and 'av-' + user['Name'] in self.objects.keys(): tempRect=self.objects['av-%s'%user['Name']].rect del self.objects['av-%s'%user['Name']] self.blit(tempRect) @@ -191,9 +191,12 @@ Create an new object, of type `objname`. """ - if not objname in self.modObjects.keys(): return - print '## Open Object', name, 'as', objname #DEBUG + if not objname in self.modObjects.keys(): + print 'ERROR @Playground: Object type', objname,'not found, cannot open', name + return + #print '## Open Object', name, 'as', objname #DEBUG + obj = self.modObjects[objname] obj = obj(data, self.sh) self.objects[name] = obj This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |