abilityIcon.py (11903B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\inflight\squadrons\abilityIcon.py 2 import dogma.data as dogma_data 3 from carbon.common.lib.const import MSEC 4 from carbonui.primitives.container import Container 5 import carbonui.const as uiconst 6 from carbonui.primitives.sprite import Sprite 7 from carbonui.uianimations import animations 8 from eve.client.script.ui.crimewatch import crimewatchConst 9 from eve.client.script.ui.control.eveIcon import Icon 10 from eve.client.script.ui.control.eveLabel import EveLabelSmall, Label 11 from eve.client.script.ui.inflight.shipModuleButton.ramps import ShipModuleButtonRamps, ShipModuleReactivationTimer 12 from eve.client.script.ui.inflight.shipModuleButton.shipmodulebutton import GLOWCOLOR, BUSYCOLOR 13 from eve.client.script.ui.inflight.squadrons.shipFighterState import GetShipFighterState 14 from eve.client.script.ui.inflight.squadrons.squadronAbilityTooltip import SquadronTooltipModuleWrapper 15 from fighters import GetChargeCountForTypeAndSlot, GetAbilityIDForSlot 16 from fighters.abilityAttributes import GetDogmaEffectIDForAbilityID 17 import trinity 18 import uthread 19 import blue 20 21 class AbilityIcon(Container): 22 default_width = 48 23 default_height = 48 24 default_align = uiconst.TOPLEFT 25 default_state = uiconst.UI_NORMAL 26 tooltipPanelClassInfo = SquadronTooltipModuleWrapper() 27 28 def ApplyAttributes(self, attributes): 29 Container.ApplyAttributes(self, attributes) 30 self.activeCurve = None 31 self.activationPendingCurve = None 32 self.deactivationCurve = None 33 self.ramp_active = False 34 self.buttonDisabled = False 35 self.glow = None 36 self.busy = None 37 self.abilityIcon = None 38 self.shipFighterState = GetShipFighterState() 39 self.crimewatchSvc = sm.GetService('crimewatchSvc') 40 self.innerCont = Container(name='innerCont', parent=self, align=uiconst.TOBOTTOM, height=self.height) 41 self.stateLabel = EveLabelSmall(parent=self.innerCont, align=uiconst.CENTER) 42 self.controller = attributes.controller 43 self.slotID = self.controller.slotID 44 self.fighterID = attributes.fighterID 45 self.fighterTypeID = attributes.fighterTypeID 46 ability = self.GetAbilityInfo() 47 self.abilityNameID = ability.displayNameID 48 iconID = ability.iconID 49 self.abilityIcon = Icon(parent=self.innerCont, align=uiconst.CENTER, width=32, height=32, icon=iconID, state=uiconst.UI_DISABLED) 50 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) 51 self.hilite.display = False 52 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) 53 self.abilityIcon.SetSize(32, 32) 54 self.DrawQtyCont() 55 self.DrawTimer() 56 self.DrawCoolDownTimer() 57 self.DrawSafetyGlow() 58 self.targetMode = ability.targetMode 59 abilityID = GetAbilityIDForSlot(self.fighterTypeID, self.slotID) 60 effectID = GetDogmaEffectIDForAbilityID(abilityID) 61 self.abilityEffect = dogma_data.get_effect(effectID) 62 self.OnAbilityStatusUpdated(self.fighterID, self.slotID) 63 self.shipFighterState.signalOnAbilityActivationStatusUpdate.connect(self.OnAbilityStatusUpdated) 64 65 def GetSafetyWarning(self): 66 requiredSafetyLevel = self.GetRequiredSafetyLevel() 67 if self.crimewatchSvc.CheckUnsafe(requiredSafetyLevel): 68 return requiredSafetyLevel 69 else: 70 return None 71 72 def GetRequiredSafetyLevel(self): 73 requiredSafetyLevel = self.crimewatchSvc.GetRequiredSafetyLevelForEffect(self.abilityEffect) 74 return requiredSafetyLevel 75 76 def OnMouseEnter(self, *args): 77 self.hilite.display = True 78 requiredSafetyLevel = self.GetSafetyWarning() 79 if requiredSafetyLevel is not None: 80 if requiredSafetyLevel == const.shipSafetyLevelNone: 81 color = crimewatchConst.Colors.Criminal 82 else: 83 color = crimewatchConst.Colors.Suspect 84 self.safetyGlow.SetRGBA(*color.GetRGBA()) 85 self.safetyGlow.display = True 86 87 def OnMouseExit(self, *args): 88 self.hilite.display = False 89 self.safetyGlow.display = False 90 91 def DrawSafetyGlow(self): 92 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()) 93 self.safetyGlow.display = False 94 95 def DrawTimer(self): 96 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) 97 self.glow.display = False 98 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) 99 self.busy.display = False 100 self.ramps = ShipModuleButtonRamps(parent=self.innerCont, idx=0, top=-8) 101 self.ramps.display = False 102 103 def DrawCoolDownTimer(self): 104 self.coolDownRamps = ShipModuleReactivationTimer(parent=self.innerCont, name='coolDown', idx=-1) 105 self.coolDownRamps.display = False 106 107 def DrawQtyCont(self): 108 self.quantityParent = Container(parent=self.innerCont, name='quantityParent', pos=(16, 6, 24, 10), align=uiconst.BOTTOMRIGHT, state=uiconst.UI_DISABLED, idx=0) 109 self.chargeCountLabel = Label(text='', parent=self.quantityParent, fontsize=9, letterspace=1, left=3, width=30, state=uiconst.UI_DISABLED) 110 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)) 111 112 def GetAbilityInfo(self): 113 ability = self.controller.GetAbilityInfo() 114 return ability 115 116 def OnAbilityStatusUpdated(self, fighterID, slotID): 117 if fighterID == self.fighterID and slotID == self.slotID: 118 abilityActivationStatus = self.shipFighterState.GetAbilityActivationStatus(self.fighterID, self.slotID) 119 if abilityActivationStatus: 120 if abilityActivationStatus.isPending: 121 self._StartActivationPendingAnimation() 122 else: 123 self._StopActivationPendingAnimation() 124 if abilityActivationStatus.isDeactivating: 125 self._StartDeactivationAnimation() 126 else: 127 self._StopDeactivationAnimation() 128 if not abilityActivationStatus.isPending and not abilityActivationStatus.isDeactivating: 129 self._StartActiveAnimation() 130 self.buttonDisabled = False 131 else: 132 self._StopActiveAnimation() 133 self.buttonDisabled = True 134 if abilityActivationStatus.startTime and abilityActivationStatus.durationMs: 135 self._StartCycleAnimation(abilityActivationStatus.startTime, abilityActivationStatus.durationMs) 136 else: 137 self._StopCycleAnimation() 138 else: 139 self._StopActivationPendingAnimation() 140 self._StopDeactivationAnimation() 141 self._StopActiveAnimation() 142 self._StopCycleAnimation() 143 cooldown = self.shipFighterState.GetAbilityCooldown(self.fighterID, self.slotID) 144 if cooldown is not None: 145 self.buttonDisabled = True 146 uthread.new(self._StartCoolDownAnimation, cooldown) 147 else: 148 self.buttonDisabled = False 149 self._UpdateChargeCountLabel() 150 151 def _UpdateChargeCountLabel(self): 152 maxChargeCount = GetChargeCountForTypeAndSlot(self.fighterTypeID, self.slotID) 153 if maxChargeCount is not None: 154 currentChargeCount = self.shipFighterState.GetAbilityChargeCount(self.fighterID, self.slotID) 155 self.quantityParent.Show() 156 self.chargeCountLabel.SetText(currentChargeCount) 157 else: 158 self.quantityParent.Hide() 159 160 def _StartCycleAnimation(self, startTime, durationMs): 161 if self.ramp_active: 162 return 163 uthread.new(self._StartCycleAnimationThread, startTime, durationMs) 164 165 def _StartCycleAnimationThread(self, startTime, durationMs): 166 duration = durationMs * MSEC 167 self.ramp_active = True 168 self.ramps.display = True 169 self.coolDownRamps.display = False 170 while self.ramp_active: 171 now = blue.os.GetSimTime() 172 portionDone = (now - startTime) / duration 173 if portionDone > 1: 174 iterations = int(portionDone) 175 startTime += long(duration * iterations) 176 portionDone -= iterations 177 self.ramps.SetRampValues(portionDone) 178 blue.pyos.synchro.Yield() 179 180 def _StopCycleAnimation(self): 181 self.ramp_active = False 182 self.ramps.display = False 183 184 def _StartCoolDownAnimation(self, cooldown): 185 self.coolDownRamps.display = True 186 startTime, endTime = cooldown 187 coolDownTime = int(endTime - startTime) 188 self.coolDownRamps.AnimateTimer(startTime, coolDownTime) 189 if endTime <= blue.os.GetSimTime(): 190 self.coolDownRamps.display = False 191 self.buttonDisabled = False 192 193 def _StartActiveAnimation(self): 194 self.glow.display = True 195 self.activeCurve = animations.FadeTo(self.glow, loops=uiconst.ANIM_REPEAT, curveType=uiconst.ANIM_WAVE) 196 animations.SyncPlayback(self.activeCurve) 197 198 def _StopActiveAnimation(self): 199 if self.glow: 200 self.glow.display = False 201 if self.activeCurve: 202 self.activeCurve.Stop() 203 self.activeCurve = None 204 205 def _StartActivationPendingAnimation(self): 206 self.activationPendingCurve = animations.FadeTo(self.abilityIcon, loops=uiconst.ANIM_REPEAT, curveType=uiconst.ANIM_WAVE) 207 animations.SyncPlayback(self.activationPendingCurve) 208 209 def _StopActivationPendingAnimation(self): 210 if self.activationPendingCurve: 211 self.activationPendingCurve.Stop() 212 self.activationPendingCurve = None 213 if self.abilityIcon: 214 animations.FadeIn(self.abilityIcon) 215 216 def _StartDeactivationAnimation(self): 217 self.busy.display = True 218 self.deactivationCurve = animations.FadeTo(self.busy, loops=uiconst.ANIM_REPEAT, curveType=uiconst.ANIM_WAVE) 219 animations.SyncPlayback(self.deactivationCurve) 220 221 def _StopDeactivationAnimation(self): 222 if self.busy: 223 self.busy.display = False 224 if self.deactivationCurve: 225 self.deactivationCurve.Stop() 226 self.deactivationCurve = None 227 228 def OnClick(self, *args): 229 if self.buttonDisabled: 230 return 231 self.controller.OnAbilityClick(self.targetMode) 232 233 def Close(self): 234 self._StopActiveAnimation() 235 self._StopActivationPendingAnimation() 236 self._StopDeactivationAnimation() 237 self.shipFighterState.signalOnAbilityActivationStatusUpdate.disconnect(self.OnAbilityStatusUpdated) 238 super(AbilityIcon, self).Close() 239 240 def OnMouseDown(self, *args): 241 if self.buttonDisabled: 242 return 243 self.innerCont.top = 2 244 245 def OnMouseUp(self, *args): 246 if self.buttonDisabled: 247 return 248 self.innerCont.top = 0