ajout de panneaux de contrôles, de paramètres et refactorisation de la gestion de l'audio
This commit is contained in:
35
gui/menu/controls/controls.tscn
Normal file
35
gui/menu/controls/controls.tscn
Normal file
@@ -0,0 +1,35 @@
|
||||
[gd_scene load_steps=3 format=3 uid="uid://b4qe1dwwsk87t"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://dmefdkcsmgr4l" path="res://gui/menu/controls/scripts/controls.gd" id="1_g86te"]
|
||||
[ext_resource type="PackedScene" uid="uid://brxrl7sipyy6k" path="res://gui/menu/window/window.tscn" id="1_mnd1d"]
|
||||
|
||||
[node name="Controls" type="Control"]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
script = ExtResource("1_g86te")
|
||||
|
||||
[node name="ControlsWindow" parent="." instance=ExtResource("1_mnd1d")]
|
||||
unique_name_in_owner = true
|
||||
custom_minimum_size = Vector2(900, 500)
|
||||
layout_mode = 1
|
||||
title = "CONTROLS"
|
||||
|
||||
[node name="WindowTitle" parent="ControlsWindow/WindowHeader/MarginContainer" index="0"]
|
||||
text = "CONTROLS"
|
||||
|
||||
[node name="MarginContainer" type="MarginContainer" parent="ControlsWindow/WindowContent/MarginContainer/ContentContainer" index="0"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 3
|
||||
theme_override_constants/margin_left = 5
|
||||
theme_override_constants/margin_top = 0
|
||||
|
||||
[node name="ControlsContainer" type="VBoxContainer" parent="ControlsWindow/WindowContent/MarginContainer/ContentContainer/MarginContainer"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
|
||||
[editable path="ControlsWindow"]
|
||||
24
gui/menu/controls/input_group.tscn
Normal file
24
gui/menu/controls/input_group.tscn
Normal file
@@ -0,0 +1,24 @@
|
||||
[gd_scene load_steps=4 format=3 uid="uid://dapsvw31ux0j2"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://d3agt2njfgddb" path="res://gui/menu/window/content_label.tscn" id="1_ganst"]
|
||||
[ext_resource type="Script" uid="uid://dhs6kispjoecs" path="res://gui/menu/controls/scripts/input_group.gd" id="1_kkwd7"]
|
||||
[ext_resource type="Theme" uid="uid://bgcmd213j6gk1" path="res://gui/ressources/default_theme.tres" id="3_s602q"]
|
||||
|
||||
[node name="InputGroup" type="HBoxContainer"]
|
||||
size_flags_horizontal = 3
|
||||
script = ExtResource("1_kkwd7")
|
||||
|
||||
[node name="Text" parent="." instance=ExtResource("1_ganst")]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
text = "Input"
|
||||
|
||||
[node name="Button" type="Button" parent="."]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 10
|
||||
theme = ExtResource("3_s602q")
|
||||
text = "Text"
|
||||
|
||||
[connection signal="button_down" from="Button" to="." method="_on_button_button_down"]
|
||||
[connection signal="pressed" from="Button" to="." method="_on_button_pressed"]
|
||||
33
gui/menu/controls/scripts/controls.gd
Normal file
33
gui/menu/controls/scripts/controls.gd
Normal file
@@ -0,0 +1,33 @@
|
||||
@tool
|
||||
extends Control
|
||||
|
||||
const INPUT_GROUP_SCENE = preload("res://gui/menu/controls/input_group.tscn")
|
||||
|
||||
@export_tool_button("Update", "Callable") var update_action = create_input_list
|
||||
|
||||
func _ready():
|
||||
create_input_list()
|
||||
if not Engine.is_editor_hint():
|
||||
%ControlsWindow.close_window()
|
||||
show()
|
||||
|
||||
func open_controls():
|
||||
%ControlsWindow.open_window()
|
||||
|
||||
func close_controls():
|
||||
%ControlsWindow.close_window()
|
||||
|
||||
func create_input_list():
|
||||
InputMap.load_from_project_settings()
|
||||
for child in %ControlsContainer.get_children():
|
||||
child.queue_free()
|
||||
|
||||
for action in InputMap.get_actions():
|
||||
if action.substr(0, 3) != "ui_":
|
||||
var input_group = instantiate_input_group()
|
||||
input_group.action_name = action
|
||||
%ControlsContainer.add_child(input_group)
|
||||
|
||||
|
||||
func instantiate_input_group() -> InputGroup:
|
||||
return INPUT_GROUP_SCENE.instantiate() as InputGroup
|
||||
1
gui/menu/controls/scripts/controls.gd.uid
Normal file
1
gui/menu/controls/scripts/controls.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://dmefdkcsmgr4l
|
||||
38
gui/menu/controls/scripts/input_group.gd
Normal file
38
gui/menu/controls/scripts/input_group.gd
Normal file
@@ -0,0 +1,38 @@
|
||||
@tool
|
||||
extends HBoxContainer
|
||||
class_name InputGroup
|
||||
|
||||
const MAX_INPUT_NAME = 30
|
||||
|
||||
var event : InputEvent = null
|
||||
var is_remapping := false
|
||||
|
||||
@export var action_name : String :
|
||||
set(v):
|
||||
action_name = v
|
||||
var events : Array[InputEvent] = InputMap.action_get_events(action_name)
|
||||
event = null if events.size() == 0 else events[0]
|
||||
update()
|
||||
|
||||
func update():
|
||||
%Text.text = action_name.to_upper()
|
||||
var input_name = "UNASSIGNED" if event == null else event.as_text()
|
||||
if input_name.length() > MAX_INPUT_NAME:
|
||||
input_name = input_name.substr(0,MAX_INPUT_NAME) + "..."
|
||||
%Button.text = input_name
|
||||
# (%Button as Button).add_theme_color_override("font_color", Color.RED if )
|
||||
|
||||
func _input(new_event):
|
||||
if is_remapping:
|
||||
if (
|
||||
new_event is InputEventKey or (new_event is InputEventMouseButton and new_event.is_pressed())
|
||||
):
|
||||
is_remapping = false
|
||||
GameInfo.update_input(action_name, event, new_event)
|
||||
event = new_event
|
||||
update()
|
||||
|
||||
func _on_button_button_down():
|
||||
if !is_remapping:
|
||||
is_remapping = true
|
||||
%Button.text = "PRESS_KEY"
|
||||
1
gui/menu/controls/scripts/input_group.gd.uid
Normal file
1
gui/menu/controls/scripts/input_group.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://dhs6kispjoecs
|
||||
Reference in New Issue
Block a user