Thread Tools Display Modes
01-10-10, 12:07 AM   #1
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
SecureUnitButtonTemplate

can the secure templates only be done in xml?
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
  Reply With Quote
01-10-10, 12:23 AM   #2
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,918
Nope

Code:
local function MagePorts_CreateSecureSpellButton(spellID, reagentID, level, quest)
	local SpellName, _, SpellIcon = GetSpellInfo(spellID);
	local Available = ( GetSpellInfo(SpellName) ~= nil );
	local ButtonName = "P_" .. spellID;
	local TextureName = ButtonName .. "_Texture";
	
	-- Show a tooltip for the button
	local function ShowTooltip(self)
		local Available = ( GetSpellInfo(SpellName) ~= nil );
		local TimeNow = GetTime();
		local CooldownStart, CooldownDuration, CooldownEnabled = GetSpellCooldown(SpellName);
		local CooldownCounter = 0;
		if ( CooldownEnabled ) then	CooldownCounter = CooldownDuration - (TimeNow - CooldownStart); end
		CooldownCounter = math.floor(CooldownCounter);
		local reagentCount = GetItemCount(reagentID);
		GameTooltip:SetOwner(self, "ANCHOR_CURSOR");
		GameTooltip:SetText(SpellName, 1.0, 1.0, 0.0 );
		GameTooltip:AddLine(_L["LEVEL"] .. level,1.0,1.0,1.0);
		if ( quest ) then GameTooltip:AddLine(_L["ATTAINED_VIA_QUEST"], 1.0,1.0,1.0); end
		if ( not Available ) then
			GameTooltip:AddLine(_L["UNKNOWN"],1.0,1.0,1.0);
		elseif ( reagentCount < 1 ) then
			GameTooltip:AddLine(_L["OUT_OF_REAGENTS"], 1.0,1.0,1.0);
		elseif ( CooldownDuration == 0 ) then
			GameTooltip:AddLine(_L["AVAILABLE"], 1.0,1.0,1.0);
		elseif ( CooldownEnabled and CooldownDuration ~= 0) then
			GameTooltip:AddLine(_L["ON_COOLDOWN"], 1.0,1.0,1.0);
		end
		GameTooltip:Show();		
	end
	
	-- Hide the buttons tooltip
	local function HideTooltip(self)
		GameTooltip:Hide();
	end
	
	-- Update the cooldown counter
	local function UpdateCooldown(self)
		local TimeNow = GetTime();
		local CooldownStart, CooldownDuration, CooldownEnabled = GetSpellCooldown(SpellName);
		if ( not CooldownEnabled ) then return; end
		if ( CooldownDuration == 0 ) then return; end	
		local DiffTime = TimeNow - CooldownStart;
		local CooldownCounter = CooldownDuration - DiffTime;
		CooldownCounter = math.floor(CooldownCounter);
		if ( CooldownCounter > 0 ) then	
			self.Text:SetText(CooldownCounter);	
		else
			self.Text:SetText("");	
		end
	end
	
	-- Create the button and its children and attributes
	local Button = CreateFrame("Button", ButtonName, UIParent,"ActionButtonTemplate,SecureActionButtonTemplate");			
	Button:SetWidth(36);
	Button:SetHeight(36);			
	Button.Texture = Button:CreateTexture(TextureName,"OVERLAY");
	Button.Texture:SetAllPoints(Button);
	Button.Texture:SetTexture(SpellIcon);
	Button:SetNormalTexture( "" ); 
	Button:SetHighlightTexture("Interface\\Buttons\\ButtonHilight-Square", add);
	Button:SetPushedTexture("Interface\\Buttons\\UI-Quickslot-Depress");
	if ( not Available ) then 
		Button:SetAlpha(MagePorts_Defaults.NotAvailableAlpha); 
	else
		Button:SetAlpha(MagePorts_Defaults.AvailableAlpha);
	end
	Button:SetAttribute("type","spell");
	Button:SetAttribute("spell",SpellName);
	Button:SetScript("OnEnter",ShowTooltip);
	Button:SetScript("OnLeave",HideTooltip);
	
	-- Create the Cooldown frame to display the Cooldown Counter
	Button.Cooldown = CreateFrame("Frame", ButtonName.."_Cooldown", Button);
	Button.Cooldown:SetAllPoints(Button);
	Button.Cooldown.Text = Button.Cooldown:CreateFontString(ButtonName.."_Cooldown_Text", 'ARTWORK', "GameFontNormal");
	local Path, Size, Flags = Button.Cooldown.Text:GetFont()
	Button.Cooldown.Text:SetFont(Path,MagePorts_Defaults.FontSize,Flags);
	Button.Cooldown.Text:SetAllPoints(Button.Cooldown);
	Button.Cooldown.Text:SetJustifyH( "CENTER" );
	Button.Cooldown.Text:SetJustifyV( "MIDDLE" );
	Button.Cooldown.Text:SetTextColor( 1, 1, 0, 1 );
	Button.Cooldown.Text:SetText("");  
	Button.Cooldown:SetScript("OnUpdate",UpdateCooldown);
		
	return Button;
end
To see the whole thing check out my MagePorts addon. It took me awhile to figure it out and involved chatting to some Blizz Forum Expert or something to explain a few things.
__________________
  Reply With Quote
01-10-10, 12:24 AM   #3
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,918
Okay, scratch that .. rofl, thought you said Action Button at first but maybe it will help in some form.
__________________
  Reply With Quote
01-10-10, 01:14 AM   #4
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
after looking at both they are pretty much the same. i read the info on wowwikki but some of the code examples there are hard to follow.

this is what im working with. trying to make the healthbar target the player on left click. right click opens the menu obviously. everything works except it does not target on left click.

Code:
local healthborder = CreateFrame('Button', "GrimUI_HealthBar", frame, "SecureActionButtonTemplate")
healthborder:SetHeight(25)
healthborder:SetWidth(175)
healthborder:SetPoint("TOPRIGHT", GrimPlayerFrame, "TOPRIGHT", 0, 0)
healthborder:SetFrameStrata("HIGH")
healthborder:SetFrameLevel("4")
healthborder:RegisterForClicks('RightButtonUp', 'LeftButtonUp')
healthborder:SetAttribute("type1", "target")
healthborder:SetAttribute("target", "Player")
healthborder:SetScript('OnClick', function(self, button)
	if button == "RightButton" then
	ToggleDropDownMenu(1, nil, PlayerFrameDropDown, healthborder, 0, 0)
	end
end)
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
  Reply With Quote
01-10-10, 01:36 AM   #5
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,918
Try just "type" instead of "type1" and "player" instead of "Player". Who knows if they're picky. I do know once you add more types you can put the number in but perhaps it doesn't like it for the first one.

Edit 1: However, this would only target you. You would have to change that to "party1", "party2", "raid1" etc as required. Or so I suspect. I have never played with unit frames personally so am not sure about that side of things.

Edit 2 : Reading wowwiki again and I realise I misunderstood the use of the 1 and 2 in those types etc.

Try this and see how that works, I somehow think you need the 1 for that other option as well, to signify the left button usage. :
healthborder:SetAttribute("type1", "target1")
healthborder:SetAttribute("target1", "player")
__________________

Last edited by Xrystal : 01-10-10 at 01:44 AM.
  Reply With Quote
01-10-10, 01:41 AM   #6
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
yea its only supposed to target you. working on the playerframe atm. The partyframes will need those other things im sure. hmm if i do type though wont that cause the right click function to have problems?
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
  Reply With Quote
01-10-10, 01:44 AM   #7
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,918
Originally Posted by Grimsin View Post
yea its only supposed to target you. working on the playerframe atm. The partyframes will need those other things im sure. hmm if i do type though wont that cause the right click function to have problems?
Rofl, was hoping to do my edit before you replied but yeah I adjusted my post slightly
__________________
  Reply With Quote
01-10-10, 01:49 AM   #8
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,918
Okay, take a look at this post and see if the discussion there lights up some ideas.

http://www.wowinterface.com/forums/s...ad.php?t=25360

Edit : Okay by that post it might work this way :

healthborder:SetAttribute("type1", "target")
healthborder:SetAttribute("target1", "player")

And for example you may be able to do this if you wanted to ( but that Im guessing as I didn't double check the commands before typing this bit )
healthborder:SetAttribute("type2", "focus")
healthborder:SetAttribute("focus2", "target")
__________________

Last edited by Xrystal : 01-10-10 at 01:53 AM.
  Reply With Quote
01-10-10, 02:03 AM   #9
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
so far no combination of any of the above has worked i think maybe i need to somehow work that rightclick function into an setattribute
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
  Reply With Quote
01-10-10, 04:14 AM   #10
p3lim
A Pyroguard Emberseer
 
p3lim's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 1,710
First you need to set what the action is gonna do
In this case, target a unit on left click:
x:SetAttribute('type1', 'target')

Then you need to set which unit it should target:
x:SetAttribute('target', 'player')


For a menu you have to set which button (type2) then the function name.
x:SetAttribute('type2', 'menu')

Then your function:
function x.menu(self) end


More information here:
http://wowprogramming.com/docs/secur...ButtonTemplate
  Reply With Quote
01-10-10, 11:59 AM   #11
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
still does not work.....
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
  Reply With Quote
01-10-10, 12:24 PM   #12
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
okay.... SO the proper use for the target self is this... - maybe not proper but it works

Code:
healthborder:SetAttribute("type1", "target")
healthborder:SetAttribute("unit", "player")
still have not gotten the dropdown menu to work.
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
  Reply With Quote
01-10-10, 01:20 PM   #13
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
Originally Posted by p3lim View Post
Then your function:
function x.menu(self) end
so your saying it should look like this?
Code:
healthborder:SetAttribute('type1', 'target')
healthborder:SetAttribute('type2', 'menu')
healthborder:SetAttribute('unit', "player")

function healthborder.menu(self) ToggleDropDownMenu(1, 1, PlayerFrameDropDown, healthborder, 0 ,0) end
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
  Reply With Quote
01-10-10, 02:46 PM   #14
Xus
A Fallenroot Satyr
 
Xus's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2007
Posts: 25
Originally Posted by Grimsin View Post
so your saying it should look like this?
Code:
healthborder:SetAttribute('type1', 'target')
healthborder:SetAttribute('type2', 'menu')
healthborder:SetAttribute('unit', "player")

function healthborder.menu(self) ToggleDropDownMenu(1, 1, PlayerFrameDropDown, healthborder, 0 ,0) end
it may have to be: healthborder.menu = function(self) ToggleDropDownMenu(1, 1, PlayerFrameDropDown, healthborder, 0 ,0) end
  Reply With Quote
01-10-10, 03:11 PM   #15
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
Originally Posted by Xus View Post
it may have to be: healthborder.menu = function(self) ToggleDropDownMenu(1, 1, PlayerFrameDropDown, healthborder, 0 ,0) end
Yes in deed it should. worked like a charm thank you.
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
  Reply With Quote
01-10-10, 04:00 PM   #16
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,918
Ooh, learn something new everyday. Will be useful to know how to do that menu thing like that at some point
__________________
  Reply With Quote
01-10-10, 04:08 PM   #17
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
now i cant figure out how to fade a texture if its not one thing its another. Hmm fade isnt the right word i have no idea what you would call it.
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
  Reply With Quote
01-10-10, 04:09 PM   #18
Grimsin
A Molten Giant
 
Grimsin's Avatar
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 990
better yet how do you make the menu show on pointer instead of at an x, y? lol
__________________
"Are we there yet?"

GrimUI
[SIGPIC][/SIGPIC]
  Reply With Quote
01-10-10, 04:11 PM   #19
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,918
And setting alpha level doesn't work ? Texture object should contain UIObjects SetAlpha functionality

Do you mean you want it to fade gradually through the image ?

Perhaps ?
Texture:SetGradient("orientation", minR, minG, minB, maxR, maxG, maxB)
Texture:SetGradientAlpha("orientation", minR, minG, minB, minA, maxR, maxG, maxB, maxA)
__________________
  Reply With Quote
01-10-10, 04:13 PM   #20
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,918
Originally Posted by Grimsin View Post
better yet how do you make the menu show on pointer instead of at an x, y? lol
Find out where the mouse pointer is at the time and use those x,y coords ?

local x, y = GetCursorPosition();
__________________
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » SecureUnitButtonTemplate

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