diff --git a/Bagnon_Forever/db.lua b/Bagnon_Forever/db.lua index cbd2a01..cadfbe4 100644 --- a/Bagnon_Forever/db.lua +++ b/Bagnon_Forever/db.lua @@ -12,6 +12,8 @@ BagnonDB:SetScript('OnEvent', function(self, event, arg1) end) BagnonDB:RegisterEvent('ADDON_LOADED') +ASC_PERSONAL_BANK_OFFSET = 1000; + --constants local L = BAGNON_FOREVER_LOCALS local CURRENT_VERSION = GetAddOnMetadata('Bagnon_Forever', 'Version') @@ -40,6 +42,10 @@ end local function ToShortLink(link) if link then local a,b,c,d,e,f,g,h = link:match('(%-?%d+):(%-?%d+):(%-?%d+):(%-?%d+):(%-?%d+):(%-?%d+):(%-?%d+):(%-?%d+)') + + --ASC sets this to unique id in the personal bank, clear it + c = 0; + if(b == '0' and b == c and c == d and d == e and e == f and f == g) then return a end @@ -51,6 +57,11 @@ local function GetBagSize(bag) if bag == KEYRING_CONTAINER then return GetKeyRingSize() end + + if (bag >= ASC_PERSONAL_BANK_OFFSET) then + return 98 + end + if bag == 'e' then return NUM_EQUIPMENT_SLOTS end @@ -124,6 +135,10 @@ function BagnonDB:PLAYER_LOGIN() self:SaveEquipment() self:SaveNumBankSlots() + + self:RegisterEvent('GUILDBANKFRAME_OPENED') + self:RegisterEvent('GUILDBANKFRAME_CLOSED') + self:RegisterEvent('GUILDBANKBAGSLOTS_CHANGED') self:RegisterEvent('BANKFRAME_OPENED') self:RegisterEvent('BANKFRAME_CLOSED') self:RegisterEvent('PLAYER_MONEY') @@ -164,6 +179,48 @@ function BagnonDB:BANKFRAME_CLOSED() self.atBank = nil end + + +function BagnonDB:GUILDBANKFRAME_OPENED() + if HasJsonCacheData("BANK_PERMISSIONS_PAYLOAD", 0) then + local json = GetJsonCacheData("BANK_PERMISSIONS_PAYLOAD", 0) + if json then + local jsonObject = C_Serialize:FromJSON(json) + if jsonObject then + self.IsPersonalBank = jsonObject.IsPersonalBank + self.IsRealmBank = jsonObject.IsRealmBank + end + end + end + + + if (self.IsPersonalBank) then + for i = 1, 6 do + local avail = GetGuildBankTabInfo(i) + if type(avail) == "string" then + self:UpdateBag(i + ASC_PERSONAL_BANK_OFFSET) + end + end + end +end + +function BagnonDB:GUILDBANKFRAME_CLOSED() + self.IsPersonalBank = nil + self.IsRealmBank = nil +end + +function BagnonDB:GUILDBANKBAGSLOTS_CHANGED() + if (self.IsPersonalBank) then + for i = 1, 6 do + local avail = GetGuildBankTabInfo(i) + if type(avail) == "string" then + self:UpdateBag(i + ASC_PERSONAL_BANK_OFFSET) + end + end + end +end + + function BagnonDB:UNIT_INVENTORY_CHANGED(event, unit) if unit == 'player' then self:SaveEquipment() @@ -314,6 +371,11 @@ function BagnonDB:GetItemCount(itemLink, bag, player) local total = 0 local itemLink = select(2, GetItemInfo(ToShortLink(itemLink))) local size = (self:GetBagData(bag, player)) or 0 + + if (bag == "e") then + size = NUM_EQUIPMENT_SLOTS + end + for slot = 1, size do local link, count = self:GetItemData(bag, slot, player) if link == itemLink then @@ -350,7 +412,7 @@ function BagnonDB:SaveEquipment() local link = ToShortLink(link) local count = GetInventoryItemCount('player', slot) count = count > 1 and count or nil - + if(link and count) then self.pdb[index] = format('%s,%d', link, count) else @@ -364,48 +426,81 @@ end --saves data about a specific item the current player has function BagnonDB:SaveItem(bag, slot) - local texture, count = GetContainerItemInfo(bag, slot) - local index = ToIndex(bag, slot) - if texture then - local link = ToShortLink(GetContainerItemLink(bag, slot)) - count = count > 1 and count or nil + if (bag > ASC_PERSONAL_BANK_OFFSET) then + local texture, count = GetGuildBankItemInfo(bag - ASC_PERSONAL_BANK_OFFSET, slot) - if(link and count) then - self.pdb[index] = format('%s,%d', link, count) + local index = ToIndex(bag, slot) + + if texture then + local link = ToShortLink(GetGuildBankItemLink(bag - ASC_PERSONAL_BANK_OFFSET, slot)) + count = count > 1 and count or nil + if(link and count) then + self.pdb[index] = format('%s,%d', link, count) + else + self.pdb[index] = link + end else - self.pdb[index] = link + self.pdb[index] = nil end else - self.pdb[index] = nil + local texture, count = GetContainerItemInfo(bag, slot) + + local index = ToIndex(bag, slot) + + if texture then + local link = ToShortLink(GetContainerItemLink(bag, slot)) + count = count > 1 and count or nil + + if(link and count) then + self.pdb[index] = format('%s,%d', link, count) + else + self.pdb[index] = link + end + else + self.pdb[index] = nil + end end + end --saves all information about the given bag, EXCEPT the bag's contents function BagnonDB:SaveBag(bag) local data = self.pdb - local size = GetBagSize(bag) - local index = ToBagIndex(bag) - if size > 0 then - local equipSlot = bag > 0 and ContainerIDToInventoryID(bag) - local link = ToShortLink(GetInventoryItemLink('player', equipSlot)) - local count = GetInventoryItemCount('player', equipSlot) - if count < 1 then - count = nil - end + if (bag >= ASC_PERSONAL_BANK_OFFSET) then + local size = GetBagSize(bag) + local index = ToBagIndex(bag) + self.pdb[index] = size + else + local size = GetBagSize(bag) + local index = ToBagIndex(bag) - if(size and link and count) then - self.pdb[index] = format('%d,%s,%d', size, link, count) - elseif(size and link) then - self.pdb[index] = format('%d,%s', size, link) + if size > 0 then + local equipSlot = bag > 0 and ContainerIDToInventoryID(bag) + local link = ToShortLink(GetInventoryItemLink('player', equipSlot)) + local count = GetInventoryItemCount('player', equipSlot) + if count < 1 then + count = nil + end + + if(size and link and count) then + self.pdb[index] = format('%d,%s,%d', size, link, count) + elseif(size and link) then + self.pdb[index] = format('%d,%s', size, link) + else + self.pdb[index] = size + end else - self.pdb[index] = size + self.pdb[index] = nil end - else - self.pdb[index] = nil + + end + + + end --saves both relevant information about the given bag, and all information about items in the given bag @@ -451,4 +546,4 @@ function BagnonDB:RemovePlayer(player, realm) end end end -end \ No newline at end of file +end diff --git a/Bagnon_Tooltips/localization/localization.lua b/Bagnon_Tooltips/localization/localization.lua index f0a31eb..0a91ef0 100644 --- a/Bagnon_Tooltips/localization/localization.lua +++ b/Bagnon_Tooltips/localization/localization.lua @@ -5,4 +5,5 @@ BAGNON_NUM_BAGS = 'Bags: %d' BAGNON_NUM_BANK = 'Bank: %d' -BAGNON_EQUIPPED = 'Equipped' \ No newline at end of file +BAGNON_EQUIPPED = 'Equipped' +BAGNON_NUM_PBANK = 'PBank: %d' diff --git a/Bagnon_Tooltips/tooltips.lua b/Bagnon_Tooltips/tooltips.lua index 30f238a..c14a210 100644 --- a/Bagnon_Tooltips/tooltips.lua +++ b/Bagnon_Tooltips/tooltips.lua @@ -8,9 +8,9 @@ local itemInfo = {} local SILVER = '|cffc7c7cf%s|r' local TEAL = '|cff00ff9a%s|r' -local function CountsToInfoString(invCount, bankCount, equipCount) +local function CountsToInfoString(invCount, bankCount, equipCount, pbankCount) local info - local total = invCount + bankCount + equipCount + local total = invCount + bankCount + equipCount + pbankCount if invCount > 0 then info = BAGNON_NUM_BAGS:format(invCount) @@ -24,6 +24,15 @@ local function CountsToInfoString(invCount, bankCount, equipCount) info = count end end + + if pbankCount > 0 then + local count = BAGNON_NUM_PBANK:format(pbankCount) + if info then + info = strjoin(', ', info, count) + else + info = count + end + end if equipCount > 0 then if info then @@ -57,10 +66,15 @@ do for i = 1, NUM_BANKBAGSLOTS do bankCount = bankCount + BagnonDB:GetItemCount(link, NUM_BAG_SLOTS + i, player) end + + local personalBankCount = 0 + for i = 1, 6 do + personalBankCount = personalBankCount + BagnonDB:GetItemCount(link, i + ASC_PERSONAL_BANK_OFFSET, player) + end local equipCount = BagnonDB:GetItemCount(link, 'e', player) - self[link] = CountsToInfoString(invCount or 0, bankCount or 0, equipCount or 0) or '' + self[link] = CountsToInfoString(invCount or 0, bankCount or 0, equipCount or 0, personalBankCount or 0) or '' return self[link] end}) end @@ -80,10 +94,15 @@ local function AddOwners(frame, link) for i = 1, NUM_BANKBAGSLOTS do bankCount = bankCount + BagnonDB:GetItemCount(link, NUM_BAG_SLOTS + i, player) end + + local personalBankCount = 0 + for i = 1, 6 do + personalBankCount = personalBankCount + BagnonDB:GetItemCount(link, i + ASC_PERSONAL_BANK_OFFSET, player) + end local equipCount = BagnonDB:GetItemCount(link, 'e', player) - infoString = CountsToInfoString(invCount or 0, bankCount or 0, equipCount or 0) + infoString = CountsToInfoString(invCount or 0, bankCount or 0, equipCount or 0, personalBankCount or 0) else infoString = itemInfo[player][link] end @@ -105,4 +124,4 @@ local function HookTip(tooltip) end HookTip(GameTooltip) -HookTip(ItemRefTooltip) \ No newline at end of file +HookTip(ItemRefTooltip)