Ajout du menu principal et des paramètres. Attention : ça ne fonctionne pas

This commit is contained in:
E213872U 2025-01-24 08:58:24 +01:00
parent ffaa27de5c
commit 432f7ccc7a
28 changed files with 69743 additions and 19 deletions

View file

@ -0,0 +1,49 @@
[gd_scene load_steps=2 format=3 uid="uid://n5vmjs3xhmma"]
[ext_resource type="Script" path="res://parametres/assign_menu/assigner_bouton.gd" id="1_jtqf2"]
[node name="assigner_bouton" type="Control" groups=["changer_touches"]]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_jtqf2")
[node name="HBoxContainer" type="HBoxContainer" parent="."]
layout_mode = 1
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -268.5
offset_top = -26.5
offset_right = 268.5
offset_bottom = 26.5
grow_horizontal = 2
grow_vertical = 2
alignment = 1
[node name="Label" type="Label" parent="HBoxContainer"]
custom_minimum_size = Vector2(200, 40)
layout_mode = 2
theme_override_font_sizes/font_size = 32
text = "ACTION"
vertical_alignment = 1
[node name="VSeparator" type="VSeparator" parent="HBoxContainer"]
modulate = Color(1, 1, 1, 0)
self_modulate = Color(1, 1, 1, 0)
custom_minimum_size = Vector2(50, 0)
layout_mode = 2
[node name="Button" type="Button" parent="HBoxContainer"]
custom_minimum_size = Vector2(75, 75)
layout_mode = 2
theme_override_font_sizes/font_size = 32
text = "BOUTON ACTION
"
[connection signal="pressed" from="HBoxContainer/Button" to="." method="_on_button_pressed"]

View file

@ -0,0 +1,67 @@
class_name Assigner_Bouton
extends Control
@onready var label = $HBoxContainer/Label as Label
@onready var button = $HBoxContainer/Button as Button
@export var nom_action : String = "BOUGER_HAUT"
var nom_touche : String = OS.get_keycode_string(InputMap.action_get_events(nom_action)[0].physical_keycode)
# Called when the node enters the scene tree for the first time.
func _ready():
set_process_unhandled_key_input(false)
set_texte_label()
set_texte_bouton()
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
pass
func set_texte_label() -> void :
label.text = "Non assignée"
match nom_action :
"BOUGER_HAUT":
label.text = "monter"
"BOUGER_BAS":
label.text = "descendre"
"BOUGER_DROITE":
label.text = "droite"
"BOUGER_GAUCHE":
label.text = "gauche"
"PAUSE":
label.text = "Pause"
func set_texte_bouton() -> void:
nom_touche = OS.get_keycode_string(InputMap.action_get_events(nom_action)[0].physical_keycode)
button.text = "%s" % nom_touche
func definir_touche(touche)-> void:
var old = InputMap.action_get_events(nom_action)[0]
var action_keycode=touche.physical_keycode
InputMap.action_erase_events(nom_action)
InputMap.action_add_event(nom_action, touche)
set_texte_bouton()
for i in get_tree().get_nodes_in_group("changer_touches"):
if i.nom_action != self.nom_action :
if i.nom_touche==self.nom_touche :
i.definir_touche(old)
func _on_button_pressed():
button.text = "Appuyez sur une touche..."
set_process_unhandled_key_input(true)
func _unhandled_key_input(event):
definir_touche(event)
set_process_unhandled_key_input(false)
func _on_hidden():
set_process_unhandled_key_input(true)
set_texte_bouton()

View file

@ -0,0 +1,50 @@
[gd_scene load_steps=2 format=3 uid="uid://n5vmjs3xhmma"]
[ext_resource type="Script" path="res://parametres/assign_menu/assigner_bouton.gd" id="1_jtqf2"]
[node name="assigner_bouton" type="Control" groups=["changer_touches"]]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_jtqf2")
[node name="HBoxContainer" type="HBoxContainer" parent="."]
layout_mode = 1
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -268.5
offset_top = -26.5
offset_right = 268.5
offset_bottom = 26.5
grow_horizontal = 2
grow_vertical = 2
alignment = 1
[node name="Label" type="Label" parent="HBoxContainer"]
custom_minimum_size = Vector2(200, 40)
layout_mode = 2
theme_override_font_sizes/font_size = 32
text = "ACTION"
vertical_alignment = 1
[node name="VSeparator" type="VSeparator" parent="HBoxContainer"]
modulate = Color(1, 1, 1, 0)
self_modulate = Color(1, 1, 1, 0)
custom_minimum_size = Vector2(50, 0)
layout_mode = 2
size_flags_horizontal = 3
[node name="Button" type="Button" parent="HBoxContainer"]
custom_minimum_size = Vector2(150, 75)
layout_mode = 2
theme_override_font_sizes/font_size = 32
text = "BOUTON_ACTION"
[connection signal="hidden" from="." to="." method="_on_hidden"]
[connection signal="pressed" from="HBoxContainer/Button" to="." method="_on_button_pressed"]