Exemplo n.º 1
0
class NumberAttribute(SE_BaseClassCore):
    refreshDelay = 0.5

    def ApplyAttributes(self, attributes):
        SE_BaseClassCore.ApplyAttributes(self, attributes)
        left = Container(parent=self, align=uiconst.TOLEFT_PROP, width=0.5)
        right = Container(parent=self, align=uiconst.TOALL)
        self.label = Label(parent=left)
        self.value = Label(parent=right, autoUpdate=True)
        self.GetValue = None

    def Load(self, node):
        self.GetValue = node.getvalue
        self.label.SetText(node.text)
        self.UpdateValue()

    def UpdateValue(self):
        if self.GetValue:
            self.value.text = self.GetValue()
Exemplo n.º 2
0
class PreviewWnd(Window):
    __guid__ = 'form.PreviewWnd'
    default_windowID = 'previewWnd'
    default_topParentHeight = 0
    default_minSize = (420, 320)
    default_caption = localization.GetByLabel('UI/Preview/PreviewCaption')
    PANEL_WIDTH = 280

    def ApplyAttributes(self, attributes):
        Window.ApplyAttributes(self, attributes)
        itemID = attributes.itemID
        self.typeID = attributes.typeID
        subsystems = attributes.subsystems
        animate = attributes.animate
        width = self.PANEL_WIDTH if self.IsPanelExpanded() else 0
        self.sidePanel = Container(parent=self.sr.main,
                                   align=uiconst.TOLEFT,
                                   width=width,
                                   clipChildren=True)
        self.skinController = SkinPanelController(typeID=None)
        SkinPanel(parent=self.sidePanel,
                  align=uiconst.TOLEFT,
                  width=self.PANEL_WIDTH - 10,
                  left=10,
                  controller=self.skinController,
                  settingsPrefix='Preview_SkinPanel',
                  logContext='PreviewWindow')
        mainCont = Container(parent=self.sr.main,
                             align=uiconst.TOALL,
                             padding=(2, 0, 2, 2))
        opacity = 1.0 if self.IsPanelEnabled() else 0.0
        self.sidePanelButton = SidePanelButton(parent=mainCont,
                                               align=uiconst.CENTERLEFT,
                                               opacity=opacity,
                                               onClick=self.ToggleSidePanel,
                                               expanded=self.IsPanelExpanded())
        self.loadingWheel = LoadingWheel(parent=mainCont,
                                         align=uiconst.CENTER,
                                         state=uiconst.UI_DISABLED)
        self.previewContFill = FillThemeColored(parent=mainCont,
                                                align=uiconst.TOALL)
        overlayCont = Container(name='overlayCont',
                                parent=mainCont,
                                padding=2,
                                clipChildren=1)
        self.title = EveCaptionMedium(text='',
                                      parent=overlayCont,
                                      align=uiconst.TOTOP,
                                      padding=(17, 4, 17, 0),
                                      state=uiconst.UI_NORMAL)
        self.title.GetMenu = self.GetShipMenu
        self.title.expandOnLeft = 1
        self.subtitle = EveHeaderSmall(text='',
                                       parent=overlayCont,
                                       align=uiconst.TOTOP,
                                       padding=(19, 0, 17, 0),
                                       state=uiconst.UI_DISABLED)
        descLayer = Container(parent=mainCont)
        self.descCont = ContainerAutoSize(parent=descLayer,
                                          align=uiconst.TOBOTTOM,
                                          bgColor=(0.0, 0.0, 0.0, 0.3),
                                          padding=6,
                                          state=uiconst.UI_HIDDEN)
        self.desc = Label(parent=self.descCont,
                          padding=6,
                          fontsize=12,
                          align=uiconst.TOBOTTOM)
        self.previewContainer = PreviewContainer(
            parent=mainCont,
            OnStartLoading=self.OnStartLoading,
            OnStopLoading=self.OnStopLoading)
        self.previewContainer.navigation.OnDropData = self.OnDropData
        self.PreviewType(self.typeID, subsystems, itemID, animate)

    def IsPanelExpanded(self):
        return self.IsPanelEnabled() and settings.user.ui.Get(
            'previewPanel', 1)

    def IsPanelEnabled(self):
        return evetypes.GetCategoryID(
            self.typeID) == invconst.categoryShip or evetypes.GetGroupID(
                self.typeID) == invconst.groupShipSkins

    def ToggleSidePanel(self):
        isExpanded = not self.IsPanelExpanded()
        settings.user.ui.Set('previewPanel', isExpanded)
        self.UpdateSidePanel(isExpanded)

    def UpdateSidePanel(self, expanded=None):
        if expanded is None:
            expanded = settings.user.ui.Get('previewPanel', 1)
        width = self.PANEL_WIDTH if expanded else 0
        uicore.animations.MorphScalar(self.sidePanel,
                                      'width',
                                      startVal=self.sidePanel.width,
                                      endVal=width,
                                      duration=0.3)

    def OnStartLoading(self, previewCont):
        uicore.animations.FadeIn(self.loadingWheel, duration=0.4)
        uicore.animations.FadeIn(self.previewContFill,
                                 duration=0.2,
                                 sleep=True)
        self.ClearText()

    def OnStopLoading(self, previewCont, success):
        uicore.animations.FadeOut(self.loadingWheel, duration=0.2)
        if success:
            uicore.animations.FadeOut(self.previewContFill, duration=0.4)
            self.UpdateText()

    def UpdateText(self):
        context = self.previewContainer.context
        if not hasattr(context, 'typeID'):
            return
        groupID = evetypes.GetGroupID(context.typeID)
        categoryID = evetypes.GetCategoryID(context.typeID)
        title = evetypes.GetName(context.typeID)
        if hasattr(context, 'itemID'):
            bp = sm.GetService('michelle').GetBallpark()
            if bp:
                slim = bp.GetInvItem(context.itemID)
                if slim:
                    title = slim.name
        self.title.text = title
        subtitle = ''
        if categoryID != invconst.categoryApparel:
            scene = self.previewContainer.sceneContainer.scene
            model = first_or_default(getattr(scene, 'objects', []), None)
            if model:
                radius = round(model.GetBoundingSphereRadius() * 2, 0)
                if groupID in invconst.turretModuleGroups or groupID in invconst.turretAmmoGroups:
                    subtitle = localization.GetByLabel(
                        'UI/Preview/ShipSubLabelNoRace',
                        groupName=evetypes.GetGroupName(context.typeID),
                        length=FmtDist(radius))
                else:
                    raceID = evetypes.GetRaceID(context.typeID)
                    race = cfg.races.Get(
                        raceID) if raceID in cfg.races else None
                    if race is None:
                        subtitle = localization.GetByLabel(
                            'UI/Preview/ShipSubLabelNoRace',
                            groupName=evetypes.GetGroupName(context.typeID),
                            length=FmtDist(radius))
                    else:
                        raceName = localization.GetByMessageID(race.raceNameID)
                        subtitle = localization.GetByLabel(
                            'UI/Preview/ShipSubLabel',
                            raceName=raceName,
                            groupName=evetypes.GetGroupName(context.typeID),
                            length=FmtDist(radius))
        self.subtitle.text = subtitle
        if categoryID == invconst.categoryApparel:
            self.descCont.Show()
            description = evetypes.GetDescription(context.typeID) or ''
            description = re.sub('<b>|</b>|\\r', '', description)
            description = re.sub('\\n', '<br>', description)
            self.desc.text = description

    def GetShipMenu(self, *args):
        return sm.GetService('menu').GetMenuFormItemIDTypeID(
            None,
            self.typeID,
            ignoreMarketDetails=False,
            filterFunc=[localization.GetByLabel('UI/Preview/Preview')])

    def OnDropData(self, dragObj, nodes):
        super(PreviewWnd, self).OnDropData(dragObj, nodes)
        node = first(nodes)
        typeID = None
        if hasattr(node, 'item') and hasattr(node.item, 'typeID'):
            typeID = node.item.typeID
        elif hasattr(node, 'typeID'):
            typeID = node.typeID
        itemID = None
        if hasattr(node, 'item') and hasattr(node.item, 'itemID'):
            itemID = node.item.itemID
        elif hasattr(node, 'itemID'):
            itemID = node.itemID
        if typeID:
            self.PreviewType(typeID, itemID=itemID)

    def PreviewType(self, typeID, subsystems=None, itemID=None, animate=True):
        uthread.new(self._PreviewType, typeID, subsystems, itemID, animate)

    def _PreviewType(self, typeID, subsystems, itemID, animate):
        self.typeID = typeID
        self.BringToFront()
        if evetypes.GetCategoryID(typeID) == invconst.categoryApparel:
            self.SetMinSize([320, 470])
            self.SetMaxSize([800, 950])
        else:
            self.SetMinSize([660, 320])
            self.SetMaxSize([None, None])
        if not self.IsPanelEnabled():
            uicore.animations.FadeOut(self.sidePanelButton, duration=0.3)
            self.UpdateSidePanel(expanded=False)
        newScene = self.previewContainer.PreviewType(
            typeID,
            subsystems=subsystems,
            itemID=itemID,
            controller=getattr(self, 'skinController', None))
        if self.IsPanelEnabled():
            uicore.animations.FadeIn(self.sidePanelButton, duration=0.3)
            self.UpdateSidePanel()
        if IsModularShip(typeID):
            kv = KeyVal(typeID=typeID)
            wnd = AssembleShip.GetIfOpen('PreviewSubSystems')
            if wnd:
                wnd.UpdateShip(kv, self.previewContainer.context.subsystems)
            else:
                AssembleShip.Open(
                    windowID='PreviewSubSystems',
                    ship=kv,
                    groupIDs=None,
                    isPreview=True,
                    setselected=self.previewContainer.context.subsystems)
        else:
            self.CloseSubSystemWnd()
        if newScene and animate:
            self.previewContainer.AnimEntry()

    def ClearText(self):
        self.title.text = ''
        self.subtitle.text = ''
        self.desc.SetText('')
        self.descCont.Hide()

    def BringToFront(self):
        self.Maximize()
        wnd = AssembleShip.GetIfOpen(windowID='PreviewSubSystems')
        if wnd and wnd.parent.children.index(wnd) > 1:
            wnd.Maximize()

    def _OnResize(self, *args, **kw):
        self.previewContainer.UpdateViewPort()

    def CloseSubSystemWnd(self):
        AssembleShip.CloseIfOpen(windowID='PreviewSubSystems')

    def Close(self, setClosed=False, *args, **kwds):
        Window.Close(self, setClosed, *args, **kwds)
        self.CloseSubSystemWnd()
Exemplo n.º 3
0
class PreviewWnd(Window):
    __guid__ = 'form.PreviewWnd'
    default_windowID = 'previewWnd'
    default_topParentHeight = 0
    default_minSize = (420, 320)
    default_caption = localization.GetByLabel('UI/Preview/PreviewCaption')

    def ApplyAttributes(self, attributes):
        Window.ApplyAttributes(self, attributes)
        itemID = attributes.itemID
        self.typeID = attributes.typeID
        subsystems = attributes.subsystems
        animate = attributes.animate
        self.loadingWheel = LoadingWheel(parent=self.sr.main,
                                         align=uiconst.CENTER,
                                         state=uiconst.UI_DISABLED)
        self.previewContFill = FillThemeColored(parent=self.sr.main,
                                                align=uiconst.TOALL)
        overlayCont = Container(name='overlayCont',
                                parent=self.sr.main,
                                padding=2,
                                clipChildren=1)
        self.title = EveCaptionMedium(text='',
                                      parent=overlayCont,
                                      align=uiconst.TOTOP,
                                      padding=(17, 4, 17, 0),
                                      state=uiconst.UI_NORMAL)
        self.title.GetMenu = self.GetShipMenu
        self.title.expandOnLeft = 1
        self.subtitle = EveHeaderSmall(text='',
                                       parent=overlayCont,
                                       align=uiconst.TOTOP,
                                       padding=(19, 0, 17, 0),
                                       state=uiconst.UI_DISABLED)
        descLayer = Container(parent=self.sr.main)
        self.descCont = ContainerAutoSize(parent=descLayer,
                                          align=uiconst.TOBOTTOM,
                                          bgColor=(0.0, 0.0, 0.0, 0.3),
                                          padding=6,
                                          state=uiconst.UI_HIDDEN)
        self.desc = Label(parent=self.descCont,
                          padding=6,
                          fontsize=12,
                          align=uiconst.TOBOTTOM)
        self.previewContainer = PreviewContainer(
            parent=self.sr.main,
            OnStartLoading=self.OnStartLoading,
            OnStopLoading=self.OnStopLoading,
            padding=2)
        self.previewContainer.navigation.OnDropData = self.OnDropData
        self.PreviewType(self.typeID, subsystems, itemID, animate)

    def OnStartLoading(self, previewCont):
        uicore.animations.FadeIn(self.loadingWheel, duration=0.4)
        uicore.animations.FadeIn(self.previewContFill,
                                 duration=0.2,
                                 sleep=True)
        self.ClearText()

    def OnStopLoading(self, previewCont):
        if previewCont.loadingFailed:
            uicore.animations.FadeOut(self.loadingWheel, duration=0.2)
        else:
            uicore.animations.FadeOut(self.loadingWheel, duration=0.2)
            uicore.animations.FadeOut(self.previewContFill, duration=0.4)
            self.UpdateText()

    def UpdateText(self):
        context = self.previewContainer.context
        if not hasattr(context, 'typeID'):
            return
        typeInfo = cfg.invtypes.Get(context.typeID)
        title = typeInfo.name
        if hasattr(context, 'itemID'):
            bp = sm.GetService('michelle').GetBallpark()
            if bp:
                slim = bp.GetInvItem(context.itemID)
                if slim:
                    title = slim.name
        self.title.text = title
        if typeInfo.categoryID == invconst.categoryApparel:
            subtitle = ''
        else:
            scene = self.previewContainer.sceneContainer.scene
            model = first_or_default(getattr(scene, 'objects', []), None)
            if model:
                radius = round(model.GetBoundingSphereRadius() * 2, 0)
                if typeInfo.groupID in invconst.turretModuleGroups or typeInfo.groupID in invconst.turretAmmoGroups:
                    subtitle = localization.GetByLabel(
                        'UI/Preview/ShipSubLabelNoRace',
                        groupName=typeInfo.Group().groupName,
                        length=FmtDist(radius))
                else:
                    raceID = typeInfo.raceID
                    race = cfg.races.Get(
                        raceID) if raceID in cfg.races else None
                    if race is None:
                        subtitle = localization.GetByLabel(
                            'UI/Preview/ShipSubLabelNoRace',
                            groupName=typeInfo.Group().groupName,
                            length=FmtDist(radius))
                    else:
                        raceName = localization.GetByMessageID(race.raceNameID)
                        subtitle = localization.GetByLabel(
                            'UI/Preview/ShipSubLabel',
                            raceName=raceName,
                            groupName=typeInfo.Group().groupName,
                            length=FmtDist(radius))
        self.subtitle.text = subtitle
        if typeInfo.categoryID == invconst.categoryApparel:
            self.descCont.Show()
            description = typeInfo.description or ''
            description = re.sub('<b>|</b>|\\r', '', description)
            description = re.sub('\\n', '<br>', description)
            self.desc.text = description

    def GetShipMenu(self, *args):
        return sm.GetService('menu').GetMenuFormItemIDTypeID(
            None,
            self.typeID,
            ignoreMarketDetails=False,
            filterFunc=[localization.GetByLabel('UI/Preview/Preview')])

    def OnDropData(self, dragObj, nodes):
        super(PreviewWnd, self).OnDropData(dragObj, nodes)
        node = first(nodes)
        typeID = None
        if hasattr(node, 'item') and hasattr(node.item, 'typeID'):
            typeID = node.item.typeID
        elif hasattr(node, 'typeID'):
            typeID = node.typeID
        itemID = None
        if hasattr(node, 'item') and hasattr(node.item, 'itemID'):
            itemID = node.item.itemID
        elif hasattr(node, 'itemID'):
            itemID = node.itemID
        if typeID:
            self.PreviewType(typeID, itemID=itemID)

    def PreviewType(self, typeID, subsystems=None, itemID=None, animate=True):
        uthread.new(self._PreviewType, typeID, subsystems, itemID, animate)

    def _PreviewType(self, typeID, subsystems, itemID, animate):
        self.typeID = typeID
        self.BringToFront()
        typeInfo = cfg.invtypes.Get(typeID)
        if typeInfo.categoryID == invconst.categoryApparel:
            self.SetMinSize([320, 470])
            self.SetMaxSize([800, 950])
        else:
            self.SetMinSize([420, 320])
            self.SetMaxSize([None, None])
        newScene = self.previewContainer.PreviewType(typeID,
                                                     subsystems=subsystems,
                                                     itemID=itemID)
        if IsModularShip(typeID):
            kv = KeyVal(typeID=typeID)
            wnd = AssembleShip.GetIfOpen('PreviewSubSystems')
            if wnd:
                wnd.UpdateShip(kv, self.previewContainer.context.subsystems)
            else:
                AssembleShip.Open(
                    windowID='PreviewSubSystems',
                    ship=kv,
                    groupIDs=None,
                    isPreview=True,
                    setselected=self.previewContainer.context.subsystems)
        else:
            self.CloseSubSystemWnd()
        if newScene and animate:
            self.previewContainer.AnimEntry(-1.8, 0.2, -0.7, -0.3)

    def ClearText(self):
        self.title.text = ''
        self.subtitle.text = ''
        self.desc.SetText('')
        self.descCont.Hide()

    def BringToFront(self):
        self.Maximize()
        wnd = AssembleShip.GetIfOpen(windowID='PreviewSubSystems')
        if wnd and wnd.parent.children.index(wnd) > 1:
            wnd.Maximize()

    def _OnResize(self, *args, **kw):
        self.previewContainer.UpdateViewPort()

    def CloseSubSystemWnd(self):
        AssembleShip.CloseIfOpen(windowID='PreviewSubSystems')

    def Close(self, setClosed=False, *args, **kwds):
        Window.Close(self, setClosed, *args, **kwds)
        self.CloseSubSystemWnd()
Exemplo n.º 4
0
class AbilityIcon(Container):
    default_width = 48
    default_height = 48
    default_align = uiconst.TOPLEFT
    default_state = uiconst.UI_NORMAL
    tooltipPanelClassInfo = SquadronTooltipModuleWrapper()

    def ApplyAttributes(self, attributes):
        Container.ApplyAttributes(self, attributes)
        self.activeCurve = None
        self.activationPendingCurve = None
        self.deactivationCurve = None
        self.ramp_active = False
        self.buttonDisabled = False
        self.shipFighterState = GetShipFighterState()
        self.crimewatchSvc = sm.GetService('crimewatchSvc')
        self.innerCont = Container(name='innerCont',
                                   parent=self,
                                   align=uiconst.TOBOTTOM,
                                   height=self.height)
        self.stateLabel = EveLabelSmall(parent=self.innerCont,
                                        align=uiconst.CENTER)
        self.controller = attributes.controller
        self.slotID = self.controller.slotID
        self.fighterID = attributes.fighterID
        self.fighterTypeID = attributes.fighterTypeID
        ability = self.GetAbilityInfo()
        self.abilityNameID = ability.displayNameID
        iconID = ability.iconID
        self.abilityIcon = Icon(parent=self.innerCont,
                                align=uiconst.CENTER,
                                width=32,
                                height=32,
                                icon=iconID,
                                state=uiconst.UI_DISABLED)
        self.hilite = Sprite(
            parent=self.innerCont,
            name='hilite',
            width=44,
            height=44,
            align=uiconst.CENTER,
            state=uiconst.UI_DISABLED,
            texturePath='res:/UI/Texture/classes/ShipUI/slotHilite.png',
            blendMode=trinity.TR2_SBM_ADDX2)
        self.hilite.display = False
        bgSprite = Sprite(
            parent=self.innerCont,
            align=uiconst.CENTER,
            width=64,
            height=64,
            texturePath=
            'res:/UI/Texture/classes/ShipUI/Fighters/slotFighterAbility.png',
            state=uiconst.UI_DISABLED)
        self.abilityIcon.SetSize(32, 32)
        self.DrawQtyCont()
        self.DrawTimer()
        self.DrawCoolDownTimer()
        self.DrawSafetyGlow()
        self.targetMode = ability.targetMode
        abilityID = GetAbilityIDForSlot(self.fighterTypeID, self.slotID)
        effectID = GetDogmaEffectIDForAbilityID(abilityID)
        self.abilityEffect = cfg.dgmeffects.Get(effectID)
        self.OnAbilityStatusUpdated(self.fighterID, self.slotID)
        self.shipFighterState.signalOnAbilityActivationStatusUpdate.connect(
            self.OnAbilityStatusUpdated)

    def GetSafetyWarning(self):
        requiredSafetyLevel = self.GetRequiredSafetyLevel()
        if self.crimewatchSvc.CheckUnsafe(requiredSafetyLevel):
            return requiredSafetyLevel
        else:
            return None

    def GetRequiredSafetyLevel(self):
        requiredSafetyLevel = self.crimewatchSvc.GetRequiredSafetyLevelForEffect(
            self.abilityEffect)
        return requiredSafetyLevel

    def OnMouseEnter(self, *args):
        self.hilite.display = True
        requiredSafetyLevel = self.GetSafetyWarning()
        if requiredSafetyLevel is not None:
            if requiredSafetyLevel == const.shipSafetyLevelNone:
                color = crimewatchConst.Colors.Criminal
            else:
                color = crimewatchConst.Colors.Suspect
            self.safetyGlow.color.SetRGBA(*color.GetRGBA())
            self.safetyGlow.display = True

    def OnMouseExit(self, *args):
        self.hilite.display = False
        self.safetyGlow.display = False

    def DrawSafetyGlow(self):
        self.safetyGlow = Sprite(
            parent=self.innerCont,
            name='safetyGlow',
            width=64,
            height=64,
            padding=2,
            align=uiconst.CENTER,
            state=uiconst.UI_DISABLED,
            texturePath='res:/UI/Texture/classes/ShipUI/slotGlow.png',
            color=crimewatchConst.Colors.Yellow.GetRGBA())
        self.safetyGlow.display = False

    def DrawTimer(self):
        self.glow = Sprite(
            parent=self.innerCont,
            name='glow',
            width=64,
            height=64,
            padding=2,
            align=uiconst.CENTER,
            state=uiconst.UI_DISABLED,
            texturePath='res:/UI/Texture/classes/ShipUI/slotGlow.png',
            color=GLOWCOLOR)
        self.glow.display = False
        self.busy = Sprite(
            parent=self.innerCont,
            name='busy',
            width=64,
            height=64,
            padding=2,
            align=uiconst.CENTER,
            state=uiconst.UI_DISABLED,
            texturePath='res:/UI/Texture/classes/ShipUI/slotGlow.png',
            color=BUSYCOLOR)
        self.busy.display = False
        self.ramps = ShipModuleButtonRamps(parent=self.innerCont,
                                           idx=0,
                                           top=-8)
        self.ramps.display = False

    def DrawCoolDownTimer(self):
        self.coolDownRamps = ShipModuleReactivationTimer(parent=self.innerCont,
                                                         name='coolDown',
                                                         idx=-1)
        self.coolDownRamps.display = False

    def DrawQtyCont(self):
        self.quantityParent = Container(parent=self.innerCont,
                                        name='quantityParent',
                                        pos=(16, 6, 24, 10),
                                        align=uiconst.BOTTOMRIGHT,
                                        state=uiconst.UI_DISABLED,
                                        idx=0)
        self.chargeCountLabel = Label(text='',
                                      parent=self.quantityParent,
                                      fontsize=9,
                                      letterspace=1,
                                      left=3,
                                      width=30,
                                      state=uiconst.UI_DISABLED)
        underlay = Sprite(
            parent=self.quantityParent,
            align=uiconst.TOALL,
            state=uiconst.UI_DISABLED,
            texturePath=
            'res:/UI/Texture/classes/ShipUI/slotQuantityUnderlay.png',
            color=(0, 0, 0, 1))

    def GetAbilityInfo(self):
        ability = self.controller.GetAbilityInfo()
        return ability

    def OnAbilityStatusUpdated(self, fighterID, slotID):
        if fighterID == self.fighterID and slotID == self.slotID:
            abilityActivationStatus = self.shipFighterState.GetAbilityActivationStatus(
                self.fighterID, self.slotID)
            if abilityActivationStatus:
                if abilityActivationStatus.isPending:
                    self._StartActivationPendingAnimation()
                else:
                    self._StopActivationPendingAnimation()
                if abilityActivationStatus.isDeactivating:
                    self._StartDeactivationAnimation()
                else:
                    self._StopDeactivationAnimation()
                if not abilityActivationStatus.isPending and not abilityActivationStatus.isDeactivating:
                    self._StartActiveAnimation()
                    self.buttonDisabled = False
                else:
                    self._StopActiveAnimation()
                    self.buttonDisabled = True
                if abilityActivationStatus.startTime and abilityActivationStatus.durationMs:
                    self._StartCycleAnimation(
                        abilityActivationStatus.startTime,
                        abilityActivationStatus.durationMs)
                else:
                    self._StopCycleAnimation()
            else:
                self._StopActivationPendingAnimation()
                self._StopDeactivationAnimation()
                self._StopActiveAnimation()
                self._StopCycleAnimation()
                cooldown = self.shipFighterState.GetAbilityCooldown(
                    self.fighterID, self.slotID)
                if cooldown is not None:
                    self.buttonDisabled = True
                    uthread.new(self._StartCoolDownAnimation, cooldown)
                else:
                    self.buttonDisabled = False
            self._UpdateChargeCountLabel()

    def _UpdateChargeCountLabel(self):
        maxChargeCount = GetChargeCountForTypeAndSlot(self.fighterTypeID,
                                                      self.slotID)
        if maxChargeCount is not None:
            currentChargeCount = self.shipFighterState.GetAbilityChargeCount(
                self.fighterID, self.slotID)
            self.quantityParent.Show()
            self.chargeCountLabel.SetText(currentChargeCount)
        else:
            self.quantityParent.Hide()

    def _StartCycleAnimation(self, startTime, durationMs):
        if self.ramp_active:
            return
        uthread.new(self._StartCycleAnimationThread, startTime, durationMs)

    def _StartCycleAnimationThread(self, startTime, durationMs):
        duration = durationMs * MSEC
        self.ramp_active = True
        self.ramps.display = True
        self.coolDownRamps.display = False
        while self.ramp_active:
            now = blue.os.GetSimTime()
            portionDone = (now - startTime) / duration
            if portionDone > 1:
                iterations = int(portionDone)
                startTime += long(duration * iterations)
                portionDone -= iterations
            self.ramps.SetRampValues(portionDone)
            blue.pyos.synchro.Yield()

    def _StopCycleAnimation(self):
        self.ramp_active = False
        self.ramps.display = False

    def _StartCoolDownAnimation(self, cooldown):
        self.coolDownRamps.display = True
        startTime, endTime = cooldown
        coolDownTime = int(endTime - startTime)
        self.coolDownRamps.AnimateTimer(startTime, coolDownTime)
        if endTime <= blue.os.GetSimTime():
            self.coolDownRamps.display = False
            self.buttonDisabled = False

    def _StartActiveAnimation(self):
        self.glow.display = True
        self.activeCurve = animations.FadeTo(self.glow,
                                             loops=uiconst.ANIM_REPEAT,
                                             curveType=uiconst.ANIM_WAVE)
        animations.SyncPlayback(self.activeCurve)

    def _StopActiveAnimation(self):
        self.glow.display = False
        if self.activeCurve:
            self.activeCurve.Stop()
            self.activeCurve = None

    def _StartActivationPendingAnimation(self):
        self.activationPendingCurve = animations.FadeTo(
            self.abilityIcon,
            loops=uiconst.ANIM_REPEAT,
            curveType=uiconst.ANIM_WAVE)
        animations.SyncPlayback(self.activationPendingCurve)

    def _StopActivationPendingAnimation(self):
        if self.activationPendingCurve:
            self.activationPendingCurve.Stop()
            self.activationPendingCurve = None
        animations.FadeIn(self.abilityIcon)

    def _StartDeactivationAnimation(self):
        self.busy.display = True
        self.deactivationCurve = animations.FadeTo(self.busy,
                                                   loops=uiconst.ANIM_REPEAT,
                                                   curveType=uiconst.ANIM_WAVE)
        animations.SyncPlayback(self.deactivationCurve)

    def _StopDeactivationAnimation(self):
        self.busy.display = False
        if self.deactivationCurve:
            self.deactivationCurve.Stop()
            self.deactivationCurve = None

    def OnClick(self, *args):
        if self.buttonDisabled:
            return
        self.controller.OnAbilityClick(self.targetMode)

    def Close(self):
        self._StopActiveAnimation()
        self._StopActivationPendingAnimation()
        self._StopDeactivationAnimation()
        self.shipFighterState.signalOnAbilityActivationStatusUpdate.disconnect(
            self.OnAbilityStatusUpdated)
        super(AbilityIcon, self).Close()

    def OnMouseDown(self, *args):
        if self.buttonDisabled:
            return
        self.innerCont.top = 2

    def OnMouseUp(self, *args):
        if self.buttonDisabled:
            return
        self.innerCont.top = 0
Exemplo n.º 5
0
class SeasonCharacterSelectionSidebar(Container):
    default_align = uiconst.TORIGHT_NOPUSH
    default_width = SEASON_BAR_WIDTH
    season_container = None

    def ApplyAttributes(self, attributes):
        Container.ApplyAttributes(self, attributes)
        self.season_sidebar_fill = Fill(bgParent=self,
                                        color=SEASON_BAR_BACKGROUND_COLOR)
        self.redeemable_items_panel_height = attributes.redeemable_items_panel_height
        self.hide_season = True if trinity.device.width < MINIMUM_SCREEN_WIDTH else False
        self.season_sidebar_fill.display = not self.hide_season

    def load_data(self):
        self.season_service = sm.GetService('seasonService')
        self._construct_season_header()
        self._construct_floating_news()
        self._construct_season_expander()
        self.clock.update_clock()
        self.floating_news_thread = None
        self._construct_season()

    def _construct_season_header(self):
        season_header_container = Container(name='season_header_container',
                                            parent=self,
                                            align=uiconst.TOTOP,
                                            height=SEASON_TITLE_HEIGHT)
        add_base_border_line_to_container(season_header_container,
                                          uiconst.TOLEFT)
        add_base_border_line_to_container(season_header_container,
                                          uiconst.TOBOTTOM)
        season_header_content_container = Container(
            name='season_header_container',
            parent=season_header_container,
            align=uiconst.TOTOP,
            height=season_header_container.height)
        fill_default_background_color_for_container(
            season_header_content_container)
        Fill(bgParent=season_header_content_container,
             color=SEASONS_THEME_BACKGROUND_COLOR)
        season_top_container = Container(
            name='season_top_container',
            parent=season_header_content_container,
            align=uiconst.TOTOP,
            height=SEASON_TITLE_HEIGHT)
        Line(parent=season_top_container, align=uiconst.TOBOTTOM, weight=1)
        scope_logo_container = Container(name='scope_logo_container',
                                         parent=season_top_container,
                                         align=uiconst.TOLEFT,
                                         width=SCOPE_LOGO_WIDTH,
                                         padBottom=SEASON_BASE_PADDING,
                                         padLeft=SEASON_BASE_PADDING)
        Sprite(name='scope_logo',
               parent=scope_logo_container,
               texturePath=season_client_const.SCOPE_LOGO_RES_PATH,
               align=uiconst.TOALL)
        clock_container = Container(name='clock_container',
                                    parent=season_top_container,
                                    align=uiconst.TORIGHT,
                                    width=CLOCK_WIDTH)
        self.clock = InGameClock(parent=clock_container,
                                 align=uiconst.TOALL,
                                 label_font_size=CLOCK_LABEL_SIZE)
        scope_title_container = Container(name='scope_title_container',
                                          parent=season_top_container,
                                          align=uiconst.TOTOP,
                                          height=SEASON_TITLE_LABEL_HEIGHT,
                                          padLeft=SEASON_BASE_PADDING,
                                          padTop=SEASON_BASE_PADDING)
        EveLabelLargeBold(name='scope_title_label',
                          parent=scope_title_container,
                          text=season_client_const.get_seasons_title())
        scope_title_description_container = Container(
            name='scope_title_description_container',
            parent=season_top_container,
            align=uiconst.TOTOP,
            height=SEASON_TITLE_DESCRIPTION_HEIGHT,
            padLeft=SEASON_BASE_PADDING)
        Label(name='scope_title_description_label',
              parent=scope_title_description_container,
              text=season_client_const.get_seasons_subcaption(),
              align=uiconst.TOPLEFT,
              fontsize=10)

    def _construct_floating_news(self):
        self.season_floating_news_container = Container(
            name='season_floating_news_container',
            parent=self,
            align=uiconst.TOTOP,
            height=FLOATING_NEWS_HEIGHT,
            clipChildren=True)
        add_base_border_line_to_container(self.season_floating_news_container,
                                          uiconst.TOLEFT)
        add_base_border_line_to_container(self.season_floating_news_container,
                                          uiconst.TOBOTTOM)
        self.season_floating_news_content_container = Container(
            name='season_floating_news_container',
            parent=self.season_floating_news_container,
            align=uiconst.TOTOP,
            height=self.season_floating_news_container.height)
        Fill(bgParent=self.season_floating_news_content_container,
             color=SEASONS_THEME_BACKGROUND_COLOR)
        self.floating_news_thread = uthread.new(self._float_the_news)

    def _construct_float_news_label(self):
        self.season_floating_news_content_container.Flush()
        self.floating_news_label = Label(
            name='floating_news_label',
            parent=self.season_floating_news_content_container,
            align=uiconst.CENTERLEFT)
        self.floating_news_label.color = FLOATING_NEWS_COLOR

    def _float_the_news(self):
        news = self.season_service.get_season_news()
        while not self.destroyed:
            for newsString in news:
                self._construct_float_news_label()
                self.floating_news_label.SetText(newsString)
                width_factor = float(
                    self.floating_news_label.width) / float(SEASON_BAR_WIDTH)
                animation_duration = FLOATING_NEWS_ANIMATION_DURATION * width_factor
                animations.MoveInFromRight(
                    self.floating_news_label,
                    SEASON_BAR_WIDTH,
                    curveType=uiconst.ANIM_LINEAR,
                    duration=FLOATING_NEWS_ANIMATION_DURATION,
                    sleep=True)
                animations.MoveOutLeft(self.floating_news_label,
                                       self.floating_news_label.width,
                                       curveType=uiconst.ANIM_LINEAR,
                                       duration=animation_duration,
                                       sleep=True)

    def _construct_season_expander(self):
        expander_container = Container(name='expander_container',
                                       parent=self,
                                       align=uiconst.TOTOP,
                                       height=SEASON_EXPANDER_HEIGHT)
        add_base_border_line_to_container(expander_container, uiconst.TOLEFT)
        self.expander_bottom_line = Line(
            parent=expander_container,
            align=uiconst.TOBOTTOM,
            weight=SEASON_DEFAULT_BORDER_LINE_WEIGHT,
            color=SEASON_DEFAULT_BORDER_LINE_COLOR,
            state=uiconst.UI_HIDDEN)
        expander_content_container = Container(
            name='expander_container',
            parent=expander_container,
            align=uiconst.TOTOP,
            height=expander_container.height,
            state=uiconst.UI_NORMAL)
        fill_default_background_color_for_container(expander_content_container)
        EveLabelMediumBold(name='expander_label',
                           parent=expander_content_container,
                           text=SEASON_EXPANDER_LABEL_TEXT,
                           align=uiconst.CENTERLEFT,
                           padLeft=SEASON_BASE_PADDING)
        expander_sprite_container = Container(
            name='expander_sprite_container',
            parent=expander_content_container,
            align=uiconst.TORIGHT,
            width=SEASON_EXPANDER_SPRITE_SIZE,
            padRight=SEASON_BASE_PADDING)
        self.expander_sprite = Sprite(
            name='expander_sprite',
            parent=expander_sprite_container,
            texturePath=SEASON_EXPANDER_ARROW_RES_PATH,
            align=uiconst.CENTER,
            width=SEASON_EXPANDER_SPRITE_SIZE,
            height=SEASON_EXPANDER_SPRITE_SIZE)
        expander_content_container.OnClick = self._toggle_display_season
        self.expander_sprite.OnClick = self._toggle_display_season

    def _toggle_display_season(self):
        if not self.season_container:
            self.expander_bottom_line.Hide()
            self._construct_season()
            return
        if self.season_container.display:
            self.expander_sprite.rotation = math.pi
            uicore.animations.FadeOut(self.season_container,
                                      duration=PANEL_FADE_DURATION)
            self.expander_bottom_line.Show()
        self.season_container.display = not self.season_container.display
        self.season_sidebar_fill.display = not self.season_sidebar_fill.display
        if self.season_container.display:
            self.expander_sprite.rotation = 0
            self.expander_bottom_line.Hide()
            uicore.animations.FadeIn(self.season_container,
                                     duration=PANEL_FADE_DURATION)

    def _construct_season(self):
        if self.season_container and not self.season_container.destroyed:
            return
        self.season_container = Container(
            name='season_container',
            parent=self,
            align=uiconst.TOTOP,
            height=uicore.desktop.height - SEASON_TITLE_HEIGHT -
            FLOATING_NEWS_HEIGHT - SEASON_EXPANDER_HEIGHT -
            CHALLENGE_ADDITIONAL_PADDING,
            bgColor=util.Color.BLACK if self.hide_season else None,
            opacity=0 if self.hide_season else 1)
        self.season_container.display = not self.hide_season
        self.expander_bottom_line.display = self.hide_season
        add_base_border_line_to_container(self.season_container,
                                          uiconst.TOLEFT)
        add_base_border_line_to_container(self.season_container,
                                          uiconst.TOBOTTOM)
        self.season_container_scroll = ScrollContainer(
            name='season_container_scroll',
            parent=self.season_container,
            align=uiconst.TOTOP,
            height=self.season_container.height)
        self._construct_season_details(
            parent_container=self.season_container_scroll)
        self._construct_challenges(
            parent_container=self.season_container_scroll)

    def _construct_season_details(self, parent_container):
        CurrentEvent(name='season_details_container',
                     parent=parent_container,
                     season_service=self.season_service,
                     align=uiconst.TOTOP,
                     width=SEASON_BAR_WIDTH - 2 * SEASON_DETAILS_PADDING -
                     SCROLL_PADDING,
                     height=SEASON_DETAILS_HEIGHT,
                     padding=SEASON_DETAILS_PADDING)

    def _construct_challenges(self, parent_container):
        challenges_container = Container(name='challenges_container',
                                         parent=parent_container,
                                         align=uiconst.TOTOP,
                                         height=CHALLENGE_ADDITIONAL_PADDING,
                                         padTop=CHALLENGES_PAD_TOP)
        challenges_content_container = ContainerAutoSize(
            name='challenges_content_container',
            parent=challenges_container,
            align=uiconst.TOTOP,
            height=challenges_container.height)
        challenges_header_container = Container(
            name='challenges_header_container',
            parent=challenges_content_container,
            align=uiconst.TOTOP,
            height=CHALLENGES_HEADER_LABEL_HEIGHT,
            padBottom=CHALLENGES_HEADER_PAD_BOT)
        fill_header_background_color_for_container(challenges_header_container)
        Label(name='challenges_label',
              parent=challenges_header_container,
              align=uiconst.TOTOP,
              text=CHALLENGES_HEADER_LABEL_TEXT,
              bold=True,
              fontize=CHALLENGES_HEADER_FONTSIZE,
              padTop=CHALLENGES_HEADER_PAD_TOP,
              padLeft=SEASON_BASE_PADDING)
        challenges = self.season_service.get_challenges_for_last_active_character(
        )
        challenge_width = SEASON_BAR_WIDTH - CHALLENGE_PROGRESS_BAR_PADDING - 2 * CHALLENGE_PADDING
        for challenge in challenges.itervalues():
            challenge_height, title_text_height, description_text_height = calculate_challenge_height(
                challenge, challenge_width)
            challenge_task_entry_container = Container(
                name='challenge_task_entry_container',
                parent=challenges_content_container,
                align=uiconst.TOTOP,
                width=challenge_width,
                height=challenge_height,
                padding=CHALLENGE_PADDING)
            ChallengeTaskEntry(
                name='challengetaskentry_%s' % challenge.challenge_id,
                parent=challenge_task_entry_container,
                align=uiconst.TOTOP,
                width=challenge_width,
                height=challenge_height,
                challenge=challenge,
                challenge_title_height=title_text_height,
                challenge_description_height=description_text_height,
                progress_frame_width=challenge_width,
                progress_frame_width_reduction=
                CHALLENGE_PROGRESS_FRAME_WIDTH_REDUCTION,
                padBottom=CHALLENGE_BOTTOM_PADDING)
            challenges_container.height += challenge_height + CHALLENGE_BOTTOM_PADDING

    def reconstruct_season(self):
        if self.season_container and not self.season_container.destroyed:
            self._remove_season()
        else:
            self._construct_season()

    def _remove_season(self):
        if self.season_container and not self.season_container.destroyed:
            self.expander_bottom_line.Show()
            season_container = self.season_container
            self.season_container = None
            uicore.animations.FadeOut(season_container,
                                      duration=PANEL_FADE_DURATION)
            uicore.animations.MorphScalar(season_container,
                                          'height',
                                          season_container.height,
                                          0,
                                          duration=PANEL_FADE_DURATION,
                                          callback=season_container.Close)