47 lines
No EOL
1.2 KiB
GDScript
47 lines
No EOL
1.2 KiB
GDScript
extends Control
|
|
|
|
signal card_selected()
|
|
signal card_unselected()
|
|
signal card_hover(position)
|
|
signal card_clicked()
|
|
signal loaded()
|
|
|
|
var cardID := "" setget set_cardid
|
|
var ready = false
|
|
|
|
func set_cardid(val: String):
|
|
cardID = val
|
|
if ready and cardID != "":
|
|
Resources.get_card(val, self, "_card_fetched")
|
|
|
|
func _ready():
|
|
if cardID != "":
|
|
Resources.get_card(cardID, self, "_card_fetched")
|
|
ready = true
|
|
|
|
func _gui_input(event):
|
|
# Left click
|
|
if event is InputEventMouseButton and event.button_index == BUTTON_LEFT and event.pressed:
|
|
accept_event()
|
|
emit_signal("card_clicked")
|
|
if event is InputEventMouseMotion:
|
|
emit_signal("card_hover", event.position)
|
|
|
|
func _mouse_entered():
|
|
$AnimationPlayer.play("glow")
|
|
emit_signal("card_selected")
|
|
|
|
func _mouse_exited():
|
|
$AnimationPlayer.play_backwards("glow")
|
|
emit_signal("card_unselected")
|
|
|
|
# warning-ignore:unused_argument
|
|
func _card_fetched(result: int, response_code: int, headers: PoolStringArray, body: PoolByteArray):
|
|
assert(result == HTTPRequest.RESULT_SUCCESS)
|
|
var img = Image.new()
|
|
var err = img.load_webp_from_buffer(body)
|
|
assert(err == OK)
|
|
var texture := ImageTexture.new()
|
|
texture.create_from_image(img)
|
|
$TextureRect.texture = texture
|
|
emit_signal("loaded") |