infoPanelIncursions.py (14531B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\infoPanels\infoPanelIncursions.py 2 import carbonui.const as uiconst 3 import blue 4 import trinity 5 import localization 6 import uthread 7 from carbon.common.script.util.timerstuff import AutoTimer 8 from carbonui.primitives.container import Container 9 from carbonui.primitives.containerAutoSize import ContainerAutoSize 10 from carbonui.primitives.fill import Fill 11 from carbonui.primitives.line import Line 12 from carbonui.primitives.sprite import Sprite 13 from eve.client.script.ui.control import eveIcon, eveLabel 14 from eve.client.script.ui.shared.incursions.incursionConst import SCENETYPE_DATA 15 from eve.client.script.ui.shared.incursions.taleSystemEffect import TaleSystemEffect 16 from eve.client.script.ui.shared.infoPanels.InfoPanelBase import InfoPanelBase 17 from localization import GetByLabel 18 from talecommon.const import scenesTypes, INCURSION_TEMPLATE_CLASSES 19 from carbonui.uicore import uicore 20 from talecommon.influence import CalculateDecayedInfluence 21 from eve.client.script.ui.shared.infoPanels.const import infoPanelConst 22 ICONSIZE = 22 23 ARROWS = ('ui_77_32_41', 'ui_77_32_42') 24 EFFECT_SPACING = 16 25 COLOR_ENABLED = (1, 1, 1, 0.75) 26 COLOR_DISABLED = (1, 1, 1, 0.25) 27 INCURSION_UPDATE_RATE = 60000 28 29 class InfoPanelIncursions(InfoPanelBase): 30 default_name = 'InfoPanelIncursions' 31 hasSettings = False 32 panelTypeID = infoPanelConst.PANEL_INCURSIONS 33 label = 'UI/Incursion/HUD/IncursionProfileTitle' 34 default_iconTexturePath = 'res:/UI/Texture/Classes/InfoPanels/taleDefaultIcon.png' 35 default_severity = scenesTypes.vanguard 36 default_height = 120 37 __notifyevents__ = ['OnInfluenceUpdate', 'ProcessUpdateInfoPanel'] 38 39 def ApplyAttributes(self, attributes): 40 InfoPanelBase.ApplyAttributes(self, attributes) 41 sm.RegisterNotify(self) 42 self.lastInfluence = None 43 self.headerTextCont = Container(name='headerTextCont', parent=self.headerCont, align=uiconst.TOALL) 44 self.title = self.headerCls(name='title', text='<color=white url=localsvc:method=ShowIncursionTab&constellationID=%d&open=1>%s</url>' % (session.constellationid, localization.GetByLabel(self.label)), parent=self.headerTextCont, align=uiconst.CENTERLEFT, state=uiconst.UI_NORMAL) 45 self.subTitle = eveLabel.EveHeaderMedium(name='subtitle', parent=self.headerTextCont, left=self.title.width + 4, align=uiconst.CENTERLEFT, state=uiconst.UI_NORMAL, top=3) 46 self.headerInfluenceBar = SystemInfluenceBar(parent=self.headerCont, state=uiconst.UI_HIDDEN, align=uiconst.TOALL, height=0, padding=(0, 6, 24, 6)) 47 self.headerInfluenceBar.OnClick = self.topCont.OnClick 48 self.headerInfluenceBar.OnMouseEnter = self.topCont.OnMouseEnter 49 self.headerInfluenceBar.OnMouseExit = self.topCont.OnMouseExit 50 self.influenceBar = SystemInfluenceBar(parent=self.mainCont, padding=(0, 0, 0, 2)) 51 self.bottomContainer = Container(name='bottomContainer', parent=self.mainCont, align=uiconst.TOTOP, height=33) 52 self.severityIcon = eveIcon.Icon(name='severityIcon', parent=self.bottomContainer, align=uiconst.CENTERLEFT, color=COLOR_ENABLED, pos=(0, 0, 32, 32), ignoreSize=True, size=48, state=uiconst.UI_NORMAL) 53 self.iconCont = ContainerAutoSize(name='iconCont', parent=self.bottomContainer, align=uiconst.CENTERLEFT, pos=(40, 54 0, 55 0, 56 ICONSIZE)) 57 self.finalEncounterIcon = IncursionFinalEncounterIcon(name='finalEncounterIcon', parent=self.bottomContainer, align=uiconst.CENTERRIGHT) 58 self.effects = self._GetEffectsForTale() 59 uthread.new(self.UpdateInfluenceThread) 60 61 def _GetEffectsForTale(self): 62 data = sm.GetService('incursion').GetActiveIncursionData() 63 if not hasattr(data, 'effects'): 64 return [] 65 return [ TaleSystemEffect(name=effectInfo['name'], align=uiconst.TOLEFT, parent=self.iconCont, color=COLOR_ENABLED, width=ICONSIZE, opacity=0.0, padRight=6, texturePath=effectInfo['texturePath'], hint=localization.GetByLabel(effectInfo['hint']), isScalable=effectInfo['isScalable']) for effectInfo in data.effects ] 66 67 def ConstructCompact(self): 68 data = sm.GetService('incursion').GetActiveIncursionData() 69 self._SetFinalEncounterSpawned(data.hasFinalEncounter, data.templateClassID) 70 influence = CalculateDecayedInfluence(data.influenceData) 71 self.SetInfluence(influence, None, animate=False) 72 73 def ConstructNormal(self): 74 data = sm.GetService('incursion').GetActiveIncursionData() 75 info = SCENETYPE_DATA[data.severity] 76 influence = CalculateDecayedInfluence(data.influenceData) 77 self.subTitle.text = localization.GetByLabel(info.subTitle) 78 self.severityIcon.LoadIcon(info.severityIcon, ignoreSize=True) 79 self.severityIcon.hint = localization.GetByLabel(info.hint) 80 self._SetFinalEncounterSpawned(data.hasFinalEncounter, data.templateClassID) 81 self.SetInfluence(influence, None, animate=False) 82 self.severityIcon.opacity = 0.0 83 84 def OnEndModeChanged(self, oldMode): 85 if self.mode == infoPanelConst.MODE_NORMAL and oldMode: 86 uicore.animations.BlinkIn(self.severityIcon) 87 blue.synchro.SleepWallclock(200) 88 for icon in self.effects: 89 uicore.animations.BlinkIn(icon, endVal=COLOR_ENABLED[3]) 90 blue.synchro.SleepWallclock(50) 91 92 else: 93 self.severityIcon.opacity = 1.0 94 for icon in self.effects: 95 icon.opacity = COLOR_ENABLED[3] 96 97 def OnStartModeChanged(self, oldMode): 98 uthread.new(self._OnStartModeChanged, oldMode) 99 100 def _OnStartModeChanged(self, oldMode): 101 if self.mode == infoPanelConst.MODE_COMPACT: 102 if oldMode: 103 uicore.animations.FadeOut(self.headerTextCont, duration=0.3, sleep=True) 104 self.headerTextCont.Hide() 105 self.headerInfluenceBar.Show() 106 uicore.animations.FadeTo(self.headerInfluenceBar, 0.0, 1.0, duration=0.3) 107 else: 108 self.headerTextCont.Hide() 109 self.headerInfluenceBar.Show() 110 elif self.headerInfluenceBar.display: 111 uicore.animations.FadeOut(self.headerInfluenceBar, duration=0.3, sleep=True) 112 self.headerInfluenceBar.Hide() 113 self.headerTextCont.Show() 114 uicore.animations.FadeTo(self.headerTextCont, 0.0, 1.0, duration=0.3) 115 116 @staticmethod 117 def IsAvailable(): 118 return sm.GetService('incursion').IsIncursionActive() 119 120 def UpdateInfluenceThread(self): 121 while not self.destroyed: 122 newInfluence = None 123 data = sm.GetService('incursion').GetActiveIncursionData() 124 if data: 125 newInfluence = CalculateDecayedInfluence(data.influenceData) 126 if self.lastInfluence is None or self.lastInfluence != newInfluence: 127 self.SetInfluence(newInfluence, False, True) 128 blue.pyos.synchro.SleepWallclock(INCURSION_UPDATE_RATE) 129 130 def SetInfluence(self, influence, positiveProgress, animate = True): 131 self.influenceBar.SetInfluence(influence, positiveProgress, animate) 132 self.headerInfluenceBar.SetInfluence(influence, positiveProgress, animate) 133 for icon in self.effects: 134 icon.SetInfluence(influence) 135 136 self.lastInfluence = influence 137 138 def OnInfluenceUpdate(self, taleID, newInfluenceData): 139 data = sm.GetService('incursion').GetActiveIncursionData() 140 if data and data.taleID == taleID: 141 influenceData = data.influenceData 142 oldInfluence = CalculateDecayedInfluence(influenceData) 143 influenceData.influence = newInfluenceData.influence 144 influenceData.lastUpdated = newInfluenceData.lastUpdated 145 newInfluence = CalculateDecayedInfluence(influenceData) 146 positiveProgress = oldInfluence < newInfluence 147 self.SetInfluence(newInfluence, positiveProgress) 148 149 def _SetFinalEncounterSpawned(self, hasSpawned, templateClassId): 150 if templateClassId in INCURSION_TEMPLATE_CLASSES: 151 self.finalEncounterIcon.SetFinalEncounterSpawned(hasSpawned) 152 153 154 class IncursionFinalEncounterIcon(Sprite): 155 default_name = 'finalEncounterIcon' 156 default_texturePath = 'res:/UI/Texture/classes/Incursions/iconMothership.png' 157 default_state = uiconst.UI_NORMAL 158 default_width = 32 159 default_height = 32 160 161 def ApplyAttributes(self, attributes): 162 super(IncursionFinalEncounterIcon, self).ApplyAttributes(attributes) 163 hasSpawned = attributes.get('hasSpawned', False) 164 self.SetFinalEncounterSpawned(hasSpawned) 165 166 def SetFinalEncounterSpawned(self, hasSpawned): 167 self.hasSpawned = hasSpawned 168 self.SetRGBA(*(COLOR_ENABLED if hasSpawned else COLOR_DISABLED)) 169 170 def LoadTooltipPanel(self, tooltipPanel, *args): 171 tooltipPanel.LoadGeneric1ColumnTemplate() 172 text = self._GetTooltipText() 173 tooltipPanel.AddLabelMedium(text=text, wrapWidth=250) 174 175 def _GetTooltipText(self): 176 if self.hasSpawned: 177 return GetByLabel('UI/Incursion/HUD/IncursionFinalEncounterReportHint') 178 else: 179 return GetByLabel('UI/Incursion/HUD/NoIncursionFinalEncounterHint') 180 181 182 class BarFill(Sprite): 183 __guid__ = 'uicls.BarFill' 184 default_name = 'BarFill' 185 default_rect = (0, 0, 0, 32) 186 default_texturePath = 'res:/ui/texture/classes/InfluenceBar/influenceBarDefault.png' 187 default_slice = None 188 default_state = uiconst.UI_HIDDEN 189 default_align = uiconst.RELATIVE 190 default_spriteEffect = trinity.TR2_SFX_COPY 191 TEX_SIZE = 134 192 193 def ApplyAttributes(self, attributes): 194 Sprite.ApplyAttributes(self, attributes) 195 slice = attributes.get('slice', self.default_slice) 196 if slice is not None: 197 self.SetTextureSlice(slice) 198 199 def SetTextureSlice(self, slice): 200 self.SetTexturePath(slice) 201 202 def SetBar(self, delta): 203 if not self.parent: 204 return 205 ppl, ppt, mainBarWidth, h = self.parent.parent.GetAbsolute() 206 pl, pt, parentWidth, h = self.parent.GetAbsolute() 207 barOffset = pl - ppl 208 self.left = int(-barOffset + mainBarWidth - round(mainBarWidth * delta)) 209 self.width = mainBarWidth 210 211 212 class SystemInfluenceBar(Container): 213 __guid__ = 'uicls.SystemInfluenceBar' 214 default_name = 'SystemInfluenceBar' 215 default_left = 0 216 default_top = 0 217 default_width = 0 218 default_height = 12 219 default_influence = 0.0 220 default_align = uiconst.TOTOP 221 default_padTop = 4 222 default_padBottom = 4 223 default_state = uiconst.UI_NORMAL 224 default_clipChildren = False 225 FRAME_COLOR = (0.5, 0.5, 0.5, 1.0) 226 TEX_WIDTH = 256 227 PADDING = (0, 4, 0, 4) 228 ARROW_HEIGHT = 32 229 LEFT_SLICE = 'res:/ui/texture/classes/InfluenceBar/influenceBarNegative.png' 230 RIGHT_SLICE = 'res:/ui/texture/classes/InfluenceBar/influenceBarPositive.png' 231 HINT_LABEL = 'UI/Incursion/HUD/InfluenceBarHint' 232 233 def ApplyAttributes(self, attributes): 234 Container.ApplyAttributes(self, attributes) 235 l, t, w, h = self.GetAbsolute() 236 self.influence = attributes.get('influence', 0.0) 237 self.targetInfluence = self.influence 238 self.blueBar = Container(parent=self, name='blueBar', align=uiconst.TOLEFT_PROP, width=0, clipChildren=True) 239 Fill(name='blueBase', parent=self.blueBar, color=(0, 1, 1, 0.25)) 240 self.blueArrows = BarFill(name='blueFill', pos=(0, 241 0, 242 w, 243 h), parent=self.blueBar, color=(0, 1, 1, 0.75)) 244 self.knob = Line(parent=self, name='sliderKnob', color=self.FRAME_COLOR, align=uiconst.TOLEFT) 245 self.redBar = Container(parent=self, name='redBar', align=uiconst.TOALL, clipChildren=True) 246 Fill(name='redBase', parent=self.redBar, color=(1, 0, 0, 0.25)) 247 self.redArrows = BarFill(pos=(0, 248 0, 249 w, 250 h), name='redFill', parent=self.redBar, color=(1, 0, 0, 0.75)) 251 252 def SetInfluence(self, influence, positiveProgress, animate = True): 253 if self.HINT_LABEL is not None: 254 self.SetHint(localization.GetByLabel(self.HINT_LABEL, influence=int(round((1.0 - influence) * 100)))) 255 if animate: 256 self.targetInfluence = influence 257 self.animationTimer = AutoTimer(100, self.Animation_Thread, positiveProgress) 258 else: 259 self.influence = self.targetInfluence = influence 260 self.blueBar.width = influence 261 262 def Animation_Thread(self, positiveProgress): 263 l, t, w, h = self.GetAbsolute() 264 totalWidth = w - self.knob.width 265 count = 5 266 if positiveProgress is None: 267 moveFunc = None 268 self.blueArrows.state = uiconst.UI_HIDDEN 269 self.redArrows.state = uiconst.UI_HIDDEN 270 elif positiveProgress: 271 moveFunc = self.MoveRight 272 self.blueArrows.SetTextureSlice(self.RIGHT_SLICE) 273 self.blueArrows.state = uiconst.UI_DISABLED 274 self.redArrows.SetTextureSlice(self.RIGHT_SLICE) 275 self.redArrows.state = uiconst.UI_DISABLED 276 else: 277 moveFunc = self.MoveLeft 278 self.blueArrows.SetTextureSlice(self.LEFT_SLICE) 279 self.blueArrows.state = uiconst.UI_DISABLED 280 self.redArrows.SetTextureSlice(self.LEFT_SLICE) 281 self.redArrows.state = uiconst.UI_DISABLED 282 while count > 0: 283 start = blue.os.GetWallclockTime() 284 lastDelta = delta = 0.0 285 while delta < 2.0: 286 delta = max(0.0, min(blue.os.TimeDiffInMs(start, blue.os.GetWallclockTime()) / 1000.0, 2.0)) 287 dt = delta - lastDelta 288 if self.targetInfluence > self.influence: 289 self.influence = min(self.influence + 0.25 * dt, self.targetInfluence) 290 else: 291 self.influence = max(self.influence - 0.25 * dt, self.targetInfluence) 292 self.blueBar.width = self.influence 293 if moveFunc: 294 moveFunc(delta) 295 lastDelta = delta 296 blue.pyos.synchro.Yield() 297 if not self or self.destroyed: 298 return 299 300 count -= 1 301 302 self.animationTimer = None 303 304 def MoveRight(self, delta): 305 self.blueArrows.SetBar(2.0 - delta) 306 self.redArrows.SetBar(2.0 - delta) 307 308 def MoveLeft(self, delta): 309 self.blueArrows.SetBar(delta) 310 self.redArrows.SetBar(delta)