diff --git a/.godot/editor/create_recent.Node b/.godot/editor/create_recent.Node index 701732f556c847436fc39f1a55ec263c52ddb007..8fddfd9f7b34fbc9a841ff024a5bc0007638c8a8 100644 --- a/.godot/editor/create_recent.Node +++ b/.godot/editor/create_recent.Node @@ -1,5 +1,5 @@ -ColorRect Label +ColorRect TextureRect HBoxContainer MarginContainer diff --git a/.godot/editor/editor_layout.cfg b/.godot/editor/editor_layout.cfg index 6c9b251f1d6fc0a9599da16f7a49e7daadf178f6..0727ffe2568147209e4cc23e47dd069fa5a98ff2 100644 --- a/.godot/editor/editor_layout.cfg +++ b/.godot/editor/editor_layout.cfg @@ -28,14 +28,14 @@ dock_5="Inspector,Node,History" open_scenes=PackedStringArray("res://scenes/game.tscn", "res://main.tscn", "res://scenes/Shop.tscn", "res://scenes/ShopItem.tscn") current_scene="res://scenes/ShopItem.tscn" -center_split_offset=-336 +center_split_offset=-319 selected_default_debugger_tab_idx=0 -selected_main_editor_idx=0 +selected_main_editor_idx=2 selected_bottom_panel_item=0 [ScriptEditor] -open_scripts=["res://scripts/game.gd", "res://README.md", "res://scripts/scene_manager.gd", "res://scripts/Shop.gd"] +open_scripts=["res://scripts/game.gd", "res://README.md", "res://scripts/scene_manager.gd", "res://scripts/Shop.gd", "res://scenes/shop_item.gd"] selected_script="res://scripts/game.gd" open_help=[] script_split_offset=70 diff --git a/.godot/editor/filesystem_update4 b/.godot/editor/filesystem_update4 index 89772e7b70b93a2af82e65a9bed3daa63e62d5b9..21c9f9399b2c2beb986379113c68f0b842f284e0 100644 --- a/.godot/editor/filesystem_update4 +++ b/.godot/editor/filesystem_update4 @@ -20,3 +20,4 @@ res://scripts/Knight.gd res://scripts/Assassin.gd res://scripts/Mage.gd res://scripts/Wizard.gd +res://scenes/shop_item.gd diff --git a/.godot/editor/game.tscn-editstate-c2a7af834e91ff64325daddf58e45dc0.cfg b/.godot/editor/game.tscn-editstate-c2a7af834e91ff64325daddf58e45dc0.cfg index ab9a8f19095bdc9556d1e3b4d0ee7a6e2ddca80c..3acd289e16a35bd2066572357b1462e83e5d0a42 100644 --- a/.godot/editor/game.tscn-editstate-c2a7af834e91ff64325daddf58e45dc0.cfg +++ b/.godot/editor/game.tscn-editstate-c2a7af834e91ff64325daddf58e45dc0.cfg @@ -175,4 +175,4 @@ Anim={ "zfar": 4000.01, "znear": 0.05 } -selected_nodes=Array[NodePath]([NodePath("/root/@EditorNode@16886/@Panel@13/@VBoxContainer@14/DockHSplitLeftL/DockHSplitLeftR/DockHSplitMain/@VBoxContainer@25/DockVSplitCenter/@VSplitContainer@52/@VBoxContainer@53/@PanelContainer@98/MainScreen/@CanvasItemEditor@9272/@VSplitContainer@9094/@HSplitContainer@9096/@HSplitContainer@9098/@Control@9099/@SubViewportContainer@9100/@SubViewport@9101/ShopItem/MarginContainer/VBoxContainer/SoldOutLabel")]) +selected_nodes=Array[NodePath]([NodePath("/root/@EditorNode@16886/@Panel@13/@VBoxContainer@14/DockHSplitLeftL/DockHSplitLeftR/DockHSplitMain/@VBoxContainer@25/DockVSplitCenter/@VSplitContainer@52/@VBoxContainer@53/@PanelContainer@98/MainScreen/@CanvasItemEditor@9272/@VSplitContainer@9094/@HSplitContainer@9096/@HSplitContainer@9098/@Control@9099/@SubViewportContainer@9100/@SubViewport@9101/ShopItem")]) diff --git a/.godot/editor/main.tscn-editstate-3070c538c03ee49b7677ff960a3f5195.cfg b/.godot/editor/main.tscn-editstate-3070c538c03ee49b7677ff960a3f5195.cfg index b3165f8001be059c7877f054e4fd4797c23df880..839fabb1a72bf72ef7ed3248b6c87504a7d6bb21 100644 --- a/.godot/editor/main.tscn-editstate-3070c538c03ee49b7677ff960a3f5195.cfg +++ b/.godot/editor/main.tscn-editstate-3070c538c03ee49b7677ff960a3f5195.cfg @@ -175,4 +175,4 @@ Anim={ "zfar": 4000.01, "znear": 0.05 } -selected_nodes=Array[NodePath]([NodePath("/root/@EditorNode@16886/@Panel@13/@VBoxContainer@14/DockHSplitLeftL/DockHSplitLeftR/DockHSplitMain/@VBoxContainer@25/DockVSplitCenter/@VSplitContainer@52/@VBoxContainer@53/@PanelContainer@98/MainScreen/@CanvasItemEditor@9272/@VSplitContainer@9094/@HSplitContainer@9096/@HSplitContainer@9098/@Control@9099/@SubViewportContainer@9100/@SubViewport@9101/ShopItem/MarginContainer/VBoxContainer/SoldOutLabel")]) +selected_nodes=Array[NodePath]([NodePath("/root/@EditorNode@16886/@Panel@13/@VBoxContainer@14/DockHSplitLeftL/DockHSplitLeftR/DockHSplitMain/@VBoxContainer@25/DockVSplitCenter/@VSplitContainer@52/@VBoxContainer@53/@PanelContainer@98/MainScreen/@CanvasItemEditor@9272/@VSplitContainer@9094/@HSplitContainer@9096/@HSplitContainer@9098/@Control@9099/@SubViewportContainer@9100/@SubViewport@9101/ShopItem")]) diff --git a/.godot/editor/project_metadata.cfg b/.godot/editor/project_metadata.cfg index 2066ffecf9210b3e9009fe09e4c6e63ea94849db..d05792b31b2ac7fec0b439bf54680dbe92159591 100644 --- a/.godot/editor/project_metadata.cfg +++ b/.godot/editor/project_metadata.cfg @@ -12,7 +12,7 @@ create_new_node=Rect2(2430, 190, 900, 700) [recent_files] scenes=["res://scenes/ShopItem.tscn", "res://Shop.tscn", "res://main.tscn", "res://scenes/game.tscn"] -scripts=["res://scripts/scene_manager.gd", "res://scripts/game.gd", "res://Shop.gd", "res://README.md"] +scripts=["res://scenes/shop_item.gd", "res://scripts/scene_manager.gd", "res://scripts/game.gd", "res://Shop.gd", "res://README.md"] [script_setup] diff --git a/.godot/editor/script_editor_cache.cfg b/.godot/editor/script_editor_cache.cfg index d109ea4f3b1c38e50d5f9036d3dd03be1bf08ca0..050b59c02a3a36737188c1c5526e00af4629f2b9 100644 --- a/.godot/editor/script_editor_cache.cfg +++ b/.godot/editor/script_editor_cache.cfg @@ -17,11 +17,11 @@ state={ state={ "bookmarks": PackedInt32Array(), "breakpoints": PackedInt32Array(), -"column": 46, +"column": 37, "folded_lines": Array[int]([]), "h_scroll_position": 0, -"row": 519, -"scroll_position": 511.0, +"row": 52, +"scroll_position": 41.0, "selection": false, "syntax_highlighter": "GDScript" } @@ -31,11 +31,11 @@ state={ state={ "bookmarks": PackedInt32Array(), "breakpoints": PackedInt32Array(), -"column": 33, +"column": 52, "folded_lines": Array[int]([]), "h_scroll_position": 0, -"row": 68, -"scroll_position": 58.0, +"row": 34, +"scroll_position": 23.0, "selection": false, "syntax_highlighter": "GDScript" } @@ -49,7 +49,21 @@ state={ "folded_lines": Array[int]([]), "h_scroll_position": 0, "row": 24, -"scroll_position": 15.0, +"scroll_position": 12.0, +"selection": false, +"syntax_highlighter": "GDScript" +} + +[res://scenes/shop_item.gd] + +state={ +"bookmarks": PackedInt32Array(), +"breakpoints": PackedInt32Array(), +"column": 1, +"folded_lines": Array[int]([]), +"h_scroll_position": 0, +"row": 23, +"scroll_position": 3.0, "selection": false, "syntax_highlighter": "GDScript" } diff --git a/scenes/ShopItem.tscn b/scenes/ShopItem.tscn index e2a2d7a9eaaf34b293a3125433229ef156c09192..39d1a38dcbd2c2891d4b9a9d592f4535e396557a 100644 --- a/scenes/ShopItem.tscn +++ b/scenes/ShopItem.tscn @@ -1,4 +1,6 @@ -[gd_scene load_steps=2 format=3 uid="uid://cjkxtlxn3rgo5"] +[gd_scene load_steps=3 format=3 uid="uid://cjkxtlxn3rgo5"] + +[ext_resource type="Script" path="res://scenes/shop_item.gd" id="1_gxhtm"] [sub_resource type="StyleBoxFlat" id="StyleBoxFlat_yun3n"] bg_color = Color(0.408717, 0.672092, 0.458479, 1) @@ -8,6 +10,7 @@ custom_minimum_size = Vector2(150, 200) offset_right = 8.0 offset_bottom = 66.0 theme_override_styles/panel = SubResource("StyleBoxFlat_yun3n") +script = ExtResource("1_gxhtm") [node name="MarginContainer" type="MarginContainer" parent="."] layout_mode = 2 @@ -32,6 +35,9 @@ horizontal_alignment = 1 layout_mode = 2 horizontal_alignment = 1 +[node name="TierLabel" type="Label" parent="MarginContainer/VBoxContainer"] +layout_mode = 2 + [node name="BuyButton" type="Button" parent="MarginContainer/VBoxContainer"] custom_minimum_size = Vector2(100, 40) layout_mode = 2 diff --git a/scenes/shop_item.gd b/scenes/shop_item.gd new file mode 100644 index 0000000000000000000000000000000000000000..e82a1692447f267d420ddf5e665d09bb6dd62373 --- /dev/null +++ b/scenes/shop_item.gd @@ -0,0 +1,26 @@ +extends PanelContainer + +func set_tier_style(tier: String): + var style = StyleBoxFlat.new() + + # Define tier colors + var tier_colors = { + "bronze": Color("#cd7f32"), + "silver": Color("#c0c0c0"), + "gold": Color("#ffd700") + } + + # Style configuration + style.bg_color = tier_colors[tier] + style.corner_radius_top_left = 8 + style.corner_radius_top_right = 8 + style.corner_radius_bottom_right = 8 + style.corner_radius_bottom_left = 8 + style.border_width_bottom = 2 + style.border_width_top = 2 + style.border_width_left = 2 + style.border_width_right = 2 + style.border_color = Color(0, 0, 0, 0.3) + + # Apply the style to THIS PanelContainer + self.add_theme_stylebox_override("panel", style) diff --git a/scripts/Shop.gd b/scripts/Shop.gd index f5e3509242853696b4c8c9a16e8c9c13e390d182..f393806fda6d6a9c3048b8e9c01450bc76ac5de0 100644 --- a/scripts/Shop.gd +++ b/scripts/Shop.gd @@ -9,25 +9,34 @@ signal next_round_requested var shop_items = { "pieces": [ - {"name": "Pawn", "price": 1, "texture": "res://assets/Resized Chess Piece Assets/White_Pawn.png", "purchased": false}, - {"name": "Rook", "price": 3, "texture": "res://assets/Resized Chess Piece Assets/White_Rook.png", "purchased": false}, - {"name": "Bishop", "price": 3, "texture": "res://assets/Resized Chess Piece Assets/White_Bishop.png", "purchased": false}, - {"name": "Knight", "price": 3, "texture": "res://assets/Resized Chess Piece Assets/White_Knight.png", "purchased": false}, - {"name": "Queen", "price": 5, "texture": "res://assets/Resized Chess Piece Assets/White_Queen.png", "purchased": false} + {"name": "Pawn", "price": 1, "tier": "bronze", "texture": "res://assets/...", "purchased": false}, + {"name": "Rook", "price": 3, "tier": "silver", "texture": "res://assets/...", "purchased": false}, + {"name": "Bishop", "price": 3, "tier": "silver", "texture": "res://assets/...", "purchased": false}, + {"name": "Knight", "price": 3, "tier": "silver", "texture": "res://assets/...", "purchased": false}, + {"name": "Queen", "price": 5, "tier": "gold", "texture": "res://assets/...", "purchased": false} ], "upgrades": [ - {"name": "Upgrade 1", "price": 3, "texture": "res://assets/Resized Chess Piece Assets/Black_Pawn.png", "purchased": false}, - {"name": "Upgrade 2", "price": 5, "texture": "res://assets/Resized Chess Piece Assets/Black_Rook.png", "purchased": false}, - {"name": "Upgrade 3", "price": 5, "texture": "res://assets/Resized Chess Piece Assets/Black_Bishop.png", "purchased": false}, - {"name": "Upgrade 4", "price": 5, "texture": "res://assets/Resized Chess Piece Assets/Black_Knight.png", "purchased": false}, - {"name": "Upgrade 5", "price": 5, "texture": "res://assets/Resized Chess Piece Assets/Black_Queen.png", "purchased": false} + {"name": "Upgrade 1", "price": 3, "tier": "bronze", "texture": "res://assets/Resized Chess Piece Assets/Black_Pawn.png", "purchased": false}, + {"name": "Upgrade 2", "price": 5, "tier": "silver", "texture": "res://assets/Resized Chess Piece Assets/Black_Rook.png", "purchased": false}, + {"name": "Upgrade 3", "price": 5, "tier": "silver", "texture": "res://assets/Resized Chess Piece Assets/Black_Bishop.png", "purchased": false}, + {"name": "Upgrade 4", "price": 5, "tier": "silver", "texture": "res://assets/Resized Chess Piece Assets/Black_Knight.png", "purchased": false}, + {"name": "Upgrade 5", "price": 5, "tier": "gold", "texture": "res://assets/Resized Chess Piece Assets/Black_Queen.png", "purchased": false} ] } +var tier_weights = { + "bronze": 5, + "silver": 3, + "gold": 1 +} + func _ready(): self.visible = false # Start hidden + # Each item is 150, 200 with 10 margin on each side, 2 rows and 3 columns + var _shop_size = Vector2(570, 480) print("Shop scene loaded!") # Check if this prints populate_rows() # Populate the shop rows + # self.custom_minimum_size = get_viewport_rect().size # Fill the screen func set_visibility(visible: bool): self.visible = visible @@ -36,19 +45,51 @@ func _on_back_button_pressed(): get_tree().change_scene_to_file("res://Game.tscn") # Return to game func populate_rows(): - for item in shop_items["pieces"]: - # Create a copy to avoid modifying the original data - var item_copy = item.duplicate() - add_item_to_row(item_copy, $MainContainer/RowsContainer/PiecesRow) + clear_row($MainContainer/RowsContainer/PiecesRow) + clear_row($MainContainer/RowsContainer/UpgradesRow) + + # Add 3 random pieces + for i in 3: + var piece = select_random_item("pieces") + add_item_to_row(piece, $MainContainer/RowsContainer/PiecesRow) + + # Add 3 random upgrades + for i in 3: + var upgrade = select_random_item("upgrades") + add_item_to_row(upgrade, $MainContainer/RowsContainer/UpgradesRow) - for item in shop_items["upgrades"]: - var item_copy = item.duplicate() - add_item_to_row(item_copy, $MainContainer/RowsContainer/UpgradesRow) + +func clear_row(row: HBoxContainer): + for child in row.get_children(): + child.queue_free() + + +func select_random_item(category: String) -> Dictionary: + var items = shop_items[category] + var total_weight = 0 + + # Calculate total weight + for item in items: + total_weight += tier_weights[item["tier"]] + + # Select random item + var random_value = randf() * total_weight + var cumulative = 0.0 + + for item in items: + cumulative += tier_weights[item["tier"]] + if random_value < cumulative: + return item.duplicate() # Return a copy to avoid modifying original + + return items[0].duplicate() # Fallback func add_item_to_row(item_data: Dictionary, row: HBoxContainer): var shop_item = shop_item_scene.instantiate() + # Set the tier style FIRST + shop_item.set_tier_style(item_data["tier"]) + shop_item.get_node("MarginContainer/VBoxContainer/ItemName").text = item_data["name"] shop_item.get_node("MarginContainer/VBoxContainer/ItemPrice").text = "%dg" % item_data["price"] shop_item.get_node("MarginContainer/VBoxContainer/ItemSprite").texture = load(item_data["texture"]) @@ -57,8 +98,18 @@ func add_item_to_row(item_data: Dictionary, row: HBoxContainer): var buy_button = shop_item.get_node("MarginContainer/VBoxContainer/BuyButton") buy_button.connect("pressed", Callable(self, "_on_buy_button_pressed").bind(item_data, shop_item)) - # # Connect the button to a handler, passing the item_data - # buy_button.connect("pressed", Callable(self, "_on_buy_button_pressed").bind(item_data)) + # Add tier indicator + var tier_label = shop_item.get_node("MarginContainer/VBoxContainer/TierLabel") + tier_label.text = item_data["tier"].capitalize() + + # Optional: Color code tiers + match item_data["tier"]: + "bronze": + tier_label.add_theme_color_override("font_color", Color("#cd7f32")) + "silver": + tier_label.add_theme_color_override("font_color", Color("#c0c0c0")) + "gold": + tier_label.add_theme_color_override("font_color", Color("#ffd700")) row.add_child(shop_item) diff --git a/scripts/game.gd b/scripts/game.gd index e5c882dbea10aca19ea2dcc7983ca151d8e79d4b..f6585a7a1bd85c2e7c62713d911c424896addd8b 100644 --- a/scripts/game.gd +++ b/scripts/game.gd @@ -48,13 +48,17 @@ var player_turn : bool = true func _ready() -> void: shop = shop_scene.instantiate() add_child(shop) - shop.position = Vector2(200, 10) + var viewport_size = get_viewport().get_visible_rect().size + shop.position = (viewport_size / 2) - Vector2(570, 670) / 2 shop.visible = false # Start hidden update_gold_display() # Initialize gold display set_gold_display_position() # Set the anchors and margins for the gold display shop.purchase_attempted.connect(_on_purchase_attempted) shop.next_round_requested.connect(_on_next_round_requested) + # Connect the resize signal + get_viewport().connect("size_changed", Callable(self, "_on_viewport_size_changed")) + DisplayServer.window_set_min_size(Vector2(1152, 648)) # Set minimum window size #creates 2D array for board, with empty (null) spaces @@ -563,3 +567,8 @@ func set_gold_display_position(): gold_display.anchor_top = 0.0 gold_display.anchor_right = 1.0 gold_display.anchor_bottom = 0.1 + +func _on_viewport_size_changed(): + if shop: + var viewport_size = get_viewport().get_visible_rect().size + shop.position = viewport_size / 2