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

historySlider.py (9201B)


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