diff --git a/common/anim.gd b/common/anim.gd index ec68edb..cf75678 100644 --- a/common/anim.gd +++ b/common/anim.gd @@ -24,15 +24,20 @@ static func enabled() -> bool: ## one with the same key so they don't fight. Returns null when animations are off or the ## node is not in the tree. static func tween(node: Node, key: StringName = &"anim") -> Tween: + stop(node, key) + if !enabled() || !node.is_inside_tree(): + return null + var new_tween: Tween = node.create_tween() + node.set_meta(StringName("_tween_" + key), new_tween) + return new_tween + + +## Stops the animation called [param key] on [param node], if one is running. +static func stop(node: Node, key: StringName = &"anim") -> void: var meta: StringName = StringName("_tween_" + key) var old: Variant = node.get_meta(meta) if node.has_meta(meta) else null if old is Tween && (old as Tween).is_valid(): (old as Tween).kill() - if !enabled() || !node.is_inside_tree(): - return null - var new_tween: Tween = node.create_tween() - node.set_meta(meta, new_tween) - return new_tween ## Makes [param control] grow from its middle. diff --git a/common/animated_progress_bar.gd b/common/animated_progress_bar.gd new file mode 100644 index 0000000..c1375ba --- /dev/null +++ b/common/animated_progress_bar.gd @@ -0,0 +1,118 @@ +class_name AnimatedProgressBar +extends ProgressBar +## A progress bar with some life in it: +## - [method wait] shows Godot's busy animation until there is any progress; +## - [method move_to] glides to each new value instead of jumping; +## - a soft highlight sweeps along the filled part, kept inside its rounded corners. +## +## The bar's style, e.g. [code]SyncProgressBar[/code], has a [code]shine[/code] colour for +## the highlight, and two more styles go with it: [code]