-
Notifications
You must be signed in to change notification settings - Fork 0
/
ContentDisplay.gd
171 lines (151 loc) · 5.31 KB
/
ContentDisplay.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
extends PanelContainer
@onready var right_text = get_node("%TextRight")
@onready var left_text = get_node("%TextLeft")
@onready var right_image = get_node("%ImageRight")
@onready var left_image = get_node("%ImageLeft")
@onready var center_image = get_node("%ImageCenter")
@onready var center_text = get_node("%TextCenter")
@onready var logon_text = get_node("%LOGON")
@onready var logoff = get_node("%LOGOFF")
#Example input terminal
# [
# [
# {
# "mode" : "right", #left, right, logon, logoff, information
# "text" : "Hello World",
# "image" : "res://icon.png",
# "command" : "INTERLEVEL TELEPORT", # can be INTERLEVEL TELEPORT, INTRALEVEL TELEPORT, SOUND, STATIC
# "arg" : "any" # can be anything
# },
# {
# "mode" : "left", #left, right, logon, logoff, information
# "text" : "Hello World",
# "image" : "res://icon.png",
# "command" : "INTERLEVEL TELEPORT", # can be INTERLEVEL TELEPORT, INTRALEVEL TELEPORT, SOUND, STATIC
# "arg" : "any" # can be anything
# }...
# ],
# [
# {
# "mode" : "right", #left, right, logon, logoff, information
# "text" : "Hello World",
# "image" : "res://icon.png",
# "command" : "INTERLEVEL TELEPORT", # can be INTERLEVEL TELEPORT, INTRALEVEL TELEPORT, SOUND, STATIC
# "arg" : "any" # can be anything
# },
# {
# "mode" : "left", #left, right, logon, logoff, information
# "text" : "Hello World",
# "image" : "res://icon.png",
# "command" : "INTERLEVEL TELEPORT", # can be INTERLEVEL TELEPORT, INTRALEVEL TELEPORT, SOUND, STATIC
# "arg" : "any" # can be anything
# }...
# ]
# ]
var terminals = []
func load_terminals(data: Array) -> void:
terminals = data
var current_terminal = []
var current_page_idx = 0
signal terminal_command_triggered(what, arg)
func display_terminal(term_idx: int) -> void:
if term_idx < terminals.size():
current_terminal = terminals[term_idx]
print(current_terminal)
func clear_display() -> void:
right_text.text = ""
right_image.texture = null
right_image.hide()
left_text.text = ""
left_image.texture = null
left_image.hide()
center_text.text = ""
center_image.texture = null
center_image.hide()
logon_text.text = " "
logoff.text = " "
func display_page() -> void:
match current_terminal[current_page_idx].mode:
"right":
clear_display()
right_text.text = to_bbcode(current_terminal[current_page_idx].text, Align.RIGHT)
right_image.texture = to_image_ref(current_terminal[current_page_idx].image)
right_image.visible = true
"left":
clear_display()
left_text.text = to_bbcode(current_terminal[current_page_idx].text, Align.LEFT)
left_image.texture = to_image_ref(current_terminal[current_page_idx].image)
left_image.visible = true
"information":
clear_display()
center_text.text = to_bbcode(current_terminal[current_page_idx].text, Align.LEFT)
#This is a special case where we don't want to display an image
"logon":
clear_display()
logon_text.text = to_bbcode(current_terminal[current_page_idx].text, Align.CENTER)
center_image.texture = to_image_ref(current_terminal[current_page_idx].image)
center_image.visible = true
logoff.text = " "
"logoff":
clear_display()
logoff.text = to_bbcode(current_terminal[current_page_idx].text, Align.CENTER)
center_image.texture = to_image_ref(current_terminal[current_page_idx].image)
center_image.visible = true
logon_text.text = " "
_:
print("Nothing!")
if current_terminal[current_page_idx].command != "INTERLEVEL TELEPORT":
execute_terminal(current_page_idx)
enum Align{
CENTER,
RIGHT,
LEFT}
func to_bbcode(text: String, align :int) -> String:
var colors_to_close = 1
var bbcode = text.replace("$I", "[i]")
bbcode = bbcode.replace("$B", "[b]")
bbcode = bbcode.replace("$U", "[u]")
bbcode = bbcode.replace("$i", "[/i]")
bbcode = bbcode.replace("$b", "[/b]")
bbcode = bbcode.replace("$u", "[/u]")
colors_to_close = bbcode.count("$C")
bbcode = "[color=lime]" + bbcode #default color
bbcode = bbcode.replace("$C0", "[color=lime]")
bbcode = bbcode.replace("$C1", "[color=white]")
bbcode = bbcode.replace("$C2", "[color=red]")
bbcode = bbcode.replace("$C3", "[color=darkgreen]")
bbcode = bbcode.replace("$C4", "[color=lightblue]")
bbcode = bbcode.replace("$C5", "[color=yellow]")
bbcode = bbcode.replace("$C6", "[color=darkred]")
bbcode = bbcode.replace("$C7", "[color=darkblue]")
for i in range(colors_to_close):
bbcode += "[/color]"
bbcode += "[/color]"
match align:
Align.CENTER:
bbcode = "[center]" + bbcode + "[/center]"
Align.RIGHT:
bbcode = "[right]" + bbcode + "[/right]"
Align.LEFT:
bbcode = "[left]" + bbcode + "[/left]"
return bbcode
func to_image_ref(file) -> ImageTexture:
var image = Image.load_from_file(file)
return ImageTexture.create_from_image(image)
func execute_terminal(page_idx: int) -> void:
terminal_command_triggered.emit(current_terminal[page_idx].command, current_terminal[page_idx].arg)
func next_page() -> void:
print(current_terminal.size())
if current_page_idx < current_terminal.size()-1:
current_page_idx += 1
display_terminal(current_page_idx)
else:
execute_terminal(current_page_idx)
current_page_idx = 0
func previous_page() -> void:
if current_page_idx > 0:
current_page_idx -= 1
display_terminal(current_page_idx)
else:
current_page_idx = current_terminal.size() - 1
display_terminal(current_page_idx)