-
Notifications
You must be signed in to change notification settings - Fork 3
/
HideableUI.gd
40 lines (31 loc) · 1.32 KB
/
HideableUI.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
extends Control
const config_interface_scene = preload ("res://ConfigInterface/ConfigInterface.tscn")
var current_alpha: float
var target_alpha: float = 1
const anim_speed: float = 3 # higher value = faster fade in/out
func _ready():
current_alpha = target_alpha
modulate.a = target_alpha
var show_on_hover = get_meta("show_on_hover", null)
if (show_on_hover is bool) and show_on_hover:
mouse_entered.connect(_on_mouse_entered)
mouse_exited.connect(_on_mouse_exited)
func _process(delta):
anim_step(delta)
func anim_step(delta):
# there is no need for checking if current_alpha is equal to target_alpha,
# because if they are, (target_alpha - current_alpha) * delta = 0 * delta = 0
# It is done anyways for clarity :3
if current_alpha != target_alpha:
current_alpha += (target_alpha - current_alpha) * delta * anim_speed
current_alpha = clampf(current_alpha, 0, 1) # could be combined into the previous line but it's more readable like this
# 2.2 is ease in, 0.2 is ease out.
# Using ease in if target alpha is 1 or vice versa feels very slow.
modulate.a = ease(current_alpha, 2.2 - target_alpha * 2)
func change_to_alpha(new_alpha: float):
target_alpha = new_alpha
func _on_mouse_entered():
change_to_alpha(1)
func _on_mouse_exited():
if not ConfigHandler.current_config.always_show_hamburger:
change_to_alpha(0)