From 13ce3a5a67d201838fc4f8558633958d665fa9f9 Mon Sep 17 00:00:00 2001 From: Adrian L Lange Date: Thu, 10 Jun 2010 20:20:26 +0200 Subject: [PATCH] Some cleaning and cosmetic changes, no functional --- Molinari.lua | 82 ++++++++++++++++++++++++++-------------------------------- 1 file changed, 37 insertions(+), 45 deletions(-) diff --git a/Molinari.lua b/Molinari.lua index 32fa9dc..7ee06d5 100644 --- a/Molinari.lua +++ b/Molinari.lua @@ -1,10 +1,9 @@ -local addon = ... +local addonName, spells = ... +local button = CreateFrame('Button', addonName, UIParent, 'SecureActionButtonTemplate, AutoCastShineTemplate') +button:SetScript('OnEvent', function(self, event, ...) self[event](self, event, ...) end) +button:RegisterEvent('PLAYER_LOGIN') -local button = CreateFrame('Button', addon, UIParent, 'SecureActionButtonTemplate, AutoCastShineTemplate') -local macro = '/cast %s\n/use %s %s' -local spells = {} - -local function ScanTooltip(text) +local function ScanTooltip() for index = 1, GameTooltip:NumLines() do local info = spells[_G['GameTooltipTextLeft'..index]:GetText()] if(info) then @@ -13,67 +12,60 @@ local function ScanTooltip(text) end end -local function Clickable() - return not InCombatLockdown() and IsAltKeyDown() -end - -local function Disperse(self) +local function OnLeave(self) if(InCombatLockdown()) then self:RegisterEvent('PLAYER_REGEN_ENABLED') else - self:Hide() - self:ClearAllPoints() AutoCastShine_AutoCastStop(self) + self:ClearAllPoints() + self:Hide() end end -function button:MODIFIER_STATE_CHANGED(event, key) - if(self:IsShown() and (key == 'LALT' or key == 'RALT')) then - Disperse(self) - end -end - -function button:PLAYER_REGEN_ENABLED(event) - self:UnregisterEvent(event) - Disperse(self) -end - -GameTooltip:HookScript('OnTooltipSetItem', function(self) - local item = self:GetItem() - if(item and Clickable()) then +local function OnTooltip(self) + if(self:GetItem() and not InCombatLockdown() and IsAltKeyDown()) then local spell, r, g, b = ScanTooltip() + if(spell) then local bag, slot = GetMouseFocus():GetParent(), GetMouseFocus() - button:SetAttribute('macrotext', macro:format(spell, bag:GetID(), slot:GetID())) + button:SetAttribute('macrotext', string.format('/cast %s\n/use %s %s', spell, bag:GetID(), slot:GetID())) + AutoCastShine_AutoCastStart(button, r, g, b) button:SetAllPoints(slot) button:Show() - AutoCastShine_AutoCastStart(button, r, g, b) end end -end) +end function button:PLAYER_LOGIN() + if(not IsSpellKnown(51005) and not IsSpellKnown(31252)) then return end + if(IsSpellKnown(51005)) then - spells[ITEM_MILLABLE] = {GetSpellInfo(51005), 0.5, 1, 0.5} + spells[ITEM_MILLABLE] = {GetSpellInfo(51005), 1/2, 1, 1/2} end - if(IsSpellKnown(31252)) then - spells[ITEM_PROSPECTABLE] = {GetSpellInfo(31252), 1, 0.5, 0.5} + spells[ITEM_PROSPECTABLE] = {GetSpellInfo(31252), 1, 1/2, 1/2} end -end -do - button:SetScript('OnLeave', Disperse) - button:SetScript('OnEvent', function(self, event, ...) self[event](self, event, ...) end) - button:SetFrameStrata('DIALOG') - button:RegisterEvent('MODIFIER_STATE_CHANGED') - button:RegisterEvent('PLAYER_LOGIN') - button:RegisterForClicks('LeftButtonUp') - button:SetAttribute('*type*', 'macro') - button:Hide() + GameTooltip:HookScript('OnTooltipSetItem', OnTooltip) + self:SetFrameStrata('DIALOG') + self:SetAttribute('alt-type1', 'macro') + self:SetScript('OnLeave', OnLeave) + self:RegisterEvent('MODIFIER_STATE_CHANGED') + self:Hide() for _, sparks in pairs(button.sparkles) do - sparks:SetHeight(sparks:GetHeight() * 3) - sparks:SetWidth(sparks:GetWidth() * 3) + sparks:SetHeight(sparks:GetHeight() * 2) + sparks:SetWidth(sparks:GetWidth() * 2) + end +end + +function button:MODIFIER_STATE_CHANGED(event, key) + if(self:IsShown() and (key == 'LALT' or key == 'RALT')) then + OnLeave(self) end end + +function button:PLAYER_REGEN_ENABLED(event) + self:UnregisterEvent(event) + OnLeave(self) +end -- 1.7.9.5