From 17142e2a5b86656f513547a6010559937c2f3400 Mon Sep 17 00:00:00 2001 From: Florian Date: Wed, 17 Sep 2025 16:41:29 +0200 Subject: [PATCH] Made the item display work (incl. cooldown) --- buildings/Building 1x2 fixed.png.import | 6 ++++++ buildings/Building 2x1 downside.png.import | 6 ++++++ buildings/Building 2x1 fixed.png.import | 6 ++++++ item_ui/cooldown.gdshader | 22 ++++++++++++++++++++++ item_ui/cooldown.gdshader.uid | 1 + item_ui/item_ui.gd | 8 +++++++- item_ui/item_ui.tscn | 11 ++++++++++- items/active_item.gd | 1 + items/bow.gd | 6 +++++- items/bow.tscn | 1 + items/updash.gd | 6 +++++- items/updash.tscn | 2 +- player/Player_Walk/Walk 1.png.import | 6 ++++++ player/Player_Walk/Walk 2.png.import | 6 ++++++ player/Player_Walk/Walk 3.png.import | 6 ++++++ player/Player_Walk/Walk 4.png.import | 6 ++++++ player/Player_Walk/Walk 5.png.import | 6 ++++++ player/Player_Walk/Walk 6.png.import | 6 ++++++ player/player.gd | 10 ++++++++-- project.godot | 2 +- 20 files changed, 116 insertions(+), 8 deletions(-) create mode 100644 item_ui/cooldown.gdshader create mode 100644 item_ui/cooldown.gdshader.uid diff --git a/buildings/Building 1x2 fixed.png.import b/buildings/Building 1x2 fixed.png.import index 0ac93ca..39a81c9 100644 --- a/buildings/Building 1x2 fixed.png.import +++ b/buildings/Building 1x2 fixed.png.import @@ -18,6 +18,8 @@ dest_files=["res://.godot/imported/Building 1x2 fixed.png-e90afc0d25a8919ada5700 compress/mode=0 compress/high_quality=false compress/lossy_quality=0.7 +compress/uastc_level=0 +compress/rdo_quality_loss=0.0 compress/hdr_compression=1 compress/normal_map=0 compress/channel_pack=0 @@ -25,6 +27,10 @@ mipmaps/generate=false mipmaps/limit=-1 roughness/mode=0 roughness/src_normal="" +process/channel_remap/red=0 +process/channel_remap/green=1 +process/channel_remap/blue=2 +process/channel_remap/alpha=3 process/fix_alpha_border=true process/premult_alpha=false process/normal_map_invert_y=false diff --git a/buildings/Building 2x1 downside.png.import b/buildings/Building 2x1 downside.png.import index 52d9ce5..0e57d53 100644 --- a/buildings/Building 2x1 downside.png.import +++ b/buildings/Building 2x1 downside.png.import @@ -18,6 +18,8 @@ dest_files=["res://.godot/imported/Building 2x1 downside.png-4b432eb4152bab7dd59 compress/mode=0 compress/high_quality=false compress/lossy_quality=0.7 +compress/uastc_level=0 +compress/rdo_quality_loss=0.0 compress/hdr_compression=1 compress/normal_map=0 compress/channel_pack=0 @@ -25,6 +27,10 @@ mipmaps/generate=false mipmaps/limit=-1 roughness/mode=0 roughness/src_normal="" +process/channel_remap/red=0 +process/channel_remap/green=1 +process/channel_remap/blue=2 +process/channel_remap/alpha=3 process/fix_alpha_border=true process/premult_alpha=false process/normal_map_invert_y=false diff --git a/buildings/Building 2x1 fixed.png.import b/buildings/Building 2x1 fixed.png.import index a78eae3..e7fdbe6 100644 --- a/buildings/Building 2x1 fixed.png.import +++ b/buildings/Building 2x1 fixed.png.import @@ -18,6 +18,8 @@ dest_files=["res://.godot/imported/Building 2x1 fixed.png-b02748fa52aebae62f987c compress/mode=0 compress/high_quality=false compress/lossy_quality=0.7 +compress/uastc_level=0 +compress/rdo_quality_loss=0.0 compress/hdr_compression=1 compress/normal_map=0 compress/channel_pack=0 @@ -25,6 +27,10 @@ mipmaps/generate=false mipmaps/limit=-1 roughness/mode=0 roughness/src_normal="" +process/channel_remap/red=0 +process/channel_remap/green=1 +process/channel_remap/blue=2 +process/channel_remap/alpha=3 process/fix_alpha_border=true process/premult_alpha=false process/normal_map_invert_y=false diff --git a/item_ui/cooldown.gdshader b/item_ui/cooldown.gdshader new file mode 100644 index 0000000..f47f260 --- /dev/null +++ b/item_ui/cooldown.gdshader @@ -0,0 +1,22 @@ +shader_type canvas_item; + +uniform float percentage; + +void vertex() { + // Called for every vertex the material is visible on. +} + +void fragment() { + vec2 coord = UV - .5; + float angle = atan(coord.x, coord.y); + + float draw = float(angle + PI > percentage * TAU); + COLOR *= 1. - draw; + + //COLOR = vec4(angle); +} + +//void light() { +// // Called for every pixel for every light affecting the CanvasItem. +// // Uncomment to replace the default light processing function with this one. +//} diff --git a/item_ui/cooldown.gdshader.uid b/item_ui/cooldown.gdshader.uid new file mode 100644 index 0000000..be62bf2 --- /dev/null +++ b/item_ui/cooldown.gdshader.uid @@ -0,0 +1 @@ +uid://d0a7tk6dh1xq1 diff --git a/item_ui/item_ui.gd b/item_ui/item_ui.gd index 8ad93f1..edc693a 100644 --- a/item_ui/item_ui.gd +++ b/item_ui/item_ui.gd @@ -1,9 +1,15 @@ extends MarginContainer @export var player : Player; +@onready var timer : Timer = player.get_node("ActiveItemCooldown") func _on_player_active_item_changed(newitem: ActiveItem) -> void: %ItemTexture.texture = newitem.sprite func _process(_delta: float) -> void: - player + # visible = timer.time_left != 0; + if not visible: return; + + var percentage = timer.time_left / timer.wait_time; + $CooldownOverlay.material.set_shader_parameter("percentage", percentage); + diff --git a/item_ui/item_ui.tscn b/item_ui/item_ui.tscn index 5676bf2..2fa82b3 100644 --- a/item_ui/item_ui.tscn +++ b/item_ui/item_ui.tscn @@ -1,6 +1,7 @@ -[gd_scene load_steps=3 format=3 uid="uid://73g8y37skebh"] +[gd_scene load_steps=5 format=3 uid="uid://73g8y37skebh"] [ext_resource type="Script" uid="uid://eusti457vwq1" path="res://item_ui/item_ui.gd" id="1_lfuq2"] +[ext_resource type="Shader" uid="uid://d0a7tk6dh1xq1" path="res://item_ui/cooldown.gdshader" id="2_60pal"] [sub_resource type="StyleBoxFlat" id="StyleBoxFlat_8oq0s"] draw_center = false @@ -15,6 +16,10 @@ corner_radius_top_right = 50 corner_radius_bottom_right = 50 corner_radius_bottom_left = 50 +[sub_resource type="ShaderMaterial" id="ShaderMaterial_de2rv"] +shader = ExtResource("2_60pal") +shader_parameter/percentage = 1.01 + [node name="ItemUI" type="MarginContainer"] anchors_preset = 1 anchor_left = 1.0 @@ -36,3 +41,7 @@ theme_override_styles/panel = SubResource("StyleBoxFlat_8oq0s") unique_name_in_owner = true layout_mode = 2 expand_mode = 1 + +[node name="CooldownOverlay" type="Panel" parent="."] +material = SubResource("ShaderMaterial_de2rv") +layout_mode = 2 diff --git a/items/active_item.gd b/items/active_item.gd index d110c4b..746b915 100644 --- a/items/active_item.gd +++ b/items/active_item.gd @@ -5,6 +5,7 @@ class_name ActiveItem extends Item func collect() -> bool: if (player.active_item == null): player.active_item = self + return true return false diff --git a/items/bow.gd b/items/bow.gd index d94bab1..0affe74 100644 --- a/items/bow.gd +++ b/items/bow.gd @@ -2,9 +2,13 @@ extends ActiveItem @export var cooldown = 1 @export var arrow_scene : PackedScene +func collect(): + player.set_cooldown(cooldown) + return super.collect() + func activate(): - player.item_cooldown = cooldown + player.activate_cooldown() var arrow : Area2D = arrow_scene.instantiate() get_tree().get_root().add_child(arrow) arrow.position = player.position diff --git a/items/bow.tscn b/items/bow.tscn index 76a26e3..4f9ac19 100644 --- a/items/bow.tscn +++ b/items/bow.tscn @@ -11,6 +11,7 @@ collision_layer = 0 collision_mask = 4 script = ExtResource("1_xppub") arrow_scene = ExtResource("2_0id2q") +sprite = ExtResource("2_gllxn") [node name="CollisionShape2D" type="CollisionShape2D" parent="."] scale = Vector2(3.1, 3.1) diff --git a/items/updash.gd b/items/updash.gd index 09b04b7..ac8989a 100644 --- a/items/updash.gd +++ b/items/updash.gd @@ -1,9 +1,13 @@ extends ActiveItem var cooldown = 10 +func collect(): + player.set_cooldown(cooldown) + return super.collect() + func activate(): - player.item_cooldown = cooldown + player.activate_cooldown() player.reset_to_velocity = Vector2(0,1) await get_tree().create_timer(0.1).timeout player.reset_to_velocity = Vector2(0, -2400) diff --git a/items/updash.tscn b/items/updash.tscn index dd04581..e2026f0 100644 --- a/items/updash.tscn +++ b/items/updash.tscn @@ -1,6 +1,6 @@ [gd_scene load_steps=4 format=3 uid="uid://ewe36lqcjojk"] -[ext_resource type="Script" path="res://items/updash.gd" id="1_ghbl6"] +[ext_resource type="Script" uid="uid://bbwsc2a2hd0ow" path="res://items/updash.gd" id="1_ghbl6"] [ext_resource type="Texture2D" uid="uid://cy70quh6k3s1j" path="res://icon.svg" id="1_ptc3l"] [sub_resource type="CircleShape2D" id="CircleShape2D_ghbl6"] diff --git a/player/Player_Walk/Walk 1.png.import b/player/Player_Walk/Walk 1.png.import index 97cf918..7803358 100644 --- a/player/Player_Walk/Walk 1.png.import +++ b/player/Player_Walk/Walk 1.png.import @@ -18,6 +18,8 @@ dest_files=["res://.godot/imported/Walk 1.png-47c623e9d3540b4a00d2bddf52ae0b2a.c compress/mode=0 compress/high_quality=false compress/lossy_quality=0.7 +compress/uastc_level=0 +compress/rdo_quality_loss=0.0 compress/hdr_compression=1 compress/normal_map=0 compress/channel_pack=0 @@ -25,6 +27,10 @@ mipmaps/generate=false mipmaps/limit=-1 roughness/mode=0 roughness/src_normal="" +process/channel_remap/red=0 +process/channel_remap/green=1 +process/channel_remap/blue=2 +process/channel_remap/alpha=3 process/fix_alpha_border=true process/premult_alpha=false process/normal_map_invert_y=false diff --git a/player/Player_Walk/Walk 2.png.import b/player/Player_Walk/Walk 2.png.import index 48f18ef..3fac54f 100644 --- a/player/Player_Walk/Walk 2.png.import +++ b/player/Player_Walk/Walk 2.png.import @@ -18,6 +18,8 @@ dest_files=["res://.godot/imported/Walk 2.png-5dea4fdec55fa43e26680e08090fd654.c compress/mode=0 compress/high_quality=false compress/lossy_quality=0.7 +compress/uastc_level=0 +compress/rdo_quality_loss=0.0 compress/hdr_compression=1 compress/normal_map=0 compress/channel_pack=0 @@ -25,6 +27,10 @@ mipmaps/generate=false mipmaps/limit=-1 roughness/mode=0 roughness/src_normal="" +process/channel_remap/red=0 +process/channel_remap/green=1 +process/channel_remap/blue=2 +process/channel_remap/alpha=3 process/fix_alpha_border=true process/premult_alpha=false process/normal_map_invert_y=false diff --git a/player/Player_Walk/Walk 3.png.import b/player/Player_Walk/Walk 3.png.import index 285ace3..c65053d 100644 --- a/player/Player_Walk/Walk 3.png.import +++ b/player/Player_Walk/Walk 3.png.import @@ -18,6 +18,8 @@ dest_files=["res://.godot/imported/Walk 3.png-27890c0cb512383b8ecbd848c73efee1.c compress/mode=0 compress/high_quality=false compress/lossy_quality=0.7 +compress/uastc_level=0 +compress/rdo_quality_loss=0.0 compress/hdr_compression=1 compress/normal_map=0 compress/channel_pack=0 @@ -25,6 +27,10 @@ mipmaps/generate=false mipmaps/limit=-1 roughness/mode=0 roughness/src_normal="" +process/channel_remap/red=0 +process/channel_remap/green=1 +process/channel_remap/blue=2 +process/channel_remap/alpha=3 process/fix_alpha_border=true process/premult_alpha=false process/normal_map_invert_y=false diff --git a/player/Player_Walk/Walk 4.png.import b/player/Player_Walk/Walk 4.png.import index 03aa90d..c12f6b8 100644 --- a/player/Player_Walk/Walk 4.png.import +++ b/player/Player_Walk/Walk 4.png.import @@ -18,6 +18,8 @@ dest_files=["res://.godot/imported/Walk 4.png-232b1eae2acf3ad82130431014262cde.c compress/mode=0 compress/high_quality=false compress/lossy_quality=0.7 +compress/uastc_level=0 +compress/rdo_quality_loss=0.0 compress/hdr_compression=1 compress/normal_map=0 compress/channel_pack=0 @@ -25,6 +27,10 @@ mipmaps/generate=false mipmaps/limit=-1 roughness/mode=0 roughness/src_normal="" +process/channel_remap/red=0 +process/channel_remap/green=1 +process/channel_remap/blue=2 +process/channel_remap/alpha=3 process/fix_alpha_border=true process/premult_alpha=false process/normal_map_invert_y=false diff --git a/player/Player_Walk/Walk 5.png.import b/player/Player_Walk/Walk 5.png.import index fe3ebef..47122be 100644 --- a/player/Player_Walk/Walk 5.png.import +++ b/player/Player_Walk/Walk 5.png.import @@ -18,6 +18,8 @@ dest_files=["res://.godot/imported/Walk 5.png-cfb8eb15ace876127c083283fe74cdc0.c compress/mode=0 compress/high_quality=false compress/lossy_quality=0.7 +compress/uastc_level=0 +compress/rdo_quality_loss=0.0 compress/hdr_compression=1 compress/normal_map=0 compress/channel_pack=0 @@ -25,6 +27,10 @@ mipmaps/generate=false mipmaps/limit=-1 roughness/mode=0 roughness/src_normal="" +process/channel_remap/red=0 +process/channel_remap/green=1 +process/channel_remap/blue=2 +process/channel_remap/alpha=3 process/fix_alpha_border=true process/premult_alpha=false process/normal_map_invert_y=false diff --git a/player/Player_Walk/Walk 6.png.import b/player/Player_Walk/Walk 6.png.import index 22d7868..5b2bdef 100644 --- a/player/Player_Walk/Walk 6.png.import +++ b/player/Player_Walk/Walk 6.png.import @@ -18,6 +18,8 @@ dest_files=["res://.godot/imported/Walk 6.png-f243f98e182be67eb8681a11d34ee554.c compress/mode=0 compress/high_quality=false compress/lossy_quality=0.7 +compress/uastc_level=0 +compress/rdo_quality_loss=0.0 compress/hdr_compression=1 compress/normal_map=0 compress/channel_pack=0 @@ -25,6 +27,10 @@ mipmaps/generate=false mipmaps/limit=-1 roughness/mode=0 roughness/src_normal="" +process/channel_remap/red=0 +process/channel_remap/green=1 +process/channel_remap/blue=2 +process/channel_remap/alpha=3 process/fix_alpha_border=true process/premult_alpha=false process/normal_map_invert_y=false diff --git a/player/player.gd b/player/player.gd index 0027380..0da9544 100644 --- a/player/player.gd +++ b/player/player.gd @@ -55,6 +55,13 @@ var active_item : ActiveItem = null: active_item_changed.emit(active_item) +func set_cooldown(cooldown): + active_item_cooldown.wait_time = cooldown + +func activate_cooldown(): + active_item_cooldown.start() + + func _ready() -> void: max_hp_changed.emit(max_hp) health_changed.emit(current_hp) @@ -79,8 +86,7 @@ func manage_attack(delta : float): sword.swing() atk_timer = atk_cooldown -func manage_active(delta : float): - # item_cooldown = max(item_cooldown - delta, 0) +func manage_active(_delta : float): if(active_item != null and Input.is_action_just_pressed("item") and active_item_cooldown.is_stopped()): active_item.activate() diff --git a/project.godot b/project.godot index ec9b026..182a0cf 100644 --- a/project.godot +++ b/project.godot @@ -12,7 +12,7 @@ config_version=5 config/name="The Dark Side of Earth" run/main_scene="uid://cxo6bq26huau7" -config/features=PackedStringArray("4.4", "Forward Plus") +config/features=PackedStringArray("4.5", "Forward Plus") config/icon="res://icon.svg" [display]