contrebasse@98: local addonName, A = ... contrebasse@98: contrebasse@98: local CAMPFIRE_ID = 818 contrebasse@98: local COOKING_ID = 2550 contrebasse@98: local btn contrebasse@98: local cookingName contrebasse@105: local CooldownFrame_SetTimer = CooldownFrame_SetTimer contrebasse@105: local GetSpellCooldown = GetSpellCooldown contrebasse@105: contrebasse@105: local function WaitCooldown(self) contrebasse@105: local start, duration, enable = GetSpellCooldown(CAMPFIRE_ID) contrebasse@105: if start>0 then contrebasse@105: CooldownFrame_SetTimer(btn.cooldown,GetSpellCooldown(CAMPFIRE_ID)) contrebasse@105: self:SetScript("OnUpdate",nil) contrebasse@105: end contrebasse@105: end contrebasse@98: contrebasse@98: -- Create button contrebasse@98: function A.InitialiseCampFireBtn() contrebasse@103: if not GetTradeSkillLine() or InCombatLockdown() then return end contrebasse@103: contrebasse@98: -- create the frame contrebasse@98: btn = CreateFrame("Button", nil, TradeSkillFrame, "SecureActionButtonTemplate") contrebasse@98: btn:SetNormalTexture(select(3,GetSpellInfo(CAMPFIRE_ID))) contrebasse@105: btn:SetHighlightTexture("Interface\\BUTTONS\\ButtonHilight-Square") contrebasse@98: btn:SetSize(24,24) contrebasse@98: btn:SetPoint("BOTTOMRIGHT",TradeSkillFrame,"BOTTOMRIGHT",-10,179) contrebasse@98: contrebasse@98: -- Set the action contrebasse@98: btn:SetAttribute("type", "spell") contrebasse@98: btn:SetAttribute("spell", CAMPFIRE_ID) contrebasse@98: contrebasse@98: -- Set the tooltip contrebasse@98: btn:SetScript("OnEnter",function(self) contrebasse@98: GameTooltip:SetOwner(self, "ANCHOR_TOPLEFT") contrebasse@98: GameTooltip:SetSpellByID(CAMPFIRE_ID) contrebasse@98: GameTooltip:Show() contrebasse@98: end) contrebasse@98: btn:SetScript("OnLeave",function() GameTooltip:Hide(); end) contrebasse@98: contrebasse@98: -- Add cooldown contrebasse@98: btn.cooldown = CreateFrame("Cooldown",nil,btn) contrebasse@98: btn.cooldown:SetAllPoints(btn) contrebasse@98: contrebasse@105: -- Check if recipe failed due to lack of campfire contrebasse@105: local campfireName = GetSpellInfo(CAMPFIRE_ID) contrebasse@105: local errorMsg contrebasse@105: btn:SetScript("OnEvent",function(self,event,arg1,arg2) contrebasse@105: if not errorMsg or errorMsg==LOCKED_WITH_ITEM then contrebasse@105: local i = GetTradeSkillSelectionIndex() contrebasse@105: if i and i>01 then contrebasse@105: errorMsg = LOCKED_WITH_ITEM:format(GetTradeSkillTools(GetTradeSkillSelectionIndex())) contrebasse@105: end contrebasse@105: end contrebasse@105: if event == "UNIT_SPELLCAST_SUCCEEDED" then contrebasse@105: if arg1 == "player" and arg2 == campfireName then contrebasse@105: self:SetScript("OnUpdate",WaitCooldown) contrebasse@105: --CooldownFrame_SetTimer(self.cooldown,GetSpellCooldown(CAMPFIRE_ID)) contrebasse@105: end contrebasse@105: elseif arg1 == errorMsg and GetSpellCooldown(CAMPFIRE_ID)==0 then contrebasse@105: -- Flash the button if the user tried to cook something without fire contrebasse@105: self.cooldown:SetCooldown(0,0) contrebasse@105: end contrebasse@105: end) contrebasse@98: end contrebasse@98: contrebasse@98: -- Hide button contrebasse@98: function A.HideCampFireBtn() contrebasse@101: if btn then btn:Hide() end contrebasse@98: end contrebasse@98: contrebasse@98: -- Show button if applicable contrebasse@98: function A.ManageCampFireBtn() contrebasse@98: -- Display only if the tradeskill is Cooking contrebasse@103: if not cookingName then cookingName = GetSpellInfo(COOKING_ID) end contrebasse@103: if GetTradeSkillLine() ~= cookingName then contrebasse@105: if btn then btn:Hide(); btn:UnregisterAllEvents() end contrebasse@98: else contrebasse@103: -- create button if necessary contrebasse@103: if not btn then contrebasse@103: A.InitialiseCampFireBtn() contrebasse@103: end contrebasse@103: -- It may not have been created contrebasse@103: if not btn then return end contrebasse@98: btn:Show() contrebasse@105: btn:RegisterEvent("UI_ERROR_MESSAGE") contrebasse@105: btn:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED") contrebasse@105: CooldownFrame_SetTimer(btn.cooldown,GetSpellCooldown(CAMPFIRE_ID)) contrebasse@98: end contrebasse@98: end