Exemplo n.º 1
0
class BracketTooltipRow(BracketTooltipRowBase):
    subLabel = None
    fleetBroadcastSprite = None
    fleetBroadcastType = None

    def ApplyAttributes(self, attributes):
        BracketTooltipRowBase.ApplyAttributes(self, attributes)
        self.selectedSprite = None
        if self.bracket.slimItem:
            selected, hilited = sm.GetService('state').GetStates(
                self.bracket.slimItem, [state.selected, state.mouseOver])
            self.SetSelected(selected)
            self.SetHilited(hilited)
        self.StartDynamicUpdates()

    def CreateIcon(self):
        self.iconObj = SpaceObjectIcon(state=uiconst.UI_DISABLED,
                                       pos=(0, 0, 16, 16),
                                       align=uiconst.CENTER,
                                       parent=self.iconParent)
        self.UpdateIcon()
        return self.iconObj

    def IsBracketStillValid(self):
        ball = self.bracket.ball
        slimItem = self.bracket.slimItem
        return ball or slimItem

    def UpdateIcon(self):
        if not self.bracket or self.bracket.destroyed:
            return
        ball = self.bracket.ball
        slimItem = self.bracket.slimItem
        if slimItem:
            self.iconObj.UpdateSpaceObjectIcon(slimItem, ball)
            self.iconObj.UpdateSpaceObjectIconColor(slimItem, ball)
            self.iconObj.UpdateSpaceObjectState(slimItem, ball)
            self.iconObj.UpdateSpaceObjectFlagAndBackgroundColor(
                slimItem, ball)
        else:
            iconNo = getattr(self.bracket, 'iconNo', None)
            if iconNo:
                self.iconObj.iconSprite.LoadIcon(iconNo)

    def SetSelected(self, selectedState):
        if selectedState:
            if not self.selectedSprite:
                self.selectedSprite = Sprite(
                    parent=self.iconObj,
                    pos=(0, 0, 30, 30),
                    name='selection',
                    state=uiconst.UI_DISABLED,
                    texturePath=
                    'res:/UI/Texture/classes/Bracket/selectionCircle.png',
                    align=uiconst.CENTER,
                    color=(1, 1, 1, 0.5))
            self.selectedSprite.display = True
        elif self.selectedSprite:
            self.selectedSprite.display = False

    def UpdateDynamicValues(self):
        if self.destroyed:
            return
        bracket = self.GetBracket()
        if not bracket or bracket.destroyed:
            self.dynamicsUpdateTimer = None
            return
        distance = None
        if getattr(bracket, 'showDistance', 1):
            distance = bracket.GetDistance()
            if distance:
                if not self.isCompact:
                    self.distanceLabel.text = FmtDist(distance)
        rightAligned = self.mainLabel.align != uiconst.CENTERLEFT
        fleetBroadcastType = getattr(bracket, 'fleetBroadcastType', None)
        if fleetBroadcastType:
            if fleetBroadcastType != self.fleetBroadcastType:
                self.fleetBroadcastType = fleetBroadcastType
                icon = fleetbr.types[fleetBroadcastType]['smallIcon']
                if not self.fleetBroadcastSprite:
                    self.fleetBroadcastSprite = Sprite(
                        parent=self.mainLabel,
                        pos=(0, 0, 16, 16),
                        state=uiconst.UI_NORMAL,
                        align=uiconst.CENTERLEFT,
                        idx=0)
                    self.fleetBroadcastSprite.DelegateEvents(self)
                self.fleetBroadcastSprite.LoadIcon(icon)
            if rightAligned:
                self.mainLabel.SetSideMargins(0, 18)
                self.fleetBroadcastSprite.align = uiconst.CENTERRIGHT
            else:
                self.mainLabel.SetSideMargins(18, 0)
        elif self.fleetBroadcastSprite:
            self.fleetBroadcastSprite.Close()
            self.fleetBroadcastSprite = None
            self.fleetBroadcastType = None
            self.mainLabel.SetSideMargins()
        tagAndTargetStr = getattr(bracket, 'tagAndTargetStr', None)
        subinfoString = None
        if hasattr(bracket, 'GetSubLabelCallback'):
            subinfoCallback = bracket.GetSubLabelCallback()
            if subinfoCallback:
                subinfoString = subinfoCallback()
        combinedString = ''
        if rightAligned:
            combinedString = '<right>'
        combinedString += bracket.displayName
        if self.isCompact and distance:
            combinedString += ' ' + FmtDist(distance)
        if subinfoString or tagAndTargetStr:
            combinedString += '<br>'
            if tagAndTargetStr:
                combinedString += '<b>' + tagAndTargetStr + '</b>'
            if subinfoString:
                if tagAndTargetStr:
                    combinedString += '  '
                combinedString += '[' + subinfoString + ']'
        self.mainLabel.text = combinedString
        self.iconParent.height = max(MINENTRYHEIGHT, self.mainLabel.height)
Exemplo n.º 2
0
 def Close(self, *args, **kw):
     if self.whileMouseDownFuncTasklet and self.whileMouseDownFuncTasklet.alive:
         self.whileMouseDownFuncTasklet.kill()
     self.whileMouseDownFuncTasklet = None
     Sprite.Close(self, *args, **kw)
Exemplo n.º 3
0
class CircularGraphSegment(VectorLineTrace):
    sizeFactor = 1.0
    pointer = None

    def ShowPointer(self):
        if self.pointer is None:
            self.pointer = Sprite(
                parent=self.parent,
                texturePath='res:/UI/Texture/classes/Graph/barPointer.png',
                pos=(0, 0, 15, 15),
                state=uiconst.UI_DISABLED,
                idx=0)
            self.UpdatePointer()

    def HidePointer(self):
        if self.pointer and not self.pointer.destroyed:
            self.pointer.Close()
            self.pointer = None

    def UpdatePointer(self):
        if not self.pointer:
            return
        x, y, angle = self.GetOuterCenterPointAndAngle()
        self.pointer.left = x - self.pointer.width / 2
        self.pointer.top = y - self.pointer.height / 2
        self.pointer.rotation = math.pi * 2 - angle

    def GetOuterCenterPointAndAngle(self):
        centerProportion = self.start + (self.end - self.start) / 2
        angle = centerProportion * math.pi * 2
        radius = self.width / 2
        x = radius * (1.0 + math.cos(angle + math.pi / 2))
        y = radius * (1.0 + math.sin(angle + math.pi / 2))
        return (self.width - x, self.height - y, angle)

    @apply
    def start():
        doc = '\n        Where to start drawing the line, as a proportion of the length of\n        the line path. Defaults to 0 to start at the start of the path.\n        '
        fget = VectorLineTrace.start.fget

        def fset(self, value):
            VectorLineTrace.start.fset(self, value)
            self.UpdatePointer()

        return property(**locals())

    @apply
    def end():
        doc = '\n        Where to stop drawing the line, as a proportion of the length of\n        the line path. Defaults to 1 to stop at the end of the path.\n        '
        fget = VectorLineTrace.end.fget

        def fset(self, value):
            VectorLineTrace.end.fset(self, value)
            self.UpdatePointer()

        return property(**locals())

    def GetTooltipPosition(self):
        xp, yp = self.GetAbsolutePosition()
        x, y, angle = self.GetOuterCenterPointAndAngle()
        return (x + xp, y + yp, 0, 0)

    def GetTooltipPointer(self):
        x, y, angle = self.GetOuterCenterPointAndAngle()
        x = x - self.width / 2
        y = y - self.height / 2
        if y > 0:
            if x > 0:
                return uiconst.POINT_TOPLEFT
            else:
                return uiconst.POINT_TOPRIGHT
        else:
            if x > 0:
                return uiconst.POINT_BOTTOMLEFT
            return uiconst.POINT_BOTTOMRIGHT
        return uiconst.POINT_TOP_2