Exemple #1
0
class SplashScreen:
    def __init__(self, doneCallback):
        self.cioimg = OnscreenImage(
            image='materials/engine/coginvasiononline.png')
        self.cioimg.hide()
        self.cioimg.setColorScale(0, 0, 0, 1)
        self.pandaimg = OnscreenImage(
            image='materials/engine/powered_by_panda3d.png')
        self.pandaimg.hide()
        self.pandaimg.setColorScale(0, 0, 0, 1)
        self.discimg = OnscreenImage(image='materials/engine/disclaimer.png')
        self.discimg.hide()
        self.discimg.setColorScale(0, 0, 0, 1)

        self.doneCallback = doneCallback

        self.splashIval = Sequence(
            Func(self.cioimg.show), Wait(1.0),
            Func(base.playMusic, "encntr_suit_HQ_nbrhood"),
            LerpColorScaleInterval(self.cioimg, 1.0, (1, 1, 1, 1),
                                   (0, 0, 0, 1)), Wait(3),
            LerpColorScaleInterval(self.cioimg, 1.0, (0, 0, 0, 1),
                                   (1, 1, 1, 1)), Func(self.cioimg.hide),
            Func(self.pandaimg.show),
            LerpColorScaleInterval(self.pandaimg, 1.0, (1, 1, 1, 1),
                                   (0, 0, 0, 1)), Wait(1.0),
            LerpColorScaleInterval(self.pandaimg, 1.0, (0, 0, 0, 1),
                                   (1, 1, 1, 1)), Func(self.pandaimg.hide),
            Func(self.discimg.show),
            LerpColorScaleInterval(self.discimg, 1.0, (1, 1, 1, 1),
                                   (0, 0, 0, 1)), Wait(3.5),
            LerpColorScaleInterval(self.discimg, 1.0, (0, 0, 0, 1),
                                   (1, 1, 1, 1)), Func(self.discimg.hide),
            Func(self.cleanup), Func(self.doneCallback))
        self.splashIval.start()

        base.accept('space', self.splashIval.finish)

    def cleanup(self):
        base.ignore('space')
        self.splashIval.finish()
        self.splashIval = None
        self.pandaimg.destroy()
        self.pandaimg = None
        self.cioimg.destroy()
        self.cioimg = None
        self.discimg.destroy()
        self.discimg = None
class ClickToStart(DirectObject):
    notify = directNotify.newCategory('ClickToStart')

    def __init__(self, version='n/a'):
        DirectObject.__init__(self)

        self.backgroundNodePath = render2d.attachNewNode('background', 0)
        self.backgroundModel = loader.loadModel(
            'phase_3/models/gui/loading-background.bam')
        self.backgroundModel.reparentTo(self.backgroundNodePath)
        self.backgroundNodePath.find('**/fg').removeNode()
        self.backgroundNodePath.setScale(1, 1, 1)

        self.logo = OnscreenImage(
            parent=base.a2dTopCenter, image='phase_3/maps/toontown-logo.png',
            scale=(1.0, 1, 0.5), pos=(0, 0, -0.85))
        self.logo.setTransparency(TransparencyAttrib.MAlpha)

        self.label = OnscreenText(
            TTLocalizer.ClickToStartLabel, parent=base.a2dBottomCenter,
            font=ToontownGlobals.getMinnieFont(), fg=Vec4(1, 1, 1, 1),
            scale=0.1, align=TextNode.ACenter)
        self.label.setZ(0.35)

        self.versionLabel = OnscreenText(
            '\x01white_shadow\x01%s\x02' % version, parent=base.a2dBottomRight,
            font=ToontownGlobals.getMinnieFont(), fg=Vec4(0, 0, 0, 1),
            scale=0.06, align=TextNode.ARight)
        self.versionLabel.setPos(-0.025, 0.025)

        self.setColorScale(Vec4(0, 0, 0, 0))

        self.fadeTrack = None
        self.logoPosTrack = None
        self.logoScaleTrack = None
        self.labelPosTrack = None
        self.labelColorScaleTrack = None

    def delete(self):
        if self.labelColorScaleTrack is not None:
            self.labelColorScaleTrack.finish()
            self.labelColorScaleTrack = None

        if self.labelPosTrack is not None:
            self.labelPosTrack.finish()
            self.labelPosTrack = None

        if self.logoScaleTrack is not None:
            self.logoScaleTrack.finish()
            self.logoScaleTrack = None

        if self.logoPosTrack is not None:
            self.logoPosTrack.finish()
            self.logoPosTrack = None

        if self.fadeTrack is not None:
            self.fadeTrack.finish()
            self.fadeTrack = None

        if self.versionLabel is not None:
            self.versionLabel.destroy()
            self.versionLabel = None

        if self.label is not None:
            self.label.destroy()
            self.label = None

        if self.logo is not None:
            self.logo.destroy()
            self.logo = None

        if self.backgroundNodePath is not None:
            self.backgroundNodePath.removeNode()
            self.backgroundNodePath = None

        if self.backgroundModel is not None:
            self.backgroundModel.removeNode()
            self.backgroundModel = None

    def start(self):
        base.transitions.fadeOut(t=0)

        self.setColorScale(Vec4(1, 1, 1, 1))

        if self.fadeTrack is not None:
            self.fadeTrack.finish()
            self.fadeTrack = None

        self.fadeTrack = base.transitions.getFadeInIval(t=2)
        self.fadeTrack.start()

        if self.logoScaleTrack is not None:
            self.logoScaleTrack.finish()
            self.logoScaleTrack = None

        self.logoScaleTrack = Sequence(
            LerpScaleInterval(self.logo, 2, Vec3(1.1, 1, 0.55), Vec3(1, 1, 0.5),
                              blendType='easeInOut'),
            LerpScaleInterval(self.logo, 2, Vec3(1, 1, 0.5), Vec3(1.1, 1, 0.55),
                              blendType='easeInOut')
        )

        if self.logoPosTrack is not None:
            self.logoPosTrack.finish()
            self.logoPosTrack = None

        self.logoPosTrack = Sequence(
            LerpPosInterval(self.logo, 2, Point3(0, 0, -0.85),
                            Point3(0, 0, -0.7), blendType='easeOut'),
            Func(self.logoScaleTrack.loop)
        )
        self.logoPosTrack.start()

        if self.labelColorScaleTrack is not None:
            self.labelColorScaleTrack.finish()
            self.labelColorScaleTrack = None

        self.labelColorScaleTrack = Sequence(
            LerpColorScaleInterval(self.label, 1, Vec4(1, 1, 1, 0.6),
                                   Vec4(1, 1, 1, 1)),
            LerpColorScaleInterval(self.label, 1, Vec4(1, 1, 1, 1),
                                   Vec4(1, 1, 1, 0.6))
        )

        if self.labelPosTrack is not None:
            self.labelPosTrack.finish()
            self.labelPosTrack = None

        self.labelPosTrack = Sequence(
            LerpPosInterval(self.label, 2, Point3(0, 0, 0.35),
                            Point3(0, 0, 0.15), blendType='easeOut'),
            Func(self.labelColorScaleTrack.loop)
        )
        self.labelPosTrack.start()

        self.acceptOnce('mouse1', self.begin)

    def stop(self):
        self.ignore('mouse1')

        if self.labelPosTrack is not None:
            self.labelPosTrack.finish()
            self.labelPosTrack = None

        if self.labelColorScaleTrack is not None:
            self.labelColorScaleTrack.finish()
            self.labelColorScaleTrack = None

        if self.logoPosTrack is not None:
            self.logoPosTrack.finish()
            self.logoPosTrack = None

        if self.logoScaleTrack is not None:
            self.logoScaleTrack.finish()
            self.logoScaleTrack = None

        if self.fadeTrack is not None:
            self.fadeTrack.finish()
            self.fadeTrack = None

        self.setColorScale(Vec4(0, 0, 0, 0))

    def begin(self):
        base.cr.introDone = True

        if self.fadeTrack is not None:
            self.fadeTrack.finish()
            self.fadeTrack = None

        self.fadeTrack = base.transitions.getFadeOutIval(t=2)

        Sequence(
            Func(self.fadeTrack.start),
            Wait(2),
            Func(self.delete),
            Func(base.cr.introduction.delete),
            Func(base.cr.loginFSM.request, 'chooseAvatar', [base.cr.avList]),
            Func(base.transitions.fadeIn, 2)
        ).start()

    def setColorScale(self, *args, **kwargs):
        self.backgroundNodePath.setColorScale(*args, **kwargs)
        self.logo.setColorScale(*args, **kwargs)
        self.label.setColorScale(*args, **kwargs)
        self.versionLabel.setColorScale(*args, **kwargs)
Exemple #3
0
class FPSCamera(DirectObject):

    MaxP = 90.0
    MinP = -90.0
    PitchUpdateEpsilon = 0.1
    ViewModelFOV = 70.0

    BobCycleMin = 1.0
    BobCycleMax = 0.45
    Bob = 0.002
    BobUp = 0.5

    PunchDamping = 9.0
    PunchSpring = 65.0

    PrintAnimLengths = False

    def __init__(self):
        DirectObject.__init__(self)

        self.mouseEnabled = False

        self.lastCamRoot2Quat = Quat(Quat.identQuat())

        self.punchAngleVel = Vec3(0)
        self.punchAngle = Vec3(0)

        self.lastFacing = Vec3(0)

        self.lastMousePos = Point2(0)
        self.currMousePos = Point2(0)

        self.bobTime = 0
        self.lastBobTime = 0

        self.lastVMPos = Point3(0)

        self.camRoot = NodePath("camRoot")
        self.camRoot2 = self.camRoot.attachNewNode("camRoot2")
        self.lastPitch = 0

        self.lastEyeHeight = 0.0

        # Updates to the transform of camRoot
        self.vmRender = NodePath(
            BSPRender('vmRender', BSPLoader.getGlobalPtr()))
        self.vmRender.setShaderAuto()
        self.vmRoot = self.vmRender.attachNewNode('vmRoot')
        self.vmRoot2 = self.vmRoot.attachNewNode(ModelRoot('vmRoot2'))
        self.viewModel = Actor(
            "phase_14/models/char/v_toon_arms.bam",
            {
                "zero": "phase_14/models/char/v_toon_arms.egg",

                # Squirt gun viewmodel animations
                "sg_draw": "phase_14/models/char/v_toon_arms-draw.egg",
                "sg_idle": "phase_14/models/char/v_toon_arms-idle.egg",
                "sg_inspect": "phase_14/models/char/v_toon_arms-inspect.egg",
                "sg_shoot_begin":
                "phase_14/models/char/v_toon_arms-shoot_begin.egg",
                "sg_shoot_loop":
                "phase_14/models/char/v_toon_arms-shoot_loop.egg",
                "sg_shoot_end":
                "phase_14/models/char/v_toon_arms-shoot_end.egg",
                "pie_draw": "phase_14/models/char/v_toon_arms-pie_draw.egg",
                "pie_idle": "phase_14/models/char/v_toon_arms-pie_idle.egg",
                "button_draw":
                "phase_14/models/char/v_toon_arms-button_draw.egg",
                "button_idle":
                "phase_14/models/char/v_toon_arms-button_idle.egg",
                "button_press":
                "phase_14/models/char/v_toon_arms-button_press.egg",
                "gumball_draw":
                "phase_14/models/char/v_toon_arms-gumball_draw.egg",
                "gumball_idle":
                "phase_14/models/char/v_toon_arms-gumball_idle.egg",
                "gumball_fire":
                "phase_14/models/char/v_toon_arms-gumball_fire.egg",
                "hose_draw": "phase_14/models/char/v_toon_arms-hose_draw.egg",
                "hose_idle": "phase_14/models/char/v_toon_arms-hose_idle.egg",
                "hose_shoot_begin":
                "phase_14/models/char/v_toon_arms-hose_shoot_begin.egg",
                "hose_shoot_loop":
                "phase_14/models/char/v_toon_arms-hose_shoot_loop.egg",
                "hose_shoot_end":
                "phase_14/models/char/v_toon_arms-hose_shoot_end.egg",
                "tnt_draw": "phase_14/models/char/v_toon_arms-tnt_draw.egg",
                "tnt_idle": "phase_14/models/char/v_toon_arms-tnt_idle.egg",
                "tnt_throw": "phase_14/models/char/v_toon_arms-tnt_throw.egg",
                "slap_idle": "phase_14/models/char/v_toon_arms-slap_idle.egg",
                "slap_hit": "phase_14/models/char/v_toon_arms-slap_hit.egg",
                "sound": "phase_14/models/char/v_toon_arms-sound.egg"
            })
        self.viewModel.setBlend(
            frameBlend=base.config.GetBool("interpolate-frames", False))
        self.viewModel.reparentTo(self.vmRoot2)
        self.viewModel.find("**/hands").setTwoSided(True)
        self.viewModel.hide()

        self.defaultViewModel = self.viewModel
        self.idealFov = self.ViewModelFOV

        precacheActor(self.viewModel)
        #self.viewModel.clearMaterial()
        #self.viewModel.setMaterial(CIGlobals.getCharacterMaterial(specular = (0, 0, 0, 1)), 1)
        self.viewportLens = PerspectiveLens()
        self.viewportLens.setMinFov(self.ViewModelFOV / (4. / 3.))
        self.viewportLens.setNear(0.3)
        # Updates to the transform of base.camera
        self.viewportCam = base.makeCamera(base.win,
                                           clearDepth=True,
                                           camName='fpsViewport',
                                           mask=CIGlobals.ViewModelCamMask,
                                           lens=self.viewportLens)
        # Pretend to be the main camera so the viewmodel gets ambient probes updated
        self.viewportCam.node().setTag("__mainpass__", "1")
        self.viewportCam.reparentTo(self.vmRoot)

        self.vmGag = None
        self.vmAnimTrack = None
        self.dmgFade = OnscreenImage(image="phase_14/maps/damage_effect.png",
                                     parent=render2d)
        self.dmgFade.setBin('gui-popup', 100)
        self.dmgFade.setTransparency(1)
        self.dmgFade.setColorScale(1, 1, 1, 0)
        self.dmgFadeIval = None

        #self.accept('v', self.vmRender.ls)

        #base.bspLoader.addDynamicNode(self.vmRoot)

        if self.PrintAnimLengths:
            print "v_toon_arms animation lengths:"
            for anim in self.viewModel.getAnimNames():
                print "\t{0}\t:\t{1}".format(anim,
                                             self.viewModel.getDuration(anim))

        taskMgr.add(self.__vpDebugTask, "vpdebutask", sort=-100)

    def setViewModelFOV(self, fov):
        self.idealFov = fov

    def restoreViewModelFOV(self):
        self.idealFov = self.ViewModelFOV

    def swapViewModel(self, newViewModel, fov=70.0):
        if newViewModel.isEmpty():
            return

        isHidden = False
        if not self.viewModel.isEmpty():
            self.viewModel.reparentTo(hidden)
            isHidden = self.viewModel.isHidden()

        self.viewModel = newViewModel
        self.viewModel.reparentTo(self.vmRoot2)
        if isHidden:
            self.viewModel.hide()
        else:
            self.viewModel.show()

        self.setViewModelFOV(fov)

    def restoreViewModel(self):
        isHidden = False
        if not self.viewModel.isEmpty():
            self.viewModel.reparentTo(hidden)
            isHidden = self.viewModel.isHidden()

        self.viewModel = self.defaultViewModel
        self.viewModel.reparentTo(self.vmRoot2)
        if isHidden:
            self.viewModel.hide()
        else:
            self.viewModel.show()

        self.restoreViewModelFOV()

    def addViewPunch(self, punch):
        self.punchAngleVel += punch * 20

    def resetViewPunch(self, tolerance=0.0):
        if tolerance != 0.0:
            tolerance *= tolerance
            check = self.punchAngleVel.lengthSquared(
            ) + self.punchAngle.lengthSquared()
            if check > tolerance:
                return

        self.punchAngle = Vec3(0)
        self.punchAngleVel = Vec3(0)

    def decayPunchAngle(self):
        if self.punchAngle.lengthSquared(
        ) > 0.001 or self.punchAngleVel.lengthSquared() > 0.001:
            dt = globalClock.getDt()
            self.punchAngle += self.punchAngleVel * dt
            damping = 1 - (self.PunchDamping * dt)

            if damping < 0:
                damping = 0
            self.punchAngleVel *= damping

            # Torsional spring
            springForceMag = self.PunchSpring * dt
            springForceMag = CIGlobals.clamp(springForceMag, 0.0, 2.0)
            self.punchAngleVel -= self.punchAngle * springForceMag

            # Don't wrap around
            self.punchAngle.set(CIGlobals.clamp(self.punchAngle[0], -179, 179),
                                CIGlobals.clamp(self.punchAngle[1], -89, 89),
                                CIGlobals.clamp(self.punchAngle[2], -89, 89))
        else:
            self.punchAngle = Vec3(0)
            self.punchAngleVel = Vec3(0)

    def hideViewModel(self):
        self.viewModel.hide(BitMask32.allOn())

    def showViewModel(self):
        if not base.localAvatar.isFirstPerson():
            return

        self.viewModel.showThrough(CIGlobals.ViewModelCamMask)

    def __vpDebugTask(self, task):
        if self.vmRender.getState() != render.getState():
            # pretend like the view model is part of the main scene
            self.vmRender.setState(render.getState())

        self.viewportLens.setAspectRatio(base.getAspectRatio())
        self.viewportLens.setMinFov(self.idealFov / (4. / 3.))
        self.vmRoot.setTransform(render, self.camRoot.getTransform(render))
        self.viewportCam.setTransform(render, base.camera.getTransform(render))

        # Since the viewmodel is not underneath BSPRender, it's not going to be automatically
        # influenced by the ambient probes. We need to do this explicitly.
        #base.bspLoader.updateDynamicNode(self.vmRoot)

        #self.viewportDebug.setImage(self.viewportCam.node().getDisplayRegion(0).getScreenshot())

        return task.cont

    def handleSuitAttack(self, attack):
        print "FPSCamera handleSuitAttack:", attack

    def doDamageFade(self, r, g, b, severity=1.0):
        if self.dmgFadeIval:
            self.dmgFadeIval.finish()
            self.dmgFadeIval = None
        severity = min(1.0, severity)
        self.dmgFadeIval = Sequence(
            LerpColorScaleInterval(self.dmgFade,
                                   0.25, (r, g, b, severity), (r, g, b, 0),
                                   blendType='easeOut'), Wait(1.0),
            LerpColorScaleInterval(self.dmgFade,
                                   2.0, (r, g, b, 0), (r, g, b, severity),
                                   blendType='easeInOut'))
        self.dmgFadeIval.start()

    def setVMAnimTrack(self, track, loop=False):
        self.clearVMAnimTrack()

        self.vmAnimTrack = track
        if loop:
            self.vmAnimTrack.loop()
        else:
            self.vmAnimTrack.start()

    def clearVMAnimTrack(self):
        if self.vmAnimTrack:
            self.vmAnimTrack.pause()
            self.vmAnimTrack = None

    def setVMGag(self,
                 gag,
                 pos=(0, 0, 0),
                 hpr=(0, 0, 0),
                 scale=(1, 1, 1),
                 hand=0,
                 animate=True):
        self.clearVMGag()

        handNode = NodePath()
        if hand == ATTACK_HOLD_RIGHT:
            handNode = self.getViewModelRightHand()
        elif hand == ATTACK_HOLD_LEFT:
            handNode = self.getViewModelLeftHand()

        if isinstance(gag, Actor) and animate:
            self.vmGag = Actor(other=gag)
            self.vmGag.reparentTo(handNode)
            self.vmGag.loop('chan')
        else:
            self.vmGag = gag.copyTo(handNode)
        self.vmGag.setPos(pos)
        self.vmGag.setHpr(hpr)
        self.vmGag.setScale(scale)

    def clearVMGag(self):
        if self.vmGag:
            if isinstance(self.vmGag, Actor):
                self.vmGag.cleanup()
            self.vmGag.removeNode()
            self.vmGag = None

    def setup(self):
        try:
            # Match the arm color with the torso color of local avatar
            self.viewModel.find("**/arms").setColorScale(
                base.localAvatar.getTorsoColor(), 1)
            # Same with glove cover
            self.viewModel.find("**/hands").setColorScale(
                base.localAvatar.getGloveColor(), 1)
        except:
            pass

        self.attachCamera()

    def attachCamera(self, reset=True):
        if reset:
            self.camRoot.reparentTo(base.localAvatar)
            if base.localAvatar.isFirstPerson():
                self.camRoot.setPos(base.localAvatar.getEyePoint())
            else:
                self.camRoot.setPos(0, 0, max(base.localAvatar.getHeight(),
                                              3.0))
            self.camRoot.setHpr(0, 0, 0)
            self.camRoot2.setPosHpr(0, 0, 0, 0, 0, 0)

        base.camera.reparentTo(self.camRoot2)

        if base.localAvatar.isFirstPerson():
            base.camera.setPosHpr(0, 0, 0, 0, 0, 0)
        elif base.localAvatar.isThirdPerson():
            pos, lookAt = self.getThirdPersonBattleCam()
            base.localAvatar.smartCamera.setIdealCameraPos(pos)
            base.localAvatar.smartCamera.setLookAtPoint(lookAt)

    def getThirdPersonBattleCam(self):
        camHeight = max(base.localAvatar.getHeight(), 3.0)
        heightScaleFactor = camHeight * 0.3333333333

        return ((1, -5 * heightScaleFactor, 0), (1, 10, 0))

    def getViewModelLeftHand(self):
        return self.viewModel.find("**/def_left_hold")

    def getViewModelRightHand(self):
        return self.viewModel.find("**/def_right_hold")

    def getViewModel(self):
        return self.viewModel

    def acceptEngageKeys(self):
        self.acceptOnce("escape", self.__handleEscapeKey)

    def ignoreEngageKeys(self):
        self.ignore("escape")

    def enableMouseMovement(self):
        props = WindowProperties()
        props.setMouseMode(WindowProperties.MConfined)
        props.setCursorHidden(True)
        base.win.requestProperties(props)

        self.attachCamera(False)
        if base.localAvatar.isFirstPerson():
            base.localAvatar.getGeomNode().hide()

        base.win.movePointer(0,
                             base.win.getXSize() / 2,
                             base.win.getYSize() / 2)

        base.taskMgr.add(self.__updateTask, "mouseUpdateFPSCamera", sort=-40)
        self.acceptEngageKeys()

        self.mouseEnabled = True

        base.localAvatar.enableGagKeys()

    def disableMouseMovement(self, allowEnable=False, showAvatar=True):
        props = WindowProperties()
        props.setMouseMode(WindowProperties.MAbsolute)
        props.setCursorHidden(False)
        base.win.requestProperties(props)

        base.taskMgr.remove("mouseUpdateFPSCamera")

        base.localAvatar.disableGagKeys()

        if allowEnable:
            self.acceptEngageKeys()
        else:
            self.ignoreEngageKeys()
            if showAvatar or base.localAvatar.isThirdPerson():
                base.localAvatar.getGeomNode().show()
            else:
                base.localAvatar.getGeomNode().hide()

        self.mouseEnabled = False

    def __handleEscapeKey(self):
        if self.mouseEnabled:
            self.disableMouseMovement(True)
        else:
            self.enableMouseMovement()

    #def doCameraJolt(self, amplitude, horizRange = [-1, 1], vertRange = [1]):
    #h = random.choice(horizRange) * amplitude
    #p = random.choice(vertRange) * amplitude
    #nquat = Quat(Quat.identQuat())
    #nquat.setHpr((h, p, 0))
    #self.lastCamRoot2Quat = self.lastCamRoot2Quat + nquat

    #Effects.createPBounce(self.camRoot2, 3, self.camRoot2.getHpr(), 1, amplitude).start()
    #Effects.createHBounce(self.camRoot2, 3, self.camRoot2.getHpr(), 1, amplitude).start()

    def handleJumpHardLand(self):
        down = Parallel(
            LerpPosInterval(base.cam,
                            0.1, (-0.1, 0, -0.2), (0, 0, 0),
                            blendType='easeOut'),
            LerpHprInterval(base.cam,
                            0.1, (0, 0, -2.5), (0, 0, 0),
                            blendType='easeOut'))
        up = Parallel(
            LerpPosInterval(base.cam,
                            0.7, (0, 0, 0), (-0.1, 0, -0.2),
                            blendType='easeInOut'),
            LerpHprInterval(base.cam,
                            0.7, (0, 0, 0), (0, 0, -2.5),
                            blendType='easeInOut'))
        Sequence(down, up).start()

    def __updateTask(self, task):
        # TODO -- This function does a lot of math, I measured it to take .5 ms on my laptop
        #         That's a lot of time for something miniscule like sway and bob.

        dt = globalClock.getDt()
        time = globalClock.getFrameTime()

        if base.localAvatar.isFirstPerson():
            eyePoint = base.localAvatar.getEyePoint()
            if base.localAvatar.walkControls.crouching:
                eyePoint[2] = eyePoint[2] / 2.0
            eyePoint[2] = CIGlobals.lerpWithRatio(eyePoint[2],
                                                  self.lastEyeHeight, 0.4)
            self.lastEyeHeight = eyePoint[2]

        camRootAngles = Vec3(0)

        # Mouse look around
        mw = base.mouseWatcherNode
        if mw.hasMouse():
            md = base.win.getPointer(0)
            center = Point2(base.win.getXSize() / 2, base.win.getYSize() / 2)

            xDist = md.getX() - center.getX()
            yDist = md.getY() - center.getY()

            sens = self.__getMouseSensitivity()

            angular = -(xDist * sens) / dt
            base.localAvatar.walkControls.controller.setAngularMovement(
                angular)
            camRootAngles.setY(self.lastPitch - yDist * sens)

            if camRootAngles.getY() > FPSCamera.MaxP:
                camRootAngles.setY(FPSCamera.MaxP)
                yDist = 0
            elif camRootAngles.getY() < FPSCamera.MinP:
                yDist = 0
                camRootAngles.setY(FPSCamera.MinP)

            base.win.movePointer(0, int(center.getX()), int(center.getY()))

        if base.localAvatar.isFirstPerson():
            # Camera / viewmodel bobbing
            vmBob = Point3(0)
            vmAngles = Vec3(0)
            vmRaise = Point3(0)
            camBob = Point3(0)

            maxSpeed = base.localAvatar.walkControls.BattleRunSpeed * 16.0

            speed = base.localAvatar.walkControls.speeds.length() * 16.0
            speed = max(-maxSpeed, min(maxSpeed, speed))

            bobOffset = CIGlobals.remapVal(speed, 0, maxSpeed, 0.0, 1.0)

            self.bobTime += (time - self.lastBobTime) * bobOffset
            self.lastBobTime = time

            # Calculate the vertical bob
            cycle = self.bobTime - int(
                self.bobTime / self.BobCycleMax) * self.BobCycleMax
            cycle /= self.BobCycleMax
            if cycle < self.BobUp:
                cycle = math.pi * cycle / self.BobUp
            else:
                cycle = math.pi + math.pi * (cycle - self.BobUp) / (1.0 -
                                                                    self.BobUp)

            verticalBob = speed * 0.005
            verticalBob = verticalBob * 0.3 + verticalBob * 0.7 * math.sin(
                cycle)
            verticalBob = max(-7.0, min(4.0, verticalBob))
            verticalBob /= 16.0

            # Calculate the lateral bob
            cycle = self.bobTime - int(
                self.bobTime / self.BobCycleMax * 2) * self.BobCycleMax * 2
            cycle /= self.BobCycleMax * 2
            if cycle < self.BobUp:
                cycle = math.pi * cycle / self.BobUp
            else:
                cycle = math.pi + math.pi * (cycle - self.BobUp) / (1.0 -
                                                                    self.BobUp)

            lateralBob = speed * 0.005
            lateralBob = lateralBob * 0.3 + lateralBob * 0.7 * math.sin(cycle)
            lateralBob = max(-7.0, min(4.0, lateralBob))
            lateralBob /= 16.0

            # Apply bob, but scaled down a bit
            vmBob.set(lateralBob * 0.8, 0, verticalBob * 0.1)
            # Z bob a bit more
            vmBob[2] += verticalBob * 0.1
            # Bob the angles
            vmAngles[2] += verticalBob * 0.5
            vmAngles[1] -= verticalBob * 0.4
            vmAngles[0] -= lateralBob * 0.3

            # ================================================================
            # Viewmodel lag/sway

            angles = self.camRoot.getHpr(render)
            quat = Quat()
            quat.setHpr(angles)
            invQuat = Quat()
            invQuat.invertFrom(quat)

            maxVMLag = 1.5
            lagforward = quat.getForward()
            if dt != 0.0:
                lagdifference = lagforward - self.lastFacing
                lagspeed = 5.0
                lagdiff = lagdifference.length()
                if (lagdiff > maxVMLag) and (maxVMLag > 0.0):
                    lagscale = lagdiff / maxVMLag
                    lagspeed *= lagscale

                self.lastFacing = CIGlobals.extrude(self.lastFacing,
                                                    lagspeed * dt,
                                                    lagdifference)
                self.lastFacing.normalize()
                lfLocal = invQuat.xform(lagdifference)
                vmBob = CIGlobals.extrude(vmBob, 5.0 / 16.0, lfLocal * -1.0)

            pitch = angles[1]
            if pitch > 180:
                pitch -= 360
            elif pitch < -180:
                pitch += 360

            vmBob = CIGlobals.extrude(vmBob, pitch * (0.035 / 16),
                                      Vec3.forward())
            vmBob = CIGlobals.extrude(vmBob, pitch * (0.03 / 16), Vec3.right())
            vmBob = CIGlobals.extrude(vmBob, pitch * (0.02 / 16), Vec3.up())

            # ================================================================

            vmRaise.set(
                0, 0, 0
            )  #(0, abs(camRootAngles.getY()) * -0.002, camRootAngles.getY() * 0.002)
            camBob.set(0, 0, 0)

            # Apply bob, raise, and sway to the viewmodel.
            self.viewModel.setPos(vmBob + vmRaise + self.lastVMPos)
            self.vmRoot2.setHpr(vmAngles)
            self.camRoot.setPos(eyePoint + camBob)

        newPitch = camRootAngles.getY()

        if abs(newPitch - self.lastPitch) > self.PitchUpdateEpsilon:
            # Broadcast where our head is looking
            head = base.localAvatar.getPart("head")
            if head and not head.isEmpty():
                # Constrain the head pitch a little bit so it doesn't look like their head snapped
                headPitch = max(-47, newPitch)
                headPitch = min(75, headPitch)
                base.localAvatar.b_setLookPitch(headPitch)

        self.lastPitch = newPitch

        if base.localAvatar.isFirstPerson():
            # Apply punch angle
            self.decayPunchAngle()
            camRootAngles += self.punchAngle

        self.camRoot.setHpr(camRootAngles)

        return task.cont

    def __getMouseSensitivity(self):
        return CIGlobals.getSettingsMgr().getSetting('fpmgms').getValue()

    def cleanup(self):
        taskMgr.remove("vpdebutask")
        self.disableMouseMovement(False, False)
        self.clearVMAnimTrack()
        self.clearVMGag()
        if self.viewModel:
            self.viewModel.cleanup()
            self.viewModel.removeNode()
        self.viewModel = None
        if self.vmRender:
            self.vmRender.removeNode()
        self.vmRender = None
        self.vmRoot = None
        self.vmRoot2 = None
        self.viewportLens = None
        if self.viewportCam:
            self.viewportCam.removeNode()
        self.viewportCam = None
        if self.camRoot:
            self.camRoot.removeNode()
        self.camRoot = None
        self.camRoot2 = None
        self.lastEyeHeight = None
        self.lastPitch = None
        self.bobTime = None
        self.lastBobTime = None
        self.mouseEnabled = None
        self.lastCamRoot2Quat = None
        self.punchAngleVel = None
        self.punchAngle = None
        self.lastFacing = None
        self.lastMousePos = None
        self.currMousePos = None
        self.lastVMPos = None
        self.defaultViewModel = None
        self.idealFov = None
        self.vmGag = None
        self.vmAnimTrack = None
        self.dmgFade = None
        self.dmgFadeIval = None
        self.ignoreAll()
Exemple #4
0
class DMenuScreen(DirectObject):
    notify = directNotify.newCategory('DMenuScreen')

    def __init__(self):
        DirectObject.__init__(self)
        base.cr.DMENU_SCREEN = self
        self.seq = None
        self.isSeqPlaying = False  # .isPlaying() doesnt want to work
        if DMENU_GAME == 'Toontown':
            base.cr.avChoice = None
        fadeSequence = Sequence(
            Func(base.transitions.fadeOut, .001), Wait(.5),
            Func(base.transitions.fadeIn, .5),
            base.camera.posHprInterval(1,
                                       Point3(MAIN_POS),
                                       VBase3(MAIN_HPR),
                                       blendType='easeInOut')).start()
        if DMENU_GAME == 'Toontown':
            self.background = loader.loadModel(
                'phase_3.5/models/modules/tt_m_ara_int_toonhall')
            self.background.reparentTo(render)
            self.background.setPosHpr(-25, 0, 8.1, -95, 0, 0)
            ropes = loader.loadModel(
                'phase_4/models/modules/tt_m_ara_int_ropes')
            ropes.reparentTo(self.background)
            self.sillyMeter = Actor.Actor(
                'phase_4/models/props/tt_a_ara_ttc_sillyMeter_default', {
                    'arrowTube':
                    'phase_4/models/props/tt_a_ara_ttc_sillyMeter_arrowFluid',
                    'phaseOne':
                    'phase_4/models/props/tt_a_ara_ttc_sillyMeter_phaseOne',
                    'phaseTwo':
                    'phase_4/models/props/tt_a_ara_ttc_sillyMeter_phaseTwo',
                    'phaseThree':
                    'phase_4/models/props/tt_a_ara_ttc_sillyMeter_phaseThree',
                    'phaseFour':
                    'phase_4/models/props/tt_a_ara_ttc_sillyMeter_phaseFour',
                    'phaseFourToFive':
                    'phase_4/models/props/tt_a_ara_ttc_sillyMeter_phaseFourToFive',
                    'phaseFive':
                    'phase_4/models/props/tt_a_ara_ttc_sillyMeter_phaseFive'
                })
            self.sillyMeter.reparentTo(self.background)
            self.sillyMeter.makeSubpart('arrow',
                                        ['uvj_progressBar*', 'def_springA'])
            self.sillyMeter.makeSubpart('meter', ['def_pivot'],
                                        ['uvj_progressBar*', 'def_springA'])
            self.audio3d = Audio3DManager.Audio3DManager(
                base.sfxManagerList[0], camera)

            self.phase3Sfx = self.audio3d.loadSfx(
                'phase_4/audio/sfx/tt_s_prp_sillyMeterPhaseThree.ogg')
            self.phase3Sfx.setLoop(True)
            self.arrowSfx = self.audio3d.loadSfx(
                'phase_4/audio/sfx/tt_s_prp_sillyMeterArrow.ogg')
            self.arrowSfx.setLoop(False)
            self.phase3Sfx.setVolume(0.2)
            self.arrowSfx.setVolume(0.2)

            self.animSeq = Sequence(
                Sequence(
                    ActorInterval(self.sillyMeter,
                                  'arrowTube',
                                  partName='arrow',
                                  constrainedLoop=0,
                                  startFrame=236,
                                  endFrame=247), Func(self.arrowSfx.play)),
                Parallel(
                    ActorInterval(self.sillyMeter,
                                  'arrowTube',
                                  partName='arrow',
                                  duration=604800,
                                  constrainedLoop=1,
                                  startFrame=247,
                                  endFrame=276),
                    Sequence(
                        Func(self.phase3Sfx.play),
                        Func(self.audio3d.attachSoundToObject, self.phase3Sfx,
                             self.sillyMeter))))
            self.animSeq.start()
            self.smPhase2 = self.sillyMeter.find('**/stage2')
            self.smPhase2.show()
            self.sillyMeter.loop('phaseOne', partName='meter')
            self.sillyMeter.setBlend(frameBlend=True)

            self.surlee = Toon.Toon()
            self.surlee.setName('Doctor Surlee')
            self.surlee.setPickable(0)
            self.surlee.setPlayerType(CCNonPlayer)
            dna = ToonDNA.ToonDNA()
            dna.newToonFromProperties('pls', 'ls', 'l', 'm', 9, 0, 9, 9, 98,
                                      27, 86, 27, 38, 27)
            self.surlee.setDNA(dna)
            self.surlee.loop('scientistGame')
            self.surlee.reparentTo(self.background)
            self.surlee.setPosHpr(13, 24, 0.025, -180, 0, 0)

            self.dimm = Toon.Toon()
            self.dimm.setName('Doctor Dimm')
            self.dimm.setPickable(0)
            self.dimm.setPlayerType(CCNonPlayer)
            dna = ToonDNA.ToonDNA()
            dna.newToonFromProperties('fll', 'ss', 's', 'm', 15, 0, 15, 15, 99,
                                      27, 86, 27, 39, 27)
            self.dimm.setDNA(dna)
            self.dimm.loop('scientistGame')
            self.dimm.reparentTo(self.background)
            self.dimm.setPosHpr(16, 24, 0.025, -180, 0, 0)

            surleeHand = self.surlee.find('**/def_joint_right_hold')
            clipBoard = loader.loadModel(
                'phase_4/models/props/tt_m_prp_acs_clipboard')
            surleeHandNode = surleeHand.attachNewNode('ClipBoard')
            clipBoard.instanceTo(surleeHandNode)
            surleeHandNode.setH(180)
            surleeHandNode.setScale(render, 1.0)
            surleeHandNode.setPos(0, 0, 0.1)

            dimmHand = self.dimm.find('**/def_joint_right_hold')
            sillyReader = loader.loadModel(
                'phase_4/models/props/tt_m_prp_acs_sillyReader')
            dimHandNode = dimmHand.attachNewNode('SillyReader')
            sillyReader.instanceTo(dimHandNode)
            dimHandNode.setH(180)
            dimHandNode.setScale(render, 1.0)
            dimHandNode.setPos(0, 0, 0.1)

            self.banana = self.background.find('**/gagBanana')

            self.bananaClicker = CollisionTraverser()
            #self.bananaClicker.showCollisions(render)
            self.collHandlerQueue = CollisionHandlerQueue()

            self.bananaRayNode = CollisionNode('bananaMouseRay')
            self.bananaRayNP = base.camera.attachNewNode(self.bananaRayNode)
            self.bananaRayNode.setIntoCollideMask(BitMask32.bit(0))
            self.bananaRayNode.setFromCollideMask(BitMask32.bit(1))
            self.banana.setCollideMask(BitMask32.bit(1))
            self.ray = CollisionRay()
            self.bananaRayNode.addSolid(self.ray)
            self.bananaClicker.addCollider(self.bananaRayNP,
                                           self.collHandlerQueue)
            self.accept("mouse1", self.slipAndSlideOnThisBananaPeelHaHaHa)

            for frame in render.findAllMatches('*/doorFrame*'):
                frame.removeNode()
            self.sky = loader.loadModel('phase_3.5/models/props/TT_sky')
            SkyUtil.startCloudSky(self)
            base.camera.setPosHpr(MAIN_POS, MAIN_HPR)

        self.logo = OnscreenImage(image=GameLogo, scale=(.5, .5, .25))
        self.logo.reparentTo(aspect2d)
        self.logo.setTransparency(TransparencyAttrib.MAlpha)
        scale = self.logo.getScale()
        self.logo.setPos(0, 0, .5)
        self.logo.setColorScale(Vec4(0, 0, 0, 0))
        fadeInLogo = (LerpColorScaleInterval(self.logo, 1, Vec4(1, 1, 1, 1),
                                             Vec4(1, 1, 1, 0))).start()

        self.createButtons()

        self.fadeOut = None
        self.optionsMgr = PickAToonOptions.NewPickAToonOptions()
        #self.quitConfirmation = DMenuQuit()
        self.patNode = None

        if DMENU_GAME == 'Toontown':
            # TT: We need these to run the Pick A Toon screen
            self.patAvList = base.cr.PAT_AVLIST
            self.patFSM = base.cr.PAT_LOGINFSM
            self.patDoneEvent = base.cr.PAT_DONEEVENT

    def slipAndSlideOnThisBananaPeelHaHaHa(self):
        if base.mouseWatcherNode.hasMouse():
            mpos = base.mouseWatcherNode.getMouse()

            def setPlayingStatus(status):
                self.isSeqPlaying = status

            self.ray.setFromLens(base.camNode, mpos.getX(), mpos.getY())
            self.bananaClicker.traverse(render)

            if self.collHandlerQueue.getNumEntries() > 0:
                self.collHandlerQueue.sortEntries()
                pickedObj = self.collHandlerQueue.getEntry(0).getIntoNodePath()
                surleeAnim = random.choice(['slip-backward', 'slip-forward'])
                dimmAnim = random.choice(['slip-backward', 'slip-forward'])
                if pickedObj == self.banana:
                    self.seq = Sequence(
                        Func(setPlayingStatus, True),
                        Func(self.surlee.play, surleeAnim),
                        Func(self.dimm.play, dimmAnim), Wait(3),
                        Func(self.surlee.loop, 'scientistGame'),
                        Func(self.dimm.loop, 'scientistGame'),
                        Func(setPlayingStatus, False))
                    if not self.isSeqPlaying:
                        self.seq.start()

    def skyTrack(self, task):
        return SkyUtil.cloudSkyTrack(task)

    def createButtons(self):
        buttonImage = GuiModel.find('**/QuitBtn_RLVR')

        self.PlayButton = DirectButton(relief=None,
                                       text_style=3,
                                       text_fg=(1, 1, 1, 1),
                                       text=PlayGame,
                                       text_scale=.1,
                                       scale=0.95,
                                       command=self.playGame)
        self.PlayButton.reparentTo(aspect2d)
        self.PlayButton.setPos(PlayBtnHidePos)
        self.PlayButton.show()

        self.OptionsButton = DirectButton(relief=None,
                                          text_style=3,
                                          text_fg=(1, 1, 1, 1),
                                          text=Options,
                                          text_scale=.1,
                                          scale=0.95,
                                          command=self.openOptions)
        self.OptionsButton.reparentTo(aspect2d)
        self.OptionsButton.setPos(OptionsBtnHidePos)
        self.OptionsButton.show()

        self.QuitButton = DirectButton(relief=None,
                                       text_style=3,
                                       text_fg=(1, 1, 1, 1),
                                       text=Quit,
                                       text_scale=.1,
                                       scale=0.95,
                                       command=self.quitGame)
        self.QuitButton.reparentTo(aspect2d)
        self.QuitButton.setPos(QuitBtnHidePos)
        self.QuitButton.show()

        # self.BRButton = DirectButton(text = 'REPORT BUG', text_scale = .1, scale=0.95)
        # self.BRButton.reparentTo(aspect2d)
        # self.BRButton.setPos(-.9, 0, -.9)
        # self.BRButton.show()

        self.buttonInAnimation()

    def murder(self):
        if self.logo is not None:
            self.logo.destroy()
            self.logo = None

        if self.background is not None:
            self.background.hide()
            self.background.reparentTo(hidden)
            self.background.removeNode()
            self.background = None

        if self.PlayButton is not None:
            self.PlayButton.destroy()
            self.PlayButton = None

        if self.OptionsButton is not None:
            self.OptionsButton.destroy()
            self.OptionsButton = None

        if self.QuitButton is not None:
            self.QuitButton.destroy()
            self.QuitButton = None

        if self.phase3Sfx:
            self.phase3Sfx.stop()
            del self.phase3Sfx

        if self.surlee:
            self.surlee.delete()
        if self.dimm:
            self.dimm.delete()

        del self.bananaRayNode
        del self.bananaRayNP
        del self.bananaClicker
        del self.collHandlerQueue
        del self.ray

        self.ignoreAll()

        taskMgr.remove('skyTrack')
        self.sky.reparentTo(hidden)

    def openOptions(self):
        self.optionsMgr.showOptions()
        self.closeOptionsButton = DirectButton(
            relief=None,
            image=(btnUp, btnDn, btnRlvr),
            text="Back",
            text_fg=(0, 0, 0, 1),
            text_scale=TTLocalizer.AClogoutButton,
            text_pos=(0, -0.035),
            image_scale=1,
            image1_scale=1.05,
            image2_scale=1.05,
            scale=0.7,
            command=self.hideOptions)
        self.closeOptionsButton.reparentTo(base.a2dTopLeft)
        self.closeOptionsButton.setPos(0.5, 0, -0.07)
        Parallel(
            self.PlayButton.posInterval(.5,
                                        Point3(PlayBtnHidePos),
                                        blendType='easeInOut'),
            self.OptionsButton.posInterval(.5,
                                           Point3(OptionsBtnHidePos),
                                           blendType='easeInOut'),
            self.QuitButton.posInterval(.5,
                                        Point3(QuitBtnHidePos),
                                        blendType='easeInOut'),
            self.logo.posInterval(0.5,
                                  Point3(0, 0, 2.5),
                                  blendType='easeInOut')).start()

    def hideOptions(self):
        self.optionsMgr.hideOptions()
        self.closeOptionsButton.hide()
        self.buttonInAnimation()

    def playGame(self):
        if self.fadeOut is not None:
            self.fadeOut.finish()
            self.fadeOut = None
        self.fadeOut = base.transitions.getFadeOutIval(t=1)
        #base.camera.posHprInterval(1, Point3(TOON_HALL_POS), VBase3(TOON_HALL_HPR), blendType = 'easeInOut').start()
        Sequence(
            Func(self.doPlayButton),
            Wait(1),
            #Func(self.murder),
            Func(self.enterGame)).start()
        #Func(base.transitions.fadeIn, 1)).start()

    def enterOptions(self):
        pass

    def enterGame(self):
        base.cr.avChoice = PickAToon.PickAToon(self.patAvList, self.patFSM,
                                               self.patDoneEvent)
        base.cr.avChoice.load()
        base.cr.avChoice.enter()

    def doPlayButton(self):
        Parallel(
            self.PlayButton.posInterval(1,
                                        Point3(PlayBtnHidePos),
                                        blendType='easeInOut'),
            self.OptionsButton.posInterval(1,
                                           Point3(OptionsBtnHidePos),
                                           blendType='easeInOut'),
            self.QuitButton.posInterval(1,
                                        Point3(QuitBtnHidePos),
                                        blendType='easeInOut'),
            self.logo.posInterval(0.5,
                                  Point3(0, 0, 2.5),
                                  blendType='easeInOut')).start()

    def quitGame(self):
        self.showQuitConfirmation()

    def showQuitConfirmation(self):
        #self.quitConfirmation.showConfirmation()
        base.exitFunc()

    def buttonInAnimation(self):
        logo = self.logo.posInterval(.5,
                                     Point3(0, 0, .5),
                                     blendType='easeInOut')
        play = self.PlayButton.posInterval(.5,
                                           Point3(PlayBtnPos),
                                           blendType='easeInOut')
        opt = self.OptionsButton.posInterval(.5,
                                             Point3(OptionsBtnPos),
                                             blendType='easeInOut')
        quit = self.QuitButton.posInterval(.5,
                                           Point3(QuitBtnPos),
                                           blendType='easeInOut')

        Sequence(Func(logo.start), Wait(0.1), Func(play.start), Wait(0.2),
                 Func(opt.start), Wait(0.2), Func(quit.start)).start()

    def showHamburgerMenu(self):
        self.hbButton.hide()
        self.hbHideButton.show()

        self.patNode2d = aspect2d.find("**/patNode2d")
        self.patNode2d.posInterval(.5, Point3(.5, 0, 0),
                                   blendType='easeInOut').start()

        self.patNode = render.find("**/patNode")
        self.patNode.posInterval(.5, Point3(0, -3, 0),
                                 blendType='easeInOut').start()

    def hideHamburgerMenu(self):
        self.hbButton.show()
        self.hbHideButton.hide()

        self.patNode2d.posInterval(.5, Point3(0, 0, 0),
                                   blendType='easeInOut').start()

        self.patNode.posInterval(.5, Point3(0, 0, 0),
                                 blendType='easeInOut').start()

    def reportBug(self):
        BugReportGUI.BugReportGUI()

    def createTabs(self):
        self.PlayButton = DirectButton(relief=None,
                                       text_style=3,
                                       text_fg=(1, 1, 1, 1),
                                       text=PlayGame,
                                       text_scale=.1,
                                       scale=0.95,
                                       command=self.playGame)
        self.PlayButton.reparentTo(aspect2d)
        self.PlayButton.setPos(PlayBtnHidePos)
        self.PlayButton.show()

        self.OptionsButton = DirectButton(relief=None,
                                          text_style=3,
                                          text_fg=(1, 1, 1, 1),
                                          text=Options,
                                          text_scale=.1,
                                          scale=0.95,
                                          command=self.openOptions)
        self.OptionsButton.reparentTo(aspect2d)
        self.OptionsButton.setPos(OptionsBtnHidePos)
        self.OptionsButton.show()

        self.QuitButton = DirectButton(relief=None,
                                       text_style=3,
                                       text_fg=(1, 1, 1, 1),
                                       text=Quit,
                                       text_scale=.1,
                                       scale=0.95,
                                       command=self.quitGame)
        self.QuitButton.reparentTo(aspect2d)
        self.QuitButton.setPos(QuitBtnHidePos)
        self.QuitButton.show()
Exemple #5
0
class ClickToStart(DirectObject):
    notify = directNotify.newCategory('ClickToStart')

    def __init__(self, version='n/a'):
        DirectObject.__init__(self)

        self.backgroundNodePath = render2d.attachNewNode('background', 0)
        self.backgroundModel = loader.loadModel(
            'phase_3/models/gui/loading-background.bam')
        self.backgroundModel.reparentTo(self.backgroundNodePath)
        self.backgroundNodePath.find('**/fg').removeNode()
        self.backgroundNodePath.setScale(1, 1, 1)

        self.logo = OnscreenImage(parent=base.a2dTopCenter,
                                  image='phase_3/maps/toontown-logo.png',
                                  scale=(1.0, 1, 0.5),
                                  pos=(0, 0, -0.85))
        self.logo.setTransparency(TransparencyAttrib.MAlpha)

        self.label = OnscreenText(TTLocalizer.ClickToStartLabel,
                                  parent=base.a2dBottomCenter,
                                  font=ToontownGlobals.getMinnieFont(),
                                  fg=Vec4(1, 1, 1, 1),
                                  scale=0.1,
                                  align=TextNode.ACenter)
        self.label.setZ(0.35)

        self.versionLabel = OnscreenText('\x01white_shadow\x01%s\x02' %
                                         version,
                                         parent=base.a2dBottomRight,
                                         font=ToontownGlobals.getMinnieFont(),
                                         fg=Vec4(0, 0, 0, 1),
                                         scale=0.06,
                                         align=TextNode.ARight)
        self.versionLabel.setPos(-0.025, 0.025)

        self.setColorScale(Vec4(0, 0, 0, 0))

        self.fadeTrack = None
        self.logoPosTrack = None
        self.logoScaleTrack = None
        self.labelPosTrack = None
        self.labelColorScaleTrack = None

    def delete(self):
        if self.labelColorScaleTrack is not None:
            self.labelColorScaleTrack.finish()
            self.labelColorScaleTrack = None

        if self.labelPosTrack is not None:
            self.labelPosTrack.finish()
            self.labelPosTrack = None

        if self.logoScaleTrack is not None:
            self.logoScaleTrack.finish()
            self.logoScaleTrack = None

        if self.logoPosTrack is not None:
            self.logoPosTrack.finish()
            self.logoPosTrack = None

        if self.fadeTrack is not None:
            self.fadeTrack.finish()
            self.fadeTrack = None

        if self.versionLabel is not None:
            self.versionLabel.destroy()
            self.versionLabel = None

        if self.label is not None:
            self.label.destroy()
            self.label = None

        if self.logo is not None:
            self.logo.destroy()
            self.logo = None

        if self.backgroundNodePath is not None:
            self.backgroundNodePath.removeNode()
            self.backgroundNodePath = None

        if self.backgroundModel is not None:
            self.backgroundModel.removeNode()
            self.backgroundModel = None

    def start(self):
        base.transitions.fadeOut(t=0)

        self.setColorScale(Vec4(1, 1, 1, 1))

        if self.fadeTrack is not None:
            self.fadeTrack.finish()
            self.fadeTrack = None

        self.fadeTrack = base.transitions.getFadeInIval(t=2)
        self.fadeTrack.start()

        if self.logoScaleTrack is not None:
            self.logoScaleTrack.finish()
            self.logoScaleTrack = None

        self.logoScaleTrack = Sequence(
            LerpScaleInterval(self.logo,
                              2,
                              Vec3(1.1, 1, 0.55),
                              Vec3(1, 1, 0.5),
                              blendType='easeInOut'),
            LerpScaleInterval(self.logo,
                              2,
                              Vec3(1, 1, 0.5),
                              Vec3(1.1, 1, 0.55),
                              blendType='easeInOut'))

        if self.logoPosTrack is not None:
            self.logoPosTrack.finish()
            self.logoPosTrack = None

        self.logoPosTrack = Sequence(
            LerpPosInterval(self.logo,
                            2,
                            Point3(0, 0, -0.85),
                            Point3(0, 0, -0.7),
                            blendType='easeOut'),
            Func(self.logoScaleTrack.loop))
        self.logoPosTrack.start()

        if self.labelColorScaleTrack is not None:
            self.labelColorScaleTrack.finish()
            self.labelColorScaleTrack = None

        self.labelColorScaleTrack = Sequence(
            LerpColorScaleInterval(self.label, 1, Vec4(1, 1, 1, 0.6),
                                   Vec4(1, 1, 1, 1)),
            LerpColorScaleInterval(self.label, 1, Vec4(1, 1, 1, 1),
                                   Vec4(1, 1, 1, 0.6)))

        if self.labelPosTrack is not None:
            self.labelPosTrack.finish()
            self.labelPosTrack = None

        self.labelPosTrack = Sequence(
            LerpPosInterval(self.label,
                            2,
                            Point3(0, 0, 0.35),
                            Point3(0, 0, 0.15),
                            blendType='easeOut'),
            Func(self.labelColorScaleTrack.loop))
        self.labelPosTrack.start()

        self.acceptOnce('mouse1', self.begin)

    def stop(self):
        self.ignore('mouse1')

        if self.labelPosTrack is not None:
            self.labelPosTrack.finish()
            self.labelPosTrack = None

        if self.labelColorScaleTrack is not None:
            self.labelColorScaleTrack.finish()
            self.labelColorScaleTrack = None

        if self.logoPosTrack is not None:
            self.logoPosTrack.finish()
            self.logoPosTrack = None

        if self.logoScaleTrack is not None:
            self.logoScaleTrack.finish()
            self.logoScaleTrack = None

        if self.fadeTrack is not None:
            self.fadeTrack.finish()
            self.fadeTrack = None

        self.setColorScale(Vec4(0, 0, 0, 0))

    def begin(self):
        base.cr.introDone = True

        if self.fadeTrack is not None:
            self.fadeTrack.finish()
            self.fadeTrack = None

        self.fadeTrack = base.transitions.getFadeOutIval(t=2)

        Sequence(
            Func(self.fadeTrack.start), Wait(2), Func(self.delete),
            Func(base.cr.introduction.delete),
            Func(base.cr.loginFSM.request, 'chooseAvatar', [base.cr.avList]),
            Func(base.transitions.fadeIn, 2)).start()

    def setColorScale(self, *args, **kwargs):
        self.backgroundNodePath.setColorScale(*args, **kwargs)
        self.logo.setColorScale(*args, **kwargs)
        self.label.setColorScale(*args, **kwargs)
        self.versionLabel.setColorScale(*args, **kwargs)
class DMenuScreen(DirectObject):
    notify = directNotify.newCategory('DMenuScreen')

    def __init__(self):#, avatarList, parentFSM, doneEvent):
        DirectObject.__init__(self)
        base.disableMouse()
        #base.cr.avChoice = None
        fadeSequence = Sequence(
            Wait(.5),
            Func(base.transitions.fadeIn, .5),
            Wait(1)).start()#,
            #base.camera.posHprInterval(1, Point3(MAIN_POS), VBase3(MAIN_HPR), blendType = 'easeInOut')).start()
        #self.background = loader.loadModel('phase_4/models/neighborhoods/toontown_central_full')
        #self.background.reparentTo(render)
        #for frame in render.findAllMatches('*/doorFrame*'):
        #    frame.removeNode()
        #self.sky = loader.loadModel('phase_3.5/models/props/TT_sky')
        #SkyUtil.startCloudSky(self)

        #base.camera.setPosHpr(INIT_POS, INIT_HPR)
        self.background = OnscreenImage(image = DMenuResources.MenuBackground, parent = aspect2d)
        self.background.setBin('background', 1)
        self.background.reparentTo(aspect2d)
        self.background.setScale(2, 1, 1)
        
        self.logo = OnscreenImage(image = DMenuResources.GameLogo, scale = (1, 1, .5))
        self.logo.reparentTo(aspect2d)
        self.logo.setTransparency(TransparencyAttrib.MAlpha)
        scale = self.logo.getScale()
        self.logo.setPos(0, 0, .5)
        self.logo.setColorScale(Vec4(0, 0, 0, 0))

        #fadeInBackground = (LerpColorScaleInterval(self.background, 1, Vec4(1, 1, 1, 1), Vec4(1, 1, 1, 0))).start()
        fadeInLogo = (LerpColorScaleInterval(self.logo, 1, Vec4(1, 1, 1, 1), Vec4(1, 1, 1, 0))).start()

        self.createButtons()

        self.fadeOut = None
        self.optionsMgr = DMenuOptions.DMenuOptions()
        self.quitConfirmation = DMenuQuit.DMenuQuit()

        # TT: We need these to run the Pick A Toon screen
        #self.patAvList = avatarList
        #self.patFSM = parentFSM
        #self.patDoneEvent = doneEvent
        
        self.transcircle = Resources.transcircle
        self.transcircle.setTransparency(TransparencyAttrib.MAlpha)
        self.transcircle.setScale(VBase3(0.01, 0.01, 0.01))
        self.transcircle.setBin('background', 3)
        
        self.savemgr = LOTASaveMgr.LOTASaveMgr()
        
        # Get the save data
        self.savePos = self.savemgr.loadSaveData()
        
        self.titleMusic = Resources.titleMusic
        self.titleMusic.setLoop(1)
        self.setMusicNormal()

    def skyTrack(self, task):
    #    return SkyUtil.cloudSkyTrack(task)
        pass

    def createButtons(self):
        self.PlayButton = DirectButton(relief = None, text_style = 3, text_fg = (1, 1, 1, 1), text = DMenuLocalizer.PlayGame, text_scale = .1, scale = 0.95, command = self.playGame)
        self.PlayButton.reparentTo(aspect2d)
        self.PlayButton.setPos(PlayBtnHidePos)
        self.PlayButton.show()

        self.OptionsButton = DirectButton(relief = None, text_style = 3, text_fg = (1, 1, 1, 1), text = DMenuLocalizer.Options, text_scale = .1, scale = 0.95, command = self.openOptions)
        self.OptionsButton.reparentTo(aspect2d)
        self.OptionsButton.setPos(OptionsBtnHidePos)
        self.OptionsButton.show()

        self.QuitButton = DirectButton(relief = None, text_style = 3, text_fg = (1, 1, 1, 1), text = DMenuLocalizer.Quit, text_scale = .1, scale = 0.95, command = self.quitGame)
        self.QuitButton.reparentTo(aspect2d)
        self.QuitButton.setPos(QuitBtnHidePos)
        self.QuitButton.show()


        # self.BRButton = DirectButton(text = 'REPORT BUG', text_scale = .1, scale=0.95)
        # self.BRButton.reparentTo(aspect2d)
        # self.BRButton.setPos(-.9, 0, -.9)
        # self.BRButton.show()
        
        self.buttonInAnimation()
        
        # Slap on the saves menu from the old main menu until a proper implementation to DMENU is made
        self.SavesButton = DirectButton(relief = None, text = AmdLocalizerEnglish.LOTA_SAVES, image_scale = 2, text_scale = .1, scale = 0.95, command = self.openSavesMenu)
        self.SavesButton.reparentTo(aspect2d)
        self.SavesButton.setPos(0, 0, -.5)
        self.SavesButton.show()

    def murder(self):
        if self.logo is not None:
            self.logo.destroy()
            self.logo = None

        if self.background is not None:
            self.background.hide()
            self.background.reparentTo(hidden)
            self.background.removeNode()
            self.background = None

        if self.PlayButton is not None:
            self.PlayButton.destroy()
            self.PlayButton = None

        if self.OptionsButton is not None:
            self.OptionsButton.destroy()
            self.OptionsButton = None

        if self.QuitButton is not None:
            self.QuitButton.destroy()
            self.QuitButton = None
            
        if self.SavesButton is not None:
            self.SavesButton.destroy()
            self.SavesButton = None
            
        if self.titleMusic is not None:
            self.titleMusic.stop()

        #taskMgr.remove('skyTrack')
        #self.sky.reparentTo(hidden)

    def openOptions(self):
        self.optionsMgr.showOptions()
        self.closeOptionsButton = DirectButton(relief = None, text = "< Back", text_fg = (0.977, 0.816, 0.133, 1), text_pos = (0, -0.035), scale = .1, command = self.hideOptions)
        self.closeOptionsButton.reparentTo(base.a2dTopLeft)
        self.closeOptionsButton.setPos(0.5, 0, -0.07)
        Parallel(
            self.PlayButton.posInterval(.5, Point3(PlayBtnHidePos), blendType = 'easeInOut'),
            self.OptionsButton.posInterval(.5, Point3(OptionsBtnHidePos), blendType = 'easeInOut'),
            self.QuitButton.posInterval(.5, Point3(QuitBtnHidePos), blendType = 'easeInOut'),
            self.logo.posInterval(0.5, Point3(0, 0, 2.5), blendType = 'easeInOut')).start()
        #base.camera.posHprInterval(0.5, Point3(HQ_POS), VBase3(HQ_HPR), blendType = 'easeInOut').start()
        #self.setMusicCalm()

    def hideOptions(self):
        self.optionsMgr.hideOptions()
        self.closeOptionsButton.hide()
        Parallel(
            self.PlayButton.posInterval(.5, Point3(PlayBtnPos), blendType = 'easeInOut'),
            self.OptionsButton.posInterval(.5, Point3(OptionsBtnPos), blendType = 'easeInOut'),
            self.QuitButton.posInterval(.5, Point3(QuitBtnPos), blendType = 'easeInOut'),
            self.logo.posInterval(.5, Point3(0, 0, .5), blendType = 'easeInOut')).start()
        base.camera.posHprInterval(0.5, Point3(MAIN_POS), VBase3(MAIN_HPR), blendType = 'easeInOut').start()
        #self.setMusicNormal()

    def playGame(self):
        if self.fadeOut is not None:
            self.fadeOut.finish()
            self.fadeOut = None
        self.fadeOut = base.transitions.getFadeOutIval(t = 1)
        #base.camera.posHprInterval(1, Point3(TOON_HALL_POS), VBase3(TOON_HALL_HPR), blendType = 'easeInOut').start()
        Sequence(
            Func(self.doPlayButton),
            #Func(self.fadeOut.start),
            Wait(1),
            Func(self.murder),
            Wait(1),
            Func(self.enterGame)).start()#,
            #Func(base.transitions.fadeIn, 1)).start()

    def enterOptions(self):
        pass

    def enterGame(self):
        #base.cr.avChoice = AvatarChooser.AvatarChooser(self.patAvList, self.patFSM, self.patDoneEvent)
        #base.cr.avChoice.load(1)
        #base.cr.avChoice.enter()
        from Game.NewGame.Scenes import SceneOne
        # Hamburger Menu Button
        #self.hbButton = DirectButton(image = "phase_3/maps/dmenu/dmhbmenu.png", relief = None, text = ' ', command=self.showHamburgerMenu)
        #self.hbButton.reparentTo(base.a2dTopLeft)
        #self.hbButton.setPos(0.05, 0, -0.05)
        #self.hbButton.setScale(0.04)

        # Hamburger Menu Hide Button
        #self.hbHideButton = DirectButton(image = "phase_3/maps/dmenu/close_window.png", relief = None, text = ' ', command=self.hideHamburgerMenu)
        #self.hbHideButton.reparentTo(base.a2dTopLeft)
        #self.hbHideButton.setPos(0.05, 0, -0.05)
        #self.hbHideButton.setScale(0.04)
        #self.hbHideButton.hide()

        # TODO: Add options and stuff to the hamburger menu

    def doPlayButton(self):
        Parallel(
            self.PlayButton.posInterval(1, Point3(PlayBtnHidePos), blendType = 'easeInOut'),
            self.OptionsButton.posInterval(1, Point3(OptionsBtnHidePos), blendType = 'easeInOut'),
            self.QuitButton.posInterval(1, Point3(QuitBtnHidePos), blendType = 'easeInOut'),
            self.logo.posInterval(0.5, Point3(0, 0, 2.5), blendType = 'easeInOut')).start()

    def quitGame(self):
        self.showQuitConfirmation()

    def showQuitConfirmation(self):
        self.quitConfirmation.showConfirmation()
        #base.exitFunc()

    def setMusicNormal(self):
        #LerpFunctionInterval(base.cr.music.setVolume, fromData = 0, toData = .9, duration = 1).start()
        #LerpFunctionInterval(base.cr.musicCalm.setVolume, fromData = .9, toData = 0, duration = 1).start()
        self.titleMusic.play()

    def setMusicCalm(self):
        LerpFunctionInterval(base.cr.music.setVolume, fromData = .9, toData = 0, duration = 1).start()
        LerpFunctionInterval(base.cr.musicCalm.setVolume, fromData = 0, toData = .9, duration = 1).start()

    def openSavesMenu(self):
        self.saveOne = DirectButton(relief=None, text = 'Save One: ' + '(Scene ' + str(self.savePos) + ')', scale=0.3, command=self.saveLoader, parent=aspect2d, pos=(0, 0, -.6), text_scale = .5)
        self.saveOne.hide()
        self.transcircle.show()
        self.exitLoadButton = DirectButton(relief=None, text = '< Back', scale=0.3, command=self.closeSavesMenu, parent=base.a2dBottomCenter, pos=(0, 0, -.4), text_scale = .5)
        self.exitLoadButton.show()

        
        self.openSavesMenuSequence = Parallel(
            self.transcircle.scaleInterval(0.5, VBase3(3, 3, 3), blendType = 'easeInOut'),
            self.exitLoadButton.posInterval(0.5, Point3(0, 0, .4), blendType = 'easeInOut'),
            Func(self.saveOne.show),
            self.saveOne.posInterval(0.5, Point3(0, 0, .2), blendType = 'easeInOut'))
        self.openSavesMenuSequence.start()
        
    def closeSavesMenu(self):
        self.hideThings = Sequence(
            Wait(0.5),
            Func(self.saveOne.hide),
            Func(self.transcircle.hide))
    
        self.closeSavesMenuSequence = Parallel(
            self.saveOne.posInterval(0.5, Point3(0, 0, -.6), blendType = 'easeInOut'),
            self.transcircle.scaleInterval(0.5, VBase3(0.01, 0.01, 0.01), blendType = 'easeInOut'),
            self.exitLoadButton.posInterval(0.5, Point3(0, 0, -.4), blendType = 'easeInOut'),
            Func(self.hideThings.start))
        self.closeSavesMenuSequence.start()
        self.exitLoadButton.removeNode()
        del self.exitLoadButton
        
    def saveLoader(self):
        # this was thrown together in like 10 seconds. how the f**k does this work
        # TODO: Make this save to a file thats not easily editable
        self.saveOne.hide()
        self.background.hide()
        self.transcircle.hide()
        if self.savePos == '1':
            from Game.NewGame.Scenes import SceneOne
        elif self.savePos == '2':
            from Game import SceneTwo
        elif self.savePos == '3':
            from Game import SceneThree
        elif self.savePos == '4':
            from Game import SceneFour
        elif self.savePos == '5':
            from Game import SceneFive
        else:
            print ("\n\n Save data is set to an unknown scene!!\n\n")
            
    def buttonInAnimation(self):
        logo = self.logo.posInterval(.5, Point3(0, 0, .5), blendType = 'easeInOut')
        play = self.PlayButton.posInterval(.5, Point3(PlayBtnPos), blendType = 'easeInOut')
        opt = self.OptionsButton.posInterval(.5, Point3(OptionsBtnPos), blendType = 'easeInOut')
        quit = self.QuitButton.posInterval(.5, Point3(QuitBtnPos), blendType = 'easeInOut')
        
        Sequence(
                 Func(logo.start),
                 Wait(0.1),
                 Func(play.start),
                 Wait(0.2),
                 Func(opt.start),
                 Wait(0.2),
                 Func(quit.start)).start()
                 
    def showHamburgerMenu(self):
        self.hbButton.hide()
        self.hbHideButton.show()
        
    def hideHamburgerMenu(self):
        self.hbButton.show()
        self.hbHideButton.hide()
Exemple #7
0
class CameraShyFirstPerson(FirstPerson):
    notify = directNotify.newCategory("CameraShyFirstPerson")

    defaultColor = VBase4(1.0, 1.0, 1.0, 1.0)
    toonInFocusColor = VBase4(0.0, 0.7, 0.0, 1.0)
    toonOutOfFocusColor = VBase4(0.25, 1.0, 0.25, 1.0)
    redColor = VBase4(0.8, 0.0, 0.0, 1.0)
    batteryLevelTwoColor = VBase4(0.9, 0.36, 0.0, 1.0)
    batteryLevelThreeColor = VBase4(0.9, 0.9, 0.0, 1.0)
    batteryLevelFourColor = VBase4(1.0, 1.0, 0.0, 1.0)
    batteryLevelFiveColor = VBase4(0.0, 1.0, 0.0, 1.0)
    fullyChargedState = 5

    def __init__(self, mg):
        self.mg = mg
        self.batteryFrame = None
        self.batteryBg = None
        self.batteryBar = None
        self.rechargeSound = None
        self.fullyChargedSound = None

        self.hasToonInFocus = False
        self.toonToTakePicOf = None

        self.cameraRechargeState = None
        self.cameraRechargingLabel = None
        self.cameraFlashSeq = None

        self.viewfinder = None

        self.camFSM = ClassicFSM('CameraFSM', [
            State('off', self.enterOff, self.exitOff),
            State('ready', self.enterCameraReady, self.exitCameraReady),
            State('recharge', self.enterCameraRecharge,
                  self.exitCameraRecharge)
        ], 'off', 'off')
        self.camFSM.enterInitialState()
        FirstPerson.__init__(self)

    def enterOff(self):
        pass

    def exitOff(self):
        pass

    def enterCameraReady(self):
        self.acceptOnce("mouse1", self.__mouse1Pressed)

    def stopCameraFlash(self):
        if self.cameraFlashSeq:
            self.cameraFlashSeq.finish()
            self.cameraFlashSeq = None

    def __mouse1Pressed(self):
        self.cameraFlashSeq = Sequence(
            Func(base.transitions.setFadeColor, 1, 1, 1),
            Func(base.transitions.fadeOut, 0.1), Wait(0.1),
            Func(base.transitions.fadeIn, 0.1), Wait(0.1),
            Func(base.transitions.setFadeColor, 0, 0, 0))
        self.cameraFlashSeq.start()
        self.mg.sendUpdate('remoteAvatarTakePicture', [base.localAvatar.doId])
        self.mg.myRemoteAvatar.takePicture()
        self.viewfinder['image'].setColorScale(self.defaultColor)
        picData = self.viewfinder.takePictureRaw()
        if self.hasToonInFocus and self.toonToTakePicOf:
            self.mg.sendUpdate('tookPictureOfToon',
                               [self.toonToTakePicOf.doId])
        self.camFSM.request('recharge')

    def exitCameraReady(self):
        self.ignore("mouse1")

    def enterCameraRecharge(self):
        self.batteryBar.update(0)
        taskMgr.add(self.__rechargeNextState, "rechargeCamera")

    def __rechargeNextState(self, task):
        if self.cameraRechargeState is None:
            self.cameraRechargeState = -1
        self.cameraRechargeState += 1
        if self.cameraRechargeState > 0:
            base.playSfx(self.rechargeSound)

            if self.cameraRechargeState <= 1:
                self.batteryBar.setColorScale(self.redColor)
            elif self.cameraRechargeState == 2:
                self.batteryBar.setColorScale(self.batteryLevelTwoColor)
            elif self.cameraRechargeState == 3:
                self.batteryBar.setColorScale(self.batteryLevelThreeColor)
            elif self.cameraRechargeState == 4:
                self.batteryBar.setColorScale(self.batteryLevelFourColor)
            else:
                self.batteryBar.setColorScale(self.batteryLevelFiveColor)

        self.batteryBar.update(self.cameraRechargeState)
        if self.cameraRechargeState == self.fullyChargedState:
            base.playSfx(self.fullyChargedSound)
            self.camFSM.request('ready')
            return task.done
        task.delayTime = 1.0
        return task.again

    def exitCameraRecharge(self):
        taskMgr.remove("rechargeCamera")
        self.cameraRechargeState = None

    def __traverse(self, task):
        if not base.mouseWatcherNode.hasMouse():
            return task.cont

        toonInFoc = False
        avatar = None

        for av in self.mg.remoteAvatars:
            if av.avId != base.localAvatar.doId:
                if self.viewfinder.isInView(av):
                    self.notify.info("{0} is in our view finder".format(
                        av.avId))
                    avatar = self.mg.cr.doId2do.get(av.avId)
                    break
        if avatar:
            remoteAvatar = self.mg.getRemoteAvatar(avatar.doId)
            if remoteAvatar:
                toonInFoc = True
                self.notify.info("We've got an avatar in focus ({0})".format(
                    avatar.doId))
                self.__handleToonInFocus(avatar)

        if not toonInFoc:
            self.toonToTakePicOf = None
            self.hasToonInFocus = False
            self.notify.info("No avatar in focus")
            if self.viewfinder['image'].getColorScale(
            ) == self.toonInFocusColor:
                self.viewfinder['image'].setColorScale(
                    self.toonOutOfFocusColor)

        return task.cont

    def __handleToonInFocus(self, toon):
        if not self.hasToonInFocus or self.toonToTakePicOf is not None or self.toonToTakePicOf.doId != toon.doId:
            self.toonToTakePicOf = toon
            self.hasToonInFocus = True
            self.viewfinder['image'].setColorScale(self.toonInFocusColor)

    def start(self):
        self.fullyChargedSound = base.loadSfx('phase_4/audio/sfx/ring_get.ogg')
        self.rechargeSound = base.loadSfx(
            'phase_4/audio/sfx/MG_sfx_travel_game_blue_arrow.ogg')
        self.batteryFrame = DirectFrame(parent=base.a2dBottomRight,
                                        pos=(-0.2, 0, 0.1),
                                        scale=(0.8, 0, 1))
        self.batteryBg = OnscreenImage(
            image='phase_4/maps/battery_charge_frame.png',
            parent=self.batteryFrame)
        self.batteryBg.setTransparency(1)
        self.batteryBg.setX(0.03)
        self.batteryBg.setScale(0.17, 0, 0.05)
        self.batteryBg.setColorScale(0, 0, 0, 1)
        self.batteryBar = DirectWaitBar(value=0,
                                        range=5,
                                        barColor=(1, 1, 1, 1),
                                        relief=None,
                                        scale=(0.12, 0.0, 0.3),
                                        parent=self.batteryFrame)

        self.viewfinder = Viewfinder(1.0)

        base.localAvatar.walkControls.setWalkSpeed(CIGlobals.ToonForwardSpeed,
                                                   0.0,
                                                   CIGlobals.ToonReverseSpeed,
                                                   CIGlobals.ToonRotateSpeed)
        FirstPerson.start(self)

    def reallyStart(self):
        taskMgr.add(self.__traverse, "CSFP.__traverse")
        self.camFSM.request('recharge')
        #taskMgr.add(self.movementTask, "movementTask")
        base.localAvatar.startTrackAnimToSpeed()
        FirstPerson.reallyStart(self)

    def end(self):
        self.camFSM.request('off')
        taskMgr.remove("movementTask")
        taskMgr.remove("CSFP.__traverse")
        FirstPerson.end(self)

    def reallyEnd(self):
        self.batteryBar.destroy()
        self.batteryBar = None
        self.batteryBg.destroy()
        self.batteryBg = None
        self.batteryFrame.destroy()
        self.batteryFrame = None
        self.hasToonInFocus = None
        self.toonToTakePicOf = None
        self.fullyChargedSound = None
        self.rechargeSound = None
        self.viewfinder.cleanup()
        self.viewfinder = None
        self.stopCameraFlash()
        FirstPerson.reallyEnd(self)
        base.localAvatar.walkControls.setWalkSpeed(CIGlobals.ToonForwardSpeed,
                                                   CIGlobals.ToonJumpForce,
                                                   CIGlobals.ToonReverseSpeed,
                                                   CIGlobals.ToonRotateSpeed)

    def cleanup(self):
        self.camFSM.requestFinalState()
        self.camFSM = None
        FirstPerson.cleanup(self)