Exemplo n.º 1
0
class SquadronController(object):
    def __init__(self):
        self.shipFighterState = GetShipFighterState()
        self.michelle = sm.GetService('michelle')

    def GetSquadronVelocity(self, tubeFlagID):
        ball = self.GetSquadronBallInfo(tubeFlagID)
        if ball:
            velocity = ball.GetVectorDotAt(self.GetTimeNow()).Length()
            return velocity

    def GetSquadronDistance(self, tubeFlagID):
        ball = self.GetSquadronBallInfo(tubeFlagID)
        if ball:
            ball.GetVectorAt(self.GetTimeNow())
            return ball.surfaceDist

    def GetSquadronBallInfo(self, tubeFlagID):
        fightersItemID = self.GetFightersInSpaceItemID(tubeFlagID)
        if fightersItemID:
            ball = self.GetFightersBall(fightersItemID)
            return ball

    def GetFightersBall(self, fightersItemID):
        return self.michelle.GetBall(fightersItemID)

    def GetTimeNow(self):
        return gametime.GetSimTime()

    def GetFightersInSpaceItemID(self, tubeFlagID):
        fightersInSpace = self.shipFighterState.GetFightersInSpace(tubeFlagID)
        if fightersInSpace:
            return fightersInSpace.itemID

    def GetIsInSpace(self, tubeFlagID):
        fightersInSpace = self.shipFighterState.GetFightersInSpace(tubeFlagID)
        if fightersInSpace:
            return True
        return False

    def GetSquadronAction(self, tubeFlagID):
        tubeStatus = self.shipFighterState.GetTubeStatus(tubeFlagID)
        stateText = LABEL_BY_STATE[tubeStatus.statusID]
        if session.stationid2:
            stateColor = Color(*COLOR_OPEN)
        else:
            stateColor = Color(*COLOR_BY_STATE[tubeStatus.statusID])
        stateColor.a = 0.8
        return (stateText, stateColor)

    def GetAbilities(self, fighterTypeID):
        if fighterTypeID:
            abilities = fighters.IterTypeAbilities(fighterTypeID)
            return abilities

    def GetIncomingEwarEffects(self, fighterID):
        return self.shipFighterState.GetIncomingFighterEwar(fighterID)

    def GetSquadronHealth(self):
        return (12, 1, 4)
Exemplo n.º 2
0
 def ApplyAttributes(self, attributes):
     Container.ApplyAttributes(self, attributes)
     self.shipFighterState = GetShipFighterState()
     self.typeID = None
     self.squadronSize = None
     self.squadronMaxSize = None
     self.noHealthyFighters = 0
     self.squadronState = attributes.get('state', None)
     self.tubeFlagID = attributes.get('tubeFlagID', None)
     dashColors = self.GetDashColors()
     self.classIcon = Sprite(name='classIcon',
                             parent=self,
                             align=uiconst.CENTERBOTTOM,
                             width=16,
                             height=16,
                             top=18)
     self.classIcon.OnMouseEnter = self.OnMouseEnter
     self.classIcon.OnMouseExit = self.OnMouseExit
     self.classIcon.GetDragData = self.GetDragData
     self.fightersGauge = FighterHealthGaugeLine(parent=self,
                                                 dashColors=dashColors,
                                                 align=uiconst.CENTER)
     Sprite(
         parent=self,
         align=uiconst.CENTER,
         width=86,
         height=86,
         texturePath=
         'res:/UI/Texture/classes/ShipUI/Fighters/fighterItemOverlay.png',
         state=uiconst.UI_DISABLED)
     self.fighterIcon = Icon(
         parent=self,
         align=uiconst.CENTER,
         width=52,
         height=52,
         state=uiconst.UI_DISABLED,
         blendMode=1,
         textureSecondaryPath=
         'res:/UI/Texture/classes/ShipUI/Fighters/fighterItemMask.png',
         spriteEffect=trinity.TR2_SFX_MODULATE)
     Sprite(
         parent=self,
         align=uiconst.CENTER,
         width=86,
         height=86,
         texturePath=
         'res:/UI/Texture/classes/ShipUI/Fighters/fighterItemUnderlay.png',
         state=uiconst.UI_DISABLED)
     self.hilite = Sprite(
         parent=self,
         name='hilite',
         width=86,
         height=86,
         align=uiconst.CENTER,
         state=uiconst.UI_DISABLED,
         texturePath=
         'res:/UI/Texture/classes/ShipUI/Fighters/fighterItemUnderlayOver.png'
     )
     self.hilite.display = False
 def AddFighter(self, fighterID):
     if fighterID in self.items:
         return
     if self.shipFighterState is None:
         self.shipFighterState = GetShipFighterState()
         self.shipFighterState.ConnectFighterTargetUpdatedHandler(self._OnFighterTargetUpdate)
     self.items.append(fighterID)
     self._RebuildConnectorsForFighter(fighterID)
Exemplo n.º 4
0
 def ApplyAttributes(self, attributes):
     Container.ApplyAttributes(self, attributes)
     self.activeCurve = None
     self.activationPendingCurve = None
     self.deactivationCurve = None
     self.ramp_active = False
     self.buttonDisabled = False
     self.shipFighterState = GetShipFighterState()
     self.crimewatchSvc = sm.GetService('crimewatchSvc')
     self.innerCont = Container(name='innerCont',
                                parent=self,
                                align=uiconst.TOBOTTOM,
                                height=self.height)
     self.stateLabel = EveLabelSmall(parent=self.innerCont,
                                     align=uiconst.CENTER)
     self.controller = attributes.controller
     self.slotID = self.controller.slotID
     self.fighterID = attributes.fighterID
     self.fighterTypeID = attributes.fighterTypeID
     ability = self.GetAbilityInfo()
     self.abilityNameID = ability.displayNameID
     iconID = ability.iconID
     self.abilityIcon = Icon(parent=self.innerCont,
                             align=uiconst.CENTER,
                             width=32,
                             height=32,
                             icon=iconID,
                             state=uiconst.UI_DISABLED)
     self.hilite = Sprite(
         parent=self.innerCont,
         name='hilite',
         width=44,
         height=44,
         align=uiconst.CENTER,
         state=uiconst.UI_DISABLED,
         texturePath='res:/UI/Texture/classes/ShipUI/slotHilite.png',
         blendMode=trinity.TR2_SBM_ADDX2)
     self.hilite.display = False
     bgSprite = Sprite(
         parent=self.innerCont,
         align=uiconst.CENTER,
         width=64,
         height=64,
         texturePath=
         'res:/UI/Texture/classes/ShipUI/Fighters/slotFighterAbility.png',
         state=uiconst.UI_DISABLED)
     self.abilityIcon.SetSize(32, 32)
     self.DrawQtyCont()
     self.DrawTimer()
     self.DrawCoolDownTimer()
     self.DrawSafetyGlow()
     self.targetMode = ability.targetMode
     abilityID = GetAbilityIDForSlot(self.fighterTypeID, self.slotID)
     effectID = GetDogmaEffectIDForAbilityID(abilityID)
     self.abilityEffect = cfg.dgmeffects.Get(effectID)
     self.OnAbilityStatusUpdated(self.fighterID, self.slotID)
     self.shipFighterState.signalOnAbilityActivationStatusUpdate.connect(
         self.OnAbilityStatusUpdated)
Exemplo n.º 5
0
 def ConstructFighterManagementUI(self):
     self.shipFighterState = GetShipFighterState()
     topCont = Container(parent=self, align=uiconst.TOTOP, height=216)
     inSpace = Container(parent=topCont, align=uiconst.TOTOP, height=20)
     self.lightSquadrons = SquadronLightContainer(parent=inSpace)
     self.supportSquadrons = SquadronSupportContainer(parent=inSpace)
     self.heavySquadrons = SquadronHeavyContainer(parent=inSpace)
     self.squadronsCont = Container(parent=topCont, align=uiconst.TOALL)
     self.numOfTubes = GetFighterTubesForShip()
     self.ConstructSquadrons()
     self.ConstructSquadronTypes()
     self.UpdateSquadronTypes()
     self.GetTypeIDs()
     self.shipFighterState.signalOnFighterTubeStateUpdate.connect(
         self.OnFighterTubeStateUpdate)
Exemplo n.º 6
0
    def _AddActiveFighterAbilities(self):
        abilitiesOnTarget = GetShipFighterState().abilityTargetTracker.GetFighterAbilitiesForTarget(self.itemID)
        for fighterID, abilitySlotID in abilitiesOnTarget:
            self._AddFighterAbility(fighterID, abilitySlotID)

        self.ArrangeWeapons()
        self.SetSizeAutomatically()
        uthread.new(sm.GetService('target').AdjustRowSize)
Exemplo n.º 7
0
 def ApplyAttributes(self, attributes):
     ContainerAutoSize.ApplyAttributes(self, attributes)
     self.fighterID = attributes.fighterID
     self.tubeFlagID = attributes.tubeFlagID
     self.effectsOnFighter = None
     self.shipFighterState = GetShipFighterState()
     self.ewarIcons = {}
     self.controller = attributes.controller
     self.BuildEffectsData()
Exemplo n.º 8
0
 def ApplyAttributes(self, attributes):
     ContainerAutoSize.ApplyAttributes(self, attributes)
     self.shipFighterState = GetShipFighterState()
     self.parentFunc = attributes.parentFunc
     self.squadrons = []
     self.lastSelected = None
     left = BUTTONCONT_WIDTH + 4
     numOfTubes = GetFighterTubesForShip()
     self.DrawControlButtons()
     for i, tubeFlagID in enumerate(const.fighterTubeFlags):
         if i < numOfTubes:
             squadron = SquadronUI(parent=self,
                                   align=uiconst.BOTTOMLEFT,
                                   tubeFlagID=tubeFlagID,
                                   left=left)
             left = squadron.left + squadron.width + 6
             self.squadrons.append(squadron)
             self.width += SQUADRON_WIDTH
Exemplo n.º 9
0
 def _AddFighterAbility(self, fighterID, abilitySlotID):
     fighterState = GetShipFighterState()
     fighter = fighterState.GetFighterInSpaceByID(fighterID)
     fighterTypeID = fighter.typeID
     cont = uiprimitives.Container(parent=self.sr.assigned, align=uiconst.RELATIVE, width=32, height=32, state=uiconst.UI_HIDDEN)
     abilityID = GetAbilityIDForSlot(fighterTypeID, abilitySlotID)
     abilityInfo = fighters.AbilityStorage()[abilityID]
     abilityIconID = abilityInfo.iconID
     icon = uicontrols.Icon(parent=cont, align=uiconst.TOALL, width=0, height=0, state=uiconst.UI_NORMAL, icon=abilityIconID)
     cont.sr.moduleID = (fighterID, abilitySlotID)
     cont.sr.fighterID = fighterID
     cont.sr.abilitySlotID = abilitySlotID
     cont.icon = icon
     icon.sr.fighterID = fighterID
     icon.sr.abilitySlotID = abilitySlotID
     squadronNumber = SquadronNumber(parent=cont, top=-2, left=-4, idx=0)
     squadronNumber.SetColor()
     squadronNumber.SetText(fighter.tubeFlagID)
Exemplo n.º 10
0
    def Startup(self, slimItem):
        sm.RegisterNotify(self)
        GetShipFighterState().ConnectFighterTargetUpdatedHandler(self._OnFighterTargetUpdate)
        self.ball = _weakref.ref(sm.GetService('michelle').GetBall(slimItem.itemID))
        self.slimItem = _weakref.ref(slimItem)
        self.id = slimItem.itemID
        self.itemID = slimItem.itemID
        self.updatedamage = slimItem.categoryID not in (const.categoryAsteroid, const.categoryFighter) and slimItem.groupID not in (const.groupHarvestableCloud, const.groupOrbitalTarget)
        self.AddUIObjects(slimItem, self.itemID)
        iconPar = self.sr.iconPar
        barAndImageCont = self.barAndImageCont
        barAndImageCont.isDragObject = True
        barAndImageCont.GetDragData = self.GetTargetDragData
        barAndImageCont.OnMouseDown = self.OnTargetMouseDown
        barAndImageCont.OnClick = self.OnTargetClick
        barAndImageCont.GetMenu = self.GetTargetMenu
        barAndImageCont.OnMouseEnter = self.OnTargetMouseEnter
        barAndImageCont.OnMouseExit = self.OnTargetMouseExit
        self.sr.activeTarget = uicls.ActiveTargetOnBracket(parent=iconPar, itemID=self.itemID)
        self.slimForFlag = slimItem
        self.SetStandingIcon()
        self.sr.hilite = uiprimitives.Sprite(name='hiliteSprite', parent=iconPar, left=-3, top=-3, width=100, height=100, texturePath='res:/UI/Texture/classes/Target/targetUnderlay.png', color=(1.0, 1.0, 1.0, 0.05))
        self.sr.activeTarget.RotateArrows()
        labelClass = uicontrols.EveLabelSmall
        labelContainer = uicontrols.ContainerAutoSize(parent=self, name='labelContainer', align=uiconst.TOTOP)
        self.labelContainer = labelContainer
        self.sr.label = labelClass(text=' ', parent=labelContainer, align=uiconst.TOTOP, state=uiconst.UI_DISABLED, maxLines=1)
        self.sr.label2 = labelClass(text=' ', parent=labelContainer, align=uiconst.TOTOP, state=uiconst.UI_DISABLED, maxLines=1)
        self.sr.shipLabel = labelClass(text=' ', parent=labelContainer, align=uiconst.TOTOP, state=uiconst.UI_DISABLED, maxLines=1)
        self.sr.distanceLabel = labelClass(text=' ', parent=labelContainer, align=uiconst.TOTOP, state=uiconst.UI_DISABLED, maxLines=1)
        self.SetTargetLabel()
        self.sr.assignedPar = uiprimitives.Container(name='assignedPar', align=uiconst.TOTOP, parent=self, height=32)
        self.sr.assigned = uiprimitives.Container(name='assigned', align=uiconst.CENTERTOP, parent=self.sr.assignedPar, height=32)
        self.sr.updateTimer = base.AutoTimer(random.randint(750, 1000), self.UpdateData)
        self.UpdateData()
        selected = sm.GetService('state').GetExclState(state.selected)
        self.Select(selected == slimItem.itemID)
        hilited = sm.GetService('state').GetExclState(state.mouseOver)
        self.Hilite(hilited == slimItem.itemID)
        activeTargetID = sm.GetService('target').GetActiveTargetID()
        self.ActiveTarget(activeTargetID == slimItem.itemID)
        drones = sm.GetService('michelle').GetDrones()
        for key in drones:
            droneState = drones[key]
            if droneState.targetID == self.id:
                self.drones[droneState.droneID] = droneState.typeID

        self.UpdateDrones()
        for moduleInfo in sm.GetService('godma').GetStateManager().GetActiveModulesOnTargetID(slimItem.itemID):
            if moduleInfo:
                moduleID = moduleInfo.itemID
                if moduleID and moduleID not in self.activeModules:
                    self.AddWeapon(moduleInfo)
                    self.activeModules[moduleID] = moduleInfo

        self._AddActiveFighterAbilities()
Exemplo n.º 11
0
 def _OnFighterTargetUpdate(self, fighterID, abilitySlotID, targetID):
     if targetID != self.itemID:
         return
     abilitiesOnTarget = GetShipFighterState().abilityTargetTracker.GetFighterAbilitiesForTarget(self.itemID)
     if (fighterID, abilitySlotID) in abilitiesOnTarget:
         self._AddFighterAbility(fighterID, abilitySlotID)
     else:
         self._RemoveFighterAbility(fighterID, abilitySlotID)
     self.ArrangeWeapons()
     self.SetSizeAutomatically()
     uthread.new(sm.GetService('target').AdjustRowSize)
Exemplo n.º 12
0
class AbilityController(object):

    def __init__(self, abilityID, fighterID, slotID, fighterTypeID):
        self.abilityID = abilityID
        self.fighterID = fighterID
        self.slotID = slotID
        self.fighterTypeID = fighterTypeID
        self.shipFighterState = GetShipFighterState()

    def GetAbilityInfo(self):
        return fighters.AbilityStorage()[self.abilityID]

    def OnAbilityClick(self, targetMode):
        if self.shipFighterState.IsAbilityActive(self.fighterID, self.slotID):
            self.DeactivateAbility()
        else:
            self.ActivateAbility(targetMode)

    def ActivateAbility(self, targetMode):
        if self.fighterID is None:
            raise RuntimeError('Attempt to activate ability on null fighter')
        if targetMode == fighters.TARGET_MODE_UNTARGETED:
            self._OnActivateAbilityOnSelf()
        elif targetMode == fighters.TARGET_MODE_ITEMTARGETED:
            targetID = sm.GetService('target').GetActiveTargetID()
            self._OnActivateAbilityOnTarget(targetID)
        elif targetMode == fighters.TARGET_MODE_POINTTARGETED:
            eveCommands = sm.GetService('cmd')
            eveCommands.CmdAimFighterAbility(self.fighterID, self.slotID)
        else:
            raise ValueError('ActivateAbility got unexpected targetmode')

    def DeactivateAbility(self):
        self._OnDeactivateAbility()

    def _OnActivateAbilityOnTarget(self, targetID):
        sm.GetService('fighters').ActivateAbilitySlotsOnTarget([self.fighterID], self.slotID, targetID)

    def _OnActivateAbilityOnSelf(self):
        sm.GetService('fighters').ActivateAbilitySlotsOnSelf([self.fighterID], self.slotID)

    def _OnDeactivateAbility(self):
        sm.GetService('fighters').DeactivateAbilitySlots([self.fighterID], self.slotID)
Exemplo n.º 13
0
 def OnF(self, sidx, gidx):
     if not self.CheckShipHasFighterBay():
         self.slotsContainer.OnF(sidx, gidx)
         return
     shipIsSelected, fightersSelected = movementFunctions.GetSelectedShipAndFighters()
     if self.IsFightersDetached():
         moduleIsActive = self.IsModuleActiveForFKey(sidx, gidx)
         isAllAbilitiesActiveOrInCooldown = GetShipFighterState().IsAllAbilitiesInSlotActiveOrInCooldown(sidx)
         if shipIsSelected:
             if isAllAbilitiesActiveOrInCooldown:
                 if moduleIsActive is not None:
                     self.slotsContainer.OnF(sidx, gidx)
                 if moduleIsActive is None or moduleIsActive == True:
                     self.fighterCont.OnF(sidx)
             else:
                 self.fighterCont.OnF(sidx)
                 if moduleIsActive == False:
                     self.slotsContainer.OnF(sidx, gidx)
         else:
             self.fighterCont.OnF(sidx)
     elif self.IsFightersShown():
         self.fighterCont.OnF(sidx)
     else:
         self.slotsContainer.OnF(sidx, gidx)
Exemplo n.º 14
0
class SquadronUI(Container):
    __notifyevents__ = ['OnStateChange']
    default_width = SQUADRON_WIDTH
    default_height = 266
    default_name = 'squadronCont'

    def ApplyAttributes(self, attributes):
        Container.ApplyAttributes(self, attributes)
        sm.RegisterNotify(self)
        self.squadronMgmtController = SquadronMgmtController()
        self.inSpace = False
        self.shipFighterState = GetShipFighterState()
        self.tubeFlagID = attributes.tubeFlagID
        fighters = self.GetFightersState()
        if fighters:
            fighterID = fighters.itemID
            fighterTypeID = fighters.typeID
            squadronSize = fighters.squadronSize
        else:
            fighterID = None
            fighterTypeID = None
            squadronSize = None
        self.fighterID = fighterID
        self.fighterTypeID = fighterTypeID
        self.controller = SquadronController()
        self.squadronCont = SquadronCont(parent=self,
                                         controller=self.controller,
                                         align=uiconst.BOTTOMLEFT,
                                         tubeFlagID=self.tubeFlagID,
                                         state=uiconst.UI_NORMAL)
        self.squadronCont.OnClick = self.OnSquadronClick
        self.squadronCont.GetMenu = self.GetSquadronMenu
        self.squadronCont.SetNewSquadron(fighterID, fighterTypeID,
                                         squadronSize)
        self.squadronContEmpty = SquadronContEmpty(parent=self,
                                                   controller=self.controller,
                                                   fighterID=fighterID,
                                                   fighterTypeID=fighterTypeID,
                                                   align=uiconst.BOTTOMLEFT,
                                                   tubeFlagID=self.tubeFlagID)
        self.squadronContEmpty.GetMenu = self.GetSquadronMenu
        if not fighterID and not fighterTypeID:
            self.ShowEmpty()
        else:
            self.HideEmpty()
        self.effectsCont = EffectsCont(parent=self,
                                       controller=self.controller,
                                       fighterID=fighterID,
                                       fighterTypeID=fighterTypeID,
                                       tubeFlagID=self.tubeFlagID,
                                       top=self.squadronCont.height,
                                       align=uiconst.BOTTOMLEFT)
        self.modulesCont = AbilitiesCont(parent=self,
                                         left=20,
                                         top=self.squadronCont.height,
                                         align=uiconst.BOTTOMLEFT)
        self.modulesCont.SetNewSquadron(fighterID, fighterTypeID)
        self.SetupFighters()
        self.shipFighterState.signalOnFighterTubeStateUpdate.connect(
            self.OnFighterTubeStateUpdate)
        self.shipFighterState.signalOnFighterTubeContentUpdate.connect(
            self.OnFighterTubeContentUpdate)
        self.shipFighterState.signalOnFighterInSpaceUpdate.connect(
            self.OnFighterInSpaceUpdate)
        self.shipFighterState.signalOnIncomingEwarStarted.connect(
            self.OnEwarUpdated)
        self.shipFighterState.signalOnIncomingEwarEnded.connect(
            self.OnEwarUpdated)

    def SetupFighters(self):
        if self.inSpace:
            self.ShowInSpaceUI()
        else:
            self.HideInSpaceUI()

    def ShowInSpaceUI(self):
        self.modulesCont.ShowModules()
        self.effectsCont.ShowEffects()

    def HideInSpaceUI(self):
        self.modulesCont.HideModules()
        self.effectsCont.HideEffects()

    def ShowEmpty(self):
        self.squadronContEmpty.display = True
        self.squadronCont.display = False

    def HideEmpty(self):
        self.squadronContEmpty.display = False
        self.squadronCont.display = True

    def GetFightersInSpaceState(self):
        fighterInSpace = self.shipFighterState.GetFightersInSpace(
            self.tubeFlagID)
        if fighterInSpace is not None:
            self.inSpace = True
            return fighterInSpace

    def GetFightersInTubeState(self):
        fighterInTube = self.shipFighterState.GetFightersInTube(
            self.tubeFlagID)
        if fighterInTube is not None:
            self.inSpace = False
            return fighterInTube

    def GetFightersState(self):
        fightersInTube = self.GetFightersInTubeState()
        if fightersInTube:
            return fightersInTube
        fightersInSpace = self.GetFightersInSpaceState()
        if fightersInSpace:
            return fightersInSpace

    def OnEwarUpdated(self, targetBallID, sourceBallID, sourceModuleID,
                      jammingType):
        if targetBallID != self.fighterID:
            return
        self.effectsCont.BuildEffectsData()

    def OnFighterTubeStateUpdate(self, tubeFlagID):
        if tubeFlagID == self.tubeFlagID:
            tubeStatus = self.shipFighterState.GetTubeStatus(self.tubeFlagID)
            self.squadronCont.SetSquadronAction(self.tubeFlagID)
            if tubeStatus.statusID == TUBE_STATE_EMPTY:
                self.ShowEmpty()
            else:
                self.HideEmpty()
                if tubeStatus.endTime:
                    self.squadronCont.loadingGauge.display = True
                    now = gametime.GetSimTime()
                    duration = float(tubeStatus.endTime - tubeStatus.startTime)
                    loadingProgress = max(
                        0.0, min(1.0, (now - tubeStatus.startTime) / duration))
                    self.squadronCont.loadingGauge.SetValue(loadingProgress,
                                                            animate=False)
                    remainingTime = tubeStatus.endTime - now
                    remainingTimeSeconds = max(float(remainingTime) / SEC, 0.1)
                    self.squadronCont.loadingGauge.SetValueTimed(
                        1.0, remainingTimeSeconds)
                else:
                    self.squadronCont.loadingGauge.display = False

    def OnFighterTubeContentUpdate(self, tubeFlagID):
        if tubeFlagID == self.tubeFlagID:
            tubeStatus = self.shipFighterState.GetTubeStatus(self.tubeFlagID)
            if tubeStatus.statusID in (TUBE_STATE_EMPTY, TUBE_STATE_READY,
                                       TUBE_STATE_UNLOADING):
                self.ShowEmpty()
                self.squadronCont.ClearFighters()
            else:
                self.HideEmpty()
                fightersInTube = self.GetFightersInTubeState()
                if fightersInTube:
                    self.squadronCont.SetNewSquadron(
                        fightersInTube.itemID, fightersInTube.typeID,
                        fightersInTube.squadronSize)
                    self.fighterID = fightersInTube.itemID
                    self.fighterTypeID = fightersInTube.typeID
                    self.effectsCont.UpdateFighterID(self.fighterID)

    def OnFighterInSpaceUpdate(self, fighterID, tubeFlagID):
        if tubeFlagID == self.tubeFlagID:
            fightersInSpace = self.GetFightersInSpaceState()
            if fightersInSpace:
                self.squadronCont.SetNewSquadron(fightersInSpace.itemID,
                                                 fightersInSpace.typeID,
                                                 fightersInSpace.squadronSize)
                self.modulesCont.SetNewSquadron(fightersInSpace.itemID,
                                                fightersInSpace.typeID)
                self.squadronCont.SetSquadronInfo(tubeFlagID)
                self.ShowInSpaceUI()
            else:
                self.squadronCont.StopSquadronTimer()
                self.HideInSpaceUI()

    def Close(self):
        self.shipFighterState.signalOnFighterTubeStateUpdate.disconnect(
            self.OnFighterTubeStateUpdate)
        self.shipFighterState.signalOnFighterTubeContentUpdate.disconnect(
            self.OnFighterTubeContentUpdate)
        self.shipFighterState.signalOnFighterInSpaceUpdate.disconnect(
            self.OnFighterInSpaceUpdate)
        self.shipFighterState.signalOnIncomingEwarStarted.disconnect(
            self.OnEwarUpdated)
        self.shipFighterState.signalOnIncomingEwarEnded.disconnect(
            self.OnEwarUpdated)
        self.squadronCont.damageTimer = None
        Container.Close(self)

    def OnSquadronClick(self, *args):
        ctrl = uicore.uilib.Key(uiconst.VK_CONTROL)
        shift = uicore.uilib.Key(uiconst.VK_SHIFT)
        if not ctrl and not shift and uicore.cmd.IsSomeCombatCommandLoaded():
            uicore.cmd.ExecuteCombatCommand(self.fighterID, uiconst.UI_CLICK)
        elif shift:
            if self.parent.GetLastSelectedTube():
                self.parent.MultiSelectSquadrons(self.tubeFlagID)
                self.parent.SetLastSelectedTube(self.tubeFlagID)
        elif ctrl:
            if movementFunctions.IsSelectedForNavigation(self.fighterID):
                self.DeselectSquadron()
            else:
                self.SelectSquadron()
                self.parent.SetLastSelectedTube(self.tubeFlagID)
        else:
            self.parent.ClearSelection()
            if movementFunctions.IsSelectedForNavigation(session.shipid):
                movementFunctions.DeselectForNavigation(session.shipid)
            self.SelectSquadron()
            self.parent.SetLastSelectedTube(self.tubeFlagID)

    def IsSelected(self):
        if self.shipFighterState.GetFightersInSpace(self.tubeFlagID) is None:
            return False
        return movementFunctions.IsSelectedForNavigation(self.fighterID)

    def OnStateChange(self, itemID, flag, flagState, *args):
        if flag == states.selectedForNavigation and itemID == self.fighterID:
            if flagState:
                self.squadronCont.ShowSelectionHilite()
            else:
                self.squadronCont.HideSelectionHilite()

    def SelectSquadron(self):
        movementFunctions.SelectForNavigation(self.fighterID)

    def DeselectSquadron(self):
        movementFunctions.DeselectForNavigation(self.fighterID)

    def GetFighterItemID(self):
        return self.squadronCont.GetFighterItemID()

    def GetSquadronMenu(self):
        m = []
        ship = sm.GetService('godma').GetItem(session.shipid)
        if ship is None:
            return m
        tubeStatus = self.shipFighterState.GetTubeStatus(self.tubeFlagID)
        if tubeStatus.statusID == TUBE_STATE_EMPTY:
            m += self._GetSquadronMenuForEmptyTube()
            return m
        if self.GetFightersInSpaceState():
            m.append((MenuLabel('UI/Inventory/Fighters/RecallToLaunchTube'),
                      self.RecallFighterToTube))
            m.append((MenuLabel('UI/Drones/ReturnDroneAndOrbit'),
                      self.ReturnAndOrbit))
            m.append(
                (MenuLabel('UI/Fighters/AbandonFighter'), self.AbandonFighter))
        elif self.GetFightersInTubeState():
            m.append((MenuLabel('UI/Inventory/Fighters/LaunchToSpace'),
                      self.LaunchFightersFromTube))
            m.append((MenuLabel('UI/Inventory/Fighters/UnloadFromLaunchTube'),
                      self.UnloadTubeToFighterBay))
        m += sm.GetService('menu').CelestialMenu(self.fighterID,
                                                 typeID=self.fighterTypeID)
        return m

    def _GetSquadronMenuForEmptyTube(self):
        HEAVY = 0
        LIGHT = 1
        SUPPORT = 2
        OTHER = 3
        m = []
        fightersInBay = sm.GetService('invCache').GetInventoryFromId(
            session.shipid).ListFighterBay()
        optionsByClass = defaultdict(list)
        for fighter in fightersInBay:
            typeID = fighter.typeID
            if SquadronIsHeavy(typeID):
                fighterClass = HEAVY
            elif SquadronIsLight(typeID):
                fighterClass = LIGHT
            elif SquadronIsSupport(typeID):
                fighterClass = SUPPORT
            else:
                fighterClass = OTHER
            fighterLabel = GetByLabel(
                'UI/Inflight/Drone/DroneBayEntryWithStacksize',
                drone=fighter.typeID,
                stacksize=fighter.stacksize)
            optionsByClass[fighterClass].append(
                (fighterLabel, self.LoadFighterToTube, (fighter.itemID, )))

        for fighterClass in (HEAVY, LIGHT, SUPPORT, OTHER):
            options = optionsByClass.get(fighterClass, [])
            if not options:
                continue
            sortedOptions = sorted(options, key=lambda x: x[0])
            m += sortedOptions
            m += [None]

        return m

    def RecallFighterToTube(self):
        self.squadronMgmtController.RecallFighterToTube(self.fighterID)

    def LoadFighterToTube(self, fighterID):
        self.squadronMgmtController.LoadFightersToTube(fighterID,
                                                       self.tubeFlagID)

    def UnloadTubeToFighterBay(self):
        self.squadronMgmtController.UnloadTubeToFighterBay(self.tubeFlagID)

    def LaunchFightersFromTube(self):
        self.squadronMgmtController.LaunchFightersFromTube(self.tubeFlagID)

    def AbandonFighter(self):
        sm.GetService('fighters').AbandonFighter(self.fighterID)

    def ReturnAndOrbit(self):
        sm.GetService('fighters').CmdReturnAndOrbit([self.fighterID])
Exemplo n.º 15
0
class FighterLaunchControlCont(Container):
    default_height = 196
    default_width = 86
    default_align = uiconst.TOLEFT

    def ApplyAttributes(self, attributes):
        Container.ApplyAttributes(self, attributes)
        self.controller = SquadronMgmtController()
        self.shipFighterState = GetShipFighterState()
        self.tubeFlagID = attributes.tubeFlagID
        self.leftTube = Sprite(
            parent=self,
            texturePath=
            'res:/UI/Texture/classes/CarrierBay/tubeSideElement.png',
            align=uiconst.TOLEFT_NOPUSH,
            width=15)
        self.rightTube = Sprite(
            parent=self,
            texturePath=
            'res:/UI/Texture/classes/CarrierBay/tubeSideElementRIGHT.png',
            align=uiconst.TORIGHT_NOPUSH,
            width=15)
        inSpaceCont = Container(parent=self, height=86, align=uiconst.TOTOP)
        inSpaceCont.OnDropData = self.OnDropToSpace
        inSpaceCont.GetMenu = self.GetMenu
        self.squadronNumber = SquadronNumber(parent=inSpaceCont, top=1, left=1)
        self.squadronNumber.SetText(self.tubeFlagID)
        self.inStationCont = Container(parent=inSpaceCont, align=uiconst.TOALL)
        cantLaunchIcon = Sprite(
            parent=self.inStationCont,
            width=44,
            height=44,
            align=uiconst.CENTER,
            texturePath='res:/UI/Texture/classes/CarrierBay/unableToLaunch.png'
        )
        self.stateCont = Container(parent=self,
                                   height=24,
                                   align=uiconst.TOTOP,
                                   state=uiconst.UI_NORMAL)
        self.stateContBG = Fill(bgParent=self.stateCont, color=(0, 0, 0, 0))
        deckCont = Container(parent=self,
                             height=86,
                             align=uiconst.TOTOP,
                             state=uiconst.UI_NORMAL)
        deckCont.OnDropData = self.OnDropToTube
        deckCont.GetMenu = self.GetMenu
        self.tubeStatusLabel = EveHeaderSmall(parent=self.stateCont,
                                              align=uiconst.CENTER,
                                              text='')
        self.loadingGauge = Gauge(parent=self.stateCont,
                                  align=uiconst.CENTERBOTTOM,
                                  backgroundColor=(0, 0, 0, 1),
                                  color=(0.2, 0.2, 0.2, 0.5),
                                  padLeft=1,
                                  padRight=1,
                                  top=1,
                                  width=75,
                                  value=0.0)
        self.loadingGauge.display = False
        spaceColor = Color(*COLOR_INSPACE)
        spaceColor.a = 1.0
        self.launchIcon = ButtonIcon(
            parent=inSpaceCont,
            align=uiconst.CENTER,
            width=86,
            height=86,
            iconSize=44,
            texturePath='res:/UI/Texture/classes/CarrierBay/tubeLaunch_Up.png',
            downTexture=
            'res:/UI/Texture/classes/CarrierBay/tubeLaunch_Down.png',
            hoverTexture=
            'res:/UI/Texture/classes/CarrierBay/tubeLaunch_Over.png',
            iconColor=spaceColor.GetRGBA(),
            showGlow=False)
        self.launchIcon.OnClick = self.LaunchFightersFromTube
        self.launchIcon.OnDropData = self.OnDropToSpace
        returnColor = Color(*COLOR_RETURNING)
        returnColor.a = 1.0
        self.scoopIcon = ButtonIcon(
            parent=deckCont,
            align=uiconst.CENTER,
            width=86,
            height=86,
            iconSize=44,
            texturePath='res:/UI/Texture/classes/CarrierBay/tubeRecall_Up.png',
            downTexture=
            'res:/UI/Texture/classes/CarrierBay/tubeRecall_Down.png',
            hoverTexture=
            'res:/UI/Texture/classes/CarrierBay/tubeRecall_Over.png',
            iconColor=returnColor.GetRGBA(),
            showGlow=False)
        self.scoopIcon.OnClick = self.RecallFighterToTube
        self.scoopIcon.OnDropData = self.OnDropToTube
        self.landingStrip = LandingStrip(parent=deckCont)
        self.landingStrip.display = False
        self.emptyTubeIcon = ButtonIcon(
            parent=deckCont,
            align=uiconst.CENTER,
            width=44,
            height=44,
            iconSize=44,
            texturePath='res:/UI/Texture/classes/CarrierBay/tubeOpen_Up.png',
            downTexture='res:/UI/Texture/classes/CarrierBay/tubeOpen_Down.png',
            hoverTexture='res:/UI/Texture/classes/CarrierBay/tubeOpen_Over.png',
            showGlow=False)
        self.emptyTubeIcon.OnDropData = self.OnDropToTube
        self.squadronInSpace = FightersHealthGauge(name='squadronInSpace',
                                                   parent=inSpaceCont,
                                                   align=uiconst.CENTER,
                                                   width=86,
                                                   height=86,
                                                   state=TUBE_STATE_INSPACE,
                                                   tubeFlagID=self.tubeFlagID)
        self.squadronInSpace.display = False
        self.squadronInSpace.GetMenu = self.GetMenu
        self.squadronInTube = FightersHealthGauge(name='squadronInTube',
                                                  parent=deckCont,
                                                  align=uiconst.CENTER,
                                                  width=86,
                                                  height=86,
                                                  state=TUBE_STATE_READY,
                                                  tubeFlagID=self.tubeFlagID)
        self.squadronInTube.OnDropData = self.OnDropToTube
        self.squadronInTube.display = False
        self.squadronInTube.GetMenu = self.GetMenu
        self.launchingStrip = LaunchingStrip(parent=inSpaceCont)
        self.launchingStrip.display = False
        self.UpdateLaunchTubeContentUI()
        self.UpdateLaunchTubeStateUI()
        self.UpdateInSpaceUI()
        self.shipFighterState.signalOnFighterTubeStateUpdate.connect(
            self.OnFighterTubeStateUpdate)
        self.shipFighterState.signalOnFighterTubeContentUpdate.connect(
            self.OnFighterTubeContentUpdate)
        self.shipFighterState.signalOnFighterInSpaceUpdate.connect(
            self.OnFighterInSpaceUpdate)

    def Close(self):
        self.shipFighterState.signalOnFighterTubeStateUpdate.disconnect(
            self.OnFighterTubeStateUpdate)
        self.shipFighterState.signalOnFighterTubeContentUpdate.disconnect(
            self.OnFighterTubeContentUpdate)
        self.shipFighterState.signalOnFighterInSpaceUpdate.disconnect(
            self.OnFighterInSpaceUpdate)

    def LaunchFightersFromTube(self):
        self.controller.LaunchFightersFromTube(self.tubeFlagID)

    def RecallFighterToTube(self):
        fighterInSpace = self.shipFighterState.GetFightersInSpace(
            self.tubeFlagID)
        self.controller.RecallFighterToTube(fighterInSpace.itemID)

    def ReturnAndOrbit(self):
        fighterInSpace = self.shipFighterState.GetFightersInSpace(
            self.tubeFlagID)
        sm.GetService('fighters').CmdReturnAndOrbit([fighterInSpace.itemID])

    def OnDropToSpace(self, dragSource, dragData):
        data = dragData[0]
        if data.tubeFlagID == self.tubeFlagID and data.squadronState == TUBE_STATE_READY:
            self.LaunchFightersFromTube()

    def OnDropToTube(self, dragSource, dragData):
        data = dragData[0]
        if data.__guid__ == 'uicls.FightersHealthGauge':
            if data.tubeFlagID == self.tubeFlagID and data.squadronState == TUBE_STATE_INSPACE:
                self.RecallFighterToTube()
        elif data.__guid__ in ('xtriui.InvItem', 'listentry.InvItem'):
            tubeStatus = self.shipFighterState.GetTubeStatus(self.tubeFlagID)
            if tubeStatus.statusID in (TUBE_STATE_EMPTY, TUBE_STATE_READY):
                fighterID = data.itemID
                self.controller.LoadFightersToTube(fighterID, self.tubeFlagID)

    def UnloadTubeToFighterBay(self):
        self.controller.UnloadTubeToFighterBay(self.tubeFlagID)

    def UpdateLaunchTubeContentUI(self):
        fighterInTube = self.shipFighterState.GetFightersInTube(
            self.tubeFlagID)
        if fighterInTube is not None:
            self.squadronInTube.display = True
            if not self.ShouldShowStationUI():
                self.launchIcon.display = True
            self.scoopIcon.display = False
            self.landingStrip.display = False
            self.squadronInTube.LoadFighterToSquadron(fighterInTube.typeID)
            self.squadronInTube.SetSquadronSize(fighterInTube.squadronSize)
        else:
            self.squadronInTube.display = False
            self.launchIcon.display = False

    def ShowStationUI(self):
        self.inStationCont.display = True
        self.launchIcon.display = False

    def UpdateLaunchTubeStateUI(self):
        tubeStatus = self.shipFighterState.GetTubeStatus(self.tubeFlagID)
        self.UpdateStatusUI(tubeStatus)
        if tubeStatus.endTime:
            if tubeStatus.statusID in (TUBE_STATE_RECALLING,
                                       TUBE_STATE_LANDING):
                self.landingStrip.display = True
                self.scoopIcon.display = False
            elif tubeStatus.statusID == TUBE_STATE_LAUNCHING:
                self.launchingStrip.display = True
                self.launchIcon.display = False
            else:
                self.loadingGauge.display = True
                now = gametime.GetSimTime()
                duration = float(tubeStatus.endTime - tubeStatus.startTime)
                loadingProgress = max(
                    0.0, min(1.0, (now - tubeStatus.startTime) / duration))
                self.loadingGauge.SetValue(loadingProgress, animate=False)
                remainingTime = tubeStatus.endTime - now
                remainingTimeSeconds = max(float(remainingTime) / SEC, 0.1)
                self.loadingGauge.SetValueTimed(1.0, remainingTimeSeconds)
                self.tubeStatusLabel.top = -2
        else:
            self.loadingGauge.SetValue(0)
            self.loadingGauge.display = False
            self.landingStrip.display = False
            self.launchingStrip.display = False
            self.tubeStatusLabel.top = 0
        if tubeStatus.statusID == TUBE_STATE_EMPTY:
            self.emptyTubeIcon.display = True
            self.scoopIcon.display = False
            self.squadronNumber.SetColor(True)
        else:
            self.emptyTubeIcon.display = False
            self.squadronNumber.SetColor(False)

    def UpdateStatusUI(self, tubeStatus):
        stateText = LABEL_BY_STATE[tubeStatus.statusID]
        self.tubeStatusLabel.text = GetByLabel(stateText)
        if self.ShouldShowStationUI():
            stateColor = Color(*COLOR_OPEN)
        else:
            stateColor = Color(*COLOR_BY_STATE[tubeStatus.statusID])
        self.leftTube.SetRGBA(*stateColor.GetRGBA())
        self.rightTube.SetRGBA(*stateColor.GetRGBA())
        stateColor.a = 0.8
        self.tubeStatusLabel.SetTextColor(stateColor.GetRGBA())

    def UpdateInSpaceUI(self):
        if self.ShouldShowStationUI():
            self.ShowStationUI()
            return
        self.inStationCont.display = False
        fighterInSpace = self.shipFighterState.GetFightersInSpace(
            self.tubeFlagID)
        if fighterInSpace is not None:
            self.scoopIcon.display = True
            self.squadronInSpace.display = True
            self.squadronInSpace.LoadFighterToSquadron(fighterInSpace.typeID)
            self.squadronInSpace.SetSquadronSize(fighterInSpace.squadronSize)
        else:
            self.scoopIcon.display = False
            self.squadronInSpace.display = False

    def GetMenu(self):
        m = []
        fighterInTube = self.shipFighterState.GetFightersInTube(
            self.tubeFlagID)
        if fighterInTube is not None:
            if not session.stationid2:
                m.append((MenuLabel('UI/Inventory/Fighters/LaunchToSpace'),
                          self.LaunchFightersFromTube))
            m.append((MenuLabel('UI/Inventory/Fighters/UnloadFromLaunchTube'),
                      self.UnloadTubeToFighterBay))
            m.append((MenuLabel('UI/Commands/ShowInfo'),
                      sm.GetService('menu').ShowInfo, (fighterInTube.typeID,
                                                       fighterInTube.itemID)))
        fighterInSpace = self.shipFighterState.GetFightersInSpace(
            self.tubeFlagID)
        if fighterInSpace is not None:
            m.append((MenuLabel('UI/Inventory/Fighters/RecallToLaunchTube'),
                      self.RecallFighterToTube))
            m.append((MenuLabel('UI/Drones/ReturnDroneAndOrbit'),
                      self.ReturnAndOrbit))
            m.append((MenuLabel('UI/Commands/ShowInfo'),
                      sm.GetService('menu').ShowInfo, (fighterInSpace.typeID,
                                                       fighterInSpace.itemID)))
        return m

    def OnFighterTubeStateUpdate(self, tubeFlagID):
        if tubeFlagID == self.tubeFlagID:
            self.UpdateLaunchTubeStateUI()

    def OnFighterTubeContentUpdate(self, tubeFlagID):
        if tubeFlagID == self.tubeFlagID:
            self.UpdateLaunchTubeContentUI()

    def OnFighterInSpaceUpdate(self, fighterID, tubeFlagID):
        if tubeFlagID == self.tubeFlagID:
            self.UpdateInSpaceUI()

    def ShouldShowStationUI(self):
        return session.stationid2
Exemplo n.º 16
0
 def ApplyAttributes(self, attributes):
     Container.ApplyAttributes(self, attributes)
     self.controller = SquadronMgmtController()
     self.shipFighterState = GetShipFighterState()
     self.tubeFlagID = attributes.tubeFlagID
     self.leftTube = Sprite(
         parent=self,
         texturePath=
         'res:/UI/Texture/classes/CarrierBay/tubeSideElement.png',
         align=uiconst.TOLEFT_NOPUSH,
         width=15)
     self.rightTube = Sprite(
         parent=self,
         texturePath=
         'res:/UI/Texture/classes/CarrierBay/tubeSideElementRIGHT.png',
         align=uiconst.TORIGHT_NOPUSH,
         width=15)
     inSpaceCont = Container(parent=self, height=86, align=uiconst.TOTOP)
     inSpaceCont.OnDropData = self.OnDropToSpace
     inSpaceCont.GetMenu = self.GetMenu
     self.squadronNumber = SquadronNumber(parent=inSpaceCont, top=1, left=1)
     self.squadronNumber.SetText(self.tubeFlagID)
     self.inStationCont = Container(parent=inSpaceCont, align=uiconst.TOALL)
     cantLaunchIcon = Sprite(
         parent=self.inStationCont,
         width=44,
         height=44,
         align=uiconst.CENTER,
         texturePath='res:/UI/Texture/classes/CarrierBay/unableToLaunch.png'
     )
     self.stateCont = Container(parent=self,
                                height=24,
                                align=uiconst.TOTOP,
                                state=uiconst.UI_NORMAL)
     self.stateContBG = Fill(bgParent=self.stateCont, color=(0, 0, 0, 0))
     deckCont = Container(parent=self,
                          height=86,
                          align=uiconst.TOTOP,
                          state=uiconst.UI_NORMAL)
     deckCont.OnDropData = self.OnDropToTube
     deckCont.GetMenu = self.GetMenu
     self.tubeStatusLabel = EveHeaderSmall(parent=self.stateCont,
                                           align=uiconst.CENTER,
                                           text='')
     self.loadingGauge = Gauge(parent=self.stateCont,
                               align=uiconst.CENTERBOTTOM,
                               backgroundColor=(0, 0, 0, 1),
                               color=(0.2, 0.2, 0.2, 0.5),
                               padLeft=1,
                               padRight=1,
                               top=1,
                               width=75,
                               value=0.0)
     self.loadingGauge.display = False
     spaceColor = Color(*COLOR_INSPACE)
     spaceColor.a = 1.0
     self.launchIcon = ButtonIcon(
         parent=inSpaceCont,
         align=uiconst.CENTER,
         width=86,
         height=86,
         iconSize=44,
         texturePath='res:/UI/Texture/classes/CarrierBay/tubeLaunch_Up.png',
         downTexture=
         'res:/UI/Texture/classes/CarrierBay/tubeLaunch_Down.png',
         hoverTexture=
         'res:/UI/Texture/classes/CarrierBay/tubeLaunch_Over.png',
         iconColor=spaceColor.GetRGBA(),
         showGlow=False)
     self.launchIcon.OnClick = self.LaunchFightersFromTube
     self.launchIcon.OnDropData = self.OnDropToSpace
     returnColor = Color(*COLOR_RETURNING)
     returnColor.a = 1.0
     self.scoopIcon = ButtonIcon(
         parent=deckCont,
         align=uiconst.CENTER,
         width=86,
         height=86,
         iconSize=44,
         texturePath='res:/UI/Texture/classes/CarrierBay/tubeRecall_Up.png',
         downTexture=
         'res:/UI/Texture/classes/CarrierBay/tubeRecall_Down.png',
         hoverTexture=
         'res:/UI/Texture/classes/CarrierBay/tubeRecall_Over.png',
         iconColor=returnColor.GetRGBA(),
         showGlow=False)
     self.scoopIcon.OnClick = self.RecallFighterToTube
     self.scoopIcon.OnDropData = self.OnDropToTube
     self.landingStrip = LandingStrip(parent=deckCont)
     self.landingStrip.display = False
     self.emptyTubeIcon = ButtonIcon(
         parent=deckCont,
         align=uiconst.CENTER,
         width=44,
         height=44,
         iconSize=44,
         texturePath='res:/UI/Texture/classes/CarrierBay/tubeOpen_Up.png',
         downTexture='res:/UI/Texture/classes/CarrierBay/tubeOpen_Down.png',
         hoverTexture='res:/UI/Texture/classes/CarrierBay/tubeOpen_Over.png',
         showGlow=False)
     self.emptyTubeIcon.OnDropData = self.OnDropToTube
     self.squadronInSpace = FightersHealthGauge(name='squadronInSpace',
                                                parent=inSpaceCont,
                                                align=uiconst.CENTER,
                                                width=86,
                                                height=86,
                                                state=TUBE_STATE_INSPACE,
                                                tubeFlagID=self.tubeFlagID)
     self.squadronInSpace.display = False
     self.squadronInSpace.GetMenu = self.GetMenu
     self.squadronInTube = FightersHealthGauge(name='squadronInTube',
                                               parent=deckCont,
                                               align=uiconst.CENTER,
                                               width=86,
                                               height=86,
                                               state=TUBE_STATE_READY,
                                               tubeFlagID=self.tubeFlagID)
     self.squadronInTube.OnDropData = self.OnDropToTube
     self.squadronInTube.display = False
     self.squadronInTube.GetMenu = self.GetMenu
     self.launchingStrip = LaunchingStrip(parent=inSpaceCont)
     self.launchingStrip.display = False
     self.UpdateLaunchTubeContentUI()
     self.UpdateLaunchTubeStateUI()
     self.UpdateInSpaceUI()
     self.shipFighterState.signalOnFighterTubeStateUpdate.connect(
         self.OnFighterTubeStateUpdate)
     self.shipFighterState.signalOnFighterTubeContentUpdate.connect(
         self.OnFighterTubeContentUpdate)
     self.shipFighterState.signalOnFighterInSpaceUpdate.connect(
         self.OnFighterInSpaceUpdate)
Exemplo n.º 17
0
 def _OnClose(self, *args):
     sm.UnregisterNotify(self)
     self.sr.updateTimer = None
     GetShipFighterState().DisconnectFighterTargetUpdatedHandler(self._OnFighterTargetUpdate)
Exemplo n.º 18
0
 def __init__(self):
     self.shipFighterState = GetShipFighterState()
     self.michelle = sm.GetService('michelle')
Exemplo n.º 19
0
class FighterInvCont(invCont._InvContBase):
    __guid__ = 'invCont.FighterInvCont'
    __invControllerClass__ = None
    __notifyevents__ = invCont._InvContBase.__notifyevents__ + [
        'ProcessActiveShipChanged'
    ]

    def ApplyAttributes(self, attributes):
        self.squadrons = []
        invCont._InvContBase.ApplyAttributes(self, attributes)

    def ConstructUI(self):
        if self.IsCurrentShip():
            self.ConstructFighterManagementUI()
        invCont._InvContBase.ConstructUI(self)

    def ConstructFighterManagementUI(self):
        self.shipFighterState = GetShipFighterState()
        topCont = Container(parent=self, align=uiconst.TOTOP, height=216)
        inSpace = Container(parent=topCont, align=uiconst.TOTOP, height=20)
        self.lightSquadrons = SquadronLightContainer(parent=inSpace)
        self.supportSquadrons = SquadronSupportContainer(parent=inSpace)
        self.heavySquadrons = SquadronHeavyContainer(parent=inSpace)
        self.squadronsCont = Container(parent=topCont, align=uiconst.TOALL)
        self.numOfTubes = GetFighterTubesForShip()
        self.ConstructSquadrons()
        self.ConstructSquadronTypes()
        self.UpdateSquadronTypes()
        self.GetTypeIDs()
        self.shipFighterState.signalOnFighterTubeStateUpdate.connect(
            self.OnFighterTubeStateUpdate)

    def _OnClose(self, *args):
        if self.IsCurrentShip():
            self.shipFighterState.signalOnFighterTubeStateUpdate.disconnect(
                self.OnFighterTubeStateUpdate)
        invCont._InvContBase._OnClose(self, args)

    def IsCurrentShip(self):
        return self.itemID == session.shipid

    def ConstructSquadrons(self):
        for i, tubeFlagID in enumerate(const.fighterTubeFlags):
            if i < self.numOfTubes:
                squadron = FighterLaunchControlCont(parent=self.squadronsCont,
                                                    tubeFlagID=tubeFlagID,
                                                    left=2)
                self.squadrons.append(squadron)

    def ConstructSquadronTypes(self):
        light, support, heavy = GetLightSupportHeavySlotsForShip()
        if heavy:
            self.heavySquadrons.SetTotalSlots(heavy)
        else:
            self.heavySquadrons.display = False
        if support:
            self.supportSquadrons.SetTotalSlots(support)
        else:
            self.supportSquadrons.display = False
        if light:
            self.lightSquadrons.SetTotalSlots(light)
        else:
            self.lightSquadrons.display = False

    def OnFighterTubeStateUpdate(self, *args):
        self.UpdateSquadronTypes()

    def UpdateSquadronTypes(self):
        heavy, support, light = self.GetSquadronTypes()
        self.heavySquadrons.SetUsedSlots(heavy)
        self.supportSquadrons.SetUsedSlots(support)
        self.lightSquadrons.SetUsedSlots(light)

    def GetSquadronTypes(self):
        heavy = 0
        support = 0
        light = 0
        typeIDs = self.GetTypeIDs()
        for typeID in typeIDs:
            if SquadronIsHeavy(typeID):
                heavy += 1
            elif SquadronIsSupport(typeID):
                support += 1
            elif SquadronIsLight(typeID):
                light += 1

        return (heavy, support, light)

    def GetTypeIDs(self):
        squadronTypeIDs = []
        for i, tubeFlagID in enumerate(const.fighterTubeFlags):
            if i < self.numOfTubes:
                fighterInTube = self.shipFighterState.GetFightersInTube(
                    tubeFlagID)
                if fighterInTube is not None:
                    squadronTypeIDs.append(fighterInTube.typeID)
                fighterInSpace = self.shipFighterState.GetFightersInSpace(
                    tubeFlagID)
                if fighterInSpace is not None:
                    squadronTypeIDs.append(fighterInSpace.typeID)

        return squadronTypeIDs

    def ProcessActiveShipChanged(self, shipID, oldShipID):
        self.Flush()
        self.ConstructUI()
Exemplo n.º 20
0
class ActionDisplay:

    def __init__(self, navPointContainer):
        self.shipid = 'shipid'
        self.items = [self.shipid]
        self.targetConnectors = {}
        self.orbitConnectors = {}
        self.navPointContainer = navPointContainer
        self.itemKeyToNavPoint = {}
        self.abilityTargets = {}
        self.shipFighterState = None
        self._updateThreadRunning = False

    def Enable(self, enable):
        if enable:
            if self.shipid not in self.items:
                self.items.append(self.shipid)
            if not self._updateThreadRunning:
                self._updateThreadRunning = True
                uthread2.StartTasklet(self._UpdateThread)
        else:
            self.ClearAll()
            self._updateThreadRunning = False

    def SetMaxMoveRange(self, range):
        self.maxMoveDistance = range * 2.0

    def _SetNavigationPoint(self, itemKey, globalPosition):
        ballID = self._GetBallID(itemKey)
        if self._HasCorrectNavPoint(itemKey, globalPosition):
            return self.itemKeyToNavPoint[itemKey]
        self._RemoveNavPointForBall(itemKey)
        navPoint = self.navPointContainer.GetOrCreatePoint(globalPosition)
        self.navPointContainer.ConfirmNavPoint(ballID, navPoint)
        self.itemKeyToNavPoint[itemKey] = navPoint
        return navPoint

    def _RemoveNavPointForBall(self, itemKey):
        if itemKey in self.itemKeyToNavPoint:
            oldNavPoint = self.itemKeyToNavPoint[itemKey]
            self.navPointContainer.Dereference(oldNavPoint)
            del self.itemKeyToNavPoint[itemKey]

    def _HasCorrectNavPoint(self, itemKey, globalPosition):
        if itemKey in self.itemKeyToNavPoint:
            oldNavPoint = self.itemKeyToNavPoint[itemKey]
            if oldNavPoint.globalPosition == globalPosition:
                return True
        return False

    def _GetBallID(self, itemKey):
        if itemKey == self.shipid:
            return session.shipid
        return itemKey

    def _ClearUIForItem(self, itemKey):
        itemID = self._GetBallID(itemKey)
        if itemKey in self.itemKeyToNavPoint:
            self._RemoveNavPointForBall(itemKey)
        if itemKey in self.targetConnectors:
            self._RemoveMovementLine(itemKey)
        if itemKey in self.orbitConnectors:
            self._RemoveOrbit(itemKey)
        if itemID in self.abilityTargets:
            for targetID in self.abilityTargets[itemID]:
                connector = self.abilityTargets[itemID][targetID]
                connector.Destroy()

            del self.abilityTargets[itemID]

    def ClearAll(self):
        for itemKey in self.items:
            self._ClearUIForItem(itemKey)

        self.positionToNavPoint = {}
        self.itemKeyToNavPoint = {}
        self.abilityTargets = {}
        self.items = [self.shipid]

    def _AddMovementLine(self, itemKey, sourceBall, targetBall, maxDistance):
        if targetBall is None:
            return
        if itemKey in self.targetConnectors:
            self.targetConnectors[itemKey].SetDestinationCurve(targetBall)
            self.targetConnectors[itemKey].lineConnector.length = maxDistance
        else:
            connector = tacticalui.CreateMovementConnector(sourceBall, targetBall)
            self.targetConnectors[itemKey] = connector
            self.targetConnectors[itemKey].lineConnector.length = maxDistance

    def _RemoveMovementLine(self, itemKey):
        if itemKey in self.targetConnectors:
            connector = self.targetConnectors[itemKey]
            connector.Destroy()
            del self.targetConnectors[itemKey]

    def _SetOrbitLine(self, itemKey, sourceBall, targetBall):
        if itemKey in self.orbitConnectors:
            connector = self.orbitConnectors[itemKey]
            self.orbitConnectors[itemKey].SetDestinationCurve(targetBall)
            self.orbitConnectors[itemKey].SetSourceCurve(sourceBall)
        else:
            connector = tacticalui.CreateOrbitConenctor(sourceBall, targetBall)
            self.orbitConnectors[itemKey] = connector
        connector.lineConnector.length = targetBall.radius + sourceBall.followRange + sourceBall.radius
        precession = 0.001
        currentTime = GetBallpark().currentTime
        phi1 = currentTime * precession
        phi2 = (sourceBall.id & 65535) + currentTime * precession
        x = math.cos(phi1) * math.cos(phi2)
        y = math.sin(phi2)
        z = math.sin(phi1) * math.cos(phi2)
        connector.lineConnector.planeNormal = (x, y, z)

    def _RemoveOrbit(self, itemKey):
        if itemKey in self.orbitConnectors:
            connector = self.orbitConnectors[itemKey]
            connector.Destroy()
            del self.orbitConnectors[itemKey]

    def AddFighter(self, fighterID):
        if fighterID in self.items:
            return
        if self.shipFighterState is None:
            self.shipFighterState = GetShipFighterState()
            self.shipFighterState.ConnectFighterTargetUpdatedHandler(self._OnFighterTargetUpdate)
        self.items.append(fighterID)
        self._RebuildConnectorsForFighter(fighterID)

    def _OnFighterTargetUpdate(self, fighterID, abilitySlotID, targetID):
        self._RebuildConnectorsForFighter(fighterID)

    def _RebuildConnectorsForFighter(self, fighterID):
        if fighterID not in self.abilityTargets:
            self.abilityTargets[fighterID] = {}
        fighterBall = GetBall(fighterID)
        if fighterBall is None:
            return
        targets = self.shipFighterState.GetAbilityTargetsForFighter(fighterID)
        for targetID in self.abilityTargets[fighterID]:
            connector = self.abilityTargets[fighterID][targetID]
            connector.Destroy()

        self.abilityTargets[fighterID] = {}
        for targetID in targets:
            targetBall = GetBall(targetID)
            if targetBall is not None and not (getattr(targetBall, 'released', False) or getattr(targetBall, 'explodeOnRemove', False)):
                connector = tacticalui.CreateAgressionConnector(fighterBall, targetBall)
                self.abilityTargets[fighterID][targetID] = connector

        self._UpdateItem(fighterID)

    def RemoveFighter(self, fighterID):
        self.items.remove(fighterID)
        self._ClearUIForItem(fighterID)

    def RemoveBall(self, ballID):
        rebuildFighters = []
        for fighterID in self.abilityTargets:
            if ballID in self.abilityTargets[fighterID]:
                rebuildFighters.append(fighterID)

        for fighterID in rebuildFighters:
            self._RebuildConnectorsForFighter(fighterID)

    def _GetMode(self, ball):
        mode = None
        if ball.mode == destiny.DSTBALL_GOTO:
            mode = destiny.DSTBALL_GOTO
        elif ball.mode == destiny.DSTBALL_ORBIT:
            mode = ball.mode
        elif ball.followId != 0:
            mode = destiny.DSTBALL_FOLLOW
        return mode

    def _UpdateItem(self, itemKey):
        ballID = self._GetBallID(itemKey)
        ball = GetBall(ballID)
        if ball is None:
            self._ClearUIForItem(ballID)
            return
        maxMoveDistance = 0
        if itemKey == self.shipid:
            maxMoveDistance = self.maxMoveDistance
        followBall = None
        mode = self._GetMode(ball)
        if mode == destiny.DSTBALL_FOLLOW or mode == destiny.DSTBALL_ORBIT:
            followBall = GetBall(ball.followId)
            self._RemoveNavPointForBall(itemKey)
        elif mode == destiny.DSTBALL_GOTO:
            globalPosition = (ball.gotoX, ball.gotoY, ball.gotoZ)
            followBall = self._SetNavigationPoint(itemKey, globalPosition).GetNavBall()
            if followBall is None:
                self._RemoveNavPointForBall(itemKey)
        else:
            self._RemoveNavPointForBall(itemKey)
        if followBall is None:
            self._RemoveMovementLine(itemKey)
        elif ballID in self.abilityTargets and followBall.id in self.abilityTargets[ballID]:
            self._RemoveMovementLine(itemKey)
        elif mode == destiny.DSTBALL_ORBIT:
            self._RemoveMovementLine(itemKey)
        else:
            self._AddMovementLine(itemKey, ball, followBall, maxMoveDistance)
        if mode == destiny.DSTBALL_ORBIT and followBall:
            self._SetOrbitLine(itemKey, ball, followBall)
        else:
            self._RemoveOrbit(itemKey)

    def _UpdateThread(self):
        while self._updateThreadRunning:
            for each in self.items:
                self._UpdateItem(each)

            blue.synchro.SleepSim(500)
Exemplo n.º 21
0
class SquadronsUI(ContainerAutoSize):
    default_width = SQUADRON_WIDTH
    default_height = 266

    def ApplyAttributes(self, attributes):
        ContainerAutoSize.ApplyAttributes(self, attributes)
        self.shipFighterState = GetShipFighterState()
        self.parentFunc = attributes.parentFunc
        self.squadrons = []
        self.lastSelected = None
        left = BUTTONCONT_WIDTH + 4
        numOfTubes = GetFighterTubesForShip()
        self.DrawControlButtons()
        for i, tubeFlagID in enumerate(const.fighterTubeFlags):
            if i < numOfTubes:
                squadron = SquadronUI(parent=self,
                                      align=uiconst.BOTTOMLEFT,
                                      tubeFlagID=tubeFlagID,
                                      left=left)
                left = squadron.left + squadron.width + 6
                self.squadrons.append(squadron)
                self.width += SQUADRON_WIDTH

    def DrawControlButtons(self):
        buttonCont = Container(parent=self,
                               align=uiconst.BOTTOMLEFT,
                               width=BUTTONCONT_WIDTH,
                               height=120)
        self.fighterToggleBtn = FighterDragButton(
            name='fighterToggleBtn',
            parent=buttonCont,
            align=uiconst.BOTTOMLEFT,
            top=0,
            left=2,
            iconSize=24,
            texturePath=
            'res:/UI/Texture/classes/ShipUI/Fighters/positionFighters_Up.png',
            downTexture=
            'res:/UI/Texture/classes/ShipUI/Fighters/positionFighters_Down.png',
            hoverTexture=
            'res:/UI/Texture/classes/ShipUI/Fighters/positionFighters_Over.png',
            func=self.OnToggleFightersDetached)
        self.recallAll = FightersButtonRecallAll(parent=buttonCont,
                                                 align=uiconst.BOTTOMLEFT,
                                                 top=25)
        self.openFighterBay = self.GetFighterBayBtn(buttonCont)
        self.launchAll = FightersButtonLaunchAll(parent=buttonCont,
                                                 align=uiconst.BOTTOMLEFT,
                                                 top=25 + HUDBUTTON_HEIGHT * 2)

    def GetFighterBayBtn(self, buttonCont):
        if session.structureid:
            return FightersButtonOpenStructureBay(parent=buttonCont,
                                                  align=uiconst.BOTTOMLEFT,
                                                  top=25 + HUDBUTTON_HEIGHT)
        else:
            return FightersButtonOpenBay(parent=buttonCont,
                                         align=uiconst.BOTTOMLEFT,
                                         top=25 + HUDBUTTON_HEIGHT)

    def OnToggleFightersDetached(self, *args):
        self.parentFunc(args)
        self.KeepSelection()

    def KeepSelection(self):
        selectedFighters = movementFunctions.GetFightersSelectedForNavigation()
        for fighterID in selectedFighters:
            movementFunctions.SelectForNavigation(fighterID)

    def SelectAll(self):
        for squadron in self.squadrons:
            squadron.SelectSquadron()

    def ClearSelection(self):
        for squadron in self.squadrons:
            squadron.DeselectSquadron()

    def GetSelectedSquadrons(self):
        selectedSquadrons = []
        for squadron in self.squadrons:
            if squadron.IsSelected():
                selectedSquadrons.append(
                    SelectedFighterTuple(
                        fighterItemID=squadron.GetFighterItemID(),
                        tubeFlagID=squadron.tubeFlagID,
                        squadron=squadron))

        return selectedSquadrons

    def OnF(self, abilitySlotID):
        untargetedAbilityFighters = []
        itemTargetedAbilityFighters = []
        pointTargetedAbilityFighters = []
        isAllAbilitiesActive = self.shipFighterState.IsAllAbilitiesInSlotActiveOrInCooldown(
            abilitySlotID)
        for squadron in self.GetSelectedSquadrons():
            try:
                ability = squadron.squadron.modulesCont.abilityIcons[
                    abilitySlotID]
            except KeyError:
                continue

            abilityActivationStatus = self.shipFighterState.GetAbilityActivationStatus(
                squadron.fighterItemID, abilitySlotID)
            if isAllAbilitiesActive:
                if abilityActivationStatus:
                    if abilityActivationStatus.isPending:
                        continue
                    if abilityActivationStatus.isDeactivating:
                        continue
            else:
                if abilityActivationStatus:
                    continue
                if self.shipFighterState.GetAbilityCooldown(
                        squadron.fighterItemID, abilitySlotID):
                    continue
            if ability.targetMode == TARGET_MODE_UNTARGETED:
                untargetedAbilityFighters.append(squadron.fighterItemID)
            elif ability.targetMode == TARGET_MODE_ITEMTARGETED:
                itemTargetedAbilityFighters.append(squadron.fighterItemID)
            elif ability.targetMode == TARGET_MODE_POINTTARGETED:
                pointTargetedAbilityFighters.append(squadron.fighterItemID)

        fightersSvc = sm.GetService('fighters')
        if isAllAbilitiesActive:
            fighterIDs = untargetedAbilityFighters + itemTargetedAbilityFighters + pointTargetedAbilityFighters
            fightersSvc.DeactivateAbilitySlots(fighterIDs, abilitySlotID)
        else:
            if untargetedAbilityFighters:
                fightersSvc.ActivateAbilitySlotsOnSelf(
                    untargetedAbilityFighters, abilitySlotID)
            if itemTargetedAbilityFighters:
                targetID = sm.GetService('target').GetActiveTargetID()
                fightersSvc.ActivateAbilitySlotsOnTarget(
                    itemTargetedAbilityFighters, abilitySlotID, targetID)
            if pointTargetedAbilityFighters:
                eveCommands = sm.GetService('cmd')
                eveCommands.CmdAimMultiSquadronFighterAbilities(
                    pointTargetedAbilityFighters, abilitySlotID)

    def SetLastSelectedTube(self, tubeFlagID):
        self.lastSelected = tubeFlagID

    def GetLastSelectedTube(self):
        return self.lastSelected

    def MultiSelectSquadrons(self, selectedSquadron):
        if selectedSquadron <= self.lastSelected:
            minSelected = selectedSquadron
            maxSelected = self.lastSelected
        else:
            minSelected = self.lastSelected
            maxSelected = selectedSquadron
        for squadron in self.squadrons:
            if squadron.tubeFlagID >= minSelected and squadron.tubeFlagID <= maxSelected:
                squadron.SelectSquadron()
Exemplo n.º 22
0
class AbilityIcon(Container):
    default_width = 48
    default_height = 48
    default_align = uiconst.TOPLEFT
    default_state = uiconst.UI_NORMAL
    tooltipPanelClassInfo = SquadronTooltipModuleWrapper()

    def ApplyAttributes(self, attributes):
        Container.ApplyAttributes(self, attributes)
        self.activeCurve = None
        self.activationPendingCurve = None
        self.deactivationCurve = None
        self.ramp_active = False
        self.buttonDisabled = False
        self.shipFighterState = GetShipFighterState()
        self.crimewatchSvc = sm.GetService('crimewatchSvc')
        self.innerCont = Container(name='innerCont',
                                   parent=self,
                                   align=uiconst.TOBOTTOM,
                                   height=self.height)
        self.stateLabel = EveLabelSmall(parent=self.innerCont,
                                        align=uiconst.CENTER)
        self.controller = attributes.controller
        self.slotID = self.controller.slotID
        self.fighterID = attributes.fighterID
        self.fighterTypeID = attributes.fighterTypeID
        ability = self.GetAbilityInfo()
        self.abilityNameID = ability.displayNameID
        iconID = ability.iconID
        self.abilityIcon = Icon(parent=self.innerCont,
                                align=uiconst.CENTER,
                                width=32,
                                height=32,
                                icon=iconID,
                                state=uiconst.UI_DISABLED)
        self.hilite = Sprite(
            parent=self.innerCont,
            name='hilite',
            width=44,
            height=44,
            align=uiconst.CENTER,
            state=uiconst.UI_DISABLED,
            texturePath='res:/UI/Texture/classes/ShipUI/slotHilite.png',
            blendMode=trinity.TR2_SBM_ADDX2)
        self.hilite.display = False
        bgSprite = Sprite(
            parent=self.innerCont,
            align=uiconst.CENTER,
            width=64,
            height=64,
            texturePath=
            'res:/UI/Texture/classes/ShipUI/Fighters/slotFighterAbility.png',
            state=uiconst.UI_DISABLED)
        self.abilityIcon.SetSize(32, 32)
        self.DrawQtyCont()
        self.DrawTimer()
        self.DrawCoolDownTimer()
        self.DrawSafetyGlow()
        self.targetMode = ability.targetMode
        abilityID = GetAbilityIDForSlot(self.fighterTypeID, self.slotID)
        effectID = GetDogmaEffectIDForAbilityID(abilityID)
        self.abilityEffect = cfg.dgmeffects.Get(effectID)
        self.OnAbilityStatusUpdated(self.fighterID, self.slotID)
        self.shipFighterState.signalOnAbilityActivationStatusUpdate.connect(
            self.OnAbilityStatusUpdated)

    def GetSafetyWarning(self):
        requiredSafetyLevel = self.GetRequiredSafetyLevel()
        if self.crimewatchSvc.CheckUnsafe(requiredSafetyLevel):
            return requiredSafetyLevel
        else:
            return None

    def GetRequiredSafetyLevel(self):
        requiredSafetyLevel = self.crimewatchSvc.GetRequiredSafetyLevelForEffect(
            self.abilityEffect)
        return requiredSafetyLevel

    def OnMouseEnter(self, *args):
        self.hilite.display = True
        requiredSafetyLevel = self.GetSafetyWarning()
        if requiredSafetyLevel is not None:
            if requiredSafetyLevel == const.shipSafetyLevelNone:
                color = crimewatchConst.Colors.Criminal
            else:
                color = crimewatchConst.Colors.Suspect
            self.safetyGlow.color.SetRGBA(*color.GetRGBA())
            self.safetyGlow.display = True

    def OnMouseExit(self, *args):
        self.hilite.display = False
        self.safetyGlow.display = False

    def DrawSafetyGlow(self):
        self.safetyGlow = Sprite(
            parent=self.innerCont,
            name='safetyGlow',
            width=64,
            height=64,
            padding=2,
            align=uiconst.CENTER,
            state=uiconst.UI_DISABLED,
            texturePath='res:/UI/Texture/classes/ShipUI/slotGlow.png',
            color=crimewatchConst.Colors.Yellow.GetRGBA())
        self.safetyGlow.display = False

    def DrawTimer(self):
        self.glow = Sprite(
            parent=self.innerCont,
            name='glow',
            width=64,
            height=64,
            padding=2,
            align=uiconst.CENTER,
            state=uiconst.UI_DISABLED,
            texturePath='res:/UI/Texture/classes/ShipUI/slotGlow.png',
            color=GLOWCOLOR)
        self.glow.display = False
        self.busy = Sprite(
            parent=self.innerCont,
            name='busy',
            width=64,
            height=64,
            padding=2,
            align=uiconst.CENTER,
            state=uiconst.UI_DISABLED,
            texturePath='res:/UI/Texture/classes/ShipUI/slotGlow.png',
            color=BUSYCOLOR)
        self.busy.display = False
        self.ramps = ShipModuleButtonRamps(parent=self.innerCont,
                                           idx=0,
                                           top=-8)
        self.ramps.display = False

    def DrawCoolDownTimer(self):
        self.coolDownRamps = ShipModuleReactivationTimer(parent=self.innerCont,
                                                         name='coolDown',
                                                         idx=-1)
        self.coolDownRamps.display = False

    def DrawQtyCont(self):
        self.quantityParent = Container(parent=self.innerCont,
                                        name='quantityParent',
                                        pos=(16, 6, 24, 10),
                                        align=uiconst.BOTTOMRIGHT,
                                        state=uiconst.UI_DISABLED,
                                        idx=0)
        self.chargeCountLabel = Label(text='',
                                      parent=self.quantityParent,
                                      fontsize=9,
                                      letterspace=1,
                                      left=3,
                                      width=30,
                                      state=uiconst.UI_DISABLED)
        underlay = Sprite(
            parent=self.quantityParent,
            align=uiconst.TOALL,
            state=uiconst.UI_DISABLED,
            texturePath=
            'res:/UI/Texture/classes/ShipUI/slotQuantityUnderlay.png',
            color=(0, 0, 0, 1))

    def GetAbilityInfo(self):
        ability = self.controller.GetAbilityInfo()
        return ability

    def OnAbilityStatusUpdated(self, fighterID, slotID):
        if fighterID == self.fighterID and slotID == self.slotID:
            abilityActivationStatus = self.shipFighterState.GetAbilityActivationStatus(
                self.fighterID, self.slotID)
            if abilityActivationStatus:
                if abilityActivationStatus.isPending:
                    self._StartActivationPendingAnimation()
                else:
                    self._StopActivationPendingAnimation()
                if abilityActivationStatus.isDeactivating:
                    self._StartDeactivationAnimation()
                else:
                    self._StopDeactivationAnimation()
                if not abilityActivationStatus.isPending and not abilityActivationStatus.isDeactivating:
                    self._StartActiveAnimation()
                    self.buttonDisabled = False
                else:
                    self._StopActiveAnimation()
                    self.buttonDisabled = True
                if abilityActivationStatus.startTime and abilityActivationStatus.durationMs:
                    self._StartCycleAnimation(
                        abilityActivationStatus.startTime,
                        abilityActivationStatus.durationMs)
                else:
                    self._StopCycleAnimation()
            else:
                self._StopActivationPendingAnimation()
                self._StopDeactivationAnimation()
                self._StopActiveAnimation()
                self._StopCycleAnimation()
                cooldown = self.shipFighterState.GetAbilityCooldown(
                    self.fighterID, self.slotID)
                if cooldown is not None:
                    self.buttonDisabled = True
                    uthread.new(self._StartCoolDownAnimation, cooldown)
                else:
                    self.buttonDisabled = False
            self._UpdateChargeCountLabel()

    def _UpdateChargeCountLabel(self):
        maxChargeCount = GetChargeCountForTypeAndSlot(self.fighterTypeID,
                                                      self.slotID)
        if maxChargeCount is not None:
            currentChargeCount = self.shipFighterState.GetAbilityChargeCount(
                self.fighterID, self.slotID)
            self.quantityParent.Show()
            self.chargeCountLabel.SetText(currentChargeCount)
        else:
            self.quantityParent.Hide()

    def _StartCycleAnimation(self, startTime, durationMs):
        if self.ramp_active:
            return
        uthread.new(self._StartCycleAnimationThread, startTime, durationMs)

    def _StartCycleAnimationThread(self, startTime, durationMs):
        duration = durationMs * MSEC
        self.ramp_active = True
        self.ramps.display = True
        self.coolDownRamps.display = False
        while self.ramp_active:
            now = blue.os.GetSimTime()
            portionDone = (now - startTime) / duration
            if portionDone > 1:
                iterations = int(portionDone)
                startTime += long(duration * iterations)
                portionDone -= iterations
            self.ramps.SetRampValues(portionDone)
            blue.pyos.synchro.Yield()

    def _StopCycleAnimation(self):
        self.ramp_active = False
        self.ramps.display = False

    def _StartCoolDownAnimation(self, cooldown):
        self.coolDownRamps.display = True
        startTime, endTime = cooldown
        coolDownTime = int(endTime - startTime)
        self.coolDownRamps.AnimateTimer(startTime, coolDownTime)
        if endTime <= blue.os.GetSimTime():
            self.coolDownRamps.display = False
            self.buttonDisabled = False

    def _StartActiveAnimation(self):
        self.glow.display = True
        self.activeCurve = animations.FadeTo(self.glow,
                                             loops=uiconst.ANIM_REPEAT,
                                             curveType=uiconst.ANIM_WAVE)
        animations.SyncPlayback(self.activeCurve)

    def _StopActiveAnimation(self):
        self.glow.display = False
        if self.activeCurve:
            self.activeCurve.Stop()
            self.activeCurve = None

    def _StartActivationPendingAnimation(self):
        self.activationPendingCurve = animations.FadeTo(
            self.abilityIcon,
            loops=uiconst.ANIM_REPEAT,
            curveType=uiconst.ANIM_WAVE)
        animations.SyncPlayback(self.activationPendingCurve)

    def _StopActivationPendingAnimation(self):
        if self.activationPendingCurve:
            self.activationPendingCurve.Stop()
            self.activationPendingCurve = None
        animations.FadeIn(self.abilityIcon)

    def _StartDeactivationAnimation(self):
        self.busy.display = True
        self.deactivationCurve = animations.FadeTo(self.busy,
                                                   loops=uiconst.ANIM_REPEAT,
                                                   curveType=uiconst.ANIM_WAVE)
        animations.SyncPlayback(self.deactivationCurve)

    def _StopDeactivationAnimation(self):
        self.busy.display = False
        if self.deactivationCurve:
            self.deactivationCurve.Stop()
            self.deactivationCurve = None

    def OnClick(self, *args):
        if self.buttonDisabled:
            return
        self.controller.OnAbilityClick(self.targetMode)

    def Close(self):
        self._StopActiveAnimation()
        self._StopActivationPendingAnimation()
        self._StopDeactivationAnimation()
        self.shipFighterState.signalOnAbilityActivationStatusUpdate.disconnect(
            self.OnAbilityStatusUpdated)
        super(AbilityIcon, self).Close()

    def OnMouseDown(self, *args):
        if self.buttonDisabled:
            return
        self.innerCont.top = 2

    def OnMouseUp(self, *args):
        if self.buttonDisabled:
            return
        self.innerCont.top = 0
Exemplo n.º 23
0
 def __init__(self, abilityID, fighterID, slotID, fighterTypeID):
     self.abilityID = abilityID
     self.fighterID = fighterID
     self.slotID = slotID
     self.fighterTypeID = fighterTypeID
     self.shipFighterState = GetShipFighterState()
Exemplo n.º 24
0
 def ApplyAttributes(self, attributes):
     Container.ApplyAttributes(self, attributes)
     sm.RegisterNotify(self)
     self.squadronMgmtController = SquadronMgmtController()
     self.inSpace = False
     self.shipFighterState = GetShipFighterState()
     self.tubeFlagID = attributes.tubeFlagID
     fighters = self.GetFightersState()
     if fighters:
         fighterID = fighters.itemID
         fighterTypeID = fighters.typeID
         squadronSize = fighters.squadronSize
     else:
         fighterID = None
         fighterTypeID = None
         squadronSize = None
     self.fighterID = fighterID
     self.fighterTypeID = fighterTypeID
     self.controller = SquadronController()
     self.squadronCont = SquadronCont(parent=self,
                                      controller=self.controller,
                                      align=uiconst.BOTTOMLEFT,
                                      tubeFlagID=self.tubeFlagID,
                                      state=uiconst.UI_NORMAL)
     self.squadronCont.OnClick = self.OnSquadronClick
     self.squadronCont.GetMenu = self.GetSquadronMenu
     self.squadronCont.SetNewSquadron(fighterID, fighterTypeID,
                                      squadronSize)
     self.squadronContEmpty = SquadronContEmpty(parent=self,
                                                controller=self.controller,
                                                fighterID=fighterID,
                                                fighterTypeID=fighterTypeID,
                                                align=uiconst.BOTTOMLEFT,
                                                tubeFlagID=self.tubeFlagID)
     self.squadronContEmpty.GetMenu = self.GetSquadronMenu
     if not fighterID and not fighterTypeID:
         self.ShowEmpty()
     else:
         self.HideEmpty()
     self.effectsCont = EffectsCont(parent=self,
                                    controller=self.controller,
                                    fighterID=fighterID,
                                    fighterTypeID=fighterTypeID,
                                    tubeFlagID=self.tubeFlagID,
                                    top=self.squadronCont.height,
                                    align=uiconst.BOTTOMLEFT)
     self.modulesCont = AbilitiesCont(parent=self,
                                      left=20,
                                      top=self.squadronCont.height,
                                      align=uiconst.BOTTOMLEFT)
     self.modulesCont.SetNewSquadron(fighterID, fighterTypeID)
     self.SetupFighters()
     self.shipFighterState.signalOnFighterTubeStateUpdate.connect(
         self.OnFighterTubeStateUpdate)
     self.shipFighterState.signalOnFighterTubeContentUpdate.connect(
         self.OnFighterTubeContentUpdate)
     self.shipFighterState.signalOnFighterInSpaceUpdate.connect(
         self.OnFighterInSpaceUpdate)
     self.shipFighterState.signalOnIncomingEwarStarted.connect(
         self.OnEwarUpdated)
     self.shipFighterState.signalOnIncomingEwarEnded.connect(
         self.OnEwarUpdated)
Exemplo n.º 25
0
class FightersHealthGauge(Container):
    default_height = 86
    default_width = 86
    default_align = uiconst.TOPLEFT
    default_state = uiconst.UI_PICKCHILDREN
    isDragObject = True

    def ApplyAttributes(self, attributes):
        Container.ApplyAttributes(self, attributes)
        self.shipFighterState = GetShipFighterState()
        self.typeID = None
        self.squadronSize = None
        self.squadronMaxSize = None
        self.noHealthyFighters = 0
        self.squadronState = attributes.get('state', None)
        self.tubeFlagID = attributes.get('tubeFlagID', None)
        dashColors = self.GetDashColors()
        self.classIcon = Sprite(name='classIcon',
                                parent=self,
                                align=uiconst.CENTERBOTTOM,
                                width=16,
                                height=16,
                                top=18)
        self.classIcon.OnMouseEnter = self.OnMouseEnter
        self.classIcon.OnMouseExit = self.OnMouseExit
        self.classIcon.GetDragData = self.GetDragData
        self.fightersGauge = FighterHealthGaugeLine(parent=self,
                                                    dashColors=dashColors,
                                                    align=uiconst.CENTER)
        Sprite(
            parent=self,
            align=uiconst.CENTER,
            width=86,
            height=86,
            texturePath=
            'res:/UI/Texture/classes/ShipUI/Fighters/fighterItemOverlay.png',
            state=uiconst.UI_DISABLED)
        self.fighterIcon = Icon(
            parent=self,
            align=uiconst.CENTER,
            width=52,
            height=52,
            state=uiconst.UI_DISABLED,
            blendMode=1,
            textureSecondaryPath=
            'res:/UI/Texture/classes/ShipUI/Fighters/fighterItemMask.png',
            spriteEffect=trinity.TR2_SFX_MODULATE)
        Sprite(
            parent=self,
            align=uiconst.CENTER,
            width=86,
            height=86,
            texturePath=
            'res:/UI/Texture/classes/ShipUI/Fighters/fighterItemUnderlay.png',
            state=uiconst.UI_DISABLED)
        self.hilite = Sprite(
            parent=self,
            name='hilite',
            width=86,
            height=86,
            align=uiconst.CENTER,
            state=uiconst.UI_DISABLED,
            texturePath=
            'res:/UI/Texture/classes/ShipUI/Fighters/fighterItemUnderlayOver.png'
        )
        self.hilite.display = False

    def LoadFighterToSquadron(self, typeID):
        if typeID == self.typeID:
            return
        self.typeID = typeID
        self.fighterIcon.LoadIconByTypeID(typeID=typeID)
        self.squadronMaxSize = GetMaxSquadronSize(self.typeID)
        roleTexturePath = GetSquadronRoleResPath(self.typeID)
        self.classIcon.LoadTexture(roleTexturePath)
        hintString = HINTTEXT_BY_ROLE[GetSquadronRole(self.typeID)]
        self.classIcon.hint = GetByLabel(hintString)
        self.UpdateHint()

    def ClearFighters(self):
        self.fightersGauge.ClearFighters()

    def UpdateHint(self, damage=None):
        typeName = evetypes.GetName(self.typeID)
        if self.tubeFlagID is not None:
            tubeStatus = self.shipFighterState.GetTubeStatus(self.tubeFlagID)
            if tubeStatus.statusID not in TUBE_STATES_INSPACE:
                damage = None
        if damage and damage < 0.99:
            damageNumber = round((1.0 - damage) * 100)
            hintText = GetByLabel(
                'UI/Inventory/Fighters/SquadronHintWithDamage',
                typeName=typeName,
                numFighters=int(self.noHealthyFighters),
                damagePercentage=damageNumber)
        else:
            hintText = GetByLabel('UI/Inventory/Fighters/SquadronHint',
                                  typeName=typeName,
                                  numFighters=int(self.noHealthyFighters))
        self.hint = hintText

    def SetSquadronSize(self, squadronSize):
        self.squadronSize = squadronSize
        self.UpdateFighters()

    def GetDashColors(self, damage=None):
        self.noHealthyFighters = 0
        dashColors = []
        if self.tubeFlagID is not None:
            tubeStatus = self.shipFighterState.GetTubeStatus(self.tubeFlagID)
            if tubeStatus.statusID not in TUBE_STATES_INSPACE:
                damage = None
        if not self.typeID:
            return dashColors
        for i in xrange(1, self.squadronMaxSize + 1):
            if i <= self.squadronSize:
                self.noHealthyFighters += 1
                dashColor = self.GetHealthyFighterColor()
                if damage and damage < 0.99:
                    if i == self.squadronSize:
                        dashColor = DAMAGED_FIGHTER
                        self.noHealthyFighters -= 1
            else:
                dashColor = DEAD_FIGHTER
            dashColors.append(dashColor)

        return dashColors

    def GetHealthyFighterColor(self):
        if self.tubeFlagID is None:
            return HEALTHY_FIGHTER_SPACE
        else:
            tubeStatus = self.shipFighterState.GetTubeStatus(self.tubeFlagID)
            if tubeStatus.statusID in TUBE_STATES_INSPACE:
                return HEALTHY_FIGHTER_SPACE
            return HEALTHY_FIGHTER_TUBE

    def GetDragData(self):
        if self.squadronState is not None:
            squadronData = util.KeyVal()
            squadronData.tubeFlagID = self.tubeFlagID
            squadronData.squadronState = self.squadronState
            squadronData.typeID = self.typeID
            squadronData.__guid__ = 'uicls.FightersHealthGauge'
            return [squadronData]
        else:
            return []

    def UpdateFighters(self, damage=None):
        if not self.typeID:
            return
        dashColors = self.GetDashColors(damage)
        self.fightersGauge.UpdateFighterColors(dashColors)
        self.UpdateHint(damage)

    def LoadBySlimItem(self, slimItem):
        self.LoadFighterToSquadron(slimItem.typeID)
        squadronSize = GetSquadronSizeFromSlimItem(slimItem)
        self.SetSquadronSize(squadronSize)
        self.UpdateFighters()

    def OnMouseEnter(self, *args):
        self.hilite.display = True

    def OnMouseExit(self, *args):
        self.hilite.display = False