hackingVirusInfo.py (8619B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\hacking\hackingVirusInfo.py 2 import random 3 from math import pi 4 import carbonui.const as uiconst 5 import localization 6 import hackingcommon.hackingConstants as hackingConst 7 from carbonui.primitives.container import Container 8 from carbonui.primitives.sprite import Sprite 9 from carbonui.primitives.transform import Transform 10 from carbonui.util.color import Color 11 from eve.client.script.ui.hacking import hackingUIConst 12 from eve.client.script.ui.hacking.hackingStatContainer import StatContainer 13 import uthread 14 import blue 15 import trinity 16 from carbonui.uicore import uicore 17 18 class VirusInfo(Container): 19 __notifyevents__ = ['OnHackingVirusChanged'] 20 default_align = uiconst.BOTTOMLEFT 21 default_state = uiconst.UI_NORMAL 22 default_width = 123 23 default_height = 95 24 25 def ApplyAttributes(self, attributes): 26 Container.ApplyAttributes(self, attributes) 27 sm.RegisterNotify(self) 28 self.strength = None 29 self.coherence = None 30 self.iconSprite = Sprite(name='virusIconSprite', texturePath='res:/UI/Texture/classes/hacking/hudIcon.png', parent=self, align=uiconst.CENTER, state=uiconst.UI_DISABLED, pos=(0, 0, 59, 44)) 31 self.coherenceBar = VirusInfoBar(parent=self, align=uiconst.CENTERLEFT, color=hackingUIConst.COLOR_HUD_BAR_COHERENCE) 32 self.strengthBar = VirusInfoBar(parent=self, align=uiconst.CENTERRIGHT, color=hackingUIConst.COLOR_HUD_BAR_STRENGTH, mirrored=True) 33 self.strengthCont = StatContainer(name='strengthCont', parent=self, statType=hackingUIConst.STAT_STRENGTH, align=uiconst.CENTERBOTTOM, state=uiconst.UI_NORMAL, top=4, hint=localization.GetByLabel('UI/Hacking/VirusStrength')) 34 self.coherenceCont = StatContainer(name='coherencesCont', parent=self, statType=hackingUIConst.STAT_COHERENCE, align=uiconst.CENTERTOP, state=uiconst.UI_NORMAL, top=4, hint=localization.GetByLabel('UI/Hacking/VirusCoherence')) 35 Sprite(name='bg', parent=self, align=uiconst.TOALL, texturePath='res:/UI/Texture/classes/hacking/hudBG.png') 36 noiseData = ('res:/UI/Texture/Classes/hacking/hudNoise1.png', 'res:/UI/Texture/Classes/hacking/hudNoise2.png', 'res:/UI/Texture/Classes/hacking/hudNoise3.png', 'res:/UI/Texture/Classes/hacking/hudNoise4.png') 37 self.noiseSprites = [] 38 for num, texturePath in enumerate(noiseData): 39 noise = HudNoise(parent=self, texturePath=texturePath, width=self.width, height=self.height, num=num) 40 self.noiseSprites.append(noise) 41 42 self.iconBG = Sprite(name='iconBG', texturePath='res:/UI/Texture/classes/hacking/hudIconBG.png', parent=self, align=uiconst.CENTER, state=uiconst.UI_DISABLED, pos=(0, 0, 118, 118), opacity=0.0) 43 self.animateIconThread = None 44 self.AnimateIconBG() 45 46 def SetIntensity(self, value): 47 for noise in self.noiseSprites: 48 noise.SetIntensity(value) 49 50 def AnimateIconBG(self): 51 if self.animateIconThread: 52 self.animateIconThread.kill() 53 self.animateIconThread = uthread.new(self._AnimateIconBG) 54 55 def _AnimateIconBG(self): 56 color = Color(*hackingUIConst.COLOR_DATACACHE).SetAlpha(0.5).GetRGBA() 57 uicore.animations.SpColorMorphTo(self.iconBG, self.iconBG.GetRGBA(), color, duration=1.0, callback=self.AnimateIconBG, sleep=True) 58 if self.animateIconThread: 59 self.animateIconThread.kill() 60 uicore.animations.FadeTo(self.iconBG, 0.5, 0.85, duration=5.0, curveType=uiconst.ANIM_WAVE, loops=uiconst.ANIM_REPEAT) 61 62 def OnHackingVirusChanged(self, objectData, eventID): 63 if eventID == hackingConst.EVENT_ATTACK: 64 blue.synchro.Sleep(300) 65 self.UpdateVirusInfo() 66 67 def UpdateVirusInfo(self): 68 strength, coherence = sm.GetService('hackingUI').GetVirusStrengthAndCoherence() 69 if self.coherence is None: 70 self.coherenceBar.SetMaxValue(4.0 / 3.0 * coherence) 71 if self.strength is None: 72 self.strengthBar.SetMaxValue(2.0 * strength) 73 if self.coherence and coherence < self.coherence: 74 uicore.animations.BlinkIn(self.iconSprite, loops=1, duration=0.15) 75 self.iconBG.opacity = 1.0 76 if self.animateIconThread: 77 self.animateIconThread.kill() 78 uicore.animations.SpColorMorphTo(self.iconBG, Color.WHITE, (0, 0, 0, 0), duration=0.6, callback=self.AnimateIconBG) 79 self.coherenceCont.SetValue(coherence) 80 self.strengthCont.SetValue(strength) 81 self.coherenceBar.SetValue(coherence) 82 self.strengthBar.SetValue(strength) 83 if self.coherence > hackingUIConst.LOW_COHERENCE_WARN_LEVEL and coherence < hackingUIConst.LOW_COHERENCE_WARN_LEVEL: 84 sm.GetService('audio').SendUIEvent('minigame_coherence_low_start') 85 elif self.coherence < hackingUIConst.LOW_COHERENCE_WARN_LEVEL and coherence > hackingUIConst.LOW_COHERENCE_WARN_LEVEL: 86 sm.GetService('audio').SendUIEvent('minigame_coherence_low_stop') 87 self.coherence = coherence 88 self.strength = strength 89 90 91 class VirusInfoBar(Container): 92 default_mirrored = False 93 default_width = 24 94 default_height = 71 95 default_left = 4 96 default_state = uiconst.UI_NORMAL 97 default_maxValue = 1.0 98 99 def ApplyAttributes(self, attributes): 100 Container.ApplyAttributes(self, attributes) 101 mirrored = attributes.get('mirrored', self.default_mirrored) 102 self.color = attributes.color 103 self.maxValue = float(attributes.get('maxValue', self.default_maxValue)) 104 self.value = 0 105 stripeTexturePath = 'res:/UI/Texture/classes/hacking/hudBarStripesMirrored.png' if mirrored else 'res:/UI/Texture/classes/hacking/hudBarStripes.png' 106 fillTexturePath = 'res:/UI/Texture/classes/hacking/hudBarFillMirrored.png' if mirrored else 'res:/UI/Texture/classes/hacking/hudBarFill.png' 107 self.hint = localization.GetByLabel('UI/Hacking/VirusStrength') if mirrored else localization.GetByLabel('UI/Hacking/VirusCoherence') 108 self.bar = Container(name='bar', parent=self, align=uiconst.TOBOTTOM_PROP, state=uiconst.UI_DISABLED, height=0.0, clipChildren=True) 109 self.barTexture = Sprite(name='barTexture', parent=self.bar, align=uiconst.CENTERBOTTOM, width=self.width, height=self.height, texturePath=fillTexturePath, textureSecondaryPath=stripeTexturePath, spriteEffect=trinity.TR2_SFX_MODULATE, color=self.color) 110 self.bg = Sprite(name='bg', bgParent=self, texturePath=fillTexturePath, color=hackingUIConst.COLOR_HUD_BAR_BG, textureSecondaryPath=stripeTexturePath, spriteEffect=trinity.TR2_SFX_MODULATE) 111 112 def SetMaxValue(self, value): 113 self.maxValue = float(value) 114 115 def SetValue(self, value): 116 if value == self.value: 117 return 118 uicore.animations.MorphScalar(self.bar, 'height', self.bar.height, value / self.maxValue, duration=0.6) 119 color = Color(*self.color).SetBrightness(1.0).GetRGBA() 120 uicore.animations.SpColorMorphTo(self.barTexture, color, self.barTexture.GetRGBA(), duration=0.6) 121 self.value = value 122 123 124 class HudNoise(Transform): 125 default_align = uiconst.CENTER 126 default_scalingCenter = (0.5, 0.5) 127 default_opacity = 0.0 128 COLOR = Color.WHITE 129 130 def ApplyAttributes(self, attributes): 131 Transform.ApplyAttributes(self, attributes) 132 texturePath = attributes.texturePath 133 num = attributes.num 134 self.intensity = 1.0 135 self.sprite = Sprite(bgParent=self, texturePath=texturePath) 136 uthread.new(self.Animate, num) 137 138 def Animate(self, num): 139 blue.synchro.SleepWallclock(num * 800) 140 while not self.destroyed: 141 duration = 5.0 * self.intensity 142 color = Color(*hackingUIConst.COLOR_EXPLORED).SetAlpha(0.1 + 0.4 * random.random()).GetRGBA() 143 self.sprite.SetRGBA(*color) 144 self.rotation = random.choice((0, pi)) 145 uicore.animations.Tr2DRotateTo(self, self.rotation, self.rotation + random.choice((0.05, -0.05)), duration=duration) 146 uicore.animations.Tr2DScaleTo(self, (0.9, 0.9), (1.0, 1.0), duration=duration) 147 uicore.animations.FadeTo(self, 0.0, 1.0, duration=duration, curveType=uiconst.ANIM_WAVE) 148 x = 0.5 * random.random() - 0.4 * self.intensity + 0.5 149 sleepTime = duration * (0.2 + 0.8 * x) 150 blue.synchro.SleepWallclock(sleepTime * 1000) 151 self.StopAnimations() 152 uicore.animations.BlinkOut(self) 153 blue.synchro.SleepWallclock(1000) 154 155 def SetIntensity(self, value): 156 self.intensity = value