WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   AddOn Search/Requests (https://www.wowinterface.com/forums/forumdisplay.php?f=6)
-   -   Tooltip Item Level AddOn (https://www.wowinterface.com/forums/showthread.php?t=51537)

Tonyleila 01-15-15 08:09 AM

Tooltip Item Level AddOn
 
There are many AddOns that show the Equipped Item Level in the tooltip but non of them seam to be up to date. Untill now I was using FreebTip that had this integrated but it dosen't work corretly and also buggs if you try to inspect someone :( So I'd like to switch to TipTac but its missing this.
I just need to see the overall itemlevel NOT the item level of each item seperated.

http://www.wowinterface.com/download...ScoreLite.html
http://www.wowinterface.com/download...ItemLevel.html
http://www.wowinterface.com/download...ItemLevel.html
http://www.wowinterface.com/download...elTooltip.html
http://www.curse.com/addons/wow/eil
http://www.curse.com/addons/wow/simple-ilevel --> latest beta bugged/not updated since

http://www.wowinterface.com/download...vgItemLvl.html --> this one is up to date but shows pvp gear with lower item level? Bad idea when pvp items are better the some heroic gear

EKE 01-15-15 11:41 AM

this is an update from villiv's EquippedItemLevel, edit by nj55top

but cant use with freebtip because they get lua code conflict.

Code:

--[[ Equipped Item Level v121025 villiv ]]--

-- decimal places of the equipped average item level. to assign '2' will show it like '123.45'
local DECIMAL_PLACES = 2

-- additional strings. if you don't like it just assign 'nil'. but do not delete these variables themselves.
local UPDATED = CANNOT_COOPERATE_LABEL -- '*'
local WAITING = CONTINUED -- '...'
local PENDING = CONTINUED .. CONTINUED -- '......'

-- output prefix. has to have unique strings to update the tooltip correctly
local PREFIX = STAT_FORMAT:format(STAT_AVERAGE_ITEM_LEVEL) .. '|Heqppditmlvl|h |h' .. HIGHLIGHT_FONT_COLOR_CODE


local f = CreateFrame('Frame')
f:SetScript('OnEvent', function(self, event, ...) return self[event](self, event, ...) end)
f:Hide()

local playerGUID, inCombat, updateTimer
local currentUnit, currentGUID
local isDelayed, isForced, isNotified, isReady

local function GetTipUnit ()
        local _, unit = GameTooltip:GetUnit()
        if ( not unit ) then
                local mouseFocus = GetMouseFocus()
                unit = mouseFocus and (mouseFocus.unit or mouseFocus:GetAttribute('unit'))
        end

        return unit and UnitIsPlayer(unit) and unit
end

local SetTipText
do
        local function search (line, numLines)
                if ( line > numLines ) then return end

                local fontString = _G['GameTooltipTextLeft' .. line]
                local stringText = fontString and fontString:GetText()
                if ( stringText and stringText:match(PREFIX) ) then        return fontString end

                return search(line + 1, numLines)
        end

        function SetTipText (text)
                if ( not text ) then return end

                local fontString = search(1, GameTooltip:NumLines())
                if ( fontString ) then
                        fontString:SetText(PREFIX .. text)
                else
                        GameTooltip:AddLine(PREFIX .. text)
                end

                return GameTooltip:Show()
        end
end

local CanSafeInspect -- 6 times per 10 secs
do
        local limit, period = 6, 11
        local count, startTime = 0, 0

        hooksecurefunc('NotifyInspect', function ()
                local currentTime = GetTime()
                if ( currentTime - startTime > period ) then
                        count, startTime = 1, currentTime
                        return
                end

                count = count + 1
        end)

        function CanSafeInspect (unit)
                if ( not CanInspect(unit) or InspectFrame and InspectFrame:IsShown() or Examiner and Examiner:IsShown() ) then return end

                local pending = count > limit and period - (GetTime() - startTime)
                return true, pending and pending > 0 and pending
        end
end

local UnitItemLevel
do
        local formatString = '%.' .. DECIMAL_PLACES .. 'f'

        local function scan (unit, slot, total, count, twoHanded, incomplete)
                if ( slot > INVSLOT_LAST_EQUIPPED ) then
                        return formatString:format(total / (twoHanded and count - 2 or count-1)), incomplete
                end

                if ( slot == INVSLOT_BODY or slot == INVSLOT_TABARD ) then
                        return scan(unit, slot + 1, total, count, twoHanded, incomplete)
                end

                local hasItem = GetInventoryItemTexture(unit, slot) and true
                local _, level, equipLoc

                local link = hasItem and GetInventoryItemLink(unit, slot)
                if ( link ) then
                        repeat
                                _, _, _, level, _, _, _, _, equipLoc = GetItemInfo(link)
                        until level and equipLoc

                        total = total + level
                end

                -- two-handed weapon and Titan's Grip
                if ( slot == INVSLOT_MAINHAND ) then
                        twoHanded = equipLoc == 'INVTYPE_2HWEAPON' and 1 or not hasItem and 0
                elseif ( slot == INVSLOT_OFFHAND ) then
                        twoHanded = twoHanded == 1 and not hasItem or twoHanded == 0 and equipLoc == 'INVTYPE_2HWEAPON'
                end

                local failed = hasItem and not link
                return scan(unit, slot + 1, total, failed and count or count + 1, twoHanded, incomplete or failed)
        end

        function UnitItemLevel (unit)
                if ( unit == 'player' or UnitIsUnit(unit, 'player') ) then
                        local _, level = GetAverageItemLevel()
                        return formatString:format(level)
                end

                return scan(unit, INVSLOT_FIRST_EQUIPPED, 0, 0)
        end
end

local UpdateItemLevel
do
        local cache = {}
        local cachedLevel

        local function update (unit, guid)
                local level, incomplete = UnitItemLevel(unit)

                if ( incomplete ) then
                        updateTimer = TOOLTIP_UPDATE_TIME
                        f:Show()
                        level = cachedLevel or level
                        return SetTipText(WAITING and level .. WAITING or level)
                end

                if ( isReady ) then
                        cache[guid] = level
                        return SetTipText(UPDATED and level .. UPDATED or level)
                end

                level = cachedLevel or level
                return SetTipText(WAITING and level .. WAITING or level)
        end

        function UpdateItemLevel ()
                cachedLevel = cache[currentGUID]

                if ( inCombat ) then return SetTipText(cachedLevel) end

                if ( isReady ) then return update(currentUnit, currentGUID) end

                if ( not isForced and cachedLevel ) then return SetTipText(cachedLevel) end

                if ( currentGUID == playerGUID ) then
                        local level = UnitItemLevel('player')
                        cache[playerGUID] = level
                        return SetTipText(level)
                end

                local canInspect, pending = CanSafeInspect(currentUnit)
                if ( not canInspect ) then return SetTipText(cachedLevel) end

                if ( pending ) then
                        updateTimer = pending
                        f:Show()
                        return SetTipText(cachedLevel and cachedLevel .. PENDING or PENDING)
                end

                if ( not isDelayed ) then
                        isDelayed = true
                        updateTimer = TOOLTIP_UPDATE_TIME
                        f:Show()
                        return SetTipText(cachedLevel and (WAITING and cachedLevel .. WAITING or cachedLevel) or PENDING)
                end

                if ( not isNotified ) then
                        isNotified = true
                        NotifyInspect(currentUnit)
                end

                return update(currentUnit, currentGUID)
        end
end

local function OnTooltipSetUnit ()
        currentUnit, currentGUID, isDelayed, isForced, isNotified, isReady = GetTipUnit(), nil, nil, nil, nil, nil
        if ( not currentUnit ) then return end

        currentGUID, isForced = UnitGUID(currentUnit), UnitIsUnit(currentUnit, 'target')

        return UpdateItemLevel()
end
GameTooltip:HookScript('OnTooltipSetUnit', OnTooltipSetUnit)

f:SetScript('OnUpdate', function (self, elapsed)
        updateTimer = updateTimer - elapsed
        if ( updateTimer > 0 ) then return end
        self:Hide()

        if ( not currentGUID ) then return end

        local tipUnit = GetTipUnit()
        if ( not tipUnit or UnitGUID(tipUnit) ~= currentGUID ) then return end

        return UpdateItemLevel()
end)

function f:INSPECT_READY (_, guid)
        if ( not currentGUID or guid ~= currentGUID ) then return end

        local tipUnit = GetTipUnit()
        if ( not tipUnit or UnitGUID(tipUnit) ~= currentGUID ) then return end

        isReady = true

        return UpdateItemLevel()
end
f:RegisterEvent('INSPECT_READY')

function f:UNIT_INVENTORY_CHANGED (_, unit)
        if ( not currentGUID or UnitGUID(unit) ~= currentGUID ) then return end

        local tipUnit = GetTipUnit()
        if ( not tipUnit or UnitGUID(tipUnit) ~= currentGUID ) then return end

        isForced, isNotified, isReady = true, nil, nil

        return UpdateItemLevel()
end
f:RegisterEvent('UNIT_INVENTORY_CHANGED')

function f:PLAYER_TARGET_CHANGED ()
        return self:UNIT_INVENTORY_CHANGED (nil, 'target')
end
f:RegisterEvent('PLAYER_TARGET_CHANGED')

function f:PLAYER_REGEN_DISABLED ()
        inCombat = true
end
f:RegisterEvent('PLAYER_REGEN_DISABLED')

function f:PLAYER_REGEN_ENABLED ()
        inCombat = nil
end
f:RegisterEvent('PLAYER_REGEN_ENABLED')

function f:PLAYER_LOGIN ()
        self:UnregisterEvent('PLAYER_LOGIN')
        self.PLAYER_LOGIN = nil

        playerGUID = UnitGUID('player')
end

if ( IsLoggedIn() ) then
        f:PLAYER_LOGIN()
        inCombat = InCombatLockdown()
        return OnTooltipSetUnit()
end

return f:RegisterEvent('PLAYER_LOGIN')


Tonyleila 01-15-15 05:50 PM

Thank you very much! It works fine with TipTac.

BTW you can attach zip and lua files to your forum posts ;)

EKE 01-15-15 09:12 PM

Quote:

Originally Posted by Tonyleila (Post 304953)
Thank you very much! It works fine with TipTac.

BTW you can attach zip and lua files to your forum posts ;)

well err im not the auther or editer, also use forum first time....

actually i hope can find other lite addon to replace freebtip_ilvl and freeb_spec

Tonyleila 01-16-15 07:13 AM

Quote:

Originally Posted by EKE (Post 304958)
well err im not the auther or editer, also use forum first time....

actually i hope can find other lite addon to replace freebtip_ilvl and freeb_spec

What are you missing in TipTac? Its also very lite and TipTacTalents and TipTacItemRef can be removed. The Author seams to be very active.

EKE 01-16-15 02:30 PM

Quote:

Originally Posted by Tonyleila (Post 304972)
What are you missing in TipTac? Its also very lite and TipTacTalents and TipTacItemRef can be removed. The Author seams to be very active.

i use tiptac few years ago , but for my habit, i like no SavedVariables, no gui addon, just my preferences.

Tonyleila 01-16-15 02:33 PM

Quote:

Originally Posted by EKE (Post 305001)
i use tiptac few years ago , but for my habit, i like no SavedVariables, no gui addon, just my preferences.

FreebTip has SavedVariables and TipTac options can be changed in core.lua and then you can just remove the TipTacOptions folder.

Seerah 01-16-15 03:07 PM

Quote:

Originally Posted by EKE (Post 305001)
i use tiptac few years ago , but for my habit, i like no SavedVariables, no gui addon, just my preferences.

Just curious, but are you running a machine with only 2GB of RAM? ;)

EKE 01-16-15 04:03 PM

Quote:

Originally Posted by Tonyleila (Post 305002)
FreebTip has SavedVariables and TipTac options can be changed in core.lua and then you can just remove the TipTacOptions folder.

just only tooltip anchor can be ignore and i dont need much config XD

EKE 01-16-15 04:15 PM

Quote:

Originally Posted by Seerah (Post 305006)
Just curious, but are you running a machine with only 2GB of RAM? ;)

hahahaha not

my computer running with 16GB ram, so i said just my strange preferences O.o

Tonyleila 01-16-15 07:01 PM

So I'm not 100% happy with the code yet.
I'd like disable this part of the tooltip for e.g. group members that are not in range, when you hoover them it trys to update and trys and that looks odd :D
But it also shoud be possible to view the itemlevel of group/raid members that are not in range because you can inspect there gear when they are in your group even if there are not in range.

pas06 12-01-15 02:43 PM

the code above shows an too low item level for hunters for me. Don't you have that problem?

Tonyleila 12-01-15 03:19 PM

Quote:

Originally Posted by pas06 (Post 312092)
the code above shows an too low item level for hunters for me. Don't you have that problem?

Yes :(
and if I remember right its also has another wrong display for something. Woud be great if someone coud fix it ;)

Tonyleila 12-02-15 12:48 PM

Uhm... where is the post that some guy here posted yesterday with new addon code?? I woud like to test it :( please

pas06 12-02-15 01:09 PM

i posted it but i deleted it because i was not sure if it is against any license because i copy and pasted stuff and mofified it

Tonyleila 12-02-15 03:24 PM

Quote:

Originally Posted by pas06 (Post 312114)
i posted it but i deleted it because i was not sure if it is against any license because i copy and pasted stuff and mofified it

Its not. But if you don't want to share it again here woud be cool if you coud send me the code via PM ;)


All times are GMT -6. The time now is 10:15 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI