WoWInterface SVN Molinari

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

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 milling, prospecting = GetSpellInfo(51005), GetSpellInfo(31252)
if(not GetSpellInfo(milling) and not GetSpellInfo(31252)) then return end

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

local strings = {
        [ITEM_MILLABLE] = { name = milling, r = 0.5, g = 1, b = 0.5 },
        [ITEM_PROSPECTABLE] = { name = prospecting, r = 1, g = 0.5, b = 0.5 },
}

local function clickArgs()
        return (not IsAddOnLoaded('Blizzard_AuctionUI') or AuctionFrame and not AuctionFrame:IsShown()) and not TradeFrame:IsShown() and not BankFrame:IsShown() and not MailFrame:IsShown() and not InCombatLockdown() and IsAltKeyDown()
end

local function hookScript(self)
        if(self:GetItem() and clickArgs()) then
                local spell = strings[GameTooltipTextLeft2:GetText()]

                if(spell) then
                        local mouse = GetMouseFocus()

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

                        AutoCastShine_AutoCastStart(button, spell.r, spell.g, spell.b)
                end
        end
end

local function safeStop(self)
        if(InCombatLockdown()) then
                self:RegisterEvent('PLAYER_REGEN_ENABLED')
        else
                self:Hide()
        end
end

function button:MODIFIER_STATE_CHANGED(event, key)
        if(self:IsShown() and string.match(key, 'ALT$')) then
                safeStop(self)
        end
end

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

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

        self:SetScript('OnLeave', safeStop)
        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
if(Bagnon or cargBags or Combuctor) then return end
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