Integrated DeckManager Ui
This commit is contained in:
parent
94e920a80f
commit
62344f91ee
9 changed files with 113 additions and 94 deletions
|
|
@ -21,6 +21,8 @@ func _ready():
|
||||||
# Connect signals for interaction
|
# Connect signals for interaction
|
||||||
mouse_filter = Control.MOUSE_FILTER_STOP
|
mouse_filter = Control.MOUSE_FILTER_STOP
|
||||||
gui_input.connect(_on_gui_input)
|
gui_input.connect(_on_gui_input)
|
||||||
|
if card_frame:
|
||||||
|
card_frame.mouse_filter = Control.MOUSE_FILTER_PASS
|
||||||
|
|
||||||
func set_card(card):
|
func set_card(card):
|
||||||
current_card = card
|
current_card = card
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,8 @@ func _ready():
|
||||||
# Connect signals for interaction
|
# Connect signals for interaction
|
||||||
mouse_filter = Control.MOUSE_FILTER_STOP
|
mouse_filter = Control.MOUSE_FILTER_STOP
|
||||||
gui_input.connect(_on_gui_input)
|
gui_input.connect(_on_gui_input)
|
||||||
|
if card_border:
|
||||||
|
card_border.mouse_filter = Control.MOUSE_FILTER_PASS
|
||||||
|
|
||||||
func set_card(card):
|
func set_card(card):
|
||||||
current_card = card
|
current_card = card
|
||||||
|
|
@ -69,16 +71,17 @@ func _on_gui_input(event):
|
||||||
if event.pressed:
|
if event.pressed:
|
||||||
# Start drag
|
# Start drag
|
||||||
if current_card:
|
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)
|
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):
|
func _process(delta):
|
||||||
if dragging:
|
if dragging:
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ func _init():
|
||||||
super._init()
|
super._init()
|
||||||
# id = Utils.generate_guid()
|
# id = Utils.generate_guid()
|
||||||
cardName = "Double Time"
|
cardName = "Double Time"
|
||||||
rank = Rank.RANK_2
|
rank = Rank.RANK_3
|
||||||
effectType = EffectType.MOVEMENT_MODIFIER
|
effectType = EffectType.MOVEMENT_MODIFIER
|
||||||
description = "Piece can move twice in one turn"
|
description = "Piece can move twice in one turn"
|
||||||
duration = 2 # Lasts for 2 turns
|
duration = 2 # Lasts for 2 turns
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ func _init():
|
||||||
duration = 1
|
duration = 1
|
||||||
super._init()
|
super._init()
|
||||||
cardName = "Explosive Boots"
|
cardName = "Explosive Boots"
|
||||||
rank = Rank.RANK_2
|
rank = Rank.RANK_3
|
||||||
effectType = EffectType.PIECE_EFFECT
|
effectType = EffectType.PIECE_EFFECT
|
||||||
description = "All enemy units within 1 radius of the moving peice at the end of the turn are captured"
|
description = "All enemy units within 1 radius of the moving peice at the end of the turn are captured"
|
||||||
unitWhitelist = ["Pawn", "Knight", "King"]
|
unitWhitelist = ["Pawn", "Knight", "King"]
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ class_name DeckManager
|
||||||
|
|
||||||
var deck: Array = []
|
var deck: Array = []
|
||||||
var hand: Array = []
|
var hand: Array = []
|
||||||
|
var bank: Array = []
|
||||||
var discard: Array = []
|
var discard: Array = []
|
||||||
var attached_cards: Dictionary = {} # piece_id: card
|
var attached_cards: Dictionary = {} # piece_id: card
|
||||||
var attached_effects: Dictionary = {} # piece_id: [card]
|
var attached_effects: Dictionary = {} # piece_id: [card]
|
||||||
|
|
@ -17,7 +18,9 @@ const CARD_BASE_COSTS = {
|
||||||
}
|
}
|
||||||
|
|
||||||
func _init():
|
func _init():
|
||||||
|
print("************************DECK INIT*****************")
|
||||||
initializeStartingDeck()
|
initializeStartingDeck()
|
||||||
|
initializeStartingBank()
|
||||||
|
|
||||||
func initializeStartingDeck():
|
func initializeStartingDeck():
|
||||||
deck.clear();
|
deck.clear();
|
||||||
|
|
@ -30,8 +33,22 @@ func initializeStartingDeck():
|
||||||
deck.append(DoubleTimeCard.new())
|
deck.append(DoubleTimeCard.new())
|
||||||
deck.append(DrunkDrivingCard.new())
|
deck.append(DrunkDrivingCard.new())
|
||||||
deck.append(SupernovaCard.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():
|
func shuffleDeck():
|
||||||
deck.shuffle()
|
deck.shuffle()
|
||||||
|
|
|
||||||
|
|
@ -93,6 +93,7 @@ func _ready() -> void:
|
||||||
print("MenuContainer not found, will initialize game now")
|
print("MenuContainer not found, will initialize game now")
|
||||||
call_deferred("initialize_game_system")
|
call_deferred("initialize_game_system")
|
||||||
turnIndicator.visible = false
|
turnIndicator.visible = false
|
||||||
|
deckManager = DeckManager.new()
|
||||||
# 2rnbqkbnr1R/2ppp1pppp2/5p6/75/66/66/66/66/66/66/2PPPPPPPP2/2RNBQKBN3 b KQkq - 0 3
|
# 2rnbqkbnr1R/2ppp1pppp2/5p6/75/66/66/66/66/66/66/2PPPPPPPP2/2RNBQKBN3 b KQkq - 0 3
|
||||||
func _on_new_game_requested(options = {}):
|
func _on_new_game_requested(options = {}):
|
||||||
print("ChessGame received new_game_requested signal ", is_initialized)
|
print("ChessGame received new_game_requested signal ", is_initialized)
|
||||||
|
|
@ -190,8 +191,9 @@ func initializeCardPreview() -> void:
|
||||||
add_child(cardPreview)
|
add_child(cardPreview)
|
||||||
|
|
||||||
func initializeDeckSystem() -> void:
|
func initializeDeckSystem() -> void:
|
||||||
|
deckManager.shuffleDeck()
|
||||||
|
deckManager.drawStartingHand()
|
||||||
# Initialize the deck manager and card display
|
# Initialize the deck manager and card display
|
||||||
deckManager = DeckManager.new()
|
|
||||||
cardDisplay = CardDisplay.new()
|
cardDisplay = CardDisplay.new()
|
||||||
add_child(deckManager)
|
add_child(deckManager)
|
||||||
add_child(cardDisplay)
|
add_child(cardDisplay)
|
||||||
|
|
|
||||||
|
|
@ -4,158 +4,148 @@ class_name DeckManagerScreen
|
||||||
signal back_pressed
|
signal back_pressed
|
||||||
|
|
||||||
# Node references
|
# Node references
|
||||||
@onready var deck_grid = $MainContainer/GridContainer
|
@onready var deckGrid = $MainContainer/GridScrollContainer/GridContainer
|
||||||
@onready var bank_container = $MainContainer/BankContainer/ScrollContainer/VBoxContainer
|
@onready var bankContainer = $MainContainer/BankContainer/ScrollContainer/VBoxContainer
|
||||||
@onready var back_button = $BackButton
|
@onready var backButton = $BackButton
|
||||||
|
|
||||||
# Default deck size (can be overridden via options)
|
# Default deck size (can be overridden via options)
|
||||||
var max_deck_size = 40
|
var maxDeckSize = 35
|
||||||
var deck_manager = null
|
var deckManager = null
|
||||||
var bank_cards = [] # Cards available but not in deck
|
var bankCards = [] # Cards available but not in deck
|
||||||
|
|
||||||
# The current deck
|
# The current deck
|
||||||
var current_deck = []
|
var currentDeck = []
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
# Connect back button
|
# Connect back button
|
||||||
if back_button:
|
if backButton:
|
||||||
back_button.connect("pressed", Callable(self, "_on_back_button_pressed"))
|
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):
|
func initialize(options = null):
|
||||||
# Process options if provided
|
# Process options if provided
|
||||||
if options:
|
if options:
|
||||||
if options.has("max_deck_size") and options.max_deck_size is int:
|
if options.has("maxDeckSize") and options.maxDeckSize is int:
|
||||||
max_deck_size = options.max_deck_size
|
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 from deck and bank
|
||||||
load_cards()
|
loadCards()
|
||||||
|
|
||||||
# Set up the grid with empty card containers
|
# Set up the grid with empty card containers
|
||||||
setup_deck_grid()
|
setupDeckGrid()
|
||||||
|
|
||||||
# Populate the bank with available cards
|
# Populate the bank with available cards
|
||||||
populate_bank()
|
populateBank()
|
||||||
|
|
||||||
func load_cards():
|
func loadCards():
|
||||||
if deck_manager:
|
if deckManager:
|
||||||
# Clone the deck to work with
|
# 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
|
bankCards = deckManager.bank.duplicate()
|
||||||
# In a real implementation, you'd get this from a saved player state
|
|
||||||
bank_cards = create_card_bank()
|
|
||||||
else:
|
else:
|
||||||
# Fallback with empty collections if deck manager not found
|
# Fallback with empty collections if deck manager not found
|
||||||
current_deck = []
|
currentDeck = []
|
||||||
bank_cards = []
|
bankCards = []
|
||||||
print("Warning: DeckManager not found")
|
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
|
func setupDeckGrid():
|
||||||
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
|
# Clear existing children
|
||||||
for child in deck_grid.get_children():
|
for child in deckGrid.get_children():
|
||||||
child.queue_free()
|
child.queue_free()
|
||||||
|
|
||||||
# Calculate grid dimensions
|
# Calculate grid dimensions
|
||||||
var rows = 4 # You might want to make this responsive or configurable
|
var cols = 7 #check screen to deteremine
|
||||||
var cols = max_deck_size / rows
|
var rows = maxDeckSize / cols
|
||||||
deck_grid.columns = cols
|
deckGrid.columns = cols
|
||||||
|
|
||||||
# Create card slots
|
# Create card slots
|
||||||
for i in range(max_deck_size):
|
for i in range(maxDeckSize):
|
||||||
var card_slot = preload("res://card_slot.tscn").instantiate()
|
var card_slot = preload("res://card_slot.tscn").instantiate()
|
||||||
deck_grid.add_child(card_slot)
|
deckGrid.add_child(card_slot)
|
||||||
|
|
||||||
# Connect signals
|
# Connect signals
|
||||||
card_slot.connect("card_selected", Callable(self, "_on_deck_card_selected"))
|
card_slot.connect("card_selected", Callable(self, "_on_deck_card_selected"))
|
||||||
|
|
||||||
# Set card if available
|
# Set card if available
|
||||||
if i < current_deck.size():
|
if i < currentDeck.size():
|
||||||
card_slot.set_card(current_deck[i])
|
card_slot.set_card(currentDeck[i])
|
||||||
else:
|
else:
|
||||||
card_slot.clear()
|
card_slot.clear()
|
||||||
|
|
||||||
func populate_bank():
|
func populateBank():
|
||||||
# Clear existing children
|
# Clear existing children
|
||||||
for child in bank_container.get_children():
|
for child in bankContainer.get_children():
|
||||||
child.queue_free()
|
child.queue_free()
|
||||||
|
|
||||||
# Add each bank card to the list
|
# 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()
|
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.set_card(card)
|
||||||
card_item.connect("card_selected", Callable(self, "_on_bank_card_selected"))
|
card_item.connect("card_selected", Callable(self, "_on_bank_card_selected"))
|
||||||
|
|
||||||
func _on_deck_card_selected(card_slot, card):
|
func _on_deck_card_selected(card_slot, card):
|
||||||
if card:
|
if card:
|
||||||
# Remove card from deck
|
# Remove card from deck
|
||||||
var index = current_deck.find(card)
|
var index = currentDeck.find(card)
|
||||||
if index >= 0:
|
if index >= 0:
|
||||||
current_deck.remove_at(index)
|
currentDeck.remove_at(index)
|
||||||
|
|
||||||
# Add to bank
|
# Add to bank
|
||||||
bank_cards.append(card)
|
bankCards.append(card)
|
||||||
|
|
||||||
# Update UI
|
# Update UI
|
||||||
card_slot.clear()
|
card_slot.clear()
|
||||||
populate_bank()
|
populateBank()
|
||||||
|
|
||||||
func _on_bank_card_selected(card_item, card):
|
func _on_bank_card_selected(card_item, card):
|
||||||
|
print("_on_bank_card_selected")
|
||||||
# Find first empty slot in deck
|
# Find first empty slot in deck
|
||||||
var empty_slot_index = -1
|
var empty_slot_index = -1
|
||||||
for i in range(deck_grid.get_child_count()):
|
for i in range(deckGrid.get_child_count()):
|
||||||
var slot = deck_grid.get_child(i)
|
var slot = deckGrid.get_child(i)
|
||||||
if !slot.has_card():
|
if !slot.has_card():
|
||||||
empty_slot_index = i
|
empty_slot_index = i
|
||||||
break
|
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
|
# Remove from bank
|
||||||
var bank_index = bank_cards.find(card)
|
var bank_index = bankCards.find(card)
|
||||||
if bank_index >= 0:
|
if bank_index >= 0:
|
||||||
bank_cards.remove_at(bank_index)
|
bankCards.remove_at(bank_index)
|
||||||
|
|
||||||
# Add to deck
|
# Add to deck
|
||||||
current_deck.append(card)
|
currentDeck.append(card)
|
||||||
|
|
||||||
# Update UI
|
# Update UI
|
||||||
deck_grid.get_child(empty_slot_index).set_card(card)
|
deckGrid.get_child(empty_slot_index).set_card(card)
|
||||||
populate_bank()
|
populateBank()
|
||||||
|
|
||||||
func save_deck():
|
func saveDeck():
|
||||||
if deck_manager:
|
if deckManager:
|
||||||
# Save the current deck to the deck manager
|
# 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 ", currentDeck.size(), " cards")
|
||||||
print("Deck saved with ", current_deck.size(), " cards")
|
|
||||||
|
|
||||||
func _on_back_button_pressed():
|
func _on_backButton_pressed():
|
||||||
# Save changes before returning
|
# Save changes before returning
|
||||||
save_deck()
|
saveDeck()
|
||||||
|
|
||||||
# Emit signal to go back
|
# Emit signal to go back
|
||||||
emit_signal("back_pressed")
|
emit_signal("back_pressed")
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ layout_mode = 3
|
||||||
anchors_preset = 15
|
anchors_preset = 15
|
||||||
anchor_right = 1.0
|
anchor_right = 1.0
|
||||||
anchor_bottom = 1.0
|
anchor_bottom = 1.0
|
||||||
offset_right = -104.0
|
offset_right = 8.0
|
||||||
offset_bottom = -5.0
|
offset_bottom = -5.0
|
||||||
grow_horizontal = 2
|
grow_horizontal = 2
|
||||||
grow_vertical = 2
|
grow_vertical = 2
|
||||||
|
|
|
||||||
|
|
@ -38,17 +38,22 @@ anchors_preset = 15
|
||||||
anchor_right = 1.0
|
anchor_right = 1.0
|
||||||
anchor_bottom = 1.0
|
anchor_bottom = 1.0
|
||||||
offset_left = 20.0
|
offset_left = 20.0
|
||||||
offset_top = 80.0
|
offset_top = 100.0
|
||||||
offset_right = -20.0
|
offset_right = -20.0
|
||||||
offset_bottom = -80.0
|
offset_bottom = -60.0
|
||||||
grow_horizontal = 2
|
grow_horizontal = 2
|
||||||
grow_vertical = 2
|
grow_vertical = 2
|
||||||
|
|
||||||
[node name="GridContainer" type="GridContainer" parent="MainContainer"]
|
[node name="GridScrollContainer" type="ScrollContainer" parent="MainContainer"]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
size_flags_horizontal = 3
|
size_flags_horizontal = 3
|
||||||
size_flags_vertical = 3
|
size_flags_vertical = 3
|
||||||
size_flags_stretch_ratio = 3.0
|
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/h_separation = 10
|
||||||
theme_override_constants/v_separation = 10
|
theme_override_constants/v_separation = 10
|
||||||
columns = 5
|
columns = 5
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue