From 73ede51027d778796596106a6602dcb7272ed7ec Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sun, 1 Oct 2023 14:39:16 +0200 Subject: [PATCH] Begin creation of ShopUI --- game/game.tscn | 37 ++++++++ interface/game_container.tscn | 15 ++++ interface/game_ui.tscn | 45 ++++++++++ interface/interface_theme.tres | 6 ++ interface/purchasable_item.gd | 78 ++++++++++++++++ interface/purchasable_item.tscn | 115 ++++++++++++++++++++++++ interface/purchasable_item_padding.tscn | 6 ++ interface/shop_ui.gd | 2 + interface/shop_ui.tscn | 63 +++++++++++++ root.tscn | 96 +++----------------- 10 files changed, 377 insertions(+), 86 deletions(-) create mode 100644 game/game.tscn create mode 100644 interface/game_container.tscn create mode 100644 interface/game_ui.tscn create mode 100644 interface/interface_theme.tres create mode 100644 interface/purchasable_item.gd create mode 100644 interface/purchasable_item.tscn create mode 100644 interface/purchasable_item_padding.tscn create mode 100644 interface/shop_ui.gd create mode 100644 interface/shop_ui.tscn diff --git a/game/game.tscn b/game/game.tscn new file mode 100644 index 0000000..7d567d1 --- /dev/null +++ b/game/game.tscn @@ -0,0 +1,37 @@ +[gd_scene load_steps=5 format=3 uid="uid://c3rxmcwa5nqng"] + +[ext_resource type="PackedScene" uid="uid://bllsprv8orpn4" path="res://bottle/bottle.tscn" id="1_y7o2l"] +[ext_resource type="PackedScene" uid="uid://d05b8jy3xmpcb" path="res://bottle/gravity_from_gyro.tscn" id="2_h2pfr"] +[ext_resource type="PackedScene" uid="uid://c67lfbk4gf1ga" path="res://spawner/spawner.tscn" id="3_qwsty"] +[ext_resource type="PackedScene" uid="uid://c3kitncwpi42j" path="res://entity/coin_copper.tscn" id="4_e5nwi"] + +[node name="Game" type="Node2D"] +texture_filter = 1 + +[node name="Bottle" parent="." instance=ExtResource("1_y7o2l")] + +[node name="GravityFromGyro" parent="Bottle" instance=ExtResource("2_h2pfr")] + +[node name="TimeSpawner" parent="." instance=ExtResource("3_qwsty")] +position = Vector2(0, -480) +scene = ExtResource("4_e5nwi") +buffer_cap = 1 +spawn_position_range_x = 32.0 +spawn_rotation_range = 15.0 +overlapping_bodies_collision_mask = 4 +overlapping_body_count_limit = 4 + +[node name="Timer" type="Timer" parent="TimeSpawner"] +wait_time = 0.03 +autostart = true + +[node name="ButtonSpawner" parent="." instance=ExtResource("3_qwsty")] +position = Vector2(0, -480) +scene = ExtResource("4_e5nwi") +buffer_cap = 50 +spawn_position_range_x = 32.0 +spawn_rotation_range = 15.0 +overlapping_bodies_collision_mask = 4 +overlapping_body_count_limit = 4 + +[connection signal="timeout" from="TimeSpawner/Timer" to="TimeSpawner" method="spawn"] diff --git a/interface/game_container.tscn b/interface/game_container.tscn new file mode 100644 index 0000000..ecbeb0b --- /dev/null +++ b/interface/game_container.tscn @@ -0,0 +1,15 @@ +[gd_scene load_steps=2 format=3 uid="uid://mfa1v4fsnupp"] + +[ext_resource type="PackedScene" uid="uid://c3rxmcwa5nqng" path="res://game/game.tscn" id="1_dbqdv"] + +[node name="GameContainer" type="Control"] +layout_mode = 3 +anchors_preset = 7 +anchor_left = 0.5 +anchor_top = 1.0 +anchor_right = 0.5 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 0 + +[node name="Game" parent="." instance=ExtResource("1_dbqdv")] diff --git a/interface/game_ui.tscn b/interface/game_ui.tscn new file mode 100644 index 0000000..468f291 --- /dev/null +++ b/interface/game_ui.tscn @@ -0,0 +1,45 @@ +[gd_scene load_steps=2 format=3 uid="uid://bo5unrhqpoyim"] + +[ext_resource type="Theme" uid="uid://ba5utvfhnxa5i" path="res://interface/interface_theme.tres" id="1_ppf8y"] + +[node name="Rows" type="VBoxContainer"] +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +theme = ExtResource("1_ppf8y") + +[node name="UpperButtons" type="HBoxContainer" parent="."] +custom_minimum_size = Vector2(0, 54) +layout_mode = 2 +size_flags_vertical = 8 +alignment = 1 + +[node name="MoneyButton" type="Button" parent="UpperButtons"] +custom_minimum_size = Vector2(72, 0) +layout_mode = 2 +size_flags_horizontal = 0 +text = "$0" +alignment = 0 + +[node name="UpperButtonsSpacerLeft" type="PanelContainer" parent="UpperButtons"] +layout_mode = 2 +size_flags_horizontal = 3 + +[node name="SpawnButton" type="Button" parent="UpperButtons"] +custom_minimum_size = Vector2(72, 0) +layout_mode = 2 +size_flags_horizontal = 4 +text = "Drop" + +[node name="UpperButtonsSpacerRight" type="PanelContainer" parent="UpperButtons"] +layout_mode = 2 +size_flags_horizontal = 3 + +[node name="ShopButton" type="Button" parent="UpperButtons"] +custom_minimum_size = Vector2(72, 0) +layout_mode = 2 +size_flags_horizontal = 8 +text = "Shop" +alignment = 2 diff --git a/interface/interface_theme.tres b/interface/interface_theme.tres new file mode 100644 index 0000000..7381328 --- /dev/null +++ b/interface/interface_theme.tres @@ -0,0 +1,6 @@ +[gd_resource type="Theme" load_steps=2 format=3 uid="uid://ba5utvfhnxa5i"] + +[ext_resource type="FontFile" uid="uid://cs8tiwyb76gig" path="res://font/press-start/prstart.ttf" id="1_mtdor"] + +[resource] +default_font = ExtResource("1_mtdor") diff --git a/interface/purchasable_item.gd b/interface/purchasable_item.gd new file mode 100644 index 0000000..a0fe873 --- /dev/null +++ b/interface/purchasable_item.gd @@ -0,0 +1,78 @@ +extends Panel +class_name PurchasableItem + +## Name of the item that can be purchased. +@export var item_name: String: + get: + return item_name + set(value): + item_name = value + $Contents/Header/NameLabel.text = value + +## Description of the item that can be purchased. +@export var item_description: String: + get: + return item_description + set(value): + item_description = value + $Contents/Header/DescriptionLabel.text = value + +## Text to be displayed on the cost label of the item. +@export var item_cost_text: String: + get: + return item_cost_text + set(value): + item_cost_text = value + $Contents/Action/CostLabel.text = value + +## Collectible type of the item required to buy the item. +@export var item_cost_type: StringName + +## Amount of items of the given type to collect to buy the item. +@export var item_cost_goal: int + +## Whether the player can click or not the Buy button. +## +## Used to prevent two items from getting bought at the same time. +@export var can_buy: bool: + get: + return can_buy + set(value): + can_buy = value + $Contents/Action/BuyButton.disabled = not can_buy + +## Whether the player is currently buying this item. +## +## Used to cancel the purchase. +var is_buying: bool: + get: + return is_buying + set(value): + is_buying = value + $Contents/Action/BuyButton.text = "Cancel" if value else "Buy" + + +## Emitted when a purchase has started. +signal purchase_begin + +## Emitted when a purchase is cancelled. +signal purchase_cancel + +## Emitted when a purchase is completed. +## +## Emitted by complete_purchase(). +signal purchase_success + + +func _on_buy_button_pressed(): + if is_buying: + is_buying = false + purchase_cancel.emit() + else: + is_buying = true + purchase_begin.emit() + + +func complete_purchase(): + is_buying = false + purchase_success.emit() \ No newline at end of file diff --git a/interface/purchasable_item.tscn b/interface/purchasable_item.tscn new file mode 100644 index 0000000..af7ba38 --- /dev/null +++ b/interface/purchasable_item.tscn @@ -0,0 +1,115 @@ +[gd_scene load_steps=3 format=3 uid="uid://dul1fpyh733t7"] + +[ext_resource type="Texture2D" uid="uid://cxsl5yvdhswc7" path="res://icon.png" id="1_drwcj"] +[ext_resource type="Script" path="res://interface/purchasable_item.gd" id="1_h8jix"] + +[node name="PurchasableItem" type="Panel"] +custom_minimum_size = Vector2(0, 182) +anchors_preset = 10 +anchor_right = 1.0 +grow_horizontal = 2 +size_flags_horizontal = 3 +script = ExtResource("1_h8jix") + +[node name="Contents" type="VBoxContainer" parent="."] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 + +[node name="HeaderPaddingTop" type="Control" parent="Contents"] +custom_minimum_size = Vector2(0, 4) +layout_mode = 2 + +[node name="Header" type="HBoxContainer" parent="Contents"] +layout_mode = 2 +size_flags_vertical = 8 + +[node name="IconPaddingLeft" type="Control" parent="Contents/Header"] +custom_minimum_size = Vector2(8, 0) +layout_mode = 2 + +[node name="IconRect" type="TextureRect" parent="Contents/Header"] +custom_minimum_size = Vector2(54, 54) +layout_mode = 2 +texture = ExtResource("1_drwcj") +expand_mode = 2 + +[node name="IconNameSeparator" type="Control" parent="Contents/Header"] +custom_minimum_size = Vector2(8, 0) +layout_mode = 2 + +[node name="NameLabel" type="Label" parent="Contents/Header"] +layout_mode = 2 +size_flags_horizontal = 3 +theme_override_font_sizes/font_size = 20 +text = "Garasaut" +uppercase = true + +[node name="NamePaddingRight" type="Control" parent="Contents/Header"] +custom_minimum_size = Vector2(8, 0) +layout_mode = 2 + +[node name="HeaderDescriptionPadding" type="Control" parent="Contents"] +custom_minimum_size = Vector2(0, 4) +layout_mode = 2 +size_flags_vertical = 3 + +[node name="Description" type="HBoxContainer" parent="Contents"] +layout_mode = 2 +size_flags_vertical = 4 + +[node name="DescriptionPaddingLeft" type="Control" parent="Contents/Description"] +custom_minimum_size = Vector2(8, 0) +layout_mode = 2 + +[node name="DescriptionLabel" type="Label" parent="Contents/Description"] +layout_mode = 2 +size_flags_horizontal = 3 +theme_override_font_sizes/font_size = 12 +text = "Garasa tutte le auto della zona per ottenere upgrade" +autowrap_mode = 2 + +[node name="DescriptionPaddingRight" type="Control" parent="Contents/Description"] +custom_minimum_size = Vector2(8, 0) +layout_mode = 2 + +[node name="DescriptionActionPadding" type="Control" parent="Contents"] +custom_minimum_size = Vector2(0, 4) +layout_mode = 2 +size_flags_vertical = 3 + +[node name="Action" type="HBoxContainer" parent="Contents"] +layout_mode = 2 +size_flags_vertical = 0 + +[node name="BuyButtonPaddingLeft" type="Control" parent="Contents/Action"] +custom_minimum_size = Vector2(8, 0) +layout_mode = 2 + +[node name="BuyButton" type="Button" parent="Contents/Action"] +layout_mode = 2 +text = "Buy" + +[node name="BuyCostPadding" type="Control" parent="Contents/Action"] +custom_minimum_size = Vector2(8, 0) +layout_mode = 2 + +[node name="CostLabel" type="Label" parent="Contents/Action"] +layout_mode = 2 +size_flags_horizontal = 3 +theme_override_font_sizes/font_size = 8 +text = "3 copper coins" +vertical_alignment = 1 + +[node name="CostLabelPaddingRight" type="Control" parent="Contents/Action"] +custom_minimum_size = Vector2(8, 0) +layout_mode = 2 + +[node name="ActionPaddingBottom" type="Control" parent="Contents"] +custom_minimum_size = Vector2(0, 4) +layout_mode = 2 + +[connection signal="pressed" from="Contents/Action/BuyButton" to="." method="_on_buy_button_pressed"] diff --git a/interface/purchasable_item_padding.tscn b/interface/purchasable_item_padding.tscn new file mode 100644 index 0000000..a249774 --- /dev/null +++ b/interface/purchasable_item_padding.tscn @@ -0,0 +1,6 @@ +[gd_scene format=3 uid="uid://wodgj6rp2ewm"] + +[node name="PurchasableItemPadding" type="Control"] +custom_minimum_size = Vector2(0, 8) +layout_mode = 3 +anchors_preset = 0 diff --git a/interface/shop_ui.gd b/interface/shop_ui.gd new file mode 100644 index 0000000..1a5bf66 --- /dev/null +++ b/interface/shop_ui.gd @@ -0,0 +1,2 @@ +extends Panel +class_name ShopUI diff --git a/interface/shop_ui.tscn b/interface/shop_ui.tscn new file mode 100644 index 0000000..23f99ab --- /dev/null +++ b/interface/shop_ui.tscn @@ -0,0 +1,63 @@ +[gd_scene load_steps=4 format=3 uid="uid://cklkdygv61bny"] + +[ext_resource type="Theme" uid="uid://ba5utvfhnxa5i" path="res://interface/interface_theme.tres" id="1_qdf0y"] +[ext_resource type="PackedScene" uid="uid://dul1fpyh733t7" path="res://interface/purchasable_item.tscn" id="2_2dtc0"] +[ext_resource type="PackedScene" uid="uid://wodgj6rp2ewm" path="res://interface/purchasable_item_padding.tscn" id="3_4feaj"] + +[node name="ShopUI" type="Panel"] +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 +theme = ExtResource("1_qdf0y") + +[node name="Rows" type="VBoxContainer" parent="."] +layout_mode = 1 +anchors_preset = 15 +anchor_right = 1.0 +anchor_bottom = 1.0 +grow_horizontal = 2 +grow_vertical = 2 + +[node name="UpperButtons" type="HBoxContainer" parent="Rows"] +custom_minimum_size = Vector2(0, 54) +layout_mode = 2 + +[node name="MoneyButton" type="Button" parent="Rows/UpperButtons"] +custom_minimum_size = Vector2(54, 0) +layout_mode = 2 +size_flags_horizontal = 0 +text = "$0" +alignment = 0 + +[node name="UpperButtonsSpacer" type="PanelContainer" parent="Rows/UpperButtons"] +layout_mode = 2 +size_flags_horizontal = 3 + +[node name="BackButton" type="Button" parent="Rows/UpperButtons"] +custom_minimum_size = Vector2(54, 0) +layout_mode = 2 +size_flags_horizontal = 8 +text = "Back" +alignment = 2 + +[node name="Scrollable" type="ScrollContainer" parent="Rows"] +layout_mode = 2 +size_flags_vertical = 3 +horizontal_scroll_mode = 0 +vertical_scroll_mode = 2 + +[node name="ScrollableItems" type="VBoxContainer" parent="Rows/Scrollable"] +layout_mode = 2 +size_flags_horizontal = 3 +size_flags_vertical = 3 + +[node name="PurchasableItem" parent="Rows/Scrollable/ScrollableItems" instance=ExtResource("2_2dtc0")] +layout_mode = 2 + +[node name="PurchasableItemPadding" parent="Rows/Scrollable/ScrollableItems" instance=ExtResource("3_4feaj")] +layout_mode = 2 + +[node name="PurchasableItem2" parent="Rows/Scrollable/ScrollableItems" instance=ExtResource("2_2dtc0")] +layout_mode = 2 diff --git a/root.tscn b/root.tscn index 0884c6b..0b7c961 100644 --- a/root.tscn +++ b/root.tscn @@ -1,13 +1,14 @@ [gd_scene load_steps=5 format=3 uid="uid://cbccs6kwwf265"] -[ext_resource type="PackedScene" uid="uid://bllsprv8orpn4" path="res://bottle/bottle.tscn" id="1_4fmd3"] -[ext_resource type="PackedScene" uid="uid://c3kitncwpi42j" path="res://entity/coin_copper.tscn" id="2_dv01l"] -[ext_resource type="PackedScene" uid="uid://d05b8jy3xmpcb" path="res://bottle/gravity_from_gyro.tscn" id="2_m7p4p"] -[ext_resource type="PackedScene" uid="uid://c67lfbk4gf1ga" path="res://spawner/spawner.tscn" id="3_pubxn"] +[ext_resource type="Theme" uid="uid://ba5utvfhnxa5i" path="res://interface/interface_theme.tres" id="1_h26ax"] +[ext_resource type="PackedScene" uid="uid://mfa1v4fsnupp" path="res://interface/game_container.tscn" id="1_xjgvu"] +[ext_resource type="PackedScene" uid="uid://cklkdygv61bny" path="res://interface/shop_ui.tscn" id="3_lvefk"] +[ext_resource type="PackedScene" uid="uid://bo5unrhqpoyim" path="res://interface/game_ui.tscn" id="5_2cc15"] [node name="Root" type="Node"] [node name="UI" type="Control" parent="."] +texture_filter = 1 layout_mode = 3 anchors_preset = 15 anchor_right = 1.0 @@ -15,90 +16,13 @@ anchor_bottom = 1.0 grow_horizontal = 2 grow_vertical = 2 size_flags_vertical = 8 +theme = ExtResource("1_h26ax") -[node name="GameContainer" type="Control" parent="UI"] +[node name="GameContainer" parent="UI" instance=ExtResource("1_xjgvu")] layout_mode = 1 -anchors_preset = 7 -anchor_left = 0.5 -anchor_top = 1.0 -anchor_right = 0.5 -anchor_bottom = 1.0 -grow_horizontal = 2 -grow_vertical = 0 -[node name="Game" type="Node2D" parent="UI/GameContainer"] -texture_filter = 1 - -[node name="Bottle" parent="UI/GameContainer/Game" instance=ExtResource("1_4fmd3")] - -[node name="GravityFromGyro" parent="UI/GameContainer/Game/Bottle" instance=ExtResource("2_m7p4p")] - -[node name="TimeSpawner" parent="UI/GameContainer/Game" instance=ExtResource("3_pubxn")] -position = Vector2(0, -480) -scene = ExtResource("2_dv01l") -buffer_cap = 1 -spawn_position_range_x = 32.0 -spawn_rotation_range = 15.0 -overlapping_bodies_collision_mask = 4 -overlapping_body_count_limit = 4 - -[node name="Timer" type="Timer" parent="UI/GameContainer/Game/TimeSpawner"] -wait_time = 0.03 -autostart = true - -[node name="ButtonSpawner" parent="UI/GameContainer/Game" instance=ExtResource("3_pubxn")] -position = Vector2(0, -480) -scene = ExtResource("2_dv01l") -buffer_cap = 50 -spawn_position_range_x = 32.0 -spawn_rotation_range = 15.0 -overlapping_bodies_collision_mask = 4 -overlapping_body_count_limit = 4 - -[node name="Rows" type="VBoxContainer" parent="UI"] +[node name="GameUI" parent="UI" instance=ExtResource("5_2cc15")] layout_mode = 1 -anchors_preset = 15 -anchor_right = 1.0 -anchor_bottom = 1.0 -grow_horizontal = 2 -grow_vertical = 2 -[node name="NotchSpacer" type="PanelContainer" parent="UI/Rows"] -layout_mode = 2 -size_flags_horizontal = 3 - -[node name="UpperButtons" type="HBoxContainer" parent="UI/Rows"] -custom_minimum_size = Vector2(0, 54) -layout_mode = 2 -size_flags_vertical = 8 - -[node name="MoneyButton" type="Button" parent="UI/Rows/UpperButtons"] -custom_minimum_size = Vector2(54, 0) -layout_mode = 2 -size_flags_horizontal = 8 -text = "$0" -alignment = 0 - -[node name="UpperButtonsSpacerLeft" type="PanelContainer" parent="UI/Rows/UpperButtons"] -layout_mode = 2 -size_flags_horizontal = 3 - -[node name="SpawnButton" type="Button" parent="UI/Rows/UpperButtons"] -custom_minimum_size = Vector2(54, 0) -layout_mode = 2 -size_flags_horizontal = 8 -text = "Drop" - -[node name="UpperButtonsSpacerRight" type="PanelContainer" parent="UI/Rows/UpperButtons"] -layout_mode = 2 -size_flags_horizontal = 3 - -[node name="ShopButton" type="Button" parent="UI/Rows/UpperButtons"] -custom_minimum_size = Vector2(54, 0) -layout_mode = 2 -size_flags_horizontal = 8 -text = "Shop" -alignment = 2 - -[connection signal="timeout" from="UI/GameContainer/Game/TimeSpawner/Timer" to="UI/GameContainer/Game/TimeSpawner" method="spawn"] -[connection signal="pressed" from="UI/Rows/UpperButtons/SpawnButton" to="UI/GameContainer/Game/ButtonSpawner" method="spawn"] +[node name="ShopUI" parent="UI" instance=ExtResource("3_lvefk")] +layout_mode = 1