-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.lua
More file actions
74 lines (63 loc) · 1.61 KB
/
Copy pathmain.lua
File metadata and controls
74 lines (63 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
local THRESHOLD = 6
local function addonLoadedHandler(self, event, name)
if name == 'Scrap' then
onLoad();
return;
end
end
local function getFreeSlotCount()
local available = 0
for i=0, 4 do
local slots, type = GetContainerNumFreeSlots(i)
if type == 0 then
available = available + slots
end
end
return available
end
local b = CreateFrame("Button", "MyButton", UIParent, "UIPanelButtonTemplate")
b:SetSize(80 ,22) -- width, height
b:SetText("Clean bags!")
b:SetPoint("TOP")
b:SetScript("OnClick", function()
local slotCount = getFreeSlotCount()
local countToDelete = THRESHOLD - slotCount
for bag, slot in Scrap:IterateJunk() do
PickupContainerItem(bag, slot)
DeleteCursorItem()
countToDelete = countToDelete - 1
if countToDelete <= 0 then
return
end
end
end)
b:Hide()
local function checkInventorySpace()
local slotCount = getFreeSlotCount()
local bag, slot, id = Scrap:IterateJunk()()
if slotCount < THRESHOLD and bag ~= nil and slot ~= nil then
b:Show()
else
b:Hide()
end
return slotCount;
end
local function inventoryChangedHandler(self, event, container)
local slots, type = GetContainerNumFreeSlots(container)
if type == 0 then
checkInventorySpace()
end
end
local function onLoad()
local frame = CreateFrame("FRAME");
frame:RegisterEvent("ITEM_PUSH");
frame:RegisterEvent("BAG_UPDATE");
frame:SetScript("OnEvent", inventoryChangedHandler);
end
if Scrap then
onLoad()
else
local frame = CreateFrame("FRAME");
frame:RegisterEvent("ADDON_LOADED");
frame:SetScript("OnEvent", addonLoadedHandler);
end