local addonName = ... local addon = _G[addonName] local L = LibStub("AceLocale-3.0"):GetLocale(addonName) local BI = LibStub("LibBabble-Inventory-3.0"):GetLookupTable() local INFO_REALM_LINE = 0 local INFO_CHARACTER_LINE = 1 local INFO_TOTAL_LINE = 2 local WHITE = "|cFFFFFFFF" local TEAL = "|cFF00FF9A" local RED = "|cFFFF0000" local ORANGE = "|cFFFF7F00" local YELLOW = "|cFFFFFF00" local GREEN = "|cFF00FF00" local RECIPE_GREY = "|cFF808080" local RECIPE_GREEN = "|cFF40C040" local RECIPE_ORANGE = "|cFFFF8040" local ICON_FACTION_HORDE = "Interface\\Icons\\INV_BannerPVP_01" local ICON_FACTION_ALLIANCE = "Interface\\Icons\\INV_BannerPVP_02" local ns = addon.TradeSkills -- ns = namespace local Characters = addon.Characters local size = 22 local inset = 2 function ns:Update() local VisibleLines = 20 local frame = "AltoholicFrameSkills" local entry = frame.."Entry" local DS = DataStore -- CoA: vertical list. For each visible character a header row, then one row per known -- profession / secondary skill (icon + name + rank/max), top to bottom (like the other detail views). local SECONDARY = { 2550, 3273, 7733 } -- Cooking, First Aid, Fishing (spell id -> icon + GetSpellInfo name) local items = {} for _, viewLine in pairs(Characters:GetView()) do if Characters:GetLineType(viewLine) == INFO_CHARACTER_LINE then local character = DS:GetCharacter( Characters:GetInfo(viewLine) ) items[#items + 1] = { kind = "header", viewLine = viewLine, character = character } local profs = Characters:GetField(viewLine, "professions") if profs then for _, p in ipairs(profs) do items[#items + 1] = { kind = "skill", viewLine = viewLine, character = character, spellID = p.spellID, name = p.name, rank = p.rank or 0, maxRank = p.maxRank or 0 } end end for _, sid in ipairs(SECONDARY) do local sName = GetSpellInfo(sid) if sName then local cur, max = DS:GetSkillInfo(character, sName) if cur and cur > 0 then items[#items + 1] = { kind = "skill", viewLine = viewLine, character = character, spellID = sid, name = sName, rank = cur, maxRank = max or 0 } end end end local riding = Characters:GetField(viewLine, "riding") or 0 if riding > 0 then items[#items + 1] = { kind = "skill", viewLine = viewLine, character = character, spellID = 33388, name = (L and L["Riding"]) or "Riding", rank = riding, maxRank = 300 } end end end local offset = FauxScrollFrame_GetOffset( _G[ frame.."ScrollFrame" ] ) for i = 1, VisibleLines do local e = entry..i local btn = _G[e] local item = items[i + offset] if item then _G[e.."Collapse"]:Hide() _G[e.."Level"]:SetText("") _G[e.."Skill1NormalText"]:SetText("") _G[e.."CookingNormalText"]:SetText("") _G[e.."FirstAidNormalText"]:SetText("") _G[e.."FishingNormalText"]:SetText("") _G[e.."RidingNormalText"]:SetText("") _G[e.."Name"]:SetWidth(680) _G[e.."Name"]:SetPoint("TOPLEFT", 15, 0) _G[e.."NameNormalText"]:SetWidth(680) if item.kind == "header" then local _, class = DS:GetCharacterClass(item.character) _G[e.."NameNormalText"]:SetText( (DS:GetColoredCharacterName(item.character) or "?") .. " " .. WHITE .. "(" .. (class or "") .. ")" ) else local iconEsc = "" if item.spellID then iconEsc = addon:TextureToFontstring2(addon:GetSpellIcon(item.spellID), size, size, inset, inset, inset, inset) .. " " end local cap = (item.maxRank > 0) and item.maxRank or 450 _G[e.."NameNormalText"]:SetText( " " .. iconEsc .. WHITE .. item.name .. " " .. ns:GetColor(item.rank, cap) .. item.rank .. "/" .. item.maxRank .. "|r" ) end btn.coaItem = item btn:SetID(item.viewLine or 0) btn:Show() else btn.coaItem = nil btn:SetID(0) btn:Hide() end end FauxScrollFrame_Update( _G[ frame.."ScrollFrame" ], #items, VisibleLines, 18 ) end function ns:OnEnter(frame) local item = frame:GetParent() and frame:GetParent().coaItem if not item or item.kind ~= "skill" then return end AltoTooltip:ClearLines() AltoTooltip:SetOwner(frame, "ANCHOR_RIGHT") AltoTooltip:AddLine(WHITE .. item.name, 1, 1, 1) local cap = (item.maxRank > 0) and item.maxRank or 450 AltoTooltip:AddLine( ns:GetColor(item.rank, cap) .. item.rank .. " / " .. item.maxRank, 1, 1, 1 ) AltoTooltip:Show() end function ns:OnClick(frame, button) -- CoA: clicking a profession row opens that character's profession recipe list, if available. local item = frame:GetParent() and frame:GetParent().coaItem if not item or item.kind ~= "skill" or not item.character then return end if addon.Tabs and addon.Tabs.Characters and addon.Tabs.Characters.ViewCharInfo then local name, realm, account = Characters:GetInfo(item.viewLine) addon:SetCurrentCharacter(name, realm, account) addon.Tabs.Characters:SetCurrent(name, realm, account) addon.Tabs:OnClick(2) end end local skillColors = { RECIPE_GREY, RED, ORANGE, YELLOW, GREEN } function ns:GetColor(rank, skillCap) rank = rank or 0 -- CoA: skill fields are nil for chars DataStore_Characters hasn't scanned skillCap = skillCap or 450 -- CoA: custom professions can exceed skillCap (e.g. ranks > 450), which would -- push the index past the 5-colour table and return nil -> crash on concat. -- Clamp into [1, #skillColors]. local index = floor(rank / (skillCap / 4)) + 1 if index < 1 then index = 1 end if index > #skillColors then index = #skillColors end return skillColors[index] end