Exemple #1
0
 def LoadImage(self, filename, parent):
     myImage = OnscreenImage(image = 'Assets/Images/HUD/%s' % (filename))
     myImage.setTransparency(TransparencyAttrib.MAlpha)
     myImage.reparentTo(parent)
     myImage.setScale((myImage.getTexture().getOrigFileXSize() / 1024.0, 1, myImage.getTexture().getOrigFileYSize() / 1024.0))
     myImage.hide()
     return myImage
Exemple #2
0
class ItemIcon():
    
    def __init__(self, itemName, parentNode):
        print 'itemicon', itemName, parentNode
        self.parentNode = parentNode    # The node of its parent (e.g. the inventory)
        self.itemName = itemName        # The filename of the icon
        self.image = None               # The actual icon
        #self.iconNode = aspect2d.attachNewNode('iconnode')
        
        self.LoadContent()
        
    def LoadContent(self):
        self.itemImage = OnscreenImage(image = "Assets/Images/Items/%s.png" % (self.itemName))
        self.itemImage.setScale((self.itemImage.getTexture().getOrigFileXSize() / 1024.0, 1, self.itemImage.getTexture().getOrigFileYSize() / 1024.0))
        self.itemImage.setTransparency(TransparencyAttrib.MAlpha)
        self.itemImage.reparentTo(self.parentNode)
        
    def setBin(self, binType, value):
        print 'set bin', binType, value
        self.itemImage.setBin(binType, value)
        
    def SetPos(self, pos):
        self.itemImage.setPos(pos)
        
    def Destroy(self):
        self.itemImage.destroy()
class BetterOnscreenImage(DebugObject):

    def __init__(self, image=None, parent=None, x=0, y=0, w=10, h=10, transparent=True, nearFilter=True):
        DebugObject.__init__(self, "BOnscreenImage")

        self.initialPos = Vec3(x + w / 2.0, 1, -y - h / 2.0)

        self._node = OnscreenImage(
            image=image, parent=parent, pos=self.initialPos, scale=(w / 2.0,  1, h / 2.0))

        if transparent:
            self._node.setTransparency(TransparencyAttrib.MAlpha)

        tex = self._node.getTexture()
        tex.setMinfilter(Texture.FTNearest)
        tex.setMagfilter(Texture.FTNearest)
        tex.setAnisotropicDegree(8)
        tex.setWrapU(Texture.WMClamp)
        tex.setWrapV(Texture.WMClamp)

    def getInitialPos(self):
        return self.initialPos

    def posInterval(self, *args, **kwargs):
        return self._node.posInterval(*args, **kwargs)
class BetterOnscreenImage(DebugObject):

    """ Simple wrapper arroun OnscreenImage, providing a simpler interface and
    better visuals """

    def __init__(self, image=None, parent=None, x=0, y=0, w=10, h=10,
                 transparent=True, nearFilter=True, anyFilter=True):
        """ Creates a new image, taking (x,y) as topleft coordinates.

        When nearFilter is set to true, a near filter will be set to the
        texture passed. This provides sharper images.

        When anyFilter is set to false, the passed image won't be modified at
        all. This enables you to display existing textures, otherwise the
        texture would get a near filter in the 3D View, too. """

        DebugObject.__init__(self, "BetterOnscreenImage")

        self.w, self.h = w, h
        self.initialPos = self.translatePos(x, y)

        self._node = OnscreenImage(
            image=image, parent=parent, pos=self.initialPos,
            scale=(w / 2.0, 1, h / 2.0))

        if transparent:
            self._node.setTransparency(TransparencyAttrib.MAlpha)

        tex = self._node.getTexture()

        if nearFilter and anyFilter:
            tex.setMinfilter(Texture.FTNearest)
            tex.setMagfilter(Texture.FTNearest)

        if anyFilter:
            tex.setAnisotropicDegree(8)
            tex.setWrapU(Texture.WMClamp)
            tex.setWrapV(Texture.WMClamp)

    def getInitialPos(self):
        """ Returns the initial position of the image. This can be used for
        animations """
        return self.initialPos

    def posInterval(self, *args, **kwargs):
        """ Returns a pos interval, this is a wrapper arround
        NodePath.posInterval """
        return self._node.posInterval(*args, **kwargs)

    def setImage(self, img):
        """ Sets the current image """
        self._node.setImage(img)

    def setPos(self, x, y):
        """ Sets the position """
        self.initialPos = self.translatePos(x, y)
        self._node.setPos(self.initialPos)

    def translatePos(self, x, y):
        """ Converts 2d coordinates to pandas coordinate system """
        return Vec3(x + self.w / 2.0, 1, -y - self.h / 2.0)


    def hide(self):
        self._node.hide()

    def show(self):
        self._node.show()
class BetterOnscreenImage(DebugObject):
    """ Simple wrapper arroun OnscreenImage, providing a simpler interface and
    better visuals """
    def __init__(self,
                 image=None,
                 parent=None,
                 x=0,
                 y=0,
                 w=10,
                 h=10,
                 transparent=True,
                 nearFilter=True,
                 anyFilter=True):
        """ Creates a new image, taking (x,y) as topleft coordinates.

        When nearFilter is set to true, a near filter will be set to the
        texture passed. This provides sharper images.

        When anyFilter is set to false, the passed image won't be modified at
        all. This enables you to display existing textures, otherwise the
        texture would get a near filter in the 3D View, too. """

        DebugObject.__init__(self, "BetterOnscreenImage")

        self.w, self.h = w, h
        self.initialPos = self.translatePos(x, y)

        self._node = OnscreenImage(image=image,
                                   parent=parent,
                                   pos=self.initialPos,
                                   scale=(w / 2.0, 1, h / 2.0))

        if transparent:
            self._node.setTransparency(TransparencyAttrib.MAlpha)

        tex = self._node.getTexture()

        if nearFilter and anyFilter:
            tex.setMinfilter(Texture.FTNearest)
            tex.setMagfilter(Texture.FTNearest)

        if anyFilter:
            tex.setAnisotropicDegree(8)
            tex.setWrapU(Texture.WMClamp)
            tex.setWrapV(Texture.WMClamp)

    def getInitialPos(self):
        """ Returns the initial position of the image. This can be used for
        animations """
        return self.initialPos

    def posInterval(self, *args, **kwargs):
        """ Returns a pos interval, this is a wrapper around
        NodePath.posInterval """
        return self._node.posInterval(*args, **kwargs)

    def hprInterval(self, *args, **kwargs):
        """ Returns a hpr interval, this is a wrapper around
        NodePath.hprInterval """
        return self._node.hprInterval(*args, **kwargs)

    def setImage(self, img):
        """ Sets the current image """
        self._node.setImage(img)

    def setPos(self, x, y):
        """ Sets the position """
        self.initialPos = self.translatePos(x, y)
        self._node.setPos(self.initialPos)

    def translatePos(self, x, y):
        """ Converts 2d coordinates to pandas coordinate system """
        return Vec3(x + self.w / 2.0, 1, -y - self.h / 2.0)

    def remove(self):
        self._node.remove()

    def hide(self):
        self._node.hide()

    def show(self):
        self._node.show()