.
Bondwoman Um, could you explain a little more what you are actually trying to do, what you current have and what the issues are?
Pantheon I have 6 inventory slots and i am trying to make it so that when an inventory button
enters the first slot, the resource will have its first slot variable set to true but if it enters any other slot
its first slot variable would be set to false.
inventory_gui control script:
`using Godot;
using System;
using System.Collections.Generic;
public partial class inventory_gui : Control
{
private GridContainer gridContainer;
private PackedScene InventoryButton;
[Export]
private string itemButtonPath = "res://scenes/inventory_button.tscn";
[Export]
public int Capacity { get; set; } = 5;
public InventoryButton GrabbedObject { get; set; }
public InventoryButton HoverOverButton { get; set; }
private Vector2 lastMouseClickedPos;
public Control statsShow;
public ProgressBar progressBar;
public InventoryButton inventoryButton;
public Area2D invButtonArea;
private List<EData> items = new List<EData>();
public override void _Ready()
{
gridContainer = GetNode<GridContainer>("NinePatchRect/GridContainer");
InventoryButton = ResourceLoader.Load<PackedScene>(itemButtonPath);
inventoryButton = GetNode<InventoryButton>("NinePatchRect/GridContainer/InventoryButton");
statsShow = GetNode<Control>("/root/Node2D/Player/CanvasLayer2/StatsShow");
progressBar = GetNode<ProgressBar>("/root/Node2D/Player/CanvasLayer2/StatsShow/ProgressBar");
invButtonArea = GetNode<Area2D>("NinePatchRect/GridContainer/InventoryButton/Area2D");
populateButtons();
_starterAdded();
//_enemyAdded();
}
private void populateButtons()
{
for(int i = 0; i < Capacity; i++)
{
InventoryButton currentInventoryButton = InventoryButton.Instantiate<InventoryButton>();
gridContainer.AddChild(currentInventoryButton);
}
}
// Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _Process(double delta)
{
GetNode<Area2D>("MouseArea2d").Position = GetTree().Root.GetMousePosition() - (this.Size / 4);
if(HoverOverButton != null && Visible == true)
{
if (Input.IsActionJustPressed("Stats"))
{
GD.Print("Clicked");
if (Visible == true)
{
Visible = false;
statsShow.Visible = true;
}
}
if (Input.IsActionJustPressed("Throw"))
{
GrabbedObject = HoverOverButton;
lastMouseClickedPos = GetTree().Root.GetMousePosition();
}
if(lastMouseClickedPos.DistanceTo(GetTree().Root.GetMousePosition()) > 2)
{
if(Input.IsActionPressed("Throw"))
{
InventoryButton button = GetNode<Area2D>("MouseArea2d").GetNode<InventoryButton>("InventoryButton");
button.Show();
button.UpdateItem(GrabbedObject.InventoryItem, 0);
}
if(Input.IsActionJustReleased("Throw"))
{
int buttonindex = GrabbedObject.GetIndex();
int button2index = HoverOverButton.GetIndex();
gridContainer.MoveChild(GrabbedObject, button2index);
gridContainer.MoveChild(HoverOverButton, buttonindex);
//inventoryButton.InventoryItem._slotChange(1);
InventoryButton button = GetNode<Area2D>("MouseArea2d").GetNode<InventoryButton>("InventoryButton");
button.Hide();
}
}
}
}
public void Add(EData item) {
EData currentItem = item.Copy();
items.Add(currentItem);
UpdateButton(items.Count - 1);
}
public void UpdateButton(int index) {
gridContainer.GetChild<InventoryButton>(index).UpdateItem(items[index], index);
}
public void _on_add_button_button_down()
{
Add(ResourceLoader.Load<EData>("res://EnemyData.tres"));
}
public void _starterAdded()
{
Add(ResourceLoader.Load<EData>("res://PlayerStart.tres"));
}`
InventoryButton script:
`using Godot;
using System;
public partial class InventoryButton : Button
{
public EData InventoryItem;
private int index;
[Export]
public Resource edata;
public void UpdateItem(EData item, int index)
{
this.index = index;
InventoryItem = item;
nameLabel.Text = item.Name.ToString();
levelLabel.Text = "Lvl: " + item.Level;
progressBar.Value = item.currentEnemyHealth;
progressBar.MaxValue = item.maxEnemyHealth;
healthLabel.Text = item.currentEnemyHealth + "/" + item.maxEnemyHealth;
icon.Texture = item.Icon;
}
}`
I was following this youtube tutorial:
© 2022 - 2024 — McMap. All rights reserved.