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

hackingProgressBar.py (6384B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\control\hackingProgressBar.py
      2 import math
      3 import random
      4 import blue
      5 import uthread
      6 from carbonui import uiconst
      7 from carbonui.primitives.container import Container
      8 from carbonui.primitives.fill import Fill
      9 from carbonui.primitives.frame import Frame
     10 from carbonui.util.color import Color
     11 from carbonui.util.effect import UIEffects
     12 from eve.client.script.ui.control.eveLabel import EveHeaderMedium, Label
     13 from eve.client.script.ui.util import uix
     14 
     15 class HackingProgressBar(Container):
     16     default_name = 'hackingProgressBar'
     17     HEXDIGITS = ['0',
     18      '1',
     19      '2',
     20      '3',
     21      '4',
     22      '5',
     23      '6',
     24      '7',
     25      '8',
     26      '9',
     27      'A',
     28      'B',
     29      'C',
     30      'D',
     31      'E',
     32      'F']
     33 
     34     def ApplyAttributes(self, attributes):
     35         Container.ApplyAttributes(self, attributes)
     36         color = attributes.Get('color', Color.WHITE)
     37         backgroundColor = attributes.Get('backgroundColor', None)
     38         self.value = attributes.Get('value', 0.0)
     39         self.uiEffects = UIEffects()
     40         self.busy = False
     41         self.queuedSetValue = None
     42         self.gaugeCont = Container(parent=self, name='gaugeCont', pos=(0,
     43          0,
     44          self.width,
     45          self.height), align=uiconst.TOPLEFT)
     46         Frame(parent=self.gaugeCont, color=(1.0, 1.0, 1.0, 0.2))
     47         self.gauge = Fill(parent=self.gaugeCont, name='gauge', align=uiconst.TOLEFT, width=0, color=color)
     48         if backgroundColor is None:
     49             backgroundColor = Color(*color).SetAlpha(0.2).GetRGBA()
     50         Fill(parent=self.gaugeCont, name='background', color=backgroundColor)
     51         testString = ''.join(self.HEXDIGITS)
     52         fontSize = 1
     53         textHeight = uix.GetTextHeight(testString, fontsize=fontSize)
     54         while textHeight < self.height:
     55             fontSize += 1
     56             textHeight = uix.GetTextHeight(testString, fontsize=fontSize)
     57         else:
     58             fontSize -= 1
     59             textHeight = uix.GetTextHeight(testString, fontsize=fontSize)
     60 
     61         self.textCont = Container(parent=self, name='textCont', pos=(0,
     62          0,
     63          self.width,
     64          textHeight), align=uiconst.CENTER, clipChildren=True, idx=0)
     65         self.text = Label(parent=self.textCont, name='hackText', align=uiconst.TOALL, fontsize=fontSize, text='')
     66         hackText = random.choice(self.HEXDIGITS)
     67         while uix.GetTextWidth(hackText[1:], fontsize=fontSize) < self.width:
     68             hackText += random.choice(self.HEXDIGITS)
     69 
     70         self.text.text = hackText
     71         self.SetValueInstantly(self.value)
     72         self.hackStrings = ['Hacking Gibson...',
     73          'Cracking Codes...',
     74          'Inserting Rootkit...',
     75          'Defeating ICE...',
     76          'Circumventing Firewall...',
     77          'Polymorphing Virii...',
     78          'Erasing Logs...',
     79          'Reticulating Splines...',
     80          'Twisting Mersenne...',
     81          'Curving Ellipses...',
     82          'Analyzing Ciphers...',
     83          'Factoring Primes...']
     84         self.hackText = EveHeaderMedium(text='', parent=self, align=uiconst.CENTERBOTTOM, height=20, state=uiconst.UI_HIDDEN, top=-24)
     85         self.active = True
     86         uthread.new(self._CycleText)
     87 
     88     def SetValue(self, value, frequency = 10.0):
     89         if self.value == value:
     90             return
     91         if self.busy:
     92             self.queuedSetValue = (self.gauge, value, frequency)
     93             return
     94         uthread.new(self._SetValue, self.gauge, value, frequency)
     95 
     96     def SetValueInstantly(self, value):
     97         self.value = value
     98         self.gauge.width = int(self.width * value)
     99 
    100     def _SetValue(self, gauge, value, frequency):
    101         if not self or self.destroyed:
    102             return
    103         self.busy = True
    104         self.value = value
    105         self.uiEffects.MorphUIMassSpringDamper(gauge, 'width', int(self.width * value), newthread=0, float=0, dampRatio=0.6, frequency=frequency, minVal=0, maxVal=self.width, maxTime=2.0)
    106         if not self or self.destroyed:
    107             return
    108         self.busy = False
    109         if self.queuedSetValue:
    110             nextSetValue = self.queuedSetValue
    111             self.queuedSetValue = None
    112             self._SetValue(*nextSetValue)
    113 
    114     def _CycleText(self):
    115         t = 0.0
    116         lastTextChange = blue.os.GetWallclockTime()
    117         self.hackText.text = random.choice(self.hackStrings)
    118         self.hackText.state = uiconst.UI_DISABLED
    119         while self and not self.destroyed and self.active:
    120             t += 1.0 / max(1.0, blue.os.fps)
    121             self.hackText.opacity = math.cos(t * math.pi / 0.5) * 0.4 + 0.6
    122             if lastTextChange + 5 * const.SEC < blue.os.GetWallclockTime():
    123                 self.hackText.text = random.choice(self.hackStrings)
    124                 lastTextChange = blue.os.GetWallclockTime()
    125             while uix.GetTextWidth(self.text.text[1:], fontsize=self.text.fontsize) - (60 + abs(self.text.left)) < self.width:
    126                 self.text.text += random.choice(self.HEXDIGITS)
    127 
    128             self.text.left -= 2
    129             firstLetterWidth = uix.GetTextWidth(self.text.text[0], fontsize=self.text.fontsize)
    130             while abs(self.text.left) > firstLetterWidth:
    131                 self.text.text = self.text.text[1:]
    132                 self.text.left += firstLetterWidth
    133                 firstLetterWidth = uix.GetTextWidth(self.text.text[0], fontsize=self.text.fontsize)
    134 
    135             blue.pyos.synchro.SleepWallclock(20)
    136 
    137         while self and not self.destroyed and self.text.opacity > 0.0:
    138             self.text.opacity -= 0.03
    139             self.text.opacity = max(self.text.opacity, 0.0)
    140             blue.pyos.synchro.SleepWallclock(70)
    141 
    142     def Finalize(self, complete = False):
    143         uthread.new(self._FinishText, complete)
    144 
    145     def _FinishText(self, complete):
    146         flipCount = 0
    147         self.hackText.opacity = 0.8
    148         self.hackText.state = uiconst.UI_HIDDEN
    149         self.hackText.text = 'HACK COMPLETE!' if complete else 'DISCONNECTING...'
    150         self.active = False
    151         while flipCount < 3:
    152             blue.pyos.synchro.SleepWallclock(500)
    153             if not self or self.destroyed:
    154                 return
    155             if self.hackText.state == uiconst.UI_HIDDEN:
    156                 self.hackText.state = uiconst.UI_DISABLED
    157             else:
    158                 self.hackText.state = uiconst.UI_HIDDEN
    159                 flipCount += 1
    160 
    161         self.state = uiconst.UI_HIDDEN