ajout de panneaux de contrôles, de paramètres et refactorisation de la gestion de l'audio
This commit is contained in:
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