def moviehandler(event): #Skip if there are no movies playing if globals.playing != []: #Build a list of all unpaused, visible, playing movies tmpmovielist = [curmovie for curmovie in globals.playing if curmovie.isvisible() and not curmovie.ispaused()] #If there are any: if tmpmovielist != []: #Get one of the movies rects dirtyrect = tmpmovielist[0].getrect() #Make a rect that encompasses all movies rects dirtyrect.unionall_ip([item.getrect() for item in tmpmovielist]) #find the lowest playing movie in the list of user areas lowest = len(globals.userareasordered) for curmovie in tmpmovielist: if globals.userareasordered.index(curmovie) < lowest: lowest = globals.userareasordered.index(curmovie) #Hide all objects above the lowest item that are in the rect made earlier dirtyrect = userarea._redrawfrom(globals.userareasordered[lowest], 0, dirtyrect) #If this movie has an old background saved, draw it to the uhabuffer if globals.userareasordered[lowest]._bgsurface != None: globals.uhabuffer.fill((0,0,0,0), globals.userareasordered[lowest]._rect) globals.uhabuffer.blit(globals.userareasordered[lowest]._bgsurface, globals.userareasordered[lowest]._rect) #Redraw the lowest movie globals.userareasordered[lowest]._draw() #Restore all objects above the lowest movie in the compund rect #As a side effect this causes ALL the movies to be redrawn dirtyrect = userarea._redrawfrom(globals.userareasordered[lowest], 1, dirtyrect) #Update the screen globals.updateuhasurface(dirtyrect) #Stop any finished movies for curmovie in tmpmovielist: #If the movie is not busy, it's done playing if not curmovie._movie.get_busy(): #Stop it and allow the exit function to be called curmovie.stop(0)
def update(self, file = None, rect = None, cursor = None, looping = None, endfunc = None, visible = None, skippable = None): #Rect to hold updatd screen area dirtyrect = None #If playing, changing rect or visibility need to restore the old bg and hide the items above it if self._playing: if visible != None or rect != None: dirtyrect = userarea._redrawfrom(self, 0 , dirtyrect) globals.uhabuffer.fill((0,0,0,0), self._rect) globals.uhabuffer.blit(self._bgsurface, self._rect) #Update the visibility (can only be changed when the movie is playing) if visible != None: self._visible = visible else: #These items can only be changed if the movie is not playing if file != None: self._file = file #If changed to a looping movie, set this movie to show the cursor, and clear the end function #Otherwise set the cursor and end function to the new values, if any if looping != None: self._looping = looping if looping: self._cursor = 1 self._endfunc = None self._skippable = 0 else: if cursor != None: self._cursor = cursor if endfunc != None: self._endfunc = endfunc if skippable != None: self._skippable = skippable else: if cursor != None: self._cursor = cursor if endfunc != None: self._endfunc = endfunc if skippable != None: self._skippable = skippable #Rect can be changed no matter what if rect != None: if len(rect) > 2: self._rect = pygame.Rect(rect) else: self._rect = pygame.Rect(rect,(0,0)) #If the movie is playing, set the rect size to the movie size if self._playing: self._rect.size = self._movie.get_size() #If movie is visible hide everything above it and redraw it if self._visible: dirtyrect = userarea._redrawfrom(self, 0, dirtyrect) self._draw() #If any areas have been hidden by this update, restore all items hidden so far #then update the screen if dirtyrect != None: dirtyrect = userarea._redrawfrom(self, 1, dirtyrect) globals.updateuhasurface(dirtyrect)
def _handleenter(self): #Set the state to "activated" self._state = 1 #If the inventory is visible, and the show and hide alphas are different, we need to redraw the inventory if self._visible and (self._hidealpha != self._showalpha): #Hide all areas above this one dirtyrect = userarea._redrawfrom(self) #Restore the background globals.uhabuffer.fill((0,0,0,0), self._rect) globals.uhabuffer.blit(self._bgsurface, self._rect) #Draw the updated inventory self._draw() #Redraw all areas above this one dirtyrect = userarea._redrawfrom(self, 1, dirtyrect) #Set the cursor to be an arrow globals.curcursor = globals.cursors['arrow'] #Update the screen globals.updateuhasurface(dirtyrect)
def _itemupdate(self, item): #Only update if the item is in the players inventory if item in self._itemlist: #If initialized, reload the items image if self._initialized: self._itemimages[self._itemlist.index(item)] = [item._draw(),None] #Redraw the inventory if needed if self._visible: #Hide all areas above this one dirtyrect = userarea._redrawfrom(self) #Restore the background globals.uhabuffer.fill((0,0,0,0), self._rect) globals.uhabuffer.blit(self._bgsurface, self._rect) #Draw the updated inventory self._draw() #Redraw all areas above this one dirtyrect = userarea._redrawfrom(self, 1, dirtyrect) #Update the screen globals.updateuhasurface(dirtyrect)
def _handleevent(self, event): if event.type == 'init': #If init, initialize the area self._handleinit() elif event.type == 'mouseenter': #If enter, do entrance function self._handleenter() elif event.type == 'mouseexit': #If exit, do exit function self._handleexit() elif event.type == pygame.MOUSEMOTION: #If mouse has moved, find the currently highlighted item self._handlemove(event) #Return 1 so this event is not passed to other objects return 1 elif event.type == pygame.MOUSEBUTTONDOWN: #If a click, show the current item if one is selected (or scroll if needed) if self._currentitem != None: if self._currentitem != 'back' and self._currentitem != 'fwd': #It's not a scroll arrow, so call it's click function self._itemlist[self._currentitem]._click() elif self._currentitem == 'back': #it's the back arrow, so decrement the starting item if self._startitem != 0: self._startitem -= 1 else: #Its fwd scroll so increment the starting item if self._enditem != len(self._itemimages): self._startitem +=1 if self._visible: #Hide all areas above this one dirtyrect = userarea._redrawfrom(self) #Restore the background globals.uhabuffer.fill((0,0,0,0), self._rect) globals.uhabuffer.blit(self._bgsurface, self._rect) #Draw the updated inventory self._draw() #Redraw all areas above this one dirtyrect = userarea._redrawfrom(self, 1, dirtyrect) #Update the screen globals.updateuhasurface(dirtyrect) #Return 1 so this event is not passed to other objects return 1
def remove(self, item): #Only remove it if it is in the inventory if item in self._itemlist: #Delete this items image del self._itemimages[self._itemlist.index(item)] #Remove the item from the inventory self._itemlist.remove(item) #Redraw the inventory if needed if self._visible: #Hide all areas above this one dirtyrect = userarea._redrawfrom(self) #Restore the background globals.uhabuffer.fill((0,0,0,0), self._rect) globals.uhabuffer.blit(self._bgsurface, self._rect) #Draw the updated inventory self._draw() #Redraw all areas above this one dirtyrect = userarea._redrawfrom(self, 1, dirtyrect) #Update the screen globals.updateuhasurface(dirtyrect)
def _handleexit(self): #Set the state to "deactivated" self._state = 0 #If the inventory is visible and the show and hide alphas are different or there is a highlighted item if self._visible and (self._hidealpha != self._showalpha or self._currentitem != None): #Hide all areas above this one dirtyrect = userarea._redrawfrom(self) #Restore the background globals.uhabuffer.fill((0,0,0,0), self._rect) globals.uhabuffer.blit(self._bgsurface, self._rect) #Clear the current item self._currentitem = None #Draw the updated inventory self._draw() #Redraw all areas above this one dirtyrects = userarea._redrawfrom(self, 1, dirtyrect) #Update the screen globals.updateuhasurface(dirtyrect) #Clear the current item self._currentitem = None
def add(self, item): #Only add it if it's not already there if item not in self._itemlist: #Add it to the inventory self._itemlist.append(item) #If the inventory bar has been initialized, load the item if self._initialized: self._itemimages.append([item._draw(),None]) #Redraw the inventory if needed if self._visible: #Hide all areas above this one dirtyrect = userarea._redrawfrom(self) #Restore the background globals.uhabuffer.fill((0,0,0,0), self._rect) globals.uhabuffer.blit(self._bgsurface, self._rect) #Draw the updated inventory self._draw() #Redraw all areas above this one dirtyrect = userarea._redrawfrom(self, 1, dirtyrect) #Update the screen globals.updateuhasurface(dirtyrect)
def update(self, rect = None, bgfile = None, bgdatfile = None, bgencryption = None, hidealpha = None, showalpha = None, mouseoveralpha = None, visible = None, enabled = None): #This will hold the area of the screen effected by this update dirtyrect = None if self._visible: #Hide all areas above this one, and restore the background dirtyrect = userarea._redrawfrom(self) globals.uhabuffer.fill((0,0,0,0), self._rect) globals.uhabuffer.blit(self._bgsurface, self._rect) #Update attributes if rect != None: self._rect = pygame.Rect(rect) if bgfile != None: self._bgfile = bgfile if bgdatfile != None: self._bgdatfile = bgdatfile if bgencryption != None: self._bgencryption = bgencryption if hidealpha != None: self._hidealpha = hidealpha if showalpha != None: self._showalpha = showalpha if mouseoveralpha != None: self._mouseoveralpha = mouseoveralpha if visible != None: self._visible = visible if enabled != None: self._enabled = enabled #If any of the following changed, reload the background file if bgfile != None or bgdatfile != None or bgencryption != None: self._bgfilesurface = None if self._visible: #Hide all areas above this one dirtyrect = userarea._redrawfrom(self, 0, dirtyrect) #Draw area self._draw() if dirtyrect != None: #Restore all areas above this one (if needed) dirtyrect = userarea._redrawfrom(self, 1, dirtyrect) globals.updateuhasurface(dirtyrect)
def _handlemove(self, event): #Only check movement if visible if self._visible: #If there are any items in the inventory if len(self._itemlist): #Adjust the event position to be relative to the topleft of the inventory bar pos = (event.pos[0] - self._rect.left, event.pos[1] - self._rect.top) #If the back scroll arrow is displayed if self._backrect != None: #Check if the mouse is over the back scroll arrow if self._backrect.collidepoint(pos): #If so, set the back scroll arrow to be the highlighted item if it is not already if self._currentitem != 'back': self._currentitem = 'back' #If the item needs to be highlighted if self._mouseoveralpha != self._showalpha: #Hide all areas above this one dirtyrect = userarea._redrawfrom(self) #Restore the background globals.uhabuffer.fill((0,0,0,0), self._rect) globals.uhabuffer.blit(self._bgsurface, self._rect) #Draw the updated inventory self._draw() #Redraw all areas above this one dirtyrect = userarea._redrawfrom(self, 1, dirtyrect) #Update the screen globals.updateuhasurface(dirtyrect) #Found the current item, so return return #If the forward scroll arrow is displayed if self._fwdrect != None: #Check if the mouse is over the forward scroll arrow if self._fwdrect.collidepoint(pos): #If so, set the forward scroll arrow to be the highlighted item if it is not already if self._currentitem != 'fwd': self._currentitem = 'fwd' #If the item needs to be highlighted if self._mouseoveralpha != self._showalpha: #Hide all areas above this one dirtyrect = userarea._redrawfrom(self) #Restore the background globals.uhabuffer.fill((0,0,0,0), self._rect) globals.uhabuffer.blit(self._bgsurface, self._rect) #Draw the updated inventory self._draw() #Redraw all areas above this one dirtyrect = userarea._redrawfrom(self, 1, dirtyrect) #Update the screen globals.updateuhasurface(dirtyrect) #Found the current item, so return return #If it wasn't the back or fwd arrows, loop through items to find the current one for item in range(self._startitem, self._enditem + 1): #This is to prevent an "out of bounds" error caused by the +1 above if item < len(self._itemimages): #Check if the mouse is over this item if self._itemimages[item][1].collidepoint(pos): #If so, set this item to be the highlighted item if it is not already if self._currentitem != item: self._currentitem = item #If the item needs to be highlighted if self._mouseoveralpha != self._showalpha: #Hide all areas above this one dirtyrect = userarea._redrawfrom(self) #Restore the background globals.uhabuffer.fill((0,0,0,0), self._rect) globals.uhabuffer.blit(self._bgsurface, self._rect) #Draw the updated inventory self._draw() #Redraw all areas above this one dirtyrect = userarea._redrawfrom(self, 1, dirtyrect) #Update the screen globals.updateuhasurface(dirtyrect) #Found the current item, so return return #If we got here the mouse is not over any items, so set the current item to None, and redraw the inventory self._currentitem = None #An item may need to be un-highlighted if self._mouseoveralpha != self._showalpha: #Hide all areas above this one dirtyrect = userarea._redrawfrom(self) #Restore the background globals.uhabuffer.fill((0,0,0,0), self._rect) globals.uhabuffer.blit(self._bgsurface, self._rect) #Draw the updated inventory self._draw() #Redraw all areas above this one dirtyrect = userarea._redrawfrom(self, 1, dirtyrect) #Update the screen globals.updateuhasurface(dirtyrect)