Thread Tools Display Modes
07-25-12, 12:42 AM   #1
Brozuf
A Defias Bandit
Join Date: Jul 2012
Posts: 2
Right Click Menus Question

Hey all,

I'm in the process of editing the default unitframes to change their appearance etc. I have a tiny bit of lua knowledge and have been able to figure everything out by using google and lurking this forum except for this one issue.

Since I've hidden my portraits and blizz art the right click menu for my target and player frames is just the empty space next to the frame. I've been trying to remove that and let the dropdown menu appear when I right click the healthbar of the respective frames.

I've been playing with the following but can't get it to work and it might be completely wrong:

Code:
TargetFrameHealthBar:SetScript('OnClick', function(self, button)
	if button == "RightButton" then
		ToggleDropDownMenu(1, nil, TargetFrameDropDown, TargetFrameHealthBar, 0, 0)
	end
end)

Any help is hugely appreciated!
  Reply With Quote
07-29-12, 01:56 AM   #2
Aanson
A Flamescale Wyrmkin
Join Date: Aug 2009
Posts: 124
Hey,

I'm no expert either, but I've got some suggestions.

I'm not in wow, so none of the frame names I use will be correct and will need to be changed:

With regard to copy/pasting the dropdownmenu script from PlayerPortrait to "PlayerHealthBar" (or whatever it's called!), I'd suggest the code below. I'm unsure if it would work, but it certainly seems logical to me. Would be good if someone with some knowledge on this could offer some input.

Lua Code:
  1. if PlayerHealthBar and PlayerHealthBar:IsVisible() then
  2.   PlayerHealthBar:SetScript("OnClick", PlayerPortrait:GetScript("OnClick"); end);
  3.   PlayerPortrait:SetScript("OnClick", nil) -- PlayerPortrait will no longer react to clicks
  4. end

I'm surprised that PlayerPortrait does still respond to clicks if you've hidden it using :Hide()... or have you removed the art layers only?)...

Let me know if it works, I'm curious.
__________________
__________________
  Reply With Quote
07-29-12, 07:45 PM   #3
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
The Blizzard unit frames do not normally use OnClick scripts to show menus. They use secure frame attributes, eg:
Code:
TargetFrame:SetAttribute("*type2", "menu")
TargetFrame.menu = function()
	ToggleDropDownMenu(1, nil, TargetFrameDropDown, TargetFrame, 120, 10)
end
The reason you're still getting a response when you click over the "empty" area where the portrait was is because you're not changing the size of the actual unit frame, or its "hit area". If you change its size, you would need to reposition the health and mana bars, since they are positioned relative to the frame. You would also need to change the hit area; see TargetFrame.xml in the Blizzard UI code to see the default values.

Another option would be to remove the default menu by doing:
Code:
TargetFrame:SetAttribute("*type2", nil)
and then setting an OnClick script on the health bar:
Code:
TargetFrameHealthBar:SetScript("OnClick", function(self, button)
	if button == "RightButton" then
		ToggleDropDownMenu(1, nil, TargetFrameDropDown, TargetFrame, 0, 0)
	end
end)
You may also need to enable the mouse on the health bar first:
Code:
TargetFrameHealthBar:EnableMouse(true)
TargetFrameHealthBar:RegisterForClicks("AnyUp")
However, if you use an OnClick script, you will be "tainting" the menu, and then commands like Set Focus will not work anymore.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
07-31-12, 05:53 AM   #4
Brozuf
A Defias Bandit
Join Date: Jul 2012
Posts: 2
To Aanson and Phanx: Thank you so much for your help!
I've looked into the codes you've both posted and made it work using the following:

Code:
TargetFrame:SetAttribute("*type2", nil)
TargetFrameHealthBar:EnableMouse(true)
TargetFrameHealthBar:SetScript("OnMouseDown", function(self, button)
	if button == "RightButton" then
		ToggleDropDownMenu(1, nil, TargetFrameDropDown, TargetFrame, 0, 0)
	end
end)
But like Phanx mentioned it taints the menu so I've been looking into changing the hit area.

This is what I came up with and I changed the AbsInsets but it doesn't seem to have any effect:
Code:
<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/
..\FrameXML\UI.xsd">
	<Button name="TargetFrame" frameStrata="LOW" toplevel="true" movable="true" inherits="SecureUnitButtonTemplate" parent="UIParent">
		<HitRectInsets>
			<AbsInset left="10" right="10" top="10" bottom="10"/>
		</HitRectInsets>
	</Button>
</Ui>
Any help is hugely appreciated!
  Reply With Quote
08-01-12, 12:05 AM   #5
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Defining a new frame named "TargetFrame" does nothing; you need to modify the existing TargetFrame:

Code:
TargetFrame:SetHitRectInsets(10, 10, 10, 10)
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote

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


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