challenge-editor/scene/bag_side_card.gd
2024-10-09 20:34:18 +08:00

57 lines
1.6 KiB
GDScript

extends TextureRect
class_name BagSideCard
const BAG_SIDE_CARD_INTRODUCTION = preload("res://scene/bag_side_card_introduction.tscn")
var is_mouse_enter:bool=false
var equip_index:int=0
signal click(data:Dictionary)
var data:Dictionary={
"texture":"test_character_tsubaki"
}
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
pass
func _input(event: InputEvent) -> void:
if event.is_action_pressed("mouse_left") and is_mouse_enter:
click.emit(data)
func _get_drag_data(at_position: Vector2) -> Variant:
var texture_rect=TextureRect.new()
texture_rect.texture=Database.get_texture(data["texture"])
texture_rect.expand_mode=TextureRect.EXPAND_IGNORE_SIZE
texture_rect.stretch_mode=TextureRect.STRETCH_KEEP_ASPECT_CENTERED
texture_rect.size=self.size
set_drag_preview(texture_rect)
var new_data=data.duplicate(true)
new_data["ind"]=equip_index
return new_data
func set_data(_data:Dictionary):
data=_data
%face.texture=Database.get_texture(data["texture"])
pass
func _on_mouse_entered() -> void:
is_mouse_enter=true
click.emit(data)
pass # Replace with function body.
func _on_mouse_exited() -> void:
is_mouse_enter=false
pass # Replace with function body.
func _get_tooltip(at_position: Vector2) -> String:
return JSON.stringify(data)
pass
func _make_custom_tooltip(for_text: String) -> Object:
var new_card=BAG_SIDE_CARD_INTRODUCTION.instantiate()
new_card.data=JSON.parse_string(for_text)
return new_card
pass