godot-third-person-basic-scene/scenes/controls/option_define_input.gd

116 lines
3 KiB
GDScript

extends Control
signal refresh_control_define_input
signal cancel_define_input
var type_event:int
var action = null
var last_event = null
var last_last_event = null
var focus_ok:bool = false
var detect_two_event: bool = false
func _ready():
type_event = 0
func set_disabled(state:bool):
$Window/v/h/Ok.disabled = state
func get_action():
return action
func get_type_event():
return type_event
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"
elif typeevent == 3:
comment = "OPTION_DEFINE_INPUT/MESSAGE_JOYPAD"
elif typeevent == 4:
comment = "OPTION_DEFINE_INPUT/MESSAGE_JOYPAD"
else:
comment = "OPTION_DEFINE_INPUT/DISABLED"
type_event = typeevent
action = _action
last_event = null
last_last_event = null
focus_ok = false
detect_two_event = false
$Window/v/result.set_text("")
$Window/v/label.set_text(comment)
set_disabled(true)
func _on_cancel_pressed():
$Window.hide()
emit_signal("cancel_define_input")
func _on_ok_pressed():
$Window.hide()
Common.set_input_plus(action, last_event, last_last_event, self.type_event == 2)
emit_signal("refresh_control_define_input")
func _on_window_window_input(event):
if event.is_pressed() == false:
return
if focus_ok:
return
if (event is InputEventKey) && (self.type_event == 1):
#last_last_event = last_event
last_event = event
$Window/v/result.set_text( Common.get_string_input(event) )
elif event is InputEventMouseButton and self.type_event == 2:
last_last_event = last_event
last_event = event
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)))
elif event is InputEventJoypadButton and self.type_event == 3:
#last_last_event = last_event
last_event = event
$Window/v/result.set_text( Common.get_string_input(event) )
elif event is InputEventJoypadMotion and self.type_event == 4:
#last_last_event = last_event
if not last_event:
last_event = event
elif last_event.get_axis() != event.get_axis():
last_last_event = last_event
last_event = event
if last_last_event != null:
$Window/v/result.set_text( "Axe:" + str(event.get_axis()) + " & " + str(last_last_event.get_axis()))
else:
$Window/v/result.set_text( "move all axes" )
if last_event != null:
if self.type_event != 4 or last_last_event != null:
set_disabled(false)
func _on_ok_mouse_entered():
focus_ok = true
func _on_ok_mouse_exited():
focus_ok = false