From 426646f4e0cf501ffb7c8351bfec1b6695e3db85 Mon Sep 17 00:00:00 2001 From: Ervan Lefevre Date: Sun, 1 Oct 2023 10:21:31 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=85:=20Adds=20a=20UI=20to=20show=20lev?= =?UTF-8?q?el=20messages?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nodes/triggers/level_trigger.gd | 6 +- nodes/ui/ui.gd | 8 +++ nodes/ui/ui.tscn | 104 ++++++++++++++++++++++++++++++++ scenes/poc.tscn | 21 +++++-- 4 files changed, 130 insertions(+), 9 deletions(-) create mode 100644 nodes/ui/ui.gd create mode 100644 nodes/ui/ui.tscn diff --git a/nodes/triggers/level_trigger.gd b/nodes/triggers/level_trigger.gd index 84615ec..ac5ba7c 100644 --- a/nodes/triggers/level_trigger.gd +++ b/nodes/triggers/level_trigger.gd @@ -4,6 +4,7 @@ extends Area2D @export var LEVEL_MESSAGE : String = '' @export var ENABLED_NODES : Array[Node] = [] @export var DISABLED_NODES : Array[Node] = [] +@export var UI : Node # Called when the node enters the scene tree for the first time. func _ready(): @@ -18,9 +19,8 @@ func on_body_entered(body): if body.is_in_group("npc"): body.queue_free() if LEVEL_MESSAGE: - # TODO - print(LEVEL_MESSAGE) - pass + if UI: + UI.show_message(LEVEL_MESSAGE) for node in ENABLED_NODES: node.set_physics_process(true) for node in DISABLED_NODES: diff --git a/nodes/ui/ui.gd b/nodes/ui/ui.gd new file mode 100644 index 0000000..3e1c195 --- /dev/null +++ b/nodes/ui/ui.gd @@ -0,0 +1,8 @@ +extends CanvasLayer + +@onready var animator = $animator +@onready var title = $panel/title + +func show_message(message): + title.text = message + animator.play('splash') diff --git a/nodes/ui/ui.tscn b/nodes/ui/ui.tscn new file mode 100644 index 0000000..2e959f5 --- /dev/null +++ b/nodes/ui/ui.tscn @@ -0,0 +1,104 @@ +[gd_scene load_steps=6 format=3 uid="uid://7flwkthps8ty"] + +[ext_resource type="Script" path="res://nodes/ui/ui.gd" id="1_1svns"] + +[sub_resource type="Animation" id="Animation_6cer2"] +resource_name = "splash" +length = 6.0 +tracks/0/type = "value" +tracks/0/imported = false +tracks/0/enabled = true +tracks/0/path = NodePath("panel:modulate") +tracks/0/interp = 1 +tracks/0/loop_wrap = true +tracks/0/keys = { +"times": PackedFloat32Array(0, 2, 4, 6), +"transitions": PackedFloat32Array(1, 1, 1, 1), +"update": 0, +"values": [Color(1, 1, 1, 0), Color(1, 1, 1, 1), Color(1, 1, 1, 1), Color(1, 1, 1, 0)] +} +tracks/1/type = "value" +tracks/1/imported = false +tracks/1/enabled = true +tracks/1/path = NodePath("panel:visible") +tracks/1/interp = 1 +tracks/1/loop_wrap = true +tracks/1/keys = { +"times": PackedFloat32Array(0, 6), +"transitions": PackedFloat32Array(1, 1), +"update": 1, +"values": [true, false] +} + +[sub_resource type="Animation" id="Animation_4v8h2"] +length = 0.001 +tracks/0/type = "value" +tracks/0/imported = false +tracks/0/enabled = true +tracks/0/path = NodePath("panel:modulate") +tracks/0/interp = 1 +tracks/0/loop_wrap = true +tracks/0/keys = { +"times": PackedFloat32Array(0), +"transitions": PackedFloat32Array(1), +"update": 0, +"values": [Color(1, 1, 1, 1)] +} +tracks/1/type = "value" +tracks/1/imported = false +tracks/1/enabled = true +tracks/1/path = NodePath("panel:visible") +tracks/1/interp = 1 +tracks/1/loop_wrap = true +tracks/1/keys = { +"times": PackedFloat32Array(0), +"transitions": PackedFloat32Array(1), +"update": 1, +"values": [true] +} + +[sub_resource type="Animation" id="Animation_d41ii"] +resource_name = "hide" +tracks/0/type = "value" +tracks/0/imported = false +tracks/0/enabled = true +tracks/0/path = NodePath("panel:visible") +tracks/0/interp = 1 +tracks/0/loop_wrap = true +tracks/0/keys = { +"times": PackedFloat32Array(0), +"transitions": PackedFloat32Array(1), +"update": 1, +"values": [false] +} + +[sub_resource type="AnimationLibrary" id="AnimationLibrary_iii80"] +_data = { +"RESET": SubResource("Animation_4v8h2"), +"hide": SubResource("Animation_d41ii"), +"splash": SubResource("Animation_6cer2") +} + +[node name="ui" type="CanvasLayer"] +script = ExtResource("1_1svns") + +[node name="animator" type="AnimationPlayer" parent="."] +autoplay = "hide" +libraries = { +"": SubResource("AnimationLibrary_iii80") +} + +[node name="panel" type="Panel" parent="."] +offset_left = 64.0 +offset_top = 64.0 +offset_right = 1856.0 +offset_bottom = 264.0 + +[node name="title" type="Label" parent="panel"] +layout_mode = 0 +offset_right = 448.0 +offset_bottom = 48.0 +scale = Vector2(4, 4) +text = "Level 3 - Spider-Ant, Spider-ant ! " +horizontal_alignment = 1 +vertical_alignment = 1 diff --git a/scenes/poc.tscn b/scenes/poc.tscn index 18a7338..8a51a48 100644 --- a/scenes/poc.tscn +++ b/scenes/poc.tscn @@ -1,5 +1,6 @@ -[gd_scene load_steps=23 format=3 uid="uid://ce8ov6npvl27w"] +[gd_scene load_steps=24 format=3 uid="uid://ce8ov6npvl27w"] +[ext_resource type="PackedScene" uid="uid://7flwkthps8ty" path="res://nodes/ui/ui.tscn" id="1_3abey"] [ext_resource type="Texture2D" uid="uid://cfq8pma4bpgq" path="res://assets/tilesets/cave_tileset.png" id="1_vofrt"] [ext_resource type="PackedScene" uid="uid://c5rmt3jeffjx7" path="res://nodes/player/player.tscn" id="2_gxv3v"] [ext_resource type="Texture2D" uid="uid://ccqiabs4p3ryl" path="res://assets/placeholders/map.png" id="3_aeud1"] @@ -232,6 +233,8 @@ radius = 48.6621 [node name="root" type="Node2D"] +[node name="ui" parent="." instance=ExtResource("1_3abey")] + [node name="WIP" type="Sprite2D" parent="."] self_modulate = Color(1, 1, 1, 0.329412) position = Vector2(1757.35, 448) @@ -266,44 +269,50 @@ texture = ExtResource("5_8geoi") [node name="triggers" type="Node2D" parent="."] -[node name="level_1" parent="triggers" node_paths=PackedStringArray("ENABLED_NODES") instance=ExtResource("5_7efj6")] +[node name="level_1" parent="triggers" node_paths=PackedStringArray("ENABLED_NODES", "UI") instance=ExtResource("5_7efj6")] position = Vector2(1184, 1968) LEVEL_MESSAGE = "Level 1 - Crawler" ENABLED_NODES = [NodePath("../../npcs/npc_factory"), NodePath("../../npcs/npc_factory2"), NodePath("../../npcs/npc_factory3"), NodePath("../../npcs/npc_factory4"), NodePath("../../npcs/npc_factory5"), NodePath("../../npcs/npc_factory6"), NodePath("../../npcs/npc_factory7")] +UI = NodePath("../../ui") [node name="shape" type="CollisionShape2D" parent="triggers/level_1"] shape = SubResource("RectangleShape2D_vlkgl") -[node name="level_2" parent="triggers" node_paths=PackedStringArray("ENABLED_NODES") instance=ExtResource("5_7efj6")] +[node name="level_2" parent="triggers" node_paths=PackedStringArray("ENABLED_NODES", "UI") instance=ExtResource("5_7efj6")] position = Vector2(1480, 1584) LEVEL_MESSAGE = "Level 2 - Glide of Faith" ENABLED_NODES = [NodePath("../../npcs/npc_factory8"), NodePath("../../npcs/npc_factory9"), NodePath("../../npcs/npc_factory9")] +UI = NodePath("../../ui") [node name="shape" type="CollisionShape2D" parent="triggers/level_2"] shape = SubResource("RectangleShape2D_vlkgl") -[node name="level_3" parent="triggers" node_paths=PackedStringArray("ENABLED_NODES") instance=ExtResource("5_7efj6")] +[node name="level_3" parent="triggers" node_paths=PackedStringArray("ENABLED_NODES", "UI") instance=ExtResource("5_7efj6")] position = Vector2(2880, 656) LEVEL_MESSAGE = "Level 3 - Spider-Ant, Spider-Ant" ENABLED_NODES = [NodePath("../../npcs/npc_factory12"), NodePath("../../npcs/npc_factory13"), NodePath("../../npcs/npc_factory14")] +UI = NodePath("../../ui") [node name="shape" type="CollisionShape2D" parent="triggers/level_3"] position = Vector2(7, 0) shape = SubResource("RectangleShape2D_vlkgl") -[node name="level_4" parent="triggers" node_paths=PackedStringArray("ENABLED_NODES") instance=ExtResource("5_7efj6")] +[node name="level_4" parent="triggers" node_paths=PackedStringArray("ENABLED_NODES", "UI") instance=ExtResource("5_7efj6")] position = Vector2(2016, -48) LEVEL_MESSAGE = "Level 4 - The Queen of Them All" ENABLED_NODES = [NodePath("../../npcs/npc_factory15"), NodePath("../../npcs/npc_factory16")] +UI = NodePath("../../ui") [node name="shape" type="CollisionShape2D" parent="triggers/level_4"] position = Vector2(8, 0) shape = SubResource("RectangleShape2D_vlkgl") -[node name="level_5" parent="triggers" node_paths=PackedStringArray("DISABLED_NODES") instance=ExtResource("5_7efj6")] +[node name="level_5" parent="triggers" node_paths=PackedStringArray("DISABLED_NODES", "UI") instance=ExtResource("5_7efj6")] position = Vector2(2624, -464) KILL_ALL_NPCS = true +LEVEL_MESSAGE = "Last Level - What are you running from ?" DISABLED_NODES = [NodePath("../../npcs/npc_factory15"), NodePath("../../npcs/npc_factory16")] +UI = NodePath("../../ui") [node name="shape" type="CollisionShape2D" parent="triggers/level_5"] position = Vector2(8, 0)