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

searchCont.py (4909B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\structure\accessGroups\searchCont.py
      2 import math
      3 from carbonui import fontconst
      4 from carbonui.control.singlelineedits.singleLineEditText import SingleLineEditText
      5 from carbonui.primitives.container import Container
      6 from carbonui.primitives.transform import Transform
      7 from carbonui.control.buttonIcon import ButtonIcon
      8 import carbonui.const as uiconst
      9 from eve.client.script.ui.control.eveLabel import Label
     10 from localization import GetByLabel
     11 from carbonui.uicore import uicore
     12 from bannedwords.client import bannedwords
     13 hintText = GetByLabel('UI/Structures/AccessGroups/SearchFieldHint')
     14 
     15 class SearchCont(Container):
     16 
     17     def ApplyAttributes(self, attributes):
     18         Container.ApplyAttributes(self, attributes)
     19         self.controller = attributes.controller
     20         texturePath = 'res:/UI/Texture/WindowIcons/peopleandplaces.png'
     21         searchIconHint = GetByLabel('UI/Structures/AccessGroups/SearchButtonHint')
     22         self.searchIcon = ButtonIcon(name='searchIcon', parent=self, align=uiconst.CENTERRIGHT, pos=(2, 0, 24, 24), iconSize=24, texturePath=texturePath, func=self.OnSearchBtnClicked, hint=searchIconHint)
     23         arrowTexturePath = 'res:/UI/Texture/Icons/1_16_99.png'
     24         self.arrowCont = Transform(name='arrowCont', parent=self, pos=(24, 0, 16, 16), align=uiconst.CENTERRIGHT, rotation=self.GetRotation())
     25         self.expandArrow = ButtonIcon(name='expandArrow', parent=self.arrowCont, pos=(0, 0, 16, 16), iconSize=16, texturePath=arrowTexturePath, func=self.OnExpanderClicked)
     26         self.searchField = SingleLineEditText(parent=self, align=uiconst.CENTERRIGHT, pos=(40,
     27          0,
     28          self.GetWidth(),
     29          0), OnReturn=self.DoSearch, hintText=hintText, isCharCorpOrAllianceField=True, maxLength=100)
     30         self.searchField.OnClearButtonClick = self.OnClearingSearchField
     31         self.searchField.ShowClearButton(hint=GetByLabel('UI/Inventory/Clear'))
     32         self.memberNamesByMemberID = {}
     33         self.height = max(self.searchField.height, self.searchIcon.height)
     34         self.collapsedWidth = 10 + self.searchField.left + self.searchField.width
     35         self.width = self.collapsedWidth
     36 
     37     def OnSearchBtnClicked(self, *args):
     38         if settings.user.ui.Get('accessGroup_searchExpanded', False):
     39             self.DoSearch()
     40         else:
     41             self.OnExpanderClicked()
     42 
     43     def OnExpanderClicked(self, *args):
     44         isExpandedNow = settings.user.ui.Get('accessGroup_searchExpanded', False)
     45         settings.user.ui.Set('accessGroup_searchExpanded', not isExpandedNow)
     46         newRotation = self.GetRotation()
     47         newWidth = self.GetWidth()
     48         uicore.animations.MorphScalar(self.arrowCont, 'rotation', self.arrowCont.rotation, newRotation, duration=0.35)
     49         uicore.animations.MorphScalar(self.searchField, 'width', startVal=self.searchField.width, endVal=newWidth, duration=0.35)
     50         self.width = self.collapsedWidth + newWidth
     51         if not isExpandedNow:
     52             self.PrimeMembers()
     53 
     54     def GetRotation(self):
     55         if settings.user.ui.Get('accessGroup_searchExpanded', False):
     56             return math.pi
     57         return 0
     58 
     59     def GetWidth(self):
     60         if settings.user.ui.Get('accessGroup_searchExpanded', False):
     61             width, _ = Label.MeasureTextSize(text=hintText, fontsize=fontconst.EVE_MEDIUM_FONTSIZE)
     62             return max(200, width + 10)
     63         return 0
     64 
     65     def DoSearch(self, *args):
     66         searchString = self.searchField.GetValue().lower()
     67         if len(searchString) < 3:
     68             self.controller.SetCurrentSearchResults(None)
     69             return
     70         bannedwords.check_search_words_allowed(searchString)
     71         allMemberInfo = self.PrimeMembers()
     72         groupsWithMatchedMembers = set()
     73         matchedMembers = set()
     74         for groupID, membersDict in allMemberInfo.iteritems():
     75             for eachMemberID in membersDict.iterkeys():
     76                 memberName = self.GetMemberName(eachMemberID)
     77                 if memberName.find(searchString) > -1:
     78                     groupsWithMatchedMembers.add(groupID)
     79                     matchedMembers.add(eachMemberID)
     80 
     81         searchResults = (matchedMembers, groupsWithMatchedMembers)
     82         self.controller.SetCurrentSearchResults(searchResults)
     83 
     84     def PrimeMembers(self):
     85         allMemberInfo, allMemberIDs = self.controller.GetAllMyMemberIDs()
     86         cfg.eveowners.Prime(allMemberIDs)
     87         return allMemberInfo
     88 
     89     def GetMemberName(self, memberID):
     90         memberName = self.memberNamesByMemberID.get(memberID)
     91         if memberName:
     92             return memberName
     93         memberName = cfg.eveowners.Get(memberID).name.lower()
     94         self.memberNamesByMemberID[memberID] = memberName
     95         return memberName
     96 
     97     def OnClearingSearchField(self):
     98         SingleLineEditText.OnClearButtonClick(self.searchField)
     99         self.DoSearch()