Skip to content

Commit

Permalink
1.0.7
Browse files Browse the repository at this point in the history
Updated to use Baganator Skins system
Fixed issue that could cause fake log entries when items weren't cached
  • Loading branch information
Noshei committed Dec 14, 2024
1 parent 31859a4 commit 77761c4
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 107 deletions.
9 changes: 0 additions & 9 deletions Display.lua
Original file line number Diff line number Diff line change
Expand Up @@ -78,24 +78,15 @@ function WBL:InitializeDataProvider()
end

function WBL_API:Open()
if not WBL.Display.BaseFrame then
WBL:CreateDisplay()
end
WBL.Display.BaseFrame:Show()
WBL.Display.BaseFrame.Container.ScrollBox:SetScrollPercentage(100)
end

function WBL_API:Close()
if not WBL.Display.BaseFrame then
WBL:CreateDisplay()
end
WBL.Display.BaseFrame:Hide()
end

function WBL_API:Toggle()
if not WBL.Display.BaseFrame then
WBL:CreateDisplay()
end
if WBL.Display.BaseFrame:IsVisible() then
WBL_API:Close()
else
Expand Down
50 changes: 2 additions & 48 deletions Plugins/Plugins.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,55 +27,9 @@ EventUtil.ContinueOnAddOnLoaded("Baganator", function()
WBLButton.Icon:SetSize(30, 30)
elseif Baganator.API.Skins.GetCurrentSkin() ~= "blizzard" then
WBLButton:SetPoint("TOPLEFT", 1.5, -1.5)
WBLButton.Left:Hide()
WBLButton.Right:Hide()
WBLButton.Middle:Hide()
WBLButton:ClearHighlightTexture()

Mixin(WBLButton, BackdropTemplateMixin)
WBLButton:SetBackdrop({
bgFile = "Interface/AddOns/Baganator/Assets/Skins/dark-backgroundfile",
edgeFile = "Interface/AddOns/Baganator/Assets/Skins/dark-edgefile",
tile = true,
tileEdge = true,
tileSize = 32,
edgeSize = 6,
})
local color = { r = 0, g = 0, b = 0 }
WBLButton:SetBackdropColor(color.r, color.g, color.b, 0.5)
WBLButton:SetBackdropBorderColor(color.r, color.g, color.b, 1)
WBLButton:HookScript("OnEnter", function()
if WBLButton:IsEnabled() then
local r, g, b = 0.3, 0.3, 0.3
WBLButton:SetBackdropColor(r, g, b, 0.8)
WBLButton:SetBackdropBorderColor(r, g, b, 1)
end
end)
WBLButton:HookScript("OnMouseDown", function()
if WBLButton:IsEnabled() then
local r, g, b = 0.2, 0.2, 0.2
WBLButton:SetBackdropColor(r, g, b, 0.8)
WBLButton:SetBackdropBorderColor(r, g, b, 1)
end
end)
WBLButton:HookScript("OnMouseUp", function()
if WBLButton:IsEnabled() and WBLButton:IsMouseOver() then
local r, g, b = 0.3, 0.3, 0.3
WBLButton:SetBackdropColor(r, g, b, 0.8)
WBLButton:SetBackdropBorderColor(r, g, b, 1)
end
end)
WBLButton:HookScript("OnLeave", function()
WBLButton:SetBackdropColor(color.r, color.g, color.b, 0.5)
WBLButton:SetBackdropBorderColor(color.r, color.g, color.b, 1)
end)
WBLButton:HookScript("OnDisable", function()
WBLButton:SetBackdropColor(color.r, color.g, color.b, 0.1)
end)
WBLButton:HookScript("OnEnable", function()
WBLButton:SetBackdropColor(color.r, color.g, color.b, 0.5)
end)
Baganator.Skins.AddFrame("IconButton", WBLButton)
end

return WBLButton
end
Baganator.API.Skins.RegisterListener(CreateWBLButton)
Expand Down
14 changes: 1 addition & 13 deletions Plugins/Plugins.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<Ui xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.blizzard.com/wow/ui/" xsi:schemaLocation="http://www.blizzard.com/wow/ui/
https://raw.githubusercontent.com/Gethe/wow-ui-source/live/Interface/FrameXML/UI_shared.xsd">

<Button name="WBLBaganatorIcon" virtual="true" inherits="UIPanelButtonTemplate">
<Size x="32" y="22"/>
<Button name="WBLBaganatorIcon" virtual="true" inherits="BaganatorTooltipIconButtonTemplate">
<Layers>
<Layer level="ARTWORK">
<Texture parentKey="Icon" file="Interface\AddOns\Warband-Bank-Log\Media\Plugins\Scroll">
Expand All @@ -14,17 +13,6 @@ https://raw.githubusercontent.com/Gethe/wow-ui-source/live/Interface/FrameXML/UI
</Layer>
</Layers>
<Scripts>
<OnEnter>
GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
GameTooltip:SetText(self.tooltipHeader)
if self.tooltipText then
GameTooltip:AddLine(self.tooltipText, 1, 1, 1, true)
end
GameTooltip:Show()
</OnEnter>
<OnLeave>
GameTooltip:Hide()
</OnLeave>
<OnClick>
WBL_API:Toggle()
</OnClick>
Expand Down
102 changes: 66 additions & 36 deletions Warband-Bank-Log.lua
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,16 @@ local function tableDiff(oldTable, newTable)
diff[itemLink] = {}
diff[itemLink].stackCount = newTable[itemLink] - itemCount
if diff[itemLink].stackCount > 0 then
WBL:Debug("Table Diff: Added 1", 2, itemLink, itemCount, newTable[itemLink])
diff[itemLink].type = "added"
else
WBL:Debug("Table Diff: Removed 1", 2, itemLink, itemCount, newTable[itemLink])
diff[itemLink].type = "removed"
diff[itemLink].stackCount = math.abs(diff[itemLink].stackCount)
end
end
else
WBL:Debug("Table Diff: Removed 2", 3, itemLink, itemCount)
diff[itemLink] = {
type = "removed",
stackCount = itemCount
Expand All @@ -121,6 +124,7 @@ local function tableDiff(oldTable, newTable)

for itemLink, itemCount in pairs(newTable) do
if oldTable[itemLink] == nil then
WBL:Debug("Table Diff: Added 2", 3, itemLink, itemCount)
diff[itemLink] = {
type = "added",
stackCount = itemCount
Expand All @@ -146,23 +150,39 @@ end

function WBL:BANKFRAME_OPENED()
WBL.BankOpen = true
WBL:GetBankData()
WBL:GetBankContent("BANKFRAME_OPENED")
end

function WBL:GetBankData()
local tempBank = WBL:GetBankContent()
function WBL:BAG_UPDATE(event, bag)
if not bag then return end
if not WBL.BankOpen then return end
if bag < WarbankStart or bag > WarbankEnd then
return
end

WBL:GetBankContent("BAG_UPDATE")
WBL:Debug("BAG_UPDATE", 2, bag)
end

function WBL:GetBankData(tempBank, event)
local tempGold = WBL:GetBankGold()
local playerData = WBL:GetPlayerInfo()

if WBL:NeedToInitialize() then
WBL:InitializeData(tempBank, tempGold)
return
end
local diffs = tableDiff(WBL.Bank, tempBank)
WBL:UpdateChanges(diffs, tempBank, tempGold)

if WBL.db.profile.autoOpen then
WBL_API:Open()
local diffs = tableDiff(WBL.Bank, tempBank)
if event == "BANKFRAME_OPENED" then
playerData = nil
if WBL.db.profile.autoOpen then
WBL_API:Open()
end
end
WBL:UpdateChanges(diffs, tempBank, tempGold, playerData)
end
WBL:RegisterMessage("BankItemsLoaded", WBL.GetBankData)

function WBL:BANKFRAME_CLOSED()
WBL.BankOpen = false
Expand All @@ -171,22 +191,6 @@ function WBL:BANKFRAME_CLOSED()
end
end

function WBL:BAG_UPDATE(event, bag)
if not bag then return end
if not WBL.BankOpen then return end
if bag < WarbankStart or bag > WarbankEnd then
return
end

local tempBank = WBL:GetBankContent()
local tempGold = WBL:GetBankGold()
local diffs = tableDiff(WBL.Bank, tempBank)
local playerData = WBL:GetPlayerInfo()

WBL:Debug("BAG_UPDATE", 2, bag, playerData.name, playerData.realm, playerData.color, tempGold)
WBL:UpdateChanges(diffs, tempBank, tempGold, playerData)
end

function WBL:ACCOUNT_MONEY()
local tempGold = WBL:GetBankGold()
local playerData = WBL:GetPlayerInfo()
Expand All @@ -208,23 +212,49 @@ end

---Gets the contents of the Warband Bank and returns a temporary table that will be used to compare to cached data
---see https://warcraft.wiki.gg/wiki/BagID bag ID's that are used for initial loop values
---@return table
function WBL:GetBankContent()
local tempBank = {}
function WBL:GetBankContent(event)
local items = {}
local continuableContainer = ContinuableContainer:Create()
for bag = WarbankStart, WarbankEnd do
for slot = 1, C_Container.GetContainerNumSlots(bag) do
local itemInfo = C_Container.GetContainerItemInfo(bag, slot)

if itemInfo then
local chunks = strsplittable(":", itemInfo.hyperlink)
chunks[10] = ""
chunks[11] = ""
local link = table.concat(chunks, ":")
tempBank[link] = (tempBank[link] or 0) + itemInfo.stackCount
local item = Item:CreateFromBagAndSlot(bag, slot)
if not item:IsItemEmpty() then
table.insert(items, item)
continuableContainer:AddContinuable(item)

--[[if not C_Item.IsItemDataCachedByID(itemInfo.itemID) then
local item = Item:CreateFromBagAndSlot(bag, slot)
item:ContinueOnItemLoad(function()
output("Loaded item")
local chunks = strsplittable(":", item:GetItemLink())
chunks[10] = ""
chunks[11] = ""
local link = table.concat(chunks, ":")
tempBank[link] = (tempBank[link] or 0) + item:GetStackCount()
end)
else
output("Cached item")
local chunks = strsplittable(":", itemInfo.hyperlink)
chunks[10] = ""
chunks[11] = ""
local link = table.concat(chunks, ":")
tempBank[link] = (tempBank[link] or 0) + itemInfo.stackCount
end]]
end
end
end
return tempBank
continuableContainer:ContinueOnLoad(function()
local tempBank = {}
for _, item in ipairs(items) do
WBL:Debug("Get Bank Content", 3, item:GetItemLink())
local chunks = strsplittable(":", item:GetItemLink())
chunks[10] = ""
chunks[11] = ""
local link = table.concat(chunks, ":")
tempBank[link] = (tempBank[link] or 0) + item:GetStackCount()
end
WBL:SendMessage("BankItemsLoaded", tempBank, event)
end)
end

---@return number bankGold
Expand Down Expand Up @@ -307,5 +337,5 @@ function WBL:AddLogEntry(itemLink, itemType, itemData, playerData)
table.insert(WBL.Logs, logEntry)
WBL.DataProvider:Insert(logEntry)
WBL.Display.BaseFrame.Container.ScrollBox:SetScrollPercentage(100)
WBL:Debug("added Log", 1, logEntry)
WBL:Debug("added Log", 1, logEntry.name, logEntry.changeType, logEntry.link)
end
2 changes: 1 addition & 1 deletion Warband-Bank-Log.toc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
## Title: Warband Bank Log
## Notes: Provides a log of which character added or removed items/gold from the Warband Bank
## Author: Noshei
## Version: 1.0.6
## Version: 1.0.7
## SavedVariables: WarbandBankLogDB, WarbandBankLogSettings
## AddonCompartmentFunc: WarbandBankLog_OnAddonCompartmentClick
## IconTexture: 1505935
Expand Down

0 comments on commit 77761c4

Please sign in to comment.