gestion d'une deuxieme touche raccorucit pour le clavier.

This commit is contained in:
osquallo 2018-08-03 14:58:20 +02:00
parent e06c20765d
commit f72dde76c5
6 changed files with 81 additions and 75 deletions

View file

@ -106,20 +106,7 @@ func load_from_config():
var config = ConfigFile.new() var config = ConfigFile.new()
var err = config.load( config_file ) var err = config.load( config_file )
if err:# Assuming that file is missing, generate default config if err:# Assuming that file is missing, generate default config
#
# for event in InputMap.get_action_list( action_name ):
# if event is InputEventKey:
# var scancode = OS.get_scancode_string( event.get_scancode_with_modifiers() )
# config.set_value(current_keyboard.name, action_name, scancode)
## if current_keyboard.name == "keyboard_alt":
## break
# current_keyboard = $keyboard_alt
#
# elif event is InputEventJoypadButton:
# var joy_button_name = Input.get_joy_button_string( event.button_index )
# config.set_value("joypad", action_name, joy_button_name)
config.save( config_file ) config.save( config_file )
load_from_config()
else: else:
# on initialise l'entrée, si elle n'existe pas déjà, par la valeur par defaut du projet. # on initialise l'entrée, si elle n'existe pas déjà, par la valeur par defaut du projet.
@ -137,12 +124,19 @@ func load_from_config():
var scancode = OS.get_scancode_string( event.get_scancode_with_modifiers() ) var scancode = OS.get_scancode_string( event.get_scancode_with_modifiers() )
config.set_value("keyboard_alt", action_name, scancode) config.set_value("keyboard_alt", action_name, scancode)
break break
is_first = false if is_first and event is InputEventKey:
is_first = false
if not config.has_section_key("joypad", action_name):
for event in InputMap.get_action_list( action_name ):
if event is InputEventJoypadButton:
var scancode = Input.get_joy_button_string( event.button_index )
config.set_value("joypad", action_name, scancode)
break
# On efface toutes les touches de clavier de l'InputMap correspondants à l'action en cours. # On efface toutes les touches de clavier de l'InputMap correspondants à l'action en cours.
for old_event in InputMap.get_action_list( action_name ): for old_event in InputMap.get_action_list( action_name ):
if old_event is InputEventKey: if old_event is InputEventKey or old_event is InputEventJoypadButton:
InputMap.action_erase_event(action_name, old_event) InputMap.action_erase_event(action_name, old_event)
# on recupere les touches du fichier de config et on les ajoutes à l'input map. # on recupere les touches du fichier de config et on les ajoutes à l'input map.
@ -154,11 +148,6 @@ func load_from_config():
var event = get_event_with_modifier_from_string( config.get_value("keyboard", action_name), "keyboard") var event = get_event_with_modifier_from_string( config.get_value("keyboard", action_name), "keyboard")
InputMap.action_add_event(action_name, event) InputMap.action_add_event(action_name, event)
break break
# if not action_found:
# for event in InputMap.get_action_list( action_name ):
# if event is InputEventKey:
# var scancode = OS.get_scancode_string( event.get_scancode_with_modifiers() )
# config.set_value("keyboard", action_name, scancode)
if config.has_section("keyboard_alt"): if config.has_section("keyboard_alt"):
var action_found = false var action_found = false
@ -168,12 +157,6 @@ func load_from_config():
var event = get_event_with_modifier_from_string( config.get_value("keyboard_alt", action_name), "keyboard") var event = get_event_with_modifier_from_string( config.get_value("keyboard_alt", action_name), "keyboard")
InputMap.action_add_event(action_name, event) InputMap.action_add_event(action_name, event)
break break
# if not action_found:
# for event in InputMap.get_action_list( action_name ):
# if event is InputEventKey:
# var scancode = OS.get_scancode_string( event.get_scancode_with_modifiers() )
# config.set_value("keyboard_alt", action_name, scancode)
if config.has_section("joypad"): if config.has_section("joypad"):
var action_found = false var action_found = false
@ -185,12 +168,6 @@ func load_from_config():
if old_event is InputEventJoypadButton: if old_event is InputEventJoypadButton:
InputMap.action_erase_event(action_name, old_event) InputMap.action_erase_event(action_name, old_event)
InputMap.action_add_event(action_name, event) InputMap.action_add_event(action_name, event)
if not action_found:
for event in InputMap.get_action_list( action_name ):
if event is InputEventJoypadButton:
var joy_button_name = Input.get_joy_button_string( event.button_index )
config.set_value("joypad", action_name, joy_button_name)
config.save( config_file ) config.save( config_file )
@ -241,15 +218,18 @@ func _input(event):
current_keyboard.text += input_string current_keyboard.text += input_string
var key_to_change = 0 var change_first_key = true
if current_keyboard.name == "keyboard_alt": if current_keyboard.name == "keyboard_alt":
key_to_change = 1 change_first_key = false
var current_key = 0 var is_first_key = true
for old_event in InputMap.get_action_list( action_name ): for old_event in InputMap.get_action_list( action_name ):
if old_event is InputEventKey and key_to_change == current_key: if old_event is InputEventKey:
InputMap.action_erase_event(action_name, old_event) if is_first_key:
current_key +=1 if change_first_key:
InputMap.action_erase_event(action_name, old_event)
is_first_key = false
elif not change_first_key:
InputMap.action_erase_event(action_name, old_event)
InputMap.action_add_event(action_name, event) InputMap.action_add_event(action_name, event)
save_to_config(current_keyboard.name, action_name, current_keyboard.text) save_to_config(current_keyboard.name, action_name, current_keyboard.text)

View file

@ -45,12 +45,15 @@ move_up=[ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"
] ]
move_down=[ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777234,"unicode":0,"echo":false,"script":null) move_down=[ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777234,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":13,"pressure":0.0,"pressed":false,"script":null) , Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":13,"pressure":0.0,"pressed":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":83,"unicode":0,"echo":false,"script":null)
] ]
move_left=[ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777231,"unicode":0,"echo":false,"script":null) move_left=[ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777231,"unicode":0,"echo":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":14,"pressure":0.0,"pressed":false,"script":null) , Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":14,"pressure":0.0,"pressed":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":81,"unicode":0,"echo":false,"script":null)
] ]
move_right=[ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777233,"unicode":0,"echo":false,"script":null) move_right=[ Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":15,"pressure":0.0,"pressed":false,"script":null)
, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":15,"pressure":0.0,"pressed":false,"script":null) , Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777233,"unicode":0,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":68,"unicode":0,"echo":false,"script":null)
] ]
jump=[ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":32,"unicode":0,"echo":false,"script":null) jump=[ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":32,"unicode":0,"echo":false,"script":null)
] ]

View file

@ -14,7 +14,7 @@
[ext_resource path="res://scenes/GUI/HUD/trauma.gd" type="Script" id=12] [ext_resource path="res://scenes/GUI/HUD/trauma.gd" type="Script" id=12]
[ext_resource path="res://scenes/GUI/HUD/douleur.gd" type="Script" id=13] [ext_resource path="res://scenes/GUI/HUD/douleur.gd" type="Script" id=13]
[node name="HUD" type="MarginContainer" index="0"] [node name="HUD" type="MarginContainer"]
anchor_left = 0.0 anchor_left = 0.0
anchor_top = 0.0 anchor_top = 0.0

View file

@ -8,34 +8,35 @@ const ACTION_LIST = [ "ui_debug_window", "ui_music_controls", "hide_char", "ui_h
const ACTION_TEXT = [ "show/hide debug", "show/hide music", "Hide/show character", "hide/show UI", "move up", "move down", "move left", "move right", "fly up", "fly down", "on/off flashlight", "pause/play", "reload the scene", "free/capture mouse cursor", "quit" ] const ACTION_TEXT = [ "show/hide debug", "show/hide music", "Hide/show character", "hide/show UI", "move up", "move down", "move left", "move right", "fly up", "fly down", "on/off flashlight", "pause/play", "reload the scene", "free/capture mouse cursor", "quit" ]
func _ready(): func _ready():
# Called every time the node is added to the scene. _on_Refresh_pressed()
# Initialization here
var index = 0
for action_name in ACTION_LIST:
for event in InputMap.get_action_list( action_name ):
if event is InputEventKey:
var label = Label.new()
label.name = action_name
label.text = ACTION_TEXT[ index ] + ": " + OS.get_scancode_string( event.get_scancode_with_modifiers() )
$MarginContainer/VBoxContainer.add_child( label )
label.set_owner( $MarginContainer/VBoxContainer )
index += 1
func _on_Refresh_pressed(): func _on_Refresh_pressed():
var index = 0 var index = 0
for action_name in ACTION_LIST: for action_name in ACTION_LIST:
var event_index = 0
for event in InputMap.get_action_list( action_name ): for event in InputMap.get_action_list( action_name ):
if event is InputEventKey: if event is InputEventKey:
if get_node( "MarginContainer/VBoxContainer" ).has_node( action_name ): print("key: "+str(action_name+str(event_index)))
get_node( "MarginContainer/VBoxContainer" ).remove_child( get_node( "MarginContainer/VBoxContainer" ).get_node( action_name ) ) if get_node( "ScrollContainer/MarginContainer/VBoxContainer" ).has_node( action_name+str(event_index) ):
get_node( "ScrollContainer/MarginContainer/VBoxContainer" ).remove_child( get_node( "ScrollContainer/MarginContainer/VBoxContainer" ).get_node( action_name+str(event_index) ) )
var label = Label.new() var label = Label.new()
label.name = action_name label.name = action_name+str(event_index)
label.text = ACTION_TEXT[ index ] + ": " + OS.get_scancode_string( event.get_scancode_with_modifiers() ) label.text = ACTION_TEXT[ index ] + ": " + OS.get_scancode_string( event.get_scancode_with_modifiers() )
$MarginContainer/VBoxContainer.add_child( label ) $ScrollContainer/MarginContainer/VBoxContainer.add_child( label )
label.set_owner( $MarginContainer/VBoxContainer ) label.set_owner( $ScrollContainer/MarginContainer/VBoxContainer )
elif event is InputEventJoypadButton:
print("joy: "+str(action_name+str(event_index)))
if get_node( "ScrollContainer/MarginContainer/VBoxContainer" ).has_node( action_name+str(event_index) ):
get_node( "ScrollContainer/MarginContainer/VBoxContainer" ).remove_child( get_node( "ScrollContainer/MarginContainer/VBoxContainer" ).get_node( action_name+str(event_index) ) )
var label = Label.new()
label.name = action_name+str(event_index)
label.text = ACTION_TEXT[ index ] + ": " + Input.get_joy_button_string( event.button_index )
$ScrollContainer/MarginContainer/VBoxContainer.add_child( label )
label.set_owner( $ScrollContainer/MarginContainer/VBoxContainer )
event_index += 1
index += 1 index += 1
func _input( event ): func _input( event ):

View file

@ -14,7 +14,7 @@ flags = 4
gradient = SubResource( 1 ) gradient = SubResource( 1 )
width = 2048 width = 2048
[node name="Help" type="MarginContainer"] [node name="Help" type="MarginContainer" index="0"]
anchor_left = 0.0 anchor_left = 0.0
anchor_top = 0.0 anchor_top = 0.0
@ -41,8 +41,8 @@ anchor_left = 0.0
anchor_top = 0.0 anchor_top = 0.0
anchor_right = 0.0 anchor_right = 0.0
anchor_bottom = 0.0 anchor_bottom = 0.0
margin_right = 85.0 margin_right = 256.0
margin_bottom = 82.0 margin_bottom = 256.0
rect_pivot_offset = Vector2( 0, 0 ) rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = false rect_clip_content = false
mouse_filter = 2 mouse_filter = 2
@ -52,7 +52,29 @@ size_flags_vertical = 1
texture = SubResource( 2 ) texture = SubResource( 2 )
_sections_unfolded = [ "Anchor", "Margin", "Size Flags", "Theme" ] _sections_unfolded = [ "Anchor", "Margin", "Size Flags", "Theme" ]
[node name="MarginContainer" type="MarginContainer" parent="." index="1"] [node name="ScrollContainer" type="ScrollContainer" parent="." index="1"]
anchor_left = 0.0
anchor_top = 0.0
anchor_right = 0.0
anchor_bottom = 0.0
margin_right = 256.0
margin_bottom = 256.0
rect_min_size = Vector2( 256, 256 )
rect_pivot_offset = Vector2( 0, 0 )
rect_clip_content = true
mouse_filter = 0
mouse_default_cursor_shape = 0
size_flags_horizontal = 3
size_flags_vertical = 3
scroll_horizontal_enabled = true
scroll_horizontal = 0
scroll_vertical_enabled = true
scroll_vertical = 0
scroll_deadzone = 0
_sections_unfolded = [ "Rect", "Size Flags" ]
[node name="MarginContainer" type="MarginContainer" parent="ScrollContainer" index="2"]
anchor_left = 0.0 anchor_left = 0.0
anchor_top = 0.0 anchor_top = 0.0
@ -72,7 +94,7 @@ custom_constants/margin_left = 4
custom_constants/margin_bottom = 4 custom_constants/margin_bottom = 4
_sections_unfolded = [ "Anchor", "Margin", "custom_constants" ] _sections_unfolded = [ "Anchor", "Margin", "custom_constants" ]
[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer" index="0"] [node name="VBoxContainer" type="VBoxContainer" parent="ScrollContainer/MarginContainer" index="0"]
anchor_left = 0.0 anchor_left = 0.0
anchor_top = 0.0 anchor_top = 0.0
@ -91,7 +113,7 @@ size_flags_vertical = 1
alignment = 0 alignment = 0
_sections_unfolded = [ "Size Flags" ] _sections_unfolded = [ "Size Flags" ]
[node name="Title" type="Label" parent="MarginContainer/VBoxContainer" index="0"] [node name="Title" type="Label" parent="ScrollContainer/MarginContainer/VBoxContainer" index="0"]
anchor_left = 0.0 anchor_left = 0.0
anchor_top = 0.0 anchor_top = 0.0
@ -110,7 +132,7 @@ percent_visible = 1.0
lines_skipped = 0 lines_skipped = 0
max_lines_visible = -1 max_lines_visible = -1
[node name="FPS" type="Label" parent="MarginContainer/VBoxContainer" index="1"] [node name="FPS" type="Label" parent="ScrollContainer/MarginContainer/VBoxContainer" index="1"]
anchor_left = 0.0 anchor_left = 0.0
anchor_top = 0.0 anchor_top = 0.0
@ -131,7 +153,7 @@ lines_skipped = 0
max_lines_visible = -1 max_lines_visible = -1
script = ExtResource( 2 ) script = ExtResource( 2 )
[node name="DefaultKey" type="Label" parent="MarginContainer/VBoxContainer" index="2"] [node name="DefaultKey" type="Label" parent="ScrollContainer/MarginContainer/VBoxContainer" index="2"]
anchor_left = 0.0 anchor_left = 0.0
anchor_top = 0.0 anchor_top = 0.0
@ -151,7 +173,7 @@ percent_visible = 1.0
lines_skipped = 0 lines_skipped = 0
max_lines_visible = -1 max_lines_visible = -1
[node name="Refresh" type="Button" parent="MarginContainer/VBoxContainer" index="3"] [node name="Refresh" type="Button" parent="ScrollContainer/MarginContainer/VBoxContainer" index="3"]
anchor_left = 0.0 anchor_left = 0.0
anchor_top = 0.0 anchor_top = 0.0
@ -175,6 +197,6 @@ text = "refresh"
flat = false flat = false
align = 1 align = 1
[connection signal="pressed" from="MarginContainer/VBoxContainer/Refresh" to="." method="_on_Refresh_pressed"] [connection signal="pressed" from="ScrollContainer/MarginContainer/VBoxContainer/Refresh" to="." method="_on_Refresh_pressed"]

View file

@ -148,7 +148,7 @@ use_filter = false
font_data = ExtResource( 2 ) font_data = ExtResource( 2 )
_sections_unfolded = [ "Font", "Settings" ] _sections_unfolded = [ "Font", "Settings" ]
[node name="Settings" type="MarginContainer" index="0"] [node name="Settings" type="MarginContainer"]
anchor_left = 0.0 anchor_left = 0.0
anchor_top = 0.0 anchor_top = 0.0
@ -233,7 +233,6 @@ _sections_unfolded = [ "Hint", "Rect", "Size Flags", "Theme", "Visibility", "cus
[node name="Display" type="MarginContainer" parent="Menus/TabContainer" index="0"] [node name="Display" type="MarginContainer" parent="Menus/TabContainer" index="0"]
editor/display_folded = true editor/display_folded = true
visible = false
anchor_left = 0.0 anchor_left = 0.0
anchor_top = 0.0 anchor_top = 0.0
anchor_right = 1.0 anchor_right = 1.0
@ -619,6 +618,7 @@ _sections_unfolded = [ "Size Flags" ]
[node name="Controles" type="VBoxContainer" parent="Menus/TabContainer" index="1"] [node name="Controles" type="VBoxContainer" parent="Menus/TabContainer" index="1"]
visible = false
anchor_left = 0.0 anchor_left = 0.0
anchor_top = 0.0 anchor_top = 0.0
anchor_right = 1.0 anchor_right = 1.0
@ -679,7 +679,6 @@ _sections_unfolded = [ "Hint", "Size Flags", "custom_colors", "custom_constants"
[node name="Jeu" type="VBoxContainer" parent="Menus/TabContainer/Controles/ScrollContainer/TabContainer" index="0"] [node name="Jeu" type="VBoxContainer" parent="Menus/TabContainer/Controles/ScrollContainer/TabContainer" index="0"]
visible = false
anchor_left = 0.0 anchor_left = 0.0
anchor_top = 0.0 anchor_top = 0.0
anchor_right = 1.0 anchor_right = 1.0
@ -983,6 +982,7 @@ default_joypad = null
[node name="Deplacement" type="VBoxContainer" parent="Menus/TabContainer/Controles/ScrollContainer/TabContainer" index="2"] [node name="Deplacement" type="VBoxContainer" parent="Menus/TabContainer/Controles/ScrollContainer/TabContainer" index="2"]
visible = false
anchor_left = 0.0 anchor_left = 0.0
anchor_top = 0.0 anchor_top = 0.0
anchor_right = 1.0 anchor_right = 1.0