shipTreeShipIcon.py (12873B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\shipTree\shipTreeShipIcon.py 2 from __future__ import absolute_import 3 from carbon.client.script.environment.AudioUtil import PlaySound 4 import log 5 import carbonui.const as uiconst 6 import evetypes 7 import inventorycommon.typeHelpers 8 from . import shipTreeConst 9 import trinity 10 from carbon.client.script.environment.AudioUtil import PlaySound 11 from carbonui.const import ANIM_REPEAT, ANIM_WAVE 12 from carbonui.primitives.container import Container 13 from carbonui.primitives.frame import Frame 14 from carbonui.primitives.sprite import Sprite 15 from carbonui.primitives.transform import Transform 16 from carbonui.uicore import uicore 17 from carbonui.util.color import Color 18 from eve.client.script.ui.shared.shipTree import shipTreeUtil 19 from eve.client.script.ui.shared.shipTree.shipTreeConst import COLOR_BG, COLOR_HOVER_UNLOCKED, COLOR_HOVER_LOCKED, COLOR_HOVER_MASTERED 20 from eveservices.menu import GetMenuService 21 from utillib import KeyVal 22 import uthread2 23 OPACITY_LOCKED = 0.4 24 OPACITY_MASTERY_LOCKED = 0.2 25 26 class ShipTreeShipIcon(Container): 27 default_name = 'ShipTreeShipIcon' 28 default_align = uiconst.TOPLEFT 29 default_state = uiconst.UI_NORMAL 30 isDragObject = True 31 __notifyevents__ = 'OnShipTreeShipFocused' 32 33 def ApplyAttributes(self, attributes): 34 Container.ApplyAttributes(self, attributes) 35 sm.RegisterNotify(self) 36 self.typeID = attributes.typeID 37 self.factionID = attributes.factionID 38 self.groupNode = attributes.groupNode 39 self.expertSystemTypeIDs = attributes.expertSystemTypeIDs 40 self.activeRelatedExpertSystem = attributes.get('activeRelatedExpertSystem', False) 41 self.masteryLevel = None 42 self.isMasteryIconBlinking = False 43 self.bgFrame = Frame(bgParent=self, cornerSize=10, opacity=0.5, texturePath='res:/UI/Texture/Classes/ShipTree/groups/frameUnlocked.png') 44 self.expertSystemBgBlinkFill = None 45 self.bgBlinkFill = None 46 self.bgThumpFill = None 47 self.bgVignette = Sprite(name='bgFill', bgParent=self, texturePath='res:/UI/Texture/Classes/ShipTree/groups/bgFill.png') 48 Sprite(name='bgVignette', bgParent=self, texturePath='res:/UI/Texture/Classes/ShipTree/groups/bgVignette.png', color=COLOR_BG) 49 self.recentUnlockBG = None 50 texturePath = shipTreeUtil.GetTagIconForType(self.typeID) 51 if texturePath: 52 self.techIcon = Sprite(name='techIcon', parent=self, align=uiconst.TOPLEFT, state=uiconst.UI_DISABLED, width=32, height=32, texturePath=texturePath, idx=0) 53 else: 54 self.techIcon = None 55 self.iconTransform = Transform(parent=self, align=uiconst.TOALL, scalingCenter=(0.5, 0.5)) 56 try: 57 texturePath = inventorycommon.typeHelpers.GetHoloIconPath(self.typeID) 58 except AttributeError as e: 59 texturePath = None 60 log.LogException(e) 61 62 self.iconSprite = Sprite(name='iconSprite', parent=self.iconTransform, align=uiconst.TOPLEFT_PROP, state=uiconst.UI_DISABLED, texturePath=texturePath, blendMode=trinity.TR2_SBM_ADD, ignoreColorBlindMode=True, pos=(0.5, 63 0.08, 64 self.width - 36, 65 self.width - 36), idx=0) 66 self.masteryIcon = Sprite(name='masterySprite', parent=self, align=uiconst.CENTERBOTTOM, state=uiconst.UI_DISABLED, pos=(0, -3, 45, 45), idx=0) 67 if self.activeRelatedExpertSystem: 68 self.expertSystemBgFrame = Frame(bgParent=self, cornerSize=10, opacity=1.0, texturePath='res:/UI/Texture/Classes/ExpertSystems/ExpertSystem_ShipTree_BG.png') 69 self.expertSystemsAnimSprite = Sprite(bgParent=self, texturePath='res:/UI/Texture/Classes/ExpertSystems/ExpertSystem_ShipTree_BG_Overlay.png') 70 uicore.animations.SpSwoopBlink(self.expertSystemsAnimSprite, duration=3, loops=uiconst.ANIM_REPEAT) 71 self.masteryIcon.state = uiconst.UI_HIDDEN 72 Sprite(parent=self, name='expertSystemIcon', texturePath='res:/UI/Texture/classes/ExpertSystems/logo_simple_20.png', width=20, height=20, align=uiconst.CENTERBOTTOM, top=10, state=uiconst.UI_DISABLED) 73 elif self.expertSystemTypeIDs: 74 self.masteryIcon.state = uiconst.UI_HIDDEN 75 Sprite(parent=self, name='expertSystemIcon', texturePath='res:/UI/Texture/classes/ExpertSystems/logo_inactive_20.png', width=20, height=20, align=uiconst.CENTERBOTTOM, top=10, state=uiconst.UI_DISABLED) 76 77 def UpdateState(self, animate = True): 78 self.masteryLevel = sm.GetService('certificates').GetCurrCharMasteryLevel(self.typeID) 79 duration = 0.6 if animate else 0.01 80 if self.groupNode.IsLocked(): 81 self._UpdateStateLocked(duration) 82 else: 83 self._UpdateStateUnlocked(duration) 84 if self.groupNode.IsRecentlyUnlocked(): 85 if not self.recentUnlockBG: 86 self.ConstructRecentUnlockBG() 87 i = self.parent.children.index(self) 88 uicore.animations.FadeTo(self.recentUnlockBG, 0.7, 0.0, duration=2.4, loops=uiconst.ANIM_REPEAT, curveType=uiconst.ANIM_WAVE, timeOffset=i * 0.15) 89 sm.GetService('audio').SendUIEvent('isis_line_2filled') 90 elif self.recentUnlockBG: 91 uicore.animations.FadeOut(self.recentUnlockBG) 92 if sm.GetService('shipTree').IsShipMasteryRecentlyIncreased(self.typeID): 93 if not self.isMasteryIconBlinking: 94 uicore.animations.FadeTo(self.masteryIcon, OPACITY_MASTERY_LOCKED, 1.5, duration=2.4, loops=uiconst.ANIM_REPEAT, curveType=uiconst.ANIM_WAVE) 95 if self.IsElite(): 96 sm.GetService('audio').SendUIEvent('isis_masteryunlock_elite') 97 else: 98 sm.GetService('audio').SendUIEvent('isis_masteryunlock') 99 self.isMasteryIconBlinking = True 100 else: 101 uicore.animations.FadeTo(self.masteryIcon, 1.0) 102 texturePath = sm.GetService('certificates').GetMasteryIconForLevel(self.masteryLevel) 103 self.masteryIcon.texturePath = texturePath 104 105 def ConstructRecentUnlockBG(self): 106 if not self.recentUnlockBG: 107 if self.IsElite(): 108 color = COLOR_HOVER_MASTERED 109 else: 110 color = COLOR_HOVER_UNLOCKED 111 self.recentUnlockBG = Sprite(name='recentUnlockBG', bgParent=self, texturePath='res:/UI/Texture/Classes/ShipTree/groups/bgVignette.png', color=color) 112 113 def IsElite(self): 114 return self.masteryLevel == 5 115 116 def GetDragData(self): 117 ret = KeyVal(__guid__='uicls.GenericDraggableForTypeID', typeID=self.typeID, label=evetypes.GetName(self.typeID)) 118 return (ret,) 119 120 def _UpdateStateLocked(self, duration): 121 self.bgVignette.SetRGBA(*shipTreeConst.COLOR_SHIPICON_LOCKED) 122 for obj in (self.techIcon, self.iconSprite): 123 if obj: 124 uicore.animations.FadeTo(obj, obj.opacity, OPACITY_LOCKED, duration=duration) 125 126 uicore.animations.FadeTo(self.masteryIcon, self.masteryIcon.opacity, OPACITY_MASTERY_LOCKED, duration=duration) 127 uicore.animations.FadeTo(self.bgFrame, self.bgFrame.opacity, 0.25, duration=duration) 128 self.iconSprite.SetRGBA(1.0, 1.0, 1.0, self.iconSprite.opacity) 129 self.bgFrame.SetTexturePath('res:/UI/Texture/Classes/ShipTree/groups/frameLocked.png') 130 131 def _UpdateStateUnlocked(self, duration): 132 for obj in (self.techIcon, self.iconSprite): 133 if obj: 134 uicore.animations.FadeTo(obj, obj.opacity, 1.0, duration=duration) 135 136 if not self.isMasteryIconBlinking: 137 uicore.animations.FadeTo(self.masteryIcon, self.masteryIcon.opacity, 1.0, duration=duration) 138 uicore.animations.FadeTo(self.bgFrame, self.bgFrame.opacity, 0.5, duration=duration) 139 if self.IsElite(): 140 texturePath = 'res:/UI/Texture/Classes/ShipTree/groups/frameElite.png' 141 c = shipTreeConst.COLOR_MASTERED 142 self.bgVignette.SetRGBA(c[0], c[1], c[2], 0.15) 143 self.iconSprite.SetRGBA(c[0], c[1], c[2], self.iconSprite.opacity) 144 else: 145 texturePath = 'res:/UI/Texture/Classes/ShipTree/groups/frameUnlocked.png' 146 self.bgVignette.SetRGBA(*shipTreeConst.COLOR_SHIPICON_UNLOCKED) 147 self.iconSprite.SetRGBA(1.0, 1.0, 1.0, self.iconSprite.opacity) 148 self.bgFrame.SetTexturePath(texturePath) 149 150 def OnMouseEnter(self, *args): 151 PlaySound(uiconst.SOUND_BUTTON_HOVER) 152 if not self.groupNode.IsLocked(): 153 uicore.animations.FadeTo(self.iconSprite, self.iconSprite.opacity, 3.0, duration=3.0, curveType=uiconst.ANIM_WAVE, loops=uiconst.ANIM_REPEAT) 154 uicore.animations.Tr2DScaleTo(self.iconTransform, self.iconTransform.scale, (1.05, 1.05), duration=0.3) 155 else: 156 uicore.animations.FadeTo(self.iconSprite, self.iconSprite.opacity, 1.0, duration=0.3) 157 uicore.animations.FadeTo(self.masteryIcon, self.masteryIcon.opacity, 1.0, duration=0.3) 158 sm.GetService('shipTreeUI').ShowInfoBubble(self, factionID=self.factionID, typeID=self.typeID, expertSystems=self.expertSystemTypeIDs) 159 sm.GetService('audio').SendUIEventByTypeID(self.typeID) 160 self.ConstructBgBlinkFill() 161 uicore.animations.FadeTo(self.bgBlinkFill, self.bgBlinkFill.opacity, 0.5, duration=0.3) 162 163 def OnMouseExit(self, *args): 164 opacity = OPACITY_LOCKED if self.groupNode.IsLocked() else 1.0 165 uicore.animations.FadeTo(self.iconSprite, self.iconSprite.opacity, opacity, duration=0.3) 166 opacity = OPACITY_MASTERY_LOCKED if self.groupNode.IsLocked() else 1.0 167 uicore.animations.FadeTo(self.masteryIcon, self.masteryIcon.opacity, opacity, duration=0.3) 168 if self.bgBlinkFill: 169 uicore.animations.FadeOut(self.bgBlinkFill, duration=0.3) 170 uicore.animations.Tr2DScaleTo(self.iconTransform, self.iconTransform.scale, (1.0, 1.0), duration=0.3) 171 sm.GetService('audio').SendUIEvent('ui_shipsound_stop') 172 173 def Close(self): 174 Container.Close(self) 175 sm.GetService('shipTreeUI').CloseInfoBubble() 176 sm.GetService('audio').SendUIEvent('ui_shipsound_stop') 177 178 def GetMenu(self): 179 return GetMenuService().GetMenuFromItemIDTypeID(None, self.typeID, includeMarketDetails=True) 180 181 def OnClick(self, *args): 182 PlaySound(uiconst.SOUND_BUTTON_CLICK) 183 sm.GetService('info').ShowInfo(self.typeID) 184 185 def OnShipTreeShipFocused(self, typeID): 186 if typeID == self.typeID: 187 self.Blink() 188 elif self.bgBlinkFill: 189 uicore.animations.FadeOut(self.bgBlinkFill) 190 191 def Blink(self): 192 self.ConstructBgBlinkFill() 193 uicore.animations.FadeTo(self.bgBlinkFill, 0.0, 1.0, loops=ANIM_REPEAT, duration=1.2, curveType=ANIM_WAVE) 194 195 def Thump(self, duration = 0.3, delay = 0): 196 if not self.bgThumpFill: 197 self.bgThumpFill = Sprite(name='bgFillBlink', bgParent=self, texturePath='res:/UI/Texture/Classes/ShipTree/groups/bgWhite.png') 198 self.bgThumpFill.SetRGBA(1, 1, 1, 0) 199 uicore.animations.FadeTo(self.bgThumpFill, 0.0, 3, duration=duration, curveType=ANIM_WAVE, timeOffset=delay) 200 uicore.animations.FadeTo(self.iconSprite, self.iconSprite.opacity, 3, duration=duration, curveType=uiconst.ANIM_WAVE, timeOffset=delay) 201 uicore.animations.Tr2DScaleTo(self.iconTransform, self.iconTransform.scale, (1.15, 1.15), duration=duration, curveType=uiconst.ANIM_WAVE, timeOffset=delay) 202 uthread2.start_tasklet(self._DelayedThumpSound, delay=delay) 203 204 def _DelayedThumpSound(self, delay): 205 uthread2.sleep(delay) 206 PlaySound('ship_goals_reveal_ship_play') 207 208 def StartExpertSystemBlink(self): 209 self.ConstructExpertSystemBgBlinkFill() 210 uicore.animations.FadeTo(self.expertSystemBgBlinkFill, 0.0, 1.0, loops=ANIM_REPEAT, duration=1.2, curveType=ANIM_WAVE) 211 212 def StopExpertSystemBlink(self): 213 self.ConstructExpertSystemBgBlinkFill() 214 uicore.animations.FadeOut(self.expertSystemBgBlinkFill, duration=1.2) 215 216 def ConstructExpertSystemBgBlinkFill(self): 217 if not self.expertSystemBgBlinkFill: 218 self.expertSystemBgBlinkFill = Sprite(name='bgFillBlink', bgParent=self, texturePath='res:/UI/Texture/Classes/ShipTree/groups/bgVignette.png', color=Color.GREEN, opacity=0.0) 219 220 def ConstructBgBlinkFill(self): 221 if not self.bgBlinkFill: 222 self.bgBlinkFill = Sprite(name='bgFillBlink', bgParent=self, texturePath='res:/UI/Texture/Classes/ShipTree/groups/bgVignette.png') 223 if self.groupNode.IsLocked(): 224 self.bgBlinkFill.SetRGBA(*COLOR_HOVER_LOCKED) 225 elif self.IsElite(): 226 self.bgBlinkFill.SetRGBA(*COLOR_HOVER_MASTERED) 227 else: 228 self.bgBlinkFill.SetRGBA(*COLOR_HOVER_UNLOCKED)