diff --git a/Scenes/Board.tscn b/Scenes/Board.tscn index f5cd324..23d4ac6 100644 --- a/Scenes/Board.tscn +++ b/Scenes/Board.tscn @@ -37,11 +37,14 @@ material/0 = null [node name="Deck" parent="Cards" instance=ExtResource( 5 )] transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -4.30889, 0, 3.52858 ) title = "Deck" +zoneName = "player1.deck" [node name="Graveyard" parent="Cards" instance=ExtResource( 5 )] transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -5.23371, 0, 3.52858 ) title = "Graveyard" +zoneName = "player1.graveyard" [node name="Banished" parent="Cards" instance=ExtResource( 5 )] transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -5.23371, 0, 2.40401 ) title = "Banished" +zoneName = "player1.banished" diff --git a/Scenes/Components/Card.gd b/Scenes/Components/Card.gd index 6e80a7f..30867e3 100644 --- a/Scenes/Components/Card.gd +++ b/Scenes/Components/Card.gd @@ -1,4 +1,4 @@ -extends Spatial +extends Area class_name Card @@ -13,9 +13,11 @@ var clicked := false var exhausted := false var lifted := false var flipped := false -export var cardID := "" -export var playerID := 0 -export var inHand := false +var cardID := "" +var playerID := 0 +var inHand := false +var inZone := false +var zoneName = "" onready var animation := $Border/AnimationPlayer @@ -30,6 +32,8 @@ func _input_event(camera, event, click_position, click_normal, shape_idx): if clicked and event is InputEventMouseMotion: if not lifted: emit_signal("card_picked") + # Disable input for now + input_ray_pickable = false lifted = true var origin: Vector3 = camera.project_ray_origin(event.position) var direction: Vector3 = camera.project_ray_normal(event.position) @@ -37,6 +41,9 @@ func _input_event(camera, event, click_position, click_normal, shape_idx): translation = Vector3(direction.x * 3.0, 0.25, -0.25) # Fix rotation if coming from hand rotation = Vector3.ZERO + elif inZone: + translation = Vector3.ZERO + rotation = Vector3.ZERO else: var denom := Vector3.UP.dot(direction) var t: float = (-camera.transform.origin).dot(Vector3.UP) / denom; @@ -53,6 +60,7 @@ func _input_event(camera, event, click_position, click_normal, shape_idx): # Check for card dropped if not clicked and lifted: emit_signal("card_dropped") + input_ray_pickable = true lifted = false # Check double click diff --git a/Scenes/Components/Stack.gd b/Scenes/Components/Stack.gd index fe3c191..3c99c4c 100644 --- a/Scenes/Components/Stack.gd +++ b/Scenes/Components/Stack.gd @@ -1,9 +1,21 @@ -extends Spatial +extends Area + +class_name Stack + +signal hover() +signal blur() export var title: String +export var zoneName: String func _ready(): set_title(title) func set_title(title: String): - $LabelViewport/Label.text = title \ No newline at end of file + $LabelViewport/Label.text = title + +func _mouse_entered(): + emit_signal("hover") + +func _mouse_exited(): + emit_signal("blur") diff --git a/Scenes/Components/Stack.tscn b/Scenes/Components/Stack.tscn index d999e91..0e1af26 100644 --- a/Scenes/Components/Stack.tscn +++ b/Scenes/Components/Stack.tscn @@ -1,21 +1,28 @@ -[gd_scene load_steps=5 format=2] +[gd_scene load_steps=6 format=2] [ext_resource path="res://Scenes/Components/Stack.gd" type="Script" id=1] -[sub_resource type="DynamicFontData" id=2] +[sub_resource type="BoxShape" id=4] +extents = Vector3( 0.424389, 0.024053, 0.546632 ) + +[sub_resource type="DynamicFontData" id=1] font_path = "res://UIAssets/Fonts/Catamaran-Bold.ttf" -[sub_resource type="DynamicFont" id=3] +[sub_resource type="DynamicFont" id=2] outline_size = 2 outline_color = Color( 0, 0, 0, 0.54902 ) -font_data = SubResource( 2 ) +font_data = SubResource( 1 ) -[sub_resource type="ViewportTexture" id=1] +[sub_resource type="ViewportTexture" id=3] viewport_path = NodePath("LabelViewport") -[node name="Stack" type="Spatial"] +[node name="Stack" type="Area"] script = ExtResource( 1 ) +[node name="CollisionShape" type="CollisionShape" parent="."] +transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.0239744, 0 ) +shape = SubResource( 4 ) + [node name="CSGBox" type="CSGBox" parent="."] transform = Transform( 0.85598, 0, 0, 0, 1, 0, 0, 0, 0.871019, 0, 0, 0 ) width = 0.946586 @@ -50,11 +57,13 @@ usage = 0 [node name="Label" type="Label" parent="LabelViewport"] anchor_right = 1.0 anchor_bottom = 1.0 -custom_fonts/font = SubResource( 3 ) +custom_fonts/font = SubResource( 2 ) align = 1 valign = 1 [node name="LabelSprite" type="Sprite3D" parent="."] transform = Transform( 0.5853, 0.810817, -3.54419e-008, 0, -4.37114e-008, -1, -0.810817, 0.5853, -2.55843e-008, 1.05839e-009, 0.0298628, 7.64017e-010 ) -texture = SubResource( 1 ) +texture = SubResource( 3 ) region_rect = Rect2( 0, 0, 30, 30 ) +[connection signal="mouse_entered" from="." to="." method="_mouse_entered"] +[connection signal="mouse_exited" from="." to="." method="_mouse_exited"] diff --git a/Scenes/Scripts/Board.gd b/Scenes/Scripts/Board.gd index d901a79..c632d73 100644 --- a/Scenes/Scripts/Board.gd +++ b/Scenes/Scripts/Board.gd @@ -13,21 +13,18 @@ export var mouseHandThreshold = 0.85 var holdingCard: Card = null var focusedCard: Card = null +var currentZone: Stack = null var mouseOrigin: Vector2 var lastCameraTransform: Transform + +onready var zones: Dictionary = { + "player1.deck": $Cards/Deck, + "player1.banished": $Cards/Banished, + "player1.graveyard": $Cards/Graveyard +} func _ready(): - add_card("ff36", 0, true) - add_card("ff36", 0, true) - add_card("ff36", 0, true) - add_card("ff36", 0, true) - add_card("ff36", 0, true) - add_card("ff36", 0, true) - add_card("ff36", 0, true) - add_card("ff36", 0, true) - add_card("ff36", 0, true) - add_card("ff36", 0, true) add_card("ff36", 0, false) reorder_hand() @@ -52,9 +49,11 @@ func _process(delta: float): camera.transform.origin = lastCameraTransform.origin - Vector3(mousePos.x, 0, mousePos.y) # If holding a card, move it between board/hand if holdingCard != null: + # Check if we're selecting our hand while holding a card var relPos: Vector2 = absMousePos / get_viewport().size var xMargin = 1.0-HAND_SCREEN_PERC var selectingHand: bool = relPos.y > mouseHandThreshold and (relPos.x > xMargin/2 and relPos.x < (1.0-xMargin/2)) + # Move card in/out hand if selectingHand and not holdingCard.inHand: holdingCard.inHand = true call_deferred("reparent", holdingCard, cards, hand) @@ -62,6 +61,42 @@ func _process(delta: float): holdingCard.inHand = false call_deferred("reparent", holdingCard, hand, cards) + # Move card to/from zone + if currentZone != null: + if holdingCard.inZone: + if holdingCard.zoneName != currentZone.zoneName: + # Move from old zone to new + call_deferred("reparent", holdingCard, zones[holdingCard.zoneName], currentZone) + holdingCard.zoneName = currentZone.zoneName + else: + holdingCard.inZone = true + holdingCard.zoneName = currentZone.zoneName + if holdingCard.inHand: + call_deferred("reparent", holdingCard, hand, currentZone) + else: + call_deferred("reparent", holdingCard, cards, currentZone) + elif holdingCard.inZone: + # Move from zone to hand/field + if holdingCard.inHand: + call_deferred("reparent", holdingCard, zones[holdingCard.zoneName], hand) + else: + call_deferred("reparent", holdingCard, zones[holdingCard.zoneName], cards) + holdingCard.inZone = false + holdingCard.zoneName = "" + +func _physics_process(delta): + # Do some raycast magic that normal Godot events cannot get (like ignoring items) + var space_state := get_world().direct_space_state + var absMousePos := get_viewport().get_mouse_position() + var from: Vector3 = camera.project_ray_origin(absMousePos) + var to: Vector3 = from + camera.project_ray_normal(absMousePos) * 1000 + var result := space_state.intersect_ray(from, to, [self, holdingCard], 0x7FFFFFFF, true, true) + if result: + if result.collider is Stack: + currentZone = result.collider + else: + currentZone = null + func _card_picked(card: Card): holdingCard = card holdingCard.animation.play("lift") diff --git a/project.godot b/project.godot index 197e966..c958416 100644 --- a/project.godot +++ b/project.godot @@ -14,14 +14,20 @@ _global_script_classes=[ { "language": "GDScript", "path": "res://Scenes/Scripts/Board.gd" }, { -"base": "Spatial", +"base": "Area", "class": "Card", "language": "GDScript", "path": "res://Scenes/Components/Card.gd" +}, { +"base": "Area", +"class": "Stack", +"language": "GDScript", +"path": "res://Scenes/Components/Stack.gd" } ] _global_script_class_icons={ "Board": "", -"Card": "" +"Card": "", +"Stack": "" } [application]