diff --git a/.godot/editor/create_recent.Node b/.godot/editor/create_recent.Node index 027464d80804ce35f9cb2b1fc76080e3fdcb6937..b7fd6c6a3be00b5efcf0f44d60c750bc76c53674 100644 --- a/.godot/editor/create_recent.Node +++ b/.godot/editor/create_recent.Node @@ -1,14 +1,14 @@ Label -Button TextureRect +HBoxContainer +MarginContainer +Button +VBoxContainer +PanelContainer Node2D Node Control AnimationPlayer ColorRect CanvasLayer -VBoxContainer Sprite2D -Panel -RichTextLabel -HBoxContainer diff --git a/.godot/editor/editor_layout.cfg b/.godot/editor/editor_layout.cfg index 224c5e2e0cd4d188e573347396751a1957c099b7..90deb6bec8af045d10f428957ac6588871d0cb87 100644 --- a/.godot/editor/editor_layout.cfg +++ b/.godot/editor/editor_layout.cfg @@ -2,7 +2,7 @@ dock_3_selected_tab_idx=0 dock_4_selected_tab_idx=0 -dock_5_selected_tab_idx=1 +dock_5_selected_tab_idx=0 dock_floating={} dock_bottom=[] dock_closed=[] @@ -10,7 +10,7 @@ dock_split_2=0 dock_split_3=0 dock_hsplit_1=0 <<<<<<<HEADdock_hsplit_2=498 -dock_hsplit_3=-290 +dock_hsplit_3=-436 dock_hsplit_2=306 dock_hsplit_4=0 dock_filesystem_h_split_offset=240 @@ -18,7 +18,7 @@ dock_filesystem_v_split_offset=0 dock_filesystem_display_mode=0 dock_filesystem_file_sort=0 dock_filesystem_file_list_display_mode=1 -dock_filesystem_selected_paths=PackedStringArray("res://scenes/Shop.tscn") +dock_filesystem_selected_paths=PackedStringArray("res://scenes/ShopItem.tscn") dock_filesystem_uncollapsed_paths=PackedStringArray("Favorites", "res://", "res://scenes/") dock_3="Scene,Import" dock_4="FileSystem" @@ -26,16 +26,16 @@ dock_5="Inspector,Node,History" [EditorNode] -open_scenes=PackedStringArray("res://scenes/game.tscn", "res://main.tscn", "res://scenes/Shop.tscn") -current_scene="res://scenes/Shop.tscn" -center_split_offset=-252 +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=-314 selected_default_debugger_tab_idx=0 -selected_main_editor_idx=2 +selected_main_editor_idx=0 selected_bottom_panel_item=0 [ScriptEditor] -open_scripts=["res://scripts/game.gd", "res://README.md", "res://scripts/Shop.gd"] +open_scripts=["res://scripts/game.gd", "res://README.md", "res://scripts/scene_manager.gd", "res://scripts/Shop.gd"] selected_script="res://scripts/Shop.gd" open_help=[] script_split_offset=70 diff --git a/.godot/editor/filesystem_update4 b/.godot/editor/filesystem_update4 index 021a5938f55ec2ad448d2d1c7dfdaab4cd0afae3..bc232df7c2dda5f864c56468600b4031e58c4231 100644 --- a/.godot/editor/filesystem_update4 +++ b/.godot/editor/filesystem_update4 @@ -9,3 +9,5 @@ res://scenes/game.tscn res://main.tscn res://scenes/Shop.tscn res://scripts/Shop.gd +res://scenes/ShopItem.tscn +res://scripts/Piece.gd diff --git a/.godot/editor/game.tscn-editstate-c2a7af834e91ff64325daddf58e45dc0.cfg b/.godot/editor/game.tscn-editstate-c2a7af834e91ff64325daddf58e45dc0.cfg index c5053912d751218b6f11be54ccf85a91bc508847..e9cdfcf48c6da90050394bc926a8102515630aa4 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/Shop/Item1")]) +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/ItemSprite")]) diff --git a/.godot/editor/main.tscn-editstate-3070c538c03ee49b7677ff960a3f5195.cfg b/.godot/editor/main.tscn-editstate-3070c538c03ee49b7677ff960a3f5195.cfg index 6278739e173a4509253cd1bf685b1e15526ae8ec..a564203b9dfc044bee4a937a438243286270c16f 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/Shop/Item1")]) +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/ItemSprite")]) diff --git a/.godot/editor/project_metadata.cfg b/.godot/editor/project_metadata.cfg index b57aa133e9e486b54ea77236d7839c2edd7bd25e..0fc6f8d2c2f12d9625adb309f6b8b9047f1e5610 100644 --- a/.godot/editor/project_metadata.cfg +++ b/.godot/editor/project_metadata.cfg @@ -11,9 +11,14 @@ create_new_node=Rect2(2430, 190, 900, 700) [recent_files] -scenes=["res://Shop.tscn", "res://main.tscn", "res://scenes/game.tscn"] -scripts=["res://scripts/game.gd", "res://Shop.gd", "res://README.md"] +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"] [script_setup] last_selected_language="GDScript" + +[color_picker] + +picker_shape=3 +recent_presets=PackedColorArray(0.408717, 0.672092, 0.458479, 1) diff --git a/.godot/editor/script_editor_cache.cfg b/.godot/editor/script_editor_cache.cfg index 42173071a2269474bce4563a0dae0fb48579ff42..43d3b31795692171043c409ce07c65abc38fa651 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": 9, +"column": 16, "folded_lines": Array[int]([]), "h_scroll_position": 0, -"row": 50, -"scroll_position": 39.0, +"row": 47, +"scroll_position": 38.0, "selection": false, "syntax_highlighter": "GDScript" } @@ -31,11 +31,25 @@ state={ state={ "bookmarks": PackedInt32Array(), "breakpoints": PackedInt32Array(), -"column": 18, +"column": 33, "folded_lines": Array[int]([]), "h_scroll_position": 0, -"row": 35, -"scroll_position": 0.0, +"row": 72, +"scroll_position": 60.0, +"selection": false, +"syntax_highlighter": "GDScript" +} + +[res://scripts/scene_manager.gd] + +state={ +"bookmarks": PackedInt32Array(), +"breakpoints": PackedInt32Array(), +"column": 0, +"folded_lines": Array[int]([]), +"h_scroll_position": 0, +"row": 24, +"scroll_position": 15.0, "selection": false, "syntax_highlighter": "GDScript" } diff --git a/.godot/uid_cache.bin b/.godot/uid_cache.bin index db3632908ccd371439677e93a6be9e5d85f34bdb..a396f2727697105e1f96727d0ce929080ca2cd35 100644 Binary files a/.godot/uid_cache.bin and b/.godot/uid_cache.bin differ diff --git a/scenes/Shop.tscn b/scenes/Shop.tscn index c57ba06b909091e61c7fb4cff7507d4b56402e5b..5ba5fdeb320b4618b0c2c31157e37bdb162dbc31 100644 --- a/scenes/Shop.tscn +++ b/scenes/Shop.tscn @@ -1,26 +1,20 @@ -[gd_scene load_steps=2 format=3 uid="uid://ct878s7wjsq77"] +[gd_scene load_steps=3 format=3 uid="uid://ct878s7wjsq77"] [ext_resource type="Script" path="res://scripts/Shop.gd" id="1_8nmap"] +[sub_resource type="PlaceholderTexture2D" id="PlaceholderTexture2D_rcoi1"] +size = Vector2(16, 16) + [node name="Shop" type="Node2D"] script = ExtResource("1_8nmap") [node name="Background" type="TextureRect" parent="."] +visible = false offset_right = 131.0 offset_bottom = 101.0 -[node name="Title" type="Label" parent="."] -anchors_preset = 5 -anchor_left = 0.5 -anchor_right = 0.5 -offset_left = -20.0 -offset_top = -24.0 -offset_right = 20.0 -offset_bottom = -1.0 -grow_horizontal = 2 -text = "Shop" - [node name="Item1" type="Button" parent="."] +visible = false anchors_preset = 8 anchor_left = 0.5 anchor_top = 0.5 @@ -35,26 +29,74 @@ grow_vertical = 2 text = "Item 1" [node name="Item2" type="Button" parent="."] +visible = false offset_left = 2.0 offset_top = 30.0 offset_right = 59.0 offset_bottom = 61.0 text = "Item 2" -[node name="GoldDisplay" type="Label" parent="."] -offset_left = -21.0 -offset_top = 2.0 -offset_right = 21.0 -offset_bottom = 26.0 - -[node name="BackButton" type="Button" parent="."] -offset_left = -23.0 -offset_top = 68.0 -offset_right = 22.0 -offset_bottom = 99.0 -text = "Back +[node name="MainContainer" type="MarginContainer" parent="."] +offset_right = 40.0 +offset_bottom = 40.0 +theme_override_constants/margin_left = 20 +theme_override_constants/margin_top = 20 +theme_override_constants/margin_right = 20 +theme_override_constants/margin_bottom = 20 + +[node name="GoldDisplay" type="MarginContainer" parent="MainContainer"] +layout_mode = 2 +size_flags_horizontal = 8 +size_flags_vertical = 0 +theme_override_constants/margin_top = 20 +theme_override_constants/margin_right = 20 + +[node name="HBoxContainer" type="HBoxContainer" parent="MainContainer/GoldDisplay"] +layout_mode = 2 +theme_override_constants/separation = 10 + +[node name="GoldIcon" type="TextureRect" parent="MainContainer/GoldDisplay/HBoxContainer"] +layout_mode = 2 +texture = SubResource("PlaceholderTexture2D_rcoi1") +stretch_mode = 2 + +[node name="GoldAmount" type="Label" parent="MainContainer/GoldDisplay/HBoxContainer"] +layout_mode = 2 +theme_override_font_sizes/font_size = 24 +text = "0" + +[node name="RowsContainer" type="VBoxContainer" parent="MainContainer"] +layout_mode = 2 +theme_override_constants/separation = 30 + +[node name="Title" type="Label" parent="MainContainer/RowsContainer"] +layout_mode = 2 +theme_override_font_sizes/font_size = 32 +text = "Shop" +horizontal_alignment = 1 + +[node name="PiecesRow" type="HBoxContainer" parent="MainContainer/RowsContainer"] +layout_mode = 2 +theme_override_constants/separation = 20 + +[node name="UpgradesRow" type="HBoxContainer" parent="MainContainer/RowsContainer"] +layout_mode = 2 +theme_override_constants/separation = 20 + +[node name="BottomSection" type="MarginContainer" parent="MainContainer/RowsContainer"] +layout_mode = 2 +theme_override_constants/margin_left = 20 +theme_override_constants/margin_top = 20 +theme_override_constants/margin_right = 20 +theme_override_constants/margin_bottom = 20 + +[node name="NextRoundButton" type="Button" parent="MainContainer/RowsContainer/BottomSection"] +layout_mode = 2 +size_flags_horizontal = 8 +text = "Next Round " [connection signal="item_purchased" from="." to="." method="_on_item_purchased"] [connection signal="pressed" from="Item1" to="." method="_on_item_1_pressed"] [connection signal="pressed" from="Item2" to="." method="_on_item_2_pressed"] +[connection signal="pressed" from="MainContainer/RowsContainer/BottomSection/NextRoundButton" to="." method="_on_next_round_button_pressed"] diff --git a/scenes/ShopItem.tscn b/scenes/ShopItem.tscn new file mode 100644 index 0000000000000000000000000000000000000000..d7308a4f23997c231df13b3b405a12de25096104 --- /dev/null +++ b/scenes/ShopItem.tscn @@ -0,0 +1,38 @@ +[gd_scene load_steps=2 format=3 uid="uid://cjkxtlxn3rgo5"] + +[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_yun3n"] +bg_color = Color(0.408717, 0.672092, 0.458479, 1) + +[node name="ShopItem" type="PanelContainer"] +custom_minimum_size = Vector2(150, 200) +offset_right = 8.0 +offset_bottom = 66.0 +theme_override_styles/panel = SubResource("StyleBoxFlat_yun3n") + +[node name="MarginContainer" type="MarginContainer" parent="."] +layout_mode = 2 +theme_override_constants/margin_left = 10 +theme_override_constants/margin_top = 10 +theme_override_constants/margin_right = 10 +theme_override_constants/margin_bottom = 10 + +[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer"] +layout_mode = 2 + +[node name="ItemSprite" type="TextureRect" parent="MarginContainer/VBoxContainer"] +custom_minimum_size = Vector2(64, 64) +layout_mode = 2 +size_flags_horizontal = 4 + +[node name="ItemName" type="Label" parent="MarginContainer/VBoxContainer"] +layout_mode = 2 +horizontal_alignment = 1 + +[node name="ItemPrice" type="Label" parent="MarginContainer/VBoxContainer"] +layout_mode = 2 +horizontal_alignment = 1 + +[node name="BuyButton" type="Button" parent="MarginContainer/VBoxContainer"] +custom_minimum_size = Vector2(100, 40) +layout_mode = 2 +text = "BUY" diff --git a/scenes/game.tscn b/scenes/game.tscn index 72a98bdf1e807d24bebf3db06bd10b63e5dae71c..3a2e16344dfad4c88761c4470c0825dccccac5ac 100644 --- a/scenes/game.tscn +++ b/scenes/game.tscn @@ -73,7 +73,8 @@ offset_bottom = 20.0 grow_horizontal = 0 size_flags_horizontal = 8 size_flags_vertical = 0 -text = "Shop Button" +text = "Shop Toggle +" [node name="GoldDisplay" type="Label" parent="."] anchors_preset = 1 diff --git a/scripts/Shop.gd b/scripts/Shop.gd index 18c06d38f7028a942cdee94301c6292d7f00137a..2e95e570f89202d2afaa9b28a69de34bc8c991b4 100644 --- a/scripts/Shop.gd +++ b/scripts/Shop.gd @@ -3,55 +3,85 @@ extends Node2D signal item_purchased(item_name: String) # Define the signal signal gold_spent(amount: int) +signal next_round_requested @onready var gold_display: Label = $GoldDisplay -var player_gold: int = 0 # Declare player_gold variable +@onready var shop_item_scene = preload("res://scenes/ShopItem.tscn") +@onready var gold_amount: Label = $MainContainer/GoldDisplay/HBoxContainer/GoldAmount +@onready var gold_icon: TextureRect = $MainContainer/GoldDisplay/HBoxContainer/GoldIcon + +var player_gold: int = 0 + +var shop_items = { + "pieces": [ + {"name": "Pawn", "price": 1, "texture": "res://assets/Resized Chess Piece Assets/White_Pawn.png"}, + {"name": "Rook", "price": 3, "texture": "res://assets/Resized Chess Piece Assets/White_Rook.png"}, + {"name": "Bishop", "price": 3, "texture": "res://assets/Resized Chess Piece Assets/White_Bishop.png"}, + {"name": "Knight", "price": 3, "texture": "res://assets/Resized Chess Piece Assets/White_Knight.png"}, + {"name": "Queen", "price": 5, "texture": "res://assets/Resized Chess Piece Assets/White_Queen.png"} + ], + "upgrades": [ + {"name": "Upgrade 1", "price": 3, "texture": "res://assets/Resized Chess Piece Assets/Black_Pawn.png"}, + {"name": "Upgrade 2", "price": 5, "texture": "res://assets/Resized Chess Piece Assets/Black_Rook.png"}, + {"name": "Upgrade 3", "price": 5, "texture": "res://assets/Resized Chess Piece Assets/Black_Bishop.png"}, + {"name": "Upgrade 4", "price": 5, "texture": "res://assets/Resized Chess Piece Assets/Black_Knight.png"}, + {"name": "Upgrade 5", "price": 5, "texture": "res://assets/Resized Chess Piece Assets/Black_Queen.png"} + ] +} func _ready(): self.visible = false # Start hidden print("Shop scene loaded!") # Check if this prints + populate_rows() # Populate the shop rows update_gold_display(player_gold) # Initialize gold display - # connect the signals - $Item1.connect("pressed", Callable(self, "_on_item1_pressed")) - $Item2.connect("pressed", Callable(self, "_on_item2_pressed")) func set_visibility(visible: bool): self.visible = visible func update_gold_display(gold: int): player_gold = gold # Store gold locally for shop logic - gold_display.text = "Gold: %d" % player_gold - -func _on_item1_pressed(): - print("Item1 pressed!") - if player_gold >= 1: # Example cost - player_gold -= 1 - # Apply item effect (e.g., upgrade a piece) - update_gold_display(player_gold) - emit_signal("gold_spent", 1) # Emit the signal - emit_signal("item_purchased", "item1") # Notify main game scene - print("SHOP: Item 1 purchased") - -func _on_item2_pressed(): - print("Item2 pressed!") - if player_gold >= 2: # Example cost for Item2 - player_gold -= 2 - update_gold_display(player_gold) - emit_signal("gold_spent", 2) # Emit the signal - emit_signal("item_purchased", "item2") # Emit signal for Item2 - print("SHOP: Item 2 purchased") + gold_amount.text = str(gold) # Update the label text 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"]: + add_item_to_row(item, $MainContainer/RowsContainer/PiecesRow) + for item in shop_items["upgrades"]: + add_item_to_row(item, $MainContainer/RowsContainer/UpgradesRow) + -func _on_item_1_pressed() -> void: - pass # Replace with function body. +func add_item_to_row(item_data: Dictionary, row: HBoxContainer): + var shop_item = shop_item_scene.instantiate() + 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"]) -func _on_item_2_pressed() -> void: - pass # Replace with function body. + # Get the BuyButton + var buy_button = shop_item.get_node("MarginContainer/VBoxContainer/BuyButton") + + # Connect the button to a handler, passing the item_data + buy_button.connect("pressed", Callable(self, "_on_item_purchased").bind(item_data)) + + row.add_child(shop_item) + +func _on_item_purchased(item_data: Dictionary): + if player_gold >= item_data["price"]: + player_gold -= item_data["price"] + update_gold_display(player_gold) + emit_signal("gold_spent", item_data["price"]) # Emit the signal + emit_signal("item_purchased", item_data["name"]) # Notify the main game + print("Purchased: ", item_data["name"]) + # TODO: Add a sound effect / Animation for purchasing items + else: + # TODO: Add a sound effect / warning for not enough gold + print("Not enough gold!") + -func _on_item_purchased(item_name: String) -> void: - pass # Replace with function body. +func _on_next_round_button_pressed(): + print("Next Round button pressed!") + visible = false # Hide the shop + emit_signal("next_round_requested") # Notify the main game script diff --git a/scripts/game.gd b/scripts/game.gd index 1e329427be7379bdd122e00b5fdc1eeb36424b84..ae3d7f8717b7f4dac51af5ae65139e812ec7facc 100644 --- a/scripts/game.gd +++ b/scripts/game.gd @@ -46,13 +46,11 @@ var player_turn : bool = true func _ready() -> void: shop = shop_scene.instantiate() add_child(shop) - shop.position = Vector2(200, 200) + shop.position = Vector2(200, 10) shop.visible = false # Start hidden - if shop.has_signal("gold_spent"): # Check if the signal exists - shop.gold_spent.connect(_on_gold_spent) - else: - print("Error: 'gold_spent' signal not found in shop!") + shop.gold_spent.connect(_on_gold_spent) update_gold_display() # Initialize gold display + shop.next_round_requested.connect(_on_next_round_requested) DisplayServer.window_set_min_size(Vector2(1152, 648)) # Set minimum window size @@ -505,6 +503,9 @@ func _on_shop_button_pressed(): print("Attempting to open shop...") shop.visible = !shop.visible shop.update_gold_display(player_gold) # Pass current gold to shop + piece_container.visible = !piece_container.visible + shadow_container.visible = !shadow_container.visible + tile_container.visible = !tile_container.visible print("Shop added to scene tree!") # Check if this prints # Signal handler method @@ -530,8 +531,15 @@ func _on_shop_item_purchased(item_name: String) -> void: func _on_gold_spent(amount: int): player_gold -= amount - update_gold_display() # Update the gold display + gold_display.text = "Gold: %d" % player_gold # Update the display print("Gold spent: %d. Remaining gold: %d" % [amount, player_gold]) func update_gold_display(): gold_display.text = "Gold: %d" % player_gold + +func _on_next_round_requested(): + print("Next round requested!") + shop.visible = false # Hide the shop + piece_container.visible = true # Show the board + shadow_container.visible = true + tile_container.visible = true