xiandie/ui/button/sound_texture_button.gd

38 lines
1.2 KiB
GDScript3
Raw Normal View History

@tool
2024-12-23 01:29:31 +00:00
extends TextureButton
class_name SoundTextureButton
@export var generate_click_mask := false:
set(val):
generate_click_mask = false
if val and texture_normal:
var mask_image := texture_normal.get_image()
texture_click_mask = BitMap.new()
texture_click_mask.create_from_image_alpha(mask_image)
@export var audio_streams := [preload("res://asset/audio/sfx/ui/click.wav")] as Array[AudioStream]
@export var audio_collections = [] as Array[AudioStreamCollection]
2024-12-23 01:29:31 +00:00
func _ready():
if audio_streams:
var collection := AudioStreamCollection.new()
collection.audios = audio_streams
audio_collections.append(collection)
2024-12-23 01:29:31 +00:00
if audio_collections:
#print("sound button load audio_collections into audio_player")
var audio_player := RandomAudioStreamPlayer.new()
audio_player.audio_collections = audio_collections
button_down.connect(audio_player.play_random)
add_child(audio_player)
else:
push_warning("sound button has no audio_collections! ignore initialization of audio_player")
2024-12-23 01:29:31 +00:00
#button_down.connect(_on_press_down)
#button_up.connect(_on_press_up)
#func _on_press_down():
#InputUtil.set_cursor_hand_patting()
2024-12-23 01:29:31 +00:00
#
#func _on_press_up():
#InputUtil.set_cursor_hand_rest()