WoW - 为修改键添加事件处理程序 - kgPanels

WoW - Adding event handler for modifier key - kgPanels

我正在使用 kgPanels 创建一个 raid 标记实用程序。我有两个面板。一个面板用作按钮 - 我们将其称为 rmButton。当按下 rmButton 时,它会打开 raid 标记实用程序 - rmUtility。

在 kgPanels 中,您可以创建一个面板,您可以在该面板上添加用于许多不同处理程序的脚本。对于 rmUtility,我使用 OnLoad 和 OnEvent。

现在,就在目标上放置标记而言,一切正常。我想添加更多功能,允许在按住任一 shift 按钮时放置世界标记。我在整合时遇到了麻烦。

在我的 OnLoad 脚本中:

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")

在我的 OnEvent 脚本中:

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

加载此面板时,它会生成六个按钮 - 五个带有突袭标记,一个用于清除标记。当按下一个按钮时面板会隐藏,当我进入战斗时面板会自动隐藏。

如前所述,我需要面板接受 'shift' 修饰键来放置世界标记。

谢谢。

你有没有试过

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

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

除非你的意思是你想使用 Shift 来放置世界标记?而不是将其用作安全操作按钮的修饰符?我不知道任何修改键,如 shift、ctrl、alt 能够激活操作按钮。