Card hover works..ish!

This commit is contained in:
Hamcha 2019-05-05 00:01:00 +02:00
parent ceb53bb4a2
commit a162d12aba
Signed by: hamcha
GPG key ID: A40413D21021EAEE
9 changed files with 47 additions and 39 deletions

View file

@ -25,7 +25,7 @@ flags/repeat=true
flags/filter=true flags/filter=true
flags/mipmaps=true flags/mipmaps=true
flags/anisotropic=false flags/anisotropic=false
flags/srgb=2 flags/srgb=1
process/fix_alpha_border=true process/fix_alpha_border=true
process/premult_alpha=false process/premult_alpha=false
process/HDR_as_SRGB=false process/HDR_as_SRGB=false

View file

@ -25,7 +25,7 @@ flags/repeat=true
flags/filter=true flags/filter=true
flags/mipmaps=true flags/mipmaps=true
flags/anisotropic=false flags/anisotropic=false
flags/srgb=2 flags/srgb=1
process/fix_alpha_border=true process/fix_alpha_border=true
process/premult_alpha=false process/premult_alpha=false
process/HDR_as_SRGB=false process/HDR_as_SRGB=false

View file

@ -23,7 +23,7 @@ flags/repeat=true
flags/filter=true flags/filter=true
flags/mipmaps=true flags/mipmaps=true
flags/anisotropic=false flags/anisotropic=false
flags/srgb=2 flags/srgb=1
process/fix_alpha_border=true process/fix_alpha_border=true
process/premult_alpha=false process/premult_alpha=false
process/HDR_as_SRGB=false process/HDR_as_SRGB=false

View file

@ -30,3 +30,7 @@ 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_unselected" from="Card" to="BoardUI" method="_card_unselected"]
[connection signal="mouse_exited" from="Card" to="." method="_mouse_blur"]

View file

@ -1,6 +1,7 @@
[gd_scene load_steps=3 format=2] [gd_scene load_steps=4 format=2]
[ext_resource path="res://MLPAssets/ExampleCard/ff6.jpg" type="Texture" id=1] [ext_resource path="res://Scenes/Scripts/BoardUI.gd" type="Script" id=1]
[ext_resource path="res://MLPAssets/ExampleCard/ff6.jpg" type="Texture" id=2]
[sub_resource type="Animation" id=1] [sub_resource type="Animation" id=1]
resource_name = "fade ui card" resource_name = "fade ui card"
@ -46,14 +47,17 @@ tracks/2/keys = {
[node name="BoardUI" type="Control"] [node name="BoardUI" type="Control"]
anchor_right = 1.0 anchor_right = 1.0
anchor_bottom = 1.0 anchor_bottom = 1.0
mouse_filter = 2
script = ExtResource( 1 )
[node name="TextureRect" type="TextureRect" parent="."] [node name="TextureRect" type="TextureRect" parent="."]
visible = false
modulate = Color( 1, 1, 1, 0 )
margin_left = 40.0 margin_left = 40.0
margin_top = 40.0
margin_right = 384.0 margin_right = 384.0
margin_bottom = 520.0 margin_bottom = 520.0
rect_scale = Vector2( 0.8, 0.8 ) rect_scale = Vector2( 0.8, 0.8 )
texture = ExtResource( 1 ) texture = ExtResource( 2 )
stretch_mode = 5 stretch_mode = 5
[node name="AnimationPlayer" type="AnimationPlayer" parent="."] [node name="AnimationPlayer" type="AnimationPlayer" parent="."]

View file

@ -1,8 +1,10 @@
extends Spatial extends Spatial
signal card_selected()
signal card_unselected()
func _mouse_hover(): func _mouse_hover():
print("MOUSE HOVER") emit_signal("card_selected")
func _area_input(camera, event, click_position, click_normal, shape_idx): func _mouse_blur():
breakpoint emit_signal("card_unselected")

View file

@ -5,7 +5,10 @@
[ext_resource path="res://MLPAssets/Models/cardborder.material" type="Material" id=3] [ext_resource path="res://MLPAssets/Models/cardborder.material" type="Material" id=3]
[ext_resource path="res://MLPAssets/ExampleCard/ff6.jpg" type="Texture" id=4] [ext_resource path="res://MLPAssets/ExampleCard/ff6.jpg" type="Texture" id=4]
[sub_resource type="Animation" id=7] [sub_resource type="BoxShape" id=1]
extents = Vector3( 0.367502, 0.0309108, 0.49861 )
[sub_resource type="Animation" id=2]
length = 0.3 length = 0.3
tracks/0/type = "value" tracks/0/type = "value"
tracks/0/path = NodePath(".:rotation_degrees") tracks/0/path = NodePath(".:rotation_degrees")
@ -20,7 +23,7 @@ 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=2] [sub_resource type="Animation" id=3]
length = 0.5 length = 0.5
step = 0.05 step = 0.05
tracks/0/type = "value" tracks/0/type = "value"
@ -48,7 +51,7 @@ tracks/1/keys = {
"values": [ Vector3( 0, 0, 0 ), Vector3( 0, 0, 180 ) ] "values": [ Vector3( 0, 0, 0 ), Vector3( 0, 0, 180 ) ]
} }
[sub_resource type="PlaneMesh" id=8] [sub_resource type="PlaneMesh" id=4]
[sub_resource type="SpatialMaterial" id=5] [sub_resource type="SpatialMaterial" id=5]
flags_unshaded = true flags_unshaded = true
@ -56,29 +59,25 @@ albedo_texture = ExtResource( 4 )
uv1_scale = Vector3( 0.9, 0.9, 1 ) uv1_scale = Vector3( 0.9, 0.9, 1 )
uv1_offset = Vector3( 0.05, 0.05, 0 ) uv1_offset = Vector3( 0.05, 0.05, 0 )
[sub_resource type="BoxShape" id=6] [node name="Card" type="Area"]
extents = Vector3( 0.367502, 0.0283921, 0.49861 ) input_capture_on_drag = true
[node name="Card" type="Spatial"]
script = ExtResource( 1 ) script = ExtResource( 1 )
[node name="CollisionShape" type="CollisionShape" parent="."]
transform = Transform( 1, 0, 0, 0, 1.17955, 0, 0, 0, 1, 0, 0, 0 )
shape = SubResource( 1 )
[node name="Border" type="MeshInstance" parent="."] [node name="Border" type="MeshInstance" parent="."]
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( 7 ) anims/flip = SubResource( 2 )
anims/tap = SubResource( 2 ) 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( 8 ) mesh = SubResource( 4 )
material/0 = SubResource( 5 ) material/0 = SubResource( 5 )
[connection signal="mouse_entered" from="." to="." method="_mouse_hover"]
[node name="Area" type="Area" parent="."] [connection signal="mouse_exited" from="." to="." method="_mouse_blur"]
input_capture_on_drag = true
[node name="CollisionShape" type="CollisionShape" parent="Area"]
shape = SubResource( 6 )
[connection signal="input_event" from="Area" to="." method="_area_input"]
[connection signal="mouse_entered" from="Area" to="." method="_mouse_hover"]

View file

@ -22,13 +22,3 @@ func _process(delta: float):
var mouseDelta := get_viewport().get_mouse_position() - mouseOrigin var mouseDelta := get_viewport().get_mouse_position() - mouseOrigin
var mousePos: Vector2 = mouseDelta * 0.0096 * (1-camera.getZoomLevel()/5) # Magic numbers everywhere var mousePos: Vector2 = mouseDelta * 0.0096 * (1-camera.getZoomLevel()/5) # Magic numbers everywhere
camera.transform.origin = lastCameraTransform.origin - Vector3(mousePos.x, 0, mousePos.y) camera.transform.origin = lastCameraTransform.origin - Vector3(mousePos.x, 0, mousePos.y)
func _physics_process(delta: float):
# Raycast mouse to check for hover
var mousePos := get_viewport().get_mouse_position()
var from: Vector3 = camera.project_ray_origin(mousePos)
var to: Vector3 = from + camera.project_ray_normal(mousePos) * 1000
var space_state := get_world().direct_space_state
var result := space_state.intersect_ray(from, to)
if result.size() > 0:
print(result)

View file

@ -0,0 +1,9 @@
extends Control
onready var animation = $AnimationPlayer
func _card_selected(cardID):
animation.play("fade ui card")
func _card_unselected():
animation.play_backwards("fade ui card")