WoWInterface (
-   AddOn Help/Support (
-   -   Mouseover functionality for unit frames (

auvier 08-04-19 11:29 AM

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:

-- 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:SetColorTexture(1, 0, 0)

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

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


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!

jeruku 08-04-19 09:54 PM

Why not use macros with conditionals on your action bar?


/cast [mod,@boss1,harm][@mouseover,harm][]Corruption

auvier 08-05-19 01:38 AM

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 ^^

jlam 08-08-19 05:57 PM

Isn't this what Clique does?

Vrul 08-09-19 06:22 AM


Originally Posted by auvier (Post 333063)
(=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.

auvier 08-13-19 09:12 AM


Originally Posted by jlam (Post 333091)
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 (Post 333097)
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.

All times are GMT -6. The time now is 05:52 AM.

vBulletin © 2021, Jelsoft Enterprises Ltd
© 2004 - 2020 MMOUI