stateFlag.py (12747B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\stateFlag.py 2 import homestation.client 3 from brennivin.itertoolsext import Bundle 4 from carbonui import const as uiconst 5 from carbonui.primitives.container import Container 6 from carbonui.primitives.fill import Fill 7 from carbonui.primitives.frame import Frame 8 from carbonui.primitives.sprite import Sprite 9 import eve.client.script.parklife.states as statesConst 10 import inventorycommon.const as inventoryConst 11 from eve.client.script.parklife.states import flagForcedOn 12 from eve.common.lib import appConst as const 13 from eve.client.script.ui import eveColor 14 from eve.common.script.sys import idCheckers 15 from stargate.client.const import EMANATION_GATE_UNAVAILABLE, EMANATION_GATE_AVAILABLE 16 from structures import STATE_UNANCHORED, DOCKING_ACCESS_UNKNOWN, STATE_ANCHOR_VULNERABLE 17 from structures.types import IsFlexStructure 18 from utillib import KeyVal 19 from carbonui.uicore import uicore 20 EXTRA_INFO_HOME_STATION = 'isHomeStation' 21 EXTRA_INFO_DOCKING_RIGHTS = 'hasDockingRights' 22 EXTRA_INFO_GATE_LOCK = 'gateLockValue' 23 24 def GetStateFlagFromData(data): 25 charID = getattr(data, 'charID', 0) 26 if charID == session.charid: 27 return 28 fakeSlimItem = KeyVal() 29 fakeSlimItem.ownerID = charID 30 fakeSlimItem.charID = charID 31 fakeSlimItem.corpID = data.Get('corpID', 0) 32 fakeSlimItem.allianceID = data.Get('allianceID', 0) 33 fakeSlimItem.warFactionID = data.Get('warFactionID', 0) 34 if getattr(data, 'bounty', None): 35 if data.bounty.bounty > 0.0: 36 fakeSlimItem.bounty = data.bounty 37 fakeSlimItem.groupID = data.Get('groupID', inventoryConst.groupCharacter) 38 fakeSlimItem.categoryID = data.Get('categoryID', inventoryConst.categoryOwner) 39 fakeSlimItem.securityStatus = data.Get('securityStatus', None) 40 flag = sm.GetService('stateSvc').CheckStates(fakeSlimItem, 'flag') 41 return flag 42 43 44 def AddAndSetFlagIconFromData(data, parentCont, **kwargs): 45 flag = GetStateFlagFromData(data) 46 return AddAndSetFlagIcon(parentCont=parentCont, flag=flag, **kwargs) 47 48 49 def AddAndSetFlagIcon(parentCont, *args, **kwargs): 50 flag = kwargs.get('flag', 0) 51 stateFlagIcon = getattr(parentCont, 'stateFlagIcon', None) 52 if not flag or flag == -1: 53 if stateFlagIcon and not stateFlagIcon.destroyed: 54 stateFlagIcon.ModifyIcon(flagInfo=None) 55 return 56 flagInfo = sm.GetService('stateSvc').GetStatePropsColorAndBlink(flag) 57 if stateFlagIcon and not stateFlagIcon.destroyed: 58 stateFlagIcon.ModifyIcon(flagInfo=flagInfo) 59 else: 60 stateFlagIcon = FlagIconWithState(parent=parentCont, flagInfo=flagInfo, **kwargs) 61 parentCont.stateFlagIcon = stateFlagIcon 62 return stateFlagIcon 63 64 65 def GetFlagTexturePath(iconIdx): 66 if iconIdx == 1: 67 return 'res:/UI/Texture/classes/FlagIcon/8/1.png' 68 if iconIdx == 2: 69 return 'res:/UI/Texture/classes/FlagIcon/8/2.png' 70 if iconIdx == 3: 71 return 'res:/UI/Texture/classes/FlagIcon/8/3.png' 72 if iconIdx == 4: 73 return 'res:/UI/Texture/classes/FlagIcon/8/4.png' 74 if iconIdx == 5: 75 return 'res:/UI/Texture/classes/FlagIcon/8/5.png' 76 if iconIdx == 6: 77 return 'res:/UI/Texture/classes/FlagIcon/8/6.png' 78 if iconIdx == 7: 79 return 'res:/UI/Texture/classes/FlagIcon/8/7.png' 80 if iconIdx == 8: 81 return 'res:/UI/Texture/classes/FlagIcon/8/8.png' 82 if iconIdx == 9: 83 return 'res:/UI/Texture/classes/FlagIcon/8/9.png' 84 if iconIdx == 10: 85 return 'res:/UI/Texture/classes/FlagIcon/8/10.png' 86 if iconIdx == 11: 87 return 'res:/UI/Texture/classes/FlagIcon/8/11.png' 88 if iconIdx == 12: 89 return 'res:/UI/Texture/classes/FlagIcon/8/12.png' 90 if iconIdx == 13: 91 return 'res:/UI/Texture/classes/FlagIcon/8/13.png' 92 93 94 class FlagIcon(Container): 95 default_align = uiconst.TOPRIGHT 96 default_width = 10 97 default_height = 10 98 default_idx = 0 99 100 def ApplyAttributes(self, attributes): 101 Container.ApplyAttributes(self, attributes) 102 if self.width > 10: 103 self.flagBackground = Frame(bgParent=self, texturePath='res:/UI/Texture/Classes/FlagIcon/bgFrame.png') 104 else: 105 self.flagBackground = Fill(bgParent=self) 106 self.flagBackground.opacity = 0 107 iconSize = 8 108 self.flagIcon = Sprite(parent=self, pos=(0, 109 0, 110 iconSize, 111 iconSize), name='flagIcon', state=uiconst.UI_DISABLED, align=uiconst.CENTER) 112 113 def SetIconTexturePath(self, iconIdx): 114 self.flagIcon.texturePath = GetFlagTexturePath(iconIdx) 115 116 def SetBackgroundColor(self, color, opacity = 0.75): 117 newColor = (color[0], 118 color[1], 119 color[2], 120 opacity) 121 self.flagBackground.SetRGBA(*newColor) 122 123 def ChangeIconVisibility(self, display): 124 self.flagIcon.display = display 125 126 def ChangeFlagPos(self, left, top, width, height): 127 self.left = left 128 self.top = top 129 self.width = width 130 self.height = height 131 132 def ChangeIconPos(self, left, top, width, height): 133 self.flagIcon.left = left 134 self.flagIcon.top = top 135 self.flagIcon.width = width 136 self.flagIcon.height = height 137 138 139 class FlagIconWithState(FlagIcon): 140 141 def ApplyAttributes(self, attributes): 142 FlagIcon.ApplyAttributes(self, attributes) 143 flagInfo = attributes.flagInfo 144 showHint = attributes.get('showHint', True) 145 extraInfo = attributes.extraInfo 146 if flagInfo is not None: 147 self.ModifyIcon(flagInfo=flagInfo, showHint=showHint, extraInfo=extraInfo) 148 149 def ModifyIcon(self, flagInfo, showHint = True, extraInfo = None): 150 if not flagInfo: 151 self.display = False 152 return 153 self.display = True 154 flagProperties = flagInfo.flagProperties 155 self.flagIcon.SetRGBA(*flagProperties.iconColor) 156 col = flagInfo.flagColor 157 blink = flagInfo.flagBlink 158 if blink: 159 uicore.animations.FadeTo(self, startVal=0.0, endVal=1.0, duration=0.5, loops=uiconst.ANIM_REPEAT, curveType=uiconst.ANIM_WAVE) 160 else: 161 self.StopAnimations() 162 self.opacity = 1.0 163 self.SetBackgroundColor(col) 164 self.SetIconTexturePath(flagProperties.iconIndex + 1) 165 if showHint and flagProperties.text: 166 self.hint = flagProperties.text 167 self.state = uiconst.UI_NORMAL 168 if extraInfo: 169 if getattr(extraInfo, EXTRA_INFO_HOME_STATION, False): 170 self.SetIconTexturePath(homestation.texture.flag_icon_index) 171 self.SetBackgroundColor(homestation.Color.home_station_icon_background) 172 elif getattr(extraInfo, EXTRA_INFO_DOCKING_RIGHTS, DOCKING_ACCESS_UNKNOWN) not in (DOCKING_ACCESS_UNKNOWN, None): 173 iconIdx = 9 if extraInfo.hasDockingRights else 10 174 self.SetIconTexturePath(iconIdx) 175 elif getattr(extraInfo, EXTRA_INFO_GATE_LOCK, None) is not None: 176 if extraInfo.gateLockValue == EMANATION_GATE_AVAILABLE: 177 iconIdx = 13 178 col = eveColor.CRYO_BLUE 179 else: 180 iconIdx = 12 181 col = (0.75, 0.0, 0.0, 1.0) 182 self.SetIconTexturePath(iconIdx) 183 self.SetBackgroundColor(col) 184 185 def SetFlagID(self, flagID): 186 flagInfo = sm.GetService('stateSvc').GetStatePropsColorAndBlink(flagID) 187 self.ModifyIcon(flagInfo) 188 189 190 def GetRelationShipFlag(itemID, corpID, allianceID): 191 ret = sm.GetService('addressbook').GetRelationship(itemID, corpID, allianceID) 192 relationships = [(ret.persToCorp, 'UI/PeopleAndPlaces/StandingPersToCorp'), 193 (ret.persToPers, 'UI/PeopleAndPlaces/StandingPersToPers'), 194 (ret.persToAlliance, 'UI/PeopleAndPlaces/StandingPersToAlliance'), 195 (ret.corpToPers, 'UI/PeopleAndPlaces/StandingCorpToPers'), 196 (ret.corpToCorp, 'UI/PeopleAndPlaces/StandingCorpToCorp'), 197 (ret.corpToAlliance, 'UI/PeopleAndPlaces/StandingCorpToAlliance'), 198 (ret.allianceToPers, 'UI/PeopleAndPlaces/StandingAllianceToPers'), 199 (ret.allianceToCorp, 'UI/PeopleAndPlaces/StandingAllianceToCorp'), 200 (ret.allianceToAlliance, 'UI/PeopleAndPlaces/StandingAllianceToAlliance')] 201 relationship = 0.0 202 flagHintPath = None 203 for r, hintPath in relationships: 204 if r != 0.0 and r > relationship or relationship == 0.0: 205 relationship = r 206 flagHintPath = hintPath 207 208 flag = GetFlagFromRelationShip(relationship) 209 return (flag, flagHintPath) 210 211 212 def GetFlagFromRelationShip(relationship): 213 flag = None 214 if relationship > const.contactGoodStanding: 215 flag = statesConst.flagStandingHigh 216 elif const.contactNeutralStanding < relationship <= const.contactGoodStanding: 217 flag = statesConst.flagStandingGood 218 elif const.contactBadStanding <= relationship < const.contactNeutralStanding: 219 flag = statesConst.flagStandingBad 220 elif relationship < const.contactBadStanding: 221 flag = statesConst.flagStandingHorrible 222 return flag 223 224 225 def GetExtraInfoForSlimItem(slimItem): 226 extraInfo = Bundle() 227 extraInfo.update(GetExtraInfoForStructure(slimItem)) 228 extraInfo.update(GetExtraInfoForHomeStation(slimItem)) 229 extraInfo.update(GetExtraInfoRestrictedGates(slimItem)) 230 return extraInfo 231 232 233 def GetExtraInfoForHomeStation(slimItem): 234 return {EXTRA_INFO_HOME_STATION: IsHomeStation(slimItem)} 235 236 237 def IsHomeStation(slimItem): 238 is_station = idCheckers.IsStation(slimItem.itemID) 239 is_structure = idCheckers.IsStructure(slimItem.categoryID) 240 if not is_station and not is_structure: 241 return False 242 if is_structure and slimItem.state == STATE_UNANCHORED: 243 return False 244 home_station_service = homestation.Service.instance() 245 if home_station_service.is_home_station_data_loaded: 246 home_station = home_station_service.get_home_station() 247 if home_station.id == slimItem.itemID: 248 return True 249 return False 250 251 252 def GetExtraInfoForStructure(slimItem): 253 if slimItem.categoryID != const.categoryStructure or slimItem.state == STATE_UNANCHORED: 254 return {} 255 if IsFlexStructure(slimItem.typeID): 256 return {} 257 structureProximityTrackerSvc = sm.GetService('structureProximityTracker') 258 if structureProximityTrackerSvc.HasDockingAccessChanged(): 259 hasDockingRights = DOCKING_ACCESS_UNKNOWN 260 else: 261 hasDockingRights = FindDockingRightsToDisplay(structureProximityTrackerSvc, slimItem) 262 return {EXTRA_INFO_DOCKING_RIGHTS: hasDockingRights} 263 264 265 def FindDockingRightsToDisplay(structureProximityTrackerSvc, slimItem): 266 if slimItem.state == STATE_UNANCHORED or IsFlexStructure(slimItem.typeID): 267 return DOCKING_ACCESS_UNKNOWN 268 hasDockingRights = HasDockingRights(slimItem, structureProximityTrackerSvc) 269 if slimItem.state == STATE_ANCHOR_VULNERABLE and not hasDockingRights: 270 hasDockingRights = DOCKING_ACCESS_UNKNOWN 271 return hasDockingRights 272 273 274 def HasDockingRights(slimItem, structureProximityTrackerSvc): 275 hasDockingRights = structureProximityTrackerSvc.IsStructureDockable(slimItem.itemID) 276 return hasDockingRights 277 278 279 def GetExtraInfoRestrictedGates(slimItem): 280 gateLockValue = GetGateLockValueForSlimItem(slimItem) 281 if gateLockValue: 282 return {EXTRA_INFO_GATE_LOCK: gateLockValue} 283 return {} 284 285 286 def GetGateLockValueForSlimItem(slimItem): 287 if slimItem.groupID != const.groupStargate: 288 return {} 289 lock_details = _GetGateLockDetails() 290 if not lock_details: 291 return {} 292 return GetGateLockValue(lock_details.gate_id, slimItem.itemID) 293 294 295 def GetGateLockValue(lockedGateID, gateID): 296 if gateID == lockedGateID: 297 return EMANATION_GATE_AVAILABLE 298 return EMANATION_GATE_UNAVAILABLE 299 300 301 def GetLockedToGateID(): 302 lock_details = _GetGateLockDetails() 303 if lock_details: 304 return lock_details.gate_id 305 306 307 def _GetGateLockDetails(): 308 lock_datails = sm.GetService('gatejump').GetGateLockDetails() 309 if lock_datails and lock_datails.solar_system_id != session.solarsystemid: 310 return None 311 return lock_datails 312 313 314 def GetExtraInfoForNode(node): 315 return Bundle(hasDockingRights=node.hasDockingRights, isHomeStation=node.isHomeStation, gateLockValue=node.gateLockValue) 316 317 318 def GetIconFlagAndBackgroundFlag(slimItem, stateSvc = None): 319 if stateSvc is None: 320 stateSvc = sm.GetService('stateSvc') 321 iconFlag, backgroundFlag = stateSvc.GetIconAndBackgroundFlags(slimItem) 322 if iconFlag == 0: 323 if slimItem.categoryID == const.categoryStructure or IsHomeStation(slimItem) or GetGateLockValueForSlimItem(slimItem): 324 iconFlag = flagForcedOn 325 return (iconFlag, backgroundFlag)