about summary refs log tree commit diff stats
path: root/Archipelago/messages.gd
blob: 3a2b4b28f816acaa14329fbcce55ff30aca80315 (plain) (blame)
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
extends Node

var _message_queue = []


func _ready():
	var label = Label.new()
	label.set_name("label")
	label.margin_right = 1920.0
	label.margin_bottom = 1080.0 - 20
	label.margin_left = 20.0
	label.align = Label.ALIGN_LEFT
	label.valign = Label.VALIGN_BOTTOM

	var dynamic_font = DynamicFont.new()
	dynamic_font.font_data = load("res://fonts/Lingo.ttf")
	dynamic_font.size = 36
	dynamic_font.outline_color = Color(0, 0, 0, 1)
	dynamic_font.outline_size = 2
	label.add_font_override("font", dynamic_font)

	add_child(label)


func showMessage(text):
	var label = self.get_node("label")
	if label.text.count("\n") >= 9:
		_message_queue.append(text)
		return

	if !label.text == "":
		label.text += "\n"
		label.text += text
		return

	label.text = text

	var timeout = 10.0
	while label.text != "":
		yield(get_tree().create_timer(timeout), "timeout")

		var newline = label.text.find("\n")
		if newline == -1:
			label.text = ""
		else:
			label.text = label.text.substr(newline + 1)

		if !_message_queue.empty():
			var next_msg = _message_queue.pop_front()
			label.text += "\n"
			label.text += next_msg

		if timeout > 4:
			timeout -= 3