joystick delay axis, single x/y
This commit is contained in:
parent
25df1d29bd
commit
b48f04e89c
|
@ -124,6 +124,8 @@ class Configuration(RawConfigParser):
|
|||
set_option(section, "advance", "7", False)
|
||||
set_option(section, "pause", "7", False)
|
||||
set_option(section, "select", "6", False)
|
||||
set_option(section, "single-xy", "no", False)
|
||||
set_option(section, "delay-axis", "0", False)
|
||||
section = "event"
|
||||
add_section(section)
|
||||
set_option(section, "user-event-id", "USEREVENT", False)
|
||||
|
@ -412,7 +414,11 @@ class TypeDeclarations(dict):
|
|||
|
||||
"keys": {"list": ["up", "right", "down", "left"]},
|
||||
|
||||
"joy": {"int": ["advance", "pause", "select"]},
|
||||
"joy": {"int": ["advance", "pause", "select"],
|
||||
|
||||
"float": "delay-axis",
|
||||
|
||||
"bool": "single-xy"},
|
||||
|
||||
"audio": {"path": "sfx-path",
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ class Input(GameChild):
|
|||
GameChild.__init__(self, game)
|
||||
self.last_mouse_down_left = None
|
||||
self.axes_cancelled = {"up": True, "right": True, "down": True, "left": True}
|
||||
self.last_command_post_time = get_secs()
|
||||
self.joystick = Joystick()
|
||||
self.delegate = self.get_delegate()
|
||||
self.load_configuration()
|
||||
|
@ -95,28 +96,49 @@ class Input(GameChild):
|
|||
if not self.suppressed and not self.check_command_line("-disable-joy-axis"):
|
||||
axis = event.axis
|
||||
value = event.value
|
||||
single_xy = self.get_configuration("joy", "single-xy")
|
||||
command = None
|
||||
if -.01 < value < .01:
|
||||
for command in "up", "right", "down", "left":
|
||||
if not self.axes_cancelled[command]:
|
||||
self.post_command(command, cancel=True)
|
||||
if command not in self.any_press_ignored:
|
||||
self.post_any_command(command, True)
|
||||
self.axes_cancelled[command] = True
|
||||
for direction in "up", "right", "down", "left":
|
||||
if not self.axes_cancelled[direction]:
|
||||
self.post_command(direction, cancel=True)
|
||||
if direction not in self.any_press_ignored:
|
||||
self.post_any_command(direction, True)
|
||||
self.axes_cancelled[direction] = True
|
||||
if single_xy:
|
||||
if direction == "up" and self.joystick.is_direction_pressed(Joystick.down):
|
||||
command = "down"
|
||||
elif direction == "down" and self.joystick.is_direction_pressed(Joystick.up):
|
||||
command = "up"
|
||||
elif direction == "right" and self.joystick.is_direction_pressed(Joystick.left):
|
||||
command = "left"
|
||||
elif direction == "left" and self.joystick.is_direction_pressed(Joystick.right):
|
||||
command = "right"
|
||||
else:
|
||||
if axis == 1:
|
||||
if value < 0:
|
||||
command = "up"
|
||||
if not single_xy or not self.joystick.is_direction_pressed(Joystick.down):
|
||||
command = "up"
|
||||
elif value > 0:
|
||||
command = "down"
|
||||
if not single_xy or not self.joystick.is_direction_pressed(Joystick.up):
|
||||
command = "down"
|
||||
else:
|
||||
if value > 0:
|
||||
command = "right"
|
||||
if not single_xy or not self.joystick.is_direction_pressed(Joystick.left):
|
||||
command = "right"
|
||||
elif value < 0:
|
||||
command = "left"
|
||||
self.post_command(command)
|
||||
if command not in self.any_press_ignored:
|
||||
self.post_any_command(command)
|
||||
self.axes_cancelled[command] = False
|
||||
if not single_xy or not self.joystick.is_direction_pressed(Joystick.right):
|
||||
command = "left"
|
||||
if command is not None:
|
||||
delay = self.get_configuration("joy", "delay-axis")
|
||||
secs = get_secs()
|
||||
print get_secs(), self.last_command_post_time
|
||||
if not delay or secs - self.last_command_post_time > delay:
|
||||
self.post_command(command)
|
||||
if command not in self.any_press_ignored:
|
||||
self.post_any_command(command)
|
||||
self.axes_cancelled[command] = False
|
||||
self.last_command_post_time = secs
|
||||
|
||||
def is_command_active(self, command):
|
||||
if not self.suppressed:
|
||||
|
|
Loading…
Reference in New Issue