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

pointerWnd.py (12425B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\pointerTool\pointerWnd.py
      2 from __future__ import print_function
      3 import uthread
      4 from carbon.common.script.util.timerstuff import AutoTimer
      5 from carbonui.primitives.container import Container
      6 from carbonui.primitives.containerAutoSize import ContainerAutoSize
      7 from carbonui.primitives.fill import Fill
      8 from carbonui.primitives.frame import Frame
      9 from carbonui.util.various_unsorted import IsUnder
     10 from carbonui.control.checkbox import Checkbox
     11 from eve.client.script.ui.control.eveLabel import EveLabelMedium, EveLabelSmall
     12 from eve.client.script.ui.control.eveScroll import Scroll
     13 from carbonui.control.window import Window
     14 import carbonui.const as uiconst
     15 from carbonui.uicore import uicore
     16 from eve.client.script.ui.control.infoIcon import MoreInfoIcon
     17 from eve.client.script.ui.quickFilter import QuickFilterEdit
     18 from eve.client.script.ui.shared.pointerTool.pointerFrame import PointerFrame
     19 from eve.client.script.ui.shared.pointerTool.pointerToolConst import SOURCE_LOCATION_WINDOW
     20 from eve.client.script.ui.shared.pointerTool.pointerToolFraming import CreateBinding, RemoveAllFrames, RemoveOldFrames
     21 from eve.client.script.ui.shared.pointerTool.pointerToolFunctions import GetScreenElementsByUniqueName, FindElementUnderMouse
     22 from eve.client.script.ui.shared.pointerTool.pointerToolUtil import GetFilteredScrollList
     23 from eve.client.script.ui.shared.pointerTool.pointerToolSignals import on_reset
     24 from globalConfig.getFunctions import ArePointerLinksActive
     25 from localization import GetByLabel
     26 import log
     27 FRAME_UPDATE_INTERVAL_MSEC = 200
     28 
     29 class PointerToolWnd(Window):
     30     __guid__ = 'pointerToolWnd'
     31     __notifyevents__ = ['OnMapShortcut', 'OnFavoriteGroupChanged']
     32     default_height = 500
     33     default_width = 500
     34     default_minSize = (300, 300)
     35     default_windowID = 'pointerToolWnd'
     36     default_iconNum = 'res:/UI/Texture/WindowIcons/UIHelper.png'
     37     default_captionLabelPath = 'UI/Help/PointerWndName'
     38     default_isCompactable = True
     39 
     40     def DebugReload(self, *args):
     41         self.Close()
     42         uthread.new(PointerToolWnd)
     43 
     44     def ApplyAttributes(self, attributes):
     45         self.updateFrameThread = None
     46         Window.ApplyAttributes(self, attributes)
     47         if not ArePointerLinksActive(sm.GetService('machoNet')):
     48             log.LogError("Trying to open the pointer tool when it's not allowed")
     49             Window.Close(self)
     50             return
     51         self.frameCurveSet = uicore.animations.CreateCurveSet(useRealTime=True)
     52         self.frameCurveSet.name = 'frameCurveSet'
     53         self.frameCurveSet.Play()
     54         self.pythonBindings = {}
     55         self.frameCont = getattr(uicore.desktop, 'pointerFrameCont', None)
     56         if not self.frameCont or self.frameCont.destroyed:
     57             self.frameCont = Container(name='pointerFrameCont', parent=uicore.desktop, align=uiconst.TOALL, state=uiconst.UI_DISABLED, idx=0)
     58             uicore.desktop.pointerFrameCont = self.frameCont
     59         self.frameCont.Flush()
     60         self.frameDict = {}
     61         self._selectedObject = None
     62         self._hiliteFrame = Fill(parent=uicore.desktop, align=uiconst.ABSOLUTE, color=(0, 1, 0, 0.3), idx=0, state=uiconst.UI_DISABLED)
     63         self._selectedFrame = Frame(parent=uicore.desktop, align=uiconst.ABSOLUTE, color=(0, 1, 0, 0.3), idx=0, state=uiconst.UI_DISABLED)
     64         aboutWndCont = ContainerAutoSize(name='aboutWndCont', parent=self.sr.main, align=uiconst.TOTOP, alignMode=uiconst.TOTOP, minHeight=16)
     65         aboutIcon = MoreInfoIcon(parent=aboutWndCont, align=uiconst.TOPLEFT, hint=GetByLabel('UI/Help/PointerWndText'))
     66         text = GetByLabel('UI/Help/AboutHelpPointerWindow')
     67         labelLeft = aboutIcon.left + aboutIcon.width + 12
     68         label = EveLabelMedium(text=text, parent=aboutWndCont, padLeft=labelLeft, state=uiconst.UI_NORMAL, color=None, align=uiconst.TOTOP)
     69         label.opacity = 0.75
     70         self.shortcutLabel = None
     71         cmd = uicore.cmd.commandMap.GetCommandByName('CmdGetUiPointer')
     72         if cmd:
     73             shortcutCont = ContainerAutoSize(name='shortcutCont', parent=self.sr.main, align=uiconst.TOTOP, alignMode=uiconst.TOTOP, minHeight=16)
     74             moreInfoIcon = MoreInfoIcon(parent=shortcutCont, align=uiconst.TOPLEFT, hint=GetByLabel('UI/Help/PointerWndTextWithoutShortcut', cmdName=cmd.GetName()))
     75             text = self.GetShortcutText()
     76             labelLeft = moreInfoIcon.left + moreInfoIcon.width + 12
     77             self.shortcutLabel = EveLabelMedium(text=text, parent=shortcutCont, padLeft=labelLeft, state=uiconst.UI_NORMAL, color=None, align=uiconst.TOTOP)
     78             self.shortcutLabel.opacity = 0.75
     79         text = GetByLabel('UI/Help/PointerWndShowHighlights')
     80         areFramesVisible = settings.user.ui.Get('poingerWnd_showFrames', False)
     81         cb = Checkbox(text=text, parent=self.sr.main, settingsPath=('user', 'ui'), settingsKey='poingerWnd_showFrames', checked=areFramesVisible, callback=self.CheckBoxChange, align=uiconst.TOTOP)
     82         self.cbText = EveLabelMedium(name='cbText', parent=self.sr.main, text=GetByLabel('UI/Help/PointerWndShowHighlightsDesc'), align=uiconst.TOTOP, padLeft=cb.padLeft + cb.label.padLeft, padBottom=8)
     83         self.SetDisplaysFromCheckbox(cb)
     84         self.topRightCont = ContainerAutoSize(name='topRightCont2', parent=self.sr.main, align=uiconst.TOTOP, clipChildren=True, padding=(0, 0, 0, 4))
     85         filterEditCont = ContainerAutoSize(parent=self.topRightCont, align=uiconst.TOTOP, maxWidth=200)
     86         self.filterEdit = QuickFilterEdit(name='filterEdit', parent=filterEditCont, hintText=GetByLabel('UI/Inventory/Filter'), maxLength=64, align=uiconst.TOPRIGHT, OnClearFilter=self.OnFilterEditCleared, width=200, isTypeField=True)
     87         self.filterEdit.ReloadFunction = self.OnFilterEdit
     88         self.scroll = Scroll(parent=self.sr.main, padding=(0, 4, 0, 0), id='pointerScroll')
     89         self.scroll.multiSelect = False
     90         self.LoadContent()
     91         self._keyDownCookie = uicore.uilib.RegisterForTriuiEvents([uiconst.UI_KEYDOWN], self.OnGlobalKeyDown)
     92         if areFramesVisible:
     93             self._UpdateFrames()
     94             self.updateFrameThread = AutoTimer(FRAME_UPDATE_INTERVAL_MSEC, self._UpdateFrames)
     95         on_reset.connect(self.on_reset)
     96         sm.RegisterNotify(self)
     97         uicore.registry.SetFocus(self.filterEdit)
     98 
     99     def GetShortcutText(self):
    100         cmd = uicore.cmd.commandMap.GetCommandByName('CmdGetUiPointer')
    101         if cmd:
    102             if cmd.shortcut:
    103                 shortcut = '<b>%s</b>' % cmd.GetShortcutAsString()
    104             else:
    105                 shortcut = GetByLabel('UI/Help/ShortcutNotSet')
    106             return GetByLabel('UI/Help/PointerWndTextWithShortcut', shortcut=shortcut)
    107         return ''
    108 
    109     def OnMapShortcut(self, *args):
    110         if self.shortcutLabel:
    111             self.shortcutLabel.text = self.GetShortcutText()
    112 
    113     def CheckBoxChange(self, cb, *args):
    114         framesAreVisible = cb.checked
    115         if framesAreVisible:
    116             self._UpdateFrames()
    117             self.updateFrameThread = AutoTimer(FRAME_UPDATE_INTERVAL_MSEC, self._UpdateFrames)
    118         else:
    119             self.updateFrameThread = False
    120         self.SetDisplaysFromCheckbox(cb)
    121 
    122     def SetDisplaysFromCheckbox(self, cb):
    123         text = GetByLabel('UI/Help/PointerWndShowHighlights')
    124         framesAreVisible = cb.checked
    125         self.cbText.display = framesAreVisible
    126         self.frameCont.display = framesAreVisible
    127         for eachFrame in self.frameDict.itervalues():
    128             if eachFrame and not eachFrame[0].destroyed:
    129                 eachFrame[0].display = framesAreVisible
    130 
    131         cb.label.text = text
    132 
    133     def LoadContent(self, selectedName = None):
    134         scrollList = self.GetScrollList(selectedName)
    135         self.scroll.LoadContent(contentList=scrollList, noContentHint=GetByLabel('UI/Common/NothingFound'))
    136 
    137     def GetScrollList(self, selectedName = None):
    138         filterText = self.filterEdit.GetValue().strip().lower()
    139         scrollList = GetFilteredScrollList(filterText, selectedName, sourceLocation=SOURCE_LOCATION_WINDOW)
    140         if len(scrollList) == 1:
    141             scrollList[0]['forceOpen'] = True
    142         return scrollList
    143 
    144     def OnFilterEditCleared(self):
    145         self.LoadContent()
    146 
    147     def OnFilterEdit(self):
    148         self.LoadContent()
    149 
    150     def _FrameElements(self, elementsToFrame):
    151         for key, eachElement in elementsToFrame.iteritems():
    152             if eachElement is None or eachElement.destroyed or not eachElement.display:
    153                 continue
    154             f, _ = self.frameDict.get(key, (None, None))
    155             if f and not f.destroyed:
    156                 continue
    157             try:
    158                 if isinstance(eachElement, Window) and eachElement.sr.underlay:
    159                     bgParent = eachElement.sr.underlay
    160                 else:
    161                     bgParent = eachElement
    162                 f = PointerFrame(bgParent=bgParent, idx=0, state=uiconst.UI_DISABLED, color=(0.2, 0.6, 1, 0.3))
    163             except Exception as e:
    164                 elementPos = eachElement.GetAbsolute()
    165                 f = PointerFrame(parent=self.frameCont, align=uiconst.ABSOLUTE, color=(0.2, 0.6, 1, 0.3), idx=0, state=uiconst.UI_DISABLED, pos=elementPos)
    166                 self._CreateBinding(key, eachElement, f)
    167 
    168             uicore.animations.FadeTo(f, 0.4, 0.6, duration=1.5, loops=uiconst.ANIM_REPEAT, curveType=uiconst.ANIM_BOUNCE)
    169             self.frameDict[key] = (f, eachElement)
    170 
    171     def _RemoveOldFrames(self):
    172         RemoveOldFrames(self.frameDict, self.pythonBindings, self.frameCurveSet)
    173 
    174     def _UpdateFrames(self):
    175         if not settings.user.ui.Get('poingerWnd_showFrames', False):
    176             self.updateFrameThread = None
    177             return
    178         self._RemoveOldFrames()
    179         allPointers = sm.GetService('helpPointer').GetAllPointersByElementName()
    180         missingElementNames = [ x for x in allPointers.iterkeys() if x not in self.frameDict ]
    181         if missingElementNames:
    182             dictOfMissingElements = GetScreenElementsByUniqueName(missingElementNames)
    183             if dictOfMissingElements:
    184                 self._FrameElements(dictOfMissingElements)
    185 
    186     def _CreateBinding(self, key, element, elementFrame):
    187         CreateBinding(key, element, elementFrame, self.pythonBindings, self.frameCurveSet)
    188 
    189     def OnGlobalKeyDown(self, *args, **kwds):
    190         if not settings.user.ui.Get('poingerWnd_showFrames', False):
    191             return True
    192         if self.destroyed:
    193             return False
    194         ctrl = uicore.uilib.Key(uiconst.VK_CONTROL)
    195         mo = uicore.uilib.mouseOver
    196         if ctrl and not (IsUnder(mo, self) or mo is self):
    197             uthread.new(self.ShowUIObject, mo)
    198         return True
    199 
    200     def ShowUIObject(self, mouseOver):
    201         selectedElmentName = None
    202         selectedNode = self.scroll.GetSelected()
    203         if selectedNode:
    204             selectedElmentName = selectedNode[0].uiElementName
    205         uiElementName, _ = FindElementUnderMouse(mouseOver)
    206         if not uiElementName:
    207             self.scroll.DeselectAll()
    208             return
    209         if uiElementName == selectedElmentName:
    210             self.scroll.ScrollToSelectedNode()
    211             return
    212         self.scroll.DeselectAll()
    213         self.filterEdit.SetValue('', docallback=False)
    214         self.LoadContent(uiElementName)
    215         self.scroll.ScrollToSelectedNode()
    216 
    217     def OnFavoriteGroupChanged(self):
    218         self.LoadContent()
    219 
    220     def on_reset(self, *args):
    221         self.LoadContent()
    222 
    223     def Close(self, *args, **kwds):
    224         self.updateFrameThread = None
    225         on_reset.disconnect(self.on_reset)
    226         try:
    227             self._RemoveAllFramesAndStopCurveSet()
    228             uicore.event.UnregisterForTriuiEvents(self._keyDownCookie)
    229         except Exception as e:
    230             print('e = ', e)
    231 
    232         frame = getattr(self, '_hiliteFrame', None)
    233         if frame:
    234             frame.Close()
    235         if getattr(self, '_selectedFrame', None):
    236             self._selectedFrame.Close()
    237         Window.Close(self, *args, **kwds)
    238 
    239     def _RemoveAllFramesAndStopCurveSet(self):
    240         RemoveAllFrames(self.pythonBindings, self.frameDict, self.frameCurveSet)
    241         self.frameCont.Flush()
    242         if getattr(uicore.desktop, 'pointerFrameCont', None):
    243             uicore.desktop.pointerFrameCont.Close()
    244             delattr(uicore.desktop, 'pointerFrameCont')
    245         self.frameCurveSet.Stop()
    246         self.frameCurveSet = None