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

historySlider.py (9305B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\login\charcreation_new\historySlider.py
      2 import carbonui.const as uiconst
      3 import uthread
      4 import charactercreator.const as ccConst
      5 import localization
      6 from carbon.client.script.environment.AudioUtil import PlaySound
      7 from carbon.common.script.util import timerstuff
      8 from carbonui.primitives.container import Container
      9 from carbonui.primitives.fill import Fill
     10 from carbonui.primitives.frame import Frame
     11 from carbonui.uicore import uicore
     12 from carbonui.util.various_unsorted import FlushList
     13 from eve.client.script.ui.control import eveIcon
     14 from eve.client.script.ui.login.charcreation_new.charCreationUtils import CCLabel
     15 from eve.client.script.ui.login.charcreation_new.dollManager import GetCharacterCreationDollManager
     16 
     17 class CharacterCreationHistorySlider(Container):
     18     __notifyevents__ = ['OnDollUpdated', 'OnHistoryUpdated']
     19     SIZE = 15
     20     BITWIDTH = 4
     21     BITGAP = 3
     22     default_name = 'CharacterCreationHistorySlider'
     23     default_left = 0
     24     default_top = 0
     25     default_width = 400
     26     default_height = SIZE
     27     default_align = uiconst.CENTER
     28 
     29     def ApplyAttributes(self, attributes):
     30         Container.ApplyAttributes(self, attributes)
     31         for each in uicore.layer.main.children:
     32             if each.name == self.default_name:
     33                 each.Close()
     34 
     35         if not attributes.parent:
     36             uicore.layer.main.children.insert(0, self)
     37         self.bitChangeCheck = attributes.bitChangeCheck
     38         self._lastLit = None
     39         self._currentIndex = None
     40         self._scrolling = False
     41         self._mouseOffset = 0
     42         self._lastLoadIndex = attributes.lastLitHistoryBit
     43         for name, icon, align in (('left', ccConst.ICON_BACK, uiconst.TOLEFT), ('right', ccConst.ICON_NEXT, uiconst.TORIGHT)):
     44             btn = Container(name='%sBtn' % name, parent=self, align=align, width=self.SIZE, state=uiconst.UI_NORMAL)
     45             btn.icon = eveIcon.Icon(name='%sIcon' % name, icon=icon, parent=btn, state=uiconst.UI_DISABLED, align=uiconst.CENTER, color=ccConst.COLOR50)
     46             Frame(parent=btn, frameConst=ccConst.MAINFRAME_INV, color=(1.0, 1.0, 1.0, 0.5))
     47             Fill(parent=btn, color=(0.0, 0.0, 0.0, 0.25))
     48             btn.OnClick = (self.OnButtonClicked, btn)
     49             btn.OnMouseEnter = (self.OnButtonEnter, btn)
     50             btn.OnMouseExit = (self.OnButtonExit, btn)
     51             btn.cursor = uiconst.UICURSOR_SELECT
     52 
     53         CCLabel(parent=self, idx=0, text=localization.GetByLabel('UI/Login/CharacterCreation/UndoHistory'), top=-20, uppercase=True, letterspace=1, shadowOffset=(0, 0), color=ccConst.COLOR50)
     54         self.mainPar = Container(parent=self, clipChildren=True, padding=(3, 0, 3, 0))
     55         self.bitParent = Container(parent=self.mainPar, align=uiconst.TOPLEFT, height=self.SIZE)
     56         self.scrollHandle = Container(parent=self.bitParent, align=uiconst.TOPLEFT, pos=(0,
     57          0,
     58          10,
     59          self.SIZE), color=(1.0, 1.0, 1.0, 1.0), state=uiconst.UI_NORMAL)
     60         Fill(parent=self.scrollHandle, color=(1.0, 1.0, 1.0, 1.0), padding=(2, 0, 2, 0))
     61         self.scrollHandle.OnMouseDown = self.SH_MouseDown
     62         self.scrollHandle.OnMouseUp = self.SH_MouseUp
     63         Frame(parent=self.mainPar, frameConst=ccConst.MAINFRAME_INV, color=(1.0, 1.0, 1.0, 0.5))
     64         Fill(parent=self.mainPar, color=(0.0, 0.0, 0.0, 0.25))
     65         frame = Frame(parent=self, frameConst=ccConst.FRAME_SOFTSHADE, color=(0.0, 0.0, 0.0, 0.25))
     66         frame.padding = (-32, -5, -32, -15)
     67         self.UpdateHistory()
     68         sm.RegisterNotify(self)
     69 
     70     def OnDollUpdated(self, charID, redundantUpdate, *args):
     71         if not self.destroyed and not redundantUpdate and self.state != uiconst.UI_HIDDEN:
     72             self.UpdateHistory()
     73 
     74     def OnHistoryUpdated(self, *args):
     75         if not self.destroyed:
     76             self.UpdateHistory()
     77 
     78     def UpdateHistory(self):
     79         dnaLog = GetCharacterCreationDollManager().GetDollDNAHistory()
     80         if dnaLog is not None:
     81             self.LoadHistory(len(dnaLog))
     82 
     83     def GetCurrentIndexAndMaxIndex(self):
     84         if self._lastLit and self._lastLit in self.bitParent.children:
     85             currentIndex = self.bitParent.children.index(self._lastLit) - 1
     86         else:
     87             currentIndex = 0
     88         return (currentIndex, len(self.bitParent.children) - 2)
     89 
     90     def OnButtonClicked(self, button, *args):
     91         PlaySound('ui_icc_button_mouse_down_play')
     92         if self.bitChangeCheck and not self.bitChangeCheck():
     93             return
     94         if button.name == 'leftBtn':
     95             direction = -1
     96         else:
     97             direction = 1
     98         self.ButtonScroll(direction)
     99 
    100     def ButtonScroll(self, direction):
    101         currentIndex, maxIndex = self.GetCurrentIndexAndMaxIndex()
    102         if currentIndex + direction > maxIndex:
    103             return
    104         currentIndex += 1
    105         newIndex = max(0, min(len(self.bitParent.children) - 1, direction + currentIndex))
    106         if newIndex == 0:
    107             self._lastLit = None
    108         else:
    109             self._lastLit = self.bitParent.children[newIndex]
    110         self.SettleScrollHandle()
    111         self.UpdateBitsState()
    112         self.UpdatePosition()
    113 
    114     def OnButtonEnter(self, button, *args):
    115         PlaySound('ui_icc_button_mouse_over_play')
    116         button.icon.SetAlpha(1.0)
    117 
    118     def OnButtonExit(self, button, *args):
    119         button.icon.SetAlpha(0.5)
    120 
    121     def LoadHistory(self, historyLength):
    122         FlushList(self.bitParent.children[1:])
    123         litBit = None
    124         for i in xrange(historyLength):
    125             bit = Container(parent=self.bitParent, name='bit_%s' % i, align=uiconst.TOPLEFT, pos=(i * (self.BITWIDTH + self.BITGAP),
    126              0,
    127              self.BITWIDTH + self.BITGAP,
    128              self.SIZE), state=uiconst.UI_NORMAL)
    129             Fill(parent=bit, color=(1.0, 1.0, 1.0, 0.75), padding=(self.BITGAP,
    130              4,
    131              0,
    132              4))
    133             bit.OnClick = (self.OnClickBit, bit)
    134             bit.OnMouseEnter = self.OnBitMouseEnter
    135             bit.idx = i
    136             if i == self._lastLoadIndex:
    137                 litBit = bit
    138 
    139         self._lastLoadIndex = None
    140         self.UpdateContentWidth()
    141         if litBit is None:
    142             self.ScrollTo(1.0, initing=True)
    143         else:
    144             self._lastLit = litBit
    145             self.SettleScrollHandle(initing=True)
    146             self.UpdateBitsState()
    147 
    148     def OnBitMouseEnter(self):
    149         PlaySound('ui_icc_button_mouse_over_play')
    150 
    151     def OnClickBit(self, bit, *args):
    152         PlaySound('ui_icc_button_mouse_down_play')
    153         if self.bitChangeCheck and not self.bitChangeCheck():
    154             return
    155         self._lastLit = bit
    156         self.SettleScrollHandle()
    157         self.UpdateBitsState()
    158 
    159     def UpdateContentWidth(self):
    160         self.bitParent.width = (len(self.bitParent.children) - 1) * (self.BITWIDTH + self.BITGAP) + self.BITGAP
    161 
    162     def ScrollTo(self, portion, initing = False):
    163         l, t, w, h = self.mainPar.GetAbsolute()
    164         scrollRange = min(0, w - self.bitParent.width)
    165         self.scrollHandle.left = int((self.bitParent.width - self.scrollHandle.width) * portion)
    166         self.UpdatePosition()
    167         self.SettleScrollHandle(initing)
    168 
    169     def SH_MouseDown(self, *args):
    170         if self.bitChangeCheck and not self.bitChangeCheck():
    171             return
    172         l, t, w, h = self.scrollHandle.GetAbsolute()
    173         self._mouseOffset = uicore.uilib.x - l
    174         self._scrolling = True
    175         self.scrollTimer = timerstuff.AutoTimer(5, self.DragScroll)
    176 
    177     def SH_MouseUp(self, *args):
    178         if self.bitChangeCheck and not self.bitChangeCheck():
    179             return
    180         self._scrolling = False
    181         self._mouseOffset = 0
    182         self.scrollTimer = None
    183         self.SettleScrollHandle()
    184 
    185     def SettleScrollHandle(self, initing = False):
    186         if self._lastLit is not None:
    187             self.scrollHandle.left = self._lastLit.left
    188             if not initing:
    189                 self._currentIndex = self._lastLit.idx
    190                 uthread.new(GetCharacterCreationDollManager().LoadDnaFromHistory, self._lastLit.idx)
    191                 self._lastLoadIndex = self._lastLit.idx
    192         else:
    193             self.scrollHandle.left = -2
    194 
    195     def DragScroll(self, *args):
    196         l, t, w, h = self.mainPar.GetAbsolute()
    197         bl, bt, bw, bh = self.bitParent.GetAbsolute()
    198         self.scrollHandle.left = min(bw - self.scrollHandle.width, max(0, uicore.uilib.x - self._mouseOffset - bl))
    199         self.UpdatePosition()
    200 
    201     def UpdatePosition(self):
    202         l, t, w, h = self.mainPar.GetAbsolute()
    203         sl, st, sw, sh = self.scrollHandle.GetAbsolute()
    204         if self.bitParent.width <= w:
    205             self.bitParent.left = 0
    206         elif sl < l:
    207             self.bitParent.left += l - sl
    208         elif sl + sw > l + w:
    209             self.bitParent.left -= sl + sw - (l + w)
    210         self.UpdateBitsState()
    211 
    212     def UpdateBitsState(self):
    213         self._lastLit = None
    214         l, t, w, h = self.bitParent.GetAbsolute()
    215         for bit in self.bitParent.children[1:]:
    216             if bit.left + self.BITGAP + self.BITWIDTH / 2 > self.scrollHandle.left + self.scrollHandle.width / 2:
    217                 bit.children[0].opacity = 0.25
    218             else:
    219                 bit.children[0].opacity = 1.0
    220                 self._lastLit = bit