Refactor all gameItem into one object for easier stats

This commit is contained in:
derek.holloway
2025-12-17 19:13:10 -08:00
parent 063b70a4d5
commit 25e86a6990
201 changed files with 1829 additions and 868 deletions
+107 -146
View File
@@ -15,7 +15,7 @@ public partial class Inventory : Panel {
Vector2I InventorySize = new Vector2I(4, 15);
int MaxWeight;
List<(InventoryItem, Panel)> _Inventory;
List<GameItem> _Inventory;
Vector2 _GridSize;
ProgressBar _WeightBar;
HeldItem _itemBeingHeld;
@@ -39,7 +39,7 @@ public partial class Inventory : Panel {
_Reference = GetNode<Reference>("/root/Reference");
_Reference.Inventory = this;
_Inventory = new List<(InventoryItem, Panel)>();
_Inventory = new List<GameItem>();
MaxWeight = 400;
Control GridBackdrop = GetChild(0).GetChild<Control>( 0 );
@@ -85,28 +85,28 @@ public partial class Inventory : Panel {
public int GetWeight() {
int _w = 0;
foreach( (InventoryItem, Control) cur in _Inventory ) {
_w += cur.Item1.Weight;
foreach(GameItem cur in _Inventory ) {
_w += cur.ItemStats.InventoryWeight;
}
_WeightBar.Value = _w;
_WeightBar.GetChild<Label>( 0 ).Text = _w.ToString() + " / " + MaxWeight.ToString();
return _w;
}
public void UpdateItem( InventoryItem item ) {
foreach( (InventoryItem, Panel) cur in _Inventory ) {
if( item.Guid == cur.Item1.Guid ) {
cur.Item1.Quantity = item.Quantity;
cur.Item2.GetChild<MenuButton>( 0 ).Text = item.Name + "\n" +
item.Quantity + " / " + item.MaxQuantity;
public void UpdateItem( GameItem item ) {
foreach( GameItem cur in _Inventory ) {
if( item.Guid == cur.Guid ) {
cur.InventoryObject.Quantity = item.InventoryObject.Quantity;
cur.InventoryFrame.GetChild<MenuButton>( 0 ).Text = item.ItemStats.ItemName + "\n" +
item.InventoryObject.Quantity + " / " + item.ItemStats.MaxQuantity;
break;
}
}
}
public bool AddInventory( InventoryItem Item ) {
Item.Rotated = false;
if( GetWeight() + Item.Weight > MaxWeight ) {
public bool AddInventory( GameItem Item ) {
Item.InventoryObject.Rotated = false;
if( GetWeight() + Item.ItemStats.InventoryWeight > MaxWeight ) {
_Reference.Alert.PerformAlert( "Max weight!" );
return false;
}
@@ -114,10 +114,10 @@ public partial class Inventory : Panel {
for( int rotation = 0; rotation <= 1; rotation++ ) {
// Try both rotations of the block
Vector2I tempSize = Item.GridSize;
Vector2I tempSize = Item.ItemStats.InventorySize;
if( rotation == 1 ) {
Item.Rotated = true;
tempSize = new Vector2I( Item.GridSize.Y, Item.GridSize.X );
Item.InventoryObject.Rotated = true;
tempSize = new Vector2I( Item.ItemStats.InventorySize.Y, Item.ItemStats.InventorySize.X );
}
// Go through the inventory grid minus overflow from the size of the item were trying to place
@@ -134,11 +134,11 @@ public partial class Inventory : Panel {
MenuButton dropDown = new MenuButton();
if( Item.isQuantityItem ) {
dropDown.Text = Item.Name + "\n" +
Item.Quantity + " / " + Item.MaxQuantity;
if( Item.ItemStats.IsQuantityItem ) {
dropDown.Text = Item.ItemStats.ItemName + "\n" +
Item.InventoryObject.Quantity + " / " + Item.ItemStats.MaxQuantity;
} else {
dropDown.Text = Item.Name;
dropDown.Text = Item.ItemStats.ItemName;
}
dropDown.SetAnchorsPreset( LayoutPreset.FullRect );
@@ -147,20 +147,20 @@ public partial class Inventory : Panel {
dropDown.GuiInput += frameInput;
dropDown.GetPopup().IndexPressed += DropdownPressed;
foreach( string cur in Enum.GetNames( typeof( InventoryOptions ) ) ) {
if( cur == "Split" && !Item.isQuantityItem ) {
if( cur == "Split" && !Item.ItemStats.IsQuantityItem ) {
continue;
}
dropDown.GetPopup().AddItem( cur );
}
Item.GridPosition = new Vector2I( xindex, yindex );
_Inventory.Add( (Item, ItemBackDrop) );
Item.InventoryObject.GridPosition = new Vector2I( xindex, yindex );
_Inventory.Add( Item );
GetWeight();
// Add Tool if its a tool
if (!string.IsNullOrEmpty(Item.ToolPath)){
PackedScene toolCopy = GD.Load<PackedScene>(Item.ToolPath);
if (!string.IsNullOrEmpty(Item.ItemStats.ToolPath)){
PackedScene toolCopy = GD.Load<PackedScene>(Item.ItemStats.ToolPath);
Label tool = toolCopy.Instantiate<Label>();
// Place tool into toolbar in the correct spot and shift everything down to zero if need be
Node[] toolbarChildren = _Reference.ToolBar.GetChildren().ToArray();
@@ -190,17 +190,17 @@ public partial class Inventory : Panel {
return false;
}
public void DropInventory( InventoryItem item, Panel frame ) {
public void DropInventory( GameItem item ) {
string[] PickupItems = _Reference.ItemSpawner._SpawnableScenes;
PackedScene ps = GD.Load<PackedScene>(PickupItems[item.ItemID]);
Pickup prefab = ps.Instantiate<Pickup>();
prefab.GlobalTransform = _Reference.Humanoid.GlobalTransform;
prefab.Quantity = item.Quantity;
prefab.Quantity = item.InventoryObject.Quantity;
_Reference.ItemSpawnPath.AddChild( prefab );
RemoveInventory( item, frame );
RemoveInventory( item );
}
public void RemoveInventory( InventoryItem item, Panel frame ) {
public void RemoveInventory( GameItem item ) {
foreach(Label cur in _Reference.ToolBar.GetChildren()){
if ( cur.GetChild(0) is ITool ){
ITool x = (ITool)cur.GetChild(0);
@@ -214,8 +214,9 @@ public partial class Inventory : Panel {
}
}
_Inventory.Remove( (item, frame) ) ;
frame.Free();
_Inventory.Remove( item ) ;
item.InventoryFrame.Free();
item.InventoryFrame = null;
GetWeight();
}
@@ -224,22 +225,21 @@ public partial class Inventory : Panel {
//------------------------------//
void MouseDown( Vector2 mousePos ) {
(InventoryItem, Panel)? clicked = GetItemFromScreen( mousePos );
if( clicked.HasValue ) {
GameItem? clicked = GetItemFromScreen( mousePos );
if( clicked != null ) {
_itemBeingHeld = new HeldItem {
MouseStart = mousePos,
MouseOffset = clicked.Value.Item2.Position - mousePos,
Frame = clicked.Value.Item2,
Item = clicked.Value.Item1
MouseOffset = clicked.InventoryFrame.Position - mousePos,
Item = clicked
};
}
}
void MouseMove( Vector2 mousePos ) {
if( _itemBeingHeld != null ) {
Vector2I TempSize = _itemBeingHeld.Item.GridSize;
if( _itemBeingHeld.Item.Rotated ) {
TempSize = new Vector2I( _itemBeingHeld.Item.GridSize.Y, _itemBeingHeld.Item.GridSize.X );
Vector2I TempSize = _itemBeingHeld.Item.ItemStats.InventorySize;
if( _itemBeingHeld.Item.InventoryObject.Rotated ) {
TempSize = new Vector2I( _itemBeingHeld.Item.ItemStats.InventorySize.Y, _itemBeingHeld.Item.ItemStats.InventorySize.X );
}
Vector2 newFramePos = mousePos + _itemBeingHeld.MouseOffset;
if( newFramePos.X < 0 ) {
@@ -254,15 +254,15 @@ public partial class Inventory : Panel {
if( newFramePos.Y > _GridSize.Y * InventorySize.Y - (_GridSize.Y * TempSize.Y) ) {
newFramePos.Y = _GridSize.Y * InventorySize.Y - (_GridSize.Y * TempSize.Y);
}
_itemBeingHeld.Frame.Position = newFramePos;
_itemBeingHeld.Item.InventoryFrame.Position = newFramePos;
}
}
void MouseUp( Vector2 mousePos ) {
if( _itemBeingHeld != null ) {
Vector2I TempSize = _itemBeingHeld.Item.GridSize;
if( _itemBeingHeld.Item.Rotated ) {
TempSize = new Vector2I( _itemBeingHeld.Item.GridSize.Y, _itemBeingHeld.Item.GridSize.X );
Vector2I TempSize = _itemBeingHeld.Item.ItemStats.InventorySize;
if( _itemBeingHeld.Item.InventoryObject.Rotated ) {
TempSize = new Vector2I( _itemBeingHeld.Item.ItemStats.InventorySize.Y, _itemBeingHeld.Item.ItemStats.InventorySize.X );
}
Vector2 FinalGrid = new Vector2(
Mathf.Round((mousePos.X + _itemBeingHeld.MouseOffset.X) / _GridSize.X),
@@ -273,33 +273,33 @@ public partial class Inventory : Panel {
if( FinalGrid.X > (InventorySize.X - TempSize.X) ) { FinalGrid.X = InventorySize.X - TempSize.X; }
if( FinalGrid.Y > (InventorySize.Y - TempSize.Y) ) { FinalGrid.Y = InventorySize.Y - TempSize.Y; }
if( CheckBlock( TempSize, new Vector2I( Convert.ToInt32( FinalGrid.X ), Convert.ToInt32( FinalGrid.Y )), _itemBeingHeld.Item ) ) { // Check fitment
_itemBeingHeld.Item.GridPosition = new Vector2I( Convert.ToInt32( FinalGrid.X ), Convert.ToInt32( FinalGrid.Y ) );
_itemBeingHeld.Frame.Position = _GridSize * FinalGrid + new Vector2( 5, 5 );
_itemBeingHeld.Item.InventoryObject.GridPosition = new Vector2I( Convert.ToInt32( FinalGrid.X ), Convert.ToInt32( FinalGrid.Y ) );
_itemBeingHeld.Item.InventoryFrame.Position = _GridSize * FinalGrid + new Vector2( 5, 5 );
} else {
(InventoryItem, Panel)? itemAtSpot = GetItemFromScreen( mousePos );
if( itemAtSpot.Value.Item1.isQuantityItem && itemAtSpot.Value.Item1.ItemID == _itemBeingHeld.Item.ItemID ) {
GameItem? itemAtSpot = GetItemFromScreen( mousePos );
if( itemAtSpot.ItemStats.IsQuantityItem && itemAtSpot.ItemID == _itemBeingHeld.Item.ItemID ) {
// Try Combine
int MaxQuantity = _itemBeingHeld.Item.MaxQuantity;
int Total = itemAtSpot.Value.Item1.Quantity + _itemBeingHeld.Item.Quantity;
int MaxQuantity = _itemBeingHeld.Item.ItemStats.MaxQuantity;
int Total = itemAtSpot.InventoryObject.Quantity + _itemBeingHeld.Item.InventoryObject.Quantity;
if( Total > MaxQuantity ) {
int remainder = Total - MaxQuantity;
itemAtSpot.Value.Item1.Quantity = MaxQuantity;
_itemBeingHeld.Item.Quantity = remainder;
_itemBeingHeld.Frame.Position = new Vector2(
_itemBeingHeld.Item.GridPosition.X * _GridSize.X + 5,
_itemBeingHeld.Item.GridPosition.Y * _GridSize.Y + 5
itemAtSpot.InventoryObject.Quantity = MaxQuantity;
_itemBeingHeld.Item.InventoryObject.Quantity = remainder;
_itemBeingHeld.Item.InventoryFrame.Position = new Vector2(
_itemBeingHeld.Item.InventoryObject.GridPosition.X * _GridSize.X + 5,
_itemBeingHeld.Item.InventoryObject.GridPosition.Y * _GridSize.Y + 5
);
} else {
itemAtSpot.Value.Item1.Quantity = Total;
MenuButton button = itemAtSpot.Value.Item2.GetChild<MenuButton>(0);
button.Text = itemAtSpot.Value.Item1.Name + "\n" +
itemAtSpot.Value.Item1.Quantity + " / " + itemAtSpot.Value.Item1.MaxQuantity;
RemoveInventory( _itemBeingHeld.Item, _itemBeingHeld.Frame );
itemAtSpot.InventoryObject.Quantity = Total;
MenuButton button = itemAtSpot.InventoryFrame.GetChild<MenuButton>(0);
button.Text = itemAtSpot.ItemStats.ItemName + "\n" +
itemAtSpot.InventoryObject.Quantity + " / " + itemAtSpot.ItemStats.MaxQuantity;
RemoveInventory( _itemBeingHeld.Item );
}
} else {
_itemBeingHeld.Frame.Position = new Vector2(
_itemBeingHeld.Item.GridPosition.X * _GridSize.X + 5,
_itemBeingHeld.Item.GridPosition.Y * _GridSize.Y + 5
_itemBeingHeld.Item.InventoryFrame.Position = new Vector2(
_itemBeingHeld.Item.InventoryObject.GridPosition.X * _GridSize.X + 5,
_itemBeingHeld.Item.InventoryObject.GridPosition.Y * _GridSize.Y + 5
);
}
}
@@ -308,12 +308,12 @@ public partial class Inventory : Panel {
}
void RightMouseDown( Vector2 mousePos ) {
(InventoryItem, Panel)? clicked = GetItemFromScreen( mousePos );
if( clicked.HasValue ) {
GameItem? clicked = GetItemFromScreen( mousePos );
if( clicked != null ) {
_lastRightClickedItem = new HeldItem {
Frame = clicked.Value.Item2,
Item = clicked.Value.Item1,
MouseStart = mousePos,
MouseOffset = clicked.InventoryFrame.Position - mousePos,
Item = clicked
};
}
}
@@ -322,15 +322,15 @@ public partial class Inventory : Panel {
// Screen Space Math //
//------------------------------//
(InventoryItem, Panel)? GetItemFromScreen( Vector2 screenPos ) {
GameItem? GetItemFromScreen( Vector2 screenPos ) {
Vector2 ClickedGrid = new Vector2( Mathf.Floor(screenPos.X / _GridSize.X), Mathf.Floor(screenPos.Y / _GridSize.Y) );
foreach( (InventoryItem, Panel) cur in _Inventory ) {
Vector2I TempSize = cur.Item1.GridSize;
if( cur.Item1.Rotated ) {
TempSize = new Vector2I( cur.Item1.GridSize.Y, cur.Item1.GridSize.X );
foreach( GameItem cur in _Inventory ) {
Vector2I TempSize = cur.ItemStats.InventorySize;
if( cur.InventoryObject.Rotated ) {
TempSize = new Vector2I( cur.ItemStats.InventorySize.Y, cur.ItemStats.InventorySize.X );
}
if( ClickedGrid.X >= cur.Item1.GridPosition.X && ClickedGrid.X <= (cur.Item1.GridPosition.X + TempSize.X - 1) &&
ClickedGrid.Y >= cur.Item1.GridPosition.Y && ClickedGrid.Y <= (cur.Item1.GridPosition.Y + TempSize.Y - 1) ) {
if( ClickedGrid.X >= cur.InventoryObject.GridPosition.X && ClickedGrid.X <= (cur.InventoryObject.GridPosition.X + TempSize.X - 1) &&
ClickedGrid.Y >= cur.InventoryObject.GridPosition.Y && ClickedGrid.Y <= (cur.InventoryObject.GridPosition.Y + TempSize.Y - 1) ) {
return cur;
}
}
@@ -345,24 +345,24 @@ public partial class Inventory : Panel {
return localPos;
}
bool CheckBlock( Vector2I BlockSize, Vector2I BlockGridPostion, InventoryItem Ignore ) {
bool CheckBlock( Vector2I BlockSize, Vector2I BlockGridPostion, GameItem Ignore ) {
for( int y = 0; y < BlockSize.Y; y++ ) {
for( int x = 0; x < BlockSize.X; x++ ) {
foreach( (InventoryItem, Control) cur in _Inventory ) {
foreach( GameItem cur in _Inventory ) {
// Check Ignore
if( Ignore != null && cur.Item1.Guid == Ignore.Guid ) {
if( Ignore != null && cur.Guid == Ignore.Guid ) {
continue;
}
// Properly rotate block
Vector2I tempSize;
if( !cur.Item1.Rotated ) {
tempSize = cur.Item1.GridSize;
if( !cur.InventoryObject.Rotated ) {
tempSize = cur.ItemStats.InventorySize;
} else {
tempSize = new Vector2I( cur.Item1.GridSize.Y, cur.Item1.GridSize.X );
tempSize = new Vector2I( cur.ItemStats.InventorySize.Y, cur.ItemStats.InventorySize.X );
}
// Check fit
Vector2I curTopLeft = cur.Item1.GridPosition;
Vector2I curBotRight = new Vector2I( cur.Item1.GridPosition.X + tempSize.X - 1, cur.Item1.GridPosition.Y + tempSize.Y - 1 );
Vector2I curTopLeft = cur.InventoryObject.GridPosition;
Vector2I curBotRight = new Vector2I( cur.InventoryObject.GridPosition.X + tempSize.X - 1, cur.InventoryObject.GridPosition.Y + tempSize.Y - 1 );
if( (x + BlockGridPostion.X) >= curTopLeft.X && (x + BlockGridPostion.X) <= curBotRight.X &&
(y + BlockGridPostion.Y) >= curTopLeft.Y && (y + BlockGridPostion.Y) <= curBotRight.Y ) {
return false;
@@ -395,12 +395,12 @@ public partial class Inventory : Panel {
// Right Click Functions //
//------------------------------//
(bool, Vector2I) TryRotate( InventoryItem item ) {
(bool, Vector2I) TryRotate( GameItem item ) {
Vector2I tempSize;
if( item.Rotated ) {
tempSize = item.GridSize;
if( item.InventoryObject.Rotated ) {
tempSize = item.ItemStats.InventorySize;
} else {
tempSize = new Vector2I( item.GridSize.Y, item.GridSize.X );
tempSize = new Vector2I( item.ItemStats.InventorySize.Y, item.ItemStats.InventorySize.X );
}
// Go through the inventory grid minus overflow from the size of the item were trying to place
for( int yindex = 0; yindex <= (InventorySize.Y - tempSize.Y); yindex++ ) {
@@ -428,11 +428,13 @@ public partial class Inventory : Panel {
void SplitFrame_Split() {
int quantity = Convert.ToInt32( _splitFrame.GetChild<LineEdit>( 1 ).Text );
InventoryItem x = _lastRightClickedItem.Item;
if (quantity <= x.Quantity ) {
PickupItem test = new PickupItem( x.ItemID, x.Name, x.GridSize, x.Weight, x.isQuantityItem, quantity, x.MaxQuantity );
GameItem x = _lastRightClickedItem.Item;
if (quantity <= x.InventoryObject.Quantity ) {
GameItem test = new GameItem( x.ItemID );
test.InventoryObject.Quantity = quantity;
if( AddInventory( test ) ) {
_lastRightClickedItem.Item.Quantity -= quantity;
_lastRightClickedItem.Item.InventoryObject.Quantity -= quantity;
UpdateItem( _lastRightClickedItem.Item );
} else {
_Reference.Alert.PerformAlert( "Not enough space to split" );
@@ -455,8 +457,8 @@ public partial class Inventory : Panel {
int test = Convert.ToInt32(output);
if (test < 0) {
test = 0;
}else if (test > _lastRightClickedItem.Item.MaxQuantity) {
test = _lastRightClickedItem.Item.MaxQuantity;
}else if (test > _lastRightClickedItem.Item.ItemStats.MaxQuantity) {
test = _lastRightClickedItem.Item.ItemStats.MaxQuantity;
}
_splitFrame.GetChild<LineEdit>( 1 ).Text = test.ToString();
_splitFrame.GetChild<LineEdit>( 1 ).CaretColumn = 50;
@@ -465,20 +467,20 @@ public partial class Inventory : Panel {
void DropdownPressed( long index ) {
InventoryOptions pressed = (InventoryOptions)index;
if( pressed == InventoryOptions.Drop ) {
DropInventory( _lastRightClickedItem.Item, _lastRightClickedItem.Frame );
DropInventory( _lastRightClickedItem.Item );
} else if( pressed == InventoryOptions.Rotate ) {
(bool, Vector2I) tryRotate = TryRotate( _lastRightClickedItem.Item );
if( tryRotate.Item1 ) {
_lastRightClickedItem.Item.Rotated = !_lastRightClickedItem.Item.Rotated;
_lastRightClickedItem.Item.InventoryObject.Rotated = !_lastRightClickedItem.Item.InventoryObject.Rotated;
Vector2 tempSize;
if( _lastRightClickedItem.Item.Rotated ) {
tempSize = new Vector2( _lastRightClickedItem.Item.GridSize.Y, _lastRightClickedItem.Item.GridSize.X );
if( _lastRightClickedItem.Item.InventoryObject.Rotated ) {
tempSize = new Vector2( _lastRightClickedItem.Item.ItemStats.InventorySize.Y, _lastRightClickedItem.Item.ItemStats.InventorySize.X );
} else {
tempSize = _lastRightClickedItem.Item.GridSize;
tempSize = _lastRightClickedItem.Item.ItemStats.InventorySize;
}
_lastRightClickedItem.Frame.Size = new Vector2( _GridSize.X * tempSize.X - 10, _GridSize.Y * tempSize.Y - 10 );
_lastRightClickedItem.Frame.Position = new Vector2( tryRotate.Item2.X * _GridSize.X + 5, tryRotate.Item2.Y * _GridSize.Y + 5 );
_lastRightClickedItem.Item.GridPosition = tryRotate.Item2;
_lastRightClickedItem.Item.InventoryFrame.Size = new Vector2( _GridSize.X * tempSize.X - 10, _GridSize.Y * tempSize.Y - 10 );
_lastRightClickedItem.Item.InventoryFrame.Position = new Vector2( tryRotate.Item2.X * _GridSize.X + 5, tryRotate.Item2.Y * _GridSize.Y + 5 );
_lastRightClickedItem.Item.InventoryObject.GridPosition = tryRotate.Item2;
} else {
_Reference.Alert.PerformAlert( "Not enough space to rotate");
}
@@ -496,55 +498,14 @@ public partial class Inventory : Panel {
// Data Objects //
//------------------------------//
class HeldItem {
public Vector2 MouseStart;
public Vector2 MouseOffset;
public InventoryItem Item;
public Panel Frame;
}
public class PickupItem : InventoryItem {
public Guid Guid { get; }
public int ItemID { get; }
public string Name { get; }
public Vector2I GridPosition { get; set; }
public bool Rotated { get; set; }
public Vector2I GridSize { get; }
public int Weight {get;}
public bool isQuantityItem { get; }
public int Quantity { get; set; }
public int MaxQuantity { get; set; }
public string ToolPath{ get; }
public PickupItem( int _ItemID, string _Name, Vector2I _GridSize, int _Weight, bool _isQuantityItem, int _Quanitity = 0, int _MaxQuantity = 0, string _ToolPath = "" ) {
Guid = Guid.NewGuid();
ItemID = _ItemID;
Name = _Name;
GridSize = _GridSize;
Weight = _Weight;
isQuantityItem = _isQuantityItem;
Quantity = _Quanitity;
MaxQuantity = _MaxQuantity;
ToolPath = _ToolPath;
}
}
public interface InventoryItem {
public Guid Guid { get; }
public int ItemID { get; }
public string Name { get; }
public Vector2I GridPosition { get; set; }
public bool Rotated { get; set; }
public Vector2I GridSize { get; }
public int Weight { get; }
public bool isQuantityItem { get; }
public int Quantity { get; set; }
public int MaxQuantity { get; set; }
public string ToolPath { get; }
}
enum InventoryOptions {
Drop,
Rotate,
Split
}
public class HeldItem {
public Vector2 MouseStart { get; set; }
public Vector2 MouseOffset { get; set; }
public GameItem Item { get; set; }
}
-11
View File
@@ -1,11 +0,0 @@
using Godot;
public partial class Pickup : RigidBody3D {
[Export]
public int ItemID {get; set;}
[Export]
public int Quantity {get; set;}
}
-1
View File
@@ -1 +0,0 @@
uid://bd1tifuc7cih1
+11 -10
View File
@@ -1,6 +1,5 @@
using Godot;
using Godot.Collections;
using System.Diagnostics;
public partial class SelectTool : Node3D, ITool {
@@ -8,7 +7,6 @@ public partial class SelectTool : Node3D, ITool {
Options _Options;
Reference _Reference;
ItemStats _Stats;
[Export] PackedScene SelectToolFrame;
[Export] Material HoverMaterial;
@@ -50,19 +48,23 @@ public partial class SelectTool : Node3D, ITool {
int ItemID = ((Pickup)test).ItemID;
int Quantity = ((Pickup)test).Quantity;
StatItem ItemStats = _Stats.stats[ ItemID ];
PickupItem item = new PickupItem( ItemID, ItemStats.ItemName, ItemStats.InventorySize, ItemStats.Weight, ItemStats.IsQuantityItem, Quantity, ItemStats.MaxQuantity, ItemStats.ToolPath );
GameItem item = new GameItem(ItemID);
item.GameObject = test;
if (item.ItemStats.IsQuantityItem) {
item.InventoryObject.Quantity = Quantity;
}
if( _lookingAt == null ) {
_lookingAt = test.GetChild<MeshInstance3D>( 1 );
_defaultMaterial = _lookingAt.GetSurfaceOverrideMaterial( 0 );
_lookingAt.SetSurfaceOverrideMaterial( 0, HoverMaterial );
_SelectToolFrame.Visible = true;
_SelectToolFrame.GetChild<Label>( 0 ).Text = item.Name;
_SelectToolFrame.GetChild<Label>( 1 ).Text = "Slot : " + item.GridSize.ToString();
_SelectToolFrame.GetChild<Label>( 2 ).Text = "Weight : " + item.Weight;
if (item.isQuantityItem ) {
_SelectToolFrame.GetChild<Label>( 3 ).Text = "Capacity : " + item.Quantity + "/" + item.MaxQuantity;
_SelectToolFrame.GetChild<Label>( 0 ).Text = item.ItemStats.ItemName;
_SelectToolFrame.GetChild<Label>( 1 ).Text = "Slot : " + item.ItemStats.InventorySize.ToString();
_SelectToolFrame.GetChild<Label>( 2 ).Text = "Weight : " + item.ItemStats.InventoryWeight;
if (item.ItemStats.IsQuantityItem ) {
_SelectToolFrame.GetChild<Label>( 3 ).Text = "Capacity : " + item.InventoryObject.Quantity + "/" + item.ItemStats.MaxQuantity;
_SelectToolFrame.Size = new Vector2( _SelectToolFrame.Size.X, 95 );
} else {
_SelectToolFrame.GetChild<Label>( 3 ).Text = "";
@@ -91,7 +93,6 @@ public partial class SelectTool : Node3D, ITool {
public void Equiped() {
_Options = GetNode<Options>( "/root/Options" );
_Reference = GetNode<Reference>("/root/Reference");
_Stats = (ItemStats)_Reference.ItemSpawnPath;
_SelectToolFrame = SelectToolFrame.Instantiate<Control>();
GetNode( "/root/GameRoot/UI/GameUI/Game" ).AddChild( _SelectToolFrame );
equipped = true;