164 lines
No EOL
4.8 KiB
GDScript
164 lines
No EOL
4.8 KiB
GDScript
extends Control
|
|
class_name DeckManagerScreen
|
|
|
|
signal back_pressed
|
|
|
|
# Node references
|
|
@onready var deck_grid = $MainContainer/GridContainer
|
|
@onready var bank_container = $MainContainer/BankContainer/ScrollContainer/VBoxContainer
|
|
@onready var back_button = $BackButton
|
|
|
|
# Default deck size (can be overridden via options)
|
|
var max_deck_size = 40
|
|
var deck_manager = null
|
|
var bank_cards = [] # Cards available but not in deck
|
|
|
|
# The current deck
|
|
var current_deck = []
|
|
|
|
func _ready():
|
|
# Connect back button
|
|
if back_button:
|
|
back_button.connect("pressed", Callable(self, "_on_back_button_pressed"))
|
|
|
|
# Find the DeckManager instance
|
|
deck_manager = get_node_or_null("/root/Board").deckManager
|
|
|
|
func initialize(options = null):
|
|
# Process options if provided
|
|
if options:
|
|
if options.has("max_deck_size") and options.max_deck_size is int:
|
|
max_deck_size = options.max_deck_size
|
|
|
|
# Load cards from deck and bank
|
|
load_cards()
|
|
|
|
# Set up the grid with empty card containers
|
|
setup_deck_grid()
|
|
|
|
# Populate the bank with available cards
|
|
populate_bank()
|
|
|
|
func load_cards():
|
|
if deck_manager:
|
|
# Clone the deck to work with
|
|
current_deck = deck_manager.deck.duplicate()
|
|
|
|
# For testing, we'll create a bank of all card types
|
|
# In a real implementation, you'd get this from a saved player state
|
|
bank_cards = create_card_bank()
|
|
else:
|
|
# Fallback with empty collections if deck manager not found
|
|
current_deck = []
|
|
bank_cards = []
|
|
print("Warning: DeckManager not found")
|
|
|
|
func create_card_bank():
|
|
# This is a placeholder - in a real implementation you'd load this from saved state
|
|
var bank = []
|
|
|
|
# Add some sample cards
|
|
bank.append(HopscotchCard.new())
|
|
bank.append(FieryCapeCard.new())
|
|
bank.append(FieryTrailCard.new())
|
|
bank.append(ExplosiveBootsCard.new())
|
|
bank.append(DoubleTimeCard.new())
|
|
bank.append(DrunkDrivingCard.new())
|
|
bank.append(SupernovaCard.new())
|
|
|
|
# Add some duplicates for testing
|
|
for i in range(3):
|
|
bank.append(HopscotchCard.new())
|
|
bank.append(FieryCapeCard.new())
|
|
|
|
return bank
|
|
|
|
func setup_deck_grid():
|
|
# Clear existing children
|
|
for child in deck_grid.get_children():
|
|
child.queue_free()
|
|
|
|
# Calculate grid dimensions
|
|
var rows = 4 # You might want to make this responsive or configurable
|
|
var cols = max_deck_size / rows
|
|
deck_grid.columns = cols
|
|
|
|
# Create card slots
|
|
for i in range(max_deck_size):
|
|
var card_slot = preload("res://card_slot.tscn").instantiate()
|
|
deck_grid.add_child(card_slot)
|
|
|
|
# Connect signals
|
|
card_slot.connect("card_selected", Callable(self, "_on_deck_card_selected"))
|
|
|
|
# Set card if available
|
|
if i < current_deck.size():
|
|
card_slot.set_card(current_deck[i])
|
|
else:
|
|
card_slot.clear()
|
|
|
|
func populate_bank():
|
|
# Clear existing children
|
|
for child in bank_container.get_children():
|
|
child.queue_free()
|
|
|
|
# Add each bank card to the list
|
|
for card in bank_cards:
|
|
var card_item = preload("res://card_bank_item.tscn").instantiate()
|
|
bank_container.add_child(card_item)
|
|
card_item.set_card(card)
|
|
card_item.connect("card_selected", Callable(self, "_on_bank_card_selected"))
|
|
|
|
func _on_deck_card_selected(card_slot, card):
|
|
if card:
|
|
# Remove card from deck
|
|
var index = current_deck.find(card)
|
|
if index >= 0:
|
|
current_deck.remove_at(index)
|
|
|
|
# Add to bank
|
|
bank_cards.append(card)
|
|
|
|
# Update UI
|
|
card_slot.clear()
|
|
populate_bank()
|
|
|
|
func _on_bank_card_selected(card_item, card):
|
|
# Find first empty slot in deck
|
|
var empty_slot_index = -1
|
|
for i in range(deck_grid.get_child_count()):
|
|
var slot = deck_grid.get_child(i)
|
|
if !slot.has_card():
|
|
empty_slot_index = i
|
|
break
|
|
|
|
if empty_slot_index >= 0 and current_deck.size() < max_deck_size:
|
|
# Remove from bank
|
|
var bank_index = bank_cards.find(card)
|
|
if bank_index >= 0:
|
|
bank_cards.remove_at(bank_index)
|
|
|
|
# Add to deck
|
|
current_deck.append(card)
|
|
|
|
# Update UI
|
|
deck_grid.get_child(empty_slot_index).set_card(card)
|
|
populate_bank()
|
|
|
|
func save_deck():
|
|
if deck_manager:
|
|
# Save the current deck to the deck manager
|
|
deck_manager.deck = current_deck.duplicate()
|
|
|
|
# If we implement persistence, we'd save the bank state as well
|
|
print("Deck saved with ", current_deck.size(), " cards")
|
|
|
|
func _on_back_button_pressed():
|
|
# Save changes before returning
|
|
save_deck()
|
|
|
|
# Emit signal to go back
|
|
emit_signal("back_pressed")
|
|
|
|
# Hide this screen
|
|
visible = false |