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

View File

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

View File

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

View File

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