mlpcardgame/Scenes/Components/Card.gd

41 lines
1.1 KiB
GDScript3
Raw Normal View History

2019-05-04 21:42:07 +00:00
extends Spatial
2019-05-04 22:01:00 +00:00
signal card_selected()
signal card_unselected()
2019-05-05 19:19:39 +00:00
signal card_picked()
signal card_dropped()
2019-05-04 21:42:07 +00:00
2019-05-04 23:18:55 +00:00
var lifted := false
2019-05-05 19:19:39 +00:00
export var inHand := false
2019-05-04 23:18:55 +00:00
onready var animation := $Border/AnimationPlayer
2019-05-04 21:42:07 +00:00
func _mouse_hover():
2019-05-05 19:19:39 +00:00
if inHand:
animation.play("focus")
2019-05-04 22:01:00 +00:00
emit_signal("card_selected")
2019-05-04 21:42:07 +00:00
2019-05-04 22:01:00 +00:00
func _mouse_blur():
2019-05-05 19:19:39 +00:00
if inHand:
animation.play("blur")
2019-05-04 23:18:55 +00:00
emit_signal("card_unselected")
func _input_event(camera, event, click_position, click_normal, shape_idx):
if event is InputEventMouseButton and event.button_index == BUTTON_LEFT:
if event.pressed:
lifted = true
animation.play("lift")
2019-05-05 19:19:39 +00:00
emit_signal("card_picked")
2019-05-04 23:18:55 +00:00
else:
lifted = false
animation.play_backwards("lift")
2019-05-05 19:19:39 +00:00
emit_signal("card_dropped")
2019-05-04 23:18:55 +00:00
if lifted and event is InputEventMouseMotion:
var origin: Vector3 = camera.project_ray_origin(event.position)
var direction: Vector3 = camera.project_ray_normal(event.position)
2019-05-05 19:19:39 +00:00
if inHand:
transform.origin = Vector3.ZERO + Vector3.RIGHT * direction * 3.0
else:
var denom := Vector3.UP.dot(direction)
var t: float = (-camera.transform.origin).dot(Vector3.UP) / denom;
transform.origin = origin + direction * t