using Godot; using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; // Remove all the global positions from this file public partial class Inventory : Panel { Options _Options; Reference _Reference; [Export] PackedScene SplitFrame; Vector2I InventorySize = new Vector2I(4, 15); int MaxWeight; List _Inventory; Vector2 _GridSize; ProgressBar _WeightBar; HeldItem _itemBeingHeld; HeldItem __h; HeldItem _lastRightClickedItem { get { return __h; } set { if (_splitFrame != null) { _splitFrame.Free(); _splitFrame = null; } __h = value; } } public Control _splitFrame; public override void _EnterTree() { _Options = GetNode( "/root/Options" ); _Reference = GetNode("/root/Reference"); _Reference.Inventory = this; _Inventory = new List(); MaxWeight = 400; Control GridBackdrop = GetChild(0).GetChild( 0 ); _WeightBar = GetChild( 1 ); // Scale Scrollbar Vector2 FrameSize = GetChild(0).Size; GridBackdrop.CustomMinimumSize = new Vector2( GetChild(0).Size.X - 8 , InventorySize.Y * FrameSize.X / InventorySize.X ); GridBackdrop.Size = GridBackdrop.CustomMinimumSize; _GridSize = new Vector2( GridBackdrop.Size.X / InventorySize.X, GridBackdrop.Size.Y / InventorySize.Y ); _WeightBar.MaxValue = MaxWeight; // Horizontal Grid Bars for (int y=0; y< InventorySize.Y - 1; y++) { HSeparator cur = new HSeparator{ Position = new Vector2(0, _GridSize.Y * (y + 1) - 2), Size = new Vector2(GridBackdrop.Size.X, 4) }; GetChild(0).GetChild(0).AddChild( cur ); } // Vertical Grid Bars for (int x=0; x< InventorySize.X - 1; x++) { VSeparator cur = new VSeparator{ Position = new Vector2(_GridSize.X * (x + 1) - 2, 0), Size = new Vector2(4, GridBackdrop.Size.Y) }; GetChild(0).GetChild(0).AddChild( cur ); } GetWeight(); } public void UpdateMaxWeight(int maxWeight){ MaxWeight = maxWeight; _WeightBar.MaxValue = MaxWeight; GetWeight(); } //------------------------------// // Public Functions // //------------------------------// public int GetWeight() { int _w = 0; foreach(GameItem cur in _Inventory ) { _w += cur.ItemStats.InventoryWeight; } _WeightBar.Value = _w; _WeightBar.GetChild