- Change event registration methods

- Add MyBank sorting
- Fix some tainting issue
This commit is contained in:
Sandor Takacs
2015-01-06 19:41:22 +01:00
parent 3e06a3a7ad
commit 25765b5f3c
4 changed files with 50 additions and 23 deletions

View File

@ -1,5 +1,5 @@
local MBC = "MyBagsCore-1.0"
local MBC_MINOR = "2015.01.05.3"
local MBC_MINOR = "2015.01.06.7"
if not LibStub then
error(MBC .. " requires LibStub.")
end
@ -18,8 +18,6 @@ local MYBAGS_BOTTOMOFFSET = 20
local MYBAGS_COLWIDTH = 40
local MYBAGS_ROWHEIGHT = 40
local MYBAGS_MAXBAGSLOTS = 28
local MIN_SCALE_VAL = "0.2"
local MAX_SCALE_VAL = "2.0"
@ -255,13 +253,12 @@ function MyBagsCore:OnEmbedInitialize(addon)
local charName = strtrim(UnitName("player"))
local realmName = strtrim(GetRealmName())
-- self.atBank = false
-- self.atBank = false
addon.Player = charName .. L["CHARACTER_DELIMITOR"] .. realmName
end
-- OnEnable
function MyBagsCore:OnEmbedEnable(addon)
addon:RegisterEvents()
addon:HookFunctions()
if addon.GetOpt("Scale") then
addon.frame:SetScale(addon.GetOpt("Scale"))
@ -300,6 +297,14 @@ function MyBagsCore:RegisterEvents(obj)
self:RegisterEvent("ITEM_LOCK_CHANGED", "LayoutFrameOnEvent")
end
function MyBagsCore:UnregisterEvents(obj)
if (obj) then
self = obj
end
self:UnregisterAllEvents()
end
function MyBagsCore:HookFunctions(obj)
if (obj) then
self = obj
@ -430,6 +435,7 @@ function MyBagsCore:TooltipSetOwner(owner, anchor)
end
function MyBagsCore:Open()
self:RegisterEvents()
if not self.frame:IsVisible() then
self.frame:Show()
end
@ -452,6 +458,8 @@ function MyBagsCore:Close()
if self.frame:IsVisible() then
self.frame:Hide()
end
self:UnregisterEvents()
end
function MyBagsCore:Toggle()
@ -768,7 +776,6 @@ function MyBagsCore:ItemButton_OnLeave(widget)
end
function MyBagsCore:ItemButton_OnClick(widget, button)
--[[
if self.isLive then
if widget.hasItem then
self.watchLock = 1
@ -780,7 +787,6 @@ function MyBagsCore:ItemButton_OnClick(widget, button)
ContainerFrameItemButton_OnClick(widget, button)
end
end
]]
end
function MyBagsCore:ItemButton_OnModifiedClick(widget, button)
@ -1568,7 +1574,7 @@ function MyBagsCore:LayoutFrameOnEvent(event, unit)
end
if event == "BAG_UPDATE_COOLDOWN" then
if unit == "player" and self.isLive then
if self.isLive then
self:LayoutFrame()
end
end
@ -1577,7 +1583,6 @@ end
function MyBagsCore:SortBags()
PlaySound("UI_BagSorting_01")
SortBags()
self:LayoutFrame()
end
function MyBagsCore:LockButton_OnClick()
@ -1771,14 +1776,10 @@ function MyBagsCore:ResetAnchor()
end
function MyBagsCore:SetAnchor(point)
if point == "topleft" then
elseif point == "topright" then
elseif point == "bottomleft" then
elseif point == "bottomright" then
else
if not (point == "topleft" or point == "topright" or point == "bottomleft" or point == "bottomright") then
self.Error("Invalid Entry for Anchor")
return
end
end
local anchorframe = self.frame:GetParent()
local top = self.frame:GetTop()
@ -1786,7 +1787,8 @@ function MyBagsCore:SetAnchor(point)
local top1 = anchorframe:GetTop()
local left1 = anchorframe:GetLeft()
if not top or not left or not left1 or not top1 then
self.Error("Frame must be open to set anchor") return
self.Error("Frame must be open to set anchor")
return
end
self.frame:ClearAllPoints()

View File

@ -2,7 +2,7 @@
xsi:schemaLocation="http://www.blizzard.com/wow/ui/FrameXML/UI.xsd">
<Script file="MyBags.lua"/>
<!-- Templates -->
<Button name="MyBagsItemButtonTemplate" inherits="ContainerFrameItemButtonTemplate" virtual="true">
<Button name="MyBagsItemButtonTemplate" inherits="ContainerFrameItemButtonTemplate" virtual="true" hidden="true">
<Frames>
<Cooldown name="$parentCooldown" inherits="CooldownFrameTemplate"/>
</Frames>

View File

@ -2,10 +2,11 @@ local MYBANK_DEFAULT_OPTIONS = {
["Columns"] = 14,
["Replace"] = true,
["Bag"] = "bar",
["BagSort"] = true,
["Graphics"] = "art",
["Count"] = "free",
["HlItems"] = true,
["Sort"] = "realm",
["Sort"] = "realm",
["Search"] = true,
["HlBags"] = true,
["Freeze"] = "sticky",
@ -136,6 +137,17 @@ function MyBank:OnInitialize()
MyBank:SetBagDisplay(val)
end,
},
bagsort = {
type = "toggle",
name = "BagSort",
desc = "Toggle bag sort button",
get = function(info)
return MyBank.IsSet("BagSort")
end,
set = function(info, val)
MyBank:SetBagSort()
end,
},
back = {
type = "select",
name = "Background",
@ -389,7 +401,7 @@ function MyBank:OnInitialize()
end
function MyBank:OnEnable()
-- MyBagsCore:Enable(self);
-- MyBagsCore:Enable(self);
MyBankFrameBank.maxIndex = 28
MyBankFrameBank:SetID(BANK_CONTAINER)
MyBankFrameBag0:SetID(5)
@ -403,8 +415,10 @@ function MyBank:OnEnable()
if self.GetOpt("Replace") then
BankFrame:UnregisterEvent("BANKFRAME_OPENED")
BankFrame:UnregisterEvent("BANKFRAME_CLOSED")
_G["BankFrame"] = self.frame
end
self:RegisterEvent("BANKFRAME_OPENED")
MyBankFramePortrait:SetTexture("Interface\\Addons\\MyBags\\Skin\\MyBankPortrait")
StaticPopupDialogs["PURCHASE_BANKBAG"] = {
preferredIndex = STATICPOPUPS_NUMDIALOGS,
@ -490,10 +504,14 @@ end
function MyBank:RegisterEvents()
MB_Core:RegisterEvents(self)
self:RegisterEvent("BANKFRAME_OPENED")
self:RegisterEvent("BANKFRAME_CLOSED")
self:RegisterEvent("PLAYERBANKSLOTS_CHANGED", "LayoutFrameOnEvent")
self:RegisterEvent("PLAYERBANKBAGSLOTS_CHANGED","LayoutFrameOnEvent")
self:RegisterEvent("BANKFRAME_CLOSED")
end
function MyBank:UnregisterEvents()
MB_Core:UnregisterEvents(self)
self:RegisterEvent("BANKFRAME_OPENED")
end
function MyBank:HookFunctions()
@ -549,6 +567,7 @@ function MyBank:BAG_UPDATE(event, bag)
end
function MyBank:BANKFRAME_OPENED()
self:RegisterEvents()
MyBank.atBank = true
SetPortraitTexture(MyBankFramePortrait, "npc")
if self.Freeze == "always" or (self.Freeze == "sticky" and self.frame:IsVisible()) then
@ -574,6 +593,7 @@ function MyBank:BANKFRAME_CLOSED()
self.holdOpen = false
if self.isLive then self:LayoutFrame() end
end
self:UnregisterEvents()
end
function MyBank:GetInfoFunc()
@ -703,3 +723,8 @@ function MyBank:SetReplace()
BankFrame:RegisterEvent("BANKFRAME_CLOSED")
end
end
function MyBank:SortBags()
PlaySound("UI_BagSorting_01")
SortBankBags()
end

View File

@ -446,7 +446,7 @@ function MyInventory:LoadDropDown()
_G["this"] = dropDownButton
UIDropDownMenu_Initialize(dropDown, self.UserDropDown_Initialize)
UIDropDownMenu_SetSelectedValue(dropDown, self:GetCurrentPlayer())
-- UIDropDownMenu_SetSelectedValue(dropDown, self.Player)
-- UIDropDownMenu_SetSelectedValue(dropDown, self.Player)
UIDropDownMenu_SetWidth(dropDown, 140)
_G["this"] = last_this
end