class DefenseCannonGUI(CannonGUI):
    notify = DirectNotifyGlobal.directNotify.newCategory('DefenseCannonGUI')
    
    def __init__(self, cannon):
        CannonGUI.__init__(self, cannon)
        self.exitEvent = None
        self._DefenseCannonGUI__dialog = None
        self.helpButton = None
        self.helpUI = None
        self.flashHelp = None
        self.ammoFade = None
        self._DefenseCannonGUI__ammoCountersHidden = False
        self.setupExtraButtons()
        self.exitCannon['command'] = self.showExitDialog
        self.volleyLabel.setPos(-0.28000000000000003, 0, 0.089999999999999997)
        self.reloadBar.setPos(-0.13, 0, 0.080000000000000002)
        self.ammoImage.setPos(-0.38, 0, 0.059999999999999998)
        self.repMeter = ReputationMeter(InventoryType.DefenseCannonRep, width = 0.69999999999999996)
        self.repMeter.reparentTo(base.a2dBottomCenter)
        self.repMeter.setPos(0.0, 0.0, 0.025000000000000001)
        self.hud = CannonDefenseHUD()
        self.hud.create()
        self._exp = 0
        self.lastLevel = 1
        self.accept('incDefenseCannonExp', self.increaseExp)
        if __dev__:
            base.dcg = self
        

    
    def destroy(self):
        if self.ammoFade:
            self.ammoFade.finish()
            self.ammoFade = None
        
        if self.flashHelp:
            self.flashHelp.finish()
            self.flashHelp = None
        
        if self.helpButton:
            self.helpButton.destroy()
            self.helpButton = None
        
        if self.helpUI:
            self.helpUI.destroy()
            self.helpUI = None
        
        if self.hud:
            self.hud.destroy()
            self.hud = None
        
        base.musicMgr.requestFadeOut(SoundGlobals.MUSIC_MINIGAME_CANNON)
        self.repMeter.destroy()
        self.ignore('incDefenseCannonExp')
        CannonGUI.destroy(self)

    
    def setupExtraButtons(self):
        weaponIcons = loader.loadModel('models/gui/gui_icons_weapon')
        self.helpButton = DirectButton(parent = base.a2dBottomRight, relief = None, pos = (-0.59999999999999998, 0, 0.089999999999999997), scale = 0.5, text = '?', text_pos = (0, -0.055), text_scale = 0.20999999999999999, text_fg = PiratesGuiGlobals.TextFG2, text_shadow = PiratesGuiGlobals.TextShadow, text_font = PiratesGlobals.getPirateBoldOutlineFont(), sortOrder = 2, command = self.toggleHelpUI)
        DirectLabel(parent = self.helpButton, text = PLocalizer.CannonDefense['Help'], text_pos = (0, -0.14999999999999999), text_scale = 0.080000000000000002, text_fg = PiratesGuiGlobals.TextFG2, text_shadow = PiratesGuiGlobals.TextShadow, text_font = PiratesGlobals.getPirateBoldOutlineFont(), frameColor = (1, 1, 1, 0))

    
    def increaseExp(self, amt, total):
        self._exp += amt
        if self._exp > total:
            return None
        
        (level, leftoverValue) = ReputationGlobals.getLevelFromTotalReputation(InventoryType.DefenseCannonRep, self._exp)
        self.repMeter.update(self._exp)
        if level > self.lastLevel:
            base.localAvatar.levelUpMsg(InventoryType.DefenseCannonRep, level, 0)
            self.lastLevel = level
        

    
    def toggleHelpUI(self):
        if self.helpUI == None:
            self._DefenseCannonGUI__createHelpUI()
            self.fadeOutAmmoCounters()
            if self.cannon.ammoPanel.state == pirates.minigame.AmmoPanel.CLOSED:
                self.cannon.ammoPanel.onTabClick()
            
        else:
            self._DefenseCannonGUI__destroyHelpUI()
            self.fadeInAmmoCounters()
            if self.cannon.ammoPanel.state == pirates.minigame.AmmoPanel.OPENED:
                self.cannon.ammoPanel.onTabClick()
            

    
    def _DefenseCannonGUI__createHelpUI(self):
        self.helpUI = CannonDefenseHelpManager(0.5)
        self.helpUI.exit.reparentTo(self.exitCannon)
        self.helpUI.exit.setScale(2.0)
        self.helpUI.help.reparentTo(self.helpButton)
        self.helpUI.help.setScale(2.0)
        self.helpUI.ammoPanel.reparentTo(self.cannon.ammoPanel.panel)
        self.helpUI.ammoPanel.setScale(1.0 / 3.0)
        self.helpUI.ammo.reparentTo(base.a2dBottomCenter)
        self.helpUI.mine.reparentTo(self.hud.goldRemainingUI.mineCounter)
        self.helpUI.mine.setScale(2.0 / 3.0)
        self.helpUI.wave.reparentTo(self.hud.timeRemainingUI.timeRemaining)
        self.helpUI.wave.setScale(1.0 / 0.75)
        self.helpUI.fadeIn.start()

    
    def _DefenseCannonGUI__destroyHelpUI(self):
        cleanup = Sequence(Func(self.helpUI.fadeIn.pause), self.helpUI.fadeOut, Func(self.helpUI.destroy), name = self.cannon.uniqueName('HelpUI_FadeIn'))
        cleanup.start()
        self.helpUI = None

    
    def isHelpUIVisible(self):
        return self.helpUI != None

    
    def flashHelpButton(self, delay = 0.20000000000000001, length = 5):
        if self.flashHelp:
            self.flashHelp.finish()
            self.flashHelp = None
        
        self.flashHelp = Sequence(name = self.cannon.uniqueName('HelpButton_Flash'))
        
        def setColor(key, value):
            self.helpButton[key] = value

        for i in range(0, length):
            self.flashHelp.append(Wait(delay))
            self.flashHelp.append(Func(setColor, 'text_fg', PiratesGuiGlobals.TextFG19))
            self.flashHelp.append(Wait(delay))
            self.flashHelp.append(Func(setColor, 'text_fg', PiratesGuiGlobals.TextFG2))
        
        self.flashHelp.start()

    
    def fadeOutAmmoCounters(self, length = 0.5):
        if self._DefenseCannonGUI__ammoCountersHidden:
            return None
        
        transparent = Vec4(1, 1, 1, 0)
        if self.ammoFade:
            self.ammoFade.finish()
        
        self.ammoFade = Parallel(self.volleyLabel.colorScaleInterval(length, transparent), self.reloadBar.colorScaleInterval(length, transparent), self.ammoImage.colorScaleInterval(length, transparent))
        self.ammoFade.start()
        self._DefenseCannonGUI__ammoCountersHidden = True

    
    def fadeInAmmoCounters(self, length = 0.5):
        if self._DefenseCannonGUI__ammoCountersHidden == False:
            return None
        
        opaque = Vec4(1, 1, 1, 1)
        transparent = Vec4(1, 1, 1, 0)
        if self.ammoFade:
            self.ammoFade.finish()
        
        self.ammoFade = Parallel(self.volleyLabel.colorScaleInterval(length, opaque, transparent), self.reloadBar.colorScaleInterval(length, opaque, transparent), self.ammoImage.colorScaleInterval(length, opaque, transparent))
        self.ammoFade.start()
        self._DefenseCannonGUI__ammoCountersHidden = False

    
    def showExitDialog(self):
        if self._DefenseCannonGUI__dialog == None:
            self._DefenseCannonGUI__dialog = PDialog(text = PLocalizer.CannonDefense['ExitCannon'], style = OTPDialog.YesNo, giveMouse = False, command = self._DefenseCannonGUI__onDialogItemSelected)
        else:
            self._DefenseCannonGUI__dialog.cleanup()
            self._DefenseCannonGUI__dialog = None

    
    def _DefenseCannonGUI__onDialogItemSelected(self, value):
        if value == 1:
            if self.exitEvent:
                self.exitEvent()
            
        
        self._DefenseCannonGUI__dialog.cleanup()
        self._DefenseCannonGUI__dialog = None
class DistributedFishingSpot(DistributedInteractive.DistributedInteractive, Lootable):
    notify = DirectNotifyGlobal.directNotify.newCategory('DistributedFishingSpot')
    
    def __init__(self, cr):
        DistributedInteractive.DistributedInteractive.__init__(self, cr)
        Lootable.__init__(self)
        self.index = -1
        self.onABoat = False
        self.fadeTime = 0.5
        self.loadingSequence = None
        self.fishingGame = None
        self.xpBonus = 0
        self.goldBonus = 0
        self.showTutorial = False
        self._DistributedFishingSpot__dialog = None
        self.prevBaseCamParent = None
        self.prevCamPos = None
        self.prevCamHpr = None
        self.oldAvatarPos = None

    
    def generate(self):
        DistributedInteractive.DistributedInteractive.generate(self)
        NodePath.__init__(self, 'DistributedFishingSpot')
        self.setInteractOptions(proximityText = PLocalizer.InteractFishingSpot, sphereScale = 8, diskRadius = 8)
        self.setAllowInteract(True)

    
    def announceGenerate(self):
        DistributedInteractive.DistributedInteractive.announceGenerate(self)
        if self.getOnABoat() and self.getParentObj():
            self.getParentObj().registerFishingSpot(self)
        

    
    def setXpBonus(self, xpBonusAmount):
        self.xpBonus = xpBonusAmount
        if self.fishingGame:
            self.fishingGame.updateResultsScreen()
        

    
    def getXpBonus(self):
        return self.xpBonus

    
    def setGoldBonus(self, goldBonusAmount):
        self.goldBonus = goldBonusAmount
        if self.fishingGame:
            self.fishingGame.updateResultsScreen()
        

    
    def getGoldBonus(self):
        return self.goldBonus

    
    def setOnABoat(self, onABoat):
        self.onABoat = onABoat

    
    def getOnABoat(self):
        return self.onABoat

    
    def setOceanOffset(self, offset):
        self.oceanOffset = offset

    
    def requestInteraction(self, avId, interactType = 0):
        inv = localAvatar.getInventory()
        rodQty = inv.getStackQuantity(InventoryType.FishingRod)
        regLureQty = inv.getStackQuantity(InventoryType.RegularLure)
        legendaryLureQty = inv.getStackQuantity(InventoryType.LegendaryLure)
        if rodQty > 0:
            if regLureQty + legendaryLureQty <= 0:
                localAvatar.guiMgr.createWarning(PLocalizer.FishingNoLuresWarning, PiratesGuiGlobals.TextFG6)
            elif localAvatar.isUndead():
                localAvatar.guiMgr.createWarning(PLocalizer.NoFishingWhileUndeadWarning, PiratesGuiGlobals.TextFG6)
            else:
                localAvatar.motionFSM.off()
                DistributedInteractive.DistributedInteractive.requestInteraction(self, avId, interactType)
        else:
            localAvatar.guiMgr.createWarning(PLocalizer.FishingNoRodWarning, PiratesGuiGlobals.TextFG6)

    
    def rejectInteraction(self):
        localAvatar.motionFSM.on()
        localAvatar.gameFSM.request('LandRoam')
        self.refreshState()
        DistributedInteractive.DistributedInteractive.rejectInteraction(self)

    
    def requestExit(self):
        DistributedInteractive.DistributedInteractive.requestExit(self)
        taskMgr.remove('tryFishingSpotAgain')
        if self.onABoat and self.oldAvatarPos:
            localAvatar.setPos(self.oldAvatarPos)
            self.oldAvatarPos = None
        
        if not localAvatar.gameFSM.isInTransition():
            localAvatar.b_setGameState(localAvatar.gameFSM.defaultState)
        
        self.loadingSequence.pause()
        self.loadingSequence.clearToInitial()
        base.transitions.fadeIn(self.fadeTime)
        if self.fishingGame is not None:
            self.fishingGame.delete()
            self.fishingGame = None
        
        if self.prevBaseCamParent is not None:
            base.cam.reparentTo(self.prevBaseCamParent)
            base.cam.setPos(self.prevCamPos)
            base.cam.setHpr(self.prevCamHpr)
            self.prevBaseCamParent = None
            self.prevCamPos = None
            self.prevCamHpr = None
        
        taskMgr.remove(self.uniqueName('bootFromFishing'))
        localAvatar.motionFSM.on()
        self.setAllowInteract(True)
        base.localAvatar.guiMgr.setIgnoreEscapeHotKey(False)
        self.refreshState()

    
    def checkAndLoadFishingGame(self):
        localAvatar.b_setGameState('Fishing')
        if self.fishingGame is None:
            self.fishingGame = FishingGame(self)
        
        if self.onABoat:
            self.oldAvatarPos = localAvatar.getPos()
            localAvatar.collisionGhost()
            localAvatar.setPos(*FishingGlobals.fishingSpotPosHprBoatInformation[self.index]['pos'])
            localAvatar.setHpr(*FishingGlobals.fishingSpotPosHprBoatInformation[self.index]['hpr'])
            self.setHpr(*FishingGlobals.fishingSpotPosHprBoatInformation[self.index]['fishingSpotHpr'])
            base.cam.reparentTo(self.fishingGame.fishingSpot)
            base.cam.setPos(13.0, -18.0, 7.0)
            base.cam.setHpr(0.0, 0.0, 0.0)
        else:
            par = localAvatar.getParentObj()
            uid = par.getUniqueId()
            if uid == LocationIds.DEL_FUEGO_ISLAND:
                localAvatar.setHpr(50.0, 0.0, 0.0)
            elif localAvatar.onWelcomeWorld:
                localAvatar.setHpr(self.getH(render) - 196.0, 0.0, 0.0)
            else:
                localAvatar.setHpr(self.getH(render) - 16.0, 0.0, 0.0)
            localAvatar.setPos(self, Point3(*FishingGlobals.fishingSpotPosOffset))
            base.cam.reparentTo(self.fishingGame.fishingSpot)
            base.cam.setHpr(0.0, 0.0, 0.0)
        localAvatar.sendCurrentPosition()

    
    def requestPlayerIdleState(self, task = None):
        if base.localAvatar.find('**/fishingRod').isEmpty():
            taskMgr.doMethodLater(0.5, self.requestPlayerIdleState, name = 'tryFishingSpotAgain')
        else:
            self.fishingGame.fsm.request('PlayerIdle')
            self.fishingGame.checkLures()

    
    def enterUse(self):
        DistributedInteractive.DistributedInteractive.enterUse(self)
        self.prevBaseCamParent = base.cam.getParent()
        self.prevCamPos = base.cam.getPos()
        self.prevCamHpr = base.cam.getHpr()
        if not base.transitions.fadeOutActive():
            self.loadingSequence = Sequence(Func(self.fadeOut), Wait(self.fadeTime + 0.10000000000000001), Func(self.checkAndLoadFishingGame), Wait(1.5), Func(self.requestPlayerIdleState), Func(self.fadeIn))
            self.loadingSequence.start()
        else:
            print '--------------------- DistributedFishingSpot : Trouble fading out!'
        taskMgr.doMethodLater(FishingGlobals.idleDuration, self.bootFromFishing, self.uniqueName('bootFromFishing'))
        self.accept('mouse1', self.resetBootCheck)
        self.accept('fishing-skill-used', self.resetBootCheck)
        self.accept('newItemHeld', self.resetBootCheck)
        self.accept('releaseHeld', self.resetBootCheck)
        self.accept('plunderClosed', self.requestPlayerIdle)

    
    def fadeOut(self):
        base.transitions.setFadeColor(0, 0, 0)
        if base.transitions.fadeOutActive():
            return None
        
        base.transitions.fadeOut(self.fadeTime)
        base.localAvatar.guiMgr.inventoryUIManager.hidePlunder()
        base.loadingScreen.showTarget(fishing = True)
        base.cr.loadingScreen.show()

    
    def fadeIn(self):
        base.transitions.fadeIn(self.fadeTime)
        base.musicMgr.request(SoundGlobals.MUSIC_MINIGAME_FISHING, looping = True, priority = 1)
        base.cr.loadingScreen.hide()
        base.localAvatar.guiMgr.inventoryUIManager.showPlunder()

    
    def exitUse(self):
        self.ignoreAll()
        DistributedInteractive.DistributedInteractive.exitUse(self)
        base.musicMgr.requestFadeOut(SoundGlobals.MUSIC_MINIGAME_FISHING)

    
    def firstTimeFisher(self):
        self.showTutorial = True

    
    def spotFilledByAvId(self, avId):
        if avId == 0:
            self.setAllowInteract(True)
            self.showTutorial = False
            return None
        
        if base.localAvatar.doId != avId:
            self.setAllowInteract(False)
        

    
    def delete(self):
        self.ignoreAll()
        taskMgr.remove(self.uniqueName('bootFromFishing'))
        if self.fishingGame is not None:
            self.fishingGame.delete()
            del self.fishingGame
        
        if self.prevBaseCamParent is not None:
            base.cam.reparentTo(self.prevBaseCamParent)
            base.cam.setPos(self.prevCamPos)
            base.cam.setHpr(self.prevCamHpr)
            self.prevBaseCamParent = None
            self.prevCamPos = None
            self.prevCamHpr = None
        
        DistributedInteractive.DistributedInteractive.delete(self)

    
    def b_setIndex(self, index):
        self.index = index
        self.sendUpdate('setIndex', [
            index])

    
    def setIndex(self, index):
        self.index = index

    
    def getIndex(self):
        return self.index

    
    def d_caughtFish(self, fishId, weight):
        self.sendUpdate('caughtFish', [
            fishId,
            weight])

    
    def lostLure(self, lureId):
        pass

    
    def d_lostLure(self, lureId):
        self.sendUpdate('lostLure', [
            lureId])

    
    def handleEndInteractKey(self):
        if self.fishingGame or not self.fishingGame.gui.resultsScreen.isHidden() or localAvatar.guiMgr.inventoryUIManager.hasPlunder():
            return None
        
        if self._DistributedFishingSpot__dialog == None:
            self._DistributedFishingSpot__dialog = PDialog(text = PLocalizer.FishingGui['ExitText'], style = OTPDialog.YesNo, giveMouse = False, command = self._DistributedFishingSpot__onDialogItemSelected)
        else:
            self._DistributedFishingSpot__dialog.cleanup()
            self._DistributedFishingSpot__dialog = None

    
    def _DistributedFishingSpot__onDialogItemSelected(self, value):
        if value == 1:
            self.requestExit()
        
        self._DistributedFishingSpot__dialog.cleanup()
        self._DistributedFishingSpot__dialog = None

    
    def bootFromFishing(self, task = None):
        self.requestExit()

    
    def resetBootCheck(self, arg1 = None, arg2 = None):
        taskMgr.remove(self.uniqueName('bootFromFishing'))
        taskMgr.doMethodLater(FishingGlobals.idleDuration, self.bootFromFishing, self.uniqueName('bootFromFishing'))

    
    def requestPlayerIdle(self, arg1 = None):
        if self.fishingGame.fsm.getCurrentOrNextState() == 'Reward':
            self.fishingGame.fsm.request('PlayerIdle')
        

    
    def startLooting(self, plunderList, itemsToTake = 0, timer = 0, autoShow = False, customName = None):
        Lootable.startLooting(self, plunderList, itemsToTake, timer = timer, autoShow = autoShow, customName = PLocalizer.FoundFishing)
        if self.fishingGame and not self.fishingGame.gui.resultsScreen.isHidden():
            localAvatar.guiMgr.inventoryUIManager.hidePlunder()
示例#3
0
class DistributedFishingSpot(DistributedInteractive.DistributedInteractive,
                             Lootable):
    notify = DirectNotifyGlobal.directNotify.newCategory(
        'DistributedFishingSpot')

    def __init__(self, cr):
        DistributedInteractive.DistributedInteractive.__init__(self, cr)
        Lootable.__init__(self)
        self.index = -1
        self.onABoat = False
        self.fadeTime = 0.5
        self.loadingSequence = None
        self.fishingGame = None
        self.xpBonus = 0
        self.goldBonus = 0
        self.showTutorial = False
        self._DistributedFishingSpot__dialog = None
        self.prevBaseCamParent = None
        self.prevCamPos = None
        self.prevCamHpr = None
        self.oldAvatarPos = None

    def generate(self):
        DistributedInteractive.DistributedInteractive.generate(self)
        NodePath.__init__(self, 'DistributedFishingSpot')
        self.setInteractOptions(proximityText=PLocalizer.InteractFishingSpot,
                                sphereScale=8,
                                diskRadius=8)
        self.setAllowInteract(True)

    def announceGenerate(self):
        DistributedInteractive.DistributedInteractive.announceGenerate(self)
        if self.getOnABoat() and self.getParentObj():
            self.getParentObj().registerFishingSpot(self)

    def setXpBonus(self, xpBonusAmount):
        self.xpBonus = xpBonusAmount
        if self.fishingGame:
            self.fishingGame.updateResultsScreen()

    def getXpBonus(self):
        return self.xpBonus

    def setGoldBonus(self, goldBonusAmount):
        self.goldBonus = goldBonusAmount
        if self.fishingGame:
            self.fishingGame.updateResultsScreen()

    def getGoldBonus(self):
        return self.goldBonus

    def setOnABoat(self, onABoat):
        self.onABoat = onABoat

    def getOnABoat(self):
        return self.onABoat

    def setOceanOffset(self, offset):
        self.oceanOffset = offset

    def requestInteraction(self, avId, interactType=0):
        inv = localAvatar.getInventory()
        rodQty = inv.getStackQuantity(InventoryType.FishingRod)
        regLureQty = inv.getStackQuantity(InventoryType.RegularLure)
        legendaryLureQty = inv.getStackQuantity(InventoryType.LegendaryLure)
        if rodQty > 0:
            if regLureQty + legendaryLureQty <= 0:
                localAvatar.guiMgr.createWarning(
                    PLocalizer.FishingNoLuresWarning,
                    PiratesGuiGlobals.TextFG6)
            elif localAvatar.isUndead():
                localAvatar.guiMgr.createWarning(
                    PLocalizer.NoFishingWhileUndeadWarning,
                    PiratesGuiGlobals.TextFG6)
            else:
                localAvatar.motionFSM.off()
                DistributedInteractive.DistributedInteractive.requestInteraction(
                    self, avId, interactType)
        else:
            localAvatar.guiMgr.createWarning(PLocalizer.FishingNoRodWarning,
                                             PiratesGuiGlobals.TextFG6)

    def rejectInteraction(self):
        localAvatar.motionFSM.on()
        localAvatar.gameFSM.request('LandRoam')
        self.refreshState()
        DistributedInteractive.DistributedInteractive.rejectInteraction(self)

    def requestExit(self):
        DistributedInteractive.DistributedInteractive.requestExit(self)
        taskMgr.remove('tryFishingSpotAgain')
        if self.onABoat and self.oldAvatarPos:
            localAvatar.setPos(self.oldAvatarPos)
            self.oldAvatarPos = None

        if not localAvatar.gameFSM.isInTransition():
            localAvatar.b_setGameState(localAvatar.gameFSM.defaultState)

        self.loadingSequence.pause()
        self.loadingSequence.clearToInitial()
        base.transitions.fadeIn(self.fadeTime)
        if self.fishingGame is not None:
            self.fishingGame.delete()
            self.fishingGame = None

        if self.prevBaseCamParent is not None:
            base.cam.reparentTo(self.prevBaseCamParent)
            base.cam.setPos(self.prevCamPos)
            base.cam.setHpr(self.prevCamHpr)
            self.prevBaseCamParent = None
            self.prevCamPos = None
            self.prevCamHpr = None

        taskMgr.remove(self.uniqueName('bootFromFishing'))
        localAvatar.motionFSM.on()
        self.setAllowInteract(True)
        base.localAvatar.guiMgr.setIgnoreEscapeHotKey(False)
        self.refreshState()

    def checkAndLoadFishingGame(self):
        localAvatar.b_setGameState('Fishing')
        if self.fishingGame is None:
            self.fishingGame = FishingGame(self)

        if self.onABoat:
            self.oldAvatarPos = localAvatar.getPos()
            localAvatar.collisionGhost()
            localAvatar.setPos(
                *FishingGlobals.fishingSpotPosHprBoatInformation[
                    self.index]['pos'])
            localAvatar.setHpr(
                *FishingGlobals.fishingSpotPosHprBoatInformation[
                    self.index]['hpr'])
            self.setHpr(*FishingGlobals.fishingSpotPosHprBoatInformation[
                self.index]['fishingSpotHpr'])
            base.cam.reparentTo(self.fishingGame.fishingSpot)
            base.cam.setPos(13.0, -18.0, 7.0)
            base.cam.setHpr(0.0, 0.0, 0.0)
        else:
            par = localAvatar.getParentObj()
            uid = par.getUniqueId()
            if uid == LocationIds.DEL_FUEGO_ISLAND:
                localAvatar.setHpr(50.0, 0.0, 0.0)
            elif localAvatar.onWelcomeWorld:
                localAvatar.setHpr(self.getH(render) - 196.0, 0.0, 0.0)
            else:
                localAvatar.setHpr(self.getH(render) - 16.0, 0.0, 0.0)
            localAvatar.setPos(self,
                               Point3(*FishingGlobals.fishingSpotPosOffset))
            base.cam.reparentTo(self.fishingGame.fishingSpot)
            base.cam.setHpr(0.0, 0.0, 0.0)
        localAvatar.sendCurrentPosition()

    def requestPlayerIdleState(self, task=None):
        if base.localAvatar.find('**/fishingRod').isEmpty():
            taskMgr.doMethodLater(0.5,
                                  self.requestPlayerIdleState,
                                  name='tryFishingSpotAgain')
        else:
            self.fishingGame.fsm.request('PlayerIdle')
            self.fishingGame.checkLures()

    def enterUse(self):
        DistributedInteractive.DistributedInteractive.enterUse(self)
        self.prevBaseCamParent = base.cam.getParent()
        self.prevCamPos = base.cam.getPos()
        self.prevCamHpr = base.cam.getHpr()
        if not base.transitions.fadeOutActive():
            self.loadingSequence = Sequence(
                Func(self.fadeOut), Wait(self.fadeTime + 0.10000000000000001),
                Func(self.checkAndLoadFishingGame), Wait(1.5),
                Func(self.requestPlayerIdleState), Func(self.fadeIn))
            self.loadingSequence.start()
        else:
            print '--------------------- DistributedFishingSpot : Trouble fading out!'
        taskMgr.doMethodLater(FishingGlobals.idleDuration,
                              self.bootFromFishing,
                              self.uniqueName('bootFromFishing'))
        self.accept('mouse1', self.resetBootCheck)
        self.accept('fishing-skill-used', self.resetBootCheck)
        self.accept('newItemHeld', self.resetBootCheck)
        self.accept('releaseHeld', self.resetBootCheck)
        self.accept('plunderClosed', self.requestPlayerIdle)

    def fadeOut(self):
        base.transitions.setFadeColor(0, 0, 0)
        if base.transitions.fadeOutActive():
            return None

        base.transitions.fadeOut(self.fadeTime)
        base.localAvatar.guiMgr.inventoryUIManager.hidePlunder()
        base.loadingScreen.showTarget(fishing=True)
        base.cr.loadingScreen.show()

    def fadeIn(self):
        base.transitions.fadeIn(self.fadeTime)
        base.musicMgr.request(SoundGlobals.MUSIC_MINIGAME_FISHING,
                              looping=True,
                              priority=1)
        base.cr.loadingScreen.hide()
        base.localAvatar.guiMgr.inventoryUIManager.showPlunder()

    def exitUse(self):
        self.ignoreAll()
        DistributedInteractive.DistributedInteractive.exitUse(self)
        base.musicMgr.requestFadeOut(SoundGlobals.MUSIC_MINIGAME_FISHING)

    def firstTimeFisher(self):
        self.showTutorial = True

    def spotFilledByAvId(self, avId):
        if avId == 0:
            self.setAllowInteract(True)
            self.showTutorial = False
            return None

        if base.localAvatar.doId != avId:
            self.setAllowInteract(False)

    def delete(self):
        self.ignoreAll()
        taskMgr.remove(self.uniqueName('bootFromFishing'))
        if self.fishingGame is not None:
            self.fishingGame.delete()
            del self.fishingGame

        if self.prevBaseCamParent is not None:
            base.cam.reparentTo(self.prevBaseCamParent)
            base.cam.setPos(self.prevCamPos)
            base.cam.setHpr(self.prevCamHpr)
            self.prevBaseCamParent = None
            self.prevCamPos = None
            self.prevCamHpr = None

        DistributedInteractive.DistributedInteractive.delete(self)

    def b_setIndex(self, index):
        self.index = index
        self.sendUpdate('setIndex', [index])

    def setIndex(self, index):
        self.index = index

    def getIndex(self):
        return self.index

    def d_caughtFish(self, fishId, weight):
        self.sendUpdate('caughtFish', [fishId, weight])

    def lostLure(self, lureId):
        pass

    def d_lostLure(self, lureId):
        self.sendUpdate('lostLure', [lureId])

    def handleEndInteractKey(self):
        if self.fishingGame or not self.fishingGame.gui.resultsScreen.isHidden(
        ) or localAvatar.guiMgr.inventoryUIManager.hasPlunder():
            return None

        if self._DistributedFishingSpot__dialog == None:
            self._DistributedFishingSpot__dialog = PDialog(
                text=PLocalizer.FishingGui['ExitText'],
                style=OTPDialog.YesNo,
                giveMouse=False,
                command=self._DistributedFishingSpot__onDialogItemSelected)
        else:
            self._DistributedFishingSpot__dialog.cleanup()
            self._DistributedFishingSpot__dialog = None

    def _DistributedFishingSpot__onDialogItemSelected(self, value):
        if value == 1:
            self.requestExit()

        self._DistributedFishingSpot__dialog.cleanup()
        self._DistributedFishingSpot__dialog = None

    def bootFromFishing(self, task=None):
        self.requestExit()

    def resetBootCheck(self, arg1=None, arg2=None):
        taskMgr.remove(self.uniqueName('bootFromFishing'))
        taskMgr.doMethodLater(FishingGlobals.idleDuration,
                              self.bootFromFishing,
                              self.uniqueName('bootFromFishing'))

    def requestPlayerIdle(self, arg1=None):
        if self.fishingGame.fsm.getCurrentOrNextState() == 'Reward':
            self.fishingGame.fsm.request('PlayerIdle')

    def startLooting(self,
                     plunderList,
                     itemsToTake=0,
                     timer=0,
                     autoShow=False,
                     customName=None):
        Lootable.startLooting(self,
                              plunderList,
                              itemsToTake,
                              timer=timer,
                              autoShow=autoShow,
                              customName=PLocalizer.FoundFishing)
        if self.fishingGame and not self.fishingGame.gui.resultsScreen.isHidden(
        ):
            localAvatar.guiMgr.inventoryUIManager.hidePlunder()
class FishingGameGUI:
    
    def __init__(self, gameObject = None):
        base.loadingScreen.beginStep('GameGUI', 3, 20)
        self.gameObject = gameObject
        gui = loader.loadModel('models/gui/toplevel_gui')
        guiIcons = loader.loadModel('models/textureCards/icons')
        weaponIcons = loader.loadModel('models/gui/gui_icons_weapon')
        fishingIcons = loader.loadModel('models/textureCards/fishing_icons')
        self.tackleBoxButton = DirectButton(parent = base.a2dBottomRight, relief = None, pos = (-0.53000000000000003, 0.0, 0.10000000000000001), scale = 0.5, text = PLocalizer.FishingGui['Lures'], text_pos = (0, -0.14999999999999999), text_scale = 0.065000000000000002, text_fg = PiratesGuiGlobals.TextFG2, text_shadow = PiratesGuiGlobals.TextShadow, text_font = PiratesGlobals.getPirateBoldOutlineFont(), image_pos = (0, 0, 0), image_scale = 0.17999999999999999, geom = (fishingIcons.find('**/pir_t_gui_fsh_tackleBasket'), fishingIcons.find('**/pir_t_gui_fsh_tackleBasket'), fishingIcons.find('**/pir_t_gui_fsh_tackleBasket_over')), geom_pos = (0, 0, 0), geom_scale = 0.25, geom_color = (1.0, 1.0, 1.0, 1), sortOrder = 2, command = self.toggleLureSelectionDialog)
        self.tackleBoxInterval = Sequence(self.tackleBoxButton.colorScaleInterval(0.5, Vec4(1.0, 0.59999999999999998, 0.59999999999999998, 1.0)), self.tackleBoxButton.colorScaleInterval(0.5, Vec4(1.0, 1.0, 1.0, 1.0)))
        self.exitButton = DirectButton(parent = base.a2dBottomRight, relief = None, pos = (-0.29999999999999999, 0.0, 0.10000000000000001), scale = 0.5, text = PLocalizer.FishingGui['ExitButton'], text_pos = (0, -0.14999999999999999), text_scale = 0.065000000000000002, text_fg = PiratesGuiGlobals.TextFG2, text_shadow = PiratesGuiGlobals.TextShadow, text_font = PiratesGlobals.getPirateBoldOutlineFont(), image_pos = (0, 0, 0), image_scale = 0.17999999999999999, geom = (fishingIcons.find('**/pir_t_gui_fsh_esc'), fishingIcons.find('**/pir_t_gui_fsh_esc'), fishingIcons.find('**/pir_t_gui_fsh_esc_over')), geom_pos = (0, 0, 0), geom_scale = 0.25, geom_color = (1.0, 1.0, 1.0, 1), sortOrder = 2, command = self.handleExitGame)
        self.OkDialog = None
        base.loadingScreen.tick()
        dialogText = PLocalizer.FishingGui['ChooseYourLure']
        self.lureSelectionPanel = GuiPanel.GuiPanel(dialogText, 0.75, 0.5, True, 1)
        self.lureSelectionPanel.reparentTo(base.a2dBottomRight)
        self.lureSelectionPanel.setPos(-0.90000000000000002, 0.0, 0.22)
        self.lureSelectionPanel.regularLureButton = DirectButton(parent = self.lureSelectionPanel, relief = None, pos = (0.20000000000000001, 0, 0.25), scale = 0.5, text = '', text_pos = (0, 0), text_scale = PiratesGuiGlobals.TextScaleSmall, text_fg = PiratesGuiGlobals.TextFG2, text_shadow = PiratesGuiGlobals.TextShadow, text_font = PiratesGlobals.getPirateBoldOutlineFont(), image = fishingIcons.find('**/pir_t_gui_fsh_lureReg'), image_pos = (0, 0, 0), image_scale = 0.17999999999999999, geom = (gui.find('**/pir_t_gui_but_circle'), gui.find('**/pir_t_gui_but_circle'), gui.find('**/pir_t_gui_but_circle_over')), geom_pos = (0, 0, 0), geom_scale = 1, geom_hpr = (0, 0, 90), geom_color = (1.0, 1.0, 1.0, 1), sortOrder = 2, command = self.chooseRegularLure)
        self.lureSelectionPanel.regularLureButtonText = DirectLabel(parent = self.lureSelectionPanel, relief = None, text = PLocalizer.FishingGui['RegularLures'], text_align = TextNode.ARight, text_scale = PiratesGuiGlobals.TextScaleSmall, text_pos = (0.28000000000000003, 0.14999999999999999), text_fg = PiratesGuiGlobals.TextFG2, text_shadow = PiratesGuiGlobals.TextShadow, text_font = PiratesGlobals.getPirateBoldOutlineFont(), textMayChange = 1)
        base.loadingScreen.tick()
        inv = localAvatar.getInventory()
        regQty = inv.getStackQuantity(InventoryType.RegularLure)
        self.lureSelectionPanel.regularLureQty = DirectLabel(parent = self.lureSelectionPanel, relief = None, text = 'x' + str(regQty), text_align = TextNode.ACenter, text_scale = PiratesGuiGlobals.TextScaleSmall, text_pos = (0.29999999999999999, 0.20000000000000001), text_fg = PiratesGuiGlobals.TextFG2, text_shadow = PiratesGuiGlobals.TextShadow, text_font = PiratesGlobals.getPirateBoldOutlineFont(), textMayChange = 1)
        self.lureSelectionPanel.legendaryLureButton = DirectButton(parent = self.lureSelectionPanel, relief = None, pos = (0.55000000000000004, 0.0, 0.25), scale = 0.5, text = '', text_pos = (0, 0), text_scale = PiratesGuiGlobals.TextScaleSmall, text_fg = PiratesGuiGlobals.TextFG2, text_shadow = PiratesGuiGlobals.TextShadow, text_font = PiratesGlobals.getPirateBoldOutlineFont(), image = fishingIcons.find('**/pir_t_gui_fsh_lureLegend'), image_pos = (0, 0, 0), image_scale = 0.17999999999999999, geom = (gui.find('**/pir_t_gui_but_circle'), gui.find('**/pir_t_gui_but_circle'), gui.find('**/pir_t_gui_but_circle_over')), geom_pos = (0, 0, 0), geom_scale = 1, geom_hpr = (0, 0, 90), geom_color = (1.0, 1.0, 1.0, 1), sortOrder = 2, command = self.chooseLegendaryLure)
        self.lureSelectionPanel.legendaryLureButtonText = DirectLabel(parent = self.lureSelectionPanel, relief = None, text = PLocalizer.FishingGui['LegendaryLures'], text_align = TextNode.ARight, text_scale = PiratesGuiGlobals.TextScaleSmall, text_pos = (0.65000000000000002, 0.14999999999999999), text_fg = PiratesGuiGlobals.TextFG2, text_shadow = PiratesGuiGlobals.TextShadow, text_font = PiratesGlobals.getPirateBoldOutlineFont(), textMayChange = 1)
        inv = localAvatar.getInventory()
        legQty = inv.getStackQuantity(InventoryType.LegendaryLure)
        self.lureSelectionPanel.legendaryLureQty = DirectLabel(parent = self.lureSelectionPanel, relief = None, text = 'x' + str(legQty), text_align = TextNode.ACenter, text_scale = PiratesGuiGlobals.TextScaleSmall, text_pos = (0.66000000000000003, 0.20000000000000001), text_fg = PiratesGuiGlobals.TextFG2, text_shadow = PiratesGuiGlobals.TextShadow, text_font = PiratesGlobals.getPirateBoldOutlineFont(), textMayChange = 1)
        self.lureSelectionPanel.hide()
        self.lureSelectionPanelShowing = False
        self.resultsScreen = FishingResults(self.gameObject)
        self.resultsScreen.hide()
        bestRod = self.gameObject.getAvatarsBestRod()
        if bestRod == -1:
            base.notify.error('Somehow the avatar got into the fishing game without a rod in their inventory!')
        
        if bestRod == ItemGlobals.FISHING_ROD_3:
            self.castPowerMeterModel = loader.loadModel('models/gui/pir_m_gui_fsh_fishingBarExpert')
        elif bestRod == ItemGlobals.FISHING_ROD_2:
            self.castPowerMeterModel = loader.loadModel('models/gui/pir_m_gui_fsh_fishingBarNovice')
        else:
            self.castPowerMeterModel = loader.loadModel('models/gui/pir_m_gui_fsh_fishingBarBeginner')
        base.loadingScreen.tick()
        self.castPowerMeter = NodePath('castPowerMeter')
        self.castPowerMeter.reparentTo(base.a2dLeftCenter)
        self.castMeterBackground = self.castPowerMeterModel.find('**/background')
        self.castMeterBackground.setBin('fixed', 32)
        self.castMeterBackground.reparentTo(self.castPowerMeter)
        self.castMeterBar = self.castPowerMeterModel.find('**/meter')
        self.castMeterBar.setBin('fixed', 33)
        self.castMeterBar.reparentTo(self.castPowerMeter)
        self.castMeterBar.setColorScale(0.5, 0.5, 1.0, 1.0)
        self.castMeterFrame = self.castPowerMeterModel.find('**/bar')
        self.castMeterFrame.setBin('fixed', 34)
        self.castMeterFrame.reparentTo(self.castPowerMeter)
        self.castPowerMeter.setPos(0.13700000000000001, 0, 0.22800000000000001)
        self.castPowerMeter.setScale(1)
        self.lineHealthMeter = NodePath('lineHealthMeter')
        self.lineHealthMeter.reparentTo(base.a2dLeftCenter)
        self.lineHealthMeterModel = loader.loadModel('models/gui/pir_m_gui_fsh_fishingBarHealth')
        self.lineHealthMeterBackground = self.lineHealthMeterModel.find('**/background')
        self.lineHealthMeterBackground.setBin('fixed', 32)
        self.lineHealthMeterBackground.reparentTo(self.lineHealthMeter)
        self.lineHealthMeterBar = self.lineHealthMeterModel.find('**/meter')
        self.lineHealthMeterBar.setBin('fixed', 33)
        self.lineHealthMeterBar.reparentTo(self.lineHealthMeter)
        self.lineHealthMeterFrame = self.lineHealthMeterModel.find('**/bar')
        self.lineHealthMeterFrame.setBin('fixed', 34)
        self.lineHealthMeterFrame.reparentTo(self.lineHealthMeter)
        self.lineHealthMeter.setPos(0.13700000000000001, 0, 0.25)
        self.lineHealthMeter.setScale(1)
        self.lineLengthLabel = TextPrinter()
        self.lineLengthLabel.text.setScale(1.2)
        self.lineLengthLabel.text.setHpr(0.0, 0.0, 0.0)
        self.lineLengthLabel.text['sortOrder'] = 200
        self.lineLengthLabel.text.setBin('gui-fixed', 10)
        self.lineLengthLabel.text.setDepthTest(0)
        self.lineLengthLabel.text.setDepthWrite(0)
        self.lineLengthLabel.showText('0', (1, 1, 1, 1))
        base.loadingScreen.endStep('GameGUI')

    
    def updateLureQuantities(self, caller = None):
        inv = localAvatar.getInventory()
        regQty = inv.getStackQuantity(InventoryType.RegularLure)
        legQty = inv.getStackQuantity(InventoryType.LegendaryLure)
        self.lureSelectionPanel.regularLureQty['text'] = 'x' + str(regQty)
        self.lureSelectionPanel.legendaryLureQty['text'] = 'x' + str(legQty)

    
    def handleExitGame(self):
        messenger.send('escape')

    
    def chooseRegularLure(self):
        inv = localAvatar.getInventory()
        qty = inv.getStackQuantity(InventoryType.RegularLure)
        if qty > 0:
            self.gameObject.chooseLure(InventoryType.RegularLure)
            self.lureSelectionPanel.hide()
            self.lureSelectionPanelShowing = False
            self.gameObject.sfx['lureEquip'].play()
        else:
            localAvatar.guiMgr.createWarning(PLocalizer.NotEnoughFishingLures, PiratesGuiGlobals.TextFG6)
            self.gameObject.tutorialManager.showTutorial(InventoryType.FishingNoMoreLures)

    
    def chooseLegendaryLure(self):
        inv = localAvatar.getInventory()
        qty = inv.getStackQuantity(InventoryType.LegendaryLure)
        if qty > 0:
            self.gameObject.chooseLure(InventoryType.LegendaryLure)
            self.lureSelectionPanel.hide()
            self.lureSelectionPanelShowing = False
            self.gameObject.sfx['lureEquip'].play()
        else:
            localAvatar.guiMgr.createWarning(PLocalizer.NotEnoughFishingLures, PiratesGuiGlobals.TextFG6)

    
    def hideGui(self):
        self.tackleBoxInterval.finish()
        self.castPowerMeter.reparentTo(hidden)
        self.lineHealthMeter.reparentTo(hidden)
        self.tackleBoxButton.reparentTo(hidden)
        self.exitButton.hide()
        self.resultsScreen.cleanUp()
        self.lureSelectionPanelShowing = False
        self.lureSelectionPanel.hide()
        self.lineLengthLabel.text.hide()
        if self.OkDialog is not None:
            self.OkDialog.cleanup()
            self.OkDialog = None
        

    
    def showGui(self):
        self.toggleGuiElements()

    
    def hideExitButton(self):
        self.exitButton.hide()

    
    def toggleGuiElements(self):
        if self.gameObject.fsm.getCurrentOrNextState() == 'LegendaryFish':
            self.hideGui()
            return None
        
        if self.gameObject.fsm.getCurrentOrNextState() in [
            'Offscreen',
            'ChargeCast',
            'Cast',
            'PlayerIdle']:
            self.lineHealthMeter.reparentTo(hidden)
            self.castPowerMeter.reparentTo(base.a2dLeftCenter)
            self.lineLengthLabel.text.reparentTo(base.a2dLeftCenter)
            self.lineLengthLabel.text.setPos(0.13700000000000001, 0.0, 0.52800000000000002)
            self.exitButton.show()
            self.tackleBoxButton.show()
            if self.tackleBoxInterval.isPlaying():
                self.toggleLureSelectionDialog()
            
        
        if self.gameObject.fsm.getCurrentOrNextState() in [
            'Fishing',
            'Reeling',
            'QuickReel',
            'FishFight']:
            self.castPowerMeter.reparentTo(hidden)
            self.lineHealthMeter.reparentTo(base.a2dLeftCenter)
            self.lineLengthLabel.text.reparentTo(base.a2dLeftCenter)
            self.lineLengthLabel.text.setPos(0.13700000000000001, 0.0, 0.53800000000000003)
            self.updateLineHealthMeter(self.gameObject.lineHealth)
            self.tackleBoxButton.hide()
            self.lureSelectionPanel.hide()
            self.lureSelectionPanelShowing = False
        
        self.tackleBoxButton.reparentTo(base.a2dBottomRight)

    
    def setTackleBoxPulse(self, bool):
        if bool:
            self.tackleBoxInterval.loop()
        else:
            self.tackleBoxInterval.finish()

    
    def resetGui(self):
        self.castMeterBar.setScale(1.0, 1.0, 0.01)
        self.lineHealthMeterBar.setScale(1.0, 1.0, 1.0)
        self.toggleGuiElements()

    
    def destroy(self):
        self.castPowerMeter.removeNode()
        self.lineHealthMeter.removeNode()
        self.lureSelectionPanel.destroy()
        self.lureSelectionPanel.regularLureButton = None
        self.lureSelectionPanel.regularLureButtonText = None
        self.lureSelectionPanel.legendaryLureButton = None
        self.lureSelectionPanel.legendaryLureButtonText = None
        self.lureSelectionPanel = None
        self.lineLengthLabel = None
        self.tackleBoxButton.destroy()
        self.tackleBoxButton = None
        self.exitButton.destroy()
        self.exitButton = None

    
    def startPowerMeter(self):
        self.startCastFrameTime = globalClock.getFrameTime()

    
    def updateCastPowerMeter(self, value):
        self.castMeterBar.setScale(1.0, 1.0, value / 100.0)

    
    def updateCastPowerMeterTask(self, task):
        time = globalClock.getFrameTime()
        elapsed = max(time - self.startCastFrameTime, 0.0)
        value = round(-math.cos(elapsed * 5.0) * 50.0 + 50.0)
        value = max(value, 0.0)
        self.updateCastPowerMeter(value)
        return Task.again

    
    def updateLineHealthMeter(self, value):
        self.lineHealthMeterBar.setScale(1.0, 1.0, value / 100.0)
        self.lineHealthMeterBar.setColorScale(self.gameObject.getLineColorBasedOnHealth())

    
    def showRewardDialog(self, fish):
        self.resultsScreen.showAll()
        self.exitButton.hide()

    
    def showExitCheckDialog(self):
        dialogText = PLocalizer.FishingGui['AreYouSure']
        self.OkDialog = PDialog(text = dialogText, style = OTPDialog.Acknowledge, giveMouse = False, command = self.closeDialogGotoPlayerIdle)
        self.OkDialog.setPos(0.80000000000000004, 0.0, 0.5)

    
    def closeDialogGotoPlayerIdle(self, arg):
        self.OkDialog.cleanup()
        self.OkDialog = None
        self.gameObject.fsm.request('PlayerIdle')

    
    def toggleLureSelectionDialog(self):
        if self.lureSelectionPanelShowing:
            self.lureSelectionPanel.hide()
        else:
            self.lureSelectionPanel.show()
        self.lureSelectionPanelShowing = not (self.lureSelectionPanelShowing)
示例#5
0
class DefenseCannonGUI(CannonGUI):
    notify = DirectNotifyGlobal.directNotify.newCategory('DefenseCannonGUI')

    def __init__(self, cannon):
        CannonGUI.__init__(self, cannon)
        self.exitEvent = None
        self._DefenseCannonGUI__dialog = None
        self.helpButton = None
        self.helpUI = None
        self.flashHelp = None
        self.ammoFade = None
        self._DefenseCannonGUI__ammoCountersHidden = False
        self.setupExtraButtons()
        self.exitCannon['command'] = self.showExitDialog
        self.volleyLabel.setPos(-0.28000000000000003, 0, 0.089999999999999997)
        self.reloadBar.setPos(-0.13, 0, 0.080000000000000002)
        self.ammoImage.setPos(-0.38, 0, 0.059999999999999998)
        self.repMeter = ReputationMeter(InventoryType.DefenseCannonRep,
                                        width=0.69999999999999996)
        self.repMeter.reparentTo(base.a2dBottomCenter)
        self.repMeter.setPos(0.0, 0.0, 0.025000000000000001)
        self.hud = CannonDefenseHUD()
        self.hud.create()
        self._exp = 0
        self.lastLevel = 1
        self.accept('incDefenseCannonExp', self.increaseExp)
        if __dev__:
            base.dcg = self

    def destroy(self):
        if self.ammoFade:
            self.ammoFade.finish()
            self.ammoFade = None

        if self.flashHelp:
            self.flashHelp.finish()
            self.flashHelp = None

        if self.helpButton:
            self.helpButton.destroy()
            self.helpButton = None

        if self.helpUI:
            self.helpUI.destroy()
            self.helpUI = None

        if self.hud:
            self.hud.destroy()
            self.hud = None

        base.musicMgr.requestFadeOut(SoundGlobals.MUSIC_MINIGAME_CANNON)
        self.repMeter.destroy()
        self.ignore('incDefenseCannonExp')
        CannonGUI.destroy(self)

    def setupExtraButtons(self):
        weaponIcons = loader.loadModel('models/gui/gui_icons_weapon')
        self.helpButton = DirectButton(
            parent=base.a2dBottomRight,
            relief=None,
            pos=(-0.59999999999999998, 0, 0.089999999999999997),
            scale=0.5,
            text='?',
            text_pos=(0, -0.055),
            text_scale=0.20999999999999999,
            text_fg=PiratesGuiGlobals.TextFG2,
            text_shadow=PiratesGuiGlobals.TextShadow,
            text_font=PiratesGlobals.getPirateBoldOutlineFont(),
            sortOrder=2,
            command=self.toggleHelpUI)
        DirectLabel(parent=self.helpButton,
                    text=PLocalizer.CannonDefense['Help'],
                    text_pos=(0, -0.14999999999999999),
                    text_scale=0.080000000000000002,
                    text_fg=PiratesGuiGlobals.TextFG2,
                    text_shadow=PiratesGuiGlobals.TextShadow,
                    text_font=PiratesGlobals.getPirateBoldOutlineFont(),
                    frameColor=(1, 1, 1, 0))

    def increaseExp(self, amt, total):
        self._exp += amt
        if self._exp > total:
            return None

        (level, leftoverValue) = ReputationGlobals.getLevelFromTotalReputation(
            InventoryType.DefenseCannonRep, self._exp)
        self.repMeter.update(self._exp)
        if level > self.lastLevel:
            base.localAvatar.levelUpMsg(InventoryType.DefenseCannonRep, level,
                                        0)
            self.lastLevel = level

    def toggleHelpUI(self):
        if self.helpUI == None:
            self._DefenseCannonGUI__createHelpUI()
            self.fadeOutAmmoCounters()
            if self.cannon.ammoPanel.state == pirates.minigame.AmmoPanel.CLOSED:
                self.cannon.ammoPanel.onTabClick()

        else:
            self._DefenseCannonGUI__destroyHelpUI()
            self.fadeInAmmoCounters()
            if self.cannon.ammoPanel.state == pirates.minigame.AmmoPanel.OPENED:
                self.cannon.ammoPanel.onTabClick()

    def _DefenseCannonGUI__createHelpUI(self):
        self.helpUI = CannonDefenseHelpManager(0.5)
        self.helpUI.exit.reparentTo(self.exitCannon)
        self.helpUI.exit.setScale(2.0)
        self.helpUI.help.reparentTo(self.helpButton)
        self.helpUI.help.setScale(2.0)
        self.helpUI.ammoPanel.reparentTo(self.cannon.ammoPanel.panel)
        self.helpUI.ammoPanel.setScale(1.0 / 3.0)
        self.helpUI.ammo.reparentTo(base.a2dBottomCenter)
        self.helpUI.mine.reparentTo(self.hud.goldRemainingUI.mineCounter)
        self.helpUI.mine.setScale(2.0 / 3.0)
        self.helpUI.wave.reparentTo(self.hud.timeRemainingUI.timeRemaining)
        self.helpUI.wave.setScale(1.0 / 0.75)
        self.helpUI.fadeIn.start()

    def _DefenseCannonGUI__destroyHelpUI(self):
        cleanup = Sequence(Func(self.helpUI.fadeIn.pause),
                           self.helpUI.fadeOut,
                           Func(self.helpUI.destroy),
                           name=self.cannon.uniqueName('HelpUI_FadeIn'))
        cleanup.start()
        self.helpUI = None

    def isHelpUIVisible(self):
        return self.helpUI != None

    def flashHelpButton(self, delay=0.20000000000000001, length=5):
        if self.flashHelp:
            self.flashHelp.finish()
            self.flashHelp = None

        self.flashHelp = Sequence(
            name=self.cannon.uniqueName('HelpButton_Flash'))

        def setColor(key, value):
            self.helpButton[key] = value

        for i in range(0, length):
            self.flashHelp.append(Wait(delay))
            self.flashHelp.append(
                Func(setColor, 'text_fg', PiratesGuiGlobals.TextFG19))
            self.flashHelp.append(Wait(delay))
            self.flashHelp.append(
                Func(setColor, 'text_fg', PiratesGuiGlobals.TextFG2))

        self.flashHelp.start()

    def fadeOutAmmoCounters(self, length=0.5):
        if self._DefenseCannonGUI__ammoCountersHidden:
            return None

        transparent = Vec4(1, 1, 1, 0)
        if self.ammoFade:
            self.ammoFade.finish()

        self.ammoFade = Parallel(
            self.volleyLabel.colorScaleInterval(length, transparent),
            self.reloadBar.colorScaleInterval(length, transparent),
            self.ammoImage.colorScaleInterval(length, transparent))
        self.ammoFade.start()
        self._DefenseCannonGUI__ammoCountersHidden = True

    def fadeInAmmoCounters(self, length=0.5):
        if self._DefenseCannonGUI__ammoCountersHidden == False:
            return None

        opaque = Vec4(1, 1, 1, 1)
        transparent = Vec4(1, 1, 1, 0)
        if self.ammoFade:
            self.ammoFade.finish()

        self.ammoFade = Parallel(
            self.volleyLabel.colorScaleInterval(length, opaque, transparent),
            self.reloadBar.colorScaleInterval(length, opaque, transparent),
            self.ammoImage.colorScaleInterval(length, opaque, transparent))
        self.ammoFade.start()
        self._DefenseCannonGUI__ammoCountersHidden = False

    def showExitDialog(self):
        if self._DefenseCannonGUI__dialog == None:
            self._DefenseCannonGUI__dialog = PDialog(
                text=PLocalizer.CannonDefense['ExitCannon'],
                style=OTPDialog.YesNo,
                giveMouse=False,
                command=self._DefenseCannonGUI__onDialogItemSelected)
        else:
            self._DefenseCannonGUI__dialog.cleanup()
            self._DefenseCannonGUI__dialog = None

    def _DefenseCannonGUI__onDialogItemSelected(self, value):
        if value == 1:
            if self.exitEvent:
                self.exitEvent()

        self._DefenseCannonGUI__dialog.cleanup()
        self._DefenseCannonGUI__dialog = None