Color text when chanting
All checks were successful
/ test (push) Successful in 2s

This commit is contained in:
Antonio Dell'Annunziata 2025-03-09 10:31:55 +01:00
parent 097de25931
commit f6c53bf5ca
No known key found for this signature in database
GPG key ID: 8D2BB16641F06E94
8 changed files with 81 additions and 31 deletions

View file

@ -1,28 +1,38 @@
extends Path2D
signal completed
var is_mouse_in_path_follow_area: bool = false
var is_incantation_started: bool = false
var incantation_progress: float = 0.0
var is_incantation_completed: bool = false
@onready var path_follow: Node2D = $PathFollow2D
@onready var path_follow_area: Area2D = $PathFollow2D/Area2D
@onready var area: Area2D = $Area2D
@onready var incantation_text: IncantationText = $IncantationText
func _ready():
path_follow_area.mouse_entered.connect(func(): is_mouse_in_path_follow_area = true)
path_follow_area.mouse_exited.connect(func():
area.mouse_entered.connect(func(): is_mouse_in_path_follow_area = true)
area.mouse_exited.connect(func():
is_mouse_in_path_follow_area = false
reset_incantation()
)
func _draw():
var points = curve.get_baked_points()
for i in points.size():
if i == 0: continue
draw_line(points[i-1], points[i], Color.BLACK, 2.0)
# Draws debug line accross the path in game
#var points = curve.get_baked_points()
#for i in points.size():
# if i == 0: continue
# draw_line(points[i-1], points[i], Color.BLACK, 2.0)
pass
var previous_offset: float:
set(new_value):
previous_offset = new_value
incantation_text.colored_offset = previous_offset
var previous_offset: float
func _input(event):
if is_incantation_completed: return
if event is InputEventMouseButton:
if event.is_pressed() and is_mouse_in_path_follow_area and not is_incantation_started:
is_incantation_started = true
@ -30,15 +40,19 @@ func _input(event):
var motion_event = event as InputEventMouseMotion
var next_point = curve.get_closest_point(to_local(motion_event.global_position))
var next_offset = curve.get_closest_offset(next_point)
print(previous_offset, " " ,next_offset)
if previous_offset <= 0.0:
previous_offset = next_offset
elif next_offset - previous_offset <= 0:
return
previous_offset = next_offset
path_follow.position = next_point
area.position = next_point
if next_point == curve.get_point_position(curve.point_count - 1):
completed.emit()
is_incantation_completed = true
func reset_incantation():
if is_incantation_completed: return
is_incantation_started = false
path_follow.position = curve.get_point_position(0)
area.position = curve.get_point_position(0)
previous_offset = 0.0

29
incantation_text.gd Normal file
View file

@ -0,0 +1,29 @@
@tool
class_name IncantationText
extends Control
@export_multiline var text: String:
set(new_value):
text = new_value
queue_redraw()
@export var colored_offset: float = 0:
set(new_value):
colored_offset = new_value
queue_redraw()
var curve: Curve2D
func _ready():
curve = (get_parent() as Path2D).curve
func _draw():
if text.length() < 2: return
var offset = 0
for c in text:
var t = curve.sample_baked_with_rotation(offset)
draw_set_transform(t.origin - (Vector2.UP * 5).rotated(t.get_rotation()), t.get_rotation())
#t.rotated_local()
draw_char(get_theme_default_font(), Vector2.ZERO, c, 16, Color.WHITE if offset >= colored_offset else Color.RED)
offset += 10

View file

@ -27,6 +27,10 @@ cutter=""
grabber=""
patience_bar=""
[gui]
theme/default_font_multichannel_signed_distance_field=true
[layer_names]
2d_physics/layer_1="Scalpel"

6
prototype_ritual_book.gd Normal file
View file

@ -0,0 +1,6 @@
extends Node2D
signal incantation_completed
func _on_incantation_completed():
incantation_completed.emit()

View file

@ -0,0 +1 @@
uid://dsiaa53vt3y6e

View file

@ -1,6 +1,8 @@
[gd_scene load_steps=8 format=3 uid="uid://qkwh186nbcya"]
[ext_resource type="Script" uid="uid://dak6uc4v3us7w" path="res://incantation.gd" id="1_v6csu"]
[ext_resource type="Script" uid="uid://dsiaa53vt3y6e" path="res://prototype_ritual_book.gd" id="1_yc2mw"]
[ext_resource type="Script" uid="uid://cpscp5a5nxfop" path="res://incantation_text.gd" id="2_5ntyk"]
[sub_resource type="Gradient" id="Gradient_2cqfq"]
offsets = PackedFloat32Array(0.80212, 0.978799, 1)
@ -18,15 +20,10 @@ _data = {
point_count = 11
[sub_resource type="CircleShape2D" id="CircleShape2D_v6csu"]
[sub_resource type="Gradient" id="Gradient_v6csu"]
[sub_resource type="GradientTexture2D" id="GradientTexture2D_5ntyk"]
gradient = SubResource("Gradient_v6csu")
width = 10
height = 10
radius = 13.8924
[node name="PrototypeRitualBook" type="Node2D"]
script = ExtResource("1_yc2mw")
[node name="Left" type="Sprite2D" parent="."]
position = Vector2(306, 311)
@ -42,16 +39,21 @@ position = Vector2(-1, 1)
curve = SubResource("Curve2D_5ntyk")
script = ExtResource("1_v6csu")
[node name="PathFollow2D" type="Node2D" parent="Incantation"]
[node name="Area2D" type="Area2D" parent="Incantation"]
position = Vector2(202, 149)
rotation = 0.562498
[node name="Area2D" type="Area2D" parent="Incantation/PathFollow2D"]
collision_layer = 512
collision_mask = 512
[node name="CollisionShape2D" type="CollisionShape2D" parent="Incantation/PathFollow2D/Area2D"]
[node name="CollisionShape2D" type="CollisionShape2D" parent="Incantation/Area2D"]
shape = SubResource("CircleShape2D_v6csu")
[node name="Sprite2D" type="Sprite2D" parent="Incantation/PathFollow2D"]
texture = SubResource("GradientTexture2D_5ntyk")
[node name="IncantationText" type="Control" parent="Incantation"]
layout_mode = 3
anchors_preset = 0
offset_right = 40.0
offset_bottom = 23.0
script = ExtResource("2_5ntyk")
text = "Hallo dies ist ein langer TExt, er könnte auch eine Ritual sein. Wir werden sehen"
[connection signal="completed" from="Incantation" to="." method="_on_incantation_completed"]

View file

@ -1,6 +0,0 @@
extends Label
func _draw():
(get_parent() as Path2D).curve.sample_baked_with_rotation()