Thread Tools Display Modes
05-15-11, 12:13 AM   #1
lastgamer
A Deviate Faerie Dragon
Join Date: Oct 2009
Posts: 11
How to

Hi,guys. I want to set aura position. How can i make OUF AURA like this :
Code:
local AURA_START_X = 4;
local AURA_START_Y = 32;
local AURA_OFFSET_Y = 2;
local LARGE_AURA_SIZE = 50;		
local SMALL_AURA_SIZE = 23;		
local FIRST_AURA_ROW_WIDTH = 122;
local AURA_ROW_WIDTH =200;
local TOT_AURA_ROW_WIDTH = 101;
local NUM_TOT_AURA_ROWS = 2;		

local largeBuffList = {};
local largeDebuffList = {};
local auraRows = 0
local PLAYER_UNITS = {
	player = true,
	vehicle = true,
	pet = true,
};

hooksecurefunc("TargetFrame_OnUpdate", function(self)
	TargetFrame_UpdateAuras (self)
end)

function TargetFrame_UpdateAuras (self)
	local frame, frameName;
	local frameIcon, frameCount, frameCooldown;

	local name, rank, icon, count, debuffType, duration, expirationTime, caster, isStealable;
	local playerIsTarget = UnitIsUnit(PlayerFrame.unit, "target");

	local frameStealable;
	local color;
	local frameBorder;
	local numBuffs = 0;
	for i=1, MAX_TARGET_BUFFS do
		name, rank, icon, count, debuffType, duration, expirationTime, caster, isStealable = UnitBuff("target", i);
		frameName = "TargetFrameBuff"..i;
		frame = _G[frameName];
		if ( not frame ) then
			if ( not icon ) then
				break;
			else
				frame = CreateFrame("Button", frameName, TargetFrame, "TargetBuffFrameTemplate");
				frame.unit = "target";
			end
		end
		if ( icon ) then
			frame:SetID(i);

			-- set the icon
			frameIcon = _G[frameName.."Icon"];
			frameIcon:SetTexture(icon);

			-- set the count
			frameCount = _G[frameName.."Count"];
			if ( count > 1 ) then
				frameCount:SetText(count);
				frameCount:Show();
			else
				frameCount:Hide();
			end

			-- Handle cooldowns
			frameCooldown = _G[frameName.."Cooldown"];
			if ( duration > 0 ) then
				frameCooldown:Show();
				CooldownFrame_SetTimer(frameCooldown, expirationTime - duration, duration, 1);
			else
				frameCooldown:Hide();
			end
			-- Show stealable frame if the target is not a player and the buff is stealable.
			frameStealable = _G[frameName.."Stealable"];
			if ( not playerIsTarget and isStealable ) then
				frameStealable:Show();
			else
				frameStealable:Hide();
			end

			-- set the buff to be big if the target is not the player and the buff is cast by the player or his pet
			largeBuffList[i] = (not playerIsTarget and PLAYER_UNITS[caster]);

			numBuffs = numBuffs + 1;

			frame:ClearAllPoints();
			frame:Show();
		else
			frame:Hide();
		end
	end

	local color;
	local frameBorder;
	local numDebuffs = 0;
	for i=1, MAX_TARGET_DEBUFFS do
		name, rank, icon, count, debuffType, duration, expirationTime, caster = UnitDebuff("target", i);
		frameName = "TargetFrameDebuff"..i;
		frame = _G[frameName];
		if ( not frame ) then
			if ( not icon ) then
				break;
			else
				frame = CreateFrame("Button", frameName, TargetFrame, "TargetDebuffFrameTemplate");
				frame.unit = "target";
			end
		end
		if ( icon ) then
			frame:SetID(i);

			-- set the icon
			frameIcon = _G[frameName.."Icon"];
			frameIcon:SetTexture(icon);

			-- set the count
			frameCount = _G[frameName.."Count"];
			if ( count > 1 ) then
				frameCount:SetText(count);
				frameCount:Show();
			else
				frameCount:Hide();
			end

			-- Handle cooldowns
			frameCooldown = _G[frameName.."Cooldown"];
			if ( duration > 0 ) then
				frameCooldown:Show();
				CooldownFrame_SetTimer(frameCooldown, expirationTime - duration, duration, 1);
			else
				frameCooldown:Hide();
			end

			-- set debuff type color
			if ( debuffType ) then
				color = DebuffTypeColor[debuffType];
			else
				color = DebuffTypeColor["none"];
			end
			frameBorder = _G[frameName.."Border"];
                        frameBorder:SetVertexColor(0.8, 0.3, 0.3);
			--frameBorder:SetVertexColor(color.r, color.g, color.b);

			-- set the debuff to be big if the buff is cast by the player or his pet
			largeDebuffList[i] = (PLAYER_UNITS[caster]);

			numDebuffs = numDebuffs + 1;

			frame:ClearAllPoints();
			frame:Show();
		else
			frame:Hide();
		end
	end

	auraRows = 0;
	local haveTargetofTarget = TargetFrameToT:IsShown();
	local maxRowWidth;
        local buffsOnTop = ( UnitIsFriend("player", "target") or numDebuffs == 0 );
        if (buffsOnTop) then
	-- update buff positions
	maxRowWidth = ( haveTargetofTarget and TOT_AURA_ROW_WIDTH ) or AURA_ROW_WIDTH;
	TargetFrame_UpdateAuraPositions("TargetFrameBuff", numBuffs, numDebuffs, largeBuffList, TargetFrame_UpdateBuffAnchor, maxRowWidth, 3, buffsOnTop and FIRST_AURA_ROW_WIDTH or maxRowWidth);
	end
 -- update debuff positions
	maxRowWidth = ( haveTargetofTarget and TargetFrame.auraRows < NUM_TOT_AURA_ROWS and TOT_AURA_ROW_WIDTH ) or AURA_ROW_WIDTH;
	TargetFrame_UpdateAuraPositions("TargetFrameDebuff", numDebuffs, numBuffs, largeDebuffList, TargetFrame_UpdateDebuffAnchor, maxRowWidth, 3, buffsOnTop and maxRowWidth or FIRST_AURA_ROW_WIDTH);
		if (not buffsOnTop) then
		-- update buff positions
		maxRowWidth = ( haveTargetofTarget and auraRows <= NUM_TOT_AURA_ROWS and TOT_AURA_ROW_WIDTH ) or AURA_ROW_WIDTH;
		TargetFrame_UpdateAuraPositions("TargetFrameBuff", numBuffs, numDebuffs, largeBuffList, TargetFrame_UpdateBuffAnchor, maxRowWidth, 3, buffsOnTop and FIRST_AURA_ROW_WIDTH or maxRowWidth);
	end
-- update the spell bar position
	if TargetFrame.spellBar then
		TargetFrame_Target_Spellbar_AdjustPosition(TargetFrame.spellBar)
	end
end

function TargetFrame_UpdateAuraPositions(auraName, numAuras, numOppositeAuras, largeAuraList, updateFunc, maxRowWidth, offsetX, firstRowLength)
	-- a lot of this complexity is in place to allow the auras to wrap around the target of target frame if it's shown

	-- Position auras
	local size;
	local offsetY = AURA_OFFSET_Y;
	-- current width of a row, increases as auras are added and resets when a new aura's width exceeds the max row width
	local rowWidth = 0;
	local firstBuffOnRow = 1;
	for i=1, numAuras do
		-- update size and offset info based on large aura status
		if ( largeAuraList[i] ) then
			size = LARGE_AURA_SIZE;
			offsetY = AURA_OFFSET_Y + AURA_OFFSET_Y;
		else
			size = SMALL_AURA_SIZE;
		end

		-- anchor the current aura
		if ( i == 1 ) then
			rowWidth = size;
			auraRows = auraRows + 1;
		else
			rowWidth = rowWidth + size + offsetX;
		end
		if ( rowWidth > maxRowWidth or auraRows == 1 and rowWidth > firstRowLength ) then
			-- this aura would cause the current row to exceed the max row width, so make this aura
			-- the start of a new row instead
                        _G[auraName..i]:ClearAllPoints()
			updateFunc(auraName, i, numOppositeAuras, firstBuffOnRow, size, offsetX, offsetY);

			rowWidth = size;
			auraRows = auraRows + 1;
			firstBuffOnRow = i;
			offsetY = AURA_OFFSET_Y;

			if ( auraRows > NUM_TOT_AURA_ROWS ) then
				-- if we exceed the number of tot rows, then reset the max row width
				-- note: don't have to check if we have tot because AURA_ROW_WIDTH is the default anyway
				maxRowWidth = AURA_ROW_WIDTH;
			end
		else
                        _G[auraName..i]:ClearAllPoints()
			updateFunc(auraName, i, numOppositeAuras, i - 1, size, offsetX, offsetY);
		end
	end
end

function TargetFrame_UpdateBuffAnchor(buffName, index, numDebuffs, anchorIndex, size, offsetX, offsetY)
	local buff = _G[buffName..index];

	if ( index == 1 ) then
		if ( UnitIsFriend("player", "target") or numDebuffs == 0 ) then
			-- unit is friendly or there are no debuffs...buffs start on top
			buff:SetPoint("TOPLEFT", TargetFrame, "BOTTOMLEFT", AURA_START_X, AURA_START_Y);
		else
			-- unit is not friendly and we have debuffs...buffs start on bottom
			buff:SetPoint("TOPLEFT", TargetFrameDebuffs, "BOTTOMLEFT", 0, -offsetY);
		end
		TargetFrameBuffs:SetPoint("TOPLEFT", buff, "TOPLEFT", 0, 0);
		TargetFrameBuffs:SetPoint("BOTTOMLEFT", buff, "BOTTOMLEFT", 0, -AURA_OFFSET_Y);
	elseif ( anchorIndex ~= (index-1) ) then
		-- anchor index is not the previous index...must be a new row
		buff:SetPoint("TOPLEFT", _G[buffName..anchorIndex], "BOTTOMLEFT", 0, -offsetY);
		TargetFrameBuffs:SetPoint("BOTTOMLEFT", buff, "BOTTOMLEFT", 0, -AURA_OFFSET_Y);
	else
		-- anchor index is the previous index
		buff:SetPoint("TOPLEFT", _G[buffName..anchorIndex], "TOPRIGHT", offsetX, 0);
	end

	-- Resize
	buff:SetWidth(size);
	buff:SetHeight(size);
end
function TargetFrame_UpdateDebuffAnchor(debuffName, index, numBuffs, anchorIndex, size, offsetX, offsetY)
	local buff = _G[debuffName..index];

	if ( index == 1 ) then
		if ( UnitIsFriend("player", "target") and numBuffs > 0 ) then
			-- unit is friendly and there are buffs...debuffs start on bottom
			buff:SetPoint("TOPLEFT", TargetFrameBuffs, "BOTTOMLEFT", 0, -offsetY);
		else
			-- unit is not friendly or there are no buffs...debuffs start on top
			buff:SetPoint("TOPLEFT", TargetFrame, "BOTTOMLEFT", AURA_START_X, AURA_START_Y);
		end
		TargetFrameDebuffs:SetPoint("TOPLEFT", buff, "TOPLEFT", 0, 0);
		TargetFrameDebuffs:SetPoint("BOTTOMLEFT", buff, "BOTTOMLEFT", 0, -AURA_OFFSET_Y);
	elseif ( anchorIndex ~= (index-1) ) then
		-- anchor index is not the previous index...must be a new row
		buff:SetPoint("TOPLEFT", _G[debuffName..anchorIndex], "BOTTOMLEFT", 0, -offsetY);
		TargetFrameDebuffs:SetPoint("BOTTOMLEFT", buff, "BOTTOMLEFT", 0, -AURA_OFFSET_Y);
	else
		-- anchor index is the previous index
		buff:SetPoint("TOPLEFT", _G[debuffName..(index-1)], "TOPRIGHT", offsetX, 0);
	end

	-- Resize
	buff:SetWidth(size);
	buff:SetHeight(size);
	local debuffFrame =_G[debuffName..index.."Border"];
	debuffFrame:SetWidth(size+2);
	debuffFrame:SetHeight(size+2);
end

function Target_Spellbar_AdjustPosition ()
	local yPos = 5;
	if ( TargetFrame.auraRows ) then
		if ( TargetFrame.auraRows <= NUM_TOT_AURA_ROWS ) then
			yPos = LARGE_AURA_SIZE + SMALL_AURA_SIZE;
		else
			yPos = (LARGE_AURA_SIZE - 3) * TargetFrame.auraRows;
		end
	end
	if ( TargetFrameToT:IsShown() ) then
		if ( yPos <= 25 ) then
			yPos = yPos + 25;
		end
	else
		yPos = yPos - 5;
		local classification = UnitClassification("target");
		if ( (yPos < 17) and ((classification == "worldboss") or (classification == "rareelite") or (classification == "elite") or (classification == "rare")) ) then
			yPos = 17;
		end
	end
	TargetFrameSpellBar:SetPoint("BOTTOM", "TargetFrame", "BOTTOM", -15, -yPos);
end
thanks
  Reply With Quote
05-15-11, 06:08 AM   #2
haste
Featured Artist
 
haste's Avatar
Premium Member
Featured
Join Date: Dec 2005
Posts: 1,027
You ask how, but what you want is someone to do it for you. People here will help you reach the goal, but they generally won't do all the work for you.

To answer how:
There's no easy solution to this. You would have to go over what the code currently does, and refactor it to replace oUF's :SetPosition with a user-defined one.

Note that a lot of the code you pasted handles updating as well, which won't really be needed anymore, as oUF does that already.
__________________
「貴方は1人じゃないよ」
  Reply With Quote
05-20-11, 02:39 AM   #3
lastgamer
A Deviate Faerie Dragon
Join Date: Oct 2009
Posts: 11
I'm sorry for my English and i'm not good enough at Lua

my question:
1:I make debuffs that cast by me bigger like this:
Code:
       local button = icons[index + offset]
               if icon.debuff and button.isPlayer then   
                       button:SetHeight(icons.size + 7)
                       button:SetWidth(icons.size + 7)
                       icon.overlay:SetVertexColor(0.9, 0.1, 0.1)
               else
                       button:SetHeight(23)
                       button:SetWidth(23)
                       icon.overlay:SetVertexColor(0.6, 0.6, 0.6)
       end
But the bigger debuffs and others are overlapping

2: I want there're four auras in the first and second row if targettarget, otherwize six per row.

Thanks very very mush.
Attached Thumbnails
Click image for larger version

Name:	123.jpg
Views:	1339
Size:	6.2 KB
ID:	6178  
  Reply With Quote
05-21-11, 10:51 PM   #4
lastgamer
A Deviate Faerie Dragon
Join Date: Oct 2009
Posts: 11
I need some help
  Reply With Quote
05-22-11, 12:22 PM   #5
Dawn
A Molten Giant
 
Dawn's Avatar
AddOn Author - Click to view addons
Join Date: May 2006
Posts: 918
Take a look at the code again, you need to adress the "offsetY" for new rows.
__________________
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
05-23-11, 09:13 AM   #6
lastgamer
A Deviate Faerie Dragon
Join Date: Oct 2009
Posts: 11
Hi,haste and Dawn,Thanks for the hint. But i'm a beginner,can you give me more suggestion?

Thank you.
  Reply With Quote
05-23-11, 09:48 AM   #7
haste
Featured Artist
 
haste's Avatar
Premium Member
Featured
Join Date: Dec 2005
Posts: 1,027
As mentioned earlier. You have to implement your own :SetPosition which handles icons with variable height/width.

There isn't really much more suggestions to give, without starting to write the code for you.
__________________
「貴方は1人じゃないよ」
  Reply With Quote
05-24-11, 01:14 AM   #8
lastgamer
A Deviate Faerie Dragon
Join Date: Oct 2009
Posts: 11

Thank you.
It's really a thorny problem.
  Reply With Quote
05-24-11, 07:57 AM   #9
Dawn
A Molten Giant
 
Dawn's Avatar
AddOn Author - Click to view addons
Join Date: May 2006
Posts: 918
Take a look at this thread (the code is in one of the last posts).

click me


On a sidenote, desaturating non player debuffs is a more visible way without having to "mess" with this. Just my 2 cents.
__________________
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
05-25-11, 04:28 AM   #10
lastgamer
A Deviate Faerie Dragon
Join Date: Oct 2009
Posts: 11
Dawn, I wanna make ”thanks” bigger for you.
Thank you very mush,my friends.
  Reply With Quote

WoWInterface » Featured Projects » oUF (Otravi Unit Frames) » How to


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