Skip to content

Commit

Permalink
feat(styled_button): 添加 disabled 和更改颜色功能
Browse files Browse the repository at this point in the history
添加了 button_disabled.png 以及根据主题更改配色功能。
  • Loading branch information
cutekibry committed Feb 16, 2024
1 parent 7a1fc70 commit ecfddb6
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 1 deletion.
Binary file modified objects/styled_button/button.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added objects/styled_button/button_disabled.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/styled_button/button_disabled.png.import
Original file line number Diff line number Diff line change
@@ -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
Binary file modified objects/styled_button/button_highlighted.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions objects/styled_button/styled_button.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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)
11 changes: 10 additions & 1 deletion objects/styled_button/styled_button.tscn
Original file line number Diff line number Diff line change
@@ -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"]

Expand All @@ -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"]
Expand All @@ -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")

Expand Down

0 comments on commit ecfddb6

Please sign in to comment.