summaryrefslogtreecommitdiff
path: root/source/ui/elements/game/CraftingWindow.cs
diff options
context:
space:
mode:
authorhazel <hazel@hazelthats.me>2026-01-26 22:04:39 +0100
committerhazel <hazel@hazelthats.me>2026-01-26 22:04:39 +0100
commit567c422f8cd42eba2437f9a8c2522716a1649be7 (patch)
tree93c5b296f3b7c14b626d0aadf5cad37764c41c74 /source/ui/elements/game/CraftingWindow.cs
downloadcelesteia-567c422f8cd42eba2437f9a8c2522716a1649be7.tar.gz
celesteia-567c422f8cd42eba2437f9a8c2522716a1649be7.tar.bz2
celesteia-567c422f8cd42eba2437f9a8c2522716a1649be7.zip
celesteia archive, last updated april 9th 2024
Signed-off-by: hazel <hazel@hazelthats.me>
Diffstat (limited to 'source/ui/elements/game/CraftingWindow.cs')
-rw-r--r--source/ui/elements/game/CraftingWindow.cs62
1 files changed, 62 insertions, 0 deletions
diff --git a/source/ui/elements/game/CraftingWindow.cs b/source/ui/elements/game/CraftingWindow.cs
new file mode 100644
index 0000000..e5bcc71
--- /dev/null
+++ b/source/ui/elements/game/CraftingWindow.cs
@@ -0,0 +1,62 @@
+using System;
+using System.Collections.Generic;
+using Celesteia.Game.Components.Items;
+using Celesteia.GUIs.Game;
+using Celesteia.Resources;
+using Celesteia.Resources.Management;
+using Celesteia.Resources.Types;
+using Microsoft.Xna.Framework;
+using Microsoft.Xna.Framework.Graphics;
+
+namespace Celesteia.UI.Elements.Game {
+ public class CraftingWindow : Container {
+ private Inventory _referenceInventory;
+ private Image background;
+ private GameGUI _gameGui;
+
+ public CraftingWindow(GameGUI gameGui, Rect rect, Texture2D backgroundImage, Inventory inventory, CraftingRecipeSlot template) : base(rect) {
+ _gameGui = gameGui;
+
+ _referenceInventory = inventory;
+
+ background = new Image(Rect.RelativeFull(rect)).SetTexture(backgroundImage).MakePatches(4).SetColor(Color.White);
+ AddChild(background);
+
+ AddRecipes(27, template);
+ }
+
+ int columns = 9;
+ private void AddRecipes(int amountPerPage, CraftingRecipeSlot template) {
+ int rows = (int)Math.Ceiling(amountPerPage / (double)columns);
+
+ float o = CraftingRecipeSlot.SLOT_SPACING;
+ int index = 0;
+ int i = 0;
+ for (int row = 0; row < rows; row++)
+ for (int column = 0; column < columns; column++) {
+ if (i >= ResourceManager.Recipes.Recipes.Count) break;
+
+ int slotNumber = i;
+ Recipe recipe = ResourceManager.Recipes.Recipes[index];
+ CraftingRecipeSlot slot = template.Clone()
+ .SetNewRect(template.GetRect()
+ .SetX(AbsoluteUnit.WithValue(column * CraftingRecipeSlot.SLOT_SIZE + (column * CraftingRecipeSlot.SLOT_SPACING) + o))
+ .SetY(AbsoluteUnit.WithValue(row * CraftingRecipeSlot.SLOT_SIZE + (row * CraftingRecipeSlot.SLOT_SPACING) + o))
+ )
+ .SetRecipe(recipe)
+ .SetOnMouseUp((button, point) => {
+ if (button == MonoGame.Extended.Input.MouseButton.Left) {
+ recipe.Craft(_referenceInventory);
+ }
+ });
+ slot.referenceInv = _referenceInventory;
+ slot.SetPivot(new Vector2(0f, 0f));
+
+ index++;
+ i++;
+
+ AddChild(slot);
+ }
+ }
+ }
+} \ No newline at end of file