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

baseContentPiece.py (14427B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\agencyNew\contentPieces\baseContentPiece.py
      2 from collections import defaultdict
      3 from evePathfinder.core import IsUnreachableJumpCount
      4 import evetypes
      5 from carbonui.util.color import Color
      6 from eve.client.script.ui.const import buttonConst
      7 from eve.client.script.ui.control.statefulButtonController import StatefulButtonController
      8 from eve.client.script.ui.inflight.shipHud import ActiveShipController
      9 from eve.client.script.ui.services.menuSvcExtras.movementFunctions import WarpToItem
     10 from eve.client.script.ui.shared.agencyNew import agencyConst, agencyEventLog
     11 from eve.client.script.ui.shared.agencyNew.ui import agencyUIConst
     12 from eve.client.script.ui.shared.agencyNew.agencyUtil import GetNumberOfJumps, IsAvoidanceSystem, GetNoRouteFoundText
     13 from eve.client.script.ui.shared.mapView import mapViewUtil
     14 from eve.common.lib import appConst
     15 from eve.common.script.sys import idCheckers
     16 from eve.common.script.sys.idCheckers import IsStation, IsCorporation, IsKnownSpaceSystem
     17 from eve.common.script.util.eveFormat import FmtSystemSecStatus
     18 from localization import GetByLabel
     19 from npcs.npccorporations import get_corporation_faction_id
     20 
     21 def GetOwnerFactionID(ownerID):
     22     if not ownerID:
     23         return
     24     if idCheckers.IsNPCCorporation(ownerID):
     25         return get_corporation_faction_id(ownerID)
     26     if idCheckers.IsFaction(ownerID):
     27         return ownerID
     28 
     29 
     30 class BaseContentPiece(StatefulButtonController, object):
     31     contentType = None
     32 
     33     def __init__(self, solarSystemID = None, locationID = None, itemID = None, typeID = None, ownerID = None, enemyOwnerID = None, isNew = False, **kwargs):
     34         self.solarSystemID = solarSystemID
     35         self.locationID = locationID
     36         self.itemID = itemID
     37         self.typeID = typeID
     38         self.ownerID = ownerID
     39         self.enemyOwnerID = enemyOwnerID
     40         self.isNew = isNew
     41         StatefulButtonController.__init__(self)
     42 
     43     def GetBracketIconTexturePath(self):
     44         return 'res:/UI/Texture/classes/MapView/scanResultLocation.png'
     45 
     46     def GetCardText(self):
     47         text = ''
     48         subtitle = self.GetSubtitle()
     49         if subtitle:
     50             text += '%s<br>' % subtitle
     51         numJumps = self.GetSolarSystemAndSecurityAndNumJumpsText()
     52         if numJumps:
     53             text += '%s' % numJumps
     54         return text
     55 
     56     def GetHint(self):
     57         text = '<b>%s</b>' % self.GetTitle()
     58         subtitle = self.GetSubtitle()
     59         if subtitle:
     60             text += '<br>%s' % subtitle
     61         numJumps = self.GetSolarSystemAndSecurityAndNumJumpsText()
     62         if numJumps:
     63             text += '<br>%s' % numJumps
     64         expiryTime = self.GetExpiryTimeText()
     65         if expiryTime:
     66             text += '<br><b>%s</b>' % expiryTime
     67         return text
     68 
     69     def GetTitle(self):
     70         return self.GetSolarSystemName()
     71 
     72     def GetSolarSystemName(self):
     73         return cfg.evelocations.Get(self.solarSystemID).locationName
     74 
     75     def GetName(self):
     76         return self.GetSolarSystemName()
     77 
     78     def GetSubtitle(self):
     79         pass
     80 
     81     def GetItemID(self):
     82         return self.itemID
     83 
     84     def GetCardID(self):
     85         return (self.contentType, self.itemID)
     86 
     87     def __eq__(self, other):
     88         return other is not None and hasattr(other, 'GetCardID') and self.GetCardID() == other.GetCardID()
     89 
     90     def GetExpandedTitle(self):
     91         return self.GetTitle()
     92 
     93     def GetExpandedSubtitle(self):
     94         return self.GetSubtitle()
     95 
     96     def GetDescription(self):
     97         pass
     98 
     99     def GetOwnerID(self):
    100         return self.ownerID
    101 
    102     def GetOwnerName(self):
    103         return cfg.eveowners.Get(self.GetOwnerID()).ownerName
    104 
    105     def GetBlurbText(self):
    106         return ''
    107 
    108     def GetContentTypeID(self):
    109         return self.contentType
    110 
    111     def GetContentSubTypeID(self):
    112         return None
    113 
    114     def GetOwnerIDs(self):
    115         if not self.ownerID:
    116             return []
    117         ownerIDs = [self.ownerID]
    118         factionID = self.GetFactionID()
    119         if factionID:
    120             ownerIDs.append(factionID)
    121         return ownerIDs
    122 
    123     def GetCorpID(self):
    124         if idCheckers.IsNPCCorporation(self.ownerID):
    125             return self.ownerID
    126 
    127     def GetFactionID(self):
    128         return GetOwnerFactionID(self.ownerID)
    129 
    130     def GetEnemyOwnerID(self):
    131         return self.enemyOwnerID
    132 
    133     def GetEnemyFactionID(self):
    134         return GetOwnerFactionID(self.GetEnemyOwnerID())
    135 
    136     def GetContentTypeName(self):
    137         return agencyConst.LABEL_BY_CONTENTTYPE[self.contentType]
    138 
    139     def GetColor(self):
    140         return agencyUIConst.COLOR_BY_CONTENTTYPE.get(self.contentType, Color.GRAY)
    141 
    142     def GetBgColor(self):
    143         return agencyUIConst.BG_COLOR_BY_CONTENTTYPE[self.contentType]
    144 
    145     def GetIconTexturePath(self):
    146         return None
    147 
    148     def GetCardSortValue(self):
    149         return self.GetJumpsToSelfFromCurrentLocation()
    150 
    151     def GetSolarSystemAndSecurityAndNumJumpsText(self):
    152         if not self.solarSystemID:
    153             return None
    154         elif self.IsInCurrentStation():
    155             return GetByLabel('UI/Agency/ContentInCurrentStation')
    156         elif self.IsInCurrentSolarSystem():
    157             return GetByLabel('UI/Agency/ContentInCurrentSystem') + ' %s' % self.GetSecStatusNumberColoredText()
    158         else:
    159             return self.GetAgentLocationText()
    160 
    161     def GetAgentLocationText(self):
    162         isAvoided = self.solarSystemID and IsAvoidanceSystem(self.solarSystemID)
    163         return self.GetSystemSecurityAndNumJumpsText(isAvoided)
    164 
    165     def GetSystemAndSecurityText(self, isAvoided = False):
    166         secStatus = self.GetSecStatusNumberColoredText()
    167         label = 'UI/Agency/AvoidedLocation' if isAvoided else 'UI/Agency/Location'
    168         return GetByLabel(label, location=self.solarSystemID, secStatus=secStatus)
    169 
    170     def GetLocationAndSecurityText(self):
    171         return self.GetSystemAndSecurityText()
    172 
    173     def GetSystemSecurityAndNumJumpsText(self, isAvoided = False):
    174         label = 'UI/Agency/AvoidedLocationAndNumJumps' if isAvoided else 'UI/Agency/LocationAndNumJumps'
    175         return GetByLabel(label, location=self.GetDestinationSolarSystemID(), secStatus=self.GetSecStatusNumberColoredText(), jumps=self.GetNumJumpsText())
    176 
    177     def GetSecStatusNumberColoredText(self):
    178         sec = self.GetSystemSecurityStatus()
    179         secStatus, color = FmtSystemSecStatus(sec, True)
    180         color = Color.RGBtoHex(*color)
    181         iconText = self.GetSystemSecurityStatusModifierIconText()
    182         return "<color='%s'>%s</color>%s" % (color, secStatus, iconText)
    183 
    184     def GetSystemSecurityStatus(self):
    185         return sm.GetService('map').GetSecurityStatus(self.GetDestinationSolarSystemID())
    186 
    187     def GetSystemSecurityStatusModifierIconText(self):
    188         destinationSolarSystemID = self.GetDestinationSolarSystemID()
    189         return sm.GetService('securitySvc').get_security_modifier_icon_text(destinationSolarSystemID)
    190 
    191     def GetNumJumpsText(self):
    192         if self.IsInCurrentStation():
    193             return GetByLabel('UI/Generic/CurrentStation')
    194         if self.IsInCurrentSolarSystem():
    195             return GetByLabel('UI/Generic/CurrentSystem')
    196         if IsKnownSpaceSystem(session.solarsystemid2):
    197             numJumps = self.GetJumpsToSelfFromCurrentLocation()
    198             if numJumps:
    199                 if IsUnreachableJumpCount(numJumps):
    200                     return GetByLabel('UI/Generic/NoGateToGateRoute')
    201                 return GetByLabel('UI/Common/NumJumps', numJumps=numJumps)
    202         return GetByLabel('UI/Generic/NoGateToGateRoute')
    203 
    204     def GetJumpsToSelfFromCurrentLocation(self):
    205         return GetNumberOfJumps(self.solarSystemID)
    206 
    207     def GetStationID(self):
    208         return None
    209 
    210     def GetExpiryTimeText(self):
    211         pass
    212 
    213     def GetDisabledHint(self):
    214         return self.GetPrimaryActionDisabledHint()
    215 
    216     def IsInCurrentSolarSystem(self):
    217         return self.solarSystemID == session.solarsystemid2
    218 
    219     def IsInCurrentStation(self):
    220         locationID = self.GetLocationID()
    221         return session.stationid is not None and session.stationid == locationID
    222 
    223     def IsAvailable(self):
    224         return True
    225 
    226     def GetLocationID(self):
    227         return self.locationID
    228 
    229     def _GetButtonState(self):
    230         warpingState = self.GetWarpingState()
    231         if warpingState and self.buttonState in (buttonConst.STATE_WARPTO,
    232          buttonConst.STATE_PREPARING_WARP,
    233          buttonConst.STATE_WARPING,
    234          buttonConst.STATE_DOCK):
    235             return warpingState
    236         if self.IsInCurrentSolarSystem():
    237             if self.IsInStation():
    238                 if sm.GetService('undocking').IsExiting():
    239                     return buttonConst.STATE_UNDOCKING
    240                 return buttonConst.STATE_UNDOCK
    241             if self.GetStationID():
    242                 return buttonConst.STATE_DOCK
    243             if self.IsWarpableTo():
    244                 return buttonConst.STATE_WARPTO
    245         else:
    246             waypoints = sm.StartService('starmap').GetWaypoints()
    247             if waypoints and waypoints[-1] in (self.GetLocationID(), self.solarSystemID):
    248                 return buttonConst.STATE_DESTINATIONSET
    249             return buttonConst.STATE_SETDESTINATION
    250         return super(BaseContentPiece, self)._GetButtonState()
    251 
    252     def IsWarpableTo(self):
    253         return True
    254 
    255     def GetButtonFunction(self):
    256         return lambda x: self._ExecutePrimaryFunction(self.buttonState)
    257 
    258     def _ExecutePrimaryFunction(self, buttonState):
    259         agencyEventLog.LogEventPrimaryButtonClick(self, buttonState)
    260         if buttonState in (buttonConst.STATE_UNDOCK, buttonConst.STATE_UNDOCKING):
    261             sm.GetService('undocking').UndockBtnClicked()
    262         elif buttonState == buttonConst.STATE_DOCK:
    263             sm.GetService('menu').Dock(self.GetStationID())
    264         elif buttonState == buttonConst.STATE_WARPTO:
    265             self._ExecuteWarpTo()
    266         elif buttonState == buttonConst.STATE_SETDESTINATION:
    267             self.SetDestinationTo()
    268 
    269     def SetDestinationTo(self):
    270         sm.StartService('starmap').SetWaypoint(self.GetDestinationID(), clearOtherWaypoints=True)
    271 
    272     def _ExecuteWarpTo(self):
    273         if self.itemID:
    274             WarpToItem(self.itemID)
    275 
    276     def GetPrimaryActionDisabledHint(self):
    277         buttonState = self.GetButtonState()
    278         if buttonState == buttonConst.STATE_SETDESTINATION:
    279             if self.GetDestinationID() in sm.StartService('starmap').GetWaypoints():
    280                 return GetByLabel('UI/Agency/DisabledHintWaypointAlreadySet')
    281             if self.GetDestinationSolarSystemID() == session.solarsystemid2:
    282                 return GetByLabel('UI/Agency/DisabledHintAlreadyThere')
    283         elif buttonState == buttonConst.STATE_WARPTO:
    284             michelle = sm.GetService('michelle')
    285             if michelle.InWarp():
    286                 return GetByLabel('UI/Agency/DisabledHintAlreadyWarping')
    287             if not michelle.IsPositionWithinWarpDistance(self.GetSubSolarSystemPosition()):
    288                 return GetByLabel('UI/Agency/DisabledHintAlreadyThere')
    289 
    290     def GetDestinationSolarSystemID(self):
    291         return self.solarSystemID
    292 
    293     def GetDestinationID(self):
    294         stationID = self.GetStationID()
    295         if stationID:
    296             return stationID
    297         else:
    298             return self.GetDestinationSolarSystemID()
    299 
    300     def IsInStation(self):
    301         return session.stationid is not None or session.structureid is not None
    302 
    303     def GetMarkerID(self):
    304         return '%s_%s_%s' % (self.solarSystemID, self.itemID, self.contentType)
    305 
    306     def GetSubSolarSystemPosition(self):
    307         locationID = self.GetLocationID()
    308         if IsStation(locationID):
    309             stationInfo = sm.GetService('ui').GetStationStaticInfo(locationID)
    310             return (stationInfo.x, stationInfo.y, stationInfo.z)
    311         else:
    312             return mapViewUtil.TryGetPosFromItemID(locationID, self.solarSystemID)
    313 
    314     def GetMenu(self):
    315         return sm.GetService('menu').GetMenuFromItemIDTypeID(self.GetItemID(), self.typeID)
    316 
    317     def GetDragData(self):
    318         return []
    319 
    320     def GetModulesRequiredTypeIDs(self):
    321         return []
    322 
    323     def GetRewardTypes(self):
    324         return []
    325 
    326     def GetResourceTypeIDs(self):
    327         return []
    328 
    329     def GetCorpAndFactionStandingText(self):
    330         corpID = self.GetCorpID()
    331         if not corpID:
    332             return ''
    333         factionID = self.GetFactionID()
    334         corpStanding = sm.GetService('standing').GetStandingWithSkillBonus(corpID, session.charid)
    335         factionStanding = sm.GetService('standing').GetStandingWithSkillBonus(factionID, session.charid)
    336         return GetByLabel('UI/Agency/StandingWithCorpAndFaction', corpID=corpID, corpStanding=round(corpStanding, 2), factionID=factionID, factionStanding=round(factionStanding, 2))
    337 
    338     def GetAllowedShipTypeIDs(self):
    339         return []
    340 
    341     def GetAllowedShipTypeIDsByGroupID(self):
    342         typeIDsByGroupID = defaultdict(list)
    343         typeIDs = self.GetAllowedShipTypeIDs()
    344         for typeID in typeIDs:
    345             typeIDsByGroupID[evetypes.GetGroupID(typeID)].append(typeID)
    346 
    347         return typeIDsByGroupID
    348 
    349     def CombineGroupsUnderBrackets(self, typeIDsByGroupID):
    350         typeIDsByBracket = defaultdict(list)
    351         for groupID, typeIDs in typeIDsByGroupID.iteritems():
    352             bracketData = sm.GetService('bracket').GetBracketDataByGroupID(groupID)
    353             typeIDsByBracket[bracketData].extend(typeIDs)
    354 
    355         return typeIDsByBracket
    356 
    357     def IsActiveShipAllowed(self):
    358         typeID = ActiveShipController().GetTypeID()
    359         allowedTypes = self.GetAllowedShipTypeIDs()
    360         return not allowedTypes or typeID in allowedTypes
    361 
    362     def IsShipRestrictionShown(self):
    363         return not self.IsActiveShipAllowed()
    364 
    365     def GetEnemyRoamingText(self):
    366         ownerID = self.GetEnemyOwnerID()
    367         if ownerID != appConst.factionUnknown:
    368             ownerTypeID = self.GetEnemyOwnerTypeID()
    369             return GetByLabel('UI/Agency/EnemyRoaming', ownerID=ownerID, ownerTypeID=ownerTypeID)
    370         else:
    371             return GetByLabel('UI/Agency/UnknownEnemyRoaming')
    372 
    373     def GetEnemyOwnerTypeID(self):
    374         if IsCorporation(self.GetEnemyOwnerID()):
    375             return appConst.typeCorporation
    376         return appConst.typeFaction
    377 
    378     def GetChatChannelID(self):
    379         return None
    380 
    381     def GetSunTypeID(self):
    382         star = cfg.mapSolarSystemContentCache[self.solarSystemID].star
    383         return star.typeID
    384 
    385     def GetBGVideoPath(self):
    386         return None