From ec515b06f20d9a08eb629b45f793c17bede9dc0c Mon Sep 17 00:00:00 2001 From: Xruptor Date: Sat, 20 Aug 2016 19:16:09 -0400 Subject: [PATCH] Cross Realm Fix and More! -Fixed an issue where realms with spaces in their names would not be counted in the Cross-Realm Option. Sadly because of this issue, I've had to make adjustments to the database. Those users whom play on a server with a space in the name, will have to login to each toon individually. This is because I've removed all servers from the DB that have spaces in it. In the future they will be stored with whitespace removed as Blizzard uses in their code. I've made a small database to store the true server names that include spaces and symbols for display purposes only (like in the tooltip) SORRY! -I've cleaned up inconsistent coding throughout the entire addon. There where times I was using single quotes and then double quotes. It was annoying me lol. -The options panel code has been completely reworked from the ground up. You won't notice a change but it will be easy for me to add options in the future. -I've added color selection options for the tooltips! Hurray! Now you can change the color of the tooltips. -Moved all the libraries into individual folders instead of the way they used to be before. This is more common practice with addons anyways. Don't know what I was thinking back in the day. -Fixed a slight bug in LibSimpleOptions-1.0 as SetTexture has been changed to SetColorTexture -Added new localization for new color options in config. TODO: -Fix the profiles window to allow support for cross realms and BNET support. I may just make it global lol to solve that issue. -Fix the tokens window to support cross-realm and BNET support. -Rework the search frames and pretty much any frame that uses a scroll slider. The current way it's coded just annoys me LOL. --- BagSync.lua | 432 +++++---- BagSync.toc | 13 +- BagSync_Blacklist.lua | 4 +- BagSync_Config.lua | 532 +++++------ BagSync_Crafts.lua | 14 +- BagSync_Profiles.lua | 10 +- BagSync_Search.lua | 28 +- BagSync_Tokens.lua | 16 +- libs/CallbackHandler-1.0.lua | 239 ----- libs/CallbackHandler-1.0/CallbackHandler-1.0.lua | 238 +++++ libs/CallbackHandler-1.0/CallbackHandler-1.0.xml | 4 + libs/LibDataBroker-1.1.lua | 90 -- libs/LibDataBroker-1.1/LibDataBroker-1.1.lua | 90 ++ libs/LibDataBroker-1.1/README.textile | 13 + libs/LibItemSearch-1.0.lua | 480 ---------- libs/LibItemSearch-1.0/LibItemSearch-1.0.lua | 480 ++++++++++ .../Changelog-LibSimpleOptions-1.0-r46.txt | 15 + libs/LibSimpleOptions-1.0/LibSimpleOptions-1.0.lua | 957 ++++++++++++++++++++ libs/LibSimpleOptions-1.0/LibSimpleOptions-1.0.toc | 15 + libs/LibSimpleOptions-1.0/LibStub/LibStub.lua | 30 + libs/LibSimpleOptions-1.0/lib.xml | 4 + libs/LibStub.lua | 30 - libs/LibStub/LibStub.lua | 51 ++ libs/LibStub/LibStub.toc | 13 + libs/LibStub/tests/test.lua | 41 + libs/LibStub/tests/test2.lua | 27 + libs/LibStub/tests/test3.lua | 14 + libs/LibStub/tests/test4.lua | 41 + localization/localization.lua | 6 + 29 files changed, 2568 insertions(+), 1359 deletions(-) delete mode 100644 libs/CallbackHandler-1.0.lua create mode 100644 libs/CallbackHandler-1.0/CallbackHandler-1.0.lua create mode 100644 libs/CallbackHandler-1.0/CallbackHandler-1.0.xml delete mode 100644 libs/LibDataBroker-1.1.lua create mode 100644 libs/LibDataBroker-1.1/LibDataBroker-1.1.lua create mode 100644 libs/LibDataBroker-1.1/README.textile delete mode 100644 libs/LibItemSearch-1.0.lua create mode 100644 libs/LibItemSearch-1.0/LibItemSearch-1.0.lua create mode 100644 libs/LibSimpleOptions-1.0/Changelog-LibSimpleOptions-1.0-r46.txt create mode 100644 libs/LibSimpleOptions-1.0/LibSimpleOptions-1.0.lua create mode 100644 libs/LibSimpleOptions-1.0/LibSimpleOptions-1.0.toc create mode 100644 libs/LibSimpleOptions-1.0/LibStub/LibStub.lua create mode 100644 libs/LibSimpleOptions-1.0/lib.xml delete mode 100644 libs/LibStub.lua create mode 100644 libs/LibStub/LibStub.lua create mode 100644 libs/LibStub/LibStub.toc create mode 100644 libs/LibStub/tests/test.lua create mode 100644 libs/LibStub/tests/test2.lua create mode 100644 libs/LibStub/tests/test3.lua create mode 100644 libs/LibStub/tests/test4.lua diff --git a/BagSync.lua b/BagSync.lua index 5b5770e..70c8590 100644 --- a/BagSync.lua +++ b/BagSync.lua @@ -23,6 +23,7 @@ local BS_GD local BS_TD local BS_CD local BS_BL +local BS_RK local MAX_GUILDBANK_SLOTS_PER_TAB = 98 local doTokenUpdate = 0 local guildTabQueryQueue = {} @@ -31,11 +32,6 @@ local atVoidBank = false local atGuildBank = false local isCheckingMail = false -local SILVER = '|cffc7c7cf%s|r' -local MOSS = '|cFF80FF00%s|r' -local TTL_C = '|cFFF4A460%s|r' -local GN_C = '|cFF65B8C0%s|r' - local debugf = tekDebug and tekDebug:GetFrame("BagSync") local function Debug(...) if debugf then debugf:AddMessage(string.join(", ", tostringall(...))) end @@ -58,15 +54,15 @@ local dataobj = ldb:NewDataObject("BagSyncLDB", { text = "BagSync", OnClick = function(self, button) - if button == 'LeftButton' and BagSync_SearchFrame then + if button == "LeftButton" and BagSync_SearchFrame then if BagSync_SearchFrame:IsVisible() then BagSync_SearchFrame:Hide() else BagSync_SearchFrame:Show() end - elseif button == 'RightButton' and BagSync_TokensFrame then + elseif button == "RightButton" and BagSync_TokensFrame then if bgsMinimapDD then - ToggleDropDownMenu(1, nil, bgsMinimapDD, 'cursor', 0, 0) + ToggleDropDownMenu(1, nil, bgsMinimapDD, "cursor", 0, 0) end end end, @@ -84,7 +80,7 @@ local dataobj = ldb:NewDataObject("BagSyncLDB", { local BagSync = CreateFrame("Frame", "BagSync", UIParent) -BagSync:SetScript('OnEvent', function(self, event, ...) +BagSync:SetScript("OnEvent", function(self, event, ...) if self[event] then self[event](self, event, ...) end @@ -94,7 +90,31 @@ function BagSync:Debug(...) Debug(...) end -if IsLoggedIn() then BagSync:PLAYER_LOGIN() else BagSync:RegisterEvent('PLAYER_LOGIN') end +if IsLoggedIn() then BagSync:PLAYER_LOGIN() else BagSync:RegisterEvent("PLAYER_LOGIN") end + +---------------------- +-- Local -- +---------------------- + +local function rgbhex(r, g, b) + if type(r) == "table" then + if r.r then + r, g, b = r.r, r.g, r.b + else + r, g, b = unpack(r) + end + end + return string.format("|cff%02x%02x%02x", (r or 1) * 255, (g or 1) * 255, (b or 1) * 255) +end + +local function tooltipColor(color, str) + return string.format("|cff%02x%02x%02x%s|r", (color.r or 1) * 255, (color.g or 1) * 255, (color.b or 1) * 255, str) +end + +local function ToShortLink(link) + if not link then return nil end + return link:match("item:(%d+):") or nil +end ---------------------- -- DB Functions -- @@ -117,6 +137,15 @@ local function StartupDB() if BagSyncOpt.enableCrossRealmsItems == nil then BagSyncOpt.enableCrossRealmsItems = true end if BagSyncOpt.enableBNetAccountItems == nil then BagSyncOpt.enableBNetAccountItems = false end + --setup the default colors + if BagSyncOpt.colors == nil then BagSyncOpt.colors = {} end + if BagSyncOpt.colors.FIRST == nil then BagSyncOpt.colors.FIRST = { r = 128/255, g = 1, b = 0 } end + if BagSyncOpt.colors.SECOND == nil then BagSyncOpt.colors.SECOND = { r = 199/255, g = 199/255, b = 207/255 } end + if BagSyncOpt.colors.TOTAL == nil then BagSyncOpt.colors.TOTAL = { r = 244/255, g = 164/255, b = 96/255 } end + if BagSyncOpt.colors.GUILD == nil then BagSyncOpt.colors.GUILD = { r = 101/255, g = 184/255, b = 192/255 } end + if BagSyncOpt.colors.CROSS == nil then BagSyncOpt.colors.CROSS = { r = 1, g = 125/255, b = 10/255 } end + if BagSyncOpt.colors.BNET == nil then BagSyncOpt.colors.BNET = { r = 53/255, g = 136/255, b = 1 } end + --new format, get rid of old if not BagSyncOpt.dbversion or not tonumber(BagSyncOpt.dbversion) or tonumber(BagSyncOpt.dbversion) < 7 then BagSyncDB = {} @@ -146,10 +175,13 @@ local function StartupDB() BagSyncBLACKLIST_DB[currentRealm] = BagSyncBLACKLIST_DB[currentRealm] or {} BS_BL = BagSyncBLACKLIST_DB[currentRealm] + BagSync_REALMKEY = BagSync_REALMKEY or {} + BagSync_REALMKEY[currentRealm] = GetRealmName() + BS_RK = BagSync_REALMKEY + end function BagSync:FixDB_Data(onlyChkGuild) - if debugging then return end --Removes obsolete character information --Removes obsolete guild information --Removes obsolete characters from tokens db @@ -161,16 +193,21 @@ function BagSync:FixDB_Data(onlyChkGuild) local storeGuilds = {} for realm, rd in pairs(BagSyncDB) do - --realm - storeUsers[realm] = storeUsers[realm] or {} - storeGuilds[realm] = storeGuilds[realm] or {} - for k, v in pairs(rd) do - --users - storeUsers[realm][k] = storeUsers[realm][k] or 1 - if v.realm == nil then v.realm = realm end --Adds realm name to characters profiles if missing, v8.6 - for q, r in pairs(v) do - if q == 'guild' then - storeGuilds[realm][r] = true + if string.find(realm, " ") then + --get rid of old realm names with whitespaces, we aren't going to use it anymore + BagSyncDB[realm] = nil + else + --realm + storeUsers[realm] = storeUsers[realm] or {} + storeGuilds[realm] = storeGuilds[realm] or {} + for k, v in pairs(rd) do + --users + storeUsers[realm][k] = storeUsers[realm][k] or 1 + if v.realm == nil then v.realm = realm end --Adds realm name to characters profiles if missing, v8.6 + for q, r in pairs(v) do + if q == "guild" then + storeGuilds[realm][r] = true + end end end end @@ -178,12 +215,17 @@ function BagSync:FixDB_Data(onlyChkGuild) --guildbank data for realm, rd in pairs(BagSyncGUILD_DB) do - --realm - for k, v in pairs(rd) do - --users - if not storeGuilds[realm][k] then - --delete the guild because no one has it - BagSyncGUILD_DB[realm][k] = nil + if string.find(realm, " ") then + --get rid of old realm names with whitespaces, we aren't going to use it anymore + BagSyncGUILD_DB[realm] = nil + else + --realm + for k, v in pairs(rd) do + --users + if not storeGuilds[realm][k] then + --delete the guild because no one has it + BagSyncGUILD_DB[realm][k] = nil + end end end end @@ -194,21 +236,26 @@ function BagSync:FixDB_Data(onlyChkGuild) --fix tokens for realm, rd in pairs(BagSyncTOKEN_DB) do - --realm - if not storeUsers[realm] then - --if it's not a realm that ANY users are on then delete it + if string.find(realm, " ") then + --get rid of old realm names with whitespaces, we aren't going to use it anymore BagSyncTOKEN_DB[realm] = nil else - --delete old db information for tokens if it exists - if BagSyncTOKEN_DB[realm] and BagSyncTOKEN_DB[realm][1] then BagSyncTOKEN_DB[realm][1] = nil end - if BagSyncTOKEN_DB[realm] and BagSyncTOKEN_DB[realm][2] then BagSyncTOKEN_DB[realm][2] = nil end - - for k, v in pairs(rd) do - for x, y in pairs(v) do - if x ~= "icon" and x ~= "header" then - if not storeUsers[realm][x] then - --if the user doesn't exist then delete data - BagSyncTOKEN_DB[realm][k][x] = nil + --realm + if not storeUsers[realm] then + --if it's not a realm that ANY users are on then delete it + BagSyncTOKEN_DB[realm] = nil + else + --delete old db information for tokens if it exists + if BagSyncTOKEN_DB[realm] and BagSyncTOKEN_DB[realm][1] then BagSyncTOKEN_DB[realm][1] = nil end + if BagSyncTOKEN_DB[realm] and BagSyncTOKEN_DB[realm][2] then BagSyncTOKEN_DB[realm][2] = nil end + + for k, v in pairs(rd) do + for x, y in pairs(v) do + if x ~= "icon" and x ~= "header" then + if not storeUsers[realm][x] then + --if the user doesn't exist then delete data + BagSyncTOKEN_DB[realm][k][x] = nil + end end end end @@ -218,19 +265,32 @@ function BagSync:FixDB_Data(onlyChkGuild) --fix professions for realm, rd in pairs(BagSyncCRAFT_DB) do - --realm - if not storeUsers[realm] then - --if it's not a realm that ANY users are on then delete it + if string.find(realm, " ") then + --get rid of old realm names with whitespaces, we aren't going to use it anymore BagSyncCRAFT_DB[realm] = nil else - for k, v in pairs(rd) do - if not storeUsers[realm][k] then - --if the user doesn't exist then delete data - BagSyncCRAFT_DB[realm][k] = nil + --realm + if not storeUsers[realm] then + --if it's not a realm that ANY users are on then delete it + BagSyncCRAFT_DB[realm] = nil + else + for k, v in pairs(rd) do + if not storeUsers[realm][k] then + --if the user doesn't exist then delete data + BagSyncCRAFT_DB[realm][k] = nil + end end end end end + + --fix blacklist + for realm, rd in pairs(BagSyncBLACKLIST_DB) do + if string.find(realm, " ") then + --get rid of old realm names with whitespaces, we aren't going to use it anymore + BagSyncBLACKLIST_DB[realm] = nil + end + end DEFAULT_CHAT_FRAME:AddMessage("|cFF99CC33BagSync:|r |cFFFF9900"..L["A FixDB has been performed on BagSync! The database is now optimized!"].."|r") end @@ -266,22 +326,25 @@ end function BagSync:getCharacterRealmInfo(charName, charRealm) - local yName, yRealm = strsplit('^', charName) - + local yName, yRealm = strsplit("^", charName) + local realmFullName = charRealm + + if BS_RK[charRealm] then realmFullName = BS_RK[charRealm] end + --add Cross-Realm and BNet identifiers to Characters not on same realm if BagSyncOpt.enableBNetAccountItems then if charRealm and charRealm ~= currentRealm then if not crossRealmNames[charRealm] then - charName = yName.." |cff3588ff[BNet-"..charRealm.."]|r" + charName = yName.." "..rgbhex(BagSyncOpt.colors.BNET).."[BNet-"..realmFullName.."]|r" else - charName = yName.." |cffff7d0a[XR-"..charRealm.."]|r" + charName = yName.." "..rgbhex(BagSyncOpt.colors.CROSS).."[XR-"..realmFullName.."]|r" end else charName = yName end elseif BagSyncOpt.enableCrossRealmsItems then if charRealm and charRealm ~= currentRealm then - charName = yName.." |cffff7d0a[XR-"..charRealm.."]|r" + charName = yName.." "..rgbhex(BagSyncOpt.colors.CROSS).."[XR-"..realmFullName.."]|r" else charName = yName end @@ -295,20 +358,24 @@ end function BagSync:getGuildRealmInfo(guildName, guildRealm) + local realmFullName = guildRealm + + if BS_RK[guildRealm] then realmFullName = BS_RK[guildRealm] end + --add Cross-Realm and BNet identifiers to Guilds not on same realm if BagSyncOpt.enableBNetAccountItems then if guildRealm and guildRealm ~= currentRealm then if not crossRealmNames[guildRealm] then - guildName = guildName.." |cff3588ff[BNet-"..guildRealm.."]|r" + guildName = guildName.." "..rgbhex(BagSyncOpt.colors.BNET).."[BNet-"..realmFullName.."]|r" else - guildName = guildName.." |cffff7d0a[XR-"..guildRealm.."]|r" + guildName = guildName.." "..rgbhex(BagSyncOpt.colors.CROSS).."[XR-"..realmFullName.."]|r" end else guildName = guildName end elseif BagSyncOpt.enableCrossRealmsItems then if guildRealm and guildRealm ~= currentRealm then - guildName = guildName.." |cffff7d0a[XR-"..guildRealm.."]|r" + guildName = guildName.." "..rgbhex(BagSyncOpt.colors.CROSS).."[XR-"..realmFullName.."]|r" else guildName = guildName end @@ -319,22 +386,6 @@ function BagSync:getGuildRealmInfo(guildName, guildRealm) return guildName end ----------------------- --- Local -- ----------------------- - -local function doRegularTradeSkill(numIndex, dbIdx) - local name, icon, skillLevel, maxSkillLevel, numAbilities, spelloffset, skillLine, skillModifier = GetProfessionInfo(numIndex) - if name and skillLevel then - BS_CD[dbIdx] = format('%s,%s', name, skillLevel) - end -end - -local function ToShortLink(link) - if not link then return nil end - return link:match("item:(%d+):") or nil -end - ---------------------- -- Bag Functions -- @@ -357,7 +408,7 @@ local function SaveBag(bagname, bagid) if ToShortLink(link) then count = (count > 1 and count) or nil if count then - slotItems[slot] = format('%s,%d', ToShortLink(link), count) + slotItems[slot] = format("%s,%d", ToShortLink(link), count) else slotItems[slot] = ToShortLink(link) end @@ -376,40 +427,40 @@ local function SaveEquipment() lastDisplayed = {} if not BS_DB then StartupDB() end - BS_DB['equip'] = BS_DB['equip'] or {} + BS_DB["equip"] = BS_DB["equip"] or {} local slotItems = {} --start at 1, 0 used to be the old range slot (not needed anymore) for slot = 1, NUM_EQUIPMENT_SLOTS do - local link = GetInventoryItemLink('player', slot) + local link = GetInventoryItemLink("player", slot) if link and ToShortLink(link) then - local count = GetInventoryItemCount('player', slot) + local count = GetInventoryItemCount("player", slot) count = (count and count > 1) or nil if count then - slotItems[slot] = format('%s,%d', ToShortLink(link), count) + slotItems[slot] = format("%s,%d", ToShortLink(link), count) else slotItems[slot] = ToShortLink(link) end end end - BS_DB['equip'][0] = slotItems + BS_DB["equip"][0] = slotItems end local function ScanEntireBank() --force scan of bank bag -1, since blizzard never sends updates for it - SaveBag('bank', BANK_CONTAINER) + SaveBag("bank", BANK_CONTAINER) for i = NUM_BAG_SLOTS + 1, NUM_BAG_SLOTS + NUM_BANKBAGSLOTS do - SaveBag('bank', i) + SaveBag("bank", i) end if IsReagentBankUnlocked() then - SaveBag('reagentbank', REAGENTBANK_CONTAINER) + SaveBag("reagentbank", REAGENTBANK_CONTAINER) end end local function ScanVoidBank() if VoidStorageFrame and VoidStorageFrame:IsShown() then if not BS_DB then StartupDB() end - BS_DB['void'] = BS_DB['void'] or {} + BS_DB["void"] = BS_DB["void"] or {} --reset our tooltip data since we scanned new items (we want current data not old) lastItem = nil @@ -429,7 +480,7 @@ local function ScanVoidBank() end end - BS_DB['void'][0] = slotItems + BS_DB["void"][0] = slotItems end end @@ -462,7 +513,7 @@ local function ScanGuildBank() count = (count > 1 and count) or nil if count then - slotItems[index] = format('%s,%d', ToShortLink(link), count) + slotItems[index] = format("%s,%d", ToShortLink(link), count) else slotItems[index] = ToShortLink(link) end @@ -485,7 +536,7 @@ local function ScanMailbox() CheckInbox() if not BS_DB then StartupDB() end - BS_DB['mailbox'] = BS_DB['mailbox'] or {} + BS_DB["mailbox"] = BS_DB["mailbox"] or {} local slotItems = {} local mailCount = 0 @@ -506,7 +557,7 @@ local function ScanMailbox() mailCount = mailCount + 1 count = (count > 1 and count) or nil if count then - slotItems[mailCount] = format('%s,%d', ToShortLink(link), count) + slotItems[mailCount] = format("%s,%d", ToShortLink(link), count) else slotItems[mailCount] = ToShortLink(link) end @@ -515,13 +566,13 @@ local function ScanMailbox() end end - BS_DB['mailbox'][0] = slotItems + BS_DB["mailbox"][0] = slotItems isCheckingMail = false end local function ScanAuctionHouse() if not BS_DB then StartupDB() end - BS_DB['auction'] = BS_DB['auction'] or {} + BS_DB["auction"] = BS_DB["auction"] or {} local slotItems = {} local ahCount = 0 @@ -541,13 +592,13 @@ local function ScanAuctionHouse() if link and ToShortLink(link) and timeLeft then ahCount = ahCount + 1 count = (count or 1) - slotItems[ahCount] = format('%s,%s,%s', ToShortLink(link), count, timeLeft) + slotItems[ahCount] = format("%s,%s,%s", ToShortLink(link), count, timeLeft) end end end end - BS_DB['auction'][0] = slotItems + BS_DB["auction"][0] = slotItems BS_DB.AH_Count = ahCount end @@ -562,16 +613,16 @@ local function RemoveExpiredAuctions() --users k=name, v=values if BagSyncDB[realm][k].AH_LastScan and BagSyncDB[realm][k].AH_Count then --only proceed if we have an auction house time to work with --check to see if we even have something to work with - if BagSyncDB[realm][k]['auction'] then + if BagSyncDB[realm][k]["auction"] then --we do so lets do a loop local bVal = BagSyncDB[realm][k].AH_Count --do a loop through all of them and check to see if any expired for x = 1, bVal do - if BagSyncDB[realm][k]['auction'][0][x] then + if BagSyncDB[realm][k]["auction"][0][x] then --check for expired and remove if necessary --it's okay if the auction count is showing more then actually stored, it's just used as a means --to scan through all our items. Even if we have only 3 and the count is 6 it will just skip the last 3. - local dblink, dbcount, dbtimeleft = strsplit(',', BagSyncDB[realm][k]['auction'][0][x]) + local dblink, dbcount, dbtimeleft = strsplit(",", BagSyncDB[realm][k]["auction"][0][x]) --only proceed if we have everything to work with, otherwise this auction data is corrupt if dblink and dbcount and dbtimeleft then @@ -580,11 +631,11 @@ local function RemoveExpiredAuctions() local diff = time() - BagSyncDB[realm][k].AH_LastScan if diff > timestampChk[tonumber(dbtimeleft)] then --technically this isn't very realiable. but I suppose it's better the nothing - BagSyncDB[realm][k]['auction'][0][x] = nil + BagSyncDB[realm][k]["auction"][0][x] = nil end else --it's corrupt delete it - BagSyncDB[realm][k]['auction'][0][x] = nil + BagSyncDB[realm][k]["auction"][0][x] = nil end end end @@ -662,7 +713,7 @@ function BagSync:ShowMoneyTooltip() local usrData = {} - tooltip:SetOwner(UIParent, 'ANCHOR_NONE') + tooltip:SetOwner(UIParent, "ANCHOR_NONE") tooltip:ClearLines() tooltip:ClearAllPoints() tooltip:SetPoint("CENTER",UIParent,"CENTER",0,0) @@ -689,7 +740,7 @@ function BagSync:ShowMoneyTooltip() end if BagSyncOpt.showTotal and gldTotal > 0 then tooltip:AddLine(" ") - tooltip:AddDoubleLine(format(TTL_C, L["Total:"]), buildMoneyString(gldTotal, false), 1, 1, 1, 1, 1, 1) + tooltip:AddDoubleLine(tooltipColor(BagSyncOpt.colors.TOTAL, buildMoneyString(gldTotal, false)), 1, 1, 1, 1, 1, 1) end tooltip:AddLine(" ") @@ -721,7 +772,7 @@ local function ScanTokens() if IsInBG() or IsInArena() or InCombatLockdown() or UnitAffectingCombat("player") then --avoid (Honor point spam), avoid (arena point spam), if it's world PVP...well then it sucks to be you doTokenUpdate = 1 - BagSync:RegisterEvent('PLAYER_REGEN_ENABLED') + BagSync:RegisterEvent("PLAYER_REGEN_ENABLED") return end @@ -772,79 +823,79 @@ local function CountsToInfoString(countTable) local info local total = 0 - if countTable['bag'] > 0 then - info = L["Bags: %d"]:format(countTable['bag']) - total = total + countTable['bag'] + if countTable["bag"] > 0 then + info = L["Bags: %d"]:format(countTable["bag"]) + total = total + countTable["bag"] end - if countTable['bank'] > 0 then - local count = L["Bank: %d"]:format(countTable['bank']) + if countTable["bank"] > 0 then + local count = L["Bank: %d"]:format(countTable["bank"]) if info then - info = strjoin(', ', info, count) + info = strjoin(", ", info, count) else info = count end - total = total + countTable['bank'] + total = total + countTable["bank"] end - if countTable['reagentbank'] > 0 then - local count = L["Reagent: %d"]:format(countTable['reagentbank']) + if countTable["reagentbank"] > 0 then + local count = L["Reagent: %d"]:format(countTable["reagentbank"]) if info then - info = strjoin(', ', info, count) + info = strjoin(", ", info, count) else info = count end - total = total + countTable['reagentbank'] + total = total + countTable["reagentbank"] end - if countTable['equip'] > 0 then - local count = L["Equip: %d"]:format(countTable['equip']) + if countTable["equip"] > 0 then + local count = L["Equip: %d"]:format(countTable["equip"]) if info then - info = strjoin(', ', info, count) + info = strjoin(", ", info, count) else info = count end - total = total + countTable['equip'] + total = total + countTable["equip"] end - if countTable['guild'] > 0 and BagSyncOpt.enableGuild and not BagSyncOpt.showGuildNames then - local count = L["Guild: %d"]:format(countTable['guild']) + if countTable["guild"] > 0 and BagSyncOpt.enableGuild and not BagSyncOpt.showGuildNames then + local count = L["Guild: %d"]:format(countTable["guild"]) if info then - info = strjoin(', ', info, count) + info = strjoin(", ", info, count) else info = count end - total = total + countTable['guild'] --add the guild count only if we don't have showguildnames on, otherwise it's counted twice + total = total + countTable["guild"] --add the guild count only if we don't have showguildnames on, otherwise it's counted twice end - if countTable['mailbox'] > 0 and BagSyncOpt.enableMailbox then - local count = L["Mail: %d"]:format(countTable['mailbox']) + if countTable["mailbox"] > 0 and BagSyncOpt.enableMailbox then + local count = L["Mail: %d"]:format(countTable["mailbox"]) if info then - info = strjoin(', ', info, count) + info = strjoin(", ", info, count) else info = count end - total = total + countTable['mailbox'] + total = total + countTable["mailbox"] end - if countTable['void'] > 0 then - local count = L["Void: %d"]:format(countTable['void']) + if countTable["void"] > 0 then + local count = L["Void: %d"]:format(countTable["void"]) if info then - info = strjoin(', ', info, count) + info = strjoin(", ", info, count) else info = count end - total = total + countTable['void'] + total = total + countTable["void"] end - if countTable['auction'] > 0 and BagSyncOpt.enableAuction then - local count = L["AH: %d"]:format(countTable['auction']) + if countTable["auction"] > 0 and BagSyncOpt.enableAuction then + local count = L["AH: %d"]:format(countTable["auction"]) if info then - info = strjoin(', ', info, count) + info = strjoin(", ", info, count) else info = count end - total = total + countTable['auction'] + total = total + countTable["auction"] end if info and info ~= "" then @@ -858,10 +909,10 @@ local function CountsToInfoString(countTable) end if not totalPass then - local totalStr = format(MOSS, total) - return totalStr .. format(SILVER, format(' (%s)', info)) + local totalStr = tooltipColor(BagSyncOpt.colors.FIRST, total) + return totalStr .. tooltipColor(BagSyncOpt.colors.SECOND, format(" (%s)", info)) else - return format(MOSS, info) + return tooltipColor(BagSyncOpt.colors.FIRST, info) end end end @@ -881,26 +932,15 @@ local function pairsByKeys (t, f) return iter end -local function rgbhex(r, g, b) - if type(r) == "table" then - if r.r then - r, g, b = r.r, r.g, r.b - else - r, g, b = unpack(r) - end - end - return string.format("|cff%02x%02x%02x", (r or 1) * 255, (g or 1) * 255, (b or 1) * 255) -end - local function getNameColor(sName, sClass) if not BagSyncOpt.enableUnitClass then - return format(MOSS, sName) + return tooltipColor(BagSyncOpt.colors.FIRST, sName) else if sName ~= "Unknown" and sClass and RAID_CLASS_COLORS[sClass] then return rgbhex(RAID_CLASS_COLORS[sClass])..sName.."|r" end end - return format(MOSS, sName) + return tooltipColor(BagSyncOpt.colors.FIRST, sName) end local function getPlayerNameColor(sName) @@ -908,7 +948,7 @@ local function getPlayerNameColor(sName) local sClass = BagSyncDB[currentRealm][sName].class return getNameColor(sName, sClass) end - return format(MOSS, sName) + return tooltipColor(BagSyncOpt.colors.FIRST, sName) end local function AddCurrencyToTooltip(frame, currencyName) @@ -950,7 +990,7 @@ local function AddItemToTooltip(frame, link) --workaround if lastItem and itemLink and itemLink == lastItem then if table.getn(lastDisplayed) > 0 then for i = 1, #lastDisplayed do - local ename, ecount = strsplit('@', lastDisplayed[i]) + local ename, ecount = strsplit("@", lastDisplayed[i]) if ename and ecount then frame:AddDoubleLine(ename, ecount) end @@ -1002,7 +1042,7 @@ local function AddItemToTooltip(frame, link) --workaround --slotID = slotid for specific bagid, itemValue = data of specific slotid if type(bagInfo) == "table" then for slotID, itemValue in pairs(bagInfo) do - local dblink, dbcount = strsplit(',', itemValue) + local dblink, dbcount = strsplit(",", itemValue) if dblink and dblink == itemLink then allowList[q] = allowList[q] + (dbcount or 1) grandTotal = grandTotal + (dbcount or 1) @@ -1026,7 +1066,7 @@ local function AddItemToTooltip(frame, link) --workaround --we only really need to see this information once per guild local tmpCount = 0 for q, r in pairs(BagSyncGUILD_DB[v.realm][guildN]) do - local dblink, dbcount = strsplit(',', r) + local dblink, dbcount = strsplit(",", r) if dblink and dblink == itemLink then allowList["guild"] = allowList["guild"] + (dbcount or 1) tmpCount = tmpCount + (dbcount or 1) @@ -1042,9 +1082,9 @@ local function AddItemToTooltip(frame, link) --workaround local pClass = v.class or nil infoString = CountsToInfoString(allowList) - if infoString and infoString ~= '' then + if infoString and infoString ~= "" then k = BagSync:getCharacterRealmInfo(k, v.realm) - table.insert(lastDisplayed, getNameColor(k or 'Unknown', pClass).."@"..(infoString or 'unknown')) + table.insert(lastDisplayed, getNameColor(k or "Unknown", pClass).."@"..(infoString or "unknown")) end end @@ -1059,7 +1099,7 @@ local function AddItemToTooltip(frame, link) --workaround for k, v in pairsByKeys(previousGuilds) do --only print stuff higher then zero if v > 0 then - table.insert(lastDisplayed, format(GN_C, k).."@"..format(SILVER, v)) + table.insert(lastDisplayed, tooltipColor(BagSyncOpt.colors.GUILD, k).."@"..tooltipColor(BagSyncOpt.colors.SECOND, v)) end end end @@ -1067,7 +1107,7 @@ local function AddItemToTooltip(frame, link) --workaround --show grand total if we have something --don't show total if there is only one item if BagSyncOpt.showTotal and grandTotal > 0 and getn(lastDisplayed) > 1 then - table.insert(lastDisplayed, format(TTL_C, L["Total:"]).."@"..format(SILVER, grandTotal)) + table.insert(lastDisplayed, tooltipColor(BagSyncOpt.colors.TOTAL, L["Total:"]).."@"..tooltipColor(BagSyncOpt.colors.SECOND, grandTotal)) end --now check for seperater and only add if we have something in the table already @@ -1078,7 +1118,7 @@ local function AddItemToTooltip(frame, link) --workaround --add it all together now if table.getn(lastDisplayed) > 0 then for i = 1, #lastDisplayed do - local ename, ecount = strsplit('@', lastDisplayed[i]) + local ename, ecount = strsplit("@", lastDisplayed[i]) if ename and ecount then frame:AddDoubleLine(ename, ecount) end @@ -1099,11 +1139,11 @@ local function hookTip(tooltip) modified = false self.lastHyperLink = nil end) - tooltip:HookScript('OnTooltipCleared', function(self) + tooltip:HookScript("OnTooltipCleared", function(self) modified = false end) - tooltip:HookScript('OnTooltipSetItem', function(self) + tooltip:HookScript("OnTooltipSetItem", function(self) if modified or not BagSyncOpt.enableTooltips then return end local name, link = self:GetItem() if link and ToShortLink(link) then @@ -1128,28 +1168,28 @@ local function hookTip(tooltip) end) --------------------------------- --Special thanks to GetItem() being broken we need to capture the ItemLink before the tooltip shows sometimes - hooksecurefunc(tooltip, 'SetBagItem', function(self, tab, slot) + hooksecurefunc(tooltip, "SetBagItem", function(self, tab, slot) if not BagSyncOpt.enableTooltips then return end local link = GetContainerItemLink(tab, slot) if link and ToShortLink(link) then self.lastHyperLink = link end end) - hooksecurefunc(tooltip, 'SetInventoryItem', function(self, tab, slot) + hooksecurefunc(tooltip, "SetInventoryItem", function(self, tab, slot) if not BagSyncOpt.enableTooltips then return end local link = GetInventoryItemLink(tab, slot) if link and ToShortLink(link) then self.lastHyperLink = link end end) - hooksecurefunc(tooltip, 'SetGuildBankItem', function(self, tab, slot) + hooksecurefunc(tooltip, "SetGuildBankItem", function(self, tab, slot) if not BagSyncOpt.enableTooltips then return end local link = GetGuildBankItemLink(tab, slot) if link and ToShortLink(link) then self.lastHyperLink = link end end) - hooksecurefunc(tooltip, 'SetHyperlink', function(self, link) + hooksecurefunc(tooltip, "SetHyperlink", function(self, link) if modified or not BagSyncOpt.enableTooltips then return end if link and ToShortLink(link) then --I'm pretty sure there is a better way to do this but since Recipes fire OnTooltipSetItem with empty/nil GetItem(). There is really no way to my knowledge to grab the current itemID @@ -1161,7 +1201,7 @@ local function hookTip(tooltip) --------------------------------- --lets hook other frames so we can show tooltips there as well - hooksecurefunc(tooltip, 'SetRecipeReagentItem', function(self, recipeID, reagentIndex) + hooksecurefunc(tooltip, "SetRecipeReagentItem", function(self, recipeID, reagentIndex) if modified or not BagSyncOpt.enableTooltips then return end local link = C_TradeSkillUI.GetRecipeReagentItemLink(recipeID, reagentIndex) if link and ToShortLink(link) then @@ -1169,7 +1209,7 @@ local function hookTip(tooltip) AddItemToTooltip(self, link) end end) - hooksecurefunc(tooltip, 'SetRecipeResultItem', function(self, recipeID) + hooksecurefunc(tooltip, "SetRecipeResultItem", function(self, recipeID) if modified or not BagSyncOpt.enableTooltips then return end local link = C_TradeSkillUI.GetRecipeItemLink(recipeID) if link and ToShortLink(link) then @@ -1177,7 +1217,7 @@ local function hookTip(tooltip) AddItemToTooltip(self, link) end end) - hooksecurefunc(tooltip, 'SetQuestLogItem', function(self, itemType, index) + hooksecurefunc(tooltip, "SetQuestLogItem", function(self, itemType, index) if modified or not BagSyncOpt.enableTooltips then return end local link = GetQuestLogItemLink(itemType, index) if link and ToShortLink(link) then @@ -1185,7 +1225,7 @@ local function hookTip(tooltip) AddItemToTooltip(self, link) end end) - hooksecurefunc(tooltip, 'SetQuestItem', function(self, itemType, index) + hooksecurefunc(tooltip, "SetQuestItem", function(self, itemType, index) if modified or not BagSyncOpt.enableTooltips then return end local link = GetQuestItemLink(itemType, index) if link and ToShortLink(link) then @@ -1202,19 +1242,19 @@ local function hookTip(tooltip) -- end) -------------------------------------------------- - hooksecurefunc(tooltip, 'SetCurrencyToken', function(self, index) + hooksecurefunc(tooltip, "SetCurrencyToken", function(self, index) if modified or not BagSyncOpt.enableTooltips then return end modified = true local currencyName = GetCurrencyListInfo(index) AddCurrencyToTooltip(self, currencyName) end) - hooksecurefunc(tooltip, 'SetCurrencyByID', function(self, id) + hooksecurefunc(tooltip, "SetCurrencyByID", function(self, id) if modified or not BagSyncOpt.enableTooltips then return end modified = true local currencyName = GetCurrencyInfo(id) AddCurrencyToTooltip(self, currencyName) end) - hooksecurefunc(tooltip, 'SetBackpackToken', function(self, index) + hooksecurefunc(tooltip, "SetBackpackToken", function(self, index) if modified or not BagSyncOpt.enableTooltips then return end modified = true local currencyName = GetBackpackCurrencyInfo(index) @@ -1248,8 +1288,8 @@ function BagSync:PLAYER_LOGIN() local ver = GetAddOnMetadata("BagSync","Version") or 0 --load our player info after login - currentPlayer = UnitName('player') - currentRealm = GetRealmName() + currentPlayer = UnitName("player") + currentRealm = select(2, UnitFullName("player")) --get shortend realm name with no spaces and dashes playerClass = select(2, UnitClass("player")) playerFaction = UnitFactionGroup("player") @@ -1264,6 +1304,9 @@ function BagSync:PLAYER_LOGIN() --initiate the db StartupDB() + --load the options menu + BSOpt_Startup() + --do DB cleanup check by version number if not BagSyncOpt.dbversion or BagSyncOpt.dbversion ~= ver then self:FixDB_Data() @@ -1293,7 +1336,7 @@ function BagSync:PLAYER_LOGIN() --save all inventory data, including backpack(0) for i = BACKPACK_CONTAINER, BACKPACK_CONTAINER + NUM_BAG_SLOTS do - SaveBag('bag', i) + SaveBag("bag", i) end --force an equipment scan @@ -1312,28 +1355,28 @@ function BagSync:PLAYER_LOGIN() BagSync_MinimapButton:Hide() end - self:RegisterEvent('PLAYER_MONEY') - self:RegisterEvent('BANKFRAME_OPENED') - self:RegisterEvent('BANKFRAME_CLOSED') - self:RegisterEvent('GUILDBANKFRAME_OPENED') - self:RegisterEvent('GUILDBANKFRAME_CLOSED') - self:RegisterEvent('GUILDBANKBAGSLOTS_CHANGED') - self:RegisterEvent('PLAYERREAGENTBANKSLOTS_CHANGED') - self:RegisterEvent('BAG_UPDATE') - self:RegisterEvent('PLAYERBANKSLOTS_CHANGED') - self:RegisterEvent('UNIT_INVENTORY_CHANGED') - self:RegisterEvent('GUILD_ROSTER_UPDATE') - self:RegisterEvent('MAIL_SHOW') - self:RegisterEvent('MAIL_INBOX_UPDATE') + self:RegisterEvent("PLAYER_MONEY") + self:RegisterEvent("BANKFRAME_OPENED") + self:RegisterEvent("BANKFRAME_CLOSED") + self:RegisterEvent("GUILDBANKFRAME_OPENED") + self:RegisterEvent("GUILDBANKFRAME_CLOSED") + self:RegisterEvent("GUILDBANKBAGSLOTS_CHANGED") + self:RegisterEvent("PLAYERREAGENTBANKSLOTS_CHANGED") + self:RegisterEvent("BAG_UPDATE") + self:RegisterEvent("PLAYERBANKSLOTS_CHANGED") + self:RegisterEvent("UNIT_INVENTORY_CHANGED") + self:RegisterEvent("GUILD_ROSTER_UPDATE") + self:RegisterEvent("MAIL_SHOW") + self:RegisterEvent("MAIL_INBOX_UPDATE") self:RegisterEvent("AUCTION_HOUSE_SHOW") self:RegisterEvent("AUCTION_OWNED_LIST_UPDATE") --currency - self:RegisterEvent('CURRENCY_DISPLAY_UPDATE') + self:RegisterEvent("CURRENCY_DISPLAY_UPDATE") --void storage - self:RegisterEvent('VOID_STORAGE_OPEN') - self:RegisterEvent('VOID_STORAGE_CLOSE') + self:RegisterEvent("VOID_STORAGE_OPEN") + self:RegisterEvent("VOID_STORAGE_CLOSE") self:RegisterEvent("VOID_STORAGE_UPDATE") self:RegisterEvent("VOID_STORAGE_CONTENTS_UPDATE") self:RegisterEvent("VOID_TRANSFER_DONE") @@ -1485,14 +1528,14 @@ function BagSync:BAG_UPDATE(event, bagid) --get the correct bag name based on it's id, trying NOT to use numbers as Blizzard may change bagspace in the future --so instead I'm using constants :) if ((bagid >= NUM_BAG_SLOTS + 1) and (bagid <= NUM_BAG_SLOTS + NUM_BANKBAGSLOTS)) then - bagname = 'bank' + bagname = "bank" elseif (bagid >= BACKPACK_CONTAINER) and (bagid <= BACKPACK_CONTAINER + NUM_BAG_SLOTS) then - bagname = 'bag' + bagname = "bag" else return end - if bagname == 'bank' and not atBank then return; end + if bagname == "bank" and not atBank then return; end --now save the item information in the bag from bagupdate, this could be bag or bank SaveBag(bagname, bagid) @@ -1501,7 +1544,7 @@ end function BagSync:UNIT_INVENTORY_CHANGED(event, unit) if debugging then return end - if unit == 'player' then + if unit == "player" then SaveEquipment() end end @@ -1525,7 +1568,7 @@ function BagSync:PLAYERBANKSLOTS_CHANGED(event, slotid) if debugging then return end --Remove atBank when/if Blizzard allows Bank access without being at the bank if atBank then - SaveBag('bank', BANK_CONTAINER) + SaveBag("bank", BANK_CONTAINER) end end @@ -1535,7 +1578,7 @@ end function BagSync:PLAYERREAGENTBANKSLOTS_CHANGED() if debugging then return end - SaveBag('reagentbank', REAGENTBANK_CONTAINER) + SaveBag("reagentbank", REAGENTBANK_CONTAINER) end ------------------------------ @@ -1648,6 +1691,13 @@ end -- PROFESSION -- ------------------------------ +local function doRegularTradeSkill(numIndex, dbIdx) + local name, icon, skillLevel, maxSkillLevel, numAbilities, spelloffset, skillLine, skillModifier = GetProfessionInfo(numIndex) + if name and skillLevel then + BS_CD[dbIdx] = format("%s,%s", name, skillLevel) + end +end + function BagSync:TRADE_SKILL_SHOW() if debugging then return end diff --git a/BagSync.toc b/BagSync.toc index 390eecd..9c098b3 100644 --- a/BagSync.toc +++ b/BagSync.toc @@ -2,16 +2,17 @@ ## Title: BagSync ## Notes: BagSync tracks your characters items and displays it within tooltips. ## Author: Xruptor -## Version: 9.1 +## Version: 9.2 ## OptionalDeps: tekDebug -## SavedVariables: BagSyncDB, BagSyncOpt, BagSyncGUILD_DB, BagSyncTOKEN_DB, BagSyncCRAFT_DB, BagSyncBLACKLIST_DB +## SavedVariables: BagSyncDB, BagSyncOpt, BagSyncGUILD_DB, BagSyncTOKEN_DB, BagSyncCRAFT_DB, BagSyncBLACKLIST_DB, BagSync_REALMKEY localization\localization.lua -libs\LibStub.lua -libs\CallbackHandler-1.0.lua +libs\LibStub\LibStub.lua +libs\CallbackHandler-1.0\CallbackHandler-1.0.xml +libs\LibItemSearch-1.0\LibItemSearch-1.0.lua +libs\LibDataBroker-1.1\LibDataBroker-1.1.lua +libs\LibSimpleOptions-1.0\LibSimpleOptions-1.0.lua libs\tekKonfigScroll.lua -libs\LibItemSearch-1.0.lua -libs\LibDataBroker-1.1.lua BagSync_Minimap.lua BagSync_Search.lua diff --git a/BagSync_Blacklist.lua b/BagSync_Blacklist.lua index 9e0e2f4..36b8681 100644 --- a/BagSync_Blacklist.lua +++ b/BagSync_Blacklist.lua @@ -1,8 +1,8 @@ local L = BAGSYNC_L local blacklistTable = {} local tRows, tAnchor = {} -local currentPlayer = UnitName('player') -local currentRealm = GetRealmName() +local currentPlayer = UnitName("player") +local currentRealm = select(2, UnitFullName("player")) --get shortend realm name with no spaces and dashes local storedBarCount = 0 local prevClickedBar diff --git a/BagSync_Config.lua b/BagSync_Config.lua index d079678..412850d 100644 --- a/BagSync_Config.lua +++ b/BagSync_Config.lua @@ -1,291 +1,247 @@ local L = BAGSYNC_L -local currentPlayer = UnitName('player') -local currentRealm = GetRealmName() +local currentPlayer = UnitName("player") +local currentRealm = select(2, UnitFullName("player")) local ver = GetAddOnMetadata("BagSync","Version") or 0 -local bgsOpt = CreateFrame("Frame", "BagSyncConfig", InterfaceOptionsFramePanelContainer) -bgsOpt:Hide() -bgsOpt.name = "BagSync" - -bgsOpt:SetScript("OnShow", function() - if BagSyncOpt then - BagSyncConfig_Total:SetChecked(BagSyncOpt["showTotal"]) - BagSyncConfig_GuildNames:SetChecked(BagSyncOpt["showGuildNames"]) - BagSyncConfig_BothFactions:SetChecked(BagSyncOpt["enableFaction"]) - BagSyncConfig_ClassColors:SetChecked(BagSyncOpt["enableUnitClass"]) - BagSyncConfig_Minimap:SetChecked(BagSyncOpt["enableMinimap"]) - BagSyncConfig_GuildInfo:SetChecked(BagSyncOpt["enableGuild"]) - BagSyncConfig_MailboxInfo:SetChecked(BagSyncOpt["enableMailbox"]) - BagSyncConfig_AuctionInfo:SetChecked(BagSyncOpt["enableAuction"]) - BagSyncConfig_TooltipSearchOnly:SetChecked(BagSyncOpt["tooltipOnlySearch"]) - BagSyncConfig_EnableBagSyncTooltips:SetChecked(BagSyncOpt["enableTooltips"]) - BagSyncConfig_EnableBagSyncTooltipsSeperator:SetChecked(BagSyncOpt["enableTooltipSeperator"]) - BagSyncConfig_EnableCrossRealmsItems:SetChecked(BagSyncOpt["enableCrossRealmsItems"]) - BagSyncConfig_EnableBNetAccountItems:SetChecked(BagSyncOpt["enableBNetAccountItems"]) - end -end) - -local title = bgsOpt:CreateFontString(nil, "ARTWORK", "GameFontNormalLarge") -title:SetPoint("TOPLEFT", 16, -16) -title:SetText("|cFF99CC33BagSync|r [|cFFDF2B2B"..ver.."|r]") -InterfaceOptions_AddCategory(bgsOpt) - ---[[ Total ]]-- -local bgs_Total_Opt = CreateFrame("CheckButton", "BagSyncConfig_Total", bgsOpt, "OptionsBaseCheckButtonTemplate") -bgs_Total_Opt:SetPoint("TOPLEFT", 16, -45) -bgs_Total_Opt:SetScript("OnClick", function(frame) - if BagSyncOpt then - if frame:GetChecked() then - PlaySound("igMainMenuOptionCheckBoxOn") - BagSyncOpt["showTotal"] = true - if BagSync then BagSync:resetTooltip() end - else - PlaySound("igMainMenuOptionCheckBoxOff") - BagSyncOpt["showTotal"] = false - if BagSync then BagSync:resetTooltip() end - end - end -end) -local bgs_Total_OptText = bgs_Total_Opt:CreateFontString(nil, "ARTWORK", "GameFontHighlight") -bgs_Total_OptText:SetPoint("LEFT", bgs_Total_Opt, "RIGHT", 0, 1) -bgs_Total_OptText:SetText(L["Display [Total] in tooltips and gold display."]) - ---[[ Guild Names ]]-- -local bgs_GuildNames_Opt = CreateFrame("CheckButton", "BagSyncConfig_GuildNames", bgsOpt, "OptionsBaseCheckButtonTemplate") -bgs_GuildNames_Opt:SetPoint("TOPLEFT", 16, -73) -bgs_GuildNames_Opt:SetScript("OnClick", function(frame) - if BagSyncOpt then - if frame:GetChecked() then - PlaySound("igMainMenuOptionCheckBoxOn") - BagSyncOpt["showGuildNames"] = true - if BagSync then BagSync:resetTooltip() end - else - PlaySound("igMainMenuOptionCheckBoxOff") - BagSyncOpt["showGuildNames"] = false - if BagSync then BagSync:resetTooltip() end - end - end -end) -local bgs_GuildNames_OptText = bgs_GuildNames_Opt:CreateFontString(nil, "ARTWORK", "GameFontHighlight") -bgs_GuildNames_OptText:SetPoint("LEFT", bgs_GuildNames_Opt, "RIGHT", 0, 1) -bgs_GuildNames_OptText:SetText(L["Display [Guild Name] display in tooltips."]) - ---[[ Display Both Factions ]]-- -local bgs_BothFactions_Opt = CreateFrame("CheckButton", "BagSyncConfig_BothFactions", bgsOpt, "OptionsBaseCheckButtonTemplate") -bgs_BothFactions_Opt:SetPoint("TOPLEFT", 16, -101) -bgs_BothFactions_Opt:SetScript("OnClick", function(frame) - if BagSyncOpt then - if frame:GetChecked() then - PlaySound("igMainMenuOptionCheckBoxOn") - BagSyncOpt["enableFaction"] = true - if BagSync then BagSync:resetTooltip() end - else - PlaySound("igMainMenuOptionCheckBoxOff") - BagSyncOpt["enableFaction"] = false - if BagSync then BagSync:resetTooltip() end - end - end -end) -local bgs_BothFactions_OptText = bgs_BothFactions_Opt:CreateFontString(nil, "ARTWORK", "GameFontHighlight") -bgs_BothFactions_OptText:SetPoint("LEFT", bgs_BothFactions_Opt, "RIGHT", 0, 1) -bgs_BothFactions_OptText:SetText(L["Display items for both factions (Alliance/Horde)."]) - ---[[ Class Colors ]]-- -local bgs_ClassColors_Opt = CreateFrame("CheckButton", "BagSyncConfig_ClassColors", bgsOpt, "OptionsBaseCheckButtonTemplate") -bgs_ClassColors_Opt:SetPoint("TOPLEFT", 16, -129) -bgs_ClassColors_Opt:SetScript("OnClick", function(frame) - if BagSyncOpt then - if frame:GetChecked() then - PlaySound("igMainMenuOptionCheckBoxOn") - BagSyncOpt["enableUnitClass"] = true - if BagSync then BagSync:resetTooltip() end - else - PlaySound("igMainMenuOptionCheckBoxOff") - BagSyncOpt["enableUnitClass"] = false - if BagSync then BagSync:resetTooltip() end - end - end -end) -local bgs_ClassColors_OptText = bgs_ClassColors_Opt:CreateFontString(nil, "ARTWORK", "GameFontHighlight") -bgs_ClassColors_OptText:SetPoint("LEFT", bgs_ClassColors_Opt, "RIGHT", 0, 1) -bgs_ClassColors_OptText:SetText(L["Display class colors for characters."]) - ---[[ Minimap ]]-- -local bgs_Minimap_Opt = CreateFrame("CheckButton", "BagSyncConfig_Minimap", bgsOpt, "OptionsBaseCheckButtonTemplate") -bgs_Minimap_Opt:SetPoint("TOPLEFT", 16, -157) -bgs_Minimap_Opt:SetScript("OnClick", function(frame) - if BagSyncOpt then - if frame:GetChecked() then - PlaySound("igMainMenuOptionCheckBoxOn") - BagSyncOpt["enableMinimap"] = true - if BagSync_MinimapButton and not BagSync_MinimapButton:IsVisible() then BagSync_MinimapButton:Show() end - else - PlaySound("igMainMenuOptionCheckBoxOff") - BagSyncOpt["enableMinimap"] = false - if BagSync_MinimapButton and BagSync_MinimapButton:IsVisible() then BagSync_MinimapButton:Hide() end - end - end -end) -local bgs_Minimap_OptText = bgs_Minimap_Opt:CreateFontString(nil, "ARTWORK", "GameFontHighlight") -bgs_Minimap_OptText:SetPoint("LEFT", bgs_Minimap_Opt, "RIGHT", 0, 1) -bgs_Minimap_OptText:SetText(L["Display BagSync minimap button."]) - ---[[ Enable Guild Info ]]-- -local bgs_GuildInfo_Opt = CreateFrame("CheckButton", "BagSyncConfig_GuildInfo", bgsOpt, "OptionsBaseCheckButtonTemplate") -bgs_GuildInfo_Opt:SetPoint("TOPLEFT", 16, -185) -bgs_GuildInfo_Opt:SetScript("OnClick", function(frame) - if BagSyncOpt then - if frame:GetChecked() then - PlaySound("igMainMenuOptionCheckBoxOn") - BagSyncOpt["enableGuild"] = true - if BagSync then BagSync:resetTooltip() end - else - PlaySound("igMainMenuOptionCheckBoxOff") - BagSyncOpt["enableGuild"] = false - if BagSync then BagSync:resetTooltip() end - end - end -end) -local bgs_GuildInfo_OptText = bgs_GuildInfo_Opt:CreateFontString(nil, "ARTWORK", "GameFontHighlight") -bgs_GuildInfo_OptText:SetPoint("LEFT", bgs_GuildInfo_Opt, "RIGHT", 0, 1) -bgs_GuildInfo_OptText:SetText(L["Enable guild bank items."]) - ---[[ Enable Mailbox Info ]]-- -local bgs_MailboxInfo_Opt = CreateFrame("CheckButton", "BagSyncConfig_MailboxInfo", bgsOpt, "OptionsBaseCheckButtonTemplate") -bgs_MailboxInfo_Opt:SetPoint("TOPLEFT", 16, -213) -bgs_MailboxInfo_Opt:SetScript("OnClick", function(frame) - if BagSyncOpt then - if frame:GetChecked() then - PlaySound("igMainMenuOptionCheckBoxOn") - BagSyncOpt["enableMailbox"] = true - if BagSync then BagSync:resetTooltip() end - else - PlaySound("igMainMenuOptionCheckBoxOff") - BagSyncOpt["enableMailbox"] = false - if BagSync then BagSync:resetTooltip() end - end - end -end) -local bgs_MailboxInfo_OptText = bgs_MailboxInfo_Opt:CreateFontString(nil, "ARTWORK", "GameFontHighlight") -bgs_MailboxInfo_OptText:SetPoint("LEFT", bgs_MailboxInfo_Opt, "RIGHT", 0, 1) -bgs_MailboxInfo_OptText:SetText(L["Enable mailbox items."]) - ---[[ Enable Auction House Info Info ]]-- -local bgs_AuctionInfo_Opt = CreateFrame("CheckButton", "BagSyncConfig_AuctionInfo", bgsOpt, "OptionsBaseCheckButtonTemplate") -bgs_AuctionInfo_Opt:SetPoint("TOPLEFT", 16, -241) -bgs_AuctionInfo_Opt:SetScript("OnClick", function(frame) - if BagSyncOpt then - if frame:GetChecked() then - PlaySound("igMainMenuOptionCheckBoxOn") - BagSyncOpt["enableAuction"] = true - if BagSync then BagSync:resetTooltip() end - else - PlaySound("igMainMenuOptionCheckBoxOff") - BagSyncOpt["enableAuction"] = false - if BagSync then BagSync:resetTooltip() end - end - end -end) -local bgs_AuctionInfo_OptText = bgs_AuctionInfo_Opt:CreateFontString(nil, "ARTWORK", "GameFontHighlight") -bgs_AuctionInfo_OptText:SetPoint("LEFT", bgs_AuctionInfo_Opt, "RIGHT", 0, 1) -bgs_AuctionInfo_OptText:SetText(L["Enable auction house items."]) - ---[[ Display tooltips only in the BagSync Search window ]]-- -local bgs_TooltipSearchOnly_Opt = CreateFrame("CheckButton", "BagSyncConfig_TooltipSearchOnly", bgsOpt, "OptionsBaseCheckButtonTemplate") -bgs_TooltipSearchOnly_Opt:SetPoint("TOPLEFT", 16, -269) -bgs_TooltipSearchOnly_Opt:SetScript("OnClick", function(frame) - if BagSyncOpt then - if frame:GetChecked() then - PlaySound("igMainMenuOptionCheckBoxOn") - BagSyncOpt["tooltipOnlySearch"] = true - if BagSync then BagSync:resetTooltip() end - else - PlaySound("igMainMenuOptionCheckBoxOff") - BagSyncOpt["tooltipOnlySearch"] = false - if BagSync then BagSync:resetTooltip() end - end - end -end) -local bgs_TooltipSearchOnly_OptText = bgs_TooltipSearchOnly_Opt:CreateFontString(nil, "ARTWORK", "GameFontHighlight") -bgs_TooltipSearchOnly_OptText:SetPoint("LEFT", bgs_TooltipSearchOnly_Opt, "RIGHT", 0, 1) -bgs_TooltipSearchOnly_OptText:SetText(L["Display modified tooltips ONLY in the BagSync Search window."]) - ---[[ Toggle for BagSync tooltips]]-- -local bgs_EnableBagSyncTooltips_Opt = CreateFrame("CheckButton", "BagSyncConfig_EnableBagSyncTooltips", bgsOpt, "OptionsBaseCheckButtonTemplate") -bgs_EnableBagSyncTooltips_Opt:SetPoint("TOPLEFT", 16, -297) -bgs_EnableBagSyncTooltips_Opt:SetScript("OnClick", function(frame) - if BagSyncOpt then - if frame:GetChecked() then - PlaySound("igMainMenuOptionCheckBoxOn") - BagSyncOpt["enableTooltips"] = true - if BagSync then BagSync:resetTooltip() end - else - PlaySound("igMainMenuOptionCheckBoxOff") - BagSyncOpt["enableTooltips"] = false - if BagSync then BagSync:resetTooltip() end - end - end -end) -local bgs_EnableBagSyncTooltips_OptText = bgs_EnableBagSyncTooltips_Opt:CreateFontString(nil, "ARTWORK", "GameFontHighlight") -bgs_EnableBagSyncTooltips_OptText:SetPoint("LEFT", bgs_EnableBagSyncTooltips_Opt, "RIGHT", 0, 1) -bgs_EnableBagSyncTooltips_OptText:SetText(L["Enable BagSync Tooltips"]) - ---[[ Toggle for BagSync Tooltip Seperator]]-- -local bgs_EnableBagSyncTooltipsSeperator_Opt = CreateFrame("CheckButton", "BagSyncConfig_EnableBagSyncTooltipsSeperator", bgsOpt, "OptionsBaseCheckButtonTemplate") -bgs_EnableBagSyncTooltipsSeperator_Opt:SetPoint("TOPLEFT", 16, -325) -bgs_EnableBagSyncTooltipsSeperator_Opt:SetScript("OnClick", function(frame) - if BagSyncOpt then - if frame:GetChecked() then - PlaySound("igMainMenuOptionCheckBoxOn") - BagSyncOpt["enableTooltipSeperator"] = true - if BagSync then BagSync:resetTooltip() end - else - PlaySound("igMainMenuOptionCheckBoxOff") - BagSyncOpt["enableTooltipSeperator"] = false - if BagSync then BagSync:resetTooltip() end - end - end -end) -local bgs_EnableBagSyncTooltipsSeperator_OptText = bgs_EnableBagSyncTooltipsSeperator_Opt:CreateFontString(nil, "ARTWORK", "GameFontHighlight") -bgs_EnableBagSyncTooltipsSeperator_OptText:SetPoint("LEFT", bgs_EnableBagSyncTooltipsSeperator_Opt, "RIGHT", 0, 1) -bgs_EnableBagSyncTooltipsSeperator_OptText:SetText(L["Enable empty line seperator above BagSync tooltip display."]) - ---[[ Toggle for Cross-Realms Items]]-- -local bgs_EnableCrossRealmsItems_Opt = CreateFrame("CheckButton", "BagSyncConfig_EnableCrossRealmsItems", bgsOpt, "OptionsBaseCheckButtonTemplate") -bgs_EnableCrossRealmsItems_Opt:SetPoint("TOPLEFT", 16, -353) -bgs_EnableCrossRealmsItems_Opt:SetScript("OnClick", function(frame) - if BagSyncOpt then - if frame:GetChecked() then - PlaySound("igMainMenuOptionCheckBoxOn") - BagSyncOpt["enableCrossRealmsItems"] = true - if BagSync then BagSync:resetTooltip() end - else - PlaySound("igMainMenuOptionCheckBoxOff") - BagSyncOpt["enableCrossRealmsItems"] = false - if BagSync then BagSync:resetTooltip() end - end - end -end) -local bgs_EnableCrossRealmsItems_OptText = bgs_EnableCrossRealmsItems_Opt:CreateFontString(nil, "ARTWORK", "GameFontHighlight") -bgs_EnableCrossRealmsItems_OptText:SetPoint("LEFT", bgs_EnableCrossRealmsItems_Opt, "RIGHT", 0, 1) -bgs_EnableCrossRealmsItems_OptText:SetText(L["Enable items for Cross-Realms characters."]) - ---[[ Toggle for current Battle.Net Account Character Items]]-- -local bgs_EnableBNetAccountItems_Opt = CreateFrame("CheckButton", "BagSyncConfig_EnableBNetAccountItems", bgsOpt, "OptionsBaseCheckButtonTemplate") -bgs_EnableBNetAccountItems_Opt:SetPoint("TOPLEFT", 16, -381) -bgs_EnableBNetAccountItems_Opt:SetScript("OnClick", function(frame) - if BagSyncOpt then - if frame:GetChecked() then - PlaySound("igMainMenuOptionCheckBoxOn") - BagSyncOpt["enableBNetAccountItems"] = true - if BagSync then BagSync:resetTooltip() end - else - PlaySound("igMainMenuOptionCheckBoxOff") - BagSyncOpt["enableBNetAccountItems"] = false - if BagSync then BagSync:resetTooltip() end - end - end -end) -local bgs_EnableBNetAccountItems_OptText = bgs_EnableBNetAccountItems_Opt:CreateFontString(nil, "ARTWORK", "GameFontHighlight") -bgs_EnableBNetAccountItems_OptText:SetPoint("LEFT", bgs_EnableBNetAccountItems_Opt, "RIGHT", 0, 1) -bgs_EnableBNetAccountItems_OptText:SetText(L["Enable items for current Battle.Net Account characters. |cFFDF2B2B((Not Recommended))|r"]) \ No newline at end of file +local SO = LibStub("LibSimpleOptions-1.0") + +function BSOpt_Startup() + + local panel = SO.AddOptionsPanel("BagSync", function() end) + + local title, subText = panel:MakeTitleTextAndSubText("|cFF99CC33BagSync|r [|cFFDF2B2B"..ver.."|r]", "These options allow you to customize the BagSync displays data.") + + --toggle BagSync tooltips + panel:MakeToggle( + "name", L["Enable BagSync Tooltips"], + "description", "", + "default", false, + "getFunc", function() return BagSyncOpt["enableTooltips"] end, + "setFunc", function(value) + BagSyncOpt["enableTooltips"] = value + BagSync:resetTooltip() + end + ):SetPoint("TOPLEFT", subText, "BOTTOMLEFT", 0, -16) + + --tooltip seperator + panel:MakeToggle( + "name", L["Enable empty line seperator above BagSync tooltip display."], + "description", "", + "default", false, + "getFunc", function() return BagSyncOpt["enableTooltipSeperator"] end, + "setFunc", function(value) + BagSyncOpt["enableTooltipSeperator"] = value + BagSync:resetTooltip() + end + ):SetPoint("TOPLEFT", subText, "BOTTOMLEFT", 0, -41) + + --total + panel:MakeToggle( + "name", L["Display [Total] in tooltips and gold display."], + "description", "", + "default", false, + "getFunc", function() return BagSyncOpt["showTotal"] end, + "setFunc", function(value) + BagSyncOpt["showTotal"] = value + BagSync:resetTooltip() + end + ):SetPoint("TOPLEFT", subText, "BOTTOMLEFT", 0, -66) + + --guild names + panel:MakeToggle( + "name", L["Display [Guild Name] display in tooltips."], + "description", "", + "default", false, + "getFunc", function() return BagSyncOpt["showGuildNames"] end, + "setFunc", function(value) + BagSyncOpt["showGuildNames"] = value + BagSync:resetTooltip() + end + ):SetPoint("TOPLEFT", subText, "BOTTOMLEFT", 0, -91) + + --factions + panel:MakeToggle( + "name", L["Display items for both factions (Alliance/Horde)."], + "description", "", + "default", false, + "getFunc", function() return BagSyncOpt["enableFaction"] end, + "setFunc", function(value) + BagSyncOpt["enableFaction"] = value + BagSync:resetTooltip() + end + ):SetPoint("TOPLEFT", subText, "BOTTOMLEFT", 0, -116) + + --class colors + panel:MakeToggle( + "name", L["Display class colors for characters."], + "description", "", + "default", false, + "getFunc", function() return BagSyncOpt["enableUnitClass"] end, + "setFunc", function(value) + BagSyncOpt["enableUnitClass"] = value + BagSync:resetTooltip() + end + ):SetPoint("TOPLEFT", subText, "BOTTOMLEFT", 0, -141) + + --minimap + panel:MakeToggle( + "name", L["Display BagSync minimap button."], + "description", "", + "default", false, + "getFunc", function() return BagSyncOpt["enableMinimap"] end, + "setFunc", function(value) + BagSyncOpt["enableMinimap"] = value + if value then BagSync_MinimapButton:Show() else BagSync_MinimapButton:Hide() end + end + ):SetPoint("TOPLEFT", subText, "BOTTOMLEFT", 0, -166) + + --guild info + panel:MakeToggle( + "name", L["Enable guild bank items."], + "description", "", + "default", false, + "getFunc", function() return BagSyncOpt["enableGuild"] end, + "setFunc", function(value) + BagSyncOpt["enableGuild"] = value + BagSync:resetTooltip() + end + ):SetPoint("TOPLEFT", subText, "BOTTOMLEFT", 0, -191) + + --mailbox info + panel:MakeToggle( + "name", L["Enable mailbox items."], + "description", "", + "default", false, + "getFunc", function() return BagSyncOpt["enableMailbox"] end, + "setFunc", function(value) + BagSyncOpt["enableMailbox"] = value + BagSync:resetTooltip() + end + ):SetPoint("TOPLEFT", subText, "BOTTOMLEFT", 0, -216) + + --auction house + panel:MakeToggle( + "name", L["Enable auction house items."], + "description", "", + "default", false, + "getFunc", function() return BagSyncOpt["enableAuction"] end, + "setFunc", function(value) + BagSyncOpt["enableAuction"] = value + BagSync:resetTooltip() + end + ):SetPoint("TOPLEFT", subText, "BOTTOMLEFT", 0, -241) + + --tooltip only on bagsync search window + panel:MakeToggle( + "name", L["Display modified tooltips ONLY in the BagSync Search window."], + "description", "", + "default", false, + "getFunc", function() return BagSyncOpt["tooltipOnlySearch"] end, + "setFunc", function(value) + BagSyncOpt["tooltipOnlySearch"] = value + BagSync:resetTooltip() + end + ):SetPoint("TOPLEFT", subText, "BOTTOMLEFT", 0, -266) + + --cross realms + panel:MakeToggle( + "name", L["Enable items for Cross-Realms characters."], + "description", "", + "default", false, + "getFunc", function() return BagSyncOpt["enableCrossRealmsItems"] end, + "setFunc", function(value) + BagSyncOpt["enableCrossRealmsItems"] = value + BagSync:resetTooltip() + end + ):SetPoint("TOPLEFT", subText, "BOTTOMLEFT", 0, -291) + + --battle.net account characters + panel:MakeToggle( + "name", L["Enable items for current Battle.Net Account characters. |cFFDF2B2B((Not Recommended))|r"], + "description", "", + "default", false, + "getFunc", function() return BagSyncOpt["enableBNetAccountItems"] end, + "setFunc", function(value) + BagSyncOpt["enableBNetAccountItems"] = value + BagSync:resetTooltip() + end + ):SetPoint("TOPLEFT", subText, "BOTTOMLEFT", 0, -316) + + --first color (default moss) + panel:MakeColorPicker( + "name", L["Primary BagSync tooltip color."], + "description", "", + "hasAlpha", false, + "defaultR", 128/255, + "defaultG", 1, + "defaultB", 0, + "getFunc", function() return BagSyncOpt.colors.FIRST.r, BagSyncOpt.colors.FIRST.g, BagSyncOpt.colors.FIRST.b end, + "setFunc", function(r, g, b) BagSyncOpt.colors.FIRST.r, BagSyncOpt.colors.FIRST.g, BagSyncOpt.colors.FIRST.b = r, g, b end + ):SetPoint("TOPLEFT", subText, "BOTTOMLEFT", 0, -341) + + --second color (default silver) + panel:MakeColorPicker( + "name", L["Secondary BagSync tooltip color."], + "description", "", + "hasAlpha", false, + "defaultR", 199/255, + "defaultG", 199/255, + "defaultB", 207/255, + "getFunc", function() return BagSyncOpt.colors.SECOND.r, BagSyncOpt.colors.SECOND.g, BagSyncOpt.colors.SECOND.b end, + "setFunc", function(r, g, b) BagSyncOpt.colors.SECOND.r, BagSyncOpt.colors.SECOND.g, BagSyncOpt.colors.SECOND.b = r, g, b end + ):SetPoint("TOPLEFT", subText, "BOTTOMLEFT", 0, -366) + + --total color + panel:MakeColorPicker( + "name", L["BagSync [Total] tooltip color."], + "description", "", + "hasAlpha", false, + "defaultR", 244/255, + "defaultG", 164/255, + "defaultB", 96/255, + "getFunc", function() return BagSyncOpt.colors.TOTAL.r, BagSyncOpt.colors.TOTAL.g, BagSyncOpt.colors.TOTAL.b end, + "setFunc", function(r, g, b) BagSyncOpt.colors.TOTAL.r, BagSyncOpt.colors.TOTAL.g, BagSyncOpt.colors.TOTAL.b = r, g, b end + ):SetPoint("TOPLEFT", subText, "BOTTOMLEFT", 0, -391) + + --guild color + panel:MakeColorPicker( + "name", L["BagSync [Guild] tooltip color."], + "description", "", + "hasAlpha", false, + "defaultR", 101/255, + "defaultG", 184/255, + "defaultB", 192/255, + "getFunc", function() return BagSyncOpt.colors.GUILD.r, BagSyncOpt.colors.GUILD.g, BagSyncOpt.colors.GUILD.b end, + "setFunc", function(r, g, b) BagSyncOpt.colors.GUILD.r, BagSyncOpt.colors.GUILD.g, BagSyncOpt.colors.GUILD.b = r, g, b end + ):SetPoint("TOPLEFT", subText, "BOTTOMLEFT", 0, -416) + + --cross realm color + panel:MakeColorPicker( + "name", L["BagSync [Cross-Realms] tooltip color."], + "description", "", + "hasAlpha", false, + "defaultR", 1, + "defaultG", 125/255, + "defaultB", 10/255, + "getFunc", function() return BagSyncOpt.colors.CROSS.r, BagSyncOpt.colors.CROSS.g, BagSyncOpt.colors.CROSS.b end, + "setFunc", function(r, g, b) BagSyncOpt.colors.CROSS.r, BagSyncOpt.colors.CROSS.g, BagSyncOpt.colors.CROSS.b = r, g, b end + ):SetPoint("TOPLEFT", subText, "BOTTOMLEFT", 0, -441) + + --bnet color + panel:MakeColorPicker( + "name", L["BagSync [Battle.Net] tooltip color."], + "description", "", + "hasAlpha", false, + "defaultR", 53/255, + "defaultG", 136/255, + "defaultB", 1, + "getFunc", function() return BagSyncOpt.colors.BNET.r, BagSyncOpt.colors.BNET.g, BagSyncOpt.colors.BNET.b end, + "setFunc", function(r, g, b) BagSyncOpt.colors.BNET.r, BagSyncOpt.colors.BNET.g, BagSyncOpt.colors.BNET.b = r, g, b end + ):SetPoint("TOPLEFT", subText, "BOTTOMLEFT", 0, -466) + + + --i'm calling a refresh for the panel, because sometimes (like the color picker) some of the items aren't refreshed on the screen due to a /reload + --so instead I'm just going to force the getFunc for all the controls + panel:Refresh() + +end \ No newline at end of file diff --git a/BagSync_Crafts.lua b/BagSync_Crafts.lua index e5dc424..675dfe3 100644 --- a/BagSync_Crafts.lua +++ b/BagSync_Crafts.lua @@ -1,8 +1,8 @@ local L = BAGSYNC_L local craftsTable = {} local tRows, tAnchor = {} -local currentPlayer = UnitName('player') -local currentRealm = GetRealmName() +local currentPlayer = UnitName("player") +local currentRealm = select(2, UnitFullName("player")) local bgCrafts = CreateFrame("Frame","BagSync_CraftsFrame", UIParent) @@ -11,7 +11,7 @@ local function LoadSlider() local function OnEnter(self) if self.canLink and self.owner then GameTooltip:SetOwner(self, "ANCHOR_RIGHT") - GameTooltip:AddLine(format('|cFF99CC33%s|r', self.owner)) + GameTooltip:AddLine(format("|cFF99CC33%s|r", self.owner)) GameTooltip:AddLine(L["Left Click = Link to view tradeskill."]) GameTooltip:AddLine(L["Right Click = Insert tradeskill link."]) GameTooltip:Show() @@ -50,7 +50,7 @@ local function LoadSlider() row:SetScript("OnClick", function (self, button, down) if self.link then if button == "LeftButton" then - DEFAULT_CHAT_FRAME:AddMessage(format('%s|cFF99CC33%s|r ==> %s', L["Click to view profession: "], self.owner, self.link)) + DEFAULT_CHAT_FRAME:AddMessage(format("%s|cFF99CC33%s|r ==> %s", L["Click to view profession: "], self.owner, self.link)) else local editBox = ChatEdit_ChooseBoxForSend() @@ -76,9 +76,9 @@ local function LoadSlider() row.title:SetText("|cFFFFFFFF"..craftsTable[i + offset].name.."|r") else if craftsTable[i + offset].isLink then - row.title:SetText( format('|cFF99CC33%s|r |cFFFFFFFF(%s)|r', craftsTable[i + offset].name, craftsTable[i + offset].level)) + row.title:SetText( format("|cFF99CC33%s|r |cFFFFFFFF(%s)|r", craftsTable[i + offset].name, craftsTable[i + offset].level)) else - row.title:SetText( format('|cFF6699FF%s|r |cFFFFFFFF(%s)|r', craftsTable[i + offset].name, craftsTable[i + offset].level)) + row.title:SetText( format("|cFF6699FF%s|r |cFFFFFFFF(%s)|r", craftsTable[i + offset].name, craftsTable[i + offset].level)) end end @@ -148,7 +148,7 @@ local function DoCrafts() tmp = {} for q, r in pairs(v) do if type(r) == "string" then - local trName, trSkillLevel = strsplit(',', r) + local trName, trSkillLevel = strsplit(",", r) if trName and trSkillLevel then table.insert(tmp, { name=trName, level=trSkillLevel, isLink=false, owner=k} ) end diff --git a/BagSync_Profiles.lua b/BagSync_Profiles.lua index afb3ebe..8a92d9f 100644 --- a/BagSync_Profiles.lua +++ b/BagSync_Profiles.lua @@ -1,11 +1,11 @@ local L = BAGSYNC_L -local currentPlayer = UnitName('player') -local currentRealm = GetRealmName() +local currentPlayer = UnitName("player") +local currentRealm = select(2, UnitFullName("player")) local bgProfiles = CreateFrame("Frame","BagSync_ProfilesFrame", UIParent) --lets do the dropdown menu of DOOM local bgsProfilesDD = CreateFrame("Frame", "bgsProfilesDD") -bgsProfilesDD.displayMode = 'MENU' +bgsProfilesDD.displayMode = "MENU" local function addButton(level, text, isTitle, notCheckable, hasArrow, value, func) local info = UIDropDownMenu_CreateInfo() @@ -31,7 +31,7 @@ bgsProfilesDD.initialize = function(self, level) table.sort(tmp, function(a,b) return (a < b) end) if level == 1 then - PlaySound('gsTitleOptionExit') + PlaySound("gsTitleOptionExit") for i=1, #tmp do addButton(level, tmp[i], nil, 1, nil, tmp[i], function(frame, ...) @@ -93,7 +93,7 @@ bgProfiles.toonName:SetBackdrop({ bgFile = "Interface\\Buttons\\WHITE8x8", }) bgProfiles.toonName:SetBackdropColor(0,1,0,0.25) -bgProfiles.toonName:SetScript("OnClick", function() ToggleDropDownMenu(1, nil, bgsProfilesDD, 'cursor', 0, 0) end) +bgProfiles.toonName:SetScript("OnClick", function() ToggleDropDownMenu(1, nil, bgsProfilesDD, "cursor", 0, 0) end) bgProfiles.toonName.text = buttonText bgProfiles.deleteButton = CreateFrame("Button", nil, bgProfiles, "UIPanelButtonTemplate"); diff --git a/BagSync_Search.lua b/BagSync_Search.lua index d59df67..48e3d2a 100644 --- a/BagSync_Search.lua +++ b/BagSync_Search.lua @@ -1,20 +1,20 @@ local L = BAGSYNC_L local searchTable = {} local rows, anchor = {} -local currentRealm = GetRealmName() -local GetItemInfo = _G['GetItemInfo'] -local currentPlayer = UnitName('player') +local currentRealm = select(2, UnitFullName("player")) +local GetItemInfo = _G["GetItemInfo"] +local currentPlayer = UnitName("player") -local ItemSearch = LibStub('LibItemSearch-1.0') +local ItemSearch = LibStub("LibItemSearch-1.0") local bgSearch = CreateFrame("Frame","BagSync_SearchFrame", UIParent) --add class search -local tooltipScanner = _G['LibItemSearchTooltipScanner'] or CreateFrame('GameTooltip', 'LibItemSearchTooltipScanner', UIParent, 'GameTooltipTemplate') +local tooltipScanner = _G["LibItemSearchTooltipScanner"] or CreateFrame("GameTooltip", "LibItemSearchTooltipScanner", UIParent, "GameTooltipTemplate") local tooltipCache = setmetatable({}, {__index = function(t, k) local v = {} t[k] = v return v end}) ItemSearch:RegisterTypedSearch{ - id = 'classRestriction', - tags = {'c', 'class'}, + id = "classRestriction", + tags = {"c", "class"}, canSearch = function(self, _, search) return search @@ -23,7 +23,7 @@ ItemSearch:RegisterTypedSearch{ findItem = function(self, link, _, search) if link:find("battlepet") then return false end - local itemID = link:match('item:(%d+)') + local itemID = link:match("item:(%d+)") if not itemID then return end @@ -33,7 +33,7 @@ ItemSearch:RegisterTypedSearch{ return cachedResult end - tooltipScanner:SetOwner(UIParent, 'ANCHOR_NONE') + tooltipScanner:SetOwner(UIParent, "ANCHOR_NONE") tooltipScanner:SetHyperlink(link) local result = false @@ -41,7 +41,7 @@ ItemSearch:RegisterTypedSearch{ local pattern = string.gsub(ITEM_CLASSES_ALLOWED:lower(), "%%s", "(.+)") for i = 1, tooltipScanner:NumLines() do - local text = _G[tooltipScanner:GetName() .. 'TextLeft' .. i]:GetText():lower() + local text = _G[tooltipScanner:GetName() .. "TextLeft" .. i]:GetText():lower() local textChk = string.find(text, pattern) if textChk and tostring(text):find(search) then @@ -117,7 +117,7 @@ local function LoadSlider() if searchTable[i + offset].rarity then --local hex = (select(4, GetItemQualityColor(searchTable[i + offset].rarity))) local hex = (select(4, GetItemQualityColor(searchTable[i + offset].rarity))) - row.title:SetText(format('|c%s%s|r', hex, searchTable[i + offset].name) or searchTable[i + offset].name) + row.title:SetText(format("|c%s%s|r", hex, searchTable[i + offset].name) or searchTable[i + offset].name) else row.title:SetText(searchTable[i + offset].name) end @@ -199,7 +199,7 @@ local function DoSearch() for k, v in pairs(xDB) do local pFaction = v.faction or playerFaction --just in case ;) if we dont know the faction yet display it anyways - local yName, yRealm = strsplit('^', k) + local yName, yRealm = strsplit("^", k) --check if we should show both factions or not if BagSyncOpt.enableFaction or pFaction == playerFaction then @@ -214,7 +214,7 @@ local function DoSearch() --slotID = slotid for specific bagid, itemValue = data of specific slotid if type(bagInfo) == "table" then for slotID, itemValue in pairs(bagInfo) do - local dblink, dbcount = strsplit(',', itemValue) + local dblink, dbcount = strsplit(",", itemValue) if dblink then local dName, dItemLink, dRarity = GetItemInfo(dblink) if dName and dItemLink then @@ -249,7 +249,7 @@ local function DoSearch() if not previousGuilds[gName] then --we only really need to see this information once per guild for q, r in pairs(BagSyncGUILD_DB[v.realm][guildN]) do - local dblink, dbcount = strsplit(',', r) + local dblink, dbcount = strsplit(",", r) if dblink then local dName, dItemLink, dRarity = GetItemInfo(dblink) if dName then diff --git a/BagSync_Tokens.lua b/BagSync_Tokens.lua index 3297881..626ba3f 100644 --- a/BagSync_Tokens.lua +++ b/BagSync_Tokens.lua @@ -1,23 +1,25 @@ local L = BAGSYNC_L local tokensTable = {} local tRows, tAnchor = {} -local currentPlayer = UnitName('player') -local currentRealm = GetRealmName() -local GetItemInfo = _G['GetItemInfo'] -local SILVER = '|cffc7c7cf%s|r' -local MOSS = '|cFF80FF00%s|r' +local currentPlayer = UnitName("player") +local currentRealm = select(2, UnitFullName("player")) +local GetItemInfo = _G["GetItemInfo"] local bgTokens = CreateFrame("Frame","BagSync_TokensFrame", UIParent) +local function tooltipColor(color, str) + return string.format("|cff%02x%02x%02x%s|r", (color.r or 1) * 255, (color.g or 1) * 255, (color.b or 1) * 255, str) +end + local function LoadSlider() local function OnEnter(self) if self.name and self.tooltip then GameTooltip:SetOwner(self, "ANCHOR_RIGHT") GameTooltip:AddLine(self.name) - GameTooltip:AddLine(' ') + GameTooltip:AddLine(" ") for i=1, #self.tooltip do - GameTooltip:AddDoubleLine(format(MOSS, self.tooltip[i].name), format(SILVER, self.tooltip[i].count)) + GameTooltip:AddDoubleLine(tooltipColor(BagSyncOpt.colors.FIRST, self.tooltip[i].name), tooltipColor(BagSyncOpt.colors.SECOND, self.tooltip[i].count)) end GameTooltip:Show() end diff --git a/libs/CallbackHandler-1.0.lua b/libs/CallbackHandler-1.0.lua deleted file mode 100644 index 5ad658f..0000000 --- a/libs/CallbackHandler-1.0.lua +++ /dev/null @@ -1,239 +0,0 @@ ---[[ $Id: CallbackHandler-1.0.lua 60548 2008-02-07 11:04:06Z nevcairiel $ ]] -local MAJOR, MINOR = "CallbackHandler-1.0", 3 -local CallbackHandler = LibStub:NewLibrary(MAJOR, MINOR) - -if not CallbackHandler then return end -- No upgrade needed - -local meta = {__index = function(tbl, key) tbl[key] = {} return tbl[key] end} - -local type = type -local pcall = pcall -local pairs = pairs -local assert = assert -local concat = table.concat -local loadstring = loadstring -local next = next -local select = select -local type = type -local xpcall = xpcall - -local function errorhandler(err) - return geterrorhandler()(err) -end - -local function CreateDispatcher(argCount) - local code = [[ - local next, xpcall, eh = ... - - local method, ARGS - local function call() method(ARGS) end - - local function dispatch(handlers, ...) - local index - index, method = next(handlers) - if not method then return end - local OLD_ARGS = ARGS - ARGS = ... - repeat - xpcall(call, eh) - index, method = next(handlers, index) - until not method - ARGS = OLD_ARGS - end - - return dispatch - ]] - - local ARGS, OLD_ARGS = {}, {} - for i = 1, argCount do ARGS[i], OLD_ARGS[i] = "arg"..i, "old_arg"..i end - code = code:gsub("OLD_ARGS", concat(OLD_ARGS, ", ")):gsub("ARGS", concat(ARGS, ", ")) - return assert(loadstring(code, "safecall Dispatcher["..argCount.."]"))(next, xpcall, errorhandler) -end - -local Dispatchers = setmetatable({}, {__index=function(self, argCount) - local dispatcher = CreateDispatcher(argCount) - rawset(self, argCount, dispatcher) - return dispatcher -end}) - --------------------------------------------------------------------------- --- CallbackHandler:New --- --- target - target object to embed public APIs in --- RegisterName - name of the callback registration API, default "RegisterCallback" --- UnregisterName - name of the callback unregistration API, default "UnregisterCallback" --- UnregisterAllName - name of the API to unregister all callbacks, default "UnregisterAllCallbacks". false == don't publish this API. - -function CallbackHandler:New(target, RegisterName, UnregisterName, UnregisterAllName, OnUsed, OnUnused) - -- TODO: Remove this after beta has gone out - assert(not OnUsed and not OnUnused, "ACE-80: OnUsed/OnUnused are deprecated. Callbacks are now done to registry.OnUsed and registry.OnUnused") - - RegisterName = RegisterName or "RegisterCallback" - UnregisterName = UnregisterName or "UnregisterCallback" - if UnregisterAllName==nil then -- false is used to indicate "don't want this method" - UnregisterAllName = "UnregisterAllCallbacks" - end - - -- we declare all objects and exported APIs inside this closure to quickly gain access - -- to e.g. function names, the "target" parameter, etc - - - -- Create the registry object - local events = setmetatable({}, meta) - local registry = { recurse=0, events=events } - - -- registry:Fire() - fires the given event/message into the registry - function registry:Fire(eventname, ...) - if not rawget(events, eventname) or not next(events[eventname]) then return end - local oldrecurse = registry.recurse - registry.recurse = oldrecurse + 1 - - Dispatchers[select('#', ...) + 1](events[eventname], eventname, ...) - - registry.recurse = oldrecurse - - if registry.insertQueue and oldrecurse==0 then - -- Something in one of our callbacks wanted to register more callbacks; they got queued - for eventname,callbacks in pairs(registry.insertQueue) do - local first = not rawget(events, eventname) or not next(events[eventname]) -- test for empty before. not test for one member after. that one member may have been overwritten. - for self,func in pairs(callbacks) do - events[eventname][self] = func - -- fire OnUsed callback? - if first and registry.OnUsed then - registry.OnUsed(registry, target, eventname) - first = nil - end - end - end - registry.insertQueue = nil - end - end - - -- Registration of a callback, handles: - -- self["method"], leads to self["method"](self, ...) - -- self with function ref, leads to functionref(...) - -- "addonId" (instead of self) with function ref, leads to functionref(...) - -- all with an optional arg, which, if present, gets passed as first argument (after self if present) - target[RegisterName] = function(self, eventname, method, ... --[[actually just a single arg]]) - if type(eventname) ~= "string" then - error("Usage: "..RegisterName.."(eventname, method[, arg]): 'eventname' - string expected.", 2) - end - - method = method or eventname - - local first = not rawget(events, eventname) or not next(events[eventname]) -- test for empty before. not test for one member after. that one member may have been overwritten. - - if type(method) ~= "string" and type(method) ~= "function" then - error("Usage: "..RegisterName.."(\"eventname\", \"methodname\"): 'methodname' - string or function expected.", 2) - end - - local regfunc - - if type(method) == "string" then - -- self["method"] calling style - if type(self) ~= "table" then - error("Usage: "..RegisterName.."(\"eventname\", \"methodname\"): self was not a table?", 2) - elseif self==target then - error("Usage: "..RegisterName.."(\"eventname\", \"methodname\"): do not use Library:"..RegisterName.."(), use your own 'self'", 2) - elseif type(self[method]) ~= "function" then - error("Usage: "..RegisterName.."(\"eventname\", \"methodname\"): 'methodname' - method '"..tostring(method).."' not found on self.", 2) - end - - if select("#",...)>=1 then -- this is not the same as testing for arg==nil! - local arg=select(1,...) - regfunc = function(...) self[method](self,arg,...) end - else - regfunc = function(...) self[method](self,...) end - end - else - -- function ref with self=object or self="addonId" - if type(self)~="table" and type(self)~="string" then - error("Usage: "..RegisterName.."(self or \"addonId\", eventname, method): 'self or addonId': table or string expected.", 2) - end - - if select("#",...)>=1 then -- this is not the same as testing for arg==nil! - local arg=select(1,...) - regfunc = function(...) method(arg,...) end - else - regfunc = method - end - end - - - if events[eventname][self] or registry.recurse<1 then - -- if registry.recurse<1 then - -- we're overwriting an existing entry, or not currently recursing. just set it. - events[eventname][self] = regfunc - -- fire OnUsed callback? - if registry.OnUsed and first then - registry.OnUsed(registry, target, eventname) - end - else - -- we're currently processing a callback in this registry, so delay the registration of this new entry! - -- yes, we're a bit wasteful on garbage, but this is a fringe case, so we're picking low implementation overhead over garbage efficiency - registry.insertQueue = registry.insertQueue or setmetatable({},meta) - registry.insertQueue[eventname][self] = regfunc - end - end - - -- Unregister a callback - target[UnregisterName] = function(self, eventname) - if not self or self==target then - error("Usage: "..UnregisterName.."(eventname): bad 'self'", 2) - end - if type(eventname) ~= "string" then - error("Usage: "..UnregisterName.."(eventname): 'eventname' - string expected.", 2) - end - if rawget(events, eventname) and events[eventname][self] then - events[eventname][self] = nil - -- Fire OnUnused callback? - if registry.OnUnused and not next(events[eventname]) then - registry.OnUnused(registry, target, eventname) - end - end - if registry.insertQueue and rawget(registry.insertQueue, eventname) and registry.insertQueue[eventname][self] then - registry.insertQueue[eventname][self] = nil - end - end - - -- OPTIONAL: Unregister all callbacks for given selfs/addonIds - if UnregisterAllName then - target[UnregisterAllName] = function(...) - if select("#",...)<1 then - error("Usage: "..UnregisterAllName.."([whatFor]): missing 'self' or \"addonId\" to unregister events for.", 2) - end - if select("#",...)==1 and ...==target then - error("Usage: "..UnregisterAllName.."([whatFor]): supply a meaningful 'self' or \"addonId\"", 2) - end - - - for i=1,select("#",...) do - local self = select(i,...) - if registry.insertQueue then - for eventname, callbacks in pairs(registry.insertQueue) do - if callbacks[self] then - callbacks[self] = nil - end - end - end - for eventname, callbacks in pairs(events) do - if callbacks[self] then - callbacks[self] = nil - -- Fire OnUnused callback? - if registry.OnUnused and not next(callbacks) then - registry.OnUnused(registry, target, eventname) - end - end - end - end - end - end - - return registry -end - - --- CallbackHandler purposefully does NOT do explicit embedding. Nor does it --- try to upgrade old implicit embeds since the system is selfcontained and --- relies on closures to work. - diff --git a/libs/CallbackHandler-1.0/CallbackHandler-1.0.lua b/libs/CallbackHandler-1.0/CallbackHandler-1.0.lua new file mode 100644 index 0000000..2a64013 --- /dev/null +++ b/libs/CallbackHandler-1.0/CallbackHandler-1.0.lua @@ -0,0 +1,238 @@ +--[[ $Id: CallbackHandler-1.0.lua 18 2014-10-16 02:52:20Z mikk $ ]] +local MAJOR, MINOR = "CallbackHandler-1.0", 6 +local CallbackHandler = LibStub:NewLibrary(MAJOR, MINOR) + +if not CallbackHandler then return end -- No upgrade needed + +local meta = {__index = function(tbl, key) tbl[key] = {} return tbl[key] end} + +-- Lua APIs +local tconcat = table.concat +local assert, error, loadstring = assert, error, loadstring +local setmetatable, rawset, rawget = setmetatable, rawset, rawget +local next, select, pairs, type, tostring = next, select, pairs, type, tostring + +-- Global vars/functions that we don't upvalue since they might get hooked, or upgraded +-- List them here for Mikk's FindGlobals script +-- GLOBALS: geterrorhandler + +local xpcall = xpcall + +local function errorhandler(err) + return geterrorhandler()(err) +end + +local function CreateDispatcher(argCount) + local code = [[ + local next, xpcall, eh = ... + + local method, ARGS + local function call() method(ARGS) end + + local function dispatch(handlers, ...) + local index + index, method = next(handlers) + if not method then return end + local OLD_ARGS = ARGS + ARGS = ... + repeat + xpcall(call, eh) + index, method = next(handlers, index) + until not method + ARGS = OLD_ARGS + end + + return dispatch + ]] + + local ARGS, OLD_ARGS = {}, {} + for i = 1, argCount do ARGS[i], OLD_ARGS[i] = "arg"..i, "old_arg"..i end + code = code:gsub("OLD_ARGS", tconcat(OLD_ARGS, ", ")):gsub("ARGS", tconcat(ARGS, ", ")) + return assert(loadstring(code, "safecall Dispatcher["..argCount.."]"))(next, xpcall, errorhandler) +end + +local Dispatchers = setmetatable({}, {__index=function(self, argCount) + local dispatcher = CreateDispatcher(argCount) + rawset(self, argCount, dispatcher) + return dispatcher +end}) + +-------------------------------------------------------------------------- +-- CallbackHandler:New +-- +-- target - target object to embed public APIs in +-- RegisterName - name of the callback registration API, default "RegisterCallback" +-- UnregisterName - name of the callback unregistration API, default "UnregisterCallback" +-- UnregisterAllName - name of the API to unregister all callbacks, default "UnregisterAllCallbacks". false == don't publish this API. + +function CallbackHandler:New(target, RegisterName, UnregisterName, UnregisterAllName) + + RegisterName = RegisterName or "RegisterCallback" + UnregisterName = UnregisterName or "UnregisterCallback" + if UnregisterAllName==nil then -- false is used to indicate "don't want this method" + UnregisterAllName = "UnregisterAllCallbacks" + end + + -- we declare all objects and exported APIs inside this closure to quickly gain access + -- to e.g. function names, the "target" parameter, etc + + + -- Create the registry object + local events = setmetatable({}, meta) + local registry = { recurse=0, events=events } + + -- registry:Fire() - fires the given event/message into the registry + function registry:Fire(eventname, ...) + if not rawget(events, eventname) or not next(events[eventname]) then return end + local oldrecurse = registry.recurse + registry.recurse = oldrecurse + 1 + + Dispatchers[select('#', ...) + 1](events[eventname], eventname, ...) + + registry.recurse = oldrecurse + + if registry.insertQueue and oldrecurse==0 then + -- Something in one of our callbacks wanted to register more callbacks; they got queued + for eventname,callbacks in pairs(registry.insertQueue) do + local first = not rawget(events, eventname) or not next(events[eventname]) -- test for empty before. not test for one member after. that one member may have been overwritten. + for self,func in pairs(callbacks) do + events[eventname][self] = func + -- fire OnUsed callback? + if first and registry.OnUsed then + registry.OnUsed(registry, target, eventname) + first = nil + end + end + end + registry.insertQueue = nil + end + end + + -- Registration of a callback, handles: + -- self["method"], leads to self["method"](self, ...) + -- self with function ref, leads to functionref(...) + -- "addonId" (instead of self) with function ref, leads to functionref(...) + -- all with an optional arg, which, if present, gets passed as first argument (after self if present) + target[RegisterName] = function(self, eventname, method, ... --[[actually just a single arg]]) + if type(eventname) ~= "string" then + error("Usage: "..RegisterName.."(eventname, method[, arg]): 'eventname' - string expected.", 2) + end + + method = method or eventname + + local first = not rawget(events, eventname) or not next(events[eventname]) -- test for empty before. not test for one member after. that one member may have been overwritten. + + if type(method) ~= "string" and type(method) ~= "function" then + error("Usage: "..RegisterName.."(\"eventname\", \"methodname\"): 'methodname' - string or function expected.", 2) + end + + local regfunc + + if type(method) == "string" then + -- self["method"] calling style + if type(self) ~= "table" then + error("Usage: "..RegisterName.."(\"eventname\", \"methodname\"): self was not a table?", 2) + elseif self==target then + error("Usage: "..RegisterName.."(\"eventname\", \"methodname\"): do not use Library:"..RegisterName.."(), use your own 'self'", 2) + elseif type(self[method]) ~= "function" then + error("Usage: "..RegisterName.."(\"eventname\", \"methodname\"): 'methodname' - method '"..tostring(method).."' not found on self.", 2) + end + + if select("#",...)>=1 then -- this is not the same as testing for arg==nil! + local arg=select(1,...) + regfunc = function(...) self[method](self,arg,...) end + else + regfunc = function(...) self[method](self,...) end + end + else + -- function ref with self=object or self="addonId" or self=thread + if type(self)~="table" and type(self)~="string" and type(self)~="thread" then + error("Usage: "..RegisterName.."(self or \"addonId\", eventname, method): 'self or addonId': table or string or thread expected.", 2) + end + + if select("#",...)>=1 then -- this is not the same as testing for arg==nil! + local arg=select(1,...) + regfunc = function(...) method(arg,...) end + else + regfunc = method + end + end + + + if events[eventname][self] or registry.recurse<1 then + -- if registry.recurse<1 then + -- we're overwriting an existing entry, or not currently recursing. just set it. + events[eventname][self] = regfunc + -- fire OnUsed callback? + if registry.OnUsed and first then + registry.OnUsed(registry, target, eventname) + end + else + -- we're currently processing a callback in this registry, so delay the registration of this new entry! + -- yes, we're a bit wasteful on garbage, but this is a fringe case, so we're picking low implementation overhead over garbage efficiency + registry.insertQueue = registry.insertQueue or setmetatable({},meta) + registry.insertQueue[eventname][self] = regfunc + end + end + + -- Unregister a callback + target[UnregisterName] = function(self, eventname) + if not self or self==target then + error("Usage: "..UnregisterName.."(eventname): bad 'self'", 2) + end + if type(eventname) ~= "string" then + error("Usage: "..UnregisterName.."(eventname): 'eventname' - string expected.", 2) + end + if rawget(events, eventname) and events[eventname][self] then + events[eventname][self] = nil + -- Fire OnUnused callback? + if registry.OnUnused and not next(events[eventname]) then + registry.OnUnused(registry, target, eventname) + end + end + if registry.insertQueue and rawget(registry.insertQueue, eventname) and registry.insertQueue[eventname][self] then + registry.insertQueue[eventname][self] = nil + end + end + + -- OPTIONAL: Unregister all callbacks for given selfs/addonIds + if UnregisterAllName then + target[UnregisterAllName] = function(...) + if select("#",...)<1 then + error("Usage: "..UnregisterAllName.."([whatFor]): missing 'self' or \"addonId\" to unregister events for.", 2) + end + if select("#",...)==1 and ...==target then + error("Usage: "..UnregisterAllName.."([whatFor]): supply a meaningful 'self' or \"addonId\"", 2) + end + + + for i=1,select("#",...) do + local self = select(i,...) + if registry.insertQueue then + for eventname, callbacks in pairs(registry.insertQueue) do + if callbacks[self] then + callbacks[self] = nil + end + end + end + for eventname, callbacks in pairs(events) do + if callbacks[self] then + callbacks[self] = nil + -- Fire OnUnused callback? + if registry.OnUnused and not next(callbacks) then + registry.OnUnused(registry, target, eventname) + end + end + end + end + end + end + + return registry +end + + +-- CallbackHandler purposefully does NOT do explicit embedding. Nor does it +-- try to upgrade old implicit embeds since the system is selfcontained and +-- relies on closures to work. + diff --git a/libs/CallbackHandler-1.0/CallbackHandler-1.0.xml b/libs/CallbackHandler-1.0/CallbackHandler-1.0.xml new file mode 100644 index 0000000..876df83 --- /dev/null +++ b/libs/CallbackHandler-1.0/CallbackHandler-1.0.xml @@ -0,0 +1,4 @@ + +