Skip to content
Merged
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
6 changes: 3 additions & 3 deletions Assets/Animations/Portrait_base_anim.tres
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[gd_resource type="SpriteFrames" load_steps=4 format=3 uid="uid://b5l6qnwf46vyd"]

[ext_resource type="Texture2D" uid="uid://brrexw4jtnjag" path="res://addons/Suada/Assets/Sprites/portrait_base_idle3.png" id="1"]
[ext_resource type="Texture2D" uid="uid://ctrxjhqyqjsu3" path="res://addons/Suada/Assets/Sprites/portrait_base_idle2.png" id="2"]
[ext_resource type="Texture2D" uid="uid://cgq3ulsyuh0ja" path="res://addons/Suada/Assets/Sprites/portrait_base_idle1.png" id="3"]
[ext_resource type="Texture2D" uid="uid://brrexw4jtnjag" path="res://addons/Suada_bk/Assets/Sprites/portrait_base_idle3.png" id="1"]
[ext_resource type="Texture2D" uid="uid://ctrxjhqyqjsu3" path="res://addons/Suada_bk/Assets/Sprites/portrait_base_idle2.png" id="2"]
[ext_resource type="Texture2D" uid="uid://cgq3ulsyuh0ja" path="res://addons/Suada_bk/Assets/Sprites/portrait_base_idle1.png" id="3"]

[resource]
animations = [{
Expand Down
8 changes: 7 additions & 1 deletion Assets/Fonts/FSEX302.ttf.import
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ dest_files=["res://.godot/imported/FSEX302.ttf-cc9c15cb9d32cbd7c3aa3009757748a2.
Rendering=null
antialiasing=1
generate_mipmaps=false
disable_embedded_bitmaps=true
multichannel_signed_distance_field=false
msdf_pixel_range=8
msdf_size=48
Expand All @@ -27,7 +28,12 @@ Fallbacks=null
fallbacks=[]
Compress=null
compress=true
preload=[]
preload=[{
"chars": [],
"glyphs": [],
"name": "New Configuration",
"size": Vector2i(16, 0)
}]
language_support={}
script_support={}
opentype_features={}
5 changes: 1 addition & 4 deletions Assets/Fonts/FixedsysExcelsior.tres
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
[gd_resource type="FontFile" load_steps=2 format=3 uid="uid://do40he6kkb8dk"]

[ext_resource type="FontFile" uid="uid://bq0g08pyvyx4p" path="res://Assets/Fonts/FSEX302.ttf" id="1"]
[ext_resource type="FontFile" uid="uid://spyvb3ij26jf" path="res://addons/Suada_bk/Assets/Fonts/FSEX302.ttf" id="1"]

[resource]
fallbacks = Array[Font]([ExtResource("1")])
face_index = null
embolden = null
transform = null
cache/0/16/0/ascent = 0.0
cache/0/16/0/descent = 0.0
cache/0/16/0/underline_position = 0.0
Expand Down
2 changes: 1 addition & 1 deletion Assets/Themes/main_theme.tres
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[gd_resource type="Theme" load_steps=4 format=3 uid="uid://bruovco3l4r7k"]

[ext_resource type="FontFile" uid="uid://do40he6kkb8dk" path="res://addons/Suada/Assets/Fonts/FixedsysExcelsior.tres" id="1"]
[ext_resource type="Texture2D" uid="uid://b03mcowynm1j4" path="res://addons/Suada/Assets/Sprites/dialogue_box_9_tile.png" id="2"]
[ext_resource type="Texture2D" uid="uid://b03mcowynm1j4" path="res://addons/Suada_bk/Assets/Sprites/dialogue_box_9_tile.png" id="2"]

[sub_resource type="StyleBoxTexture" id="1"]
texture = ExtResource("2")
Expand Down
2 changes: 1 addition & 1 deletion Assets/Themes/name_theme.tres
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[gd_resource type="Theme" load_steps=4 format=3 uid="uid://ddetutsupn7m0"]

[ext_resource type="FontFile" uid="uid://do40he6kkb8dk" path="res://addons/Suada/Assets/Fonts/FixedsysExcelsior.tres" id="1"]
[ext_resource type="Texture2D" uid="uid://csr38a60osub6" path="res://addons/Suada/Assets/Sprites/name_box_9_tile.png" id="2"]
[ext_resource type="Texture2D" uid="uid://csr38a60osub6" path="res://addons/Suada_bk/Assets/Sprites/name_box_9_tile.png" id="2"]

[sub_resource type="StyleBoxTexture" id="2"]
texture = ExtResource("2")
Expand Down
2 changes: 1 addition & 1 deletion Nodes/Dialogue.tscn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_scene load_steps=24 format=3 uid="uid://x6mnw54gmo8v"]
[gd_scene load_steps=24 format=3 uid="uid://besgwi2vkunl3"]

[ext_resource type="Script" path="res://addons/Suada/Nodes/DialogueSystem.gd" id="1"]
[ext_resource type="Theme" uid="uid://ddetutsupn7m0" path="res://addons/Suada/Assets/Themes/name_theme.tres" id="2"]
Expand Down
7 changes: 4 additions & 3 deletions Nodes/DialogueAudioPlayer.gd
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
class_name DialogueAudioPlayer
extends AudioStreamPlayer2D


Expand All @@ -13,7 +14,7 @@ func set_voice_sound(audio: AudioStream):
## @param wait_to_play If true, waits until the last sound was played.
func play_voice_sound(wait_to_play: bool = true):
if wait_to_play:
if !self.playing:
self.play()
if !playing:
play()
else:
self.play()
play()
1 change: 1 addition & 0 deletions Nodes/DialogueAudioPlayer.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://bisrw25bck2i6
54 changes: 47 additions & 7 deletions Nodes/DialogueBox.gd
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,54 @@ class_name DialogueTextBox
extends Control

var _text_next_char_it: float = 0
var _parsed_dialog: ParsedDialog = null
var _pause: bool = false

@onready var _text_label = $Panel/Text as RichTextLabel
@onready var _portrait_box: PortraitBox = $"../PortraitBox"
@onready var _finished_effect: Sprite2D = $FinishEffect


func _ready():
if SuadaGlobals.text_speed == -1:
if SuadaConfig.text_speed == -1:
_text_label.visible_characters = -1


func _process(_delta):
if _text_label.text.is_empty():
if _text_label.text.is_empty() or !_text_label.visible:
return

if _text_label.visible_ratio == 1:
_finished_effect.visible = true
return

var text = _text_label.text
if _pause:
return

_text_next_char_it = (
SuadaGlobals.text_speed
SuadaConfig.text_speed
if _text_next_char_it >= 1
else _text_next_char_it + SuadaGlobals.text_speed
else _text_next_char_it + SuadaConfig.text_speed
)
_text_label.visible_characters += _text_next_char_it

var letter = text[_text_label.visible_characters - 1]
if SuadaGlobals.vocal_sound:
var letter = _text_label.text[_text_label.visible_characters - 1].to_lower()
_handle_effects(_text_label.visible_characters as int)
_handle_letter_pauses(letter)

if SuadaConfig.vocal_sound:
if letter == "a" or letter == "e" or letter == "i" or letter == "o" or letter == "u":
_portrait_box.play_voice()
else:
_portrait_box.play_voice()


func set_text(text: String, font: Font, colour: Color = Color.WHITE, visible: bool = false) -> void:
var text_without_suada_effect = BBCParser.bbc_remover(text, BBCCodes.BBC_REXP)
_text_label.text = text
_parsed_dialog = BBCParser.parse(_text_label.get_parsed_text())
_text_label.text = text_without_suada_effect

_text_label.add_theme_font_override("normal_font", font)
_text_label.add_theme_color_override("default_color", colour)
_text_label.visible_characters = -1 if visible else 0
Expand All @@ -51,3 +61,33 @@ func show_all_text():

func is_complete() -> bool:
return _text_label.visible_ratio == 1


func _handle_effects(pos: int):
if not _parsed_dialog.effects.has(pos):
return

var curr_effect: EffectLocation = _parsed_dialog.effects[pos]
_parsed_dialog.effects.erase(pos)

match curr_effect.effect:
BBCCodes.BBC_EFFECT.WAIT:
_handle_pause(curr_effect.value.to_int())
_:
pass


func _handle_letter_pauses(letter: String):
match letter:
",", ".":
_handle_pause(0.1)
"?", "!":
_handle_pause(0.2)
_:
pass


func _handle_pause(time: float) -> void:
_pause = true
await get_tree().create_timer(time).timeout
_pause = false
1 change: 1 addition & 0 deletions Nodes/DialogueBox.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://dxciertla70xt
46 changes: 24 additions & 22 deletions Nodes/DialogueSystem.gd
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
class_name DialogueSystem
extends Control

# Imports
const Types = preload("res://addons/Suada/Nodes/Objects/Types.gd")

# Customise (FOR USER)
@export
var _voice_snd_effect: AudioStream = load("res://addons/Suada/Assets/Sounds/vocal_sound_1.ogg")
Expand All @@ -26,7 +24,7 @@ var _pause = false
var _exiting = false
var _chosen = false
var _choice = 0
var _conversation: Array[Dialog] = []
var _conversation: Dictionary[int, Dialog] = {}

@onready var _dialogue_box: DialogueTextBox = $DialogueContainer/TextBox
@onready var _name_box: MarginContainer = $NameBox
Expand All @@ -35,7 +33,7 @@ var _conversation: Array[Dialog] = []


## Add a convesation and setup the dialog system.
func add_conversation(conversation: Array) -> void:
func add_conversation(conversation: Dictionary[int, Dialog]) -> void:
_conversation = conversation
_setup()

Expand Down Expand Up @@ -65,8 +63,8 @@ func _process(_delta):
# Interact behaviour
if _interact_key_pressed:
if _conversation[_page].type == Types.DialogType.NORMAL:
if _page + 1 < _conversation.size():
_page += 1
_page = _conversation[_page].next
if _page != -1:
_set_portrait(_conversation[_page].portrait)
_setup()
else:
Expand Down Expand Up @@ -109,12 +107,21 @@ func _input(event):
_down_key_pressed = 0


func _reset() -> void:
_choice = 0
_chosen = false
_pause = false


func _setup() -> void:
_reset()

_portrait_box.setup(
load(_conversation[0].portrait.portrait_path) as SpriteFrames, _voice_snd_effect
)

if _page < 0 or _page >= _conversation.size():
printerr("Wrong conversation position.")
return

var name_str = _conversation[_page].name
Expand All @@ -134,28 +141,23 @@ func _setup() -> void:
func _handle_dialogue_choice() -> void:
_handle_pause(0.1)

if _page + 1 < _conversation.size():
var nl = _next_line[_page]
match nl[_choice]:
-1:
queue_free()
return
0:
_page += 1
_:
_page = nl[_choice]

_setup()
else:
if _choice > _conversation.size():
printerr("Choice position out of conversation.")
queue_free()
return

_chosen = false
if _choice == -1:
queue_free()
return

_page = _conversation[_page].choices[_choice].next
_setup()


func _handle_dialogue_change_choice(visible: bool = false) -> void:
var text = _conversation[_page].text
for choice_index in _conversation[_page].choices.size():
var choice_text = _conversation[_page].choices[choice_index]
var choice_text = _conversation[_page].choices[choice_index].text

text += "\n"

Expand Down
1 change: 1 addition & 0 deletions Nodes/DialogueSystem.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://7u5tl70iop21
1 change: 1 addition & 0 deletions Nodes/Effects/RichTextEffectFlicker.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://5yswxgvifti8
1 change: 1 addition & 0 deletions Nodes/Effects/RichTextEffectGhost.gd
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ func _process_custom_fx(char_fx):

var alpha = sin(char_fx.elapsed_time * speed + (char_fx.range.x / span)) * 0.5 + 0.5
char_fx.color.a = alpha

return true
1 change: 1 addition & 0 deletions Nodes/Effects/RichTextEffectGhost.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://blrkxba5rjrdd
1 change: 1 addition & 0 deletions Nodes/Effects/RichTextEffectMatrix.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://cojx35wpxirrm
1 change: 1 addition & 0 deletions Nodes/Effects/RichTextEffectPulse.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://biw6a0o6espjc
1 change: 1 addition & 0 deletions Nodes/Effects/RichTextEffectShift.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://drmvnbvsiehsq
19 changes: 19 additions & 0 deletions Nodes/Effects/RichTextEffectSpin.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
@tool
class_name RichTextEffectSpin
extends RichTextEffect

# Syntax: [spin freq=5.0 span=10.0][/spin]

# Define the tag name.
var bbcode = "spin"


func _process_custom_fx(char_fx: CharFXTransform):
var freq = char_fx.env.get("freq", 5.0)

var val: float = char_fx.elapsed_time * 100
var shift: float = sin(val * PI * freq / SuadaGlobals.TARGET_FPS)
var rotation = shift / 4
char_fx.transform = char_fx.transform.rotated_local(rotation)

return true
1 change: 1 addition & 0 deletions Nodes/Effects/RichTextEffectSpin.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://bbvp37cw5mk81
1 change: 1 addition & 0 deletions Nodes/FinishEffect.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://cvnq24ncd7wdb
17 changes: 17 additions & 0 deletions Nodes/Globals/BBCCodes.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class_name BBCCodes

## Dialog types.
enum BBC_EFFECT { NONE, WAIT }

# BBCode effects.
const BBC_CODES_MAP: Dictionary[String, BBC_EFFECT] = {
"wait": BBC_EFFECT.WAIT,
}

# BBCode regular expression.
const BBC_REXP: String = "\\[(wait)(?:=([\\w\\d]+))?\\]"

# Any BBCode regular expression.
# Used in case a wrong one was read and we need to remove it.
# It matches any BBCode, even not supported.
const BBC_ANY_REXP: String = "\\[.*\\]"
1 change: 1 addition & 0 deletions Nodes/Globals/BBCCodes.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://d2v6wmxmtm5xl
8 changes: 8 additions & 0 deletions Nodes/Globals/SuadaConfig.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
extends Node

# Configurable
@export var text_speed: float = 0.25
@export var vocal_sound: bool = true

# Counters
@export var effect_cnt: int = 0
1 change: 1 addition & 0 deletions Nodes/Globals/SuadaConfig.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://fuj82s32vfds
8 changes: 8 additions & 0 deletions Nodes/Globals/SuadaGlobals.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class_name SuadaGlobals
extends Resource

const TARGET_FPS: int = 60

# Effect variables
const AMPLITUDE: int = 4
const FREQUENCY: int = 2
1 change: 1 addition & 0 deletions Nodes/Globals/SuadaGlobals.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://chogjltrgtqcu
4 changes: 4 additions & 0 deletions Nodes/Globals/Types.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class_name Types

## Dialog types.
enum DialogType { NORMAL, CHOICE }
1 change: 1 addition & 0 deletions Nodes/Globals/Types.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://de78qnqcg336r
1 change: 1 addition & 0 deletions Nodes/NameBox.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://c6du80pgr26nq
1 change: 1 addition & 0 deletions Nodes/NameText.gd.uid
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://dt3sbbh26vbd8
15 changes: 15 additions & 0 deletions Nodes/Objects/Choice.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## The Choice class
##
## @desc:
## An object to hold choice data.
class_name Choice
extends Resource

var text: String = ""
var next: int = -1


## Initialise the dialog object.
func _init(text: String, next: int = -1):
self.text = text
self.next = next
Loading