improvements
This commit is contained in:
@@ -13,8 +13,8 @@ signal dialogue_completed()
|
||||
@export var hide_animation_duration: float = 0.2 # seconds
|
||||
|
||||
# Private variables
|
||||
var dialogue_box: Control = null
|
||||
var text_label: Label = null
|
||||
@onready var dialogue_box = $PanelContainer
|
||||
@onready var text_label: Label = $PanelContainer/Label
|
||||
var timer: Timer = null
|
||||
var current_text: String = ""
|
||||
var current_duration: float = 0.0
|
||||
@@ -24,58 +24,7 @@ var is_revealing: bool = false
|
||||
|
||||
func _ready():
|
||||
# Initialize the dialogue system
|
||||
_create_dialogue_ui()
|
||||
|
||||
func _create_dialogue_ui():
|
||||
# Create dialogue box UI
|
||||
dialogue_box = Control.new()
|
||||
dialogue_box.name = "DialogueBox"
|
||||
|
||||
# Create background
|
||||
var background = ColorRect.new()
|
||||
background.name = "Background"
|
||||
background.color = Color(1, 1, 1, 1) # White background
|
||||
background.size = Vector2(300, 80)
|
||||
background.anchor_left = 0.5
|
||||
background.anchor_top = 1.0
|
||||
background.anchor_right = 0.5
|
||||
background.anchor_bottom = 1.0
|
||||
background.position = Vector2(-150, -40) # Positioned above character
|
||||
background.pivot_offset = Vector2(150, 40) # Center pivot
|
||||
|
||||
# Create text label
|
||||
text_label = Label.new()
|
||||
text_label.name = "TextLabel"
|
||||
text_label.text = ""
|
||||
text_label.size = Vector2(280, 60)
|
||||
text_label.anchor_left = 0.5
|
||||
text_label.add_theme_color_override("font_color", Color.BLACK)
|
||||
text_label.anchor_top = 0.5
|
||||
text_label.anchor_right = 0.5
|
||||
text_label.anchor_bottom = 0.5
|
||||
text_label.position = Vector2(-140, -30) # Centered in background
|
||||
text_label.pivot_offset = Vector2(140, 30) # Center pivot
|
||||
text_label.horizontal_alignment = HORIZONTAL_ALIGNMENT_LEFT
|
||||
text_label.vertical_alignment = VERTICAL_ALIGNMENT_TOP
|
||||
text_label.autowrap_mode = 2 # TextServer.AUTOWRAP_WORD_SMART
|
||||
#text_label.custom_styles.normal.font_size = 16
|
||||
|
||||
# Add to dialogue box
|
||||
dialogue_box.add_child(background)
|
||||
dialogue_box.add_child(text_label)
|
||||
|
||||
# Set initial state - hidden and transparent
|
||||
dialogue_box.visible = false
|
||||
dialogue_box.modulate.a = 0.0
|
||||
|
||||
# Add to scene tree (should be added to parent character)
|
||||
add_child(dialogue_box)
|
||||
|
||||
# Position the dialogue box above the character
|
||||
# This ensures it's positioned correctly relative to the character
|
||||
if get_parent() != null:
|
||||
var parent_pos = get_parent().position
|
||||
dialogue_box.position = Vector2(parent_pos.x, parent_pos.y - 50) # Position above character
|
||||
pass
|
||||
|
||||
func trigger_dialogue(text: String, duration: float = 3.0) -> void:
|
||||
"""Trigger dialogue with specified text and duration"""
|
||||
@@ -167,7 +116,8 @@ func reveal_next_character():
|
||||
text_index += 1
|
||||
|
||||
# Schedule next character reveal
|
||||
await get_tree().create_timer(text_reveal_speed)
|
||||
|
||||
await get_tree().create_timer(text_reveal_speed).timeout
|
||||
reveal_next_character()
|
||||
|
||||
func _on_dialogue_timeout():
|
||||
|
||||
Reference in New Issue
Block a user