From 85fb4995c207f81adf9d665a0bd5ce7a25f9648d Mon Sep 17 00:00:00 2001 From: Adrian L Lange Date: Mon, 27 May 2013 16:18:33 +0200 Subject: [PATCH] Proper handling of spells - Fixes disenchanting issue --- Molinari.lua | 59 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/Molinari.lua b/Molinari.lua index 682b281..2d68f23 100644 --- a/Molinari.lua +++ b/Molinari.lua @@ -13,8 +13,23 @@ local function ScanTooltip(self, spells) end end +local function ApplyButton(itemLink, spell, r, g, b) + local slot = GetMouseFocus() + local bag = slot:GetParent():GetID() + + if(GetContainerItemLink(bag, slot:GetID()) == itemLink) then + button:SetAttribute('spell', spell) + button:SetAttribute('target-bag', bag) + button:SetAttribute('target-slot', slot:GetID()) + button:SetAllPoints(slot) + button:Show() + + AutoCastShine_AutoCastStart(button, r, g, b) + end +end + function button:PLAYER_LOGIN() - local spells, disenchanter, rogue, smith = {} + local spells, disenchanter, lockpicking, smith = {} if(IsSpellKnown(51005)) then spells[ITEM_MILLABLE] = {GetSpellInfo(51005), 1/2, 1, 1/2} end @@ -23,44 +38,30 @@ function button:PLAYER_LOGIN() spells[ITEM_PROSPECTABLE] = {GetSpellInfo(31252), 1, 1/3, 1/3} end - -- I wish Blizzard could treat disenchanting the same way - disenchanter = IsSpellKnown(13262) - rogue = IsSpellKnown(1804) + disenchanting = IsSpellKnown(13262) and GetSpellInfo(13262) + lockpicking = IsSpellKnown(1804) and GetSpellInfo(1804) smith = GetSpellBookItemInfo((GetSpellInfo(2018))) GameTooltip:HookScript('OnTooltipSetItem', function(self) - local item, link = self:GetItem() + local item, itemLink = self:GetItem() if(item and not InCombatLockdown() and IsAltKeyDown() and not (AuctionFrame and AuctionFrame:IsShown())) then local spell, r, g, b = ScanTooltip(self, spells) - - if(not spell and disenchanter and ns.Disenchantable(link)) then - spell, r, g, b = GetSpellInfo(13262), 1/2, 1/2, 1 - end - - if(not spell and rogue and ns.Openable(link)) then - spell, r, g, b = GetSpellInfo(1804), 0, 1, 1 - end - - if(not spell and smith and ns.Openable(link)) then - spell, r, g, b = ns.SkeletonKey(), 0, 1, 1 - end - - if(not spell) then - return - end - - local bag, slot = GetMouseFocus():GetParent(), GetMouseFocus() - if(GetContainerItemLink(bag:GetID(), slot:GetID()) == link) then - button:SetAttribute('macrotext', string.format('/cast %s\n/use %s %s', spell, bag:GetID(), slot:GetID())) - button:SetAllPoints(slot) - button:Show() - AutoCastShine_AutoCastStart(button, r, g, b) + if(spell) then + ApplyButton(itemLink, spell, r, g, b) + else + if(disenchanting and ns.Disenchantable(itemLink)) then + ApplyButton(itemLink, disenchanting, 1/2, 1/2, 1) + elseif(lockpicking and ns.Openable(itemLink)) then + ApplyButton(itemLink, lockpicking, 0, 1, 1) + elseif(smith and ns.Openable(itemLink)) then + ApplyButton(itemLink, ns.SkeletonKey(), 0, 1, 1) + end end end end) self:SetFrameStrata('TOOLTIP') - self:SetAttribute('alt-type1', 'macro') + self:SetAttribute('alt-type1', 'spell') self:SetScript('OnLeave', self.MODIFIER_STATE_CHANGED) self:RegisterEvent('MODIFIER_STATE_CHANGED') -- 1.7.9.5