armory/blender/arm/logicnode/input/LN_gamepad.py

64 lines
2.4 KiB
Python
Raw Normal View History

2017-04-10 21:17:17 +02:00
from arm.logicnode.arm_nodes import *
class GamepadNode(ArmLogicTreeNode):
2020-11-17 16:01:15 +01:00
"""Activates the output on the given gamepad event.
2020-09-28 15:58:41 +02:00
@seeNode Gamepad Coords
@input Gamepad: the ID of the gamepad.
@option State: the state of the gamepad button to listen to.
@option Button: the gamepad button that should activate the output.
"""
bl_idname = 'LNMergedGamepadNode'
bl_label = 'Gamepad'
arm_version = 1
2020-10-27 19:44:37 +01:00
arm_section = 'gamepad'
2018-12-18 23:48:38 +01:00
property0: EnumProperty(
2020-11-17 21:35:22 +01:00
items = [('started', 'Started', 'The gamepad button starts to be pressed'),
('down', 'Down', 'The gamepad button is pressed'),
('released', 'Released', 'The gamepad button stops being pressed')],
2017-04-10 21:17:17 +02:00
# ('Moved Left', 'Moved Left', 'Moved Left'),
# ('Moved Right', 'Moved Right', 'Moved Right'),],
2020-11-17 21:35:22 +01:00
name='', default='down')
2018-12-18 23:48:38 +01:00
property1: EnumProperty(
2017-04-10 21:17:17 +02:00
items = [('cross', 'cross / a', 'cross / a'),
('circle', 'circle / b', 'circle / b'),
('square', 'square / x', 'square / x'),
('triangle', 'triangle / y', 'triangle / y'),
('l1', 'l1 / lb', 'l1 / lb'),
('r1', 'r1 / rb', 'r1 / rb'),
('l2', 'l2 / lt', 'l2 / lt'),
('r2', 'r2 / rt', 'r2 / rt'),
2017-04-10 21:17:17 +02:00
('share', 'share', 'share'),
('options', 'options', 'options'),
('l3', 'l3', 'l3'),
('r3', 'r3', 'r3'),
('up', 'up', 'up'),
('down', 'down', 'down'),
('left', 'left', 'left'),
('right', 'right', 'right'),
('home', 'home', 'home'),
('touchpad', 'touchpad', 'touchpad'),],
name='', default='cross')
def init(self, context):
super(GamepadNode, self).init(context)
2020-09-08 21:49:02 +02:00
self.add_output('ArmNodeSocketAction', 'Out')
self.add_output('NodeSocketBool', 'State')
2020-11-17 16:01:15 +01:00
2020-09-08 21:49:02 +02:00
self.add_input('NodeSocketInt', 'Gamepad')
2017-04-10 21:17:17 +02:00
def draw_buttons(self, context, layout):
layout.prop(self, 'property0')
layout.prop(self, 'property1')
2020-12-15 23:47:38 +01:00
def draw_label(self) -> str:
inp_gamepad = self.inputs['Gamepad']
if inp_gamepad.is_linked:
return f'{self.bl_label}: {self.property1}'
return f'{self.bl_label} {inp_gamepad.default_value}: {self.property1}'