Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions scenes/game_root.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ script/source = "extends CanvasLayer
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
Signals.startDialogue.connect(
func(text):
func(text, faces, sounds):
if !TextBox.has_textbox and Global.moveable:
var textbox := TextBox.create(text)
var textbox := TextBox.create(text, faces, sounds)
add_child(textbox)
)
"
Expand Down
64 changes: 29 additions & 35 deletions scenes/overworld/rooms/hometown.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -245,29 +245,37 @@ script/source = "extends StaticBody2D

func interact() -> void:
var text = [
\"* That's right fuckers, I'm the [shake rate=50.0 level=10 connected=1][color=red][img=x32]res://sprites/example/tennatime.png[/img] Roaring Knight[/color][/shake]!\",
\"* wait what the fuck\",
\"Where is my asterick\",
\"* ive got many askerisks?\\n* yes\\n* maybe too many\",
\"* funnytext test\\n* [img=350x70]res://sprites/souls/soul.png[/img]\"
\"* I am Susie and I am yapping a lot to test wrapping with portraits\",
\"* I am Ralsei (Quiet)\",
\"* I am Tenna and I'm yapping a lot to test face-portrait-less text wrapping\"
]
TextBox.start_dialogue(text)
var faces = [
\"res://sprites/face_portraits/susie_grin.png\",
\"res://sprites/face_portraits/ralsei_smile.png\",
\"none\"
]
var sounds = [
[\"res://sounds/voice/susie.wav\"],
[\"res://sounds/voice/snd_txtral.wav\"],
[
\"res://sounds/voice/snd_tv_voice_short.wav\",
\"res://sounds/voice/snd_tv_voice_short_2.wav\",
\"res://sounds/voice/snd_tv_voice_short_3.wav\",
\"res://sounds/voice/snd_tv_voice_short_4.wav\",
\"res://sounds/voice/snd_tv_voice_short_5.wav\",
\"res://sounds/voice/snd_tv_voice_short_6.wav\",
\"res://sounds/voice/snd_tv_voice_short_7.wav\",
\"res://sounds/voice/snd_tv_voice_short_8.wav\",
\"res://sounds/voice/snd_tv_voice_short_9.wav\",
\"res://sounds/voice/snd_tv_voice_short_10.wav\"

]
]
TextBox.start_dialogue(text, faces, sounds)
"

[sub_resource type="RectangleShape2D" id="RectangleShape2D_j46a3"]

[sub_resource type="GDScript" id="GDScript_oqv75"]
script/source = "extends Area2D

func _on_body_entered(body: Node2D) -> void:
var text = [
\"* $#!&-stains\",
\"* $#!&-stains on the wall\",
\"yo\"
]
TextBox.start_dialogue(text)
"

[node name="Hometown" type="Node2D" unique_id=2025934906]
scale = Vector2(2, 2)
script = ExtResource("1_b2ck7")
Expand Down Expand Up @@ -344,28 +352,14 @@ texture = ExtResource("10_eflds")
position = Vector2(70, 70)
script = ExtResource("11_obw5g")

[node name="Room" type="StaticBody2D" parent="." unique_id=1944634033]
[node name="Face Test" type="StaticBody2D" parent="." unique_id=1944634033]
position = Vector2(139.00003, 155)
script = SubResource("GDScript_n2hw7")

[node name="Room" type="Sprite2D" parent="Room" unique_id=125079961]
[node name="Room" type="Sprite2D" parent="Face Test" unique_id=125079961]
position = Vector2(0.9999695, 5)
texture = ExtResource("12_oqv75")

[node name="CollisionShape2D" type="CollisionShape2D" parent="Room" unique_id=1351192506]
[node name="CollisionShape2D" type="CollisionShape2D" parent="Face Test" unique_id=1351192506]
position = Vector2(0.9999695, 5)
shape = SubResource("RectangleShape2D_j46a3")

[node name="Room2" type="Area2D" parent="." unique_id=436147738]
position = Vector2(184.00003, 155)
script = SubResource("GDScript_oqv75")

[node name="Room" type="Sprite2D" parent="Room2" unique_id=523366664]
position = Vector2(0.9999695, 5)
texture = ExtResource("12_oqv75")

[node name="CollisionShape2D" type="CollisionShape2D" parent="Room2" unique_id=1049520239]
position = Vector2(0.9999695, 5)
shape = SubResource("RectangleShape2D_j46a3")

[connection signal="body_entered" from="Room2" to="Room2" method="_on_body_entered"]
15 changes: 6 additions & 9 deletions scenes/ui/textbox.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

[ext_resource type="Script" uid="uid://cx1nqx718bnfa" path="res://scripts/classes/textbox.gd" id="1_hyn88"]
[ext_resource type="PackedScene" uid="uid://tw5hkjn0a81b" path="res://scenes/ui/dark_box.tscn" id="2_fto3e"]
[ext_resource type="AudioStream" uid="uid://b73flekf0aj0h" path="res://sounds/ui/select.wav" id="3_fto3e"]
[ext_resource type="PackedScene" uid="uid://d1tmmpanucxap" path="res://scenes/ui/light_box.tscn" id="3_seire"]
[ext_resource type="Texture2D" uid="uid://bu708k77nhnyg" path="res://sprites/actors/susie/faces/sincere.png" id="4_hdjaa"]
[ext_resource type="AudioStream" uid="uid://cp7rxhw17v65x" path="res://sounds/ui/menumove.wav" id="4_seire"]
[ext_resource type="Texture2D" uid="uid://bu708k77nhnyg" path="res://sprites/face_portraits/susie_sincere.png" id="5_hyn88"]
[ext_resource type="FontFile" uid="uid://dcrh8bap8gwdn" path="res://fonts/main_mono.ttf" id="5_okh7m"]
[ext_resource type="AudioStream" uid="uid://b2y0nkg6g0lnd" path="res://sounds/voice/susie.wav" id="6_k71a8"]

Expand All @@ -20,9 +18,8 @@ anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_hyn88")
talk_sounds = Array[AudioStream]([ExtResource("6_k71a8"), ExtResource("3_fto3e"), ExtResource("4_seire")])
lower_range = -0.09999999999999964
upper_range = 0.1
sounds = []
talk_sounds = Array[AudioStream]([ExtResource("6_k71a8")])

[node name="DarkBox" parent="." unique_id=619300672 instance=ExtResource("2_fto3e")]
visible = false
Expand All @@ -47,13 +44,13 @@ offset_top = 350.0
offset_right = 114.0
offset_bottom = 401.0
scale = Vector2(2, 2)
texture = ExtResource("4_hdjaa")
texture = ExtResource("5_hyn88")

[node name="HBoxContainer" type="HBoxContainer" parent="." unique_id=1309665849]
layout_mode = 0
offset_left = 174.0
offset_left = 62.0
offset_top = 340.0
offset_right = 590.0
offset_right = 574.0
offset_bottom = 453.0
theme_override_constants/separation = 16

Expand Down
55 changes: 48 additions & 7 deletions scripts/classes/textbox.gd
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@ class_name TextBox extends Control
set_text(text[text_index])
set_asterisks()

@export var faces: Array[String] = [""]
var is_face := false

@onready var ast = $HBoxContainer/asterisks
@onready var dia = $HBoxContainer/dialoguetext
@onready var dark_box: NinePatchRect = $DarkBox
@onready var light_box: NinePatchRect = $LightBox

@export_group("Talking Sound")
@export var talk_sounds: Array[AudioStream]
@export var sounds: Array = [""]
@export var talk_sounds: Array = [""]
@export_subgroup("Random Pitch Range")
@export_range(-1, 0, 0.1) var lower_range: float = 0.0
@export_range(0, 1, 0.1) var upper_range: float = 0.0
Expand All @@ -32,25 +36,34 @@ static var has_textbox := false
var animating := false
var text_index := 0

@export var fast_text_skip := false
var can_advance := true
var can_skip := true

# this is actually called a `paragraph` in `RichTextLabel`
# because each line here means includes wrapped lines
var line_starts_with_asterisk: Array[bool] = []
var has_asterisks: bool

static func start_dialogue(text: Array) -> void:
Signals.startDialogue.emit(text)
static func start_dialogue(text: Array, faces: Array, sounds: Array) -> void:
Signals.startDialogue.emit(text, faces, sounds)
Global.moveable = false

func line_asterisk(line: String) -> bool:
return (len(line) == 1 and line[0] == '*') \
or (line.substr(0,2) == '* ')

# Creates a new textbox.
static func create(text: Array) -> TextBox:
static func create(text: Array, faces: Array, sounds: Array) -> TextBox:
var textbox_inst: TextBox = textbox_scene.instantiate()
#textbox_inst.text = text
# append_array needed otherwise godot is weird
textbox_inst.text.clear()
textbox_inst.text.append_array(text)
textbox_inst.faces.clear()
textbox_inst.faces.append_array(faces)
textbox_inst.sounds.clear()
textbox_inst.sounds.append_array(sounds)
return textbox_inst

func set_text(text: String):
Expand Down Expand Up @@ -79,6 +92,19 @@ func set_asterisks():
lineno += 1
ast.visible_characters = 0

func set_face():
is_face = faces[text_index] != "none"
if is_face:
$TalkSprite.texture = load(faces[text_index])
$HBoxContainer.position = Vector2(174, 340)
$HBoxContainer.size = Vector2(400, 113)
else:
$TalkSprite.texture = null
$HBoxContainer.position = Vector2(62, 340)
$HBoxContainer.size = Vector2(512, 113)
$HBoxContainer/dialoguetext.custom_minimum_size = $HBoxContainer.size
$HBoxContainer/dialoguetext.custom_maximum_size = $HBoxContainer.size

func _ready():
has_textbox = true

Expand All @@ -92,6 +118,8 @@ func _ready():
light_box.visible = false
$TalkSprite.set_position(Vector2(69.0, 350.0))

set_face()
talk_sounds = sounds[text_index]
set_text(text[text_index])
set_asterisks()
animate_text()
Expand All @@ -102,8 +130,10 @@ func animate_text():
print(text)
dia.visible_characters = 0
while dia.visible_characters < dia.get_total_character_count():
if Input.is_action_just_pressed("cancel"):
if (Input.is_action_just_pressed("cancel") or Input.is_action_pressed("menu")) and can_skip:
dia.visible_characters = dia.get_total_character_count()
play_talk_sound()
can_advance = !fast_text_skip
animating = false
return
animating = true
Expand All @@ -117,7 +147,7 @@ func play_talk_sound():
var sound = talk_sounds.pick_random()
var pitch_offset = randf_range(lower_range, upper_range)
var player = AudioStreamPlayer.new()
player.stream = sound
player.stream = load(sound)
player.pitch_scale += pitch_offset
player.finished.connect(
func():
Expand All @@ -130,6 +160,8 @@ func play_talk_sound():
func _process(_delta: float) -> void:
if Engine.is_editor_hint():
return

#Set box style
match Global.world_type:
Global.WorldTypes.WORLD_LIGHT:
dark_box.visible = false
Expand All @@ -139,17 +171,26 @@ func _process(_delta: float) -> void:
dark_box.visible = true
light_box.visible = false
$TalkSprite.set_position(Vector2(69.0, 350.0))

ast.visible_characters = dia.get_visible_line_count()
if Input.is_action_just_pressed("confirm") and !animating:
if (Input.is_action_just_pressed("confirm") or Input.is_action_pressed("menu")) and !animating and can_advance:
text_index += 1

if text_index >= text.size():
Global.moveable = true
queue_free()
has_textbox = false
return
else:
set_face()
talk_sounds = sounds[text_index]

set_text(text[text_index])
set_asterisks()
animate_text()

if !can_advance:
can_advance = true

#func paragraph_starts_with_asterisk(i: int):
#var offset = get_paragraph_offset(i)
Expand Down
2 changes: 1 addition & 1 deletion scripts/dark_menu.gd
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func _ready():
option.button_pressed = false
submenu_open = false
)

Signals.toggleMenu.connect(
func():
if !animating:
Expand Down
Binary file added sounds/voice/snd_tv_voice_short.wav
Binary file not shown.
24 changes: 24 additions & 0 deletions sounds/voice/snd_tv_voice_short.wav.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[remap]

importer="wav"
type="AudioStreamWAV"
uid="uid://5fd7is3xx3yc"
path="res://.godot/imported/snd_tv_voice_short.wav-1a1cce17c12e88c2aa8834c17c91d0a2.sample"

[deps]

source_file="res://sounds/voice/snd_tv_voice_short.wav"
dest_files=["res://.godot/imported/snd_tv_voice_short.wav-1a1cce17c12e88c2aa8834c17c91d0a2.sample"]

[params]

force/8_bit=false
force/mono=false
force/max_rate=false
force/max_rate_hz=44100
edit/trim=false
edit/normalize=false
edit/loop_mode=0
edit/loop_begin=0
edit/loop_end=-1
compress/mode=2
Binary file added sounds/voice/snd_tv_voice_short_10.wav
Binary file not shown.
24 changes: 24 additions & 0 deletions sounds/voice/snd_tv_voice_short_10.wav.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[remap]

importer="wav"
type="AudioStreamWAV"
uid="uid://bhxuymb3g105v"
path="res://.godot/imported/snd_tv_voice_short_10.wav-071159273d043dc652777ed92afbe757.sample"

[deps]

source_file="res://sounds/voice/snd_tv_voice_short_10.wav"
dest_files=["res://.godot/imported/snd_tv_voice_short_10.wav-071159273d043dc652777ed92afbe757.sample"]

[params]

force/8_bit=false
force/mono=false
force/max_rate=false
force/max_rate_hz=44100
edit/trim=false
edit/normalize=false
edit/loop_mode=0
edit/loop_begin=0
edit/loop_end=-1
compress/mode=2
Binary file added sounds/voice/snd_tv_voice_short_2.wav
Binary file not shown.
24 changes: 24 additions & 0 deletions sounds/voice/snd_tv_voice_short_2.wav.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[remap]

importer="wav"
type="AudioStreamWAV"
uid="uid://m0mhafntivgd"
path="res://.godot/imported/snd_tv_voice_short_2.wav-28cd562d05efde9e4794492f60f64a82.sample"

[deps]

source_file="res://sounds/voice/snd_tv_voice_short_2.wav"
dest_files=["res://.godot/imported/snd_tv_voice_short_2.wav-28cd562d05efde9e4794492f60f64a82.sample"]

[params]

force/8_bit=false
force/mono=false
force/max_rate=false
force/max_rate_hz=44100
edit/trim=false
edit/normalize=false
edit/loop_mode=0
edit/loop_begin=0
edit/loop_end=-1
compress/mode=2
Binary file added sounds/voice/snd_tv_voice_short_3.wav
Binary file not shown.
24 changes: 24 additions & 0 deletions sounds/voice/snd_tv_voice_short_3.wav.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[remap]

importer="wav"
type="AudioStreamWAV"
uid="uid://dapohg1k66dwj"
path="res://.godot/imported/snd_tv_voice_short_3.wav-07dbffff17e6f8affefa62fe1cf6ce16.sample"

[deps]

source_file="res://sounds/voice/snd_tv_voice_short_3.wav"
dest_files=["res://.godot/imported/snd_tv_voice_short_3.wav-07dbffff17e6f8affefa62fe1cf6ce16.sample"]

[params]

force/8_bit=false
force/mono=false
force/max_rate=false
force/max_rate_hz=44100
edit/trim=false
edit/normalize=false
edit/loop_mode=0
edit/loop_begin=0
edit/loop_end=-1
compress/mode=2
Binary file added sounds/voice/snd_tv_voice_short_4.wav
Binary file not shown.
Loading