-
Notifications
You must be signed in to change notification settings - Fork 1
/
BindingButton.gd
48 lines (41 loc) · 1.36 KB
/
BindingButton.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
extends Button
class_name BindingButton
export var action: String = "";
export var keyboard_mode: bool = true;
export var i: int = 0;
var event: InputEvent = null;
var parent: Node2D = null;
var image: Sprite = null;
func _ready() -> void:
set_process_unhandled_input(false)
set_process_unhandled_key_input(false)
func _toggled(is_button_pressed):
set_process_unhandled_input(is_button_pressed)
set_process_unhandled_key_input(is_button_pressed)
if is_button_pressed:
text = "(What?)"
if (image != null):
image.queue_free();
image = null;
if (parent.rebinding_button != null and parent.rebinding_button != self):
parent.rebinding_button.pressed = false;
parent.rebinding_button._toggled(false);
parent.rebinding_button = self;
release_focus();
else:
display_current_key()
func _gui_input(event):
if event is InputEventMouseButton:
if event.button_index == BUTTON_RIGHT and event.pressed:
parent.remap_dance(self, null);
pressed = false
func _unhandled_input(new_event : InputEvent):
if new_event is InputEventJoypadButton and !keyboard_mode and new_event.is_pressed():
parent.remap_dance(self, new_event)
pressed = false
func _unhandled_key_input(new_event : InputEventKey):
if keyboard_mode and new_event.is_pressed():
parent.remap_dance(self, new_event)
pressed = false
func display_current_key():
parent.setup_button(self);