hackingStatContainer.py (3823B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\hacking\hackingStatContainer.py 2 import localization 3 from carbonui import fontconst, uiconst 4 from carbonui.primitives.container import Container 5 from carbonui.primitives.containerAutoSize import ContainerAutoSize 6 from carbonui.primitives.sprite import Sprite 7 from carbonui.uicore import uicore 8 from carbonui.util.color import Color 9 from eve.client.script.ui.control import eveLabel 10 from eve.client.script.ui.hacking import hackingUIConst 11 12 class StatContainer(Container): 13 default_width = hackingUIConst.TILE_SIZE 14 default_height = 12 15 default_align = uiconst.TOPLEFT 16 default_state = uiconst.UI_NORMAL 17 18 def ApplyAttributes(self, attributes): 19 Container.ApplyAttributes(self, attributes) 20 self.statType = attributes.statType 21 self.value = None 22 self.diffQueue = [] 23 self.mainCont = ContainerAutoSize(parent=self, align=uiconst.CENTER) 24 Sprite(name='icon', parent=self.mainCont, align=uiconst.TOPLEFT, state=uiconst.UI_DISABLED, texturePath=self.GetTexturePath(), pos=(0, 0, 10, 10), opacity=0.7) 25 self.label = eveLabel.Label(name='label', parent=self.mainCont, align=uiconst.TOPLEFT, state=uiconst.UI_DISABLED, color=Color.WHITE, fontsize=fontconst.EVE_SMALL_FONTSIZE, pos=(11, -1, 0, 0)) 26 self.diffLabel = None 27 28 def SetValue(self, value): 29 if value == self.value: 30 return 31 if self.value and value < self.value: 32 uicore.animations.BlinkIn(self.label, loops=3) 33 elif self.value and value > self.value: 34 uicore.animations.FadeTo(self.label, 2.0, 1.0, duration=1.0) 35 if self.value: 36 self.AddDiffLabel(value) 37 self.label.text = str(value) 38 self.value = value 39 40 def AddDiffLabel(self, value): 41 diff = value - self.value 42 if self.diffLabel: 43 self.diffQueue.append(diff) 44 return 45 self._AddDiffLabel(diff) 46 47 def _AddDiffLabel(self, diff): 48 if diff > 0: 49 text = '+%s' % diff 50 else: 51 text = '%s' % diff 52 left = (self.width - self.mainCont.width) / 2 + 6 53 self.diffLabel = eveLabel.Label(parent=self, align=self.GetDiffLabelAlign(), text=text, fontsize=fontconst.EVE_SMALL_FONTSIZE, left=left) 54 duration = 1.0 55 curveType = ((0.0, 0.0), 56 (0.1, 1.0), 57 (0.9, 1.0), 58 (1.0, 0.0)) 59 uicore.animations.FadeTo(self.diffLabel, 0.0, 1.0, duration=duration, curveType=curveType) 60 curveType = ((0.0, 5), 61 (0.1, -13), 62 (0.9, -13), 63 (1.0, -25)) 64 uicore.animations.MorphScalar(self.diffLabel, 'top', 5, -15, duration=duration, curveType=curveType, callback=self.OnDiffLabelFadedOut) 65 66 def OnDiffLabelFadedOut(self): 67 self.diffLabel.Close() 68 self.diffLabel = None 69 if self.diffQueue: 70 diff = self.diffQueue.pop(0) 71 self._AddDiffLabel(diff) 72 73 def GetHint(self): 74 if self.hint: 75 return self.hint 76 if self.statType == hackingUIConst.STAT_STRENGTH: 77 return localization.GetByLabel('UI/Hacking/Strength') 78 if self.statType == hackingUIConst.STAT_COHERENCE: 79 return localization.GetByLabel('UI/Hacking/Coherence') 80 81 def GetTexturePath(self): 82 if self.statType == hackingUIConst.STAT_STRENGTH: 83 return 'res:/UI/Texture/classes/hacking/strength.png' 84 if self.statType == hackingUIConst.STAT_COHERENCE: 85 return 'res:/UI/Texture/classes/hacking/coherence.png' 86 87 def GetDiffLabelAlign(self): 88 if self.statType == hackingUIConst.STAT_STRENGTH: 89 return uiconst.TOBOTTOM 90 if self.statType == hackingUIConst.STAT_COHERENCE: 91 return uiconst.TOTOP