Mercurial > wow > reagentmaker
comparison CampFireButton.lua @ 105:08ede537787b v1.0beta12
Upgrade Campfirebutton
author | contrebasse |
---|---|
date | Tue, 31 May 2011 00:57:01 +0200 |
parents | c8d527a9fb3a |
children | af23986010ef |
comparison
equal
deleted
inserted
replaced
104:a9bda1f95232 | 105:08ede537787b |
---|---|
2 | 2 |
3 local CAMPFIRE_ID = 818 | 3 local CAMPFIRE_ID = 818 |
4 local COOKING_ID = 2550 | 4 local COOKING_ID = 2550 |
5 local btn | 5 local btn |
6 local cookingName | 6 local cookingName |
7 local CooldownFrame_SetTimer = CooldownFrame_SetTimer | |
8 local GetSpellCooldown = GetSpellCooldown | |
9 | |
10 local function WaitCooldown(self) | |
11 local start, duration, enable = GetSpellCooldown(CAMPFIRE_ID) | |
12 if start>0 then | |
13 CooldownFrame_SetTimer(btn.cooldown,GetSpellCooldown(CAMPFIRE_ID)) | |
14 self:SetScript("OnUpdate",nil) | |
15 end | |
16 end | |
7 | 17 |
8 -- Create button | 18 -- Create button |
9 function A.InitialiseCampFireBtn() | 19 function A.InitialiseCampFireBtn() |
10 if not GetTradeSkillLine() or InCombatLockdown() then return end | 20 if not GetTradeSkillLine() or InCombatLockdown() then return end |
11 | 21 |
12 -- create the frame | 22 -- create the frame |
13 btn = CreateFrame("Button", nil, TradeSkillFrame, "SecureActionButtonTemplate") | 23 btn = CreateFrame("Button", nil, TradeSkillFrame, "SecureActionButtonTemplate") |
14 btn:SetNormalTexture(select(3,GetSpellInfo(CAMPFIRE_ID))) | 24 btn:SetNormalTexture(select(3,GetSpellInfo(CAMPFIRE_ID))) |
25 btn:SetHighlightTexture("Interface\\BUTTONS\\ButtonHilight-Square") | |
15 btn:SetSize(24,24) | 26 btn:SetSize(24,24) |
16 btn:SetPoint("BOTTOMRIGHT",TradeSkillFrame,"BOTTOMRIGHT",-10,179) | 27 btn:SetPoint("BOTTOMRIGHT",TradeSkillFrame,"BOTTOMRIGHT",-10,179) |
17 | 28 |
18 -- Set the action | 29 -- Set the action |
19 btn:SetAttribute("type", "spell") | 30 btn:SetAttribute("type", "spell") |
28 btn:SetScript("OnLeave",function() GameTooltip:Hide(); end) | 39 btn:SetScript("OnLeave",function() GameTooltip:Hide(); end) |
29 | 40 |
30 -- Add cooldown | 41 -- Add cooldown |
31 btn.cooldown = CreateFrame("Cooldown",nil,btn) | 42 btn.cooldown = CreateFrame("Cooldown",nil,btn) |
32 btn.cooldown:SetAllPoints(btn) | 43 btn.cooldown:SetAllPoints(btn) |
33 local CooldownFrame_SetTimer = CooldownFrame_SetTimer | |
34 local GetSpellCooldown = GetSpellCooldown | |
35 btn:SetScript("OnUpdate",function(self) CooldownFrame_SetTimer(self.cooldown,GetSpellCooldown(CAMPFIRE_ID)); end) | |
36 | 44 |
37 -- Show if needed | 45 -- Check if recipe failed due to lack of campfire |
38 A.ManageCampFireBtn() | 46 local campfireName = GetSpellInfo(CAMPFIRE_ID) |
47 local errorMsg | |
48 btn:SetScript("OnEvent",function(self,event,arg1,arg2) | |
49 if not errorMsg or errorMsg==LOCKED_WITH_ITEM then | |
50 local i = GetTradeSkillSelectionIndex() | |
51 if i and i>01 then | |
52 errorMsg = LOCKED_WITH_ITEM:format(GetTradeSkillTools(GetTradeSkillSelectionIndex())) | |
53 end | |
54 end | |
55 if event == "UNIT_SPELLCAST_SUCCEEDED" then | |
56 if arg1 == "player" and arg2 == campfireName then | |
57 self:SetScript("OnUpdate",WaitCooldown) | |
58 --CooldownFrame_SetTimer(self.cooldown,GetSpellCooldown(CAMPFIRE_ID)) | |
59 end | |
60 elseif arg1 == errorMsg and GetSpellCooldown(CAMPFIRE_ID)==0 then | |
61 -- Flash the button if the user tried to cook something without fire | |
62 self.cooldown:SetCooldown(0,0) | |
63 end | |
64 end) | |
39 end | 65 end |
40 | 66 |
41 -- Hide button | 67 -- Hide button |
42 function A.HideCampFireBtn() | 68 function A.HideCampFireBtn() |
43 if btn then btn:Hide() end | 69 if btn then btn:Hide() end |
46 -- Show button if applicable | 72 -- Show button if applicable |
47 function A.ManageCampFireBtn() | 73 function A.ManageCampFireBtn() |
48 -- Display only if the tradeskill is Cooking | 74 -- Display only if the tradeskill is Cooking |
49 if not cookingName then cookingName = GetSpellInfo(COOKING_ID) end | 75 if not cookingName then cookingName = GetSpellInfo(COOKING_ID) end |
50 if GetTradeSkillLine() ~= cookingName then | 76 if GetTradeSkillLine() ~= cookingName then |
51 if btn then btn:Hide() end | 77 if btn then btn:Hide(); btn:UnregisterAllEvents() end |
52 else | 78 else |
53 -- create button if necessary | 79 -- create button if necessary |
54 if not btn then | 80 if not btn then |
55 A.InitialiseCampFireBtn() | 81 A.InitialiseCampFireBtn() |
56 end | 82 end |
57 -- It may not have been created | 83 -- It may not have been created |
58 if not btn then return end | 84 if not btn then return end |
59 btn:Show() | 85 btn:Show() |
86 btn:RegisterEvent("UI_ERROR_MESSAGE") | |
87 btn:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED") | |
88 CooldownFrame_SetTimer(btn.cooldown,GetSpellCooldown(CAMPFIRE_ID)) | |
60 end | 89 end |
61 end | 90 end |