flickerstreak@161
|
1 --[[
|
flickerstreak@161
|
2 ReAction Totem button module
|
flickerstreak@161
|
3
|
flickerstreak@161
|
4 --]]
|
flickerstreak@161
|
5
|
flickerstreak@161
|
6 -- local imports
|
flickerstreak@161
|
7 local ReAction = ReAction
|
flickerstreak@161
|
8 local L = ReAction.L
|
flickerstreak@161
|
9 local _G = _G
|
flickerstreak@161
|
10
|
flickerstreak@161
|
11 -- button
|
flickerstreak@161
|
12 local Button = ReAction.Button.MultiCast
|
flickerstreak@161
|
13
|
flickerstreak@161
|
14 -- module declaration
|
flickerstreak@161
|
15 local moduleID = "Totem"
|
flickerstreak@161
|
16 local module = ReAction:NewModule( moduleID,
|
flickerstreak@161
|
17 "AceEvent-3.0"
|
flickerstreak@161
|
18 -- mixins go here
|
flickerstreak@161
|
19 )
|
flickerstreak@161
|
20
|
flickerstreak@161
|
21 -- handlers
|
flickerstreak@161
|
22 function module:OnInitialize()
|
flickerstreak@161
|
23 self.db = ReAction.db:RegisterNamespace( moduleID,
|
flickerstreak@161
|
24 {
|
flickerstreak@161
|
25 profile = {
|
flickerstreak@161
|
26 buttons = { }
|
flickerstreak@161
|
27 }
|
flickerstreak@161
|
28 }
|
flickerstreak@161
|
29 )
|
flickerstreak@161
|
30
|
flickerstreak@161
|
31 self.buttons = { }
|
flickerstreak@161
|
32
|
flickerstreak@161
|
33 ReAction:RegisterOptions(self, self:GetOptions())
|
flickerstreak@161
|
34
|
flickerstreak@161
|
35 ReAction.RegisterCallback(self, "OnCreateBar", "OnRefreshBar")
|
flickerstreak@161
|
36 ReAction.RegisterCallback(self, "OnDestroyBar")
|
flickerstreak@161
|
37 ReAction.RegisterCallback(self, "OnRefreshBar")
|
flickerstreak@161
|
38 ReAction.RegisterCallback(self, "OnEraseBar")
|
flickerstreak@161
|
39 ReAction.RegisterCallback(self, "OnRenameBar")
|
flickerstreak@161
|
40
|
flickerstreak@162
|
41 self:RegisterEvent("UPDATE_MULTI_CAST_ACTIONBAR","PLAYER_ENTERING_WORLD")
|
flickerstreak@161
|
42 end
|
flickerstreak@161
|
43
|
flickerstreak@161
|
44 function module:OnEnable()
|
flickerstreak@161
|
45 ReAction:RegisterBarType(L["Totem Bar"],
|
flickerstreak@161
|
46 {
|
flickerstreak@161
|
47 type = moduleID ,
|
flickerstreak@161
|
48 defaultButtonSize = 36,
|
flickerstreak@161
|
49 defaultBarRows = 1,
|
flickerstreak@161
|
50 defaultBarCols = 6,
|
flickerstreak@161
|
51 defaultBarSpacing = 3
|
flickerstreak@161
|
52 })
|
flickerstreak@161
|
53
|
flickerstreak@161
|
54 end
|
flickerstreak@161
|
55
|
flickerstreak@161
|
56 function module:OnDisable()
|
flickerstreak@161
|
57 ReAction:UnregisterBarType(L["Totem Bar"])
|
flickerstreak@161
|
58 end
|
flickerstreak@161
|
59
|
flickerstreak@161
|
60 function module:OnDestroyBar(event, bar, name)
|
flickerstreak@161
|
61 local btns = self.buttons[bar]
|
flickerstreak@161
|
62 if btns then
|
flickerstreak@161
|
63 for _,b in pairs(btns) do
|
flickerstreak@161
|
64 if b then
|
flickerstreak@161
|
65 b:Destroy()
|
flickerstreak@161
|
66 end
|
flickerstreak@161
|
67 end
|
flickerstreak@161
|
68 self.buttons[bar] = nil
|
flickerstreak@161
|
69 end
|
flickerstreak@161
|
70 end
|
flickerstreak@161
|
71
|
flickerstreak@161
|
72 function module:OnRefreshBar(event, bar, name)
|
flickerstreak@161
|
73 if bar.config.type == moduleID then
|
flickerstreak@161
|
74 local btns = self.buttons[bar]
|
flickerstreak@161
|
75 if btns == nil then
|
flickerstreak@161
|
76 btns = { }
|
flickerstreak@161
|
77 self.buttons[bar] = btns
|
flickerstreak@161
|
78 end
|
flickerstreak@161
|
79 local profile = self.db.profile
|
flickerstreak@161
|
80 if profile.buttons[name] == nil then
|
flickerstreak@161
|
81 profile.buttons[name] = {}
|
flickerstreak@161
|
82 end
|
flickerstreak@161
|
83 local btnCfg = profile.buttons[name]
|
flickerstreak@161
|
84
|
flickerstreak@161
|
85 local r, c = bar:GetButtonGrid()
|
flickerstreak@163
|
86 local n = min(r*c,6)
|
flickerstreak@163
|
87 Button.SetupBarHeader(bar)
|
flickerstreak@161
|
88 for i = 1, n do
|
flickerstreak@161
|
89 if btnCfg[i] == nil then
|
flickerstreak@161
|
90 btnCfg[i] = {}
|
flickerstreak@161
|
91 end
|
flickerstreak@164
|
92 if not btns[i] then
|
flickerstreak@161
|
93 local success, r = pcall(Button.New,Button,i,btnCfg,bar)
|
flickerstreak@163
|
94 if success then
|
flickerstreak@161
|
95 btns[i] = r
|
flickerstreak@163
|
96 if r then
|
flickerstreak@163
|
97 bar:AddButton(i,r)
|
flickerstreak@163
|
98 end
|
flickerstreak@161
|
99 else
|
flickerstreak@161
|
100 geterrorhandler()(r)
|
flickerstreak@161
|
101 n = i - 1
|
flickerstreak@161
|
102 bar:ClipNButtons(n)
|
flickerstreak@161
|
103 break
|
flickerstreak@161
|
104 end
|
flickerstreak@161
|
105 end
|
flickerstreak@163
|
106 if btns[i] then
|
flickerstreak@163
|
107 btns[i]:Refresh()
|
flickerstreak@163
|
108 end
|
flickerstreak@161
|
109 end
|
flickerstreak@161
|
110 for i = n+1, #btns do
|
flickerstreak@161
|
111 if btns[i] then
|
flickerstreak@161
|
112 bar:RemoveButton(btns[i])
|
flickerstreak@161
|
113 btns[i] = btns[i]:Destroy()
|
flickerstreak@161
|
114 if btnCfg[i] then
|
flickerstreak@161
|
115 btnCfg[i] = nil
|
flickerstreak@161
|
116 end
|
flickerstreak@161
|
117 end
|
flickerstreak@161
|
118 end
|
flickerstreak@161
|
119 end
|
flickerstreak@161
|
120
|
flickerstreak@161
|
121 end
|
flickerstreak@161
|
122
|
flickerstreak@161
|
123 function module:OnEraseBar(event, bar, name)
|
flickerstreak@161
|
124 self.db.profile.buttons[name] = nil
|
flickerstreak@161
|
125 end
|
flickerstreak@161
|
126
|
flickerstreak@161
|
127 function module:OnRenameBar(event, bar, oldName, newName)
|
flickerstreak@161
|
128 local b = self.db.profile.buttons
|
flickerstreak@161
|
129 b[newname], b[oldname] = b[oldname], nil
|
flickerstreak@161
|
130 end
|
flickerstreak@161
|
131
|
flickerstreak@161
|
132 function module:RefreshAll()
|
flickerstreak@161
|
133 for bar in pairs(self.buttons) do
|
flickerstreak@161
|
134 self:OnRefreshBar(nil,bar,bar:GetName())
|
flickerstreak@161
|
135 end
|
flickerstreak@161
|
136 end
|
flickerstreak@161
|
137
|
flickerstreak@162
|
138 function module:UPDATE_MULTI_CAST_ACTIONBAR()
|
flickerstreak@162
|
139 if not InCombatLockdown() then
|
flickerstreak@162
|
140 for bar in pairs(self.buttons) do
|
flickerstreak@162
|
141 self:OnRefreshBar("OnRefreshBar", bar, bar:GetName())
|
flickerstreak@162
|
142 end
|
flickerstreak@162
|
143 end
|
flickerstreak@162
|
144 end
|
flickerstreak@162
|
145
|
flickerstreak@162
|
146 function module:PLAYER_ENTERING_WORLD()
|
flickerstreak@162
|
147 for bar in pairs(self.buttons) do
|
flickerstreak@162
|
148 self:OnRefreshBar("OnRefreshBar", bar, bar:GetName())
|
flickerstreak@162
|
149 end
|
flickerstreak@162
|
150 end
|
flickerstreak@162
|
151
|
flickerstreak@161
|
152
|
flickerstreak@161
|
153 ---- options ----
|
flickerstreak@161
|
154 function module:GetOptions()
|
flickerstreak@161
|
155 return {
|
flickerstreak@161
|
156 stance =
|
flickerstreak@161
|
157 {
|
flickerstreak@161
|
158 name = L["Totem Buttons"],
|
flickerstreak@161
|
159 type = "group",
|
flickerstreak@161
|
160 args = {
|
flickerstreak@161
|
161 -- TODO
|
flickerstreak@161
|
162 }
|
flickerstreak@161
|
163 }
|
flickerstreak@161
|
164 }
|
flickerstreak@161
|
165 end
|