comparison modules/Stance.lua @ 134:d186e041ca14

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