improvements
This commit is contained in:
45
scenes/dialogue_system.tscn
Normal file
45
scenes/dialogue_system.tscn
Normal file
@@ -0,0 +1,45 @@
|
||||
[gd_scene load_steps=3 format=3 uid="uid://hnknhvuc6wut"]
|
||||
|
||||
[ext_resource type="Script" path="res://scripts/dialogue_system.gd" id="1_78qb7"]
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_u70vs"]
|
||||
border_width_left = 10
|
||||
border_width_top = 10
|
||||
border_width_right = 10
|
||||
border_width_bottom = 10
|
||||
corner_radius_top_left = 25
|
||||
corner_radius_top_right = 25
|
||||
corner_radius_bottom_right = 25
|
||||
corner_radius_bottom_left = 25
|
||||
|
||||
[node name="DialogueSystem" type="Node2D"]
|
||||
script = ExtResource("1_78qb7")
|
||||
text_reveal_speed = 0.02
|
||||
|
||||
[node name="PanelContainer" type="PanelContainer" parent="."]
|
||||
clip_children = 1
|
||||
anchors_preset = 8
|
||||
anchor_left = 0.5
|
||||
anchor_top = 0.5
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 0.5
|
||||
offset_left = -125.0
|
||||
offset_top = -50.0
|
||||
offset_right = 125.0
|
||||
offset_bottom = 50.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
theme_override_styles/panel = SubResource("StyleBoxFlat_u70vs")
|
||||
|
||||
[node name="ColorRect" type="ColorRect" parent="PanelContainer"]
|
||||
custom_minimum_size = Vector2(250, 100)
|
||||
layout_mode = 2
|
||||
|
||||
[node name="Control" type="Control" parent="PanelContainer/ColorRect"]
|
||||
anchors_preset = 0
|
||||
offset_right = 40.0
|
||||
offset_bottom = 40.0
|
||||
|
||||
[node name="Label" type="Label" parent="PanelContainer"]
|
||||
layout_mode = 2
|
||||
theme_override_colors/font_color = Color(0, 0, 0, 1)
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
[ext_resource type="Script" path="res://scripts/test_dialogue.gd" id="1_f305o"]
|
||||
[ext_resource type="Script" path="res://scripts/base_character.gd" id="2_00bif"]
|
||||
[ext_resource type="Script" path="res://scripts/dialogue_system.gd" id="3_11ynk"]
|
||||
[ext_resource type="PackedScene" uid="uid://hnknhvuc6wut" path="res://scenes/dialogue_system.tscn" id="3_febaf"]
|
||||
|
||||
[node name="TestScene" type="Node2D"]
|
||||
position = Vector2(-1, 0)
|
||||
@@ -19,5 +19,4 @@ color = Color(0.2, 0.6, 1, 1)
|
||||
antialiased = true
|
||||
polygon = PackedVector2Array(10, -20, 20, 0, 10, 20, -10, 20, -20, 0, -10, -20)
|
||||
|
||||
[node name="DialogueSystem" type="Node2D" parent="Character/BaseCharacter"]
|
||||
script = ExtResource("3_11ynk")
|
||||
[node name="DialogueSystem" parent="Character/BaseCharacter" instance=ExtResource("3_febaf")]
|
||||
|
||||
@@ -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