- 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_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
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_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 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 = {
type = "group",
args = {
@ -71,9 +124,10 @@ local function ColorConvertHexToDigit(h)
e = 14,
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,
((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
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,
((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
local function GetItemInfoFromLink(l)
@ -382,12 +436,10 @@ end
function MyBagsCore:CanSaveItems()
local live = self:IsLive()
self.isLive = false
if self:GetInfoFunc() ~= self.GetInfoNone then
self.isLive = live
if self:GetInfoFunc() ~= self.GetInfoNone then
return true
else
self.isLive = live
return false
end
end
@ -423,7 +475,7 @@ function MyBagsCore:TooltipSetOwner(owner, anchor)
end
local parent = owner:GetParent()
if parent and (parent == self.frame or parent:GetParent() == self.frame ) then
if parent and (parent == self.frame or parent:GetParent() == self.frame) then
local point = self.GetOpt("Anchor") or "bottomright"
if point == "topleft" or point == "bottomleft" then
anchor = "ANCHOR_RIGHT"
@ -520,6 +572,7 @@ function MyBagsCore:IncludeBag(bag)
if self.db.profiles[prof][bs] and self.db.profiles[prof][bs]["Exclude"] then
return false
end
return true
end
end
@ -546,6 +599,7 @@ function MyBagsCore:GetCash()
local char_key = DS:GetCharacter(player, realm)
return DS:GetMoney(char_key)
end
return nil
end
@ -568,9 +622,11 @@ function MyBagsCore:SplitString(s, p, n)
tinsert(l, s)
break
end
if (n) then
n = n - 1
end
if (n and (n == 0)) then
tinsert(l, s)
break
@ -613,23 +669,20 @@ function MyBagsCore:GetInfoLive(bag, slot)
local charName = strtrim(UnitName("player"))
local realmName = strtrim(GetRealmName())
self.Player = charName .. L["CHARACTER_DELIMITOR"] .. realmName
local texture, count, ID, locked, quality, readable, name, i_type, _
if slot ~= nil then
-- 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 name, quality, _, ID, i_type
if itemLink then
name, quality, _, ID, i_type = GetItemInfoFromLink(itemLink)
end
count = tonum(count)
return texture, count, ID, locked, quality, readable, name or nil, i_type
else
-- it's a bag
local count = GetContainerNumSlots(bag)
i_type = "bag"
count = GetContainerNumSlots(bag)
local itemLink
local inventoryID = self:BagIDToInvSlotID(bag)
local texture, itemLink, locked, readable
local name, quality, _, ID
if inventoryID then
texture = GetInventoryItemTexture("player", inventoryID)
itemLink = GetInventoryItemLink("player", inventoryID)
@ -645,18 +698,17 @@ function MyBagsCore:GetInfoLive(bag, slot)
texture = "Interface\\Buttons\\Button-Backpack-Up"
count = 16
end
end
count = tonum(count)
return texture, count, ID, locked, quality, readable, name or nil, "bag"
end
return texture, count, ID, locked, quality, readable, name or nil, i_type
end
function MyBagsCore:GetInfoDataStore(bag, slot)
local DS = DataStore
local player, realm = self:SplitString(self:GetCurrentPlayer(), L["CHARACTER_DELIMITOR"])
local char_key = DS:GetCharacter(player, realm)
local readable
local quality
local texture, count, ID, quality, readable, name, i_type, _
if self.isEquipment then
-- texture, count, id, locked, quality, _, name = GetInfo(item)
@ -673,18 +725,18 @@ function MyBagsCore:GetInfoDataStore(bag, slot)
if bag == -1 then
bag = 100
end
local container = DS:GetContainer(char_key, bag)
if not slot then
local texture, ID, count, _, _ = DS:GetContainerInfo(char_key, bag)
local name
i_type = "bag"
texture, ID, count, _, _ = DS:GetContainerInfo(char_key, bag)
if ID then
name = GetItemInfo(ID)
readable = IsSpecialtyBagFromID(ID)
end
return texture, count, ID, nil, nil, readable, name
else
local ID, slotLink, count = DS:GetSlotInfo(container, slot)
local name, itemLink, texture, i_type
local slotLink, itemLink
ID, slotLink, count = DS:GetSlotInfo(container, slot)
if ID then
name, itemLink = GetItemInfo(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"))
end
end
if slotLink then
ID = slotLink
end
return texture, count, ID, nil, quality, readable, name, i_type
end
count = tonum(count)
return texture, count, ID, nil, quality or nil, readable, name, i_type
end
end
@ -744,7 +799,7 @@ end
--ITEMBUTTONS--
function MyBagsCore:ItemButton_OnLoad(widget)
_G[widget:GetName().."NormalTexture"]:SetTexture("Interface\\AddOns\\MyBags\\Skin\\Button")
_G[widget:GetName() .. "NormalTexture"]:SetTexture("Interface\\AddOns\\MyBags\\Skin\\Button")
ContainerFrameItemButton_OnLoad(widget)
widget.UpdateTooltip = widget.ItemButton_OnEnter
end
@ -755,6 +810,7 @@ function MyBagsCore:ItemButton_OnLeave(widget)
if bagButton then
bagButton:UnlockHighlight()
end
CursorUpdate(widget)
end
@ -828,6 +884,7 @@ function MyBagsCore:ItemButton_OnEnter(widget)
if (BattlePetTooltip) then
BattlePetTooltip:Hide()
end
ContainerFrameItemButton_OnEnter(widget)
end
end
@ -836,7 +893,9 @@ function MyBagsCore:ItemButton_OnEnter(widget)
local i_type = select(8, self:GetInfo(widget:GetParent():GetID(), widget:GetID() - 1000))
if ID and i_type ~= "battlepet" then
local hyperlink = self:GetHyperlink(ID)
if hyperlink then GameTooltip:SetHyperlink(hyperlink) end
if hyperlink then
GameTooltip:SetHyperlink(hyperlink)
end
end
end
@ -905,6 +964,7 @@ function MyBagsCore:BagButton_OnEnter(widget)
else
SetMoneyFrameColor("GameTooltipMoneyFrame", 1.0, 0.1, 0.1)
end
GameTooltip:Show()
end
else
@ -959,6 +1019,7 @@ function MyBagsCore:BagButton_OnClick(widget, button, ignoreShift)
if not StaticPopupDialogs["PURCHASE_BANKBAG"] then
return
end
StaticPopup_Show("PURCHASE_BANKBAG")
end
@ -980,8 +1041,10 @@ function MyBagsCore:BagButton_OnClick(widget, button, ignoreShift)
if not self.db.profiles[prof][bg] then
self.db.profiles[prof][bg] = {}
end
self.db.profiles[prof][bg]["Exclude"] = true
end
self.hooks.CloseBag(bgnum)
self:LayoutFrame()
end
@ -1011,6 +1074,7 @@ function MyBagsCore:BagButton_OnReceiveDrag(widget)
else
hadItem = PutItemInBag(invID)
end
if not hadItem then
if not self:IncludeBag(bagFrame:GetID()) then
self.hooks.ToggleBag(bagFrame:GetID())
@ -1065,25 +1129,27 @@ function MyBagsCore:LayoutOptions()
for i = 1, MAX_WATCHED_TOKENS do
local name, count, icon, currencyID = GetBackpackCurrencyInfo(i)
-- Update watched tokens
local watchButton = _G[self.frameName .. "TokenFrameToken"..i]
if ( name ) then
local watchButton = _G[self.frameName .. "TokenFrameToken" .. i]
if (name) then
watchButton.icon:SetTexture(icon)
if ( count <= 99999 ) then
if (count <= 99999) then
watchButton.count:SetText(count)
else
watchButton.count:SetText("*")
end
watchButton.currencyID = currencyID
watchButton:Show()
BackpackTokenFrame.shouldShow = 1
BackpackTokenFrame.numWatchedTokens = i
else
watchButton:Hide()
if ( i == 1 ) then
if (i == 1) then
BackpackTokenFrame.shouldShow = nil
end
end
end
token:Show()
else
token:Hide()
@ -1107,6 +1173,7 @@ function MyBagsCore:LayoutOptions()
else
playerSelectFrame:Hide()
end
playerSelectFrame:ClearAllPoints()
if self.GetOpt("Graphics") == "art" then
@ -1127,7 +1194,7 @@ function MyBagsCore:LayoutOptions()
end
if (self.frame.isBank) then
MYBAGS_BOTTOMOFFSET = MYBAGS_BOTTOMOFFSET+20
MYBAGS_BOTTOMOFFSET = MYBAGS_BOTTOMOFFSET + 20
cash:ClearAllPoints()
cash:SetPoint("BOTTOMRIGHT", self.frameName, "BOTTOMRIGHT", 0, 25)
end
@ -1155,6 +1222,7 @@ function MyBagsCore:LayoutOptions()
else
slots:Hide()
end
if self.GetOpt("Reverse") then
self.reverseOrder = true
else
@ -1165,11 +1233,19 @@ function MyBagsCore:LayoutOptions()
if self.GetOpt("AIOI") then
self.aioiOrder = true
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)
if self.isEquipment then displaySlots = 20 end
self.curCol = columns - (mod(displaySlots, columns) )
if self.curCol == columns then self.curCol = 0 end
if self.isEquipment then
displaySlots = 20
end
self.curCol = columns - (mod(displaySlots, columns))
if self.curCol == columns then
self.curCol = 0
end
else
self.aioiOrder = false
end
@ -1391,7 +1467,7 @@ function MyBagsCore:LayoutBagFrame(bagFrame)
local newItemTexture = _G[itemBase .. slot].NewItemTexture
local flash = _G[itemBase .. slot].flashAnim
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 battlepayItemTexture = _G[itemBase .. slot].BattlepayItemTexture
@ -1407,6 +1483,7 @@ function MyBagsCore:LayoutBagFrame(bagFrame)
else
newItemTexture:SetAtlas("bags-glow-white")
end
battlepayItemTexture:Hide()
newItemTexture:Show()
end
@ -1572,7 +1649,6 @@ end
function MyBagsCore:SetColumns(cols)
cols = floor(tonum(cols))
self.SetOpt("Columns", cols)
self:LayoutFrame()
end
@ -1791,7 +1867,7 @@ function MyBagsCore:SetAnchor(point)
self.SetOpt("Anchor", point)
self.Result("Anchor", point)
self.anchorPoint = strupper(point)
return TRUE
return true
end
function MyBagsCore:SetCompanion()
@ -1944,7 +2020,7 @@ local mixins = {
"GetCoreVersion",
}
function MyBagsCore:Embed( target )
function MyBagsCore:Embed(target)
for k, v in pairs(mixins) do
target[v] = self[v]
end