示例#1
0
 def PopulateScheduleColumn(self):
     self.scheduleColumn.Flush()
     vulnerableHoursThisWeek = self.controller.GetCurrentSchedule()
     vulnerableHoursNextWeek = self.controller.GetNextWeekSchedule()
     isSameSchedule = vulnerableHoursThisWeek == vulnerableHoursNextWeek
     s = SmallSchedule(parent=self.scheduleColumn,
                       align=uiconst.CENTERLEFT,
                       vulnerableHours=vulnerableHoursThisWeek,
                       state=uiconst.UI_NORMAL,
                       left=6)
     s.DelegateEvents(self)
     if not isSameSchedule:
         texturePath = 'res:/UI/Texture/classes/StructureBrowser/notSameSchedule.png'
         hint = GetByLabel('UI/Structures/Browser/NotSameScheduleHint')
         diffSprite = Sprite(name='notSameSchedule',
                             parent=self.scheduleColumn,
                             align=uiconst.CENTERRIGHT,
                             pos=(2, 2, 16, 16),
                             iconSize=16,
                             texturePath=texturePath,
                             opacity=0.75,
                             hint=hint)
         diffSprite.DelegateEvents(self)
     s.LoadTooltipPanel = self.LoadScheduleToolTip
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)