skillPlanEntry.py (8181B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\skillPlan\browser\skillPlanEntry.py 2 import eveicon 3 import logging 4 import blue 5 import uthread2 6 from carbon.client.script.environment.AudioUtil import PlaySound 7 from carbon.common.script.sys.serviceConst import ROLE_PROGRAMMER 8 from carbonui import TextColor, uiconst 9 from carbonui.primitives.container import Container 10 from carbonui.primitives.stretchspritehorizontal import StretchSpriteHorizontal 11 from carbonui.uianimations import animations 12 from eve.client.script.ui import eveColor 13 from eve.client.script.ui.control.eveLabel import EveLabelLarge, EveCaptionLarge 14 from eve.client.script.ui.control.gauge import GaugeMultiValue 15 from eve.client.script.ui.skillPlan import skillPlanUISignals 16 from eve.client.script.ui.skillPlan.browser.skillPlanEntryTooltip import SkillPlanEntryTooltip 17 from eveui import Sprite 18 from localization import GetByLabel 19 from omega.client.clone_grade_svc import get_clone_grade_svc 20 from skills.skillplan import skillPlanSignals 21 from skills.skillplan.loggers.skillPlanLogger import log_certified_skill_plan_clicked 22 from skills.skillplan.skillPlanDragData import SkillPlanDragData 23 from skills.skillplan.skillPlanService import GetSkillPlanSvc 24 from uihighlighting.uniqueNameConst import GetUniqueSkillPlanName 25 logger = logging.getLogger(__name__) 26 TRACKED_ICON_SIZE = 20 27 OPACITY_BG_IDLE = 0.1 28 OPACITY_BG_HOVER = 0.3 29 30 class SkillPlanEntry(Container): 31 default_name = 'SkillPlanEntry' 32 default_state = uiconst.UI_NORMAL 33 isDragObject = True 34 __notifyevents__ = ['OnSkillQueueChanged'] 35 36 def ApplyAttributes(self, attributes): 37 super(SkillPlanEntry, self).ApplyAttributes(attributes) 38 sm.RegisterNotify(self) 39 skillPlanSignals.on_tracked_plan_changed.connect(self.OnTrackedPlanChanged) 40 self.skillPlan = attributes.skillPlan 41 self.name = 'SkillPlanEntry_%s' % self.skillPlan.GetInternalName() 42 if attributes.addUniqueName: 43 self.AddUniqueName() 44 self.gauge = None 45 self.trackedIcon = None 46 self.trainingTimeLabel = None 47 self.updateTrainingTimeThread = None 48 self.mainCont = Container(name='mainCont', parent=self, padding=(27, 53, 0, 0)) 49 self.ConstructTextCont() 50 self.ConstructCompletionIndicators() 51 self.underlay = StretchSpriteHorizontal(bgParent=self, texturePath='res:/UI/Texture/classes/SkillPlan/planEntryBG.png', opacity=OPACITY_BG_IDLE, leftEdgeSize=27) 52 uthread2.start_tasklet(self.UpdateState) 53 54 def ConstructTextCont(self): 55 textCont = Container(name='textCont', parent=self.mainCont, align=uiconst.TOTOP, height=38, padRight=34) 56 EveCaptionLarge(parent=textCont, align=uiconst.TOBOTTOM, padBottom=8, text=self.skillPlan.GetName(), autoFadeSides=True, maxLines=3) 57 58 def UpdateState(self): 59 self.CheckShowOmegaIndicator() 60 self.UpdateProgressGauge() 61 self.UpdateTrackedIcon() 62 self.UpdateCompletedIcon() 63 self.UpdateTrainingTimeLabel() 64 65 def UpdateTrainingTimeLabel(self): 66 self.trainingTimeLabel.text = self.skillPlan.GetTotalTrainingTimeLeftText() 67 self.bottomCont.height = max(self.trainingTimeLabel.height, self.bottomCont.height) 68 if self.skillPlan.IsCompleted(): 69 self.trainingTimeLabel.SetRGBA(*TextColor.SUCCESS) 70 if self.updateTrainingTimeThread: 71 self.updateTrainingTimeThread.kill() 72 else: 73 self.trainingTimeLabel.SetRGBA(*TextColor.NORMAL) 74 75 def ConstructCompletionIndicators(self): 76 self.trackedIcon = Sprite(name='trackedIcon', parent=self, state=uiconst.UI_HIDDEN, align=uiconst.TOPRIGHT, pos=(12, 77 20, 78 TRACKED_ICON_SIZE, 79 TRACKED_ICON_SIZE), texturePath=eveicon.look_at.resolve(16), hint=GetByLabel('UI/SkillPlan/TrackedSkillPlan')) 80 self.gauge = GaugeMultiValue(parent=self.mainCont, backgroundColor=(0, 0, 0, 0.4), colors=(eveColor.WHITE, eveColor.CRYO_BLUE), align=uiconst.TOTOP, gaugeHeight=4) 81 self.bottomCont = Container(name='bottomCont', parent=self.mainCont, align=uiconst.TOTOP, height=20, padTop=10) 82 self.trainingTimeLabel = EveLabelLarge(parent=self.bottomCont, align=uiconst.CENTERLEFT) 83 rightIconCont = Container(name='rightIconCont', parent=self.bottomCont, align=uiconst.CENTERRIGHT, pos=(8, 0, 68, 34)) 84 self.omegaCont = Container(parent=rightIconCont, align=uiconst.TORIGHT, pos=(0, 0, 34, 34)) 85 Sprite(name='omegaIcon', parent=self.omegaCont, align=uiconst.CENTER, pos=(0, 0, 20, 20), texturePath='res:/UI/Texture/classes/Seasons/omega_32x32.png') 86 self.omegaCont.display = False 87 self.completedIcon = Sprite(name='completedIcon', parent=rightIconCont, align=uiconst.TORIGHT, pos=(0, 0, 34, 34), texturePath='res:/UI/Texture/classes/SkillPlan/completedIcon.png') 88 self.completedIcon.display = False 89 90 def CheckShowOmegaIndicator(self): 91 if self.skillPlan.IsOmega() and not get_clone_grade_svc().is_omega_with_grace_period(): 92 self.omegaCont.display = True 93 else: 94 self.omegaCont.display = False 95 96 def OnMouseEnter(self, *args): 97 PlaySound(uiconst.SOUND_BUTTON_HOVER) 98 animations.FadeTo(self.underlay, self.underlay.opacity, OPACITY_BG_HOVER, duration=uiconst.TIME_ENTRY) 99 100 def OnMouseExit(self, *args): 101 animations.FadeTo(self.underlay, self.underlay.opacity, OPACITY_BG_IDLE, duration=uiconst.TIME_EXIT) 102 103 def OnClick(self, *args): 104 PlaySound('skills_planner_path_select_list_play') 105 skillPlanUISignals.on_selected(self.skillPlan) 106 if self.skillPlan.IsCertified(): 107 log_certified_skill_plan_clicked(self.skillPlan.GetID()) 108 109 def GetMenu(self): 110 m = [] 111 if self.skillPlan.IsEditable(): 112 m.append((GetByLabel('UI/Neocom/Edit'), self.Edit)) 113 m.append((GetByLabel('UI/Common/Buttons/Delete'), self.Delete)) 114 if session.role & ROLE_PROGRAMMER: 115 m.append(None) 116 m.append((u'GM: Copy Skill Plan ID', blue.pyos.SetClipboardData, (str(self.skillPlan.GetID()),))) 117 return m 118 119 def Delete(self): 120 GetSkillPlanSvc().Delete(self.skillPlan.GetID()) 121 122 def Edit(self): 123 skillPlanUISignals.on_edit_button(self.skillPlan) 124 125 def UpdateProgressGauge(self): 126 progressRatio = self.skillPlan.GetProgressRatio() 127 inTrainingRatio = self.skillPlan.GetInTrainingRatio() 128 self.gauge.SetValue(0, progressRatio) 129 self.gauge.SetValue(1, progressRatio + inTrainingRatio) 130 if inTrainingRatio and not self.updateTrainingTimeThread: 131 self.updateTrainingTimeThread = uthread2.start_tasklet(self._UpdateTrainingTimeThread) 132 133 def _UpdateTrainingTimeThread(self): 134 while not self.destroyed: 135 self.UpdateState() 136 uthread2.Sleep(1.0) 137 138 def UpdateCompletedIcon(self): 139 if self.skillPlan.IsCompleted(): 140 self.completedIcon.Show() 141 else: 142 self.completedIcon.Hide() 143 144 def UpdateTrackedIcon(self): 145 if GetSkillPlanSvc().IsSkillPlanTracked(self.skillPlan.GetID()): 146 self.trackedIcon.Show() 147 else: 148 self.trackedIcon.Hide() 149 150 def OnTrackedPlanChanged(self, oldPlan, newPlan): 151 if self.skillPlan and self.skillPlan.GetID() in [oldPlan.GetID() if oldPlan else None, newPlan.GetID() if newPlan else None]: 152 self.UpdateTrackedIcon() 153 154 def LoadTooltipPanel(self, tooltipPanel, *args): 155 SkillPlanEntryTooltip(skillPlan=self.skillPlan, tooltipPanel=tooltipPanel) 156 157 def GetTooltipPointer(self): 158 return uiconst.POINT_LEFT_2 159 160 def GetDragData(self): 161 return SkillPlanDragData(self.skillPlan.GetID(), self.skillPlan.GetName(), self.skillPlan.GetOwnerID()) 162 163 def OnSkillQueueChanged(self): 164 self.UpdateProgressGauge() 165 166 def AddUniqueName(self): 167 try: 168 skillPlanID = self.skillPlan.GetID().int 169 self.uniqueUiName = GetUniqueSkillPlanName(skillPlanID) 170 except Exception as e: 171 logger.exception('Failed to set unique name for skill plan, e: %s' % e)