From 9b911db541970d5f97713b97a5c5e6adc8d5b29b Mon Sep 17 00:00:00 2001 From: Joe Shochet Date: Fri, 3 Aug 2007 04:04:23 +0000 Subject: [PATCH] better handling of wasd to turn switching --- direct/src/controls/ControlManager.py | 37 +++++++++++++++++---------- direct/src/controls/InputState.py | 12 +++++++-- 2 files changed, 33 insertions(+), 16 deletions(-) diff --git a/direct/src/controls/ControlManager.py b/direct/src/controls/ControlManager.py index 939c775199..715bc9b7e5 100755 --- a/direct/src/controls/ControlManager.py +++ b/direct/src/controls/ControlManager.py @@ -52,8 +52,8 @@ class ControlManager: ist.append(inputState.watchWithModifiers("forward", "w", inputSource=inputState.WASD)) ist.append(inputState.watchWithModifiers("reverse", "s", inputSource=inputState.WASD)) - ist.append(inputState.watchWithModifiers("slideLeft", "q", inputSource=inputState.WASD)) - ist.append(inputState.watchWithModifiers("slideRight", "e", inputSource=inputState.WASD)) + ist.append(inputState.watchWithModifiers("slideLeft", "q", inputSource=inputState.QE)) + ist.append(inputState.watchWithModifiers("slideRight", "e", inputSource=inputState.QE)) # Used to switch between strafe and turn. We will default to turn self.WASDTurnTokens = () @@ -262,29 +262,38 @@ class ControlManager: def setWASDTurn(self, turn): - turnLeftSet = inputState.isSet("turnLeft") - turnRightSet = inputState.isSet("turnRight") - slideLeftSet = inputState.isSet("slideLeft") - slideRightSet = inputState.isSet("slideRight") + turnLeftWASDSet = inputState.isSet("turnLeft", inputSource=inputState.WASD) + turnRightWASDSet = inputState.isSet("turnRight", inputSource=inputState.WASD) + slideLeftWASDSet = inputState.isSet("slideLeft", inputSource=inputState.WASD) + slideRightWASDSet = inputState.isSet("slideRight", inputSource=inputState.WASD) for token in self.WASDTurnTokens: token.release() + if turn: self.WASDTurnTokens = ( inputState.watchWithModifiers("turnLeft", "a", inputSource=inputState.WASD), inputState.watchWithModifiers("turnRight", "d", inputSource=inputState.WASD), ) + + if slideLeftWASDSet: + inputState.set("turnLeft", True, inputSource=inputState.WASD) + if slideRightWASDSet: + inputState.set("turnRight", True, inputSource=inputState.WASD) + + inputState.set("slideLeft", False, inputSource=inputState.WASD) + inputState.set("slideRight", False, inputSource=inputState.WASD) + else: self.WASDTurnTokens = ( inputState.watchWithModifiers("slideLeft", "a", inputSource=inputState.WASD), inputState.watchWithModifiers("slideRight", "d", inputSource=inputState.WASD), ) - - """ - inputState.set("turnLeft", turnLeftSet, inputSource=inputState.WASD) - inputState.set("turnRight", turnRightSet, inputSource=inputState.WASD) - inputState.set("slideLeft", slideLeftSet, inputSource=inputState.WASD) - inputState.set("slideRight", slideRightSet, inputSource=inputState.WASD) - """ - + if turnLeftWASDSet: + inputState.set("slideLeft", True, inputSource=inputState.WASD) + if turnRightWASDSet: + inputState.set("slideRight", True, inputSource=inputState.WASD) + + inputState.set("turnLeft", False, inputSource=inputState.WASD) + inputState.set("turnRight", False, inputSource=inputState.WASD) diff --git a/direct/src/controls/InputState.py b/direct/src/controls/InputState.py index e1d5437082..6b8c28c2f1 100755 --- a/direct/src/controls/InputState.py +++ b/direct/src/controls/InputState.py @@ -53,6 +53,7 @@ class InputState(DirectObject.DirectObject): # standard input sources WASD = 'WASD' + QE = 'QE' ArrowKeys = 'ArrowKeys' Keyboard = 'Keyboard' Mouse = 'Mouse' @@ -80,7 +81,7 @@ class InputState(DirectObject.DirectObject): del self._state self.ignoreAll() - def isSet(self, name): + def isSet(self, name, inputSource=None): """ returns True/False """ @@ -89,7 +90,14 @@ class InputState(DirectObject.DirectObject): return True elif name in self._forcingOff: return False - return name in self._state + if inputSource: + s = self._state.get(name) + if s: + return inputSource in s + else: + return False + else: + return name in self._state def set(self, name, isActive, inputSource=None): assert self.debugPrint("set(name=%s, isActive=%s, inputSource=%s)"%(name, isActive, inputSource))