vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1  
2 ------------------------------
3 -- Are you local? --
4 ------------------------------
5  
6 local dewdrop = AceLibrary("Dewdrop-2.0")
7 local tablet = AceLibrary("Tablet-2.0")
8  
9 local events, opts = {}, {}
10  
11  
12 local custom = SupplyAndDemand:NewModule("Misc")
13  
14  
15 function custom:GetDefaults()
16 for name,mod in pairs(self.lodmods) do
17 local desc = GetAddOnMetadata(name, "X-S&D-CustomDesc")
18 if desc then
19 local event = GetAddOnMetadata(name, "X-S&D-CustomEvent")
20 local condition = GetAddOnMetadata(name, "X-S&D-CustomCondition")
21 self:RegisterMod(name, desc, event, condition)
22 end
23 end
24  
25 return opts
26 end
27  
28  
29 function custom:RegisterMod(name, desc, event, condition)
30 assert(name, "No addon name passed")
31 assert(desc, "No loadset description passed")
32 assert(event or condition, "No event or condition function passed for "..name)
33  
34 local mod = self.lodmods[name]
35 mod.hashandler = true
36 mod.customdesc = desc
37  
38 if event then
39 mod.customevent = event
40 events[event] = events[event] or {}
41 events[event][name] = true
42 end
43  
44 if type(condition) == "string" then
45 local func, errorMessage = loadstring(condition, "S&DCustomCond_"..name)
46 if errorMessage then error(errorMessage) end
47 mod.customcondition = func
48 elseif type(condition) == "function" then
49 mod.customcondition = condition
50 end
51  
52 opts[name] = true
53 end
54  
55  
56 function custom:OnEnable()
57 for name,mod in pairs(self.lodmods) do
58 if self.db.profile[name] and not IsAddOnLoaded(name) and mod.customcondition and mod.customcondition() then
59 mod.loadedby = mod.customdesc
60 LoadAddOn(name)
61 end
62 if mod.loadedby and mod.customevent then events[mod.customevent][name] = nil end
63 end
64  
65 for event,val in pairs(events) do
66 if next(val) then self:RegisterEvent(event, "EventHandler") end
67 end
68 end
69  
70  
71 function custom:EventHandler()
72 if events[event] then
73 for name in pairs(events[event]) do
74 local mod = self.lodmods[name]
75 if self.db.profile[name] and not IsAddOnLoaded(name) and (not mod.customcondition or mod.customcondition()) then
76 mod.loadedby = mod.customdesc
77 LoadAddOn(name)
78 end
79 if mod.loadedby then events[event][name] = nil end
80 end
81 if not next(events[event]) then
82 self:UnregisterEvent(event)
83 events[event] = nil
84 end
85 end
86 end
87  
88  
89 function custom:MenuValid()
90 for name,mod in pairs(self.lodmods) do
91 if mod.customdesc then return true end
92 end
93 end
94  
95  
96 function custom:OnMenuRequest(level, v1, intip, v2, v3, v4)
97 if level == 2 then
98 for _,mod in pairs(self.sortmods) do
99 local v = self.lodmods[mod]
100 if v.customdesc then
101 dewdrop:AddLine("text", v.title.." |cffff8080("..v.customdesc..")", "value", mod, "checked", self.db.profile[mod],
102 "func", self.Toggle, "arg1", self, "arg2", mod)
103 end
104 end
105 end
106 end
107  
108  
109 function custom:Toggle(mod)
110 self.db.profile[mod] = not self.db.profile[mod]
111 end
112