client: cards can now be clicked
This commit is contained in:
+14
-6
@@ -17,15 +17,23 @@ func _ready() -> void:
|
|||||||
|
|
||||||
func move_to(new_x_position: float) -> void:
|
func move_to(new_x_position: float) -> void:
|
||||||
#self.position.x = new_x_position
|
#self.position.x = new_x_position
|
||||||
var tween = create_tween()
|
_get_new_tween().tween_property(self, "position:x", new_x_position, move_duration)
|
||||||
tween.set_trans(Tween.TRANS_BACK)
|
|
||||||
tween.set_ease(Tween.EASE_OUT)
|
func select() -> void:
|
||||||
tween.tween_property(self, "position:x", new_x_position, move_duration)
|
_get_new_tween().tween_property(self, "position:y", 0.36, move_duration)
|
||||||
|
|
||||||
|
func unselect() -> void:
|
||||||
|
_get_new_tween().tween_property(self, "position:y", 0.0, move_duration)
|
||||||
|
|
||||||
func set_front_texture(texture: Texture) -> void:
|
func set_front_texture(texture: Texture) -> void:
|
||||||
card_mesh.get_surface_override_material(0).albedo_texture = front_texture
|
card_mesh.get_surface_override_material(0).albedo_texture = front_texture
|
||||||
|
|
||||||
|
func _get_new_tween() -> Tween:
|
||||||
|
var tween = create_tween()
|
||||||
|
tween.set_trans(Tween.TRANS_BACK)
|
||||||
|
tween.set_ease(Tween.EASE_OUT)
|
||||||
|
return tween
|
||||||
|
|
||||||
func _on_input_event(camera: Node, event: InputEvent, event_position: Vector3, normal: Vector3, shape_idx: int) -> void:
|
func _on_input_event(camera: Node, event: InputEvent, event_position: Vector3, normal: Vector3, shape_idx: int) -> void:
|
||||||
if event.is_action_pressed("left_mouse_button"):
|
if event.is_action_released("left_mouse_button"):
|
||||||
print("yahaha!")
|
|
||||||
card_clicked.emit(self)
|
card_clicked.emit(self)
|
||||||
|
|||||||
+10
-3
@@ -16,13 +16,15 @@ extends Node3D
|
|||||||
|
|
||||||
@export_range(0, 20, 0.1, "radians_as_degrees") var card_angle: float
|
@export_range(0, 20, 0.1, "radians_as_degrees") var card_angle: float
|
||||||
|
|
||||||
|
var _selected_card: PlayingCard = null
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
_arrange_cards()
|
_arrange_cards()
|
||||||
for i in test_card_count:
|
for i in test_card_count:
|
||||||
var card: PlayingCard = card_scene.instantiate()
|
var card: PlayingCard = card_scene.instantiate()
|
||||||
card.card_clicked.connect(_on_card_clicked)
|
card.card_clicked.connect(_on_card_clicked)
|
||||||
add_card(card)
|
add_card(card)
|
||||||
await get_tree().create_timer(0.24).timeout
|
await get_tree().create_timer(0.2).timeout
|
||||||
|
|
||||||
func add_card(card: PlayingCard) -> void:
|
func add_card(card: PlayingCard) -> void:
|
||||||
self.add_child(card)
|
self.add_child(card)
|
||||||
@@ -41,7 +43,6 @@ func _arrange_cards() -> void:
|
|||||||
var desired_width: float = (card_distance * (cards.size() - 1))
|
var desired_width: float = (card_distance * (cards.size() - 1))
|
||||||
var card_position = -desired_width / 2.0
|
var card_position = -desired_width / 2.0
|
||||||
for card in cards:
|
for card in cards:
|
||||||
#card.position.x = card_position
|
|
||||||
card.move_to(card_position)
|
card.move_to(card_position)
|
||||||
card_position += card_distance
|
card_position += card_distance
|
||||||
card.rotation.y = card_angle
|
card.rotation.y = card_angle
|
||||||
@@ -50,4 +51,10 @@ func _get_card_distance(card_count: int) -> float:
|
|||||||
return card_distance_min + ((card_distance_max - card_distance_min) * (1.0 - (float(card_count) / 19.0)))
|
return card_distance_min + ((card_distance_max - card_distance_min) * (1.0 - (float(card_count) / 19.0)))
|
||||||
|
|
||||||
func _on_card_clicked(playing_card: PlayingCard) -> void:
|
func _on_card_clicked(playing_card: PlayingCard) -> void:
|
||||||
pass
|
if _selected_card:
|
||||||
|
_selected_card.unselect()
|
||||||
|
if _selected_card == playing_card:
|
||||||
|
_selected_card = null
|
||||||
|
else:
|
||||||
|
_selected_card = playing_card
|
||||||
|
playing_card.select()
|
||||||
|
|||||||
@@ -5,6 +5,6 @@
|
|||||||
|
|
||||||
[node name="PlayerHand" type="Node3D"]
|
[node name="PlayerHand" type="Node3D"]
|
||||||
script = ExtResource("1_ank64")
|
script = ExtResource("1_ank64")
|
||||||
test_card_count = 20
|
test_card_count = 5
|
||||||
card_scene = ExtResource("2_11xsc")
|
card_scene = ExtResource("2_11xsc")
|
||||||
card_angle = 0.125664
|
card_angle = 0.125664
|
||||||
|
|||||||
Reference in New Issue
Block a user