forked from team-sg/hero-mark-2
basic implementation of input remapping
This commit is contained in:
parent
5f2b3c6d5e
commit
70ef1a8450
5 changed files with 290 additions and 45 deletions
|
@ -1,4 +1,4 @@
|
|||
[gd_scene load_steps=10 format=2]
|
||||
[gd_scene load_steps=12 format=2]
|
||||
|
||||
[ext_resource path="res://objects/hud/options_screen_scholar.gd" type="Script" id=1]
|
||||
[ext_resource path="res://ui/theme.tres" type="Theme" id=2]
|
||||
|
@ -7,6 +7,8 @@
|
|||
[ext_resource path="res://graphics/hud/pause_arrow.png" type="Texture" id=5]
|
||||
[ext_resource path="res://objects/hud/select_border.gd" type="Script" id=6]
|
||||
[ext_resource path="res://objects/hud/labeled_slider.gd" type="Script" id=7]
|
||||
[ext_resource path="res://objects/hud/set_keyboard_button.gd" type="Script" id=8]
|
||||
[ext_resource path="res://objects/hud/set_gamepad_button.gd" type="Script" id=9]
|
||||
|
||||
[sub_resource type="ShaderMaterial" id=1]
|
||||
shader = ExtResource( 4 )
|
||||
|
@ -249,6 +251,7 @@ alignment = 1
|
|||
|
||||
[node name="BorderBackArrow" type="TextureRect" parent="CenterContainer/PanelContainer/MarginContainer/VBoxContainer/Tabs/Video/Border/HBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
visible = false
|
||||
material = SubResource( 1 )
|
||||
margin_left = 30.0
|
||||
margin_top = 1.0
|
||||
|
@ -266,6 +269,7 @@ margin_bottom = 10.0
|
|||
focus_neighbour_left = NodePath(".")
|
||||
focus_neighbour_top = NodePath("../../../FadeSpeed/SelectFadeSpeed")
|
||||
focus_neighbour_right = NodePath(".")
|
||||
focus_neighbour_bottom = NodePath("../../../Scanlines/SelectScanlines")
|
||||
theme = ExtResource( 2 )
|
||||
custom_colors/font_color = Color( 1, 1, 1, 1 )
|
||||
text = "trans rights"
|
||||
|
@ -273,6 +277,7 @@ script = ExtResource( 6 )
|
|||
|
||||
[node name="BorderNextArrow" type="TextureRect" parent="CenterContainer/PanelContainer/MarginContainer/VBoxContainer/Tabs/Video/Border/HBoxContainer"]
|
||||
unique_name_in_owner = true
|
||||
visible = false
|
||||
material = SubResource( 2 )
|
||||
margin_left = 128.0
|
||||
margin_top = 1.0
|
||||
|
@ -296,8 +301,7 @@ unique_name_in_owner = true
|
|||
margin_left = 74.0
|
||||
margin_right = 218.0
|
||||
margin_bottom = 10.0
|
||||
focus_neighbour_top = NodePath("../../Scaling/SelectScaling")
|
||||
focus_neighbour_bottom = NodePath("../../Border/HBoxContainer/SelectBorder")
|
||||
focus_neighbour_top = NodePath("../../Border/HBoxContainer/SelectBorder")
|
||||
focus_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
script = ExtResource( 3 )
|
||||
|
@ -495,6 +499,8 @@ margin_right = 155.0
|
|||
margin_bottom = 10.0
|
||||
size_flags_horizontal = 3
|
||||
text = "-"
|
||||
script = ExtResource( 8 )
|
||||
action = "move_left"
|
||||
|
||||
[node name="Gamepad" type="Button" parent="CenterContainer/PanelContainer/MarginContainer/VBoxContainer/Tabs/Input/Left"]
|
||||
margin_left = 159.0
|
||||
|
@ -502,6 +508,8 @@ margin_right = 218.0
|
|||
margin_bottom = 10.0
|
||||
size_flags_horizontal = 3
|
||||
text = "-"
|
||||
script = ExtResource( 9 )
|
||||
action = "move_left"
|
||||
|
||||
[node name="Right" type="HBoxContainer" parent="CenterContainer/PanelContainer/MarginContainer/VBoxContainer/Tabs/Input"]
|
||||
margin_top = 30.0
|
||||
|
@ -521,6 +529,8 @@ margin_right = 155.0
|
|||
margin_bottom = 10.0
|
||||
size_flags_horizontal = 3
|
||||
text = "-"
|
||||
script = ExtResource( 8 )
|
||||
action = "move_right"
|
||||
|
||||
[node name="Gamepad" type="Button" parent="CenterContainer/PanelContainer/MarginContainer/VBoxContainer/Tabs/Input/Right"]
|
||||
margin_left = 159.0
|
||||
|
@ -528,6 +538,8 @@ margin_right = 218.0
|
|||
margin_bottom = 10.0
|
||||
size_flags_horizontal = 3
|
||||
text = "-"
|
||||
script = ExtResource( 9 )
|
||||
action = "move_right"
|
||||
|
||||
[node name="Up" type="HBoxContainer" parent="CenterContainer/PanelContainer/MarginContainer/VBoxContainer/Tabs/Input"]
|
||||
margin_top = 44.0
|
||||
|
@ -547,6 +559,8 @@ margin_right = 155.0
|
|||
margin_bottom = 10.0
|
||||
size_flags_horizontal = 3
|
||||
text = "-"
|
||||
script = ExtResource( 8 )
|
||||
action = "move_up"
|
||||
|
||||
[node name="Gamepad" type="Button" parent="CenterContainer/PanelContainer/MarginContainer/VBoxContainer/Tabs/Input/Up"]
|
||||
margin_left = 159.0
|
||||
|
@ -554,6 +568,8 @@ margin_right = 218.0
|
|||
margin_bottom = 10.0
|
||||
size_flags_horizontal = 3
|
||||
text = "-"
|
||||
script = ExtResource( 9 )
|
||||
action = "move_up"
|
||||
|
||||
[node name="Down" type="HBoxContainer" parent="CenterContainer/PanelContainer/MarginContainer/VBoxContainer/Tabs/Input"]
|
||||
margin_top = 58.0
|
||||
|
@ -573,6 +589,8 @@ margin_right = 155.0
|
|||
margin_bottom = 10.0
|
||||
size_flags_horizontal = 3
|
||||
text = "-"
|
||||
script = ExtResource( 8 )
|
||||
action = "move_down"
|
||||
|
||||
[node name="Gamepad" type="Button" parent="CenterContainer/PanelContainer/MarginContainer/VBoxContainer/Tabs/Input/Down"]
|
||||
margin_left = 159.0
|
||||
|
@ -580,6 +598,8 @@ margin_right = 218.0
|
|||
margin_bottom = 10.0
|
||||
size_flags_horizontal = 3
|
||||
text = "-"
|
||||
script = ExtResource( 9 )
|
||||
action = "move_down"
|
||||
|
||||
[node name="Jump" type="HBoxContainer" parent="CenterContainer/PanelContainer/MarginContainer/VBoxContainer/Tabs/Input"]
|
||||
margin_top = 72.0
|
||||
|
@ -599,6 +619,8 @@ margin_right = 155.0
|
|||
margin_bottom = 10.0
|
||||
size_flags_horizontal = 3
|
||||
text = "-"
|
||||
script = ExtResource( 8 )
|
||||
action = "jump"
|
||||
|
||||
[node name="Gamepad" type="Button" parent="CenterContainer/PanelContainer/MarginContainer/VBoxContainer/Tabs/Input/Jump"]
|
||||
margin_left = 159.0
|
||||
|
@ -606,6 +628,8 @@ margin_right = 218.0
|
|||
margin_bottom = 10.0
|
||||
size_flags_horizontal = 3
|
||||
text = "-"
|
||||
script = ExtResource( 9 )
|
||||
action = "jump"
|
||||
|
||||
[node name="Attack" type="HBoxContainer" parent="CenterContainer/PanelContainer/MarginContainer/VBoxContainer/Tabs/Input"]
|
||||
margin_top = 86.0
|
||||
|
@ -625,6 +649,8 @@ margin_right = 155.0
|
|||
margin_bottom = 10.0
|
||||
size_flags_horizontal = 3
|
||||
text = "-"
|
||||
script = ExtResource( 8 )
|
||||
action = "shoot"
|
||||
|
||||
[node name="Gamepad" type="Button" parent="CenterContainer/PanelContainer/MarginContainer/VBoxContainer/Tabs/Input/Attack"]
|
||||
margin_left = 159.0
|
||||
|
@ -632,6 +658,16 @@ margin_right = 218.0
|
|||
margin_bottom = 10.0
|
||||
size_flags_horizontal = 3
|
||||
text = "-"
|
||||
script = ExtResource( 9 )
|
||||
action = "shoot"
|
||||
|
||||
[node name="DefaultControls" type="Button" parent="CenterContainer/PanelContainer/MarginContainer/VBoxContainer"]
|
||||
margin_left = 81.0
|
||||
margin_top = 136.0
|
||||
margin_right = 137.0
|
||||
margin_bottom = 146.0
|
||||
size_flags_horizontal = 4
|
||||
text = "defaults"
|
||||
|
||||
[connection signal="selected" from="CenterContainer/PanelContainer/MarginContainer/VBoxContainer/SelectTab" to="." method="_on_tab_selected"]
|
||||
[connection signal="selected" from="CenterContainer/PanelContainer/MarginContainer/VBoxContainer/Tabs/Game/Rumble/SelectRumble" to="." method="_on_Rumble_selected"]
|
||||
|
|
55
objects/hud/set_gamepad_button.gd
Normal file
55
objects/hud/set_gamepad_button.gd
Normal file
|
@ -0,0 +1,55 @@
|
|||
extends Button
|
||||
|
||||
|
||||
const BLINK_SPEED: int = 150
|
||||
|
||||
|
||||
export var action: String
|
||||
|
||||
|
||||
var listen := false
|
||||
|
||||
|
||||
func _init() -> void:
|
||||
connect("pressed", self, "_on_pressed")
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
_update_text()
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if listen:
|
||||
if Time.get_ticks_msec() % (BLINK_SPEED * 2) < BLINK_SPEED:
|
||||
modulate.a = 0.0
|
||||
else:
|
||||
modulate.a = 1.0
|
||||
|
||||
|
||||
func _update_text() -> void:
|
||||
text = str(Controls.get_button(action))
|
||||
modulate.a = 1.0
|
||||
|
||||
|
||||
func _on_pressed() -> void:
|
||||
if not listen:
|
||||
listen = true
|
||||
disabled = true
|
||||
text = ""
|
||||
get_tree().create_timer(2.0, true).connect("timeout", self, "_on_timeout")
|
||||
|
||||
|
||||
func _on_timeout() -> void:
|
||||
listen = false
|
||||
disabled = false
|
||||
_update_text()
|
||||
|
||||
|
||||
func _gui_input(event: InputEvent) -> void:
|
||||
if listen:
|
||||
if event is InputEventJoypadButton and event.pressed:
|
||||
Controls.set_button(action, event.button_index)
|
||||
listen = false
|
||||
set_deferred("disabled", false)
|
||||
_update_text()
|
||||
accept_event()
|
55
objects/hud/set_keyboard_button.gd
Normal file
55
objects/hud/set_keyboard_button.gd
Normal file
|
@ -0,0 +1,55 @@
|
|||
extends Button
|
||||
|
||||
|
||||
const BLINK_SPEED: int = 150
|
||||
|
||||
|
||||
export var action: String
|
||||
|
||||
|
||||
var listen := false
|
||||
|
||||
|
||||
func _init() -> void:
|
||||
connect("pressed", self, "_on_pressed")
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
_update_text()
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if listen:
|
||||
if Time.get_ticks_msec() % (BLINK_SPEED * 2) < BLINK_SPEED:
|
||||
modulate.a = 0.0
|
||||
else:
|
||||
modulate.a = 1.0
|
||||
|
||||
|
||||
func _update_text() -> void:
|
||||
text = OS.get_scancode_string(Controls.get_key(action))
|
||||
modulate.a = 1.0
|
||||
|
||||
|
||||
func _on_pressed() -> void:
|
||||
if not listen:
|
||||
listen = true
|
||||
disabled = true
|
||||
text = ""
|
||||
get_tree().create_timer(2.0, true).connect("timeout", self, "_on_timeout")
|
||||
|
||||
|
||||
func _on_timeout() -> void:
|
||||
listen = false
|
||||
disabled = false
|
||||
_update_text()
|
||||
|
||||
|
||||
func _gui_input(event: InputEvent) -> void:
|
||||
if listen:
|
||||
if event is InputEventKey and event.pressed:
|
||||
Controls.set_key(action, event.physical_scancode)
|
||||
listen = false
|
||||
set_deferred("disabled", false)
|
||||
_update_text()
|
||||
accept_event()
|
Loading…
Add table
Add a link
Reference in a new issue