You can drag cards now!

This commit is contained in:
Hamcha 2019-05-05 01:18:55 +02:00
parent a162d12aba
commit c2318a92d1
Signed by: hamcha
GPG key ID: A40413D21021EAEE
3 changed files with 53 additions and 3 deletions

View file

@ -30,7 +30,6 @@ material/0 = null
[node name="Card" parent="." instance=ExtResource( 5 )] [node name="Card" parent="." instance=ExtResource( 5 )]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 1.55435, -0.001, 1.13711 ) transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 1.55435, -0.001, 1.13711 )
input_capture_on_drag = false
[connection signal="card_selected" from="Card" to="BoardUI" method="_card_selected" binds= [ "ff6" ]] [connection signal="card_selected" from="Card" to="BoardUI" method="_card_selected" binds= [ "ff6" ]]
[connection signal="card_unselected" from="Card" to="BoardUI" method="_card_unselected"] [connection signal="card_unselected" from="Card" to="BoardUI" method="_card_unselected"]
[connection signal="mouse_exited" from="Card" to="." method="_mouse_blur"] [connection signal="mouse_exited" from="Card" to="." method="_mouse_blur"]

View file

@ -3,8 +3,27 @@ extends Spatial
signal card_selected() signal card_selected()
signal card_unselected() signal card_unselected()
var lifted := false
onready var animation := $Border/AnimationPlayer
func _mouse_hover(): func _mouse_hover():
emit_signal("card_selected") emit_signal("card_selected")
func _mouse_blur(): func _mouse_blur():
emit_signal("card_unselected") 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")
else:
lifted = false
animation.play_backwards("lift")
if lifted and event is InputEventMouseMotion:
var origin: Vector3 = camera.project_ray_origin(event.position)
var direction: Vector3 = camera.project_ray_normal(event.position)
var denom := Vector3.UP.dot(direction)
var t: float = (-camera.transform.origin).dot(Vector3.UP) / denom;
transform.origin = origin + direction * t

View file

@ -1,4 +1,4 @@
[gd_scene load_steps=10 format=2] [gd_scene load_steps=11 format=2]
[ext_resource path="res://Scenes/Components/Card.gd" type="Script" id=1] [ext_resource path="res://Scenes/Components/Card.gd" type="Script" id=1]
[ext_resource path="res://MLPAssets/Models/cardborder.obj" type="ArrayMesh" id=2] [ext_resource path="res://MLPAssets/Models/cardborder.obj" type="ArrayMesh" id=2]
@ -23,6 +23,35 @@ tracks/0/keys = {
"values": [ Vector3( 0, 0, 0 ), Vector3( 0, -90, 0 ) ] "values": [ Vector3( 0, 0, 0 ), Vector3( 0, -90, 0 ) ]
} }
[sub_resource type="Animation" id=6]
resource_name = "lift"
length = 0.3
step = 0.05
tracks/0/type = "value"
tracks/0/path = NodePath(".:translation")
tracks/0/interp = 2
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"times": PoolRealArray( 0, 0.3 ),
"transitions": PoolRealArray( 0.965936, 0.870551 ),
"update": 0,
"values": [ Vector3( 0, 0, 0 ), Vector3( 0, 0.15, 0 ) ]
}
tracks/1/type = "value"
tracks/1/path = NodePath(".:rotation_degrees")
tracks/1/interp = 2
tracks/1/loop_wrap = true
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/keys = {
"times": PoolRealArray( 0, 0.05, 0.15, 0.3 ),
"transitions": PoolRealArray( 0.392292, 0.392292, 1, 0.329877 ),
"update": 0,
"values": [ Vector3( 0, 0, 0 ), Vector3( 0, 0, 0 ), Vector3( 0, 0, 9.73853 ), Vector3( 0, 0, 0 ) ]
}
[sub_resource type="Animation" id=3] [sub_resource type="Animation" id=3]
length = 0.5 length = 0.5
step = 0.05 step = 0.05
@ -68,16 +97,19 @@ transform = Transform( 1, 0, 0, 0, 1.17955, 0, 0, 0, 1, 0, 0, 0 )
shape = SubResource( 1 ) shape = SubResource( 1 )
[node name="Border" type="MeshInstance" parent="."] [node name="Border" type="MeshInstance" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0 )
mesh = ExtResource( 2 ) mesh = ExtResource( 2 )
material/0 = ExtResource( 3 ) material/0 = ExtResource( 3 )
[node name="AnimationPlayer" type="AnimationPlayer" parent="Border"] [node name="AnimationPlayer" type="AnimationPlayer" parent="Border"]
anims/flip = SubResource( 2 ) anims/flip = SubResource( 2 )
anims/lift = SubResource( 6 )
anims/tap = SubResource( 3 ) anims/tap = SubResource( 3 )
[node name="CardImage" type="MeshInstance" parent="Border"] [node name="CardImage" type="MeshInstance" parent="Border"]
transform = Transform( 0.318962, 0, 0, 0, 1, 0, 0, 0, 0.450381, 0, 0.007, 0 ) transform = Transform( 0.318962, 0, 0, 0, 1, 0, 0, 0, 0.450381, 0, 0.007, 0 )
mesh = SubResource( 4 ) mesh = SubResource( 4 )
material/0 = SubResource( 5 ) material/0 = SubResource( 5 )
[connection signal="input_event" from="." to="." method="_input_event"]
[connection signal="mouse_entered" from="." to="." method="_mouse_hover"] [connection signal="mouse_entered" from="." to="." method="_mouse_hover"]
[connection signal="mouse_exited" from="." to="." method="_mouse_blur"] [connection signal="mouse_exited" from="." to="." method="_mouse_blur"]