-- Button
local BB = CreateFrame("Button","FBags_BagButton",UIParent,"SecureActionButtonTemplate")
BB:SetPoint("CENTER", UIParent, "CENTER",0,500)
BB:SetSize(50, 50)
local ButtonTexture = BB:CreateTexture("ButtonTexture", "BACKGROUND")
ButtonTexture:SetTexture("Interface\\Buttons\\Button-Backpack-Up")
ButtonTexture:SetPoint("CENTER","FBags_BagButton","CENTER")
ButtonTexture:SetSize(50, 50)
BB:SetScript("OnClick", function(self)
FB:SetShown(not FB:IsShown())
print("Bag Clicked")
end)
BB:RegisterEvent("PLAYER_ENTERING_WORLD")
FB = CreateFrame("Button","FBags",UIParent, "ActionButtonTemplate")
FB:SetFrameStrata("BACKGROUND")
FB:SetPoint("CENTER", UIParent, "CENTER",-400,300)
FB:SetSize(50, 50)
FB:Hide()
-- Bag Layout
for bagid = 0,4 do
for bagslot = 1,GetContainerNumSlots(bagid) do
local icon, itemCount, locked, ContItemQuality, readable, lootable, ContItemLink, isFiltered, noValue, ContItemID = GetContainerItemInfo(bagid, bagslot)
local SlotFrame = CreateFrame("Button", "Bag"..bagid.."Slot"..bagslot, FB,"SecureActionButtonTemplate, ActionButtonTemplate",100*bagid+bagslot)
SlotFrame:SetSize(40,40)
SlotFrame:SetPoint("TOP",FB,"BOTTOM",40*bagslot,-40*bagid)
SlotFrame:RegisterEvent("BAG_UPDATE")
SlotFrame:RegisterEvent("ITEM_LOCKED")
SlotFrame:RegisterEvent("ITEM_UNLOCKED")
SlotFrame:RegisterForClicks("AnyUp")
-- to use items
SlotFrame:SetAttribute("type2", "item")
SlotFrame:SetAttribute("bag", bagid)
SlotFrame:SetAttribute("slot", bagslot)
-- adding a texture, text, cooldown
local texture = SlotFrame:CreateTexture("Bag"..bagid.."Slot"..bagslot.."Texture", "BACKGROUND")
local text = SlotFrame:CreateFontString("Bag"..bagid.."Slot"..bagslot.."Text", "OVERLAY")
text:SetFont("Fonts\\FRIZQT___CYR.TTF", 12, "OUTLINE")
text:SetPoint("BOTTOMRIGHT",SlotFrame,"BOTTOMRIGHT")
local cooldown = CreateFrame("Cooldown", "Bag"..bagid.."Slot"..bagslot.."Cooldown", SlotFrame, "CooldownFrameTemplate")
cooldown:SetAllPoints()
-- widget scripts
-- Tooltip
SlotFrame:SetScript("OnEnter", function()
GameTooltip:SetOwner(SlotFrame, "ANCHOR_CURSOR")
GameTooltip:SetBagItem(bagid, bagslot); -- SetBagItem(bagid, bagslot)
GameTooltip:Show()
end)
SlotFrame:SetScript("OnLeave", function()
GameTooltip:Hide()
end)
-- Item moving
SlotFrame:SetScript("OnMouseUp", function(self, button)
local CursorItem, CursorItemID, CursorItemLink = GetCursorInfo()
local x = GetMouseFocus():GetID()
local b = (x-x%100)/100
local s = x%100
local icon1, itemCount1, locked1, quality1, readable1, lootable1, itemLink1, isFiltered1, noValue1, ContItemID1 = GetContainerItemInfo(b, s)
if not (b == 0 and s == 0) then
if button == "LeftButton" then
if GetContainerItemInfo(b, s) and not GetCursorInfo() then
PickupContainerItem(b, s)
print("Picking up bag "..b.." slot "..s.." using "..button)
elseif GetCursorInfo() and not GetContainerItemInfo(b, s) then
PickupContainerItem(b, s)
print("Putting down bag "..b.." slot "..s.." using "..button)
elseif not GetCursorInfo() and not GetContainerItemInfo(b, s) then
print("Nothing to pick up")
elseif ContItemID1 == 82800 then
PickupContainerItem(b, s)
print("Putting down bag "..b.." slot "..s.." using "..button)
elseif CursorItemID == ContItemID1 then
ClearCursor()
print("Same cell, putting down")
elseif CursorItemID ~= ContItemID1 then
PickupContainerItem(b, s)
print("Filled cell, swapping")
end
end
end
end)
-- Bag Update, cooldowns, icons
local function eventHandler(self, event, ...)
local icon, itemCount, locked, quality, readable, lootable, itemLink, isFiltered, noValue, itemID = GetContainerItemInfo(bagid, bagslot)
local startTime, duration, isEnabled = GetContainerItemCooldown(bagid, bagslot)
if event == "BAG_UPDATE" then
if GetContainerItemInfo(bagid, bagslot) then
if duration>0 then
cooldown:SetCooldown(startTime,duration)
print("cooldown started in "..bagid.." "..bagslot)
else
cooldown:SetCooldown(0,0)
end
texture:SetTexture(icon)
texture:SetPoint("CENTER","Bag"..bagid.."Slot"..bagslot,"CENTER")
texture:SetSize(40, 40)
if itemCount>1 then
text:SetText(itemCount)
else
text:SetText(nil)
end
else
texture:SetTexture("Interface\\BUTTONS\\UI-Slot-Background.blp")
texture:SetPoint("CENTER","Bag"..bagid.."Slot"..bagslot,"CENTER",11,-10)
texture:SetSize(60, 60)
text:SetText()
cooldown:SetCooldown(0,0)
end
end
end
SlotFrame:SetScript("OnEvent", eventHandler);
end
end
-- "OpenBackpack" "CloseBackpack" "ToggleBackpack" "CloseAllBags" "OpenAllBags" "ToggleAllBags"
-- hook functions
hooksecurefunc(
"CloseAllBags",function()
if FB:IsShown() then
FB:Hide()
end
print("CloseAllBags hookedfunction fired")
end
)
hooksecurefunc(
"ToggleAllBags",function()
FB:SetShown(not FB:IsShown())
print("ToggleAllBags hookedfunction fired")
end
)