Skip to content

Commit

Permalink
refactor(card): 将 Highlight border 独立出来
Browse files Browse the repository at this point in the history
将原先 card_highlighted.png 替换为仅包含高亮而不包含卡背颜色的素材 card_highlight_border.png,
同时新建 Sprite2D 场景 HighlightSprite 用于显示高亮
  • Loading branch information
cutekibry committed Feb 10, 2024
1 parent 52ed33e commit 4e9a94c
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 19 deletions.
9 changes: 5 additions & 4 deletions objects/card/card.gd
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ var is_shaking := false
func _ready():
origin_global_position = global_position
last_global_position = global_position
$HighlightSprite.visible = false

func _on_mouse_release():
#prints(entered_area.name, is_card_entered, entered_area.occupied)
Expand Down Expand Up @@ -135,22 +136,22 @@ func shake(is_letter_red: bool, amount: float, duration: float) -> void:
if is_letter_red:
$Word.set_color(ImageLib.PALETTE["red"])
else:
$CardBackSprite.animation = "default"
$HighlightSprite.visible = false




func _on_mouse_entered():
$CardBackSprite.animation = "highlighted"
$HighlightSprite.visible = true
Input.set_default_cursor_shape(Input.CURSOR_POINTING_HAND)

func _on_mouse_exited():
$CardBackSprite.animation = "default"
$HighlightSprite.visible = false
Input.set_default_cursor_shape(Input.CURSOR_ARROW)

func set_color(value: Color) -> void:
$Word.set_color(value)


func set_victory(v: bool):
if v:
$CollisionShape2D.set_deferred("disabled", true)
Expand Down
25 changes: 10 additions & 15 deletions objects/card/card.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
[ext_resource type="Texture2D" uid="uid://cfbqh1k0etr6g" path="res://objects/card/card1.png" id="3_o4f0v"]
[ext_resource type="Texture2D" uid="uid://c8qjbksyn1bqt" path="res://objects/card/card2.png" id="4_c30j1"]
[ext_resource type="Texture2D" uid="uid://bevrfq1hhyqwe" path="res://objects/card/card3.png" id="5_w81n3"]
[ext_resource type="Texture2D" uid="uid://cmcc5xrpkrd0f" path="res://objects/card/card_highlighted.png" id="6_po2i6"]
[ext_resource type="Texture2D" uid="uid://pmapbo480in1" path="res://objects/card/card_highlight_border.png" id="7_kix4t"]
[ext_resource type="AudioStream" uid="uid://cj4v8ehypq3sk" path="res://objects/card/put_down.wav" id="7_u4ylf"]

[sub_resource type="RectangleShape2D" id="RectangleShape2D_gu6l6"]

[sub_resource type="SpriteFrames" id="SpriteFrames_fo0r0"]
animations = [{
"frames": [{
Expand All @@ -25,16 +23,10 @@ animations = [{
"loop": true,
"name": &"default",
"speed": 5.0
}, {
"frames": [{
"duration": 1.0,
"texture": ExtResource("6_po2i6")
}],
"loop": true,
"name": &"highlighted",
"speed": 5.0
}]

[sub_resource type="RectangleShape2D" id="RectangleShape2D_gu6l6"]

[node name="Card" type="Area2D"]
z_index = 50
script = ExtResource("1_0bviv")
Expand All @@ -45,14 +37,17 @@ frame_progress = 0.111549
text_id = 1
color = Color(0, 0, 0, 1)

[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
z_index = 15
shape = SubResource("RectangleShape2D_gu6l6")

[node name="CardBackSprite" type="AnimatedSprite2D" parent="."]
sprite_frames = SubResource("SpriteFrames_fo0r0")
autoplay = "default"

[node name="HighlightSprite" type="Sprite2D" parent="."]
texture = ExtResource("7_kix4t")

[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
z_index = 15
shape = SubResource("RectangleShape2D_gu6l6")

[node name="SFXPutDown" type="AudioStreamPlayer" parent="."]
stream = ExtResource("7_u4ylf")
volume_db = 13.117
Expand Down
Binary file added objects/card/card_highlight_border.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions objects/card/card_highlight_border.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://pmapbo480in1"
path="res://.godot/imported/card_highlight_border.png-c0b130850c2d1dcdc5af25ea7e1dafdc.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://objects/card/card_highlight_border.png"
dest_files=["res://.godot/imported/card_highlight_border.png-c0b130850c2d1dcdc5af25ea7e1dafdc.ctex"]

[params]

compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1
Binary file removed objects/card/card_highlighted.png
Binary file not shown.

0 comments on commit 4e9a94c

Please sign in to comment.