Exemplo n.º 1
0
class CogdoMazeGuiManager:
    def __init__(self, maze, bossCode):
        self.maze = maze
        self.root = NodePath('CogdoMazeGui')
        self.root.reparentTo(aspect2d)
        self.mazeMapGui = CogdoMazeMapGui(self.maze.collisionTable)
        if bossCode is not None:
            self._bossGui = CogdoMazeBossGui(bossCode)
        else:
            self._bossGui = None
        self._memoGui = CogdoMemoGui(self.root)
        self._memoGui.posNextToLaffMeter()
        self._presentGuiIval = None
        self._presentTimerIval = None
        self._hud = CogdoMazeHud()
        self._timer = None
        self._initMessageDisplay()
        return

    def _initTimer(self):
        self._timer = ToontownTimer()
        self._timer.hide()
        self._timer.posInTopRightCorner()

    def _initMessageDisplay(self):
        self.messageDisplay = CogdoGameMessageDisplay(
            'CogdoMazeMessageDisplay', self.root, pos=Globals.MessageLabelPos)

    def destroy(self):
        ToontownIntervals.cleanup('present_gui')
        ToontownIntervals.cleanup('present_timer')
        ToontownIntervals.cleanup('present_memo')
        self._hud.destroy()
        self._hud = None
        self._memoGui.destroy()
        self._memoGui = None
        if self._bossGui is not None:
            self._bossGui.destroy()
            self._bossGui = None
        self.messageDisplay.destroy()
        self.messageDisplay = None
        self.destroyMazeMap()
        self.destroyTimer()
        if self._presentGuiIval:
            self._presentGuiIval.pause()
            self._presentGuiIval = None
        if self._presentTimerIval:
            self._presentTimerIval.pause()
            self._presentTimerIval = None
        return

    def destroyMazeMap(self):
        if hasattr(self, 'mazeMapGui') and self.mazeMapGui is not None:
            self.mazeMapGui.destroy()
            del self.mazeMapGui
        return

    def destroyTimer(self):
        if self._timer is not None:
            self._timer.stop()
            self._timer.destroy()
            self._timer = None
        return

    def showPickupCounter(self):
        ToontownIntervals.start(
            ToontownIntervals.getPresentGuiIval(self._memoGui, 'present_memo'))

    def startGame(self, firstMessage):
        self._presentGuiIval = ToontownIntervals.start(
            Sequence(ToontownIntervals.getPresentGuiIval(self._bossGui,
                                                         '',
                                                         startPos=(0, 0,
                                                                   -0.15)),
                     Func(self.mazeMapGui.show),
                     ToontownIntervals.getPulseLargerIval(
                         self.mazeMapGui, '',
                         scale=self.mazeMapGui.getScale()),
                     Func(self.setMessage, firstMessage),
                     name='present_gui'))

    def hideMazeMap(self):
        self.mazeMapGui.hide()

    def showBossGui(self):
        if self._bossGui is not None:
            self._bossGui.show()
        return

    def hideBossGui(self):
        if self._bossGui is not None:
            self._bossGui.hide()
        return

    def revealMazeMap(self):
        self.mazeMapGui.revealAll()

    def hideLock(self, lockIndex):
        self.mazeMapGui.hideLock(lockIndex)

    def showTimer(self, duration, timerExpiredCallback=None):
        if self._timer is None:
            self._initTimer()
        self._timer.setTime(duration)
        self._timer.countdown(duration, timerExpiredCallback)
        self._timer.show()
        self._presentTimerIval = ToontownIntervals.start(
            ToontownIntervals.getPresentGuiIval(self._timer,
                                                'present_timer',
                                                startPos=(0, 0, 0.35)))
        return

    def hideTimer(self):
        if hasattr(self, 'timer') and self._timer is not None:
            self._timer.hide()
            self._timer.stop()
        return

    def setMessage(self, text, color=None, transition='fade'):
        self.messageDisplay.updateMessage(text, color, transition)

    def setMessageTemporary(self, text, time=3.0):
        self.messageDisplay.showMessageTemporarily(text, time)

    def clearMessage(self):
        self.messageDisplay.updateMessage('')

    def setPickupCount(self, count):
        self._memoGui.setCount(count)

    def showBossCode(self, bossIndex):
        self._bossGui.showNumber(bossIndex)

    def showBossHit(self, bossIndex):
        self._bossGui.showHit(bossIndex)

    def showQuestArrow(self, toon, target, offset):
        self._hud.showQuestArrow(toon, target, offset)

    def hideQuestArrow(self):
        self._hud.hideQuestArrow()
Exemplo n.º 2
0
class CogdoFlyingGuiManager:
    ClearMessageDisplayEventName = 'ClearMessageDisplayEvent'
    EagleTargetingLocalPlayerEventName = 'EagleTargetingLocalPlayerEvent'
    EagleAttackingLocalPlayerEventName = 'EagleAttackingLocalPlayerEvent'
    FirstPressOfCtrlEventName = 'FirstPressOfCtrlEvent'
    PickedUpFirstPropellerEventName = 'PickedUpFirstPropellerEvent'
    InvulnerableEventName = 'InvulnerableEvent'
    StartRunningOutOfTimeMusicEventName = 'StartRunningOutOfTimeEvent'

    def __init__(self, level):
        self._level = level
        self.root = NodePath('CogdoFlyingGui')
        self.root.reparentTo(aspect2d)
        self.root.stash()
        self.fuelGui = NodePath('CogdoFlyingFuelGui')
        self.fuelGui.reparentTo(base.a2dBottomLeft)
        self.fuelGui.stash()
        self.progressGui = NodePath('CogdoFlyingProgressGui')
        self.progressGui.reparentTo(base.a2dBottomRight)
        self.progressGui.stash()
        self._initTimer()
        self._initHud()
        self._initMessageDisplay()
        self.sentTimeRunningOutMessage = False
        self._refuelGui = CogdoFlyingFuelGui(self.fuelGui)
        self._progressGui = CogdoFlyingProgressGui(self.progressGui,
                                                   self._level)

    def _initHud(self):
        self._memoGui = CogdoMemoGui(self.root, 'memo_card')
        self._memoGui.posNextToLaffMeter()

    def _initTimer(self):
        self._timer = ToontownTimer()
        self._timer.hide()
        self._timer.posInTopRightCorner()

    def _initMessageDisplay(self):
        audioMgr = base.cogdoGameAudioMgr
        sound = audioMgr.createSfx('popupHelpText')
        self._messageDisplay = CogdoGameMessageDisplay(
            'CogdoFlyingMessageDisplay', self.root, sfx=sound)

    def destroyTimer(self):
        if self._timer is not None:
            self._timer.stop()
            self._timer.destroy()
            self._timer = None
        return

    def onstage(self):
        self.root.unstash()
        self.fuelGui.unstash()
        self.progressGui.unstash()
        self._refuelGui.hide()
        self._progressGui.hide()

    def presentProgressGui(self):
        ToontownIntervals.start(
            ToontownIntervals.getPresentGuiIval(self._progressGui,
                                                'present_progress_gui'))

    def presentRefuelGui(self):
        ToontownIntervals.start(
            ToontownIntervals.getPresentGuiIval(self._refuelGui,
                                                'present_fuel_gui'))

    def presentTimerGui(self):
        ToontownIntervals.start(
            ToontownIntervals.getPresentGuiIval(self._timer,
                                                'present_timer_gui'))

    def presentMemoGui(self):
        ToontownIntervals.start(
            ToontownIntervals.getPresentGuiIval(self._memoGui,
                                                'present_memo_gui'))

    def offstage(self):
        self.root.stash()
        self.fuelGui.stash()
        self.progressGui.stash()
        self._refuelGui.hide()
        self._progressGui.hide()
        self.hideTimer()

    def getTimeLeft(self):
        return Globals.Gameplay.SecondsUntilGameOver - self._timer.getElapsedTime(
        )

    def isTimeRunningOut(self):
        return self.getTimeLeft() < Globals.Gameplay.TimeRunningOutSeconds

    def startTimer(self,
                   duration,
                   timerExpiredCallback=None,
                   keepHidden=False):
        if self._timer is None:
            self._initTimer()
        self._timer.setTime(duration)
        self._timer.countdown(duration, timerExpiredCallback)
        if keepHidden:
            self.hideTimer()
        else:
            self.showTimer()
        return

    def stopTimer(self):
        if hasattr(self, '_timer') and self._timer is not None:
            self.hideTimer()
            self._timer.stop()
        return

    def showTimer(self):
        self._timer.show()

    def hideTimer(self):
        self._timer.hide()

    def forceTimerDone(self):
        if self._timer.countdownTask != None:
            self._timer.countdownTask.duration = 0
        return

    def showRefuelGui(self):
        self._refuelGui.show()

    def hideRefuelGui(self):
        self._refuelGui.hide()

    def setMessage(self, text, color=None, transition='fade'):
        self._messageDisplay.updateMessage(text, color, transition)

    def setTemporaryMessage(self, text, duration=3.0, color=None):
        self._messageDisplay.showMessageTemporarily(text, duration, color)

    def setFuel(self, fuel):
        self._refuelGui.setFuel(fuel)

    def resetBlades(self):
        self._refuelGui.resetBlades()

    def setBlades(self, fuelState):
        self._refuelGui.setBlades(fuelState)

    def bladeLost(self):
        self._refuelGui.bladeLost()

    def setPropellerSpinRate(self, newRate):
        self._refuelGui.setPropellerSpinRate(newRate)

    def setMemoCount(self, score):
        self._memoGui.setCount(score)

    def addToonToProgressMeter(self, toon):
        self._progressGui.addToon(toon)

    def removeToonFromProgressMeter(self, toon):
        self._progressGui.removeToon(toon)

    def update(self):
        if self.isTimeRunningOut() and not self.sentTimeRunningOutMessage:
            messenger.send(
                CogdoFlyingGuiManager.StartRunningOutOfTimeMusicEventName)
            self.sentTimeRunningOutMessage = True
        self._refuelGui.update()
        self._progressGui.update()

    def destroy(self):
        ToontownIntervals.cleanup('present_fuel_gui')
        ToontownIntervals.cleanup('present_timer_gui')
        ToontownIntervals.cleanup('present_memo_gui')
        ToontownIntervals.cleanup('present_progress_gui')
        self._refuelGui.destroy()
        self._refuelGui = None
        self._memoGui.destroy()
        self._memoGui = None
        self._progressGui.destroy()
        self._progressGui = None
        self.destroyTimer()
        self._messageDisplay.destroy()
        self._messageDisplay = None
        self.root.removeNode()
        self.root = None
        self.fuelGui.removeNode()
        self.fuelGui = None
        self.progressGui.removeNode()
        self.progressGui = None
        return
class CogdoMazeGuiManager:

    def __init__(self, maze, bossCode):
        self.maze = maze
        self.root = NodePath('CogdoMazeGui')
        self.root.reparentTo(aspect2d)
        self.mazeMapGui = CogdoMazeMapGui(self.maze.collisionTable)
        if bossCode is not None:
            self._bossGui = CogdoMazeBossGui(bossCode)
        else:
            self._bossGui = None
        self._memoGui = CogdoMemoGui(self.root)
        self._memoGui.posNextToLaffMeter()
        self._presentGuiIval = None
        self._presentTimerIval = None
        self._hud = CogdoMazeHud()
        self._timer = None
        self._initMessageDisplay()
        return

    def _initTimer(self):
        self._timer = ToontownTimer()
        self._timer.hide()
        self._timer.posInTopRightCorner()

    def _initMessageDisplay(self):
        self.messageDisplay = CogdoGameMessageDisplay('CogdoMazeMessageDisplay', self.root, pos=Globals.MessageLabelPos)

    def destroy(self):
        ToontownIntervals.cleanup('present_gui')
        ToontownIntervals.cleanup('present_timer')
        ToontownIntervals.cleanup('present_memo')
        self._hud.destroy()
        self._hud = None
        self._memoGui.destroy()
        self._memoGui = None
        if self._bossGui is not None:
            self._bossGui.destroy()
            self._bossGui = None
        self.messageDisplay.destroy()
        self.messageDisplay = None
        self.destroyMazeMap()
        self.destroyTimer()
        if self._presentGuiIval:
            self._presentGuiIval.pause()
            self._presentGuiIval = None
        if self._presentTimerIval:
            self._presentTimerIval.pause()
            self._presentTimerIval = None
        return

    def destroyMazeMap(self):
        if hasattr(self, 'mazeMapGui') and self.mazeMapGui is not None:
            self.mazeMapGui.destroy()
            del self.mazeMapGui
        return

    def destroyTimer(self):
        if self._timer is not None:
            self._timer.stop()
            self._timer.destroy()
            self._timer = None
        return

    def showPickupCounter(self):
        ToontownIntervals.start(ToontownIntervals.getPresentGuiIval(self._memoGui, 'present_memo'))

    def startGame(self, firstMessage):
        self._presentGuiIval = ToontownIntervals.start(Sequence(ToontownIntervals.getPresentGuiIval(self._bossGui, '', startPos=(0, 0, -0.15)), Func(self.mazeMapGui.show), ToontownIntervals.getPulseLargerIval(self.mazeMapGui, '', scale=self.mazeMapGui.getScale()), Func(self.setMessage, firstMessage), name='present_gui'))

    def hideMazeMap(self):
        self.mazeMapGui.hide()

    def showBossGui(self):
        if self._bossGui is not None:
            self._bossGui.show()
        return

    def hideBossGui(self):
        if self._bossGui is not None:
            self._bossGui.hide()
        return

    def revealMazeMap(self):
        self.mazeMapGui.revealAll()

    def hideLock(self, lockIndex):
        self.mazeMapGui.hideLock(lockIndex)

    def showTimer(self, duration, timerExpiredCallback = None):
        if self._timer is None:
            self._initTimer()
        self._timer.setTime(duration)
        self._timer.countdown(duration, timerExpiredCallback)
        self._timer.show()
        self._presentTimerIval = ToontownIntervals.start(ToontownIntervals.getPresentGuiIval(self._timer, 'present_timer', startPos=(0, 0, 0.35)))
        return

    def hideTimer(self):
        if hasattr(self, 'timer') and self._timer is not None:
            self._timer.hide()
            self._timer.stop()
        return

    def setMessage(self, text, color = None, transition = 'fade'):
        self.messageDisplay.updateMessage(text, color, transition)

    def setMessageTemporary(self, text, time = 3.0):
        self.messageDisplay.showMessageTemporarily(text, time)

    def clearMessage(self):
        self.messageDisplay.updateMessage('')

    def setPickupCount(self, count):
        self._memoGui.setCount(count)

    def showBossCode(self, bossIndex):
        self._bossGui.showNumber(bossIndex)

    def showBossHit(self, bossIndex):
        self._bossGui.showHit(bossIndex)

    def showQuestArrow(self, toon, target, offset):
        self._hud.showQuestArrow(toon, target, offset)

    def hideQuestArrow(self):
        self._hud.hideQuestArrow()
class CogdoFlyingGuiManager:
    ClearMessageDisplayEventName = 'ClearMessageDisplayEvent'
    EagleTargetingLocalPlayerEventName = 'EagleTargetingLocalPlayerEvent'
    EagleAttackingLocalPlayerEventName = 'EagleAttackingLocalPlayerEvent'
    FirstPressOfCtrlEventName = 'FirstPressOfCtrlEvent'
    PickedUpFirstPropellerEventName = 'PickedUpFirstPropellerEvent'
    InvulnerableEventName = 'InvulnerableEvent'
    StartRunningOutOfTimeMusicEventName = 'StartRunningOutOfTimeEvent'

    def __init__(self, level):
        self._level = level
        self.root = NodePath('CogdoFlyingGui')
        self.root.reparentTo(aspect2d)
        self.root.stash()
        self.fuelGui = NodePath('CogdoFlyingFuelGui')
        self.fuelGui.reparentTo(base.a2dBottomLeft)
        self.fuelGui.stash()
        self.progressGui = NodePath('CogdoFlyingProgressGui')
        self.progressGui.reparentTo(base.a2dBottomRight)
        self.progressGui.stash()
        self._initTimer()
        self._initHud()
        self._initMessageDisplay()
        self.sentTimeRunningOutMessage = False
        self._refuelGui = CogdoFlyingFuelGui(self.fuelGui)
        self._progressGui = CogdoFlyingProgressGui(self.progressGui, self._level)

    def _initHud(self):
        self._memoGui = CogdoMemoGui(self.root, 'memo_card')
        self._memoGui.posNextToLaffMeter()

    def _initTimer(self):
        self._timer = ToontownTimer()
        self._timer.hide()
        self._timer.posInTopRightCorner()

    def _initMessageDisplay(self):
        audioMgr = base.cogdoGameAudioMgr
        sound = audioMgr.createSfx('popupHelpText')
        self._messageDisplay = CogdoGameMessageDisplay('CogdoFlyingMessageDisplay', self.root, sfx=sound)

    def destroyTimer(self):
        if self._timer is not None:
            self._timer.stop()
            self._timer.destroy()
            self._timer = None
        return

    def onstage(self):
        self.root.unstash()
        self.fuelGui.unstash()
        self.progressGui.unstash()
        self._refuelGui.hide()
        self._progressGui.hide()

    def presentProgressGui(self):
        ToontownIntervals.start(ToontownIntervals.getPresentGuiIval(self._progressGui, 'present_progress_gui'))

    def presentRefuelGui(self):
        ToontownIntervals.start(ToontownIntervals.getPresentGuiIval(self._refuelGui, 'present_fuel_gui'))

    def presentTimerGui(self):
        ToontownIntervals.start(ToontownIntervals.getPresentGuiIval(self._timer, 'present_timer_gui'))

    def presentMemoGui(self):
        ToontownIntervals.start(ToontownIntervals.getPresentGuiIval(self._memoGui, 'present_memo_gui'))

    def offstage(self):
        self.root.stash()
        self.fuelGui.stash()
        self.progressGui.stash()
        self._refuelGui.hide()
        self._progressGui.hide()
        self.hideTimer()

    def getTimeLeft(self):
        return Globals.Gameplay.SecondsUntilGameOver - self._timer.getElapsedTime()

    def isTimeRunningOut(self):
        return self.getTimeLeft() < Globals.Gameplay.TimeRunningOutSeconds

    def startTimer(self, duration, timerExpiredCallback = None, keepHidden = False):
        if self._timer is None:
            self._initTimer()
        self._timer.setTime(duration)
        self._timer.countdown(duration, timerExpiredCallback)
        if keepHidden:
            self.hideTimer()
        else:
            self.showTimer()
        return

    def stopTimer(self):
        if hasattr(self, '_timer') and self._timer is not None:
            self.hideTimer()
            self._timer.stop()
        return

    def showTimer(self):
        self._timer.show()

    def hideTimer(self):
        self._timer.hide()

    def forceTimerDone(self):
        if self._timer.countdownTask != None:
            self._timer.countdownTask.duration = 0
        return

    def showRefuelGui(self):
        self._refuelGui.show()

    def hideRefuelGui(self):
        self._refuelGui.hide()

    def setMessage(self, text, color = None, transition = 'fade'):
        self._messageDisplay.updateMessage(text, color, transition)

    def setTemporaryMessage(self, text, duration = 3.0, color = None):
        self._messageDisplay.showMessageTemporarily(text, duration, color)

    def setFuel(self, fuel):
        self._refuelGui.setFuel(fuel)

    def resetBlades(self):
        self._refuelGui.resetBlades()

    def setBlades(self, fuelState):
        self._refuelGui.setBlades(fuelState)

    def bladeLost(self):
        self._refuelGui.bladeLost()

    def setPropellerSpinRate(self, newRate):
        self._refuelGui.setPropellerSpinRate(newRate)

    def setMemoCount(self, score):
        self._memoGui.setCount(score)

    def addToonToProgressMeter(self, toon):
        self._progressGui.addToon(toon)

    def removeToonFromProgressMeter(self, toon):
        self._progressGui.removeToon(toon)

    def update(self):
        if self.isTimeRunningOut() and not self.sentTimeRunningOutMessage:
            messenger.send(CogdoFlyingGuiManager.StartRunningOutOfTimeMusicEventName)
            self.sentTimeRunningOutMessage = True
        self._refuelGui.update()
        self._progressGui.update()

    def destroy(self):
        ToontownIntervals.cleanup('present_fuel_gui')
        ToontownIntervals.cleanup('present_timer_gui')
        ToontownIntervals.cleanup('present_memo_gui')
        ToontownIntervals.cleanup('present_progress_gui')
        self._refuelGui.destroy()
        self._refuelGui = None
        self._memoGui.destroy()
        self._memoGui = None
        self._progressGui.destroy()
        self._progressGui = None
        self.destroyTimer()
        self._messageDisplay.destroy()
        self._messageDisplay = None
        self.root.removeNode()
        self.root = None
        self.fuelGui.removeNode()
        self.fuelGui = None
        self.progressGui.removeNode()
        self.progressGui = None
        return