Forráskód Böngészése

adding silenceInput() and reviveInput() for global disabling of all inputs at once

Josh Wilson 18 éve
szülő
commit
7d9121d2d4
1 módosított fájl, 25 hozzáadás és 5 törlés
  1. 25 5
      direct/src/showbase/ShowBase.py

+ 25 - 5
direct/src/showbase/ShowBase.py

@@ -373,10 +373,12 @@ class ShowBase(DirectObject.DirectObject):
 
 
         if self.windowType != 'none':
         if self.windowType != 'none':
             self.__doStartDirect()
             self.__doStartDirect()
-            
+
+        self.__deadInputs = None
+        
         # Start IGLOOP
         # Start IGLOOP
         self.restart()
         self.restart()
-
+        
     # add a collision traverser via pushCTrav and remove it via popCTrav
     # add a collision traverser via pushCTrav and remove it via popCTrav
     # that way the owner of the new cTrav doesn't need to hold onto the
     # that way the owner of the new cTrav doesn't need to hold onto the
     # previous one in order to put it back
     # previous one in order to put it back
@@ -1177,14 +1179,13 @@ class ShowBase(DirectObject.DirectObject):
         self.dataRootNode = self.dataRoot.node()
         self.dataRootNode = self.dataRoot.node()
         self.dataUnused = NodePath('dataUnused')
         self.dataUnused = NodePath('dataUnused')
 
 
-
     def setupMouse(self, win):
     def setupMouse(self, win):
         """
         """
         Creates the structures necessary to monitor the mouse input,
         Creates the structures necessary to monitor the mouse input,
         using the indicated window.  If the mouse has already been set
         using the indicated window.  If the mouse has already been set
         up for a different window, those structures are deleted first.
         up for a different window, those structures are deleted first.
         """
         """
-
+        self.reviveInput()
         if self.buttonThrowers != None:
         if self.buttonThrowers != None:
             for bt in self.buttonThrowers:
             for bt in self.buttonThrowers:
                 mw = bt.getParent()
                 mw = bt.getParent()
@@ -1192,7 +1193,6 @@ class ShowBase(DirectObject.DirectObject):
                 bt.removeNode()
                 bt.removeNode()
                 mw.removeNode()
                 mw.removeNode()
                 mk.removeNode()
                 mk.removeNode()
-
         # For each mouse/keyboard device, we create
         # For each mouse/keyboard device, we create
         #  - MouseAndKeyboard
         #  - MouseAndKeyboard
         #  - MouseWatcher
         #  - MouseWatcher
@@ -1692,6 +1692,26 @@ class ShowBase(DirectObject.DirectObject):
         if self.mouse2cam:
         if self.mouse2cam:
             self.mouse2cam.reparentTo(self.mouseInterface)
             self.mouse2cam.reparentTo(self.mouseInterface)
 
 
+    def silenceInput(self):
+        """
+        This is a heavy-handed way of temporarily turning off
+        all inputs.  Bring them back with reviveInput().
+        """
+        if not self.__deadInputs:
+            self.__deadInputs = self.dataRoot.getChildren()
+            self.dataRoot.removeChildren()
+
+    def reviveInput(self):
+        """
+        Restores inputs after a previous call to silenceInput.
+        """
+        if self.__deadInputs:
+            self.eventMgr.doEvents()
+            self.__deadInputs.reparentTo(self.dataRoot)
+            self.__deadInputs = None
+            self.dgTrav.traverse(base.dataRootNode)
+            self.eventMgr.eventQueue.clear()
+        
     def setMouseOnNode(self, newNode):
     def setMouseOnNode(self, newNode):
         if self.mouse2cam:
         if self.mouse2cam:
             self.mouse2cam.node().setNode(newNode)
             self.mouse2cam.node().setNode(newNode)