searchOld.py (13258B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\util\searchOld.py 2 import evetypes 3 import localization 4 from eve.client.script.ui.control.listwindow import ListWindow 5 from eve.client.script.ui.util import searchUtil 6 from eve.common.lib import appConst 7 from eve.common.script.search.const import MatchBy, ResultType 8 from eve.common.script.sys import idCheckers 9 from inventorycommon.util import IsNPC 10 from bannedwords.client import bannedwords 11 from player_messaging.client.ui_message import prompt_player_fsd_dialog 12 13 def _PrimeSearchResultsInEveOwners(results): 14 if results: 15 cfg.eveowners.Prime(results) 16 17 18 def __Search(searchStr, groupID, exact, filterCorpID, hideNPC = False): 19 result = [] 20 if groupID == appConst.groupCharacter: 21 groupIDList = [ResultType.character] 22 if not hideNPC: 23 groupIDList.append(ResultType.agent) 24 result = searchUtil.GetResultsList(searchStr, groupIDList, exact) 25 _PrimeSearchResultsInEveOwners(result) 26 elif groupID == appConst.groupCorporation: 27 onlyAltName = False 28 groupIDList = [ResultType.corporation] 29 if exact == -1: 30 onlyAltName = True 31 elif filterCorpID == -1: 32 hideNPC = True 33 result = searchUtil.GetResultsList(searchStr, groupIDList, exact, hideNPC=hideNPC, onlyAltName=onlyAltName) 34 _PrimeSearchResultsInEveOwners(result) 35 elif groupID == appConst.groupAlliance: 36 onlyAltName = False 37 groupIDList = [ResultType.alliance] 38 if exact == -1: 39 onlyAltName = True 40 result = searchUtil.GetResultsList(searchStr, groupIDList, exact, onlyAltName=onlyAltName) 41 _PrimeSearchResultsInEveOwners(result) 42 elif groupID == appConst.groupStation: 43 result = searchUtil.GetResultsList(searchStr, [ResultType.station, ResultType.structure_with_inlined_data], exact) 44 elif groupID == appConst.groupFaction: 45 result = searchUtil.GetResultsList(searchStr, [ResultType.faction], exact) 46 elif groupID == appConst.groupSolarSystem: 47 result = searchUtil.GetResultsList(searchStr, [ResultType.solar_system, ResultType.wormhole], exact) 48 elif evetypes.GetCategoryIDByGroup(groupID) == appConst.categoryCelestial: 49 result = sm.RemoteSvc('lookupSvc').LookupKnownLocationsByGroup(groupID, searchStr) 50 result = [ each.itemID for each in result ] 51 if result: 52 cfg.evelocations.Prime(result) 53 return result 54 55 56 def __ValidSearch(searchStr, getError, exact): 57 searchStr = searchStr.replace('%', '').replace('?', '') 58 if len(searchStr) < 1: 59 sm.GetService('loading').StopCycle() 60 if getError: 61 return localization.GetByLabel('UI/Common/PleaseTypeSomething') 62 prompt_player_fsd_dialog('LookupStringMinimum', {'minimum': 1}) 63 return None 64 if len(searchStr) >= 100 or exact == -1 and len(searchStr) > 5: 65 sm.GetService('loading').StopCycle() 66 if getError: 67 return localization.GetByLabel('UI/Common/SearchStringTooLong') 68 prompt_player_fsd_dialog('CustomInfo', {'info': localization.GetByLabel('UI/Common/SearchStringTooLong')}) 69 return None 70 bannedwords.check_search_words_allowed(searchStr) 71 return searchStr 72 73 74 def Search(searchStr, groupID, categoryID = None, modal = 1, exact = MatchBy.partial_terms, getError = 0, notifyOneMatch = 0, filterCorpID = None, hideNPC = 0, searchWndName = 'mySearch', getWindow = 1, listType = None, hideDustChars = False): 75 searchStr = __ValidSearch(searchStr, getError, exact) 76 if not searchStr: 77 return 78 attrGroupName = {appConst.groupCharacter: 'Character', 79 appConst.groupCorporation: 'Corporation', 80 appConst.groupFaction: 'Faction', 81 appConst.groupStation: 'Station', 82 appConst.groupAsteroidBelt: 'Asteroid Belt', 83 appConst.groupSolarSystem: 'SolarSystem', 84 appConst.groupConstellation: 'Constellation', 85 appConst.groupRegion: 'Region', 86 appConst.groupAlliance: 'Alliance'}.get(groupID, '') 87 attrLocGroupNamePlural = {appConst.groupCharacter: 'UI/Common/Characters', 88 appConst.groupCorporation: 'UI/Common/Corporations', 89 appConst.groupFaction: 'UI/Common/Factions', 90 appConst.groupStation: 'UI/Common/Stations', 91 appConst.groupAsteroidBelt: 'UI/Common/AsteroidBelts', 92 appConst.groupSolarSystem: 'UI/Common/SolarSystems', 93 appConst.groupConstellation: 'UI/Common/Constellations', 94 appConst.groupRegion: 'UI/Common/Regions', 95 appConst.groupAlliance: 'UI/Common/Alliances'}.get(groupID, '') 96 if categoryID: 97 if categoryID == appConst.categoryOwner: 98 groupIDList = [ResultType.character, ResultType.corporation] 99 if not hideNPC: 100 groupIDList.append(ResultType.agent) 101 result = searchUtil.GetResultsList(searchStr, groupIDList, exact, hideNPC=hideNPC) 102 _PrimeSearchResultsInEveOwners(result) 103 displayGroupName = localization.GetByLabel('UI/Common/Owner') 104 displayGroupNamePlural = localization.GetByLabel('UI/Common/Owners') 105 elif categoryID == appConst.categoryStructure: 106 groupIDList = [ResultType.structure_with_inlined_data, ResultType.station] 107 result = searchUtil.GetResultsList(searchStr, groupIDList, exact) 108 displayGroupName = localization.GetByLabel('UI/Common/Location') 109 displayGroupNamePlural = localization.GetByLabel('UI/Common/Locations') 110 else: 111 displayGroupName = evetypes.GetGroupNameByGroup(groupID) 112 if attrGroupName and attrLocGroupNamePlural: 113 displayGroupNamePlural = localization.GetByLabel(attrLocGroupNamePlural) 114 else: 115 displayGroupNamePlural = displayGroupName 116 result = __Search(searchStr, groupID, exact, filterCorpID, hideNPC) 117 if not result: 118 sm.GetService('loading').StopCycle() 119 if searchStr[-1] == '*': 120 searchStr = searchStr[:-1] 121 if getError: 122 return localization.GetByLabel('UI/Search/NoGroupFoundWith', groupName=displayGroupName, searchTerm=searchStr) 123 if exact and groupID == appConst.groupCharacter: 124 prompt_player_fsd_dialog('CustomInfo', {'info': localization.GetByLabel('UI/Search/NoCharacterFoundWith', searchTerm=searchStr)}) 125 else: 126 prompt_player_fsd_dialog('CustomInfo', {'info': localization.GetByLabel('UI/Search/NoGroupFoundWith', groupName=displayGroupName, searchTerm=searchStr)}) 127 return 128 if len(result) == 1: 129 if (categoryID == appConst.categoryStructure or groupID == appConst.groupStation) and getattr(result[0], 'structureID', None): 130 return result[0].structureID 131 if result[0] and modal: 132 if notifyOneMatch: 133 return (result[0], 1) 134 return result[0] 135 hint = localization.GetByLabel('UI/Search/OneGroupFoundWith', groupName=displayGroupName, searchTerm=searchStr) 136 else: 137 hint = localization.GetByLabel('UI/Search/ManyGroupsFoundWith', itemCount=len(result), groupNames=displayGroupNamePlural, searchTerm=searchStr) 138 tmplist = [] 139 corpTickersToPrime = [] 140 for each in result: 141 itemID = each 142 if categoryID == appConst.categoryOwner: 143 ownerData = cfg.eveowners.Get(each) 144 if ownerData.typeID == appConst.typeCorporation: 145 groupID = appConst.groupCorporation 146 elif ownerData.typeID == appConst.typeAlliance: 147 groupID = appConst.groupAlliance 148 else: 149 groupID = appConst.groupCharacter 150 if groupID == appConst.groupCorporation: 151 corpTickersToPrime.append(each) 152 if groupID == appConst.groupCharacter and IsNPC(each): 153 agentInfo = sm.GetService('agents').GetAgentByID(each) 154 if agentInfo is not None and agentInfo.agentTypeID == appConst.agentTypeAura: 155 if each != sm.GetService('agents').GetAuraAgentID(): 156 continue 157 if (categoryID == appConst.categoryStructure or groupID == appConst.groupStation) and not idCheckers.IsStation(each): 158 typeID = each.typeID 159 name = each.itemName 160 itemID = each.structureID 161 else: 162 typeID = _GetType(each, groupID) 163 name = _GetName(each, groupID) 164 if each and name: 165 tmplist.append((name, itemID, typeID or 0)) 166 167 cfg.corptickernames.Prime(corpTickersToPrime) 168 sm.GetService('loading').StopCycle() 169 if getWindow: 170 selectionText = localization.GetByLabel('UI/Search/GenericSelection', groupName=displayGroupName) 171 if listType is None: 172 listType = attrGroupName.lower() 173 if not listType: 174 listType = 'Generic' 175 chosen = ListWindow.ShowList(tmplist, listType, [displayGroupNamePlural, selectionText][modal], hint, 1, minChoices=modal, isModal=modal, windowName=searchWndName, unstackable=1) 176 if chosen: 177 return chosen[1] 178 else: 179 return tmplist 180 181 182 def _GetName(rec, groupID = None): 183 if groupID in (appConst.groupCharacter, 184 appConst.groupCorporation, 185 appConst.groupFaction, 186 appConst.groupAlliance): 187 return cfg.eveowners.Get(rec).name 188 if groupID in (appConst.groupStation, 189 appConst.groupAsteroidBelt, 190 appConst.groupSolarSystem, 191 appConst.groupConstellation, 192 appConst.groupRegion): 193 return cfg.evelocations.Get(rec).name 194 return '' 195 196 197 def _GetType(rec, groupID = None): 198 if groupID in (appConst.groupCharacter, 199 appConst.groupCorporation, 200 appConst.groupFaction, 201 appConst.groupAlliance): 202 return cfg.eveowners.Get(rec).typeID 203 if groupID == appConst.groupStation: 204 return cfg.stations.Get(rec).stationTypeID 205 if groupID == appConst.groupSolarSystem: 206 return appConst.typeSolarSystem 207 if groupID == appConst.groupConstellation: 208 return appConst.typeConstellation 209 if groupID == appConst.groupRegion: 210 return appConst.typeRegion 211 if groupID == appConst.groupAsteroidBelt: 212 return appConst.typeAsteroidBelt 213 return 0 214 215 216 def SearchOwners(searchStr, groupIDs = None, exact = False, notifyOneMatch = False, hideNPC = False, getError = False, searchWndName = 'mySearch'): 217 if type(groupIDs) == int: 218 groupIDs = [groupIDs] 219 elif groupIDs is None: 220 groupIDs = [appConst.groupCharacter, 221 appConst.groupCorporation, 222 appConst.groupAlliance, 223 appConst.groupFaction] 224 groupNames = {appConst.groupCharacter: [localization.GetByLabel('UI/Common/Character'), localization.GetByLabel('UI/Common/Characters')], 225 appConst.groupCorporation: [localization.GetByLabel('UI/Common/Corporation'), localization.GetByLabel('UI/Common/Corporations')], 226 appConst.groupAlliance: [localization.GetByLabel('UI/Common/Alliance'), localization.GetByLabel('UI/Common/Alliances')], 227 appConst.groupFaction: [localization.GetByLabel('UI/Common/Faction'), localization.GetByLabel('UI/Common/Factions')]} 228 searchStr = searchStr.replace('%', '').replace('?', '') 229 if len(searchStr) < 1: 230 sm.GetService('loading').StopCycle() 231 if getError: 232 return localization.GetByLabel('UI/Common/PleaseTypeSomething') 233 prompt_player_fsd_dialog('LookupStringMinimum', {'minimum': 1}) 234 return 235 if len(searchStr) >= 100 or exact == -1 and len(searchStr) > 5: 236 sm.GetService('loading').StopCycle() 237 if getError: 238 return localization.GetByLabel('UI/Common/SearchStringTooLong') 239 prompt_player_fsd_dialog('CustomInfo', {'info': localization.GetByLabel('UI/Common/SearchStringTooLong')}) 240 return 241 displayGroupName = '' 242 displayGroupNamePlural = '' 243 for g in groupNames: 244 if g in groupIDs: 245 displayGroupName += groupNames[g][0] + '/' 246 displayGroupNamePlural += groupNames[g][1] + '/' 247 248 displayGroupName = displayGroupName[:-1] 249 displayGroupNamePlural = displayGroupNamePlural[:-1] 250 if hideNPC: 251 owners = sm.RemoteSvc('lookupSvc').LookupPCOwners(searchStr, exact) 252 else: 253 owners = sm.RemoteSvc('lookupSvc').LookupOwners(searchStr, exact) 254 list = [] 255 for o in owners: 256 if o.groupID in groupIDs: 257 list.append(('%s %s' % (o.ownerName, groupNames[o.groupID][0]), o.ownerID, o.typeID)) 258 259 if not list: 260 sm.GetService('loading').StopCycle() 261 if getError: 262 return localization.GetByLabel('UI/Search/NoGroupFoundWith', groupName=displayGroupName, searchTerm=searchStr) 263 prompt_player_fsd_dialog('CustomInfo', {'info': localization.GetByLabel('UI/Search/NoGroupFoundWith', groupName=displayGroupName, searchTerm=searchStr)}) 264 return 265 if len(list) == 1 and not notifyOneMatch: 266 return list[0][1] 267 hint = localization.GetByLabel('UI/Search/ManyGroupsFoundWith', itemCount=len(list), groupNames=displayGroupNamePlural, searchTerm=searchStr) 268 chosen = ListWindow.ShowList(lst=list, listtype='owner', caption=localization.GetByLabel('UI/Search/GenericSelection', groupName=displayGroupName), hint=hint, ordered=1, minChoices=1, windowName=searchWndName) 269 if chosen: 270 return chosen[1]