From 234a632f392161d0a7af9024192383b6d16e7a98 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: Wed, 10 Sep 2025 06:31:53 +0800 Subject: [PATCH] =?UTF-8?q?refactor(UI):=20=E8=B0=83=E6=95=B4=E6=8A=80?= =?UTF-8?q?=E8=83=BD=E5=9B=BE=E6=A0=87=E5=B8=83=E5=B1=80=E5=B9=B6=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E5=86=B7=E5=8D=B4=E6=95=88=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修改技能图标面板的锚点设置以改善布局 将冷却进度着色器逻辑反转并优化视觉效果 统一材质管理方式,移除重复的材质复制 --- components/Abstracts/SkillIconBase.tscn | 18 ++++++++++-------- components/Scenes/UI.tscn | 10 +++++----- scripts/Statemachine/SkillIcon.gd | 5 ++--- shaders/CooldownProgress.gdshader | 16 ++++++++++------ 4 files changed, 27 insertions(+), 22 deletions(-) diff --git a/components/Abstracts/SkillIconBase.tscn b/components/Abstracts/SkillIconBase.tscn index 7002344..4c27b12 100644 --- a/components/Abstracts/SkillIconBase.tscn +++ b/components/Abstracts/SkillIconBase.tscn @@ -4,6 +4,14 @@ [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="ShaderMaterial" id="ShaderMaterial_3fyf3"] +shader = ExtResource("1_jaivk") +shader_parameter/progress = 0.55 +shader_parameter/backAlpha = 0.25 +shader_parameter/edgeHeight = 0.05 +shader_parameter/trailHeight = 0.3 +shader_parameter/trailAlpha = 0.5 + [sub_resource type="StyleBoxFlat" id="StyleBoxFlat_a60wd"] content_margin_left = 5.0 content_margin_top = 5.0 @@ -15,14 +23,8 @@ corner_radius_top_right = 20 corner_radius_bottom_right = 20 corner_radius_bottom_left = 20 -[sub_resource type="ShaderMaterial" id="ShaderMaterial_ew32n"] -shader = ExtResource("1_jaivk") -shader_parameter/progress = 0.5 -shader_parameter/backAlpha = 0.25 -shader_parameter/edgeHeight = 0.05 -shader_parameter/trailHeight = 0.3 - [node name="SkillIconBase" type="PanelContainer"] +material = SubResource("ShaderMaterial_3fyf3") custom_minimum_size = Vector2(40, 40) offset_right = 30.0 offset_bottom = 30.0 @@ -31,7 +33,7 @@ script = ExtResource("1_l7say") [node name="texture" type="TextureRect" parent="."] unique_name_in_owner = true -material = SubResource("ShaderMaterial_ew32n") +z_index = -1 layout_mode = 2 texture = ExtResource("2_hh1bl") expand_mode = 1 diff --git a/components/Scenes/UI.tscn b/components/Scenes/UI.tscn index bc766eb..f5acb76 100644 --- a/components/Scenes/UI.tscn +++ b/components/Scenes/UI.tscn @@ -119,7 +119,6 @@ _data = { } [sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_12otr"] -content_margin_right = 10.0 [node name="UI" type="CanvasLayer"] process_mode = 3 @@ -252,12 +251,13 @@ libraries = { [node name="skills" type="PanelContainer" parent="root"] layout_mode = 1 -anchors_preset = 6 -anchor_left = 1.0 +anchors_preset = -1 +anchor_left = 0.97 anchor_top = 0.5 -anchor_right = 1.0 +anchor_right = 0.97 anchor_bottom = 0.5 -offset_left = -10.0 +offset_left = 0.399902 +offset_right = 0.399902 grow_horizontal = 0 grow_vertical = 2 theme_override_styles/panel = SubResource("StyleBoxEmpty_12otr") diff --git a/scripts/Statemachine/SkillIcon.gd b/scripts/Statemachine/SkillIcon.gd index e162739..218796e 100644 --- a/scripts/Statemachine/SkillIcon.gd +++ b/scripts/Statemachine/SkillIcon.gd @@ -4,11 +4,10 @@ class_name SkillIcon @export var weapon: Weapon = null; @onready var textureRect: TextureRect = $"%texture" - func _ready(): - textureRect.material = textureRect.material.duplicate() + material = material.duplicate() func _physics_process(_delta): if is_instance_valid(weapon): textureRect.texture = weapon.avatarTexture var progress = min(weapon.cooldownTimer.timeSinceLastStart() / weapon.cooldownTimer.cooldown, UIState.player.energy / weapon.needEnergy) - textureRect.material.set_shader_parameter("progress", progress) + material.set_shader_parameter("progress", progress) diff --git a/shaders/CooldownProgress.gdshader b/shaders/CooldownProgress.gdshader index 71af89a..55b0c03 100644 --- a/shaders/CooldownProgress.gdshader +++ b/shaders/CooldownProgress.gdshader @@ -5,11 +5,15 @@ uniform float edgeHeight:hint_range(0.0, 1.0, 0.01)=0.05; uniform float trailHeight:hint_range(0.0, 1.0, 0.01)=0.3; uniform float trailAlpha:hint_range(0.0, 1.0, 0.01)=0.5; void fragment() { - if(UV.y>=progress){ - COLOR.a*=backAlpha; - }else if(distance(UV.y,progress)=1.0-progress){ + if(1.0-progress+trailHeight-UV.y>0.0){ + float dist=distance(UV.y,1.0-progress); + COLOR=vec4(1); + COLOR.a=(trailHeight-dist)/trailHeight*trailAlpha; + }else{ + COLOR.a*=backAlpha; + } + }else if(distance(UV.y,1.0-progress)