Thread Tools Display Modes
08-04-19, 11:29 AM   #1
auvier
A Defias Bandit
Join Date: Aug 2019
Posts: 3
Mouseover functionality for unit frames

Hello everyone!

I'm trying to create mouseover cast functionality to my unit frames, working essentially the same way VuhDo works for party and raid frames. An example of desired functionality: when hovering over my Boss1 frame, I would like to be able to cast dots on boss1 unit by simply pressing an assigned hotkey, not needing to click the unit and switch targets. [EDIT]: This is specifically for keybinds, not mouse clicks.
Regular mouseover macros don't quite cut it in my case, and I would really like to learn how to implement this kind of functionality properly.

I've gotten to the point where I think I'm quite close to my goal, but the implementation is very clunky and has a few problems. My code so far:
Code:
-- a is helper table
a.unit = "focus"   -- Frame is focus for testing purposes
a.unitFrameName = "MyFocusFrame"
a.unitFrame = _G[a.unitFrameName]

-- Using SecureUnitButtonTemplate for easy unit frame functionality, EnterLeave for mouse enter/leave
local b = a.unitFrame or CreateFrame("Button", a.unitFrameName, UIParent, "SecureUnitButtonTemplate, SecureHandlerEnterLeaveTemplate")

b:SetPoint("CENTER", UIParent, "CENTER", 0, 0)  -- Temp test position and size
b:SetSize(100, 100)

local tex = b:CreateTexture(nil)  -- To see my frame
tex:SetAllPoints()
tex:SetColorTexture(1, 0, 0)

b.unit = a.unit
b:SetAttribute("unit", a.unit)
b:SetAttribute("type1", "target")
b:SetAttribute("type2", "togglemenu")

b:EnableMouse(true)
b:RegisterForClicks("LeftButtonUp", "RightButtonUp")

-- SetScripts disable the _onenter and _onleave state handlers
--b:SetScript("OnEnter", UnitFrame_OnEnter)
--b:SetScript("OnLeave", UnitFrame_OnLeave)

b:SetFrameRef("b", b)
b:SetAttribute("_onenter", [=[
    local b = self:GetFrameRef("b") 
    --local unit = self:GetAttribute("unit")
    b:SetBindingMacro(nil, "G", "Flash Heal macro")  -- Where said macro is "/use [@mouseover] Flash Heal"
]=])

b:SetAttribute("_onleave", [=[ 
    b = self:GetFrameRef("b")
    print("Mouse left Focus frame") -- testing
    b:ClearBindings()  -- Clear override bindings on leave
]=])

RegisterUnitWatch(b)
My logic is to create an override binding macro when my mouse enters the frame, and clear it once the mouse leaves. I added SecureHandlerEnterLeaveTemplate to inherit from for that purpose. It seemed like a sensible solution and the example macro is actually working; I'm able to cast Flash Heal on my focus target when I press G and my mouse is above my focus frame.

However, I don't know if this is the best solution by any means, and I have a few problems and questions:

1) To be able to assign macros to SetBindingMacro, those macros have to exist in my macros. Is there a way to create them locally within the frame, maybe using macrotext attributes or something? Otherwise this will be a pain with multiple characters and different frames. I know Vuhdo is able to do it, I just don't understand how.
2) How should I handle GameTooltip? AFAIK I can't do anything to it in restricted environment, and using SetScript overrides my state handlers. Should I have two separate frames for that?
3) Would there be some other, entirely different solution to achieving my goal? E.g. some other handlers or using virtual button clicks etc.

Overall I feel like I'm close, but at the moment stuck and I just can't seem to figure out a way to get forward. I've spent hours trying to get hints reading the source of Vuhdo, Clique, Healbots and FrameXML, but honestly I couldn't get much out of any of those :/

Any help would be hugely appreciated!

Last edited by auvier : 08-04-19 at 12:29 PM.
  Reply With Quote
08-04-19, 09:54 PM   #2
jeruku
A Cobalt Mageweaver
 
jeruku's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2010
Posts: 223
Why not use macros with conditionals on your action bar?

Code:
/cast [mod,@boss1,harm][@mouseover,harm][]Corruption
__________________
"I have not failed, I simply found 10,000 ways that did not work." - Thomas Edison
  Reply With Quote
08-05-19, 01:38 AM   #3
auvier
A Defias Bandit
Join Date: Aug 2019
Posts: 3
Thanks for the reply!

The macro solution is what I'm actually doing right now, but it has its problems as well. It leads to a near endless elseif chain of mouseover conditions for all and any unitIds I would like mouseover functionality to cover. Even still, it doesn't fix the annoyance of sometimes hovering over those units' character models and accidentally applying whatever spell that way. It gets even worse with multiple [harm]ii;[help]jj macros. Alternatively, I could use different keybinds for different units for the same spell, but that is just a no-no.

Surely I could just create a bunch of override keybinds for different scenarios (raids, BGs, arenas etc), but it is a messy solution at best. What I would fancy is a [@unitFrame] conditional, which would solve all of my problems, but since it doesn't exist, I'm trying to create it kind of artificially.

I know what I'm trying to do isn't an easy or class wide universal solution either, but I feel like this is as close to the root problem (=not having a @unitFrame condition) that I can get. Evidently it isn't that simple to achieve, and I understand it may seem excessive, but I'm willing to put in the hours to make it work. And after all, I would like to learn new stuff ^^

Last edited by auvier : 08-05-19 at 01:49 AM.
  Reply With Quote
08-08-19, 05:57 PM   #4
jlam
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Oct 2010
Posts: 29
Isn't this what Clique does?
  Reply With Quote
08-09-19, 06:22 AM   #5
Vrul
A Scalebane Royal Guard
 
Vrul's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 404
Originally Posted by auvier View Post
(=not having a @unitFrame condition)
You can look through the code of ImpliedTarget to see how I implemented an @unitframe and @unitmodel conditional. I haven't played in several months or on Classic beta so it may not even work anymore but the basic idea of how to do it should still be sound.
  Reply With Quote
08-13-19, 09:12 AM   #6
auvier
A Defias Bandit
Join Date: Aug 2019
Posts: 3
Originally Posted by jlam View Post
Isn't this what Clique does?
I played around with Clique earlier, and couldn't manage to make it work without it permanently overriding my keybinds and work in a mouseover-only fashion, i.e. I could no longer cast on my target.

Originally Posted by Vrul View Post
You can look through the code of ImpliedTarget to see how I implemented an @unitframe and @unitmodel conditional. I haven't played in several months or on Classic beta so it may not even work anymore but the basic idea of how to do it should still be sound.
This is exactly what I was looking for, thank you! Silly me didn't realize to google with the @unitFrame keyword earlier.
Also, thank you for the well-structured and commented code -- the @unitModel implementation especially was interesting to learn.
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » Mouseover functionality for unit frames

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