Controller Gamepad Suport for Rebind UI (Kindof, still needs polish)
This commit is contained in:
parent
07aa3c846b
commit
d3a27af77b
6 changed files with 185 additions and 21 deletions
|
@ -7,13 +7,14 @@
|
||||||
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_02uod"]
|
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_02uod"]
|
||||||
bg_color = Color(0.439216, 0.631373, 0.537255, 1)
|
bg_color = Color(0.439216, 0.631373, 0.537255, 1)
|
||||||
|
|
||||||
[node name="SettingsMenu" type="Node" node_paths=PackedStringArray("back_button", "tab_container", "bottom_item_video", "bottom_item_audio", "bottom_item_controls", "display_options_button", "vsync_toggle", "resolutions_options_button", "master_volume_slider", "music_volume_slider", "sfx_volume_slider")]
|
[node name="SettingsMenu" type="Node" node_paths=PackedStringArray("back_button", "tab_container", "bottom_item_video", "bottom_item_audio", "bottom_item_controls", "bottom_item_controls_gamepad", "display_options_button", "vsync_toggle", "resolutions_options_button", "master_volume_slider", "music_volume_slider", "sfx_volume_slider")]
|
||||||
script = ExtResource("1_2rgd2")
|
script = ExtResource("1_2rgd2")
|
||||||
back_button = NodePath("Back Button")
|
back_button = NodePath("Back Button")
|
||||||
tab_container = NodePath("SettingsTabs")
|
tab_container = NodePath("SettingsTabs")
|
||||||
bottom_item_video = NodePath("SettingsTabs/Video/MarginContainer/GridContainer/ResolutionsOptions")
|
bottom_item_video = NodePath("SettingsTabs/Video/MarginContainer/GridContainer/ResolutionsOptions")
|
||||||
bottom_item_audio = NodePath("SettingsTabs/Audio/MarginContainer/GridContainer/SFXVolSlider")
|
bottom_item_audio = NodePath("SettingsTabs/Audio/MarginContainer/GridContainer/SFXVolSlider")
|
||||||
bottom_item_controls = NodePath("SettingsTabs/Controls/MarginContainer/GridContainer/MoveRightRemapButton")
|
bottom_item_controls = NodePath("SettingsTabs/Controls/MarginContainer/GridContainer/AttackRemapButton")
|
||||||
|
bottom_item_controls_gamepad = NodePath("SettingsTabs/Gamepad/MarginContainer/GridContainer/AttackRemapButton")
|
||||||
display_options_button = NodePath("SettingsTabs/Video/MarginContainer/GridContainer/DisplayModeOptions")
|
display_options_button = NodePath("SettingsTabs/Video/MarginContainer/GridContainer/DisplayModeOptions")
|
||||||
vsync_toggle = NodePath("SettingsTabs/Video/MarginContainer/GridContainer/VsyncButton")
|
vsync_toggle = NodePath("SettingsTabs/Video/MarginContainer/GridContainer/VsyncButton")
|
||||||
resolutions_options_button = NodePath("SettingsTabs/Video/MarginContainer/GridContainer/ResolutionsOptions")
|
resolutions_options_button = NodePath("SettingsTabs/Video/MarginContainer/GridContainer/ResolutionsOptions")
|
||||||
|
@ -239,6 +240,104 @@ script = ExtResource("2_4asaa")
|
||||||
input_action_name = "move_right"
|
input_action_name = "move_right"
|
||||||
remap_controller = NodePath("../../../../../Remap Controller")
|
remap_controller = NodePath("../../../../../Remap Controller")
|
||||||
|
|
||||||
|
[node name="AttackLabel" type="Label" parent="SettingsTabs/Controls/MarginContainer/GridContainer"]
|
||||||
|
custom_minimum_size = Vector2(400, 40)
|
||||||
|
layout_mode = 2
|
||||||
|
text = "Attack
|
||||||
|
"
|
||||||
|
vertical_alignment = 1
|
||||||
|
|
||||||
|
[node name="AttackRemapButton" type="Button" parent="SettingsTabs/Controls/MarginContainer/GridContainer" node_paths=PackedStringArray("remap_controller")]
|
||||||
|
layout_mode = 2
|
||||||
|
size_flags_horizontal = 3
|
||||||
|
focus_neighbor_bottom = NodePath("../../../../../Back Button")
|
||||||
|
script = ExtResource("2_4asaa")
|
||||||
|
input_action_name = "attack"
|
||||||
|
remap_controller = NodePath("../../../../../Remap Controller")
|
||||||
|
|
||||||
|
[node name="Gamepad" type="VBoxContainer" parent="SettingsTabs"]
|
||||||
|
visible = false
|
||||||
|
layout_mode = 2
|
||||||
|
|
||||||
|
[node name="MarginContainer" type="MarginContainer" parent="SettingsTabs/Gamepad"]
|
||||||
|
custom_minimum_size = Vector2(0, 425)
|
||||||
|
layout_mode = 2
|
||||||
|
theme_override_constants/margin_left = 25
|
||||||
|
theme_override_constants/margin_top = 25
|
||||||
|
theme_override_constants/margin_right = 25
|
||||||
|
theme_override_constants/margin_bottom = 25
|
||||||
|
|
||||||
|
[node name="GridContainer" type="GridContainer" parent="SettingsTabs/Gamepad/MarginContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
columns = 2
|
||||||
|
|
||||||
|
[node name="MoveUpLabel" type="Label" parent="SettingsTabs/Gamepad/MarginContainer/GridContainer"]
|
||||||
|
custom_minimum_size = Vector2(400, 40)
|
||||||
|
layout_mode = 2
|
||||||
|
text = "Move Up"
|
||||||
|
vertical_alignment = 1
|
||||||
|
|
||||||
|
[node name="MoveUpRemapButton" type="Button" parent="SettingsTabs/Gamepad/MarginContainer/GridContainer" node_paths=PackedStringArray("remap_controller")]
|
||||||
|
layout_mode = 2
|
||||||
|
script = ExtResource("2_4asaa")
|
||||||
|
input_action_name = "move_up_controller"
|
||||||
|
remap_controller = NodePath("../../../../../Remap Controller")
|
||||||
|
|
||||||
|
[node name="MoveLeftLabel" type="Label" parent="SettingsTabs/Gamepad/MarginContainer/GridContainer"]
|
||||||
|
custom_minimum_size = Vector2(400, 40)
|
||||||
|
layout_mode = 2
|
||||||
|
text = "Move Left"
|
||||||
|
vertical_alignment = 1
|
||||||
|
|
||||||
|
[node name="MoveLeftRemapButton" type="Button" parent="SettingsTabs/Gamepad/MarginContainer/GridContainer" node_paths=PackedStringArray("remap_controller")]
|
||||||
|
layout_mode = 2
|
||||||
|
size_flags_horizontal = 3
|
||||||
|
script = ExtResource("2_4asaa")
|
||||||
|
input_action_name = "move_left_controller"
|
||||||
|
remap_controller = NodePath("../../../../../Remap Controller")
|
||||||
|
|
||||||
|
[node name="MoveDownLabel" type="Label" parent="SettingsTabs/Gamepad/MarginContainer/GridContainer"]
|
||||||
|
custom_minimum_size = Vector2(400, 40)
|
||||||
|
layout_mode = 2
|
||||||
|
text = "Move Down"
|
||||||
|
vertical_alignment = 1
|
||||||
|
|
||||||
|
[node name="MoveDownRemapButton" type="Button" parent="SettingsTabs/Gamepad/MarginContainer/GridContainer" node_paths=PackedStringArray("remap_controller")]
|
||||||
|
layout_mode = 2
|
||||||
|
size_flags_horizontal = 3
|
||||||
|
script = ExtResource("2_4asaa")
|
||||||
|
input_action_name = "move_down_controller"
|
||||||
|
remap_controller = NodePath("../../../../../Remap Controller")
|
||||||
|
|
||||||
|
[node name="MoveRightLabel" type="Label" parent="SettingsTabs/Gamepad/MarginContainer/GridContainer"]
|
||||||
|
custom_minimum_size = Vector2(400, 40)
|
||||||
|
layout_mode = 2
|
||||||
|
text = "Move RIght"
|
||||||
|
vertical_alignment = 1
|
||||||
|
|
||||||
|
[node name="MoveRightRemapButton" type="Button" parent="SettingsTabs/Gamepad/MarginContainer/GridContainer" node_paths=PackedStringArray("remap_controller")]
|
||||||
|
layout_mode = 2
|
||||||
|
size_flags_horizontal = 3
|
||||||
|
focus_neighbor_bottom = NodePath("../../../../../Back Button")
|
||||||
|
script = ExtResource("2_4asaa")
|
||||||
|
input_action_name = "move_right_controller"
|
||||||
|
remap_controller = NodePath("../../../../../Remap Controller")
|
||||||
|
|
||||||
|
[node name="AttackLabel" type="Label" parent="SettingsTabs/Gamepad/MarginContainer/GridContainer"]
|
||||||
|
custom_minimum_size = Vector2(400, 40)
|
||||||
|
layout_mode = 2
|
||||||
|
text = "Attack
|
||||||
|
"
|
||||||
|
vertical_alignment = 1
|
||||||
|
|
||||||
|
[node name="AttackRemapButton" type="Button" parent="SettingsTabs/Gamepad/MarginContainer/GridContainer" node_paths=PackedStringArray("remap_controller")]
|
||||||
|
layout_mode = 2
|
||||||
|
size_flags_horizontal = 3
|
||||||
|
focus_neighbor_bottom = NodePath("../../../../../Back Button")
|
||||||
|
script = ExtResource("2_4asaa")
|
||||||
|
input_action_name = "attack"
|
||||||
|
remap_controller = NodePath("../../../../../Remap Controller")
|
||||||
|
|
||||||
[node name="Back Button" type="Button" parent="."]
|
[node name="Back Button" type="Button" parent="."]
|
||||||
custom_minimum_size = Vector2(500, 40)
|
custom_minimum_size = Vector2(500, 40)
|
||||||
anchors_preset = 7
|
anchors_preset = 7
|
||||||
|
@ -268,4 +367,10 @@ text = "Back"
|
||||||
[connection signal="pressed" from="SettingsTabs/Controls/MarginContainer/GridContainer/MoveLeftRemapButton" to="SettingsTabs/Controls/MarginContainer/GridContainer/MoveLeftRemapButton" method="_on_pressed"]
|
[connection signal="pressed" from="SettingsTabs/Controls/MarginContainer/GridContainer/MoveLeftRemapButton" to="SettingsTabs/Controls/MarginContainer/GridContainer/MoveLeftRemapButton" method="_on_pressed"]
|
||||||
[connection signal="pressed" from="SettingsTabs/Controls/MarginContainer/GridContainer/MoveDownRemapButton" to="SettingsTabs/Controls/MarginContainer/GridContainer/MoveDownRemapButton" method="_on_pressed"]
|
[connection signal="pressed" from="SettingsTabs/Controls/MarginContainer/GridContainer/MoveDownRemapButton" to="SettingsTabs/Controls/MarginContainer/GridContainer/MoveDownRemapButton" method="_on_pressed"]
|
||||||
[connection signal="pressed" from="SettingsTabs/Controls/MarginContainer/GridContainer/MoveRightRemapButton" to="SettingsTabs/Controls/MarginContainer/GridContainer/MoveRightRemapButton" method="_on_pressed"]
|
[connection signal="pressed" from="SettingsTabs/Controls/MarginContainer/GridContainer/MoveRightRemapButton" to="SettingsTabs/Controls/MarginContainer/GridContainer/MoveRightRemapButton" method="_on_pressed"]
|
||||||
|
[connection signal="pressed" from="SettingsTabs/Controls/MarginContainer/GridContainer/AttackRemapButton" to="SettingsTabs/Controls/MarginContainer/GridContainer/AttackRemapButton" method="_on_pressed"]
|
||||||
|
[connection signal="pressed" from="SettingsTabs/Gamepad/MarginContainer/GridContainer/MoveUpRemapButton" to="SettingsTabs/Gamepad/MarginContainer/GridContainer/MoveUpRemapButton" method="_on_pressed"]
|
||||||
|
[connection signal="pressed" from="SettingsTabs/Gamepad/MarginContainer/GridContainer/MoveLeftRemapButton" to="SettingsTabs/Gamepad/MarginContainer/GridContainer/MoveLeftRemapButton" method="_on_pressed"]
|
||||||
|
[connection signal="pressed" from="SettingsTabs/Gamepad/MarginContainer/GridContainer/MoveDownRemapButton" to="SettingsTabs/Gamepad/MarginContainer/GridContainer/MoveDownRemapButton" method="_on_pressed"]
|
||||||
|
[connection signal="pressed" from="SettingsTabs/Gamepad/MarginContainer/GridContainer/MoveRightRemapButton" to="SettingsTabs/Gamepad/MarginContainer/GridContainer/MoveRightRemapButton" method="_on_pressed"]
|
||||||
|
[connection signal="pressed" from="SettingsTabs/Gamepad/MarginContainer/GridContainer/AttackRemapButton" to="SettingsTabs/Gamepad/MarginContainer/GridContainer/AttackRemapButton" method="_on_pressed"]
|
||||||
[connection signal="pressed" from="Back Button" to="." method="_on_back_pressed"]
|
[connection signal="pressed" from="Back Button" to="." method="_on_back_pressed"]
|
||||||
|
|
|
@ -13,13 +13,14 @@ func load_data():
|
||||||
"display_mode": 0,
|
"display_mode": 0,
|
||||||
"vsync_on": false,
|
"vsync_on": false,
|
||||||
"current_resolution_index": 0,
|
"current_resolution_index": 0,
|
||||||
"move_up": KEY_W,
|
|
||||||
"move_down": KEY_S,
|
|
||||||
"move_left": KEY_A,
|
|
||||||
"move_right": KEY_D,
|
|
||||||
"master_volume": 0,
|
"master_volume": 0,
|
||||||
"music_volume": 0,
|
"music_volume": 0,
|
||||||
"sfx_volume": 0,
|
"sfx_volume": 0,
|
||||||
|
"move_up": KEY_W,
|
||||||
|
"move_left": KEY_A,
|
||||||
|
"move_down": KEY_S,
|
||||||
|
"move_right": KEY_D,
|
||||||
|
"attack": "m" + str(MOUSE_BUTTON_LEFT),
|
||||||
}
|
}
|
||||||
save_data()
|
save_data()
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -4,12 +4,18 @@ extends Node
|
||||||
@export var music_bus_index : int = 1
|
@export var music_bus_index : int = 1
|
||||||
@export var sfx_bus_index : int = 2
|
@export var sfx_bus_index : int = 2
|
||||||
|
|
||||||
@export var remappable_input_actions = ["move_up", "move_down", "move_left", "move_right"]
|
@export var remappable_input_actions = [
|
||||||
|
"move_up",
|
||||||
|
"move_down",
|
||||||
|
"move_left",
|
||||||
|
"move_right",
|
||||||
|
"attack"
|
||||||
|
]
|
||||||
|
|
||||||
const resolutions_dictionary : Dictionary = {
|
const resolutions_dictionary : Dictionary = {
|
||||||
"800x600" : Vector2(800, 600),
|
"800x600" : Vector2(800, 600),
|
||||||
"1024x546" : Vector2(1024, 546),
|
"1024x546" : Vector2(1024, 546),
|
||||||
"1152x648" : Vector2(1152, 648),
|
"1280x720" : Vector2(1280, 720),
|
||||||
"1600x900" : Vector2(1600, 900),
|
"1600x900" : Vector2(1600, 900),
|
||||||
"1366x768" : Vector2(1366, 768),
|
"1366x768" : Vector2(1366, 768),
|
||||||
"1920x1080" : Vector2(1920, 1080),
|
"1920x1080" : Vector2(1920, 1080),
|
||||||
|
@ -65,15 +71,26 @@ func update_sfx_volume(vol : int) -> void:
|
||||||
# Controls
|
# Controls
|
||||||
func set_controls_from_save_file() -> void:
|
func set_controls_from_save_file() -> void:
|
||||||
for remappable_input_action in remappable_input_actions:
|
for remappable_input_action in remappable_input_actions:
|
||||||
for i in Save.game_data.keys().size():
|
var action = Save.game_data.keys().find(remappable_input_action)
|
||||||
if Save.game_data.keys()[i] == remappable_input_action:
|
for key in InputMap.action_get_events(remappable_input_action):
|
||||||
for key in InputMap.action_get_events(remappable_input_action):
|
InputMap.action_erase_event(remappable_input_action, key)
|
||||||
InputMap.action_erase_event(remappable_input_action, key)
|
var binding = Save.game_data.values()[action]
|
||||||
var control_key = InputEventKey.new()
|
var control_event
|
||||||
control_key.set_keycode(Save.game_data.values()[i])
|
match str(binding)[0]:
|
||||||
InputMap.action_add_event(remappable_input_action, control_key)
|
"m":
|
||||||
pass
|
binding = int(binding.right(binding.length()-1))
|
||||||
|
control_event = InputEventMouseButton.new()
|
||||||
func set_control_binding(action : String, keycode : int):
|
control_event.button_index = binding
|
||||||
print(keycode)
|
"b":
|
||||||
|
binding = int(binding.right(binding.length()-1))
|
||||||
|
control_event = InputEventJoypadButton.new()
|
||||||
|
control_event.button_index = binding
|
||||||
|
"j":
|
||||||
|
binding = int(binding.right(binding.length()-1))
|
||||||
|
control_event = InputEventJoypadMotion.new()
|
||||||
|
control_event.axis = binding
|
||||||
|
_:
|
||||||
|
control_event = InputEventKey.new()
|
||||||
|
control_event.set_keycode(binding)
|
||||||
|
InputMap.action_add_event(remappable_input_action, control_event)
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -7,7 +7,13 @@ func _ready():
|
||||||
display_key()
|
display_key()
|
||||||
|
|
||||||
func display_key ():
|
func display_key ():
|
||||||
text = "%s" % InputMap.action_get_events(input_action_name)[0].as_text()
|
self.text = "%s" % InputMap.action_get_events(input_action_name)[0].as_text()
|
||||||
|
if self.text.begins_with("Joypad Motion on Axis"):
|
||||||
|
var split_text = self.text.split(" ")
|
||||||
|
self.text = split_text[3] + " " + split_text[4]
|
||||||
|
if self.text.begins_with("Joypad Button"):
|
||||||
|
var split_text = self.text.split(" ")
|
||||||
|
self.text = split_text[1] + " " + split_text[2]
|
||||||
pass
|
pass
|
||||||
|
|
||||||
func _on_pressed():
|
func _on_pressed():
|
||||||
|
|
|
@ -1,24 +1,46 @@
|
||||||
extends Control
|
extends Control
|
||||||
|
|
||||||
|
@export var min_time_between_remaps := 0.1
|
||||||
|
|
||||||
var remap_button : Button
|
var remap_button : Button
|
||||||
var remap_action : String
|
var remap_action : String
|
||||||
|
|
||||||
|
var time_since_remap := 0.0
|
||||||
|
|
||||||
func _unhandled_key_input(event):
|
func _unhandled_key_input(event):
|
||||||
if remap_button != null and event.pressed:
|
if remap_button != null and event.pressed:
|
||||||
remap_key(event)
|
remap_key(event)
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
func _input(event):
|
||||||
|
if remap_button != null:
|
||||||
|
if event is InputEventMouseButton and event.pressed:
|
||||||
|
remap_key(event)
|
||||||
|
if event is InputEventJoypadButton and event.pressed:
|
||||||
|
print(event)
|
||||||
|
remap_key(event)
|
||||||
|
if event is InputEventJoypadMotion:
|
||||||
|
remap_key(event)
|
||||||
|
pass
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
set_process_unhandled_key_input(false)
|
set_process_unhandled_key_input(false)
|
||||||
remap_button = null
|
remap_button = null
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
func _process(delta):
|
||||||
|
if remap_button == null:
|
||||||
|
time_since_remap += delta
|
||||||
|
pass
|
||||||
|
|
||||||
func start_remap(button : Button, action : String):
|
func start_remap(button : Button, action : String):
|
||||||
|
if(time_since_remap < min_time_between_remaps): return
|
||||||
if(remap_button != null):
|
if(remap_button != null):
|
||||||
remap_button.display_key()
|
remap_button.display_key()
|
||||||
remap_button = button
|
remap_button = button
|
||||||
remap_action = action
|
remap_action = action
|
||||||
remap_button.text = "..."
|
remap_button.text = "..."
|
||||||
|
remap_button.disabled = true
|
||||||
set_process_unhandled_key_input(true)
|
set_process_unhandled_key_input(true)
|
||||||
button.release_focus()
|
button.release_focus()
|
||||||
pass
|
pass
|
||||||
|
@ -28,8 +50,19 @@ func remap_key(event):
|
||||||
for key in InputMap.action_get_events(remap_action):
|
for key in InputMap.action_get_events(remap_action):
|
||||||
InputMap.action_erase_event(remap_action, key)
|
InputMap.action_erase_event(remap_action, key)
|
||||||
InputMap.action_add_event(remap_action, event)
|
InputMap.action_add_event(remap_action, event)
|
||||||
Save.game_data["%s" % [remap_action]] = event.keycode
|
|
||||||
|
match str(event.get_class()):
|
||||||
|
"InputEventJoypadButton":
|
||||||
|
Save.game_data["%s" % [remap_action]] = "b" + str(event.button_index)
|
||||||
|
"InputEventJoypadMotion":
|
||||||
|
Save.game_data["%s" % [remap_action]] = "j" + str(event.axis)
|
||||||
|
"InputEventMouseButton":
|
||||||
|
Save.game_data["%s" % [remap_action]] = "m" + str(event.button_index)
|
||||||
|
"InputEventKey":
|
||||||
|
Save.game_data["%s" % [remap_action]] = event.keycode
|
||||||
remap_button.display_key()
|
remap_button.display_key()
|
||||||
remap_button.grab_focus()
|
remap_button.grab_focus()
|
||||||
|
remap_button.disabled = false
|
||||||
|
time_since_remap = 0
|
||||||
remap_button = null
|
remap_button = null
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -6,6 +6,7 @@ extends Node
|
||||||
@export var bottom_item_video : Control
|
@export var bottom_item_video : Control
|
||||||
@export var bottom_item_audio : Control
|
@export var bottom_item_audio : Control
|
||||||
@export var bottom_item_controls : Control
|
@export var bottom_item_controls : Control
|
||||||
|
@export var bottom_item_controls_gamepad : Control
|
||||||
|
|
||||||
@export var display_options_button : OptionButton
|
@export var display_options_button : OptionButton
|
||||||
@export var vsync_toggle : CheckButton
|
@export var vsync_toggle : CheckButton
|
||||||
|
@ -58,6 +59,7 @@ func update_change_tab():
|
||||||
0: back_button.focus_neighbor_top = bottom_item_video.get_path()
|
0: back_button.focus_neighbor_top = bottom_item_video.get_path()
|
||||||
1: back_button.focus_neighbor_top = bottom_item_audio.get_path()
|
1: back_button.focus_neighbor_top = bottom_item_audio.get_path()
|
||||||
2: back_button.focus_neighbor_top = bottom_item_controls.get_path()
|
2: back_button.focus_neighbor_top = bottom_item_controls.get_path()
|
||||||
|
3: back_button.focus_neighbor_top = bottom_item_controls_gamepad.get_path()
|
||||||
back_button.grab_focus()
|
back_button.grab_focus()
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
Reference in a new issue