Mercurial > wow > reagentmaker
comparison EnchantOnScroll.lua @ 77:cd36938d2a48
Add a button to put enchants directly on a scroll
| author | contrebasse |
|---|---|
| date | Sat, 14 May 2011 23:54:02 +0200 |
| parents | |
| children | d2b4b378bea4 |
comparison
equal
deleted
inserted
replaced
| 76:9d487333bf10 | 77:cd36938d2a48 |
|---|---|
| 1 local addonName, A = ... | |
| 2 | |
| 3 local SCROLL_ID = 38682 | |
| 4 local ENCHANTING_ID = 7411 | |
| 5 local btn | |
| 6 | |
| 7 local EventsFrame = CreateFrame("Frame",nil,TradeSkillFrame) -- It will be hidden with the TradeSkillFrame | |
| 8 | |
| 9 local function CheckButtonAvailable(arg1) | |
| 10 if not btn then return end | |
| 11 | |
| 12 -- Do not manage guild tradeskill | |
| 13 -- Check that we're still with the enchanting tradeskill | |
| 14 if IsTradeSkillGuild() or IsTradeSkillLinked() or GetTradeSkillLine() ~= GetSpellInfo(ENCHANTING_ID) then | |
| 15 btn:Hide() | |
| 16 return | |
| 17 end | |
| 18 | |
| 19 -- Check that the selected recipe can be crafted, and the crafted thing is an enchant | |
| 20 local index = GetTradeSkillSelectionIndex() | |
| 21 if not index then | |
| 22 btn:Disable() | |
| 23 btn:Show() | |
| 24 return | |
| 25 end | |
| 26 local _, _, numAvailable, _, serviceType = GetTradeSkillInfo(index) | |
| 27 | |
| 28 -- serviceType is localised, but nil if an item is created | |
| 29 if not serviceType then | |
| 30 btn:Hide() | |
| 31 return | |
| 32 end | |
| 33 if numAvailable==0 or not serviceType then | |
| 34 btn:Disable() | |
| 35 btn:Show() | |
| 36 return | |
| 37 end | |
| 38 | |
| 39 -- Check that there's scrolls in the bags | |
| 40 local itemCount = GetItemCount(SCROLL_ID) | |
| 41 if not itemCount or itemCount==0 then | |
| 42 btn:Disable() | |
| 43 btn:Show() | |
| 44 return | |
| 45 end | |
| 46 | |
| 47 -- It passed the tests | |
| 48 btn:Enable() | |
| 49 btn:Show() | |
| 50 end | |
| 51 EventsFrame:SetScript("OnEvent",CheckButtonAvailable) | |
| 52 EventsFrame:RegisterEvent("BAG_UPDATE") | |
| 53 hooksecurefunc("SelectTradeSkill",CheckButtonAvailable) | |
| 54 | |
| 55 function A.LoadEnchantOnScroll() | |
| 56 btn = CreateFrame("Button", nil, TradeSkillFrame, "UIPanelButtonTemplate") | |
| 57 btn:SetSize(168,22) | |
| 58 btn:SetPoint("TOPRIGHT",TradeSkillCreateButton,"TOPLEFT",0,0) | |
| 59 btn:SetText(A.L["Enchant on a scroll"]) | |
| 60 btn:Show() | |
| 61 | |
| 62 btn:SetScript("OnClick",function() | |
| 63 -- from http://wowprogramming.com/utils/xmlbrowser/live/AddOns/Blizzard_TradeSkillUI/Blizzard_TradeSkillUI.xml | |
| 64 DoTradeSkill(TradeSkillFrame.selectedSkill,1) | |
| 65 | |
| 66 -- From GnomeWorks/ScrollMaking.lua | |
| 67 UseItemByName(SCROLL_ID) | |
| 68 end) | |
| 69 end |
