![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | yokopoko |
I could add buttons to TreeItem items with the add_button()
method, but then how am I supposed to use those buttons?
Tree has a get_pressed_button()
method but it returns the same number every time, if I press different buttons in different rows and columns.
public void UpdateQueueTree()
{
queue.Clear();
queue.Columns = 4;
var r = queue.CreateItem();
queue.SetColumnTitlesVisible(true);
queue.SetColumnTitle(0, "Queue");
queue.SetColumnMinWidth(0, 5);
queue.SetColumnTitle(1, "N.");
foreach (var item in c.Production.queue.items)
{
var p = queue.CreateItem(r);
p.SetText(0, buildingName(item.id));
p.SetExpandRight(0, true);
p.SetText(1, item.quantity.ToString());
p.SetTextAlign(1, (TreeItem.TextAlign)1);
p.AddButton(2, Res.treeButtonPlus);
p.AddButton(3, Res.treeButtonMinus);
}
}
void QueueButtons(InputEvent @event)
{
if (@event is InputEventMouseButton)
{
InputEventMouseButton ev = (InputEventMouseButton)@event;
if (ev.ButtonIndex == (int)ButtonList.Left && ev.Pressed)
{
GD.Print("pressed: " + queue.GetPressedButton());
}
}
}