WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   oUF (Otravi Unit Frames) (https://www.wowinterface.com/forums/forumdisplay.php?f=87)
-   -   Sorting of auras (https://www.wowinterface.com/forums/showthread.php?t=28802)

Tastyfrog 11-27-09 02:45 PM

Sorting of auras
 
This might be a stupid question (because im really new to oUF), but is it possible to sort buffs?

haste 11-27-09 04:07 PM

Quote:

Originally Posted by Tastyfrog (Post 167236)
This might be a stupid question (because im really new to oUF), but is it possible to sort buffs?

Yes, you can sort buffs with :PreAuraSetPosition(auras, max). It does however require you to implement your own sort function. The oUF aura/buffs/debuffs tables are designed to support table.sort however.

Dawn 11-27-09 04:10 PM

It's damn tricky and I don't know if anyone got a working way that doesn't bug out now and then.

Edit: haste beat me to it... however, it's surely possible, just not sure if anyone (besides haste) is clever enough to code it. :D

haste 11-27-09 04:12 PM

Depends on how you want to sort really. But what issues did you run into and with what sort function?

Dawn 11-27-09 04:32 PM

I managed to sort it by time left, but from time to time some buffs disappeared from the buff list.

Like
BUFFICON 1, BUFFICON 2, BUFFICON 3
becomes
BUFFICON 1, BUFFICON 3

while BUFF 2 is still there, just the icon got "overridden" ... strange thing. :)

haste 11-27-09 04:54 PM

That doesn't show any code tho' :P. Anyway, a quick and dirty example on how to do aura sorting can found on this post.

Tastyfrog 11-27-09 06:39 PM

wow, it is actually kinda easy to sort buffs. thanks.

my code:
Code:

local prePosition = function(self, a, n)
        table.sort(a, function(a,b) return a.timeLeft>b.timeLeft end)
end


Dawn 11-28-09 04:13 AM

Quote:

Originally Posted by haste (Post 167248)
That doesn't show any code tho' :P. Anyway, a quick and dirty example on how to do aura sorting can found on this post.

I was doing it similar to this:

Code:

local preAuraSetPosition = function(self, buffs, max)
        local visBuffs = 0
        for i=1, #buffs do
                if( buffs[i].timeLeft == nil ) then
                        buffs[i].timeLeft = 0
                end
                if( buffs[i]:IsShown() ) then
                        visBuffs = visBuffs + 1
                end
        end
       
        if(visBuffs == 0 ) then
                buffs:SetHeight(0)
        else
                buffs:SetHeight(math.ceil((visBuffs/10)) * 26 )
        end
       
        table.sort(buffs, function(a,b) return a.timeLeft > b.timeLeft end)
end

note:
This is taken from oUF_Banthis, since I don't have the exact piece of code I used, still around. However, that code above is having the same issues of "disappearing" buff icons, with still active buffs.


Quote:

*In some strange cases, the auras (which are divided into those that expire and don't, aka auras and buffs) will jump around with blank spaces between them. I have no idea why. Adding an aura (like a hunter aspect) makes it stop.

The thing with the code you linked in that post is that it still crits me for over NIIIINEEEETHOOOOOUSAAAND. And I didn't find the time to play around with it, until now. Seems like I have to take enough time to look into it. :banana:

haste 11-28-09 07:36 AM

There's a couple of things you want to think of when you want to sort auras using table.sort:
1. Auras that aren't shown also have outdated information.
2. Auras with no duration are represented as 0 in duration.

The following should handle both those cases:
Lua Code:
  1. local CustomAuraFilter = function(icons, unit, icon, name, rank, texture, count, dtype, duration, timeLeft, caster)
  2.        local isPlayer
  3.  
  4.        if(caster == 'player' or caster == 'vehicle') then
  5.                isPlayer = true
  6.        end
  7.  
  8.        if((icons.onlyShowPlayer and isPlayer) or (not icons.onlyShowPlayer and name)) then
  9.                icon.isPlayer = isPlayer
  10.                icon.owner = caster
  11.  
  12.                -- We set it to math.huge, because it lasts until cancelled.
  13.                if(timeLeft == 0) then
  14.                        icon.timeLeft = math.huge
  15.                else
  16.                        icon.timeLeft = timeLeft
  17.                end
  18.  
  19.                return true
  20.        end
  21. end
  22.  
  23. local sort = function(a, b)
  24.        return (a.timeLeft and a.timeLeft) > (b.timeLeft and b.timeLeft)
  25. end
  26. local PreAuraSetPosition = function(self, auras, max)
  27.        -- Make all hidden icons "invalid"
  28.        for i=1, max do
  29.                local icon = auras[i]
  30.                if(not icon:IsShown()) then
  31.                        icon.timeLeft = nil
  32.                end
  33.        end
  34.  
  35.        table.sort(auras, sort)
  36. end
CustomAuraFilter is pretty much a copy/paste of the one oUF uses internally, but with timeLeft added.

p3lim 11-28-09 09:24 AM

Quote:

Originally Posted by haste (Post 167299)
There's a couple of things you want to think of when you want to sort auras using table.sort:
1. Auras that aren't shown also have outdated information.
2. Auras with no duration are represented as 0 in duration.

The following should handle both those cases:
Lua Code:
  1. local CustomAuraFilter = function(icons, unit, icon, name, rank, texture, count, dtype, duration, timeLeft, caster)
  2.        local isPlayer
  3.  
  4.        if(caster == 'player' or caster == 'vehicle') then
  5.                isPlayer = true
  6.        end
  7.  
  8.        if((icons.onlyShowPlayer and isPlayer) or (not icons.onlyShowPlayer and name)) then
  9.                icon.isPlayer = isPlayer
  10.                icon.owner = caster
  11.  
  12.                -- We set it to math.huge, because it lasts until cancelled.
  13.                if(timeLeft == 0) then
  14.                        icon.timeLeft = math.huge
  15.                else
  16.                        icon.timeLeft = timeLeft
  17.                end
  18.  
  19.                return true
  20.        end
  21. end
  22.  
  23. local sort = function(a, b)
  24.        return (a.timeLeft and a.timeLeft) > (b.timeLeft and b.timeLeft)
  25. end
  26. local PreAuraSetPosition = function(self, auras, max)
  27.        -- Make all hidden icons "invalid"
  28.        for i=1, max do
  29.                local icon = auras[i]
  30.                if(not icon:IsShown()) then
  31.                        icon.timeLeft = nil
  32.                end
  33.        end
  34.  
  35.        table.sort(auras, sort)
  36. end
CustomAuraFilter is pretty much a copy/paste of the one oUF uses internally, but with timeLeft added.

Error on line 24, comparing number with nil.

Dawn 11-28-09 11:23 AM

I got no error, but no sort effect, either. Crazy stuff. :cool:

wurmfood 11-28-09 12:34 PM

Using math.huge is a really good idea. Depending on your personal preferences though on how to sort auras, I'd suggest setting auras (timeleft = nil) to either math.huge or 0, and if the aura isn't shown, set it to -1. Using -1 ensures it's always outside the normal range and might take care of the blank space issue.

haste 11-28-09 12:49 PM

Quote:

Originally Posted by wurmfood (Post 167324)
Using math.huge is a really good idea. Depending on your personal preferences though on how to sort auras, I'd suggest setting auras (timeleft = nil) to either math.huge or 0, and if the aura isn't shown, set it to -1. Using -1 ensures it's always outside the normal range and might take care of the blank space issue.

I support this post.

haste 12-02-09 09:02 AM

You know the spacing issue, that no-one wanted to report? Here's a fix for it. Below is also revised aura sorting without any extra cruft.
lua Code:
  1. local CustomAuraFilter = function(icons, unit, icon, name, rank, texture, count, dtype, duration, timeLeft, caster)
  2.        local isPlayer
  3.  
  4.        if(caster == 'player' or caster == 'vehicle') then
  5.                isPlayer = true
  6.        end
  7.  
  8.        if((icons.onlyShowPlayer and isPlayer) or (not icons.onlyShowPlayer and name)) then
  9.                icon.isPlayer = isPlayer
  10.                icon.owner = caster
  11.  
  12.                -- We set it to math.huge, because it lasts until cancelled.
  13.                if(timeLeft == 0) then
  14.                        icon.timeLeft = math.huge
  15.                else
  16.                        icon.timeLeft = timeLeft
  17.                end
  18.  
  19.                return true
  20.        end
  21. end
  22.  
  23. local sort = function(a, b)
  24.        return a.timeLeft > b.timeLeft
  25. end
  26.  
  27. local PreAuraSetPosition = function(self, auras, max)
  28.        table.sort(auras, sort)
  29. end

I'll try to push out 1.3.22 soonish, just need to level a DK and figure out how death runes work so I can fix the runebar bug people are complaining about.

wurmfood 12-02-09 11:56 AM

Heh, I just always assumed the gaps were caused by something I was doing wrong, not a problem in oUF. Thanks for the fix, though.

haste 12-02-09 12:28 PM

It's better that people report possible errors than ignoring them, as the last won't make them get fixed until I notice them myself.

Dawn 12-02-09 03:09 PM

We're just assuming that we are wrong, since you can't! ;)

Dawn 12-02-09 03:26 PM

Double post inc..

Just for the record: Why not add aura sorting to oUF core? I mean it's a really good thing in general.

haste 12-02-09 03:28 PM

I don't really see why it should be needed. You can already do it quite easily. Depending on what/how you want to sort ofc :).

Dawn 12-02-09 03:30 PM

I get the following error (several times) with that github version you posted above. :)

Code:

22.26  oUF: Error: Handler for event [UNIT_COMBAT] on unit [unknown] does not exist.
And the sorting function doesn't sort something, maybe I'm copy pasting it wrong, though. Even though I get no errors, just no sorting. :banana:


All times are GMT -6. The time now is 11:41 AM.

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