diff --git a/Assets/Images/InventorySymbol.png b/Assets/Images/InventorySymbol.png new file mode 100644 index 0000000..a27dd49 Binary files /dev/null and b/Assets/Images/InventorySymbol.png differ diff --git a/Assets/Images/InventorySymbol.png.import b/Assets/Images/InventorySymbol.png.import new file mode 100644 index 0000000..68252a7 --- /dev/null +++ b/Assets/Images/InventorySymbol.png.import @@ -0,0 +1,40 @@ +[remap] + +importer="texture" +type="CompressedTexture2D" +uid="uid://ciehcg34et0q3" +path="res://.godot/imported/InventorySymbol.png-992c7fa6db2b090a5926e973600828c4.ctex" +metadata={ +"vram_texture": false +} + +[deps] + +source_file="res://Assets/Images/InventorySymbol.png" +dest_files=["res://.godot/imported/InventorySymbol.png-992c7fa6db2b090a5926e973600828c4.ctex"] + +[params] + +compress/mode=0 +compress/high_quality=false +compress/lossy_quality=0.7 +compress/uastc_level=0 +compress/rdo_quality_loss=0.0 +compress/hdr_compression=1 +compress/normal_map=0 +compress/channel_pack=0 +mipmaps/generate=false +mipmaps/limit=-1 +roughness/mode=0 +roughness/src_normal="" +process/channel_remap/red=0 +process/channel_remap/green=1 +process/channel_remap/blue=2 +process/channel_remap/alpha=3 +process/fix_alpha_border=true +process/premult_alpha=false +process/normal_map_invert_y=false +process/hdr_as_srgb=false +process/hdr_clamp_exposure=false +process/size_limit=0 +detect_3d/compress_to=1 diff --git a/Assets/Images/Sources/InventorySymbol.aseprite b/Assets/Images/Sources/InventorySymbol.aseprite new file mode 100644 index 0000000..4e3142d Binary files /dev/null and b/Assets/Images/Sources/InventorySymbol.aseprite differ diff --git a/Prefabs/Crafting/ItemDisplay.tscn b/Prefabs/Crafting/ItemDisplay.tscn new file mode 100644 index 0000000..306b713 --- /dev/null +++ b/Prefabs/Crafting/ItemDisplay.tscn @@ -0,0 +1,40 @@ +[gd_scene format=3 uid="uid://4by1t1x6m4yt"] + +[ext_resource type="Script" uid="uid://qdjn5oqn6p5d" path="res://Scripts/Crafting/ItemDisplay.cs" id="1_if7q5"] + +[node name="Item" type="PanelContainer" unique_id=247502695 node_paths=PackedStringArray("texture", "text", "amount")] +anchors_preset = 14 +anchor_top = 0.5 +anchor_right = 1.0 +anchor_bottom = 0.5 +offset_bottom = 31.0 +grow_horizontal = 2 +grow_vertical = 2 +script = ExtResource("1_if7q5") +texture = NodePath("HBoxContainer/TextureRect") +text = NodePath("HBoxContainer/ID") +amount = NodePath("HBoxContainer/Amount") + +[node name="HBoxContainer" type="HBoxContainer" parent="." unique_id=906487472] +layout_mode = 2 +theme_override_constants/separation = 20 +alignment = 1 + +[node name="TextureRect" type="TextureRect" parent="HBoxContainer" unique_id=1795632837] +layout_mode = 2 + +[node name="ID" type="RichTextLabel" parent="HBoxContainer" unique_id=46246913] +layout_mode = 2 +text = "Robot #1" +fit_content = true +autowrap_mode = 0 +horizontal_alignment = 1 +vertical_alignment = 1 + +[node name="Amount" type="RichTextLabel" parent="HBoxContainer" unique_id=1705181895] +layout_mode = 2 +text = "Robot #1" +fit_content = true +autowrap_mode = 0 +horizontal_alignment = 1 +vertical_alignment = 1 diff --git a/Scenes/Game.tscn b/Scenes/Game.tscn index 2fac78d..ff7abb0 100644 --- a/Scenes/Game.tscn +++ b/Scenes/Game.tscn @@ -11,7 +11,9 @@ [ext_resource type="Texture2D" uid="uid://deuxffyhsrinn" path="res://Assets/Images/EnergySymbol.png" id="9_71axn"] [ext_resource type="Texture2D" uid="uid://dje86ro2e37xl" path="res://Assets/Images/Resources/WaterSymbol.png" id="10_71axn"] [ext_resource type="Texture2D" uid="uid://d068gyi3e48cv" path="res://Assets/Images/MapSymbol.png" id="11_3cx6b"] +[ext_resource type="Script" uid="uid://com0u7nqag6pp" path="res://Scripts/Crafting/InventoryDisplay.cs" id="11_acvyw"] [ext_resource type="Texture2D" uid="uid://ban872p4eh4gi" path="res://Assets/Images/RobotSymbol.png" id="11_dahhg"] +[ext_resource type="Texture2D" uid="uid://ciehcg34et0q3" path="res://Assets/Images/InventorySymbol.png" id="11_wxwew"] [ext_resource type="Texture2D" uid="uid://b77mo4fhklnja" path="res://Assets/Images/OptionsSymbol.png" id="12_3so38"] [sub_resource type="CompressedTexture2D" id="CompressedTexture2D_u44n3"] @@ -62,7 +64,7 @@ environment = SubResource("Environment_sb48q") [node name="CanvasLayer" type="CanvasLayer" parent="." unique_id=1558432386] follow_viewport_enabled = true -[node name="UIHandler" type="Control" parent="CanvasLayer" unique_id=1713248285 node_paths=PackedStringArray("codingWindow", "robotList", "mainCam", "map", "FPS", "RAM", "options", "uiContent", "menu")] +[node name="UIHandler" type="Control" parent="CanvasLayer" unique_id=1713248285 node_paths=PackedStringArray("codingWindow", "robotList", "mainCam", "map", "FPS", "RAM", "options", "uiContent", "menu", "inventory")] layout_mode = 3 anchors_preset = 15 anchor_right = 1.0 @@ -83,6 +85,7 @@ RAM = NodePath("MainUI/FooterContainer/HBoxContainer/RAM") options = NodePath("MainUI/Content/Options") uiContent = NodePath("MainUI/Content") menu = NodePath("MainUI/Content/Menu") +inventory = NodePath("MainUI/Content/Inventory") [node name="MainUI" type="VBoxContainer" parent="CanvasLayer/UIHandler" unique_id=1437975209] layout_mode = 1 @@ -353,7 +356,7 @@ text = "Exit" visible = false layout_mode = 1 -[node name="Inventory" type="PanelContainer" parent="CanvasLayer/UIHandler/MainUI/Content" unique_id=407422598] +[node name="Inventory" type="PanelContainer" parent="CanvasLayer/UIHandler/MainUI/Content" unique_id=407422598 node_paths=PackedStringArray("itemList")] visible = false layout_mode = 1 anchors_preset = 11 @@ -363,6 +366,8 @@ anchor_bottom = 1.0 offset_left = -525.0 grow_horizontal = 0 grow_vertical = 2 +script = ExtResource("11_acvyw") +itemList = NodePath("VBoxContainer/ScrollContainer/VBoxContainer") [node name="VBoxContainer" type="VBoxContainer" parent="CanvasLayer/UIHandler/MainUI/Content/Inventory" unique_id=1776118554] layout_mode = 2 @@ -405,6 +410,11 @@ layout_mode = 2 fit_content = true autowrap_mode = 0 +[node name="Inventory" type="TextureButton" parent="CanvasLayer/UIHandler/MainUI/FooterContainer/HBoxContainer" unique_id=1598826377] +layout_mode = 2 +tooltip_text = "Map (M)" +texture_normal = ExtResource("11_wxwew") + [node name="Map" type="TextureButton" parent="CanvasLayer/UIHandler/MainUI/FooterContainer/HBoxContainer" unique_id=1320346210] layout_mode = 2 tooltip_text = "Map (M)" @@ -425,6 +435,7 @@ texture_normal = ExtResource("12_3so38") [connection signal="pressed" from="CanvasLayer/UIHandler/MainUI/Content/Menu/VBoxContainer/Button" to="CanvasLayer/UIHandler" method="HandleMenu"] [connection signal="pressed" from="CanvasLayer/UIHandler/MainUI/Content/Menu/VBoxContainer/Button2" to="CanvasLayer/UIHandler" method="ShowOptions"] [connection signal="pressed" from="CanvasLayer/UIHandler/MainUI/Content/Menu/VBoxContainer/Button3" to="CanvasLayer/UIHandler" method="ExitGame"] +[connection signal="pressed" from="CanvasLayer/UIHandler/MainUI/FooterContainer/HBoxContainer/Inventory" to="CanvasLayer/UIHandler" method="HandleInventoryButton"] [connection signal="pressed" from="CanvasLayer/UIHandler/MainUI/FooterContainer/HBoxContainer/Map" to="CanvasLayer/UIHandler" method="HandleMapButton"] [connection signal="pressed" from="CanvasLayer/UIHandler/MainUI/FooterContainer/HBoxContainer/Robots" to="CanvasLayer/UIHandler" method="HandleRobotListButton"] [connection signal="pressed" from="CanvasLayer/UIHandler/MainUI/FooterContainer/HBoxContainer/Options" to="CanvasLayer/UIHandler" method="HandleMenuButton"] diff --git a/Scripts/Crafting/Inventory.cs b/Scripts/Crafting/Inventory.cs index 99a55c0..3cb7a39 100644 --- a/Scripts/Crafting/Inventory.cs +++ b/Scripts/Crafting/Inventory.cs @@ -3,25 +3,25 @@ using Godot; public class Inventory { - public List inventory = new(); + public List items = new(); public int maxInventorySize = 8; public bool AddItem(Item item, int amount) { - Item inventoryItem = inventory.Find(x => x.data.Id == item.data.Id && x.currentAmount + amount <= x.data.StackSize); + Item inventoryItem = items.Find(x => x.data.Id == item.data.Id && x.currentAmount + amount <= x.data.StackSize); if (inventoryItem != null) { - GD.Print(inventory.IndexOf(inventoryItem) + ": " + inventoryItem.currentAmount); + GD.Print(items.IndexOf(inventoryItem) + ": " + inventoryItem.currentAmount); inventoryItem.currentAmount += amount; return true; } else { - if (inventory.Count < maxInventorySize) + if (items.Count < maxInventorySize) { - inventory.Add(item); - inventory[inventory.Count - 1].currentAmount += amount; + items.Add(item); + items[items.Count - 1].currentAmount += amount; return true; } } @@ -34,7 +34,7 @@ public class Inventory Item item; foreach(Ingredient ingredient in neededIngredients) { - item = inventory.Find(x => x.data.Id == ingredient.item && x.currentAmount >= ingredient.amount * amount); + item = items.Find(x => x.data.Id == ingredient.item && x.currentAmount >= ingredient.amount * amount); if (item == null) { canCraft = false; diff --git a/Scripts/Crafting/InventoryDisplay.cs b/Scripts/Crafting/InventoryDisplay.cs new file mode 100644 index 0000000..b86a41b --- /dev/null +++ b/Scripts/Crafting/InventoryDisplay.cs @@ -0,0 +1,35 @@ +using Godot; + +public partial class InventoryDisplay : PanelContainer +{ + PackedScene itemDisplayPrefab = ResourceLoader.LoadItemDisplay(); + [Export] VBoxContainer itemList; + + public override void _Notification(int id) + { + if (id == NotificationVisibilityChanged) + { + if (Visible) ReloadItems(); + } + } + + public void ReloadItems() + { + foreach (Node node in itemList.GetChildren()) + { + itemList.RemoveChild(node); + node.QueueFree(); + } + ItemDisplay display; + + foreach (Item item in GameData.inventory.items) + { + display = itemDisplayPrefab.Instantiate(); + display.item = item; + display.text.Text = item.GetReadableName(); + display.amount.Text = item.currentAmount.ToString(); + display.texture.Texture = ResourceLoader.LoadPath(item.data.Texture); + itemList.AddChild(display); + } + } +} diff --git a/Scripts/Crafting/InventoryDisplay.cs.uid b/Scripts/Crafting/InventoryDisplay.cs.uid new file mode 100644 index 0000000..3bf3401 --- /dev/null +++ b/Scripts/Crafting/InventoryDisplay.cs.uid @@ -0,0 +1 @@ +uid://com0u7nqag6pp diff --git a/Scripts/Crafting/Item.cs b/Scripts/Crafting/Item.cs index 0854676..ef81147 100644 --- a/Scripts/Crafting/Item.cs +++ b/Scripts/Crafting/Item.cs @@ -8,7 +8,6 @@ public class Item public int currentAmount = 0; public double elapsedCraftTime = 0; public int amountCrafted = 0; - public Texture2D display; public CraftingResult Craft(int amount, double delta) { @@ -31,5 +30,11 @@ public class Item } return CraftingResult.FAILED; } + + public string GetReadableName() + { + string noUnderscore = data.Id.Replace("_", " ").ToLower(); + return char.ToUpper(noUnderscore[0]) + noUnderscore.Substring(1); + } } diff --git a/Scripts/Crafting/ItemDisplay.cs b/Scripts/Crafting/ItemDisplay.cs new file mode 100644 index 0000000..c2003bb --- /dev/null +++ b/Scripts/Crafting/ItemDisplay.cs @@ -0,0 +1,19 @@ +using Godot; +using System; + +public partial class ItemDisplay : PanelContainer +{ + [Export] public TextureRect texture; + [Export] public RichTextLabel text; + [Export] public RichTextLabel amount; + public Item item; + // Called when the node enters the scene tree for the first time. + public override void _Ready() + { + } + + // Called every frame. 'delta' is the elapsed time since the previous frame. + public override void _Process(double delta) + { + } +} diff --git a/Scripts/Crafting/ItemDisplay.cs.uid b/Scripts/Crafting/ItemDisplay.cs.uid new file mode 100644 index 0000000..be1e4e3 --- /dev/null +++ b/Scripts/Crafting/ItemDisplay.cs.uid @@ -0,0 +1 @@ +uid://qdjn5oqn6p5d diff --git a/Scripts/Helpers/ResourceLoader.cs b/Scripts/Helpers/ResourceLoader.cs index bcf6c86..4a881e1 100644 --- a/Scripts/Helpers/ResourceLoader.cs +++ b/Scripts/Helpers/ResourceLoader.cs @@ -21,6 +21,16 @@ public partial class ResourceLoader return GD.Load($"res://Prefabs/Robot/RobotDisplay.tscn"); } + public static PackedScene LoadItemDisplay() + { + return GD.Load($"res://Prefabs/Crafting/ItemDisplay.tscn"); + } + + public static Texture2D LoadPath(string path) + { + return GD.Load(path); + } + public static Dictionary LoadTiles() { Dictionary tileMeshes = new Dictionary(); diff --git a/Scripts/Helpers/UIHandler.cs b/Scripts/Helpers/UIHandler.cs index 6eec69a..b56ddde 100644 --- a/Scripts/Helpers/UIHandler.cs +++ b/Scripts/Helpers/UIHandler.cs @@ -15,6 +15,7 @@ public partial class UIHandler : Control [Export] PanelContainer options; [Export] Control uiContent; [Export] PanelContainer menu; + [Export] PanelContainer inventory; bool receivedRobotJumpSignal = false; public override void _Ready() @@ -37,6 +38,7 @@ public partial class UIHandler : Control if (Input.IsActionJustPressed("map")) HandleMapButton(); if (Input.IsActionJustPressed("menu")) HandleMenuButton(); if (Input.IsActionJustPressed("robot_list")) HandleRobotListButton(); + if (Input.IsActionJustPressed("inventory")) HandleInventoryButton(); DisplayStats(); } @@ -56,6 +58,11 @@ public partial class UIHandler : Control OpenUIElement(robotList); } + public void HandleInventoryButton() + { + OpenUIElement(inventory); + } + public void DisplayStats() { FPS.Text = Engine.GetFramesPerSecond().ToString() + " FPS"; @@ -86,7 +93,6 @@ public partial class UIHandler : Control { foreach (PanelContainer child in uiContent.GetChildren()) { - GD.Print(child == element); if (child == element) continue; child.Visible = false; } diff --git a/project.godot b/project.godot index e99b3de..a9f277d 100644 --- a/project.godot +++ b/project.godot @@ -87,6 +87,11 @@ menu={ "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194305,"key_label":0,"unicode":0,"location":0,"echo":false,"script":null) ] } +inventory={ +"deadzone": 0.2, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":73,"key_label":0,"unicode":105,"location":0,"echo":false,"script":null) +] +} [layer_names]