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

124 lines
3.4 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_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"
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.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))
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_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_event = event
$Window/v/result.set_text( Common.get_string_input(event) )
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)
else:
event.set_axis_value(1.0)
last_event = event
$Window/v/result.set_text( Common.get_string_input(event) )
if last_event != null:
set_disabled(false)
func _on_ok_mouse_entered():
focus_ok = true
func _on_ok_mouse_exited():
focus_ok = false