CurseForge and Overwolf are joining forces!
Awesome More Information
  • 0

    posted a message on Library for putting icons in text

    While working on my Broker_RaidMakeup addon, I needed a way to put an icon into a line of text. The command itself was fairly straightforward, but getting all the parameters right, and for multiple icons, seemed to be a pain. I ended up write a mini-library I called IconClass to act as a wrapper and abstract some of the functionality out.

     

    I'm wondering if anyone has either experience with or a need for something like this? Is this worth developing into a proper standalone library? Is there already an existing library that does this?

     

    Right now, IconClass does just enough to support my addon. I have some ideas on how to expand it to be a proper library and handle more of the edge cases that don't come up in my addon, but I'm not willing to put in that time if something better already exists, or if there's an easier way to do it all.

     

    Here's a sample usage. In your TOC file, include the IconClass.lua file, then put the below in your main code. This would cause the icons to be displayed inline with the text.

     

    -- Using a complete .blp file as an icon
    local AllianceIcon = IconClass("Interface\\Calendar\\UI-Calendar-Event-PVP02")
    local HordeIcon = IconClass("Interface\\Calendar\\UI-Calendar-Event-PVP01")
    
    -- Usage example
    if MyPlayerInfo.Faction == CONSTANTS.FACTION_HORDE then
    	MyAddon.DescriptiveLabel = "Your faction is " .. HordeIcon:GetIconString() .. " Horde!"
    elseif MyPlayerInfo.Faction == CONSTANTS.FACTION_ALLIANCE then
    	MyAddon.DescriptiveLabel = "Your faction is " .. AllianceIcon:GetIconString() .. " Alliance!"
    else
    	-- What the hell?
    	MyAddon.DescriptiveLabel = "Your faction is ... I dunno, neutral?"
    end
    
    
    -- Using a partial .blp file as an icon.
    -- The actual file has five icons, so we have to select just the portion for each one.
    local TankIcon = IconClass("Interface\\LFGFRAME\\UI-LFG-ICON-PORTRAITROLES.blp", 64, 64, 0, 0+19, 22, 22+19)
    local HealerIcon = IconClass("Interface\\LFGFRAME\\UI-LFG-ICON-PORTRAITROLES.blp", 64, 64, 19, 19+19, 1, 1+19)
    local DPSIcon = IconClass("Interface\\LFGFRAME\\UI-LFG-ICON-PORTRAITROLES.blp", 64, 64, 19, 19+19, 22, 22+19)
    
    
    -- Usage example - the code doesn't have to deal with snipping out the icon; it's all handled by the class
    if MyPlayerInfo.Role == CONSTANTS.DPS then
    	print("Your role is " .. DPSIcon:GetIconString() .. " DPS!")
    elseif MyPlayerInfo.Role == CONSTANTS.HEALER then
    	print("Your role is " .. HealerIcon:GetIconString() .. " Healer!")
    elseif MyPlayerInfo.Role == CONSTANTS.TANK then
    	print("Your role is " .. TankIcon:GetIconString() .. " Tank!")
    else
    	print("Your role is not set.")
    end
    
    

     

    Posted in: Libraries
  • To post a comment, please or register a new account.