Integrated DeckManager Ui

This commit is contained in:
2ManyProjects 2025-03-02 22:02:03 -06:00
parent 94e920a80f
commit 62344f91ee
9 changed files with 113 additions and 94 deletions

View file

@ -21,6 +21,8 @@ func _ready():
# Connect signals for interaction
mouse_filter = Control.MOUSE_FILTER_STOP
gui_input.connect(_on_gui_input)
if card_frame:
card_frame.mouse_filter = Control.MOUSE_FILTER_PASS
func set_card(card):
current_card = card

View file

@ -27,6 +27,8 @@ func _ready():
# Connect signals for interaction
mouse_filter = Control.MOUSE_FILTER_STOP
gui_input.connect(_on_gui_input)
if card_border:
card_border.mouse_filter = Control.MOUSE_FILTER_PASS
func set_card(card):
current_card = card
@ -69,16 +71,17 @@ func _on_gui_input(event):
if event.pressed:
# Start drag
if current_card:
dragging = true
drag_offset = get_global_mouse_position() - global_position
else:
# End drag
if dragging:
dragging = false
emit_signal("card_selected", self, current_card)
elif current_card:
# Just a click, still select the card
emit_signal("card_selected", self, current_card)
# dragging = true
# drag_offset = get_global_mouse_position() - global_position
# else:
# # End drag
# if dragging:
# dragging = false
# emit_signal("card_selected", self, current_card)
# elif current_card:
# # Just a click, still select the card
# emit_signal("card_selected", self, current_card)
func _process(delta):
if dragging:

View file

@ -4,7 +4,7 @@ func _init():
super._init()
# id = Utils.generate_guid()
cardName = "Double Time"
rank = Rank.RANK_2
rank = Rank.RANK_3
effectType = EffectType.MOVEMENT_MODIFIER
description = "Piece can move twice in one turn"
duration = 2 # Lasts for 2 turns

View file

@ -6,7 +6,7 @@ func _init():
duration = 1
super._init()
cardName = "Explosive Boots"
rank = Rank.RANK_2
rank = Rank.RANK_3
effectType = EffectType.PIECE_EFFECT
description = "All enemy units within 1 radius of the moving peice at the end of the turn are captured"
unitWhitelist = ["Pawn", "Knight", "King"]

View file

@ -3,6 +3,7 @@ class_name DeckManager
var deck: Array = []
var hand: Array = []
var bank: Array = []
var discard: Array = []
var attached_cards: Dictionary = {} # piece_id: card
var attached_effects: Dictionary = {} # piece_id: [card]
@ -17,7 +18,9 @@ const CARD_BASE_COSTS = {
}
func _init():
print("************************DECK INIT*****************")
initializeStartingDeck()
initializeStartingBank()
func initializeStartingDeck():
deck.clear();
@ -30,8 +33,22 @@ func initializeStartingDeck():
deck.append(DoubleTimeCard.new())
deck.append(DrunkDrivingCard.new())
deck.append(SupernovaCard.new())
shuffleDeck()
drawStartingHand()
func initializeStartingBank():
# sample
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())
func shuffleDeck():
deck.shuffle()

View file

@ -93,6 +93,7 @@ func _ready() -> void:
print("MenuContainer not found, will initialize game now")
call_deferred("initialize_game_system")
turnIndicator.visible = false
deckManager = DeckManager.new()
# 2rnbqkbnr1R/2ppp1pppp2/5p6/75/66/66/66/66/66/66/2PPPPPPPP2/2RNBQKBN3 b KQkq - 0 3
func _on_new_game_requested(options = {}):
print("ChessGame received new_game_requested signal ", is_initialized)
@ -190,8 +191,9 @@ func initializeCardPreview() -> void:
add_child(cardPreview)
func initializeDeckSystem() -> void:
deckManager.shuffleDeck()
deckManager.drawStartingHand()
# Initialize the deck manager and card display
deckManager = DeckManager.new()
cardDisplay = CardDisplay.new()
add_child(deckManager)
add_child(cardDisplay)

View file

@ -4,158 +4,148 @@ 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
@onready var deckGrid = $MainContainer/GridScrollContainer/GridContainer
@onready var bankContainer = $MainContainer/BankContainer/ScrollContainer/VBoxContainer
@onready var backButton = $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
var maxDeckSize = 35
var deckManager = null
var bankCards = [] # Cards available but not in deck
# The current deck
var current_deck = []
var currentDeck = []
func _ready():
# Connect back button
if back_button:
back_button.connect("pressed", Callable(self, "_on_back_button_pressed"))
if backButton:
backButton.connect("pressed", Callable(self, "_on_backButton_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
if options.has("maxDeckSize") and options.maxDeckSize is int:
maxDeckSize = options.maxDeckSize
# Find the DeckManager instance
var board = get_node_or_null("/root/Board") as ChessGame
if board and "deckManager" in board:
deckManager = board.deckManager
print("Found deck manager:", deckManager)
# if(!deckManager.deck):
# deckManager.initializeStartingDeck()
else:
print("DeckManager not found on Board node")
print("DECK MANAGER")
# Load cards from deck and bank
load_cards()
loadCards()
# Set up the grid with empty card containers
setup_deck_grid()
setupDeckGrid()
# Populate the bank with available cards
populate_bank()
populateBank()
func load_cards():
if deck_manager:
func loadCards():
if deckManager:
# Clone the deck to work with
current_deck = deck_manager.deck.duplicate()
currentDeck = deckManager.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()
bankCards = deckManager.bank.duplicate()
else:
# Fallback with empty collections if deck manager not found
current_deck = []
bank_cards = []
currentDeck = []
bankCards = []
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():
func setupDeckGrid():
# Clear existing children
for child in deck_grid.get_children():
for child in deckGrid.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
var cols = 7 #check screen to deteremine
var rows = maxDeckSize / cols
deckGrid.columns = cols
# Create card slots
for i in range(max_deck_size):
for i in range(maxDeckSize):
var card_slot = preload("res://card_slot.tscn").instantiate()
deck_grid.add_child(card_slot)
deckGrid.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])
if i < currentDeck.size():
card_slot.set_card(currentDeck[i])
else:
card_slot.clear()
func populate_bank():
func populateBank():
# Clear existing children
for child in bank_container.get_children():
for child in bankContainer.get_children():
child.queue_free()
# Add each bank card to the list
for card in bank_cards:
for card in bankCards:
var card_item = preload("res://card_bank_item.tscn").instantiate()
bank_container.add_child(card_item)
bankContainer.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)
var index = currentDeck.find(card)
if index >= 0:
current_deck.remove_at(index)
currentDeck.remove_at(index)
# Add to bank
bank_cards.append(card)
bankCards.append(card)
# Update UI
card_slot.clear()
populate_bank()
populateBank()
func _on_bank_card_selected(card_item, card):
print("_on_bank_card_selected")
# 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)
for i in range(deckGrid.get_child_count()):
var slot = deckGrid.get_child(i)
if !slot.has_card():
empty_slot_index = i
break
if empty_slot_index >= 0 and current_deck.size() < max_deck_size:
if empty_slot_index >= 0 and currentDeck.size() < maxDeckSize:
# Remove from bank
var bank_index = bank_cards.find(card)
var bank_index = bankCards.find(card)
if bank_index >= 0:
bank_cards.remove_at(bank_index)
bankCards.remove_at(bank_index)
# Add to deck
current_deck.append(card)
currentDeck.append(card)
# Update UI
deck_grid.get_child(empty_slot_index).set_card(card)
populate_bank()
deckGrid.get_child(empty_slot_index).set_card(card)
populateBank()
func save_deck():
if deck_manager:
func saveDeck():
if deckManager:
# Save the current deck to the deck manager
deck_manager.deck = current_deck.duplicate()
deckManager.deck = currentDeck.duplicate()
deckManager.bank = bankCards.duplicate()
# If we implement persistence, we'd save the bank state as well
print("Deck saved with ", current_deck.size(), " cards")
print("Deck saved with ", currentDeck.size(), " cards")
func _on_back_button_pressed():
func _on_backButton_pressed():
# Save changes before returning
save_deck()
saveDeck()
# Emit signal to go back
emit_signal("back_pressed")

View file

@ -34,7 +34,7 @@ layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
offset_right = -104.0
offset_right = 8.0
offset_bottom = -5.0
grow_horizontal = 2
grow_vertical = 2

View file

@ -38,17 +38,22 @@ anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
offset_left = 20.0
offset_top = 80.0
offset_top = 100.0
offset_right = -20.0
offset_bottom = -80.0
offset_bottom = -60.0
grow_horizontal = 2
grow_vertical = 2
[node name="GridContainer" type="GridContainer" parent="MainContainer"]
[node name="GridScrollContainer" type="ScrollContainer" parent="MainContainer"]
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 3
size_flags_stretch_ratio = 3.0
horizontal_scroll_mode = 0
[node name="GridContainer" type="GridContainer" parent="MainContainer/GridScrollContainer"]
layout_mode = 2
size_flags_horizontal = 3
theme_override_constants/h_separation = 10
theme_override_constants/v_separation = 10
columns = 5