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

activityNode.py (12290B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\careerPortal\circleView\activityNode.py
      2 import math
      3 import carbonui.const as uiconst
      4 from carbon.client.script.environment.AudioUtil import PlaySound
      5 from carbon.common.script.sys.serviceConst import ROLE_GML
      6 from carbonui.primitives.sprite import Sprite
      7 from carbonui.primitives.vectorarc import VectorArc
      8 from carbonui.primitives.vectorlinetrace import DashedCircle
      9 from carbonui.uianimations import animations
     10 from carbonui.util.dpi import ScaleDpi
     11 from careergoals.client.career_goal_svc import get_career_goals_svc
     12 from eve.client.script.ui import eveColor
     13 from eve.client.script.ui.shared.careerPortal import careerConst, cpSignals
     14 from eve.client.script.ui.shared.careerPortal.careerControllerUI import get_career_portal_controller_svc
     15 from eve.client.script.ui.shared.careerPortal.circleView.circleNode import CircleNodeWithText
     16 from eve.client.script.ui.shared.careerPortal.link.dragData import NodeDragData
     17 from localization import GetByLabel
     18 ANIM_DURATION = 0.4
     19 TEXT_WIDTH = 200
     20 TEXT_PADDING = 2
     21 DEFAULT_BG_OPACITY = 0.1
     22 GLOW_SPRITE_WIDTH = 64
     23 HIGHLIGHT_BG_OPACITY = 0.3
     24 ACTIVITY_NODE_SIZE = 48
     25 
     26 class ActivityNode(CircleNodeWithText):
     27     default_name = 'ActivityNode'
     28     default_height = ACTIVITY_NODE_SIZE
     29     default_width = ACTIVITY_NODE_SIZE
     30 
     31     def ApplyAttributes(self, attributes):
     32         self.nodeObject = attributes.nodeObject
     33         self.highlight = attributes.get('highlight', False)
     34         self.highlightSprite = None
     35         super(ActivityNode, self).ApplyAttributes(attributes)
     36         self.highlight = self.highlight and not self.IsCompleted()
     37         if self.highlight:
     38             self.highlightSprite = VectorArc(name='highlight', parent=self, align=uiconst.CENTER, radius=ScaleDpi((self.default_width + ScaleDpi(16)) / 2), fill=False, color=eveColor.AURA_PURPLE, outputMode=uiconst.OUTPUT_COLOR_AND_GLOW, state=uiconst.UI_DISABLED, glowBrightness=0.5)
     39         animations.FadeIn(self.icon, duration=ANIM_DURATION, timeOffset=0.5)
     40         goals = get_career_goals_svc().get_goal_data_controller().get_goals_in_group(self.nodeObject.careerID, self.nodeObject.activityID)
     41         self.goalsInGroup = [ g.goal_id for g in goals ]
     42         self.OnCareerWindowStateChanged(attributes.initialState)
     43 
     44     def GetSignals(self):
     45         newSignals = [(cpSignals.on_career_node_hover_on, self.OnCareerNodeHoverOn), (cpSignals.on_career_node_hover_off, self.OnCareerNodeHoverOff)]
     46         return newSignals + super(ActivityNode, self).GetSignals()
     47 
     48     def ConstructIcon(self):
     49         self.icon = Sprite(parent=self.iconCont, name='activityIcon', align=uiconst.CENTER, pos=(0, 0, 32, 32), texturePath=self.nodeObject.iconTexturePath, state=uiconst.UI_DISABLED, color=eveColor.LEAFY_GREEN if self.IsCompleted() else eveColor.WHITE, opacity=0)
     50         super(ActivityNode, self).ConstructIcon()
     51         if self.IsCompleted():
     52             bgSpriteColor = eveColor.LEAFY_GREEN
     53         elif self.highlight:
     54             bgSpriteColor = eveColor.AURA_PURPLE
     55         else:
     56             bgSpriteColor = eveColor.CRYO_BLUE
     57         self.bgSprite.color = eveColor.Color(bgSpriteColor).SetOpacity(0).GetRGBA()
     58         self.glowSprite = Sprite(name='glowSprite', parent=self.iconCont, align=uiconst.CENTER, texturePath='res:/UI/Texture/classes/careerPortal/node_glow.png', state=uiconst.UI_DISABLED, outputMode=uiconst.OUTPUT_COLOR_AND_GLOW, glowBrightness=0.2, opacity=0)
     59 
     60     def UpdateAnchorPointsAndSize(self, contSize):
     61         super(ActivityNode, self).UpdateAnchorPointsAndSize(contSize)
     62         self.glowSprite.SetSize(self.width + GLOW_SPRITE_WIDTH, self.height + GLOW_SPRITE_WIDTH)
     63 
     64     def ConstructFrame(self):
     65         radius = ScaleDpi(self.default_width / 2)
     66         self.dashedFrame = DashedCircle(name='dashedFrame', parent=self.iconCont, align=uiconst.CENTER, radius=radius, lineWidth=2, color=eveColor.LEAFY_GREEN, startAngle=math.radians(-90), range=math.pi * 2, gapEnds=True, dashCount=len(self.nodeObject.GetGoals()), dashSizeFactor=8, outputMode=uiconst.OUTPUT_COLOR_AND_GLOW, glowBrightness=0.5)
     67         self.bgFrame = DashedCircle(name='dashedFrameBG', parent=self.iconCont, align=uiconst.CENTER, radius=radius, lineWidth=2, color=eveColor.WHITE, startAngle=math.radians(-90), range=math.pi * 2, gapEnds=True, dashCount=len(self.nodeObject.GetGoals()), dashSizeFactor=8, outputMode=uiconst.OUTPUT_COLOR_AND_GLOW, glowBrightness=0.4)
     68         self.dashedFrame.end = 0
     69         self.frame = VectorArc(name='frame', parent=self.iconCont, align=uiconst.CENTER, radius=radius, fill=False, opacity=0, color=eveColor.LEAFY_GREEN if self.IsCompleted() else eveColor.WHITE)
     70         self.UpdateDashedCircle()
     71 
     72     def OnCareerNodeHoverOn(self, *args):
     73         currentState = careerConst.CAREER_WINDOW_STATE_SETTING.get()
     74         if currentState != careerConst.CareerWindowState.GOALS_VIEW:
     75             return
     76         if self.IsSelected():
     77             return
     78         animations.FadeIn(self.icon, duration=ANIM_DURATION)
     79         animations.FadeIn(self.frame, duration=ANIM_DURATION)
     80         animations.FadeOut(self.bgSprite, duration=ANIM_DURATION)
     81 
     82     def OnCareerNodeHoverOff(self, *args):
     83         currentState = careerConst.CAREER_WINDOW_STATE_SETTING.get()
     84         if currentState != careerConst.CareerWindowState.GOALS_VIEW:
     85             return
     86         if self.IsSelected():
     87             return
     88         animations.FadeOut(self.frame, duration=ANIM_DURATION)
     89         animations.FadeOut(self.icon, duration=ANIM_DURATION)
     90         animations.FadeIn(self.bgSprite, duration=ANIM_DURATION)
     91 
     92     def OnCareerWindowStateChanged(self, state):
     93         if state == careerConst.CareerWindowState.ACTIVITIES_VIEW:
     94             self.Enable()
     95             animations.FadeIn(self.textCont, duration=ANIM_DURATION)
     96             animations.FadeOut(self.bgSprite, duration=ANIM_DURATION)
     97             animations.FadeOut(self.frame, duration=ANIM_DURATION)
     98             animations.FadeIn(self.icon, duration=ANIM_DURATION, timeOffset=0.5)
     99             animations.FadeIn(self.dashedFrame, duration=ANIM_DURATION)
    100             animations.FadeIn(self.bgFrame, duration=ANIM_DURATION)
    101             if self.highlight:
    102                 self.highlightSprite.display = True
    103         elif state == careerConst.CareerWindowState.GOALS_VIEW:
    104             self.Disable()
    105             if not self.IsSelected():
    106                 animations.FadeOut(self.glowSprite, duration=ANIM_DURATION)
    107                 self.frame.color = eveColor.WHITE
    108                 animations.FadeOut(self.frame, duration=ANIM_DURATION)
    109                 animations.FadeOut(self.icon, duration=ANIM_DURATION)
    110                 animations.FadeTo(self.bgSprite, startVal=0, endVal=DEFAULT_BG_OPACITY, duration=ANIM_DURATION)
    111                 endColor = eveColor.LEAFY_GREEN if self.IsCompleted() else eveColor.LED_GREY
    112                 opacity = 0.4 if self.IsCompleted() else 0.6
    113                 animations.SpColorMorphTo(self.bgSprite, startColor=self.bgSprite.rgba, endColor=eveColor.Color(endColor).SetOpacity(opacity).GetRGBA(), duration=ANIM_DURATION)
    114             else:
    115                 animations.FadeIn(self.glowSprite)
    116                 animations.FadeIn(self.frame, duration=ANIM_DURATION)
    117                 endColor = eveColor.LEAFY_GREEN if self.IsCompleted() else eveColor.CRYO_BLUE
    118                 self.frame.color = endColor
    119                 animations.SpColorMorphTo(self.glowSprite, startColor=self.glowSprite.rgba, endColor=endColor, duration=ANIM_DURATION)
    120                 animations.SpColorMorphTo(self.bgSprite, startColor=self.bgSprite.rgba, endColor=eveColor.Color(endColor).SetOpacity(0.3).GetRGBA(), duration=ANIM_DURATION)
    121             animations.FadeOut(self.textCont, duration=ANIM_DURATION)
    122             animations.FadeOut(self.dashedFrame, duration=ANIM_DURATION)
    123             animations.FadeOut(self.bgFrame, duration=ANIM_DURATION)
    124             if self.highlight:
    125                 self.highlightSprite.display = False
    126         else:
    127             animations.FadeOut(self.icon, duration=ANIM_DURATION)
    128             animations.FadeTo(self.bgSprite, startVal=0, endVal=DEFAULT_BG_OPACITY, duration=ANIM_DURATION)
    129         self.UpdateNode()
    130 
    131     def UpdateNode(self):
    132         super(ActivityNode, self).UpdateNode()
    133         self.UpdateDashedCircle()
    134 
    135     def UpdateDashedCircle(self):
    136         goals = self.nodeObject.GetGoals()
    137         completedGoals = [ goal for goal in goals if goal.is_completed() ]
    138         self.dashedFrame.SetValue(len(completedGoals) / float(len(goals)))
    139         self.bgFrame.start = len(completedGoals) / float(len(goals))
    140 
    141     def OnGoalUpdated(self, goalID, value):
    142         if goalID in self.goalsInGroup:
    143             self.UpdateNode()
    144 
    145     def OnGoalCompleted(self, goalID):
    146         if goalID in self.goalsInGroup and self.IsCompleted():
    147             self.icon.color = eveColor.LEAFY_GREEN
    148 
    149     def IsCompleted(self):
    150         progress, total = self.nodeObject.points
    151         return progress >= total
    152 
    153     def IsSelected(self):
    154         return self.nodeObject.activityID == careerConst.SELECTED_ACTIVITY_SETTING.get()
    155 
    156     def OnClick(self, *args):
    157         PlaySound('career_portal_select_mission_play')
    158         get_career_portal_controller_svc().select_activity(self.nodeObject.activityID, self.nodeObject.activityName, self.nodeObject.careerID)
    159 
    160     def SetNormalState(self):
    161         super(ActivityNode, self).SetNormalState()
    162         self.bgSprite.opacity = 0.0
    163         if self.highlight:
    164             self.highlightSprite.glowBrightness = 0.5
    165 
    166     def SetHoverState(self):
    167         PlaySound('career_portal_mission_hover_play')
    168         super(ActivityNode, self).SetHoverState()
    169         self.bgSprite.opacity = HIGHLIGHT_BG_OPACITY
    170         if self.highlight:
    171             self.highlightSprite.glowBrightness = 1.0
    172 
    173     def SetCompletedState(self):
    174         super(ActivityNode, self).SetCompletedState()
    175         self.bgSprite.color = eveColor.Color(eveColor.LEAFY_GREEN).SetOpacity(HIGHLIGHT_BG_OPACITY).GetRGBA()
    176         self.glowSprite.color = eveColor.Color(eveColor.LEAFY_GREEN).SetOpacity(HIGHLIGHT_BG_OPACITY).GetRGBA()
    177         if self.highlightSprite:
    178             self.highlightSprite.display = False
    179 
    180     def GetNameLabel(self):
    181         return self.nodeObject.activityName
    182 
    183     def GetProgressLabel(self):
    184         return self.nodeObject.progressLabel
    185 
    186     def GetDragData(self):
    187         if self.nodeObject:
    188             return NodeDragData(self.nodeObject.careerID, self.nodeObject.activityID, None, self.nodeObject.activityName)
    189 
    190     def UpdateTextPos(self, angle):
    191         super(ActivityNode, self).UpdateTextPos(angle)
    192         if self.highlight:
    193             self.textCont.top -= 4
    194 
    195     def GetMenu(self):
    196         if session and session.role & ROLE_GML:
    197             menu = [['QA: Complete All Goals In Category', self._Debug_CompleteAllGoals]]
    198             return menu
    199 
    200     def _Debug_CompleteAllGoals(self):
    201         for g in self.goalsInGroup:
    202             get_career_goals_svc().get_goal_data_controller().admin_complete_goal(g)
    203 
    204 
    205 class ActivityNodeObject(object):
    206 
    207     def __init__(self, careerID, activityID):
    208         self.careerID = careerID
    209         self.activityID = activityID
    210         self._activityName = None
    211         self._currentPoints = None
    212         self._maxPoints = None
    213 
    214     @property
    215     def iconTexturePath(self):
    216         return careerConst.ICON_BY_ACTIVITY_ID.get(self.activityID, '')
    217 
    218     @property
    219     def activityName(self):
    220         if self._activityName is None:
    221             self._activityName = careerConst.GetCareerPathGroupName(self.careerID, self.activityID)
    222         return self._activityName
    223 
    224     def GetGoals(self):
    225         return get_career_goals_svc().get_goal_data_controller().get_goals_in_group(self.careerID, self.activityID)
    226 
    227     @property
    228     def points(self):
    229         goals = self.GetGoals()
    230         self._maxPoints = len(goals)
    231         self._currentPoints = len([ g for g in goals if g.is_completed() ])
    232         return (self._currentPoints, self._maxPoints)
    233 
    234     @property
    235     def progressLabel(self):
    236         currentPoints, maxPoints = self.points
    237         return GetByLabel('UI/CareerPortal/ActivityProgressCount', currentPoints=currentPoints, totalPoints=maxPoints)
    238 
    239     def __repr__(self):
    240         return '%s - points: %s' % (self.activityName, self.progressLabel)