38 lines
1.1 KiB
GDScript
38 lines
1.1 KiB
GDScript
extends TextureRect
|
||
class_name CharacterBagCard
|
||
#被按下时发出
|
||
signal self_click(card:CharacterBagCard)
|
||
@onready var star_group:Array[TextureRect]=[$mask/HBoxContainer/HBoxContainer/TextureRect, $mask/HBoxContainer/HBoxContainer/TextureRect2, $mask/HBoxContainer/HBoxContainer/TextureRect3, $mask/HBoxContainer/HBoxContainer/TextureRect4, $mask/HBoxContainer/HBoxContainer/TextureRect5]
|
||
#初始化数据,应先更改此字典,然后进行add child 触发ready
|
||
var data={
|
||
"star_num":3,
|
||
"face":"res://res/ui/ui_003_select/test.png",
|
||
"name":"角色名字"
|
||
}
|
||
#设置星数
|
||
func set_star_num(num:int):
|
||
for i in star_group.size():
|
||
if i<num:
|
||
star_group[i].show()
|
||
else:
|
||
star_group[i].hide()
|
||
pass
|
||
#设置卡面
|
||
func set_face(path:String):
|
||
var new_face=load(path)
|
||
if new_face!=null and new_face is Texture2D:
|
||
%texture_face.texture=new_face
|
||
#设置名字
|
||
func set_character_name(n:String):
|
||
%n.text=n
|
||
pass
|
||
func _ready() -> void:
|
||
set_star_num(data.star_num)
|
||
set_face(data.face)
|
||
set_character_name(data.name)
|
||
|
||
|
||
func _on_button_pressed() -> void:
|
||
self_click.emit(self)
|
||
pass # Replace with function body.
|