test update Bags and Sort

Need more work.
Also fixes Vendor & Delete Greys
This commit is contained in:
Crum
2018-07-01 23:35:08 -05:00
parent 0bce1f6cb6
commit 8fd70922da
4 changed files with 44 additions and 56 deletions
@@ -132,7 +132,7 @@ end
--[[ Utilities ]]--
function Lib:Find(search, ...)
for i = 1, getn(arg) do
for i = 1, arg.n do
local text = arg[i]
if text and find(self:Clean(text), search) then
return true
@@ -3,17 +3,19 @@
An item text search engine of some sort
--]]
local Search = LibStub("CustomSearch-1.0");
local Unfit = LibStub("Unfit-1.0");
local Lib = LibStub:NewLibrary("LibItemSearch-1.2", 11);
local Search = LibStub("CustomSearch-1.0")
local Unfit = LibStub("Unfit-1.0")
local Lib = LibStub:NewLibrary("LibItemSearch-1.2", 11)
if Lib then
Lib.Filters = {}
else
return
end
local tonumber = tonumber
local find, strmatch, lower = string.find, string.match, string.lower
local pairs, select, tonumber = pairs, select, tonumber
local find, gsub, match, lower = string.find, string.gsub, string.match, string.lower
local GetItemInfo = GetItemInfo
--[[ User API ]]--
@@ -22,11 +24,11 @@ function Lib:Matches(link, search)
end
function Lib:Tooltip(link, search)
return link and strmatch(self.Filters.tip, link, nil, search)
return link and match(self.Filters.tip, link, nil, search)
end
function Lib:TooltipPhrase(link, search)
return link and strmatch(self.Filters.tipPhrases, link, nil, search)
return link and match(self.Filters.tipPhrases, link, nil, search)
end
--[[ Basics ]]--
@@ -39,7 +41,7 @@ Lib.Filters.name = {
end,
match = function(self, item, _, search)
local name = strmatch(item, "%[(.-)%]")
local name = match(item, "%[(.-)%]")
return Search:Find(search, name)
end
}
@@ -52,7 +54,7 @@ Lib.Filters.type = {
end,
match = function(self, item, _, search)
local type, subType, _, equipSlot = select(6, GetItemInfo(item))
local type, subType, _, equipSlot = select(6, GetItemInfo(match(item, "item:(%d+)")))
return Search:Find(search, type, subType, _G[equipSlot])
end
}
@@ -65,7 +67,7 @@ Lib.Filters.level = {
end,
match = function(self, link, operator, num)
local _, _, _, lvl = GetItemInfo(link)
local _, _, _, lvl = GetItemInfo(match(link, "item:(%d+)"))
if lvl then
return Search:Compare(operator, lvl, num)
end
@@ -80,7 +82,7 @@ Lib.Filters.requiredlevel = {
end,
match = function(self, link, operator, num)
local _, _, _, _, lvl = GetItemInfo(link)
local _, _, _, _, lvl = GetItemInfo(match(link, "item:(%d+)"))
if lvl then
return Search:Compare(operator, lvl, num)
end
@@ -106,7 +108,7 @@ Lib.Filters.quality = {
end,
match = function(self, link, operator, num)
local _, _, quality = GetItemInfo(link)
local _, _, quality = GetItemInfo(match(link, "item:(%d+)"))
return Search:Compare(operator, quality, num)
end
}
@@ -122,7 +124,7 @@ Lib.Filters.usable = {
match = function(self, link)
if(not Unfit:IsItemUnusable(link)) then
local _, _, _, _, lvl = GetItemInfo(link)
local _, _, _, _, lvl = GetItemInfo(match(link, "item:(%d+)"))
return lvl and (lvl ~= 0 and lvl <= UnitLevel("player"))
end
end
@@ -162,7 +164,7 @@ local escapes = {
local function CleanString(str)
for k, v in pairs(escapes) do
str = string.gsub(str, k, v)
str = gsub(str, k, v)
end
return str
end
@@ -173,7 +175,7 @@ Lib.Filters.tipPhrases = {
end,
match = function(self, link, _, search)
local id = strmatch(link, "item:(%d+)")
local id = match(link, "item:(%d+)")
if not id then
return
end
+17 -15
View File
@@ -6,13 +6,13 @@ local LIP = LibStub("ItemPrice-1.1", true);
--Cache global variables
--Lua functions
local _G = _G
local type, ipairs, pairs, unpack, select, assert = type, ipairs, pairs, unpack, select, assert
local type, ipairs, pairs, unpack, select, assert, pcall = type, ipairs, pairs, unpack, select, assert, pcall
local tinsert = table.insert
local floor, ceil = math.floor, math.ceil
local len, gsub, sub, find, match = string.len, string.gsub, string.sub, string.find, string.match
--WoW API / Variables
local BankFrameItemButton_Update = BankFrameItemButton_Update
local BankFrameItemButton_UpdateLocked = BankFrameItemButton_UpdateLocked
local BankFrameItemButton_OnUpdate = BankFrameItemButton_OnUpdate
local BankFrameItemButton_UpdateLock = BankFrameItemButton_UpdateLock
local CloseBag, CloseBackpack, CloseBankFrame = CloseBag, CloseBackpack, CloseBankFrame
local CooldownFrame_SetTimer = CooldownFrame_SetTimer
local CreateFrame = CreateFrame
@@ -169,7 +169,7 @@ function B:SetSearch(query)
button:SetAlpha(1)
else
SetItemButtonDesaturated(button, 1)
button:SetAlpha(0.4)
button:SetAlpha(0.5)
end
end
end
@@ -233,7 +233,7 @@ end
function B:UpdateSlot(bagID, slotID)
if (self.Bags[bagID] and self.Bags[bagID].numSlots ~= GetContainerNumSlots(bagID)) or not self.Bags[bagID] or not self.Bags[bagID][slotID] then return end
local slot, _ = self.Bags[bagID][slotID], nil
local slot = self.Bags[bagID][slotID]
local bagType = self.Bags[bagID].type
local texture, count, locked = GetContainerItemInfo(bagID, slotID)
local clink = GetContainerItemLink(bagID, slotID)
@@ -293,7 +293,7 @@ function B:UpdateSlot(bagID, slotID)
SetItemButtonTexture(slot, texture)
SetItemButtonCount(slot, count)
SetItemButtonDesaturated(slot, locked, 0.5, 0.5, 0.5)
SetItemButtonDesaturated(slot, locked)
if GameTooltip:IsOwned(slot) and not slot.hasItem then
B:Tooltip_Hide()
@@ -426,7 +426,8 @@ function B:Layout(isBank)
E:Size(f.ContainerHolder, ((buttonSize + buttonSpacing) * (isBank and i - 1 or i)) + buttonSpacing, buttonSize + (buttonSpacing * 2))
if isBank then
BankFrameItemButton_OnUpdate()
-- BankFrameItemButton_OnUpdate()
-- BankFrameItemButton_UpdateLock()
end
E:Size(f.ContainerHolder[i], buttonSize)
@@ -447,11 +448,13 @@ function B:Layout(isBank)
f.Bags[bagID] = CreateFrame("Frame", f:GetName().."Bag"..bagID, f)
f.Bags[bagID]:SetID(bagID)
f.Bags[bagID].UpdateBagSlots = B.UpdateBagSlots
-- f.Bags[bagID].UpdateSlot = B.UpdateSlot
-- f.Bags[bagID].UpdateSlot = UpdateSlot
end
f.Bags[bagID].numSlots = numSlots
-- f.Bags[bagID].type = select(2, GetContainerNumFreeSlots(bagID))
local _, _, id = strfind(GetInventoryItemLink("player", ContainerIDToInventoryID(bagID)) or "", "item:(%d+)")
f.Bags[bagID].type = select(6, GetItemInfo(id))
--Hide unused slots
for i = 1, MAX_CONTAINER_ITEMS do
@@ -530,8 +533,8 @@ function B:Layout(isBank)
if self.isBank then
if self.ContainerHolder[i] then
BankFrameItemButton_Update(self.ContainerHolder[i])
BankFrameItemButton_UpdateLocked(self.ContainerHolder[i])
BankFrameItemButton_OnUpdate()
BankFrameItemButton_UpdateLock()
end
end
end
@@ -602,7 +605,7 @@ function B:UpdateKeySlot(slotID)
if clink then
local _
slot.name, _, slot.rarity = GetItemInfo(clink)
slot.name, _, slot.rarity = GetItemInfo(match(clink, "item:(%d+)"))
local r, g, b
@@ -697,7 +700,7 @@ function B:GetGraysValue()
local l = GetContainerItemLink(b, s)
if l and find(l,"ff9d9d9d") then
local p = LIP:GetSellValue(l) * select(2, GetContainerItemInfo(b, s))
if select(3, GetItemInfo(l)) == 0 and p > 0 then
if select(3, GetItemInfo(match(l, "item:(%d+)"))) == 0 and p > 0 then
c = c + p
end
end
@@ -749,7 +752,6 @@ end
function B:VendorGrayCheck()
local value = B:GetGraysValue()
if value == 0 then
E:Print(L["No gray items to delete."])
elseif not MerchantFrame or not MerchantFrame:IsShown() then
@@ -1185,7 +1187,7 @@ function B:Initialize()
E:Point(BagFrameHolder, "BOTTOMRIGHT", RightChatPanel, "BOTTOMRIGHT", -(E.Border*2), 22 + E.Border*4 - E.Spacing*2)
E:CreateMover(BagFrameHolder, "ElvUIBagMover", L["Bag Mover"], nil, nil, B.PostBagMove)
-- self:SecureHook("UpdateContainerFrameAnchors")
self:SecureHook("UpdateContainerFrameAnchors")
return
end
+9 -25
View File
@@ -4,7 +4,7 @@ local Search = LibStub("LibItemSearch-1.2");
--Cache global variables
--Lua functions
local ipairs, pairs, tonumber, select, unpack = ipairs, pairs, tonumber, select, unpack
local ipairs, pairs, pcall, tonumber, select, unpack = ipairs, pairs, pcall, tonumber, select, unpack
local tinsert, tremove, tsort, twipe = table.insert, table.remove, table.sort, table.wipe
local floor, mod = math.floor, math.mod
local band = bit.band
@@ -361,26 +361,10 @@ function B:ScanBags()
end
end
local bagType = {
["Bag"] = 0,
["Quiver"] = 1,
["Ammo Pouch"] = 2,
["Soul Bag"] = 4,
}
function B:GetItemFamily(bagID)
if bagID == KEYRING_CONTAINER then return KEYRING_CONTAINER end
if bagID == 0 then return 0 end
local _, _, id = strfind(GetInventoryItemLink("player", ContainerIDToInventoryID(bagID)) or "", "item:(%d+)")
if id then
local _, _, _, _, itemType, subType = GetItemInfo(id)
local bagSubType = bagType[subType]
if bagSubType == 0 then return 0 end -- based off https://wow.gamepedia.com/ItemFamily
if bagSubType == 1 then return 1 end
if bagSubType == 2 then return 2 end
if bagSubType == 4 then return 4 end
local function GetItemFamily(bag)
local itemType = select(6, GetItemInfo(match(bag, "item:(%d+)")))
if itemType then
return itemType
end
return nil
@@ -395,16 +379,16 @@ function B:IsSpecialtyBag(bagID)
local bag = GetInventoryItemLink("player", inventorySlot)
if not bag then return false end
local family = B:GetItemFamily(bagID)
if family == 0 or family == nil then return false else return false end
local family = GetItemFamily(bag)
if family == "Bag" or family == nil then return false else return false end
return family
end
function B:CanItemGoInBag(bag, slot, targetBag)
local item = bagIDs[B:Encode_BagSlot(bag, slot)]
local itemFamily = B:GetItemFamily(item)
if itemFamily and itemFamily > 0 then
local itemFamily = GetItemFamily(item)
if itemFamily and (not itemFamily == "Bag") then
local equipSlot = select(8, GetItemInfo(item))
if equipSlot == "INVTYPE_BAG" then
itemFamily = 1