diff --git a/.gitignore b/.gitignore index 95d8133..117080c 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,5 @@ export_presets.cfg -tests/assets/ \ No newline at end of file +tests/assets/ +conception/ \ No newline at end of file diff --git a/entities/npcs/vrac7/vrac7.gd b/entities/npcs/vrac7/vrac7.gd index e69de29..afc6495 100644 --- a/entities/npcs/vrac7/vrac7.gd +++ b/entities/npcs/vrac7/vrac7.gd @@ -0,0 +1,31 @@ +extends Area2D + +class_name Vrac7 + +@export var prompt_text : String = "[E] Parler" + +# Dialogue initial — avant réparation +const DIALOGUE_INTRO := [ + { "name": "VRAC-7", "text": "Toi... tu es nouveau ? Non, attends — SCRAP-09 ? Tu as dormi longtemps. Très longtemps." }, + { "name": "VRAC-7", "text": "Je suis coincé sous cette étagère depuis... je ne sais plus. Tu peux m'aider ?" }, + { "name": "VRAC-7", "text": "Il me faut 1 engrenage et 1 câble. J'en ai vu par là dans l'entrepôt." }, +] + +# Dialogue après réparation +const DIALOGUE_REPAIRED := [ + { "name": "VRAC-7", "text": "Je me souviens du dernier jour. Ils ont éteint les lumières en partant." }, + { "name": "VRAC-7", "text": "Mais ils ont laissé les générateurs allumés. Je crois que c'était intentionnel." }, + { "name": "VRAC-7", "text": "L'atelier est par là. Prends la clé — tu en auras besoin." }, +] + +func interact() -> void: + var hud : HUD = get_tree().get_first_node_in_group("hud") + if hud: + hud.hide_prompt() + var dialogue_box : DialogueBox = get_tree().get_first_node_in_group("dialogue_box") + if not dialogue_box: + return + if GameState.repaired.get("vrac7", false): + dialogue_box.start(DIALOGUE_REPAIRED) + else: + dialogue_box.start(DIALOGUE_INTRO) diff --git a/entities/npcs/vrac7/vrac7.tscn b/entities/npcs/vrac7/vrac7.tscn index ffd33ac..295aaa8 100644 --- a/entities/npcs/vrac7/vrac7.tscn +++ b/entities/npcs/vrac7/vrac7.tscn @@ -1,3 +1,30 @@ [gd_scene format=3 uid="uid://bb3olg2rlygdc"] +[ext_resource type="Script" uid="uid://bs7rvg7tfjm34" path="res://entities/npcs/vrac7/vrac7.gd" id="1_vwl5e"] + +[sub_resource type="CapsuleShape2D" id="CapsuleShape2D_vwl5e"] + +[sub_resource type="SpriteFrames" id="SpriteFrames_vwl5e"] + +[sub_resource type="RectangleShape2D" id="RectangleShape2D_xy6tt"] +size = Vector2(58, 37) + [node name="Vrac7" type="Node2D" unique_id=829712169] + +[node name="Vrac7" type="Area2D" parent="." unique_id=1007989436] +collision_layer = 4 +collision_mask = 0 +script = ExtResource("1_vwl5e") + +[node name="CollisionShape2D" type="CollisionShape2D" parent="Vrac7" unique_id=611475091] +position = Vector2(0, 1) +shape = SubResource("CapsuleShape2D_vwl5e") + +[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="Vrac7" unique_id=1428714736] +sprite_frames = SubResource("SpriteFrames_vwl5e") + +[node name="InteractionZone" type="Area2D" parent="Vrac7" unique_id=1655089634] + +[node name="CollisionShape2D" type="CollisionShape2D" parent="Vrac7/InteractionZone" unique_id=1264953620] +position = Vector2(0, 1) +shape = SubResource("RectangleShape2D_xy6tt") diff --git a/tests/main.tscn b/tests/main.tscn index 4be37e2..081f392 100644 --- a/tests/main.tscn +++ b/tests/main.tscn @@ -6,6 +6,8 @@ [ext_resource type="PackedScene" uid="uid://grs5ypwkxv3x" path="res://entities/items/item.tscn" id="4_gn22r"] [ext_resource type="PackedScene" uid="uid://o7qrmpywwhu8" path="res://ui/hud.tscn" id="5_cb43m"] [ext_resource type="PackedScene" uid="uid://d5r0so1s8rf8" path="res://levels/repair_zone.tscn" id="6_y6b0w"] +[ext_resource type="PackedScene" uid="uid://bb3olg2rlygdc" path="res://entities/npcs/vrac7/vrac7.tscn" id="7_pskfe"] +[ext_resource type="PackedScene" uid="uid://jrjxu1xfx0ud" path="res://ui/dialogue_box.tscn" id="8_rdsdc"] [sub_resource type="TileSetAtlasSource" id="TileSetAtlasSource_gn22r"] texture = ExtResource("2_pi5dy") @@ -172,3 +174,9 @@ position = Vector2(98, 108) [node name="RepairZone" parent="Node2D" unique_id=2043534964 groups=["repair_zones"] instance=ExtResource("6_y6b0w")] position = Vector2(224, 145) + +[node name="Vrac7" parent="Node2D" unique_id=829712169 instance=ExtResource("7_pskfe")] +position = Vector2(63, 114) + +[node name="DialogueBox" parent="Node2D" unique_id=1374394268 instance=ExtResource("8_rdsdc")] +position = Vector2(83, 63) diff --git a/tests/main_test.gd b/tests/main_test.gd index 3140601..07413d3 100644 --- a/tests/main_test.gd +++ b/tests/main_test.gd @@ -1,11 +1,13 @@ extends Node2D func _ready() -> void: + print(get_tree().get_nodes_in_group("dialogue_box")) await get_tree().process_frame for zone in get_tree().get_nodes_in_group("repair_zones"): if zone is RepairZone: zone.repair_requested.connect(_on_repair_requested) + func _on_repair_requested(npc_id: String) -> void: # Test de trigger GameState.complete_repair(npc_id) diff --git a/ui/dialogue_box.gd b/ui/dialogue_box.gd new file mode 100644 index 0000000..9d2bb95 --- /dev/null +++ b/ui/dialogue_box.gd @@ -0,0 +1,66 @@ +class_name DialogueBox +extends CanvasLayer + +signal dialogue_finished + +@onready var speaker_name : Label = $SpeakerName +@onready var dialogue_text : RichTextLabel = $Panel/DialogueText +@onready var continue_hint : Label = $Panel/ContinueHint + +const TYPEWRITER_SPEED := 0.03 # secondes par caractère + +var _lines : Array = [] +var _index : int = 0 +var _typing : bool = false +var _finished : bool = false + +func _ready() -> void: + add_to_group("dialogue_box") + process_mode = Node.PROCESS_MODE_ALWAYS + hide() + +func start(lines: Array) -> void: + _lines = lines + _index = 0 + show() + get_tree().paused = true + _show_line() + +func _show_line() -> void: + if _index >= _lines.size(): + _finish() + return + var line : Dictionary = _lines[_index] + speaker_name.text = line.get("name", "") + dialogue_text.text = "" + _typing = true + _typewrite(line.get("text", "")) + +func _typewrite(text: String) -> void: + continue_hint.visible = false + dialogue_text.text = "" + for i in text.length(): + if not _typing: + dialogue_text.text = text + continue_hint.visible = true + return + dialogue_text.text += text[i] + await get_tree().create_timer(TYPEWRITER_SPEED).timeout + _typing = false + continue_hint.visible = true + +func _unhandled_input(event: InputEvent) -> void: + if not visible: + return + if event.is_action_pressed("interact"): + get_viewport().set_input_as_handled() + if _typing: + _typing = false + else: + _index += 1 + _show_line() + +func _finish() -> void: + get_tree().paused = false + hide() + dialogue_finished.emit() diff --git a/ui/dialogue_box.gd.uid b/ui/dialogue_box.gd.uid new file mode 100644 index 0000000..f891f94 --- /dev/null +++ b/ui/dialogue_box.gd.uid @@ -0,0 +1 @@ +uid://clc8675h6pkw5 diff --git a/ui/dialogue_box.tscn b/ui/dialogue_box.tscn index 1a914e6..b157c12 100644 --- a/ui/dialogue_box.tscn +++ b/ui/dialogue_box.tscn @@ -1,3 +1,57 @@ [gd_scene format=3 uid="uid://jrjxu1xfx0ud"] +[ext_resource type="Script" uid="uid://clc8675h6pkw5" path="res://ui/dialogue_box.gd" id="1_2ix3t"] + +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_2ix3t"] +bg_color = Color(0.101960786, 0.101960786, 0.101960786, 0.91764706) +border_width_left = 1 +border_width_top = 1 +border_width_right = 1 +border_width_bottom = 1 +border_color = Color(0.53333336, 0.53333336, 0.53333336, 1) + [node name="DialogueBox" type="Node2D" unique_id=1374394268] + +[node name="DialogueBox" type="CanvasLayer" parent="." unique_id=1732454601 groups=["dialogue_box"]] +script = ExtResource("1_2ix3t") + +[node name="SpeakerName" type="Label" parent="DialogueBox" unique_id=753234837] +anchors_preset = 12 +anchor_top = 1.0 +anchor_right = 1.0 +anchor_bottom = 1.0 +offset_left = 5.0 +offset_top = -38.0 +offset_right = 5.0 +offset_bottom = -15.0 +grow_horizontal = 2 +grow_vertical = 0 +theme_override_font_sizes/font_size = 8 + +[node name="Panel" type="PanelContainer" parent="DialogueBox" unique_id=1877086041] +anchors_preset = 12 +anchor_top = 1.0 +anchor_right = 1.0 +anchor_bottom = 1.0 +offset_top = -25.0 +grow_horizontal = 2 +grow_vertical = 0 +theme_override_styles/panel = SubResource("StyleBoxFlat_2ix3t") + +[node name="DialogueText" type="RichTextLabel" parent="DialogueBox/Panel" unique_id=1423166174] +layout_mode = 2 +theme_override_font_sizes/normal_font_size = 6 +theme_override_font_sizes/bold_font_size = 6 +theme_override_font_sizes/bold_italics_font_size = 6 +theme_override_font_sizes/italics_font_size = 6 +theme_override_font_sizes/mono_font_size = 6 +bbcode_enabled = true +fit_content = true + +[node name="ContinueHint" type="Label" parent="DialogueBox/Panel" unique_id=313929021] +visible = false +layout_mode = 2 +theme_override_font_sizes/font_size = 6 +text = "▼" +horizontal_alignment = 2 +vertical_alignment = 2