Added Card Preview
This commit is contained in:
parent
425819641d
commit
3d5aa8ade7
6 changed files with 245 additions and 4 deletions
83
Systems/CardPreviewPanel.gd
Normal file
83
Systems/CardPreviewPanel.gd
Normal file
|
|
@ -0,0 +1,83 @@
|
||||||
|
extends Panel
|
||||||
|
class_name CardPreviewPanel
|
||||||
|
|
||||||
|
# Node references
|
||||||
|
@onready var card_name_label = $CardContent/CardNameLabel
|
||||||
|
@onready var rank_label = $CardContent/RankLabel
|
||||||
|
@onready var description_label = $CardContent/DescriptionLabel
|
||||||
|
@onready var unit_list_label = $CardContent/UnitListLabel
|
||||||
|
@onready var effect_type_label = $CardContent/EffectTypeLabel
|
||||||
|
@onready var duration_label = $CardContent/DurationLabel
|
||||||
|
|
||||||
|
# Card rank colors (same as other card components)
|
||||||
|
var rank_colors = {
|
||||||
|
Card.Rank.RANK_0: Color(0.9, 0.1, 0.1, 1.0), # Red
|
||||||
|
Card.Rank.RANK_1: Color(0.9, 0.6, 0.1, 1.0), # Orange
|
||||||
|
Card.Rank.RANK_2: Color(0.1, 0.7, 0.1, 1.0), # Green
|
||||||
|
Card.Rank.RANK_3: Color(0.1, 0.7, 0.9, 1.0) # Blue
|
||||||
|
}
|
||||||
|
|
||||||
|
# Effect type descriptions
|
||||||
|
var effect_type_names = {
|
||||||
|
Card.EffectType.MOVEMENT_MODIFIER: "Movement Modifier",
|
||||||
|
Card.EffectType.BOARD_EFFECT: "Board Effect",
|
||||||
|
Card.EffectType.PIECE_EFFECT: "Piece Effect",
|
||||||
|
Card.EffectType.SPECIAL_ACTION: "Special Action"
|
||||||
|
}
|
||||||
|
|
||||||
|
func _ready():
|
||||||
|
# Hide the preview initially
|
||||||
|
visible = false
|
||||||
|
|
||||||
|
func preview_card(card: Card):
|
||||||
|
if !card:
|
||||||
|
hide_preview()
|
||||||
|
return
|
||||||
|
|
||||||
|
# Update all card information
|
||||||
|
card_name_label.text = card.cardName
|
||||||
|
|
||||||
|
# Set rank information
|
||||||
|
var rank_text = "Rank " + str(card.rank)
|
||||||
|
match card.rank:
|
||||||
|
Card.Rank.RANK_0:
|
||||||
|
rank_text += " (One-time use, removed from deck)"
|
||||||
|
Card.Rank.RANK_1:
|
||||||
|
rank_text += " (Once per match)"
|
||||||
|
Card.Rank.RANK_2:
|
||||||
|
rank_text += " (Discarded after use)"
|
||||||
|
Card.Rank.RANK_3:
|
||||||
|
rank_text += " (Reused)"
|
||||||
|
rank_label.text = rank_text
|
||||||
|
|
||||||
|
# Set rank color
|
||||||
|
if card.rank in rank_colors:
|
||||||
|
rank_label.add_theme_color_override("font_color", rank_colors[card.rank])
|
||||||
|
card_name_label.add_theme_color_override("font_color", rank_colors[card.rank])
|
||||||
|
|
||||||
|
# Set description
|
||||||
|
description_label.text = card.description
|
||||||
|
|
||||||
|
# Set unit whitelist
|
||||||
|
if card.unitWhitelist.is_empty():
|
||||||
|
unit_list_label.text = "Can be applied to: Any piece"
|
||||||
|
else:
|
||||||
|
unit_list_label.text = "Can be applied to: " + ", ".join(card.unitWhitelist)
|
||||||
|
|
||||||
|
# Set effect type
|
||||||
|
if card.effectType in effect_type_names:
|
||||||
|
effect_type_label.text = "Effect Type: " + effect_type_names[card.effectType]
|
||||||
|
else:
|
||||||
|
effect_type_label.text = "Effect Type: Unknown"
|
||||||
|
|
||||||
|
# Set duration
|
||||||
|
if card.duration > 0:
|
||||||
|
duration_label.text = "Duration: " + str(card.duration) + " turns"
|
||||||
|
else:
|
||||||
|
duration_label.text = "Duration: Instant"
|
||||||
|
|
||||||
|
# Show the preview
|
||||||
|
visible = true
|
||||||
|
|
||||||
|
func hide_preview():
|
||||||
|
visible = false
|
||||||
|
|
@ -19,10 +19,18 @@ var rank_colors = {
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
# Connect signals for interaction
|
# Connect signals for interaction
|
||||||
|
custom_minimum_size = Vector2(0, 40) # Ensure it has enough height
|
||||||
|
size_flags_horizontal = SIZE_EXPAND_FILL
|
||||||
mouse_filter = Control.MOUSE_FILTER_STOP
|
mouse_filter = Control.MOUSE_FILTER_STOP
|
||||||
gui_input.connect(_on_gui_input)
|
|
||||||
if card_frame:
|
if card_frame:
|
||||||
card_frame.mouse_filter = Control.MOUSE_FILTER_PASS
|
card_frame.mouse_filter = Control.MOUSE_FILTER_PASS
|
||||||
|
if rank_label:
|
||||||
|
rank_label.mouse_filter = Control.MOUSE_FILTER_PASS
|
||||||
|
if card_name_label:
|
||||||
|
card_name_label.mouse_filter = Control.MOUSE_FILTER_PASS
|
||||||
|
|
||||||
|
# Connect GUI input signal
|
||||||
|
gui_input.connect(_on_gui_input)
|
||||||
|
|
||||||
func set_card(card):
|
func set_card(card):
|
||||||
current_card = card
|
current_card = card
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,10 @@ func _ready():
|
||||||
gui_input.connect(_on_gui_input)
|
gui_input.connect(_on_gui_input)
|
||||||
if card_border:
|
if card_border:
|
||||||
card_border.mouse_filter = Control.MOUSE_FILTER_PASS
|
card_border.mouse_filter = Control.MOUSE_FILTER_PASS
|
||||||
|
for child in get_children():
|
||||||
|
if child is Control:
|
||||||
|
child.mouse_filter = Control.MOUSE_FILTER_PASS
|
||||||
|
|
||||||
|
|
||||||
func set_card(card):
|
func set_card(card):
|
||||||
current_card = card
|
current_card = card
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ signal back_pressed
|
||||||
@onready var deckGrid = $MainContainer/GridScrollContainer/GridContainer
|
@onready var deckGrid = $MainContainer/GridScrollContainer/GridContainer
|
||||||
@onready var bankContainer = $MainContainer/BankContainer/ScrollContainer/VBoxContainer
|
@onready var bankContainer = $MainContainer/BankContainer/ScrollContainer/VBoxContainer
|
||||||
@onready var backButton = $BackButton
|
@onready var backButton = $BackButton
|
||||||
|
@onready var card_preview = $CardPreviewPanel
|
||||||
|
|
||||||
# Default deck size (can be overridden via options)
|
# Default deck size (can be overridden via options)
|
||||||
var maxDeckSize = 35
|
var maxDeckSize = 35
|
||||||
|
|
@ -15,12 +16,16 @@ var bankCards = [] # Cards available but not in deck
|
||||||
|
|
||||||
# The current deck
|
# The current deck
|
||||||
var currentDeck = []
|
var currentDeck = []
|
||||||
|
var current_preview_card = null
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
# Connect back button
|
# Connect back button
|
||||||
if backButton:
|
if backButton:
|
||||||
backButton.connect("pressed", Callable(self, "_on_backButton_pressed"))
|
backButton.connect("pressed", Callable(self, "_on_backButton_pressed"))
|
||||||
|
|
||||||
|
if card_preview:
|
||||||
|
card_preview.visible = false
|
||||||
|
|
||||||
|
|
||||||
func initialize(options = null):
|
func initialize(options = null):
|
||||||
# Process options if provided
|
# Process options if provided
|
||||||
|
|
@ -68,7 +73,7 @@ func setupDeckGrid():
|
||||||
child.queue_free()
|
child.queue_free()
|
||||||
|
|
||||||
# Calculate grid dimensions
|
# Calculate grid dimensions
|
||||||
var cols = 7 #check screen to deteremine
|
var cols = 4 #check screen to deteremine
|
||||||
var rows = maxDeckSize / cols
|
var rows = maxDeckSize / cols
|
||||||
deckGrid.columns = cols
|
deckGrid.columns = cols
|
||||||
|
|
||||||
|
|
@ -79,6 +84,7 @@ func setupDeckGrid():
|
||||||
|
|
||||||
# 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"))
|
||||||
|
_connect_hover_signals(card_slot)
|
||||||
|
|
||||||
# Set card if available
|
# Set card if available
|
||||||
if i < currentDeck.size():
|
if i < currentDeck.size():
|
||||||
|
|
@ -86,6 +92,13 @@ func setupDeckGrid():
|
||||||
else:
|
else:
|
||||||
card_slot.clear()
|
card_slot.clear()
|
||||||
|
|
||||||
|
func _connect_hover_signals(node):
|
||||||
|
# Add hover signals for preview functionality
|
||||||
|
if node.is_class("Control"):
|
||||||
|
node.mouse_entered.connect(Callable(self, "_on_card_mouse_entered").bind(node))
|
||||||
|
# node.mouse_exited.connect(Callable(self, "_on_card_mouse_exited").bind(node))
|
||||||
|
|
||||||
|
|
||||||
func populateBank():
|
func populateBank():
|
||||||
# Clear existing children
|
# Clear existing children
|
||||||
for child in bankContainer.get_children():
|
for child in bankContainer.get_children():
|
||||||
|
|
@ -97,6 +110,7 @@ func populateBank():
|
||||||
bankContainer.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"))
|
||||||
|
_connect_hover_signals(card_item)
|
||||||
|
|
||||||
func _on_deck_card_selected(card_slot, card):
|
func _on_deck_card_selected(card_slot, card):
|
||||||
if card:
|
if card:
|
||||||
|
|
@ -111,6 +125,8 @@ func _on_deck_card_selected(card_slot, card):
|
||||||
# Update UI
|
# Update UI
|
||||||
card_slot.clear()
|
card_slot.clear()
|
||||||
populateBank()
|
populateBank()
|
||||||
|
if current_preview_card == card:
|
||||||
|
hide_card_preview()
|
||||||
|
|
||||||
func _on_bank_card_selected(card_item, card):
|
func _on_bank_card_selected(card_item, card):
|
||||||
print("_on_bank_card_selected")
|
print("_on_bank_card_selected")
|
||||||
|
|
@ -135,6 +151,39 @@ func _on_bank_card_selected(card_item, card):
|
||||||
deckGrid.get_child(empty_slot_index).set_card(card)
|
deckGrid.get_child(empty_slot_index).set_card(card)
|
||||||
populateBank()
|
populateBank()
|
||||||
|
|
||||||
|
func _on_card_mouse_entered(node):
|
||||||
|
var card = null
|
||||||
|
|
||||||
|
# Get the card from the node
|
||||||
|
if node.has_method("has_card") and node.has_card():
|
||||||
|
# This is a CardSlot
|
||||||
|
card = node.current_card
|
||||||
|
elif node.has_method("set_card") and node.current_card:
|
||||||
|
# This is a CardBankItem
|
||||||
|
card = node.current_card
|
||||||
|
|
||||||
|
if card:
|
||||||
|
show_card_preview(card)
|
||||||
|
|
||||||
|
# func _on_card_mouse_exited(node):
|
||||||
|
# # Add a short delay before hiding the preview
|
||||||
|
# # This prevents flickering when moving between cards
|
||||||
|
# await get_tree().create_timer(0.1).timeout
|
||||||
|
|
||||||
|
# # Only hide if we're not hovering over another card that shows the same preview
|
||||||
|
# if current_preview_card:
|
||||||
|
# hide_card_preview()
|
||||||
|
|
||||||
|
func show_card_preview(card):
|
||||||
|
if card_preview and card:
|
||||||
|
current_preview_card = card
|
||||||
|
card_preview.preview_card(card)
|
||||||
|
|
||||||
|
func hide_card_preview():
|
||||||
|
if card_preview:
|
||||||
|
current_preview_card = null
|
||||||
|
card_preview.hide_preview()
|
||||||
|
|
||||||
func saveDeck():
|
func saveDeck():
|
||||||
if deckManager:
|
if deckManager:
|
||||||
# Save the current deck to the deck manager
|
# Save the current deck to the deck manager
|
||||||
|
|
|
||||||
84
card_preview_panel.tscn
Normal file
84
card_preview_panel.tscn
Normal file
|
|
@ -0,0 +1,84 @@
|
||||||
|
[gd_scene load_steps=3 format=3 uid="uid://xxxxxxxx"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" path="res://Systems/CardPreviewPanel.gd" id="1_ykslh"]
|
||||||
|
|
||||||
|
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_ykslh"]
|
||||||
|
bg_color = Color(0.08, 0.08, 0.12, 0.95)
|
||||||
|
border_width_left = 3
|
||||||
|
border_width_top = 3
|
||||||
|
border_width_right = 3
|
||||||
|
border_width_bottom = 3
|
||||||
|
border_color = Color(0.2, 0.2, 0.25, 1)
|
||||||
|
corner_radius_top_left = 10
|
||||||
|
corner_radius_top_right = 10
|
||||||
|
corner_radius_bottom_right = 10
|
||||||
|
corner_radius_bottom_left = 10
|
||||||
|
|
||||||
|
[node name="CardPreviewPanel" type="Panel"]
|
||||||
|
custom_minimum_size = Vector2(300, 400)
|
||||||
|
anchors_preset = 15
|
||||||
|
anchor_right = 1.0
|
||||||
|
anchor_bottom = 1.0
|
||||||
|
offset_right = -900.0
|
||||||
|
offset_bottom = -320.0
|
||||||
|
grow_horizontal = 2
|
||||||
|
grow_vertical = 2
|
||||||
|
theme_override_styles/panel = SubResource("StyleBoxFlat_ykslh")
|
||||||
|
script = ExtResource("1_ykslh")
|
||||||
|
|
||||||
|
[node name="CardContent" type="VBoxContainer" parent="."]
|
||||||
|
layout_mode = 1
|
||||||
|
anchors_preset = 15
|
||||||
|
anchor_right = 1.0
|
||||||
|
anchor_bottom = 1.0
|
||||||
|
offset_left = 20.0
|
||||||
|
offset_top = 20.0
|
||||||
|
offset_right = -20.0
|
||||||
|
offset_bottom = -20.0
|
||||||
|
grow_horizontal = 2
|
||||||
|
grow_vertical = 2
|
||||||
|
|
||||||
|
[node name="CardNameLabel" type="Label" parent="CardContent"]
|
||||||
|
layout_mode = 2
|
||||||
|
theme_override_font_sizes/font_size = 24
|
||||||
|
text = "Card Name"
|
||||||
|
horizontal_alignment = 1
|
||||||
|
|
||||||
|
[node name="HSeparator" type="HSeparator" parent="CardContent"]
|
||||||
|
layout_mode = 2
|
||||||
|
|
||||||
|
[node name="RankLabel" type="Label" parent="CardContent"]
|
||||||
|
layout_mode = 2
|
||||||
|
theme_override_font_sizes/font_size = 18
|
||||||
|
text = "Rank 3 (Reused)"
|
||||||
|
horizontal_alignment = 1
|
||||||
|
autowrap_mode = 3
|
||||||
|
|
||||||
|
[node name="HSeparator2" type="HSeparator" parent="CardContent"]
|
||||||
|
layout_mode = 2
|
||||||
|
theme_override_constants/separation = 10
|
||||||
|
|
||||||
|
[node name="DescriptionLabel" type="RichTextLabel" parent="CardContent"]
|
||||||
|
layout_mode = 2
|
||||||
|
size_flags_vertical = 3
|
||||||
|
theme_override_font_sizes/normal_font_size = 16
|
||||||
|
text = "Card description goes here. This will explain what the card does when played."
|
||||||
|
fit_content = true
|
||||||
|
|
||||||
|
[node name="HSeparator3" type="HSeparator" parent="CardContent"]
|
||||||
|
layout_mode = 2
|
||||||
|
theme_override_constants/separation = 10
|
||||||
|
|
||||||
|
[node name="EffectTypeLabel" type="Label" parent="CardContent"]
|
||||||
|
layout_mode = 2
|
||||||
|
text = "Effect Type: Movement Modifier"
|
||||||
|
|
||||||
|
[node name="UnitListLabel" type="Label" parent="CardContent"]
|
||||||
|
custom_minimum_size = Vector2(0, 30)
|
||||||
|
layout_mode = 2
|
||||||
|
text = "Can be applied to: Any piece"
|
||||||
|
autowrap_mode = 3
|
||||||
|
|
||||||
|
[node name="DurationLabel" type="Label" parent="CardContent"]
|
||||||
|
layout_mode = 2
|
||||||
|
text = "Duration: 3 turns"
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
[gd_scene load_steps=3 format=3 uid="uid://c7uqbcxdjoais"]
|
[gd_scene load_steps=4 format=3 uid="uid://c7uqbcxdjoais"]
|
||||||
|
|
||||||
[ext_resource type="Script" path="res://Systems/Game/DeckManagerScreen.gd" id="1_gokg4"]
|
[ext_resource type="Script" path="res://Systems/Game/DeckManagerScreen.gd" id="1_gokg4"]
|
||||||
|
[ext_resource type="PackedScene" uid="uid://xxxxxxxx" path="res://card_preview_panel.tscn" id="3_abcde"]
|
||||||
[ext_resource type="Script" path="res://Systems/Game/GameMenuButton.gd" id="4_gokg4"]
|
[ext_resource type="Script" path="res://Systems/Game/GameMenuButton.gd" id="4_gokg4"]
|
||||||
|
|
||||||
[node name="DeckManagerScreen" type="Control"]
|
[node name="DeckManagerScreen" type="Control"]
|
||||||
|
|
@ -32,12 +33,24 @@ theme_override_font_sizes/font_size = 36
|
||||||
text = "DECK MANAGER"
|
text = "DECK MANAGER"
|
||||||
horizontal_alignment = 1
|
horizontal_alignment = 1
|
||||||
|
|
||||||
|
[node name="CardPreviewPanel" parent="." instance=ExtResource("3_abcde")]
|
||||||
|
layout_mode = 2
|
||||||
|
anchors_preset = 0
|
||||||
|
anchor_right = 0.0
|
||||||
|
anchor_bottom = 0.0
|
||||||
|
offset_left = 20.0
|
||||||
|
offset_top = 100.0
|
||||||
|
offset_right = 320.0
|
||||||
|
offset_bottom = 588.0
|
||||||
|
grow_horizontal = 1
|
||||||
|
grow_vertical = 1
|
||||||
|
|
||||||
[node name="MainContainer" type="HBoxContainer" parent="."]
|
[node name="MainContainer" type="HBoxContainer" parent="."]
|
||||||
layout_mode = 1
|
layout_mode = 1
|
||||||
anchors_preset = 15
|
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 = 325.0
|
||||||
offset_top = 100.0
|
offset_top = 100.0
|
||||||
offset_right = -20.0
|
offset_right = -20.0
|
||||||
offset_bottom = -60.0
|
offset_bottom = -60.0
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue