• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Lua] GetDisabledIcon

A small Utility function, might be useful for custom UIs displaying CommandButton Icons.
Lua:
-- GetDisabledIcon by Tasyen
-- a function to get the disabled version when providing the enabled version
do
    local data = {}
    function GetDisabledIcon(icon)
        if not type(icon) == "string" then return icon end
        --ReplaceableTextures\CommandButtons\BTNHeroPaladin.tga -> ReplaceableTextures\CommandButtonsDisabled\DISBTNHeroPaladin.tga
        if not data[icon] and string.sub(icon,35,35) ~= "\\" then return icon end --this string has not enough chars return it
        if not data[icon] then
            local old = icon
            -- make it lower to reduce the amount of cases and for warcraft 3 FilePath case does not matter
            icon = string.lower(icon)
            if string.find(icon, "commandbuttons\\btn") then data[old] = string.gsub(icon, "commandbuttons\\btn", "commandbuttonsdisabled\\disbtn" )
            -- default wacraft 3 style
            elseif string.find(icon, "passivebuttons\\pasbtn") then data[old] = string.gsub(icon, "passivebuttons\\pasbtn", "commandbuttonsdisabled\\dispasbtn" )
            --recommented by hiveworkshop
            elseif string.find(icon, "passivebuttons\\pas") then data[old] = string.gsub(icon, "passivebuttons\\pas", "commandbuttonsdisabled\\dispas" )
            elseif string.find(icon, "commandbuttons\\atc") then data[old] = string.gsub(icon, "commandbuttons\\atc", "commandbuttonsdisabled\\disbtn" ) end
            icon = old
        end
        return data[icon]
    end
end

Example
Lua:
print(BlzGetAbilityIcon(FourCC('Hpal')))
print(GetDisabledIcon(BlzGetAbilityIcon(FourCC('Hpal'))))
print(BlzGetAbilityIcon(GetUnitTypeId(udg_Unit)), GetDisabledIcon(BlzGetAbilityIcon(GetUnitTypeId(udg_Unit))))
 
Top