Skip to content

Commit

Permalink
v1.8.0
Browse files Browse the repository at this point in the history
* Update Interface version (#163)(#172)
* Performance and border fixes (#164)
* Close #126: Implement Loot History (#168)(#170)
* Close #44: Support multiple rows of text (#173)
* Close #155: Support Delve Companion Experience (rep) (#175)
* Close #112: Party Loot (#176)
  • Loading branch information
Mctalian committed Nov 10, 2024
1 parent e7ccbcf commit 3fb0208
Show file tree
Hide file tree
Showing 21 changed files with 1,175 additions and 205 deletions.
4 changes: 3 additions & 1 deletion .scripts/hardcode_string_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ def scan_directory(directory, ignore_files=None, ignore_dirs=None):


def main():
ignore_files = []
ignore_files = [
"SmokeTest.lua",
]
ignore_dirs = [
".git",
".github",
Expand Down
10 changes: 10 additions & 0 deletions Core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,16 @@ function G_RLF:Print(...)
G_RLF.RLF:Print(...)
end

function G_RLF:RGBAToHexFormat(r, g, b, a)
local red = string.format("%02X", math.floor(r * 255))
local green = string.format("%02X", math.floor(g * 255))
local blue = string.format("%02X", math.floor(b * 255))
local alpha = string.format("%02X", math.floor((a or 1) * 255)) -- Default alpha to 1 if not provided

-- Return in WoW format with |c prefix
return "|c" .. alpha .. red .. green .. blue
end

--@alpha@
function G_RLF:ProfileFunction(func, funcName)
return function(...)
Expand Down
56 changes: 52 additions & 4 deletions Features/Currency.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,43 @@ function Currency.Element:new(...)
return truncatedLink .. " x" .. ((existingQuantity or 0) + element.quantity)
end

element.quality = C_CurrencyInfo.GetCurrencyInfo(element.key).quality
local info = C_CurrencyInfo.GetCurrencyInfo(element.key)

element.quality = info.quality
element.currentTotal = info.quantity
element.totalEarned = info.totalEarned
element.cappedQuantity = info.maxQuantity

element.secondaryTextFn = function(...)
if element.currentTotal == 0 then
return ""
end

local str = " |cFFBABABA" .. element.currentTotal .. "|r"

if element.cappedQuantity > 0 then
local percentage, numerator
if element.totalEarned > 0 then
numerator = element.totalEarned
percentage = element.totalEarned / element.cappedQuantity
else
numerator = element.currentTotal
percentage = element.currentTotal / element.cappedQuantity
end
local color
if percentage < 0.7 then
color = "|cFFFFFFFF"
elseif percentage >= 0.7 and percentage < 0.9 then
color = "|cFFFF9B00"
else
color = "|cFFFF0000"
end

str = str .. " " .. color .. "(" .. numerator .. " / " .. element.cappedQuantity .. ")|r"
end

return str
end

return element
end
Expand All @@ -46,15 +82,15 @@ end

function Currency:OnDisable()
self:UnregisterEvent("CURRENCY_DISPLAY_UPDATE")
self:UnregisterEvent("PERKS_PROGRAM_CURRENCY_AWARDED")
end

function Currency:OnEnable()
self:RegisterEvent("CURRENCY_DISPLAY_UPDATE")
self:RegisterEvent("PERKS_PROGRAM_CURRENCY_AWARDED")
end

function Currency:CURRENCY_DISPLAY_UPDATE(eventName, ...)
local currencyType, _quantity, quantityChange, _quantityGainSource, _quantityLostSource = ...

function Currency:Process(eventName, currencyType, quantityChange)
self:getLogger():Info(eventName, "WOWEVENT", self.moduleName, currencyType, eventName, quantityChange)

if currencyType == nil or not quantityChange or quantityChange <= 0 then
Expand Down Expand Up @@ -106,6 +142,18 @@ function Currency:CURRENCY_DISPLAY_UPDATE(eventName, ...)
end)
end

function Currency:CURRENCY_DISPLAY_UPDATE(eventName, ...)
local currencyType, _quantity, quantityChange, _quantityGainSource, _quantityLostSource = ...

self:Process(eventName, currencyType, quantityChange)
end

function Currency:PERKS_PROGRAM_CURRENCY_AWARDED(eventName, quantityChange)
local currencyType = 2032 -- https://www.wowhead.com/currency=2032/traders-tender

self:Process(eventName, currencyType, quantityChange)
end

hiddenCurrencies = {
[2918] = true,
[2919] = true,
Expand Down
19 changes: 18 additions & 1 deletion Features/Experience.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
local addonName, G_RLF = ...

local Xp = G_RLF.RLF:NewModule("Experience", "AceEvent-3.0")
local currentXP, currentMaxXP, currentLevel

Xp.Element = {}

Expand All @@ -20,10 +21,26 @@ function Xp.Element:new(...)
return "+" .. ((existingXP or 0) + element.quantity) .. " " .. G_RLF.L["XP"]
end

element.secondaryTextFn = function()
if not currentXP then
return ""
end
if not currentMaxXP then
return ""
end
local color = G_RLF:RGBAToHexFormat(1, 1, 1, 1)

return " "
.. color
.. currentLevel
.. "|r "
.. math.floor((currentXP / currentMaxXP) * 10000) / 100
.. "%"
end

return element
end

local currentXP, currentMaxXP, currentLevel
local function initXpValues()
currentXP = UnitXP("player")
currentMaxXP = UnitXPMax("player")
Expand Down
137 changes: 125 additions & 12 deletions Features/ItemLoot.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ local addonName, G_RLF = ...

local ItemLoot = G_RLF.RLF:NewModule("ItemLoot", "AceEvent-3.0")

ItemLoot.SecondaryTextOption = {
["None"] = "None",
["SellPrice"] = "Sell Price",
["iLvl"] = "Item Level",
}

-- local equipLocToSlotID = {
-- ["INVTYPE_HEAD"] = INVSLOT_HEAD,
-- ["INVTYPE_NECK"] = INVSLOT_NECK,
Expand Down Expand Up @@ -36,6 +42,31 @@ local function itemQualityName(enumValue)
return nil
end

local nameUnitMap = {}

local function setNameUnitMap()
local units = {}
if IsInRaid() then
for i = 1, MEMBERS_PER_RAID_GROUP do
table.insert(units, "raid" .. i)
end
else
table.insert(units, "player")

for i = 2, MEMBERS_PER_RAID_GROUP do
table.insert(units, "party" .. (i - 1))
end
end

nameUnitMap = {}
for _, unit in ipairs(units) do
local name, server = UnitName(unit)
if name then
nameUnitMap[name] = unit
end
end
end

function ItemLoot.Element:new(...)
local element = {}
G_RLF.InitializeLootDisplayProperties(element)
Expand All @@ -48,12 +79,9 @@ function ItemLoot.Element:new(...)
element.isLink = true

local t
element.key, t, element.icon, element.quantity = ...

element.isPassingFilter = function()
local itemName, _, itemQuality, itemLevel, itemMinLevel, itemType, itemSubType, itemStackCount, itemEquipLoc, itemTexture, sellPrice, classID, subclassID, bindType, expansionID, setID, isCraftingReagent =
C_Item.GetItemInfo(t)
element.key, t, element.icon, element.quantity, element.sellPrice, element.unit = ...

function element:isPassingFilter(itemName, itemQuality)
if not G_RLF.db.global.itemQualityFilter[itemQuality] then
element:getLogger():Debug(
itemName .. " ignored by quality: " .. itemQualityName(itemQuality),
Expand Down Expand Up @@ -88,6 +116,18 @@ function ItemLoot.Element:new(...)
return truncatedLink .. " x" .. ((existingQuantity or 0) + element.quantity)
end

element.secondaryTextFn = function(...)
if element.unit then
local name, server = UnitName(element.unit)
return " " .. name .. "-" .. server
end
local quantity = ...
if not element.sellPrice or element.sellPrice == 0 then
return ""
end
return " " .. C_CurrencyInfo.GetCoinTextureString(element.sellPrice * (quantity or 1))
end

return element
end

Expand All @@ -102,25 +142,83 @@ end

function ItemLoot:OnDisable()
self:UnregisterEvent("CHAT_MSG_LOOT")
self:UnregisterEvent("GET_ITEM_INFO_RECEIVED")
self:UnregisterEvent("GROUP_ROSTER_UPDATE")
end

function ItemLoot:OnEnable()
self:RegisterEvent("CHAT_MSG_LOOT")
self:RegisterEvent("GET_ITEM_INFO_RECEIVED")
self:RegisterEvent("GROUP_ROSTER_UPDATE")
setNameUnitMap()
end

local function showItemLoot(msg, itemLink)
local pendingItemRequests = {}
local function onItemReadyToShow(itemId, itemLink, itemTexture, amount, itemName, itemQuality, sellPrice)
pendingItemRequests[itemId] = nil
local e = ItemLoot.Element:new(itemId, itemLink, itemTexture, amount, sellPrice, false)
e:Show(itemName, itemQuality)
end

local pendingPartyRequests = {}
local function onPartyReadyToShow(itemId, itemLink, itemTexture, amount, itemName, itemQuality, sellPrice, unit)
pendingPartyRequests[itemId] = nil
local e = ItemLoot.Element:new(itemId, itemLink, itemTexture, amount, sellPrice, unit)
e:Show(itemName, itemQuality)
end

function ItemLoot:GET_ITEM_INFO_RECEIVED(eventName, itemID, success)
if pendingItemRequests[itemID] then
local itemLink, amount = unpack(pendingItemRequests[itemID])

if not success then
error("Failed to load item: " .. itemID .. " " .. itemLink .. " x" .. amount)
else
local itemName, _, itemQuality, _, _, _, _, _, _, itemTexture, sellPrice, _, _, _, _, _, _ =
C_Item.GetItemInfo(itemLink)
onItemReadyToShow(itemID, itemLink, itemTexture, amount, itemName, itemQuality, sellPrice)
end
return
end

if pendingPartyRequests[itemID] then
local itemLink, amount, unit = unpack(pendingPartyRequests[itemID])

if not success then
error("Failed to load item: " .. itemID .. " " .. itemLink .. " x" .. amount .. " for " .. unit)
else
local itemName, _, itemQuality, _, _, _, _, _, _, itemTexture, sellPrice, _, _, _, _, _, _ =
C_Item.GetItemInfo(itemLink)
onPartyReadyToShow(itemID, itemLink, itemTexture, amount, itemName, itemQuality, sellPrice, unit)
end
return
end
end

local function showPartyLoot(msg, itemLink, unit)
local amount = tonumber(msg:match("r ?x(%d+)") or 1)
local _, _, itemQuality, itemLevel, itemMinLevel, itemType, itemSubType, itemStackCount, itemEquipLoc, itemTexture, sellPrice, classID, subclassID, bindType, expansionID, setID, isCraftingReagent =
local itemId = itemLink:match("Hitem:(%d+)")
pendingPartyRequests[itemId] = { itemLink, amount, unit }
local itemName, _, itemQuality, _, _, _, _, _, _, itemTexture, sellPrice, _, _, _, _, _, _ =
C_Item.GetItemInfo(itemLink)
if itemName ~= nil then
onPartyReadyToShow(itemId, itemLink, itemTexture, amount, itemName, itemQuality, sellPrice, unit)
end
end

local function showItemLoot(msg, itemLink)
local amount = tonumber(msg:match("r ?x(%d+)") or 1)
local itemId = itemLink:match("Hitem:(%d+)")

local e = ItemLoot.Element:new(itemId, itemLink, itemTexture, amount)
e:Show()
pendingItemRequests[itemId] = { itemLink, amount }
local itemName, _, itemQuality, _, _, _, _, _, _, itemTexture, sellPrice, _, _, _, _, _, _ =
C_Item.GetItemInfo(itemLink)
if itemName ~= nil then
onItemReadyToShow(itemId, itemLink, itemTexture, amount, itemName, itemQuality, sellPrice)
end
end

function ItemLoot:CHAT_MSG_LOOT(eventName, ...)
local msg, _, _, _, _, _, _, _, _, _, _, guid = ...
local msg, playerName, _, _, playerName2, _, _, _, _, _, _, guid = ...
local raidLoot = msg:match("HlootHistory:")
self:getLogger():Info(eventName, "WOWEVENT", self.moduleName, nil, eventName .. " " .. msg)
if raidLoot then
Expand All @@ -131,7 +229,16 @@ function ItemLoot:CHAT_MSG_LOOT(eventName, ...)

local me = guid == GetPlayerGuid()
if not me then
self:getLogger():Debug("Group Member Loot Ignored", "WOWEVENT", self.moduleName, "", msg)
if not G_RLF.db.global.enablePartyLoot then
self:getLogger():Debug("Party Loot Ignored", "WOWEVENT", self.moduleName, "", msg)
return
end
local sanitizedPlayerName = (playerName or playerName2):gsub("%-.+", "")
local unit = nameUnitMap[sanitizedPlayerName]
local itemLink = msg:match("|c%x+|Hitem:.-|h%[.-%]|h|r")
if itemLink then
self:fn(showPartyLoot, msg, itemLink, unit)
end
return
end

Expand All @@ -141,4 +248,10 @@ function ItemLoot:CHAT_MSG_LOOT(eventName, ...)
end
end

function ItemLoot:GROUP_ROSTER_UPDATE(eventName, ...)
self:getLogger():Info(eventName, "WOWEVENT", self.moduleName, nil, eventName)

setNameUnitMap()
end

return ItemLoot
5 changes: 3 additions & 2 deletions Features/LootDisplayProperties.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ local addonName, G_RLF = ...
G_RLF.LootDisplayProperties = {
"key",
"textFn",
"secondaryTextFn",
"isLink",
"icon",
"quantity",
Expand All @@ -29,8 +30,8 @@ function G_RLF.InitializeLootDisplayProperties(self)
return true
end

self.Show = function()
if self.isPassingFilter() then
self.Show = function(_, itemName, itemQuality)
if self:isPassingFilter(itemName, itemQuality) then
G_RLF.LootDisplay:ShowLoot(self)
end
end
Expand Down
12 changes: 10 additions & 2 deletions Features/Money.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ local Money = G_RLF.RLF:NewModule("Money", "AceEvent-3.0")

Money.Element = {}

local startingMoney

function Money.Element:new(...)
local element = {}
G_RLF.InitializeLootDisplayProperties(element)
Expand All @@ -27,11 +29,17 @@ function Money.Element:new(...)
return sign .. C_CurrencyInfo.GetCoinTextureString(math.abs(total))
end

element.secondaryTextFn = function()
local money = GetMoney()
if money > 10000000 then
money = math.floor(money / 10000) * 10000
end
return " " .. C_CurrencyInfo.GetCoinTextureString(money)
end

return element
end

local startingMoney

function Money:OnInitialize()
if G_RLF.db.global.moneyFeed then
self:Enable()
Expand Down
Loading

0 comments on commit 3fb0208

Please sign in to comment.