mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 10:15:45 +00:00
Vending Machines
This commit is contained in:
parent
e25da0fe16
commit
d020b067af
16 changed files with 249 additions and 34 deletions
|
|
@ -13,10 +13,11 @@ metadata/_custom_type_script = "uid://bxgjw8wis5l0t"
|
|||
[resource]
|
||||
script = ExtResource("1_hyh2l")
|
||||
ItemName = &"Health"
|
||||
ShortName = null
|
||||
ShortName = &"Health"
|
||||
ItemDescription = &"Gives back 25% of Max Health on use"
|
||||
ItemKey = &"HEALTH"
|
||||
Item = 4
|
||||
Price = 3
|
||||
ItemEffect = SubResource("Resource_vsvqq")
|
||||
Amount = 1
|
||||
Max = 10
|
||||
|
|
|
|||
|
|
@ -6,10 +6,11 @@
|
|||
[resource]
|
||||
script = ExtResource("1_vw5ht")
|
||||
ItemName = &"Power"
|
||||
ShortName = null
|
||||
ShortName = &"Power"
|
||||
ItemDescription = &"Necessary for upgrades"
|
||||
ItemKey = &"POWER"
|
||||
Item = 10
|
||||
Price = 1
|
||||
Amount = 1
|
||||
Max = 100
|
||||
PickupIfMaxed = false
|
||||
|
|
|
|||
|
|
@ -13,10 +13,11 @@ metadata/_custom_type_script = "uid://bxgjw8wis5l0t"
|
|||
[resource]
|
||||
script = ExtResource("2_xsuq5")
|
||||
ItemName = &"Shield Charge"
|
||||
ShortName = null
|
||||
ShortName = &"Shield"
|
||||
ItemDescription = &"Recharges the shield by 25%"
|
||||
ItemKey = &"SHIELD"
|
||||
Item = 8
|
||||
Price = 3
|
||||
ItemEffect = SubResource("Resource_qh6j2")
|
||||
Amount = 1
|
||||
Max = 10
|
||||
|
|
|
|||
102
Scenes/HUD/VendingMachineUi.tscn
Normal file
102
Scenes/HUD/VendingMachineUi.tscn
Normal file
|
|
@ -0,0 +1,102 @@
|
|||
[gd_scene load_steps=8 format=3 uid="uid://ca0g1jnl6n0pl"]
|
||||
|
||||
[ext_resource type="Theme" uid="uid://dnsadvmunm76k" path="res://Resources/Styles/MainMenuButtons.tres" id="1_2iadx"]
|
||||
[ext_resource type="Script" uid="uid://dwj7p7ydustm5" path="res://Scripts/UI/VendingMachineUi.cs" id="1_dy2e4"]
|
||||
[ext_resource type="StyleBox" uid="uid://ctw2hju32l3rg" path="res://Resources/Styles/PixelStyleBoxRed.tres" id="2_isscq"]
|
||||
[ext_resource type="Texture2D" uid="uid://b2vmpi57d7vwy" path="res://Sprites/Items/Shield_Extend.png" id="3_4n8rt"]
|
||||
[ext_resource type="Texture2D" uid="uid://dlkqy5jgchwy" path="res://Sprites/Items/Heart_Pickup.png" id="4_4n8rt"]
|
||||
[ext_resource type="Texture2D" uid="uid://4x3ouxyxjqjc" path="res://Sprites/Items/Credits_Pickup.png" id="4_dy2e4"]
|
||||
[ext_resource type="Texture2D" uid="uid://bjdsi4x8m42ky" path="res://Sprites/Items/Power_Pickup.png" id="5_dy2e4"]
|
||||
|
||||
[node name="VendingMachineUi" type="CanvasLayer" node_paths=PackedStringArray("MoneyLabel", "ItemsContainer")]
|
||||
layer = 2
|
||||
script = ExtResource("1_dy2e4")
|
||||
MoneyLabel = NodePath("PanelContainer/VBoxContainer/HBoxContainer3/Label")
|
||||
ItemsContainer = NodePath("PanelContainer/VBoxContainer/HBoxContainer2")
|
||||
|
||||
[node name="PanelContainer" type="PanelContainer" parent="."]
|
||||
anchors_preset = 8
|
||||
anchor_left = 0.5
|
||||
anchor_top = 0.5
|
||||
anchor_right = 0.5
|
||||
anchor_bottom = 0.5
|
||||
offset_left = -143.5
|
||||
offset_top = -71.5
|
||||
offset_right = 143.5
|
||||
offset_bottom = 71.5
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
size_flags_horizontal = 4
|
||||
theme = ExtResource("1_2iadx")
|
||||
theme_override_styles/panel = ExtResource("2_isscq")
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="PanelContainer"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="PanelContainer/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="Label" type="Label" parent="PanelContainer/VBoxContainer/HBoxContainer"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 10
|
||||
text = "Buy"
|
||||
|
||||
[node name="Button" type="Button" parent="PanelContainer/VBoxContainer/HBoxContainer"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 10
|
||||
text = "X"
|
||||
|
||||
[node name="HBoxContainer2" type="HBoxContainer" parent="PanelContainer/VBoxContainer"]
|
||||
process_mode = 3
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 3
|
||||
alignment = 1
|
||||
|
||||
[node name="Button" type="Button" parent="PanelContainer/VBoxContainer/HBoxContainer2"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
text = "Shield Extension
|
||||
(20)"
|
||||
icon = ExtResource("3_4n8rt")
|
||||
autowrap_mode = 3
|
||||
icon_alignment = 1
|
||||
vertical_icon_alignment = 0
|
||||
expand_icon = true
|
||||
|
||||
[node name="Button2" type="Button" parent="PanelContainer/VBoxContainer/HBoxContainer2"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
text = "Health
|
||||
(15)"
|
||||
icon = ExtResource("4_4n8rt")
|
||||
autowrap_mode = 2
|
||||
icon_alignment = 1
|
||||
vertical_icon_alignment = 0
|
||||
expand_icon = true
|
||||
|
||||
[node name="Button3" type="Button" parent="PanelContainer/VBoxContainer/HBoxContainer2"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
text = "Power
|
||||
(10)"
|
||||
icon = ExtResource("5_dy2e4")
|
||||
autowrap_mode = 2
|
||||
icon_alignment = 1
|
||||
vertical_icon_alignment = 0
|
||||
expand_icon = true
|
||||
|
||||
[node name="HBoxContainer3" type="HBoxContainer" parent="PanelContainer/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 4
|
||||
size_flags_vertical = 10
|
||||
alignment = 2
|
||||
|
||||
[node name="TextureRect" type="TextureRect" parent="PanelContainer/VBoxContainer/HBoxContainer3"]
|
||||
layout_mode = 2
|
||||
texture = ExtResource("4_dy2e4")
|
||||
|
||||
[node name="Label" type="Label" parent="PanelContainer/VBoxContainer/HBoxContainer3"]
|
||||
layout_mode = 2
|
||||
text = "123456"
|
||||
|
||||
[connection signal="pressed" from="PanelContainer/VBoxContainer/HBoxContainer/Button" to="." method="Close"]
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
[gd_scene load_steps=10 format=3 uid="uid://db5dwj6nqo8fn"]
|
||||
[gd_scene load_steps=11 format=3 uid="uid://db5dwj6nqo8fn"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://6n7duf35c52l" path="res://Scripts/Interactables/RogueliteDoorLock.cs" id="1_jm4yx"]
|
||||
[ext_resource type="Script" uid="uid://epnwjptvks3t" path="res://Scripts/Resources/LootItem.cs" id="2_q2yjn"]
|
||||
[ext_resource type="Resource" uid="uid://oa8s6xydriib" path="res://Resources/Items/Generic_Keycard.tres" id="3_q2yjn"]
|
||||
[ext_resource type="Texture2D" uid="uid://c1hcyxn2og2kq" path="res://Sprites/Actors/Key_Reader.png" id="4_bkia3"]
|
||||
[ext_resource type="Texture2D" uid="uid://dsf7jj36mk0xp" path="res://Sprites/Actors/KeyReaderOverlay.png" id="5_smh4i"]
|
||||
|
|
@ -40,7 +41,7 @@ animations = [{
|
|||
collision_layer = 4
|
||||
collision_mask = 2
|
||||
script = ExtResource("1_jm4yx")
|
||||
Requirements = [ExtResource("3_q2yjn")]
|
||||
Requirements = Array[ExtResource("2_q2yjn")]([ExtResource("3_q2yjn")])
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
|
||||
shape = SubResource("CircleShape2D_vvpve")
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
[gd_scene load_steps=7 format=3 uid="uid://d0yes7huiyisw"]
|
||||
[gd_scene load_steps=8 format=3 uid="uid://d0yes7huiyisw"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://dxs3ks2ucaxl4" path="res://Scenes/Items/Red_Keycard.tscn" id="1_8f4hq"]
|
||||
[ext_resource type="Script" uid="uid://epnwjptvks3t" path="res://Scripts/Resources/LootItem.cs" id="2_as2n7"]
|
||||
[ext_resource type="Resource" uid="uid://cj5aa7btaw6q0" path="res://Resources/Items/Blue_Keycard.tres" id="2_woclw"]
|
||||
[ext_resource type="Texture2D" uid="uid://bvybqletsvqgk" path="res://Sprites/Items/BlueKeycard_Small.png" id="3_k20dr"]
|
||||
|
||||
|
|
@ -27,7 +28,7 @@ animations = [{
|
|||
}]
|
||||
|
||||
[node name="BlueKeycard" instance=ExtResource("1_8f4hq")]
|
||||
LootTable = [ExtResource("2_woclw")]
|
||||
LootTable = Array[ExtResource("2_as2n7")]([ExtResource("2_woclw")])
|
||||
|
||||
[node name="AnimatedSprite2D" parent="." index="1"]
|
||||
sprite_frames = SubResource("SpriteFrames_gbw5v")
|
||||
|
|
|
|||
|
|
@ -70,6 +70,5 @@ autoplay = true
|
|||
[node name="Minimap" type="CanvasLayer" parent="." node_paths=PackedStringArray("RoomManager")]
|
||||
script = ExtResource("16_pfafs")
|
||||
RoomManager = NodePath("../Maps")
|
||||
CellSize = 4
|
||||
|
||||
[connection signal="ManagerReady" from="." to="Maps" method="InitSpawning"]
|
||||
|
|
|
|||
|
|
@ -1,13 +1,10 @@
|
|||
[gd_scene load_steps=11 format=4 uid="uid://cv1c7ymi8ab17"]
|
||||
[gd_scene load_steps=8 format=4 uid="uid://cv1c7ymi8ab17"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://b2j00riayxkit" path="res://Scripts/Controllers/RogueliteRoom.cs" id="1_36sk4"]
|
||||
[ext_resource type="Resource" uid="uid://cwtma7mxged8a" path="res://Resources/RogueliteMaps/ShopRoom1.tres" id="2_36sk4"]
|
||||
[ext_resource type="PackedScene" uid="uid://l84on3kv2s52" path="res://Scenes/Door_Horizontal.tscn" id="3_as6dh"]
|
||||
[ext_resource type="PackedScene" uid="uid://bc64lr3vlwchq" path="res://Scenes/Door_Vertical.tscn" id="4_ii5ao"]
|
||||
[ext_resource type="PackedScene" uid="uid://b0k2grrc8xp1l" path="res://Scenes/Props/BigTank.tscn" id="4_r367v"]
|
||||
[ext_resource type="PackedScene" uid="uid://cl7s06sk106uo" path="res://Scenes/Props/VendingMachine.tscn" id="5_g23xn"]
|
||||
[ext_resource type="TileSet" uid="uid://6k28roiljylj" path="res://Tilesets/factory_tileset.tres" id="5_o7s04"]
|
||||
[ext_resource type="Script" uid="uid://krean0uywtms" path="res://Scripts/TilemapAvoidance.cs" id="6_l5c4m"]
|
||||
[ext_resource type="PackedScene" uid="uid://cnhgvn2salyxl" path="res://Scenes/Items/Icicle_Repeater.tscn" id="7_ii5ao"]
|
||||
|
||||
[sub_resource type="NavigationPolygon" id="NavigationPolygon_rlq0q"]
|
||||
vertices = PackedVector2Array(166, 58, 294, 58, 294, 134, 166, 134, 166, 150, 154, 150, 154, 134, 154, 58, 26, 134, 26, 58, 166, 10, 154, 10)
|
||||
|
|
@ -23,9 +20,6 @@ size = Vector2(272, 85)
|
|||
process_mode = 1
|
||||
script = ExtResource("1_36sk4")
|
||||
RoomResource = ExtResource("2_36sk4")
|
||||
DoorPrefab = ExtResource("3_as6dh")
|
||||
VerticalDoorPrefab = ExtResource("4_ii5ao")
|
||||
WallPrefab = ExtResource("4_r367v")
|
||||
|
||||
[node name="Tilemaps" type="Node2D" parent="." groups=["navigation_polygon_source_geometry_group"]]
|
||||
|
||||
|
|
@ -51,8 +45,8 @@ metadata/_edit_lock_ = true
|
|||
[node name="Actors" type="Node2D" parent="Tilemaps"]
|
||||
metadata/_edit_lock_ = true
|
||||
|
||||
[node name="IcicleRepeater" parent="Tilemaps/Actors" instance=ExtResource("7_ii5ao")]
|
||||
position = Vector2(159, 91)
|
||||
[node name="VendingMachine" parent="Tilemaps/Actors" instance=ExtResource("5_g23xn")]
|
||||
position = Vector2(98, 53)
|
||||
|
||||
[node name="EnemySpawners" type="Node2D" parent="."]
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,11 @@
|
|||
[gd_scene load_steps=10 format=3 uid="uid://cl7s06sk106uo"]
|
||||
[gd_scene load_steps=13 format=3 uid="uid://cl7s06sk106uo"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://cpx2fxtumgmud" path="res://Scenes/Barrel.cs" id="1_1necu"]
|
||||
[ext_resource type="PackedScene" uid="uid://dlnw4ear5tsv3" path="res://Scenes/Props/VendingMachine_Broken.tscn" id="2_1necu"]
|
||||
[ext_resource type="Script" uid="uid://bg20enqj6y6c8" path="res://Scripts/Actors/VendingMachine.cs" id="1_hlj8y"]
|
||||
[ext_resource type="PackedScene" uid="uid://ca0g1jnl6n0pl" path="res://Scenes/HUD/VendingMachineUi.tscn" id="2_lo43l"]
|
||||
[ext_resource type="Texture2D" uid="uid://cg75fgm412pt7" path="res://Sprites/Props/VendingMachine.png" id="3_1necu"]
|
||||
[ext_resource type="Resource" uid="uid://clr1gln7nxa1o" path="res://Resources/Items/Power_Pickup.tres" id="3_oeilh"]
|
||||
[ext_resource type="Resource" uid="uid://dodwpect0ldjf" path="res://Resources/Items/Heart_Pickup.tres" id="4_8fr44"]
|
||||
[ext_resource type="Resource" uid="uid://bhbufxodybsw4" path="res://Resources/Items/Shield_Pickup.tres" id="5_0a7ay"]
|
||||
|
||||
[sub_resource type="AtlasTexture" id="AtlasTexture_wa2ji"]
|
||||
atlas = ExtResource("3_1necu")
|
||||
|
|
@ -39,14 +42,12 @@ size = Vector2(14, 24)
|
|||
[sub_resource type="RectangleShape2D" id="RectangleShape2D_vguns"]
|
||||
size = Vector2(13, 20)
|
||||
|
||||
[node name="VendingMachine" type="Area2D" groups=["Destroyable"]]
|
||||
collision_layer = 64
|
||||
collision_mask = 10
|
||||
script = ExtResource("1_1necu")
|
||||
Health = 8.0
|
||||
ExplosionRadius = 0.0
|
||||
ExplosionDamage = 0.0
|
||||
DebrisScene = ExtResource("2_1necu")
|
||||
[node name="VendingMachine" type="Area2D" groups=["Destroyable", "Interactable"]]
|
||||
collision_layer = 4
|
||||
collision_mask = 0
|
||||
script = ExtResource("1_hlj8y")
|
||||
UiScene = ExtResource("2_lo43l")
|
||||
Items = Array[Object]([ExtResource("3_oeilh"), ExtResource("4_8fr44"), ExtResource("5_0a7ay")])
|
||||
metadata/_edit_group_ = true
|
||||
|
||||
[node name="AnimatedSprite2D" type="AnimatedSprite2D" parent="."]
|
||||
|
|
@ -61,11 +62,10 @@ visible = false
|
|||
position = Vector2(0, -8)
|
||||
shape = SubResource("RectangleShape2D_0nhpj")
|
||||
|
||||
[node name="RigidBody2D" type="RigidBody2D" parent="."]
|
||||
[node name="RigidBody2D" type="StaticBody2D" parent="."]
|
||||
position = Vector2(0, -8)
|
||||
collision_layer = 64
|
||||
collision_mask = 10
|
||||
gravity_scale = 0.0
|
||||
|
||||
[node name="CollisionShape2D" type="CollisionShape2D" parent="RigidBody2D"]
|
||||
visible = false
|
||||
|
|
|
|||
|
|
@ -372,6 +372,7 @@ metadata/_edit_lock_ = true
|
|||
[node name="Navigation" type="Node2D" parent="."]
|
||||
|
||||
[node name="NavigationRegion2D" type="NavigationRegion2D" parent="Navigation"]
|
||||
visible = false
|
||||
navigation_polygon = SubResource("NavigationPolygon_j86ly")
|
||||
|
||||
[node name="Parallax2D" type="Parallax2D" parent="."]
|
||||
|
|
@ -623,7 +624,16 @@ position = Vector2(-545, -503)
|
|||
position = Vector2(-527, -504)
|
||||
|
||||
[node name="CreditsPickup" parent="Parallax2D/Factory Tilemaps/Debug Room" instance=ExtResource("30_pniyx")]
|
||||
position = Vector2(-751, -412)
|
||||
position = Vector2(-860, -454)
|
||||
|
||||
[node name="CreditsPickup2" parent="Parallax2D/Factory Tilemaps/Debug Room" instance=ExtResource("30_pniyx")]
|
||||
position = Vector2(-859, -475)
|
||||
|
||||
[node name="CreditsPickup3" parent="Parallax2D/Factory Tilemaps/Debug Room" instance=ExtResource("30_pniyx")]
|
||||
position = Vector2(-872, -464)
|
||||
|
||||
[node name="CreditsPickup4" parent="Parallax2D/Factory Tilemaps/Debug Room" instance=ExtResource("30_pniyx")]
|
||||
position = Vector2(-873.778, -451.047)
|
||||
|
||||
[node name="ShieldPickup" parent="Parallax2D/Factory Tilemaps/Debug Room" instance=ExtResource("31_5ews6")]
|
||||
position = Vector2(-751, -395)
|
||||
|
|
@ -641,7 +651,7 @@ position = Vector2(-735, -412)
|
|||
position = Vector2(-843, -345)
|
||||
|
||||
[node name="Blue Box" parent="Parallax2D/Factory Tilemaps/Debug Room" instance=ExtResource("37_gtga7")]
|
||||
position = Vector2(-832, -396)
|
||||
position = Vector2(-890, -380)
|
||||
|
||||
[node name="SwitchBox" parent="Parallax2D/Factory Tilemaps/Debug Room" node_paths=PackedStringArray("Targets") instance=ExtResource("38_qnbhd")]
|
||||
position = Vector2(-686, -484)
|
||||
|
|
@ -675,6 +685,9 @@ Script = SubResource("Resource_f37sa")
|
|||
[node name="Fridge" parent="Parallax2D/Factory Tilemaps/Debug Room" instance=ExtResource("115_dferh")]
|
||||
position = Vector2(-736, -438)
|
||||
|
||||
[node name="VendingMachine" parent="Parallax2D/Factory Tilemaps/Debug Room" instance=ExtResource("87_gqbl6")]
|
||||
position = Vector2(-840, -423)
|
||||
|
||||
[node name="Part2" type="Node2D" parent="Parallax2D/Factory Tilemaps"]
|
||||
y_sort_enabled = true
|
||||
|
||||
|
|
|
|||
28
Scripts/Actors/VendingMachine.cs
Normal file
28
Scripts/Actors/VendingMachine.cs
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
using System.Linq;
|
||||
using Cirno.Scripts.Resources;
|
||||
using Cirno.Scripts.UI;
|
||||
using Godot;
|
||||
using Godot.Collections;
|
||||
|
||||
namespace Cirno.Scripts.Actors;
|
||||
|
||||
public partial class VendingMachine : Interactable
|
||||
{
|
||||
[Export] public PackedScene UiScene { get; private set; }
|
||||
|
||||
[Export] public Array<LootItem> Items { get; set; }
|
||||
|
||||
|
||||
public override bool Activate(ActivationType activationType = ActivationType.Toggle)
|
||||
{
|
||||
GameManager.Instance.ChangeState(GameState.Shop);
|
||||
|
||||
var ui = UiScene.Instantiate<VendingMachineUi>();
|
||||
|
||||
ui.Items = Items.ToArray();
|
||||
|
||||
this.AddChild(ui);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
1
Scripts/Actors/VendingMachine.cs.uid
Normal file
1
Scripts/Actors/VendingMachine.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://bg20enqj6y6c8
|
||||
|
|
@ -344,6 +344,7 @@ public partial class GameManager : Node2D
|
|||
{
|
||||
case GameState.Paused:
|
||||
case GameState.Dialogue:
|
||||
case GameState.Shop:
|
||||
case GameState.Inventory:
|
||||
GetTree().SetPause(true);
|
||||
//Input.MouseMode = Input.MouseModeEnum.Visible;
|
||||
|
|
@ -404,5 +405,6 @@ public enum GameState
|
|||
Playing,
|
||||
Dialogue,
|
||||
Controlling,
|
||||
Inventory
|
||||
Inventory,
|
||||
Shop
|
||||
}
|
||||
|
|
@ -11,6 +11,7 @@ public partial class LootItem : Resource
|
|||
[Export] public StringName ItemDescription { get; set; }
|
||||
[Export] public StringName ItemKey { get; set; }
|
||||
[Export] public ItemTypes Item;
|
||||
[Export] public int Price { get; set; }
|
||||
[Export] public ItemEffectResource ItemEffect { get; private set; }
|
||||
[Export] public WeaponResource WeaponData { get; set; }
|
||||
[Export] public int Amount;
|
||||
|
|
|
|||
69
Scripts/UI/VendingMachineUi.cs
Normal file
69
Scripts/UI/VendingMachineUi.cs
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
using System.Linq;
|
||||
using Cirno.Scripts.Resources;
|
||||
using Godot;
|
||||
using Godot.Collections;
|
||||
|
||||
namespace Cirno.Scripts.UI;
|
||||
|
||||
public partial class VendingMachineUi : CanvasLayer
|
||||
{
|
||||
[Export] public Label MoneyLabel { get; private set; }
|
||||
[Export] public Container ItemsContainer { get; private set; }
|
||||
|
||||
public LootItem[] Items { get; set; } = new LootItem[3];
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
FillItems();
|
||||
}
|
||||
|
||||
private void FillItems()
|
||||
{
|
||||
var buttons = ItemsContainer.GetChildren().Cast<Button>();
|
||||
|
||||
int i = 0;
|
||||
foreach (var button in buttons)
|
||||
{
|
||||
var item = Items[i];
|
||||
if (item is null)
|
||||
{
|
||||
button.Icon = new PlaceholderTexture2D() { Size = new Vector2(16, 16) };
|
||||
button.Text = "Sold Out";
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
|
||||
button.Icon = item.InventorySprite;
|
||||
button.Text = $"{item.ShortName} ({item.Price})";
|
||||
|
||||
button.Pressed += () => ButtonOnPressed(item);
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
var moneyAmount = InventoryManager.Instance.GetItemCount("CREDITS");
|
||||
|
||||
MoneyLabel.Text = $"{moneyAmount}";
|
||||
}
|
||||
|
||||
private void ButtonOnPressed(LootItem item)
|
||||
{
|
||||
var moneyAmount = InventoryManager.Instance.GetItemCount("CREDITS");
|
||||
|
||||
if (moneyAmount >= item.Price)
|
||||
{
|
||||
// Buy!
|
||||
InventoryManager.Instance.RemoveItem("CREDITS", item.Price);
|
||||
|
||||
InventoryManager.Instance.AddItem(item);
|
||||
|
||||
Close();
|
||||
}
|
||||
}
|
||||
|
||||
public void Close()
|
||||
{
|
||||
GameManager.Instance.ChangeState(GameState.Playing);
|
||||
QueueFree();
|
||||
}
|
||||
}
|
||||
1
Scripts/UI/VendingMachineUi.cs.uid
Normal file
1
Scripts/UI/VendingMachineUi.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://dwj7p7ydustm5
|
||||
Loading…
Add table
Add a link
Reference in a new issue