Basic dialog system working

This commit is contained in:
2026-03-16 08:57:53 +11:00
parent 336dd59dbb
commit b433c31261
7 changed files with 45 additions and 26 deletions

View File

@@ -1,8 +1,7 @@
class_name ArrowGirl extends Area2D class_name ArrowGirl extends Area2D
@onready var _sprite = $AnimatedSprite2D @onready var _sprite = $AnimatedSprite2D
var dialog_text = preload("res://DialogDebug_1.tres") var dialog_text: DialogText = preload("res://DialogDebug_1.tres")
var dialog_counter: int = 0
#boilerplate #boilerplate
func _ready(): func _ready():
@@ -17,9 +16,4 @@ func _on_animation_finished() -> void:
func _on_body_entered(body) -> void: func _on_body_entered(body) -> void:
if body is BoxBoy: if body is BoxBoy:
%DialogController.set_dialog(dialog_text.get_line_raw(dialog_counter), 0.2) %DialogController.set_dialog_text(dialog_text, 0.2)
dialog_counter += 1
func _on_body_exited(body) -> void:
if body is BoxBoy:
%DialogController.set_dialog("")

View File

@@ -38,7 +38,7 @@ animations = [{
}] }]
[sub_resource type="RectangleShape2D" id="RectangleShape2D_53v1e"] [sub_resource type="RectangleShape2D" id="RectangleShape2D_53v1e"]
size = Vector2(32, 32) size = Vector2(32, 96)
[node name="ArrowGirl" type="Area2D" unique_id=869288979] [node name="ArrowGirl" type="Area2D" unique_id=869288979]
script = ExtResource("1_53v1e") script = ExtResource("1_53v1e")
@@ -49,10 +49,9 @@ animation = &"idle_glance"
metadata/_edit_lock_ = true metadata/_edit_lock_ = true
[node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=1190138841] [node name="CollisionShape2D" type="CollisionShape2D" parent="." unique_id=1190138841]
visible = false position = Vector2(0, -32)
shape = SubResource("RectangleShape2D_53v1e") shape = SubResource("RectangleShape2D_53v1e")
metadata/_edit_lock_ = true metadata/_edit_lock_ = true
[connection signal="body_entered" from="." to="." method="_on_body_entered"] [connection signal="body_entered" from="." to="." method="_on_body_entered"]
[connection signal="body_exited" from="." to="." method="_on_body_exited"]
[connection signal="animation_finished" from="AnimatedSprite2D" to="." method="_on_animation_finished"] [connection signal="animation_finished" from="AnimatedSprite2D" to="." method="_on_animation_finished"]

View File

@@ -33,7 +33,7 @@ func _physics_process(_delta) -> void:
buffer_grounded -= 1 buffer_grounded -= 1
#jump buffering #jump buffering
if Input.is_action_just_pressed("input_jump"): if %GameplayController.input_enabled and Input.is_action_just_pressed("input_jump"):
buffer_jumping = 6 buffer_jumping = 6
else: else:
buffer_jumping -= 1 buffer_jumping -= 1
@@ -45,7 +45,7 @@ func _physics_process(_delta) -> void:
buffer_jumping = 0 buffer_jumping = 0
#normally, fall faster than you rise #normally, fall faster than you rise
elif velocity.y < 0 and (Input.is_action_pressed("input_jump") or just_bounced): elif ((%GameplayController.input_enabled and Input.is_action_pressed("input_jump")) or just_bounced) and velocity.y < 0:
velocity.y += GRAVITY_RISING velocity.y += GRAVITY_RISING
else: else:
velocity.y += GRAVITY_FALLING velocity.y += GRAVITY_FALLING
@@ -54,7 +54,7 @@ func _physics_process(_delta) -> void:
#sideways movement #sideways movement
var move_dir = Input.get_axis("input_left", "input_right") var move_dir = Input.get_axis("input_left", "input_right")
if move_dir: if %GameplayController.input_enabled and move_dir:
_sprite.flip_h = move_dir < 0 #fancy HD 4K graphics _sprite.flip_h = move_dir < 0 #fancy HD 4K graphics
velocity.x += MOVE_FORCE * move_dir velocity.x += MOVE_FORCE * move_dir

View File

@@ -3,16 +3,37 @@ extends Node
@export var dialogContainer: MarginContainer @export var dialogContainer: MarginContainer
@export var dialogTextLabel: RichTextLabel @export var dialogTextLabel: RichTextLabel
func set_dialog(text: String, seconds: float = 1) -> void: var _current_dialog_counter: int = 0
var _current_dialog_text: DialogText = null
var _current_dialog_seconds: float = 1
func set_dialog_text(dialog_text: DialogText, seconds: float = 1) -> void:
_current_dialog_counter = -1
_current_dialog_text = dialog_text
_current_dialog_seconds = seconds
_next_dialog_line()
func _next_dialog_line() -> void:
_current_dialog_counter += 1
set_dialog_line(_current_dialog_text.get_line_raw(_current_dialog_counter), _current_dialog_seconds)
func _process(_delta: float) -> void:
if Input.is_action_just_pressed("ui_accept") and _current_dialog_text:
_next_dialog_line()
func set_dialog_line(text: String, seconds: float = 1) -> void:
dialogTextLabel.text = text dialogTextLabel.text = text
dialogTextLabel.visible_ratio = 0 dialogTextLabel.visible_ratio = 0
var ratio: float = 0 var ratio: float = 0
if text.length() == 0: if text.length() == 0:
dialogContainer.visible = false dialogContainer.visible = false
return %GameplayController.input_enabled = true
_current_dialog_text = null
return #a hacky way to clear the dialog box
else: else:
dialogContainer.visible = true dialogContainer.visible = true
%GameplayController.input_enabled = false
var increment: float = (1 / seconds)/ 60.0 var increment: float = (1 / seconds)/ 60.0

View File

@@ -9,8 +9,14 @@ const LOREM_IPSUM = [
"", "",
] ]
static var input_enabled: bool = true:
get():
return input_enabled
set(value):
input_enabled = value
static var godmode: bool = false: static var godmode: bool = false:
get: get():
return godmode return godmode
func _process(_delta: float) -> void: func _process(_delta: float) -> void:

View File

@@ -1,7 +1,6 @@
class_name DialogText extends Resource class_name DialogText extends Resource
#contains the raw text info, allows you to iterate through it line-by-line ##Contains raw text for dialog boxes, and allows you to iterate through it line-by-line.
#only parse text once
@export_multiline() var text: String @export_multiline() var text: String
var _content: Array = [] var _content: Array = []

View File

@@ -29,29 +29,29 @@ window/subwindows/embed_subwindows=false
input_right={ input_right={
"deadzone": 0.2, "deadzone": 0.2,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194321,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null) "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194321,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":68,"key_label":0,"unicode":100,"location":0,"echo":false,"script":null) , Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":68,"physical_keycode":0,"key_label":0,"unicode":100,"location":0,"echo":false,"script":null)
] ]
} }
input_left={ input_left={
"deadzone": 0.2, "deadzone": 0.2,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194319,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null) "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194319,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":65,"key_label":0,"unicode":97,"location":0,"echo":false,"script":null) , Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":65,"physical_keycode":0,"key_label":0,"unicode":97,"location":0,"echo":false,"script":null)
] ]
} }
input_jump={ input_jump={
"deadzone": 0.2, "deadzone": 0.2,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":32,"key_label":0,"unicode":32,"location":0,"echo":false,"script":null) "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":32,"physical_keycode":0,"key_label":0,"unicode":32,"location":0,"echo":false,"script":null)
] ]
} }
controller_godmode={ controller_godmode={
"deadzone": 0.2, "deadzone": 0.2,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":true,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":71,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null) "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"command_or_control_autoremap":true,"alt_pressed":false,"shift_pressed":false,"pressed":false,"keycode":71,"physical_keycode":0,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null)
] ]
} }
controller_dialog={ controller_dialog={
"deadzone": 0.2, "deadzone": 0.2,
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":true,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":68,"key_label":0,"unicode":100,"location":0,"echo":false,"script":null) "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"command_or_control_autoremap":true,"alt_pressed":false,"shift_pressed":false,"pressed":false,"keycode":68,"physical_keycode":0,"key_label":0,"unicode":100,"location":0,"echo":false,"script":null)
] ]
} }