feat: Basic xenia shop implementation

This commit is contained in:
Dendy 2026-03-05 23:44:32 +01:00
parent 2b309da90a
commit 01246b92db
10 changed files with 112 additions and 34 deletions

View File

@ -95,7 +95,6 @@ transform = Transform3D(0.9133367, 0, 0, 0, 0.9133367, 0, 0, 0, 0.9133367, -4.90
mesh = SubResource("BoxMesh_381vs")
[node name="B_area_E" type="StaticBody3D" parent="BuildingAreas" unique_id=164651542]
visible = false
[node name="Collision" type="CollisionShape3D" parent="BuildingAreas/B_area_E" unique_id=2080946797]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 47.5, 0, 0)
@ -131,7 +130,6 @@ shape = SubResource("BoxShape3D_a0kup")
[node name="Building" parent="BuildingAreas/B_area_S" unique_id=819634987 instance=ExtResource("2_eat54")]
transform = Transform3D(1.1296118, 0, 0, 0, 1.0989345, 0, 0, 0, 0.8093087, 47.032215, 2.198969, 0)
visible = false
[node name="MeshInstance3D" type="MeshInstance3D" parent="BuildingAreas/B_area_S/Building" unique_id=1325249889]
transform = Transform3D(0.7908016, 0, 0, 0, 0.9999995, 0, 0, 0, 2.8399127, -7.5103607, -2.0044072, 0)
@ -146,7 +144,6 @@ shape = SubResource("BoxShape3D_a0kup")
[node name="Building" parent="BuildingAreas/B_area_N" unique_id=737365486 instance=ExtResource("2_eat54")]
transform = Transform3D(1.1296118, 0, 0, 0, 1.0989345, 0, 0, 0, 0.8093087, 47.032215, 2.198969, 0)
visible = false
[node name="MeshInstance3D" type="MeshInstance3D" parent="BuildingAreas/B_area_N/Building" unique_id=1889416504]
transform = Transform3D(0.7908016, 0, 0, 0, 0.9999995, 0, 0, 0, 2.8399127, -7.5103607, -2.0044072, 0)

View File

@ -33,7 +33,9 @@ var is_active: bool = true
func _ready() -> void:
$Upgrades.update()
$SpecialUpgrades.update()
$Shop.upgrade_node = $Upgrades
$Shop.special_upgrade_node = $SpecialUpgrades
$Shop.populate()
$Shop.visible = false
@ -126,6 +128,7 @@ func _on_retry_button_pressed():
is_active = true
$TimeLimit.start()
$Upgrades.reset()
$SpecialUpgrades.reset()
stamina = max_stamina

View File

@ -1,6 +1,7 @@
[gd_scene format=3 uid="uid://cmb3b7xrlboy3"]
[ext_resource type="Script" uid="uid://bobw4cfg1v6gj" path="res://player.gd" id="1_4flbx"]
[ext_resource type="PackedScene" uid="uid://byv518wlck1t4" path="res://special_upgrades.tscn" id="2_hqtel"]
[ext_resource type="PackedScene" uid="uid://52hoyqjot1cs" path="res://shop.tscn" id="2_i3pqv"]
[ext_resource type="PackedScene" uid="uid://ct7cc7qg3hpu1" path="res://upgrades.tscn" id="2_onrkg"]
@ -31,7 +32,9 @@ collision_layer = 4
collision_mask = 3
script = ExtResource("1_4flbx")
[node name="Upgrades" parent="." unique_id=1238785974 instance=ExtResource("2_onrkg")]
[node name="SpecialUpgrades" parent="." unique_id=1238785974 instance=ExtResource("2_hqtel")]
[node name="Upgrades" parent="." unique_id=1484491196 instance=ExtResource("2_onrkg")]
[node name="Mesh" type="MeshInstance3D" parent="." unique_id=1740724392]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.1, 0)

57
shop.gd
View File

@ -1,14 +1,14 @@
extends Control
var upgrade_node: Node
var special_upgrade_node: Node
var available_money: int = 0
var special_currency: int = 0
signal shop_exit
func _process(delta: float) -> void:
$Money.text = str(available_money)
$Money.text = str(available_money)
$SpecialMoney.text = str(special_currency)
@ -21,15 +21,23 @@ func populate() -> void:
if upgrade.enabled:
$TuxUpgrades.set_item_disabled(index, true)
$XeniaUpgrades.clear()
for upgrade in special_upgrade_node.get_children():
var index = $XeniaUpgrades.add_item(upgrade.upgrade_description + " Cost: " + str(upgrade.cost), upgrade.icon)
$XeniaUpgrades.set_item_metadata(index, upgrade)
if upgrade.enabled:
$XeniaUpgrades.set_item_disabled(index, true)
func _on_tux_mouse_entered() -> void:
$Tux.modulate = Color(0.5, 0.5, 0.6)
$Tux.modulate = Color(0.5, 0.5, 0.6)
func _on_xenia_mouse_entered() -> void:
$Xenia.modulate = Color(0.5, 0.5, 0.6)
func _on_tux_mouse_exited() -> void:
$Tux.modulate = Color(1, 1, 1)
$Tux.modulate = Color(1.0, 1.0, 1.0)
func _on_xenia_mouse_exited() -> void:
$Xenia.modulate = Color(1.0, 1.0, 1.0)
func _on_tux_upgrades_item_clicked(index: int, at_position: Vector2, mouse_button_index: int) -> void:
@ -41,23 +49,30 @@ func _on_tux_upgrades_item_clicked(index: int, at_position: Vector2, mouse_butto
else:
$Error.text = "No tens prou Diners!!!!"
func _on_continue_pressed() -> void:
$Tux.visible = true
$Xenia.visible = true
$TuxUpgrades.visible = false
shop_exit.emit()
func _on_xenia_mouse_entered() -> void:
$Xenia.modulate = Color(0.5, 0.5, 0.6)
func _on_xenia_mouse_exited() -> void:
$Xenia.modulate = Color(1, 1, 1)
func _on_xenia_upgrades_item_clicked(index: int, at_position: Vector2, mouse_button_index: int) -> void:
var upgrade = $XeniaUpgrades.get_item_metadata(index)
if upgrade.cost <= special_currency:
upgrade.enabled = true;
special_currency -= upgrade.cost
populate()
else:
$Error.text = "No tens prou 🥘!!!!"
func _on_tux_pressed() -> void:
$Tux.visible = false
$Tux.visible = false
$Xenia.visible = false
$TuxUpgrades.visible = true
func _on_xenia_pressed():
$Tux.visible = false
$Xenia.visible = false
$XeniaUpgrades.visible = true
func _on_continue_pressed() -> void:
$Tux.visible = true
$Xenia.visible = true
$TuxUpgrades.visible = false
$XeniaUpgrades.visible = false
shop_exit.emit()

View File

@ -114,6 +114,22 @@ grow_horizontal = 2
grow_vertical = 2
fixed_icon_size = Vector2i(100, 100)
[node name="XeniaUpgrades" type="ItemList" parent="." unique_id=1728782891]
visible = false
layout_mode = 1
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -415.0
offset_top = -295.0
offset_right = -32.0
offset_bottom = 288.0
grow_horizontal = 2
grow_vertical = 2
fixed_icon_size = Vector2i(100, 100)
[node name="Pessetes" type="Label" parent="." unique_id=1267923551]
layout_mode = 0
offset_left = 205.0
@ -195,5 +211,7 @@ text = "Continuar"
[connection signal="pressed" from="Tux" to="." method="_on_tux_pressed"]
[connection signal="mouse_entered" from="Xenia" to="." method="_on_xenia_mouse_entered"]
[connection signal="mouse_exited" from="Xenia" to="." method="_on_xenia_mouse_exited"]
[connection signal="pressed" from="Xenia" to="." method="_on_xenia_pressed"]
[connection signal="item_clicked" from="TuxUpgrades" to="." method="_on_tux_upgrades_item_clicked"]
[connection signal="item_clicked" from="XeniaUpgrades" to="." method="_on_xenia_upgrades_item_clicked"]
[connection signal="pressed" from="Continue" to="." method="_on_continue_pressed"]

21
special_upgrades.gd Normal file
View File

@ -0,0 +1,21 @@
extends Node
var parent: CharacterBody3D
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
assert(get_parent().name == "Player", "Upgrade must have player as parent")
parent = get_parent()
func update() -> void:
var upgrades: Array = get_children()
print("Updating all upgrades...")
for upgrade in upgrades:
upgrade.update()
func reset():
var upgrades: Array = get_children()
print("Updating all upgrades...")
for upgrade in upgrades:
upgrade.enabled = false

1
special_upgrades.gd.uid Normal file
View File

@ -0,0 +1 @@
uid://bxvhar7bgeyau

24
special_upgrades.tscn Normal file
View File

@ -0,0 +1,24 @@
[gd_scene format=3 uid="uid://byv518wlck1t4"]
[ext_resource type="Script" uid="uid://bxvhar7bgeyau" path="res://special_upgrades.gd" id="1_76f4f"]
[sub_resource type="GDScript" id="GDScript_8j6ry"]
script/source = "extends Node
var enabled: bool = false
var cost: int = 3
var upgrade_name: String = \"Tamany bloc\"
var upgrade_description: String = \"Fa mes xicotet cada bloc\"
var icon: Texture2D = preload(\"res://assets/Images/tren.jpg\")
func update() -> void:
if enabled:
print(\"Updating chunk size\")
Global.chunk_size = 120
"
[node name="SpecialUpgrades" type="Node" unique_id=1238785974]
script = ExtResource("1_76f4f")
[node name="ChunkSize" type="Node" parent="." unique_id=1030985851]
script = SubResource("GDScript_8j6ry")

View File

@ -1,6 +1,7 @@
[gd_scene format=3 uid="uid://cf50vwp60vxxf"]
[ext_resource type="Script" uid="uid://e3kpo73hvthu" path="res://station.gd" id="1_lu35c"]
[ext_resource type="Material" uid="uid://pi37nbc20kiw" path="res://assets/Images/pavement/PavingStones074_1K-JPG2.tres" id="2_oblqs"]
[ext_resource type="PackedScene" uid="uid://8227la7x8kn1" path="res://assets/3d/Rails.glb" id="2_xmj61"]
[ext_resource type="Texture2D" uid="uid://dwp08vjv8v6h6" path="res://icon.svg" id="3_sum1q"]
@ -77,6 +78,7 @@ size = Vector3(16.840843, 19.235413, 1)
script = ExtResource("1_lu35c")
[node name="Mesh" type="MeshInstance3D" parent="." unique_id=651037282]
material_override = ExtResource("2_oblqs")
mesh = SubResource("PlaneMesh_kdh3y")
surface_material_override/0 = SubResource("StandardMaterial3D_eoxb4")

View File

@ -2,16 +2,11 @@ extends Node
var parent: CharacterBody3D
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
assert(get_parent().name == "Player", "Upgrade must have player as parent")
parent = get_parent()
## Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta: float) -> void:
#pass
func update() -> void:
var upgrades: Array = get_children()
@ -19,7 +14,6 @@ func update() -> void:
for upgrade in upgrades:
upgrade.update()
func reset():
var upgrades: Array = get_children()
print("Updating all upgrades...")