From e4d04ff599458dc8bc6e90361efadc61e4240c7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=A8=E8=90=BD=E5=9F=BA=E5=9B=B4=E8=99=BE?= <3161880837@qq.com> Date: Sat, 6 Sep 2025 15:04:32 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=8A=80=E8=83=BD=E5=9B=BE=E6=A0=87):=20?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=8A=80=E8=83=BD=E5=86=B7=E5=8D=B4=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 SkillIcon.gd 脚本用于管理武器技能图标显示 - 修改 CooldownProgress.gdshader 增加背景透明度参数 - 更新 CooldownTimer.gd 添加时间计算方法 - 重构 SkillIconBase.tscn 场景以支持新功能 --- components/Abstracts/SkillIconBase.tscn | 10 +++++++--- scripts/Statemachine/CooldownTimer.gd | 4 +++- scripts/Statemachine/SkillIcon.gd | 10 ++++++++++ shaders/CooldownProgress.gdshader | 3 ++- 4 files changed, 22 insertions(+), 5 deletions(-) create mode 100644 scripts/Statemachine/SkillIcon.gd diff --git a/components/Abstracts/SkillIconBase.tscn b/components/Abstracts/SkillIconBase.tscn index c7d86b9..dc5a773 100644 --- a/components/Abstracts/SkillIconBase.tscn +++ b/components/Abstracts/SkillIconBase.tscn @@ -1,6 +1,7 @@ -[gd_scene load_steps=5 format=3 uid="uid://ufl4kek8hrmt"] +[gd_scene load_steps=6 format=3 uid="uid://ufl4kek8hrmt"] [ext_resource type="Shader" path="res://shaders/CooldownProgress.gdshader" id="1_jaivk"] +[ext_resource type="Script" path="res://scripts/Statemachine/SkillIcon.gd" id="1_l7say"] [ext_resource type="Texture2D" uid="uid://cp4ypuarjoshp" path="res://resources/skillIcons/purple-crystal.png" id="2_hh1bl"] [sub_resource type="StyleBoxFlat" id="StyleBoxFlat_a60wd"] @@ -16,15 +17,18 @@ corner_radius_bottom_left = 15 [sub_resource type="ShaderMaterial" id="ShaderMaterial_ew32n"] shader = ExtResource("1_jaivk") -shader_parameter/progress = 0.58 +shader_parameter/progress = 0.25 +shader_parameter/backAlpha = 0.25 [node name="SkillIconBase" type="PanelContainer"] custom_minimum_size = Vector2(30, 30) offset_right = 30.0 offset_bottom = 30.0 theme_override_styles/panel = SubResource("StyleBoxFlat_a60wd") +script = ExtResource("1_l7say") -[node name="icon" type="TextureRect" parent="."] +[node name="texture" type="TextureRect" parent="."] +unique_name_in_owner = true material = SubResource("ShaderMaterial_ew32n") layout_mode = 2 texture = ExtResource("2_hh1bl") diff --git a/scripts/Statemachine/CooldownTimer.gd b/scripts/Statemachine/CooldownTimer.gd index ecb15ab..8138e4d 100644 --- a/scripts/Statemachine/CooldownTimer.gd +++ b/scripts/Statemachine/CooldownTimer.gd @@ -4,9 +4,11 @@ var cooldown: float = 100 var lastStart: int = 0 func isCooldowned(): - return WorldManager.getTime() - lastStart >= cooldown + return timeSinceLastStart() >= cooldown func start(): var state = isCooldowned() if state: lastStart = WorldManager.getTime() return state +func timeSinceLastStart(): + return WorldManager.getTime() - lastStart diff --git a/scripts/Statemachine/SkillIcon.gd b/scripts/Statemachine/SkillIcon.gd new file mode 100644 index 0000000..47a725b --- /dev/null +++ b/scripts/Statemachine/SkillIcon.gd @@ -0,0 +1,10 @@ +extends PanelContainer + +@export var weapon: Weapon = null; + +@onready var textureRect = $"%texture" + +func _physics_process(_delta): + if is_instance_valid(weapon): + textureRect.texture = weapon.avatarTexture + textureRect.material.set_shader_parameter("progress", clamp(weapon.cooldownTimer.timeSinceLastStart() / weapon.cooldownTimer.cooldown, 0, 1)) diff --git a/shaders/CooldownProgress.gdshader b/shaders/CooldownProgress.gdshader index 8b76655..c5527c2 100644 --- a/shaders/CooldownProgress.gdshader +++ b/shaders/CooldownProgress.gdshader @@ -1,8 +1,9 @@ shader_type canvas_item; uniform float progress:hint_range(0.0, 1.0, 0.01)=0.5; +uniform float backAlpha:hint_range(0.0, 1.0, 0.01)=0.25; void fragment() { COLOR=texture(TEXTURE,UV); if(UV.y>=progress){ - COLOR.a*=0.5; + COLOR.a*=backAlpha; } } \ No newline at end of file