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
28 changes: 14 additions & 14 deletions Default.tres

Large diffs are not rendered by default.

51 changes: 51 additions & 0 deletions entities/game/animated_rich_text/scenes/AnimatedRichText.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
[gd_scene format=3 uid="uid://bi2oaoxrcmttm"]

[ext_resource type="Script" uid="uid://bpvtly15ln51t" path="res://entities/game/animated_rich_text/scripts/AnimatedText.gd" id="1_e40io"]
[ext_resource type="Script" uid="uid://dlu1f0smtal4e" path="res://entities/game/animated_rich_text/scripts/AnimatedRichtText.gd" id="1_u65rn"]
[ext_resource type="AudioStream" uid="uid://ctjq1ihqaqsqu" path="res://assets/audio/effect/letter_written.ogg" id="2_u65rn"]
[ext_resource type="Texture2D" uid="uid://cg0l7tvqmtghr" path="res://assets/sprites/sheet_white1x.png" id="3_5qj5y"]
[ext_resource type="Script" uid="uid://b1muqfd0npxnt" path="res://entities/game/animated_rich_text/scripts/TutorialContinueButton.gd" id="4_geyfo"]

[sub_resource type="AtlasTexture" id="AtlasTexture_ynyq3"]
atlas = ExtResource("3_5qj5y")
region = Rect2(410, 315, 32, 20)

[node name="AnimatedRichText" type="VBoxContainer" unique_id=873433623]
script = ExtResource("1_u65rn")

[node name="Body" type="RichTextLabel" parent="." unique_id=1416319131]
unique_name_in_owner = true
layout_mode = 2
size_flags_vertical = 3
text = "BODY"
fit_content = true
autowrap_mode = 2
visible_characters_behavior = 1
script = ExtResource("1_e40io")
letter_place_sound = ExtResource("2_u65rn")
sound_db_change = -15.0

[node name="MarginContainer" type="MarginContainer" parent="." unique_id=288432057]
custom_minimum_size = Vector2(42, 30)
layout_mode = 2
size_flags_horizontal = 8
theme_override_constants/margin_right = 10
theme_override_constants/margin_bottom = 10

[node name="TextureButton" type="TextureButton" parent="MarginContainer" unique_id=258480674]
layout_mode = 2
size_flags_horizontal = 0
size_flags_vertical = 8
texture_normal = SubResource("AtlasTexture_ynyq3")
stretch_mode = 3
script = ExtResource("4_geyfo")
pixels_to_move = 5.0
animation_speed = 1.5

[connection signal="append_new_text" from="." to="Body" method="add_animated_text"]
[connection signal="initial_text_changed" from="." to="Body" method="set_initial_text"]
[connection signal="animation_state_changed" from="Body" to="." method="animation_state_changed"]
[connection signal="current_text_displayed" from="Body" to="MarginContainer/TextureButton" method="show"]
[connection signal="no_text_left" from="Body" to="MarginContainer/TextureButton" method="hide"]
[connection signal="text_getting_animated" from="Body" to="MarginContainer/TextureButton" method="hide"]
[connection signal="pressed" from="MarginContainer/TextureButton" to="Body" method="roll_in_next_text"]
22 changes: 22 additions & 0 deletions entities/game/animated_rich_text/scripts/AnimatedRichtText.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
@tool
extends Node

signal append_new_text(new_value: String)
signal initial_text_changed(new_text: String)
signal animation_playing()
signal animation_done()

@export var initial_text: String = "":
set(value):
initial_text = value
initial_text_changed.emit(value)

func add_new_text(new_value: String) -> void:
append_new_text.emit(new_value)

func animation_state_changed(new_state: bool) -> void:
if new_state:
animation_playing.emit()
return

animation_done.emit()
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
uid://dlu1f0smtal4e
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ signal text_getting_animated()
signal is_multi_text()
signal current_text_displayed()
signal no_text_left()
signal animation_state_changed(new_state: bool)

@export var letter_place_sound: AudioStream = null
@export var written_end_sound: AudioStream = null
Expand All @@ -13,20 +14,30 @@ signal no_text_left()

var tween: Tween = null
var text_queue: Array[String] = []
var target_text: String = ""

var animating: bool = false
var should_animate: bool = true
var last_index: int = 0

var _initial_text: String = ""
var _last_value: float = -1

# Called when the node enters the scene tree for the first time.
func _ready() -> void:
text = ""
add_animated_text(_initial_text)
if animating:
visible_characters = 0

func set_initial_text(new_text: String) -> void:
_initial_text = new_text
text = _initial_text

func toggle_animation(on: bool) -> void:
should_animate = on

func add_animated_text(new_text: String) -> void:
if new_text == "":
return
var translated: String = tr(new_text)
text_queue.append(translated)
if animating:
Expand All @@ -35,32 +46,38 @@ func add_animated_text(new_text: String) -> void:
display_animated_text(text_queue.pop_front())

func display_animated_text(text_to_display: String) -> void:
_last_value = -1
text = text_to_display
if !should_animate:
text = text_to_display
text_was_set()
return
animating = true
visible_characters = 0
text_getting_animated.emit()
target_text = text_to_display
last_index = 0
animation_state_changed.emit(true)
tween = create_tween()
tween.set_ease(tween.EASE_OUT)
tween.tween_method(animation_step, 0, target_text.length(), time_per_letter * target_text.length())
tween.tween_method(animation_step, 0, text.length(), time_per_letter * text.length())
tween.finished.connect(text_was_set)

func animation_step(value: float) -> void:
if _last_value == value:
return
_last_value = value
var letters_to_show: int = int(value)
if last_index < letters_to_show:
last_index = letters_to_show
play_letter_sound()
text = target_text.substr(0, letters_to_show)
play_letter_sound()

visible_characters = letters_to_show
if letters_to_show >= text.length():
visible_characters = -1

func play_letter_sound() -> void:
GlobalSoundManager.play_sound_effect(letter_place_sound, sound_db_change)

func roll_in_next_text() -> void:
if text_queue.size() == 0:
no_text_left.emit()
animation_state_changed.emit(false)
return
display_animated_text(text_queue.pop_front())

Expand All @@ -69,6 +86,7 @@ func text_was_set() -> void:
current_text_displayed.emit()
if text_queue.size() == 0:
no_text_left.emit()
animation_state_changed.emit(false)
if should_animate:
GlobalSoundManager.play_sound_effect(written_end_sound, sound_db_change)

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ extends TextureButton

var animation_tween: Tween

func _ready():
initial_position = position

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta: float) -> void:
if visible == false:
Expand All @@ -15,7 +18,7 @@ func _process(_delta: float) -> void:
func animate() -> void:
if animation_tween != null and animation_tween.is_valid():
return
print("start animation")
print("loop")
animation_tween = create_tween()
animation_tween.tween_property(self, "position", Vector2(initial_position.x, initial_position.y + pixels_to_move), animation_speed)
animation_tween.tween_property(self, "position", initial_position, animation_speed)
38 changes: 21 additions & 17 deletions entities/game/auto_close_popup/scenes/AutoClosePopup.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -2,66 +2,70 @@

[ext_resource type="Script" uid="uid://b44lnl21k5vc" path="res://entities/game/auto_close_popup/scripts/AutoClosePopup.gd" id="1_q838q"]
[ext_resource type="Script" uid="uid://cdf84o2qp0vdc" path="res://entities/ui/gameplay_settings/scripts/AutoCompleteRound.gd" id="2_6fyx6"]
[ext_resource type="StyleBox" uid="uid://d1rhal5rp1608" path="res://assets/styles/panel/MetalBox.tres" id="2_sgjc8"]
[ext_resource type="PackedScene" uid="uid://bi2oaoxrcmttm" path="res://entities/game/animated_rich_text/scenes/AnimatedRichText.tscn" id="3_1kcrw"]
[ext_resource type="Script" uid="uid://g8dk5ckx5t4d" path="res://entities/ui/gameplay_settings/scripts/AutoCloseRoundSlider.gd" id="3_sgjc8"]
[ext_resource type="Resource" uid="uid://t4b63t07og3" path="res://shared/resources/translations/assets/TimeForCompletion.tres" id="4_1kcrw"]
[ext_resource type="Script" uid="uid://chfatpxf8ucxr" path="res://shared/entities/clickable_button/ClickableButton.gd" id="5_tp0ur"]

[node name="AutoClosePopup" type="CenterContainer"]
[node name="AutoClosePopup" type="CenterContainer" unique_id=1954482098]
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_q838q")

[node name="PanelContainer" type="PanelContainer" parent="."]
[node name="PanelContainer" type="PanelContainer" parent="." unique_id=459183534]
custom_minimum_size = Vector2(500, 0)
layout_mode = 2

[node name="MarginContainer" type="MarginContainer" parent="PanelContainer"]
[node name="MarginContainer" type="MarginContainer" parent="PanelContainer" unique_id=519067603]
layout_mode = 2
theme_override_constants/margin_left = 5
theme_override_constants/margin_top = 5
theme_override_constants/margin_right = 5
theme_override_constants/margin_bottom = 5

[node name="VBoxContainer" type="VBoxContainer" parent="PanelContainer/MarginContainer"]
[node name="VBoxContainer" type="VBoxContainer" parent="PanelContainer/MarginContainer" unique_id=800117384]
layout_mode = 2

[node name="RichTextLabel" type="RichTextLabel" parent="PanelContainer/MarginContainer/VBoxContainer"]
[node name="PanelContainer" type="PanelContainer" parent="PanelContainer/MarginContainer/VBoxContainer" unique_id=421598363]
layout_mode = 2
size_flags_vertical = 3
bbcode_enabled = true
text = "AUTO_CLOSE_POPUP_BODY"
fit_content = true
theme_override_styles/panel = ExtResource("2_sgjc8")

[node name="VBoxContainer" type="VBoxContainer" parent="PanelContainer/MarginContainer/VBoxContainer"]
[node name="AnimatedRichText" parent="PanelContainer/MarginContainer/VBoxContainer/PanelContainer" unique_id=873433623 instance=ExtResource("3_1kcrw")]
layout_mode = 2
initial_text = "AUTO_CLOSE_POPUP_BODY"

[node name="AutoCompleteRound" type="CheckButton" parent="PanelContainer/MarginContainer/VBoxContainer/VBoxContainer"]
[node name="VBoxContainer" type="VBoxContainer" parent="PanelContainer/MarginContainer/VBoxContainer" unique_id=293706623]
layout_mode = 2

[node name="AutoCompleteRound" type="CheckButton" parent="PanelContainer/MarginContainer/VBoxContainer/VBoxContainer" unique_id=978446831]
layout_mode = 2
text = "AUTO_COMPLETE_ROUND"
script = ExtResource("2_6fyx6")

[node name="AutoCompleteTimer" type="HBoxContainer" parent="PanelContainer/MarginContainer/VBoxContainer/VBoxContainer"]
[node name="AutoCompleteTimer" type="HBoxContainer" parent="PanelContainer/MarginContainer/VBoxContainer/VBoxContainer" unique_id=369697036]
custom_minimum_size = Vector2(100, 0)
layout_mode = 2
script = ExtResource("3_sgjc8")
completion_time_translation = ExtResource("4_1kcrw")

[node name="TimeForCompletion" type="Label" parent="PanelContainer/MarginContainer/VBoxContainer/VBoxContainer/AutoCompleteTimer"]
[node name="TimeForCompletion" type="Label" parent="PanelContainer/MarginContainer/VBoxContainer/VBoxContainer/AutoCompleteTimer" unique_id=1975635820]
auto_translate_mode = 2
layout_mode = 2
tooltip_auto_translate_mode = 2
text = "TIME_FOR_COMPLETION"

[node name="SecondsSlider" type="HSlider" parent="PanelContainer/MarginContainer/VBoxContainer/VBoxContainer/AutoCompleteTimer"]
[node name="SecondsSlider" type="HSlider" parent="PanelContainer/MarginContainer/VBoxContainer/VBoxContainer/AutoCompleteTimer" unique_id=126651385]
custom_minimum_size = Vector2(200, 0)
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 1
max_value = 5.0

[node name="Button" type="Button" parent="PanelContainer/MarginContainer/VBoxContainer"]
[node name="Button" type="Button" parent="PanelContainer/MarginContainer/VBoxContainer" unique_id=244490318]
layout_mode = 2
size_flags_horizontal = 8
size_flags_vertical = 4
Expand All @@ -70,11 +74,11 @@ script = ExtResource("5_tp0ur")

[connection signal="settings_loaded" from="." to="PanelContainer/MarginContainer/VBoxContainer/VBoxContainer/AutoCompleteRound" method="settings_loaded"]
[connection signal="settings_loaded" from="." to="PanelContainer/MarginContainer/VBoxContainer/VBoxContainer/AutoCompleteTimer" method="settings_loaded"]
[connection signal="animation_done" from="PanelContainer/MarginContainer/VBoxContainer/PanelContainer/AnimatedRichText" to="PanelContainer/MarginContainer/VBoxContainer/Button" method="enable_button"]
[connection signal="animation_playing" from="PanelContainer/MarginContainer/VBoxContainer/PanelContainer/AnimatedRichText" to="PanelContainer/MarginContainer/VBoxContainer/Button" method="disable_button"]
[connection signal="toggled" from="PanelContainer/MarginContainer/VBoxContainer/VBoxContainer/AutoCompleteRound" to="." method="auto_complete_state_changed"]
[connection signal="toggled" from="PanelContainer/MarginContainer/VBoxContainer/VBoxContainer/AutoCompleteRound" to="PanelContainer/MarginContainer/VBoxContainer/VBoxContainer/AutoCompleteTimer" method="toggle_visibility"]
[connection signal="completion_time_changed" from="PanelContainer/MarginContainer/VBoxContainer/VBoxContainer/AutoCompleteTimer" to="PanelContainer/MarginContainer/VBoxContainer/VBoxContainer/AutoCompleteTimer/TimeForCompletion" method="set_text"]
[connection signal="update_max_slider_value" from="PanelContainer/MarginContainer/VBoxContainer/VBoxContainer/AutoCompleteTimer" to="PanelContainer/MarginContainer/VBoxContainer/VBoxContainer/AutoCompleteTimer/SecondsSlider" method="set_max"]
[connection signal="update_min_slider_value" from="PanelContainer/MarginContainer/VBoxContainer/VBoxContainer/AutoCompleteTimer" to="PanelContainer/MarginContainer/VBoxContainer/VBoxContainer/AutoCompleteTimer/SecondsSlider" method="set_min"]
[connection signal="update_slider_value" from="PanelContainer/MarginContainer/VBoxContainer/VBoxContainer/AutoCompleteTimer" to="PanelContainer/MarginContainer/VBoxContainer/VBoxContainer/AutoCompleteTimer/SecondsSlider" method="set_value"]
[connection signal="value_changed" from="PanelContainer/MarginContainer/VBoxContainer/VBoxContainer/AutoCompleteTimer/SecondsSlider" to="." method="auto_complete_time_changed"]
[connection signal="value_changed" from="PanelContainer/MarginContainer/VBoxContainer/VBoxContainer/AutoCompleteTimer/SecondsSlider" to="PanelContainer/MarginContainer/VBoxContainer/VBoxContainer/AutoCompleteTimer" method="slider_changed"]
Expand Down
Loading