Thread Tools Display Modes
09-02-09, 05:02 PM   #1
Dreamfade
A Murloc Raider
 
Dreamfade's Avatar
Join Date: Sep 2009
Posts: 5
Right Click Menus

How do you add an item to the right click menus attached to the player frames (I.E. Target)
  Reply With Quote
09-02-09, 06:07 PM   #2
zero-kill
A Firelord
 
zero-kill's Avatar
Join Date: Aug 2009
Posts: 497
Well what do you want to add there>
  Reply With Quote
09-03-09, 12:19 AM   #3
Dreamfade
A Murloc Raider
 
Dreamfade's Avatar
Join Date: Sep 2009
Posts: 5
1. If target is same faction then add "Add to Blacklist" (once clicked it would go to a lua function)
2. If target is oposite faction then add "Add to KOSlist" (this woud be linked to a different lua function)
  Reply With Quote
09-03-09, 01:05 AM   #4
zero-kill
A Firelord
 
zero-kill's Avatar
Join Date: Aug 2009
Posts: 497
I take it that you are using a KoS addon then such as Vanas KoS? I haven't tested this one myself, but I'm sure Van wouldn't mind adding that functionality (unless it is all ready there).
  Reply With Quote
09-03-09, 08:48 PM   #5
Dreamfade
A Murloc Raider
 
Dreamfade's Avatar
Join Date: Sep 2009
Posts: 5
Actually I am writing my own. and I havent found any info on adding these things to the right click menus... I know it can be done I have see other addons do this. hehe I just wanna know how lol
  Reply With Quote
09-03-09, 09:28 PM   #6
zero-kill
A Firelord
 
zero-kill's Avatar
Join Date: Aug 2009
Posts: 497
Well I dug around on WoWwiki and cannot find anything within the API section for it
  Reply With Quote
09-03-09, 09:44 PM   #7
Dreamfade
A Murloc Raider
 
Dreamfade's Avatar
Join Date: Sep 2009
Posts: 5
Hmmm, even looking into the code of other addons that DO add lines to the list I cant find the specific code they use... its like it just magicly appears there without a code call lol
  Reply With Quote
09-03-09, 10:01 PM   #8
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
If I had to guess, I would say that they added entries into the table that the right click menu gets built from...
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
09-04-09, 04:34 AM   #9
oomp
A Murloc Raider
 
oomp's Avatar
AddOn Author - Click to view addons
Join Date: May 2009
Posts: 7
Haven't checked it out myself, but perhaps taking a look at the way it's done in this addon might help you.
  Reply With Quote
09-04-09, 05:58 AM   #10
Tristanian
Andúril
Premium Member
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 279
Originally Posted by Dreamfade View Post
1. If target is same faction then add "Add to Blacklist" (once clicked it would go to a lua function)
2. If target is oposite faction then add "Add to KOSlist" (this woud be linked to a different lua function)
Inserting menu entries into UnitPopup menus is kind of "hacky", a bit complicated and generally more trouble than its worth (there is a possibility of introducing taint, among other things) and I'd personally recommend against it. That being said, here's a very simplistic example, of what you are asking :

Code:
local myframe = CreateFrame("Frame")

myframe:RegisterEvent("UNIT_TARGET")

myframe:SetScript("OnEvent", function(_, event, ...)
	myframe[event](myframe, ...)
end)

function myframe:UNIT_TARGET(unitid)
	if unitid == "player" and UnitExists("target") then
		if UnitFactionGroup("target") == UnitFactionGroup("player") and UnitIsPlayer("target") then
 			for i = 1, #UnitPopupMenus["PLAYER"] do
				if UnitPopupMenus["PLAYER"][i] == "ADD_BLIST" or UnitPopupMenus["PLAYER"][i] == "ADD_KOS" then
					tremove(UnitPopupMenus["PLAYER"], i)
				end
 			end
 			tinsert(UnitPopupMenus["PLAYER"], #UnitPopupMenus["PLAYER"] - 1, "ADD_BLIST")
		elseif UnitFactionGroup("target") ~= UnitFactionGroup("player") and UnitIsPlayer("target") then
  		for i = 1, #UnitPopupMenus["PLAYER"] do
  			if UnitPopupMenus["PLAYER"][i] == "ADD_BLIST" or UnitPopupMenus["PLAYER"][i] == "ADD_KOS" then
					tremove(UnitPopupMenus["PLAYER"], i)
				end
 			end
 			tinsert(UnitPopupMenus["PLAYER"], #UnitPopupMenus["PLAYER"] - 1, "ADD_KOS")
		end
	end
end

UnitPopupButtons["ADD_BLIST"] = {
	text = "Add to Blacklist",
	dist = 0,
	func = function() -- do stuff here 
	end
}

UnitPopupButtons["ADD_KOS"] = {
	text = "Add to KOSlist",
	dist = 0,
	func = function() -- do stuff here 
	end
}




function Assignfunchook(dropdownMenu, which, unit, name, userData, ...)
	for i=1, UIDROPDOWNMENU_MAXBUTTONS do
		local button = _G["DropDownList"..UIDROPDOWNMENU_MENU_LEVEL.."Button"..i];
		if button.value == "ADD_KOS" then
			button.func = UnitPopupButtons["ADD_KOS"].func
    elseif button.value == "ADD_BLIST" then
    	button.func = UnitPopupButtons["ADD_BLIST"].func
		end
	end
end

hooksecurefunc("UnitPopup_ShowMenu", Assignfunchook)
__________________
  Reply With Quote
09-04-09, 10:13 PM   #11
Dreamfade
A Murloc Raider
 
Dreamfade's Avatar
Join Date: Sep 2009
Posts: 5
Wonderful, this looks like exactly what I need. Thanks much.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Right Click Menus

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