Thread Tools Display Modes
09-04-19, 12:10 PM   #1
mathias234
A Murloc Raider
Join Date: Sep 2019
Posts: 4
Clicking frame targets player

Hi, I am working on a new unit frame mostly just to learn the addons api. I got alot of stuff working but on of the features of the default ui i can't seem to figure out is how when you click it you end up selecting your own character..

From what i see this is a protected function but lots of other addons are able to do it so there must be a way.

there is also another feature which is when you hold over a unit frame (group, player or target) they will also be "selected" for the time you hover this is used by hover macros and some addons like clique.

My Addon source:
LUA:
https://pastebin.com/m6CVhNdQ

XML:
https://pastebin.com/BsA9qXFk
  Reply With Quote
09-04-19, 12:30 PM   #2
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,313
Blizzard includes secure templates you can inherit from that offer access to protected functionality. Here's a list of resources to check out.
See also:
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 09-04-19 at 12:47 PM.
  Reply With Quote
09-04-19, 01:38 PM   #3
mathias234
A Murloc Raider
Join Date: Sep 2019
Posts: 4
Originally Posted by SDPhantom View Post
Blizzard includes secure templates you can inherit from that offer access to protected functionality. Here's a list of resources to check out.
See also:
Alright, I'll look into it
  Reply With Quote
09-04-19, 02:33 PM   #4
mathias234
A Murloc Raider
Join Date: Sep 2019
Posts: 4
I tried adding inherits="SecureHandlerMouseUpDownTemplate" on my PlayerFrame and adding this code to it

Code:
       
SUF_PlayerFrame:SetAttribute("_onmouseup", [=[ 
    if button == "LeftButton" then
        print("secure")
        TargetUnit("player")
    end
]=]);
And the print does execute but TargetUnit is not found, I guess I am doing this incorrectly
  Reply With Quote
09-05-19, 01:01 PM   #5
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,313
Try using SecureUnitButtonTemplate. Your frame needs to be of type Button like this.
Code:
<Button name="SUF_PlayerFrame" parent="UIParent" inherits="SecureUnitButtonTemplate" movable="true">

In your OnLoad script, you need to add these. (Note: You should pass self to your OnLoad handler and use that.)
Code:
self:RegisterForClicks("AnyUp");
self:SetAttribute("unit","player");
self:SetAttribute("type1","target");
self:SetAttribute("type2","togglemenu");
This sets up the necessary attributes to mimic what the default PlayerFrame does.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)
  Reply With Quote
09-05-19, 03:01 PM   #6
mathias234
A Murloc Raider
Join Date: Sep 2019
Posts: 4
Originally Posted by SDPhantom View Post
Try using SecureUnitButtonTemplate. Your frame needs to be of type Button like this.
Code:
<Button name="SUF_PlayerFrame" parent="UIParent" inherits="SecureUnitButtonTemplate" movable="true">

In your OnLoad script, you need to add these. (Note: You should pass self to your OnLoad handler and use that.)
Code:
self:RegisterForClicks("AnyUp");
self:SetAttribute("unit","player");
self:SetAttribute("type1","target");
self:SetAttribute("type2","togglemenu");
This sets up the necessary attributes to mimic what the default PlayerFrame does.
Thanks this seems to be working correctly
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Clicking frame targets player

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