standingsUIUtil.py (11626B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\standings\standingsUIUtil.py 2 import inventorycommon.const as invconst 3 from eve.client.script.ui.control.entries.header import Header 4 from eve.client.script.ui.control.entries.util import GetFromClass 5 from eve.client.script.ui.control.listgroup import ListGroup 6 from eve.client.script.ui.shared.standings import standingUIConst 7 from eve.client.script.ui.shared.standings.standingData import StandingData 8 from eve.client.script.ui.shared.standings.standingEntry import StandingEntry 9 from eve.client.script.ui.shared.standings.standingsUtil import RoundStandingTo10 10 from eve.common.lib import appConst 11 from eve.common.script.sys import idCheckers 12 from eve.common.script.util import standingUtil 13 from localization import GetByLabel 14 from npcs.npccorporations import get_corporation_faction_id 15 import evestations.standingsrestriction 16 THRESHOLD_BAD = 0.0 17 STANDING_SETTING_CONFIG_NAME = 'charactersheetStandingsPanelOwner' 18 19 def GetStandingScrollGroups(standings, ownerID, searchText = ''): 20 scrollList = [] 21 for each in CategoriseStandingsByOwnerType(ownerID, standings): 22 if each: 23 label = '' 24 groupID = each[0][1].groupID 25 if groupID == invconst.groupFaction: 26 label = GetByLabel('UI/Common/Factions') 27 elif groupID == invconst.groupCorporation: 28 label = GetByLabel('UI/Common/Corporations') 29 elif idCheckers.IsNPC(each[0][1].id): 30 label = GetByLabel('UI/Common/Agents') 31 if searchText: 32 standingEntries = [ entry[2] for entry in each if search_entry(entry[2], searchText.lower()) >= 0 ] 33 else: 34 standingEntries = [ entry[2] for entry in each ] 35 if standingEntries: 36 scrollList.append(GetFromClass(ListGroup, {'GetSubContent': GetStandingScrollGroupSubContent, 37 'label': label, 38 'entries': standingEntries, 39 'id': ('groupID', each[0][1].groupID), 40 'tabs': [], 41 'state': 'locked', 42 'showicon': 'hide', 43 'showlen': 0, 44 'openByDefault': True, 45 'BlockOpenWindow': True})) 46 47 return scrollList 48 49 50 def search_entry(entry, searchText): 51 name = entry.standingData.GetOwner2Name().lower() 52 find_result = name.find(searchText) 53 return find_result 54 55 56 def GetStandingScrollGroupSubContent(data, *args): 57 scrollList = [] 58 for entry in data.entries: 59 scrollList.append(entry) 60 61 return scrollList 62 63 64 def AppendEntriesSection(listEntries, scrolllist, label): 65 if listEntries: 66 scrolllist.append(GetFromClass(Header, {'label': GetByLabel(label)})) 67 for listEntry in listEntries: 68 scrolllist.append(listEntry[2]) 69 70 71 def CategoriseStandingsByOwnerType(toID, standings): 72 factions = [] 73 alliances = [] 74 corps = [] 75 chars = [] 76 agents = [] 77 for each in standings: 78 standing = each[1] 79 ownerID = each[0] 80 ownerinfo = cfg.eveowners.Get(ownerID) 81 entry = (round(standing, 2), ownerinfo, GetStandingEntry(ownerID, toID, standing)) 82 if ownerinfo.groupID == invconst.groupFaction: 83 factions.append(entry) 84 elif ownerinfo.groupID == invconst.groupCorporation: 85 corps.append(entry) 86 elif idCheckers.IsNPC(ownerID): 87 if sm.GetService('agents').GetAgentByID(ownerID) is None: 88 continue 89 agents.append(entry) 90 91 return (factions, 92 corps, 93 agents, 94 alliances, 95 chars) 96 97 98 def GetStandingEntry(ownerID, toID, standing): 99 standing = RoundStandingTo10(standing) 100 101 def OnClick(node): 102 if node.standingData: 103 ownerID = node.standingData.GetOwnerID2() 104 settings.char.ui.Set(STANDING_SETTING_CONFIG_NAME, ownerID) 105 106 return GetFromClass(StandingEntry, {'standingData': StandingData(toID, ownerID, standing2to1=standing), 107 'OnClick': OnClick}) 108 109 110 def GetStandingSkillBonus(standing, fromID, toID): 111 bonus = None 112 relevantSkills = {} 113 if toID == session.charid and idCheckers.IsNPC(fromID): 114 if idCheckers.IsCorporation(fromID): 115 fromFactionID = get_corporation_faction_id(fromID) 116 elif idCheckers.IsFaction(fromID): 117 fromFactionID = fromID 118 else: 119 agent = sm.GetService('agents').GetAgentByID(fromID) 120 if agent is None: 121 fromFactionID = None 122 else: 123 fromFactionID = agent.factionID 124 skillSvc = sm.GetService('skills') 125 for skillTypeID in (invconst.typeDiplomacy, invconst.typeConnections, invconst.typeCriminalConnections): 126 skill = skillSvc.GetSkill(skillTypeID) 127 if skill is not None: 128 relevantSkills[skillTypeID] = skill 129 130 _, bonus = standingUtil.GetStandingBonus(standing, fromFactionID, relevantSkills) 131 return bonus 132 133 134 def GetStandingColor(standing): 135 if standing < THRESHOLD_BAD: 136 return standingUIConst.COLOR_BAD 137 else: 138 return standingUIConst.COLOR_GOOD 139 140 141 def GetStandingIconTexturePath(standing): 142 if standing < THRESHOLD_BAD: 143 return 'res:/UI/Texture/Icons/38_16_229.png' 144 else: 145 return 'res:/UI/Texture/Icons/38_16_230.png' 146 147 148 def GetStandingActionIDs(ownerID): 149 if not idCheckers.IsNPC(ownerID): 150 return [] 151 if idCheckers.IsFaction(ownerID): 152 actions = list(standingUIConst.ACTIONS_FACTION) 153 if ownerID in appConst.factionsEmpires: 154 actions.append(standingUIConst.ACTION_FACTIONALWARFARE) 155 return actions 156 if idCheckers.IsCorporation(ownerID): 157 return standingUIConst.ACTIONS_NPCCORPS 158 if idCheckers.IsNPCCharacter(ownerID): 159 return standingUIConst.ACTIONS_AGENTS 160 161 162 def GetStandingBenefitIDs(ownerID): 163 if not idCheckers.IsNPC(ownerID): 164 return [] 165 elif idCheckers.IsFaction(ownerID): 166 return standingUIConst.BENEFITS_FACTION 167 elif idCheckers.IsCorporation(ownerID): 168 return standingUIConst.BENEFITS_NPCCORP 169 else: 170 return [] 171 172 173 def GetStandingEventIcon(eventID): 174 actionID = standingUIConst.ACTIONID_BY_EVENTID.get(eventID, standingUIConst.ACTION_OTHER) 175 return standingUIConst.ICONS_BY_ACTIONID.get(actionID, None) 176 177 178 def GetStandingThresholdIDs(fromID, toID): 179 if not idCheckers.IsNPC(fromID): 180 return [] 181 if idCheckers.IsCorporation(toID): 182 ids = [] 183 if fromID in appConst.factionsEmpires: 184 ids = [(standingUIConst.THRESHOLD_FACTIONALWARFARE, toID)] 185 ids.extend(_GetStationServiceThresholdIDs(fromID, True)) 186 return ids 187 if idCheckers.IsFaction(fromID): 188 return _GetFactionStandingThresholdIDs(fromID) 189 if IsResourceWarsCorporation(fromID): 190 return _GetResourceWarsStandingThresholdIDs(fromID) 191 if idCheckers.IsCorporation(fromID): 192 return _GetNPCCorpStandingThresholdIDs(fromID) 193 if idCheckers.IsNPCCharacter(fromID): 194 return _GetAgentStandingThresholdIDs(fromID) 195 196 197 def _TresholdTypeIDsToThresholdIDs(thresholdIDs): 198 return [ (thresholdID, None) for thresholdID in thresholdIDs ] 199 200 201 def _GetNPCCorpStandingThresholdIDs(fromID): 202 agents = sm.GetService('agents').GetAgentsByCorpID(fromID) 203 thresholdIDs = [] 204 if agents: 205 thresholdIDs.extend(_TresholdTypeIDsToThresholdIDs(standingUIConst.THRESHOLDS_FACTIONORCORPWITHAGENTS)) 206 thresholdIDs.extend(_GetEpicArcThresholdIDs(fromID)) 207 return thresholdIDs 208 209 210 def _GetAgentStandingThresholdIDs(fromID): 211 agent = sm.GetService('agents').GetAgentByID(fromID) 212 if agent.level > 1: 213 return [(standingUIConst.THRESHOLD_NOACCESSTOAGENT, None), (standingUIConst.THRESHOLD_AGENTOFFERSMISSIONS, agent.level)] 214 else: 215 return [] 216 217 218 def _GetFactionStandingThresholdIDs(fromID): 219 thresholdIDs = _TresholdTypeIDsToThresholdIDs(standingUIConst.THRESHOLDS_FACTION) 220 if fromID in appConst.factionsEmpires: 221 thresholdIDs.append((standingUIConst.THRESHOLD_FACTIONALWARFARE, None)) 222 if fromID not in appConst.factionsWithoutAgents: 223 thresholdIDs.extend(_TresholdTypeIDsToThresholdIDs(standingUIConst.THRESHOLDS_FACTIONORCORPWITHAGENTS)) 224 thresholdIDs.extend(_GetEpicArcThresholdIDs(fromID)) 225 thresholdIDs.extend(_GetStationServiceThresholdIDs(fromID)) 226 return thresholdIDs 227 228 229 def _GetEpicArcThresholdIDs(ownerID): 230 ret = [] 231 for agentID in standingUIConst.EPIC_ARC_STARTER_AGENTS: 232 agent = sm.GetService('agents').GetAgentByID(agentID) 233 if ownerID in (agent.factionID, agent.corporationID): 234 ret.append((standingUIConst.THRESHOLD_EPICARCUNLOCK, agentID)) 235 236 return ret 237 238 239 def GetEpicArcThresholdIDs(ownerID): 240 for agentID in standingUIConst.EPIC_ARC_STARTER_AGENTS: 241 agent = sm.GetService('agents').GetAgentByID(agentID) 242 if agent.factionID == ownerID: 243 pass 244 245 246 def _GetResourceWarsStandingThresholdIDs(ownerID): 247 return _TresholdTypeIDsToThresholdIDs(standingUIConst.THRESHOLDS_RESOURCE_WARS) 248 249 250 def _GetStationServiceThresholdIDs(ownerID, forCorporation = False): 251 thresholdIDs = [] 252 if forCorporation: 253 thresholdTypeID = standingUIConst.THRESHOLD_STATIONSERVICE_CORPORATION 254 restrictions = evestations.standingsrestriction.get_all_station_standings_restrictions_corporate(ownerID) 255 else: 256 thresholdTypeID = standingUIConst.THRESHOLD_STATIONSERVICE 257 restrictions = evestations.standingsrestriction.get_all_station_standings_restrictions_personal(ownerID) 258 groups = set() 259 for serviceID, standingsValue in restrictions.iteritems(): 260 roundedValue = round(standingsValue) + 0 261 groups.add(roundedValue) 262 263 for group in groups: 264 thresholdIDs.append((thresholdTypeID, group)) 265 266 return thresholdIDs 267 268 269 def GetStandingThresholdIcon(thresholdID): 270 thresholdTypeID = thresholdID[0] 271 if thresholdTypeID == standingUIConst.THRESHOLD_AGENTOFFERSMISSIONS: 272 agentLvl = thresholdID[1] 273 if agentLvl == 2: 274 return 'res:/UI/Texture/Classes/Standings/Thresholds/agentsLvl2.png' 275 if agentLvl == 3: 276 return 'res:/UI/Texture/Classes/Standings/Thresholds/agentsLvl3.png' 277 if agentLvl == 4: 278 return 'res:/UI/Texture/Classes/Standings/Thresholds/agentsLvl4.png' 279 if agentLvl == 5: 280 return 'res:/UI/Texture/Classes/Standings/Thresholds/agentsLvl5.png' 281 else: 282 return standingUIConst.ICONS_BY_THRESHOLDTYPEID.get(thresholdTypeID, None) 283 284 285 def GetBGOpacity(isEvenRow): 286 if isEvenRow: 287 return 0.15 288 return 0.25 289 290 291 def IsResourceWarsCorporation(corpID): 292 return sm.GetService('rwService').is_rw_corporation(corpID) 293 294 295 def GetStationServiceRestrictionsForThreshold(ownerID, thresholdValue, thresholdTypeID): 296 if thresholdTypeID == standingUIConst.THRESHOLD_STATIONSERVICE_CORPORATION: 297 restrictions = evestations.standingsrestriction.get_all_station_standings_restrictions_corporate(ownerID) 298 else: 299 restrictions = evestations.standingsrestriction.get_all_station_standings_restrictions_personal(ownerID) 300 values = [] 301 for serviceID, standingsValue in restrictions.iteritems(): 302 roundedValue = round(standingsValue) + 0 303 if roundedValue != thresholdValue: 304 continue 305 values.append((round(standingsValue, 2), serviceID)) 306 307 values.sort() 308 return values 309 310 311 def GetStationServiceLabel(serviceID): 312 return GetByLabel(evestations.standingsrestriction.get_station_standings_restriction_label(serviceID))