update Bags and Sort (Need some more work)

This commit is contained in:
Crum
2018-01-18 11:35:09 -06:00
parent cbb5f07cc7
commit 3314de89c5
2 changed files with 32 additions and 32 deletions
+13 -14
View File
@@ -9,7 +9,7 @@ local _G = _G
local type, ipairs, pairs, unpack, select, assert = type, ipairs, pairs, unpack, select, assert local type, ipairs, pairs, unpack, select, assert = type, ipairs, pairs, unpack, select, assert
local tinsert = table.insert local tinsert = table.insert
local floor, ceil = math.floor, math.ceil local floor, ceil = math.floor, math.ceil
local len, gsub, sub, find = string.len, string.gsub, string.sub, string.find local len, gsub, sub, find, match = string.len, string.gsub, string.sub, string.find, string.match
--WoW API / Variables --WoW API / Variables
local BankFrameItemButton_Update = BankFrameItemButton_Update local BankFrameItemButton_Update = BankFrameItemButton_Update
local BankFrameItemButton_UpdateLocked = BankFrameItemButton_UpdateLocked local BankFrameItemButton_UpdateLocked = BankFrameItemButton_UpdateLocked
@@ -54,7 +54,6 @@ B.ProfessionColors = {
["0x0020"] = {18/255, 181/255, 32/255}, -- Herbs ["0x0020"] = {18/255, 181/255, 32/255}, -- Herbs
["0x0040"] = {160/255, 3/255, 168/255}, -- Enchanting ["0x0040"] = {160/255, 3/255, 168/255}, -- Enchanting
["0x0080"] = {232/255, 118/255, 46/255}, -- Engineering ["0x0080"] = {232/255, 118/255, 46/255}, -- Engineering
["0x0200"] = {8/255, 180/255, 207/255}, -- Gems
["0x0400"] = {105/255, 79/255, 7/255}, -- Mining ["0x0400"] = {105/255, 79/255, 7/255}, -- Mining
["0x010000"] = {222/255, 13/255, 65/255} -- Cooking ["0x010000"] = {222/255, 13/255, 65/255} -- Cooking
} }
@@ -116,15 +115,15 @@ function B:UpdateSearch()
local MIN_REPEAT_CHARACTERS = 3 local MIN_REPEAT_CHARACTERS = 3
local searchString = this:GetText() local searchString = this:GetText()
local prevSearchString = SEARCH_STRING local prevSearchString = SEARCH_STRING
if (len(searchString) > MIN_REPEAT_CHARACTERS) then if len(searchString) > MIN_REPEAT_CHARACTERS then
local repeatChar = true local repeatChar = true
for i = 1, MIN_REPEAT_CHARACTERS, 1 do for i = 1, MIN_REPEAT_CHARACTERS, 1 do
if ( sub(searchString,(0-i), (0-i)) ~= sub(searchString,(-1-i),(-1-i)) ) then if sub(searchString,(0-i), (0-i)) ~= sub(searchString,(-1-i),(-1-i)) then
repeatChar = false repeatChar = false
break break
end end
end end
if ( repeatChar ) then if repeatChar then
B.ResetAndClear(this) B.ResetAndClear(this)
return return
end end
@@ -244,11 +243,11 @@ function B:UpdateSlot(bagID, slotID)
slot:Show() slot:Show()
slot.itemLevel:SetText("") slot.itemLevel:SetText("")
--if(B.ProfessionColors[bagType]) then if B.ProfessionColors[bagType] then
-- slot:SetBackdropBorderColor(unpack(B.ProfessionColors[bagType])) slot:SetBackdropBorderColor(unpack(B.ProfessionColors[bagType]))
if clink then elseif clink then
local iLvl, itemEquipLoc local iLvl, itemEquipLoc
slot.name, _, slot.rarity, iLvl, _, _, _, _, itemEquipLoc = GetItemInfo(string.match(clink, "item:(%d+)")) slot.name, _, slot.rarity, iLvl, _, _, _, itemEquipLoc = GetItemInfo(match(clink, "item:(%d+)"))
local r, g, b local r, g, b
@@ -390,14 +389,14 @@ function B:Layout(isBank)
if not f.ContainerHolder[i] then if not f.ContainerHolder[i] then
if isBank then if isBank then
f.ContainerHolder[i] = CreateFrame("CheckButton", "ElvUIBankBag"..bagID - 4, f.ContainerHolder, "BankItemButtonBagTemplate") f.ContainerHolder[i] = CreateFrame("CheckButton", "ElvUIBankBag"..bagID - 4, f.ContainerHolder, "BankItemButtonBagTemplate")
f.ContainerHolder[i]:SetScript("OnClick", function(self) f.ContainerHolder[i]:SetScript("OnClick", function()
local inventoryID = self:GetInventorySlot() local inventoryID = this:GetInventorySlot()
PutItemInBag(inventoryID) --Put bag on empty slot, or drop item in this bag PutItemInBag(inventoryID) --Put bag on empty slot, or drop item in this bag
end) end)
else else
f.ContainerHolder[i] = CreateFrame("CheckButton", "ElvUIMainBag"..bagID.."Slot", f.ContainerHolder, "BagSlotButtonTemplate") f.ContainerHolder[i] = CreateFrame("CheckButton", "ElvUIMainBag"..bagID.."Slot", f.ContainerHolder, "BagSlotButtonTemplate")
f.ContainerHolder[i]:SetScript("OnClick", function(self) f.ContainerHolder[i]:SetScript("OnClick", function()
local id = self:GetID() local id = this:GetID()
PutItemInBag(id) --Put bag on empty slot, or drop item in this bag PutItemInBag(id) --Put bag on empty slot, or drop item in this bag
end) end)
end end
@@ -450,7 +449,7 @@ function B:Layout(isBank)
f.Bags[bagID] = CreateFrame("Frame", f:GetName().."Bag"..bagID, f) f.Bags[bagID] = CreateFrame("Frame", f:GetName().."Bag"..bagID, f)
f.Bags[bagID]:SetID(bagID) f.Bags[bagID]:SetID(bagID)
f.Bags[bagID].UpdateBagSlots = B.UpdateBagSlots f.Bags[bagID].UpdateBagSlots = B.UpdateBagSlots
-- f.Bags[bagID].UpdateSlot = B.UpdateSlot -- f.Bags[bagID].UpdateSlot = B.UpdateSlot
end end
f.Bags[bagID].numSlots = numSlots f.Bags[bagID].numSlots = numSlots
+19 -18
View File
@@ -22,8 +22,8 @@ local GetContainerNumSlots = GetContainerNumSlots
local GetContainerNumFreeSlots = GetContainerNumFreeSlots local GetContainerNumFreeSlots = GetContainerNumFreeSlots
local ContainerIDToInventoryID = ContainerIDToInventoryID local ContainerIDToInventoryID = ContainerIDToInventoryID
local GetInventoryItemLink = GetInventoryItemLink local GetInventoryItemLink = GetInventoryItemLink
local GetCursorInfo = GetCursorInfo local CursorHasItem = CursorHasItem
local ARMOR, ENCHSLOT_WEAPON = ARMOR, ENCHSLOT_WEAPON local ARMOR = ARMOR
local bankBags = {BANK_CONTAINER} local bankBags = {BANK_CONTAINER}
local MAX_MOVE_TIME = 1.25 local MAX_MOVE_TIME = 1.25
@@ -38,10 +38,10 @@ for i = 0, NUM_BAG_SLOTS do
end end
local allBags = {} local allBags = {}
for _,i in ipairs(playerBags) do for _, i in ipairs(playerBags) do
tinsert(allBags, i) tinsert(allBags, i)
end end
for _,i in ipairs(bankBags) do for _, i in ipairs(bankBags) do
tinsert(allBags, i) tinsert(allBags, i)
end end
@@ -199,7 +199,7 @@ local function DefaultSort(a, b)
return (itemTypes[aType] or 99) < (itemTypes[bType] or 99) return (itemTypes[aType] or 99) < (itemTypes[bType] or 99)
end end
if aType == ARMOR or aType == ENCHSLOT_WEAPON then if aType == ARMOR then
local aEquipLoc = inventorySlots[aEquipLoc] or -1 local aEquipLoc = inventorySlots[aEquipLoc] or -1
local bEquipLoc = inventorySlots[bEquipLoc] or -1 local bEquipLoc = inventorySlots[bEquipLoc] or -1
if aEquipLoc == bEquipLoc then if aEquipLoc == bEquipLoc then
@@ -210,6 +210,7 @@ local function DefaultSort(a, b)
return aEquipLoc < bEquipLoc return aEquipLoc < bEquipLoc
end end
end end
if aSubType == bSubType then if aSubType == bSubType then
return PrimarySort(a, b) return PrimarySort(a, b)
end end
@@ -243,7 +244,7 @@ end
local function IterateForwards(bagList, i) local function IterateForwards(bagList, i)
i = i + 1 i = i + 1
local step = 1 local step = 1
for _,bag in ipairs(bagList) do for _, bag in ipairs(bagList) do
local slots = B:GetNumSlots(bag, bagRole) local slots = B:GetNumSlots(bag, bagRole)
if i > slots + step then if i > slots + step then
step = step + slots step = step + slots
@@ -307,9 +308,8 @@ end
function B:GetNumSlots(bag, role) function B:GetNumSlots(bag, role)
if bag then if bag then
return GetContainerNumSlots(bag) return GetContainerNumSlots(bag);
end end
return 0 return 0
end end
@@ -362,7 +362,7 @@ function B:ScanBags()
if itemID then if itemID then
bagMaxStacks[bagSlot] = select(7, GetItemInfo(itemID)) bagMaxStacks[bagSlot] = select(7, GetItemInfo(itemID))
bagIDs[bagSlot] = itemID bagIDs[bagSlot] = itemID
bagQualities[bagSlot] = select(3, GetItemInfo(B:GetItemLink(bag, slot))) bagQualities[bagSlot] = select(3, GetItemInfo(itemID))
bagStacks[bagSlot] = select(2, B:GetItemInfo(bag, slot)) bagStacks[bagSlot] = select(2, B:GetItemInfo(bag, slot))
end end
end end
@@ -374,6 +374,8 @@ function B:GetItemFamily(bagType)
if strupper(itemSubType) == "BAG" then if strupper(itemSubType) == "BAG" then
return 0 return 0
elseif strupper(itemSubType) == "QUIVER" then
return 1
elseif strupper(itemSubType) == "KEYRING" then elseif strupper(itemSubType) == "KEYRING" then
return -2 return -2
else else
@@ -405,12 +407,12 @@ function B:CanItemGoInBag(bag, slot, targetBag)
itemFamily = 1 itemFamily = 1
end end
end end
-- local bagFamily = select(2, GetContainerNumFreeSlots(targetBag)) local bagFamily = select(2, GetContainerNumFreeSlots(targetBag))
-- if itemFamily then if itemFamily then
-- return (bagFamily == 0) or band(itemFamily, bagFamily) > 0 return (bagFamily == 0) or band(itemFamily, bagFamily) > 0
-- else else
return false return false
-- end end
end end
function B.Compress(...) function B.Compress(...)
@@ -422,6 +424,7 @@ end
function B.Stack(sourceBags, targetBags, canMove) function B.Stack(sourceBags, targetBags, canMove)
if not canMove then canMove = DefaultCanMove end if not canMove then canMove = DefaultCanMove end
for _, bag, slot in B.IterateBags(targetBags, nil, "deposit") do for _, bag, slot in B.IterateBags(targetBags, nil, "deposit") do
local bagSlot = B:Encode_BagSlot(bag, slot) local bagSlot = B:Encode_BagSlot(bag, slot)
local itemID = bagIDs[bagSlot] local itemID = bagIDs[bagSlot]
@@ -487,7 +490,7 @@ function B.Sort(bags, sorter, invertDirection)
twipe(blackListedSlots) twipe(blackListedSlots)
buildBlacklist(B.db.ignoredItems) buildBlacklist(B.db.ignoredItems)
--buildBlacklist(E.global.bags.ignoredItems) buildBlacklist(E.global.bags.ignoredItems)
for i, bag, slot in B.IterateBags(bags, nil, "both") do for i, bag, slot in B.IterateBags(bags, nil, "both") do
local bagSlot = B:Encode_BagSlot(bag, slot) local bagSlot = B:Encode_BagSlot(bag, slot)
@@ -499,7 +502,7 @@ function B.Sort(bags, sorter, invertDirection)
end end
if not blackListedSlots[bagSlot] then if not blackListedSlots[bagSlot] then
for _,itemsearchquery in pairs(blackListQueries) do for _, itemsearchquery in pairs(blackListQueries) do
local success, result = pcall(Search.Matches, Search, link, itemsearchquery) local success, result = pcall(Search.Matches, Search, link, itemsearchquery)
if success and result then if success and result then
blackListedSlots[bagSlot] = blackListedSlots[bagSlot] or result blackListedSlots[bagSlot] = blackListedSlots[bagSlot] or result
@@ -603,7 +606,6 @@ function B.SortBags(...)
if not bagCache[bagType] then bagCache[bagType] = {} end if not bagCache[bagType] then bagCache[bagType] = {} end
bagCache[bagType][i] = slotNum bagCache[bagType][i] = slotNum
end end
for bagType, sortedBags in pairs(bagCache) do for bagType, sortedBags in pairs(bagCache) do
if bagType ~= "Normal" then if bagType ~= "Normal" then
B.Stack(sortedBags, sortedBags, B.IsPartial) B.Stack(sortedBags, sortedBags, B.IsPartial)
@@ -691,7 +693,6 @@ function B:DoMove(move)
end end
function B:DoMoves() function B:DoMoves()
--local cursorType, cursorItemID = GetCursorInfo()
if CursorHasItem() and currentItemID then if CursorHasItem() and currentItemID then
if lastItemID ~= currentItemID then if lastItemID ~= currentItemID then
return B:StopStacking(L["Confused.. Try Again!"]) return B:StopStacking(L["Confused.. Try Again!"])