2022-02-25 00:28:14 +00:00
|
|
|
extends Control
|
|
|
|
|
|
|
|
signal refresh_control_define_input
|
2022-04-15 07:53:44 +00:00
|
|
|
signal cancel_define_input
|
2022-02-25 00:28:14 +00:00
|
|
|
|
|
|
|
var type_event:int
|
|
|
|
var action = null
|
|
|
|
var last_event = null
|
2022-04-15 07:53:44 +00:00
|
|
|
var last_last_event = null
|
|
|
|
var focus_ok:bool = false
|
|
|
|
var detect_two_event: bool = false
|
2022-02-25 00:28:14 +00:00
|
|
|
|
|
|
|
func _ready():
|
|
|
|
type_event = 0
|
|
|
|
|
|
|
|
|
|
|
|
func set_disabled(state:bool):
|
|
|
|
$Window/v/h/Ok.disabled = state
|
|
|
|
|
|
|
|
|
2022-04-15 07:53:44 +00:00
|
|
|
func get_action():
|
|
|
|
return action
|
|
|
|
|
|
|
|
|
|
|
|
func get_type_event():
|
|
|
|
return type_event
|
|
|
|
|
|
|
|
|
2022-02-25 00:28:14 +00:00
|
|
|
func set_param(typeevent:int, _action):
|
|
|
|
var comment = ""
|
|
|
|
if typeevent == 1:
|
|
|
|
comment = "OPTION_DEFINE_INPUT/MESSAGE_KEY"
|
|
|
|
elif typeevent == 2:
|
|
|
|
comment = "OPTION_DEFINE_INPUT/MESSAGE_MOUSE"
|
2022-04-15 13:54:35 +00:00
|
|
|
elif typeevent == 3:
|
|
|
|
comment = "OPTION_DEFINE_INPUT/MESSAGE_JOYPAD"
|
|
|
|
elif typeevent == 4:
|
2022-04-15 22:12:12 +00:00
|
|
|
comment = "OPTION_DEFINE_INPUT/MESSAGE_CAMERA_LEFT_JOYPAD"
|
|
|
|
elif typeevent == 5:
|
|
|
|
comment = "OPTION_DEFINE_INPUT/MESSAGE_CAMERA_RIGHT_JOYPAD"
|
|
|
|
elif typeevent == 6:
|
|
|
|
comment = "OPTION_DEFINE_INPUT/MESSAGE_CAMERA_FORWARD_JOYPAD"
|
|
|
|
elif typeevent == 7:
|
|
|
|
comment = "OPTION_DEFINE_INPUT/MESSAGE_CAMERA_BACK_JOYPAD"
|
|
|
|
elif typeevent == 8:
|
|
|
|
comment = "OPTION_DEFINE_INPUT/MESSAGE_ACTION_LEFT_JOYPAD"
|
|
|
|
elif typeevent == 9:
|
|
|
|
comment = "OPTION_DEFINE_INPUT/MESSAGE_ACTION_RIGHT_JOYPAD"
|
|
|
|
elif typeevent == 10:
|
|
|
|
comment = "OPTION_DEFINE_INPUT/MESSAGE_ACTION_FORWARD_JOYPAD"
|
|
|
|
elif typeevent == 11:
|
|
|
|
comment = "OPTION_DEFINE_INPUT/MESSAGE_ACTION_BACK_JOYPAD"
|
2022-04-15 13:54:35 +00:00
|
|
|
else:
|
|
|
|
comment = "OPTION_DEFINE_INPUT/DISABLED"
|
2022-02-25 00:28:14 +00:00
|
|
|
type_event = typeevent
|
|
|
|
action = _action
|
|
|
|
last_event = null
|
2022-04-15 07:53:44 +00:00
|
|
|
last_last_event = null
|
|
|
|
focus_ok = false
|
|
|
|
detect_two_event = false
|
2022-02-25 00:28:14 +00:00
|
|
|
$Window/v/result.set_text("")
|
|
|
|
$Window/v/label.set_text(comment)
|
|
|
|
set_disabled(true)
|
|
|
|
|
|
|
|
|
|
|
|
func _on_cancel_pressed():
|
|
|
|
$Window.hide()
|
2022-04-15 07:53:44 +00:00
|
|
|
emit_signal("cancel_define_input")
|
2022-02-25 00:28:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
func _on_ok_pressed():
|
|
|
|
$Window.hide()
|
2022-04-15 22:12:12 +00:00
|
|
|
Common.msg_debug("type_event: " + str(self.type_event))
|
|
|
|
Common.set_input_plus(action, last_event, last_last_event, self.type_event == 2 or (self.type_event >= 4 and self.type_event <= 11))
|
2022-02-25 00:28:14 +00:00
|
|
|
emit_signal("refresh_control_define_input")
|
|
|
|
|
|
|
|
|
|
|
|
func _on_window_window_input(event):
|
|
|
|
if event.is_pressed() == false:
|
|
|
|
return
|
2022-04-15 07:53:44 +00:00
|
|
|
if focus_ok:
|
|
|
|
return
|
2022-02-25 00:28:14 +00:00
|
|
|
if (event is InputEventKey) && (self.type_event == 1):
|
|
|
|
last_event = event
|
|
|
|
$Window/v/result.set_text( Common.get_string_input(event) )
|
|
|
|
elif event is InputEventMouseButton and self.type_event == 2:
|
2022-04-15 07:53:44 +00:00
|
|
|
last_last_event = last_event
|
2022-02-25 00:28:14 +00:00
|
|
|
last_event = event
|
2022-04-15 07:53:44 +00:00
|
|
|
if last_last_event:
|
|
|
|
if last_last_event.get_button_index() == last_event.get_button_index():
|
|
|
|
detect_two_event = false
|
|
|
|
last_last_event = null
|
|
|
|
elif Input.is_mouse_button_pressed( last_last_event.get_button_index() ):
|
|
|
|
detect_two_event = true
|
|
|
|
else:
|
|
|
|
detect_two_event = false
|
|
|
|
last_last_event = null
|
|
|
|
else:
|
|
|
|
detect_two_event = false
|
|
|
|
last_last_event = null
|
|
|
|
if detect_two_event == false:
|
|
|
|
$Window/v/result.set_text( Common.get_string_input(event) )
|
|
|
|
else:
|
|
|
|
$Window/v/result.set_text( tr(Common.get_string_input(event)) + " + " + tr(Common.get_string_input(last_last_event)))
|
2022-02-25 00:28:14 +00:00
|
|
|
elif event is InputEventJoypadButton and self.type_event == 3:
|
|
|
|
last_event = event
|
|
|
|
$Window/v/result.set_text( Common.get_string_input(event) )
|
2022-04-15 22:12:12 +00:00
|
|
|
elif event is InputEventJoypadMotion and (self.type_event >= 4 and self.type_event <= 11):
|
|
|
|
if event.get_axis_value() < 0:
|
|
|
|
event.set_axis_value(-1.0)
|
2022-04-15 13:54:35 +00:00
|
|
|
else:
|
2022-04-15 22:12:12 +00:00
|
|
|
event.set_axis_value(1.0)
|
|
|
|
last_event = event
|
|
|
|
$Window/v/result.set_text( Common.get_string_input(event) )
|
2022-02-25 00:28:14 +00:00
|
|
|
if last_event != null:
|
2022-04-15 22:12:12 +00:00
|
|
|
set_disabled(false)
|
2022-04-15 07:53:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
func _on_ok_mouse_entered():
|
|
|
|
focus_ok = true
|
|
|
|
|
|
|
|
|
|
|
|
func _on_ok_mouse_exited():
|
|
|
|
focus_ok = false
|