WoWInterface SVN Molinari

[/] [trunk/] [Molinari/] [Molinari.lua] - Rev 12

Go to most recent revision | Compare with Previous | Blame | View Log

--[[

 Copyright (c) 2006-2008 Trond A Ekseth
 Copyright (c) 2009 Adrian L Lange

 Permission is hereby granted, free of charge, to any person
 obtaining a copy of this software and associated documentation
 files (the "Software"), to deal in the Software without
 restriction, including without limitation the rights to use,
 copy, modify, merge, publish, distribute, sublicense, and/or sell
 copies of the Software, and to permit persons to whom the
 Software is furnished to do so, subject to the following
 conditions:

 The above copyright notice and this permission notice shall be
 included in all copies or substantial portions of the Software.

 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 OTHER DEALINGS IN THE SOFTWARE.

--]]

local button = CreateFrame('Button', 'Molinari', UIParent, 'SecureActionButtonTemplate, AutoCastShineTemplate')

local strings = {
        [ITEM_MILLABLE] = GetSpellInfo(51005),
        [ITEM_PROSPECTABLE] = GetSpellInfo(31252),
}

local function hookScript(self)
        if(self:GetItem() and IsAltKeyDown() and not InCombatLockdown()) then
                local text = GameTooltipTextLeft2:GetText()
                local spell = strings[text]

                if(spell) then
                        local anchor = GetMouseFocus()

                        button:SetAttribute('macrotext', string.format('/cast %s\n/use %s %s', spell, anchor:GetParent():GetID(), anchor:GetID()))
                        button:ClearAllPoints()
                        button:SetAllPoints(anchor)
                        button:Show()

                        if(text == ITEM_MILLABLE) then
                                AutoCastShine_AutoCastStart(button, 0.5, 1, 0.5)
                        else
                                AutoCastShine_AutoCastStart(button, 1, 0.5, 0.5)
                        end
                end
        end
end

function button:MODIFIER_STATE_CHANGED(event, key)
        if(self:IsShown() and string.match(key, 'ALT$')) then
                if(InCombatLockdown()) then
                        self:RegisterEvent('PLAYER_REGEN_DISABLED')
                else
                        self:Hide()
                end
        end
end

function button:PLAYER_REGEN_DISABLED(event)
        self:UnregisterEvent(event)
        self:Hide()
end

function button:PLAYER_LOGIN()
        self:RegisterForClicks('LeftButtonUp')
        self:RegisterEvent('MODIFIER_STATE_CHANGED')
        self:SetFrameStrata('DIALOG')
        self:SetAttribute('*type*', 'macro')

        self:SetScript('OnLeave', function() self:Hide() end)
        GameTooltip:HookScript('OnTooltipSetItem', hookScript)
end

button:SetScript('OnEvent', function(self, event, ...) self[event](self, event, ...) end)
button:RegisterEvent('PLAYER_LOGIN')

-- temporary scaling of spark objects
for key, value in next, button.sparkles do
        value:SetWidth(value:GetWidth() * 3)
        value:SetHeight(value:GetHeight() * 3)
end

-- temporary fix for blizzard's bug with secure frames and anchoring on the ContainerFrame
hooksecurefunc('ContainerFrame_GenerateFrame', function(self, size, id)
        if(size ~= 1 and id == 0) then
                ContainerFrame1Item1:SetPoint('BOTTOMRIGHT', ContainerFrame1MoneyFrameCopperButton, 'BOTTOMRIGHT', 3, 21)
        end
end)

Go to most recent revision | Compare with Previous | Blame