-
-
Notifications
You must be signed in to change notification settings - Fork 183
/
Copy pathOutlinePanel.gd
83 lines (67 loc) · 2.09 KB
/
OutlinePanel.gd
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# Displays an animated border around a panel-based UI component.
#
# Animates the border using a stylebox's expand margin as the border properties
# use integers, causing choppy animation.
#
# As a result, to make it work, we display the border behind the parent. Append
# as a child of a PanelContainer or simular container encompassing a whole UI
# component.
extends Panel
const COLOR_TRANSPARENT := Color(1.0, 1.0, 1.0, 0.0)
const ANIMATION_DURATION := 0.6
export var max_border_width := 8.0 setget set_max_border_width
export var border_width := 0.0 setget set_border_width
onready var _border_style: StyleBoxFlat = get("custom_styles/panel")
onready var _tween := $Tween as Tween
func _ready() -> void:
set_border_width(0.0)
hide()
_tween.connect("tween_completed", self, "_on_tween_completed")
func appear() -> void:
_tween.stop_all()
_tween.interpolate_method(
self,
"set_border_width",
0.0,
max_border_width,
ANIMATION_DURATION,
Tween.TRANS_CIRC,
Tween.EASE_OUT
)
_tween.interpolate_property(
self, "self_modulate", COLOR_TRANSPARENT, Color.white, ANIMATION_DURATION / 2
)
_tween.start()
_tween.seek(0.0)
show()
func disappear() -> void:
_tween.stop_all()
_tween.interpolate_property(
self,
"border_width",
max_border_width,
0.0,
ANIMATION_DURATION,
Tween.TRANS_CIRC,
Tween.EASE_OUT
)
_tween.interpolate_property(
self, "self_modulate", Color.white, COLOR_TRANSPARENT, ANIMATION_DURATION / 2
)
_tween.start()
_tween.seek(0.0)
func set_max_border_width(new_width: float) -> void:
max_border_width = new_width
_border_style.border_width_left = int(new_width)
_border_style.border_width_top = int(new_width)
_border_style.border_width_right = int(new_width)
_border_style.border_width_bottom = int(new_width)
func set_border_width(new_width: float) -> void:
border_width = new_width
_border_style.expand_margin_left = new_width
_border_style.expand_margin_top = new_width
_border_style.expand_margin_right = new_width
_border_style.expand_margin_bottom = new_width
func _on_tween_completed(_object: Node, _key: String) -> void:
if border_width < 0.1:
hide()