Quantcast WoWInterface: SVN - KeyboardAccess - Rev 16 - /trunk/core.lua

WoWInterface SVN KeyboardAccess

[/] [trunk/] [core.lua] - Rev 16

Compare with Previous | Blame | View Log

--[[
        ##AddOn   : KeyboardAccess 
        ##Subfile : core.lua
        ##Author  : Hati-EK
--]]
KeyboardAccess = { } --just for personal debugging issues
local KA = KeyboardAccess  -- 4b6579626f617264416363657373 = Hex-CODE for KeyboarAccess
KA.name = 'KeyboardAccess'
KA.ver = GetAddOnMetadata( KA.name, 'Version')
if KA.ver=='rwowi:revision' then KA.ver='SVN' end
KA.MODShift=false
KA.handleT = {}
local events = {}

local function toboolean(x)
        if x==1 then
                return true
        else
                return false
        end
end

local function inTable(tbl,value)
  local b = false
  for i,k in ipairs(tbl) do
    if k==value then
      return i
    end
  end
  return b
end

ReadyCheckFrame.button1 = ReadyCheckFrameYesButton
ReadyCheckFrame.button2 = ReadyCheckFrameNoButton

local allowedPopups = {
        --Invites
        "ARENA_TEAM_INVITE",
        "BFMGR_INVITED_TO_QUEUE",
        "BFMGR_INVITED_TO_ENTER",
        "PARTY_INVITE",
        "GUILD_INVITE",
        --talents
        "CONFIRM_TALENT_WIPE",
        "TALENTS_INVOLUNTARILY_RESET",
        "TALENTS_INVOLUNTARILY_RESET_PET",
        "CONFIRM_REMOVE_GLYPH",
        "CONFIRM_GLYPH_PLACEMENT",
        
        --misc
        "CONFIRM_BINDER",
        "CONFIRM_GUILD_PROMOTE",
        "CONFIRM_SUMMON",
        
        --rezz
        "RESURRECT_NO_SICKNESS",
}


local function ReadyCheckFrame_OnKeyDown(self,key)
        if ( key=='ESCAPE' ) then
                ReadyCheckFrame.button2:Click()
                ReadyCheckFrame:EnableKeyboard(0)
        elseif ( GetBindingFromClick(key) == "SCREENSHOT" ) then
                RunBinding("SCREENSHOT");
                return;
        elseif key=='LSHIFT' or key=='RSHIFT' then
                self:EnableKeyboard(0)
                KA.MODShift=true
        elseif key=='ENTER' then
                ReadyCheckFrame.button1:Click()
                ReadyCheckFrame:EnableKeyboard(0)
        end
end

local function EnableEnter()
        for _,which in ipairs(allowedPopups) do
                StaticPopupDialogs[which].enterClicksFirstButton = true
        end
        if ReadyCheckFrame:IsVisible() then
                ReadyCheckFrame:EnableKeyboard(1)
                ReadyCheckFrame:SetScript('OnKeyDown',ReadyCheckFrame_OnKeyDown)
        end
end
local function DisableEnter()
        for _,which in ipairs(allowedPopups) do
                StaticPopupDialogs[which].enterClicksFirstButton = false
        end
        if ReadyCheckFrame:GetScript('OnKeyDown') then
                ReadyCheckFrame:SetScript('OnKeyDown',nil)
        end
end



function events:READY_CHECK(initiator,timer)
        if not (UnitName('player')==initiator) and not (KA.MODShift) then
                ReadyCheckFrame:EnableKeyboard(1)
                ReadyCheckFrame:SetScript('OnKeyDown',ReadyCheckFrame_OnKeyDown)
        end
end

function events:READY_CHECK_FINISHED(...)
        --print(...)
        ReadyCheckFrame:SetScript('OnKeyDown',nil)
        ReadyCheckFrame:EnableKeyboard(0)
end

function events:MODIFIER_STATE_CHANGED(modi,state)
        --print(modi,state)
        if modi=='LSHIFT' or modi=='RSHIFT' then
                KA.MODShift=toboolean(state)
                if not KA.MODShift then
                        EnableEnter()
                else
                        DisableEnter()
                end
        end
end

KA.handler = CreateFrame('Frame',KA.name.."_Handler")
KA.handler:SetScript('OnEvent',function(self,event,...)
        events[event](self, ...)
end)
for k, v in pairs(events) do
        --print('Registering',k)
        KA.handler:RegisterEvent(k); -- Register all events for which handlers have been defined
end

EnableEnter()

Compare with Previous | Blame