haha
This commit is contained in:
63
Levels/Objects/DialogBox.gd
Normal file
63
Levels/Objects/DialogBox.gd
Normal file
@@ -0,0 +1,63 @@
|
||||
extends ColorRect
|
||||
|
||||
export var dialogPath = ""
|
||||
export(float) var textSpeed = 0.05
|
||||
|
||||
var dialog
|
||||
var phraseNum = 0
|
||||
var finished = false
|
||||
|
||||
func _ready():
|
||||
# self.visible = false
|
||||
$Timer.wait_time = textSpeed
|
||||
dialog = getDialog()
|
||||
assert(dialog, "Dialong not found")
|
||||
nextPhrase()
|
||||
|
||||
|
||||
func _process(delta):
|
||||
$Indicator.visible = finished
|
||||
if Input.is_action_just_pressed("ui_accept"):
|
||||
if finished:
|
||||
nextPhrase()
|
||||
else:
|
||||
$Text.visible_characters = len($Text.text)
|
||||
func getDialog() -> Array:
|
||||
var f = File.new()
|
||||
assert(f.file_exists(dialogPath), "File path does not exist")
|
||||
|
||||
f.open(dialogPath, File.READ)
|
||||
var json = f.get_as_text()
|
||||
|
||||
var output = parse_json(json)
|
||||
|
||||
if typeof(output) == TYPE_ARRAY:
|
||||
return output
|
||||
else:
|
||||
return []
|
||||
|
||||
func nextPhrase() -> void:
|
||||
if phraseNum >= len(dialog):
|
||||
queue_free()
|
||||
return
|
||||
|
||||
finished = false
|
||||
|
||||
$Name.bbcode_text = dialog[phraseNum]["Name"]
|
||||
$Text.bbcode_text = dialog[phraseNum]["Text"]
|
||||
|
||||
$Text.visible_characters = 0
|
||||
|
||||
while $Text.visible_characters < len($Text.text):
|
||||
$Text.visible_characters += 1
|
||||
|
||||
$Timer.start()
|
||||
yield($Timer, "timeout")
|
||||
|
||||
finished = true
|
||||
phraseNum += 1
|
||||
return
|
||||
|
||||
|
||||
|
||||
|
84
Levels/Objects/Dialogue.tscn
Normal file
84
Levels/Objects/Dialogue.tscn
Normal file
@@ -0,0 +1,84 @@
|
||||
[gd_scene load_steps=6 format=2]
|
||||
|
||||
[ext_resource path="res://Levels/Objects/DialogBox.gd" type="Script" id=1]
|
||||
[ext_resource path="res://Fonts/AtariClassicSmooth.ttf" type="DynamicFontData" id=2]
|
||||
|
||||
[sub_resource type="DynamicFont" id=2]
|
||||
size = 20
|
||||
extra_spacing_top = -1
|
||||
extra_spacing_bottom = -1
|
||||
extra_spacing_char = -1
|
||||
font_data = ExtResource( 2 )
|
||||
|
||||
[sub_resource type="Theme" id=3]
|
||||
default_font = SubResource( 2 )
|
||||
|
||||
[sub_resource type="Animation" id=1]
|
||||
resource_name = "bounce"
|
||||
tracks/0/type = "value"
|
||||
tracks/0/path = NodePath("AnimationPlayer:root_node")
|
||||
tracks/0/interp = 1
|
||||
tracks/0/loop_wrap = true
|
||||
tracks/0/imported = false
|
||||
tracks/0/enabled = true
|
||||
tracks/0/keys = {
|
||||
"times": PoolRealArray( 0 ),
|
||||
"transitions": PoolRealArray( 1 ),
|
||||
"update": 1,
|
||||
"values": [ NodePath("..") ]
|
||||
}
|
||||
|
||||
[node name="Control" type="Control"]
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="DialogBox" type="ColorRect" parent="."]
|
||||
margin_left = 60.0
|
||||
margin_top = 145.0
|
||||
margin_right = 335.0
|
||||
margin_bottom = 185.0
|
||||
rect_min_size = Vector2( 275, 40 )
|
||||
rect_scale = Vector2( 0.7, 0.730801 )
|
||||
theme = SubResource( 3 )
|
||||
color = Color( 0.776471, 0.752941, 0.647059, 1 )
|
||||
script = ExtResource( 1 )
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
dialogPath = "res://Levels/Objects/journalScrapDialog.json"
|
||||
|
||||
[node name="Name" type="RichTextLabel" parent="DialogBox"]
|
||||
anchor_bottom = 2.0
|
||||
margin_right = 500.0
|
||||
margin_bottom = -17.0
|
||||
rect_scale = Vector2( 0.4, 0.4 )
|
||||
custom_colors/default_color = Color( 0, 0, 0, 1 )
|
||||
text = "ddd"
|
||||
fit_content_height = true
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="Text" type="RichTextLabel" parent="DialogBox"]
|
||||
margin_top = 9.0
|
||||
margin_right = 500.0
|
||||
margin_bottom = 70.0
|
||||
rect_scale = Vector2( 0.4, 0.4 )
|
||||
custom_colors/default_color = Color( 0, 0, 0, 1 )
|
||||
text = "dddd"
|
||||
scroll_active = false
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="Indicator" type="Polygon2D" parent="DialogBox"]
|
||||
position = Vector2( -104, 104 )
|
||||
color = Color( 0, 0, 0, 1 )
|
||||
antialiased = true
|
||||
polygon = PoolVector2Array( 370.756, -68.0704, 376.296, -74.7627, 365.367, -74.6793 )
|
||||
|
||||
[node name="AnimationPlayer" type="AnimationPlayer" parent="DialogBox/Indicator"]
|
||||
anims/bounce = SubResource( 1 )
|
||||
|
||||
[node name="Timer" type="Timer" parent="DialogBox"]
|
5
Levels/Objects/journalScrapDialog.json
Normal file
5
Levels/Objects/journalScrapDialog.json
Normal file
@@ -0,0 +1,5 @@
|
||||
[
|
||||
{"Name":"???", "Text":"Did they REALLY think they would be able to leave the ethereal plane?!"},
|
||||
{"Name":"???", "Text":"No one ever leaves the ethereal plane!"},
|
||||
{"Name":"???", "Text":"What a joke."}
|
||||
]
|
Reference in New Issue
Block a user