- Clear some leaked globals
- CS fixes
This commit is contained in:
@ -43,6 +43,24 @@ local MB_Core = LibStub("MyBagsCore-1.1")
|
|||||||
|
|
||||||
local L = LibStub("AceLocale-3.0"):GetLocale("MyBags")
|
local L = LibStub("AceLocale-3.0"):GetLocale("MyBags")
|
||||||
|
|
||||||
|
-- Lua APIs
|
||||||
|
local pairs = pairs
|
||||||
|
local strtrim = strtrim
|
||||||
|
|
||||||
|
-- WoW APIs
|
||||||
|
local _G = _G
|
||||||
|
local CloseBackpack = CloseBackpack
|
||||||
|
local IsBagOpen = IsBagOpen
|
||||||
|
local MoneyFrame_Update = MoneyFrame_Update
|
||||||
|
local OpenBackpack = OpenBackpack
|
||||||
|
local PlaySound = PlaySound
|
||||||
|
local SetPortraitTexture = SetPortraitTexture
|
||||||
|
local SortBankBags = SortBankBags
|
||||||
|
local ToggleBackpack = ToggleBackpack
|
||||||
|
|
||||||
|
--Global variables that we don't cache, list them here for the mikk's Find Globals script
|
||||||
|
-- GLOBALS:
|
||||||
|
|
||||||
function MyBank:OnInitialize()
|
function MyBank:OnInitialize()
|
||||||
self.name = "MyBank"
|
self.name = "MyBank"
|
||||||
self.frameName = "MyBankFrame"
|
self.frameName = "MyBankFrame"
|
||||||
@ -56,12 +74,13 @@ function MyBank:OnInitialize()
|
|||||||
self.anchorParent = "UIParent"
|
self.anchorParent = "UIParent"
|
||||||
self.anchorOffsetX = 5
|
self.anchorOffsetX = 5
|
||||||
self.anchorOffsetY = 100
|
self.anchorOffsetY = 100
|
||||||
self.db = LibStub("AceDB-3.0"):New("MyBankDB");
|
self.db = LibStub("AceDB-3.0"):New("MyBankDB")
|
||||||
local prof = self.db:GetCurrentProfile()
|
local prof = self.db:GetCurrentProfile()
|
||||||
if self.db.profiles[prof] and self.db.profiles[prof]["Columns"] and self.db.profiles[prof]["Columns"] > 0 then
|
if self.db.profiles[prof] and self.db.profiles[prof]["Columns"] and self.db.profiles[prof]["Columns"] > 0 then
|
||||||
else
|
else
|
||||||
self.db.profiles[prof] = self.defaults
|
self.db.profiles[prof] = self.defaults
|
||||||
end
|
end
|
||||||
|
|
||||||
self:RegisterChatCommand("mb", "MB_ChatCommand")
|
self:RegisterChatCommand("mb", "MB_ChatCommand")
|
||||||
self:RegisterChatCommand("mybank", "MB_ChatCommand")
|
self:RegisterChatCommand("mybank", "MB_ChatCommand")
|
||||||
self.options = {
|
self.options = {
|
||||||
@ -401,7 +420,7 @@ function MyBank:OnInitialize()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function MyBank:OnEnable()
|
function MyBank:OnEnable()
|
||||||
-- MyBagsCore:Enable(self);
|
-- MyBagsCore:Enable(self)
|
||||||
MyBankFrameBank.maxIndex = 28
|
MyBankFrameBank.maxIndex = 28
|
||||||
MyBankFrameBank:SetID(BANK_CONTAINER)
|
MyBankFrameBank:SetID(BANK_CONTAINER)
|
||||||
MyBankFrameBag0:SetID(5)
|
MyBankFrameBag0:SetID(5)
|
||||||
@ -443,9 +462,10 @@ function MyBank:OnEnable()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function MyBank:MB_ChatCommand(input)
|
function MyBank:MB_ChatCommand(input)
|
||||||
if not input or input:trim() == "" then
|
if not input or strtrim(input) == "" then
|
||||||
MB_Dialog:Open(self.name)
|
MB_Dialog:Open(self.name)
|
||||||
else
|
else
|
||||||
|
input = strtrim(input)
|
||||||
MB_Cmd.HandleCommand(MyBank, "mybank", self.name, input)
|
MB_Cmd.HandleCommand(MyBank, "mybank", self.name, input)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -459,7 +479,10 @@ end
|
|||||||
function MyBank:LoadDropDown()
|
function MyBank:LoadDropDown()
|
||||||
local dropDown = _G[self.frameName .. "CharSelectDropDown"]
|
local dropDown = _G[self.frameName .. "CharSelectDropDown"]
|
||||||
local dropDownButton = _G[self.frameName .. "CharSelectDropDownButton"]
|
local dropDownButton = _G[self.frameName .. "CharSelectDropDownButton"]
|
||||||
if not dropDown then return end
|
if not dropDown then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
local last_this = _G["this"]
|
local last_this = _G["this"]
|
||||||
_G["this"] = dropDownButton
|
_G["this"] = dropDownButton
|
||||||
UIDropDownMenu_Initialize(dropDown, self.UserDropDown_Initialize)
|
UIDropDownMenu_Initialize(dropDown, self.UserDropDown_Initialize)
|
||||||
@ -472,11 +495,12 @@ function MyBank:UserDropDown_Initialize()
|
|||||||
local this = self or _G.this
|
local this = self or _G.this
|
||||||
local chars, char_num
|
local chars, char_num
|
||||||
chars = MyBank:GetSortedCharList(MyBank.GetOpt("Sort"))
|
chars = MyBank:GetSortedCharList(MyBank.GetOpt("Sort"))
|
||||||
char_num = getn(chars)
|
char_num = #chars
|
||||||
if (char_num == 0) then
|
if (char_num == 0) then
|
||||||
MyBank.GetOpt("Player")
|
-- MyBank.GetOpt("Player")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local frame = this:GetParent():GetParent()
|
local frame = this:GetParent():GetParent()
|
||||||
local selectedValue = UIDropDownMenu_GetSelectedValue(this)
|
local selectedValue = UIDropDownMenu_GetSelectedValue(this)
|
||||||
|
|
||||||
@ -488,7 +512,10 @@ function MyBank:UserDropDown_Initialize()
|
|||||||
["owner"] = frame.self,
|
["owner"] = frame.self,
|
||||||
["checked"] = nil,
|
["checked"] = nil,
|
||||||
}
|
}
|
||||||
if selectedValue == info.value then info.checked = 1 end
|
if selectedValue == info.value then
|
||||||
|
info.checked = 1
|
||||||
|
end
|
||||||
|
|
||||||
UIDropDownMenu_AddButton(info)
|
UIDropDownMenu_AddButton(info)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -526,6 +553,7 @@ function MyBank:ToggleAllBags(forceopen)
|
|||||||
else
|
else
|
||||||
ToggleBackpack()
|
ToggleBackpack()
|
||||||
end
|
end
|
||||||
|
|
||||||
local action
|
local action
|
||||||
if (IsBagOpen(0) or MyInventory.frame:IsVisible()) then
|
if (IsBagOpen(0) or MyInventory.frame:IsVisible()) then
|
||||||
action = "OpenBag"
|
action = "OpenBag"
|
||||||
@ -547,15 +575,15 @@ function MyBank:ToggleAllBags(forceopen)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function MyBank:CloseAllBags()
|
function MyBank:CloseAllBags()
|
||||||
local i
|
|
||||||
MyInventory:Close()
|
MyInventory:Close()
|
||||||
CloseBackpack() -- just in case backpack is not contolled by MyInventory
|
CloseBackpack() -- just in case backpack is not contolled by MyInventory
|
||||||
for i=1, 4, 1 do
|
for i = 1, 4, 1 do
|
||||||
if not MyInventory.GetOpt("Replace") or not MyInventory:IncludeBag(i) then
|
if not MyInventory.GetOpt("Replace") or not MyInventory:IncludeBag(i) then
|
||||||
self.hooks.CloseBag(i)
|
self.hooks.CloseBag(i)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
for i=5, 11, 1 do
|
|
||||||
|
for i = 5, 11, 1 do
|
||||||
if not MyBank.GetOpt("Replace") or not MyBank:IncludeBag(i) then
|
if not MyBank.GetOpt("Replace") or not MyBank:IncludeBag(i) then
|
||||||
self.hooks.CloseBag(i)
|
self.hooks.CloseBag(i)
|
||||||
end
|
end
|
||||||
@ -577,6 +605,7 @@ function MyBank:BANKFRAME_OPENED()
|
|||||||
else
|
else
|
||||||
self.holdOpen = false
|
self.holdOpen = false
|
||||||
end
|
end
|
||||||
|
|
||||||
if self.GetOpt("Replace") then
|
if self.GetOpt("Replace") then
|
||||||
self:Open()
|
self:Open()
|
||||||
else
|
else
|
||||||
@ -593,8 +622,11 @@ function MyBank:BANKFRAME_CLOSED()
|
|||||||
end -- calling self:close() would trigger the bank closing twice
|
end -- calling self:close() would trigger the bank closing twice
|
||||||
else
|
else
|
||||||
self.holdOpen = false
|
self.holdOpen = false
|
||||||
if self.isLive then self:LayoutFrame() end
|
if self.isLive then
|
||||||
|
self:LayoutFrame()
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
self:UnregisterEvents()
|
self:UnregisterEvents()
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -602,6 +634,7 @@ function MyBank:GetInfoFunc()
|
|||||||
if self.isLive then
|
if self.isLive then
|
||||||
return self.GetInfoLive
|
return self.GetInfoLive
|
||||||
end
|
end
|
||||||
|
|
||||||
if IsAddOnLoaded("DataStore_Containers") then
|
if IsAddOnLoaded("DataStore_Containers") then
|
||||||
return self.GetInfoDataStore
|
return self.GetInfoDataStore
|
||||||
end
|
end
|
||||||
@ -610,6 +643,8 @@ function MyBank:GetInfoFunc()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function MyBank:GetSortedCharList(sorttype, realm)
|
function MyBank:GetSortedCharList(sorttype, realm)
|
||||||
|
local result = {}
|
||||||
|
|
||||||
if IsAddOnLoaded("DataStore_Containers") then
|
if IsAddOnLoaded("DataStore_Containers") then
|
||||||
local realmlist = {}
|
local realmlist = {}
|
||||||
local realmcount = 0
|
local realmcount = 0
|
||||||
@ -622,7 +657,7 @@ function MyBank:GetSortedCharList(sorttype, realm)
|
|||||||
realmcount = 1
|
realmcount = 1
|
||||||
realmlist[1] = realm
|
realmlist[1] = realm
|
||||||
end
|
end
|
||||||
local result = {}
|
|
||||||
local idx = 0
|
local idx = 0
|
||||||
for i = 1, realmcount do
|
for i = 1, realmcount do
|
||||||
for charname, charkey in pairs(DataStore:GetCharacters(realmlist[i])) do
|
for charname, charkey in pairs(DataStore:GetCharacters(realmlist[i])) do
|
||||||
@ -633,36 +668,40 @@ function MyBank:GetSortedCharList(sorttype, realm)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local swapped
|
local swapped
|
||||||
local q, w
|
local q, w
|
||||||
local x_time, y_time;
|
local x_time, y_time
|
||||||
local charName, realmName
|
local charName, realmName
|
||||||
repeat
|
repeat
|
||||||
swapped = 0
|
swapped = 0
|
||||||
for i = 1, idx-1 do
|
for i = 1, idx - 1 do
|
||||||
q = result[i]
|
q = result[i]
|
||||||
w = result[i+1]
|
w = result[i + 1]
|
||||||
charName, realmName = self:SplitString(q)
|
charName, realmName = self:SplitString(q)
|
||||||
if (not DataStore:GetModuleLastUpdate(DataStore_Containers, charName, realmName)) then
|
if (not DataStore:GetModuleLastUpdate(DataStore_Containers, charName, realmName)) then
|
||||||
x_time = 0
|
x_time = 0
|
||||||
else
|
else
|
||||||
x_time = DataStore:GetModuleLastUpdate(DataStore_Containers, charName, realmName)
|
x_time = DataStore:GetModuleLastUpdate(DataStore_Containers, charName, realmName)
|
||||||
end
|
end
|
||||||
|
|
||||||
charName, realmName = self:SplitString(w)
|
charName, realmName = self:SplitString(w)
|
||||||
if (not DataStore:GetModuleLastUpdate(DataStore_Containers, charName, realmName)) then
|
if (not DataStore:GetModuleLastUpdate(DataStore_Containers, charName, realmName)) then
|
||||||
y_time = 0
|
y_time = 0
|
||||||
else
|
else
|
||||||
y_time = DataStore:GetModuleLastUpdate(DataStore_Containers, charName, realmName)
|
y_time = DataStore:GetModuleLastUpdate(DataStore_Containers, charName, realmName)
|
||||||
end
|
end
|
||||||
|
|
||||||
if self:SortChars(q, w, x_time, y_time, sorttype) then
|
if self:SortChars(q, w, x_time, y_time, sorttype) then
|
||||||
result[i] = w
|
result[i] = w
|
||||||
result[i+1] = q
|
result[i + 1] = q
|
||||||
swapped = 1
|
swapped = 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
until swapped == 0
|
until swapped == 0
|
||||||
return result
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return result
|
||||||
end
|
end
|
||||||
|
|
||||||
function MyBank:SetReplace()
|
function MyBank:SetReplace()
|
||||||
|
|||||||
Reference in New Issue
Block a user