View Single Post
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