From cc3f6e5ea29bfe006576a35b5fa24d029a07cf7c Mon Sep 17 00:00:00 2001 From: dam Date: Wed, 9 Feb 2022 00:21:59 +0000 Subject: Add confirmation dialog to entry destructive actions. --- main.gd | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) (limited to 'main.gd') diff --git a/main.gd b/main.gd index a1b9aca..bf31aa0 100644 --- a/main.gd +++ b/main.gd @@ -1,11 +1,13 @@ extends Control -var timeout: float +var power_throttle_timeout: float -onready var controls_sensible_to_keyboard: Array = [ +onready var file_picker := get_node("/root/main/file_picker") as FileDialog +onready var confirm_action := get_node("/root/main/confirm_action") as ConfirmationDialog +onready var controls_sensible_to_keyboard := [ self, - get_node("/root/main/file_picker"), - get_node("/root/main/confirm_action"), + file_picker, + confirm_action, ] @@ -14,27 +16,35 @@ func _init(): PhysicsServer.set_active(false) +func _ready(): + confirm_action.get_cancel().connect("pressed", self, "dialog_cancelled", ["confirmed"]) + file_picker.get_cancel().connect("pressed", self, "dialog_cancelled", ["file_selected"]) + + func _process(delta: float): var keyboard_height: int = OS.get_virtual_keyboard_height() for it in controls_sensible_to_keyboard: it.margin_bottom = -keyboard_height - # @DAM Debug information. -# $debug.text = "%s" % Engine.get_frames_per_second() -# $debug.text = "%s" % timeout - if timeout > 0.0: - timeout -= delta + if power_throttle_timeout > 0.0: + power_throttle_timeout -= delta else: Engine.target_fps = 10 func _input(event: InputEvent): Engine.target_fps = 0 - timeout = 3.5 + power_throttle_timeout = 3.5 func _unhandled_input(event: InputEvent): Engine.target_fps = 0 - timeout = 3.5 + power_throttle_timeout = 3.5 + + +func dialog_cancelled(confirmation_signal_name: String): + var confirmation_handlers = confirm_action.get_signal_connection_list(confirmation_signal_name) + for it in confirmation_handlers: + confirm_action.disconnect(it.signal, it.target, it.method) -- cgit v1.2.3