NovaBryan/EVE_Dump
Log | Files | 📦 下载最新源码 (.zip) | Refs | README

milestoneTimer.py (4758B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\infoPanels\milestoneTimer\milestoneTimer.py
      2 import gametime
      3 import math
      4 from carbon.client.script.environment.AudioUtil import PlaySound
      5 from carbon.common.script.util.timerstuff import AutoTimer
      6 from carbonui import uiconst
      7 from carbonui.primitives.sprite import Sprite
      8 from carbonui.primitives.transform import Transform
      9 from carbonui.uianimations import animations
     10 from carbonui.util.color import Color
     11 from eve.client.script.ui.control.gaugeCircular import GaugeCircular
     12 from eve.client.script.ui.shared.infoPanels.milestoneTimer.tooltip import MilestoneTooltip, MilestoneRewardTooltip
     13 from milestones.common.constants import MILESTONE_REWARD_NUMBER_OF_MINUTES
     14 
     15 class MilestoneTimer(Transform):
     16     default_name = 'MilestoneTimer'
     17     default_align = uiconst.TOPLEFT
     18     default_width = 32
     19     default_height = 32
     20     default_state = uiconst.UI_NORMAL
     21     default_scalingCenter = (0.5, 0.5)
     22     gauge_alpha = 0.2
     23     update_interval_ms = 1000
     24     animate_interval_ms = 2000
     25     default_color = Color.HextoRGBA('#31C4A1')
     26     default_animation_loop_sound = 'isk_animation_loop_play'
     27     default_animation_loop_stop = 'isk_animation_loop_stop'
     28     default_claim_sound = 'isk_animation_claim_play'
     29     __notifyevents__ = ['OnLoginMilestoneAchieved', 'OnAirNpeStateChanged']
     30 
     31     def ApplyAttributes(self, attributes):
     32         super(MilestoneTimer, self).ApplyAttributes(attributes)
     33         self.iconPath = attributes.get('iconPath', '')
     34         self.iconColor = attributes.get('iconColor', self.default_color)
     35         self.gaugeColorStart = attributes.get('gaugeColorStart', self.default_color)
     36         self.gaugeColorEnd = attributes.get('gaugeColorEnd', self.default_color)
     37         self.milestoneID = attributes.get('milestoneID', None)
     38         self.animation_loop_sound = attributes.get('animationSoundStart', self.default_animation_loop_sound)
     39         self.animation_loop_stop = attributes.get('animationSoundStop', self.default_animation_loop_stop)
     40         self.claim_reward_sound = attributes.get('claimRewardSound', self.default_claim_sound)
     41         self.updateThread = None
     42         self.animateThread = None
     43         self.ConstructLayout()
     44         timeLeft = attributes.get('timeLeft', gametime.MIN)
     45         self.secondsLeft = gametime.GetSecondsUntilWallclockTime(timeLeft)
     46         totalTime = attributes.get('totalTime', gametime.MIN)
     47         self.totalSeconds = gametime.GetSecondsUntilWallclockTime(gametime.GetWallclockTime() + totalTime)
     48         self.updateThread = AutoTimer(interval=self.update_interval_ms, method=self._UpdateGauge)
     49         self.tooltipPanelClassInfo = MilestoneTooltip(self.milestoneID, self.totalSeconds, self.GetSecondsPassed)
     50         sm.RegisterNotify(self)
     51 
     52     def Close(self):
     53         PlaySound(self.animation_loop_stop)
     54         self.updateThread = None
     55         self.animateThread = None
     56         super(MilestoneTimer, self).Close()
     57 
     58     def ConstructLayout(self):
     59         self.icon = Sprite(parent=self, align=uiconst.CENTER, width=16, height=16, color=self.iconColor, state=uiconst.UI_DISABLED, texturePath=self.iconPath)
     60         self.gauge = GaugeCircular(parent=self, radius=16, align=uiconst.CENTER, colorStart=self.gaugeColorStart, colorEnd=self.gaugeColorEnd, colorBg=Color(*self.iconColor).SetAlpha(self.gauge_alpha).GetRGBA(), lineWidth=2.5, clockwise=False, showMarker=False, state=uiconst.UI_DISABLED)
     61 
     62     def _UpdateGauge(self):
     63         self.secondsLeft -= 1
     64         ratio = self.GetSecondsPassed() / float(self.totalSeconds)
     65         ratio = min(1.0, max(0.0, ratio))
     66         self.gauge.SetValue(ratio)
     67 
     68     def GetSecondsPassed(self):
     69         return self.totalSeconds - self.secondsLeft
     70 
     71     def OnLoginMilestoneAchieved(self, milestoneID, iskAmount):
     72         self.updateThread.KillTimer()
     73         shouldStartAnimating = self.display
     74         if shouldStartAnimating:
     75             self.StartAnimateLoop()
     76         self.tooltipPanelClassInfo = MilestoneRewardTooltip(milestoneID, iskAmount, lambda x: self._ClaimRewards(milestoneID), MILESTONE_REWARD_NUMBER_OF_MINUTES)
     77 
     78     def StartAnimateLoop(self):
     79         PlaySound(self.animation_loop_sound)
     80         self.AnimateNotification()
     81         self.animateThread = AutoTimer(interval=self.animate_interval_ms, method=self.AnimateNotification)
     82 
     83     def _ClaimRewards(self, milestoneID):
     84         PlaySound(self.claim_reward_sound)
     85         sm.GetService('milestoneSvc').ClaimRewards(milestoneID)
     86         self.Close()
     87 
     88     def AnimateNotification(self):
     89         animations.Tr2DRotateTo(self.icon, duration=0.75, endAngle=2 * math.pi)
     90         animations.Tr2DScaleTo(self, startScale=(1.0, 1.0), endScale=(1.2, 1.2), curveType=uiconst.ANIM_WAVE, timeOffset=0.75)