Thread Tools Display Modes
11-27-09, 02:45 PM   #1
Tastyfrog
A Deviate Faerie Dragon
Join Date: Mar 2009
Posts: 15
Sorting of auras

This might be a stupid question (because im really new to oUF), but is it possible to sort buffs?
  Reply With Quote
11-27-09, 04:07 PM   #2
haste
Featured Artist
 
haste's Avatar
Premium Member
Featured
Join Date: Dec 2005
Posts: 1,027
Originally Posted by Tastyfrog View Post
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.
__________________
「貴方は1人じゃないよ」
  Reply With Quote
11-27-09, 04:10 PM   #3
Dawn
A Molten Giant
 
Dawn's Avatar
AddOn Author - Click to view addons
Join Date: May 2006
Posts: 918
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.
__________________
Rock: "We're sub-standard DPS. Nerf Paper, Scissors are fine."
Paper: "OMG, WTF, Scissors!"
Scissors: "Rock is OP and Paper are QQers. We need PvP buffs."

"neeh the game wont be remembered as the game who made blizz the most money, it will be remembered as the game who had the most QQ'ers that just couldnt quit the game for some reason..."

  Reply With Quote
11-27-09, 04:12 PM   #4
haste
Featured Artist
 
haste's Avatar
Premium Member
Featured
Join Date: Dec 2005
Posts: 1,027
Depends on how you want to sort really. But what issues did you run into and with what sort function?
__________________
「貴方は1人じゃないよ」
  Reply With Quote
11-27-09, 04:32 PM   #5
Dawn
A Molten Giant
 
Dawn's Avatar
AddOn Author - Click to view addons
Join Date: May 2006
Posts: 918
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.
__________________
Rock: "We're sub-standard DPS. Nerf Paper, Scissors are fine."
Paper: "OMG, WTF, Scissors!"
Scissors: "Rock is OP and Paper are QQers. We need PvP buffs."

"neeh the game wont be remembered as the game who made blizz the most money, it will be remembered as the game who had the most QQ'ers that just couldnt quit the game for some reason..."

  Reply With Quote
11-27-09, 04:54 PM   #6
haste
Featured Artist
 
haste's Avatar
Premium Member
Featured
Join Date: Dec 2005
Posts: 1,027
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.
__________________
「貴方は1人じゃないよ」
  Reply With Quote
11-27-09, 06:39 PM   #7
Tastyfrog
A Deviate Faerie Dragon
Join Date: Mar 2009
Posts: 15
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
  Reply With Quote
11-28-09, 04:13 AM   #8
Dawn
A Molten Giant
 
Dawn's Avatar
AddOn Author - Click to view addons
Join Date: May 2006
Posts: 918
Originally Posted by haste View Post
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.


*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.
__________________
Rock: "We're sub-standard DPS. Nerf Paper, Scissors are fine."
Paper: "OMG, WTF, Scissors!"
Scissors: "Rock is OP and Paper are QQers. We need PvP buffs."

"neeh the game wont be remembered as the game who made blizz the most money, it will be remembered as the game who had the most QQ'ers that just couldnt quit the game for some reason..."

  Reply With Quote
11-28-09, 07:36 AM   #9
haste
Featured Artist
 
haste's Avatar
Premium Member
Featured
Join Date: Dec 2005
Posts: 1,027
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.
__________________
「貴方は1人じゃないよ」
  Reply With Quote
11-28-09, 09:24 AM   #10
p3lim
A Pyroguard Emberseer
 
p3lim's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 1,710
Originally Posted by haste View Post
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.
  Reply With Quote
11-28-09, 11:23 AM   #11
Dawn
A Molten Giant
 
Dawn's Avatar
AddOn Author - Click to view addons
Join Date: May 2006
Posts: 918
I got no error, but no sort effect, either. Crazy stuff.
__________________
Rock: "We're sub-standard DPS. Nerf Paper, Scissors are fine."
Paper: "OMG, WTF, Scissors!"
Scissors: "Rock is OP and Paper are QQers. We need PvP buffs."

"neeh the game wont be remembered as the game who made blizz the most money, it will be remembered as the game who had the most QQ'ers that just couldnt quit the game for some reason..."

  Reply With Quote
11-28-09, 12:34 PM   #12
wurmfood
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Apr 2009
Posts: 122
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.
  Reply With Quote
11-28-09, 12:49 PM   #13
haste
Featured Artist
 
haste's Avatar
Premium Member
Featured
Join Date: Dec 2005
Posts: 1,027
Originally Posted by wurmfood View Post
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.
__________________
「貴方は1人じゃないよ」
  Reply With Quote
12-02-09, 09:02 AM   #14
haste
Featured Artist
 
haste's Avatar
Premium Member
Featured
Join Date: Dec 2005
Posts: 1,027
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.
__________________
「貴方は1人じゃないよ」
  Reply With Quote
12-02-09, 11:56 AM   #15
wurmfood
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Apr 2009
Posts: 122
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.
  Reply With Quote
12-02-09, 12:28 PM   #16
haste
Featured Artist
 
haste's Avatar
Premium Member
Featured
Join Date: Dec 2005
Posts: 1,027
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.
__________________
「貴方は1人じゃないよ」
  Reply With Quote
12-02-09, 03:09 PM   #17
Dawn
A Molten Giant
 
Dawn's Avatar
AddOn Author - Click to view addons
Join Date: May 2006
Posts: 918
We're just assuming that we are wrong, since you can't!
__________________
Rock: "We're sub-standard DPS. Nerf Paper, Scissors are fine."
Paper: "OMG, WTF, Scissors!"
Scissors: "Rock is OP and Paper are QQers. We need PvP buffs."

"neeh the game wont be remembered as the game who made blizz the most money, it will be remembered as the game who had the most QQ'ers that just couldnt quit the game for some reason..."

  Reply With Quote
12-02-09, 03:26 PM   #18
Dawn
A Molten Giant
 
Dawn's Avatar
AddOn Author - Click to view addons
Join Date: May 2006
Posts: 918
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.
__________________
Rock: "We're sub-standard DPS. Nerf Paper, Scissors are fine."
Paper: "OMG, WTF, Scissors!"
Scissors: "Rock is OP and Paper are QQers. We need PvP buffs."

"neeh the game wont be remembered as the game who made blizz the most money, it will be remembered as the game who had the most QQ'ers that just couldnt quit the game for some reason..."


Last edited by Dawn : 12-02-09 at 03:30 PM.
  Reply With Quote
12-02-09, 03:28 PM   #19
haste
Featured Artist
 
haste's Avatar
Premium Member
Featured
Join Date: Dec 2005
Posts: 1,027
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 .
__________________
「貴方は1人じゃないよ」
  Reply With Quote
12-02-09, 03:30 PM   #20
Dawn
A Molten Giant
 
Dawn's Avatar
AddOn Author - Click to view addons
Join Date: May 2006
Posts: 918
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.
__________________
Rock: "We're sub-standard DPS. Nerf Paper, Scissors are fine."
Paper: "OMG, WTF, Scissors!"
Scissors: "Rock is OP and Paper are QQers. We need PvP buffs."

"neeh the game wont be remembered as the game who made blizz the most money, it will be remembered as the game who had the most QQ'ers that just couldnt quit the game for some reason..."

  Reply With Quote

WoWInterface » Featured Projects » oUF (Otravi Unit Frames) » Sorting of auras

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off