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

circleNode.py (6891B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\careerPortal\circleView\circleNode.py
      2 import math
      3 import carbonui.const as uiconst
      4 from carbonui import fontconst
      5 from carbonui.primitives.container import Container
      6 from carbonui.primitives.containerAutoSize import ContainerAutoSize
      7 from carbonui.primitives.sprite import Sprite
      8 from carbonui.primitives.transform import Transform
      9 from carbonui.uianimations import animations
     10 from careergoals.client.signal import on_goal_progress_changed, on_goal_completed
     11 from eve.client.script.ui import eveColor
     12 from eve.client.script.ui.control.eveLabel import EveLabelMedium, EveLabelSmall
     13 from eve.client.script.ui.shared.careerPortal import careerConst
     14 from eveexceptions import ExceptionEater
     15 from signals.signalUtil import ChangeSignalConnect
     16 
     17 class CircleNode(Transform):
     18     isDragObject = True
     19 
     20     def ApplyAttributes(self, attributes):
     21         super(CircleNode, self).ApplyAttributes(attributes)
     22         self.anchorPointX = self.width * 0.5
     23         self.anchorPointY = self.height * 0.5
     24         self.PrepareUI()
     25         self.ConnectSignals()
     26 
     27     def PrepareUI(self):
     28         raise NotImplementedError
     29 
     30     def ConnectSignals(self):
     31         for signal, func in self.GetSignals():
     32             signal.connect(func)
     33 
     34     def DisconnectSignals(self):
     35         for signal, func in self.GetSignals():
     36             signal.disconnect(func)
     37 
     38     def Close(self):
     39         self.DisconnectSignals()
     40         super(CircleNode, self).Close()
     41 
     42     def GetSignals(self):
     43         return [(on_goal_progress_changed, self.OnGoalUpdated), (on_goal_completed, self.OnGoalCompleted), (careerConst.CAREER_WINDOW_STATE_SETTING.on_change, self.OnCareerWindowStateChanged)]
     44 
     45     def OnCareerWindowStateChanged(self, state):
     46         pass
     47 
     48     def OnGoalUpdated(self, goalID, value):
     49         pass
     50 
     51     def OnGoalCompleted(self, goalID):
     52         pass
     53 
     54     def ResizeComponents(self, contSize, left, top, angle, animate = False):
     55         pass
     56 
     57     def UpdateAnchorPointsAndSize(self, contSize):
     58         raise NotImplementedError
     59 
     60 
     61 TEXT_PADDING = 12
     62 
     63 class CircleNodeWithText(CircleNode):
     64     default_state = uiconst.UI_NORMAL
     65     default_height = 150
     66     default_width = 150
     67     default_align = uiconst.CENTER
     68 
     69     def PrepareUI(self):
     70         self.textCont = NodeTextCont(name='textCont', parent=self, align=uiconst.CENTERTOP)
     71         self.iconCont = Container(name='iconCont', parent=self, align=uiconst.TOALL)
     72         self.ConstructFrame()
     73         self.ConstructIcon()
     74 
     75     def ConstructIcon(self):
     76         self.bgSprite = Sprite(name='bgSprite', parent=self.iconCont, align=uiconst.CENTER, texturePath='res:/UI/Texture/classes/careerPortal/circleView/nodeBg.png', state=uiconst.UI_DISABLED, opacity=0)
     77 
     78     def ConstructFrame(self):
     79         self.frame = Sprite(name='frameSprite', parent=self.iconCont, align=uiconst.TOALL, texturePath='res:/UI/Texture/classes/careerPortal/circleView/nodeFrame.png', state=uiconst.UI_DISABLED, opacity=1.0)
     80 
     81     def GetNameLabel(self):
     82         raise NotImplementedError
     83 
     84     def GetProgressLabel(self):
     85         raise NotImplementedError
     86 
     87     def IsCompleted(self):
     88         raise NotImplementedError
     89 
     90     def OnClick(self, *args):
     91         raise NotImplementedError
     92 
     93     def ResizeComponents(self, contSize, left, top, angle, animate = False):
     94         self.UpdateAnchorPointsAndSize(contSize)
     95         self.UpdateTextPos(angle)
     96         if animate:
     97             animations.MorphScalar(self, 'top', startVal=self.top, endVal=top, duration=careerConst.LEVEL_ANIMATION_DURATION)
     98             animations.MorphScalar(self, 'left', startVal=self.left, endVal=left, duration=careerConst.LEVEL_ANIMATION_DURATION)
     99         else:
    100             self.top = top
    101             self.left = left
    102 
    103     def UpdateAnchorPointsAndSize(self, contSize):
    104         self.height = self.width = contSize
    105         self.bgSprite.SetSize(self.width, self.height)
    106         self.anchorPointX = contSize / 2
    107         self.anchorPointY = contSize / 2
    108 
    109     def UpdateNode(self):
    110         self.textCont.UpdateLabels(self.GetNameLabel(), self.GetProgressLabel())
    111         if self.IsCompleted():
    112             self.SetCompletedState()
    113         else:
    114             self.SetNormalState()
    115 
    116     def OnMouseEnter(self, *args):
    117         self.SetHoverState()
    118 
    119     def OnMouseExit(self, *args):
    120         self.SetNormalState()
    121 
    122     def SetNormalState(self):
    123         if self.IsCompleted():
    124             return
    125         self.textCont.nameLabel.color = eveColor.WHITE
    126         self.textCont.progressLabel.color = eveColor.WHITE
    127 
    128     def SetHoverState(self):
    129         pass
    130 
    131     def SetCompletedState(self):
    132         self.textCont.nameLabel.color = eveColor.LEAFY_GREEN
    133         self.textCont.progressLabel.color = eveColor.LEAFY_GREEN
    134 
    135     def UpdateTextPos(self, angle):
    136         angleDegrees = math.degrees(angle + 0.5 * math.pi) % 360
    137         textAlign = uiconst.CENTER
    138         contAlign = uiconst.CENTERBOTTOM
    139         top = left = 0
    140         textWidth = self.textCont.GetWidth()
    141         textHeight = self.textCont.GetHeight()
    142         if 0 <= angleDegrees < 30 or 330 <= angleDegrees < 360:
    143             contAlign = uiconst.CENTERTOP
    144             top = -textHeight - 8
    145         elif 150 <= angleDegrees < 210:
    146             contAlign = uiconst.CENTERBOTTOM
    147             top = -textHeight - 8
    148         elif 30 <= angleDegrees < 150:
    149             textAlign = uiconst.CENTERLEFT
    150             contAlign = uiconst.CENTERRIGHT
    151             left = -textWidth - TEXT_PADDING
    152         elif 210 <= angleDegrees < 330:
    153             textAlign = uiconst.CENTERRIGHT
    154             contAlign = uiconst.CENTERLEFT
    155             left = -textWidth - TEXT_PADDING
    156         self.textCont.nameLabel.SetAlign(textAlign)
    157         self.textCont.progressLabel.SetAlign(textAlign)
    158         self.textCont.SetAlign(contAlign)
    159         self.textCont.SetPosition(left, top)
    160 
    161 
    162 class NodeTextCont(ContainerAutoSize):
    163     nameLabelClass = EveLabelMedium
    164     progressLabelClass = EveLabelSmall
    165 
    166     def ApplyAttributes(self, attributes):
    167         super(NodeTextCont, self).ApplyAttributes(attributes)
    168         self.nameLabel = self.nameLabelClass(parent=ContainerAutoSize(parent=self, align=uiconst.TOTOP), name='nameLabel', align=uiconst.CENTER, bold=True)
    169         self.progressLabel = self.progressLabelClass(parent=ContainerAutoSize(parent=self, align=uiconst.TOTOP), name='progressLabel', align=uiconst.CENTER)
    170 
    171     def GetWidth(self):
    172         w, _ = self.nameLabel.MeasureTextSize(self.nameLabel.text)
    173         return w
    174 
    175     def GetHeight(self):
    176         _, nameHeight = self.nameLabel.MeasureTextSize(self.nameLabel.text)
    177         _, progressHeight = self.progressLabel.MeasureTextSize(self.progressLabel.text)
    178         return nameHeight + progressHeight
    179 
    180     def UpdateLabels(self, name, progress):
    181         self.nameLabel.text = name
    182         self.progressLabel.text = progress
    183         self.width = self.GetWidth()