rowaasr13@0
|
1 -- [AUTOLOCAL START]
|
rowaasr13@0
|
2 local CreateFrame = CreateFrame
|
rowaasr13@0
|
3 local InCombatLockdown = InCombatLockdown
|
rowaasr13@0
|
4 local SecureHandlerWrapScript = SecureHandlerWrapScript
|
rowaasr13@0
|
5 local print = print
|
rowaasr13@0
|
6 local type = type
|
rowaasr13@0
|
7 -- [AUTOLOCAL END]
|
rowaasr13@0
|
8
|
rowaasr13@0
|
9 local frame_name = "OOCDo"
|
rowaasr13@0
|
10 local button = CreateFrame("Button", frame_name, nil, "SecureActionButtonTemplate,SecureHandlerMouseUpDownTemplate")
|
rowaasr13@0
|
11 button:SetAttribute("type", "macro")
|
rowaasr13@0
|
12 button:SetAttribute("macrotext", "")
|
rowaasr13@0
|
13 SecureHandlerWrapScript(
|
rowaasr13@0
|
14 button, -- frame
|
rowaasr13@0
|
15 "OnClick", -- script
|
rowaasr13@0
|
16 button, -- header
|
rowaasr13@6
|
17 'return nil, "reset"', -- pre
|
rowaasr13@6
|
18 'self:SetAttribute("type", "macro") self:SetAttribute("macrotext", "")' -- post
|
rowaasr13@0
|
19 )
|
rowaasr13@0
|
20
|
rowaasr13@7
|
21 --- Sets button to perform given macro text as-is.
|
rowaasr13@7
|
22 -- Sets button's .type to "macro" and .macrotext to given string verbatim
|
rowaasr13@7
|
23 -- @param command macro text to perform
|
rowaasr13@7
|
24 -- @param command2 same as command, if first argument is "taken" because of : call.
|
rowaasr13@2
|
25 function button.MacroText(command, command2)
|
rowaasr13@0
|
26 if command == button then command = command2 end
|
rowaasr13@0
|
27 if InCombatLockdown() then return end
|
rowaasr13@7
|
28 button:SetAttribute("type", "macro")
|
rowaasr13@0
|
29 button:SetAttribute("macrotext", command)
|
rowaasr13@0
|
30 end
|
rowaasr13@0
|
31 button.Macro = button.MacroText
|
rowaasr13@0
|
32 button.T = button.MacroText
|
rowaasr13@8
|
33 button.M = button.MacroText
|
rowaasr13@8
|
34
|
rowaasr13@8
|
35 --- Tries to set button to use first available item from list.
|
rowaasr13@8
|
36 -- Sets button's .type to "item" and .item to first item that player have (GetItemCount > 0).
|
rowaasr13@8
|
37 -- Returns if any item was found or not, so you can use this in conditional to do something else if there were no suitable items.
|
rowaasr13@8
|
38 -- If none of items was found, button will still lose previously assigned command.
|
rowaasr13@8
|
39 -- @param ... list of item IDs to try
|
rowaasr13@8
|
40 -- @return true if any item was found and nil otherwise
|
rowaasr13@8
|
41 function button.Use(...)
|
rowaasr13@8
|
42 if InCombatLockdown() then return end
|
rowaasr13@8
|
43 button:SetAttribute("type", "item")
|
rowaasr13@8
|
44 button:SetAttribute("item", nil)
|
rowaasr13@8
|
45 for idx = 1, select('#', ...) do repeat
|
rowaasr13@8
|
46 local elem = select(idx, ...)
|
rowaasr13@8
|
47 if elem == button then break end
|
rowaasr13@8
|
48 if type(elem) == "number" then
|
rowaasr13@8
|
49 if GetItemCount(elem) > 0 then
|
rowaasr13@8
|
50 button:SetAttribute("item", "item:" .. elem)
|
rowaasr13@8
|
51 return true
|
rowaasr13@8
|
52 end
|
rowaasr13@8
|
53 end
|
rowaasr13@8
|
54 until true end
|
rowaasr13@8
|
55 end
|
rowaasr13@8
|
56
|
rowaasr13@8
|
57 --- Tries to set button to castwe first available spell from list.
|
rowaasr13@8
|
58 -- Sets button's .type to "spell" and .spell to first spell that player knowns (GetSpellInfo(name) returns something).
|
rowaasr13@8
|
59 -- Returns if any spell was found or not, so you can use this in conditional to do something else if there were no suitable spells.
|
rowaasr13@8
|
60 -- If none of spells was found, button will still lose previously assigned command.
|
rowaasr13@8
|
61 -- @param ... list of spell IDs to try
|
rowaasr13@8
|
62 -- @return true if any spell was found and nil otherwise
|
rowaasr13@8
|
63 function button.Cast(...)
|
rowaasr13@8
|
64 if InCombatLockdown() then return end
|
rowaasr13@8
|
65 button:SetAttribute("type", "spell")
|
rowaasr13@8
|
66 button:SetAttribute("spell", nil)
|
rowaasr13@8
|
67 for idx = 1, select('#', ...) do repeat
|
rowaasr13@8
|
68 local elem = select(idx, ...)
|
rowaasr13@8
|
69 if elem == button then break end
|
rowaasr13@8
|
70 if type(elem) == "number" then
|
rowaasr13@8
|
71 if GetSpellInfo(GetSpellInfo(elem)) then
|
rowaasr13@8
|
72 button:SetAttribute("spell", elem)
|
rowaasr13@8
|
73 return true
|
rowaasr13@8
|
74 end
|
rowaasr13@8
|
75 end
|
rowaasr13@8
|
76 until true end
|
rowaasr13@8
|
77 end |