~kmdodrill/my-brother-lives-in-a-canyon

ref: 349d5abac1c6e8caccf212b82b076bb4a25565d7 my-brother-lives-in-a-canyon/src/UI/Options/RemapPopup.gd -rw-r--r-- 1.6 KiB
349d5aba — Kenneth Dodrill Adding rest of camera stuff 7 months ago
                                                                                
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
49
50
extends PopupPanel

class_name RemapPopup

onready var remap_label: Label = $HBoxContainer/VBoxContainer/Remap
onready var settings = get_tree().root.get_node("Settings")
onready var option_menu = get_parent().get_node("OptionMenu")
onready var joypad_axis_warning: AcceptDialog = get_parent().get_node("JoypadAxisWarning")
onready var timer: Timer = $Timer

var action: String
var action_inputs: Array
var caller: RemapControl

func _unhandled_input(event) -> void:
    if !visible || timer.time_left != 0.0 || joypad_axis_warning.visible:
        return
    
    if !event is InputEventKey && !event is InputEventMouseButton && !event is InputEventJoypadButton:
        if event is InputEventJoypadMotion:
            joypad_axis_warning.popup()
        return
        
    if event.is_action_pressed("ui_cancel") || action_inputs.has(event):
        print("cancelled or already has event")
        get_tree().set_input_as_handled()
        hide()
        return

    InputMap.action_add_event(action, event)
    settings.set_value("controls", action, InputMap.get_action_list(action))
    caller.set_action_values()
    get_tree().set_input_as_handled()
    option_menu.get_current_tab_control().grab_focus()
    hide()
    
func remap(action_name: String, calling_control: RemapControl) -> void:
    get_parent().get_node("OptionMenu").release_focus()
    action = action_name
    caller = calling_control
    popup()
    
    if !InputMap.has_action(action):
        push_error("The action " + action + " does not exist!")
        get_tree().quit()
    
    action_inputs = InputMap.get_action_list(action)

func _on_RemapPopup_about_to_show() -> void:
    timer.start()