Пример #1
0
 def drawInfo(self, screen): #FIXME I am shitty.
     """Displays health and description"""
     text = '%s \n Description: \n %s' % (self.healthStr(), self.description)
     textBox=Sign(150, (0, 600), image=self.image)
     textBox.addtext(text)
     textBox.render()
     textBox.draw(screen)
class ResourceBar():
    """
    A bar at the top of the screen indicating the amount of resources the player has on the current world

    @param baseLayer: background image
    @type baseLayer: DrawableObjectGroup(list(tuple(str,  str)), tuple(int, int))

    @param offset: position of amount of resource relative to ResourceBar
    @type offset: tuple(int, int)

    @param textField: Displays amount of resources own
    @type textField: Sign

    @param value: amount of resource owned
    @type value: int
    """
    def __init__(self,pos = (0,0)):
        images = [("ResourceBar.png", 'alpha')]
        self.baseLayer = DrawableObjectGroup(images,pos=pos)
        self.offset = (30,3)
        self.textField = Sign(200, (pos[0]+self.offset[0],pos[1]+self.offset[1]),fsize = 20)
        self.textField.tcolor=(180,180,0)
        self.setResourceCount(0)

    def setResourceCount(self,val=0):
        self.value = val
        self.textField.clear()
        self.textField.addtext(str(self.value))

    def draw(self,screen):
        #FIXME Add font here
        self.baseLayer.draw(screen)
        self.textField.render(screen)
Пример #3
0
 def getInfo(self):
     text = '%s \n Description: \n %s' % (self.healthStr(), self.description)
     textBox=Sign(150, (0,0))
     textBox.addtext(text)
     textBox.render()
     return textBox
class DescriptionBox():
    """
    The largest HUD element which describes the hovered unit
    and its properties (those which are player-relevant)

    @param baseLayer:  background image
    @type baseLayer: DrawableObjectGroup(list(tuple(str,  str)), tuple(int, int))

    @param entity: Entity whose information is being displayed
    @type entity: Entity

    @param descriptionOffset: position of description of entity relative to DescriptionBox
    @type descriptionOffset: tuple(int, int)

    @param description: Text description of entity
    @type descritpion: Sign

    @param pos: position of DescriptionBox on screen
    @type pos: tuple(int, int)

    @param thumbnailOffset: position of thumbnail relative to DescriptionBox
    @type thumbnailOffset: tuple(int, int)
    """
    def __init__(self,pos = (0,768-36-186)):
         #FIXME Remove this dependency - replace image with thumbnail
        from Overlay import Bar
        #Format for each tuple is (imagePath, [colorKey, [offset]])
        images = [("BarTop.png",'alpha')]
        images.append(("BarRight.png",'alpha',(325,36)))
        images.append(("DescBoxCentral.png",None,(0,36)))
        self.baseLayer = DrawableObjectGroup(images,pos=pos)
        self.entity = None
        self.descriptionOffset = (35,73+36)
        self.description = Sign(260, (pos[0]+self.descriptionOffset[0],pos[1]+self.descriptionOffset[1]),fsize = 18)
        self.description.tcolor=(180,180,0)
        self.pos = pos
        self.thumbnailOffset = (12,14+36)

    def updateDisplayedEntity(self,entity):
        """
        Changes entity displayed
        """
        import pygame
        from Overlay import Bar
        self.entity = entity
        self.thumbnail = self.entity.getDefaultImage()
        self.thumbnail = pygame.transform.scale(self.thumbnail, (44, 44))
        self.description.clear()
        self.description.addtext(entity.description)
        self.healthBar = Bar(self.entity.maxHealth,118,6,fullColor=(0,255,0),emptyColor=(30,30,30)) 

    def draw(self,screen):
        self.baseLayer.draw(screen)
        if self.entity:
            self.healthBar.updateBarWithValue(self.entity.curHealth)

            #if entity is building something, displays
            #building status
            if hasattr(self.entity,'currentTask'):
                if self.entity.currentTask:
                    if hasattr(self.entity.currentTask,'timeSpentBuilding'):
                        from Overlay import Bar
                        self.buildBar = Bar(self.entity.currentTask.timeToBuild,118,6,fullColor=(0,180,255),emptyColor=(30,30,30))
                        self.buildBar.updateBarWithValue(self.entity.currentTask.timeSpentBuilding)
                        self.buildBar.draw(screen,(self.pos[0]+78,self.pos[1]+69))
            
            screen.blit(self.thumbnail, (self.pos[0]+self.thumbnailOffset[0],self.pos[1]+self.thumbnailOffset[1]))
            self.healthBar.draw(screen,(self.pos[0]+78,self.pos[1]+56))
            
            self.description.render(screen)