def __init__(self):
        Nametag.__init__(self)
        Clickable3d.__init__(self, 'Nametag3d')
        
        self.contents.setShaderOff(1)
        self.contents.setLightOff(1)
        self.contents.hide(CIGlobals.ShadowCameraBitmask)
        CIGlobals.applyNoGlow(self.contents)

        self.distance = 0

        self.card = None
        self.cardNP = None

        self.avatarNode = None

        self.billboardOffset = 3
        self.doBillboardEffect()
예제 #2
0
    def __init__(self,
                 model,
                 modelWidth,
                 modelHeight,
                 textNode,
                 foreground=VBase4(0, 0, 0, 1),
                 background=VBase4(1, 1, 1, 1),
                 reversed=False,
                 button=None,
                 is2d=False):
        NodePath.__init__(self, 'chatBalloon')
        # We don't want chat bubbles to glow from the bloom filter, it looks terrible.
        CIGlobals.applyNoGlow(self)

        self.setLightOff(1)
        self.hide(CIGlobals.ShadowCameraBitmask)

        self.model = model
        self.modelWidth = modelWidth
        self.modelHeight = modelHeight
        self.textNode = textNode
        self.foreground = foreground
        self.background = background
        self.button = button
        self.is2d = is2d

        # Set the TextNode color:
        self.textNode.setTextColor(self.foreground)

        # Create a balloon:
        self.balloon = self.model.copyTo(self)
        self.balloon.setColor(self.background)
        self.balloon.setTransparency(self.background[3] < 1)
        if is2d:
            # Don't use the black outline on 2d chat balloons (old toontown).
            self.balloon.setTextureOff(1)
            self.balloon.setShaderOff(1)
        else:
            self.balloon.setShaderAuto(2)

        # Attach the TextNode:
        self.textNodePath = self.attachNewNode(self.textNode.generate())
        self.textNodePath.setTransparency(self.foreground[3] < 1)
        self.textNodePath.setAttrib(DepthWriteAttrib.make(0))
        self.textNodePath.setShaderOff(1)

        # Resize the balloon as necessary:
        middle = self.balloon.find('**/middle')
        top = self.balloon.find('**/top')
        self.textWidth = self.textNode.getWidth()
        if self.textWidth < self.TEXT_MIN_WIDTH:
            self.textWidth = self.TEXT_MIN_WIDTH
        paddedWidth = self.textWidth + (self.BALLOON_X_PADDING * 2)
        self.balloon.setSx(paddedWidth / modelWidth)
        self.textHeight = textNode.getHeight()
        if self.textHeight < self.TEXT_MIN_HEIGHT:
            self.textHeight = self.TEXT_MIN_HEIGHT
        paddedHeight = self.textHeight + (self.BALLOON_Z_PADDING * 2)
        middle.setSz(paddedHeight - 1.5)  # Compensate for the top, as well.
        top.setZ(middle, 1)

        if reversed:
            self.balloon.setSx(-self.balloon.getSx())
            self.balloon.setTwoSided(
                True)  # Render the backface of the balloon.

        self.width = paddedWidth
        self.height = paddedHeight

        # Position the TextNode:
        self.center = self.balloon.getBounds().getCenter()
        self.textNodePath.setPos(self.center)
        self.textNodePath.setY(self.TEXT_Y_OFFSET)
        self.textNodePath.setX(self.textNodePath, -(self.textWidth / 2))
        if self.textWidth == self.TEXT_MIN_WIDTH:
            centerX = (self.TEXT_MIN_WIDTH - self.textNode.getWidth()) / 2.0
            self.textNodePath.setX(self.textNodePath, centerX)
        self.textNodePath.setZ(top,
                               -self.BALLOON_Z_PADDING + self.TEXT_Z_OFFSET)
        if self.textHeight == self.TEXT_MIN_HEIGHT:
            centerZ = (ChatBalloon.TEXT_MIN_HEIGHT -
                       self.textNode.getHeight()) / 2.0
            self.textNodePath.setZ(self.textNodePath, -centerZ)
        self.textNodePath.setX(self.textNodePath, self.TEXT_X_OFFSET)

        # Add a button if one is given:
        if self.button is not None:
            self.buttonNodePath = button.copyTo(self)
            self.buttonNodePath.setPos(self.textNodePath, self.textWidth, 0,
                                       -self.textHeight)
            self.buttonNodePath.setPos(self.buttonNodePath,
                                       ChatBalloon.BUTTON_SHIFT)
            self.buttonNodePath.setScale(ChatBalloon.BUTTON_SCALE)
        else:
            self.buttonNodePath = None

        # Finally, enable anti-aliasing:
        self.setAntialias(AntialiasAttrib.MMultisample)