-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTextbox.gd
88 lines (69 loc) · 2.35 KB
/
Textbox.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
84
85
86
extends CanvasLayer
const CHAR_READ_RATE = 0.05
onready var textbox_container = $TextboxContainer
onready var start_symbol = $TextboxContainer/MarginContainer/HBoxContainer/Start
onready var end_symbol = $TextboxContainer/MarginContainer/HBoxContainer/End
onready var label = $TextboxContainer/MarginContainer/HBoxContainer/Label2
enum State {
READY,
READING,
FINISHED
}
var current_state = State.READY
var text_queue = []
func _ready():
print("Starting state: State.READY")
hide_textbox()
queue_text("Welcome to the game, double press 'enter' to continue the text")
queue_text("Use the 'W' key to move forward, the 'D' key to move right, the 'S' key to move backward, and the 'A' key to move left")
queue_text("Use the mouse to look around")
queue_text("Use The 'I' key to open up the Inventory/Equipment menu")
queue_text("Try to find enemies (White box) and treasure (red box), press 'E' key to interact with treasure")
queue_text("To read These messages again bump into the white small cylinder")
func _process(delta):
match current_state:
State.READY:
if !text_queue.empty():
display_text()
State.READING:
if Input.is_action_just_pressed("ui_accept"):
label.percent_visible = 1.0
$Tween.stop_all()
end_symbol.text = "v"
change_state(State.FINISHED)
State.FINISHED:
if Input.is_action_just_pressed("ui_accept"):
change_state(State.READY)
hide_textbox()
func queue_text(next_text):
text_queue.push_back(next_text)
func hide_textbox():
start_symbol.text = ""
end_symbol.text = ""
label.text = ""
textbox_container.hide()
func show_textbox():
start_symbol.text = "*"
textbox_container.show()
func display_text():
var next_text = text_queue.pop_front()
label.text = next_text
label.percent_visible = 0.0
change_state(State.READING)
show_textbox()
$Tween.interpolate_property(label, "percent_visible", 0.0, 1.0, len(next_text) * CHAR_READ_RATE, Tween.TRANS_LINEAR, Tween.EASE_IN_OUT)
$Tween.start()
func change_state(next_state):
current_state = next_state
match current_state:
State.READY:
print("Changing state to: State.READY")
State.READING:
print("Changing state to: State.READING")
State.FINISHED:
print("Changing state to: State.FINISHED")
func _on_Tween_tween_completed(object, key):
end_symbol.text = "v"
change_state(State.FINISHED)
func _on_Tween_tween_all_completed():
pass