Beispiel #1
0
    def drawChatBalloon(self, model, modelWidth, modelHeight):
        if self.chatFont is None:
            # We can't draw this without a font.
            return

        if self.isClickable():
            foreground, background = self.chatColor[self.clickState]
        else:
            foreground, background = self.chatColor[PGButton.SInactive]
        if self.chatType == NametagGlobals.SPEEDCHAT:
            background = self.speedChatColor
        if background[3] > self.CHAT_BALLOON_ALPHA:
            background = VBase4(
                background[0], background[1], background[2],
                self.CHAT_BALLOON_ALPHA)
        self.chatBalloon = ChatBalloon(
            model, modelWidth, modelHeight, self.chatTextNode,
            foreground=foreground, background=background,
            reversed=self.chatReversed,
            button=self.chatButton[self.clickState])
        self.chatBalloon.reparentTo(self.contents)
        
        self.cTag.set_chatballoon_size(self.chatBalloon.width, self.chatBalloon.height)
        
        if not base.config.GetBool('want-nametags', True):
            self.contents.show()
Beispiel #2
0
    def drawChatBalloon(self, model, modelWidth, modelHeight):
        if self.chatFont is None:
            # We can't draw this without a font.
            return

        # Prefix the nametag text:
        if hasattr(self.avatar, 'avatarType'
                   ) and self.avatar.avatarType == CIGlobals.Suit and len(
                       self.getText().split('\n')) == 3:
            # Just show the cog's name
            name, _, _ = self.getText().split('\n')
        else:
            name = self.getText()
        self.chatTextNode.setText(name + ': ' + self.actualChatText)

        # Set our priority in the margin system:
        self.setPriority(MarginGlobals.MP_normal)

        if self.textNodePath is not None:
            self.textNodePath.removeNode()
            self.textNodePath = None

        if self.arrow is not None:
            self.arrow.removeNode()
            self.arrow = None

        if self.isClickable():
            foreground, background = self.chatColor[self.clickState]
        else:
            foreground, background = self.chatColor[PGButton.SInactive]
        if self.chatType == NametagGlobals.SPEEDCHAT:
            background = self.speedChatColor
        if background[3] > self.CHAT_BALLOON_ALPHA:
            background = VBase4(background[0], background[1], background[2],
                                self.CHAT_BALLOON_ALPHA)
        self.chatBalloon = ChatBalloon(model,
                                       modelWidth,
                                       modelHeight,
                                       self.chatTextNode,
                                       foreground=foreground,
                                       background=background,
                                       reversed=self.chatReversed,
                                       button=self.chatButton[self.clickState],
                                       is2d=True)
        self.chatBalloon.reparentTo(self.contents)

        #self.cTag.set_chatballoon_size(self.chatBalloon.width, self.chatBalloon.height)

        # Calculate the center of the TextNode:
        left, right, bottom, top = self.chatTextNode.getFrameActual()
        center = self.contents.getRelativePoint(self.chatBalloon.textNodePath,
                                                ((left + right) / 2.0, 0,
                                                 (bottom + top) / 2.0))

        # Translate the chat balloon along the inverse:
        self.chatBalloon.setPos(self.chatBalloon, -center)
    def setChatAbsolute(self, chatString=None):
        if not chatString or chatString.isspace() or len(chatString) == 0:
            return

        self.clearChat()
        self.taskId = random.randint(0, 1000000000000000000000000000000)
        if self.nameTag:
            self.getNameTag().hide()

        if self.isThought(chatString):
            chatString = self.removeThoughtPrefix(chatString)
            bubble = loader.loadModel(CIGlobals.ThoughtBubble)
        else:
            length = math.sqrt(len(chatString)) / self.LENGTH_FACTOR
            if length < self.MIN_LENGTH:
                length = self.MIN_LENGTH
            if length > self.MAX_LENGTH:
                length = self.MAX_LENGTH
            bubble = loader.loadModel(CIGlobals.ChatBubble)
            if self.autoClearChat:
                taskMgr.doMethodLater(
                    length, self.clearChatTask,
                    "clearAvatarChat-%s" % (str(self.taskId)))

        if self.avatarType == CIGlobals.Suit:
            font = CIGlobals.getSuitFont()
        else:
            font = CIGlobals.getToonFont()

        self.chatBubble = ChatBalloon(bubble).generate(chatString, font)
        self.chatBubble.setEffect(
            BillboardEffect.make(Vec3(0, 0, 1), True, False, 3.0, camera,
                                 Point3(0, 0, 0)))
        if self.nameTag:
            self.chatBubble.setZ(self.getNameTag().getZ())
        else:
            if self.avatarType == CIGlobals.Suit:
                nametagZ = self.suitPlan.getNametagZ()
                self.chatBubble.setZ(nametagZ)

        if self.avatar and hasattr(self.avatar, 'getGhost'):
            if not self.avatar.getGhost(
            ) or self.avatar.doId == base.localAvatar.doId:
                self.chatBubble.reparentTo(self)
        else:
            self.chatBubble.reparentTo(self)

        LabelScaler().resize(self.chatBubble)
    def draw(self):
        if self.isClickable():
            foreground, background = self.whisperColor[self.clickState]
        else:
            foreground, background = self.whisperColor[PGButton.SInactive]
        self.chatBalloon = ChatBalloon(
            NametagGlobals.chatBalloon2dModel,
            NametagGlobals.chatBalloon2dWidth,
            NametagGlobals.chatBalloon2dHeight, self.textNode,
            foreground=foreground, background=background,
            is2d=True
        )
        self.chatBalloon.reparentTo(self.contents)

        # Calculate the center of the TextNode:
        left, right, bottom, top = self.textNode.getFrameActual()
        center = self.contents.getRelativePoint(
            self.chatBalloon.textNodePath,
            ((left+right) / 2.0, 0, (bottom+top) / 2.0))

        # Translate the chat balloon along the inverse:
        self.chatBalloon.setPos(self.chatBalloon, -center)

        # Draw the quit button:
        self.quitButton = WhisperQuitButton(self)
        quitButtonNodePath = self.contents.attachNewNode(self.quitButton)

        # Move the quit button to the top right of the TextNode:
        quitButtonNodePath.setPos(self.contents.getRelativePoint(
            self.chatBalloon.textNodePath, (right, 0, top)))

        # Apply the quit button shift:
        quitButtonNodePath.setPos(quitButtonNodePath, self.QUIT_BUTTON_SHIFT)

        # Allow the quit button to close this whisper:
        self.quitButton.setClickEvent(self.quitEvent)