--[[---------------------------------------------------------------------------- Copyright (c) 2007, Tom Wieland All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of idActionbar nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.------------------------------------------------------------------------------]]local _G = _Glocal lib = LibStub('idLibrary-1.0')local TL, TC, TR = 'TOPLEFT', 'TOP', 'TOPRIGHT'local ML, MC, MR = 'LEFT', 'CENTER', 'RIGHT'local BL, BC, BR = 'BOTTOMLEFT', 'BOTTOM', 'BOTTOMRIGHT'local bindings = { '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=',}local buttonname = 'idActionbarButton'local numbuttons = 12local totalbuttons = numbuttonslocal barpadding = 1local bar1local function updateBindings () for i = 1,numbuttons do _G[buttonname..i..'HotKey']:SetText('') endendlocal function updateName () for i = 1,numbuttons do _G[buttonname..i..'Name']:SetText('') endendlocal function giveLooks (b) local name = b:GetName() local icon = _G[name..'Icon'] local texture = _G[name..'NormalTexture2'] or _G[name..'NormalTexture'] icon:SetTexCoord(0.08,0.92,0.08,0.92) texture:SetTexCoord(0,0,0,0)endlocal function createButton (name, id, shouldmap) local a = this local b = CreateFrame('CheckButton', name..id, UIParent, 'ActionBarButtonTemplate') b:SetAttribute('type', 'action') b:SetAttribute('action', id) if shouldmap then b:SetAttribute('useparent-statebutton', true) b:SetScript('OnAttributeChanged', ActionButton_UpdateAction) end this = b ActionButton_UpdateAction() this = a return bendlocal function createBar (barname, buttonname, first, last, cols, padding, shouldmap) local bar local button local rows = math.ceil((last-first+1)/cols) if shouldmap then bar = CreateFrame('Frame', barname, UIParent, 'SecureStateDriverTemplate') else bar = CreateFrame('Frame', barname, UIParent) end button = _G[buttonname..first] or createButton(buttonname, first, shouldmap) button:SetParent(bar) button:SetPoint(BL, bar, BL) giveLooks(button) if shouldmap then bar:SetAttribute('addchild', button) for j = 1, 8 do button:SetAttribute('*action-S'..j, first + j * last - last) end RegisterStateDriver(bar, 'page', '[modifier:alt,modifier:ctrl,modifier:shift]8; [modifier:alt,modifier:ctrl]7; [modifier:alt,modifier:shift]6; [modifier:ctrl,modifier:shift]5; [modifier:alt]4; [modifier:ctrl]3; [modifier:shift]2; 1') bar:SetAttribute('statebutton', '1:S1;2:S2;3:S3;4:S4;5:S5;6:S6;7:S7;8:S8') bar:SetAttribute('statemap-page', '$input') end for i = first + 1, last do button = _G[buttonname..i] or createButton(buttonname, i, shouldmap) button:SetParent(bar) giveLooks(button) if shouldmap then bar:SetAttribute('addchild', button) for j = 1, 8 do button:SetAttribute('*action-S'..j, i + j * last - last) end end if math.fmod(i-1, cols) == 0 then button:SetPoint(BC, _G[buttonname..i-cols], TC, 0, padding) else button:SetPoint(ML, _G[buttonname..i-1], MR, padding, 0) end end bar:SetWidth(button:GetWidth() * cols + padding * (cols - 1)) bar:SetHeight(button:GetHeight() * rows + padding * (rows - 1)) return barendlocal function initialize (name) if name ~= 'idActionbar' then return end bar1 = createBar('idActionbarBar1', buttonname, 1, numbuttons, totalbuttons, barpadding, true) hooksecurefunc('ActionButton_UpdateHotkeys', updateBindings) hooksecurefunc('ActionButton_Update', updateName)endlocal function enable () for i = 1, numbuttons do SetBindingClick(bindings[i], buttonname..i) end MainMenuBar:Hide() bar1:SetPoint(BC, UIParent, BC, 0, barpadding) bar1:Show()endlocal function disable () bar1:Hide() MainMenuBar:Show()endlib:RegisterEvent('idActionbar-Initialize', 'ADDON_LOADED', initialize)lib:RegisterEvent('idActionbar-Enable', 'PLAYER_LOGIN', enable)lib:RegisterEvent('idActionbar-Disable', 'PLAYER_LOGOUT', disable)