From 3d5aa8ade7bb76438f4afa0ad1b02ebddf4df184 Mon Sep 17 00:00:00 2001 From: 2ManyProjects Date: Sun, 2 Mar 2025 23:12:40 -0600 Subject: [PATCH] Added Card Preview --- Systems/CardPreviewPanel.gd | 83 ++++++++++++++++++++++++++++++ Systems/Cards/CardBankItem.gd | 10 +++- Systems/Cards/CardSlot.gd | 4 ++ Systems/Game/DeckManagerScreen.gd | 51 ++++++++++++++++++- card_preview_panel.tscn | 84 +++++++++++++++++++++++++++++++ deck_manager_screen.tscn | 17 ++++++- 6 files changed, 245 insertions(+), 4 deletions(-) create mode 100644 Systems/CardPreviewPanel.gd create mode 100644 card_preview_panel.tscn diff --git a/Systems/CardPreviewPanel.gd b/Systems/CardPreviewPanel.gd new file mode 100644 index 0000000..b3311c8 --- /dev/null +++ b/Systems/CardPreviewPanel.gd @@ -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 \ No newline at end of file diff --git a/Systems/Cards/CardBankItem.gd b/Systems/Cards/CardBankItem.gd index c2c0a30..96429ca 100644 --- a/Systems/Cards/CardBankItem.gd +++ b/Systems/Cards/CardBankItem.gd @@ -19,10 +19,18 @@ var rank_colors = { func _ready(): # 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 - gui_input.connect(_on_gui_input) if card_frame: 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): current_card = card diff --git a/Systems/Cards/CardSlot.gd b/Systems/Cards/CardSlot.gd index bf48c41..463394d 100644 --- a/Systems/Cards/CardSlot.gd +++ b/Systems/Cards/CardSlot.gd @@ -29,6 +29,10 @@ func _ready(): gui_input.connect(_on_gui_input) if card_border: 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): current_card = card diff --git a/Systems/Game/DeckManagerScreen.gd b/Systems/Game/DeckManagerScreen.gd index da80b17..04b976a 100644 --- a/Systems/Game/DeckManagerScreen.gd +++ b/Systems/Game/DeckManagerScreen.gd @@ -7,6 +7,7 @@ signal back_pressed @onready var deckGrid = $MainContainer/GridScrollContainer/GridContainer @onready var bankContainer = $MainContainer/BankContainer/ScrollContainer/VBoxContainer @onready var backButton = $BackButton +@onready var card_preview = $CardPreviewPanel # Default deck size (can be overridden via options) var maxDeckSize = 35 @@ -15,12 +16,16 @@ var bankCards = [] # Cards available but not in deck # The current deck var currentDeck = [] +var current_preview_card = null func _ready(): # Connect back button if backButton: backButton.connect("pressed", Callable(self, "_on_backButton_pressed")) + if card_preview: + card_preview.visible = false + func initialize(options = null): # Process options if provided @@ -68,7 +73,7 @@ func setupDeckGrid(): child.queue_free() # Calculate grid dimensions - var cols = 7 #check screen to deteremine + var cols = 4 #check screen to deteremine var rows = maxDeckSize / cols deckGrid.columns = cols @@ -79,6 +84,7 @@ func setupDeckGrid(): # Connect signals card_slot.connect("card_selected", Callable(self, "_on_deck_card_selected")) + _connect_hover_signals(card_slot) # Set card if available if i < currentDeck.size(): @@ -86,6 +92,13 @@ func setupDeckGrid(): else: 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(): # Clear existing children for child in bankContainer.get_children(): @@ -97,6 +110,7 @@ func populateBank(): bankContainer.add_child(card_item) card_item.set_card(card) card_item.connect("card_selected", Callable(self, "_on_bank_card_selected")) + _connect_hover_signals(card_item) func _on_deck_card_selected(card_slot, card): if card: @@ -111,6 +125,8 @@ func _on_deck_card_selected(card_slot, card): # Update UI card_slot.clear() populateBank() + if current_preview_card == card: + hide_card_preview() func _on_bank_card_selected(card_item, card): 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) 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(): if deckManager: # Save the current deck to the deck manager diff --git a/card_preview_panel.tscn b/card_preview_panel.tscn new file mode 100644 index 0000000..f1898c4 --- /dev/null +++ b/card_preview_panel.tscn @@ -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" diff --git a/deck_manager_screen.tscn b/deck_manager_screen.tscn index 388c992..ea6ca6c 100644 --- a/deck_manager_screen.tscn +++ b/deck_manager_screen.tscn @@ -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="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"] [node name="DeckManagerScreen" type="Control"] @@ -32,12 +33,24 @@ theme_override_font_sizes/font_size = 36 text = "DECK MANAGER" 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="."] layout_mode = 1 anchors_preset = 15 anchor_right = 1.0 anchor_bottom = 1.0 -offset_left = 20.0 +offset_left = 325.0 offset_top = 100.0 offset_right = -20.0 offset_bottom = -60.0