Skip to content

Commit

Permalink
feat: 添加根据主题更改配色功能
Browse files Browse the repository at this point in the history
添加了 card, card_base, table_cloth 的更改配色功能。
  • Loading branch information
cutekibry committed Feb 16, 2024
1 parent c1575a9 commit 7a1fc70
Show file tree
Hide file tree
Showing 17 changed files with 81 additions and 23 deletions.
21 changes: 13 additions & 8 deletions objects/card/card.gd
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func shake(is_letter_red: bool, amount: float, duration: float) -> void:
self.is_shaking = true

if is_letter_red:
$Word.set_color(ImageLib.PALETTE["red"])
$Word.set_color(ImageLib.get_palette_color_by_name("red"))
else:
$HighlightSprite.visible = false

Expand All @@ -102,12 +102,17 @@ func set_victory(v: bool):
## 设置字符为 [param value],同时更新卡背颜色。
func set_word(value: String) -> void:
$Word.set_word(value)
var card_type := "card-%s" % ExprValidator.get_char_type_as_str(get_word()).to_lower() # 根据单词类型获取卡牌类型
if ImageLib.PALETTE.has(card_type): # 如果配色盘中包含该卡牌类型对应颜色,则更新卡背颜色
ImageLib.update_animation(
$CardBackSprite, 1, 3, 1, "res://objects/card/card%d.png",
ImageLib.PALETTE["lightblue"], ImageLib.PALETTE[card_type]
)
var new_color_name: String
if ExprValidator.get_char_type_as_str(get_word()) in ["VAR", "CONST"]:
new_color_name = "light"
else:
new_color_name = "lightest"

ImageLib.update_animation(
$CardBackSprite, 1, 3, 1, "res://objects/card/card%d.png",
ImageLib.get_palette_color_by_info("blue", "light"),
ImageLib.get_palette_color_by_name(new_color_name)
)


## 获取字符。
Expand Down Expand Up @@ -166,4 +171,4 @@ func _on_tree_exiting():

func _on_shake_timer_timeout():
self.is_shaking = false
$Word.set_color(ImageLib.PALETTE["default"])
$Word.set_color(ImageLib.get_palette_color_by_name("black"))
12 changes: 6 additions & 6 deletions objects/card/card.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@

[ext_resource type="Script" path="res://objects/card/card.gd" id="1_0bviv"]
[ext_resource type="PackedScene" uid="uid://cvx7wowcbfo0r" path="res://objects/word/word.tscn" id="1_ns36n"]
[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://mmtuv34pq4t2" path="res://objects/card/card1.png" id="2_m034v"]
[ext_resource type="Texture2D" uid="uid://ct5w4n7kylfuc" path="res://objects/card/card2.png" id="3_2vd1f"]
[ext_resource type="Texture2D" uid="uid://c6f6j4aln0qvp" path="res://objects/card/card3.png" id="4_wleyv"]
[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="SpriteFrames" id="SpriteFrames_fo0r0"]
animations = [{
"frames": [{
"duration": 1.0,
"texture": ExtResource("3_o4f0v")
"texture": ExtResource("2_m034v")
}, {
"duration": 1.0,
"texture": ExtResource("4_c30j1")
"texture": ExtResource("3_2vd1f")
}, {
"duration": 1.0,
"texture": ExtResource("5_w81n3")
"texture": ExtResource("4_wleyv")
}],
"loop": true,
"name": &"default",
Expand Down
Binary file modified objects/card/card1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion objects/card/card1.png.import
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

importer="texture"
type="CompressedTexture2D"
uid="uid://cfbqh1k0etr6g"
uid="uid://mmtuv34pq4t2"
path="res://.godot/imported/card1.png-a70bfeaf7072e44918be31de484a175d.ctex"
metadata={
"vram_texture": false
Expand Down
Binary file modified objects/card/card2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion objects/card/card2.png.import
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

importer="texture"
type="CompressedTexture2D"
uid="uid://c8qjbksyn1bqt"
uid="uid://ct5w4n7kylfuc"
path="res://.godot/imported/card2.png-ac2767fabcf91e439932ee4b59f788bf.ctex"
metadata={
"vram_texture": false
Expand Down
Binary file modified objects/card/card3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion objects/card/card3.png.import
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

importer="texture"
type="CompressedTexture2D"
uid="uid://bevrfq1hhyqwe"
uid="uid://c6f6j4aln0qvp"
path="res://.godot/imported/card3.png-d9431fdb530fc93bbd1398924fd9c0a1.ctex"
metadata={
"vram_texture": false
Expand Down
18 changes: 13 additions & 5 deletions objects/card_base/card_base.gd
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,19 @@ func draw_card():
## 设置字符为 e,并更新卡背颜色。
func set_word(e: String) -> void:
$Word.set_word(e)

var new_color_name: String
if ExprValidator.get_char_type_as_str(e) in ["VAR", "CONST"]:
new_color_name = "light"
else:
new_color_name = "lightest"
ImageLib.update_animation(
$CardBaseSprite, 1, 3, 1, "res://objects/card_base/card_base.png",
ImageLib.get_palette_color_by_info("blue", "light"),
ImageLib.get_palette_color_by_name(new_color_name)
)

var card_type := "card-%s" % ExprValidator.get_char_type_as_str(e).to_lower()
if ImageLib.PALETTE.has(card_type):
ImageLib.update_animation($CardBaseSprite, 1, 1, 1, "res://objects/card_base/card_base%d.png",
ImageLib.PALETTE["lightblue"], ImageLib.PALETTE[card_type])
$DisabledSprite.texture = ImageLib.replace_palette_colors_in_image($DisabledSprite.texture)


## 获取字符。
Expand Down Expand Up @@ -129,5 +137,5 @@ func _on_mouse_exited():
available_stat = DEFAULT


func _on_cards_child_exiting_tree(node: Node) -> void:
func _on_cards_child_exiting_tree(_node: Node) -> void:
set_card_count(self.card_count + 1)
Binary file added objects/card_base/card_base.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_base/card_base.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://bf6r7pnuuk5kr"
path="res://.godot/imported/card_base.png-a60b964691c8dbc2cdebd8962b3939cb.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://objects/card_base/card_base.png"
dest_files=["res://.godot/imported/card_base.png-a60b964691c8dbc2cdebd8962b3939cb.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
2 changes: 2 additions & 0 deletions objects/card_base/card_base.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ sprite_frames = SubResource("SpriteFrames_bhb3x")

[node name="Word" parent="." instance=ExtResource("2_jvsp3")]
frame_progress = 0.953211
text_id = null
color = null

[node name="HighlightSprite" type="Sprite2D" parent="."]
visible = false
Expand Down
Binary file removed objects/card_base/card_base1.png
Binary file not shown.
Binary file modified objects/card_base/card_base_disabled.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions objects/table_cloth/table_cloth.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
extends Panel


func _ready():
var stylebox := get_theme_stylebox("panel")
stylebox.texture = ImageLib.replace_palette_colors_in_image(stylebox.texture)
add_theme_stylebox_override("panel", stylebox)
Binary file modified objects/table_cloth/table_cloth.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion objects/table_cloth/table_cloth.tscn
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
[gd_scene load_steps=5 format=3 uid="uid://7kd53bu4qorc"]
[gd_scene load_steps=6 format=3 uid="uid://7kd53bu4qorc"]

[ext_resource type="Texture2D" uid="uid://1gcwvbyjejey" path="res://objects/table_cloth/table_cloth.png" id="1_8qui1"]
[ext_resource type="Texture2D" uid="uid://cb5gytqlvjj2v" path="res://objects/table_cloth/golden_cloth.png" id="2_3edv5"]
[ext_resource type="Script" path="res://objects/table_cloth/table_cloth.gd" id="2_wo6il"]

[sub_resource type="StyleBoxTexture" id="StyleBoxTexture_js8qc"]
texture = ExtResource("1_8qui1")
Expand All @@ -23,6 +24,7 @@ offset_right = 109.0
offset_bottom = 40.0
mouse_filter = 2
theme_override_styles/panel = SubResource("StyleBoxTexture_js8qc")
script = ExtResource("2_wo6il")

[node name="GoldenCloth" type="Panel" parent="."]
visible = false
Expand Down

0 comments on commit 7a1fc70

Please sign in to comment.