예제 #1
0
    def __init__(self, viewport):
        DocObject.__init__(self, viewport.doc)

        self.viewport = viewport

        self.enabled = False
        self.mouseSensitivity = 0.3
        self.cameraSpeed = 500 / 16.0
        self.timeToSpeed = 0.5  # seconds
        self.moveStart = 0.0
        self.cameraRotateSpeed = 75.0
        self.cameraSmooth = 0.7
        self.slideFactor = 0.75
        self.maxPitch = 90
        self.minPitch = -90
        self.diagonalFactor = math.sqrt(2.0) / 2.0
        self.lastSpeeds = Vec3(0)
        self.moving = False

        self.cursor = QtGui.QCursor()
        self.cursor.setShape(QtCore.Qt.BlankCursor)

        tex = base.loader.loadTexture('icons/editor-crosshair.png')
        tex.setMinfilter(SamplerState.FTLinear)
        tex.setMagfilter(SamplerState.FTLinear)
        crosshair = OnscreenImage(tex)
        crosshair.setTransparency(True)
        crosshair.setScale(0.04)
        crosshair.reparentTo(NodePath())
        self.crosshair = crosshair

        self.inputState = {}

        self.addInput("forward", KeyBind.Forward3DView)
        self.addInput("reverse", KeyBind.Back3DView)
        self.addInput("slideLeft", KeyBind.Left3DView)
        self.addInput("slideRight", KeyBind.Right3DView)
        self.addInput("floatDown", KeyBind.Down3DView)
        self.addInput("floatUp", KeyBind.Up3DView)
        self.addInput("lookUp", KeyBind.LookUp3DView)
        self.addInput("lookDown", KeyBind.LookDown3DView)
        self.addInput("lookRight", KeyBind.LookRight3DView)
        self.addInput("lookLeft", KeyBind.LookLeft3DView)

        self.accept(KeyBinds.getPandaShortcut(KeyBind.FlyCam), self.handleZ)

        self.doc.taskMgr.add(self.__flyCamTask, 'flyCam')
예제 #2
0
class UnoGameCardDeck(DirectFrame):
    def __init__(self, ug):
        DirectFrame.__init__(self,
                             relief=None,
                             sortOrder=50,
                             parent=base.a2dBottomCenter)
        self.initialiseoptions(UnoGameCardDeck)
        self.container = DirectFrame(parent=self, relief=None)
        self.title = None
        self.cards = []
        self.cardBtns = []
        self.numCards = 0
        self.unoGame = ug
        self.deck = None
        self.cardToFollowGui = None
        self.holiday = base.cr.holidayManager.getHoliday()
        self.gui = None
        self.loadCards()
        return

    def loadCards(self):
        self.gui = loader.loadModel(
            "phase_4/models/minigames/mg_uno_game_cards.egg")
        if self.holiday == HolidayType.CHRISTMAS:
            cards = self.gui.find(
                '**/mg_uno_numcards_green_7').getParent().getChildren()
            for child in cards:
                child.setTexture(
                    loader.loadTexture('winter/maps/uno/%s.png' %
                                       (child.getName())), 1)

    def updateCardToFollowGui(self):
        self.deleteCardToFollowGui()
        if self.unoGame.cardToFollow[-2:] == str(UGG.CARD_BLUE):
            self.cardToFollowGui = OnscreenImage(
                image=self.getCard('mg_uno_numcards_blue_blank'),
                parent=base.a2dRightCenter)
        elif self.unoGame.cardToFollow[-2:] == str(UGG.CARD_RED):
            self.cardToFollowGui = OnscreenImage(
                image=self.getCard('mg_uno_numcards_red_blank'),
                parent=base.a2dRightCenter)
        elif self.unoGame.cardToFollow[-2:] == str(UGG.CARD_GREEN):
            self.cardToFollowGui = OnscreenImage(
                image=self.getCard('mg_uno_numcards_green_blank'),
                parent=base.a2dRightCenter)
        elif self.unoGame.cardToFollow[-2:] == str(UGG.CARD_YELLOW):
            self.cardToFollowGui = OnscreenImage(
                image=self.getCard('mg_uno_numcards_yellow_blank'),
                parent=base.a2dRightCenter)

        if self.cardToFollowGui:
            self.cardToFollowGui.setScale(0.25, 0.3, 0.3)
            self.cardToFollowGui.setPos(-0.175, 0, -0.75)

    def deleteCardToFollowGui(self):
        if self.cardToFollowGui:
            self.cardToFollowGui.destroy()
            self.cardToFollowGui = None

    def getCard(self, cardType):
        cards = loader.loadModel(
            "phase_4/models/minigames/mg_uno_game_cards.egg")
        card = cards.find('**/' + cardType)
        if self.holiday == HolidayType.CHRISTMAS:
            holidayTexture = loader.loadTexture('winter/maps/uno/%s.png' %
                                                (card.getName()))
            card.setTexture(holidayTexture, 1)
        return card

    def generate(self):
        self.container["image"] = "phase_4/maps/mg_uno_card_deck.png"
        self.container.setTransparency(True)
        self.container.setZ(-0.456)
        self.container.setSx(2)
        self.container.setSz(1)
        gui = loader.loadModel("phase_3.5/models/gui/friendslist_gui.bam")
        numItemsVisible = 5
        itemHeight = -0.25
        self.deck = DirectScrolledList(
            itemFrame_relief=DGG.SUNKEN,
            decButton_pos=(0.35, 0, -0.02),
            decButton_geom=(gui.find('**/Horiz_Arrow_UP'),
                            gui.find('**/Horiz_Arrow_DN'),
                            gui.find('**/Horiz_Arrow_Rllvr'),
                            gui.find('**/Horiz_Arrow_UP')),
            decButton_relief=None,
            decButton_hpr=(0, 0, 90),
            incButton_pos=(0.35, 0, 1.95),
            incButton_geom=(gui.find('**/Horiz_Arrow_UP'),
                            gui.find('**/Horiz_Arrow_DN'),
                            gui.find('**/Horiz_Arrow_Rllvr'),
                            gui.find('**/Horiz_Arrow_UP')),
            incButton_hpr=(0, 0, -90),
            incButton_relief=None,
            pos=(-0.936, 0, -0.41),
            hpr=(0, 0, 90),
            scale=0.97,
            numItemsVisible=numItemsVisible,
            forceHeight=itemHeight,
            itemFrame_frameSize=(-0.2, 0.2, -0.37, 1.5),
            itemFrame_pos=(0.35, 0, 0.4),
            itemFrame_borderWidth=(0.02, 0.02),
        )

    def disable(self):
        if self.deck:
            self.deck.destroy()
            self.deck = None
        for btn in self.cardBtns:
            btn.destroy()
            del btn
        self.deleteCardToFollowGui()
        return

    def delete(self):
        DirectFrame.destroy(self)
        self.disable()
        self.gui.removeNode()
        self.gui = None
        self.cards = None
        self.title = None
        self.container = None
        self.cardBtns = None
        self.numCards = None
        self.unoGame = None
        self.deck = None
        return

    def drawCard(self, id):
        card = self.getCard(UGG.cardId2cardTex[id])
        card.setScale(0.225, 0.3, 0.3)
        card.setR(-90)
        cardBtn = DirectButton(geom=card,
                               relief=None,
                               scale=(0.3, 0.3, 0.23),
                               command=self.placeCard)
        cardBtn.setPythonTag('id', id)
        cardBtn['extraArgs'] = [id, cardBtn]
        cardBtn['state'] = DGG.DISABLED
        if not self.deck:
            self.generate()
        self.deck.addItem(cardBtn)
        self.cardBtns.append(cardBtn)
        self.enableAll(self.unoGame.cardToFollow)
        # Scroll to the card we just added to the deck.
        self.deck.scrollTo(len(self.cardBtns))
        card.removeNode()
        del card

    def enableAll(self, cardToFollow=None):
        for btn in self.cardBtns:
            if cardToFollow != None:
                if (cardToFollow == btn.getPythonTag('id')
                        or cardToFollow[:2] == btn.getPythonTag('id')[:2]
                        or cardToFollow[-2:] == btn.getPythonTag('id')[-2:]
                        or btn.getPythonTag('id') == str(UGG.CARD_WILD)
                        or btn.getPythonTag('id') == str(
                            UGG.CARD_WILD_DRAW_FOUR)):
                    btn['state'] = DGG.NORMAL
                else:
                    btn['state'] = DGG.DISABLED
            else:
                btn['state'] = DGG.NORMAL

    def disableAll(self):
        for btn in self.cardBtns:
            btn['state'] = DGG.DISABLED

    def placeCard(self, id, btn):
        self.deck.removeItem(btn)
        self.cardBtns.remove(btn)
        self.disableAll()
        self.unoGame.d_requestPlaceCard(id)
예제 #3
0
# loading screen
backgroundNodePath = aspect2d.attachNewNode(backgroundNode, 0)
backgroundNodePath.setPos(0.0, 0.0, 0.0)
backgroundNodePath.setScale(render2d, VBase3(1))
backgroundNodePath.find('**/bg').setBin('fixed', 10)

# change the logo
backgroundNodePath.find('**/fg').stash()

from direct.gui.DirectGui import OnscreenImage
logo = OnscreenImage('phase_3/maps/toontown-logo-new.png')
logo.reparentTo(backgroundNodePath)
logo.setBin('fixed', 20)
logo.setTransparency(TransparencyAttrib.MAlpha)
logo.setScale(.8, 1, .7)
logo.setZ(.3)

base.graphicsEngine.renderFrame()

# default DGG stuff
DirectGuiGlobals.setDefaultRolloverSound(
    base.loadSfx('phase_3/audio/sfx/GUI_rollover.ogg'))
DirectGuiGlobals.setDefaultClickSound(
    base.loadSfx('phase_3/audio/sfx/GUI_create_toon_fwd.ogg'))
DirectGuiGlobals.setDefaultDialogGeom(
    loader.loadModel('phase_3/models/gui/dialog_box_gui'))

# localizer
import TTLocalizer
from otp.otpbase import OTPGlobals
class CameraShyFirstPerson(FirstPerson):
    toonInFocusColor = VBase4(0.25, 1.0, 0.25, 1.0)
    toonOutOfFocusColor = VBase4(1.0, 1.0, 1.0, 1.0)
    fullyChargedState = 5

    def __init__(self, mg):
        self.mg = mg
        self.cameraFocus = None
        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.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)
        return

    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
        return

    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()
        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 == None:
            self.cameraRechargeState = -1
        self.cameraRechargeState += 1
        if self.cameraRechargeState > 0:
            base.playSfx(self.rechargeSound)
        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
        return

    def __traverse(self, task):
        if not base.mouseWatcherNode.hasMouse():
            return task.cont
        mpos = base.mouseWatcherNode.getMouse()
        self.focusRay.setFromLens(base.camNode, mpos.getX(), mpos.getY())
        self.focusTrav.traverse(render)
        if self.focusHandler.getNumEntries() > 0:
            self.focusHandler.sortEntries()
            firstObj = self.focusHandler.getEntry(0).getIntoNodePath()
            avId = firstObj.getParent().getPythonTag('player')
            avatar = self.mg.cr.doId2do.get(avId)
            toonInFoc = False
            if avatar:
                remoteAvatar = self.mg.getRemoteAvatar(avatar.doId)
                if remoteAvatar:
                    toonInFoc = True
                    self.__handleToonInFocus(avatar)
            if not toonInFoc:
                self.toonToTakePicOf = None
                self.hasToonInFocus = False
                if self.cameraFocus.getColorScale() == self.toonInFocusColor:
                    self.cameraFocus.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.cameraFocus.setColorScale(self.toonInFocusColor)
        return

    def start(self):
        self.fullyChargedSound = base.loadSfx(
            'phase_4/audio/sfx/MG_pairing_match.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.batteryBar = DirectWaitBar(value=0,
                                        range=5,
                                        barColor=(1, 1, 1, 1),
                                        relief=None,
                                        scale=(0.12, 0.0, 0.3),
                                        parent=self.batteryFrame)
        self.cameraFocus = loader.loadModel(
            'phase_4/models/minigames/photo_game_viewfinder.bam')
        self.cameraFocus.reparentTo(base.aspect2d)
        self.focusTrav = CollisionTraverser('CSFP.focusTrav')
        ray = CollisionRay()
        rayNode = CollisionNode('CSFP.rayNode')
        rayNode.addSolid(ray)
        rayNode.setCollideMask(BitMask32(0))
        rayNode.setFromCollideMask(CIGlobals.WallBitmask)
        self.focusRay = ray
        self.focusRayNode = base.camera.attachNewNode(rayNode)
        self.focusHandler = CollisionHandlerQueue()
        self.focusTrav.addCollider(self.focusRayNode, self.focusHandler)
        base.localAvatar.walkControls.setWalkSpeed(CIGlobals.ToonForwardSpeed,
                                                   0.0,
                                                   CIGlobals.ToonReverseSpeed,
                                                   CIGlobals.ToonRotateSpeed)
        FirstPerson.start(self)
        return

    def reallyStart(self):
        taskMgr.add(self.__traverse, 'CSFP.__traverse')
        self.camFSM.request('recharge')
        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.cameraFocus.removeNode()
        self.cameraFocus = None
        self.focusHandler = None
        self.focusRay = None
        self.focusRayNode.removeNode()
        self.focusRayNode = None
        self.focusTrav = None
        self.hasToonInFocus = None
        self.toonToTakePicOf = None
        self.fullyChargedSound = None
        self.rechargeSound = None
        self.stopCameraFlash()
        FirstPerson.reallyEnd(self)
        base.localAvatar.walkControls.setWalkSpeed(CIGlobals.ToonForwardSpeed,
                                                   CIGlobals.ToonJumpForce,
                                                   CIGlobals.ToonReverseSpeed,
                                                   CIGlobals.ToonRotateSpeed)
        return

    def cleanup(self):
        self.camFSM.requestFinalState()
        self.camFSM = None
        FirstPerson.cleanup(self)
        return
예제 #5
0
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()
예제 #6
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)
예제 #7
0
class CameraShyFirstPerson(FirstPerson):
    toonInFocusColor = VBase4(0.25, 1.0, 0.25, 1.0)
    toonOutOfFocusColor = VBase4(1.0, 1.0, 1.0, 1.0)
    fullyChargedState = 5

    def __init__(self, mg):
        self.mg = mg
        self.cameraFocus = None
        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.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)
        return

    def movementTask(self, task):
        if not inputState.isSet('jump') and not base.localAvatar.walkControls.isAirborne and inputState.isSet('forward') or inputState.isSet('reverse') or inputState.isSet('slideLeft') or inputState.isSet('slideRight'):
            if base.localAvatar.getAnimState() != 'run':
                base.localAvatar.setAnimState('run')
                base.localAvatar.playMovementSfx('run')
                self.mg.sendUpdate('runningAvatar', [base.localAvatar.doId])
        elif inputState.isSet('jump') or base.localAvatar.walkControls.isAirborne:
            if base.localAvatar.getAnimState() != 'jump':
                base.localAvatar.setAnimState('jump')
                base.localAvatar.playMovementSfx(None)
                self.mg.sendUpdate('jumpingAvatar', [base.localAvatar.doId])
        elif base.localAvatar.getAnimState() != 'neutral':
            base.localAvatar.setAnimState('neutral')
            base.localAvatar.playMovementSfx(None)
            self.mg.sendUpdate('standingAvatar', [base.localAvatar.doId])
        return task.cont

    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
        return

    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()
        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 == None:
            self.cameraRechargeState = -1
        self.cameraRechargeState += 1
        if self.cameraRechargeState > 0:
            base.playSfx(self.rechargeSound)
        self.batteryBar.update(self.cameraRechargeState)
        if self.cameraRechargeState == self.fullyChargedState:
            base.playSfx(self.fullyChargedSound)
            self.camFSM.request('ready')
            return task.done
        else:
            task.delayTime = 1.0
            return task.again

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

    def __handleRayInto(self, entry):
        intoNP = entry.getIntoNodePath()
        toonNP = intoNP.getParent()
        for key in base.cr.doId2do.keys():
            obj = base.cr.doId2do[key]
            if obj.__class__.__name__ == 'DistributedToon':
                if obj.getKey() == toonNP.getKey():
                    self.__handleToonInFocus(obj)

    def __handleRayOut(self, entry):
        intoNP = entry.getIntoNodePath()
        toonNP = intoNP.getParent()
        for key in base.cr.doId2do.keys():
            obj = base.cr.doId2do[key]
            if obj.__class__.__name__ == 'DistributedToon':
                if obj.getKey() == toonNP.getKey():
                    self.toonToTakePicOf = None
                    self.hasToonInFocus = False
                    if self.cameraFocus.getColorScale() == self.toonInFocusColor:
                        self.cameraFocus.setColorScale(self.toonOutOfFocusColor)

        return

    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.cameraFocus.setColorScale(self.toonInFocusColor)
        return

    def start(self):
        self.fullyChargedSound = base.loadSfx('phase_4/audio/sfx/MG_pairing_match.mp3')
        self.rechargeSound = base.loadSfx('phase_4/audio/sfx/MG_sfx_travel_game_blue_arrow.mp3')
        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.batteryBar = DirectWaitBar(value=0, range=5, barColor=(1, 1, 1, 1), relief=None, scale=(0.12, 0.0, 0.3), parent=self.batteryFrame)
        self.cameraFocus = loader.loadModel('phase_4/models/minigames/photo_game_viewfinder.bam')
        self.cameraFocus.reparentTo(base.aspect2d)
        self.focusCollHandler = CollisionHandlerEvent()
        self.focusCollHandler.setInPattern('%fn-into')
        self.focusCollHandler.setOutPattern('%fn-out')
        self.focusCollNode = CollisionNode('mouseRay')
        self.focusCollNP = base.camera.attachNewNode(self.focusCollNode)
        self.focusCollNode.setCollideMask(BitMask32(0))
        self.focusCollNode.setFromCollideMask(CIGlobals.WallBitmask)
        self.focusRay = CollisionRay()
        self.focusRay.setFromLens(base.camNode, 0.0, 0.0)
        self.focusCollNode.addSolid(self.focusRay)
        base.cTrav.addCollider(self.focusCollNP, self.focusCollHandler)
        base.localAvatar.walkControls.setWalkSpeed(CIGlobals.ToonForwardSpeed, 0.0, CIGlobals.ToonReverseSpeed, CIGlobals.ToonRotateSpeed)
        FirstPerson.start(self)
        return

    def reallyStart(self):
        self.accept('mouseRay-into', self.__handleRayInto)
        self.accept('mouseRay-out', self.__handleRayOut)
        self.camFSM.request('recharge')
        taskMgr.add(self.movementTask, 'movementTask')
        FirstPerson.reallyStart(self)

    def end(self):
        self.camFSM.request('off')
        taskMgr.remove('movementTask')
        self.ignore('mouseRay-into')
        self.ignore('mouseRay-out')
        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.cameraFocus.removeNode()
        self.cameraFocus = None
        self.focusCollHandler = None
        self.focusCollNode = None
        self.focusCollNP.removeNode()
        self.focusCollNP = None
        self.focusRay = None
        self.hasToonInFocus = None
        self.toonToTakePicOf = None
        self.fullyChargedSound = None
        self.rechargeSound = None
        self.stopCameraFlash()
        FirstPerson.reallyEnd(self)
        base.localAvatar.walkControls.setWalkSpeed(CIGlobals.ToonForwardSpeed, CIGlobals.ToonJumpForce, CIGlobals.ToonReverseSpeed, CIGlobals.ToonRotateSpeed)
        return

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