godot-third-person-basic-scene/scripts/common.gd

96 lines
2.2 KiB
GDScript

extends Node
func get_string_input_mousse_button(event:InputEventMouseButton) -> String:
match event.get_button_index():
1:
return "BUTTON_LEFT"
3:
return "BUTTON_MIDDLE"
2:
return "BUTTON_RIGHT"
4:
return "BUTTON_WHEEL_UP"
5:
return "BUTTON_WHEEL_DOWN"
6:
return "BUTTON_WHEEL_LEFT"
7:
return "BUTTON_WHEEL_RIGHT"
8:
return "BUTTON_XBUTTON1"
9:
return "BUTTON_XBUTTON2"
_:
return "MOUSSE BUTTON: " + str(event.get_button_index())
func get_string_input_joypad_button(event:InputEventJoypadButton) -> String:
match event.get_button_index():
0:
return "JOY_BUTTON_A"
1:
return "JOY_BUTTON_B"
2:
return "JOY_BUTTON_X"
3:
return "JOY_BUTTON_Y"
4:
return "JOY_BUTTON_BACK"
5:
return "JOY_BUTTON_GUIDE"
6:
return "JOY_BUTTON_START"
7:
return "JOY_BUTTON_LEFT_STICK"
8:
return "JOY_BUTTON_RIGHT_STICK"
9:
return "JOY_BUTTON_LEFT_SHOULDER"
10:
return "JOY_BUTTON_RIGHT_SHOULDER"
11:
return "JOY_BUTTON_DPAD_UP"
12:
return "JOY_BUTTON_DPAD_DOWN"
13:
return "JOY_BUTTON_DPAD_LEFT"
14:
return "JOY_BUTTON_DPAD_RIGHT"
_:
return "JOYPAD BUTTON: " + str(event.get_button_index())
func get_string_input_keyboard(event:InputEventKey) -> String:
var option:String = ""
if event.is_ctrl_pressed():
option += "Control+"
if event.is_shift_pressed():
option += "Shift+"
if event.is_alt_pressed():
option += "Alt+"
if event.is_meta_pressed():
option += "MetaKey+"
# if event.is_command_pressed():
# option += "Command+"
if event.keycode == 0:
if event.physical_keycode > 0:
return option + OS.get_keycode_string(event.physical_keycode)
else:
print("Error Event unknown keycode:" , event.keycode, ", physical_keycode:", event.physical_keycode)
return option + OS.get_keycode_string(event.keycode)
func get_string_input(event) -> String:
if event is InputEventKey:
return get_string_input_keyboard(event) # OS.get_scancode_string(event.get_scancode_with_modifiers())
elif event is InputEventMouseButton:
return get_string_input_mousse_button(event)
elif event is InputEventJoypadButton:
return get_string_input_joypad_button(event)
else:
return str(event)