GUI: dynamically created
Posted: 2012-02-27, 17:45
Hi @ll,
I am trying to create an inventory with a variable Number of Slots.
So I tried to realize this using the following Code:
The code used in
I am trying to create an inventory with a variable Number of Slots.
So I tried to realize this using the following Code:
Code: Select all
function InitInventorySlots(SlotsCnt, ...)
Inventory.SlotsCnt = SlotsCnt;
end
function Inventory:OnActivate()
local i = 1;
local ItemsPerLine = 5;
Slots = {};
for i = 1, self.SlotsCnt, 1 do
Slots[i] = gui:new("WindowT", "Slot" .. i);
Slots[i]:set("rect", 540 + ((i % ItemsPerLine) * 28), math.floor(i / ItemsPerLine) * 28, 25, 25);
Slots[i]:set("backColor", 0, 0.25, 0.7, 0.4);
Slots[i]:set("borderWidth", 0.5);
Slots[i]:set("borderColor", 0.7, 0.8, 0.9, 1);
Inventory:AddChild(Slots[i]);
end
end
Inventory:OnActivate()
was in InitInventorySlots(SlotsCnt, ...)
before, but my Inventory shows up without the Items. No error, just does not show up. Do I have to make an init method for every slot? And how can I realize this with dynamically created windows?