From 36a115fcb068a38cacfa68683ec04a041bd0091c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?tekkub=20=CA=95=20=C2=B4=E1=B4=A5=60=20=CA=94?= Date: Sun, 11 Sep 2016 20:21:48 -0600 Subject: [PATCH] Simplify show/hide a bit --- Init.lua | 20 ++++++-------------- frames/MainFrame.lua | 13 +++++++++---- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/Init.lua b/Init.lua index ecc09f3..8806dc5 100644 --- a/Init.lua +++ b/Init.lua @@ -24,7 +24,7 @@ function ns.OnLoad() local GVS = ns.NewMainFrame() GVS:SetWidth(315) GVS:SetHeight(294) - GVS:SetPoint("TOPLEFT", 8, -67) + GVS:SetPoint("TOPLEFT", MerchantFrame, 8, -67) GVS:Hide() @@ -33,20 +33,12 @@ function ns.OnLoad() MerchantBuyBackItem:SetPoint("BOTTOMRIGHT", -7, 33) - local function Show() - for i=1,12 do _G["MerchantItem"..i]:Hide() end - if GVS:IsShown() then GVS:GetScript("OnShow")(GVS, true) else GVS:Show() end + hooksecurefunc("SetMerchantFilter", function() GVS:GetScript("OnShow")(GVS) end) + + + if MerchantFrame:IsVisible() and MerchantFrame.selectedTab == 1 then + GVS:Show() end - hooksecurefunc("MerchantFrame_UpdateMerchantInfo", Show) - - - hooksecurefunc("MerchantFrame_UpdateBuybackInfo", function() - GVS:Hide() - for i=1,12 do _G["MerchantItem"..i]:Show() end - end) - - - if MerchantFrame:IsVisible() and MerchantFrame.selectedTab == 1 then Show() end -- Clean up our frame factories diff --git a/frames/MainFrame.lua b/frames/MainFrame.lua index 7203535..07f0175 100644 --- a/frames/MainFrame.lua +++ b/frames/MainFrame.lua @@ -10,7 +10,7 @@ local NUMROWS = 14 function ns.NewMainFrame() - local GVS = CreateFrame("frame", nil, MerchantFrame) + local GVS = CreateFrame("frame", nil, MerchantBuyBackItem) local search = ns.MakeSearchField(GVS) @@ -62,17 +62,22 @@ function ns.NewMainFrame() end end) GVS:SetScript("OnEvent", Refresh) - GVS:SetScript("OnShow", function(self, noreset) + GVS:SetScript("OnShow", function(self) + for i=1,12 do _G["MerchantItem"..i]:Hide() end + local max = math.max(0, GetMerchantNumItems() - NUMROWS) scrollbar:SetMinMaxValues(0, max) - scrollbar:SetValue(noreset and math.min(scrollbar:GetValue(), max) or 0) + scrollbar:SetValue(0) Refresh() GVS:RegisterEvent("BAG_UPDATE") GVS:RegisterEvent("MERCHANT_UPDATE") GVS:RegisterEvent("CURRENCY_DISPLAY_UPDATE") end) - GVS:SetScript("OnHide", GVS.UnregisterAllEvents) + GVS:SetScript("OnHide", function(self) + for i=1,12 do _G["MerchantItem"..i]:Show() end + self:UnregisterAllEvents() + end) return GVS end