From a162d12abaa8c72f01a56fd637d201618cb67e98 Mon Sep 17 00:00:00 2001 From: Hamcha Date: Sun, 5 May 2019 00:01:00 +0200 Subject: [PATCH] Card hover works..ish! --- MLPAssets/Background/boardbg.jpg.import | 2 +- MLPAssets/ExampleCard/ff6.jpg.import | 2 +- MLPAssets/Textures/CardBack.png.import | 2 +- Scenes/Board.tscn | 4 +++ Scenes/BoardUI.tscn | 12 ++++++--- Scenes/Components/Card.gd | 8 +++--- Scenes/Components/Card.tscn | 35 ++++++++++++------------- Scenes/Scripts/Board.gd | 12 +-------- Scenes/Scripts/BoardUI.gd | 9 +++++++ 9 files changed, 47 insertions(+), 39 deletions(-) create mode 100644 Scenes/Scripts/BoardUI.gd diff --git a/MLPAssets/Background/boardbg.jpg.import b/MLPAssets/Background/boardbg.jpg.import index c6a88e6..340636e 100644 --- a/MLPAssets/Background/boardbg.jpg.import +++ b/MLPAssets/Background/boardbg.jpg.import @@ -25,7 +25,7 @@ flags/repeat=true flags/filter=true flags/mipmaps=true flags/anisotropic=false -flags/srgb=2 +flags/srgb=1 process/fix_alpha_border=true process/premult_alpha=false process/HDR_as_SRGB=false diff --git a/MLPAssets/ExampleCard/ff6.jpg.import b/MLPAssets/ExampleCard/ff6.jpg.import index ddb4d3f..8d69993 100644 --- a/MLPAssets/ExampleCard/ff6.jpg.import +++ b/MLPAssets/ExampleCard/ff6.jpg.import @@ -25,7 +25,7 @@ flags/repeat=true flags/filter=true flags/mipmaps=true flags/anisotropic=false -flags/srgb=2 +flags/srgb=1 process/fix_alpha_border=true process/premult_alpha=false process/HDR_as_SRGB=false diff --git a/MLPAssets/Textures/CardBack.png.import b/MLPAssets/Textures/CardBack.png.import index 76c5dad..203f942 100644 --- a/MLPAssets/Textures/CardBack.png.import +++ b/MLPAssets/Textures/CardBack.png.import @@ -23,7 +23,7 @@ flags/repeat=true flags/filter=true flags/mipmaps=true flags/anisotropic=false -flags/srgb=2 +flags/srgb=1 process/fix_alpha_border=true process/premult_alpha=false process/HDR_as_SRGB=false diff --git a/Scenes/Board.tscn b/Scenes/Board.tscn index d473777..3318f59 100644 --- a/Scenes/Board.tscn +++ b/Scenes/Board.tscn @@ -30,3 +30,7 @@ material/0 = null [node name="Card" parent="." instance=ExtResource( 5 )] 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"] diff --git a/Scenes/BoardUI.tscn b/Scenes/BoardUI.tscn index b5e42ca..4005f5c 100644 --- a/Scenes/BoardUI.tscn +++ b/Scenes/BoardUI.tscn @@ -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] resource_name = "fade ui card" @@ -46,14 +47,17 @@ tracks/2/keys = { [node name="BoardUI" type="Control"] anchor_right = 1.0 anchor_bottom = 1.0 +mouse_filter = 2 +script = ExtResource( 1 ) [node name="TextureRect" type="TextureRect" parent="."] +visible = false +modulate = Color( 1, 1, 1, 0 ) margin_left = 40.0 -margin_top = 40.0 margin_right = 384.0 margin_bottom = 520.0 rect_scale = Vector2( 0.8, 0.8 ) -texture = ExtResource( 1 ) +texture = ExtResource( 2 ) stretch_mode = 5 [node name="AnimationPlayer" type="AnimationPlayer" parent="."] diff --git a/Scenes/Components/Card.gd b/Scenes/Components/Card.gd index dd79f9e..28ae88a 100644 --- a/Scenes/Components/Card.gd +++ b/Scenes/Components/Card.gd @@ -1,8 +1,10 @@ extends Spatial +signal card_selected() +signal card_unselected() func _mouse_hover(): - print("MOUSE HOVER") + emit_signal("card_selected") -func _area_input(camera, event, click_position, click_normal, shape_idx): - breakpoint +func _mouse_blur(): + emit_signal("card_unselected") \ No newline at end of file diff --git a/Scenes/Components/Card.tscn b/Scenes/Components/Card.tscn index 907e051..12ff7d3 100644 --- a/Scenes/Components/Card.tscn +++ b/Scenes/Components/Card.tscn @@ -5,7 +5,10 @@ [ext_resource path="res://MLPAssets/Models/cardborder.material" type="Material" id=3] [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 tracks/0/type = "value" tracks/0/path = NodePath(".:rotation_degrees") @@ -20,7 +23,7 @@ tracks/0/keys = { "values": [ Vector3( 0, 0, 0 ), Vector3( 0, -90, 0 ) ] } -[sub_resource type="Animation" id=2] +[sub_resource type="Animation" id=3] length = 0.5 step = 0.05 tracks/0/type = "value" @@ -48,7 +51,7 @@ tracks/1/keys = { "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] flags_unshaded = true @@ -56,29 +59,25 @@ albedo_texture = ExtResource( 4 ) uv1_scale = Vector3( 0.9, 0.9, 1 ) uv1_offset = Vector3( 0.05, 0.05, 0 ) -[sub_resource type="BoxShape" id=6] -extents = Vector3( 0.367502, 0.0283921, 0.49861 ) - -[node name="Card" type="Spatial"] +[node name="Card" type="Area"] +input_capture_on_drag = true 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="."] mesh = ExtResource( 2 ) material/0 = ExtResource( 3 ) [node name="AnimationPlayer" type="AnimationPlayer" parent="Border"] -anims/flip = SubResource( 7 ) -anims/tap = SubResource( 2 ) +anims/flip = SubResource( 2 ) +anims/tap = SubResource( 3 ) [node name="CardImage" type="MeshInstance" parent="Border"] 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 ) - -[node name="Area" type="Area" parent="."] -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"] +[connection signal="mouse_entered" from="." to="." method="_mouse_hover"] +[connection signal="mouse_exited" from="." to="." method="_mouse_blur"] diff --git a/Scenes/Scripts/Board.gd b/Scenes/Scripts/Board.gd index 2b92cf0..2d535f9 100644 --- a/Scenes/Scripts/Board.gd +++ b/Scenes/Scripts/Board.gd @@ -21,14 +21,4 @@ func _process(delta: float): if Input.is_action_pressed("pan"): var mouseDelta := get_viewport().get_mouse_position() - mouseOrigin var mousePos: Vector2 = mouseDelta * 0.0096 * (1-camera.getZoomLevel()/5) # Magic numbers everywhere - 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) \ No newline at end of file + camera.transform.origin = lastCameraTransform.origin - Vector3(mousePos.x, 0, mousePos.y) \ No newline at end of file diff --git a/Scenes/Scripts/BoardUI.gd b/Scenes/Scripts/BoardUI.gd new file mode 100644 index 0000000..2125cbf --- /dev/null +++ b/Scenes/Scripts/BoardUI.gd @@ -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")