reserve_bank_hacking_widget.py (9114B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\packages\dynamicresources\client\ui\reserve_bank_hacking_widget.py 2 import math 3 from carbonui import uiconst 4 from carbonui.primitives.container import Container 5 from carbonui.primitives.containerAutoSize import ContainerAutoSize 6 from carbonui.primitives.transform import Transform 7 from carbonui.uianimations import animations 8 from carbonui.util.color import Color 9 from dynamicresources.client.ui import RadialBarGraph 10 from dynamicresources.client.ui.alert_animations import TimerDissapearAnimation, TimerAppearAnimation 11 from dynamicresources.client.ui.ess_info_panel_ui_const import TRANSITION_LOCK, RESERVE_BANK_AUTOPAYOUT_BAR_COLOR 12 from eve.client.script.ui.control.eveLabel import EveCaptionSmall 13 from eve.client.script.ui.control.gaugeCircular import GaugeCircular 14 from eveui import Sprite 15 16 class ReserveBankHackingWidget(ContainerAutoSize): 17 default_alignMode = uiconst.TOPLEFT 18 default_radius = 50 19 default_padTop = 13 20 default_barHeight = 10 21 default_hoverBarHeight = 20 22 default_linked = 0 23 default_animateIn = True 24 25 def ApplyAttributes(self, attributes): 26 ContainerAutoSize.ApplyAttributes(self, attributes) 27 self.radius = attributes.get('radius', self.default_radius) 28 self.initialProgress = attributes.get('progress', 1.0) 29 self.barHeight = attributes.get('barHeight', self.default_barHeight) 30 self.hoverBarHeight = attributes.get('hoverBarHeight', self.default_hoverBarHeight) 31 self.paymentValues = attributes.paymentValues 32 self.OnMouseEnterCallback = attributes.get('onMouseEnterCallback', lambda _: None) 33 self.OnMouseExitCallback = attributes.get('onMouseExitCallback', lambda _: None) 34 self.nextPaymentTimerBlinkingOut = False 35 self.innerRadius = self.radius - self.barHeight 36 self.linked = attributes.get('linked', self.default_linked) 37 self.animateIn = attributes.get('animateIn', self.default_animateIn) 38 self.pulsesTotal = attributes.pulsesTotal 39 self.hoverStateActive = False 40 if self.animateIn: 41 self.AnimateIn() 42 self.ConstructLayout() 43 44 def AnimateOut(self): 45 TimerDissapearAnimation(parent=self, width=self.radius * 2, height=self.radius * 2, endRadius=self.radius, gaugeLineWidth=5, startAngle=-math.pi / 2, align=uiconst.TOPLEFT, left=3, top=3, includeDashedBackground=False, transitionLock=TRANSITION_LOCK, idx=0) 46 animations.FadeOut(self.gaugeCont, duration=0.25, sleep=True) 47 48 def AnimateIn(self): 49 self.animatedGaugeBackground = TimerAppearAnimation(parent=self, width=self.radius * 2, height=self.radius * 2, endRadius=self.radius, gaugeLineWidth=5, startAngle=-math.pi / 2, align=uiconst.TOPLEFT, dashSizeFactor=8.0, timerColor=Color(*Color.WHITE).SetAlpha(0.2).GetRGBA(), left=3, top=3, includeDashedBackground=False, transitionLock=TRANSITION_LOCK) 50 51 def BlinkInNextPaymentTimer(self): 52 if not self.hoverStateActive: 53 animations.BlinkIn(self.nextPayoutTimer, duration=0.2) 54 55 def BlinkOutNextPaymentTimer(self): 56 if not self.nextPaymentTimerBlinkingOut and not self.hoverStateActive: 57 58 def reset_blink_flag(): 59 self.nextPaymentTimerBlinkingOut = False 60 61 animations.BlinkOut(self.nextPayoutTimer, duration=0.2, callback=reset_blink_flag, loops=6) 62 self.nextPaymentTimerBlinkingOut = True 63 64 def _GetPrefferedBarGapRatio(self, nSegments): 65 if nSegments <= 15: 66 return 7 67 elif nSegments >= 45: 68 return 2.5 69 else: 70 return 4 71 72 def ConstructLayout(self): 73 startingOpacity = 0.0 if self.animateIn else 1.0 74 self.gaugeCont = Container(parent=self, width=self.radius * 2 + self.hoverBarHeight / 2, height=self.radius * 2 + self.hoverBarHeight / 2, align=uiconst.TOPLEFT, opacity=startingOpacity) 75 self.nextPayoutTimer = GaugeCircular(parent=self.gaugeCont, color=Color.WHITE, align=uiconst.CENTER, colorStart=Color.WHITE, colorEnd=Color.WHITE, showMarker=False, lineWidth=2.0, colorBg=Color(*Color.WHITE).SetAlpha(0.2).GetRGBA(), radius=self.radius + 6, state=uiconst.UI_DISABLED) 76 self.paymentValues.reverse() 77 barGapRatio = self._GetPrefferedBarGapRatio(len(self.paymentValues)) 78 self.reserveBankHackingGauge = ReserveBankHackingGauge(self.gaugeCont, uiconst.CENTER, self.paymentValues, radius=self.radius, inner_radius=self.innerRadius, start_angle=0.0, end_angle=360.0, progress=self.initialProgress, color=RESERVE_BANK_AUTOPAYOUT_BAR_COLOR, background_color=(1.0, 1.0, 1.0, 0.3), bar_gap_ratio=barGapRatio, value_radius_modifier=0.0) 79 self.pointingArrowRotationTransform = Transform(parent=self.gaugeCont, name='pointingArrowTransform', align=uiconst.CENTER, width=65, height=65, rotation=math.pi, opacity=0) 80 self.pointingArrowTransform = Transform(parent=self.pointingArrowRotationTransform, name='pointingArrowTransform', align=uiconst.TOBOTTOM_NOPUSH, width=10, height=7) 81 Sprite(parent=self.pointingArrowTransform, texturePath='res:/ui/Texture/classes/ess/reserveBank/Arrow_Big.png', name='pointingArrowTransform', align=uiconst.CENTER, width=10, height=7, color=RESERVE_BANK_AUTOPAYOUT_BAR_COLOR) 82 self.arrowsTransform = Transform(parent=self.gaugeCont, name='arrowsTransform', align=uiconst.CENTER, width=49, height=49) 83 Sprite(parent=self.arrowsTransform, texturePath='res:/ui/Texture/classes/ess/reserveBank/Arrows.png', name='arrows', width=49, height=49) 84 animations.Tr2DRotateTo(self.arrowsTransform, self.arrowsTransform.rotation, loops=uiconst.ANIM_REPEAT, curveType=uiconst.ANIM_LINEAR, duration=6.0) 85 Sprite(parent=self.gaugeCont, name='ring', texturePath='res:/ui/Texture/classes/ess/reserveBank/Ring.png', align=uiconst.CENTER, width=59, height=59) 86 Sprite(parent=self.gaugeCont, name='head', texturePath='res:/ui/Texture/classes/ess/reserveBank/Person.png', align=uiconst.CENTER, width=22, height=21, top=-10) 87 self.linkedLabel = EveCaptionSmall(parent=self.gaugeCont, align=uiconst.CENTER, text=self.linked, top=12, bold=False) 88 if self.animateIn: 89 animations.FadeIn(self.gaugeCont, duration=2) 90 91 def SetLinked(self, linked): 92 self.linked = linked 93 self.linkedLabel.SetText(linked) 94 95 @property 96 def value(self): 97 return self.reserveBankHackingGauge.value 98 99 @property 100 def nextPayoutTimerValue(self): 101 return self.nextPayoutTimer.value 102 103 def SetValue(self, value, animate = True, duration = 0.2): 104 self.reserveBankHackingGauge.SetValue(value, animate=animate, duration=duration) 105 onePulseWidthRotation = math.pi * 2 / self.pulsesTotal 106 segmentToPointTo = self.pulsesTotal - self.pulsesTotal * value 107 newRotation = math.pi + onePulseWidthRotation * segmentToPointTo + onePulseWidthRotation / 2 108 self.pointingArrowRotationTransform.rotation = newRotation 109 110 def SetNextPayoutTimerValue(self, value, animate = True): 111 self.nextPayoutTimer.SetValue(value, animate=animate) 112 113 def OnMouseEnter(self, *args): 114 self.hoverStateActive = True 115 self.OnMouseEnterCallback() 116 animations.FadeOut(self.arrowsTransform, duration=0.2) 117 animations.FadeOut(self.nextPayoutTimer, duration=0.2) 118 animations.FadeIn(self.pointingArrowRotationTransform, duration=0.2) 119 self.reserveBankHackingGauge.OnMouseEnter() 120 ContainerAutoSize.OnMouseEnter(self, *args) 121 122 def OnMouseExit(self, *args): 123 self.hoverStateActive = False 124 self.OnMouseExitCallback() 125 animations.FadeIn(self.arrowsTransform, duration=0.2) 126 animations.FadeIn(self.nextPayoutTimer, duration=0.2) 127 animations.FadeOut(self.pointingArrowRotationTransform, duration=0.2) 128 self.reserveBankHackingGauge.OnMouseExit() 129 ContainerAutoSize.OnMouseExit(self, *args) 130 131 132 class ReserveBankHackingGauge(RadialBarGraph): 133 default_state = uiconst.UI_NORMAL 134 135 def __init__(self, *args, **kwargs): 136 RadialBarGraph.__init__(self, *args, **kwargs) 137 self.value = self.progress 138 self.entryAnimation = None 139 self.exitAnimation = None 140 self._idleRadius = self.radius 141 self._idleInnerRadius = self.inner_radius 142 self.hoverBarHeight = 10 143 144 def SetValue(self, value, animate = True, duration = 0.2): 145 self.progress = value 146 self.value = self.progress 147 148 def OnMouseEnter(self, *args): 149 newRadius = self.radius + self.hoverBarHeight 150 self.entryAnimation = animations.MorphScalar(self, 'value_radius_modifier', startVal=self.value_radius_modifier, endVal=0.8, duration=0.2) 151 animations.MorphScalar(self, 'radius', startVal=self.radius, endVal=newRadius, duration=0.2) 152 153 def OnMouseExit(self, *args): 154 self.exitAnimation = animations.MorphScalar(self, 'value_radius_modifier', startVal=self.value_radius_modifier, endVal=0.0, duration=0.2) 155 animations.MorphScalar(self, 'radius', startVal=self.radius, endVal=self._idleRadius, duration=0.2)