mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-04 10:54:24 -04:00
added InputState.watchWithModifiers to reduce code duplication
This commit is contained in:
parent
81edb9fc7d
commit
c8d74466ee
@ -30,93 +30,31 @@ class ControlManager:
|
||||
#self.monitorTask = taskMgr.add(self.monitor, "ControlManager-%s"%(id(self)), priority=-1)
|
||||
inputState.watch("run", "running-on", "running-off")
|
||||
|
||||
inputState.watch("forward", "arrow_up", "arrow_up-up")
|
||||
inputState.watch("forward", "control-arrow_up", "arrow_up-up")
|
||||
inputState.watch("forward", "shift-control-arrow_up", "arrow_up-up")
|
||||
inputState.watch("forward", "alt-arrow_up", "arrow_up-up")
|
||||
inputState.watch("forward", "control-alt-arrow_up", "arrow_up-up")
|
||||
inputState.watch("forward", "shift-arrow_up", "arrow_up-up")
|
||||
inputState.watchWithModifiers("forward", "arrow_up")
|
||||
inputState.watch("forward", "force-forward", "force-forward-stop")
|
||||
|
||||
inputState.watch("reverse", "arrow_down", "arrow_down-up")
|
||||
inputState.watch("reverse", "control-arrow_down", "arrow_down-up")
|
||||
inputState.watch("reverse", "shift-control-arrow_down", "arrow_down-up")
|
||||
inputState.watch("reverse", "alt-arrow_down", "arrow_down-up")
|
||||
inputState.watch("reverse", "control-alt-arrow_down", "arrow_down-up")
|
||||
inputState.watch("reverse", "shift-arrow_down", "arrow_down-up")
|
||||
|
||||
inputState.watch("reverse", "mouse4", "mouse4-up")
|
||||
inputState.watch("reverse", "control-mouse4", "mouse4-up")
|
||||
inputState.watch("reverse", "shift-control-mouse4", "mouse4-up")
|
||||
inputState.watch("reverse", "alt-mouse4", "mouse4-up")
|
||||
inputState.watch("reverse", "control-alt-mouse4", "mouse4-up")
|
||||
inputState.watch("reverse", "shift-mouse4", "mouse4-up")
|
||||
inputState.watchWithModifiers("reverse", "arrow_down")
|
||||
inputState.watchWithModifiers("reverse", "mouse4")
|
||||
|
||||
inputState.watch("turnLeft", "arrow_left", "arrow_left-up")
|
||||
inputState.watch("turnLeft", "control-arrow_left", "arrow_left-up")
|
||||
inputState.watch("turnLeft", "shift-control-arrow_left", "arrow_left-up")
|
||||
inputState.watch("turnLeft", "alt-arrow_left", "alt-arrow_left-up")
|
||||
inputState.watch("turnLeft", "control-alt-arrow_left", "alt-arrow_left-up")
|
||||
inputState.watch("turnLeft", "shift-arrow_left", "arrow_left-up")
|
||||
inputState.watchWithModifiers("turnLeft", "arrow_left")
|
||||
inputState.watch("turnLeft", "mouse-look_left", "mouse-look_left-done")
|
||||
inputState.watch("turnLeft", "force-turnLeft", "force-turnLeft-stop")
|
||||
|
||||
inputState.watch("turnRight", "arrow_right", "arrow_right-up")
|
||||
inputState.watch("turnRight", "control-arrow_right", "arrow_right-up")
|
||||
inputState.watch("turnRight", "shift-control-arrow_right", "arrow_right-up")
|
||||
inputState.watch("turnRight", "alt-arrow_right", "arrow_right-up")
|
||||
inputState.watch("turnRight", "control-alt-arrow_right", "arrow_right-up")
|
||||
inputState.watch("turnRight", "shift-arrow_right", "arrow_right-up")
|
||||
inputState.watchWithModifiers("turnRight", "arrow_right")
|
||||
inputState.watch("turnRight", "mouse-look_right", "mouse-look_right-done")
|
||||
inputState.watch("turnRight", "force-turnRight", "force-turnRight-stop")
|
||||
|
||||
if self.wantWASD:
|
||||
inputState.watch("forward", "w", "w-up")
|
||||
inputState.watch("forward", "control-w", "w-up")
|
||||
inputState.watch("forward", "shift-control-w", "w-up")
|
||||
inputState.watch("forward", "alt-w", "w-up")
|
||||
inputState.watch("forward", "control-alt-w", "w-up")
|
||||
inputState.watch("forward", "shift-w", "w-up")
|
||||
|
||||
inputState.watch("reverse", "s", "s-up")
|
||||
inputState.watch("reverse", "control-s", "s-up")
|
||||
inputState.watch("reverse", "shift-control-s", "s-up")
|
||||
inputState.watch("reverse", "alt-s", "s-up")
|
||||
inputState.watch("reverse", "control-alt-s", "s-up")
|
||||
inputState.watch("reverse", "shift-s", "s-up")
|
||||
|
||||
inputState.watch("slideLeft", "a", "a-up")
|
||||
inputState.watch("slideLeft", "control-a", "a-up")
|
||||
inputState.watch("slideLeft", "shift-control-a", "a-up")
|
||||
inputState.watch("slideLeft", "alt-a", "alt-a-up")
|
||||
inputState.watch("slideLeft", "control-alt-a", "alt-a-up")
|
||||
inputState.watch("slideLeft", "shift-a", "a-up")
|
||||
|
||||
inputState.watch("slideRight", "d", "d-up")
|
||||
inputState.watch("slideRight", "control-d", "d-up")
|
||||
inputState.watch("slideRight", "shift-control-d", "d-up")
|
||||
inputState.watch("slideRight", "alt-d", "d-up")
|
||||
inputState.watch("slideRight", "control-alt-d", "d-up")
|
||||
inputState.watch("slideRight", "shift-d", "d-up")
|
||||
|
||||
|
||||
inputState.watch("turnLeft", "q", "q-up")
|
||||
inputState.watch("turnLeft", "control-q", "q-up")
|
||||
inputState.watch("turnLeft", "shift-control-q", "q-up")
|
||||
inputState.watch("turnLeft", "alt-q", "alt-q-up")
|
||||
inputState.watch("turnLeft", "control-alt-q", "alt-q-up")
|
||||
inputState.watch("turnLeft", "shift-q", "q-up")
|
||||
|
||||
inputState.watch("turnRight", "e", "e-up")
|
||||
inputState.watch("turnRight", "control-e", "e-up")
|
||||
inputState.watch("turnRight", "shift-control-e", "e-up")
|
||||
inputState.watch("turnRight", "alt-e", "e-up")
|
||||
inputState.watch("turnRight", "control-alt-e", "e-up")
|
||||
inputState.watch("turnRight", "shift-e", "e-up")
|
||||
inputState.watchWithModifiers("forward", "w")
|
||||
inputState.watchWithModifiers("reverse", "s")
|
||||
inputState.watchWithModifiers("slideLeft", "a")
|
||||
inputState.watchWithModifiers("slideRight", "d")
|
||||
inputState.watchWithModifiers("turnLeft", "q")
|
||||
inputState.watchWithModifiers("turnRight", "e")
|
||||
|
||||
# Jump controls
|
||||
if self.wantWASD:
|
||||
inputState.watch("jump", "space", "space-up")
|
||||
inputState.watchWithModifiers("jump", "space")
|
||||
else:
|
||||
inputState.watch("jump", "control", "control-up")
|
||||
|
||||
|
@ -51,6 +51,12 @@ class InputState(DirectObject.DirectObject):
|
||||
else:
|
||||
# Start a new list
|
||||
self.watching[name] = [(eventOn, eventOff)]
|
||||
|
||||
def watchWithModifiers(self, name, event, default = 0):
|
||||
patterns = ('%s', 'control-%s', 'shift-control-%s', 'alt-%s',
|
||||
'control-alt-%s', 'shift-%s',)
|
||||
for pattern in patterns:
|
||||
self.watch(name, pattern % event, '%s-up' % event, default)
|
||||
|
||||
def force(self, name, value):
|
||||
"""
|
||||
|
Loading…
x
Reference in New Issue
Block a user