base.enableMouse() help

Return to Scripting Issues

base.enableMouse() help

Postby flips » Thu May 24, 2012 10:35 pm

i have mouse disabled during gameplay and i want to re-enable the mouse when the game is paused so i can move the mouse around to use the menu. i have this code
Code: Select all
##############################################
#                                         #IMPORT#                                          #
##############################################
from pandac.PandaModules import Mat4
##############################################
#                           #External Class IMPORT#                                   #
##############################################

##############################################
#                                           #NEW CLASS#                                   #
##############################################
from Menu import *


class ControlHandler():
    fsmState = True

    def __init__(self, update, bulletDebugNode):
        #args
        self.update = update
        self.debugNP = bulletDebugNode

        self.createControls()
        self.singleSM(self.pauseGame, self.resumeGame)

    def singleSM(self, onFunction, offFunction):
        '''"Single State Machine"
        Takes two methods as args, runs onFunction
        when self.fsmState = False(Default state),
        runs offFunction when self.fsmState = True'''
        if self.fsmState:
            self.fsmState = False
            offFunction()
        else:
            self.fsmState = True
            onFunction()

    def escMenu(self):
        '''Runs functions when escape is pressed'''
        self.singleSM(self.pauseGame, self.resumeGame)

    def pauseGame(self):
        '''Pauses the game by removing any taskmgr'''
        #self.props.setCursorHidden(False)
        #base.win.requestProperties(self.props)
        mat = Mat4(camera.getMat())
        mat.invertInPlace()
        base.mouseInterfaceNode.setMat(mat)
        base.enableMouse()
        self.menu = Menu(self.escMenu)
        taskMgr.remove('update')
        self.menu.loadPauseMenu()

    def resumeGame(self):
       # taskMgr.add(self.playerList["Player1"].ship.taskTimer, 'ShipTaskTimer')
        #self.props.setCursorHidden(True)
       # base.win.requestProperties(self.props)
        try:
            self.menu.destroyAllMenus()
        except AttributeError:
            print("Nothing to destroy!")
        taskMgr.add(self.update, 'update')
        base.disableMouse()

    def debugBullet(self):
        if self.debugNP.isHidden():
            self.debugNP.show()
        else:
            self.debugNP.hide()

    def createControls(self):
        #Sets up the controls
        base.accept("escape", self.escMenu)
        base.accept("f1", self.debugBullet)


but when i pause the mouse is still disabled. Any ideas?
-Flips
flips
 
Posts: 156
Joined: Mon May 23, 2011 9:53 pm
Location: United States

Postby teedee » Thu May 24, 2012 10:45 pm

The disableMouse and enableMouse commands are just poorly named and do not actually disable and enable the mouse. What they really do is disable and enable the trackball-type mouse control of the camera.
If you mean that you cannot see the cursor, it just means that you have hidden the cursor and not unhidden it when you want to use your menu.
teedee
 
Posts: 782
Joined: Tue May 12, 2009 11:33 pm
Location: Kepler-22b

Postby flips » Fri May 25, 2012 12:37 am

yea i read about that, and no the cursor isnt hidden but its stuck in the middle of the screen, i assumed that since disableMouse(0 causes it to lock to the middle enableMouse would "unlock" it lol. Is there a way to regain my mouse movement?
-Flips
flips
 
Posts: 156
Joined: Mon May 23, 2011 9:53 pm
Location: United States

Postby Neon22 » Fri May 25, 2012 12:44 am

check if the mouse is moving by using
mpos = base.mouseWatcherNode.getMouse()
at least then you can work out if its display side or input side.
User avatar
Neon22
 
Posts: 27
Joined: Thu May 24, 2012 5:50 am

Postby flips » Sat May 26, 2012 9:16 pm

ok i figured it out, my task
Code: Select all
def updateCamera(task, self):
        base.camera.lookAt(self.np)

        pointer = base.win.getPointer(0)
        pointerX = pointer.getX()
        pointerY = pointer.getY()

        if base.win.movePointer(0, base.win.getXSize()/2, base.win.getYSize()/2):
            self.Pitch = -((pointerY - base.win.getYSize()/2)*.1)
            self.Heading = -((pointerX - base.win.getXSize()/2)*.1)

            self.np.setP(self.np, self.Pitch)
            self.np.setH(self.np, self.Heading)

        return Task.cont
wasnt being removed on pausegame, so i remove it then try to add it again and get this error "AssertionError: task->_manager == NULL && task->_state == AsyncTask::S_inactive at line 224 of c:\buildslave\dev_sdk_win32\build\panda3d\panda\src\event\asyncTaskManager.cxx" and that code is right here
Code: Select all
def resumeGame(self):
       # taskMgr.add(self.playerList["Player1"].ship.taskTimer, 'ShipTaskTimer')
        #self.props.setCursorHidden(True)
       # base.win.requestProperties(self.props)
        try:
            self.menu.destroyAllMenus()
        except AttributeError:
            print("Nothing to destroy!")
        taskMgr.add(self.update, 'update')
        taskMgr.add(self.cameraTask, "cameraTask", extraArgs=[self.camera])
        base.disableMouse()
and i define that task here
Code: Select all
##############################################
#                                         #IMPORT#                                          #
##############################################
from direct.task.Task import Task
from direct.task.TaskManagerGlobal import taskMgr
##############################################
#                           #External Class IMPORT#                                   #
##############################################

##############################################
#                                           #NEW CLASS#                                   #
##############################################


class Camera():

    def __init__(self, nodeToFollow):
        self.attachCamera(nodeToFollow)

        self.thisTask = Task(self.updateCamera)
        taskMgr.add(self.thisTask, "cameraUpdate", extraArgs=[self])
im clueless lol also im not sure why those import header things are turning out wierd on the forums
-Flips
flips
 
Posts: 156
Joined: Mon May 23, 2011 9:53 pm
Location: United States

Postby flips » Sat May 26, 2012 10:51 pm

im still not sure why i got that error but i just made a function inside of my camera task to add the task instead of trying to pass the task variable to another class. at any rate i got it, but im still curious as to hwy i got that error
-Flips
flips
 
Posts: 156
Joined: Mon May 23, 2011 9:53 pm
Location: United States


Return to Scripting Issues

Who is online

Users browsing this forum: No registered users and 0 guests