Skip to content

Commit

Permalink
Wrath support, fixes, currency overhaul (#656)
Browse files Browse the repository at this point in the history
* Fixed several bugs in Classic related to item quality.

* Complete overhaul of the currency frame.

Currencies can now be stacked into columns.

Currencies now show tooltips on each currency.

* Prevent swapped equipment from showing up as new.

* Changed CURSOR_UPDATE to CURSOR_CHANGED to fix WotLK
  • Loading branch information
Cidan authored Aug 25, 2022
1 parent ebddb57 commit f7c82c3
Show file tree
Hide file tree
Showing 11 changed files with 200 additions and 36 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,8 @@ jobs:
- name: Package and release TBC
uses: BigWigsMods/[email protected]
with:
args: -g bcc
args: -g bcc
- name: Package and release Wrath
uses: BigWigsMods/[email protected]
with:
args: -g wrath
1 change: 1 addition & 0 deletions AdiBags.toc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
## Interface-Retail: 90207
## Interface-Classic: 11403
## Interface-BCC: 20504
## Interface-Wrath: 30400

## Title: AdiBags
## Notes: Adirelle's bag addon.
Expand Down
1 change: 1 addition & 0 deletions AdiBags_Config/AdiBags_Config.toc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
## Interface-Retail: 90207
## Interface-Classic: 11403
## Interface-BCC: 20504
## Interface-Wrath: 30400

## Title: AdiBags Configuration
## Notes: Adirelle's bag addon.
Expand Down
2 changes: 1 addition & 1 deletion core/Constants.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ local L = addon.L
addon.isRetail = WOW_PROJECT_ID == WOW_PROJECT_MAINLINE
addon.isClassic = WOW_PROJECT_ID == WOW_PROJECT_CLASSIC
addon.isBCC = WOW_PROJECT_ID == WOW_PROJECT_BURNING_CRUSADE_CLASSIC and LE_EXPANSION_LEVEL_CURRENT == LE_EXPANSION_BURNING_CRUSADE
addon.isWOTLK = WOW_PROJECT_ID == WOW_PROJECT_BURNING_CRUSADE_CLASSIC and LE_EXPANSION_LEVEL_CURRENT == LE_EXPANSION_NORTHREND
addon.isWrath = WOW_PROJECT_ID == WOW_PROJECT_BURNING_CRUSADE_CLASSIC and LE_EXPANSION_LEVEL_CURRENT == LE_EXPANSION_NORTHREND

--<GLOBALS
local _G = _G
Expand Down
19 changes: 17 additions & 2 deletions core/Utility.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,17 @@ local GetContainerNumFreeSlots = _G.GetContainerNumFreeSlots
local geterrorhandler = _G.geterrorhandler
local GetItemFamily = _G.GetItemFamily
local GetItemInfo = _G.GetItemInfo
local ITEM_QUALITY_POOR = _G.Enum.ItemQuality.Poor
local ITEM_QUALITY_UNCOMMON = _G.Enum.ItemQuality.Uncommon
local ITEM_QUALITY_POOR
local ITEM_QUALITY_UNCOMMON

if addon.isRetail then
ITEM_QUALITY_POOR = _G.Enum.ItemQuality.Poor
ITEM_QUALITY_UNCOMMON = _G.Enum.ItemQuality.Uncommon
else
ITEM_QUALITY_POOR = _G.LE_ITEM_QUALITY_POOR
ITEM_QUALITY_UNCOMMON = _G.LE_ITEM_QUALITY_UNCOMMON
end

local pairs = _G.pairs
local pcall = _G.pcall
local select = _G.select
Expand Down Expand Up @@ -145,6 +154,12 @@ function addon.SetupTooltip(widget, content, anchor, xOffset, yOffset)
end
end

function addon.RemoveTooltip(widget)
widget:SetScript('OnEnter', nil)
widget:SetScript('OnLeave', nil)
widget.tooltipCallback = nil
widget.UpdateTooltip = nil
end
--------------------------------------------------------------------------------
-- Item link checking
--------------------------------------------------------------------------------
Expand Down
157 changes: 137 additions & 20 deletions modules/CurrencyFrame.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ local CreateFrame = _G.CreateFrame
local ExpandCurrencyList = _G.C_CurrencyInfo.ExpandCurrencyList
local format = _G.format
local GetCurrencyListInfo = _G.C_CurrencyInfo.GetCurrencyListInfo
local GetCurrencyInfo = _G.C_CurrencyInfo.GetCurrencyInfo
local GetCurrencyListSize = _G.C_CurrencyInfo.GetCurrencyListSize
local hooksecurefunc = _G.hooksecurefunc
local ipairs = _G.ipairs
Expand All @@ -52,13 +53,16 @@ mod.uiName = L['Currency']
mod.uiDesc = L['Display character currency at bottom left of the backpack.']

function mod:OnInitialize()
self.currencyToCell = {}
self.columns = {}
self.db = addon.db:RegisterNamespace(
self.moduleName,
{
profile = {
shown = { ['*'] = true },
hideZeroes = true,
text = addon:GetFontDefaults(NumberFontNormalLarge)
text = addon:GetFontDefaults(NumberFontNormalLarge),
width = 4,
}
}
)
Expand All @@ -75,6 +79,7 @@ function mod:OnEnable()
if self.widget then
self.widget:Show()
end

self:RegisterEvent('CURRENCY_DISPLAY_UPDATE', "Update")
if not self.hooked then
if IsAddOnLoaded('Blizzard_TokenUI') then
Expand Down Expand Up @@ -104,18 +109,47 @@ function mod:OnBagFrameCreated(bag)
if bag.bagName ~= "Backpack" then return end
local frame = bag:GetFrame()

local widget =CreateFrame("Button", addonName.."CurrencyFrame", frame)
local widget = CreateFrame("Button", addonName.."CurrencyFrame", frame)
self.widget = widget
widget:SetHeight(16)
widget:RegisterForClicks("RightButtonUp")
widget:SetScript('OnClick', function() self:OpenOptions() end)
addon.SetupTooltip(widget, { L['Currency'], L['Right-click to configure.'] }, "ANCHOR_BOTTOMLEFT")

local fs = widget:CreateFontString(nil, "OVERLAY")
fs:SetFontObject(self.font)
fs:SetPoint("BOTTOMLEFT", 0, 1)
self.fontstring = fs
-- Create the columns used for currency display. Each column has the maximum amount
-- of possible cells for the minimum width / the max number of currencies.
for i = 1, 10 do
local columnFrame = CreateFrame("Button", string.format("%sCurrencyColumnFrame%d", addonName, i), widget)
columnFrame:Show()
if i == 1 then
columnFrame:SetPoint("TOPLEFT", widget, "TOPLEFT")
else
columnFrame:SetPoint("TOPLEFT", self.columns[i-1].frame, "TOPRIGHT")
end
local column = {
frame = columnFrame,
cells = {}
}

for ii = 1, ceil(GetCurrencyListSize() / 3)+1 do
local cellFrame = CreateFrame("Button", string.format("%sCurrencyCellFrame%d%d", addonName, i, ii), columnFrame)
if ii == 1 then
cellFrame:SetPoint("TOPLEFT", columnFrame, "TOPLEFT")
else
cellFrame:SetPoint("TOPLEFT", column.cells[ii-1].frame, "BOTTOMLEFT")
end

cellFrame:Show()
local fs = cellFrame:CreateFontString(nil, "OVERLAY")
fs:SetFontObject(self.font)
fs:SetPoint("BOTTOMLEFT", 0, 1)
table.insert(column.cells, {
frame = cellFrame,
fs = fs,
text = "",
icon = "",
name = "",
})
end
table.insert(self.columns, column)
end
self:Update()
frame:AddBottomWidget(widget, "LEFT", 50)
end
Expand Down Expand Up @@ -156,31 +190,99 @@ local ICON_STRING = " \124T%s:0:0:0:0:64:64:5:59:5:59\124t "

local values = {}
local updating
function mod:Update()
function mod:Update(event, currencyType, currencyQuantity)
if not self.widget or updating then return end
updating = true

-- Refresh only the affected cell.
if currencyType ~= nil then
local info = GetCurrencyInfo(currencyType)
local cell = self.currencyToCell[info.name]
cell.text = cell.icon .. currencyQuantity
cell.fs:SetText(cell.text)
cell.frame:SetSize(
cell.fs:GetStringWidth(),
ceil(cell.fs:GetStringHeight())+3
)
local column = cell.frame:GetParent()
if column:GetWidth() < cell.frame:GetWidth() then
column:SetWidth(cell.frame:GetWidth())
end
updating = false
return
end

-- This is a full refresh of all cells, called on first load or layout changes.

-- Clear the currency -> cell map.
wipe(self.currencyToCell)

-- Clear all cells and columns completely.
for i, column in ipairs(self.columns) do
for ii, cell in ipairs(column.cells) do
cell.fs:SetText("")
cell.text = ""
cell.name = ""
cell.icon = ""
addon.RemoveTooltip(cell.frame)
end
column.frame:SetSize(0,0)
end

-- Get all the currency information from the player and store it.
local shown, hideZeroes = self.db.profile.shown, self.db.profile.hideZeroes
for i, currencyListInfo in IterateCurrencies() do
if shown[currencyListInfo.name] and (currencyListInfo.quantity > 0 or not hideZeroes) then
tinsert(values, BreakUpLargeNumbers(currencyListInfo.quantity))
tinsert(values, format(ICON_STRING, currencyListInfo.iconFileID))
tinsert(values, {
quantity = BreakUpLargeNumbers(currencyListInfo.quantity),
icon = format(ICON_STRING, currencyListInfo.iconFileID),
name = currencyListInfo.name
})
end
end

local widget, fs = self.widget, self.fontstring
-- Set the cell values.
if #values > 0 then
fs:SetText(tconcat(values, ""))
widget:Show()
widget:SetSize(
fs:GetStringWidth(),
ceil(fs:GetStringHeight()) + 3
)
for i, value in ipairs(values) do
local columnPosition = ((i-1) % self.db.profile.width)+1
local rowPosition = ceil(i / self.db.profile.width)
local column = self.columns[columnPosition]
local cell = column.cells[rowPosition]
cell.icon = value.icon
cell.name = value.name
cell.text = value.icon .. value.quantity
cell.fs:SetText(cell.text)
cell.frame:SetSize(
cell.fs:GetStringWidth(),
ceil(cell.fs:GetStringHeight())+3
)
-- Set the cell's tooltip.
addon.SetupTooltip(cell.frame, cell.name, "ANCHOR_BOTTOMLEFT")

-- Resize the columns as needed.
if column.frame:GetWidth() < cell.frame:GetWidth() then
column.frame:SetWidth(cell.frame:GetWidth())
end
column.frame:SetHeight(column.frame:GetHeight() + cell.frame:GetHeight())
self.currencyToCell[value.name] = cell
end

-- Loop over every active column and get the total width
-- of all columns for the parent widget.
local totalWidth = 0
for i = 1, self.db.profile.width do
totalWidth = totalWidth + self.columns[i].frame:GetWidth()
end

-- The first column will always be the longest column, so get the height
-- of the first column and set the parent widget to this size.
widget:SetSize(totalWidth, self.columns[1].frame:GetHeight())
wipe(values)
else
widget:Hide()
end

widget:Show()
updating = false
end

Expand All @@ -206,6 +308,21 @@ function mod:GetOptions()
type = 'toggle',
order = 20,
},
text = addon:CreateFontOptions(self.font, nil, 30)
text = addon:CreateFontOptions(self.font, nil, 30),
layout = {
name = L['Layout'],
type = 'group',
order = 100,
inline = true,
args = {
width = {
name = L['Currencies per row'],
type = 'range',
min = 3,
max = 10,
step = 1
}
}
},
}, addon:GetOptionHandler(self, false, function() return self:Update() end)
end
8 changes: 4 additions & 4 deletions modules/FilterOverride.lua
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ end

function mod:OnEnable()
self:UpdateOptions()
self:RegisterEvent('CURSOR_UPDATE')
self:RegisterEvent('CURSOR_CHANGED')
addon.RegisterSectionHeaderScript(self, 'OnTooltipUpdate', 'OnTooltipUpdateSectionHeader')
addon.RegisterSectionHeaderScript(self, 'OnClick', 'OnClickSectionHeader')
self:CURSOR_UPDATE()
self:CURSOR_CHANGED()
end

function mod:OnDisable()
Expand Down Expand Up @@ -480,7 +480,7 @@ end
function mod:OnTooltipUpdateSectionHeader(_, header, tooltip)
if GetCursorInfo() == "item" then
if header.section.name ~= FREE_SPACE then
tooltip:AddLine(L["Drop your item there to add it to this section."])
tooltip:AddLine(L["Click here with your item to add it to this section."])
tooltip:AddLine(L["Press Alt while doing so to open a dropdown menu."])
end
elseif header.section:GetKey() ~= JUNK_KEY then
Expand Down Expand Up @@ -521,7 +521,7 @@ function mod:OnReceiveDragSectionHeader(_, header)
end
end

function mod:CURSOR_UPDATE()
function mod:CURSOR_CHANGED()
if GetCursorInfo() == "item" then
addon.RegisterSectionHeaderScript(self, 'OnReceiveDrag', 'OnReceiveDragSectionHeader')
else
Expand Down
13 changes: 11 additions & 2 deletions modules/ItemLevel.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,17 @@ local L = addon.L
local _G = _G
local abs = _G.math.abs
local GetItemInfo = _G.GetItemInfo
local ITEM_QUALITY_HEIRLOOM = _G.Enum.ItemQuality.Heirloom
local ITEM_QUALITY_POOR = _G.Enum.ItemQuality.Poor
local ITEM_QUALITY_HEIRLOOM
local ITEM_QUALITY_POOR

if addon.isRetail then
ITEM_QUALITY_HEIRLOOM = _G.Enum.ItemQuality.Heirloom
ITEM_QUALITY_POOR = _G.Enum.ItemQuality.Poor
else
ITEM_QUALITY_HEIRLOOM = _G.LE_ITEM_QUALITY_HEIRLOOM
ITEM_QUALITY_POOR = _G.LE_ITEM_QUALITY_POOR
end

local QuestDifficultyColors = _G.QuestDifficultyColors
local UnitLevel = _G.UnitLevel
local modf = _G.math.modf
Expand Down
10 changes: 9 additions & 1 deletion modules/NewItemTracking.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,15 @@ local GetContainerItemInfo = _G.GetContainerItemInfo
local GetContainerNumSlots = _G.GetContainerNumSlots
local GetInventoryItemID = _G.GetInventoryItemID
local GetInventoryItemLink = _G.GetInventoryItemLink
local ITEM_QUALITY_POOR = _G.Enum.ItemQuality.Poor

local ITEM_QUALITY_POOR

if addon.isRetail then
ITEM_QUALITY_POOR = _G.Enum.ItemQuality.Poor
else
ITEM_QUALITY_POOR = _G.LE_ITEM_QUALITY_POOR
end

local next = _G.next
local pairs = _G.pairs
local PlaySound = _G.PlaySound
Expand Down
6 changes: 3 additions & 3 deletions widgets/ContainerFrame.lua
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,7 @@ function containerProto:UpdateContent(bag)
local prevSlotId = slotData.slotId
local prevLink = slotData.link
local prevTexture = slotData.texture
local prevEquipSlot = slotData.equipSlot
-- If links only differ in character level that's the same item
local sameItem = addon.IsSameLinkButLevel(slotData.link, link)

Expand All @@ -655,13 +656,12 @@ function containerProto:UpdateContent(bag)
slotData.itemId = itemId
slotData.name, slotData.quality, slotData.iLevel, slotData.reqLevel, slotData.class, slotData.subclass, slotData.equipSlot, slotData.texture, slotData.vendorPrice = name, quality, iLevel, reqLevel, class, subclass, equipSlot, texture, vendorPrice
slotData.maxStack = maxStack or (link and 1 or 0)

if sameItem then
-- Items that are the same item but have mutated are marked as "new" to make them more visble.
-- However, only things with a new texture are marked as new, i.e. wrapped items.
if prevTexture ~= texture then
if prevTexture ~= texture and equipSlot ~= prevEquipSlot then
sameChanged[slotData.slotId] = slotData
addon:SendMessage('AdiBags_AddNewItem', slotData.link)
addon:SendMessage('AdiBags_AddNewItem', slotData.link)
else
changed[slotData.slotId] = slotData
end
Expand Down
Loading

0 comments on commit f7c82c3

Please sign in to comment.