pointerToolUtil.py (11515B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\pointerTool\pointerToolUtil.py 2 from carbonui.util.sortUtil import SortListOfTuples 3 from eve.client.script.ui.control.entries.util import GetFromClass 4 from eve.client.script.ui.control.eveLabel import EveLabelMedium 5 from eve.client.script.ui.control.listgroup import ListGroup 6 from eve.client.script.ui.shared.pointerTool.entry import PointerWndEntry, FavoritePointerWndEntry, FavoriteListGroup 7 import eve.client.script.ui.shared.pointerTool.favorites as fav 8 from eve.client.script.ui.shared.pointerTool.favorites import GetNormalPointerEntryMenu, GetFavoritePointerEntryMenu 9 from localization import GetByLabel 10 11 def GetFilteredScrollList(filterText, selectedName, sourceLocation): 12 scrollList = [] 13 scrollList += _GetFavoriteGroup(filterText) 14 neocomNodes = _GetNeocomNodes(filterText, selectedName, sourceLocation) 15 scrollList += _GetSortedEntries(neocomNodes, GetByLabel('UI/Help/PointerWndNeocomHeader')) 16 actionNodes = _GetActionNodes(filterText, selectedName, sourceLocation) 17 scrollList += _GetSortedEntries(actionNodes, GetByLabel('UI/Help/PointerWndSelectedItemHeader')) 18 uiHighlightNodes = _GetUiHighlightNodes(filterText, selectedName, sourceLocation) 19 scrollList += _GetSortedEntries(uiHighlightNodes, GetByLabel('UI/Help/PointerWndUiElements')) 20 agencytNodes = _GetAgencyNodes(filterText, selectedName, sourceLocation) 21 scrollList += _GetSortedEntries(agencytNodes, GetByLabel('UI/Help/PointerAgencyElements')) 22 stationServiceNodes = _GetStationServiceNodes(filterText, selectedName, sourceLocation) 23 scrollList += _GetSortedEntries(stationServiceNodes, GetByLabel('UI/Help/PointerWndStationServices')) 24 skillPlanNodes = _SkillPlanNodes(filterText, selectedName, sourceLocation) 25 scrollList += _GetSortedEntries(skillPlanNodes, GetByLabel('UI/Help/PointerWndSkillPlans')) 26 mapNodes = _GetMapNodes(filterText, selectedName, sourceLocation) 27 scrollList += _GetSortedEntries(mapNodes, GetByLabel('UI/Help/MapFilters')) 28 return scrollList 29 30 31 def GetFilteredNodes(filterText, sourceLocation = 0): 32 filterText = filterText.lower() 33 allNodes = [] 34 allNodes += _GetActionNodes(filterText, None, sourceLocation, useLongName=True) 35 allNodes += _GetNeocomNodes(filterText, None, sourceLocation, useLongName=True, openElement=True) 36 allNodes += _GetUiHighlightNodes(filterText, None, sourceLocation) 37 allNodes += _GetAgencyNodes(filterText, None, sourceLocation) 38 allNodes += _GetStationServiceNodes(filterText, None, sourceLocation, useLongName=True, openElement=True) 39 allNodes += _SkillPlanNodes(filterText, None, sourceLocation, useLongName=True) 40 allNodes += _GetMapNodes(filterText, None, sourceLocation, useLongName=True) 41 return allNodes 42 43 44 def _GetUiHighlightNodes(filterText, selectedName, sourceLocation): 45 pointerDict = sm.GetService('helpPointer').GetHighlightByElementName() 46 uiHighlightsData = _GetEntryNodes(filterText, pointerDict, selectedName, sourceLocation) 47 return uiHighlightsData 48 49 50 def _GetAgencyNodes(filterText, selectedName, sourceLocation): 51 pointerDict = sm.GetService('helpPointer').GetAgencyLabelByElementName() 52 agencyNodes = _GetEntryNodes(filterText, pointerDict, selectedName, sourceLocation) 53 return agencyNodes 54 55 56 def _GetNeocomNodes(filterText, selectedName, sourceLocation, useLongName = False, openElement = False): 57 pointerDict = sm.GetService('helpPointer').GetNeocomPointersByElementName() 58 neocomData = _GetEntryNodes(filterText, pointerDict, selectedName, sourceLocation, openElement, useLongName) 59 return neocomData 60 61 62 def _GetActionNodes(filterText, selectedName, sourceLocation, useLongName = False): 63 pointerDict = sm.GetService('helpPointer').GetActionLabelPathsByElementName() 64 actionData = _GetEntryNodes(filterText, pointerDict, selectedName, sourceLocation, useLongName=useLongName) 65 return actionData 66 67 68 def _GetStationServiceNodes(filterText, selectedName, sourceLocation, openElement = False, useLongName = False): 69 pointerDict = sm.GetService('helpPointer').GetStationServiceTextByElementName() 70 stationServiceData = _GetEntryNodes(filterText, pointerDict, selectedName, sourceLocation, openElement, useLongName) 71 return stationServiceData 72 73 74 def _SkillPlanNodes(filterText, selectedName, sourceLocation, useLongName = False): 75 pointerDict = sm.GetService('helpPointer').GetSkillPlansByElementName() 76 stationServiceData = _GetEntryNodes(filterText, pointerDict, selectedName, sourceLocation, useLongName) 77 return stationServiceData 78 79 80 def _GetMapNodes(filterText, selectedName, sourceLocation, useLongName = False): 81 pointerDict = sm.GetService('helpPointer').GetMapPointersByName() 82 mapPointerData = _GetEntryNodes(filterText, pointerDict, selectedName, sourceLocation, useLongName) 83 return mapPointerData 84 85 86 def _GetEntryNodes(filterText, pointerDict, selectedName, sourceLocation, openElement = None, useLongName = None): 87 dataList = [] 88 for uiElementName, pointerObject in pointerDict.iteritems(): 89 if filterText and pointerObject.labelLower.find(filterText) < 0: 90 continue 91 entryData = _GetEntryData(pointerObject, selectedName, sourceLocation, openElement, useLongName) 92 dataList.append(entryData) 93 94 return dataList 95 96 97 def _GetEntryData(pointerObject, selectedName = '', sourceLocation = 0, openElement = False, useLongName = False, sublevel = 1): 98 entryData = {'label': pointerObject.label, 99 'uiElementName': pointerObject.uiElementName, 100 'texturePath': pointerObject.texturePath, 101 'iconData': pointerObject.iconData, 102 'longName': pointerObject.labelLong, 103 'useLongName': useLongName, 104 'pointerObject': pointerObject, 105 'pointerObjects': [pointerObject], 106 'openElement': openElement, 107 'sourceLocation': sourceLocation, 108 'sublevel': sublevel, 109 'isSelected': pointerObject.uiElementName == selectedName, 110 'iconSizes': pointerObject.iconSizes} 111 return entryData 112 113 114 def _GetSortedEntries(dataNodes, headerText): 115 if dataNodes: 116 forceOpen = any((x for x in dataNodes if x.get('isSelected', None))) 117 data = GetBoilerplateData() 118 data.update({'GetSubContent': _GetEntriesSubContent, 119 'label': headerText, 120 'id': ('uiPointerGroups', headerText), 121 'groupItems': dataNodes, 122 'sublevel': 0, 123 'forceOpen': forceOpen}) 124 return [GetFromClass(ListGroup, data)] 125 return [] 126 127 128 def _GetEntriesSubContent(nodedata, *args): 129 scrollList = [] 130 for eachNode in nodedata.groupItems: 131 eachNode['OnGetMenu'] = GetNormalPointerEntryMenu 132 entry = GetFromClass(PointerWndEntry, eachNode) 133 scrollList.append((eachNode['label'], entry)) 134 135 scrollList = SortListOfTuples(scrollList) 136 return scrollList 137 138 139 def GetBoilerplateData(): 140 return {'state': 'locked', 141 'BlockOpenWindow': 1, 142 'showicon': 'hide', 143 'showlen': 0, 144 'updateOnToggle': 0} 145 146 147 def _GetFavoriteGroup(filterText): 148 rootGroupID = 0 149 rootGroup = fav.GetFavoriteRootGroup() 150 if filterText: 151 elementNamesinFavorite = rootGroup.uiElementNames[:] 152 groupWithName = False 153 for g in fav.GetFavoriteGroups(): 154 elementNamesinFavorite += g.uiElementNames 155 if g.groupName.lower().find(filterText) >= 0: 156 groupWithName = True 157 break 158 159 if not groupWithName: 160 filteredPointers = _FindValidPointersAfterFilter(filterText, elementNamesinFavorite) 161 if not filteredPointers: 162 return [] 163 data = GetBoilerplateData() 164 data.update({'GetSubContent': _GetFavoriteSubGroups, 165 'label': GetByLabel('UI/HelpPointers/Wnd/FavoriteGroup'), 166 'id': ('uiPointerFavorites', rootGroupID), 167 'groupKeyVal': rootGroup, 168 'sublevel': 0, 169 'groupID': rootGroupID, 170 'MenuFunction': fav.GetFavoriteGroupMenu, 171 'DropData': fav.OnDropDataInFavorite, 172 'filterText': filterText}) 173 return [GetFromClass(FavoriteListGroup, data)] 174 175 176 def _GetFavoriteSubGroups(nodedata, *args): 177 groupKeyVal = nodedata.groupKeyVal 178 filterText = nodedata.filterText 179 uiElements = groupKeyVal.uiElementNames 180 allPointers = sm.GetService('helpPointer').GetAllPointersByElementName() 181 pointerList = [ allPointers.get(x) for x in uiElements if x in allPointers ] 182 scrollList = [] 183 parentSubLevel = nodedata.sublevel 184 for pointerObject in pointerList: 185 if filterText and pointerObject.labelLower.find(filterText) < 0: 186 continue 187 entryData = _GetEntryData(pointerObject, sublevel=parentSubLevel + 1) 188 entryData['OnGetMenu'] = GetFavoritePointerEntryMenu 189 entryData['parentGroup'] = groupKeyVal 190 entry = GetFromClass(FavoritePointerWndEntry, entryData) 191 scrollList.append(entry) 192 193 subGroups = nodedata.groupKeyVal.get('subGroups', []) 194 for eahcSubGroup in subGroups: 195 groupName = eahcSubGroup.get('groupName', GetByLabel('UI/HelpPointers/Wnd/UnknownGroupName')) 196 if filterText and groupName.lower().find(filterText) < 0: 197 filteredPointers = _FindValidPointersAfterFilter(filterText, eahcSubGroup.uiElementNames, allPointers) 198 if not filteredPointers: 199 continue 200 groupID = eahcSubGroup.groupID 201 data = GetBoilerplateData() 202 data.update({'GetSubContent': _GetFavoriteSubGroups, 203 'label': groupName, 204 'id': ('uiPointerFavorites', groupID), 205 'groupKeyVal': eahcSubGroup, 206 'sublevel': eahcSubGroup.subLevel, 207 'MenuFunction': fav.GetFavoriteSubGroupMenu, 208 'groupID': groupID, 209 'DropData': fav.OnDropDataInFavorite, 210 'filterText': filterText}) 211 scrollList += [GetFromClass(FavoriteListGroup, data)] 212 213 return scrollList 214 215 216 def _FindValidPointersAfterFilter(filterText, uiElementNames, allPointers = None): 217 if allPointers is None: 218 allPointers = sm.GetService('helpPointer').GetAllPointersByElementName() 219 pointersInSubGroup = [ allPointers.get(x) for x in uiElementNames if x in allPointers ] 220 filteredPointers = [ x for x in pointersInSubGroup if x.labelLower.find(filterText) >= 0 ] 221 return filteredPointers 222 223 224 class TextAndTexture(object): 225 indentAmount = 10 226 227 def __init__(self, text, texturePath = None, iconSizes = None, indentChar = '-', iconData = None): 228 self.text = text 229 self.texturePath = texturePath 230 self.iconSizes = iconSizes 231 self.indentChar = indentChar 232 self.iconData = iconData 233 234 def GetText(self): 235 return self.text 236 237 def GetTexturePath(self): 238 return self.texturePath 239 240 def GetIconData(self): 241 return self.iconData 242 243 def GetIconSizes(self): 244 return self.iconSizes 245 246 def GetIndentChar(self): 247 return self.indentChar 248 249 def GetMaxWidth(self, lineNum, defaultIconSize): 250 totalWidth = lineNum * self.indentAmount 251 if self.indentChar: 252 textWidth, _ = EveLabelMedium.MeasureTextSize(self.indentChar) 253 if textWidth: 254 totalWidth += textWidth 255 if self.texturePath: 256 if self.iconSizes: 257 iconWidth = self.iconSizes[0] 258 else: 259 iconWidth = defaultIconSize 260 totalWidth += iconWidth 261 textWidth, _ = EveLabelMedium.MeasureTextSize(self.text, bold=True) 262 totalWidth += textWidth 263 return totalWidth