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

hackingNumberGrid.py (7907B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\control\hackingNumberGrid.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 eve.client.script.ui.control.eveLabel import EveHeaderMedium
     11 
     12 class HackingNumberGrid(Container):
     13     default_name = 'hackingNumberGrid'
     14 
     15     def ApplyAttributes(self, attributes):
     16         Container.ApplyAttributes(self, attributes)
     17         self.cycling = False
     18         self.cyclingThread = None
     19         self.numCellRows = attributes.get('numCellRows', 5)
     20         maxCellsPerRow = attributes.get('maxCellsPerRow', 5)
     21         cellForegroundColor = attributes.get('cellForegroundColor', None)
     22         cellBackgroundColor = attributes.get('cellBackgroundColor', None)
     23         self.cellHeight = attributes.get('cellHeight', 20)
     24         self.cellWidth = attributes.get('cellWidth', 20)
     25         self.cellTextSize = attributes.get('cellTextSize', 16)
     26         self.cellsPerRow = attributes.get('cellsPerRow', 5)
     27         self.deadCells = []
     28         self.liveCells = []
     29         self.doneCells = []
     30         self.cellGlyphs = ['0',
     31          '1',
     32          '2',
     33          '3',
     34          '4',
     35          '5',
     36          '6',
     37          '7',
     38          '8',
     39          '9',
     40          'A',
     41          'B',
     42          'C',
     43          'D',
     44          'E',
     45          'F']
     46         self.cellRows = []
     47         self.cellRowContainers = []
     48         self.cellPaddingVertical = 0
     49         self.cellPaddingHorizontal = 0
     50         if cellForegroundColor is None:
     51             cellForegroundColor = (0.75, 0.0, 0.0, 0.75)
     52         if cellBackgroundColor is None:
     53             cellBackgroundColor = (0.5, 0.5, 0.5, 0.25)
     54         self.cellBackgroundColor = cellBackgroundColor
     55         self.progressColor = cellForegroundColor
     56         self.doneColor = (0.0, 0.5, 0.0, 0.5)
     57         self.flashColor = (0.75, 0.75, 0.75, 0.75)
     58         Frame(parent=self, color=(0.7, 0.7, 0.7, 0.5), idx=0)
     59         for x in xrange(0, self.numCellRows):
     60             newRow = []
     61             newRowContainer = Container(parent=self, name='hackingCellRow', align=uiconst.TOTOP, state=uiconst.UI_DISABLED, pos=(0,
     62              0,
     63              self.width,
     64              self.cellHeight))
     65             for y in xrange(0, self.cellsPerRow):
     66                 newRow.append(self.CreateCell(newRowContainer, self.cellHeight, self.cellWidth, cellBackgroundColor, cellForegroundColor))
     67 
     68             self.cellRows.append(newRow)
     69             self.cellRowContainers.append(newRowContainer)
     70 
     71         self.cellRowSemaphore = uthread.Semaphore()
     72 
     73     def IsCycling(self):
     74         return self.cyclingThread is not None
     75 
     76     def CreateCell(self, parent, height, width, backgroundColorTuple, foregroundColorTuple):
     77         newCell = Container(parent=parent, name='hackingCell', align=uiconst.TOLEFT, state=uiconst.UI_DISABLED, pos=(0,
     78          0,
     79          width,
     80          height), padding=(self.cellPaddingHorizontal,
     81          self.cellPaddingVertical,
     82          self.cellPaddingHorizontal,
     83          self.cellPaddingVertical))
     84         newCell.sr.background = Fill(parent=newCell, color=backgroundColorTuple)
     85         newCellFill = Container(parent=newCell, name='hackFill', align=uiconst.TOPLEFT, pos=(0,
     86          0,
     87          width,
     88          height), padding=(self.cellPaddingHorizontal,
     89          self.cellPaddingVertical,
     90          self.cellPaddingHorizontal,
     91          self.cellPaddingVertical))
     92         newCellFill.sr.background = Fill(parent=newCellFill, color=foregroundColorTuple)
     93         newCellFill.opacity = 0.0
     94         newCell.sr.fill = newCellFill
     95         newCell.sr.text = EveHeaderMedium(text=random.choice(self.cellGlyphs), parent=newCell, align=uiconst.CENTER, fontsize=self.cellTextSize, height=height, state=uiconst.UI_DISABLED)
     96         return newCell
     97 
     98     def SetProgress(self, progress):
     99         if self.cyclingThread is None:
    100             return
    101         progress = min(max(float(progress), 0.0), 1.0)
    102         self.cellRowSemaphore.acquire()
    103         try:
    104             numLockedCells = int(math.floor(progress * self.numCellRows * self.cellsPerRow))
    105             if numLockedCells < len(self.doneCells):
    106                 returnedCells = self.doneCells[numLockedCells:]
    107                 self.doneCells = self.doneCells[:numLockedCells]
    108                 for cell in returnedCells:
    109                     cell.sr.background.SetRGBA(*self.cellBackgroundColor)
    110                     cell.sr.fill.opacity = 0.0
    111                     cell.sr.fill.sr.background.SetRGBA(*self.progressColor)
    112                     self.deadCells.append(cell)
    113 
    114             elif numLockedCells > len(self.doneCells):
    115                 newlyLockedCells = random.sample(self.deadCells + self.liveCells, numLockedCells - len(self.doneCells))
    116                 for cell in newlyLockedCells:
    117                     if cell in self.deadCells:
    118                         self.deadCells.remove(cell)
    119                     if cell in self.liveCells:
    120                         self.liveCells.remove(cell)
    121                     cell.sr.background.SetRGBA(*self.doneColor)
    122                     cell.sr.fill.sr.background.SetRGBA(*self.flashColor)
    123                     cell.sr.fill.opacity = 1.0
    124                     self.doneCells.append(cell)
    125 
    126         finally:
    127             self.cellRowSemaphore.release()
    128 
    129     def BeginColorCycling(self):
    130         if self.cyclingThread is not None:
    131             return
    132         self.state = uiconst.UI_DISABLED
    133         self.cycling = True
    134         self.deadCells = []
    135         self.liveCells = []
    136         self.doneCells = []
    137         for row in self.cellRows:
    138             for cell in row:
    139                 cell.sr.background.SetRGBA(*self.cellBackgroundColor)
    140                 cell.sr.fill.sr.background.SetRGBA(*self.progressColor)
    141                 if cell.sr.fill.opacity <= 0.0:
    142                     self.deadCells.append(cell)
    143 
    144         self.cyclingThread = uthread.new(self._ColorCycle)
    145 
    146     def _ColorCycle(self):
    147         while 1:
    148             blue.pyos.synchro.SleepWallclock(100)
    149             self.cellRowSemaphore.acquire()
    150             try:
    151                 if self.cycling:
    152                     newlyRevivedCell = None
    153                     if len(self.deadCells) > 0:
    154                         newlyRevivedCell = random.choice(self.deadCells)
    155                         newlyRevivedCell.sr.fill.opacity = 1.0
    156                         self.deadCells.remove(newlyRevivedCell)
    157                     for cell in self.deadCells:
    158                         cell.sr.text.text = random.choice(self.cellGlyphs)
    159 
    160                     for cell in self.liveCells[:]:
    161                         cell.sr.text.text = random.choice(self.cellGlyphs)
    162                         cell.sr.fill.opacity -= 0.05
    163                         if cell.sr.fill.opacity <= 0.0:
    164                             cell.sr.fill.opacity = 0.0
    165                             self.liveCells.remove(cell)
    166                             self.deadCells.append(cell)
    167 
    168                     if newlyRevivedCell is not None:
    169                         self.liveCells.append(newlyRevivedCell)
    170                 else:
    171                     for cell in self.liveCells:
    172                         if cell.sr.fill.opacity > 0.0:
    173                             cell.sr.fill.opacity = max(0.0, cell.sr.fill.opacity - 0.05)
    174 
    175                 for cell in self.doneCells:
    176                     if cell.sr.fill.opacity > 0.0:
    177                         cell.sr.fill.opacity = max(0.0, cell.sr.fill.opacity - 0.05)
    178 
    179             finally:
    180                 self.cellRowSemaphore.release()
    181 
    182     def StopColorCycling(self):
    183         self.cycling = False
    184         uthread.new(self._Finish)
    185 
    186     def _Finish(self):
    187         blue.pyos.synchro.SleepWallclock(500)
    188         if self and not self.destroyed and self.cyclingThread is not None:
    189             self.cyclingThread.kill()
    190             self.cyclingThread = None