60 lines
No EOL
1.6 KiB
GDScript
60 lines
No EOL
1.6 KiB
GDScript
extends Control
|
|
class_name CardPreview
|
|
|
|
const PREVIEW_WIDTH = 150
|
|
const PREVIEW_HEIGHT = 200
|
|
const SCREEN_MARGIN = 20
|
|
|
|
var currentCard: Card = null
|
|
var previewPanel: CardPreviewPanel
|
|
|
|
var movesRemainingLabel: Label
|
|
func _init() -> void:
|
|
|
|
|
|
previewPanel = preload("res://card_preview_panel.tscn").instantiate()
|
|
|
|
|
|
position = Vector2(0, 0)
|
|
|
|
previewPanel.hide()
|
|
|
|
# Add the preview panel as a child
|
|
add_child(previewPanel)
|
|
|
|
# Add a custom label for moves remaining that we'll show/hide as needed
|
|
movesRemainingLabel = Label.new()
|
|
movesRemainingLabel.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
|
|
movesRemainingLabel.add_theme_font_size_override("font_size", 14)
|
|
movesRemainingLabel.visible = false
|
|
|
|
# Add the label to the preview panel's content
|
|
var content = previewPanel.get_node("CardContent")
|
|
if content:
|
|
content.add_child(movesRemainingLabel)
|
|
|
|
func show_card_preview(card: Card) -> void:
|
|
if card == null:
|
|
hide_preview()
|
|
return
|
|
|
|
currentCard = card
|
|
|
|
# Use the preview_card method from CardPreviewPanel
|
|
previewPanel.preview_card(card)
|
|
|
|
# Since we're showing a new card, hide the moves remaining label
|
|
movesRemainingLabel.visible = false
|
|
|
|
func hide_preview() -> void:
|
|
previewPanel.hide_preview()
|
|
currentCard = null
|
|
movesRemainingLabel.visible = false
|
|
|
|
func update_moves_remaining(moves: int) -> void:
|
|
if currentCard == null:
|
|
return
|
|
|
|
# Update and show the moves remaining label
|
|
movesRemainingLabel.text = "Moves remaining this turn: " + str(moves)
|
|
movesRemainingLabel.visible = true |