WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Clicking frame targets player (https://www.wowinterface.com/forums/showthread.php?t=57427)

mathias234 09-04-19 12:10 PM

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

SDPhantom 09-04-19 12:30 PM

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:

mathias234 09-04-19 01:38 PM

Quote:

Originally Posted by SDPhantom (Post 333578)
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

mathias234 09-04-19 02:33 PM

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

SDPhantom 09-05-19 01:01 PM

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.

mathias234 09-05-19 03:01 PM

Quote:

Originally Posted by SDPhantom (Post 333610)
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


All times are GMT -6. The time now is 11:11 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI