View Single Post
10-11-19, 08:24 PM   #1
illej
A Murloc Raider
Join Date: Oct 2019
Posts: 4
dynamic key bindings with SecureHandlers

Hey all,

I'm new here, and new to writing WoW addons and a bit at a loss as to how to progress with my mod.

To start with, the functionality I am trying to achieve is as follows:

The idea is that I want to be able to easily cast any Shaman totem with 3 key strokes.

1) Starting state: keys 1 through to 9 are bound as normally to actionbar 1
2) clicking '/click ElementBinder' in a macro rebinds keys 1 to 4 to represent the 4 totem elements (1: Earth, 2: Fire, 3: Water, 4: Air)
3) Now, pressing any of these overridden keys further overrides them to represent individual Totems to cast,(1: cast Earthbind Totem, 2: cast Strength of Earth, etc).
4) After any Totem is cast, clear all existing bindings: keys 1 through to 9 are bound as normally to actionbar 1

So for Example:
Pressing F > 1 > 2 casts Strength of Earth totem
Pressing F > 1 > 1 casts Earthbind Totem
Pressing F > 2 > 1 casts Searing Totem
Pressing F > 3 > 1 casts Healing Stream Totem
etc ..

So far I have been using SecureHandlers to enable this to work in combat - and it does! However, I have no way to clear the overridden bindings once a Totem is cast and I am looking for any help/suggestions to achieve this!

Here is some code snippets.

Macro to initiate the functionality:
Code:
/click ElementBinder
Lua code to handle the click:
Code:
local element_binder = CreateFrame("BUTTON", "ElementBinder", UIParent, "SecureHandlerClickTemplate");
element_binder:SetAttribute("_onclick", [=[
    if button == "LeftButton" then    
        self:SetBindingClick(true, "1", "EarthBtn")
        self:SetBindingClick(true, "2", "FireBtn")
        -- etc for water and air
    end
]=]);

local earth_btn = CreateFrame("BUTTON", "EarthBtn", element_binder, "SecureHandlerClickTemplate")
earth_btn:SetAttribute("_onclick", [=[
    if button == "LeftButton" then
        self:SetBindingSpell(true, "1", "Earthbind Totem")
        self:SetBindingSpell(true, "2", "Strength of Earth Totem")
        -- etc for the rest of the earth totems
    end
]=])
So some solutions I have (unsuccessfully) explored are:
  • trying to use :WrapScript on the 'EarthBtn' frame and call :ClearBindings() in the 'PostClick', but I have no idea really of what frames should be attached to or inherited from, and this never works
  • RegisterEvent('COMBAT_LOG_EVENT'), and parsing the combat log for 'SPELL_SUMMON' and then trying to call :ClearBindings() on one of the SecureHandler frames, but again I can't figure out the inheritance chain to enable this in the protected path.

Also, is there another way of initiating the original 'click' on the first handler other than through a macro?

Any ideas?

Thanks in advance!
  Reply With Quote