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

eventManager.py (16624B)


      1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\client\script\ui\shared\planet\eventManager.py
      2 import carbonui.const as uiconst
      3 import evetypes
      4 from carbonui.uicore import uicore
      5 from eve.client.script.ui.shared.planet import planetCommon
      6 from eve.client.script.ui.shared.planet.depletionPinManager import DepletionManager
      7 from eve.client.script.ui.shared.planet.planetConst import STATE_NORMAL, STATE_BUILDPIN, STATE_CREATELINKSTART, STATE_CREATELINKEND, STATE_CREATEROUTE, STATE_SURVEY, SUBSTATE_NORMAL, SUBSTATE_MOVEEXTRACTIONHEAD, STATE_DECOMMISSION
      8 from eve.client.script.ui.shared.planet.surveyUI import SurveyWindow
      9 
     10 class EventManager:
     11     __notifyevents__ = ['OnPlanetChangesSubmitted']
     12 
     13     def __init__(self):
     14         sm.RegisterNotify(self)
     15         self.state = STATE_NORMAL
     16         self.subState = SUBSTATE_NORMAL
     17         self.selectedPin = None
     18         self.selectedLink = None
     19         self.showRoutePin = None
     20         self.selectedPinIDs = set()
     21 
     22     def Close(self):
     23         sm.UnregisterNotify(self)
     24 
     25     def OnPlanetChangesSubmitted(self, planetID):
     26         self.SetStateNormal()
     27 
     28     def OnPlanetViewOpened(self):
     29         self.planetUISvc = sm.GetService('planetUI')
     30         self.myPinManager = self.planetUISvc.myPinManager
     31         self.myPinManager = self.planetUISvc.myPinManager
     32         self.otherPinManager = self.planetUISvc.otherPinManager
     33 
     34     def OnPlanetViewClosed(self):
     35         self.SetStateNormal()
     36 
     37     def SetStateNormal(self):
     38         self._SetState(STATE_NORMAL)
     39         self._SetSubState(SUBSTATE_NORMAL)
     40 
     41     def SetStateBuildPin(self):
     42         self._SetState(STATE_BUILDPIN)
     43 
     44     def SetStateCreateLinkStart(self):
     45         self._SetState(STATE_CREATELINKSTART)
     46 
     47     def SetStateCreateLinkEnd(self):
     48         self._SetState(STATE_CREATELINKEND)
     49 
     50     def SetStateCreateRoute(self):
     51         self._SetState(STATE_CREATEROUTE)
     52 
     53     def SetStateSurvey(self):
     54         self._SetState(STATE_SURVEY)
     55 
     56     def SetStateDecommission(self):
     57         self._SetState(STATE_DECOMMISSION)
     58 
     59     def _SetState(self, state):
     60         oldState = self.state
     61         self.state = state
     62         if state != oldState:
     63             if oldState == STATE_BUILDPIN:
     64                 self.myPinManager.EndPlacingPin()
     65             elif oldState == STATE_CREATELINKSTART and state != STATE_CREATELINKEND:
     66                 self.myPinManager.EndLinkCreation()
     67             elif oldState == STATE_CREATELINKEND:
     68                 self.myPinManager.EndLinkCreation()
     69             elif oldState == STATE_CREATEROUTE:
     70                 self.myPinManager.LeaveRouteMode()
     71             elif oldState == STATE_SURVEY:
     72                 self.myPinManager.LeaveSurveyMode()
     73         sm.ScatterEvent('OnPlanetUIStateChanged', state, oldState)
     74 
     75     def SetSubStateNormal(self):
     76         self._SetSubState(SUBSTATE_NORMAL)
     77 
     78     def SetSubStateMoveExtractionHead(self):
     79         self._SetSubState(SUBSTATE_MOVEEXTRACTIONHEAD)
     80 
     81     def _SetSubState(self, subState):
     82         if subState == self.subState:
     83             return
     84         oldSubState = self.subState
     85         self.subState = subState
     86 
     87     def OnPlanetPinClicked(self, pinID):
     88         if pinID not in self.myPinManager.pinsByID:
     89             return
     90         if uicore.uilib.rightbtn:
     91             return
     92         shouldClearMultiSelect = True
     93         if self.state == STATE_CREATEROUTE:
     94             self._CreateRouteSelectPin(pinID)
     95         elif self.state == STATE_CREATELINKEND:
     96             self.DeselectCurrentlySelected()
     97             self.myPinManager.SetLinkChild(self.myPinManager.linkParentID, pinID)
     98         elif self.state == STATE_DECOMMISSION:
     99             self.myPinManager.RemovePin(pinID)
    100         elif uicore.uilib.Key(uiconst.VK_CONTROL) or self.state == STATE_CREATELINKSTART:
    101             self.DeselectCurrentlySelected()
    102             self.myPinManager.SetLinkParent(pinID)
    103         else:
    104             shouldClearMultiSelect = False
    105             self.SelectPin(pinID)
    106         if shouldClearMultiSelect:
    107             self.selectedPinIDs.clear()
    108             self.UpdateMultiPinSelection()
    109 
    110     def SelectPin(self, pinID):
    111         shiftDown = uicore.uilib.Key(uiconst.VK_SHIFT)
    112         pin = self.GetPinByID(pinID)
    113         if not shiftDown and self.selectedPin and pin == self.selectedPin:
    114             return
    115         if shiftDown:
    116             if pinID in self.selectedPinIDs:
    117                 self.selectedPinIDs.discard(pinID)
    118             else:
    119                 self.selectedPinIDs.add(pinID)
    120         else:
    121             self.ResetMultiSelect()
    122             self.selectedPinIDs.add(pinID)
    123         panelID = self._DeselectCurrentlySelected()
    124         self.UpdateMultiPinSelection()
    125         if len(self.selectedPinIDs) < 2:
    126             self.planetUISvc.OpenContainer(pin.pin, panelID=panelID)
    127             self.selectedPin = pin
    128             pin.SetSelected()
    129             self.ShowRoutesToFromPin(pin)
    130 
    131     def ResetMultiSelect(self):
    132         self.selectedPinIDs.clear()
    133         self.UpdateMultiPinSelection()
    134 
    135     def UpdateMultiPinSelection(self):
    136         for pinID, pin in self.myPinManager.pinsByID.iteritems():
    137             doDisplay = len(self.selectedPinIDs) > 1 and pinID in self.selectedPinIDs
    138             pin.SetMultiSelectedDisplay(doDisplay)
    139 
    140     def GetPinByID(self, pinID):
    141         pin = self.myPinManager.pinsByID[pinID]
    142         return pin
    143 
    144     def DeselectCurrentlySelected(self):
    145         self.selectedPinIDs.clear()
    146         return self._DeselectCurrentlySelected()
    147 
    148     def _DeselectCurrentlySelected(self):
    149         sm.GetService('audio').SendUIEvent('msg_pi_pininteraction_close_play')
    150         if self.selectedPin:
    151             self._DeselectCurrentlySelectedPin()
    152         elif self.selectedLink:
    153             self._DeselectCurrentlySelectedLink()
    154         panelID = self.planetUISvc.CloseCurrentlyOpenPinContainer()
    155         return panelID
    156 
    157     def _DeselectCurrentlySelectedPin(self):
    158         self.selectedPin.SetDeselected()
    159         self.StopShowingRouteToFromPin()
    160         self.selectedPin = None
    161 
    162     def _DeselectCurrentlySelectedLink(self):
    163         self.selectedLink.SetDeselected()
    164         self.selectedLink = None
    165 
    166     def _CreateRouteSelectPin(self, pinID):
    167         if self.myPinManager.currentRoute:
    168             self.myPinManager.SetRouteWaypoint(pinID)
    169             if self.myPinManager.oneoffRoute:
    170                 self.myPinManager.CreateRoute()
    171             elif self.planetUISvc.currentContainer:
    172                 self.planetUISvc.currentContainer.OnPlanetRouteWaypointAdded(self.myPinManager.currentRoute)
    173         else:
    174             self.myPinManager.EnterRouteMode(pinID)
    175 
    176     def OnPlanetPinDblClicked(self, pinID):
    177         if self.state == STATE_CREATEROUTE:
    178             if self.myPinManager.oneoffRoute:
    179                 return
    180             self.myPinManager.SetRouteWaypoint(pinID)
    181             self.planetUISvc.currentContainer.SubmitRoute()
    182         elif self.planetUISvc.currentContainer:
    183             self.planetUISvc.currentContainer.ShowDefaultPanel()
    184 
    185     def OnDepletionPinClicked(self, index):
    186         self.DeselectCurrentlySelected()
    187         DepletionManager.Open(pinManager=self.myPinManager)
    188 
    189     def OnPlanetPinMouseEnter(self, pinID):
    190         if self.state == STATE_BUILDPIN:
    191             return
    192         if self.state == STATE_SURVEY and self.myPinManager.IsDraggingExtractionHead():
    193             return
    194         pin = self.myPinManager.pinsByID.get(pinID, None)
    195         if not pin:
    196             return
    197         pin.OnMouseEnter()
    198         if self.state == STATE_CREATEROUTE:
    199             self._HighlightRoute(pin)
    200         elif self.state == STATE_CREATELINKEND:
    201             parentPin = self.myPinManager.pinsByID.get(self.myPinManager.linkParentID)
    202             if not parentPin:
    203                 return
    204             self.planetUISvc.curveLineDrawer.ChangeLinePosition('rubberLink', self.myPinManager.rubberLink, pin.surfacePoint, parentPin.surfacePoint)
    205             self.myPinManager.UpdateRubberLinkLabels(pin.surfacePoint, parentPin.surfacePoint)
    206         else:
    207             self.ShowRoutesToFromPin(pin)
    208 
    209     def GetColony(self):
    210         planet = sm.GetService('planetUI').planet
    211         if planet:
    212             return planet.GetColony(session.charid)
    213 
    214     def ShowRoutesToFromPin(self, pin):
    215         self.StopShowingRouteToFromPin()
    216         self.showRoutePin = pin
    217         colony = self.GetColony()
    218         if not colony or colony.colonyData is None:
    219             return
    220         routesFrom = colony.colonyData.GetSourceRoutesForPin(pin.pin.id)
    221         routesTo = colony.colonyData.GetDestinationRoutesForPin(pin.pin.id)
    222         numRoutes = len(routesFrom)
    223         for i, route in enumerate(routesFrom):
    224             path = route.path
    225             links = self.myPinManager.GetLinksFromPath(path)
    226             for l, id in links:
    227                 l.ShowAsRoute(id, i, numRoutes)
    228 
    229             pin = self.GetPinByID(path[-1])
    230             pin.SetAsRoute()
    231 
    232         numRoutes = len(routesTo)
    233         for i, routeID in enumerate(routesTo):
    234             r = colony.GetRoute(routeID)
    235             path = r.path
    236             links = self.myPinManager.GetLinksFromPath(path)
    237             for l, id in links:
    238                 l.ShowAsRoute(id, i, numRoutes)
    239 
    240             pin = self.GetPinByID(path[0])
    241             pin.SetAsRoute()
    242 
    243     def _HighlightRoute(self, pin):
    244         colony = self.GetColony()
    245         currentRoute = self.myPinManager.currentRoute
    246         if currentRoute and pin.pin.id not in currentRoute:
    247             path = colony.FindShortestPathIDs(currentRoute[-1], pin.pin.id)
    248             self.myPinManager.routeHoverPath = path
    249             links = self.myPinManager.GetLinksFromPath(path)
    250             for l, id in links:
    251                 l.ShowAsRoute(id, 1, 1, self.myPinManager.currRouteVolume)
    252 
    253     def OnPlanetPinMouseExit(self, pinID):
    254         if not self:
    255             return
    256         pin = self.myPinManager.pinsByID.get(pinID, None)
    257         if not pin:
    258             return
    259         pin.OnMouseExit()
    260         if self.state == STATE_CREATEROUTE:
    261             path = getattr(self.myPinManager, 'routeHoverPath', [])
    262             links = self.myPinManager.GetLinksFromPath(path)
    263             for l, id in links:
    264                 l.RemoveAsRoute(id)
    265 
    266         else:
    267             self.StopShowingRouteToFromPin()
    268             if self.selectedPin:
    269                 self.ShowRoutesToFromPin(self.selectedPin)
    270 
    271     def StopShowingRouteToFromPin(self):
    272         if not self.showRoutePin:
    273             return
    274         colony = self.GetColony()
    275         if colony is None or colony.colonyData is None:
    276             return
    277         routesFrom = colony.colonyData.GetSourceRoutesForPin(self.showRoutePin.pin.id)
    278         routesTo = colony.colonyData.GetDestinationRoutesForPin(self.showRoutePin.pin.id)
    279         for route in routesFrom:
    280             path = route.path
    281             links = self.myPinManager.GetLinksFromPath(path)
    282             for l, id in links:
    283                 l.RemoveAsRoute(id)
    284 
    285             pin = self.GetPinByID(path[-1])
    286             pin.ResetAsRoute()
    287 
    288         for routeID in routesTo:
    289             r = colony.GetRoute(routeID)
    290             path = r.path
    291             links = self.myPinManager.GetLinksFromPath(path)
    292             for l, id in links:
    293                 l.RemoveAsRoute(id)
    294 
    295             pin = self.GetPinByID(path[0])
    296             pin.ResetAsRoute()
    297 
    298         self.showRoutePin = None
    299 
    300     def OnExtractionHeadMouseEnter(self, ecuID, headNum):
    301         if self.state == STATE_SURVEY:
    302             self.myPinManager.OnExtractionHeadMouseEnter(ecuID, headNum)
    303 
    304     def OnExtractionHeadMouseExit(self, ecuID, headNum):
    305         if self.state == STATE_SURVEY:
    306             self.myPinManager.OnExtractionHeadMouseExit(ecuID, headNum)
    307 
    308     def OnExtractionHeadMouseDown(self, ecuID, headNum):
    309         if self.state == STATE_SURVEY and not uicore.uilib.Key(uiconst.VK_CONTROL):
    310             self.myPinManager.BeginDragExtractionHead(ecuID, headNum)
    311 
    312     def OnExtractionHeadClicked(self, ecuID, headNum):
    313         if self.state == STATE_SURVEY:
    314             if uicore.uilib.Key(uiconst.VK_CONTROL):
    315                 self.myPinManager.RemoveExtractionHead(ecuID, headNum)
    316 
    317     def OnOtherCharactersCommandPinClicked(self, pinID):
    318         pin = self.otherPinManager.otherPlayerPinsByPinID.get(pinID)
    319         if not pin:
    320             return
    321         if evetypes.GetGroupID(pin.typeID) != const.groupCommandPins:
    322             return
    323         self.otherPinManager.RenderOtherCharactersNetwork(pin.ownerID)
    324 
    325     def OnPlanetOtherPinMouseEnter(self, pinID):
    326         if pinID not in self.otherPinManager.otherPlayerPinsByPinID:
    327             return
    328         pin = self.otherPinManager.otherPlayerPinsByPinID[pinID]
    329         pin.OnMouseEnter()
    330 
    331     def OnPlanetOtherPinMouseExit(self, pinID):
    332         if pinID not in self.otherPinManager.otherPlayerPinsByPinID:
    333             return
    334         pin = self.otherPinManager.otherPlayerPinsByPinID[pinID]
    335         pin.OnMouseExit()
    336 
    337     def OnPlanetNavClicked(self, wasDragged):
    338         surfacePoint = planetCommon.GetPickIntersectionPoint()
    339         if not wasDragged and self.state != STATE_SURVEY:
    340             self.DeselectCurrentlySelected()
    341             self.ResetMultiSelect()
    342             self.otherPinManager.HideOtherCharactersNetwork()
    343         if surfacePoint:
    344             if self.state == STATE_BUILDPIN:
    345                 if not wasDragged:
    346                     self.myPinManager.PlacePin(surfacePoint)
    347             elif self.state == STATE_SURVEY and uicore.uilib.Key(uiconst.VK_CONTROL):
    348                 wnd = SurveyWindow.GetIfOpen()
    349                 if wnd:
    350                     self.myPinManager.PlaceExtractionHead(wnd.pin.id, surfacePoint)
    351 
    352     def OnPlanetNavMouseUp(self):
    353         if self.state == STATE_SURVEY:
    354             if self.subState == SUBSTATE_MOVEEXTRACTIONHEAD:
    355                 self.myPinManager.EndDragExtractionHead()
    356 
    357     def OnPlanetNavRightClicked(self):
    358         if self.state != STATE_NORMAL:
    359             self.SetStateNormal()
    360             return True
    361         else:
    362             return False
    363 
    364     def OnPlanetSurfaceMouseMoved(self, surfacePoint):
    365         if self.state == STATE_CREATELINKEND:
    366             self.myPinManager.UpdateRubberLink(surfacePoint)
    367         elif self.state == STATE_BUILDPIN:
    368             if self.myPinManager.buildIndicatorPin:
    369                 self.myPinManager.buildIndicatorPin.SetLocation(surfacePoint)
    370                 canBuild = self.myPinManager.DistanceToOtherPinsOK(surfacePoint)
    371                 self.myPinManager.buildIndicatorPin.SetCanBuildIndication(canBuild)
    372         elif self.state == STATE_SURVEY:
    373             if self.subState == SUBSTATE_MOVEEXTRACTIONHEAD:
    374                 self.myPinManager.DragExtractionHeadTo(surfacePoint)
    375 
    376     def OnPlanetNavFocusLost(self):
    377         if self.state in (STATE_CREATELINKEND, STATE_BUILDPIN):
    378             self.SetStateNormal()
    379 
    380     def MoveTemplate(self):
    381         from eve.client.script.ui.shared.planet.templatePreviewWindow import StartDraggingTemplate
    382         x = uicore.uilib.x
    383         y = uicore.uilib.y
    384         StartDraggingTemplate(x, y)
    385 
    386     def OnPlanetLinkClicked(self, linkID):
    387         if linkID not in self.myPinManager.linksByGraphicID:
    388             return
    389         if self.state in (STATE_CREATEROUTE, STATE_CREATELINKSTART, STATE_CREATELINKEND):
    390             return
    391         if self.state == STATE_DECOMMISSION:
    392             link = self.myPinManager.linksByGraphicID[linkID]
    393             self.myPinManager.RemoveLink(link.GetIDTuple())
    394         else:
    395             self.SelectLink(linkID)
    396 
    397     def SelectLink(self, linkID):
    398         link = self.myPinManager.linksByGraphicID[linkID]
    399         if self.planetUISvc.currentContainer and self.planetUISvc.currentContainer.pin == link:
    400             return
    401         panelID = self.DeselectCurrentlySelected()
    402         link.SetSelected()
    403         self.selectedLink = link
    404         self.planetUISvc.OpenContainerLink(link, panelID)
    405 
    406     def OnPlanetLinkDblClicked(self, linkID):
    407         if self.planetUISvc.currentContainer:
    408             self.planetUISvc.currentContainer.ShowDefaultPanel()
    409 
    410     def OnPlanetLinkMouseEnter(self, lineID):
    411         if self.state == STATE_CREATEROUTE:
    412             return
    413         if lineID in self.myPinManager.linksByGraphicID:
    414             link = self.myPinManager.linksByGraphicID[lineID]
    415             link.OnMouseEnter()
    416 
    417     def OnPlanetLinkMouseExit(self, areaID):
    418         if self.state == STATE_CREATEROUTE:
    419             return
    420         if areaID in self.myPinManager.linksByGraphicID:
    421             link = self.myPinManager.linksByGraphicID[areaID]
    422             link.OnMouseExit()
    423 
    424     def BeginCreateLink(self, sourcePinID):
    425         self._SetState(STATE_CREATELINKSTART)
    426         self.DeselectCurrentlySelected()
    427         self.myPinManager.SetLinkParent(sourcePinID)