public
Description: WoW Addon - Food/water macro generator
Homepage: http://www.tekkub.net
Clone URL: git://github.com/tekkub/buffet.git
Click here to lend your support to: buffet and make a donation at www.pledgie.com !
Add ability to customize macro text on a per-char basis
tekkub (author)
Mon May 26 16:57:28 -0700 2008
commit  c564adc20f6cbaef64ad7346b5725702008777c7
tree    475517ce75852fb53ef488bc0347e2b95cd10895
parent  4af8c6c51bd4f22a0698cc3dc9ab81d19e57c785
...
1
 
 
 
 
 
2
3
4
...
14
15
16
 
 
 
 
17
18
19
...
26
27
28
29
30
31
 
 
 
32
33
34
35
36
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
38
39
40
 
 
41
42
43
44
 
 
 
 
 
 
 
 
45
46
47
...
62
63
64
65
66
 
 
67
68
69
70
71
72
73
74
75
76
77
78
79
 
 
 
 
 
 
 
 
 
 
 
 
 
80
81
82
83
...
1
2
3
4
5
6
7
8
9
...
19
20
21
22
23
24
25
26
27
28
...
35
36
37
 
 
 
38
39
40
41
 
 
 
 
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
 
79
 
80
81
82
83
84
 
85
86
87
88
89
90
91
92
93
94
95
...
110
111
112
 
 
113
114
115
116
117
118
 
 
 
 
 
 
 
 
 
119
120
121
122
123
124
125
126
127
128
129
130
131
132
 
133
 
0
@@ -1,4 +1,9 @@
0
 
0
+----------------------
0
+-- Locals --
0
+----------------------
0
+
0
+local defaults = {macro = "#showtooltip\n%MACRO%"}
0
 local ids, bests, allitems, items, dirty = LibStub("tekIDmemo"), {}, {}, {
0
   bandage = "2581:114,8545:1104,21991:3400,14530:2000,6451:640,3531:301,1251:66,8544:800,21990:2800,14529:1360,6450:400,3530:161",
0
   hstone = "14894:600,25881:400,23329:24,25883:1250,25880:180,15723:1400,11951:800,25882:640,25498:96,11952:425,11951:800,5509:500,5510:800,5511:250,5512:100,9421:1200,19004:110,19005:120,19006:275,19007:300,19008:550,19009:600,19010:880,19011:960,19012:1320,19013:1440,22103:2080,22104:2288,22105:2496",
0
@@ -14,6 +19,10 @@ local ids, bests, allitems, items, dirty = LibStub("tekIDmemo"), {}, {}, {
0
 }
0
 
0
 
0
+------------------------------
0
+-- Util Functions --
0
+------------------------------
0
+
0
 local function TableStuffer(...)
0
   local t = {}
0
   for i=1,select("#", ...) do
0
@@ -26,22 +35,61 @@ end
0
 for i,v in pairs(items) do bests[i], items[i] = {}, TableStuffer(string.split(" ,", v)) end
0
 
0
 
0
-local function edit(name, food, pot, stone, shift)
0
- local macroid = GetMacroIndexByName(name)
0
- if not macroid then return end
0
+-----------------------------
0
+-- Event Handler --
0
+-----------------------------
0
 
0
- local body = "#showtooltip\n/use "
0
- if shift then body = body .. "[mod:shift,target=player] item:"..shift.."; " end
0
- if (pot and not stone) or (stone and not pot) then body = body .. "[combat] item:"..(pot or stone).."; " end
0
- body = body .. (pot and stone and "[nocombat] " or "").."item:"..(food or "6948")
0
+Buffet = CreateFrame("frame")
0
+Buffet:SetScript("OnEvent", function(self, event, ...) if self[event] then return self[event](self, event, ...) end end)
0
+Buffet:RegisterEvent("ADDON_LOADED")
0
+function Buffet:Print(...) ChatFrame1:AddMessage(string.join(" ", "|cFF33FF99Buffet|r:", ...)) end
0
+
0
+
0
+function Buffet:ADDON_LOADED(event, addon)
0
+ if addon ~= "Buffet" then return end
0
+
0
+ BuffetDB = setmetatable(BuffetDB or {}, {__index = defaults})
0
+ self.db = BuffetDB
0
+
0
+ self:UnregisterEvent("ADDON_LOADED")
0
+ self.ADDON_LOADED = nil
0
+
0
+ if IsLoggedIn() then self:PLAYER_LOGIN() else self:RegisterEvent("PLAYER_LOGIN") end
0
+end
0
+
0
+
0
+function Buffet:PLAYER_LOGIN()
0
+ self:RegisterEvent("PLAYER_LOGOUT")
0
+
0
+ self:RegisterEvent("PLAYER_REGEN_ENABLED")
0
+ self:RegisterEvent("BAG_UPDATE")
0
+ self:RegisterEvent("PLAYER_LEVEL_UP")
0
+
0
+ self:Scan()
0
+
0
+ self:UnregisterEvent("PLAYER_LOGIN")
0
+ self.PLAYER_LOGIN = nil
0
+end
0
+
0
+
0
+function Buffet:PLAYER_LOGOUT()
0
+ for i,v in pairs(defaults) do if self.db[i] == v then self.db[i] = nil end end
0
+end
0
 
0
- if pot and stone then body = body .. "\n/castsequence [combat,nomod] reset=combat item:"..stone..", item:"..pot end
0
 
0
- EditMacro(macroid, name, 1, body, 1)
0
+function Buffet:PLAYER_REGEN_ENABLED()
0
+ if dirty then self:Scan() end
0
 end
0
 
0
 
0
-local function scan()
0
+function Buffet:BAG_UPDATE()
0
+ dirty = true
0
+ if not InCombatLockdown() then self:Scan() end
0
+end
0
+Buffet.PLAYER_LEVEL_UP = Buffet.BAG_UPDATE
0
+
0
+
0
+function Buffet:Scan()
0
   for _,t in pairs(bests) do for i in pairs(t) do t[i] = nil end end
0
   local mylevel = UnitLevel("player")
0
 
0
@@ -62,22 +110,24 @@ local function scan()
0
     end
0
   end
0
 
0
- edit("AutoHP", bests.conjfood.id or bests.percfood.id or bests.food.id or bests.hstone.id or bests.hppot.id, bests.hppot.id, bests.hstone.id, bests.bandage.id)
0
- edit("AutoMP", bests.conjwater.id or bests.percwater.id or bests.water.id or bests.mstone.id or bests.mppot.id, bests.mppot.id, bests.mstone.id)
0
+ self:Edit("AutoHP", bests.conjfood.id or bests.percfood.id or bests.food.id or bests.hstone.id or bests.hppot.id, bests.hppot.id, bests.hstone.id, bests.bandage.id)
0
+ self:Edit("AutoMP", bests.conjwater.id or bests.percwater.id or bests.water.id or bests.mstone.id or bests.mppot.id, bests.mppot.id, bests.mstone.id)
0
   dirty = false
0
 end
0
 
0
 
0
-local f = CreateFrame("Frame")
0
-f:SetScript("OnEvent", function(self, event, ...)
0
- if event ~= "PLAYER_REGEN_ENABLED" then dirty = true end
0
- if dirty and not InCombatLockdown() then scan() end
0
-end)
0
-f:RegisterEvent("PLAYER_LOGIN")
0
-f:RegisterEvent("PLAYER_REGEN_ENABLED")
0
-f:RegisterEvent("BAG_UPDATE")
0
-f:RegisterEvent("PLAYER_LEVEL_UP")
0
+function Buffet:Edit(name, food, pot, stone, shift)
0
+ local macroid = GetMacroIndexByName(name)
0
+ if not macroid then return end
0
+
0
+ local body = "/use "
0
+ if shift then body = body .. "[mod:shift,target=player] item:"..shift.."; " end
0
+ if (pot and not stone) or (stone and not pot) then body = body .. "[combat] item:"..(pot or stone).."; " end
0
+ body = body .. (pot and stone and "[nocombat] " or "").."item:"..(food or "6948")
0
+
0
+ if pot and stone then body = body .. "\n/castsequence [combat,nomod] reset=combat item:"..stone..", item:"..pot end
0
+
0
+ EditMacro(macroid, name, 1, self.db.macro:gsub("%%MACRO%%", body), 1)
0
+end
0
 
0
-scan()
0
 
0
-BUFFET_SCAN = scan
...
7
8
9
 
 
10
11
12
...
7
8
9
10
11
12
13
14
0
@@ -7,6 +7,8 @@
0
 ## X-Website: http://www.tekkub.net/
0
 ## X-Email: tekkub-wow@googlegroups.com
0
 
0
+## SavedVariablesPerCharacter: BuffetDB
0
+
0
 ## LoadManagers: AddonLoader
0
 ## X-LoadOn-Always: delayed
0
 
...
1
2
 
3
4
5
6
7
8
9
10
11
12
 
13
14
15
16
 
 
17
18
19
 
20
21
22
...
32
33
34
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
36
37
...
1
 
2
3
 
 
4
5
6
7
8
9
 
10
11
12
 
 
13
14
15
16
 
17
18
19
20
...
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
0
@@ -1,22 +1,20 @@
0
 
0
-local GAP = 8
0
+local EDGEGAP, GAP = 16, 8
0
 local tekbutt = LibStub("tekKonfig-Button")
0
-local scan = BUFFET_SCAN
0
-BUFFET_SCAN = nil
0
 
0
 
0
 local frame = CreateFrame("Frame", nil, UIParent)
0
 frame.name = "Buffet"
0
 frame:Hide()
0
 frame:SetScript("OnShow", function()
0
- local title, subtitle = LibStub("tekKonfig-Heading").new(frame, "Buffet", "This panel allows you to quickly create the base macros for Buffet to edit. You only need to do this once unless you delete the macros.")
0
+ local title, subtitle = LibStub("tekKonfig-Heading").new(frame, "Buffet", "This panel allows you to quickly create the base macros for Buffet to edit. You can also set the macro text to be used.")
0
 
0
   local function OnClick(self)
0
- if InCombatLockdown() then ChatFrame1:AddMessage("|cFF33FF99Buffet:|r Cannot create macros in combat.")
0
- elseif GetNumMacros() >= 18 then ChatFrame1:AddMessage("|cFF33FF99Buffet:|r All global macros in use.")
0
+ if InCombatLockdown() then Buffet:Print("Cannot create macros in combat.")
0
+ elseif GetNumMacros() >= 18 then Buffet:Print("All global macros in use.")
0
     else
0
       CreateMacro(self.name, 1, "", 1)
0
- scan()
0
+ Buffet:Scan()
0
     end
0
   end
0
 
0
@@ -32,6 +30,40 @@ frame:SetScript("OnShow", function()
0
   mpbutt.name = "AutoMP"
0
   mpbutt:SetScript("OnClick", OnClick)
0
 
0
+ local macrolabel = frame:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
0
+ macrolabel:SetText("Macro")
0
+ macrolabel:SetPoint("TOPLEFT", hpbutt, "BOTTOMLEFT", 5, -GAP)
0
+
0
+ local editbox = CreateFrame("EditBox", nil, frame)
0
+ editbox:SetPoint("TOP", macrolabel, "BOTTOM", 0, -5)
0
+ editbox:SetPoint("LEFT", EDGEGAP/3, 0)
0
+ editbox:SetPoint("BOTTOMRIGHT", -EDGEGAP/3, EDGEGAP/3)
0
+ editbox:SetFontObject(GameFontHighlight)
0
+ editbox:SetTextInsets(8,8,8,8)
0
+ editbox:SetBackdrop({
0
+ bgFile = "Interface\\ChatFrame\\ChatFrameBackground",
0
+ edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
0
+ edgeSize = 16,
0
+ insets = {left = 4, right = 4, top = 4, bottom = 4}
0
+ })
0
+ editbox:SetBackdropColor(.1,.1,.1,.3)
0
+ editbox:SetMultiLine(true)
0
+ editbox:SetAutoFocus(false)
0
+ editbox:SetText(Buffet.db.macro)
0
+ editbox:SetScript("OnEditFocusLost", function()
0
+ local newmacro = editbox:GetText()
0
+ if not newmacro:find("%%MACRO%%") then
0
+ Buffet:Print('Macro text must contain the string "%MACRO%".')
0
+ else
0
+ Buffet.db.macro = newmacro
0
+ Buffet:BAG_UPDATE()
0
+ end
0
+ end)
0
+ editbox:SetScript("OnEscapePressed", editbox.ClearFocus)
0
+ editbox.tiptext = 'Customize the macro text. Must include the string "%MACRO%", which is replaced with the items to be used. This setting is saved on a per-char basis.'
0
+ editbox:SetScript("OnEnter", mpbutt:GetScript("OnEnter"))
0
+ editbox:SetScript("OnLeave", mpbutt:GetScript("OnLeave"))
0
+
0
   local function Refresh(self)
0
     if GetMacroIndexByName("AutoHP") == 0 then hpbutt:Enable() else hpbutt:Disable() end
0
     if GetMacroIndexByName("AutoMP") == 0 then mpbutt:Enable() else mpbutt:Disable() end

Comments

    No one has commented yet.