flickerstreak@134
|
1 --[[
|
flickerstreak@134
|
2 ReAction Stance button module
|
flickerstreak@134
|
3
|
flickerstreak@134
|
4 --]]
|
flickerstreak@134
|
5
|
flickerstreak@134
|
6 -- local imports
|
flickerstreak@134
|
7 local ReAction = ReAction
|
flickerstreak@134
|
8 local L = ReAction.L
|
flickerstreak@134
|
9 local _G = _G
|
flickerstreak@134
|
10
|
flickerstreak@134
|
11 -- Stance button
|
flickerstreak@134
|
12 local Button = ReAction.Button.Stance
|
flickerstreak@134
|
13
|
flickerstreak@134
|
14 -- module declaration
|
flickerstreak@134
|
15 local moduleID = "Stance"
|
flickerstreak@134
|
16 local module = ReAction:NewModule( moduleID
|
flickerstreak@134
|
17 -- mixins go here
|
flickerstreak@134
|
18 )
|
flickerstreak@134
|
19
|
flickerstreak@134
|
20 -- libraries
|
flickerstreak@134
|
21 local KB = LibStub("LibKeyBound-1.0")
|
flickerstreak@134
|
22
|
flickerstreak@134
|
23 -- handlers
|
flickerstreak@134
|
24 function module:OnInitialize()
|
flickerstreak@134
|
25 self.db = ReAction.db:RegisterNamespace( moduleID,
|
flickerstreak@134
|
26 {
|
flickerstreak@134
|
27 profile = {
|
flickerstreak@134
|
28 buttons = { }
|
flickerstreak@134
|
29 }
|
flickerstreak@134
|
30 }
|
flickerstreak@134
|
31 )
|
flickerstreak@134
|
32
|
flickerstreak@134
|
33 self.buttons = { }
|
flickerstreak@134
|
34
|
flickerstreak@134
|
35 ReAction:RegisterOptions(self, self:GetOptions())
|
flickerstreak@134
|
36
|
flickerstreak@134
|
37 ReAction.RegisterCallback(self, "OnCreateBar", "OnRefreshBar")
|
flickerstreak@134
|
38 ReAction.RegisterCallback(self, "OnDestroyBar")
|
flickerstreak@134
|
39 ReAction.RegisterCallback(self, "OnRefreshBar")
|
flickerstreak@134
|
40 ReAction.RegisterCallback(self, "OnEraseBar")
|
flickerstreak@134
|
41 ReAction.RegisterCallback(self, "OnRenameBar")
|
flickerstreak@134
|
42 ReAction.RegisterCallback(self, "OnConfigModeChanged")
|
flickerstreak@134
|
43
|
flickerstreak@134
|
44 KB.RegisterCallback(self, "LIBKEYBOUND_ENABLED")
|
flickerstreak@134
|
45 KB.RegisterCallback(self, "LIBKEYBOUND_DISABLED")
|
flickerstreak@134
|
46 KB.RegisterCallback(self, "LIBKEYBOUND_MODE_COLOR_CHANGED","LIBKEYBOUND_ENABLED")
|
flickerstreak@134
|
47 end
|
flickerstreak@134
|
48
|
flickerstreak@134
|
49 function module:OnEnable()
|
flickerstreak@134
|
50 ReAction:RegisterBarType(L["Stance Bar"],
|
flickerstreak@134
|
51 {
|
flickerstreak@134
|
52 type = moduleID ,
|
flickerstreak@134
|
53 defaultButtonSize = 36,
|
flickerstreak@134
|
54 defaultBarRows = 1,
|
flickerstreak@134
|
55 defaultBarCols = 8,
|
flickerstreak@134
|
56 defaultBarSpacing = 3
|
flickerstreak@134
|
57 })
|
flickerstreak@134
|
58
|
flickerstreak@134
|
59 end
|
flickerstreak@134
|
60
|
flickerstreak@134
|
61 function module:OnDisable()
|
flickerstreak@134
|
62 ReAction:UnregisterBarType(L["Stance Bar"])
|
flickerstreak@134
|
63 end
|
flickerstreak@134
|
64
|
flickerstreak@134
|
65 function module:OnDestroyBar(event, bar, name)
|
flickerstreak@134
|
66 local btns = self.buttons[bar]
|
flickerstreak@134
|
67 if btns then
|
flickerstreak@134
|
68 for _,b in pairs(btns) do
|
flickerstreak@134
|
69 if b then
|
flickerstreak@134
|
70 b:Destroy()
|
flickerstreak@134
|
71 end
|
flickerstreak@134
|
72 end
|
flickerstreak@134
|
73 self.buttons[bar] = nil
|
flickerstreak@134
|
74 end
|
flickerstreak@134
|
75 end
|
flickerstreak@134
|
76
|
flickerstreak@134
|
77 function module:OnRefreshBar(event, bar, name)
|
flickerstreak@134
|
78 if bar.config.type == moduleID then
|
flickerstreak@134
|
79 local btns = self.buttons[bar]
|
flickerstreak@134
|
80 if btns == nil then
|
flickerstreak@134
|
81 btns = { }
|
flickerstreak@134
|
82 self.buttons[bar] = btns
|
flickerstreak@134
|
83 end
|
flickerstreak@134
|
84 local profile = self.db.profile
|
flickerstreak@134
|
85 if profile.buttons[name] == nil then
|
flickerstreak@134
|
86 profile.buttons[name] = {}
|
flickerstreak@134
|
87 end
|
flickerstreak@134
|
88 local btnCfg = profile.buttons[name]
|
flickerstreak@134
|
89
|
flickerstreak@134
|
90 local r, c = bar:GetButtonGrid()
|
flickerstreak@134
|
91 local n = r*c
|
flickerstreak@134
|
92 for i = 1, n do
|
flickerstreak@134
|
93 if btnCfg[i] == nil then
|
flickerstreak@134
|
94 btnCfg[i] = {}
|
flickerstreak@134
|
95 end
|
flickerstreak@134
|
96 if btns[i] == nil then
|
flickerstreak@134
|
97 local success, r = pcall(Button.New,Button,i,profile,bar,i>1 and btnCfg[i-1].stanceID)
|
flickerstreak@134
|
98 if success and r then
|
flickerstreak@134
|
99 btns[i] = r
|
flickerstreak@134
|
100 bar:AddButton(i,r)
|
flickerstreak@134
|
101 else
|
flickerstreak@134
|
102 n = i - 1
|
flickerstreak@134
|
103 bar:ClipNButtons(n)
|
flickerstreak@134
|
104 break
|
flickerstreak@134
|
105 end
|
flickerstreak@134
|
106 end
|
flickerstreak@134
|
107 btns[i]:Refresh()
|
flickerstreak@134
|
108 end
|
flickerstreak@134
|
109 for i = n+1, #btns do
|
flickerstreak@134
|
110 if btns[i] then
|
flickerstreak@134
|
111 bar:RemoveButton(btns[i])
|
flickerstreak@134
|
112 btns[i] = btns[i]:Destroy()
|
flickerstreak@134
|
113 if btnCfg[i] then
|
flickerstreak@134
|
114 btnCfg[i] = nil
|
flickerstreak@134
|
115 end
|
flickerstreak@134
|
116 end
|
flickerstreak@134
|
117 end
|
flickerstreak@134
|
118 end
|
flickerstreak@134
|
119
|
flickerstreak@134
|
120 end
|
flickerstreak@134
|
121
|
flickerstreak@134
|
122 function module:OnEraseBar(event, bar, name)
|
flickerstreak@134
|
123 self.db.profile.buttons[name] = nil
|
flickerstreak@134
|
124 end
|
flickerstreak@134
|
125
|
flickerstreak@134
|
126 function module:OnRenameBar(event, bar, oldName, newName)
|
flickerstreak@134
|
127 local b = self.db.profile.buttons
|
flickerstreak@134
|
128 b[newname], b[oldname] = b[oldname], nil
|
flickerstreak@134
|
129 end
|
flickerstreak@134
|
130
|
flickerstreak@134
|
131 function module:OnConfigModeChanged(event, mode)
|
flickerstreak@134
|
132 for bar in pairs(self.buttons) do
|
flickerstreak@134
|
133 for b in bar:IterateButtons() do
|
flickerstreak@134
|
134 b:UpdateActionIDLabel(mode)
|
flickerstreak@134
|
135 end
|
flickerstreak@134
|
136 end
|
flickerstreak@134
|
137 end
|
flickerstreak@134
|
138
|
flickerstreak@134
|
139 function module:LIBKEYBOUND_ENABLED(evt)
|
flickerstreak@134
|
140 for _, buttons in pairs(self.buttons) do
|
flickerstreak@134
|
141 for _, b in pairs(buttons) do
|
flickerstreak@134
|
142 b:SetKeybindMode(true)
|
flickerstreak@134
|
143 end
|
flickerstreak@134
|
144 end
|
flickerstreak@134
|
145 end
|
flickerstreak@134
|
146
|
flickerstreak@134
|
147 function module:LIBKEYBOUND_DISABLED(evt)
|
flickerstreak@134
|
148 for _, buttons in pairs(self.buttons) do
|
flickerstreak@134
|
149 for _, b in pairs(buttons) do
|
flickerstreak@134
|
150 b:SetKeybindMode(false)
|
flickerstreak@134
|
151 end
|
flickerstreak@134
|
152 end
|
flickerstreak@134
|
153 end
|
flickerstreak@134
|
154
|
flickerstreak@134
|
155 function module:RefreshAll()
|
flickerstreak@134
|
156 for bar in pairs(self.buttons) do
|
flickerstreak@134
|
157 self:OnRefreshBar(nil,bar,bar:GetName())
|
flickerstreak@134
|
158 end
|
flickerstreak@134
|
159 end
|
flickerstreak@134
|
160
|
flickerstreak@134
|
161
|
flickerstreak@134
|
162 ---- options ----
|
flickerstreak@134
|
163 function module:GetOptions()
|
flickerstreak@134
|
164 return {
|
flickerstreak@134
|
165 stance =
|
flickerstreak@134
|
166 {
|
flickerstreak@134
|
167 name = L["Stance Buttons"],
|
flickerstreak@134
|
168 type = "group",
|
flickerstreak@134
|
169 args = {
|
flickerstreak@134
|
170 showAspects = {
|
flickerstreak@134
|
171 name = L["Show Aspects"],
|
flickerstreak@134
|
172 desc = L["Show Hunter aspects as stances"],
|
flickerstreak@134
|
173 order = 1,
|
flickerstreak@134
|
174 width = "double",
|
flickerstreak@134
|
175 type = "toggle",
|
flickerstreak@134
|
176 set = function(info,value) self.db.profile.showHunterAspects = value; self:RefreshAll() end,
|
flickerstreak@134
|
177 get = function() return self.db.profile.showHunterAspects end,
|
flickerstreak@134
|
178 },
|
flickerstreak@134
|
179 hideMonkeyHawk = {
|
flickerstreak@134
|
180 name = L["Auto-hide Monkey/Hawk"],
|
flickerstreak@134
|
181 desc = L["Hide Aspect of the Monkey and Aspect of the Hawk, only when the hunter knows Aspect of the Dragonhawk"],
|
flickerstreak@134
|
182 order = 2,
|
flickerstreak@134
|
183 width = "double",
|
flickerstreak@134
|
184 type = "toggle",
|
flickerstreak@134
|
185 set = function(info,value) self.db.profile.hideMonkeyHawk = value; self:RefreshAll() end,
|
flickerstreak@134
|
186 get = function() return self.db.profile.hideMonkeyHawk end,
|
flickerstreak@134
|
187 disabled = function() return self.db.profile.showHunterAspects == false end,
|
flickerstreak@134
|
188 },
|
flickerstreak@134
|
189 hidePresences = {
|
flickerstreak@134
|
190 name = L["Hide Presences"],
|
flickerstreak@134
|
191 desc = L["Do not show Death Knight Presences as stances"],
|
flickerstreak@134
|
192 order = 3,
|
flickerstreak@134
|
193 width = "double",
|
flickerstreak@134
|
194 type = "toggle",
|
flickerstreak@134
|
195 set = function(info,value) self.db.profile.hideDKPresences = value; self:RefreshAll() end,
|
flickerstreak@134
|
196 get = function() return self.db.profile.hideDKPresences end,
|
flickerstreak@134
|
197 },
|
flickerstreak@134
|
198 hideAuras = {
|
flickerstreak@134
|
199 name = L["Hide Auras"],
|
flickerstreak@134
|
200 desc = L["Do not show Paladin Auras as stances"],
|
flickerstreak@134
|
201 order = 4,
|
flickerstreak@134
|
202 width = "double",
|
flickerstreak@134
|
203 type = "toggle",
|
flickerstreak@134
|
204 set = function(info,value) self.db.profile.hidePaladinAuras = value; self:RefreshAll() end,
|
flickerstreak@134
|
205 get = function() return self.db.profile.hidePaladinAuras end,
|
flickerstreak@134
|
206 },
|
flickerstreak@134
|
207 }
|
flickerstreak@134
|
208 }
|
flickerstreak@134
|
209 }
|
flickerstreak@134
|
210 end
|