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

statefulButtonLocationController.py (7870B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\control\statefulButtonLocationController.py
      2 from ballparkCommon.parkhelpers.warpSubjects import WarpSubjects
      3 from eve.client.script.ui.const import buttonConst
      4 from eve.client.script.ui.control.statefulButtonController import StatefulButtonController
      5 from eve.client.script.ui.services.menuSvcExtras import movementFunctions
      6 from eve.client.script.ui.services.menuSvcExtras.movementFunctions import WarpToItem
      7 from eve.common.script.sys.idCheckers import IsStation, IsDockableLocationType
      8 from localization import GetByLabel
      9 from menucheckers import SessionChecker, CelestialChecker
     10 
     11 class LocationButtonController(StatefulButtonController):
     12 
     13     def __init__(self, solarSystemID, dockabeLocationID, itemID, typeID, warpSubject = WarpSubjects.ITEM, **kwargs):
     14         self.solarSystemID = solarSystemID
     15         self.dockabeLocationID = dockabeLocationID
     16         self.itemID = itemID
     17         self.typeID = typeID
     18         self.warpSubject = warpSubject
     19         StatefulButtonController.__init__(self)
     20 
     21     def IsInCurrentSolarSystem(self):
     22         return self.solarSystemID == session.solarsystemid2
     23 
     24     def IsCurrentSolarSystem(self):
     25         return self.itemID == session.solarsystemid2
     26 
     27     def IsAvailable(self):
     28         return True
     29 
     30     def _GetButtonState(self):
     31         warpingState = self.GetWarpingState()
     32         if warpingState and self.buttonState in (buttonConst.STATE_WARPTO,
     33          buttonConst.STATE_PREPARING_WARP,
     34          buttonConst.STATE_WARPING,
     35          buttonConst.STATE_DOCK):
     36             return warpingState
     37         elif self.dockabeLocationID:
     38             return self._GetButtonStateForDockableLocation()
     39         else:
     40             return self._GetButtonStateForLocationInSpace()
     41 
     42     def _GetButtonStateForDockableLocation(self):
     43         if self.IsDocked():
     44             if sm.GetService('undocking').IsExiting():
     45                 return buttonConst.STATE_UNDOCKING
     46             elif self.IsInDockableLocation():
     47                 return buttonConst.STATE_NONE
     48             else:
     49                 return buttonConst.STATE_UNDOCK
     50         if self.IsInCurrentSolarSystem():
     51             return buttonConst.STATE_DOCK
     52         else:
     53             waypoints = sm.StartService('starmap').GetWaypoints()
     54             if waypoints and waypoints[-1] == self.GetDockableLocationID():
     55                 return buttonConst.STATE_DESTINATIONSET
     56             return buttonConst.STATE_SETDESTINATION
     57 
     58     def _GetButtonStateForLocationInSpace(self):
     59         if self.IsInCurrentSolarSystem():
     60             if self.IsCurrentSolarSystem():
     61                 return buttonConst.STATE_NONE
     62             elif self.IsDocked():
     63                 if sm.GetService('undocking').IsExiting():
     64                     return buttonConst.STATE_UNDOCKING
     65                 return buttonConst.STATE_UNDOCK
     66             elif self.IsWarpableTo():
     67                 return buttonConst.STATE_WARPTO
     68             elif self.IsApproachable():
     69                 return buttonConst.STATE_APPROACH
     70             else:
     71                 return buttonConst.STATE_NONE
     72         else:
     73             waypoints = sm.StartService('starmap').GetWaypoints()
     74             if waypoints and waypoints[-1] == self.solarSystemID:
     75                 return buttonConst.STATE_DESTINATIONSET
     76             return buttonConst.STATE_SETDESTINATION
     77 
     78     def IsWarpableTo(self):
     79         if not self.IsInCurrentSolarSystem():
     80             return False
     81         elif self.IsDocked():
     82             return False
     83         else:
     84             michelle = sm.GetService('michelle')
     85             if self.GetDockableLocationID():
     86                 coordinates = None
     87                 if IsStation(self.dockabeLocationID):
     88                     stationInfo = sm.GetService('ui').GetStationStaticInfo(self.dockabeLocationID)
     89                     coordinates = (stationInfo.x, stationInfo.y, stationInfo.z)
     90                 elif IsDockableLocationType(self.typeID):
     91                     structureInfo = sm.GetService('structureDirectory').GetStructureInfo(self.dockabeLocationID)
     92                     coordinates = (structureInfo.x, structureInfo.y, structureInfo.z)
     93                 else:
     94                     return False
     95                 return michelle.IsPositionWithinWarpDistance(coordinates)
     96             locationInfo = cfg.evelocations.GetIfExists(self.itemID)
     97             if locationInfo is None:
     98                 return True
     99             coordinates = (locationInfo.x, locationInfo.y, locationInfo.z)
    100             return michelle.IsPositionWithinWarpDistance(coordinates)
    101 
    102     def IsApproachable(self):
    103         slimItem = sm.GetService('michelle').GetItem(self.itemID)
    104         if not slimItem:
    105             return False
    106         celestialChecker = CelestialChecker(slimItem, cfg, SessionChecker(session, sm))
    107         if celestialChecker.OfferApproachObject():
    108             return True
    109         return False
    110 
    111     def GetButtonFunction(self):
    112         return lambda x: self._ExecutePrimaryFunction(self.buttonState)
    113 
    114     def _ExecutePrimaryFunction(self, buttonState):
    115         if buttonState in (buttonConst.STATE_UNDOCK, buttonConst.STATE_UNDOCKING):
    116             sm.GetService('undocking').UndockBtnClicked()
    117         elif buttonState == buttonConst.STATE_DOCK:
    118             sm.GetService('menu').Dock(self.GetDockableLocationID())
    119         elif buttonState == buttonConst.STATE_WARPTO:
    120             self._ExecuteWarpTo()
    121         elif buttonState == buttonConst.STATE_SETDESTINATION:
    122             self.SetDestinationTo()
    123         elif buttonState == buttonConst.STATE_APPROACH:
    124             movementFunctions.Approach(self.itemID)
    125 
    126     def SetDestinationTo(self):
    127         sm.StartService('starmap').SetWaypoint(self.GetDestinationID(), clearOtherWaypoints=True)
    128 
    129     def _ExecuteWarpTo(self):
    130         if not self.itemID:
    131             return
    132         WarpToItem(self.itemID, warpSubject=self.warpSubject)
    133 
    134     def GetDisabledHint(self):
    135         buttonState = self.GetButtonState()
    136         if buttonState == buttonConst.STATE_WARPTO:
    137             michelle = sm.GetService('michelle')
    138             if michelle.InWarp():
    139                 return GetByLabel('UI/Agency/DisabledHintAlreadyWarping')
    140             pos = self.GetSubSolarSystemPosition()
    141             if pos is None:
    142                 return
    143             if not michelle.IsPositionWithinWarpDistance(pos):
    144                 return GetByLabel('UI/Agency/DisabledHintAlreadyThere')
    145 
    146     def GetDestinationSolarSystemID(self):
    147         return self.solarSystemID
    148 
    149     def GetDockableLocationID(self):
    150         return self.dockabeLocationID
    151 
    152     def GetDestinationID(self):
    153         stationID = self.GetDockableLocationID()
    154         if stationID:
    155             return stationID
    156         else:
    157             return self.GetDestinationSolarSystemID()
    158 
    159     def IsDocked(self):
    160         return session.stationid is not None or session.structureid is not None
    161 
    162     def IsInDockableLocation(self):
    163         if self.dockabeLocationID is None:
    164             return False
    165         return self.dockabeLocationID in (session.stationid, session.structureid)
    166 
    167     def GetSubSolarSystemPosition(self):
    168         dockableLocationID = self.GetDockableLocationID()
    169         if IsStation(dockableLocationID):
    170             stationInfo = sm.GetService('ui').GetStationStaticInfo(dockableLocationID)
    171             return (stationInfo.x, stationInfo.y, stationInfo.z)
    172         if IsDockableLocationType(self.typeID):
    173             structureInfo = sm.GetService('structureDirectory').GetStructureInfo(dockableLocationID)
    174             return (structureInfo.x, structureInfo.y, structureInfo.z)
    175         locationInfo = cfg.evelocations.GetIfExists(self.itemID)
    176         if not locationInfo:
    177             return
    178         if locationInfo.solarSystemID != self.solarSystemID:
    179             return
    180         pos = (locationInfo.x, locationInfo.y, locationInfo.z)
    181         if pos != (0, 0, 0):
    182             return pos