From c1b6b4e952d2b504fd90f990afb62c3930bb35a4 Mon Sep 17 00:00:00 2001
From: Alan <alanjfogel@gmail.com>
Date: Fri, 7 Feb 2025 18:17:50 -0600
Subject: [PATCH] Changed shop to 3 items of each, added rarity tiers for items
 and upgrades. Shop is now kinda centered sometimes

---
 .godot/editor/create_recent.Node              |  2 +-
 .godot/editor/editor_layout.cfg               |  6 +-
 .godot/editor/filesystem_update4              |  1 +
 ...state-c2a7af834e91ff64325daddf58e45dc0.cfg |  2 +-
 ...state-3070c538c03ee49b7677ff960a3f5195.cfg |  2 +-
 .godot/editor/project_metadata.cfg            |  2 +-
 .godot/editor/script_editor_cache.cfg         | 28 ++++--
 scenes/ShopItem.tscn                          |  8 +-
 scenes/shop_item.gd                           | 26 ++++++
 scripts/Shop.gd                               | 89 +++++++++++++++----
 scripts/game.gd                               | 11 ++-
 11 files changed, 142 insertions(+), 35 deletions(-)
 create mode 100644 scenes/shop_item.gd

diff --git a/.godot/editor/create_recent.Node b/.godot/editor/create_recent.Node
index 701732f..8fddfd9 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 6c9b251..0727ffe 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 89772e7..21c9f93 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 ab9a8f1..3acd289 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 b3165f8..839fabb 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 2066ffe..d05792b 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 d109ea4..050b59c 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 e2a2d7a..39d1a38 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 0000000..e82a169
--- /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 f5e3509..f393806 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 e5c882d..f6585a7 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
-- 
GitLab