summaryrefslogtreecommitdiff
path: root/Dialogs/VisualNovelTextbox/animations.gd
blob: 43eca1f7da7416e878f24fb2cd0f1f8e6c50a5be (plain)
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
84
85
86
extends AnimationPlayer

## A custom script/node that adds some animations to the textbox.

# Careful: Sync these with the ones in the root script!
enum AnimationsIn {NONE, POP_IN, FADE_UP}
enum AnimationsOut {NONE, POP_OUT, FADE_DOWN}
enum AnimationsNewText {NONE, WIGGLE}

var animation_in : AnimationsIn
var animation_out : AnimationsOut
var animation_new_text : AnimationsNewText

var full_clear : bool = true

func get_text_panel() -> PanelContainer:
	return %DialogTextPanel


func get_dialog() -> DialogicNode_DialogText:
	return %DialogicNode_DialogText


func _ready() -> void:
	var text_system : Node = DialogicUtil.autoload().get(&'Text')
	var _error : int = 0
	_error = text_system.connect(&'animation_textbox_hide', _on_textbox_hide)
	_error = text_system.connect(&'animation_textbox_show', _on_textbox_show)
	_error = text_system.connect(&'animation_textbox_new_text', _on_textbox_new_text)
	_error = text_system.connect(&'about_to_show_text', _on_about_to_show_text)


func _on_textbox_show() -> void:
	if animation_in == AnimationsIn.NONE:
		return
	play('RESET')
	var animation_system : Node = DialogicUtil.autoload().get(&'Animations')
	animation_system.call(&'start_animating')
	get_text_panel().get_parent().get_parent().set(&'modulate', Color.TRANSPARENT)
	get_dialog().text = ""
	match animation_in:
		AnimationsIn.POP_IN:
			play("textbox_pop")
		AnimationsIn.FADE_UP:
			play("textbox_fade_up")
	if not is_connected(&'animation_finished', Callable(animation_system, &'animation_finished')):
		var _error : int = connect(&'animation_finished', Callable(animation_system, &'animation_finished'), CONNECT_ONE_SHOT)


func _on_textbox_hide() -> void:
	if animation_out == AnimationsOut.NONE:
		return
	play('RESET')
	var animation_system : Node = DialogicUtil.autoload().get(&'Animations')
	animation_system.call(&'start_animating')
	match animation_out:
		AnimationsOut.POP_OUT:
			play_backwards("textbox_pop")
		AnimationsOut.FADE_DOWN:
			play_backwards("textbox_fade_up")

	if not is_connected(&'animation_finished', Callable(animation_system, &'animation_finished')):
		var _error : int = connect(&'animation_finished', Callable(animation_system, &'animation_finished'), CONNECT_ONE_SHOT)


func _on_about_to_show_text(info:Dictionary) -> void:
	full_clear = !info.append


func _on_textbox_new_text() -> void:
	if DialogicUtil.autoload().Inputs.auto_skip.enabled:
		return

	if animation_new_text == AnimationsNewText.NONE:
		return

	var animation_system : Node = DialogicUtil.autoload().get(&'Animation')
	animation_system.call(&'start_animating')
	if full_clear:
		get_dialog().text = ""
	match animation_new_text:
		AnimationsNewText.WIGGLE:
			play("new_text")

			if not is_connected(&'animation_finished', Callable(animation_system, &'animation_finished')):
				var _error : int = connect(&'animation_finished', Callable(animation_system, &'animation_finished'), CONNECT_ONE_SHOT)