Search code examples
luaworld-of-warcraft

WoW - Adding event handler for modifier key - kgPanels


I'm working with kgPanels to create a raid marker utility. I have two panels. One panel functions as a button - we'll call it rmButton. When rmButton is pressed it opens up the raid marker utility - rmUtility.

In kgPanels you create a panel on which you can add scripts that go in a number of different handlers. For rmUtility I am using OnLoad and OnEvent.

Right now everything is working as far as placing markers on targets. I would like to add further functionality that would allow placing world markers when either shift button is held. I'm having trouble getting that integrated.

In my OnLoad script:

local btnWidth = 30 -- the width of each button
local btnHeight = 30 -- the height of each button
local leftBorderOffset = 7 -- from the left border of the kgPanel to the first button
local btnOffset = 7 -- pixels between the buttons
local topBorderOffset = -7
self:RegisterEvent ("PLAYER_REGEN_DISABLED")
self:RegisterEvent ("PLAYER_REGEN_ENABLED")
self:Show()


self.buttons = {}
local hideFunc = function(s) s.parent:Hide() end
for n=1,6 do
    local btn = CreateFrame("Button",nil,self,"SecureActionButtonTemplate")
    btn:SetSize(btnWidth, btnHeight) -- replace this
    btn:SetPoint("TOP",0,topBorderOffset - ((n-1) * (btnHeight + btnOffset)))
    btn:SetAttribute("type","macro")
    btn:RegisterForClicks("AnyUp")
    btn.parent = self
    btn:SetScript("PostClick",hideFunc)
    btn:RegisterEvent ("MODIFIER_STATE_CHANGED")
    if (event == "MODIFIER_STATE_CHANGED") then
        if n == 6 then
            btn:SetAttribute("macrotext","/cwm all")
        else
            btn:SetAttribute("macrotext",("/wm %d"):format(n))
        end
    else
        if n == 6 then
            btn:SetAttribute("macrotext","/tm 0")
        else
            btn:SetAttribute("macrotext",("/tm %d"):format(n))
        end
    end
    self.buttons[n] = btn
end
self.buttons[1]:SetNormalTexture("Interface\\AddOns\\SharedMedia\\background\\Square.tga")
self.buttons[2]:SetNormalTexture("Interface\\AddOns\\SharedMedia\\background\\Triangle.tga")
self.buttons[3]:SetNormalTexture("Interface\\AddOns\\SharedMedia\\background\\Diamond.tga")
self.buttons[4]:SetNormalTexture("Interface\\AddOns\\SharedMedia\\background\\Cross.tga")
self.buttons[5]:SetNormalTexture("Interface\\AddOns\\SharedMedia\\background\\Star.tga")
self.buttons[6]:SetNormalTexture("Interface\\AddOns\\SharedMedia\\background\\Clear.tga")

In my OnEvent script:

if event == "PLAYER_REGEN_DISABLED" then
 self:Hide()
elseif event == "PLAYER_REGEN_ENABLED" then
 self:Hide()
end

When this panel loads it makes six buttons - five with raid markers, and one that clears the markers. When a button is pressed the panel will hide, and the panel will automatically hide when I enter combat.

As mentioned, I need the panel to accept a 'shift' modifier key to place the world marker.

Thanks.


Solution

  • Did you try something like

    btn:SetAttribute("shift-macrotext1",("/wm %d"):format(n))
    

    https://wow.gamepedia.com/SecureActionButtonTemplate#Modified_attributes

    Unless you mean you want to use Shift to place a world marker? Instead of using it as a modifier for your secure action button? I'm not aware of any modifier keys like shift, ctrl, alt being able to activate an action button.