diff --git a/Scenes/Components/Card.gd b/Scenes/Components/Card.gd index 26b6a80..234edeb 100644 --- a/Scenes/Components/Card.gd +++ b/Scenes/Components/Card.gd @@ -6,10 +6,12 @@ signal card_selected() signal card_unselected() signal card_picked() signal card_dropped() +signal card_menu() var clicked := false var exhausted := false var lifted := false +var flipped := false export var cardID := "" export var playerID := 0 export var inHand := false @@ -27,6 +29,7 @@ func _mouse_blur(): emit_signal("card_unselected") func _input_event(camera, event, click_position, click_normal, shape_idx): + # Mouse motion if clicked and event is InputEventMouseMotion: if not lifted: animation.play("lift") @@ -42,6 +45,11 @@ func _input_event(camera, event, click_position, click_normal, shape_idx): var denom := Vector3.UP.dot(direction) var t: float = (-camera.transform.origin).dot(Vector3.UP) / denom; transform.origin = origin + direction * t + # Right click + if event is InputEventMouseButton and event.pressed and event.button_index == BUTTON_RIGHT: + # Show menu + emit_signal("card_menu") + # Left click if event is InputEventMouseButton and event.button_index == BUTTON_LEFT: # Update click status clicked = event.pressed @@ -62,4 +70,14 @@ func _input_event(camera, event, click_position, click_normal, shape_idx): exhausted = false else: animation.play("tap") - exhausted = true \ No newline at end of file + exhausted = true + +func _menu_action(id: int): + match id: + 0: # Flip + if flipped: + animation.play_backwards("flip") + flipped = false + else: + animation.play("flip") + flipped = true \ No newline at end of file diff --git a/Scenes/Components/Card.tscn b/Scenes/Components/Card.tscn index 348bfa5..cf68294 100644 --- a/Scenes/Components/Card.tscn +++ b/Scenes/Components/Card.tscn @@ -54,7 +54,7 @@ tracks/0/keys = { "times": PoolRealArray( 0, 0.25, 0.5 ), "transitions": PoolRealArray( 1, 1, 1 ), "update": 0, -"values": [ Vector3( 0, 0, 0 ), Vector3( 0, 0.5, 0 ), Vector3( 0, 0, 0 ) ] +"values": [ Vector3( 0, 0, 0 ), Vector3( 0, 0.5, 0 ), Vector3( 0, 0.01, 0 ) ] } tracks/1/type = "value" tracks/1/path = NodePath(".:rotation_degrees") diff --git a/Scenes/Scripts/Board.gd b/Scenes/Scripts/Board.gd index 225c5f0..0fba8d3 100644 --- a/Scenes/Scripts/Board.gd +++ b/Scenes/Scripts/Board.gd @@ -1,5 +1,7 @@ extends Spatial +class_name Board + onready var CardTemplate := preload("res://Scenes/Components/Card.tscn") onready var camera := $Camera @@ -68,6 +70,7 @@ func add_card(cardID: String, playerID: int, inHand: bool): card.connect("card_picked", self, "_card_picked", [card]) card.connect("card_selected", ui, "_card_selected", [card]) card.connect("card_unselected", ui, "_card_unselected", [card]) + card.connect("card_menu", ui, "show_card_menu", [card]) if inHand: # TODO if player != me, put in opponent's hand hand.add_child(card) diff --git a/Scenes/Scripts/BoardUI.gd b/Scenes/Scripts/BoardUI.gd index 2a691e6..a616f68 100644 --- a/Scenes/Scripts/BoardUI.gd +++ b/Scenes/Scripts/BoardUI.gd @@ -7,3 +7,10 @@ func _card_selected(card: Card): func _card_unselected(card: Card): animation.play_backwards("fade ui card") + +func show_card_menu(card): + var menu := PopupMenu.new() + menu.add_item("Flip", 0) + menu.connect("id_pressed", card, "_menu_action") + add_child(menu) + menu.popup(Rect2(get_viewport().get_mouse_position(), Vector2(100,10))) \ No newline at end of file diff --git a/project.godot b/project.godot index 64977d9..197e966 100644 --- a/project.godot +++ b/project.godot @@ -10,11 +10,17 @@ config_version=4 _global_script_classes=[ { "base": "Spatial", +"class": "Board", +"language": "GDScript", +"path": "res://Scenes/Scripts/Board.gd" +}, { +"base": "Spatial", "class": "Card", "language": "GDScript", "path": "res://Scenes/Components/Card.gd" } ] _global_script_class_icons={ +"Board": "", "Card": "" }