Skip to content

Commit

Permalink
VF: Added class/spec tooltip on class hover.
Browse files Browse the repository at this point in the history
Made Add"class/spec"IconToText seperate functions, and cached it's outputs
  • Loading branch information
evil-morfar committed Sep 20, 2024
1 parent 2d619d9 commit 215ba51
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 5 deletions.
13 changes: 12 additions & 1 deletion Modules/votingFrame.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1435,14 +1435,25 @@ function RCVotingFrame.SetCellClass(rowFrame, frame, data, cols, row, realrow, c
return
end
local specID = lootTable[session].candidates[name].specID
local specIcon = specID and select(4, GetSpecializationInfoByID(specID))
local _, specName, _, specIcon = GetSpecializationInfoByID(specID or 0)
if specIcon and db.showSpecIcon then
frame:SetNormalTexture(specIcon);
frame:GetNormalTexture():SetTexCoord(0, 1, 0, 1);
else
addon.SetCellClassIcon(rowFrame, frame, data, cols, row, realrow, column, fShow, table, lootTable[session].candidates[name].class)
end
data[realrow].cols[column].value = lootTable[session].candidates[name].class or ""

frame:SetScript("OnLeave", addon.UI.HideTooltip)
frame:SetScript("OnEnter", function()
local class = lootTable[session].candidates[name].class
local classText = addon:WrapTextInClassColor(class, addon.classTagNameToDisplayName[class])
if specName then
addon:CreateTooltip(addon:AddClassIconToText(class, classText, 16), addon:AddSpecIconToText(specID, specName, 14))
else
addon:CreateTooltip(addon:AddClassIconToText(class, classText, 16))
end
end)
end

function RCVotingFrame.SetCellName(rowFrame, frame, data, cols, row, realrow, column, fShow, table, ...)
Expand Down
4 changes: 4 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ The tooltip includes specific information as to why it won't do group loot, such

Module specific options (show more info, show tooltip, filters, etc) are no longer included in exported/synced profiles.

### Voting Frame

Hovering a candidate's class/spec icon will now show the name of their current class and spec.

## Bugfixes

- *WuE items will no longer register as BoEs (despite GetItemInfo saying so).*
Expand Down
40 changes: 36 additions & 4 deletions core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1199,12 +1199,14 @@ function RCLootCouncil:InitClassIDs()
self.classDisplayNameToID = {} -- Key: localized class display name. value: class id(number)
self.classTagNameToID = {} -- key: class name in capital english letters without space. value: class id(number)
self.classIDToDisplayName = {} -- key: class id. Value: localized name
self.classTagNameToDisplayName = {} --- @type table<string,string> Class File name to display name
self.classIDToFileName = {} -- key: class id. Value: File name
for i = 1, self.Utils.GetNumClasses() do
local info = C_CreatureInfo.GetClassInfo(i)
if info then -- Just in case class doesn't exists #Classic
self.classDisplayNameToID[info.className] = i
self.classTagNameToID[info.classFile] = i
self.classTagNameToDisplayName[info.classFile] = info.className
end
end
self.classIDToDisplayName = tInvert(self.classDisplayNameToID)
Expand Down Expand Up @@ -2282,9 +2284,24 @@ function RCLootCouncil:GetClassIconAndColoredName(nameOrPlayer, size)
size = size or 12
if not (player and player:GetClass()) then
self.Log:E("GetClassIconAndColoredName: No class found for ", nameOrPlayer)
return nameOrPlayer or ""
return nameOrPlayer --[[@as string]] or ""
end
return format("|W%s %s|w", CreateAtlasMarkup(self.CLASS_TO_ATLAS[player:GetClass()], size, size), player:GetClassColoredName())
return format("|W%s|w", self:AddClassIconToText(player:GetClass(), player:GetClassColoredName()))
end

local classAtlasCache = {}

--- Adds class icon in front of text.
---@param class ClassFile Class name to add
---@param text string Text
---@param size number? Size of the icon
function RCLootCouncil:AddClassIconToText(class, text, size)
size = size or 12
local id = class..size
if not classAtlasCache[id] then
classAtlasCache[id] = CreateAtlasMarkup(self.CLASS_TO_ATLAS[class], size, size)
end
return format("%s %s", classAtlasCache[id], text)
end

--- Creates a string with spec icon in front of a class colored name of the player.
Expand All @@ -2298,8 +2315,23 @@ function RCLootCouncil:GetSpecIconAndColoredName(nameOrPlayer, size)
-- No spec ID, fallback to class
return self:GetClassIconAndColoredName(player or nameOrPlayer, size)
end
local specIcon = select(4, GetSpecializationInfoByID(player.specID))
return format("|W%s %s|w", CreateSimpleTextureMarkup(specIcon, size), player:GetClassColoredName())
return format("|W%s|w", self:AddSpecIconToText(player.specID, player:GetClassColoredName(), size))
end

local specIconCache = {}

---Adds spec icon in front of text.
---@param specID integer SpecID
---@param text string Text
---@param size number? Size of the icon, defaults to 12.
function RCLootCouncil:AddSpecIconToText(specID, text, size)
size = size or 12
local specIcon = select(4, GetSpecializationInfoByID(specID))
local id = specIcon .. "-" .. size
if not specIconCache[id] then
specIconCache[id] = CreateSimpleTextureMarkup(specIcon, size)
end
return format("%s %s", specIconCache[id], text)
end

-- cName is name of the module
Expand Down

0 comments on commit 215ba51

Please sign in to comment.