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