- Fix some leaked globals

- CS fixes
This commit is contained in:
2016-09-08 17:13:24 +02:00
parent 771bfaf5eb
commit a4f08a0b44

View File

@ -1,7 +1,64 @@
local MBC = "MyBagsCore-1.1" local MBC = "MyBagsCore-1.1"
local MBC_MINOR = "2016.09.06.1" local MBC_MINOR = "2016.09.08.1"
local error, assert = error, assert -- Lua APIs
local error, assert, pairs, unpack = error, assert, pairs, unpack
local strfind, strlen, strsub, strlower, strgmatch, strupper = string.find, string.len, string.sub, string.lower, string.gmatch, string.upper
local strtrim, format, floor = strtrim, format, floor
local tinsert, tremove = table.insert, table.remove
local tostring, tonumber, select = tostring, tonumber, select
-- WoW APIs
local _G = _G
local NewItemsIsNewItem = C_NewItems.IsNewItem
local BackpackTokenFrame_IsShown = BackpackTokenFrame_IsShown
local BankButtonIDToInvSlotID = BankButtonIDToInvSlotID
local BattlePetToolTip_Show = BattlePetToolTip_Show
local ChatEdit_InsertLink = ChatEdit_InsertLink
local ContainerIDToInventoryID = ContainerIDToInventoryID
local CooldownFrame_Set = CooldownFrame_Set
local CreateFrame = CreateFrame
local CursorUpdate = CursorUpdate
local DressUpItemLink = DressUpItemLink
local GetBackpackCurrencyInfo = GetBackpackCurrencyInfo
local GetBankSlotCost = GetBankSlotCost
local GetContainerItemCooldown = GetContainerItemCooldown
local GetContainerItemInfo = GetContainerItemInfo
local GetContainerItemLink = GetContainerItemLink
local GetContainerNumSlots = GetContainerNumSlots
local GetInventoryItemTexture = GetInventoryItemTexture
local GetInventorySlotInfo = GetInventorySlotInfo
local GetItemIcon = GetItemIcon
local GetItemInfo = GetItemInfo
local GetItemQualityColor = GetItemQualityColor
local GetMoney = GetMoney
local GetNumBankSlots = GetNumBankSlots
local GetRealmName = GetRealmName
local IsAddOnLoaded = IsAddOnLoaded
local IsBattlePayItem = IsBattlePayItem
local IsControlKeyDown, IsShiftKeyDown = IsControlKeyDown, IsShiftKeyDown
local IsInventoryItemLocked = IsInventoryItemLocked
local IsInventoryItemProfessionBag = IsInventoryItemProfessionBag
local MoneyFrame_Update = MoneyFrame_Update
local PickupBagFromSlot = PickupBagFromSlot
local PlaySound = PlaySound
local PutItemInBackpack = PutItemInBackpack
local PutItemInBag = PutItemInBag
local SetItemButtonCount = SetItemButtonCount
local SetItemButtonDesaturated = SetItemButtonDesaturated
local SetItemButtonNormalTextureVertexColor = SetItemButtonNormalTextureVertexColor
local SetItemButtonTexture = SetItemButtonTexture
local SetItemButtonTextureVertexColor = SetItemButtonTextureVertexColor
local SetMoneyFrameColor = SetMoneyFrameColor
local SetTooltipMoney = SetTooltipMoney
local ShowInspectCursor = ShowInspectCursor
local SortBags = SortBags
local StaticPopup_Show = StaticPopup_Show
local UnitName = UnitName
--Global variables that we don't cache, list them here for the mikk's Find Globals script
-- GLOBALS: StaticPopupDialogs, UIParent, UISpecialFrames, UIDropDownMenu_SetSelectedValue, ContainerFrameItemButton_OnLoad
-- GLOBALS: BankFrameItemButtonGeneric_OnClick, ContainerFrameItemButton_OnClick, ContainerFrameItemButton_OnEnter
if not LibStub then if not LibStub then
error(MBC .. " requires LibStub.") error(MBC .. " requires LibStub.")
@ -33,17 +90,13 @@ local MYBAGS_HERBCOLOR = { 0.0, 0.6, 0.0 }
local MYBAGS_GEMCOLOR = { 0.0, 0.6, 0.6 } local MYBAGS_GEMCOLOR = { 0.0, 0.6, 0.6 }
local MYBAGS_MININGCOLOR = { 0.0, 0.0, 0.6 } local MYBAGS_MININGCOLOR = { 0.0, 0.0, 0.6 }
local ACEG_MAP_ONOFF = {[0]="|cffff5050Off|r",[1]="|cff00ff00On|r"} local ACEG_MAP_ONOFF = {
[0] = "|cffff5050Off|r",
[1] = "|cff00ff00On|r"
}
local L = LibStub("AceLocale-3.0"):GetLocale("MyBags") local L = LibStub("AceLocale-3.0"):GetLocale("MyBags")
local pairs, unpack = pairs, unpack
local strfind, strlen, strsub, strlower, strgmatch, strupper = string.find, string.len, string.sub, string.lower, string.gmatch, string.upper
local strtrim = strtrim
local tinsert, tremove = table.insert, table.remove
local tostring, tonumber, select = tostring, tonumber, select
local CreateFrame = _G.CreateFrame
local mb_options = { local mb_options = {
type = "group", type = "group",
args = { args = {
@ -71,9 +124,10 @@ local function ColorConvertHexToDigit(h)
e = 14, e = 14,
f = 15 f = 15
} }
return ((tonumber(strsub(h,1,1)) or r[strsub(h,1,1)] or 0) * 16 + (tonumber(strsub(h,2,2)) or r[strsub(h,2,2)] or 0))/255,
((tonumber(strsub(h,3,3)) or r[strsub(h,3,3)] or 0) * 16 + (tonumber(strsub(h,4,4)) or r[strsub(h,4,4)] or 0))/255, return ((tonum(strsub(h, 1, 1)) or r[strsub(h, 1, 1)] or 0) * 16 + (tonum(strsub(h, 2, 2)) or r[strsub(h, 2, 2)] or 0)) / 255,
((tonumber(strsub(h,5,5)) or r[strsub(h,5,5)] or 0) * 16 + (tonumber(strsub(h,6,6)) or r[strsub(h,6,6)] or 0))/255 ((tonum(strsub(h, 3, 3)) or r[strsub(h, 3, 3)] or 0) * 16 + (tonum(strsub(h, 4, 4)) or r[strsub(h, 4, 4)] or 0)) / 255,
((tonum(strsub(h, 5, 5)) or r[strsub(h, 5, 5)] or 0) * 16 + (tonum(strsub(h, 6, 6)) or r[strsub(h, 6, 6)] or 0)) / 255
end end
local function GetItemInfoFromLink(l) local function GetItemInfoFromLink(l)
@ -382,12 +436,10 @@ end
function MyBagsCore:CanSaveItems() function MyBagsCore:CanSaveItems()
local live = self:IsLive() local live = self:IsLive()
self.isLive = false
if self:GetInfoFunc() ~= self.GetInfoNone then
self.isLive = live self.isLive = live
if self:GetInfoFunc() ~= self.GetInfoNone then
return true return true
else else
self.isLive = live
return false return false
end end
end end
@ -520,6 +572,7 @@ function MyBagsCore:IncludeBag(bag)
if self.db.profiles[prof][bs] and self.db.profiles[prof][bs]["Exclude"] then if self.db.profiles[prof][bs] and self.db.profiles[prof][bs]["Exclude"] then
return false return false
end end
return true return true
end end
end end
@ -546,6 +599,7 @@ function MyBagsCore:GetCash()
local char_key = DS:GetCharacter(player, realm) local char_key = DS:GetCharacter(player, realm)
return DS:GetMoney(char_key) return DS:GetMoney(char_key)
end end
return nil return nil
end end
@ -568,9 +622,11 @@ function MyBagsCore:SplitString(s, p, n)
tinsert(l, s) tinsert(l, s)
break break
end end
if (n) then if (n) then
n = n - 1 n = n - 1
end end
if (n and (n == 0)) then if (n and (n == 0)) then
tinsert(l, s) tinsert(l, s)
break break
@ -613,23 +669,20 @@ function MyBagsCore:GetInfoLive(bag, slot)
local charName = strtrim(UnitName("player")) local charName = strtrim(UnitName("player"))
local realmName = strtrim(GetRealmName()) local realmName = strtrim(GetRealmName())
self.Player = charName .. L["CHARACTER_DELIMITOR"] .. realmName self.Player = charName .. L["CHARACTER_DELIMITOR"] .. realmName
local texture, count, ID, locked, quality, readable, name, i_type, _
if slot ~= nil then if slot ~= nil then
-- it's an item -- it's an item
local texture, count, locked, _ , readable = GetContainerItemInfo(bag, slot) texture, count, locked, _, readable = GetContainerItemInfo(bag, slot)
local itemLink = GetContainerItemLink(bag, slot) local itemLink = GetContainerItemLink(bag, slot)
local name, quality, _, ID, i_type
if itemLink then if itemLink then
name, quality, _, ID, i_type = GetItemInfoFromLink(itemLink) name, quality, _, ID, i_type = GetItemInfoFromLink(itemLink)
end end
count = tonum(count)
return texture, count, ID, locked, quality, readable, name or nil, i_type
else else
-- it's a bag -- it's a bag
local count = GetContainerNumSlots(bag) i_type = "bag"
count = GetContainerNumSlots(bag)
local itemLink
local inventoryID = self:BagIDToInvSlotID(bag) local inventoryID = self:BagIDToInvSlotID(bag)
local texture, itemLink, locked, readable
local name, quality, _, ID
if inventoryID then if inventoryID then
texture = GetInventoryItemTexture("player", inventoryID) texture = GetInventoryItemTexture("player", inventoryID)
itemLink = GetInventoryItemLink("player", inventoryID) itemLink = GetInventoryItemLink("player", inventoryID)
@ -645,18 +698,17 @@ function MyBagsCore:GetInfoLive(bag, slot)
texture = "Interface\\Buttons\\Button-Backpack-Up" texture = "Interface\\Buttons\\Button-Backpack-Up"
count = 16 count = 16
end end
end
count = tonum(count) count = tonum(count)
return texture, count, ID, locked, quality, readable, name or nil, "bag" return texture, count, ID, locked, quality, readable, name or nil, i_type
end
end end
function MyBagsCore:GetInfoDataStore(bag, slot) function MyBagsCore:GetInfoDataStore(bag, slot)
local DS = DataStore local DS = DataStore
local player, realm = self:SplitString(self:GetCurrentPlayer(), L["CHARACTER_DELIMITOR"]) local player, realm = self:SplitString(self:GetCurrentPlayer(), L["CHARACTER_DELIMITOR"])
local char_key = DS:GetCharacter(player, realm) local char_key = DS:GetCharacter(player, realm)
local readable local texture, count, ID, quality, readable, name, i_type, _
local quality
if self.isEquipment then if self.isEquipment then
-- texture, count, id, locked, quality, _, name = GetInfo(item) -- texture, count, id, locked, quality, _, name = GetInfo(item)
@ -673,18 +725,18 @@ function MyBagsCore:GetInfoDataStore(bag, slot)
if bag == -1 then if bag == -1 then
bag = 100 bag = 100
end end
local container = DS:GetContainer(char_key, bag) local container = DS:GetContainer(char_key, bag)
if not slot then if not slot then
local texture, ID, count, _, _ = DS:GetContainerInfo(char_key, bag) i_type = "bag"
local name texture, ID, count, _, _ = DS:GetContainerInfo(char_key, bag)
if ID then if ID then
name = GetItemInfo(ID) name = GetItemInfo(ID)
readable = IsSpecialtyBagFromID(ID) readable = IsSpecialtyBagFromID(ID)
end end
return texture, count, ID, nil, nil, readable, name
else else
local ID, slotLink, count = DS:GetSlotInfo(container, slot) local slotLink, itemLink
local name, itemLink, texture, i_type ID, slotLink, count = DS:GetSlotInfo(container, slot)
if ID then if ID then
name, itemLink = GetItemInfo(ID) name, itemLink = GetItemInfo(ID)
texture = GetItemIcon(ID) texture = GetItemIcon(ID)
@ -692,11 +744,14 @@ function MyBagsCore:GetInfoDataStore(bag, slot)
quality, i_type = select(3, strfind(itemLink, "|cff(%x+)|H(%l+):.*|h|r")) quality, i_type = select(3, strfind(itemLink, "|cff(%x+)|H(%l+):.*|h|r"))
end end
end end
if slotLink then if slotLink then
ID = slotLink ID = slotLink
end end
return texture, count, ID, nil, quality, readable, name, i_type
end end
count = tonum(count)
return texture, count, ID, nil, quality or nil, readable, name, i_type
end end
end end
@ -755,6 +810,7 @@ function MyBagsCore:ItemButton_OnLeave(widget)
if bagButton then if bagButton then
bagButton:UnlockHighlight() bagButton:UnlockHighlight()
end end
CursorUpdate(widget) CursorUpdate(widget)
end end
@ -828,6 +884,7 @@ function MyBagsCore:ItemButton_OnEnter(widget)
if (BattlePetTooltip) then if (BattlePetTooltip) then
BattlePetTooltip:Hide() BattlePetTooltip:Hide()
end end
ContainerFrameItemButton_OnEnter(widget) ContainerFrameItemButton_OnEnter(widget)
end end
end end
@ -836,7 +893,9 @@ function MyBagsCore:ItemButton_OnEnter(widget)
local i_type = select(8, self:GetInfo(widget:GetParent():GetID(), widget:GetID() - 1000)) local i_type = select(8, self:GetInfo(widget:GetParent():GetID(), widget:GetID() - 1000))
if ID and i_type ~= "battlepet" then if ID and i_type ~= "battlepet" then
local hyperlink = self:GetHyperlink(ID) local hyperlink = self:GetHyperlink(ID)
if hyperlink then GameTooltip:SetHyperlink(hyperlink) end if hyperlink then
GameTooltip:SetHyperlink(hyperlink)
end
end end
end end
@ -905,6 +964,7 @@ function MyBagsCore:BagButton_OnEnter(widget)
else else
SetMoneyFrameColor("GameTooltipMoneyFrame", 1.0, 0.1, 0.1) SetMoneyFrameColor("GameTooltipMoneyFrame", 1.0, 0.1, 0.1)
end end
GameTooltip:Show() GameTooltip:Show()
end end
else else
@ -959,6 +1019,7 @@ function MyBagsCore:BagButton_OnClick(widget, button, ignoreShift)
if not StaticPopupDialogs["PURCHASE_BANKBAG"] then if not StaticPopupDialogs["PURCHASE_BANKBAG"] then
return return
end end
StaticPopup_Show("PURCHASE_BANKBAG") StaticPopup_Show("PURCHASE_BANKBAG")
end end
@ -980,8 +1041,10 @@ function MyBagsCore:BagButton_OnClick(widget, button, ignoreShift)
if not self.db.profiles[prof][bg] then if not self.db.profiles[prof][bg] then
self.db.profiles[prof][bg] = {} self.db.profiles[prof][bg] = {}
end end
self.db.profiles[prof][bg]["Exclude"] = true self.db.profiles[prof][bg]["Exclude"] = true
end end
self.hooks.CloseBag(bgnum) self.hooks.CloseBag(bgnum)
self:LayoutFrame() self:LayoutFrame()
end end
@ -1011,6 +1074,7 @@ function MyBagsCore:BagButton_OnReceiveDrag(widget)
else else
hadItem = PutItemInBag(invID) hadItem = PutItemInBag(invID)
end end
if not hadItem then if not hadItem then
if not self:IncludeBag(bagFrame:GetID()) then if not self:IncludeBag(bagFrame:GetID()) then
self.hooks.ToggleBag(bagFrame:GetID()) self.hooks.ToggleBag(bagFrame:GetID())
@ -1073,6 +1137,7 @@ function MyBagsCore:LayoutOptions()
else else
watchButton.count:SetText("*") watchButton.count:SetText("*")
end end
watchButton.currencyID = currencyID watchButton.currencyID = currencyID
watchButton:Show() watchButton:Show()
BackpackTokenFrame.shouldShow = 1 BackpackTokenFrame.shouldShow = 1
@ -1084,6 +1149,7 @@ function MyBagsCore:LayoutOptions()
end end
end end
end end
token:Show() token:Show()
else else
token:Hide() token:Hide()
@ -1107,6 +1173,7 @@ function MyBagsCore:LayoutOptions()
else else
playerSelectFrame:Hide() playerSelectFrame:Hide()
end end
playerSelectFrame:ClearAllPoints() playerSelectFrame:ClearAllPoints()
if self.GetOpt("Graphics") == "art" then if self.GetOpt("Graphics") == "art" then
@ -1155,6 +1222,7 @@ function MyBagsCore:LayoutOptions()
else else
slots:Hide() slots:Hide()
end end
if self.GetOpt("Reverse") then if self.GetOpt("Reverse") then
self.reverseOrder = true self.reverseOrder = true
else else
@ -1165,11 +1233,19 @@ function MyBagsCore:LayoutOptions()
if self.GetOpt("AIOI") then if self.GetOpt("AIOI") then
self.aioiOrder = true self.aioiOrder = true
local columns = self.GetOpt("Columns") local columns = self.GetOpt("Columns")
if not (self.isEquipment) and self.GetOpt("Bag") == "before" then displaySlots = displaySlots + self.totalBags end if not (self.isEquipment) and self.GetOpt("Bag") == "before" then
displaySlots = displaySlots + self.totalBags
end
columns = tonum(columns) columns = tonum(columns)
if self.isEquipment then displaySlots = 20 end if self.isEquipment then
displaySlots = 20
end
self.curCol = columns - (mod(displaySlots, columns)) self.curCol = columns - (mod(displaySlots, columns))
if self.curCol == columns then self.curCol = 0 end if self.curCol == columns then
self.curCol = 0
end
else else
self.aioiOrder = false self.aioiOrder = false
end end
@ -1391,7 +1467,7 @@ function MyBagsCore:LayoutBagFrame(bagFrame)
local newItemTexture = _G[itemBase .. slot].NewItemTexture local newItemTexture = _G[itemBase .. slot].NewItemTexture
local flash = _G[itemBase .. slot].flashAnim local flash = _G[itemBase .. slot].flashAnim
local newItemAnim = _G[itemBase .. slot].newitemglowAnim local newItemAnim = _G[itemBase .. slot].newitemglowAnim
local isNewItem = C_NewItems.IsNewItem(bagFrame:GetID(), itemButton:GetID()) local isNewItem = NewItemsIsNewItem(bagFrame:GetID(), itemButton:GetID())
local isBattlePayItem = IsBattlePayItem(bagFrame:GetID(), itemButton:GetID()) local isBattlePayItem = IsBattlePayItem(bagFrame:GetID(), itemButton:GetID())
local battlepayItemTexture = _G[itemBase .. slot].BattlepayItemTexture local battlepayItemTexture = _G[itemBase .. slot].BattlepayItemTexture
@ -1407,6 +1483,7 @@ function MyBagsCore:LayoutBagFrame(bagFrame)
else else
newItemTexture:SetAtlas("bags-glow-white") newItemTexture:SetAtlas("bags-glow-white")
end end
battlepayItemTexture:Hide() battlepayItemTexture:Hide()
newItemTexture:Show() newItemTexture:Show()
end end
@ -1572,7 +1649,6 @@ end
function MyBagsCore:SetColumns(cols) function MyBagsCore:SetColumns(cols)
cols = floor(tonum(cols)) cols = floor(tonum(cols))
self.SetOpt("Columns", cols) self.SetOpt("Columns", cols)
self:LayoutFrame() self:LayoutFrame()
end end
@ -1791,7 +1867,7 @@ function MyBagsCore:SetAnchor(point)
self.SetOpt("Anchor", point) self.SetOpt("Anchor", point)
self.Result("Anchor", point) self.Result("Anchor", point)
self.anchorPoint = strupper(point) self.anchorPoint = strupper(point)
return TRUE return true
end end
function MyBagsCore:SetCompanion() function MyBagsCore:SetCompanion()