Add context menu and turning cards
This commit is contained in:
parent
2b6b0bde35
commit
2ec5792b0f
5 changed files with 36 additions and 2 deletions
|
@ -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
|
||||
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
|
|
@ -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")
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)))
|
|
@ -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": ""
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue