diff --git a/levels/ui/gameplay.gd b/levels/ui/gameplay.gd index b0911df..433aa5c 100644 --- a/levels/ui/gameplay.gd +++ b/levels/ui/gameplay.gd @@ -9,11 +9,14 @@ var musictrack var bhud = load("res://levels/bottomhud.tscn").instance() var thud = load("res://levels/ui/tophud.tscn").instance() var pmenu = load("res://levels/ui/pause.tscn").instance() +var mgamepad = load("res://levels/ui/missinggamepad.tscn").instance() +var ismgamepad = false var ispaused = false var ishud = true # Called when the node enters the scene tree for the first time. func _ready(): + Input.connect("joy_connection_changed",self,"_on_joy_connection_changed") _statrebase() add_child(bgsound) add_child(sfx1) @@ -60,6 +63,11 @@ func _process(delta): #velocity = (Vector2.RIGHT.rotated(rotation) * -100 * Global.xm * delta)-Vector2.UP.rotated(rotation) * -100 * Global.ym * delta func _input(event): + if ismgamepad && (event is InputEventJoypadButton || Input.is_key_pressed(KEY_ENTER)): + ismgamepad = false + get_tree().root.remove_child(mgamepad) + Global.live = 1 + gamepadtest.new(event) if Input.is_action_just_pressed("Pause") && Global.cdialog == []: _pausemenu() @@ -163,6 +171,12 @@ func _exit(): Global.live = 0 get_tree().change_scene("res://title.tscn") +func _on_joy_connection_changed(device_id, connected): + if !ismgamepad && !connected && Global.gamepad != 0 && Global.live == 1: + ismgamepad = true + Global.live = 4 + call_deferred("_mgamepad") + func _level(): get_tree().root.add_child(level) @@ -174,3 +188,6 @@ func _bhud(): func _pmenu(): get_tree().root.add_child(pmenu) + +func _mgamepad(): + get_tree().root.add_child(mgamepad) diff --git a/levels/ui/missinggamepad.tscn b/levels/ui/missinggamepad.tscn index 887baf1..5449601 100644 --- a/levels/ui/missinggamepad.tscn +++ b/levels/ui/missinggamepad.tscn @@ -4,17 +4,19 @@ [node name="Missinggamepad" type="Node2D"] -[node name="ColorRect" type="ColorRect" parent="."] +[node name="CanvasLayer" type="CanvasLayer" parent="."] + +[node name="ColorRect" type="ColorRect" parent="CanvasLayer"] margin_left = 90.0 margin_top = 211.0 -margin_right = 1177.0 +margin_right = 1197.0 margin_bottom = 511.0 color = Color( 0, 0, 0, 1 ) -[node name="Label" type="Label" parent="."] +[node name="Label" type="Label" parent="CanvasLayer"] margin_left = 90.0 margin_top = 211.0 -margin_right = 1177.0 +margin_right = 1197.0 margin_bottom = 511.0 rect_min_size = Vector2( 1072, 300 ) custom_fonts/font = ExtResource( 1 )