NovaBryan/EVE_Dump
Log | Files | 📦 下载最新源码 (.zip) | Refs | README

careerPortalBackground.py (7028B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\careerPortal\careerPortalBackground.py
      2 import math
      3 import carbonui.const as uiconst
      4 import trinity
      5 import uthread2
      6 from carbonui.primitives.container import Container
      7 from carbonui.primitives.fill import Fill
      8 from carbonui.primitives.sprite import Sprite
      9 from carbonui.uianimations import animations
     10 from eve.client.script.ui import eveColor
     11 from eve.client.script.ui.shared.careerPortal import careerConst, cpSignals
     12 HOVER_TRANSITION_DURATION = 0.3
     13 DEFAULT_BACKGROUND = 'res:/UI/Texture/classes/careerPortal/backgrounds/hangar_background_bright.png'
     14 
     15 class CareerPortalBackground(Container):
     16     default_clipChildren = True
     17     default_align = uiconst.CENTER
     18     default_state = uiconst.UI_DISABLED
     19 
     20     def ApplyAttributes(self, attributes):
     21         super(CareerPortalBackground, self).ApplyAttributes(attributes)
     22         self.PrepareUI()
     23         self._connect_signals()
     24 
     25     def Close(self):
     26         self._disconnect_signals()
     27         super(CareerPortalBackground, self).Close()
     28 
     29     def _connect_signals(self):
     30         careerConst.SELECTED_CAREER_PATH_SETTING.on_change.connect(self.SwitchToCareerBackground)
     31         careerConst.CAREER_WINDOW_STATE_SETTING.on_change.connect(self.OnCareerWindowStateChanged)
     32         cpSignals.on_career_node_hover_on.connect(self.OnCareerNodeHoverOn)
     33         cpSignals.on_career_node_hover_off.connect(self.OnCareerNodeHoverOff)
     34         self.on_size_changed.connect(self._on_size_changed)
     35 
     36     def _disconnect_signals(self):
     37         careerConst.SELECTED_CAREER_PATH_SETTING.on_change.disconnect(self.SwitchToCareerBackground)
     38         careerConst.CAREER_WINDOW_STATE_SETTING.on_change.disconnect(self.OnCareerWindowStateChanged)
     39         cpSignals.on_career_node_hover_on.disconnect(self.OnCareerNodeHoverOn)
     40         cpSignals.on_career_node_hover_off.disconnect(self.OnCareerNodeHoverOff)
     41         self.on_size_changed.disconnect(self._on_size_changed)
     42 
     43     def _on_size_changed(self, width, height):
     44         self.SetSize(width, height)
     45 
     46     def PrepareUI(self):
     47         Fill(bgParent=self, name='blackFill', color=eveColor.BLACK, opacity=0.95)
     48         self.airLogo = Sprite(parent=self, name='airLogo', align=uiconst.TOPLEFT, texturePath='res:/UI/Texture/classes/careerPortal/backgrounds/air_logo.png', width=153, height=20, top=32, left=32, color=eveColor.AIR_TURQUOISE, outputMode=uiconst.OUTPUT_COLOR_AND_GLOW, glowBrightness=0.4)
     49         self.circleBg = Sprite(parent=self, name='circleBg', align=uiconst.CENTER, texturePath='res:/UI/Texture/classes/careerPortal/backgrounds/bg_detail.png')
     50         self.bgHighlights = BackgroundHighlights(parent=self, name='bgDetail', align=uiconst.CENTER)
     51         self.largeDottedLine = Sprite(parent=self, name='largeDottedLine', align=uiconst.CENTER, texturePath='res:/UI/Texture/classes/careerPortal/backgrounds/bg_dottedLine.png', textureSecondaryPath='res:/UI/Texture/classes/careerPortal/backgrounds/bg_lineMask.png', spriteEffect=trinity.TR2_SFX_MODULATE)
     52         self.smallDottedLine = Sprite(parent=self, name='smallDottedLine', align=uiconst.CENTER, texturePath='res:/UI/Texture/classes/careerPortal/backgrounds/bg_dottedLine.png', textureSecondaryPath='res:/UI/Texture/classes/careerPortal/backgrounds/bg_lineMask.png', spriteEffect=trinity.TR2_SFX_MODULATE, opacity=0.5)
     53         self.backgroundSprite = Sprite(parent=self, name='backgroundSprite', align=uiconst.CENTER, opacity=0.4, texturePath=DEFAULT_BACKGROUND)
     54         self._StartRotation()
     55         self._RevealCareerBackground(careerConst.SELECTED_CAREER_PATH_SETTING.get())
     56 
     57     def SetSize(self, width, height):
     58         self.UpdateSize(width, height)
     59 
     60     def UpdateSize(self, width, height):
     61         self.circleBg.SetSize(width, width)
     62         self.bgHighlights.SetSize(width, width)
     63         self.largeDottedLine.SetSize(width, width)
     64         smallDottedLineWidth = width / 1.6
     65         self.smallDottedLine.SetSize(smallDottedLineWidth, smallDottedLineWidth)
     66         self.smallDottedLine.scaleSecondary = (0.7, 0.7)
     67         bgWidth = height * 1.7778
     68         self.backgroundSprite.SetSize(bgWidth, height)
     69 
     70     def OnCareerWindowStateChanged(self, state):
     71         width = self.parent.displayWidth
     72         height = self.parent.displayHeight
     73         self.UpdateSize(width, height)
     74         self.bgHighlights.StopAllHighlights()
     75 
     76     def SwitchToCareerBackground(self, careerID):
     77         animations.FadeOut(self.backgroundSprite, duration=0.4, callback=lambda : self._RevealCareerBackground(careerID))
     78 
     79     def _RevealCareerBackground(self, careerID):
     80         texturePath = careerConst.BG_IMAGE_BY_CAREER_ID.get(careerID, DEFAULT_BACKGROUND)
     81         self.backgroundSprite.texturePath = texturePath
     82         animations.FadeIn(self.backgroundSprite, endVal=0.4, duration=0.75)
     83 
     84     def OnCareerNodeHoverOn(self, careerPathID):
     85         self.bgHighlights.HighlightDetailForCareer(careerPathID)
     86 
     87     def OnCareerNodeHoverOff(self, careerPathID):
     88         self.bgHighlights.StopHighlightForCareer(careerPathID)
     89 
     90     def _StartRotation(self):
     91         animations.Tr2DRotateTo(self.largeDottedLine, startAngle=self.largeDottedLine.rotation, endAngle=-2 * math.pi, duration=460.0, loops=-1, curveType=uiconst.ANIM_LINEAR)
     92         animations.Tr2DRotateTo(self.smallDottedLine, startAngle=self.smallDottedLine.rotation, endAngle=2 * math.pi, duration=460.0, loops=-1, curveType=uiconst.ANIM_LINEAR)
     93 
     94 
     95 class BackgroundHighlights(Container):
     96 
     97     def ApplyAttributes(self, attributes):
     98         super(BackgroundHighlights, self).ApplyAttributes(attributes)
     99         self.bgSpriteByCareerID = {}
    100         for careerPath, texturePath in careerConst.BG_DETAIL_BY_CAREER_ID.iteritems():
    101             self.bgSpriteByCareerID[careerPath] = self._ConstructSprite(texturePath)
    102 
    103     def _ConstructSprite(self, texturePath):
    104         return Sprite(parent=self, align=uiconst.TOALL, texturePath=texturePath, outputMode=uiconst.OUTPUT_COLOR_AND_GLOW)
    105 
    106     def HighlightDetailForCareer(self, careerPathID):
    107         detailSprite = self.bgSpriteByCareerID.get(careerPathID, None)
    108         if not detailSprite:
    109             return
    110         animations.FadeIn(detailSprite, endVal=2.0, duration=HOVER_TRANSITION_DURATION)
    111         animations.MorphScalar(detailSprite, 'glowBrightness', startVal=0, endVal=0.45, duration=HOVER_TRANSITION_DURATION)
    112 
    113     def StopHighlightForCareer(self, careerPathID):
    114         detailSprite = self.bgSpriteByCareerID.get(careerPathID, None)
    115         if not detailSprite:
    116             return
    117         self._StopHighlight(detailSprite)
    118 
    119     @staticmethod
    120     def _StopHighlight(detailSprite):
    121         animations.FadeTo(detailSprite, startVal=detailSprite.opacity, endVal=1.0, duration=HOVER_TRANSITION_DURATION)
    122         animations.MorphScalar(detailSprite, 'glowBrightness', startVal=detailSprite.glowBrightness, endVal=0, duration=HOVER_TRANSITION_DURATION)
    123 
    124     def StopAllHighlights(self):
    125         for detailSprite in self.bgSpriteByCareerID.values():
    126             self._StopHighlight(detailSprite)