diff --git a/curved_label.gd b/curved_label.gd new file mode 100644 index 0000000..d5e423a --- /dev/null +++ b/curved_label.gd @@ -0,0 +1,21 @@ +@tool +class_name CurvedLabel +extends Control + + +@export var curve: Curve +@export var text: String: + set(new_value): + text = new_value + queue_redraw() +@export var enable_rotation: bool = true: + set(new_value): + enable_rotation = new_value + queue_redraw() + +func _draw(): + var rotation = 0.0 + for i in text.length(): + draw_char(get_theme_default_font(), Vector2.ZERO + (Vector2.RIGHT * (i*10)), text[i]) + rotation += 10.0 if enable_rotation else 0 + draw_set_transform(Vector2.ZERO, deg_to_rad(rotation)) diff --git a/curved_label.gd.uid b/curved_label.gd.uid new file mode 100644 index 0000000..f4665f0 --- /dev/null +++ b/curved_label.gd.uid @@ -0,0 +1 @@ +uid://dcj3w8wie6ohv diff --git a/incantation.gd b/incantation.gd new file mode 100644 index 0000000..5e790ab --- /dev/null +++ b/incantation.gd @@ -0,0 +1,44 @@ +extends Path2D + + +var is_mouse_in_path_follow_area: bool = false +var is_incantation_started: bool = false +var incantation_progress: float = 0.0 + +@onready var path_follow: Node2D = $PathFollow2D +@onready var path_follow_area: Area2D = $PathFollow2D/Area2D + +func _ready(): + path_follow_area.mouse_entered.connect(func(): is_mouse_in_path_follow_area = true) + path_follow_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) + +var previous_offset: float +func _input(event): + if event is InputEventMouseButton: + if event.is_pressed() and is_mouse_in_path_follow_area and not is_incantation_started: + is_incantation_started = true + if event is InputEventMouseMotion and is_incantation_started: + 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 + +func reset_incantation(): + is_incantation_started = false + path_follow.position = curve.get_point_position(0) + previous_offset = 0.0 diff --git a/incantation.gd.uid b/incantation.gd.uid new file mode 100644 index 0000000..6d81ce4 --- /dev/null +++ b/incantation.gd.uid @@ -0,0 +1 @@ +uid://dak6uc4v3us7w diff --git a/main.gd b/main.gd index cdef6ad..c8526f7 100644 --- a/main.gd +++ b/main.gd @@ -2,6 +2,7 @@ extends Node2D const DARK_CUT_SCENE = preload("res://operation/prototype_dark_cut.tscn") const DIALOG_SCENE = preload("res://dialog.tscn") +const RITUAL_BOOK_SCENE = preload("res://prototype_ritual_book.tscn") @onready var room: Node2D = $Room @@ -53,3 +54,7 @@ func _disable_node2d(node: Node2D): func _enable_node2d(node: Node2D): node.show() node.set_deferred("process", true) + + +func _on_ritual_book_clicked(): + pass # Replace with function body. diff --git a/main.tscn b/main.tscn index 909cd48..8009ae0 100644 --- a/main.tscn +++ b/main.tscn @@ -1,9 +1,11 @@ -[gd_scene load_steps=28 format=3 uid="uid://w3ntt1yh1nq7"] +[gd_scene load_steps=32 format=3 uid="uid://w3ntt1yh1nq7"] [ext_resource type="Script" uid="uid://lnmooufxbuym" path="res://main.gd" id="1_dp5o4"] [ext_resource type="PackedScene" uid="uid://3oqyqft8w72m" path="res://selectable.tscn" id="3_g5hfc"] [ext_resource type="Script" uid="uid://c3dlxuhruho8c" path="res://operation/feedback_canvas_modulate.gd" id="4_0odxb"] [ext_resource type="Texture2D" uid="uid://bicjfwpoa3pma" path="res://operation/test_table.png" id="5_lswn8"] +[ext_resource type="Script" uid="uid://ctpgjvo5g0sav" path="res://ritual_book.gd" id="12_ycdy4"] +[ext_resource type="PackedScene" uid="uid://qkwh186nbcya" path="res://prototype_ritual_book.tscn" id="13_ycdy4"] [ext_resource type="Texture2D" uid="uid://ccy71gl4qatjy" path="res://operation/pliers.png" id="17_b1qrp"] [ext_resource type="Script" uid="uid://crkr8emyhv1fo" path="res://operation/pliers.gd" id="18_come4"] [ext_resource type="PackedScene" uid="uid://c3of67m4ic212" path="res://operation/pickup_area.tscn" id="19_h8e4i"] @@ -49,8 +51,8 @@ width = 170 height = 170 [sub_resource type="Gradient" id="Gradient_b76e3"] -offsets = PackedFloat32Array(0.0881356) -colors = PackedColorArray(0.0885599, 0.0885599, 0.0885599, 1) +offsets = PackedFloat32Array(0.240678) +colors = PackedColorArray(0.737193, 0.737193, 0.737193, 1) [sub_resource type="GradientTexture1D" id="GradientTexture1D_soglf"] gradient = SubResource("Gradient_b76e3") @@ -76,6 +78,15 @@ radius = 5.65684 [sub_resource type="RectangleShape2D" id="RectangleShape2D_0odxb"] size = Vector2(110, 65) +[sub_resource type="Gradient" id="Gradient_vivmo"] +offsets = PackedFloat32Array(0.353357, 0.929329, 1) +colors = PackedColorArray(0, 0, 0, 1, 0.498233, 0.498233, 0.498233, 1, 1, 1, 1, 1) + +[sub_resource type="GradientTexture2D" id="GradientTexture2D_2cqfq"] +gradient = SubResource("Gradient_vivmo") +width = 32 +height = 128 + [node name="Main" type="Node2D"] script = ExtResource("1_dp5o4") @@ -131,8 +142,6 @@ position = Vector2(242, 258) texture = SubResource("GradientTexture2D_ty4ro") [node name="Selectable" parent="Room/Bob" instance=ExtResource("3_g5hfc")] -collision_layer = 256 -collision_mask = 256 [node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="Room/Bob/Selectable"] polygon = PackedVector2Array(-50, 100, -50, -100, 50, -100, 50, 100) @@ -249,8 +258,31 @@ collision_mask = 8 scale = Vector2(0.983051, 1) shape = SubResource("RectangleShape2D_0odxb") +[node name="RitualBook" type="Node2D" parent="Shelves"] +position = Vector2(-92, 240.5) +script = ExtResource("12_ycdy4") + +[node name="Sprite2D" type="Sprite2D" parent="Shelves/RitualBook"] +texture = SubResource("GradientTexture2D_2cqfq") + +[node name="Selectable" parent="Shelves/RitualBook/Sprite2D" instance=ExtResource("3_g5hfc")] + +[node name="CollisionPolygon2D" type="CollisionPolygon2D" parent="Shelves/RitualBook/Sprite2D/Selectable"] +polygon = PackedVector2Array(-16, -64, -16, 64, 16, 64, 16, -64) + +[node name="Label" type="Label" parent="Shelves/RitualBook"] +offset_left = -17.0 +offset_top = 40.5 +offset_right = 68.0 +offset_bottom = 63.5 +rotation = -1.5708 +text = "Rituals 101" + +[node name="PrototypeRitualBook" parent="." instance=ExtResource("13_ycdy4")] + [connection signal="clicked" from="Room/Bob/Selectable" to="." method="_on_bob_clicked"] [connection signal="clicked" from="Room/RitualPlace/Selectable" to="." method="_on_ritual_place_clicked"] [connection signal="area_entered" from="Shelves/Scalpel/CutArea" to="Shelves/Scalpel" method="_on_cut_area_area_entered"] [connection signal="area_exited" from="Shelves/Scalpel/CutArea" to="Shelves/Scalpel" method="_on_cut_area_area_exited"] [connection signal="timeout" from="Shelves/Scalpel/CutHurtTimer" to="Shelves/Scalpel" method="_on_cut_hurt_timer_timeout"] +[connection signal="clicked" from="Shelves/RitualBook/Sprite2D/Selectable" to="." method="_on_ritual_book_clicked"] diff --git a/project.godot b/project.godot index 35717dc..e963e1d 100644 --- a/project.godot +++ b/project.godot @@ -34,6 +34,7 @@ patience_bar="" 2d_physics/layer_3="Body" 2d_physics/layer_4="Pliers" 2d_physics/layer_9="Selectable" +2d_physics/layer_10="Incantation" [rendering] diff --git a/prototype_ritual_book.tscn b/prototype_ritual_book.tscn new file mode 100644 index 0000000..98e0446 --- /dev/null +++ b/prototype_ritual_book.tscn @@ -0,0 +1,57 @@ +[gd_scene load_steps=8 format=3 uid="uid://qkwh186nbcya"] + +[ext_resource type="Script" uid="uid://dak6uc4v3us7w" path="res://incantation.gd" id="1_v6csu"] + +[sub_resource type="Gradient" id="Gradient_2cqfq"] +offsets = PackedFloat32Array(0.80212, 0.978799, 1) +colors = PackedColorArray(0.74902, 0.647059, 0.541176, 1, 0.43, 0.371807, 0.3096, 1, 0.19, 0.164287, 0.1368, 1) + +[sub_resource type="GradientTexture2D" id="GradientTexture2D_yaehf"] +gradient = SubResource("Gradient_2cqfq") +width = 300 +height = 400 + +[sub_resource type="Curve2D" id="Curve2D_5ntyk"] +_data = { +"points": PackedVector2Array(0, 0, 0, 0, 202, 149, -40.482, 1.54217, 40.482, -1.54217, 248, 178, -17.3494, 5.01206, 17.3494, -5.01206, 309, 150, -10.7952, -15.0362, 10.7952, 15.0362, 380, 180, 0, 0, 0, 0, 380, 180, 32.7712, -32.7712, -32.7712, 32.7712, 379, 257, 30.385, 3.70613, -30.385, -3.70613, 305, 219, 0, 0, -49.7351, 23.1326, 255, 252, 27.3736, -12.3374, -27.3736, 12.3374, 198, 230, -28.5302, -24.6748, 28.5302, 24.6748, 202, 319, 0, 0, 0, 0, 377, 318) +} +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 + +[node name="PrototypeRitualBook" type="Node2D"] + +[node name="Left" type="Sprite2D" parent="."] +position = Vector2(306, 311) +texture = SubResource("GradientTexture2D_yaehf") + +[node name="Right" type="Sprite2D" parent="."] +position = Vector2(606, 311) +rotation = 3.14159 +texture = SubResource("GradientTexture2D_yaehf") + +[node name="Incantation" type="Path2D" parent="."] +position = Vector2(-1, 1) +curve = SubResource("Curve2D_5ntyk") +script = ExtResource("1_v6csu") + +[node name="PathFollow2D" type="Node2D" 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"] +shape = SubResource("CircleShape2D_v6csu") + +[node name="Sprite2D" type="Sprite2D" parent="Incantation/PathFollow2D"] +texture = SubResource("GradientTexture2D_5ntyk") diff --git a/ritual_book.gd b/ritual_book.gd new file mode 100644 index 0000000..50016d8 --- /dev/null +++ b/ritual_book.gd @@ -0,0 +1,2 @@ +class_name RitualBook +extends Node2D diff --git a/ritual_book.gd.uid b/ritual_book.gd.uid new file mode 100644 index 0000000..b8e3525 --- /dev/null +++ b/ritual_book.gd.uid @@ -0,0 +1 @@ +uid://ctpgjvo5g0sav diff --git a/selectable.gd b/selectable.gd index b3a1124..83b42e9 100644 --- a/selectable.gd +++ b/selectable.gd @@ -23,7 +23,7 @@ func _ready(): func _input(event): if is_clickable and event is InputEventMouseButton and event.is_pressed(): - clicked.emit() + clicked.emit() func _on_mouse_entered(): is_clickable = true diff --git a/test.gd b/test.gd new file mode 100644 index 0000000..7e35a97 --- /dev/null +++ b/test.gd @@ -0,0 +1,6 @@ +extends Label + + + +func _draw(): + (get_parent() as Path2D).curve.sample_baked_with_rotation() diff --git a/test.gd.uid b/test.gd.uid new file mode 100644 index 0000000..adad1c0 --- /dev/null +++ b/test.gd.uid @@ -0,0 +1 @@ +uid://cpscp5a5nxfop