diff --git a/bg/dynamic_bg/dynamic_bg.gd b/bg/dynamic_bg/dynamic_bg.gd index 589e0ff..cf3a30d 100644 --- a/bg/dynamic_bg/dynamic_bg.gd +++ b/bg/dynamic_bg/dynamic_bg.gd @@ -1,4 +1,4 @@ -extends Node2D +extends ColorRect signal victory_change(v: bool) @@ -24,8 +24,8 @@ func spawn(x_offset, y_offset): new_pattern.position = Vector2(pat_x, pat_y) new_pattern.velocity = VELOCITY victory_change.connect(new_pattern._on_victory_change) - new_pattern._on_victory_change(is_victory) add_child(new_pattern) + new_pattern._on_victory_change(is_victory) pat_x += W_STEP pat_y += H_STEP @@ -38,6 +38,8 @@ func set_victory(v: bool): func _ready(): var x_offset = 0 var y_offset = 0 + self.color = ImageLib.get_palette_color_by_name("darkest") + while HEIGHT + y_offset + (WIDTH / W_STEP) * H_STEP > -50: spawn(x_offset, y_offset) x_offset += $Timer.wait_time * VELOCITY.x diff --git a/bg/dynamic_bg/dynamic_bg.tscn b/bg/dynamic_bg/dynamic_bg.tscn index c9c0f10..78b979e 100644 --- a/bg/dynamic_bg/dynamic_bg.tscn +++ b/bg/dynamic_bg/dynamic_bg.tscn @@ -2,8 +2,17 @@ [ext_resource type="Script" path="res://bg/dynamic_bg/dynamic_bg.gd" id="1_g3cph"] -[node name="DynamicBg" type="Node2D"] -z_index = -4096 +[node name="DynamicBg" type="ColorRect"] +z_index = -50 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +offset_right = -1440.0 +offset_bottom = -810.0 +grow_horizontal = 2 +grow_vertical = 2 +mouse_filter = 2 +color = Color(0.141176, 0.223529, 0.4, 1) script = ExtResource("1_g3cph") [node name="Timer" type="Timer" parent="."] diff --git a/bg/dynamic_bg/dynamic_bg_pattern/dynamic_bg_pattern.gd b/bg/dynamic_bg/dynamic_bg_pattern/dynamic_bg_pattern.gd index 41df790..6c892a7 100644 --- a/bg/dynamic_bg/dynamic_bg_pattern/dynamic_bg_pattern.gd +++ b/bg/dynamic_bg/dynamic_bg_pattern/dynamic_bg_pattern.gd @@ -11,6 +11,8 @@ func _ready(): else: $Word1.set_word("qd<"[randi_range(0, 2)]) $Word2.set_word("=*"[randi_range(0, 1)]) + $Word1.set_color(ImageLib.get_palette_color_by_name("mid")) + $Word2.set_color(ImageLib.get_palette_color_by_name("mid")) func _process(delta): position += velocity * delta @@ -19,9 +21,9 @@ func _process(delta): func _on_victory_change(v: bool): if v: - $Word1.set_color(ImageLib.PALETTE["golden"]) - $Word2.set_color(ImageLib.PALETTE["golden"]) + $Word1.set_color(ImageLib.get_palette_color_by_name("light")) + $Word2.set_color(ImageLib.get_palette_color_by_name("light")) else: - $Word1.set_color(ImageLib.PALETTE["default"]) - $Word2.set_color(ImageLib.PALETTE["default"]) + $Word1.set_color(ImageLib.get_palette_color_by_name("mid")) + $Word2.set_color(ImageLib.get_palette_color_by_name("mid")) diff --git a/bg/dynamic_bg/dynamic_bg_pattern/dynamic_bg_pattern.tscn b/bg/dynamic_bg/dynamic_bg_pattern/dynamic_bg_pattern.tscn index f25723d..d439a93 100644 --- a/bg/dynamic_bg/dynamic_bg_pattern/dynamic_bg_pattern.tscn +++ b/bg/dynamic_bg/dynamic_bg_pattern/dynamic_bg_pattern.tscn @@ -4,11 +4,14 @@ [ext_resource type="PackedScene" uid="uid://cvx7wowcbfo0r" path="res://objects/word/word.tscn" id="2_7jm3n"] [node name="DynamicBgPattern" type="Node2D"] -modulate = Color(1, 1, 1, 0.12549) script = ExtResource("1_hrrmh") [node name="Word1" parent="." instance=ExtResource("2_7jm3n")] position = Vector2(-6, 0) +text_id = null +color = null [node name="Word2" parent="." instance=ExtResource("2_7jm3n")] position = Vector2(6, 0) +text_id = null +color = null diff --git a/jehkoba64-1x.png b/jehkoba64-1x.png new file mode 100644 index 0000000..de6cf20 Binary files /dev/null and b/jehkoba64-1x.png differ diff --git a/jehkoba64-1x.png.import b/jehkoba64-1x.png.import new file mode 100644 index 0000000..3c64d46 --- /dev/null +++ b/jehkoba64-1x.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://ds4iv57l5rrm7" +path="res://.godot/imported/jehkoba64-1x.png-02dcbbcc07ceb7ec900cbcaf48b21f3a.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://jehkoba64-1x.png" +dest_files=["res://.godot/imported/jehkoba64-1x.png-02dcbbcc07ceb7ec900cbcaf48b21f3a.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 diff --git a/levels/base_level/base_level.gd b/levels/base_level/base_level.gd index 9e97ab1..14bc905 100644 --- a/levels/base_level/base_level.gd +++ b/levels/base_level/base_level.gd @@ -167,8 +167,8 @@ func _on_block_occupied_card_changed(_node) -> void: if i != 0: if ExprValidator.is_smile(expr[i-1]+expr[i]): # print(expr[i-1]+expr[i]) - block_array[i-1].set_color(ImageLib.PALETTE["golden"]) - block_array[i].set_color(ImageLib.PALETTE["golden"]) + block_array[i-1].set_color(ImageLib.get_palette_color_by_name("golden")) + block_array[i].set_color(ImageLib.get_palette_color_by_name("golden")) func _input(event: InputEvent): if event is InputEventKey: diff --git a/main.gd b/main.gd index dea91b7..33b77d4 100644 --- a/main.gd +++ b/main.gd @@ -9,4 +9,4 @@ func _on_main_menu_enter_level(): func _on_bgm_player_finished(): $BGMPlayer.play() func set_victory(v: bool): - $Bg/DynamicBg.set_victory(v) + $DynamicBg.set_victory(v) diff --git a/main.tscn b/main.tscn index c2d3a80..f524bda 100644 --- a/main.tscn +++ b/main.tscn @@ -9,11 +9,11 @@ [node name="Main" type="Node"] script = ExtResource("1_nb6uf") -[node name="MainMenu" parent="." instance=ExtResource("1_fk6j6")] - -[node name="Bg" type="Node" parent="."] +[node name="DynamicBg" parent="." instance=ExtResource("2_8k4il")] +offset_right = 0.0 +offset_bottom = 0.0 -[node name="DynamicBg" parent="Bg" instance=ExtResource("2_8k4il")] +[node name="MainMenu" parent="." instance=ExtResource("1_fk6j6")] [node name="BGMPlayer" type="AudioStreamPlayer2D" parent="."] position = Vector2(234, 150) diff --git a/objects/block/block.gd b/objects/block/block.gd index d854f5b..3d0f0b6 100644 --- a/objects/block/block.gd +++ b/objects/block/block.gd @@ -100,7 +100,7 @@ func shake(is_frame_red: bool) -> void: if self.occupied_card != null: self.occupied_card.shake(not is_frame_red, SHAKE_AMOUNT, $ShakeTimer.wait_time) # 若框不红,则里面的字要红 elif not is_frame_red: - $Word.set_color(ImageLib.PALETTE["red"]) + $Word.set_color(ImageLib.get_palette_color_by_name("red")) if is_frame_red: $GoalFrameSprite.animation = "red" @@ -120,5 +120,5 @@ func _process(_delta): func _on_shake_timer_timeout() -> void: self.is_shaking = false $GoalFrameSprite.animation = "default" - $Word.set_color(ImageLib.PALETTE["default"]) + $Word.set_color(ImageLib.get_palette_color_by_name("black")) diff --git a/objects/card/card.gd b/objects/card/card.gd index 4447595..c404e52 100644 --- a/objects/card/card.gd +++ b/objects/card/card.gd @@ -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 @@ -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) + ) ## 获取字符。 @@ -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")) diff --git a/objects/card/card.tscn b/objects/card/card.tscn index efed77b..4e9027a 100644 --- a/objects/card/card.tscn +++ b/objects/card/card.tscn @@ -2,9 +2,9 @@ [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"] @@ -12,13 +12,13 @@ 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", diff --git a/objects/card/card1.png b/objects/card/card1.png index 10cde25..4578aaf 100644 Binary files a/objects/card/card1.png and b/objects/card/card1.png differ diff --git a/objects/card/card1.png.import b/objects/card/card1.png.import index 70b2cc6..7aebcff 100644 --- a/objects/card/card1.png.import +++ b/objects/card/card1.png.import @@ -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 diff --git a/objects/card/card2.png b/objects/card/card2.png index 6fc667d..a9628c6 100644 Binary files a/objects/card/card2.png and b/objects/card/card2.png differ diff --git a/objects/card/card2.png.import b/objects/card/card2.png.import index 279bd6c..b5f70a0 100644 --- a/objects/card/card2.png.import +++ b/objects/card/card2.png.import @@ -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 diff --git a/objects/card/card3.png b/objects/card/card3.png index c51dc86..ea22d01 100644 Binary files a/objects/card/card3.png and b/objects/card/card3.png differ diff --git a/objects/card/card3.png.import b/objects/card/card3.png.import index ca462b7..482109b 100644 --- a/objects/card/card3.png.import +++ b/objects/card/card3.png.import @@ -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 diff --git a/objects/card_base/card_base.gd b/objects/card_base/card_base.gd index bde96ec..80806e6 100644 --- a/objects/card_base/card_base.gd +++ b/objects/card_base/card_base.gd @@ -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) ## 获取字符。 @@ -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) diff --git a/objects/card_base/card_base.png b/objects/card_base/card_base.png new file mode 100644 index 0000000..b2728ae Binary files /dev/null and b/objects/card_base/card_base.png differ diff --git a/objects/card_base/card_base.png.import b/objects/card_base/card_base.png.import new file mode 100644 index 0000000..94af628 --- /dev/null +++ b/objects/card_base/card_base.png.import @@ -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 diff --git a/objects/card_base/card_base.tscn b/objects/card_base/card_base.tscn index a5b5490..a551d9b 100644 --- a/objects/card_base/card_base.tscn +++ b/objects/card_base/card_base.tscn @@ -1,9 +1,9 @@ [gd_scene load_steps=10 format=3 uid="uid://d35prv6j48a2y"] [ext_resource type="Script" path="res://objects/card_base/card_base.gd" id="1_k5qn1"] +[ext_resource type="Texture2D" uid="uid://bf6r7pnuuk5kr" path="res://objects/card_base/card_base.png" id="2_jovan"] [ext_resource type="PackedScene" uid="uid://cvx7wowcbfo0r" path="res://objects/word/word.tscn" id="2_jvsp3"] [ext_resource type="FontFile" uid="uid://1000owdyvwfg" path="res://fonts/unifont-15.1.04.otf" id="3_0qykx"] -[ext_resource type="Texture2D" uid="uid://b5d2rfms7vyfi" path="res://objects/card_base/card_base1.png" id="3_h7i1h"] [ext_resource type="Texture2D" uid="uid://bkjbrw1ppac5q" path="res://objects/card_base/card_base_disabled.png" id="4_0unxr"] [ext_resource type="Texture2D" uid="uid://bkuwo3g8pyuyi" path="res://objects/card_base/card_base_highlight_border.png" id="5_r41oe"] [ext_resource type="AudioStream" uid="uid://0sefo32v1jne" path="res://objects/card_base/pick_up.wav" id="7_0c7kt"] @@ -15,7 +15,7 @@ size = Vector2(28, 26) animations = [{ "frames": [{ "duration": 1.0, -"texture": ExtResource("3_h7i1h") +"texture": ExtResource("2_jovan") }], "loop": true, "name": &"default", @@ -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 diff --git a/objects/card_base/card_base1.png b/objects/card_base/card_base1.png deleted file mode 100644 index d499332..0000000 Binary files a/objects/card_base/card_base1.png and /dev/null differ diff --git a/objects/card_base/card_base_disabled.png b/objects/card_base/card_base_disabled.png index bb27e73..3ceb189 100644 Binary files a/objects/card_base/card_base_disabled.png and b/objects/card_base/card_base_disabled.png differ diff --git a/objects/styled_button/button.png b/objects/styled_button/button.png index 3aa4819..843bea7 100644 Binary files a/objects/styled_button/button.png and b/objects/styled_button/button.png differ diff --git a/objects/styled_button/button_disabled.png b/objects/styled_button/button_disabled.png new file mode 100644 index 0000000..ca99b0e Binary files /dev/null and b/objects/styled_button/button_disabled.png differ diff --git a/objects/styled_button/button_disabled.png.import b/objects/styled_button/button_disabled.png.import new file mode 100644 index 0000000..a943a41 --- /dev/null +++ b/objects/styled_button/button_disabled.png.import @@ -0,0 +1,34 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://hld6oeivwkrn" +path="res://.godot/imported/button_disabled.png-f5ba9e08bceb4e66e56efb835a6e9274.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://objects/styled_button/button_disabled.png" +dest_files=["res://.godot/imported/button_disabled.png-f5ba9e08bceb4e66e56efb835a6e9274.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 diff --git a/objects/styled_button/button_highlighted.png b/objects/styled_button/button_highlighted.png index ae95e06..c4122d6 100644 Binary files a/objects/styled_button/button_highlighted.png and b/objects/styled_button/button_highlighted.png differ diff --git a/objects/styled_button/styled_button.gd b/objects/styled_button/styled_button.gd index 53dab9e..e24f1ef 100644 --- a/objects/styled_button/styled_button.gd +++ b/objects/styled_button/styled_button.gd @@ -5,3 +5,11 @@ class_name StyledButton func _on_pressed(): $SFXButtonDown.play() + + +func _ready(): + for box_theme in ["normal", "hover", "presssed", "disabled", "focus"]: + var stylebox := get_theme_stylebox(box_theme) + if stylebox is StyleBoxTexture: + stylebox.texture = ImageLib.replace_palette_colors_in_image(stylebox.texture) + add_theme_stylebox_override(box_theme, stylebox) diff --git a/objects/styled_button/styled_button.tscn b/objects/styled_button/styled_button.tscn index 80c7aa5..4d535e6 100644 --- a/objects/styled_button/styled_button.tscn +++ b/objects/styled_button/styled_button.tscn @@ -1,7 +1,8 @@ -[gd_scene load_steps=8 format=3 uid="uid://drl1xe103umpi"] +[gd_scene load_steps=10 format=3 uid="uid://drl1xe103umpi"] [ext_resource type="Texture2D" uid="uid://y5v6eoqttfkv" path="res://objects/styled_button/button.png" id="1_64thl"] [ext_resource type="Texture2D" uid="uid://dqoba5dcyefbj" path="res://objects/styled_button/button_highlighted.png" id="2_8xse4"] +[ext_resource type="Texture2D" uid="uid://hld6oeivwkrn" path="res://objects/styled_button/button_disabled.png" id="3_840jk"] [ext_resource type="Script" path="res://objects/styled_button/styled_button.gd" id="3_rtcig"] [ext_resource type="AudioStream" uid="uid://dpwscp4bw7pay" path="res://objects/styled_button/button_down.wav" id="4_no3m1"] @@ -19,6 +20,13 @@ texture_margin_top = 6.0 texture_margin_right = 6.0 texture_margin_bottom = 6.0 +[sub_resource type="StyleBoxTexture" id="StyleBoxTexture_filad"] +texture = ExtResource("3_840jk") +texture_margin_left = 6.0 +texture_margin_top = 6.0 +texture_margin_right = 6.0 +texture_margin_bottom = 6.0 + [sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_tfhr0"] [node name="StyledButton" type="Button"] @@ -27,6 +35,7 @@ offset_bottom = 100.0 theme_override_styles/normal = SubResource("StyleBoxTexture_c0uot") theme_override_styles/hover = SubResource("StyleBoxTexture_eifmj") theme_override_styles/pressed = SubResource("StyleBoxTexture_eifmj") +theme_override_styles/disabled = SubResource("StyleBoxTexture_filad") theme_override_styles/focus = SubResource("StyleBoxEmpty_tfhr0") script = ExtResource("3_rtcig") diff --git a/objects/table_cloth/golden_cloth.png b/objects/table_cloth/golden_cloth.png index eb6777e..00f8386 100644 Binary files a/objects/table_cloth/golden_cloth.png and b/objects/table_cloth/golden_cloth.png differ diff --git a/objects/table_cloth/table_cloth.gd b/objects/table_cloth/table_cloth.gd new file mode 100644 index 0000000..190ba02 --- /dev/null +++ b/objects/table_cloth/table_cloth.gd @@ -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) diff --git a/objects/table_cloth/table_cloth.png b/objects/table_cloth/table_cloth.png index 40fb711..4c9ff37 100644 Binary files a/objects/table_cloth/table_cloth.png and b/objects/table_cloth/table_cloth.png differ diff --git a/objects/table_cloth/table_cloth.tscn b/objects/table_cloth/table_cloth.tscn index 7c0f2ee..fa269a1 100644 --- a/objects/table_cloth/table_cloth.tscn +++ b/objects/table_cloth/table_cloth.tscn @@ -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") @@ -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 diff --git a/objects/word/word.gd b/objects/word/word.gd index 09a9eee..621e4e0 100644 --- a/objects/word/word.gd +++ b/objects/word/word.gd @@ -41,7 +41,7 @@ func set_text_id(value: int) -> void: ## 根据当前的 [member text_id] 更新动画。 func update_animation() -> void: - ImageLib.update_animation(self, text_id + 1, 3, STEP, "res://objects/word/sprites/sprite%d.png", Color.BLACK, color) + ImageLib.update_animation(self, text_id + 1, 3, STEP, "res://objects/word/sprites/sprite%d.png", Color.BLACK, self.color) @@ -75,9 +75,9 @@ func set_color(value: Color) -> void: func set_victory(v: bool) -> void: push_warning("void set_victory(v: bool) is deprecated.") if v: - set_color(ImageLib.PALETTE["golden"]) + set_color(ImageLib.get_palette_color_by_name("golden")) else: - set_color(ImageLib.PALETTE["default"]) + set_color(ImageLib.get_palette_color_by_name("black")) diff --git a/project.godot b/project.godot index 0fb29d5..7b506d1 100644 --- a/project.godot +++ b/project.godot @@ -13,7 +13,6 @@ config_version=5 config/name="=P" run/main_scene="res://main.tscn" config/features=PackedStringArray("4.2", "Forward Plus") -boot_splash/bg_color=Color(0.196078, 0.184314, 0.301961, 1) config/icon="res://=P3.png" [debug] @@ -34,4 +33,3 @@ mouse_cursor/custom_image="res://bg/cursor/cursor_arrow.png" textures/canvas_textures/default_texture_filter=0 textures/vram_compression/import_etc2_astc=true -environment/defaults/default_clear_color=Color(0.196078, 0.184314, 0.301961, 1) diff --git a/scripts/image_lib.gd b/scripts/image_lib.gd index dc9224e..e4032c4 100644 --- a/scripts/image_lib.gd +++ b/scripts/image_lib.gd @@ -1,29 +1,60 @@ class_name ImageLib + +## 不同主题下的配色模板。 +## [br][br] +## [code]PALETTE[theme][name]: Color[/code] 表示配色主题 [param theme] 下代号为 [param name] 的颜色值。 +## [br][br] +## [param theme] 和 [param name] 的取值分别参见 [member COLOR_THEMES] 和 [member COLOR_NAMES]。 const PALETTE = { - "red": Color("#dd4132"), - "golden": Color("#f5df4d"), - - "orange": Color("#ffb463"), - "card-op": Color("#ffb463"), - - "skyblue": Color("#c2fdff"), - "card-bracl": Color("#c2fdff"), - "card-bracr": Color("#c2fdff"), - - "lightblue": Color("#8eacf3"), - "card-var": Color("#8eacf3"), - - "lightgreen": Color("#8ff297"), - "card-comp": Color("#8ff297"), - - "sliver": Color("#f0f0f0"), - "card-const": Color("#f0f0f0"), - - "default": Color.BLACK, + "blue": { + "lightest": Color("#25acf5"), + "light": Color("#1793e6"), + "mid": Color("#195ba6"), + "darkest": Color("#243966"), + + "golden": Color("#f5df4d"), + "black": Color.BLACK, + "red": Color("#dd4132"), + }, + "green": { + "lightest": Color("#94bf30"), + "light": Color("#55b33b"), + "mid": Color("#068051"), + "darkest": Color("#116061"), + + "golden": Color("#f5df4d"), + "black": Color.BLACK, + "red": Color("#dd4132"), + } } -static func change_color(image: Texture2D, old_color: Color, new_color: Color) -> Texture2D: + +const COLOR_THEMES := ["blue", "green"] ## 可选的配色主题 [code]theme[/code] 取值。 + +const COLOR_NAMES := ["lightest", "light", "mid", "darkest", "golden", "black", "red"] ## 可选的颜色代号 [code]name[/code] 取值。 + + + +static var theme := "blue" ## 当前主题。 + + + +## 获取 [param color] 的主题色 [code]theme[/code] 和代号 [code]name[/code]。 +## [br][br] +## 若没有在 [member PALETTE] 里出现,返回 [code]null[/code]。 +## [br][br] +## 否则返回 [code][theme, name][/code]。 +static func get_color_info(color: Color) -> Variant: + for col_theme in PALETTE.keys(): + for name in PALETTE[col_theme].keys(): + if color == PALETTE[col_theme][name]: + return [col_theme, name] + return null + + +## 将 [param image] 中的 [Color] [param old_color] 替换为 [Color] [param new_color]。 +static func replace_color(image: Texture2D, old_color: Color, new_color: Color) -> Texture2D: var new_texture = image.get_image() for x in range(new_texture.get_width()): for y in range(new_texture.get_height()): @@ -32,19 +63,67 @@ static func change_color(image: Texture2D, old_color: Color, new_color: Color) - new_texture.set_pixel(x, y, new_color) return ImageTexture.create_from_image(new_texture) + +## 将 [param image] 中,在 [member PALETTE] 出现过的 [Color] 替换为当前配色主题下相同代号的 [Color]。 +static func replace_palette_colors_in_image(image: Texture2D) -> Texture2D: + var new_texture = image.get_image() + for x in range(new_texture.get_width()): + for y in range(new_texture.get_height()): + var info = get_color_info(new_texture.get_pixel(x, y)) + if info != null: + new_texture.set_pixel(x, y, PALETTE[theme][info[1]]) + return ImageTexture.create_from_image(new_texture) + + +## 为 [AnimatedSprite2D] [param sprite] 生成动画并播放。 +## [br][br] +## 动画图像的路径模式串为 [param path_pattern],应当为仅带一个 [code]%d[/code] 的模式串或常量串。[param start] 为起始帧编号,[param n] 为帧的数量,[param step] 为每帧之间编号的差值。 +## [br][br] +## 图像会按照 [code]path_pattern % (i * step + start)[/code] 进行加载,其中 [code]i in range(n)[/code]。 +## [br][br] +## 加载时,会先将图像里的所有 [Color] [param old_color] 替换为 [Color] [param new_color],再将 [member PALETTE] 里出现的 [Color] 替换为当前配色主题下相同代号的 [Color]。 +## [br][br] +## 示例: +## [codeblock] +## # 载入 res://image2.png, res://image22.png, res://image42.png 作为动画,设置 self 播放。 +## # 载入时,先将图片中的白色替换为红色,再将 PALETTE 中出现的颜色替换为当前主题下的同名色。 +## update_animation(self, 2, 3, 20, "res://image%d.png", Color.WHITE, Color.RED) +## [/codeblock] static func update_animation( sprite: AnimatedSprite2D, start: int, n: int, step: int, path_pattern: String, - old_color: Color, - new_color: Color + old_color: Color = Color.BLACK, + new_color: Color = Color.BLACK ) -> void: - var animation_id = "%d_%d_%d_%s" % [start, n, step, new_color.to_html()] + var animation_id = "%d_%d_%d_%s_%s_%s" % [start, n, step, path_pattern, theme, new_color.to_html()] if not sprite.sprite_frames.has_animation(animation_id): sprite.sprite_frames.add_animation(animation_id) for i in range(n): - var image = load(path_pattern % (i * step + start)) - sprite.sprite_frames.add_frame(animation_id, ImageLib.change_color(image, old_color, new_color)) + var image + if path_pattern.contains("%d"): + image = load(path_pattern % (i * step + start)) + else: + image = load(path_pattern) + if old_color != new_color: + image = ImageLib.replace_color(image, old_color, new_color) + image = ImageLib.replace_palette_colors_in_image(image) + sprite.sprite_frames.add_frame(animation_id, image) sprite.play(animation_id) + + +## 获取当前主题下,代号为 [param name] 的颜色值。 +## [br][br] +## [param name] 的取值参见 [member COLOR_NAMES]。 +static func get_palette_color_by_name(name: String) -> Color: + return PALETTE[theme][name] + + + +## 获取主题 [param col_theme] 下,代号为 [param name] 的颜色值。 +## [br][br] +## [param col_theme] 和 [param name] 的取值参见 [member COLOR_THEMES] 和 [member COLOR_NAMES]。 +static func get_palette_color_by_info(col_theme: String, name: String) -> Color: + return PALETTE[col_theme][name]