From 4d4003f697fb700f4f316a7e83e6ef430d9858fb Mon Sep 17 00:00:00 2001 From: kaelonR Date: Thu, 12 Sep 2024 22:13:21 +0200 Subject: [PATCH] add support for tabs added through SecureTabs-2.0, add support for Scrap --- BuyEmAll.toc | 2 + MerchantFrame/BuyEmAllFrame.lua | 2 +- MerchantFrame/glue.lua | 27 ++++- libs/LibStub/LibStub.lua | 30 ++++++ libs/SecureTabs-2.0/SecureTabs-2.0.lua | 135 +++++++++++++++++++++++++ libs/TaintLess/TaintLess.xml | 93 +++++++++++++++++ libs/main.xml | 5 + 7 files changed, 292 insertions(+), 2 deletions(-) create mode 100644 libs/LibStub/LibStub.lua create mode 100644 libs/SecureTabs-2.0/SecureTabs-2.0.lua create mode 100644 libs/TaintLess/TaintLess.xml create mode 100644 libs/main.xml diff --git a/BuyEmAll.toc b/BuyEmAll.toc index 17c67c3..208ad7a 100644 --- a/BuyEmAll.toc +++ b/BuyEmAll.toc @@ -11,6 +11,8 @@ ## X-WoWI-ID: 5217 ## X-Wago-ID: kRNLnQKo +libs/main.xml + init.lua localisation/index.xml diff --git a/MerchantFrame/BuyEmAllFrame.lua b/MerchantFrame/BuyEmAllFrame.lua index ffeb1db..51d0153 100644 --- a/MerchantFrame/BuyEmAllFrame.lua +++ b/MerchantFrame/BuyEmAllFrame.lua @@ -2,7 +2,7 @@ local MAX_MONEY_DISPLAY_WIDTH = 120; local function GetMerchantItemsPerPage() if(select(1, C_AddOns.IsAddOnLoaded("Krowi_ExtendedVendorUI"))) then - return MERCHANT_ITEMS_PER_PAGE; + return _G.MERCHANT_ITEMS_PER_PAGE; end return 10; diff --git a/MerchantFrame/glue.lua b/MerchantFrame/glue.lua index 095a05c..bb032c5 100644 --- a/MerchantFrame/glue.lua +++ b/MerchantFrame/glue.lua @@ -86,4 +86,29 @@ compatManager.SellJunk = compatManager.entry(function() sellButton:SetPoint(point, BuyEmAllFrame, relativePoint, offsetX, offsetY); end) -compatManager:init(); \ No newline at end of file +compatManager.Scrap = compatManager.entry(function() + hooksecurefunc('BuyEmAllFrame_MerchantShow', function() + local children = {MerchantBuyBackItem:GetChildren()} + for _, v in pairs(children) do + if v.AnyJunk ~= nil then + v:SetParent(BuyEmAllSellAllJunkButton) + v:ClearAllPoints(); + v:SetAllPoints(BuyEmAllSellAllJunkButton) + end + end + end) +end) + +compatManager:init(); + +local tabsCache = {}; + +hooksecurefunc('BuyEmAllFrame_MerchantShow', function() + local tabs = LibStub("SecureTabs-2.0").tabs[MerchantFrame]; + for _, tab in pairs(tabs) do + if(tabsCache[tab.frame] == nil) then + LibStub("SecureTabs-2.0"):Add(BuyEmAllFrame, tab.frame, tab:GetText()); + tabsCache[tab.frame] = true; + end + end +end) \ No newline at end of file diff --git a/libs/LibStub/LibStub.lua b/libs/LibStub/LibStub.lua new file mode 100644 index 0000000..725982d --- /dev/null +++ b/libs/LibStub/LibStub.lua @@ -0,0 +1,30 @@ +-- LibStub is a simple versioning stub meant for use in Libraries. http://www.wowace.com/wiki/LibStub for more info +-- LibStub is hereby placed in the Public Domain Credits: Kaelten, Cladhaire, ckknight, Mikk, Ammo, Nevcairiel, joshborke +local LIBSTUB_MAJOR, LIBSTUB_MINOR = "LibStub", 2 -- NEVER MAKE THIS AN SVN REVISION! IT NEEDS TO BE USABLE IN ALL REPOS! +local LibStub = _G[LIBSTUB_MAJOR] + +if not LibStub or LibStub.minor < LIBSTUB_MINOR then + LibStub = LibStub or {libs = {}, minors = {} } + _G[LIBSTUB_MAJOR] = LibStub + LibStub.minor = LIBSTUB_MINOR + + function LibStub:NewLibrary(major, minor) + assert(type(major) == "string", "Bad argument #2 to `NewLibrary' (string expected)") + minor = assert(tonumber(strmatch(minor, "%d+")), "Minor version must either be a number or contain a number.") + + local oldminor = self.minors[major] + if oldminor and oldminor >= minor then return nil end + self.minors[major], self.libs[major] = minor, self.libs[major] or {} + return self.libs[major], oldminor + end + + function LibStub:GetLibrary(major, silent) + if not self.libs[major] and not silent then + error(("Cannot find a library instance of %q."):format(tostring(major)), 2) + end + return self.libs[major], self.minors[major] + end + + function LibStub:IterateLibraries() return pairs(self.libs) end + setmetatable(LibStub, { __call = LibStub.GetLibrary }) +end diff --git a/libs/SecureTabs-2.0/SecureTabs-2.0.lua b/libs/SecureTabs-2.0/SecureTabs-2.0.lua new file mode 100644 index 0000000..f8b7e76 --- /dev/null +++ b/libs/SecureTabs-2.0/SecureTabs-2.0.lua @@ -0,0 +1,135 @@ +--[[ +Copyright 2013-2024 João Cardoso +SecureTabs is distributed under the terms of the GNU General Public License (or the Lesser GPL). +This file is part of SecureTabs. + +SecureTabs is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +SecureTabs is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with SecureTabs. If not, see . +--]] + +local Lib, old = LibStub:NewLibrary('SecureTabs-2.0', 10) +if not Lib then + return +elseif not old then + hooksecurefunc('PanelTemplates_SetTab', function(panel, id) + Lib:Update(panel) + end) +end + +Lib.tabs = Lib.tabs or {} +Lib.covers = Lib.covers or {} +Lib.template = WOW_PROJECT_ID == WOW_PROJECT_MAINLINE and 'PanelTabButtonTemplate' or 'CharacterFrameTabButtonTemplate' + + +--[[ Main API ]]-- + +function Lib:Add(panel, frame, label) + local secureTabs = self.tabs[panel] or {} + local id = #secureTabs + local anchor = id > 0 and 'SecureTab' .. (id-1) or 'Tab' .. panel.numTabs + + local tab = CreateFrame('Button', '$parentSecureTab' .. id, panel, self.template) + tab:SetPoint('LEFT', panel:GetName() .. anchor, 'RIGHT', WOW_PROJECT_ID == WOW_PROJECT_MAINLINE and 3 or -16, 0) + tab:SetScript('OnClick', function(tab) self:Select(tab) end) + tab:SetText(label) + tab.frame = frame + tinsert(secureTabs, tab) + PanelTemplates_DeselectTab(tab) + + local cover = self.covers[panel] or CreateFrame('Button', '$parentCoverTab', panel, self.template) + cover:SetScript('OnClick', function(tab) self:Uncover(panel) end) + PanelTemplates_DeselectTab(cover) + + self.tabs[panel] = secureTabs + self.covers[panel] = cover + + return tab +end + +function Lib:Select(tab) + if tab.OnSelect then + tab:OnSelect() + end + + PlaySound(SOUNDKIT.IG_CHARACTER_INFO_TAB) + self:Update(tab:GetParent(), tab) +end + + +--[[ Advanced Methods ]]-- + +function Lib:Uncover(panel) + PlaySound(SOUNDKIT.IG_CHARACTER_INFO_TAB) + self:Update(panel) +end + +function Lib:Update(panel, selection) + local secureTabs = self.tabs[panel] + if not secureTabs then + return + end + + for i, tab in ipairs(secureTabs) do + local selected = tab == selection + if selected then + PanelTemplates_SelectTab(tab) + else + PanelTemplates_DeselectTab(tab) + end + + local frame = tab.frame + if frame then + frame:SetShown(selected) + + if selected then + frame:SetParent(panel) + frame:EnableMouse(true) + frame:SetAllPoints(true) + frame:SetFrameLevel(panel:GetFrameLevel() + 20) + + if frame.CloseButton then + frame.CloseButton:SetScript('OnClick', function() + local original = frame:GetParent() and frame:GetParent().CloseButton + if original then + ExecuteFrameScript(original, 'OnClick') -- make sure any additional behaviour is replicated + end + + HideUIPanel(frame) -- safest hiding method + end) + end + end + end + end + + if panel.selectedTab then + local cover = self.covers[panel] + local tab = _G[panel:GetName() .. 'Tab'.. panel.selectedTab] + + local name = tab:GetName() + local left = tab.LeftActive or _G[name..'LeftDisabled'] + local middle = tab.MiddleActive or _G[name..'MiddleDisabled'] + local right = tab.RightActive or _G[name..'RightDisabled'] + + cover:SetShown(selection) + left:SetShown(not selection) + middle:SetShown(not selection) + right:SetShown(not selection) + + if selection then + cover:SetParent(tab) + cover:SetAllPoints(tab) + cover:SetText(tab:GetText()) + PanelTemplates_TabResize(cover, 0, nil, 36, panel.maxTabWidth or 88) + end + end +end diff --git a/libs/TaintLess/TaintLess.xml b/libs/TaintLess/TaintLess.xml new file mode 100644 index 0000000..2093df6 --- /dev/null +++ b/libs/TaintLess/TaintLess.xml @@ -0,0 +1,93 @@ + \ No newline at end of file diff --git a/libs/main.xml b/libs/main.xml new file mode 100644 index 0000000..3118e34 --- /dev/null +++ b/libs/main.xml @@ -0,0 +1,5 @@ + + +