I built one of those buttons that trigger action#1 at a quick tap/click and trigger action#2 after holding down for some time. To achieve this, I set up two timers that start when holding down, a short one and a long one.
timer_long = Timer.new()
timer_long.connect("timeout", self, "_on_timer_timeout_long")
timer_short = Timer.new()
timer_short.connect("timeout", self, "_on_timer_timeout_short")
func _on_HoldButtonArea_input_event(_viewport, _event, _shape_idx):
So releasing before the short timer runs out triggers action#1, holding down until the long timer runs out triggers action#2.
Releasing in between the end of the short timer and the end of the long timer cancels everything. (Mouse-exiting cancels everything at any point, by the way.)
Among some variables there are:
var short_timer_out = false
var long_timer_out = false
short_timer_out = true
print ("Short-timer out!")
long_timer_out = true
print ("Long-timer out!")
The signals are being used for some separate animations to run above the button: A bar filling up from the moment when the short timer finished until the long timer finishes...
I use the variables for dealing with canceling things.
This all works wonderfully, but: only once! As soon as the short timer runs out once, the button does not work properly anymore (quick tap/click won't register anymore etc.).
What I can observe is the cancel-animation that should play after the short timer runs out then also plays when canceling during short-timimg, and this makes me wonder if "timershort.stop" actually really cancels the timer, so/and the timershort.start() really starts at a reset 0 time. I have the impression that the counters might somehow be paused and then resumed instead, messing everything up... could that be the case? Is "timer_short.stop" not "definite" enough?